/* ---------- Card-catalog palette ----------
 * Layout: a ledger header over a working surface. In "File it" the drawers open
 * left→right as layers descend (Miller columns); in "Write-in" the tree reads
 * like a government form with ruled blanks under printed codes. */
:root {
  --bg: #eceff1;          /* cool card stock */
  --panel: #fbfcfc;
  --panel-2: #f3f5f6;
  --rule: #d4dadf;
  --rule-strong: #a9b3bc;
  --ink: #1b2430;
  --ink-soft: #5a6472;
  --accent: #1f4f9a;      /* federal-blue ink */
  --accent-ink: #ffffff;
  --accent-soft: #dfe7f3;
  --shadow: 0 10px 30px rgba(27, 36, 48, 0.14);
  --solved-0: #3f8a54;
  --solved-1: #b8901a;
  --solved-2: #cc7029;
  --missed: #b3402f;
  --tile-l: 95%;          /* map tiles: light tint per major group's hue */
  --tile-c: 0.035;
  --tile-edge-l: 64%;
  --tile-edge-c: 0.12;
  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-body: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-code: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121820;
    --panel: #1a222c;
    --panel-2: #202a35;
    --rule: #2f3a47;
    --rule-strong: #4c5a69;
    --ink: #e4e9ef;
    --ink-soft: #9aa6b4;
    --accent: #84a9ef;
    --accent-ink: #0f1722;
    --accent-soft: #24324a;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --solved-0: #5aae70;
    --solved-1: #d4ac35;
    --solved-2: #de8a45;
    --missed: #e06a57;
    --tile-l: 27%;
    --tile-c: 0.03;
    --tile-edge-l: 72%;
    --tile-edge-c: 0.11;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121820;
  --panel: #1a222c;
  --panel-2: #202a35;
  --rule: #2f3a47;
  --rule-strong: #4c5a69;
  --ink: #e4e9ef;
  --ink-soft: #9aa6b4;
  --accent: #84a9ef;
  --accent-ink: #0f1722;
  --accent-soft: #24324a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --solved-0: #5aae70;
  --solved-1: #d4ac35;
  --solved-2: #de8a45;
  --missed: #e06a57;
  --tile-l: 27%;
  --tile-c: 0.03;
  --tile-edge-l: 72%;
  --tile-edge-c: 0.11;
  color-scheme: dark;
}

/* Derived: tinted grounds for answer states and the layer ramp, so neither theme
 * block has to repeat them. Layer 0 is the darkest ink; deeper layers fade. */
:root {
  --solved-0-bg: color-mix(in srgb, var(--solved-0) 16%, var(--panel));
  --solved-1-bg: color-mix(in srgb, var(--solved-1) 18%, var(--panel));
  --solved-2-bg: color-mix(in srgb, var(--solved-2) 18%, var(--panel));
  --missed-bg: color-mix(in srgb, var(--missed) 15%, var(--panel));
  --lvl-0: var(--accent);
  --lvl-1: color-mix(in srgb, var(--accent) 82%, var(--panel));
  --lvl-2: color-mix(in srgb, var(--accent) 66%, var(--panel));
  --lvl-3: color-mix(in srgb, var(--accent) 50%, var(--panel));
  --lvl-4: color-mix(in srgb, var(--accent) 36%, var(--panel));
  --lvl-5: color-mix(in srgb, var(--accent) 24%, var(--panel));
}

/* ---------- Frame ---------- */
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
}
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
main > section { flex: 1; min-height: 0; overflow: auto; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.code, code { font-family: var(--font-code); font-size: 0.82em; letter-spacing: 0; }

body > header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
  position: relative;
  z-index: 5;
}
.masthead { display: flex; align-items: baseline; gap: 0.9rem; min-width: 0; }
.masthead h1 { font-size: 1.35rem; letter-spacing: -0.01em; }
.app-tagline { color: var(--ink-soft); font-size: 0.88rem; }
.linklike { background: none; border: 0; padding: 0; text-align: left; }

body:not([data-view^="play"]) .play-hud { display: none; }
body[data-view^="play"] .app-tagline { display: none; }
.play-hud { display: flex; align-items: center; gap: 1rem; flex: 1; flex-wrap: wrap; min-width: 0; }
.hud-quiz { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
#quiz-title { font-weight: 600; font-size: 0.9rem; }
#quiz-subtitle { color: var(--ink-soft); font-size: 0.78rem; }
.prompt, #btn-wi-advance { display: none !important; }
body[data-view="play-writein"] .prompt--writein,
body[data-view="play-place"] .prompt--place,
body[data-view="play-race"] .prompt--race { display: flex !important; }
body[data-view="play-writein"] #btn-wi-advance { display: inline-block !important; }

.prompt {
  flex: 1;
  min-width: min(100%, 18rem);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.prompt .lead {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}
.prompt--place strong, .prompt--race strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.15;
}
.tries { font-size: 0.8rem; color: var(--missed); font-weight: 600; }
.race-from { font-size: 0.8rem; color: var(--ink-soft); }
.wi-entry { display: flex; flex-direction: column; flex: 1; min-width: min(100%, 16rem); gap: 0.15rem; }
#wi-input {
  font: 500 1.05rem var(--font-body);
  padding: 0.45rem 0.7rem;
  border: 1.5px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
}
#wi-input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.feedback { font-size: 0.8rem; color: var(--ink-soft); min-height: 1.2em; }
.feedback.is-good { color: var(--solved-0); font-weight: 600; }
.feedback.is-bad { color: var(--missed); }

.stats { display: flex; gap: 1.1rem; }
.stat { display: flex; flex-direction: column; line-height: 1.15; }
.stat .label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.stat .value { font-weight: 700; font-variant-numeric: tabular-nums; }

.primary-btn, .ghost-btn {
  border-radius: 6px;
  padding: 0.5rem 0.95rem;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.primary-btn { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
.primary-btn:hover { filter: brightness(1.08); }
.ghost-btn { background: transparent; border: 1px solid var(--rule-strong); }
.ghost-btn:hover { background: var(--panel-2); }

#error-bar { background: var(--missed-bg); color: var(--missed); padding: 0.6rem 1rem; font-weight: 600; }

/* ---------- Home ---------- */
#view-home { padding: 2rem 1rem 3rem; }
#view-home > * { max-width: 72rem; margin-inline: auto; }
.tax-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.tax-tab {
  border: 1px solid var(--rule-strong);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.tax-tab span { font-weight: 400; color: var(--ink-soft); margin-left: 0.35rem; font-size: 0.8rem; }
.tax-tab:hover { border-color: var(--accent); }
.tax-tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tax-tab[aria-pressed="true"] span { color: inherit; opacity: 0.8; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 2.5rem;
  align-items: center;
}
.eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.6rem;
}
.hero h2 { font-size: clamp(1.9rem, 3.6vw, 2.7rem); line-height: 1.08; letter-spacing: -0.015em; margin-bottom: 0.9rem; }
.hero-copy p:not(.eyebrow) { color: var(--ink-soft); max-width: 34rem; font-size: 1.02rem; }

/* The ladder: each layer as a drawer label, indented by depth, with one real path traced through it. */
.ladder {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.1rem 1.2rem 1rem;
  display: grid;
  gap: 0.35rem;
}
.ladder figcaption { font-size: 0.78rem; color: var(--ink-soft); margin-top: 0.4rem; }
.rung {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr);
  gap: 0.7rem;
  align-items: baseline;
  padding-left: calc(var(--depth) * 0.85rem);
}
.rung-count {
  font: 600 1.05rem var(--font-display);
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.rung-body { border-left: 3px solid var(--lvl); padding: 0.1rem 0 0.15rem 0.6rem; min-width: 0; }
.rung-name { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); font-weight: 600; }
.rung-eg { font-size: 0.88rem; line-height: 1.3; overflow-wrap: anywhere; }
.rung-eg .code { color: var(--ink-soft); margin-right: 0.35rem; }

.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 1.25rem;
  margin-top: 2.5rem;
}
.mode-card {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
}
.mode-card h3 { font-size: 1.4rem; }
.mode-card > p { color: var(--ink-soft); font-size: 0.93rem; }
.mode-art { height: 5.2rem; display: flex; flex-direction: column; justify-content: center; gap: 0.35rem; }
.art-blank { display: flex; align-items: baseline; gap: 0.6rem; font-size: 0.82rem; }
.art-blank i { font: normal 0.72rem var(--font-code); color: var(--ink-soft); width: 4.2rem; }
.art-blank b { font-weight: 600; color: var(--solved-0); }
.art-blank--empty b { width: 11rem; border-bottom: 1.5px solid var(--rule-strong); height: 0.9rem; }
.mode-art--cols { flex-direction: row; justify-content: flex-start; gap: 0.4rem; align-items: stretch; }
.art-col {
  width: 4.4rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--panel-2);
}
.art-col span { height: 0.5rem; border-radius: 2px; background: var(--rule); }
.art-col span.on { background: var(--solved-0); }
.art-col span.x { background: var(--missed); opacity: 0.6; }

.preset-list { display: grid; gap: 0.45rem; margin-top: 0.3rem; }
.preset {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 0.8rem;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.6rem 0.8rem;
}
.preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset b { font-weight: 600; }
.preset span { grid-column: 1; color: var(--ink-soft); font-size: 0.82rem; line-height: 1.35; }
.preset em { grid-row: 1 / span 2; grid-column: 2; align-self: center; font: normal 0.72rem var(--font-code); color: var(--ink-soft); }

.home-foot { display: flex; align-items: center; gap: 1.2rem; margin-top: 1.8rem; flex-wrap: wrap; }
.source { color: var(--ink-soft); font-size: 0.78rem; max-width: 46rem; }
.source a { color: inherit; }

/* ---------- Builder ---------- */
#view-builder { padding: 2rem 1rem 3rem; }
.builder { max-width: 40rem; margin-inline: auto; display: grid; gap: 1.1rem; }
.builder h2 { font-size: 1.8rem; }
.builder fieldset {
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--panel);
  padding: 0.9rem 1rem 1rem;
  display: grid;
  gap: 0.7rem;
  min-width: 0;
}
.builder legend { font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); padding: 0 0.3rem; }
.field { display: grid; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.field--short { max-width: 10rem; }
.field select {
  font: 400 0.95rem var(--font-body);
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
.checks { display: grid; gap: 0.4rem; }
.checks label, .check-inline { display: flex; gap: 0.55rem; align-items: baseline; font-size: 0.92rem; }
.checks em, .hint-text { font-style: normal; color: var(--ink-soft); font-size: 0.82rem; }
.checks label.is-disabled { color: var(--ink-soft); opacity: 0.55; }
.segmented { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 7px; overflow: hidden; width: fit-content; }
.segmented label { padding: 0.45rem 1rem; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.builder-summary { color: var(--ink-soft); font-size: 0.88rem; }
.builder-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ---------- Write-in board ---------- */
#view-writein { padding: 1.2rem 1rem 4rem; }
.wi-board { max-width: 92rem; margin-inline: auto; }
.wi-round-note { color: var(--ink-soft); font-size: 0.85rem; margin-bottom: 0.9rem; }

/* d1 sections stack; their children flow into newspaper columns. */
.wi-node.d1 { margin-bottom: 1.6rem; }
.wi-node.d1 > .wi-head {
  font: 600 1.2rem/1.25 var(--font-display);
  border-bottom: 2px solid var(--lvl);
  padding-bottom: 0.3rem;
  margin-bottom: 0.7rem;
}
.wi-node.d1 > .wi-kids { columns: 19rem; column-gap: 1.6rem; }
.wi-node.d2 { break-inside: avoid-column; margin-bottom: 1rem; }
.wi-node.d2 > .wi-head { font-weight: 700; font-size: 0.95rem; break-after: avoid; }
.wi-node.d3, .wi-node.d4, .wi-node.d5, .wi-node.d6 { margin-left: 0.25rem; padding-left: 0.65rem; border-left: 2px solid var(--lvl); }
.wi-node.d3 > .wi-head { font-weight: 600; font-size: 0.88rem; margin-top: 0.35rem; }
.wi-node.d4 > .wi-head, .wi-node.d5 > .wi-head { font-size: 0.85rem; margin-top: 0.15rem; }
.wi-kids.flat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 0.6rem 1.6rem; }
.wi-kids.flat-grid > .wi-node { margin: 0; }

.wi-head { display: flex; align-items: baseline; gap: 0.5rem; line-height: 1.3; padding: 0.12rem 0; min-width: 0; }
.wi-head .code { color: var(--ink-soft); flex: none; min-width: 4.6rem; }
.wi-head .t { min-width: 0; overflow-wrap: anywhere; }
.mark { display: inline-block; width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; align-self: center; }

.slot { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.18rem 0.3rem; margin-inline: -0.3rem; border-radius: 4px; min-width: 0; }
.slot .code { color: var(--ink-soft); flex: none; min-width: 4.6rem; }
.slot .fill { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.slot.is-blank .fill { border-bottom: 1.5px solid var(--rule-strong); min-height: 1.2em; }
.slot .hint-btn {
  flex: none;
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 50%;
  width: 1.35rem;
  height: 1.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1;
  align-self: center;
}
.slot .hint-btn:hover { border-color: var(--accent); color: var(--accent); }
.slot .hint { display: block; font-size: 0.78rem; color: var(--ink-soft); line-height: 1.35; padding-top: 0.15rem; }
.slot.is-blank.is-hinted .fill { border-bottom-color: var(--solved-1); }
.slot.is-named-0 { background: var(--solved-0-bg); }
.slot.is-named-0 .fill { color: var(--solved-0); font-weight: 600; }
.slot.is-named-1 { background: var(--solved-1-bg); }
.slot.is-named-1 .fill { color: var(--ink); font-weight: 600; }
.slot.is-missed { background: var(--missed-bg); }
.slot.is-missed .fill { color: var(--missed); }
.slot.is-free .fill { color: var(--ink-soft); font-style: italic; }
.slot.is-free .code::after { content: ' ·'; }
.slot.flash { animation: flash 0.9s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--solved-0); } to { box-shadow: 0 0 0 3px transparent; } }

.mark.r-0 { background: var(--solved-0); }
.mark.r-1 { background: var(--solved-1); }
.mark.r-missed { background: var(--missed); }
.mark.r-free { background: var(--rule-strong); }

.wi-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 1rem; }
.wi-legend span { display: inline-flex; gap: 0.35rem; align-items: center; }

/* ---------- File-it board (Miller columns) ---------- */
#view-place, #view-explore { overflow: hidden; display: flex; flex-direction: column; }
.pi-board {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  align-items: stretch;
}
.pi-col, .pi-result {
  flex: 0 0 clamp(15rem, 21vw, 19.5rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 9px;
  scroll-snap-align: start;
  animation: open 0.22s ease-out;
}
@keyframes open { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
.pi-col-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem 0.45rem;
  border-bottom: 1px solid var(--rule);
  border-top: 4px solid var(--lvl);
  border-radius: 9px 9px 0 0;
}
.pi-col-head .lvl { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--ink-soft); }
.pi-col-head .count { font: 0.72rem var(--font-code); color: var(--ink-soft); }
.pi-list { list-style: none; padding: 0.35rem; margin: 0; overflow-y: auto; min-height: 0; display: grid; gap: 0.15rem; align-content: start; }
.pi-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 0.5rem;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 0.42rem 0.55rem;
  line-height: 1.28;
  font-size: 0.88rem;
}
.pi-item .code { grid-column: 1; color: var(--ink-soft); font-size: 0.7rem; }
.pi-item .t { grid-column: 1; overflow-wrap: anywhere; }
.pi-item .n { grid-row: 1 / span 2; grid-column: 2; align-self: center; font: 0.7rem var(--font-code); color: var(--ink-soft); }
.pi-col.is-active .pi-item:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.pi-item:disabled { cursor: default; }
.pi-col:not(.is-active) .pi-item { color: var(--ink-soft); }
.pi-item.is-wrong { color: var(--ink-soft); }
.pi-item.is-wrong .t { text-decoration: line-through; text-decoration-color: var(--missed); }
.pi-item.is-wrong .code::before { content: '✕ '; color: var(--missed); font-weight: 700; }
.pi-item.is-chosen { color: var(--ink) !important; font-weight: 600; }
.pi-item.r-0 { background: var(--solved-0-bg); border-color: var(--solved-0); }
.pi-item.r-1 { background: var(--solved-1-bg); border-color: var(--solved-1); }
.pi-item.r-2 { background: var(--solved-2-bg); border-color: var(--solved-2); }
.pi-item.r-3 { background: var(--missed-bg); border-color: var(--missed); }
.pi-item.r-auto { background: var(--panel-2); border-color: var(--rule-strong); }
.pi-item.is-reveal { background: var(--missed-bg); border-color: var(--missed); color: var(--ink) !important; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--missed) 35%, transparent); } }
.pi-item.is-flash { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.pi-stop { border-style: dashed; border-color: var(--rule-strong); margin-bottom: 0.25rem; }
.pi-stop .t { font-style: italic; }
.peek { font-size: 0.75rem; color: var(--ink-soft); padding: 0.05rem 0.55rem 0.35rem 1.4rem; line-height: 1.35; }
.peek b { font-weight: 600; color: var(--ink); }
.auto-note { font-size: 0.72rem; color: var(--ink-soft); padding: 0.1rem 0.6rem 0.4rem; }

/* Layers still to come: empty drawers, so the board shows how deep the term goes. */
.pi-ghost {
  flex: 0 0 clamp(9rem, 12vw, 11rem);
  border: 1.5px dashed var(--rule);
  border-radius: 9px;
  padding: 0.55rem 0.8rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--ink-soft);
  opacity: 0.7;
}
.pi-result { flex-basis: clamp(17rem, 30vw, 25rem); padding: 1rem 1.1rem; gap: 0.7rem; overflow-y: auto; border-color: var(--rule-strong); }
.pi-result .verdict { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.pi-result .verdict.r-0 { color: var(--solved-0); }
.pi-result .verdict.r-1, .pi-result .verdict.r-2 { color: var(--solved-2); }
.pi-result .verdict.r-3 { color: var(--missed); }
.pi-result h3 { font-size: 1.3rem; line-height: 1.2; }
.pi-result h3 .code { display: block; font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; margin-bottom: 0.15rem; }
.pi-result .is-a { font-size: 0.86rem; color: var(--ink-soft); }
.pi-result .def { font-size: 0.86rem; line-height: 1.45; }
.pi-result .also { font-size: 0.8rem; color: var(--ink-soft); }
.pi-result .also b { color: var(--ink); font-weight: 600; }
.trail { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.trail span { font: 0.68rem var(--font-code); padding: 0.12rem 0.4rem; border-radius: 4px; border: 1px solid var(--rule); }
.trail .r-0 { background: var(--solved-0-bg); border-color: var(--solved-0); }
.trail .r-1 { background: var(--solved-1-bg); border-color: var(--solved-1); }
.trail .r-2 { background: var(--solved-2-bg); border-color: var(--solved-2); }
.trail .r-3 { background: var(--missed-bg); border-color: var(--missed); }
.trail .r-auto { background: var(--panel-2); }
.pi-result .primary-btn { align-self: flex-start; margin-top: 0.3rem; }
.kbd { font: 0.7rem var(--font-code); color: var(--ink-soft); margin-left: 0.4rem; }

/* ---------- Explore ---------- */
.hero-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.1rem; }
.ex-bar { display: flex; gap: 0.6rem 1.4rem; flex-wrap: wrap; align-items: baseline; padding: 0.8rem 1rem 0; color: var(--ink-soft); font-size: 0.85rem; }
.ex-bar .check-inline { font-size: 0.85rem; }
.pi-item.is-open { background: var(--accent-soft); border-color: var(--accent); color: var(--ink) !important; font-weight: 600; }
.ex-col.has-open .pi-item:not(.is-open) { color: var(--ink-soft); }
.ex-card .ex-level { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--accent); }
.ex-card .also { line-height: 1.5; }
.trail-link { font: 0.68rem var(--font-code); padding: 0.12rem 0.4rem; border-radius: 4px; border: 1px solid var(--rule); background: var(--panel-2); }
.trail-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Map board (Map view + Race) ---------- */
#view-map, #view-race { padding: 0.8rem 1rem 3rem; }
.map-bar { display: flex; gap: 0.5rem 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.8rem; }
#map-find {
  font: 500 0.95rem var(--font-body);
  padding: 0.45rem 0.7rem;
  border: 1.5px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  width: min(100%, 24rem);
}
#map-find:focus { outline: none; border-color: var(--accent); }
#map-found { font-size: 0.85rem; font-weight: 600; color: var(--accent); }
.map-keys { font-size: 0.78rem; color: var(--ink-soft); }
.race-keys { margin-bottom: 0.8rem; }

.map-wrap { position: relative; }
.map-board { display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: 0.6rem; align-items: start; }
.map-col { display: grid; gap: 0.6rem; align-content: start; min-width: 0; }
.tile {
  background: oklch(var(--tile-l) var(--tile-c) var(--h));
  border-top: 4px solid oklch(var(--tile-edge-l) var(--tile-edge-c) var(--h));
  border-radius: 7px;
  padding: 0.35rem 0.3rem 0.3rem;
}
.tile-head { font: 600 0.92rem/1.18 var(--font-display); padding: 0 0.3rem 0.2rem; display: flex; gap: 0.4rem; align-items: baseline; }
.tile-head .code { color: var(--ink-soft); font-size: 0.68rem; font-weight: 400; }
.tile-rows { list-style: none; padding: 0; margin: 0; display: grid; gap: 1px; }
.mrow, .brow {
  width: 100%;
  text-align: left;
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  font-size: 0.76rem;
  line-height: 1.22;
}
.mrow:hover { background: color-mix(in srgb, var(--panel) 55%, transparent); }
.mrow.is-cursor, .brow.is-cursor { border-color: var(--ink); background: var(--panel); font-weight: 600; }
.map-board.is-searching .mrow:not(.has-hits) { opacity: 0.35; }
.mrow.has-hits { font-weight: 600; }
.mrow.has-hits::after { content: attr(data-hits); float: right; font: 600 0.68rem var(--font-code); color: var(--accent); }

.map-pop {
  position: absolute;
  z-index: 4;
  width: min(22rem, 100%);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-top: 4px solid oklch(var(--tile-edge-l) var(--tile-edge-c) var(--h));
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
}
.pop-head { display: grid; gap: 0.1rem; padding: 0.1rem 0.35rem 0.45rem; border-bottom: 1px solid var(--rule); margin-bottom: 0.3rem; }
.pop-major { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--ink-soft); }
.pop-title { font: 600 1rem/1.25 var(--font-display); }
.pop-title .code { font-weight: 400; color: var(--ink-soft); }
.pop-rows { list-style: none; padding: 0; margin: 0; display: grid; gap: 1px; }
.brow { font-size: 0.85rem; padding: 0.3rem 0.45rem; display: flex; justify-content: space-between; gap: 0.5rem; }
.brow:hover { background: var(--panel-2); }
.brow .n { font: 0.68rem var(--font-code); color: var(--ink-soft); align-self: center; }
.brow.is-hit { background: var(--accent-soft); }
.brow.is-start::before { content: 'start'; font: 600 0.62rem var(--font-code); text-transform: uppercase; color: var(--ink-soft); order: 2; align-self: center; }
.brow.is-found { background: var(--solved-0-bg); border-color: var(--solved-0); }
.brow.is-flash { animation: shake 0.3s; border-color: var(--missed); }
.pop-detail { padding: 0.25rem 0.5rem 0.5rem 0.9rem; font-size: 0.78rem; color: var(--ink-soft); display: grid; gap: 0.35rem; }
.pop-occ { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.15rem; color: var(--ink); }
.pop-terms { line-height: 1.4; }
.pop-terms b { color: var(--ink); }

.race-card {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 10;
  width: min(30rem, calc(100% - 2rem));
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-top: 4px solid oklch(var(--tile-edge-l) var(--tile-edge-c) var(--h));
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1.1rem 1rem;
  display: grid;
  gap: 0.35rem;
}
.race-verdict { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--solved-0); }
.race-score { font: 600 2.2rem/1 var(--font-display); font-variant-numeric: tabular-nums; }
.race-parts { font-size: 0.85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.race-path { font-size: 0.85rem; line-height: 1.4; }
.race-path .code { color: var(--ink-soft); }
.race-card .primary-btn { justify-self: start; margin-top: 0.3rem; }

.mode-art--map { flex-direction: row; justify-content: flex-start; align-items: stretch; gap: 0.35rem; }
.art-tile {
  width: 4rem;
  border-radius: 5px;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: oklch(var(--tile-l) var(--tile-c) var(--h));
  border-top: 3px solid oklch(var(--tile-edge-l) var(--tile-edge-c) var(--h));
}
.art-tile span { height: 0.45rem; border-radius: 2px; background: color-mix(in srgb, var(--ink) 14%, transparent); }
.art-tile span.on { background: var(--ink); opacity: 0.55; }
.art-tile span.goal { background: var(--solved-0); opacity: 1; }

/* ---------- End panel ---------- */
#end-panel {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 35%, transparent);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 20;
}
.end-card {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.6rem 1.3rem;
  width: min(34rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: grid;
  gap: 0.8rem;
}
.end-card h2 { font-size: 1.4rem; }
.big-score { font: 600 3.2rem/1 var(--font-display); color: var(--accent); font-variant-numeric: tabular-nums; }
.end-meta { color: var(--ink-soft); font-size: 0.88rem; }
.end-card h3 { font-size: 1rem; margin-bottom: 0.4rem; }
#missed-list { list-style: none; padding: 0; display: grid; gap: 0.35rem; font-size: 0.85rem; }
#missed-list li { line-height: 1.35; }
#missed-list .code { color: var(--ink-soft); }
.level-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.level-table td { padding: 0.3rem 0; border-bottom: 1px solid var(--rule); }
.level-table td:last-child { text-align: right; color: var(--ink-soft); }
.end-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.3rem; }

/* ---------- Narrow screens ---------- */
@media (max-width: 860px) {
  .hero, .modes { grid-template-columns: minmax(0, 1fr); }
  .hero { gap: 1.5rem; }
}
@media (max-width: 640px) {
  body > header { gap: 0.6rem; }
  body[data-view^="play"] .masthead, body[data-view^="play"] .hud-quiz { display: none; }
  .play-hud { gap: 0.5rem 0.8rem; }
  .prompt { flex-basis: 100%; }
  .prompt--place strong { font-size: 1.2rem; }
  .stats { flex: 1; }
  .pi-ghost { display: none; }
  .app-tagline { display: none; }
  .stats { gap: 0.8rem; }
  .pi-col, .pi-result { flex-basis: calc(100vw - 3rem); }
  .wi-head .code, .slot .code { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
