:root {
  --bg: #0a111e;
  --ocean: #0d1829;
  --surface: #121d30;
  --surface-2: #18253c;
  --line: #24324c;
  --text: #e8eef8;
  --muted: #8a9ab5;
  --land: #3b4659;
  --land-hover: #56647d;
  --land-out: #222c3d;
  --territory: #2a3446;
  --border: #0d1829;
  --green: #34d399;
  --green-ink: #0b3d2a;
  --yellow: #fbbf24;
  --red: #f87171;
  --accent: #60a5fa;
  --accent-2: #a78bfa;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --panel-w: 390px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Outfit", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; letter-spacing: -.01em; }
.brand b { color: var(--green); font-weight: 800; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 50%;
  background: conic-gradient(var(--green) 0 62%, var(--land) 62% 100%);
  box-shadow: inset 0 0 0 4px var(--surface), 0 0 0 2px var(--green);
}
.modes { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-btn {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: 14px; transition: background .15s, color .15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.continent-select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px; font: inherit; font-size: 14px;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); color: var(--muted); font-weight: 700;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 36px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.toggle input:checked + .toggle-track { background: var(--red); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:checked ~ span:last-child { color: var(--red); font-weight: 600; }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.hud {
  display: flex; gap: 10px; padding: 10px 18px; align-items: stretch;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 6px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; min-width: 110px;
}
.stat-wide { flex: 1; min-width: 200px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat-label b { color: var(--text); font-size: 13px; letter-spacing: 0; margin-left: 4px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-value small { color: var(--muted); font-weight: 500; font-size: 15px; }
.stat-value.bump { animation: bump .45s ease; }
@keyframes bump { 40% { transform: scale(1.15); color: var(--green); } }
.progress { height: 9px; border-radius: 99px; background: var(--land); overflow: hidden; display: flex; margin-top: 5px; }
.progress-green { background: var(--green); transition: width .6s ease; }
.progress-yellow { background: var(--yellow); transition: width .6s ease; }
.mult { font-size: 13px; background: linear-gradient(90deg, #f59e0b, #ef4444); color: #fff; padding: 2px 7px; border-radius: 99px; vertical-align: middle; }
.timer.low { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ── Stage / map ─────────────────────────────────────────────────────────── */
.stage { flex: 1; position: relative; min-height: 0; }
.map-wrap { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 40%, #11203a 0%, var(--ocean) 55%, var(--bg) 100%); overflow: hidden; }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map:active { cursor: grabbing; }
.graticule { fill: none; stroke: #ffffff; stroke-opacity: .04; vector-effect: non-scaling-stroke; }

.country {
  fill: var(--land); stroke: var(--border); stroke-width: .6px; vector-effect: non-scaling-stroke;
  transition: fill .5s ease, opacity .3s;
  cursor: pointer;
}
.country.hover { fill: var(--land-hover); }
.outline-hover { fill: none; stroke: #fff; stroke-width: 1.6px; vector-effect: non-scaling-stroke; }
.outline-sel { fill: none; stroke: #fff; stroke-width: 2.4px; vector-effect: non-scaling-stroke; animation: sel 1.4s ease-in-out infinite; }
.country.s-green { fill: var(--green); }
.country.s-yellow { fill: var(--yellow); }
.country.s-red { fill: var(--red); }
.country.s-green.hover { fill: #6ee7b7; }
.country.s-yellow.hover { fill: #fcd34d; }
.country.s-red.hover { fill: #fca5a5; }
.country.out { opacity: .22; pointer-events: none; }
.country.selected, .country.selected.hover { fill: var(--accent); }
@keyframes sel { 50% { stroke-opacity: .35; } }
.country.just-done { animation: done 1s ease; }
@keyframes done { 0% { filter: brightness(2.2); } 100% { filter: none; } }
.territory { fill: var(--territory); stroke: var(--border); stroke-width: .5px; vector-effect: non-scaling-stroke; pointer-events: none; }

.marker { fill: var(--land); stroke: var(--text); stroke-opacity: .55; stroke-width: 1px; vector-effect: non-scaling-stroke; cursor: pointer; transition: fill .5s; }
.marker.hover { stroke: #fff; stroke-opacity: 1; stroke-width: 2px; fill: var(--land-hover); }
.marker.s-green { fill: var(--green); }
.marker.s-yellow { fill: var(--yellow); }
.marker.s-red { fill: var(--red); }
.marker.out { opacity: .2; pointer-events: none; }
.marker.selected { fill: var(--accent); stroke: #fff; stroke-opacity: 1; stroke-width: 2.5px; animation: sel 1.4s ease-in-out infinite; }

.loading { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--green); margin: 0 auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: rgba(10, 17, 30, .92); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px));
}
.tooltip img { height: 12px; vertical-align: -1px; margin-right: 6px; border-radius: 2px; }

.legend {
  position: absolute; left: 16px; bottom: 16px; display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); background: rgba(10, 17, 30, .75); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-gray { background: var(--land); } .sw-green { background: var(--green); } .sw-yellow { background: var(--yellow); } .sw-red { background: var(--red); }

.zoom-ctrl { position: absolute; left: 16px; top: 16px; display: flex; flex-direction: column; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.zoom-ctrl button { width: 36px; height: 36px; border: 0; background: rgba(18, 29, 48, .9); font-size: 18px; color: var(--muted); }
.zoom-ctrl button + button { border-top: 1px solid var(--line); }
.zoom-ctrl button:hover { color: var(--text); background: var(--surface-2); }

.hint {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(10, 17, 30, .8); border: 1px solid var(--line); padding: 7px 16px; border-radius: 999px;
  font-size: 14px; color: var(--muted); pointer-events: none; transition: opacity .3s;
}
body.panel-open .hint { opacity: 0; }

/* ── Quiz panel ──────────────────────────────────────────────────────────── */
.panel {
  position: absolute; top: 16px; right: 16px; bottom: 16px; width: var(--panel-w);
  background: rgba(18, 29, 48, .97); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; overflow-y: auto; z-index: 4;
  animation: slideIn .25s ease;
  backdrop-filter: blur(6px);
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.steps { display: flex; gap: 6px; }
.step-dot { width: 30px; height: 6px; border-radius: 99px; background: var(--line); }
.step-dot.active { background: var(--accent); }
.step-dot.ok { background: var(--green); }
.step-dot.meh { background: var(--yellow); }
.step-dot.bad { background: var(--red); }
.skip-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 4px 12px; border-radius: 99px; font-size: 13px; }
.skip-btn:hover { color: var(--text); border-color: var(--muted); }
.q-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 600; }
.q-title { font-size: 22px; font-weight: 700; margin: 4px 0 4px; line-height: 1.2; }
.q-sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; display: flex; justify-content: space-between; gap: 10px; }
.attempts { display: inline-flex; gap: 4px; align-items: center; }
.attempts i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.attempts i.used { background: var(--line); }
.worth { color: var(--green); font-weight: 600; }

.options { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; font-weight: 500; transition: border-color .12s, background .12s, transform .08s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: #0f1a2d; }
.opt:active:not(:disabled) { transform: scale(.985); }
.opt kbd { font: 600 12px "Outfit", sans-serif; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; min-width: 22px; text-align: center; }
.opt.wrong { border-color: var(--red); background: rgba(248, 113, 113, .12); color: #fecaca; animation: shake .35s; }
.opt.correct { border-color: var(--green); background: rgba(52, 211, 153, .16); color: #d1fae5; }
.opt.reveal { border-color: var(--green); border-style: dashed; }
.opt:disabled { cursor: default; }
.opt:disabled:not(.correct):not(.wrong):not(.reveal) { opacity: .45; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.flags { grid-template-columns: repeat(2, 1fr); }
.flag-opt { flex-direction: column; padding: 10px; gap: 6px; justify-content: center; }
.flag-opt img { width: 100%; aspect-ratio: 3 / 2; object-fit: contain; border-radius: 4px; background: #0003; }
.flag-opt .flag-name { font-size: 12px; color: var(--muted); min-height: 15px; text-align: center; }
.flag-opt kbd { align-self: flex-start; margin-bottom: -26px; position: relative; z-index: 1; background: rgba(10,17,30,.8); }

.type-form { display: flex; gap: 8px; }
.type-input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; outline: none;
}
.type-input:focus { border-color: var(--accent); }
.type-input.wrong { border-color: var(--red); animation: shake .35s; }
.type-input.correct { border-color: var(--green); }
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 15px;
  background: var(--accent); color: #06111f; transition: filter .15s, transform .08s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.98); }
.btn.green { background: var(--green); color: var(--green-ink); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--muted); }
.type-hint { margin-top: 10px; font-size: 14px; color: var(--muted); min-height: 20px; }
.type-hint b { color: var(--yellow); letter-spacing: .12em; }

.feedback { margin-top: 12px; min-height: 22px; font-weight: 600; font-size: 15px; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

.float-points { position: fixed; pointer-events: none; font-weight: 800; font-size: 22px; color: var(--green); z-index: 50; animation: floatUp 1s ease forwards; text-shadow: 0 2px 10px #000; }
@keyframes floatUp { to { transform: translateY(-50px); opacity: 0; } }

/* ── Info card ───────────────────────────────────────────────────────────── */
.card-result { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.badge { padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; }
.badge.green { background: rgba(52, 211, 153, .18); color: var(--green); }
.badge.yellow { background: rgba(251, 191, 36, .16); color: var(--yellow); }
.badge.red { background: rgba(248, 113, 113, .16); color: var(--red); }
.earned { margin-left: auto; font-size: 24px; font-weight: 800; color: var(--green); font-variant-numeric: tabular-nums; }
.info-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.info-flag { width: 104px; flex: none; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #0003; }
.info-name { font-size: 26px; font-weight: 800; line-height: 1.1; letter-spacing: -.01em; }
.info-region { color: var(--muted); margin-top: 2px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.fact { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.fact span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.fact b { font-weight: 600; font-size: 15px; }
.fact.full { grid-column: 1 / -1; }
.breakdown { list-style: none; margin: 0 0 16px; padding: 0; font-size: 14px; border-top: 1px solid var(--line); }
.breakdown li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.breakdown li span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.breakdown .ok { color: var(--green); } .breakdown .meh { color: var(--yellow); } .breakdown .bad { color: var(--red); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.kbd-note { font-size: 12px; color: var(--muted); margin-top: 10px; text-align: center; }

/* ── Locks & learning sections ───────────────────────────────────────────── */
.country.locked:not(.selected), .marker.locked:not(.selected) { filter: saturate(.35) brightness(.72); }
.lock-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: rgba(251, 191, 36, .08); border: 1px dashed rgba(251, 191, 36, .45); color: #fde68a;
  border-radius: 10px; padding: 9px 12px; margin-bottom: 14px; font-size: 14px;
}
.lock-box b { font-variant-numeric: tabular-nums; color: var(--yellow); }
.lock-box .btn { padding: 7px 14px; font-size: 14px; }
.sticky-actions { position: sticky; bottom: -20px; z-index: 2; background: rgb(18, 29, 48); padding: 12px 0 14px; margin: 14px 0 -6px; border-top: 1px solid var(--line); }
.sticky-actions .kbd-note { flex-basis: 100%; margin-top: 2px; }
@media (max-width: 760px) { .sticky-actions { bottom: -16px; } }
.learn { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.learn h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.learn p { margin: 0; line-height: 1.55; font-size: 15px; }
.learn small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.learn.situation h4 { color: var(--red); }
.live { font-size: 10px; letter-spacing: .1em; background: rgba(248, 113, 113, .16); color: var(--red); padding: 2px 7px; border-radius: 99px; }
.muted { color: var(--muted); font-size: 14px; }
.mini-spin { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); vertical-align: -1px; margin-right: 6px; animation: spin 1s linear infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; }
.chips-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-right: 2px; }
.chip { font-size: 12.5px; background: rgba(248, 113, 113, .12); border: 1px solid rgba(248, 113, 113, .3); color: #fecaca; padding: 3px 9px; border-radius: 99px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.events li { font-size: 14px; line-height: 1.45; padding-left: 12px; border-left: 2px solid var(--line); }
.events b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.wiki-link { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 600; }
.wiki-link:hover { text-decoration: underline; }

/* ── Toasts & modals ─────────────────────────────────────────────────────── */
.toasts { position: fixed; top: 130px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; align-items: center; }
.toast { background: var(--surface-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); animation: toastIn .3s ease, toastOut .4s ease 2.6s forwards; }
.toast.fire { background: linear-gradient(90deg, #b45309, #b91c1c); border-color: transparent; }
.toast.win { background: var(--green); color: var(--green-ink); border-color: transparent; }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-12px); opacity: 0; } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(5, 9, 17, .72); display: grid; place-items: center; z-index: 70; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.02em; }
.modal h1 b { color: var(--green); }
.modal p { color: var(--muted); line-height: 1.5; margin: 0 0 14px; }
.modal ul.rules { margin: 0 0 18px; padding-left: 18px; color: var(--muted); line-height: 1.7; }
.modal ul.rules b { color: var(--text); }
.modal .actions { margin-top: 18px; }
.victory { text-align: center; }
.victory h1 { font-size: 34px; background: linear-gradient(90deg, var(--green), var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.vstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; text-align: left; }
.vstats .fact b { font-size: 20px; }
.struggled { text-align: left; }
.struggled h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 0 0 8px; }
.struggled ol { margin: 0; padding-left: 20px; line-height: 1.7; }
.struggled ol span { color: var(--muted); }
.trophy { font-size: 54px; line-height: 1; margin-bottom: 8px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .hud { flex-wrap: wrap; }
  .stat { min-width: 0; flex: 1; padding: 5px 10px; }
  .stat-wide { flex-basis: 100%; order: 10; }
  .stat-value { font-size: 18px; }
}
@media (max-width: 760px) {
  .topbar { padding: 8px 16px; gap: 8px; }
  .brand { font-size: 18px; }
  .modes { order: 3; width: 100%; justify-content: space-between; }
  .mode-btn { padding: 6px 8px; font-size: 13px; flex: 1; white-space: nowrap; }
  .hud { padding: 8px 16px; gap: 6px; }
  .stat-label { font-size: 10px; }
  .legend { display: none; }
  .hint { font-size: 13px; top: 10px; max-width: calc(100% - 100px); text-align: center; }
  .zoom-ctrl { top: auto; bottom: 16px; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62%; border-radius: 18px 18px 0 0; padding: 16px; animation-name: slideUp; }
  @keyframes slideUp { from { transform: translateY(30px); opacity: 0; } }
  .q-title { font-size: 19px; }
  .opt { padding: 10px 12px; font-size: 15px; }
  .flags { grid-template-columns: repeat(3, 1fr); }
  .flag-opt { padding: 6px; }
  .flag-opt kbd { display: none; }
  .vstats { grid-template-columns: repeat(2, 1fr); }
  .toasts { top: 150px; width: calc(100% - 32px); }
}
