/* YAOKU v5 — one stylesheet for every page. Keeps the original identity: slate clue cells,
   white number cells, square diagonal badges, dark Loose Card tiles, gold selection. */
:root {
  --bg: #F8F9FA; --surface: #FFFFFF; --surface-2: #F1F5F9; --ink: #121213; --muted: #50555A; --line: #D5DCE4;
  --clue: #1E293B; --clue-ink: #FFFFFF; --accent: #3F6B4C; --accent-ink: #FFFFFF; --gold: #C9B458; --gold-soft: #F6F0D6; --gold-ink: #121213;
  --related: #EAF1F8; --group: #DCE8F5; --danger: #A3392B; --danger-soft: #FBE9E6; --ok: #3F7A3A; --ok-soft: #E5F2E2;
  --focus: #1D4ED8; --badge-bg: #FFFFFF; --badge-rule: #94A3B8; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.05);
  --lift: 0 1px 2px rgba(15,23,42,.18); --overlay: rgba(15,23,42,.55); --dialog-shadow: 0 20px 50px rgba(0,0,0,.25);
  --radius: 8px; --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --digit: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light;
}
/* Dark board: clue squares are a lighter, grayer slate than the blue group highlight, so a selected
   cell's row and column never read as clue squares. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121213; --surface: #1B1C1F; --surface-2: #23262B; --ink: #F3F4F6; --muted: #B7BDC4; --line: #3A3F46;
    --clue: #424F64; --clue-ink: #FFFFFF; --accent: #7DBB74; --accent-ink: #0E1A0C; --gold: #D8C46A; --gold-soft: #463C1A;
    --related: #1A2633; --group: #18324D; --danger: #F08A7B; --danger-soft: #3A1F1B; --ok: #8FD188; --ok-soft: #1D3320;
    --focus: #8AB4FF; --badge-bg: #1B1C1F; --badge-rule: #6B7686; --shadow: none; --lift: none; --overlay: rgba(0,0,0,.65); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121213; --surface: #1B1C1F; --surface-2: #23262B; --ink: #F3F4F6; --muted: #B7BDC4; --line: #3A3F46;
  --clue: #424F64; --clue-ink: #FFFFFF; --accent: #7DBB74; --accent-ink: #0E1A0C; --gold: #D8C46A; --gold-soft: #463C1A;
  --related: #1A2633; --group: #18324D; --danger: #F08A7B; --danger-soft: #3A1F1B; --ok: #8FD188; --ok-soft: #1D3320;
  --focus: #8AB4FF; --badge-bg: #1B1C1F; --badge-rule: #6B7686; --shadow: none; --lift: none; --overlay: rgba(0,0,0,.65); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-underline-offset: 2px; }
::selection { background: var(--gold-soft); color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -48px; background: var(--surface); color: var(--ink); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip-link:focus { top: 8px; }

/* ---------- header / nav */
.site-header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.site-header .bar { max-width: 1040px; margin: 0 auto; padding: 6px 16px; display: flex; align-items: center; gap: 12px; min-height: 56px; }
.wordmark { display: inline-flex; align-items: baseline; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: .06em; font-size: 20px; }
.wordmark .mark { color: var(--accent); }
.wordmark small { font-weight: 500; letter-spacing: .02em; font-size: 13px; color: var(--muted); }
.site-nav { margin-left: auto; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 2px; align-items: center; }
.site-nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 15px; }
.site-nav a:hover { background: var(--surface-2); }
.site-nav a[aria-current="page"] { font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); border-radius: 0; }
.site-nav .account-link { border: 1px solid var(--line); border-radius: 999px; margin-left: 6px; }
.site-header .menu-toggle { display: none; margin-left: auto; min-height: 44px; }
@media (max-width: 760px) {
  .site-header .menu-toggle { display: inline-flex; }
  .site-nav { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); display: none; }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; align-items: stretch; padding: 8px 16px 12px; }
  .site-nav a { width: 100%; }
  .site-nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
  .site-nav .account-link { margin: 6px 0 0; justify-content: center; }
}

main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 16px 56px; }
main.narrow { max-width: 760px; }
/* Prose keeps a readable measure; tables, panels, and the tutorial board still use the full column. */
main.narrow :is(p, li, dd):not(.notice, .draft-banner) { max-width: 60ch; }
.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.site-footer .bar { max-width: 1040px; margin: 0 auto; padding: 20px 16px; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.site-footer a { color: var(--muted); }
.site-footer .tagline { margin-right: auto; font-style: italic; }

/* Type scale: body 16 · h3 17 · h2 22 · h1 28–38. h2 sits 1.29× above h3 so sections read as sections. */
h1 { font-size: clamp(28px, 4.6vw, 38px); line-height: 1.12; margin: 0 0 12px; letter-spacing: -.015em; text-wrap: balance; }
h2 { font-size: 22px; line-height: 1.25; margin: 36px 0 10px; letter-spacing: -.005em; text-wrap: balance; }
h3 { font-size: 17px; line-height: 1.3; margin: 22px 0 6px; }
p { margin: 0 0 12px; text-wrap: pretty; }
.lede { font-size: 18px; color: var(--muted); max-width: 62ch; text-wrap: pretty; }
.eyebrow { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.crumbs { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.crumbs a { color: var(--muted); }
.muted { color: var(--muted); }
.draft-banner { border: 2px dashed var(--danger); background: var(--danger-soft); color: var(--ink); padding: 12px 14px; border-radius: var(--radius); margin: 0 0 18px; font-weight: 600; }

/* ---------- buttons, forms, cards */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 15px/1 var(--font); cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 86%, var(--ink)); border-color: color-mix(in srgb, var(--accent) 86%, var(--ink)); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
@media (pointer: coarse) { .btn.small { min-height: 44px; } }
.btn[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
label { font-weight: 600; display: block; margin: 0 0 6px; }
input[type="text"], select { width: 100%; max-width: 380px; min-height: 44px; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--muted); background: var(--surface); color: var(--ink); font: 16px var(--font); }
input[type="text"]::placeholder { color: var(--muted); }
/* Form rhythm: a field's help text sits close; the action that follows gets air. */
:is(input[type="text"], select) + p { margin-top: 8px; }
:is(input[type="text"], select) + p:has(> .btn) { margin-top: 14px; }
.panel > .btn + p, .panel > .btn + .notice { margin-top: 16px; }
.panel > .notice + .btn { margin-top: 4px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-weight: 400; }
.check-row input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.form-error { color: var(--danger); font-weight: 600; }
/* Notices are tinted blocks with a hairline, not side-tab callouts. */
.notice { border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); padding: 10px 14px; border-radius: var(--radius); margin: 12px 0; }
.notice.warn { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: var(--danger-soft); }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.data thead th { font-size: 13px; font-weight: 600; color: var(--muted); border-bottom-color: var(--muted); white-space: nowrap; }
table.data tbody th { font-weight: 600; }
table.data tr.own > * { background: var(--gold-soft); font-weight: 700; }
.table-wrap { overflow-x: auto; }
/* Segmented controls: each group is one tray of choices; the chosen segment is a slate board tile. */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); vertical-align: middle; }
.tabs button, .tabs a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; border-radius: 7px; border: 0; background: transparent; color: var(--ink); font: 600 15px var(--font); cursor: pointer; text-decoration: none; }
.tabs button:hover, .tabs a:hover { background: color-mix(in srgb, var(--surface) 75%, transparent); }
.tabs [aria-pressed="true"], .tabs [aria-current="page"] { background: var(--clue); color: var(--clue-ink); box-shadow: var(--lift); }
.mt { margin-top: 14px; }
.stat { font-variant-numeric: tabular-nums; }
.stat strong { display: block; font-size: 26px; line-height: 1.2; }
/* Profile stats: one panel divided by hairlines (the 1px gaps show the panel's line colour). */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; padding: 0; overflow: hidden; background: var(--line); }
.stats .stat { background: var(--surface); padding: 14px 18px; color: var(--muted); font-size: 14px; }
.stats .stat strong { color: var(--ink); }
.stats + p { margin-top: 10px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 24px; background: var(--surface); color: var(--ink); max-width: min(440px, calc(100vw - 32px)); box-shadow: var(--dialog-shadow); }
dialog::backdrop { background: var(--overlay); }
dialog h2 { margin: 0 0 8px; }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
#win-title { font-size: 26px; }
#win-text { font-variant-numeric: tabular-nums; }

/* ---------- game layout */
/* A text-weight button: for secondary actions that should not compete with the board's controls. */
.link-btn { display: inline-flex; align-items: center; min-height: 32px; padding: 0; border: 0; background: none; color: var(--accent); font: 600 15px var(--font); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn:hover { color: color-mix(in srgb, var(--accent) 80%, var(--ink)); }
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: not-allowed; }
@media (pointer: coarse) { .link-btn { min-height: 44px; } }
.game-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.game-head h1 { font-size: 26px; margin: 0; }
.game-head .clock { margin-left: auto; font: 700 20px/1 var(--digit); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.game-sub { font-size: 15px; margin: 4px 0 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; }
.tab-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.mode-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.mode-pill.ranked { background: var(--gold-soft); border-color: var(--gold); }
/* First visit: three rules in place, above the board they describe. Never a modal; dismissed for good. */
.intro { margin: 14px 0 0; padding: 16px 18px; border-radius: 12px; background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold) 60%, var(--line)); }
.intro h2 { font-size: 18px; margin: 0 0 8px; }
.intro ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.intro li { max-width: 60ch; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
/* Phones: one column in reading order. Desktop: the tray, group sums, and controls sit beside the board
   so a cell and its card are on screen together. */
.game-main > *, .game > .side { width: 100%; max-width: 560px; margin-inline: auto; }
.game > .side { margin-top: 28px; }
@media (min-width: 960px) {
  .game { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); grid-template-areas: "top top" "board play" "board side"; grid-template-rows: auto auto 1fr; column-gap: 32px; align-items: start; }
  .game-main { display: contents; }
  .game-main > *, .game > .side { max-width: none; margin: 0; }
  .game-top { grid-area: top; }
  .game-board { grid-area: board; }
  .game-play { grid-area: play; }
  .game > .side { grid-area: side; margin-top: 24px; }
}

.board-wrap { position: relative; width: 100%; aspect-ratio: 1; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.board { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); gap: clamp(3px, 1vw, 6px); }
.board [role="row"] { display: contents; }
.cell { position: relative; border-radius: 6px; display: flex; align-items: center; justify-content: center; font: 700 clamp(20px, 6.2vw, 30px)/1 var(--digit); font-variant-numeric: tabular-nums; min-width: 0; min-height: 0; }
.cell.white { background: var(--surface); border: 1px solid var(--line); color: var(--accent); cursor: pointer; padding: 0; }
.cell.white:hover { border-color: var(--muted); }
.cell.white.given { color: var(--ink); background: var(--surface-2); }
.cell.white.given::after { content: ""; position: absolute; bottom: 12%; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.cell.white.in-group { background: var(--group); border-color: color-mix(in srgb, var(--group) 60%, var(--muted)); }
.cell.white.related { background: var(--related); }
/* The selected square is the one thing a player must never lose: gold fill plus a 3px gold ring. */
.cell.white.selected { background: var(--gold-soft); border: 2px solid var(--gold); box-shadow: inset 0 0 0 1px var(--gold), 0 0 0 1px var(--gold); z-index: 1; }
.cell.white.conflict { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
.cell.white.wrong { background: var(--danger-soft); border: 2px solid var(--danger); }
.cell.white.wrong::before { content: "✕"; position: absolute; top: 3px; right: 5px; font-size: 11px; color: var(--danger); }
.cell.white.hinted { box-shadow: 0 0 0 3px var(--focus) inset; }
.cell.white.solved { background: var(--ok-soft); border-color: var(--ok); }
.cell .notes { position: absolute; inset: 8%; display: grid; grid-template-columns: repeat(3, 1fr); font: 600 clamp(8px, 2.2vw, 11px)/1 var(--digit); color: var(--muted); }
.cell .notes span { display: flex; align-items: center; justify-content: center; }
.cell.clue { background: var(--clue); color: var(--clue-ink); }
.cell.clue.corner::after { content: "◇"; opacity: .45; font-size: 18px; }
.cell.clue.hl { box-shadow: 0 0 0 3px var(--gold) inset; }
.clue-label { position: absolute; display: inline-flex; align-items: center; gap: 2px; font: 700 clamp(10px, 3vw, 14px)/1 var(--digit); font-variant-numeric: tabular-nums; }
.clue-label .arrow { font-size: .85em; opacity: .85; }
.clue-label.down { top: 9%; left: 10%; }
.clue-label.across { bottom: 9%; right: 10%; }
.clue-label.only { position: static; font-size: clamp(12px, 3.6vw, 17px); }
.clue.dual::before { content: ""; position: absolute; inset: 0; background: linear-gradient(to top right, transparent calc(50% - .5px), color-mix(in srgb, var(--clue-ink) 35%, transparent) 50%, transparent calc(50% + .5px)); border-radius: 6px; }

.badges { position: absolute; inset: 0; pointer-events: none; }
.badge { position: absolute; width: clamp(20px, 6vw, 28px); height: clamp(20px, 6vw, 28px); transform: translate(-50%, -50%); background: var(--badge-bg); border: 1px solid var(--badge-rule); border-radius: 3px; font: 700 clamp(9px, 2.5vw, 12px)/1 var(--digit); color: var(--ink); font-variant-numeric: tabular-nums; isolation: isolate; z-index: 2; }
.badge::after { content: ""; position: absolute; left: 50%; top: 50%; width: 1px; height: 128%; background: var(--badge-rule); transform: translate(-50%, -50%) rotate(45deg); z-index: -1; }
.badge .tens { position: absolute; top: 2px; left: 3px; }
.badge .ones { position: absolute; bottom: 2px; right: 3px; }
.badge.met { border-color: var(--ok); }
.badge.broken { border-color: var(--danger); color: var(--danger); }

/* Board states with no board: loading text, offline notice, and the official-attempt panels. */
.board-wrap > p.muted:only-child { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.board-wrap:has(> .board-message) { aspect-ratio: auto; }
.board-wrap > .board-message { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 22px; }
.board-message h2 { margin: 0; }
.board-message p, .board-message ul { margin: 0; }
.board-message ul { padding-left: 20px; display: grid; gap: 4px; }
.board-message .btn { margin-top: 6px; }
/* Nothing to play yet, so the pad, sums, and controls stay out of the way (status still reports errors). */
.game:has(.board-message) :is(.group-info, .tray-head, .tray, .controls, .more-controls, .status:empty, .clock) { display: none; }
.game:has(.board-message) .board-wrap { margin-top: 4px; }
.game-board { margin-top: 14px; }

/* Play order on every screen: board, number pad, the five actions, then what the move meant. */
.tray-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 14px 0 8px; }
.tray-head :is(h2, h3) { font-size: 16px; letter-spacing: 0; margin: 0; }
.tray-head .muted { font-size: 14px; font-variant-numeric: tabular-nums; }
/* The number pad: one slate tile per digit 1–9, the Loose Cards still left of it in the corner. */
.keypad { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.key { position: relative; min-height: 52px; border-radius: 8px; border: 1px solid var(--clue); background: var(--clue); color: var(--clue-ink); font: 700 26px/1 var(--digit); font-variant-numeric: tabular-nums; cursor: pointer; padding: 0; display: grid; place-items: center; }
.key .key-count { position: absolute; right: 6px; bottom: 5px; font: 700 12px/1 var(--digit); opacity: .8; }
.key:hover:not(:disabled) { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.key:disabled { cursor: not-allowed; }
.key.used, .key.absent { background: transparent; color: var(--muted); border-style: dashed; border-color: var(--line); }
.key.absent .key-digit { opacity: .45; }
/* Notes accept any digit the puzzle uses, so a used-up tile stays tappable then. */
.key.used:not(:disabled) { border-style: solid; border-color: var(--muted); color: var(--ink); cursor: pointer; }
.card { min-height: 46px; border-radius: 6px; border: 1px solid var(--clue); background: var(--clue); color: var(--clue-ink); font: 700 22px/1 var(--digit); font-variant-numeric: tabular-nums; }
.controls { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.controls .btn { padding: 0 4px; font-size: 15px; }
.status { min-height: 26px; margin: 12px 0 0; font-weight: 600; }
.group-info { font-size: 14px; color: var(--muted); margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.group-info strong { color: var(--ink); }
.group-info:empty { display: none; }
.more-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0 20px; margin: 10px 0 0; font-size: 15px; }
.more-controls a { font-weight: 600; text-underline-offset: 3px; }
#ranked-offer { font-size: 15px; padding: 10px 12px; margin: 14px 0 0; }
.side h2:first-child { margin-top: 0; }
.side .panel h2 { font-size: 19px; }
.how-short ol { padding-left: 20px; }
.how-short li { margin-bottom: 6px; }
@media (max-width: 480px) {
  .tabs button, .tabs a { padding: 0 11px; font-size: 14px; }
  .game-head h1 { font-size: 24px; }
  .game-head .clock { font-size: 18px; }
  .game-sub { font-size: 14px; margin-bottom: 10px; }
  /* Phones: the board, pad, and the five actions share the first screen. */
  main:has(> .game) { padding-top: 12px; }
  .game-board { margin-top: 10px; }
  .tray-head { margin: 10px 0 6px; }
  .controls .btn { font-size: 14px; }
}
@media (max-width: 360px) {
  .tabs button, .tabs a { padding: 0 8px; font-size: 13px; }
  .tab-row { gap: 6px 8px; }
  .key { min-height: 48px; font-size: 24px; }
}

/* Game controls show their own pressed state, so the browser's tap flash would only be noise. */
:is(.key, .cell.white, .btn, .tabs button, .link-btn) { -webkit-tap-highlight-color: transparent; }
@media (max-width: 560px) { .sub-extra { display: none; } }

/* ---------- result sharing */
#win-dialog .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
#win-dialog #share-btn { grid-column: 1 / -1; order: -1; }
#win-dialog .actions:has(#win-next[hidden]) #win-close { grid-column: 1 / -1; }
.share-grid { margin: 14px 0 4px; font: 22px/1.15 var(--font); letter-spacing: 1px; text-align: center; }
.share-note { font-size: 14px; }
.share-fallback { width: 100%; margin-top: 8px; padding: 10px; border-radius: 6px; border: 1px solid var(--muted); background: var(--surface-2); color: var(--ink); font: 14px/1.4 var(--font); resize: none; }
dialog .status:empty { display: none; }

/* ---------- tutorial */
.tutorial { display: grid; gap: 14px; }
.tutorial-step { border: 2px solid var(--gold); background: var(--gold-soft); border-radius: 12px; padding: 14px 16px; }
.tutorial-step h3 { margin: 0 0 6px; font-size: 19px; }
.tutorial-step .step-count { font-size: 14px; font-weight: 600; margin: 0 0 2px; font-variant-numeric: tabular-nums; }
.tutorial-step .status:empty { display: none; }
.tutorial-step .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
/* Wide screens: the step sits beside the board, so instructions and feedback stay in view while you play. */
@media (min-width: 720px) {
  .tutorial { grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 22px; align-items: start; }
  .tutorial-step { position: sticky; top: 76px; }
}

/* ---------- home */
.hero { display: grid; gap: 24px; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: center; margin: 12px 0 8px; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.hero h1 { font-size: clamp(32px, 5vw, 44px); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 12px; }
.hero-actions .btn { min-height: 48px; padding: 0 20px; font-size: 16px; }
.hero-links { font-weight: 600; margin: 0 0 6px; }
.hero-links a { text-underline-offset: 3px; }
.daily-card { display: flex; flex-direction: column; gap: 8px; }
.daily-card h3 { margin: 0; display: flex; justify-content: space-between; align-items: center; }
.daily-card .state { font-size: 14px; color: var(--muted); flex: 1; }
/* Phones: the three Dailies become compact rows (name and state, then the action). */
@media (max-width: 560px) {
  .daily-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: center; padding: 14px 16px; }
  .daily-card h3 { grid-column: 1; }
  .daily-card .state { grid-column: 1; margin: 0; }
  .daily-card .btn { grid-column: 2; grid-row: 1 / span 2; }
}
.ways { display: grid; gap: 0 28px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.ways > div { border-top: 2px solid var(--clue); padding: 14px 0 8px; }
.ways h3 { margin-top: 0; }
.legend { display: grid; gap: 10px; }
.legend-item { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; }
.legend-swatch { width: 56px; height: 56px; border-radius: 8px; position: relative; display: flex; align-items: center; justify-content: center; font: 700 18px var(--digit); }

@media (prefers-reduced-motion: no-preference) {
  .key, .btn, .cell.white, .tabs button { transition: background-color .12s, border-color .12s, transform .12s; }
  .key:hover:not(:disabled) { transform: translateY(-1px); }
  .btn:active:not(:disabled), .key:active:not(:disabled) { transform: translateY(1px); }
  .cell.white.pop { animation: pop .18s ease-out; }
  @keyframes pop { from { transform: scale(.9); } to { transform: scale(1); } }
  /* The one authored moment: a solved board settles in a diagonal wave from the top-left clue. */
  .board [role="row"]:nth-child(2) { --r: 1; } .board [role="row"]:nth-child(3) { --r: 2; } .board [role="row"]:nth-child(4) { --r: 3; }
  .board [role="row"]:nth-child(5) { --r: 4; } .board [role="row"]:nth-child(6) { --r: 5; }
  .board [role="gridcell"]:nth-child(2) { --c: 1; } .board [role="gridcell"]:nth-child(3) { --c: 2; } .board [role="gridcell"]:nth-child(4) { --c: 3; }
  .board [role="gridcell"]:nth-child(5) { --c: 4; } .board [role="gridcell"]:nth-child(6) { --c: 5; }
  .cell.white.solved { animation: settle .42s cubic-bezier(.16, 1, .3, 1) both; animation-delay: calc((var(--r, 0) + var(--c, 0)) * 45ms); }
  @keyframes settle { from { transform: scale(.86); background-color: var(--surface); } to { transform: none; } }
}
body.reduce-motion * { animation: none !important; transition: none !important; }
@media (forced-colors: active) {
  .cell.clue, .card, .key { border: 1px solid CanvasText; }
  .cell.white.selected { outline: 3px solid Highlight; }
  .badge { border: 1px solid CanvasText; }
  .tabs [aria-pressed="true"] { outline: 2px solid Highlight; }
}
.legend-badge { left: 50%; top: 50%; width: 34px; height: 34px; font-size: 14px; }
.legend-card { width: 44px; min-height: 46px; display: flex; align-items: center; justify-content: center; }
/* Anchored sections (e.g. /how-to-play#tutorial) must clear the sticky header. */
[id] { scroll-margin-top: 76px; }
.panel > :first-child { margin-top: 0; }

/* ---------- help hub (/links) */
.link-list { list-style: none; margin: 20px 0 0; padding: 0; border-top: 1px solid var(--line); }
.link-list li { display: grid; gap: 2px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.link-list a { font-weight: 700; font-size: 17px; text-underline-offset: 3px; }
.link-list span { color: var(--muted); font-size: 15px; }

/* ---------- leaderboards */
.filters { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; margin-top: 18px; }
.filters .field label { font-size: 14px; }
.filters select { min-width: 220px; }
#board-table :is(th, td):first-child { width: 4.5rem; }
#board-table :is(th, td):nth-child(n+3) { text-align: right; }
#board-table tbody td:first-child { font-weight: 700; }
#board-rule { margin-top: 12px; font-size: 14px; }
@media (max-width: 480px) {
  table.data th, table.data td { padding: 10px 6px; }
  table.data thead th { font-size: 12px; }
  #board-table :is(th, td):first-child { width: 2.75rem; }
  .filters select { min-width: 0; }
}
