/* Layout concept: a crossroads. Four category quadrants meet at a central disc that counts lives lost;
   players pick any road, clear its board with instant checking, and return to the crossroads. */
:root {
  --paper: #EEF1F6;
  --surface: #FFFFFF;
  --ink: #121729;
  --muted: #586079;
  --line: #CDD3E0;
  --geo: #127A5F;
  --word: #5B3FC4;
  --pop: #C93B24;
  --sci: #9A6700;
  --on-cat: #FFFFFF;
  --good: #11804A;
  --good-bg: #E3F4EA;
  --bad: #C42A2A;
  --bad-bg: #FBE6E6;
  --miss: #A35F00;
  --miss-bg: #FFF1D6;
  --shadow: 0 1px 0 rgba(18, 23, 41, 0.06), 0 6px 18px -10px rgba(18, 23, 41, 0.25);
  --display: "Big Shoulders Display", "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --flag: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0E1220; --surface: #161B2E; --ink: #E8EBF5; --muted: #98A0B8; --line: #283050;
    --geo: #2DBE93; --word: #9B85F5; --pop: #FF6A4F; --sci: #E8B23A; --on-cat: #0E1220;
    --good: #3DD68C; --good-bg: #123325; --bad: #FF6B6B; --bad-bg: #3A1A1F; --miss: #F2B34A; --miss-bg: #3A2C12;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 22px -12px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0E1220; --surface: #161B2E; --ink: #E8EBF5; --muted: #98A0B8; --line: #283050;
  --geo: #2DBE93; --word: #9B85F5; --pop: #FF6A4F; --sci: #E8B23A; --on-cat: #0E1220;
  --good: #3DD68C; --good-bg: #123325; --bad: #FF6B6B; --bad-bg: #3A1A1F; --miss: #F2B34A; --miss-bg: #3A2C12;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 22px -12px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { background: var(--paper); color: var(--ink); }
body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--paper);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--word); outline-offset: 2px; }

.cat-geo { --c: var(--geo); }
.cat-word { --c: var(--word); }
.cat-pop { --c: var(--pop); }
.cat-sci { --c: var(--sci); }

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 48px;
}

/* ---------- top bar (inside a board) ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px;
  display: flex; align-items: center; gap: 16px;
}
.back {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-weight: 700; font-size: 14px;
}
.pips { flex: 1; display: flex; gap: 6px; justify-content: center; min-width: 0; }
.pip { width: 34px; height: 8px; border-radius: 2px; background: color-mix(in srgb, var(--c) 22%, var(--line)); }
.pip.done { background: var(--c); }
.pip.now { box-shadow: inset 0 0 0 2px var(--c); }
.lives { white-space: nowrap; font-size: 14px; color: var(--muted); }
.lives strong { font-family: var(--display); font-weight: 900; font-size: 28px; color: var(--ink); font-variant-numeric: tabular-nums; vertical-align: -3px; }

/* ---------- hub ---------- */
.intro { display: grid; gap: 10px; margin-block: 12px 24px; }
.intro h1 {
  font-family: var(--display); font-weight: 900;
  font-size: clamp(56px, 13vw, 132px); line-height: 0.95; letter-spacing: -0.01em;
  margin: 0; padding-bottom: 0.04em; text-wrap: balance;
}
.intro p { margin: 0; color: var(--muted); font-size: 18px; max-width: 52ch; }

.crossroads {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  border-radius: 18px; overflow: hidden;
}
.quad {
  border: 0; text-align: left; font: inherit;
  background: var(--c); color: var(--on-cat);
  padding: clamp(16px, 3.4vw, 32px);
  min-height: clamp(170px, 26vw, 250px);
  display: flex; flex-direction: column; gap: 6px;
  transition: filter 140ms ease;
}
.quad:hover:not(:disabled) { filter: brightness(1.07); }
.quad:focus-visible { outline: 4px solid var(--ink); outline-offset: -8px; }
.quad:nth-child(2), .quad:nth-child(4) { text-align: right; align-items: flex-end; }
.quad:nth-child(3), .quad:nth-child(4) { justify-content: flex-end; }
.quad .num { font-family: var(--display); font-weight: 900; font-size: clamp(34px, 6vw, 56px); line-height: 0.9; opacity: 0.9; }
.quad .qname { font-family: var(--display); font-weight: 800; font-size: clamp(22px, 3.6vw, 34px); line-height: 1; text-wrap: balance; }
.quad .qtypes { font-size: clamp(12px, 1.6vw, 15px); line-height: 1.35; opacity: 0.92; max-width: 32ch; }
.quad .qstatus { font-weight: 700; font-size: clamp(13px, 1.7vw, 16px); }
.quad.done {
  cursor: default;
  background:
    repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 82%, var(--paper)) 0 10px, color-mix(in srgb, var(--c) 70%, var(--paper)) 10px 20px);
}
.hub-disc {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: clamp(104px, 17vw, 156px); aspect-ratio: 1; max-width: 100%;
  border-radius: 50%; border: 6px solid var(--paper);
  background: var(--ink); color: var(--paper);
  display: grid; place-content: center; text-align: center; box-shadow: var(--shadow);
  pointer-events: none;
}
.hub-disc .big { font-family: var(--display); font-weight: 900; font-size: clamp(38px, 6.5vw, 64px); line-height: 0.9; font-variant-numeric: tabular-nums; }
.hub-disc .small { font-size: clamp(11px, 1.4vw, 14px); opacity: 0.85; }

.setup { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; margin-top: 16px; }
.continents { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 20px; }
.cont-label { font-weight: 700; font-size: 15px; }
.cont-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cont {
  border: 2px solid var(--geo); border-radius: 999px; padding: 6px 14px;
  background: var(--geo); color: var(--on-cat); font-weight: 700; font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
}
.cont[aria-pressed="false"] {
  background: transparent; color: var(--muted); border-color: var(--line);
  text-decoration: line-through; text-decoration-thickness: 1.5px;
}
.cont:hover { border-color: var(--ink); }
.best { margin-left: auto; color: var(--muted); font-size: 14px; }
.best strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.hub-note { color: var(--muted); font-size: 14px; margin: 10px 0 0; }

/* ---------- board ---------- */
.board-head { display: grid; gap: 4px; margin-block: 8px 18px; }
.board-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: baseline; font-size: 14px; color: var(--muted); }
.board-meta .catname { color: var(--c); font-weight: 700; font-size: 15px; }
.board-head h2 {
  font-family: var(--display); font-weight: 800; font-size: clamp(30px, 5vw, 44px);
  line-height: 1; margin: 2px 0 4px; text-wrap: balance;
}
.board-head .prompt { font-size: 19px; margin: 0; max-width: 62ch; }
.board-head .hint { color: var(--muted); font-size: 15px; margin: 0; }

/* multi-select tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile {
  position: relative; text-align: left;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 14px 14px 12px; min-height: 64px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  transition: border-color 120ms ease, transform 120ms ease;
}
.tile:hover:not(:disabled) { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); }
.tile .lab { font-weight: 700; font-size: 16px; line-height: 1.25; }
.tile .sub { font-size: 13px; color: var(--muted); }
.tile.flagtile { align-items: center; text-align: center; min-height: 120px; }
.tile .flag { font-family: var(--flag); font-size: 64px; line-height: 1; }
.tile[aria-pressed="true"] { border-color: var(--c); box-shadow: inset 0 0 0 2px var(--c); }
.tile[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 8px; right: 8px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--c);
}
.tile.r-hit { border-color: var(--good); background: var(--good-bg); box-shadow: none; }
.tile.r-wrong { border-color: var(--bad); background: var(--bad-bg); box-shadow: none; }
.tile.r-miss { border-color: var(--miss); background: var(--miss-bg); border-style: dashed; box-shadow: none; }
.tile.r-hit::after, .tile.r-wrong::after, .tile.r-miss::after {
  content: attr(data-verdict); width: auto; height: auto; background: none; border-radius: 0;
  font-size: 12px; font-weight: 700; top: 6px; right: 8px;
}
.tile.r-hit::after { color: var(--good); }
.tile.r-wrong::after { color: var(--bad); }
.tile.r-miss::after { color: var(--miss); }

/* matching */
.match { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.match.graded { grid-template-columns: minmax(0, 1fr); }
.match.graded .clues { grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
.clues { display: grid; gap: 8px; }
.clue {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 10px 10px 14px;
}
.clue-parts { display: grid; gap: 6px; min-width: 0; }
.part { display: grid; gap: 1px; min-width: 0; }
.part .k { font-size: 12px; color: var(--muted); }
.part .v { font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.part .swatch { width: 100%; max-width: 120px; height: 34px; border-radius: 6px; border: 1px solid var(--line); }
.part img { max-height: 90px; border-radius: 6px; }
.slot {
  min-height: 48px; border-radius: 8px; border: 2px dashed var(--line); background: transparent;
  padding: 8px 10px; text-align: left; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere;
  color: var(--muted);
}
.slot.filled { border-style: solid; border-color: var(--c); color: var(--ink); background: color-mix(in srgb, var(--c) 9%, var(--surface)); }
.slot.active { border-color: var(--c); border-style: solid; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent); }
.slot.r-hit { border: 2px solid var(--good); background: var(--good-bg); color: var(--ink); }
.slot.r-wrong { border: 2px solid var(--bad); background: var(--bad-bg); color: var(--ink); }
.slot .fix { display: block; font-weight: 400; font-size: 13px; color: var(--ink); margin-top: 2px; }
.slot .fix b { color: var(--good); }
.slot .given { text-decoration: line-through; text-decoration-color: var(--bad); }

.tray {
  position: sticky; top: 76px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: grid; gap: 10px;
}
.tray-label { font-size: 13px; color: var(--muted); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--c); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 12px; font-weight: 700; font-size: 14px; line-height: 1.2; text-align: left;
}
.chip.used { border-style: dashed; color: var(--muted); border-color: var(--line); }
.chip[aria-pressed="true"] { background: var(--c); color: var(--on-cat); border-style: solid; border-color: var(--c); }

/* typing */
.puzzles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.puzzle {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: grid; gap: 12px; align-content: start;
}
.puzzle dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; }
.puzzle dt { font-weight: 700; color: var(--c); font-size: 14px; padding-top: 1px; }
.puzzle dd { margin: 0; line-height: 1.4; }
.blanks { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.blank { display: grid; gap: 4px; }
.blank label { font-size: 13px; color: var(--muted); }
.blank input {
  width: 100%; border: 2px solid var(--line); border-radius: 8px; background: var(--paper);
  padding: 9px 10px; font-weight: 700; font-size: 17px; letter-spacing: 0.04em;
}
.blank input:focus { border-color: var(--c); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent); }
.blank.r-hit input { border-color: var(--good); background: var(--good-bg); }
.blank.r-wrong input { border-color: var(--bad); background: var(--bad-bg); }
.blank .ans { font-size: 13px; }
.blank .ans b { color: var(--good); }

/* action bar */
.actions {
  position: sticky; bottom: 0; z-index: 4; margin-top: 22px;
  background: var(--paper); border-top: 1px solid var(--line);
  padding-block: 12px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center;
}
.verdict { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.verdict .pts { font-family: var(--display); font-weight: 900; font-size: 34px; line-height: 1; color: var(--c); font-variant-numeric: tabular-nums; }
.verdict .explain { color: var(--muted); font-size: 15px; min-width: 0; }
.status { color: var(--muted); font-size: 15px; flex: 1; min-width: 0; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 700; font-size: 16px;
  background: var(--ink); color: var(--paper); margin-left: auto;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); margin-left: 0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* summary */
.summary { display: grid; gap: 28px; margin-top: 8px; }
.total { display: grid; gap: 4px; }
.total .big { font-family: var(--display); font-weight: 900; font-size: clamp(72px, 16vw, 150px); line-height: 0.85; font-variant-numeric: tabular-nums; }
.total .big span { color: var(--muted); font-size: 0.45em; }
.total p { margin: 0; color: var(--muted); font-size: 18px; }
.cat-rows { display: grid; gap: 14px; }
.cat-row { display: grid; grid-template-columns: 210px minmax(0, 1fr) 70px; gap: 14px; align-items: center; }
.cat-row .n { font-weight: 700; }
.cat-row .bar { height: 14px; border-radius: 4px; background: var(--line); overflow: hidden; }
.cat-row .bar i { display: block; height: 100%; background: var(--c); }
.cat-row .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.review { display: grid; gap: 6px; }
.review h3 { font-family: var(--display); font-weight: 800; font-size: 26px; margin: 0 0 6px; }
.review-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.review-row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.review-row .t { min-width: 0; }
.review-row .s { font-variant-numeric: tabular-nums; font-weight: 700; }

.foot { margin-top: 40px; color: var(--muted); font-size: 13px; max-width: 70ch; }
.loading { padding: 80px 0; color: var(--muted); }
.error { padding: 40px 0; color: var(--bad); max-width: 60ch; }

/* ---------- instant feedback ---------- */
.actions .note { flex: 1; min-width: 0; color: var(--muted); font-size: 15px; }
.actions .note.ok { color: var(--good); font-weight: 700; }
.actions .note.bad { color: var(--bad); font-weight: 700; }
.board-lives { color: var(--muted); font-size: 14px; white-space: nowrap; }
.done-bar .pts { font-size: 26px; color: var(--c); }
.clue.solved { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.blank-row { display: flex; gap: 6px; }
.blank-row input { flex: 1; min-width: 0; }
.mini {
  border: 0; border-radius: 8px; background: var(--ink); color: var(--paper);
  padding: 0 12px; font-weight: 700; font-size: 14px;
}
.reveal {
  justify-self: start; border: 0; background: none; padding: 2px 0; font-size: 13px;
  color: var(--muted); text-decoration: underline; text-underline-offset: 2px;
}
.reveal.armed { color: var(--bad); font-weight: 700; }
.blank.r-revealed input { border-color: var(--miss); background: var(--miss-bg); }
.blank.r-revealed .ans { color: var(--miss); font-weight: 700; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 320ms ease; }

/* ---------- results ---------- */
.passed {
  background: var(--geo); color: var(--on-cat); border-radius: 18px;
  padding: clamp(20px, 4vw, 36px);
}
.passed .passed-title { font-family: var(--display); font-weight: 900; font-size: clamp(40px, 8vw, 76px); line-height: 0.95; margin: 0 0 6px; }
.passed p { margin: 0; font-size: 18px; }
.cat-rows .cat-row { grid-template-columns: 10px 190px minmax(0, 1fr) auto; }
.cat-row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.cat-row .t { color: var(--muted); min-width: 0; }
.row-buttons { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- narrow screens ---------- */
@media (max-width: 820px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .match { grid-template-columns: minmax(0, 1fr); }
  .tray {
    position: sticky; top: auto; bottom: 74px; order: 2; z-index: 3;
    box-shadow: var(--shadow);
  }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .chip { flex: 0 0 auto; white-space: nowrap; }
  .puzzles { grid-template-columns: minmax(0, 1fr); }
  .cat-rows .cat-row { grid-template-columns: 10px minmax(0, 1fr) auto; }
  .cat-row .t { grid-column: 2 / -1; grid-row: 2; font-size: 14px; }
}
@media (max-width: 520px) {
  .clue { grid-template-columns: minmax(0, 1fr); }
  .quad .qtypes { display: none; }
  .pip { width: 22px; }
  .quad { min-height: 150px; }
  .tile.flagtile { min-height: 100px; }
  .tile .flag { font-size: 52px; }
  .back { padding: 6px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.row-buttons .btn { margin-left: 0; }

/* ---------- flags and rankings ---------- */
.part .flagclue { font-family: var(--flag); font-size: 52px; line-height: 1; }
.rank { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank-slot {
  display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; align-items: center;
  min-height: 50px; padding: 6px 12px 6px 6px; border-radius: var(--radius);
  border: 2px dashed var(--line); background: transparent;
}
.rank-slot.next { border-color: var(--c); border-style: solid; }
.rank-slot.filled { border: 2px solid var(--good); background: var(--good-bg); }
.rank-n { font-family: var(--display); font-weight: 900; font-size: 24px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-slot.filled .rank-n { color: var(--good); }
.rank-body { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.rank-label { font-weight: 700; }
.rank-sub { font-weight: 400; color: var(--muted); }
.rank-val { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; white-space: nowrap; }
.rank-empty { color: var(--muted); font-size: 14px; }
.rank-flag { font-family: var(--flag); font-size: 22px; line-height: 1; }
.rank-pool { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; position: sticky; top: 76px; }
@media (max-width: 820px) {
  .rank { grid-template-columns: minmax(0, 1fr); }
  .rank-pool { order: -1; position: static; }
}

/* ---------- word-puzzle hint toggle ---------- */
.type-wrap { display: grid; gap: 14px; }
.hint-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.hint-toggle { border-color: var(--c); background: var(--c); }
.hint-toggle[aria-pressed="false"] { text-decoration: none; }
.hint-note { color: var(--muted); font-size: 14px; }
