/* How We Got Here - all styles. Design tokens first; see docs/DESIGN.md for the visual language. */

@font-face { font-family: 'Fraunces'; src: url('../fonts/fraunces.woff2') format('woff2'); font-weight: 300 900; font-style: normal; font-display: swap; }
@font-face { font-family: 'Fraunces'; src: url('../fonts/fraunces-italic.woff2') format('woff2'); font-weight: 300 900; font-style: italic; font-display: swap; }
@font-face { font-family: 'Lexend'; src: url('../fonts/lexend.woff2') format('woff2'); font-weight: 300 800; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('../fonts/jetbrains-mono.woff2') format('woff2'); font-weight: 400 800; font-display: swap; }

:root {
  --bg: #08131d;
  --bg-2: #0e1d2b;
  --glass: rgba(10, 21, 32, 0.74);
  --glass-hi: rgba(14, 29, 43, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --line-2: rgba(255, 255, 255, 0.22);
  --text: #eef3f6;
  --muted: #a7b8c6;
  --dim: #6f8496;
  --gold: #f2b84b;
  --gold-2: #ffd98a;
  --gold-ink: #2a1b00;
  --paper: #f7f0e1;
  --paper-2: #efe4cd;
  --paper-ink: #1f2a36;
  --paper-muted: #5f6b76;
  --st-green: #4f9a4a;
  --st-white: #f3efe4;
  --st-yellow: #f2c53d;
  --st-red: #d9443a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Lexend', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter: clamp(12px, 2.2vw, 24px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 16px; -webkit-font-smoothing: antialiased; }
body { overflow: hidden; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--gold-2); outline-offset: 2px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
#scene.pointer { cursor: pointer; }
#labels, #fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
#fade { position: fixed; inset: 0; background: var(--bg); opacity: 0; pointer-events: none; transition: opacity 0.45s ease; z-index: 40; }
#fade.on { opacity: 1; }

/* ---------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.06); color: var(--text);
  border-radius: 999px; padding: 0.7em 1.3em; font-weight: 500; letter-spacing: 0.01em; cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em; min-height: 44px;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.35); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--gold-ink); border-color: transparent; font-weight: 600; box-shadow: 0 6px 24px rgba(242, 184, 75, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
.btn-primary:hover { background: linear-gradient(180deg, #ffe4a6, #f5c060); box-shadow: 0 8px 30px rgba(242, 184, 75, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
.btn-ghost { background: rgba(8, 19, 29, 0.55); }
.btn-lg { font-size: 1.1rem; padding: 0.85em 1.8em; }
.btn-sm { font-size: 0.85rem; padding: 0.45em 1em; min-height: 36px; }
.icon-btn {
  appearance: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass);
  display: inline-grid; place-items: center; cursor: pointer; transition: background 0.2s, transform 0.15s, border-color 0.2s; color: var(--text); padding: 0;
}
.icon-btn:hover { background: var(--glass-hi); border-color: var(--line-2); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; display: block; }
.icon-btn.icon-sm { width: 38px; height: 38px; }
.icon-btn.icon-sm svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed='true'] { border-color: rgba(242, 184, 75, 0.6); color: var(--gold-2); }
.q3 .icon-btn, .q4 .icon-btn, .q5 .icon-btn { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

.corner { position: fixed; top: calc(var(--gutter) + var(--safe-t)); right: var(--gutter); display: flex; gap: 8px; z-index: 30; }

/* ---------- screens */
.screen { position: fixed; inset: 0; z-index: 10; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity 0.5s ease, visibility 0s linear 0.5s; }
.screen.is-active { opacity: 1; visibility: visible; transition: opacity 0.5s ease; }
.screen.is-active > * { pointer-events: auto; }
.eyebrow { margin: 0 0 0.4em; font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-2); font-weight: 500; }
.wordmark { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(2.2rem, 6vw, 3.6rem); letter-spacing: -0.01em; line-height: 1.02; font-variation-settings: 'opsz' 40, 'SOFT' 30; }
.wordmark.big { font-size: clamp(2.6rem, 7.4vw, 5.2rem); }
.title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(1.5rem, 3.2vw, 2.2rem); letter-spacing: -0.005em; }
.display { font-variation-settings: 'opsz' 48; }
.card { background: var(--glass-hi); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.q3 .card, .q4 .card, .q5 .card { background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); }

/* loading */
#screen-loading { background: radial-gradient(1200px 700px at 50% 45%, #10283a 0%, var(--bg) 70%); z-index: 50; display: grid; place-items: center; }
.loading { text-align: center; padding: 24px; width: min(520px, 92vw); }
.loading-mark { width: 92px; height: 92px; margin: 0 auto 18px; display: block; }
.loading-mark .ring { fill: none; stroke: rgba(242, 184, 75, 0.45); stroke-width: 1.5; stroke-dasharray: 4 7; transform-origin: 60px 60px; animation: spin 18s linear infinite; }
.loading-mark .ring-2 { stroke: rgba(255, 255, 255, 0.18); stroke-dasharray: 2 5; animation-direction: reverse; animation-duration: 26s; }
.loading-mark .needle { fill: var(--gold); transform-origin: 60px 60px; animation: seek 3.2s cubic-bezier(.45, 0, .2, 1) infinite; }
.loading-mark .pin { fill: var(--bg); stroke: var(--gold-2); stroke-width: 2; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes seek { 0% { transform: rotate(-30deg); } 35% { transform: rotate(40deg); } 60% { transform: rotate(10deg); } 80% { transform: rotate(24deg); } 100% { transform: rotate(-30deg); } }
.progress { height: 3px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; overflow: hidden; margin: 26px auto 12px; width: 100%; }
.progress span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); border-radius: 3px; transition: width 0.35s ease; box-shadow: 0 0 12px rgba(242, 184, 75, 0.7); }
.loading-status { color: var(--muted); margin: 0; font-size: 0.95rem; min-height: 1.4em; }
.loading-tip { color: var(--dim); margin: 26px 0 0; font-size: 0.85rem; min-height: 2.6em; }
.noscript { color: var(--gold-2); }
.loading-error { color: #ffb4a8; margin-top: 18px; font-size: 0.95rem; }

/* home */
#screen-home { display: grid; align-items: end; justify-items: start; padding: var(--gutter); padding-bottom: calc(var(--gutter) + 6vh + var(--safe-b)); background: linear-gradient(0deg, rgba(8, 19, 29, 0.92) 0%, rgba(8, 19, 29, 0.35) 45%, rgba(8, 19, 29, 0) 70%); }
.home { max-width: 720px; padding-left: clamp(0px, 3vw, 40px); }
.home-lede { font-size: clamp(1.05rem, 1.8vw, 1.3rem); line-height: 1.5; color: #d6e1ea; max-width: 34em; margin: 18px 0 26px; }
.home-foot { color: var(--dim); font-size: 0.85rem; margin: 22px 0 0; }

/* regions */
.regions-head { position: absolute; top: calc(var(--gutter) + var(--safe-t)); left: var(--gutter); display: flex; gap: 16px; align-items: flex-start; }
.region-list { position: absolute; left: var(--gutter); bottom: calc(var(--gutter) + var(--safe-b)); display: flex; gap: 10px; flex-wrap: wrap; max-width: calc(100vw - 2 * var(--gutter)); }
.region-chip { display: flex; align-items: center; gap: 10px; padding: 10px 16px 10px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass-hi); cursor: pointer; transition: transform 0.15s, border-color 0.2s, background 0.2s; min-height: 44px; }
.region-chip:hover, .region-chip.is-hot { border-color: var(--line-2); background: rgba(20, 38, 54, 0.95); transform: translateY(-2px); }
.region-chip .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08); }
.region-chip .nm { font-weight: 600; }
.region-chip .sub { color: var(--muted); font-size: 0.82rem; }
.region-panel { position: absolute; right: var(--gutter); top: calc(var(--gutter) + 64px + var(--safe-t)); width: min(420px, calc(100vw - 2 * var(--gutter))); padding: 22px; border-radius: var(--radius); background: var(--glass-hi); border: 1px solid var(--line); box-shadow: var(--shadow); max-height: calc(100vh - 100px); overflow: auto; animation: panelIn 0.35s cubic-bezier(.2, .8, .2, 1); }
.q3 .region-panel, .q4 .region-panel, .q5 .region-panel { background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
@keyframes panelIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.region-panel .close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; }
.region-blurb { color: #d0dce6; line-height: 1.5; margin: 10px 0 18px; }
.game-cards { display: grid; gap: 10px; }
.game-card { text-align: left; display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); cursor: pointer; transition: border-color 0.2s, background 0.2s, transform 0.15s; width: 100%; }
.game-card:hover:not([aria-disabled='true']) { border-color: rgba(242, 184, 75, 0.6); background: rgba(242, 184, 75, 0.08); transform: translateY(-1px); }
.game-card[aria-disabled='true'] { cursor: default; opacity: 0.6; }
.game-card .gi { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.06); }
.game-card .gi svg { width: 30px; height: 30px; }
.game-card .gn { font-weight: 600; font-size: 1.05rem; }
.game-card .gd { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.game-card .tag { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.game-card .tag.go { background: var(--gold); color: var(--gold-ink); border-color: transparent; font-weight: 700; }
.map-label.region .in { background: none; box-shadow: none; padding: 0; display: block; text-align: center; font-family: var(--font-display); font-weight: 600; font-size: clamp(0.95rem, 1.7vw, 1.4rem); color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.9); letter-spacing: 0.01em; transition: transform 0.3s, opacity 0.3s; }
.map-label.region.is-hot .in { transform: scale(1.12); }
.map-label.region.is-dim .in { opacity: 0.55; }
.map-label.region.is-off .in { opacity: 0; }
.map-label.region .in small { display: block; font-family: var(--font-ui); font-weight: 500; font-size: 0.6em; color: var(--gold-2); letter-spacing: 0.12em; text-transform: uppercase; margin-top: 3px; }
.map-label.inset .in { background: rgba(10, 21, 32, 0.6); color: var(--muted); box-shadow: none; font-weight: 500; font-size: 0.72rem; }

/* intro */
#screen-intro { display: grid; place-items: center; padding: var(--gutter); background: rgba(8, 19, 29, 0.35); }
.intro { width: min(560px, 100%); padding: clamp(20px, 4vw, 34px); max-height: calc(100vh - 2 * var(--gutter)); overflow: auto; }
.intro .title { font-size: clamp(1.8rem, 4.6vw, 2.6rem); margin-bottom: 18px; }
.steps { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.steps li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; line-height: 1.45; color: #dbe5ed; }
.step-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(242, 184, 75, 0.16); color: var(--gold-2); font-weight: 700; font-size: 0.9rem; border: 1px solid rgba(242, 184, 75, 0.4); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 0.9rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend b { color: var(--text); font-weight: 600; }
.sw { width: 16px; height: 16px; border-radius: 5px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.sw-green { background: var(--st-green); } .sw-white { background: var(--st-white); } .sw-yellow { background: var(--st-yellow); } .sw-red { background: var(--st-red); }
.intro-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.intro-note { color: var(--dim); font-size: 0.82rem; margin: 14px 0 0; text-align: right; min-height: 1.2em; }

/* play HUD */
.hud-left { position: absolute; top: calc(var(--gutter) + var(--safe-t)); left: var(--gutter); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.hud-game { padding: 12px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); min-width: 210px; }
.hud-title { margin: 0 0 8px; font-family: var(--font-display); font-weight: 600; font-size: 1rem; letter-spacing: 0.01em; }
.hud-progress { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; height: 8px; }
.hud-progress i { border-radius: 3px; background: rgba(255, 255, 255, 0.12); transition: background 0.4s, transform 0.3s; }
.hud-progress i.first { background: var(--st-white); } .hud-progress i.second, .hud-progress i.third { background: var(--st-yellow); } .hud-progress i.missed { background: var(--st-red); }
.hud-progress i.pop { transform: scaleY(1.8); }
.hud-count { margin: 8px 0 0; font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.prompt { position: absolute; top: calc(var(--gutter) + var(--safe-t)); left: 50%; transform: translateX(-50%); text-align: center; padding: 12px 26px 14px; border-radius: 20px; background: var(--glass); border: 1px solid var(--line); min-width: min(360px, 60vw); max-width: min(560px, calc(100vw - 2 * var(--gutter))); box-shadow: var(--shadow); transition: transform 0.3s, border-color 0.3s; }
.q3 .prompt, .q4 .prompt, .q5 .prompt, .q3 .hud-game, .q4 .hud-game, .q5 .hud-game { backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.prompt.bump { animation: bump 0.45s ease; }
.prompt.shake { animation: shake 0.45s ease; }
@keyframes bump { 30% { transform: translateX(-50%) scale(1.06); } }
@keyframes shake { 20% { transform: translateX(calc(-50% - 7px)); } 40% { transform: translateX(calc(-50% + 6px)); } 60% { transform: translateX(calc(-50% - 4px)); } 80% { transform: translateX(calc(-50% + 2px)); } }
.prompt-verb { margin: 0; font-size: 0.76rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold-2); }
.prompt-name { margin: 2px 0 6px; font-family: var(--font-display); font-weight: 650; font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.05; letter-spacing: -0.01em; font-variation-settings: 'opsz' 48; }
.prompt-name.enter { animation: nameIn 0.55s cubic-bezier(.2, .9, .2, 1.1); }
@keyframes nameIn { from { opacity: 0; transform: translateY(10px) scale(0.92); filter: blur(4px); } }
.prompt-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.tries { display: flex; gap: 6px; }
.tries i { width: 11px; height: 11px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px rgba(242, 184, 75, 0.6); transition: background 0.3s, box-shadow 0.3s, transform 0.3s; }
.tries i.used { background: rgba(255, 255, 255, 0.15); box-shadow: none; transform: scale(0.8); }
.prompt-hint { margin: 8px 0 0; font-size: 0.92rem; line-height: 1.4; color: #ffe7b3; min-height: 0; max-width: 34em; }
.prompt-hint:empty { display: none; }
.prompt-hint::before { content: 'Hint: '; font-weight: 600; color: var(--gold-2); }
.hud-timer { position: absolute; top: calc(var(--gutter) + var(--safe-t) + 4px); right: calc(var(--gutter) + 104px); padding: 9px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-variant-numeric: tabular-nums; font-weight: 500; font-size: 0.95rem; min-width: 64px; text-align: center; }
.hud-timer[hidden] { display: none; }
.map-tools { position: absolute; left: var(--gutter); bottom: calc(var(--gutter) + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.legend-hud { position: absolute; right: var(--gutter); bottom: calc(var(--gutter) + var(--safe-b)); padding: 8px 12px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); font-size: 0.78rem; gap: 6px 12px; }
.toast-zone { position: absolute; left: 50%; top: calc(var(--gutter) + var(--safe-t) + 178px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none !important; }
.toast { padding: 10px 18px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--line); font-weight: 600; font-size: 1.05rem; box-shadow: var(--shadow); animation: toastIn 0.4s cubic-bezier(.2, .9, .2, 1.2), toastOut 0.4s ease forwards; animation-delay: 0s, var(--life, 1.6s); white-space: nowrap; display: flex; gap: 10px; align-items: center; }
.toast.good { border-color: rgba(255, 255, 255, 0.4); background: linear-gradient(180deg, rgba(40, 60, 40, 0.92), rgba(20, 36, 24, 0.92)); }
.toast.gold { border-color: rgba(242, 184, 75, 0.7); color: var(--gold-2); }
.toast.soft { font-weight: 500; color: #e6edf2; }
.toast .pts { font-family: var(--font-display); color: var(--gold-2); font-size: 1.2em; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
.fact-card { position: absolute; left: 50%; bottom: calc(var(--gutter) + var(--safe-b)); transform: translate(-50%, 20px); width: min(560px, calc(100vw - 2 * var(--gutter) - 140px)); padding: 12px 16px; border-radius: 14px; background: var(--glass-hi); border: 1px solid var(--line); opacity: 0; transition: opacity 0.4s, transform 0.4s; pointer-events: none !important; font-size: 0.9rem; line-height: 1.4; color: #dbe5ed; }
.fact-card.show { opacity: 1; transform: translate(-50%, 0); }
.fact-card b { font-family: var(--font-display); font-size: 1.1em; color: #fff; }
.fact-card .meta { color: var(--gold-2); font-size: 0.82rem; margin: 2px 0 6px; }

/* labels pinned to the 3D map: the outer node is positioned by JS (inline transform), the inner pill animates */
.map-label { position: absolute; left: 0; top: 0; pointer-events: none; white-space: nowrap; will-change: transform; }
.map-label .in { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; color: #15202a; background: rgba(255, 255, 255, 0.88); box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35); }
.map-label .in .mk { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; font-weight: 800; line-height: 1; }
.map-label.first .mk { background: #2f7d4a; } .map-label.second .mk, .map-label.third .mk { background: #b8860b; } .map-label.missed .mk { background: var(--st-red); }
.map-label.found .in { animation: labelIn 0.5s cubic-bezier(.2, .9, .3, 1.3) both; }
.map-label.flash .in { font-family: var(--font-display); font-size: clamp(1.1rem, 2.4vw, 1.6rem); padding: 8px 18px; background: rgba(15, 26, 36, 0.92); color: #fff; border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: flashIn 0.35s cubic-bezier(.2, .9, .3, 1.3) both; }
.map-label.flash.reveal .in { background: rgba(120, 22, 16, 0.94); border-color: rgba(255, 150, 130, 0.6); }
.map-label.out .in { animation: labelOut 0.35s ease forwards; }
.map-label.context .in { background: none; box-shadow: none; color: rgba(235, 228, 210, 0.5); font-family: var(--font-display); font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.68rem; padding: 0; }
.map-label.hidden { visibility: hidden; }
.map-label.no-marks .mk { display: none; }
@keyframes labelIn { from { opacity: 0; transform: translateY(8px) scale(0.6); } }
@keyframes flashIn { from { opacity: 0; transform: translateY(10px) scale(0.7); } }
@keyframes labelOut { to { opacity: 0; transform: translateY(-14px) scale(0.9); } }

/* results */
#screen-results { display: grid; place-items: center; padding: var(--gutter); overflow: auto; background: radial-gradient(900px 600px at 50% 50%, rgba(8, 19, 29, 0.2), rgba(8, 19, 29, 0.7)); }
.results-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(860px, 100%); }
.results-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.results-tip { margin: 0; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* the badge (screenshot-friendly: everything a teacher needs in one rectangle) */
.badge { width: 100%; background: radial-gradient(120% 90% at 20% 0%, #fffaf0 0%, var(--paper) 45%, var(--paper-2) 100%); color: var(--paper-ink); border-radius: 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.05); padding: clamp(18px, 3vw, 30px); display: grid; grid-template-columns: auto 1fr; gap: clamp(16px, 3vw, 30px); position: relative; overflow: hidden; animation: badgeIn 0.9s cubic-bezier(.2, .9, .2, 1) both; user-select: text; -webkit-user-select: text; }
@keyframes badgeIn { from { opacity: 0; transform: translateY(30px) scale(0.94) rotate(-0.6deg); } }
.badge::before { content: ''; position: absolute; inset: 9px; border: 1.5px solid rgba(160, 120, 40, 0.35); border-radius: 15px; pointer-events: none; }
.badge-seal { width: clamp(150px, 22vw, 210px); aspect-ratio: 1; align-self: center; }
.badge-seal canvas, .badge-seal svg { width: 100%; height: 100%; display: block; }
.badge-main { min-width: 0; display: flex; flex-direction: column; }
.badge-series { margin: 0; font-size: 0.72rem; letter-spacing: 0.22em; text-transform: uppercase; color: #8a6a1f; font-weight: 600; }
.badge-game { margin: 4px 0 0; font-family: var(--font-display); font-weight: 650; font-size: clamp(1.5rem, 3.4vw, 2.2rem); line-height: 1.05; }
.badge-score { display: flex; align-items: baseline; gap: 14px; margin: 10px 0 2px; flex-wrap: wrap; }
.badge-pct { font-family: var(--font-display); font-weight: 700; font-size: clamp(3rem, 8vw, 4.6rem); line-height: 0.95; letter-spacing: -0.03em; color: #1b2733; }
.badge-rank { font-family: var(--font-display); font-style: italic; font-size: clamp(1.1rem, 2.4vw, 1.45rem); color: #7a5a14; font-weight: 500; }
.badge-line { margin: 0 0 10px; color: var(--paper-muted); font-size: 0.92rem; }
.badge-stats { display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 4px 26px; margin: 4px 0 12px; }
.badge-stats > div { display: flex; flex-direction: column; gap: 2px; }
.badge-stats dt { font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--paper-muted); }
.badge-stats dd { margin: 0; font-weight: 600; font-size: 1rem; font-variant-numeric: tabular-nums; }
.badge-items { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin: 0 0 14px; }
.badge-items span { font-size: 0.72rem; font-weight: 700; text-align: center; padding: 4px 0; border-radius: 6px; letter-spacing: 0.04em; border: 1px solid rgba(0, 0, 0, 0.12); }
.badge-items .first { background: #fffdf7; color: #2f5d3a; } .badge-items .second, .badge-items .third { background: #f6d56c; color: #4d3a00; } .badge-items .missed { background: #e46a5e; color: #fff; }
.badge-items span sup { font-size: 0.85em; margin-left: 1px; }
.badge-code { margin-top: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px dashed rgba(31, 42, 54, 0.25); }
.badge-code .lbl { font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--paper-muted); }
.badge-code code { font-family: var(--font-mono); font-weight: 600; font-size: clamp(0.95rem, 2vw, 1.12rem); letter-spacing: 0.08em; color: #1d2733; background: rgba(255, 255, 255, 0.65); padding: 5px 10px; border-radius: 8px; border: 1px solid rgba(31, 42, 54, 0.16); }
.badge-code button { appearance: none; border: 1px solid rgba(31, 42, 54, 0.25); background: transparent; color: var(--paper-ink); border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; cursor: pointer; min-height: 32px; }
.badge-code button:hover { background: rgba(31, 42, 54, 0.08); }
.badge-best { position: absolute; top: 18px; right: 22px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #fff; background: linear-gradient(180deg, #e2a53b, #c4831c); padding: 6px 12px; border-radius: 999px; box-shadow: 0 4px 12px rgba(196, 131, 28, 0.4); }

/* settings */
.scrim { position: fixed; inset: 0; background: rgba(4, 10, 16, 0.45); z-index: 59; }
.settings { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); background: #0d1b28; border-left: 1px solid var(--line); z-index: 60; display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5); animation: slideIn 0.35s cubic-bezier(.2, .8, .2, 1); user-select: none; }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: calc(16px + var(--safe-t)) 18px 12px 22px; border-bottom: 1px solid var(--line); }
.settings-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1.5rem; }
.settings-body { overflow: auto; padding: 8px 22px calc(28px + var(--safe-b)); touch-action: pan-y; }
.set-group { padding: 14px 0 6px; border-bottom: 1px solid var(--line); }
.set-group:last-child { border-bottom: 0; }
.set-group h3 { margin: 6px 0 10px; font-size: 0.75rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-2); font-weight: 600; }
.set-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; padding: 9px 0; }
.set-row label, .set-row .lbl { font-size: 0.95rem; }
.set-row .sub { grid-column: 1 / -1; color: var(--dim); font-size: 0.8rem; margin-top: -2px; line-height: 1.35; }
.set-row.slider { grid-template-columns: 1fr auto; }
.set-row.slider input { grid-column: 1 / -1; }
.set-row output { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer; margin: 0; }
input[type='range']::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--gold) var(--fill, 50%), rgba(255, 255, 255, 0.14) var(--fill, 50%)); }
input[type='range']::-moz-range-track { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.14); }
input[type='range']::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--gold); }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; margin-top: -8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); border: 0; }
input[type='range']::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); position: relative; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.switch:checked { background: var(--gold); }
.switch:checked::after { transform: translateX(20px); }
.quality-ticks { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--dim); margin-top: -2px; }
.settings select { background: #132637; color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; max-width: 190px; font: inherit; font-size: 0.85rem; }
.set-about { color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.set-about a { color: var(--gold-2); }

.confirm { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(4, 10, 16, 0.55); z-index: 70; padding: var(--gutter); }
.confirm .card { padding: 24px; width: min(420px, 100%); background: var(--glass-hi); }
.confirm p { margin: 0 0 18px; font-size: 1.05rem; line-height: 1.45; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.fps { position: fixed; left: 8px; bottom: 8px; z-index: 80; font: 12px var(--font-mono); color: #9fe0a0; background: rgba(0, 0, 0, 0.55); padding: 4px 8px; border-radius: 6px; pointer-events: none; }

/* ---------- small screens */
@media (max-width: 760px) {
  .hud-left { gap: 6px; }
  .hud-game { position: fixed; right: var(--gutter); bottom: calc(var(--gutter) + var(--safe-b)); min-width: 0; padding: 8px 10px; }
  .hud-title { display: none; }
  .hud-progress { width: 132px; }
  #screen-results { padding-top: calc(70px + var(--safe-t)); place-items: start center; }
  .prompt { top: calc(var(--gutter) + var(--safe-t) + 54px); padding: 8px 16px 10px; min-width: 0; width: calc(100vw - 2 * var(--gutter)); }
  .hud-timer { right: calc(var(--gutter) + 100px); top: calc(var(--gutter) + var(--safe-t) + 4px); }
  .legend-hud { display: none; }
  .toast-zone { top: calc(var(--gutter) + var(--safe-t) + 210px); }
  .fact-card { width: calc(100vw - 2 * var(--gutter)); bottom: calc(var(--gutter) + 66px + var(--safe-b)); font-size: 0.8rem; padding: 9px 12px; }
  .fact-card .meta { font-size: 0.74rem; margin: 1px 0 4px; }
  .map-tools { flex-direction: row; }
  .regions-head { right: 112px; }
  .regions-head .eyebrow { display: none; }
  .regions-head .title { font-size: 1.25rem; padding-top: 8px; }
  #screen-regions:has(#region-panel:not([hidden])) .region-list { display: none; }
  .badge { grid-template-columns: 1fr; text-align: center; }
  .badge-seal { width: 130px; justify-self: center; }
  .badge-score, .badge-code { justify-content: center; }
  .badge-stats { justify-content: center; grid-template-columns: repeat(2, auto); gap: 6px 22px; }
  .badge-items { grid-template-columns: repeat(4, 1fr); }
  .region-panel { top: auto; bottom: calc(var(--gutter) + var(--safe-b)); max-height: 62vh; }
  .region-list { gap: 6px; }
  .region-chip { padding: 8px 12px 8px 10px; }
  .region-chip .sub { display: none; }
}
@media (max-height: 640px) and (min-width: 761px) {
  .badge-seal { width: 140px; }
  .badge-pct { font-size: 3.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }

/* 404 page */
.page-404 { display: grid; place-items: center; min-height: 100%; overflow: auto; touch-action: auto; background: radial-gradient(1200px 700px at 50% 45%, #10283a 0%, var(--bg) 70%); }
.page-404 .loading { text-align: center; }
.page-404 a.btn { text-decoration: none; margin-top: 18px; }
