:root {
  --bg: #020617;
  --glass: rgba(10, 17, 34, 0.82);
  --glass-strong: rgba(10, 17, 34, 0.92);
  --line: rgba(148, 163, 184, 0.22);
  --text: #f1f5f9;
  --muted: #9fb0c6;
  --gold: #fbbf24;
  --sky: #38bdf8;
  --good: #22c55e;
  --bad: #ef4444;
  --radius: 14px;
  --font: 'Be Vietnam Pro', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

#globe { position: fixed; inset: 0; }
.cesium-viewer-bottom { opacity: 0.6; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------- Title card (top-left) ---------- */
#title-card {
  position: fixed; top: 16px; left: 16px; max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px 14px; border-left: 4px solid var(--gold);
}
.chips { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.chip {
  font: 700 11px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold);
  border: 1px solid rgba(251, 191, 36, 0.45); border-radius: 999px; padding: 5px 10px;
}
.chip-flag { height: 22px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25); }
#title-text { margin: 0; font-size: clamp(22px, 3.2vw, 34px); font-weight: 800; text-transform: uppercase; letter-spacing: 0.01em; line-height: 1.15; }
#title-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
#title-time { margin: 6px 0 0; font-size: 14px; font-weight: 600; color: #fde68a; }
body[data-age='little'] #title-time { font-size: 18px; }
.pill.on { background: rgba(251, 191, 36, 0.2); border-color: var(--gold); color: var(--gold); }

/* ---------- Controls (top-right) ---------- */
#controls { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#controls .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0.02em; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.pill {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(8px); font-weight: 600; font-size: 14px;
}
.pill.accent { border-color: rgba(251, 191, 36, 0.6); color: var(--gold); }
.pill.age.on { background: var(--sky); color: #04111f; border-color: var(--sky); }
.search input {
  min-height: 44px; width: 200px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--glass); color: var(--text); font: 500 14px var(--font);
}

/* ---------- Cards panel ---------- */
#panel {
  position: fixed; right: 16px; top: 270px; bottom: 40px; width: min(440px, 40vw);
  display: flex; flex-direction: column; gap: 8px;
}
.panel-head { display: flex; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 4px; flex: 1; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tab { flex: 1; min-height: 38px; border: 0; border-radius: 999px; background: transparent; font-weight: 600; font-size: 13px; color: var(--muted); }
.tab.active { background: rgba(56, 189, 248, 0.18); color: var(--text); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass-strong); font-size: 16px; }
#panel-body { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; overscroll-behavior: contain; }

.card {
  display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--glass-strong); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  animation: rise 0.35s ease both;
}
.card:nth-child(2) { animation-delay: 0.06s; } .card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.18s; } .card:nth-child(5) { animation-delay: 0.24s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.num {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center; margin-top: 2px;
  border: 1.5px solid var(--accent); border-radius: 8px; color: var(--accent); font: 700 13px var(--mono);
}
.card-main { min-width: 0; flex: 1; }
.eyebrow { margin: 0 0 3px; font: 700 11px/1.3 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent, var(--gold)); }
.card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; line-height: 1.3; }
.card .body { margin: 0; font-size: 14px; line-height: 1.55; color: #d6deea; }
.card .extra { margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.card-flag { display: block; height: 54px; margin: 6px 0; border-radius: 6px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2); }
.more { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 13px; color: #c7d2e1; }
.more ul { margin: 0 0 6px; padding-left: 18px; line-height: 1.55; }
.sources { margin: 0; color: var(--muted); font-size: 12px; }
.sources a { color: var(--sky); }
.card-actions { display: flex; gap: 8px; margin-top: 8px; }
.mini { min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 12px; font-weight: 600; }
.empty { color: var(--muted); padding: 16px; text-align: center; background: var(--glass-strong); border-radius: 12px; }

.stats { margin: 0; padding: 14px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 14px; }
.stat dt { font: 700 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; }
.stat dd { margin: 0; font-size: 15px; }
.stat small { color: var(--muted); }
.bars { display: grid; gap: 4px; margin-top: 6px; }
.bar { position: relative; height: 20px; background: rgba(255, 255, 255, 0.05); border-radius: 6px; overflow: hidden; }
.bar span { position: absolute; inset: 0 auto 0 0; background: var(--sky); opacity: 0.75; border-radius: 6px; }
.bar.vn span { background: var(--bad); }
.bar em { position: relative; font-style: normal; font-size: 11px; padding-left: 8px; line-height: 20px; font-weight: 600; }
.chip-btn { min-height: 34px; margin: 2px 2px 0 0; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(56, 189, 248, 0.1); font-size: 13px; }

/* ---------- Map labels ---------- */
#overlay { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.ov { position: absolute; left: 0; top: 0; will-change: transform; }
.ov.callout { translate: -50% -140%; }
.callout-box {
  padding: 8px 16px; text-align: center; white-space: nowrap; border-radius: 10px;
  background: rgba(10, 17, 34, 0.9); border: 1.5px solid var(--sky); box-shadow: 0 0 18px rgba(56, 189, 248, 0.45);
}
.callout-box b { display: block; font-size: 20px; font-weight: 800; text-transform: uppercase; }
.callout-box small { font: 600 10px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ov.neighbor {
  translate: -50% -50%; pointer-events: auto; cursor: pointer; white-space: nowrap;
  font: 700 11px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: rgba(226, 232, 240, 0.75);
  text-shadow: 0 1px 4px #000, 0 0 2px #000;
}
.ov.capital .pulse {
  position: absolute; left: -8px; top: -8px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7); animation: pulse 1.6s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 16px rgba(251, 191, 36, 0); } 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); } }
.ov.capital .cap-box {
  position: absolute; left: 16px; top: 6px; white-space: nowrap; padding: 4px 10px; border-radius: 6px;
  background: rgba(10, 17, 34, 0.9); border: 1px solid var(--gold);
}
.cap-box b { display: block; font-size: 13px; }
.cap-box small { font: 700 9px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.ov.island {
  translate: -6px -50%; pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12px; font-weight: 700; color: #fde68a; text-shadow: 0 1px 4px #000, 0 0 2px #000;
}
.ov.island.flip { flex-direction: column; gap: 3px; translate: -50% -5px; }
.ov.island .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px #fde68a; }

/* ---------- Vietnam's provinces ---------- */
.ov.province { translate: -5px -50%; pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.ov.province .pdot { width: 7px; height: 7px; border-radius: 50%; background: #fde68a; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.6); flex: none; }
.ov.province .pname { font-size: 11px; font-weight: 700; color: #fef3c7; text-shadow: 0 1px 3px #000, 0 0 2px #000; }
.ov.province.city .pname { font-size: 12px; color: #fff; }
.ov.province .pinfo { display: none; }
.ov.province.open { z-index: 3; align-items: flex-start; }
.ov.province.open .pname { display: none; }
.ov.province.open .pinfo {
  display: block; padding: 8px 12px; border-radius: 10px; background: rgba(10, 17, 34, 0.94); border: 1px solid #fde68a;
  font-size: 12px; line-height: 1.5; color: #e2e8f0; white-space: normal; width: max-content; max-width: 240px;
}
.ov.province.open .pinfo b { font-size: 14px; color: #fde68a; }

body[data-voice='no'] .speak { opacity: 0.45; }
#toast { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; max-width: min(420px, calc(100vw - 32px)); padding: 16px 20px; font-size: 15px; line-height: 1.5; text-align: center; }
#hint { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); padding: 12px 20px; font-weight: 600; white-space: nowrap; }
#credit { position: fixed; left: 8px; bottom: 26px; font-size: 10px; color: rgba(226, 232, 240, 0.55); max-width: 60vw; pointer-events: none; }

/* ---------- Quiz ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(2, 6, 23, 0.6); padding: 16px; z-index: 10; }
.modal-box { position: relative; width: min(520px, 100%); padding: 24px; text-align: center; background: var(--glass-strong); }
.modal-box .icon-btn { position: absolute; top: 12px; right: 12px; }
.modal-box h2 { margin: 4px 0 14px; font-size: 22px; }
#quiz-flag { width: min(260px, 70%); border-radius: 8px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 10px 24px rgba(0, 0, 0, 0.4); }
#quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.option { min-height: 54px; font-size: 16px; }
.option.right { background: var(--good); border-color: var(--good); color: #04120a; }
.option.wrong { background: var(--bad); border-color: var(--bad); }
.option.dim { opacity: 0.45; }
#quiz-feedback { min-height: 24px; margin: 14px 0 0; }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); }

/* ---------- Ages 3–5: bigger everything, fewer words ---------- */
body[data-age='little'] .card h3 { font-size: 22px; }
body[data-age='little'] .card .body { font-size: 19px; }
body[data-age='little'] .num, body[data-age='little'] .eyebrow { display: none; }
body[data-age='little'] .mini { min-height: 48px; font-size: 16px; }
body[data-age='little'] .option { min-height: 72px; font-size: 20px; }

/* ---------- Portrait tablets and phones: cards slide up from the bottom ---------- */
@media (max-width: 899px), (orientation: portrait) {
  #title-card { top: 12px; left: 12px; right: 12px; max-width: none; padding: 10px 14px; }
  #controls { top: auto; bottom: 12px; right: 12px; left: 12px; align-items: stretch; }
  #controls .row { justify-content: center; }
  .brand { display: none; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 48vh; padding: 12px 12px 16px; background: rgba(2, 6, 23, 0.9); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; z-index: 5; }
  #hint { bottom: auto; top: 50%; }
  #controls { bottom: 24px; }
  #credit { bottom: 4px; max-width: none; right: 8px; }
}

/* ---------- Picture pins (ages 3–9) ---------- */
.ov.pin { translate: -50% -50%; pointer-events: auto; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.pin-emoji {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; font-size: 24px;
  background: rgba(255, 255, 255, 0.92); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45); transition: transform 0.15s;
}
.ov.pin:hover .pin-emoji, .ov.pin.open .pin-emoji { transform: scale(1.25); }
.pin-name {
  display: none; margin-top: 6px; padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  background: rgba(10, 17, 34, 0.92); border: 1px solid var(--gold); font-weight: 700; font-size: 14px;
}
.ov.pin.open { z-index: 2; }
.ov.pin.open .pin-name { display: block; }
body[data-age='little'] .pin-emoji { width: 52px; height: 52px; font-size: 32px; }
.big-icon { font-size: 56px; line-height: 1; margin: 2px 0 8px; }

/* ---------- Passport stamp ---------- */
#stamp {
  position: fixed; left: 50%; top: 42%; z-index: 30; pointer-events: none; text-align: center;
  padding: 14px 22px; border: 4px double var(--bad); border-radius: 16px; color: #fecaca;
  background: rgba(10, 17, 34, 0.92); transform: translate(-50%, -50%) rotate(-8deg);
}
#stamp img { display: block; height: 42px; margin: 0 auto 6px; border-radius: 4px; }
#stamp b { display: block; font-size: 22px; text-transform: uppercase; }
#stamp small { font: 700 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
#stamp.go { animation: stamp 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes stamp { from { opacity: 0; transform: translate(-50%, -50%) rotate(-8deg) scale(2.2); } }

.pp-box { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; text-align: left; }
.pp-total { font-size: 16px; font-weight: 600; }
.pp-cont h3 { display: flex; justify-content: space-between; margin: 16px 0 6px; font-size: 15px; }
.pp-cont h3 small { color: var(--muted); }
.pp-bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.pp-bar span { display: block; height: 100%; background: var(--gold); }
.pp-stamps { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.stamp { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; border: 2px dashed rgba(248, 113, 113, 0.6); background: rgba(248, 113, 113, 0.08); font-size: 13px; }
.stamp img { height: 18px; border-radius: 2px; }
.pp-empty { color: var(--muted); margin: 0; font-size: 13px; }

/* ---------- Where in the world? ---------- */
#find {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 8; width: min(640px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-color: rgba(251, 191, 36, 0.6);
}
#find > img { height: 44px; border-radius: 6px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25); }
.find-main { flex: 1; min-width: 0; }
.find-q { margin: 0; font-size: 18px; }
.find-msg { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.find-msg.good { color: #86efac; font-weight: 700; }
.find-msg.bad { color: #fca5a5; }
.find-score { font-weight: 700; color: var(--gold); white-space: nowrap; }
body.finding #title-card, body.finding #panel, body.finding #hint { display: none; }

/* ---------- Compare ---------- */
.cmp-pick { display: flex; align-items: center; gap: 10px; font: 700 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.cmp-pick select { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass); color: var(--text); font: 500 14px var(--font); padding: 0 10px; }
.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp th, .cmp td { text-align: left; padding: 6px 4px; vertical-align: top; }
.cmp thead th { font-size: 13px; color: var(--sky); }
.cmp tbody th { font: 700 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); width: 26%; }
.cmp tbody tr:not(.cmp-extra) { border-top: 1px solid var(--line); }
.cmp-extra td { padding-top: 0; }
.cmp-say { margin: 6px 0 0; font-size: 13px; color: #d6deea; }
.cmp-note { margin: 0; font-size: 11px; color: var(--muted); }
