/* GeoLite — survey-chart palette: navy ink, chart paper, hi-vis pin yellow, flag red. */
:root {
  --ink: #13293d;
  --ink-2: #284660;
  --paper: #dce6e1;
  --paper-2: #c9d7d0;
  --contour: #8fa89b;
  --pin: #f5c518;
  --flag: #c8102e;
  --white: #ffffff;

  --font-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.563rem;
  --step-5: clamp(4rem, 15vw, 9.5rem);

  --panel: rgba(19, 41, 61, 0.88);
  --gutter: 16px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

.screen { min-height: 100dvh; position: relative; }

/* ---------- Buttons ---------- */
.btn {
  font: 700 var(--step-0)/1 var(--font-body);
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 0.85rem 1.4rem;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }
.btn:focus-visible, .tabs button:focus-visible, input:focus-visible {
  outline: 3px solid var(--pin);
  outline-offset: 2px;
}
.btn-primary { background: var(--pin); color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: #ffd43b; }
.btn-ink { background: var(--ink); color: var(--white); }
.btn-ink:hover { background: var(--ink-2); }
.btn-ghost { background: transparent; color: inherit; border-color: currentColor; }

.error { color: var(--flag); font-weight: 700; margin: 0.75rem 0 0; }

/* ---------- Start ---------- */
.start {
  background: var(--paper) url("/contours.svg") center / cover no-repeat;
  display: flex;
  align-items: center;
}
.start-inner {
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 3rem var(--gutter);
}
.wordmark {
  font-family: var(--font-display);
  font-size: var(--step-5);
  font-weight: 900;
  font-stretch: 68%;
  font-variation-settings: "wdth" 68;
  line-height: 0.85;
  letter-spacing: -0.01em;
  margin: 0 0 1.25rem;
  color: var(--ink);
}
.lede { font-size: var(--step-1); max-width: 34ch; margin: 0 0 2rem; }
.start-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* Game modes: one card per mode. Colour carries the mode: yellow classic,
   red blitz (time pressure), ink survival, white-outlined daily. */
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.mode-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem;
  text-align: left; cursor: pointer;
  padding: 1rem 1.1rem; border-radius: 14px; border: 2px solid var(--ink);
  font: var(--step--1)/1.35 var(--font-body);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.mode-card:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 4px 0 var(--ink); }
.mode-card:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.mode-card:disabled { cursor: progress; opacity: 0.7; }
.mode-card:focus-visible { outline: 3px solid var(--pin); outline-offset: 2px; }
.mode-name { font: 800 var(--step-1)/1.1 var(--font-display); font-stretch: 85%; font-variation-settings: "wdth" 85; }
.mode-classic { background: var(--pin); color: var(--ink); }
.mode-blitz { background: var(--flag); color: var(--white); border-color: var(--flag); }
.mode-blitz:hover:not(:disabled) { box-shadow: 0 4px 0 #7d0a1d; }
.mode-survival { background: var(--ink); color: var(--white); }
.mode-survival:hover:not(:disabled) { box-shadow: 0 4px 0 var(--ink-2); }
.mode-daily { background: var(--white); color: var(--ink); }

.mode-options { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1rem; }
.mode-options label { display: grid; gap: 0.35rem; font-weight: 700; font-size: var(--step--1); flex: 1 1 12rem; }
.mode-options select, .settings-form select {
  font: var(--step-0) var(--font-body);
  padding: 0.7rem 0.9rem; border-radius: 999px; width: 100%; min-width: 0;
  border: 2px solid var(--ink); background: var(--white); color: var(--ink);
}
.mode-options select:focus-visible { outline: 3px solid var(--pin); outline-offset: 2px; }

@media (max-width: 420px) {
  .mode-card { padding: 0.85rem 0.9rem; }
}
.hint { font-size: var(--step--1); color: var(--ink-2); margin: 0.75rem 0 0; }

.panel {
  margin-top: 2.5rem;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 1.25rem;
}
.panel h2 { font: 800 var(--step-1)/1.2 var(--font-display); font-stretch: 85%; font-variation-settings: "wdth" 85; margin: 0; }
.panel-note { margin: 0.25rem 0 1rem; color: var(--ink-2); }
.board-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

input {
  font: var(--step-0) var(--font-body);
  padding: 0.8rem 1rem; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--white); color: var(--ink);
  min-width: 0;
}

/* Play with friends */
.friends-form label { display: block; font-weight: 700; margin-bottom: 0.4rem; }
.friends-form > input { width: 100%; }
.friends-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.75rem; align-items: center; }
.join-group { display: flex; gap: 0.5rem; flex: 1 1 14rem; }
.code-input {
  flex: 1 1 6rem; width: 6rem;
  font-family: var(--font-display); font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase;
}
.tabs { display: flex; gap: 0.25rem; }
.tabs button {
  font: 700 var(--step--1)/1 var(--font-body);
  background: none; border: 0; color: var(--ink-2);
  padding: 0.5rem 0.75rem; border-radius: 999px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--white); }

.board-list { list-style: none; margin: 1rem 0 0; padding: 0; counter-reset: rank; }
.board-list li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-top: 1px solid var(--paper-2);
}
.board-list li::before { content: counter(rank); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.board-list .score { font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }
.board-list .empty { display: block; border: 0; color: var(--ink-2); }
.board-list .empty::before { content: none; }

/* ---------- Lobby ---------- */
.lobby { background: var(--paper) url("/contours.svg") center / cover no-repeat; }
.lobby-inner { max-width: 40rem; margin: 0 auto; padding: 3rem var(--gutter) 4rem; }
.lobby-kicker { font-size: var(--step-1); margin: 0; color: var(--ink-2); }
.room-code {
  font-family: var(--font-display);
  font-size: clamp(4.5rem, 22vw, 10rem);
  font-weight: 900;
  font-stretch: 70%;
  font-variation-settings: "wdth" 70;
  letter-spacing: 0.06em;
  line-height: 0.9;
  margin: 0 0 1.5rem;
  font-variant-numeric: tabular-nums;
}
.share-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.share-row input { flex: 1 1 14rem; color: var(--ink-2); }

/* Invite: QR code beside the link on wide screens; a button opens it big on phones. */
.invite { display: flex; gap: 1.25rem; align-items: center; }
.invite-main { flex: 1; min-width: 0; }
.invite-note { margin: 0 0 0.6rem; color: var(--ink-2); }
.qr-thumb {
  flex: none; width: 132px; height: 132px; padding: 0;
  border: 2px solid var(--ink); border-radius: 12px; overflow: hidden;
  background: var(--white); cursor: zoom-in;
}
.qr-thumb svg, .qr-big svg { display: block; width: 100%; height: 100%; }
.qr-thumb:focus-visible { outline: 3px solid var(--pin); outline-offset: 2px; }
.btn-qr { display: none; }
.qr-dialog {
  border: 0; border-radius: 18px; padding: 1.5rem;
  width: min(26rem, calc(100vw - 2 * var(--gutter)));
  background: var(--paper); color: var(--ink); text-align: center;
}
.qr-dialog::backdrop { background: rgba(7, 21, 33, 0.7); }
.qr-dialog h2 { font: 800 var(--step-1)/1.2 var(--font-display); margin: 0 0 1rem; }
.qr-dialog h2 span { letter-spacing: 0.08em; }
.qr-big { background: var(--white); border-radius: 12px; overflow: hidden; aspect-ratio: 1; }
.qr-dialog form { margin-top: 1rem; }
.qr-dialog .btn { width: 100%; }

@media (max-width: 600px) {
  .qr-thumb { display: none; }
  .btn-qr:not([hidden]) { display: inline-block; }
  .share-row .btn { flex: 1 1 auto; }
  .lobby-inner { padding-top: 2rem; }
  /* Keep Start / Leave in reach without scrolling past the settings. */
  .lobby-actions {
    position: sticky; bottom: 0; z-index: 10;
    margin: 1.25rem calc(-1 * var(--gutter)) 0;
    padding: 0.75rem var(--gutter) calc(0.75rem + env(safe-area-inset-bottom));
    background: var(--paper); box-shadow: 0 -1px 0 var(--paper-2);
  }
  .lobby-actions .btn { flex: 1 1 0; }
  .lobby-inner { padding-bottom: 0; }
}
.join-form { margin-top: 2rem; }
.join-form label { display: block; font-weight: 700; margin-bottom: 0.4rem; }
.player-list { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.player-list li {
  display: grid; grid-template-columns: 1rem 1fr auto; gap: 0.75rem; align-items: center;
  padding: 0.5rem 0; border-top: 1px solid var(--paper-2);
}
.player-list li.away { color: var(--ink-2); }
.player-list .name { font-weight: 700; }
.player-list .tags { color: var(--ink-2); font-size: var(--step--1); }
.lobby-hint { color: var(--ink-2); margin: 1.25rem 0 0; }
.settings-form fieldset {
  border: 0; padding: 0; margin: 0; min-width: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 1rem 0.75rem;
}
.settings-form label { display: grid; gap: 0.4rem; font-weight: 700; }
.settings-form select:focus-visible, .settings-form input:focus-visible { outline: 3px solid var(--pin); outline-offset: 2px; }
.settings-form fieldset:disabled select { opacity: 0.75; cursor: default; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.dot { width: 0.9rem; height: 0.9rem; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 2px rgba(19, 41, 61, 0.2); }

/* ---------- Play ---------- */
.play { background: #071521; overflow: hidden; height: 100dvh; }
.photo-wrap { position: absolute; inset: 0; overflow: hidden; cursor: zoom-in; }
.photo-wrap.zoomed { cursor: zoom-out; }
#photo {
  width: 100%; height: 100%;
  object-fit: contain;
  user-select: none;
  transition: transform 0.25s ease;
}
.pano { position: absolute; inset: 0; }
/* Frozen (NMPZ): the view can't be dragged, scrolled or clicked. */
.pano.frozen { pointer-events: none; }
.btn-return {
  position: absolute; top: var(--gutter); right: var(--gutter); z-index: 400;
  padding: 0.6rem 1rem; font-size: var(--step--1); background: var(--panel);
}
.pano:not([hidden]) ~ .zoom-hint { display: none; }
.photo-status {
  position: absolute; inset: 0; margin: auto; height: fit-content;
  text-align: center; color: var(--paper); font-size: var(--step-1);
  padding: 0 var(--gutter);
}

.hud {
  position: absolute; top: var(--gutter); left: var(--gutter); z-index: 400;
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  pointer-events: none;
}
.hud-chip {
  background: var(--panel); color: var(--white);
  border-radius: 10px; padding: 0.45rem 0.8rem;
  display: flex; flex-direction: column; line-height: 1.15;
}
.hud-label { font-size: 0.75rem; color: var(--paper-2); }
.hud-value { font: 800 var(--step-1)/1.1 var(--font-display); font-stretch: 80%; font-variation-settings: "wdth" 80; font-variant-numeric: tabular-nums; }
.hud-timer.low .hud-value { color: var(--pin); }
.hud-lives .hud-value { color: #ff6b7d; letter-spacing: 0.05em; font-stretch: 100%; font-variation-settings: "wdth" 100; }
.hud-lives.low .hud-value { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.45; } }

.zoom-hint {
  position: absolute; left: var(--gutter); bottom: var(--gutter); margin: 0;
  color: var(--paper-2); font-size: var(--step--1);
  background: var(--panel); border-radius: 999px; padding: 0.35rem 0.8rem;
  pointer-events: none;
}

.guess-panel {
  position: absolute; right: var(--gutter); bottom: var(--gutter);
  width: 320px;
  display: flex; flex-direction: column; gap: 0.5rem;
  transition: width 0.2s ease;
  z-index: 500;
}
.guess-map {
  height: 220px; border-radius: 12px; overflow: hidden;
  border: 2px solid var(--ink);
  transition: height 0.2s ease;
  opacity: 0.85;
}
.map-slot { position: relative; background: #cad7d6; }
.map-host { position: absolute; inset: 0; }
.map-missing {
  display: grid; place-items: center; text-align: center;
  padding: 1rem; color: var(--ink); font-size: var(--step--1);
}
.map-slot .mapboxgl-canvas { cursor: crosshair; }
#result-map .mapboxgl-canvas, #end-map .mapboxgl-canvas { cursor: grab; }
.guess-panel:hover, .guess-panel:focus-within, .guess-panel.pinned { width: min(640px, calc(100vw - 2 * var(--gutter))); }
.guess-panel:hover .guess-map, .guess-panel:focus-within .guess-map, .guess-panel.pinned .guess-map { height: min(440px, 60dvh); opacity: 1; }
.btn-guess { width: 100%; border-radius: 12px; }
.map-toggle { display: none; }

@media (max-width: 720px), (hover: none) {
  .zoom-hint { display: none; }
  /* The HUD fills the top row on phones; move "Back to start" under it. */
  .hud { right: var(--gutter); gap: 0.4rem; top: calc(var(--gutter) + env(safe-area-inset-top)); }
  .hud-chip { padding: 0.35rem 0.6rem; }
  .btn-return { top: calc(var(--gutter) + env(safe-area-inset-top) + 3.6rem); }
  .map-toggle {
    display: block; position: absolute; right: var(--gutter); bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
    z-index: 600;
  }
  .guess-panel {
    left: 0; right: 0; bottom: 0; width: auto !important;
    padding: var(--gutter); padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    background: var(--panel);
    border-radius: 16px 16px 0 0;
    transform: translateY(105%);
    transition: transform 0.25s ease;
  }
  .guess-panel.open { transform: none; }
  .guess-map { height: 55dvh !important; opacity: 1; }
}

/* ---------- Result & end ---------- */
.result { height: 100dvh; display: grid; grid-template-rows: 1fr auto; }
.result-map { min-height: 0; }
.result-sheet {
  background: var(--ink); color: var(--white);
  padding: 1.25rem var(--gutter) calc(1.25rem + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem 2rem;
}
.result-figure { display: flex; align-items: baseline; gap: 0.6rem; }
.big-number {
  font-family: var(--font-display);
  font-weight: 900;
  font-stretch: 62%;
  font-variation-settings: "wdth" 62;
  font-size: clamp(3.5rem, 11vw, 6.5rem);
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  color: var(--pin);
}
.big-unit { font-size: var(--step-1); color: var(--paper-2); }
.result-detail { margin: 0; font-size: var(--step-1); }
.result-next { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.result-wait { margin: 0; color: var(--paper-2); font-size: var(--step--1); font-variant-numeric: tabular-nums; }
.result-board {
  grid-column: 1 / -1; list-style: none; margin: 0.25rem 0 0; padding: 0;
  max-height: 28dvh; overflow-y: auto;
}
.result-board li {
  display: grid; grid-template-columns: 1rem 1fr auto 5rem; gap: 0.75rem; align-items: center;
  padding: 0.4rem 0; border-top: 1px solid var(--ink-2);
}
.result-board li.me .name { color: var(--pin); }
.result-board .d { color: var(--paper-2); font-variant-numeric: tabular-nums; }
.result-board .pts { text-align: right; font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }
.meter { grid-column: 1 / -1; height: 6px; background: var(--ink-2); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--pin); transition: width 0.6s ease-out; }
@media (max-width: 720px) {
  .result-sheet { grid-template-columns: 1fr; }
  .result-sheet .btn { width: 100%; }
  .result-next { align-items: stretch; }
}

.end { background: var(--paper) url("/contours.svg") center / cover no-repeat; }
.end-inner { max-width: 44rem; margin: 0 auto; padding: 2.5rem var(--gutter) 4rem; }
.end-kicker { font-size: var(--step-1); margin: 0 0 0.25rem; }
.end .big-number { color: var(--ink); }
.end .big-unit { color: var(--ink-2); }
.end-map { height: 320px; border-radius: 14px; border: 2px solid var(--ink); margin: 1.5rem 0 1rem; overflow: hidden; }
.standings { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.standings li {
  display: grid; grid-template-columns: 2rem 1rem 1fr auto; gap: 0.75rem; align-items: center;
  padding: 0.6rem 0; border-top: 1px solid var(--paper-2); counter-increment: place;
  font-size: var(--step-1);
}
.standings { counter-reset: place; }
.standings li::before { content: counter(place); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.standings li.me .name { font-weight: 700; }
.standings .pts { font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }
.round-list { list-style: none; padding: 0; margin: 0 0 2rem; }
.round-list li {
  display: grid; grid-template-columns: 5rem 1fr auto; gap: 0.75rem;
  padding: 0.55rem 0; border-top: 1px solid var(--paper-2);
}
.round-list .r { color: var(--ink-2); }
.round-list .pts { font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }

.save-form label { display: block; font-weight: 700; margin-bottom: 0.4rem; }
.save-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.save-row input { flex: 1 1 12rem; }
.saved { font-size: var(--step-1); font-weight: 700; }
.end-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 2rem; }

/* ---------- Map markers ----------
   Mapbox positions the wrapper with its own transform, so the rotated teardrop
   lives inside it. The wrapper's bottom edge is the pin's tip. */
.pin-wrap { --s: 22px; width: var(--s); height: calc(var(--s) * 1.21); pointer-events: none; }
.pin-wrap-lg { --s: 28px; }
.pin {
  width: var(--s); height: var(--s); border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--pin-color, var(--pin));
  border: 3px solid var(--ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); font: 800 0.8rem/1 var(--font-body); }
.pin-me { border-color: var(--white); outline: 2px solid var(--ink); }
.pin-actual { background: var(--flag); border-color: var(--white); }
.mapboxgl-map { font-family: var(--font-body); }

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