:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f24;
  --muted: #6b6f78;
  --line: #d7d5ce;
  --line-strong: #4a4d55;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --given: #1d1f24;
  --entry: #2f6fdb;
  --peer: #eef1f7;
  --same: #d9e5fb;
  --selected: #bcd3fb;
  --conflict: #c62828;
  --conflict-bg: #fde7e7;
  --done: #2e7d32;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1f2228;
    --text: #e8e9ec;
    --muted: #9a9ea8;
    --line: #353943;
    --line-strong: #8b909b;
    --accent: #6b9cf0;
    --accent-text: #0e1116;
    --given: #e8e9ec;
    --entry: #8db4f5;
    --peer: #252a33;
    --same: #2c3a52;
    --selected: #34507e;
    --conflict: #ff8a80;
    --conflict-bg: #4a2326;
    --done: #81c784;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }

.update-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--selected); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 12px;
}

.help-overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgb(0 0 0 / 45%);
}
.help-overlay .help { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; margin: 0; }
.help-overlay .help p { margin: 0 0 10px; line-height: 1.45; }

.boot { text-align: center; color: var(--muted); margin-top: 30vh; }

sudoku-app { display: block; max-width: 520px; margin: 0 auto; padding: 12px 16px 32px; }
sudoku-app > *, sudoku-board, sudoku-keypad { display: block; }
action-button { display: contents; }

header.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 12px; min-height: 44px;
}
header.bar h1 { font-size: 1.25rem; margin: 0; }
header.bar .who { color: var(--muted); font-size: 0.9rem; }

button {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 14px; min-height: 40px; cursor: pointer;
}
button:hover { border-color: var(--line-strong); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { background: none; border: none; color: var(--accent); padding: 8px; }
button.active { background: var(--selected); border-color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.muted { color: var(--muted); }
.error { color: var(--conflict); }
.notice { background: var(--conflict-bg); color: var(--conflict); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.center { text-align: center; }

/* Login */
form.login [hidden] { display: none; }
form.login label { display: block; margin: 10px 0 4px; font-size: 0.9rem; color: var(--muted); }
form.login input {
  width: 100%; font: inherit; padding: 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
form.login button { margin-top: 16px; width: 100%; }

/* Today */
.puzzles { list-style: none; margin: 0; padding: 0; }
.puzzles li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.puzzles li:last-child { border-bottom: none; }
.puzzles .name { font-weight: 600; }
.puzzles .status { font-size: 0.9rem; color: var(--muted); }
.puzzles .status.done { color: var(--done); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.actions a { color: var(--accent); padding: 8px; }

/* Play */
.timer { font-variant-numeric: tabular-nums; font-size: 1.2rem; font-weight: 600; }
sudoku-play header.bar > div { display: flex; align-items: center; gap: 4px; }

/* The play screen fills the viewport exactly, so the keypad never needs a
   scroll. The board is --board wide: as wide as the screen allows, less
   whatever height the keypad needs. Any space left over is shared equally
   above the board, between the board and keypad, and below the keypad. */
sudoku-app:has(> sudoku-play) { padding-bottom: 12px; }
sudoku-play {
  --key: clamp(40px, 10dvh, 84px);
  display: flex; flex-direction: column;
  height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
sudoku-play > header.bar { flex: none; margin-bottom: 0; }
.play-area {
  --board: min(100cqw, 100cqh - 3 * var(--key) - 16px - 24px);
  flex: 1 1 0; min-height: 0; container-type: size;
  display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
}
.play-area > * { flex: none; width: 100%; }
.play-area > .board-box { position: relative; width: var(--board); }
.board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1; width: 100%;
  border: 2px solid var(--line-strong); border-radius: 6px; overflow: hidden;
  background: var(--surface); user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: clamp(14px, var(--board) * 0.068, 30px); cursor: pointer; color: var(--entry);
  container-type: size;
}
.cell.c2, .cell.c5 { border-right: 2px solid var(--line-strong); }
.cell.c8 { border-right: none; }
.cell.r2, .cell.r5 { border-bottom: 2px solid var(--line-strong); }
.cell.r8 { border-bottom: none; }
.cell.given { color: var(--given); font-weight: 600; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--selected); }
.cell.conflict { color: var(--conflict); background: var(--conflict-bg); }
.cell.selected.conflict { background: var(--selected); }
.notes {
  position: absolute; inset: 1px; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(8px, 22cqmin, 11px); color: var(--muted); line-height: 1;
}
.notes span { display: flex; align-items: center; justify-content: center; }

.paused {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--line-strong); border-radius: 6px;
}

/* Digits in a 3x3 grid, actions in a column on the right as tall as the grid. */
.pad { display: grid; grid-template-columns: 3fr 1fr; gap: 8px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  padding: 0; min-height: 0; height: var(--key); overflow: hidden;
  font-size: min(2rem, var(--key) * 0.42); font-weight: 600; line-height: 1.1;
  touch-action: manipulation;
}
.keypad button .left { display: block; font-size: 0.75rem; font-weight: 400; color: var(--muted); }
.controls { display: grid; grid-template-rows: repeat(4, 1fr); gap: 8px; }
.controls button { padding: 4px; min-height: 0; font-size: 0.95rem; touch-action: manipulation; }

/* Short landscape screens (a phone on its side): the board takes the full
   height under the top bar, with the pad beside it at the same height. */
@media (orientation: landscape) and (max-height: 560px) {
  sudoku-app:has(> sudoku-play) { max-width: 900px; padding-top: 4px; padding-bottom: 8px; }
  sudoku-play {
    height: calc(100vh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    height: calc(100dvh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .play-area { --board: min(100cqh, 50cqw - 8px); flex-direction: row; justify-content: center; gap: 16px; }
  .play-area > * { width: auto; }
  .play-area > .pad { flex: 1 1 0; height: var(--board); }
  .play-area > .solved { flex: 1 1 0; }
  .pad sudoku-keypad, .pad .keypad { height: 100%; }
  .pad .keypad { grid-template-rows: repeat(3, 1fr); }
  .pad .keypad button { height: auto; font-size: 2rem; }
}

.solved { text-align: center; }
.solved .big { font-size: 1.6rem; font-weight: 700; color: var(--done); }

/* Leaderboard */
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tabs button { flex: 0 0 auto; padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.home-tabs { margin: 0 0 12px; }
.home-tabs button { flex: 1 1 0; }
.puzzles .status.in-progress button.link { padding: 0 4px; min-height: 0; font-size: inherit; }
form.login.endless-open select { width: auto; flex: none; }
form.login.endless-open input { width: auto; }
.date-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
table.board-table { width: 100%; border-collapse: collapse; }
table.board-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.board-table tr:last-child td { border-bottom: none; }
table.board-table td.rank { width: 2.5em; color: var(--muted); font-variant-numeric: tabular-nums; }
table.board-table td.time { text-align: right; font-variant-numeric: tabular-nums; }
table.board-table tr.me td { font-weight: 700; }
.levels { display: inline-flex; gap: 3px; vertical-align: middle; }
.levels span {
  width: 18px; height: 18px; border-radius: 50%; font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); color: var(--muted);
}
.levels span.on { background: var(--done); border-color: var(--done); color: var(--surface); }

.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card h2 { font-size: 1.05rem; margin: 0 0 8px; }

/* Serverless play */
form.login .inline { display: flex; gap: 8px; }
form.login .inline input { flex: 1; min-width: 0; }
form.login .inline button { margin-top: 0; width: auto; }
form.login select {
  width: 100%; font: inherit; padding: 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.share-link {
  width: 100%; font: inherit; font-size: 0.85rem; padding: 8px; margin: 4px 0 12px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.action-message { flex-basis: 100%; margin: 4px 0 0; }

/* Admin */
.card .small { font-size: 0.85rem; }
.card p.small { margin: 4px 0 0; }
.card label.check { display: block; margin-bottom: 8px; }
.card progress { width: 100%; height: 12px; accent-color: var(--accent); }
.releases { list-style: none; margin: 0; padding: 0; }
.releases li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.releases li:last-child { border-bottom: none; }
.releases .release-info { min-width: 0; }
.releases .name { font-weight: 600; margin-right: 6px; }
.badge {
  display: inline-block; font-size: 0.75rem; padding: 1px 8px; margin-right: 4px;
  border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted);
}
.badge.current { border-color: var(--done); color: var(--done); }
.releases button { flex: none; }

/* Anti-cheat: suspicious results and the replay viewer */
.badge.suspicious { border-color: var(--conflict); color: var(--conflict); margin-left: 6px; }
.badge.warn { border-color: var(--conflict); color: var(--conflict); }
table.board-table tr.clickable { cursor: pointer; }
table.board-table tr.warn td { color: var(--conflict); }
.warn-text { color: var(--conflict); }
.card .flag { margin-top: 8px; }
.card .flag.inline { display: flex; gap: 8px; }
.card .flag.inline input {
  flex: 1; min-width: 0; font: inherit; padding: 8px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.card .flag button { flex: none; }
button.danger { color: var(--conflict); border-color: var(--conflict); }
.replay-player { --board: min(100%, 420px); }
.replay-player label.reveal { font-weight: 600; }
.replay-board { width: var(--board); margin: 0 auto; }
.replay-board .cell { cursor: default; }
.replay-board .cell.note-text { font-size: 0.7rem; color: var(--muted); letter-spacing: 1px; }
.replay-board .cell.changed { background: var(--selected); }
.replay-board .board.solved { border-color: var(--done); }
.clocks { display: flex; justify-content: space-between; margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.replay-player p.now { margin: 4px 0; min-height: 1.4em; }
.replay-player input.scrub { width: 100%; accent-color: var(--accent); }
.replay-controls { display: flex; gap: 8px; margin: 8px 0; }
.replay-controls button { flex: 1; margin: 0; }
.speeds { margin: 0; }
table.replay-events tr.current td { background: var(--selected); }
table.replay-events tr.long td:first-child, table.replay-events tr.stretch-paused td:first-child, table.replay-events tr.stretch-hidden td:first-child { border-left: 3px solid var(--conflict); }
table.replay-events td.time { white-space: nowrap; }

/* Streaks and the Stats screen */
.streak { margin: 4px 0 8px; font-weight: 600; }
.streak .flame, .streak-big .flame { margin-right: 6px; }
.streak-big { font-size: 1.3rem; font-weight: 700; margin: 4px 0; }
.streak-marker {
  margin-left: 6px; font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.stats-table th { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-align: left; padding: 4px; }
table.stats-table th.num, table.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.stats-table td.num { white-space: nowrap; }
svg.spark { width: 64px; height: 20px; vertical-align: middle; overflow: visible; }
svg.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
