:root {
  --bg: #0a1226;
  --bg-2: #101b36;
  --ink: #e8eef8;
  --muted: #8a9bb8;
  --line: rgba(138, 155, 184, .18);
  --ns: #4fd1e6;      /* north / south */
  --ew: #f5b453;      /* east / west  */
  --ok: #5ce0a1;
  --bad: #ff5c7a;
  --radius: 14px;
  --font: "Comic Relief", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body[data-axis="EW"] { --axis: var(--ew); }
body[data-axis="NS"], body { --axis: var(--ns); }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2 { font-weight: 700; letter-spacing: -.02em; margin: 0; }
h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
.muted { color: var(--muted); }
b { font-weight: 700; }

/* ---- living background ---------------------------------------------------- */
#bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#bg svg { width: 100%; height: 100%; display: block; }
#bg .grat line { stroke: var(--line); stroke-width: .25; }
#bg .grat .eq { stroke: rgba(138, 155, 184, .35); stroke-width: .35; }
#bg .dots circle { fill: #2a3b66; transition: fill .6s, r .6s; }
#bg .dots circle.lit { fill: var(--ns); filter: drop-shadow(0 0 1.5px var(--ns)); }
#bg .dots circle.pulse { animation: pulse .9s ease-out; }
@keyframes pulse { 0% { r: .9; } 40% { r: 4; } 100% { r: .9; } }
#bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(10, 18, 38, .2), rgba(10, 18, 38, .85) 70%);
}

/* ---- layout ---------------------------------------------------------------- */
#app { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 18px calc(40px + var(--banner-h, 0px) + env(safe-area-inset-bottom)); min-height: 100dvh; }
.notice { background: color-mix(in srgb, var(--ew) 15%, var(--bg-2)); border: 1px solid var(--ew); border-radius: var(--radius); padding: 10px 14px; margin-top: 12px; font-size: .95rem; }
.screen { display: none; }
.screen.active { display: block; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.brand { text-align: center; padding: 28px 0 10px; }
.logo { width: 56px; height: 56px; color: var(--ns); display: block; margin: 0 auto 10px; }
.subtitle { margin: 2px 0 0; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; font-size: .8rem; color: var(--ew); }
.tagline { color: var(--muted); margin: 8px 0 0; }

.actions { display: grid; gap: 10px; margin: 22px 0; }
.primary, .secondary {
  border-radius: var(--radius); padding: 16px 18px; font-weight: 700; font-size: 1.1rem;
  display: flex; justify-content: space-between; align-items: center; text-align: left;
}
.primary { background: var(--ns); color: #06121c; }
.primary:active { transform: scale(.98); }
.secondary { background: var(--bg-2); border: 1px solid var(--line); }
.secondary small { font-weight: 400; color: var(--muted); font-size: .85rem; }
.secondary:disabled { opacity: .6; cursor: default; }
.link { color: var(--muted); text-decoration: underline; padding: 6px 0; }
.icon { font-size: 1.2rem; color: var(--muted); padding: 6px 10px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.stats div, .stats .stat-link { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 8px; text-align: center; min-width: 0; }
.stats .stat-link { border-color: var(--ok); cursor: pointer; }
.stats .stat-link:active { transform: scale(.97); }
.stats dd, .stats dt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats dt { font-size: .75rem; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.global { text-align: center; font-size: .85rem; margin: 14px 0 0; }
.settings { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; margin-top: 26px; font-size: .95rem; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .85rem; flex: 1 1 180px; }
.field input { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; color: var(--ink); font-size: 1rem; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.toggle select { background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: .95rem; }
.nick-box { flex: 1 1 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.nick-box p { margin: 0 0 8px; font-size: .9rem; }
.nick-box #nick-msg { margin: 8px 0 0; min-height: 1.2em; }
.nick-box #nick-msg.bad { color: var(--bad); }
.nick-box #nick-msg.ok { color: var(--ok); }
.nick-row { display: flex; gap: 8px; }
.nick-row input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; color: var(--ink); font-size: 1rem; min-width: 0; }
.primary.small { padding: 9px 16px; font-size: 1rem; }
#nick-have { flex: 1 1 100%; margin: 0; }
#nick-have b { color: var(--ink); }
#how { color: var(--muted); font-size: .95rem; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
#challenge { background: var(--bg-2); border: 1px solid var(--axis); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }
#challenge p { margin: 0; }
#challenge .muted { font-size: .85rem; margin-top: 4px; }

/* ---- game ------------------------------------------------------------------ */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 14px; }
.streak { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--axis); }

.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: center;
}
.flag { grid-row: 1 / 3; font-size: 2.2rem; line-height: 1; }
.city { font-weight: 700; font-size: 1.35rem; letter-spacing: -.01em; }
.country { color: var(--muted); font-size: .9rem; }

/* reference city: visible, but quiet */
.ref {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 6px 4px 10px; color: var(--muted); font-size: .95rem;
  border-bottom: 1px dashed var(--line); margin-bottom: 18px;
}
.ref .ref-label { font-size: .8rem; }
.ref .flag { font-size: 1.05rem; grid-row: auto; }
.ref .city { font-size: 1rem; font-weight: 400; color: var(--ink); }
.ref .country { font-size: .8rem; }

/* the city in question: the one thing on screen */
.card.cand {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 22px 16px 20px; border: 2px solid var(--axis);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--axis) 14%, transparent), 0 12px 40px -12px color-mix(in srgb, var(--axis) 45%, transparent);
}
.card.cand .cand-label { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.card.cand .flag { font-size: 3rem; grid-row: auto; }
.card.cand .city { font-size: 2rem; color: var(--axis); margin-top: 6px; line-height: 1.1; }
.card.cand .country { font-size: 1rem; margin-top: 2px; }

.question { text-align: center; margin: 14px 0 0; color: var(--muted); font-size: .95rem; }
.question b { color: var(--ink); }
.question b:first-of-type { color: var(--axis); }

.timer-track { height: 6px; background: var(--bg-2); border-radius: 3px; margin: 18px 0 14px; overflow: hidden; }
.timer { height: 100%; background: var(--axis); transform-origin: left; transform: scaleX(1); will-change: transform; }
.timer.hot { background: var(--bad); }

.answers { display: grid; gap: 10px; }
.answers.ns { grid-template-columns: 1fr; }
.answers.ew { grid-template-columns: 1fr 1fr; }
.answer {
  border-radius: var(--radius); padding: 22px 16px; font-size: 1.5rem; font-weight: 700;
  background: var(--bg-2); border: 2px solid var(--axis); color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 84px;
  transition: background .1s;
}
.answer .arrow { color: var(--axis); font-size: 1.7rem; }
.answer:active { background: color-mix(in srgb, var(--axis) 25%, var(--bg-2)); }

.toast {
  margin: 14px 0 0; min-height: 3.2em; text-align: center; font-size: .95rem; opacity: 0; transition: opacity .15s;
}
.toast.show { opacity: 1; }
.toast.ok { color: var(--ok); }
.toast.bad { color: var(--bad); }
.toast.lap { color: var(--ew); font-weight: 700; }

/* ---- over ------------------------------------------------------------------ */
#screen-over h2 { margin-top: 18px; }
.reveal-wrap { margin: 16px 0 10px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-2); }
.reveal { width: 100%; height: auto; display: block; }
.reveal .grat line { stroke: var(--line); stroke-width: .3; }
.reveal .grat .eq { stroke: rgba(138, 155, 184, .4); }
.reveal .dots circle { fill: #2a3b66; }
.reveal .guide { stroke-width: .5; stroke-dasharray: 2 2; }
.reveal .guide.ok { stroke: var(--ok); }
.reveal .guide.bad { stroke: var(--bad); }
.reveal .city.anchor { fill: var(--ink); }
.reveal .city.cand.ok { fill: var(--ok); }
.reveal .city.cand.bad { fill: var(--bad); }
.reveal .lbl { font-size: 7px; fill: var(--ink); font-family: var(--font); font-weight: 700; paint-order: stroke; stroke: var(--bg); stroke-width: 2px; }
.explain { font-weight: 700; margin: 6px 0; }
.best { margin: 8px 0 0; font-size: 1.1rem; letter-spacing: 2px; }

/* ---- atlas ----------------------------------------------------------------- */
.atlas-wrap { margin: 14px 0 8px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-2); touch-action: manipulation; }
.atlas { width: 100%; height: auto; display: block; }
.atlas .grat line { stroke: var(--line); stroke-width: .3; }
.atlas .grat .eq { stroke: rgba(138, 155, 184, .4); }
.atlas .dots circle { fill: #2a3b66; }
.atlas .lit-city { cursor: pointer; outline: none; }
.atlas .lit-city .hit { fill: transparent; }
.atlas .lit-city .dot { fill: var(--ok); filter: drop-shadow(0 0 1.5px var(--ok)); transition: r .15s; }
.atlas .lit-city:hover .dot, .atlas .lit-city:focus-visible .dot { r: 2.6; }
.atlas .lit-city.picked .dot { r: 3; fill: var(--ink); stroke: var(--ok); stroke-width: 1.2; }
.atlas-pick { min-height: 1.6em; margin: 6px 0 0; font-weight: 700; text-align: center; }
.small { font-size: .85rem; }
.atlas-list-title { font-size: .95rem; color: var(--muted); font-weight: 400; margin: 18px 0 8px; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: .85rem; cursor: pointer; }
.chips li:active, .chips li.on { border-color: var(--ok); }

/* ---- leaderboards ---------------------------------------------------------- */
.tabs { display: flex; gap: 6px; margin: 14px 0; }
.tabs button { flex: 1; padding: 9px 4px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.tabs button.on { color: var(--ink); border-color: var(--ns); }
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: grid; grid-template-columns: 2.2rem 1fr auto; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.board li.me { background: color-mix(in srgb, var(--ns) 12%, transparent); border-radius: 8px; }
.board .rank { color: var(--muted); }
.board .val { font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  #bg .dots circle.pulse { animation: none; }
  .timer { transition: none; }
}
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--ew); outline-offset: 2px; }

/* ---- cookie consent (web only) --------------------------------------------- */
.consent[hidden] { display: none; }   /* the hidden attribute must beat display:flex below */
.consent {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg-2); border-top: 1px solid var(--line);
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: center;
}
.consent p { margin: 0; font-size: .9rem; color: var(--muted); max-width: 420px; }
.consent a { color: var(--ns); }
.consent-actions { display: flex; gap: 8px; }
.consent .primary.small, .consent .secondary.small { padding: 9px 16px; font-size: .95rem; }
