/* Sudocu: the grid drawn straight on the page. Printed givens in ink, your
   entries in ballpoint blue, notes in pencil. One typeface, Archivo, used
   across its width axis: a wide wordmark, a narrow clock, normal-width digits.
   Layout: everything flush left; board beside the clock, keypad and
   leaderboard on wide screens, one column on phones. */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url(/fonts/archivo-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url(/fonts/archivo-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --paper: #ffffff;        /* page and grid */
  --ink: #16181d;          /* givens, text, box lines */
  --pencil: #686e79;       /* notes and secondary text */
  --pen: #26399f;          /* your entries: ballpoint blue */
  --on-ink: #ffffff;       /* text on ink-filled buttons */
  --rule: #d6d9df;         /* thin cell lines */
  --rule-strong: #16181d;  /* box lines and outlines */
  --line: #e4e6ea;         /* hairlines in the interface */
  --wash: #eff1f9;         /* row, column and box of the selected cell */
  --wash-strong: #dde2f4;  /* same digit as the selected cell */
  --select: #c7cfee;       /* selected cell */
  --error: #c8322b;
  --shadow: rgb(22 24 29 / 0.2);

  --face: 'Archivo', 'Helvetica Neue', Arial, system-ui, sans-serif;
  /* Type scale: 12 14 16 18 21 24 36 48 */
  --t-12: 0.75rem;
  --t-14: 0.875rem;
  --t-16: 1rem;
  --t-18: 1.125rem;
  --t-21: 1.3125rem;
  --t-24: 1.5rem;
  --t-36: 2.25rem;
  --t-48: 3rem;
  --frame: 592px;          /* page width; wider with two columns */

  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #10141c;
    --ink: #e7eaf0;
    --pencil: #8f97a5;
    --pen: #9bacff;
    --on-ink: #10141c;
    --rule: #2a3140;
    --rule-strong: #a3acbb;
    --line: #232a37;
    --wash: #171d2a;
    --wash-strong: #1f2943;
    --select: #2b3a6a;
    --error: #ff7b72;
    --shadow: rgb(0 0 0 / 0.55);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #10141c;
  --ink: #e7eaf0;
  --pencil: #8f97a5;
  --pen: #9bacff;
  --on-ink: #10141c;
  --rule: #2a3140;
  --rule-strong: #a3acbb;
  --line: #232a37;
  --wash: #171d2a;
  --wash-strong: #1f2943;
  --select: #2b3a6a;
  --error: #ff7b72;
  --shadow: rgb(0 0 0 / 0.55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--t-16)/1.5 var(--face);
  font-stretch: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, p { margin: 0; }
h1, h2 { text-wrap: balance; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Page frame ---------- */
.masthead, .layout, .footer {
  width: 100%;
  max-width: var(--frame);
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-block: 22px 18px;
}
.brand { display: grid; gap: 6px; min-width: 0; }
.wordmark {
  font-size: clamp(2rem, 1.5rem + 2vw, var(--t-48));
  font-weight: 380;
  font-stretch: 125%;
  line-height: 0.9;
  letter-spacing: -0.03em;
}
.dateline, .player { font-size: var(--t-14); color: var(--pencil); }
.player strong { color: var(--ink); font-weight: 600; }

.controls { display: flex; align-items: center; gap: 8px; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.lang button {
  min-width: 40px;
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  background: none;
  font-size: var(--t-12);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--pencil);
}
.lang button[aria-pressed='true'] { background: var(--wash); color: var(--ink); }
.theme {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--ink);
}
.lang button:hover, .theme:hover { color: var(--ink); background: var(--wash); }

.layout {
  flex: 1;
  display: grid;
  gap: 24px;
  align-items: start;
  padding-block: 0 40px;
}
.play { display: grid; gap: 12px; min-width: 0; }

/* ---------- Level tabs ---------- */
.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}
.level {
  display: grid;
  gap: 2px;
  justify-items: start;
  padding: 4px 0 10px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  text-align: left;
  color: var(--pencil);
}
.level-name { font-size: var(--t-18); font-weight: 500; line-height: 1.2; }
.level-status { min-height: 1.3em; font-size: var(--t-12); line-height: 1.3; font-variant-numeric: tabular-nums; }
.level:hover { color: var(--ink); }
.level[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--ink); }
.level[aria-selected='true'] .level-name { font-weight: 650; }
.level.solved .level-status { color: var(--pen); font-weight: 600; }

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 16px;
  font-size: var(--t-14);
  color: var(--pencil);
}

/* ---------- Board ---------- */
/* Board and panels share one grid cell, so a tall panel grows the area */
.board-wrap { display: grid; container-type: inline-size; }
.board, .sheet { grid-area: 1 / 1; }
.board {
  align-self: start;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 2px;
  aspect-ratio: 1;
  max-width: 100%;
  border: 2px solid var(--rule-strong);
  background: var(--rule-strong);
}
.box {
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 1px;
  min-width: 0;
  min-height: 0;
  background: var(--rule);
}
.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  font-size: 6.4cqi;
  font-weight: 400;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--ink);
}
.cell:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--pen); }
.cell.given { font-weight: 620; }
.cell.entry { color: var(--pen); }
.cell.peer { background: var(--wash); }
.cell.same { background: var(--wash-strong); }
.cell.selected { background: var(--select); }
.cell.conflict { color: var(--error); text-decoration: underline 0.06em; text-underline-offset: 0.14em; }
.notes {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 7%;
  font-size: 2.6cqi;
  font-weight: 500;
  line-height: 1;
  color: var(--pencil);
}
.notes span { display: grid; place-items: center; }
.notes .hit { color: var(--pen); font-weight: 700; }
.board.idle .cell, .board.done .cell { cursor: default; }
.board.veiled { opacity: 0.4; filter: blur(1.5px); }

/* The one flourish: a wave of blue across the grid when it's solved */
@media (prefers-reduced-motion: no-preference) {
  .board.celebrate .cell { animation: wave 700ms ease-out backwards; animation-delay: calc(var(--d) * 45ms); }
  @keyframes wave {
    0% { background: var(--paper); }
    35% { background: var(--select); }
    100% { background: var(--paper); }
  }
}

/* ---------- Panels over the board ---------- */
.sheet {
  /* Above the board: its faded (opacity) state would otherwise paint over
     this layer and catch every tap */
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 12px;
}
.panel {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  padding: clamp(16px, 5cqi, 24px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 18px 40px -22px var(--shadow);
}
.panel h2 { font-size: var(--t-21); font-weight: 600; line-height: 1.25; }
.panel p { color: var(--pencil); }
.field { display: grid; gap: 6px; }
.field label { font-weight: 500; }
.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
}
.field input:focus { border-color: var(--pen); outline: 2px solid var(--pen); outline-offset: -1px; }
.hint, .error { font-size: var(--t-14); }
.error { color: var(--error) !important; }
.error:empty { display: none; }
.turnstile:empty { display: none; }
.code {
  display: block;
  padding: 14px 8px;
  border-radius: 6px;
  background: var(--wash);
  font-size: clamp(1.05rem, 5cqi, 1.375rem);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
  user-select: all;
}
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  font-weight: 500;
}
.button:hover { background: var(--wash); }
.button.primary { border-color: var(--ink); background: var(--ink); color: var(--on-ink); }
.button.primary:hover { opacity: 0.88; }
.button:disabled { opacity: 0.6; cursor: progress; }
.link {
  justify-self: start;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}
.link:hover { color: var(--pen); }
.link-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; }

/* ---------- Clock, tools, keypad ---------- */
/* Phones: clock and tools share a row above the keypad strip */
.side {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "clock tools"
    "status status"
    "keys keys"
    "list list";
  gap: 10px 16px;
  align-items: center;
  min-width: 0;
}
.clock {
  grid-area: clock;
  font-size: var(--t-36);
  font-weight: 500;
  font-stretch: 68%;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clock.solved { color: var(--pen); }
.tools { grid-area: tools; justify-self: end; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.tool {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  font-size: var(--t-14);
  font-weight: 500;
}
.tool:hover { background: var(--wash); }
.tool[aria-pressed='true'] { border-color: var(--ink); background: var(--ink); color: var(--on-ink); }
.status { grid-area: status; display: grid; gap: 2px; min-height: 1.5em; }
.clock-note { font-size: var(--t-14); color: var(--pencil); }

/* The keypad is drawn like a row of the grid: thin lines, a thick line
   after every third digit */
.keypad {
  grid-area: keys;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 1px;
  border: 2px solid var(--rule-strong);
  background: var(--rule);
}
.keypad button {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 5;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  font-size: var(--t-24);
  font-weight: 500;
  line-height: 1;
  color: var(--pen);
}
.keypad button:nth-child(3), .keypad button:nth-child(6) {
  border-right: 1px solid var(--rule-strong);
  box-shadow: 1px 0 0 var(--rule-strong); /* darkens the gap too: a 2px line */
}
.keypad button:focus-visible { outline-offset: -3px; }
.keypad button:hover { background: var(--wash); }
.keypad button:active { background: var(--select); }
.keypad button.done { color: var(--pencil); opacity: 0.4; }
/* Notes mode: the digits move to the corner and turn pencil, like a note */
.keypad.notes button { place-items: start; padding: 6px 7px; font-size: var(--t-14); color: var(--pencil); }
.side.idle :is(.keypad button, .tool) { opacity: 0.35; pointer-events: none; }

/* ---------- Leaderboard ---------- */
.standings { grid-area: list; display: grid; gap: 4px; margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.standings h2 { font-size: var(--t-18); font-weight: 600; line-height: 1.3; }
.standings-level { font-size: var(--t-14); color: var(--pencil); }
.ranking { display: grid; margin: 8px 0 0; padding: 0; list-style: none; font-variant-numeric: tabular-nums; }
.ranking li {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr) auto;
  gap: 8px;
  padding: 6px 8px;
  margin-inline: -8px;
  border-radius: 4px;
}
.ranking .rank { color: var(--pencil); }
.ranking .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .me { background: var(--wash); }
.ranking .me .name { font-weight: 600; }
.empty { margin-top: 4px; font-size: var(--t-14); color: var(--pencil); }

/* ---------- Footer ---------- */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 24px;
  padding-block: 18px 24px;
  border-top: 1px solid var(--line);
  font-size: var(--t-14);
  color: var(--pencil);
  font-variant-numeric: tabular-nums;
}
.footer .link { color: var(--pencil); }
.footer .link:hover { color: var(--ink); }

/* ---------- Wide screens: board beside the side column ---------- */
@media (min-width: 860px) {
  :root { --frame: 960px; }
  .masthead { padding-block: 32px 24px; }
  .layout { grid-template-columns: auto 248px; justify-content: space-between; gap: 48px; }
  /* Shrinks on short screens so the whole board stays in view */
  .play { width: min(580px, max(380px, 100dvh - 240px), 100vw - 360px); }
  .side {
    grid-template-columns: 1fr;
    grid-template-areas: "clock" "status" "keys" "tools" "list";
    gap: 14px;
    align-items: start;
  }
  /* Clock level with the tabs; clock + status rows match the tabs + meta
     line, so the keypad's top lines up with the board's */
  .status { min-height: 24px; }
  .clock { font-size: var(--t-48); }
  .tools { justify-self: start; justify-content: flex-start; }
  /* One sudoku box of digits */
  .keypad { grid-template-columns: repeat(3, 1fr); width: 204px; }
  .keypad button { aspect-ratio: 1; }
  .keypad button:nth-child(3), .keypad button:nth-child(6) { border-right: 0; box-shadow: none; }
}
