:root {
  --ocean: #071a33;
  --ocean-2: #0c2549;
  --ocean-3: #12305c;
  --land: #d3e6f6;
  --land-ctx: #9db7d0;
  --edge: #3f6890;
  --ink: #f4fbff;
  --muted: #9fb6cf;
  --blue: #8ecdf7;
  --silver: #c5ced8;
  --good: #4fdc9f;
  --bad: #ff7f6e;
  --gold: #ffcf5a;
  --hl: #ffcf5a;
  --chrome: linear-gradient(180deg, #ffffff 15%, #c5ced8 55%, #8ecdf7 100%);
  --radius: 16px;
  --tabs-h: 64px;
  --font: 'Avenir Next', 'Helvetica Neue', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ocean); color: var(--ink); font: 16px/1.4 var(--font); -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto; }
#view { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 16px 24px; outline: none; -webkit-overflow-scrolling: touch; }
#tabs { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #06142a; border-top: 1px solid #1d3a63; }
#tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); cursor: pointer; }
#tabs button .ico { font-size: 18px; line-height: 1; }
#tabs button[aria-current='page'] { color: var(--ink); }
#tabs button[aria-current='page'] .ico { color: var(--blue); }
body.in-quiz #tabs { display: none; }

/* ---------- headings & generic ---------- */
.wordmark { margin: 4px 0 2px; font-weight: 900; font-style: italic; font-size: clamp(30px, 9vw, 46px); letter-spacing: -.01em; line-height: 1; background: var(--chrome); -webkit-background-clip: text; background-clip: text; color: transparent; }
.kicker { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--blue); }
h2 { margin: 18px 0 10px; font-size: 13px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--silver); }
h1.screen { margin: 4px 0 12px; font-size: 24px; font-weight: 800; }
p.note { color: var(--muted); font-size: 13px; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.iconbtn { background: var(--ocean-2); border: 1px solid #254a7a; border-radius: 12px; min-width: 44px; height: 44px; padding: 0 12px; cursor: pointer; font-weight: 700; }
.back { background: none; border: 0; color: var(--blue); font-weight: 700; padding: 10px 0; cursor: pointer; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid #2c5488; background: var(--ocean-2); font-weight: 800; letter-spacing: .02em; cursor: pointer; }
.btn.primary { background: linear-gradient(180deg, #a9dcfb, #6fb9ec); color: #05162d; border-color: #cfeaff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }

.seg { display: inline-flex; background: #06142a; border: 1px solid #1f3f6b; border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; min-height: 38px; }
.seg button[aria-pressed='true'] { background: var(--ocean-3); color: var(--ink); box-shadow: inset 0 0 0 1px #4b79ad; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid #27507f; background: var(--ocean-2); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer; min-height: 36px; }
.chip[aria-pressed='true'] { background: #1c4d80; border-color: var(--blue); }
.chip:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Play ---------- */
.cards { display: grid; gap: 12px; }
.card { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; text-align: left; width: 100%; padding: 18px; border-radius: var(--radius); border: 1px solid #2a548a; background: linear-gradient(160deg, #10305b, #0a2042); cursor: pointer; min-height: 116px; overflow: hidden; }
.card::before { content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1px; background: linear-gradient(140deg, rgba(255,255,255,.5), rgba(142,205,247,.15) 40%, rgba(197,206,216,.35)); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; }
.card h3 { margin: 0 0 4px; font-size: 22px; font-weight: 900; font-style: italic; letter-spacing: .01em; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .preview { width: 128px; height: 84px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.card .preview img { width: 64px; height: 48px; border-radius: 4px; box-shadow: 0 2px 8px #0008; }
.card .preview svg.outline { width: 56px; height: 56px; }
.card .preview svg.map { width: 128px; height: 84px; border-radius: 10px; }
.card.small { min-height: 0; padding: 14px 18px; }
.card.small h3 { font-size: 17px; }
.card.continue { border-color: var(--gold); }
.shuffle { position: relative; width: 120px; height: 80px; }
.shuffle > * { position: absolute; border-radius: 8px; box-shadow: 0 4px 12px #0009; }
.shuffle .s1 { left: 4px; top: 14px; width: 58px; height: 44px; transform: rotate(-10deg); }
.shuffle .s2 { left: 38px; top: 6px; width: 50px; height: 50px; background: var(--ocean-3); transform: rotate(6deg); padding: 4px; }
.shuffle .s3 { left: 70px; top: 22px; width: 48px; height: 48px; background: #e9f3fb; color: #08203f; font-weight: 900; display: flex; align-items: center; justify-content: center; transform: rotate(14deg); font-size: 22px; }

.subjects { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.subject { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 14px; border-radius: 14px; border: 1px solid #27507f; background: var(--ocean-2); cursor: pointer; text-align: left; min-height: 92px; }
.subject.big { min-height: 132px; }
.subject b { font-size: 17px; }
.subject small { color: var(--muted); font-size: 12px; }
.subject .thumb { height: 44px; display: flex; align-items: center; gap: 6px; }
.subject .thumb img { height: 36px; border-radius: 3px; }
.subject .thumb svg { height: 44px; width: 44px; }
.subject[aria-disabled='true'] { opacity: .55; cursor: default; border-style: dashed; }
.badge { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px; background: #1b3a64; color: var(--muted); }
.badge.live { background: #12442f; color: var(--good); }

/* ---------- Quiz ---------- */
.quiz { display: flex; flex-direction: column; min-height: 100%; gap: 10px; }
.qbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.qbar .qtitle { text-align: center; font-size: 13px; color: var(--muted); font-weight: 700; }
.qbar .qtitle b { display: block; color: var(--ink); font-size: 16px; }
.timer { height: 6px; background: #0a2142; border-radius: 3px; overflow: hidden; }
.timer i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #e8f6ff); transform-origin: left; }
.timer.low i { background: var(--bad); }
.timer.off { visibility: hidden; }
.stage { position: relative; flex: 0 0 auto; height: clamp(200px, 40vh, 420px); display: flex; align-items: center; justify-content: center; border-radius: var(--radius); background: radial-gradient(120% 90% at 50% 40%, #0f2d57, #071a33); border: 1px solid #1b3b66; overflow: hidden; }
.stage img.flag { max-width: 82%; max-height: 82%; width: 340px; aspect-ratio: 4/3; object-fit: contain; border-radius: 6px; box-shadow: 0 8px 30px #000a, 0 0 0 1px #ffffff22; }
.stage svg.outline { width: 78%; height: 86%; }
.stage svg.map { width: 100%; height: 100%; }
.stage .textclue { font-size: clamp(26px, 7vw, 40px); font-weight: 900; text-align: center; padding: 12px; }
.stage .tag { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: var(--muted); background: #071a33cc; padding: 3px 7px; border-radius: 6px; }
.prompt { margin: 0; text-align: center; font-weight: 800; font-size: 18px; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { position: relative; min-height: 58px; padding: 10px 12px; border-radius: 14px; border: 1px solid #2f5b91; background: var(--ocean-2); font-weight: 800; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.15; }
.opt .k { position: absolute; left: 8px; top: 6px; font-size: 10px; color: var(--muted); font-weight: 700; }
.opt img { width: 100%; max-width: 150px; aspect-ratio: 4/3; object-fit: contain; border-radius: 4px; }
.opt svg.outline { width: 78px; height: 78px; }
.opt.pic { min-height: 104px; }
.opt.correct { background: #0f4b35; border-color: var(--good); box-shadow: 0 0 0 2px var(--good) inset; }
.opt.wrong { background: #4b1d1d; border-color: var(--bad); }
.opt.dim { opacity: .5; }
.opt:disabled { cursor: default; }
.qfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.reveal { border-radius: var(--radius); background: #0a2244; border: 1px solid #2c5488; padding: 12px 14px; display: grid; gap: 8px; }
.reveal .verdict { font-weight: 900; font-size: 18px; }
.reveal .verdict.good { color: var(--good); }
.reveal .verdict.bad { color: var(--bad); }
.reveal .facts { color: var(--muted); font-size: 13px; }
.reveal .compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reveal .compare figure { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.reveal .compare img { width: 100%; max-width: 120px; aspect-ratio: 4/3; object-fit: contain; border-radius: 3px; }
.reveal .compare svg { width: 64px; height: 64px; }

/* ---------- Map ---------- */
svg.map { display: block; background: var(--ocean); }
svg.map .sphere { fill: #0a2244; }
svg.map .base path { fill: var(--land); stroke: var(--edge); stroke-width: .7; vector-effect: non-scaling-stroke; stroke-linejoin: round; transition: fill .35s; }
svg.map .base path.ctx { fill: var(--land-ctx); }
svg.map .base path.hl { fill: var(--hl); }
svg.map .base path.from { fill: #7fc4f2; }
svg.map .base path.good { fill: var(--good); }
svg.map .base path.bad { fill: var(--bad); }
svg.map .base path.gold { fill: var(--gold); }
svg.map .base path.mute { fill: #6f8cab; }
svg.map .ring { fill: none; stroke-width: 3; vector-effect: non-scaling-stroke; }
svg.map .ring.hl, svg.map .ring.gold { stroke: var(--hl); }
svg.map .ring.from { stroke: #7fc4f2; }
svg.map .ring.good { stroke: var(--good); }
svg.map .ring.bad { stroke: var(--bad); }
svg.map .ring.mute { stroke: #6f8cab; }
svg.map .shared { fill: none; stroke: #ffffff; stroke-width: 4; vector-effect: non-scaling-stroke; stroke-linecap: round; filter: drop-shadow(0 0 3px #8ecdf7); }
svg.map .shared.draw { transition: stroke-dashoffset 900ms ease-out; }
svg.map .route { fill: none; stroke: #ffffff; stroke-linejoin: round; stroke-linecap: round; opacity: .9; stroke-dasharray: 0; }
svg.map .stop { fill: #ffffff; stroke: #07203f; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
svg.map .stop.first { fill: var(--gold); }
svg.map .lbl { fill: #06142a; font-weight: 800; paint-order: stroke; stroke: #ffffffdd; stroke-width: 3; vector-effect: non-scaling-stroke; font-family: var(--font); pointer-events: none; }
.mapbox { border-radius: var(--radius); overflow: hidden; border: 1px solid #1b3b66; }
.mapbox svg.map { width: 100%; height: auto; aspect-ratio: 16/10; }

/* ---------- Results ---------- */
.score { text-align: center; padding: 10px 0 4px; }
.score .big { font-size: clamp(44px, 14vw, 72px); font-weight: 900; font-style: italic; line-height: 1; background: var(--chrome); -webkit-background-clip: text; background-clip: text; color: transparent; }
.score .sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.yeti { width: 84px; height: auto; display: block; margin: 0 auto 4px; }
.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.qlist li { display: grid; grid-template-columns: 26px 44px 1fr; gap: 10px; align-items: center; background: var(--ocean-2); border-radius: 12px; padding: 8px 10px; font-size: 14px; }
.qlist .mk { font-weight: 900; text-align: center; }
.qlist .mk.good { color: var(--good); }
.qlist .mk.bad { color: var(--bad); }
.qlist img { width: 44px; height: 33px; object-fit: contain; border-radius: 2px; }
.qlist svg { width: 40px; height: 40px; }
.qlist small { display: block; color: var(--muted); }
.actions { display: grid; gap: 10px; margin-top: 14px; }

/* ---------- Atlas / achievements ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--ocean-2); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.mist { display: flex; flex-wrap: wrap; gap: 6px; }
.mist span { display: inline-flex; align-items: center; gap: 6px; background: var(--ocean-2); border-radius: 999px; padding: 4px 10px 4px 4px; font-size: 13px; }
.mist img { width: 24px; height: 18px; border-radius: 2px; object-fit: cover; }
.stamps { display: flex; gap: 8px; flex-wrap: wrap; }
.stamp { width: 74px; height: 74px; border-radius: 50%; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 10px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; border: 3px double currentColor; transform: rotate(-8deg); padding: 6px; line-height: 1.1; }
.stamp.bronze { color: #e0a27a; } .stamp.silver { color: #dfe7ef; } .stamp.gold { color: var(--gold); } .stamp.stamp { color: var(--blue); }
.ach { background: var(--ocean-2); border-radius: 14px; padding: 14px; display: grid; gap: 8px; border: 1px solid #23476f; }
.ach.done { border-color: var(--gold); }
.tier { font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; }
.tier.bronze { background: #4a2d1c; color: #f0b48a; } .tier.silver { background: #39434d; color: #eef3f8; } .tier.gold { background: #4d3b0b; color: var(--gold); } .tier.stamp { background: #15365c; color: var(--blue); }
.bar { height: 8px; border-radius: 4px; background: #0a1f3d; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #fff); }
.list { display: grid; gap: 10px; }

/* ---------- Sheet ---------- */
#sheet { position: fixed; inset: 0; background: #020a18bb; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
#sheet[hidden] { display: none; }
#sheet .panel { width: 100%; max-width: 760px; max-height: 86vh; overflow: auto; background: #0b2144; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid #3a6496; }
#sheet h3 { margin: 0 0 8px; }
#sheet dl { margin: 0; display: grid; gap: 10px; }
#sheet dt { font-weight: 800; }
#sheet dd { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
#sheet a { color: var(--blue); }

@media (min-width: 640px) {
  .cards { grid-template-columns: 1fr 1fr 1fr; }
  .card { grid-template-columns: 1fr; align-content: start; min-height: 200px; }
  .card .preview { width: 100%; justify-content: flex-start; }
  .card.small { grid-column: 1 / -1; grid-template-columns: 1fr auto; min-height: 0; }
  .card.continue { grid-column: 1 / -1; grid-template-columns: 1fr auto; min-height: 0; }
  .subjects { grid-template-columns: repeat(3, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
@media (max-height: 640px) { .stage { height: clamp(150px, 34vh, 300px); } .opt { min-height: 50px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
svg.outline path { fill: var(--land); stroke: #ffffff; stroke-width: 1.2; vector-effect: non-scaling-stroke; stroke-linejoin: round; filter: drop-shadow(0 3px 8px #0009); }
.opt svg.outline path { stroke-width: 1; }
