: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 ---- */
/* --size fits the board, pad and buttons into one phone screen: the 250px is the toolbar, status, pad, actions and gaps. */
.game {
  --size: min(92vw, 480px, calc(100vh - 250px));
  --size: min(92vw, 480px, calc(100svh - 250px));
  display: grid; gap: 12px; justify-items: center; scroll-margin-top: 8px;
}
.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 {
  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: var(--size); }
.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: var(--size); }
.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: var(--size); }
.done-banner.show { display: block; }
.done-banner p { margin: 4px 0 10px; }
.done-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.share-note { margin: 10px 0 0; font-size: .9rem; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.share-note[hidden] { display: none; }
/* Puzzle links: one short line above the board, so the board and pad still show on arrival on a phone. */
.challenge-box { width: var(--size); margin: 0; padding: 8px 12px; border-radius: var(--radius); background: var(--accent-soft); font-size: .92rem; }
.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; }
}
.menu-btn { display: none; }
/* Phones: logo and a menu button on one row; the nav opens below as a list, so the game starts higher up. */
@media (max-width: 600px) {
  .site-header { padding: 8px 12px; }
  .menu-btn {
    display: flex; align-items: center; justify-content: center; width: 40px; height: 40px;
    border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; padding: 0;
  }
  .menu-btn span, .menu-btn span::before, .menu-btn span::after {
    display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 1px; position: relative;
  }
  .menu-btn span::before, .menu-btn span::after { content: ''; position: absolute; left: 0; }
  .menu-btn span::before { top: -6px; }
  .menu-btn span::after { top: 6px; }
  .menu-open .menu-btn span { background: transparent; }
  .menu-open .menu-btn span::before { top: 0; transform: rotate(45deg); }
  .menu-open .menu-btn span::after { top: 0; transform: rotate(-45deg); }
  .site-header nav { display: none; width: 100%; flex-direction: column; gap: 0; }
  .menu-open nav { display: flex; }
  .site-header nav a { padding: 10px 4px; border-top: 1px solid var(--line); font-size: 1rem; }
  main { padding-top: 8px; }
  /* On game pages the intro moves under the game, so the board and the number pad show on arrival. */
  main:has(> #game) { display: flex; flex-direction: column; }
  main:has(> #game) > * { order: 3; }
  main:has(> #game) > h1 { order: 0; }
  main:has(> #game) > #game { order: 1; }
  main:has(> #game) > .lede { order: 2; margin-top: 16px; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Hints ---- */
.hint-box { width: var(--size); 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; }

/* ---- Guides ---- */
.crumbs { font-size: .9rem; margin: 4px 0 0; }
.guide-list h2 { font-size: 1.1rem; }
figure.ex { margin: 16px 0; }
figure.ex figcaption { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 4px; }
.ex-grid { width: 100%; max-width: 340px; aspect-ratio: 1; margin: 0 auto; border-collapse: collapse; table-layout: fixed; border: 2px solid var(--line-strong); background: var(--surface); }
.ex-grid td { border: 1px solid var(--line); text-align: center; padding: 0; font-size: 1.05rem; }
.ex-grid td.c2, .ex-grid td.c5 { border-right: 2px solid var(--line-strong); }
.ex-grid tr:nth-child(3) td, .ex-grid tr:nth-child(6) td { border-bottom: 2px solid var(--line-strong); }
.ex-grid td.added { color: var(--entered); }
.ex-grid td.new { color: var(--entered); background: var(--accent-soft); font-weight: 700; }
.table-wrap { overflow-x: auto; margin: 16px 0; }
.cage-table caption { text-align: left; font-weight: 700; padding: 4px 0; }
.cage-table td.combos { font-variant-numeric: tabular-nums; }
.cage-table tr.one td { background: var(--accent-soft); }

/* ---- Technique diagrams ---- */
.cand-grid { max-width: 400px; }
.cand-grid td { position: relative; font-size: 1.1rem; font-weight: 600; }
.cand-grid .cm { position: absolute; inset: 1px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: .62rem; font-weight: 400; line-height: 1; color: var(--muted); }
.cand-grid .cm span { display: flex; align-items: center; justify-content: center; }
.cand-grid .cm span.k { color: var(--ink); font-weight: 700; background: var(--same); border-radius: 3px; }
.cand-grid .cm span.x { color: var(--error); text-decoration: line-through; font-weight: 700; }
.ex-grid td.u { background: var(--peer); }
.ex-grid td.hl { box-shadow: inset 0 0 0 2px var(--accent); }
.diagram-key { font-size: .9rem; color: var(--muted); text-align: center; margin: 4px 0 0; }
.diagram-key .k { color: var(--ink); font-weight: 700; background: var(--same); border-radius: 3px; padding: 0 3px; }
.diagram-key .x { color: var(--error); text-decoration: line-through; font-weight: 700; }
@media (max-width: 400px) { .cand-grid .cm { font-size: .55rem; } }
