/* Paper Games. Paper, ink, a ballpoint and a highlighter. Square corners,
   flat colour, nothing that glows. */

:root {
  --paper: #f4f2ed;
  --paper-2: #e8e5dc;
  --ink: #141414;
  --mute: #6f6b63;
  --line: #c6c1b5;
  --pen: #2447c9;
  --mark: #ffdf3d;
  --mark-2: #f8eeb4;
  --bad: #d3321c;
  --thick: 2px;
  --gutter: 16px;
  --sans: 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
  --safe-top: var(--mnbg-safe-top, env(safe-area-inset-top, 0px));
  --safe-right: var(--mnbg-safe-right, env(safe-area-inset-right, 0px));
  --safe-bottom: var(--mnbg-safe-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--mnbg-safe-left, env(safe-area-inset-left, 0px));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121212;
    --paper-2: #202020;
    --ink: #ecebe6;
    --mute: #8f8b82;
    --line: #3a3936;
    --pen: #8aa6ff;
    --mark: #6b5a00;
    --mark-2: #34300f;
    --bad: #ff6b55;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

button,
a {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

[hidden] {
  display: none !important;
}

a {
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--pen);
  outline-offset: 2px;
}

#app {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + var(--gutter)) calc(var(--safe-bottom) + 16px)
    calc(var(--safe-left) + var(--gutter));
  display: flex;
  flex-direction: column;
}

.label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}

/* ---- home ------------------------------------------------------------- */

.masthead {
  position: relative;
  padding: 28px 0 20px;
  border-bottom: var(--thick) solid var(--ink);
}

/* The language switch: two small flags, the one in use outlined. */
.langs {
  position: absolute;
  top: 0;
  right: -8px;
  display: flex;
}

.langs button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.langs svg {
  display: block;
  width: 24px;
  height: 16px;
  outline: 1px solid var(--line);
  opacity: 0.45;
}

.langs button[aria-pressed='true'] svg {
  outline: var(--thick) solid var(--ink);
  outline-offset: 2px;
  opacity: 1;
}

.masthead h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.masthead p {
  margin: 12px 0 0;
  color: var(--mute);
  max-width: 34em;
}

.games {
  list-style: none;
  margin: 0;
  padding: 0;
}

.games a {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.games a:active {
  background: var(--paper-2);
}

.games svg {
  width: 44px;
  height: 44px;
  display: block;
}

.games .name {
  display: block;
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.games .blurb {
  display: block;
  color: var(--mute);
  font-size: 14px;
}

.games .resume {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--pen);
  font-variant-numeric: tabular-nums;
}

.games .go {
  font-size: 22px;
}

.foot {
  margin-top: auto;
  padding-top: 32px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---- buttons ------------------------------------------------------------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: var(--thick) solid var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

.btn:active {
  background: var(--ink);
  color: var(--paper);
}

.btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.btn.primary:active {
  background: var(--paper);
  color: var(--ink);
}

.btn.wide {
  width: 100%;
}

.btn small {
  font-weight: 400;
  letter-spacing: 0.04em;
  margin-left: 8px;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

/* ---- bars ------------------------------------------------------------- */

.bar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: var(--thick) solid var(--ink);
  padding-bottom: 8px;
}

.bar .back {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 24px;
  margin-left: -10px;
}

.bar h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.bar .sub {
  display: block;
  font-size: 12px;
  color: var(--mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.bar .share {
  text-align: left;
}

.bar .share span {
  color: var(--pen);
}

.bar .timer {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---- setup ------------------------------------------------------------- */

.rules {
  margin: 20px 0 8px;
  padding: 0 0 0 1.3em;
}

.rules li {
  margin: 0 0 8px;
}

.field {
  margin-top: 22px;
}

.field .label {
  display: block;
  margin-bottom: 8px;
}

.seg {
  display: flex;
  border: var(--thick) solid var(--ink);
}

.seg button {
  flex: 1;
  min-height: 44px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.seg button + button {
  border-left: 1px solid var(--ink);
}

.seg button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

.actions-col {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.number .entry {
  display: flex;
}

.number input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: var(--thick) solid var(--ink);
  border-right: 0;
  background: var(--paper);
  color: var(--ink);
  font: 700 20px/1 var(--sans);
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
}

.number input::placeholder {
  color: var(--line);
}

.number .note {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--mute);
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: 28px 0 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.stats dt,
.stats dd {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stats dt {
  color: var(--mute);
}

.stats dd {
  font-weight: 700;
}

/* ---- play ------------------------------------------------------------- */

#app.play {
  height: 100%;
  min-height: 0;
  padding-bottom: calc(var(--safe-bottom) + 10px);
}

.stage {
  flex: 1;
  min-height: 160px;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 12px 0;
}

.board {
  --w: 9;
  --h: 9;
  width: min(100cqw, 100cqh * var(--w) / var(--h));
  aspect-ratio: var(--w) / var(--h);
  display: grid;
  grid-template-columns: repeat(var(--w), 1fr);
  grid-template-rows: repeat(var(--h), 1fr);
  border: var(--thick) solid var(--ink);
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.board.wait {
  place-items: center;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  border-color: var(--line);
}

.board .making {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: calc(100cqi / var(--w) * 0.56);
  line-height: 1;
  font-weight: 400;
  color: var(--pen);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}

.cell.er {
  border-right: var(--thick) solid var(--ink);
}

.cell.eb {
  border-bottom: var(--thick) solid var(--ink);
}

.cell.lc {
  border-right: 0;
}

.cell.lr {
  border-bottom: 0;
}

.cell.given {
  color: var(--ink);
  font-weight: 700;
  cursor: default;
}

.cell.peer {
  background: var(--paper-2);
}

.cell.same {
  background: var(--mark-2);
}

.cell.sel {
  background: var(--mark);
}

.cell.bad {
  color: var(--bad);
}

.cell.hinted::after {
  content: '';
  position: absolute;
  right: 3px;
  top: 3px;
  width: 4px;
  height: 4px;
  background: var(--mute);
}

.notes {
  position: absolute;
  inset: 6%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: calc(100cqi / var(--w) * 0.24);
  color: var(--mute);
  font-weight: 400;
}

.notes.five {
  grid-template-rows: repeat(2, 1fr);
}

.notes span {
  display: grid;
  place-items: center;
}

/* Binairo: a filled square and an empty one. */
.sq {
  width: 54%;
  height: 54%;
  border: max(2px, calc(100cqi / var(--w) * 0.07)) solid currentColor;
}

.sq.one {
  background: currentColor;
}

.given .sq {
  color: var(--ink);
}

.pad {
  display: grid;
  grid-template-columns: repeat(var(--keys, 9), 1fr);
  border: var(--thick) solid var(--ink);
  margin-top: 4px;
}

.pad button {
  min-height: 52px;
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
}

.pad button + button {
  border-left: 1px solid var(--ink);
}

.pad button:active:not(:disabled) {
  background: var(--ink);
  color: var(--paper);
}

.pad button:disabled {
  color: var(--line);
}

.pad.notes-on button {
  color: var(--mute);
  font-size: 18px;
}

.pad .sq {
  --w: 1;
  width: 20px;
  height: 20px;
  border-width: 3px;
}

.tools {
  display: grid;
  grid-template-columns: repeat(var(--tools, 4), 1fr);
  margin-top: 10px;
  gap: 6px;
}

.tools button {
  min-height: 44px;
  min-width: 0;
  border: 1px solid var(--ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Spanish labels run longer (Deshacer, Reiniciar), and so does any label
   on the narrowest phones. */
:lang(es) .tools button {
  font-size: min(12px, 2.8vw);
  letter-spacing: 0;
}

@media (max-width: 340px) {
  .tools button {
    font-size: min(12px, 3vw);
    letter-spacing: 0;
  }
}

.tools button:active:not(:disabled),
.tools button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

.tools button:disabled {
  border-color: var(--line);
  color: var(--line);
}

.tools .confirm {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.solved {
  margin-top: 4px;
  border: var(--thick) solid var(--ink);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.solved h3 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  text-transform: uppercase;
}

.solved p {
  margin: 0;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
}

.solved .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

#toast.on {
  opacity: 1;
}

@media (max-height: 640px) {
  .pad button {
    min-height: 44px;
    font-size: 20px;
  }
  .tools button {
    min-height: 38px;
  }
  .masthead {
    padding-top: 12px;
  }
}

@media (max-width: 370px) {
  .tools button {
    font-size: min(12px, 3vw);
    letter-spacing: 0.02em;
  }
}

@media (prefers-reduced-motion: reduce) {
  #toast {
    transition: none;
  }
}
