:root {
  --bg: #070b12;
  --panel: rgba(12, 18, 28, 0.86);
  --panel-solid: #0d1420;
  --edge: rgba(255, 255, 255, 0.12);
  --text: #eef3fb;
  --muted: #9aa8bd;
  --accent: #4cc2ff;
  --accent-ink: #04121c;
  --good: #47d18b;
  --warn: #ffc857;
  --bad: #ff6b6b;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --hud-h: 74px;
}

* { box-sizing: border-box; }

/* Several panels below are display:grid/flex, which would otherwise beat the
   `hidden` attribute the game toggles them with. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
  cursor: crosshair;
}
#map.is-idle { cursor: grab; }
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-control-attribution {
  background: rgba(7, 11, 18, 0.7);
  color: var(--muted);
  font-size: 11px;
}
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bar a {
  background: var(--panel-solid);
  color: var(--text);
  border-bottom-color: var(--edge);
}
.leaflet-bar a:hover { background: #16202f; color: var(--text); }

/* Borders toggle: a word, not a glyph — no icon says "administrative
   boundaries" clearly enough to skip the label. */
.borders-btn {
  width: auto !important;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.borders-btn.is-on { background: var(--accent) !important; color: var(--accent-ink) !important; }
.borders-btn.is-loading { opacity: 0.6; pointer-events: none; }

/* ---------- shared bits ---------- */

.panel {
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.btn {
  appearance: none;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) { background: #6fd0ff; }
.btn-block { width: 100%; }
/* The second button under a primary one: available, but not competing with it. */
.btn-quiet {
  margin-top: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 9px 16px;
}
.btn-quiet:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.icon-btn {
  appearance: none;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chrome you click rather than read: a stray double-click or a drag off a
   button would otherwise leave its label highlighted. Prose and the search box
   stay selectable. */
.btn,
.icon-btn,
.hud-label,
.field-label,
.s-row,
.legend,
.summary-actions {
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 800;
  min-height: var(--hud-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(7, 11, 18, 0.92), rgba(7, 11, 18, 0));
}
.hud-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-meta { display: flex; flex-direction: column; min-width: 0; }
.hud-progress { color: var(--muted); font-size: 12px; }
.hud-target { text-align: center; min-width: 0; }
.hud-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 10px;
  color: var(--muted);
}
.hud-place {
  margin: 1px 0 0;
  font-size: clamp(19px, 4vw, 30px);
  line-height: 1.1;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
}
.hud-right { text-align: right; }
.hud-score { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- action bar ---------- */

.actionbar {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.action-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  background: rgba(7, 11, 18, 0.7);
  padding: 5px 12px;
  border-radius: 999px;
}

/* ---------- round result ---------- */

.result {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 850;
  width: min(340px, calc(100vw - 32px));
  text-align: center;
  animation: rise 0.22s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .result { animation: none; }
}
.result-score { display: flex; align-items: baseline; justify-content: center; gap: 7px; }
.result-points {
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.result-outof { color: var(--muted); font-size: 13px; }
.result-verdict { margin: 6px 0 2px; font-weight: 600; }
/* Spacing lives on the button, so the panel keeps its shape whether or not the
   place has a population to show. */
.result-distance { margin: 0; color: var(--muted); font-size: 13px; }
.result-pop { margin: 4px 0 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result .btn { margin-top: 14px; }
.score-good .result-points { color: var(--good); }
.score-mid .result-points { color: var(--warn); }
.score-bad .result-points { color: var(--bad); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(7, 11, 18, 0.6), rgba(7, 11, 18, 0.9));
  overflow-y: auto;
}
.overlay > .panel { width: min(420px, 100%); }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand-pin { font-size: 30px; }
.brand-title { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.brand-title em { font-style: normal; color: var(--accent); }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.field { margin-bottom: 16px; }

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.rounds-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.rounds-label output { color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; }
.slider {
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--accent);
  background: transparent;
  cursor: pointer;
}
.slider:disabled { cursor: default; opacity: 0.45; }

.menu-summary { min-height: 18px; margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.credit { margin: 12px 0 0; text-align: center; font-size: 11px; color: #67748a; }

/* ---------- mode toggle ---------- */

.mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  border-radius: 10px;
}
.mode-btn {
  flex: 1;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.is-on { background: var(--accent); color: var(--accent-ink); }

/* ---------- practice grading ---------- */

.grade-bar { display: flex; gap: 8px; margin-top: 14px; }
.grade-btn { flex: 1; padding: 10px 4px; font-size: 13px; }
.grade-btn.grade-again { border-color: color-mix(in srgb, var(--bad) 55%, var(--edge)); }
.grade-btn.grade-hard { border-color: color-mix(in srgb, var(--warn) 55%, var(--edge)); }
.grade-btn.grade-good { border-color: color-mix(in srgb, var(--good) 55%, var(--edge)); }
.grade-btn.grade-easy { border-color: color-mix(in srgb, var(--accent) 55%, var(--edge)); }
.grade-btn.grade-again:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 22%, transparent); }
.grade-btn.grade-hard:hover:not(:disabled) { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.grade-btn.grade-good:hover:not(:disabled) { background: color-mix(in srgb, var(--good) 22%, transparent); }
.grade-btn.grade-easy:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.grade-tally { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.grade-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}
.grade-chip.grade-again { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.grade-chip.grade-hard { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.grade-chip.grade-good { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.grade-chip.grade-easy { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

/* A practice round is not a button — there is nothing to click through to on
   the map without the focus/peek machinery Quiz's review has — just a
   read-only line coloured by how the grade came out. */
.summary-list .p-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 10px;
  padding: 7px 6px;
  border-top: 1px solid var(--edge);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.summary-list .p-row.grade-again { border-left-color: rgba(255, 107, 107, 0.7); }
.summary-list .p-row.grade-hard { border-left-color: rgba(255, 200, 87, 0.55); }
.summary-list .p-row.grade-good { border-left-color: rgba(71, 209, 139, 0.55); }
.summary-list .p-row.grade-easy { border-left-color: rgba(76, 194, 255, 0.55); }
.summary-list .p-grade { font-weight: 700; text-transform: capitalize; }
.summary-list .p-grade.grade-again { color: var(--bad); }
.summary-list .p-grade.grade-hard { color: var(--warn); }
.summary-list .p-grade.grade-good { color: var(--good); }
.summary-list .p-grade.grade-easy { color: var(--accent); }

/* ---------- summary ---------- */

.summary-title { margin: 0 0 10px; font-size: 20px; }
.summary-total { display: flex; align-items: baseline; gap: 8px; }
.summary-avg { font-size: 44px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-list {
  list-style: none;
  counter-reset: r;
  margin: 16px 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}
.summary-list li {
  counter-increment: r;
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: baseline;
  gap: 10px;
  border-top: 1px solid var(--edge);
  font-size: 13px;
}
.summary-list li::before { content: counter(r); color: var(--muted); font-size: 11px; padding-top: 7px; }
/* Each round is a button: it is how you get to that miss on the map. The band
   colour lives on a hairline down the left rather than on the text, so twenty
   rows do not turn into a traffic light. */
.s-row {
  appearance: none;
  border: 0;
  border-left: 2px solid transparent;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 7px 6px;
  margin: 0 -4px;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.s-row:hover { background: rgba(255, 255, 255, 0.07); }
.s-row.score-good { border-left-color: rgba(71, 209, 139, 0.55); }
.s-row.score-mid { border-left-color: rgba(255, 200, 87, 0.55); }
.s-row.score-bad { border-left-color: rgba(255, 107, 107, 0.7); }
.s-row.is-focus { background: rgba(76, 194, 255, 0.16); }
.s-row.is-focus.score-good { border-left-color: var(--good); }
.s-row.is-focus.score-mid { border-left-color: var(--warn); }
.s-row.is-focus.score-bad { border-left-color: var(--bad); }
.s-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-list .s-dist { color: var(--muted); font-variant-numeric: tabular-nums; }
.summary-list .s-pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-list .s-pts.score-good { color: var(--good); }
.summary-list .s-pts.score-mid { color: var(--warn); }
.summary-list .s-pts.score-bad { color: var(--bad); }

.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.summary-head .summary-title { margin: 0; }

/* ---------- review mode ---------- */

.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { background: rgba(255, 255, 255, 0.11); }
.chip-ghost { color: var(--muted); padding: 5px 11px; font-size: 11px; }
.chip-ghost:hover { color: var(--text); }
.chip-review { margin-top: 12px; }
.chip-review.is-on { border-color: var(--accent); background: rgba(76, 194, 255, 0.16); }
/* Three overlapping dots, the run in miniature. */
.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--bad);
  box-shadow: 6px 0 0 -1px var(--warn), 12px 0 0 -2px var(--good);
  margin-right: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
}
.legend-item, .legend-note { display: inline-flex; align-items: center; gap: 5px; }
.legend-note { gap: 5px; }
.key {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.key-good { background: var(--good); }
.key-mid { background: var(--warn); }
.key-bad { background: var(--bad); }
.key-ring { border: 2px solid var(--muted); background: none; }
.key-fill { background: var(--muted); margin-left: 6px; }

/* Reviewing, and the study screen: the panel steps aside and the map is live
   underneath it. Both are the same shape — a list docked to one side of a map
   you are meant to be looking at. */
.overlay.is-review {
  place-items: start;
  background: linear-gradient(90deg, rgba(7, 11, 18, 0.75), rgba(7, 11, 18, 0) 60%);
  pointer-events: none;
  overflow: visible;
}
.overlay.is-review > .panel {
  pointer-events: auto;
  width: min(330px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  animation: slide-in 0.2s ease-out;
}
.overlay.is-review .summary-list { max-height: none; }
.overlay.is-peeking > .panel { display: none; }
.overlay.is-peeking { background: none; }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay.is-review > .panel { animation: none; }
}

/* The way back to a panel that has been tucked away. */
.peek-btn {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 950;
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.peek-btn:hover { background: #6fd0ff; }
.summary-actions { display: flex; gap: 8px; }
.summary-actions .btn { flex: 1; }

/* ---------- map markers ---------- */

.pin {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45), 0 2px 10px rgba(0, 0, 0, 0.6);
}
.pin-guess { background: var(--accent); }
.pin-actual { background: var(--good); }
/* Review pins. Colour is the round's score; shape is which end of it this is —
   a ring for where you guessed, a solid dot for where the place really is. */
.pin-review {
  border-color: var(--band);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.7);
  transition: opacity 0.2s, transform 0.2s;
}
.pin-review-guess { background: rgba(7, 11, 18, 0.55); }
.pin-review-actual { background: var(--band); }
.review-icon.is-dimmed { opacity: 0.3; }
.review-icon.is-dimmed .pin-label-review { display: none; }
.review-icon.is-focus { z-index: 700 !important; }
.review-icon.is-focus .pin-review { transform: scale(1.35); border-width: 3px; }

.pin-label {
  position: absolute;
  left: 50%;
  top: -22px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(7, 11, 18, 0.85);
  border: 1px solid var(--edge);
}
.pin-label-review {
  top: -20px;
  font-size: 10px;
  color: var(--band);
  border-color: color-mix(in srgb, var(--band) 45%, transparent);
}

@media (max-width: 560px) {
  /* No room beside the map on a phone, so the panel docks to the bottom edge
     instead and keeps the top half of the screen clear for the pins. */
  .overlay.is-review {
    place-items: end stretch;
    background: linear-gradient(0deg, rgba(7, 11, 18, 0.8), rgba(7, 11, 18, 0) 55%);
  }
  .overlay.is-review > .panel { width: 100%; max-height: 52dvh; }
  .overlay.is-review .summary-list { max-height: none; }
  .hud { grid-template-columns: auto 1fr auto; }
  .panel { padding: 16px; }
}
