:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --ink: #1f2a24;
  --muted: #5d6b63;
  --line: #c9cfc7;
  --line-strong: #2b3a32;
  --accent: #2f6f4f;
  --accent-soft: #dcebe2;
  --same: #c6e0d1;
  --peer: #eef3ee;
  --given: #1f2a24;
  --entered: #2a5db0;
  --error: #c0392b;
  --error-soft: #f8dcd8;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --surface: #1c2420;
    --ink: #e6ece8;
    --muted: #9fb0a6;
    --line: #3a4740;
    --line-strong: #a9bbb0;
    --accent: #6fbf94;
    --accent-soft: #24382d;
    --same: #2d4a3a;
    --peer: #1f2a25;
    --given: #e6ece8;
    --entered: #8fb6ff;
    --error: #ff7a6b;
    --error-soft: #4a2420;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .95rem; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--accent); }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 8px 0 4px; }
h2 { font-size: 1.25rem; margin: 28px 0 8px; }
h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.lede { color: var(--muted); margin-top: 0; }
.prose { max-width: 680px; }
.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; border-top: 1px solid var(--line); margin-top: 40px; }
.site-footer p { margin: 4px 0; }
.ai-note { font-style: italic; }
.ad { margin: 24px 0; min-height: 100px; }
.ad-label { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin: 16px 0; }
.links-grid a { display: block; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--ink); }
.links-grid a strong { display: block; color: var(--accent); }
.links-grid a span { font-size: .85rem; color: var(--muted); }

/* ---- Game ---- */
.game { display: grid; gap: 14px; justify-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; width: 100%; }
.toolbar select { font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.status { display: flex; gap: 16px; justify-content: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .95rem; }
.board {
  --size: min(92vw, 480px);
  width: var(--size); height: var(--size);
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  border: 2px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: var(--surface);
  touch-action: manipulation; user-select: none;
}
.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: calc(var(--size) / 15); color: var(--entered); cursor: pointer; background: var(--surface);
}
.cell:nth-child(9n) { border-right: 0; }
.cell.c2, .cell.c5 { border-right: 2px solid var(--line-strong); }
.cell.r2, .cell.r5 { border-bottom: 2px solid var(--line-strong); }
.cell.r8 { border-bottom: 0; }
.cell.given { color: var(--given); font-weight: 600; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.error { color: var(--error); background: var(--error-soft); }
.notes { position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: calc(var(--size) / 40); color: var(--muted); line-height: 1; }
.notes span { display: flex; align-items: center; justify-content: center; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; width: min(92vw, 480px); }
.pad button { aspect-ratio: 1 / 1.1; font-size: 1.35rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.pad button:disabled { opacity: .35; cursor: default; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(92vw, 480px); }
.actions .btn { flex-direction: column; gap: 0; font-size: .85rem; padding: 8px 4px; }
.actions .btn b { font-size: 1.15rem; line-height: 1.2; }
.done-banner { display: none; text-align: center; padding: 14px; border-radius: var(--radius); background: var(--accent-soft); width: min(92vw, 480px); }
.done-banner.show { display: block; }
.done-banner p { margin: 4px 0 10px; }
.check-row { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }

/* ---- Printable ---- */
.print-sheet { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 20px 0; }
.print-grid { width: 100%; aspect-ratio: 1; border-collapse: collapse; border: 2px solid #000; table-layout: fixed; background: #fff; color: #000; }
.print-grid td { border: 1px solid #888; text-align: center; font-size: 1.1rem; padding: 0; }
.print-grid td.c2, .print-grid td.c5 { border-right: 2px solid #000; }
.print-grid tr:nth-child(3) td, .print-grid tr:nth-child(6) td { border-bottom: 2px solid #000; }
.print-caption { text-align: center; font-size: .85rem; margin-top: 4px; }
.answers h2 { break-before: page; }
.answers .print-grid td { font-size: .8rem; }
@media print {
  .site-header, .site-footer, .no-print, .ad { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
}

/* ---- Solver ---- */
.solver-board .cell input {
  width: 100%; height: 100%; border: 0; background: transparent; text-align: center;
  font: inherit; font-size: calc(var(--size) / 15); color: var(--given); caret-color: var(--accent);
}
.solver-board .cell input:focus { outline: none; background: var(--accent-soft); }
.solver-board .cell.solved input { color: var(--entered); }
.msg { min-height: 1.6em; text-align: center; color: var(--muted); }
.msg.bad { color: var(--error); }

@media (max-width: 420px) {
  h1 { font-size: 1.35rem; }
  .pad { gap: 4px; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Hints ---- */
.hint-box { width: min(92vw, 480px); padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); font-size: .95rem; }
.hint-box[hidden] { display: none; }

/* ---- Killer cages ---- */
.board.killer .cell::before {
  content: ''; position: absolute; pointer-events: none;
  top: -1px; right: -1px; bottom: -1px; left: -1px;
  border: 0 dashed var(--muted);
}
.board.killer .cell.kt::before { top: 3px; border-top-width: 1.5px; }
.board.killer .cell.kb::before { bottom: 3px; border-bottom-width: 1.5px; }
.board.killer .cell.kl::before { left: 3px; border-left-width: 1.5px; }
.board.killer .cell.kr::before { right: 3px; border-right-width: 1.5px; }
.board.killer .cell[data-sum]::after {
  content: attr(data-sum); position: absolute; top: 1px; left: 2px; z-index: 1;
  font-size: calc(var(--size) / 40); font-weight: 700; line-height: 1; color: var(--ink);
  background: var(--surface); padding: 0 1px;
}
.board.killer .cell.selected[data-sum]::after, .board.killer .cell.peer[data-sum]::after,
.board.killer .cell.same[data-sum]::after { background: transparent; }
.board.killer .notes { top: 11px; }
.combo-table { border-collapse: collapse; margin: 10px 0; font-size: .95rem; }
.combo-table th, .combo-table td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
