:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --thick: #374151;
  --given: #111827;
  --user: #2563eb;
  --wrong: #dc2626;
  --wrong-bg: #fde8e8;
  --sel: #bfdbfe;
  --peer: #eef2f7;
  --same: #dbeafe;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --key: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #181b21; --ink: #e5e7eb; --muted: #9ca3af;
    --line: #2f343d; --thick: #9ca3af; --given: #f3f4f6; --user: #60a5fa;
    --wrong: #f87171; --wrong-bg: #3b1a1a; --sel: #1e3a5f; --peer: #1f242c;
    --same: #1c2f4a; --accent: #3b82f6; --accent-ink: #fff; --key: #20242b;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #181b21; --ink: #e5e7eb; --muted: #9ca3af;
  --line: #2f343d; --thick: #9ca3af; --given: #f3f4f6; --user: #60a5fa;
  --wrong: #f87171; --wrong-bg: #3b1a1a; --sel: #1e3a5f; --peer: #1f242c;
  --same: #1c2f4a; --accent: #3b82f6; --accent-ink: #fff; --key: #20242b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

.app { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; padding: 12px 0 20px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top h1 { font-size: 1.4rem; margin: 0; letter-spacing: .02em; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 6px 14px; font-size: .9rem;
}
.chip.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.wide { width: 100%; padding: 12px; font-size: 1rem; border-radius: 10px; }
.chip.ghost { background: transparent; }

.stats { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .9rem; }
.stats .bad { color: var(--wrong); }
.timer { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.icon { border: none; background: none; padding: 2px 6px; font-size: .8rem; color: var(--muted); }

.board-wrap { position: relative; }
.board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1; width: 100%;
  border: 2px solid var(--thick); border-radius: 6px; overflow: hidden;
  background: var(--panel);
}
.board.hidden { filter: blur(10px); }
.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(1.1rem, 6vw, 1.8rem); aspect-ratio: 1; min-width: 0;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
.cell.br { border-right: 2px solid var(--thick); }
.cell.bb { border-bottom: 2px solid var(--thick); }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--sel); }
.cell.given { color: var(--given); font-weight: 600; }
.cell.user { color: var(--user); }
.cell.wrong { color: var(--wrong); background: var(--wrong-bg); }

.notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; padding: 1px; }
.note { font-size: clamp(.5rem, 2.3vw, .72rem); color: var(--muted); display: flex; align-items: center; justify-content: center; line-height: 1; }
.note.hl { color: var(--user); font-weight: 700; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: center; text-align: center;
  background: color-mix(in srgb, var(--panel) 80%, transparent); border-radius: 6px; padding: 16px;
}
.overlay p { margin: 0; }
.overlay .big { font-size: 1.6rem; font-weight: 700; }

.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: .72rem; padding: 6px 0; border-radius: 8px;
}
.tool .ti { font-size: 1.3rem; color: var(--ink); }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.tool.on .ti { color: var(--accent-ink); }
.tool:disabled { opacity: .4; }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.key {
  display: flex; flex-direction: column; align-items: center; padding: 8px 0 4px;
  background: var(--key); border: 1px solid var(--line); border-radius: 8px;
}
.key .kd { font-size: clamp(1.2rem, 6vw, 1.7rem); color: var(--user); line-height: 1.1; }
.key .kl { font-size: .65rem; color: var(--muted); }
.key.done { opacity: .3; }

.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal { background: var(--panel); border-radius: 14px; padding: 18px; width: min(320px, 100%); display: flex; flex-direction: column; gap: 8px; }
.modal h2 { margin: 0 0 6px; font-size: 1.2rem; }

.foot { text-align: center; color: var(--muted); font-size: .75rem; }
