:root {
  --night: #173a5e;
  --night-2: #0f2740;
  --ink: #12263a;
  --muted: #5b6c7d;
  --snow: #f4f8fc;
  --paper: #ffffff;
  --line: #d7e2ec;
  --soft: #e8f0f7;
  --red: #c8322b;
  --blue: #1e62c8;
  --green: #1f9d6b;
  --gold: #f5b90f;
  --radius: 18px;
  --font: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--snow);
  color: var(--ink);
  font: 400 18px/1.45 var(--font);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; line-height: 1.1; font-weight: 600; }
h2 { font-size: 28px; }
h3 { font-size: 21px; }
p { margin: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
[hidden] { display: none !important; }

.screen { display: none; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
.screen.on { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen.on { animation: none; } }

.pad { padding: 20px 16px 40px; max-width: 1100px; margin: 0 auto; display: grid; gap: 18px; }
.pad.narrow { max-width: 560px; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, #0f2740 0%, #1d4a78 55%, #5f93c4 100%);
  color: #fff; text-align: center;
  padding: calc(34px + env(safe-area-inset-top)) 16px 96px;
}
.hero.small { padding-bottom: 84px; }
.hero h1 { font-size: clamp(44px, 11vw, 84px); font-weight: 700; letter-spacing: -0.01em; text-shadow: 0 3px 0 rgba(0,0,0,.18); position: relative; }
.hero-sub { position: relative; opacity: .85; margin-top: 6px; font-size: 19px; }
.hero-mountains {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 90px; pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 90' preserveAspectRatio='none'%3E%3Cpath d='M0 90 L0 60 L120 22 L210 50 L330 8 L450 52 L560 26 L700 62 L820 14 L960 56 L1080 30 L1200 58 L1200 90Z' fill='%23a9c6e2'/%3E%3Cpath d='M0 90 L0 72 L160 44 L300 70 L470 38 L640 74 L800 46 L980 76 L1120 52 L1200 66 L1200 90Z' fill='%23f4f8fc'/%3E%3C/svg%3E") bottom / 100% 100% no-repeat;
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(2px 2px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 30% 60%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 55% 30%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 80% 15%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 90% 50%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70% 70%, #fff 50%, transparent 51%);
  opacity: .7;
}

.topbar { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; max-width: 1100px; margin: 0 auto; }
.me-chip { display: inline-flex; align-items: center; gap: 10px; background: rgba(255,255,255,.14); padding: 6px 16px 6px 6px; border-radius: 999px; font-weight: 500; color: #fff; }
.me-chip .av { width: 40px; height: 40px; font-size: 24px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 20px; }

.countdown { position: relative; z-index: 1; margin-top: 26px; }
.countdown .big { font-size: clamp(64px, 18vw, 120px); font-weight: 700; line-height: 1; }
.countdown .lbl { font-size: 21px; opacity: .9; }

/* ---------- avatars ---------- */
.av { display: inline-grid; place-items: center; border-radius: 50%; background: var(--c, var(--blue)); color: #fff; flex: none; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.who-btn { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px 10px; display: grid; justify-items: center; gap: 8px; font-size: 22px; font-weight: 600; transition: transform .1s; }
.who-btn:active { transform: scale(.96); }
.who-btn .av { width: 76px; height: 76px; font-size: 42px; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.who-btn small { font-size: 14px; font-weight: 400; color: var(--muted); }

/* ---------- pin ---------- */
.pin-avatar .av { width: 90px; height: 90px; font-size: 50px; margin: 10px auto 0; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 8px 0; }
.pin-dots i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--night); }
.pin-dots i.on { background: var(--night); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.pin-err { color: var(--red); font-weight: 500; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 0 auto; width: 100%; }
.pin-pad button { height: 72px; border-radius: 18px; background: var(--paper); border: 2px solid var(--line); font-size: 30px; font-weight: 600; }
.pin-pad button:active { background: var(--soft); }

/* ---------- buttons ---------- */
.back { justify-self: start; color: var(--blue); font-weight: 500; padding: 6px 0; font-size: 18px; }
.link-btn { color: var(--blue); font-weight: 500; padding: 8px; justify-self: center; }
.big-btn { display: block; width: 100%; padding: 18px; border-radius: 20px; background: var(--night); color: #fff; font-size: 24px; font-weight: 600; box-shadow: 0 5px 0 var(--night-2); transition: transform .08s; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--night-2); }
.big-btn.play { background: var(--red); box-shadow: 0 5px 0 #8e211c; font-size: 30px; }
.big-btn.play:active { box-shadow: 0 2px 0 #8e211c; }
.big-btn.ghost { background: var(--paper); color: var(--night); box-shadow: 0 5px 0 var(--line); border: 2px solid var(--line); }
.big-btn.green { background: var(--green); box-shadow: 0 5px 0 #146b48; }
.big-btn:disabled { opacity: .5; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card-btn { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px 10px; font-size: 21px; font-weight: 600; display: grid; gap: 4px; justify-items: center; }
.card-btn span { font-size: 38px; }
.card { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; }
.head-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.section-h { margin-top: 18px; }

.niva-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.niva-pick button { border: 2px solid var(--line); border-radius: 14px; padding: 10px 4px; display: grid; justify-items: center; font-weight: 600; background: var(--snow); }
.niva-pick button span { font-size: 30px; }
.niva-pick button.on { border-color: var(--night); background: var(--night); color: #fff; }

.prog-line { display: flex; align-items: center; gap: 12px; }
.prog { flex: 1; height: 12px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 6px; }

/* ---------- map + levels ---------- */
.map-layout { display: grid; grid-template-columns: minmax(220px, 330px) 1fr; gap: 24px; align-items: start; }
@media (max-width: 720px) { .map-layout { grid-template-columns: 1fr; } .map-wrap { max-width: 260px; margin: 0 auto; order: 2; } }
.map-wrap svg { width: 100%; height: auto; display: block; border-radius: var(--radius); border: 2px solid var(--line); background: #eaf1f7; }
.map-wrap .land { fill: #ffffff; }
.map-wrap .sea { fill: #bcd6ec; }
.map-wrap .lake { fill: #bcd6ec; }
.map-wrap .road { fill: none; stroke: #c8322b; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.map-wrap .road.b { stroke: #1e62c8; }
.map-wrap .road.n { stroke: #173a5e; }
.map-wrap .road.done { stroke-dasharray: none; }
.map-wrap .cp { fill: #fff; stroke: var(--night); stroke-width: 2; }
.map-wrap .cp.visited { fill: var(--gold); }
.map-wrap .lvl circle { stroke: #fff; stroke-width: 2.5; }
.map-wrap .lvl text { fill: #fff; font: 600 13px var(--font); text-anchor: middle; dominant-baseline: central; }
.map-wrap .lbl { font: 500 11px var(--font); fill: var(--muted); paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.map-wrap .lbl.big { font-size: 13px; fill: var(--ink); font-weight: 600; }
.map-wrap .lakelbl { font: italic 500 11px var(--font); fill: #4a7aa6; }

.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lvl-card { width: 100%; text-align: left; display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center; background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.lvl-card .num { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; font-weight: 700; color: #fff; background: var(--night); }
.lvl-card.cleared .num { background: var(--green); }
.lvl-card.next { border-color: var(--red); box-shadow: 0 0 0 3px rgba(200,50,43,.15); }
.lvl-card.next .num { background: var(--red); }
.lvl-card.locked { opacity: .55; }
.lvl-card.locked .num { background: #9aa8b5; }
.lvl-card b { font-size: 20px; font-weight: 600; display: block; }
.lvl-card .where { font-size: 15px; color: var(--muted); }
.lvl-card .stars { font-size: 20px; letter-spacing: 2px; white-space: nowrap; }
.lvl-card .best { font-size: 14px; color: var(--muted); text-align: right; }
.lvl-card.bonus .num { background: linear-gradient(135deg, #f5b90f, #e07a10); }
.lvl-card.bonus.locked .num { background: #9aa8b5; }

/* ---------- intro ---------- */
.intro-top { position: relative; color: #fff; padding: calc(28px + env(safe-area-inset-top)) 16px 28px; text-align: center; background: linear-gradient(180deg, #0f2740, #2a5f94); }
.intro-top .nr { display: inline-block; font-size: 15px; letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
.intro-top h1 { font-size: clamp(38px, 9vw, 60px); margin: 4px 0; }
.intro-top p { opacity: .9; }
.fact-card { background: #fff8e1; border: 2px solid #f3dc8e; border-radius: var(--radius); padding: 18px; display: grid; gap: 10px; }
.fact-card .h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: #9a6b00; }
.fact-card p { font-size: 21px; line-height: 1.4; }
.speak { width: 46px; height: 46px; border-radius: 50%; background: #fff; border: 2px solid #f3dc8e; font-size: 22px; flex: none; }
.intro-rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.rule { background: var(--paper); border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 15px; display: flex; gap: 10px; align-items: center; }
.rule span { font-size: 26px; }

/* ---------- game ---------- */
.game-screen { position: fixed; inset: 0; min-height: 0; background: #eef4fa; touch-action: none; user-select: none; -webkit-user-select: none; }
.game-screen.on { animation: none; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; inset: 0; pointer-events: none; padding: calc(10px + env(safe-area-inset-top)) 12px 12px; }
.hud-top { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding-right: 54px; }
.hud-score { background: rgba(15,39,64,.82); color: #fff; border-radius: 14px; padding: 4px 14px; display: grid; line-height: 1.05; text-align: center; min-width: 96px; }
.hud-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-score small { font-size: 12px; opacity: .8; }
.hud-prog { display: grid; gap: 3px; }
.hud-prog span { font-size: 13px; font-weight: 600; color: var(--night); text-shadow: 0 0 4px #fff; }
.hud-bar { height: 12px; background: rgba(15,39,64,.18); border-radius: 6px; overflow: hidden; }
.hud-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #1e62c8, #1f9d6b); }
.hud-hearts { font-size: 20px; letter-spacing: 1px; white-space: nowrap; }
.hud-row { display: flex; gap: 8px; margin-top: 8px; }
.hud-chip { background: rgba(255,255,255,.88); border-radius: 999px; padding: 2px 12px; font-size: 16px; }
.hud-combo { background: var(--gold); font-weight: 600; }
.hud-pause { pointer-events: auto; position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 46px; height: 46px; border-radius: 50%; background: rgba(15,39,64,.82); color: #fff; font-size: 20px; }
.hud-count { position: absolute; inset: 0; display: grid; place-items: center; font-size: 120px; font-weight: 700; color: var(--night); text-shadow: 0 4px 0 #fff, 0 0 30px #fff; }
.hud-help { position: absolute; left: 0; right: 0; bottom: calc(26px + env(safe-area-inset-bottom)); text-align: center; font-weight: 600; color: var(--night); text-shadow: 0 0 6px #fff, 0 0 6px #fff; font-size: 20px; }
.pause-panel { position: absolute; inset: 0; background: rgba(15,39,64,.75); display: grid; place-content: center; gap: 14px; padding: 20px; color: #fff; text-align: center; width: 100%; }
.pause-panel > * { width: min(360px, 90vw); }

/* ---------- result + quiz ---------- */
.res-head { text-align: center; display: grid; gap: 6px; }
.res-emoji { font-size: 72px; line-height: 1; }
.res-title { font-size: 36px; font-weight: 700; }
.score-rows { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 16px; }
.score-rows div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--soft); font-size: 18px; }
.score-rows div:last-child { border: 0; font-weight: 700; font-size: 22px; }
.score-rows b { font-variant-numeric: tabular-nums; }
.big-stars { font-size: 56px; letter-spacing: 6px; text-align: center; }
.big-stars .off { filter: grayscale(1); opacity: .3; }
.big-stars span { display: inline-block; animation: pop .4s backwards; }
.big-stars span:nth-child(2) { animation-delay: .25s; }
.big-stars span:nth-child(3) { animation-delay: .5s; }
@keyframes pop { from { transform: scale(0); } 70% { transform: scale(1.3); } }
.badge { display: inline-block; background: var(--gold); color: var(--ink); font-weight: 700; padding: 6px 16px; border-radius: 999px; font-size: 20px; justify-self: center; animation: pop .5s; }
.quiz { display: grid; gap: 14px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-weight: 500; }
.quiz-q { font-size: 26px; font-weight: 600; line-height: 1.25; display: flex; gap: 12px; align-items: flex-start; }
.quiz-q .speak { border-color: var(--line); }
.opts { display: grid; gap: 10px; }
.opt { text-align: left; background: var(--paper); border: 3px solid var(--line); border-radius: 16px; padding: 16px 18px; font-size: 21px; font-weight: 500; }
.opt:active { background: var(--soft); }
.opt.right { border-color: var(--green); background: #e3f6ec; }
.opt.wrong { border-color: var(--red); background: #fbe7e5; }
.opt:disabled { cursor: default; }
.explain { border-radius: 16px; padding: 14px 16px; font-size: 18px; }
.explain.ok { background: #e3f6ec; }
.explain.no { background: #fbe7e5; }
.explain b { display: block; font-size: 22px; margin-bottom: 4px; }
.mini-board { display: grid; gap: 6px; }
.unlock-note { background: #e3f6ec; border-radius: 16px; padding: 14px 16px; font-weight: 500; text-align: center; }

/* ---------- board ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs button { white-space: nowrap; border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; background: var(--paper); font-weight: 500; }
.tabs button.on { background: var(--night); color: #fff; border-color: var(--night); }
.board-rows { display: grid; gap: 8px; }
.brow { display: grid; grid-template-columns: 44px 48px 1fr auto; gap: 12px; align-items: center; background: var(--paper); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px; }
.brow.me { border-color: var(--blue); }
.brow .rank { font-size: 26px; font-weight: 700; text-align: center; color: var(--muted); }
.brow .av { width: 48px; height: 48px; font-size: 26px; }
.brow .nm { font-weight: 600; font-size: 20px; }
.brow .sub { font-size: 14px; color: var(--muted); }
.brow .pts { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.brow .pts small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.niva-tag { font-size: 13px; background: var(--soft); border-radius: 999px; padding: 1px 8px; margin-left: 6px; font-weight: 500; }
.recent { display: grid; gap: 4px; font-size: 15px; color: var(--muted); }

/* ---------- trip ---------- */
.trip-status { background: linear-gradient(135deg, #173a5e, #2a5f94); color: #fff; border-radius: var(--radius); padding: 20px; display: grid; gap: 10px; }
.trip-status .km { font-size: 54px; font-weight: 700; line-height: 1; }
.cp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cp-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; background: var(--paper); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px; }
.cp-row .ic { font-size: 26px; text-align: center; }
.cp-row.visited { border-color: var(--gold); }
.cp-row .sub { font-size: 14px; color: var(--muted); }
.small-btn { background: var(--red); color: #fff; font-weight: 600; border-radius: 12px; padding: 8px 14px; font-size: 16px; }
.small-btn.ghost { background: var(--soft); color: var(--ink); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--night); color: #fff; padding: 14px 22px; border-radius: 16px; font-weight: 500; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); text-align: center; animation: fade .25s; }
