/* Geography quizzes. The map is an atlas: pale sea, paper land, and the
   six political-map colours that countries take as you name them. */

:root {
  color-scheme: light;
  --sea: #bcd8e8;
  --sea-deep: #a9cbe0;
  --graticule: rgba(255, 255, 255, 0.5);
  --space: #e7edf1;        /* outside the globe */
  --land: #fbf9f3;         /* a country not yet named */
  --land-ctx: #e3e0d8;     /* land outside this quiz */
  --border: #a59d8f;
  --coast: #6f8fa3;
  --ink: #1f3a52;          /* text and outlines */
  --ink-soft: #55697a;
  --paper: #fdfcf9;
  --panel: rgba(253, 252, 249, 0.9);
  --line: #d9dcd9;
  --focus: #1c6fd1;

  --atlas-0: #f2c98f;
  --atlas-1: #b7d79e;
  --atlas-2: #efa9a2;
  --atlas-3: #bcc6ec;
  --atlas-4: #f4e38e;
  --atlas-5: #a8dbd0;

  --c1: #5fb97f;           /* found first try */
  --c2: #f0c43f;           /* second try */
  --c3: #ee8b3a;           /* third try */
  --missed: #d9434f;
  --missed-soft: #f3b8bc;

  --serif: 'Spectral', Georgia, serif;
  --sans: 'Instrument Sans', system-ui, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 58, 82, 0.12), 0 8px 24px rgba(31, 58, 82, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --sea: #12293a;
    --sea-deep: #0f2433;
    --graticule: rgba(140, 180, 210, 0.12);
    --space: #0a1720;
    --land: #2d3d4a;
    --land-ctx: #1d2b36;
    --border: #65788a;
    --coast: #5a87a3;
    --ink: #e5edf3;
    --ink-soft: #a3b4c2;
    --paper: #0f1e29;
    --panel: rgba(15, 30, 41, 0.9);
    --line: #2b3d4b;
    --focus: #7db7ff;
    --atlas-0: #b78a52;
    --atlas-1: #6f9a5c;
    --atlas-2: #b06660;
    --atlas-3: #6d7bb3;
    --atlas-4: #ad9c4a;
    --atlas-5: #4c9a8d;
    --c1: #48a56b;
    --c2: #c9a232;
    --c3: #c8702d;
    --missed: #e0505c;
    --missed-soft: #7a3038;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 18px;
  border: 1px solid var(--ink); border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-soft); filter: none; }
.btn.small { min-height: 30px; padding: 0 12px; font-size: 13px; }

.notice { max-width: 34rem; margin: 18vh auto; padding: 0 16px; }
.notice h1 { font: 500 2rem/1.2 var(--serif); }

/* ---------- the map ---------- */
.map { position: absolute; inset: 0; background: var(--space); overflow: hidden; touch-action: none; }
.map.us { background: var(--sea); }
.map svg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
.map.moving svg { cursor: grabbing; }
.ocean { fill: var(--sea); }
.graticule { fill: none; stroke: var(--graticule); stroke-width: 0.6; vector-effect: non-scaling-stroke; }
.land { fill: var(--land); }
.map.us .land { filter: drop-shadow(0 2px 6px rgba(31, 58, 82, 0.18)); }
.c { fill: none; pointer-events: fill; transition: fill 0.25s; }
.c.ctx { fill: var(--land-ctx); pointer-events: none; }
.c.play { cursor: pointer; }
.c.s-found { fill: var(--atlas); }
.c.s-c1 { fill: var(--c1); }
.c.s-c2 { fill: var(--c2); }
.c.s-c3 { fill: var(--c3); }
.c.s-missed { fill: var(--missed); }
.c.flash-bad { animation: flash-bad 0.7s; }
@keyframes flash-bad { 0%, 60% { fill: var(--missed); } }
.borders { fill: none; stroke: var(--border); stroke-width: 0.7; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.coast { fill: none; stroke: var(--coast); stroke-width: 0.8; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.no-borders .borders { display: none; }
.no-borders .c.ctx { fill: none; }
.outline { fill: none; stroke: var(--ink); stroke-width: 0.9; vector-effect: non-scaling-stroke; pointer-events: none; }
.hover { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; opacity: 0; }
.hover.on { opacity: 1; }
.focusing .c.play:not(.focus) { fill: var(--land); }
.focusing .c.focus { filter: saturate(1.4) brightness(0.97); }

.dot { display: none; cursor: pointer; }
.dot.on { display: inline; }
.dot .hit { fill: transparent; }
.dot .mark { fill: var(--land); stroke: var(--ink); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.dot.s-found .mark { fill: var(--atlas); }
.dot.s-c1 .mark { fill: var(--c1); }
.dot.s-c2 .mark { fill: var(--c2); }
.dot.s-c3 .mark { fill: var(--c3); }
.dot.s-missed .mark { fill: var(--missed); }
.dot:hover .mark { stroke-width: 2.2; }

.labels text {
  display: none;
  font-family: var(--serif); font-weight: 500;
  letter-spacing: 0.08em; font-variant-caps: all-small-caps;
  text-anchor: middle; dominant-baseline: central;
  fill: var(--ink);
  paint-order: stroke; stroke: color-mix(in srgb, var(--land) 75%, transparent); stroke-width: var(--halo); stroke-linejoin: round;
  pointer-events: none;
}
.labels text.on { display: inline; }
.labels text.missed { fill: #fff; stroke: var(--missed); }
.map.moving .labels { opacity: 0.85; }

.pulse { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.pulse.bad { stroke: var(--missed); }

.map-tip {
  position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none;
  margin: 14px 0 0 12px; padding: 3px 9px; border-radius: 6px;
  background: var(--ink); color: var(--paper);
  font: 500 13px/1.4 var(--sans); white-space: nowrap;
}

.zoomctl {
  position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 4;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(8px); overflow: hidden;
}
.zoomctl button { width: 42px; height: 42px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; }
.zoomctl button + button { border-top: 1px solid var(--line); }
.zoomctl button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.zoomctl svg, .back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- home ---------- */
.home { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }
.masthead { padding: 44px 0 20px; max-width: 44rem; }
.masthead h1 { font: 500 clamp(2.2rem, 5vw, 3.4rem)/1.05 var(--serif); margin: 0 0 12px; letter-spacing: -0.01em; }
.masthead p { margin: 0; color: var(--ink-soft); font-size: 1.05rem; max-width: 36rem; }
.hero-map {
  position: relative; aspect-ratio: 1000 / 510; margin: 0 -16px;
  border-radius: 0; overflow: hidden;
}
.hero-map .map { background: var(--paper); }
.hero-map svg { cursor: default; }
.hero-map .c.play { cursor: default; }
@media (min-width: 760px) { .hero-map { margin: 0; } }

.chooser { margin-top: 28px; }
.quizzes { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.quizzes thead td { width: 190px; }
.quizzes thead th { text-align: left; vertical-align: bottom; padding: 0 10px 12px; font-weight: 400; }
.mname { display: block; font: 600 15px/1.3 var(--sans); }
.mblurb { display: block; color: var(--ink-soft); font-size: 13px; line-height: 1.4; margin-top: 3px; }
.quizzes tbody th { text-align: left; padding: 10px 12px 10px 0; font-weight: 400; white-space: nowrap; border-top: 1px solid var(--line); }
.rname { display: block; font: 500 1.3rem/1.2 var(--serif); }
.rcount { display: block; color: var(--ink-soft); font-size: 13px; }
.quizzes td { padding: 6px; border-top: 1px solid var(--line); }
.quizzes thead td { border: 0; }
.cell {
  display: flex; flex-direction: column; justify-content: center;
  min-height: 52px; padding: 8px 14px; border-radius: var(--radius);
  text-decoration: none; background: color-mix(in srgb, var(--sea) 30%, var(--paper));
  border: 1px solid transparent;
}
.cell:hover { border-color: var(--ink); background: color-mix(in srgb, var(--sea) 55%, var(--paper)); }
.cell-mode { display: none; font-weight: 600; font-size: 14px; }
.meta { font-size: 14px; color: var(--ink-soft); }
.cell:hover .meta { color: var(--ink); }
.best { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--c1) 55%, var(--ink)); }
.quizzes tbody tr:hover th .rname { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.foot { margin-top: 40px; color: var(--ink-soft); font-size: 13px; }

@media (max-width: 760px) {
  .quizzes thead { display: none; }
  .quizzes, .quizzes tbody, .quizzes tr, .quizzes th, .quizzes td { display: block; }
  .quizzes tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 14px 0; border-top: 1px solid var(--line); }
  .quizzes tbody th { grid-column: 1 / -1; border: 0; padding: 0 0 4px; }
  .quizzes td { border: 0; padding: 0; }
  .cell { min-height: 56px; }
  .cell-mode { display: block; }
  .meta, .best { font-size: 13px; }
}

/* ---------- quiz ---------- */
.quiz { min-height: 100dvh; display: flex; flex-direction: column; }
.quiz.with-map { position: fixed; inset: 0; overflow: hidden; }
.stage { position: relative; flex: 1; }
.map-stage { position: absolute; inset: var(--bar-h, 64px) 0 0 0; }

.bar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.back { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: var(--ink); flex: none; }
.back:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.titles { min-width: 0; flex: 1; }
.titles h1 { margin: 0; font: 500 1.25rem/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles p { margin: 0; font-size: 13px; color: var(--ink-soft); }
.stats { display: flex; align-items: baseline; gap: 18px; font-variant-numeric: tabular-nums; }
.score { font: 600 1.15rem/1 var(--sans); }
.score .of { font-weight: 400; color: var(--ink-soft); font-size: 0.95rem; }
.time { font: 500 1.15rem/1 var(--sans); min-width: 3.2em; text-align: right; }
.time.low { color: var(--missed); }

.entry {
  position: relative; z-index: 4;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 16px 0;
}
.top { position: sticky; top: 0; z-index: 5; }
.quiz:not(.with-map) .top { background: var(--paper); padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.quiz:not(.with-map) .bar { border-bottom: 0; }
.with-map .top { position: absolute; left: 0; right: 0; pointer-events: none; }
.with-map .top .bar, .with-map .entry > * { pointer-events: auto; }
.answer {
  width: min(420px, 100%); height: 48px; padding: 0 18px;
  border: 1.5px solid var(--ink); border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font: 500 17px var(--sans); box-shadow: var(--shadow);
}
.answer::placeholder { color: var(--ink-soft); }
.answer:focus { outline: none; box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }
.answer:disabled { opacity: 0.6; }
.prompt {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 6px 8px 6px 20px; border-radius: 999px;
  background: var(--paper); border: 1.5px solid var(--ink); box-shadow: var(--shadow);
  max-width: 100%;
}
.prompt:empty { display: none; }
.find { color: var(--ink-soft); font-size: 14px; }
.target { font: 600 1.35rem/1.1 var(--serif); }
.tries { display: inline-flex; gap: 4px; }
.tries i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.tries i.used { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-soft); }
.status {
  margin: 8px 0 0; padding: 3px 12px; border-radius: 999px; min-height: 1.5em;
  font-size: 14px; font-weight: 500; opacity: 0; transition: opacity 0.2s;
  background: var(--panel);
}
.status.show { opacity: 1; }
.status.good { color: color-mix(in srgb, var(--c1) 60%, var(--ink)); }
.status.bad { color: var(--missed); }
.status.dup { color: var(--ink-soft); }

/* board: the no-map quiz */
.board-stage { padding: 18px 16px 64px; }
.board { max-width: 1180px; margin: 0 auto; }
.board.by-continent { columns: 6 170px; column-gap: 22px; }
.board.by-letter { columns: 5 190px; column-gap: 22px; }
.group { break-inside: avoid; margin-bottom: 18px; }
.by-continent .group { break-inside: auto; }
.group h2 { display: flex; align-items: baseline; gap: 8px; margin: 0 0 6px; font: 500 1.2rem/1.2 var(--serif); }
.gcount { font: 400 13px var(--sans); color: var(--ink-soft); }
.group ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.slot {
  height: 28px; padding: 0 10px; border-radius: 6px; display: flex; align-items: center;
  background: color-mix(in srgb, var(--sea) 30%, var(--paper));
  font-size: 14px; break-inside: avoid;
}
.slot span { visibility: hidden; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot.found { background: color-mix(in srgb, var(--c1) 30%, var(--paper)); }
.slot.found span, .slot.missed span { visibility: visible; }
.slot.missed { background: color-mix(in srgb, var(--missed) 18%, var(--paper)); color: var(--missed); }
.slot.found { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(1.06); } }

/* cards: start and result */
.overlay {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--paper) 35%, transparent);
}
.quiz:not(.with-map) .overlay { position: fixed; }
.card {
  width: min(400px, 100%); padding: 24px; border-radius: 16px;
  background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 8px; font: 500 1.6rem/1.2 var(--serif); }
.card p { margin: 0 0 12px; }
.card .hint { color: var(--ink-soft); font-size: 14px; }
.card .btn { margin-top: 6px; }
.result { position: fixed; z-index: 7; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); }
.result .big { font-size: 1.1rem; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.result .big strong { font: 600 2.6rem/1 var(--serif); }
.result .pct { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.legend { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-soft); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .k { width: 12px; height: 12px; border-radius: 3px; }
.k.c1 { background: var(--c1); } .k.c2 { background: var(--c2); } .k.c3 { background: var(--c3); } .k.missed { background: var(--missed); }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; gap: 6px 10px; padding-top: 8px; padding-bottom: 8px; }
  .titles h1 { font-size: 1.05rem; }
  .titles p { font-size: 12px; }
  .stats { gap: 12px; }
  .bar .btn.ghost { min-height: 34px; padding: 0 12px; font-size: 14px; }
  .with-map .entry { padding-top: 10px; }
  .target { font-size: 1.15rem; }
  .result { left: 12px; right: 12px; bottom: 12px; width: auto; }
  .zoomctl { bottom: 16px; }
  .board.by-continent { columns: 2 150px; }
  .board.by-letter { columns: 2 140px; column-gap: 14px; }
  .slot { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.titles .short { display: none; }
@media (max-width: 640px) {
  .titles .long { display: none; }
  .titles .short { display: inline; }
}

/* Minefield: the pointer mustn't show where quiz countries end */
.no-borders svg, .no-borders .c.play, .no-borders .dot { cursor: crosshair; }
/* the status line floats over the map; clicks go through it */
.with-map .entry > .status { pointer-events: none; }
