/* Palette follows the calm slate-blue convention of classic online Sudoku:
   navy givens, blue player entries, layered blue highlights. */
:root {
  --bg: #f3f6fa;
  --panel: #ffffff;
  --ink: #344861;
  --ink-soft: #6e7c8c;
  --accent: #325aaf;
  --accent-soft: #eaeef7;
  --accent-ink: #ffffff;
  --line: #bec6d4;
  --line-strong: #344861;
  --given: #344861;
  --entry: #325aaf;
  --hl-unit: #e2ebf3;   /* row / column / box of the selected cell */
  --hl-same: #c3d7ea;   /* cells holding the same number */
  --hl-sel: #bbdefb;    /* the selected cell */
  --bad: #e55c6c;
  --bad-bg: #f7cfd6;
  --ok: #0aa06e;
  --shadow: 0 1px 2px rgba(52, 72, 97, .07), 0 8px 24px rgba(52, 72, 97, .07);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --panel: #191d25;
    --ink: #dfe5ee;
    --ink-soft: #939eae;
    --accent: #6f9dff;
    --accent-soft: #232c3c;
    --accent-ink: #0d1220;
    --line: #333b48;
    --line-strong: #93a0b4;
    --given: #eef2f8;
    --entry: #7fadff;
    --hl-unit: #263041;
    --hl-same: #35507c;
    --hl-sel: #34527f;
    --bad: #ff8894;
    --bad-bg: #4b1f26;
    --ok: #43d39e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { width: 100%; height: 100%; fill: currentColor; display: block; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(.9rem, 3vw, 2rem);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: inherit; }
.brand-mark {
  width: 1.85rem; height: 1.85rem; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 1rem;
}
.brand-name { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; }
.brand-name .dot { color: var(--accent); }
.cta {
  border: 0; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: .95rem; padding: .65rem 1.4rem; border-radius: 10px;
  cursor: pointer; transition: filter .12s, transform .08s;
}
.cta:hover { filter: brightness(1.08); }
.cta:active { transform: scale(.97); }

/* ---------- layout ---------- */
.layout {
  max-width: 1120px; margin: 0 auto;
  padding: clamp(.8rem, 2.2vw, 1.6rem);
  display: grid; gap: clamp(.9rem, 2.4vw, 2rem);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}
@media (min-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr) 23rem; }
  .col-side { position: sticky; top: 5.2rem; }
}
.col-board { display: grid; gap: .7rem; min-width: 0; }
.col-side { display: grid; gap: 1rem; min-width: 0; }

/* ---------- meta bar ---------- */
.metabar {
  display: grid; grid-template-columns: auto 1fr 1fr 1fr auto;
  align-items: end; gap: .5rem clamp(.4rem, 2vw, 1rem);
}
.meta-item { display: grid; gap: .05rem; min-width: 0; }
.meta-item.center { justify-items: center; }
.meta-item.right { justify-items: end; }
.meta-label { font-size: .78rem; color: var(--ink-soft); }
.meta-item strong { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.meta-item strong.warn { color: var(--bad); }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: .1rem; top: 50%; width: .42rem; height: .42rem;
  border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
#selLevel {
  appearance: none; background: none; border: 0; padding: 0 1.1rem 0 0;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.icon-mini {
  width: 2rem; height: 2rem; flex: none; margin-bottom: .15rem; padding: .42rem; border: 0; border-radius: 50%;
  background: var(--accent-soft); color: var(--ink-soft); cursor: pointer;
}
.icon-mini:hover { color: var(--accent); }

/* ---------- board ---------- */
.board-wrap { position: relative; }
.board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1; width: 100%;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: 4px; overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: manipulation; user-select: none;
}
.cell {
  position: relative; border: 0; padding: 0; background: var(--panel); color: var(--entry);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: clamp(1.15rem, min(5.4vw, 5vh), 2rem);
  font-weight: 400; font-variant-numeric: tabular-nums;
  display: grid; place-items: center; cursor: pointer;
  transition: background-color .12s ease;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.bt { border-top: 2px solid var(--line-strong); }
.cell.bl { border-left: 2px solid var(--line-strong); }
.cell.given { color: var(--given); font-weight: 500; }
.cell.unit { background: var(--hl-unit); }
.cell.same { background: var(--hl-same); }
.cell.sel { background: var(--hl-sel); }
.cell.bad { background: var(--bad-bg); color: var(--bad); }
.cell.bad.sel { background: var(--bad-bg); }
.cell.pulse { animation: pop .4s ease; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@keyframes pop { 0% { transform: scale(.55); } 60% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.cell.wrong-anim { animation: shake .25s ease; }
@media (prefers-reduced-motion: reduce) { .cell { transition: none; animation: none !important; } }

.notes {
  position: absolute; inset: 6%;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  font-size: .32em; line-height: 1; color: var(--ink-soft); font-weight: 600;
}
.notes span { display: grid; place-items: center; }
.notes span.hi { color: var(--accent); font-weight: 800; }

/* pause veil */
.veil {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--panel); border-radius: 4px;
  border: 2px solid var(--line-strong);
}
.veil[hidden] { display: none; }
.resume {
  display: grid; gap: .5rem; justify-items: center;
  border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer;
}
.resume svg { width: 3.4rem; height: 3.4rem; padding: .8rem; border-radius: 50%; background: var(--accent-soft); }

/* ---------- tools ---------- */
.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: .3rem; }
.tool {
  display: grid; justify-items: center; gap: .3rem;
  border: 0; background: none; color: var(--ink-soft); cursor: pointer;
  padding: .4rem .1rem; border-radius: 10px; min-height: 60px;
  transition: color .12s;
}
.tool:hover { color: var(--accent); }
.tool:active .tool-ico { transform: scale(.92); }
.tool-ico {
  position: relative; width: 2.5rem; height: 2.5rem; padding: .6rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  transition: transform .08s, background .12s;
}
.tool[aria-pressed="true"] .tool-ico { background: var(--accent); color: var(--accent-ink); }
.tool-label { font-size: .74rem; font-weight: 600; }
.badge {
  position: absolute; top: -.3rem; right: -.5rem;
  background: var(--ink-soft); color: #fff; border-radius: 999px;
  font-size: .55rem; font-weight: 800; letter-spacing: .03em;
  padding: .1rem .32rem; line-height: 1.35;
}
.tool[aria-pressed="true"] .badge { background: var(--ok); }
.badge.count { background: var(--accent); min-width: 1.05rem; text-align: center; }

/* ---------- number pad ---------- */
.digits { display: grid; grid-template-columns: repeat(9, 1fr); gap: .25rem; }
.digit {
  border: 0; background: none; color: var(--accent); cursor: pointer;
  font-size: clamp(1.6rem, 6.5vw, 2.1rem); font-weight: 500;
  min-height: 56px; display: grid; place-items: center; position: relative;
  border-radius: 10px; transition: background .12s, transform .08s, color .12s;
}
.digit:hover:not(:disabled) { background: var(--accent-soft); }
.digit:active:not(:disabled) { transform: scale(.92); }
.digit.active { background: var(--accent); color: var(--accent-ink); }
.digit.notes-on { color: var(--ink-soft); }
.digit:disabled { opacity: .3; cursor: default; }
.digit .left {
  position: absolute; bottom: .12rem; left: 0; right: 0;
  font-size: .58rem; font-weight: 700; color: var(--ink-soft);
}
.digit.active .left { color: var(--accent-ink); opacity: .8; }
@media (min-width: 940px) { .digits { gap: .35rem; } .digit { min-height: 64px; } }

/* ---------- rounds panel ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: .85rem; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .6rem; gap: .5rem; }
.panel-title {
  margin: 0; font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-soft);
}
.panel-note { font-size: .74rem; color: var(--ink-soft); }
.rounds { display: grid; grid-template-columns: repeat(10, 1fr); gap: .3rem; }
@media (min-width: 940px) { .rounds { grid-template-columns: repeat(5, 1fr); gap: .4rem; } }
.round {
  min-height: 42px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 700; font-size: .9rem; cursor: pointer;
  position: relative; display: grid; place-items: center; transition: border-color .12s, background .12s;
}
.round:hover { border-color: var(--accent); }
.round[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.round.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.round.done[aria-current="true"] { color: var(--accent-ink); }
.round.done::after {
  content: "✓"; position: absolute; top: -.32rem; right: -.32rem;
  background: var(--ok); color: #fff; font-size: .58rem; font-weight: 800;
  width: 1rem; height: 1rem; border-radius: 50%; display: grid; place-items: center;
}

/* ---------- status + tips ---------- */
.status { margin: 0; min-height: 1.35rem; text-align: center; font-size: .85rem; color: var(--ink-soft); }
.status.good { color: var(--ok); font-weight: 600; }
.status.bad { color: var(--bad); font-weight: 600; }
.tips { margin: 0; text-align: center; font-size: .72rem; color: var(--ink-soft); line-height: 2; }
kbd {
  font: inherit; font-size: .68rem; font-weight: 700;
  background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: .05rem .3rem;
}
@media (hover: none) { .tips { display: none; } }

/* ---------- overlay ---------- */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(4px); border-radius: 4px; animation: fade .18s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 1.5rem 1.5rem 1.25rem; text-align: center; max-width: 22rem; width: 100%;
  box-shadow: 0 16px 48px rgba(52, 72, 97, .25);
}
.overlay-icon { font-size: 2.2rem; line-height: 1; margin-bottom: .4rem; }
.overlay-card h2 { margin: 0 0 .35rem; font-size: 1.35rem; }
.overlay-card p { margin: 0 0 1rem; color: var(--ink-soft); font-size: .9rem; }
.overlay-stats {
  display: grid; grid-auto-flow: column; gap: .5rem;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: .7rem 0; margin-bottom: 1rem;
}
.overlay-stats[hidden] { display: none; }
.overlay-stats div { display: grid; gap: .1rem; }
.overlay-stats span { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.overlay-stats strong { font-size: 1rem; font-variant-numeric: tabular-nums; }
.overlay-actions { display: flex; gap: .5rem; }
.btn {
  flex: 1; min-height: 46px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: .92rem; font-weight: 700; cursor: pointer;
  transition: filter .12s, transform .08s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
