/* SudokuPath — one stylesheet for the whole site.
 *
 * Order: tokens, base, layout, header/footer, board, controls, content,
 * ad slots, print. The board is the product, so it gets the largest share of
 * the viewport on every screen and everything else works around it. */

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --ink: #171a24;
  --ink-2: #444a5c;
  --muted: #6b7285;
  --line: #dcdfea;
  --line-strong: #2c3142;
  --accent: #4b46d6;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfb;
  --accent-soft-2: #dedcf7;
  --good: #157a4a;
  --good-soft: #e3f5ec;
  --bad: #c0362c;
  --bad-soft: #fdeceb;
  --given: #171a24;
  --entry: #4b46d6;
  --shadow: 0 1px 2px rgba(23, 26, 36, .06), 0 8px 24px -12px rgba(23, 26, 36, .18);
  --radius: 12px;
  --wrap: 1180px;
  --gutter: 18px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1017;
  --surface: #161a24;
  --surface-2: #1e2331;
  --ink: #edeff5;
  --ink-2: #c2c7d4;
  --muted: #939aad;
  --line: #2a3040;
  --line-strong: #6d7691;
  --accent: #8b86ff;
  --accent-ink: #12131c;
  --accent-soft: #262a44;
  --accent-soft-2: #333a58;
  --good: #5ed69b;
  --good-soft: #16352a;
  --bad: #ff8f85;
  --bad-soft: #3a1f1d;
  --given: #edeff5;
  --entry: #8b86ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -14px rgba(0, 0, 0, .7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1017;
    --surface: #161a24;
    --surface-2: #1e2331;
    --ink: #edeff5;
    --ink-2: #c2c7d4;
    --muted: #939aad;
    --line: #2a3040;
    --line-strong: #6d7691;
    --accent: #8b86ff;
    --accent-ink: #12131c;
    --accent-soft: #262a44;
    --accent-soft-2: #333a58;
    --good: #5ed69b;
    --good-soft: #16352a;
    --bad: #ff8f85;
    --bad-soft: #3a1f1d;
    --given: #edeff5;
    --entry: #8b86ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -14px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; color: var(--ink); margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.25rem, 1.1rem + .7vw, 1.55rem); letter-spacing: -.01em; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em;
  background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gutter); }
/* Single-axis properties only on anything that is also a .wrap: the `margin`
   and `padding` shorthands reset the inline axis too, which cancels the wrap's
   auto centring and its gutter and leaves sections on a different left edge
   from the content above them. */
.section { margin-block: 40px; }
.section-tight { margin-block: 24px; }
.game + .section { margin-block-start: 34px; }
.lede { font-size: 1.08rem; color: var(--ink-2); max-width: 68ch; }
.muted { color: var(--muted); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* --- Header / footer ---------------------------------------------------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; gap: 12px; min-height: 58px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; color: var(--ink);
  text-decoration: none; letter-spacing: -.02em; font-size: 1.06rem; }
.logo-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: grid; place-items: center; color: var(--accent-ink); flex: none;
}
.nav { margin-left: auto; min-width: 0; }
.nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav a {
  display: block; padding: 7px 11px; border-radius: 8px; color: var(--ink-2);
  text-decoration: none; font-size: .93rem; font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.theme-toggle {
  margin-left: 0; width: 38px; height: 38px; border-radius: 9px; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
}
.nav + .theme-toggle { margin-left: 0; }

.site-footer {
  background: var(--surface); border-top: 1px solid var(--line);
  margin-top: 56px; padding: 34px 0 22px; font-size: .93rem; color: var(--ink-2);
}
.footer-grid { display: grid; gap: 26px; grid-template-columns: 1fr; }
.site-footer h2 { font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }
.footer-about p { max-width: 42ch; color: var(--muted); }
.footer-bottom {
  margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; color: var(--muted); font-size: .87rem;
}

@media (min-width: 700px) { .footer-grid { grid-template-columns: 1.6fr 1fr 1fr 1fr; } }

/* --- Breadcrumbs / page head --------------------------------------------- */
.breadcrumbs { padding-top: 16px; font-size: .87rem; }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; color: var(--muted); }
.breadcrumbs li + li::before { content: "/"; margin-right: 6px; color: var(--line-strong); opacity: .6; }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); }

.page-head { padding-block: 18px 6px; }

/* --- The board ------------------------------------------------------------ */
.game { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: start; padding-top: 10px; }

.board-col { min-width: 0; }

.board-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px; font-size: .9rem; color: var(--ink-2);
}
.board-meta .pill {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums;
}
.pill b { font-weight: 650; color: var(--ink); }
.pill-level { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 650; }
.pill.is-bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.board-meta .spacer { flex: 1 1 auto; }

.board {
  --cell-line: var(--line);
  display: grid;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
  box-shadow: var(--shadow);
}
.board.size-9 { grid-template-columns: repeat(9, 1fr); }
.board.size-6 { grid-template-columns: repeat(6, 1fr); max-width: 460px; }
.board.size-4 { grid-template-columns: repeat(4, 1fr); max-width: 360px; }

.cell {
  position: relative;
  border: 0;
  border-right: 1px solid var(--cell-line);
  border-bottom: 1px solid var(--cell-line);
  background: var(--surface);
  color: var(--entry);
  font: inherit;
  font-weight: 550;
  font-size: clamp(1.05rem, 4.2vw, 1.7rem);
  display: grid; place-items: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease;
}
.board.size-9 .cell:nth-child(9n) { border-right: 0; }
.board.size-9 .cell:nth-child(n + 73) { border-bottom: 0; }
.board.size-9 .cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--line-strong); }
.board.size-9 .cell:nth-child(n + 19):nth-child(-n + 27),
.board.size-9 .cell:nth-child(n + 46):nth-child(-n + 54) { border-bottom: 2px solid var(--line-strong); }

.board.size-6 .cell:nth-child(6n) { border-right: 0; }
.board.size-6 .cell:nth-child(n + 31) { border-bottom: 0; }
.board.size-6 .cell:nth-child(3n):not(:nth-child(6n)) { border-right: 2px solid var(--line-strong); }
.board.size-6 .cell:nth-child(n + 13):nth-child(-n + 18) { border-bottom: 2px solid var(--line-strong); }

.board.size-4 .cell:nth-child(4n) { border-right: 0; }
.board.size-4 .cell:nth-child(n + 13) { border-bottom: 0; }
.board.size-4 .cell:nth-child(2n):not(:nth-child(4n)) { border-right: 2px solid var(--line-strong); }
.board.size-4 .cell:nth-child(n + 5):nth-child(-n + 8) { border-bottom: 2px solid var(--line-strong); }

.cell.is-given { color: var(--given); font-weight: 700; }
.cell.is-peer { background: var(--surface-2); }
.cell.is-same { background: var(--accent-soft); }
.cell.is-selected { background: var(--accent-soft-2); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.is-bad { background: var(--bad-soft); color: var(--bad); }
.cell.is-hint { animation: hint-pulse 1.1s ease-in-out 2; }
@keyframes hint-pulse {
  0%, 100% { background: var(--surface); }
  50% { background: var(--good-soft); }
}
.cell.is-hint.is-selected { animation: none; }

.notes { display: grid; width: 100%; height: 100%; padding: 2px;
  font-size: clamp(.42rem, 1.5vw, .62rem); line-height: 1; color: var(--muted); font-weight: 550; }
.board.size-9 .notes { grid-template-columns: repeat(3, 1fr); }
.board.size-6 .notes { grid-template-columns: repeat(3, 1fr); }
.board.size-4 .notes { grid-template-columns: repeat(2, 1fr); }
.notes span { display: grid; place-items: center; }
.notes span:empty::after { content: ""; }

/* --- Difficulty tabs -------------------------------------------------------
 * A segmented control directly above the board. Choosing a difficulty is the
 * main thing people come to do, and it used to be a card section a full screen
 * below the board. */
.level-tabs {
  display: flex; gap: 4px; width: 100%; max-width: 560px; margin: 0 auto 12px;
  padding: 4px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; overflow-x: auto; scrollbar-width: none;
}
.level-tabs::-webkit-scrollbar { display: none; }
.level-tabs a {
  flex: 1 1 0; min-width: max-content; text-align: center; white-space: nowrap;
  padding: 9px 12px; border-radius: 9px; text-decoration: none;
  color: var(--ink-2); font-size: .92rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.level-tabs a:hover { background: var(--surface); color: var(--ink); }
.level-tabs a[aria-current="page"] {
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
}

/* --- Controls -------------------------------------------------------------- */
.controls { margin: 14px auto 0; width: 100%; max-width: 560px; display: grid; gap: 10px; }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
/* 56px clears the 44px minimum touch target with room for the label; these are
   the controls people reach for most, and they were previously cramped. */
.tool {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 12px; padding: 9px 4px 8px; font: inherit; font-size: .82rem; cursor: pointer;
  display: grid; gap: 4px; justify-items: center; align-content: center;
  line-height: 1.15; min-height: 58px; font-weight: 550;
  -webkit-tap-highlight-color: transparent;
}
.tool > span[aria-hidden] { font-size: 1.3rem; line-height: 1; }
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tool[disabled] { opacity: .45; cursor: not-allowed; }
.tool .badge { font-size: .68rem; color: var(--muted); }
.tool[aria-pressed="true"] .badge { color: inherit; opacity: .8; }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.pad.size-6 { grid-template-columns: repeat(6, 1fr); }
.pad.size-4 { grid-template-columns: repeat(4, 1fr); }
.pad button {
  aspect-ratio: 1 / 1.1; min-height: 52px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 11px; font: inherit; font-size: clamp(1.1rem, 4vw, 1.4rem); font-weight: 600;
  color: var(--ink); cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.pad button:active { background: var(--accent-soft); }
.pad button:hover { background: var(--accent-soft); border-color: var(--accent-soft-2); }
.pad button.is-done { opacity: .32; }
.pad .left { position: absolute; right: 3px; bottom: 1px; font-size: .58rem; font-weight: 500; color: var(--muted); }

@media (max-width: 460px) {
  .pad { grid-template-columns: repeat(5, 1fr); }
  .pad.size-4 { grid-template-columns: repeat(4, 1fr); }
  .tools { gap: 7px; }
  .tool { font-size: .76rem; min-height: 56px; }
}

@media (max-width: 560px) {
  :root { --gutter: 14px; }
  .section { margin-block: 32px; }
  .page-head { padding-top: 12px; }
  .grid { gap: 12px; }
  .grid.g4 { grid-template-columns: repeat(2, 1fr); }
  .tile { padding: 14px; }
  .tile-level p { font-size: .84rem; }
  .board-meta { font-size: .86rem; gap: 6px; }
  .btn { padding: 11px 14px; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; font-size: .94rem;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.status {
  min-height: 1.5em; margin: 10px auto 0; width: 100%; max-width: 560px;
  font-size: .93rem; color: var(--ink-2);
}
.status.is-good { color: var(--good); }
.status.is-bad { color: var(--bad); }
.status a { font-weight: 600; }

/* --- Win panel ------------------------------------------------------------- */
.win {
  margin: 16px auto 0; width: 100%; max-width: 560px;
  background: var(--good-soft); border: 1px solid transparent; border-radius: var(--radius);
  padding: 16px 18px;
}
.win h2 { margin-bottom: 4px; }
.win .stats { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 12px; color: var(--ink-2); font-size: .94rem; }
.win .stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- Sidebar / rail -------------------------------------------------------- */
.rail { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: .95rem; margin-bottom: 8px; letter-spacing: -.01em; }
.card .stats { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; font-size: .93rem; color: var(--ink-2); }
.card .stats b { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.card ul { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; color: var(--ink-2); font-size: .94rem; }
.card .link-list { list-style: none; padding: 0; }
.card .link-list a { text-decoration: none; font-weight: 550; }
.card .link-list a:hover { text-decoration: underline; }

/* On desktop the board column is left-aligned rather than centred, so the board,
   the tabs, the controls and every section heading below share one left edge.
   Centring the block inside a wide column was what made the page look untidy. */
@media (min-width: 1024px) {
  .game { grid-template-columns: minmax(0, 1fr) 296px; gap: 32px; }
  .game .level-tabs, .game .board, .game .controls, .game .status, .game .win { margin-inline: 0; }
  /* Tabs, board and controls share one width so their edges line up. */
  .game .board, .game .level-tabs, .game .controls, .game .status, .game .win { max-width: 600px; }
  .rail { position: sticky; top: 74px; }
}

/* --- Cards / grids --------------------------------------------------------- */
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid.g2, .grid.g3, .grid.g4 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 940px) {
  .grid.g3 { grid-template-columns: repeat(3, 1fr); }
  .grid.g4 { grid-template-columns: repeat(4, 1fr); }
}

.tile {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile h3 { margin-bottom: 4px; }
.tile p { margin: 0; color: var(--muted); font-size: .93rem; }
.tile .kicker { font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; color: var(--accent); font-weight: 700; }

/* Difficulty is the point of these four cards, so it is shown rather than
   described: four bars, filled to the level. */
.tile-level { display: grid; gap: 10px; align-content: start; }
.tile-level h3 { margin: 0; font-size: 1.15rem; }
.tile-level .meter { display: flex; gap: 4px; }
.tile-level .meter i {
  flex: 1 1 0; height: 6px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line);
}
.tile-level .meter i.on { background: var(--accent); border-color: var(--accent); }
.tile-level p { font-size: .89rem; }

.cluster-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.cluster-head h2 { font-size: clamp(1.15rem, 1.05rem + .5vw, 1.4rem); }
.cluster-head h2 { margin: 0; }
.cluster-head a { font-size: .92rem; font-weight: 600; text-decoration: none; }

.hero { padding-block: 30px 8px; }
.hero-head { padding-block: 26px 6px; }
.hero-head h1 { font-size: clamp(1.55rem, 1.15rem + 1.5vw, 2.1rem); margin-bottom: .35em; }
.hero-head .lede { max-width: 60ch; }
.hero-meta { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 20px;
  color: var(--ink-2); font-size: .93rem; }
.hero-meta li { display: inline-flex; align-items: center; gap: 7px; }
.hero-meta svg { color: var(--good); }

/* --- Prose ----------------------------------------------------------------- */
.prose { max-width: 72ch; }
.prose h2 { margin-top: 1.7em; }
.prose h3 { margin-top: 1.4em; }
.prose ul, .prose ol { padding-left: 1.25em; display: grid; gap: 7px; margin: 0 0 1.1em; }
.prose li { color: var(--ink-2); }
.prose .note {
  background: var(--surface); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
  padding: 12px 16px; color: var(--ink-2);
}
.layout { display: grid; gap: 26px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 1024px) { .layout.with-rail { grid-template-columns: minmax(0, 1fr) 300px; } }

.table-scroll { overflow-x: auto; margin: 0 0 1.2em; }
table { border-collapse: collapse; width: 100%; font-size: .94rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { font-weight: 650; color: var(--ink); background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 8px;
}
.faq summary { cursor: pointer; font-weight: 600; }
.faq-body { padding-top: 8px; color: var(--ink-2); }

.def-list { display: grid; gap: 10px; margin: 0 0 1.2em; }
.def-list dt { font-weight: 650; }
.def-list dd { margin: 0; color: var(--ink-2); }

/* Miniature board used inside strategy articles. */
.mini-board { display: grid; grid-template-columns: repeat(9, 1fr); width: min(320px, 100%);
  aspect-ratio: 1/1; border: 2px solid var(--line-strong); border-radius: 6px; overflow: hidden;
  background: var(--surface); margin: 0 0 1.2em; }
.mini-board div { display: grid; place-items: center; border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.mini-board div:nth-child(9n) { border-right: 0; }
.mini-board div:nth-child(n+73) { border-bottom: 0; }
.mini-board div:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--line-strong); }
.mini-board div:nth-child(n+19):nth-child(-n+27),
.mini-board div:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--line-strong); }
.mini-board .mark { background: var(--accent-soft); color: var(--accent); }
.mini-board .cut { background: var(--bad-soft); color: var(--bad); }

/* --- Printable puzzles ----------------------------------------------------- */
.print-form {
  display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.field { display: grid; gap: 6px; }
.field > span { font-size: .85rem; font-weight: 650; color: var(--ink-2); }
.field select, .field input[type="number"] {
  font: inherit; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); width: 100%;
}
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .field-row { grid-template-columns: repeat(4, 1fr); } }
.check { display: flex; align-items: center; gap: 9px; font-size: .93rem; color: var(--ink-2); }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.sheet { margin-top: 26px; }
.sheet-grid { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.puzzle-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.puzzle-card h3 { font-size: .86rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 10px; }
.paper-board { display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1/1;
  border: 2px solid #111; background: #fff; color: #111; }
.paper-board.size-6 { grid-template-columns: repeat(6, 1fr); }
.paper-board.size-4 { grid-template-columns: repeat(4, 1fr); }
.paper-board div { display: grid; place-items: center; border-right: 1px solid #999; border-bottom: 1px solid #999;
  font-size: clamp(.8rem, 2.4vw, 1.05rem); font-weight: 600; font-family: var(--sans); }
.paper-board.size-9 div:nth-child(9n) { border-right: 0; }
.paper-board.size-9 div:nth-child(n+73) { border-bottom: 0; }
.paper-board.size-9 div:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid #111; }
.paper-board.size-9 div:nth-child(n+19):nth-child(-n+27),
.paper-board.size-9 div:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid #111; }
.paper-board.size-6 div:nth-child(6n) { border-right: 0; }
.paper-board.size-6 div:nth-child(n+31) { border-bottom: 0; }
.paper-board.size-6 div:nth-child(3n):not(:nth-child(6n)) { border-right: 2px solid #111; }
.paper-board.size-6 div:nth-child(n+13):nth-child(-n+18) { border-bottom: 2px solid #111; }
.paper-board.size-4 div:nth-child(4n) { border-right: 0; }
.paper-board.size-4 div:nth-child(n+13) { border-bottom: 0; }
.paper-board.size-4 div:nth-child(2n):not(:nth-child(4n)) { border-right: 2px solid #111; }
.paper-board.size-4 div:nth-child(n+5):nth-child(-n+8) { border-bottom: 2px solid #111; }
.solutions { margin-top: 26px; }
.solutions .paper-board div { font-size: .7rem; font-weight: 500; }

/* --- Ad slots --------------------------------------------------------------
 * Empty containers until assets/ads.js is switched on. No height is reserved
 * while ads are off, so an ad-free build has no blank gaps. */
.ad-slot { margin: 0; text-align: center; max-width: 100%; }
.ads-on .ad-slot { margin: 22px auto; }
.ads-on .ad-slot { min-height: var(--ad-h, 280px); }
.ads-on .ad-slot::before {
  content: "Advertisement"; display: block; font-size: .66rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); margin-bottom: 4px;
}
.ad-rail { position: sticky; top: 74px; }
.ad-anchor {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); padding: 6px 0 4px; text-align: center;
}
.ad-close {
  position: absolute; top: -13px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: 14px;
}
body.has-anchor-ad { padding-bottom: 116px; }

.sp-consent {
  position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--surface);
  border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -18px rgba(0,0,0,.5);
}
.sp-consent-inner {
  max-width: var(--wrap); margin-inline: auto; padding: 14px 18px; display: grid; gap: 12px;
  align-items: center; font-size: .9rem; color: var(--ink-2);
}
.sp-consent p { margin: 0; }
.sp-consent-actions { display: flex; gap: 10px; }
@media (min-width: 760px) { .sp-consent-inner { grid-template-columns: 1fr auto; } }

/* --- Print -----------------------------------------------------------------
 * Printing is a first-class feature here: the page furniture, ads and controls
 * disappear and only the puzzle grids are laid out on the paper. */
@media print {
  :root { --ink: #000; --line: #999; --line-strong: #000; --surface: #fff; --bg: #fff; }
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .breadcrumbs, .ad-slot, .ad-anchor, .sp-consent,
  .no-print, .controls, .board-meta, .rail, .print-form, .skip-link { display: none !important; }
  main { padding: 0; }
  .wrap { max-width: none; padding: 0; }
  .sheet-grid { display: block; }
  .puzzle-card { break-inside: avoid; page-break-inside: avoid; border: 0; padding: 0; margin: 0 0 14mm; }
  .puzzle-card h3 { color: #000; margin-bottom: 4mm; }
  .paper-board { width: 150mm; max-width: 100%; margin: 0 auto; }
  .sheet-grid.per-2 .paper-board { width: 120mm; }
  .sheet-grid.per-4 { display: grid; grid-template-columns: 1fr 1fr; gap: 8mm; }
  .sheet-grid.per-4 .paper-board { width: 80mm; }
  .sheet-grid.per-6 { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
  .sheet-grid.per-6 .paper-board { width: 76mm; }
  .page-break { break-after: page; page-break-after: always; }
  .board { max-width: 150mm; box-shadow: none; }
  .print-only { display: block !important; }
  a[href]::after { content: ""; }
}
.print-only { display: none; }

@page { margin: 14mm; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* --- Language switcher -----------------------------------------------------
 * A <details> disclosure rather than a hover menu: hover does not exist on a
 * phone, and the previous version was simply unreachable there. This opens on
 * tap, on Enter, and closes on Escape or an outside click (assets/theme.js).
 * On narrow screens the trigger shrinks to the language code. */
.lang-switch { position: relative; flex: none; }
.lang-switch > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  font-size: .86rem; font-weight: 600; color: var(--ink-2); min-height: 38px;
  border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: var(--surface);
  -webkit-tap-highlight-color: transparent;
}
.lang-switch > summary::-webkit-details-marker { display: none; }
.lang-switch > summary::marker { content: ""; }
.lang-switch > summary:hover { background: var(--surface-2); color: var(--ink); }
.lang-switch > summary::after { content: "▾"; font-size: .7em; opacity: .7; }
.lang-switch[open] > summary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.lang-switch svg { flex: none; }
.lang-code { display: none; }
.lang-switch ul {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  list-style: none; margin: 0; padding: 6px; min-width: 168px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); display: grid; gap: 2px;
}
.lang-switch a {
  display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none;
  color: var(--ink-2); font-size: .93rem;
}
.lang-switch a:hover { background: var(--surface-2); color: var(--ink); }
.lang-switch a[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Below this width the header stacks: brand and controls on the first row, the
   section links on a second row that scrolls sideways rather than pushing the
   whole document wider — which is what used to happen. */
@media (max-width: 860px) {
  .site-header { position: static; }
  .header-inner { gap: 8px; padding-block: 7px; min-height: 0; }
  .logo { margin-right: auto; }
  .nav {
    order: 3; flex: 1 0 100%; margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter) 0;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav ul { flex-wrap: nowrap; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .lang-name { display: none; }
  .lang-code { display: inline; }
}
