/* Layout: full-height split. Satellite view fills the left; the panel on the right holds clues
   that scroll and a docked "Pin it" quiz underneath. Stacks to one column on phones. */
:root {
  --bg: #EDF1F1;
  --surface: #F8FAFA;
  --surface-2: #E2E8E8;
  --ink: #12201F;
  --muted: #586A69;
  --line: #CBD5D4;
  --accent: #0B7A75;
  --accent-ink: #FFFFFF;
  --truth: #B86E00;
  --truth-soft: #F5DEB3;
  --sea: #E3EAEB;
  --land: #C9D3D1;
  --land-line: #EDF1F1;
  --good: #1E7A3C;
  --warn: #9A4A12;
  --font-display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1314; --surface: #121C1D; --surface-2: #1A2627; --ink: #E2EBE9; --muted: #8DA19E; --line: #263536;
    --accent: #3CC4BA; --accent-ink: #052120; --truth: #F2B23E; --truth-soft: #3B2C0E;
    --sea: #0F1A1B; --land: #2A3B3C; --land-line: #0F1A1B; --good: #6BD38C; --warn: #F0A274;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

.app {
  height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "stage head" "stage panel";
}

/* ---------- Satellite view ---------- */
.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; background: #3b4a3f; }
.stage iframe, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.stage-note {
  position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); bottom: 16px; right: 16px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; pointer-events: none;
}
.chip-dark {
  pointer-events: auto; background: rgba(8, 14, 14, .76); color: #E8F0EE; backdrop-filter: blur(6px);
  border-radius: 999px; padding: 6px 12px; font-size: 13px;
}
.chip-dark a { color: #9BE7DF; }

/* ---------- Panel ---------- */
.panel { grid-area: panel; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); }
.panel-head {
  padding-block: 14px 12px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  grid-area: head; background: var(--surface); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: grid; gap: 10px;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 28px; letter-spacing: .01em; line-height: 1; }
.actions { display: flex; gap: 6px; }
.actions .btn { padding: 6px 11px; font-size: 14px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.stats { display: flex; gap: 6px 18px; flex-wrap: wrap; align-items: baseline; font-size: 13px; color: var(--muted); }
.stat { display: inline-flex; align-items: baseline; gap: 6px; }
.stat b { font-family: var(--font-display); font-size: 20px; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }

.scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; gap: 14px; align-content: start;
  padding-block: 14px 18px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.eyebrow { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.coords { font-family: var(--font-mono); font-size: 13px; }
.toggle { justify-self: start; display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; user-select: none; }
.toggle small { display: block; font-size: 12px; color: var(--muted); }
.toggle input { flex: none; appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; margin: 0; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.toggle input:checked { background: var(--warn); }
.toggle input:checked::after { transform: translateX(14px); }
.toggle input:disabled { cursor: default; }
.toggle:has(input:disabled) { cursor: default; }

/* ---------- Clues ---------- */
.clues { display: grid; gap: 10px; }
details.clue { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
details.clue > summary { list-style: none; cursor: pointer; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
details.clue > summary::-webkit-details-marker { display: none; }
details.clue > summary::before { content: "›"; font-size: 18px; line-height: 1; color: var(--muted); transition: transform .15s; width: 10px; }
details.clue[open] > summary::before { transform: rotate(90deg); }
.clue-name { font-weight: 600; }
.clue-src { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }
.count { font-family: var(--font-mono); font-size: 12px; background: var(--bg); border-radius: 999px; padding: 1px 8px; color: var(--muted); }
.clue-body { padding: 0 12px 12px; display: grid; gap: 10px; }
.locked-msg { display: none; padding: 0 12px 12px; color: var(--muted); font-size: 13px; }
.clues.hidden-info .clue-body { display: none; }
.clues.hidden-info .locked-msg { display: block; }
/* Errors (with Try again) and "nothing nearby" show even while hidden: there's nothing to give away. */
.clues.hidden-info .clue:has(.error, .empty) .clue-body { display: grid; }
.clues.hidden-info .clue:has(.error, .empty) .locked-msg { display: none; }
.count:empty { display: none; }
.empty, .error { font-size: 13.5px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.error button { margin-left: 6px; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }
.loading { font-size: 13.5px; color: var(--muted); }

.thumb { border-radius: 6px; aspect-ratio: 1; width: 100%; max-width: 100%; object-fit: cover; background: var(--surface-2); display: block; }
.article { display: grid; grid-template-columns: 56px minmax(0,1fr); gap: 10px; align-items: start; }
.article h4 { margin: 0; font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.article h4 a { text-decoration: none; }
.article h4 a:hover { text-decoration: underline; }
.dist { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; font-weight: 400; }
.article p {
  margin: 2px 0 0; font-size: 13.5px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; line-clamp: 3; overflow: hidden;
}

.species { display: grid; grid-template-columns: 40px minmax(0,1fr) auto; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.species:hover b { text-decoration: underline; }
.species .thumb { border-radius: 50%; }
.species b { font-weight: 600; display: block; }
.species i { font-size: 13px; color: var(--muted); }
.obs { font-family: var(--font-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.photos { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.photo { display: grid; gap: 4px; align-content: start; color: inherit; text-decoration: none; min-width: 0; }
.photo .thumb { aspect-ratio: 4 / 3; }
.photo span { font-size: 12.5px; line-height: 1.3; overflow-wrap: anywhere; }
.photo small { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }

.foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); padding-block: 6px calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.foot-links { display: flex; gap: 14px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: inherit; cursor: pointer; text-decoration: underline; }
#credits p { font-size: 14px; color: var(--muted); }

/* ---------- Quiz dock ---------- */
.dock {
  border-top: 1px solid var(--line); background: var(--surface); display: grid; gap: 10px;
  padding-block: 12px 14px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.dock-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.dock-head h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .01em; }
.hint { font-size: 12.5px; color: var(--muted); }
.mapwrap { position: relative; border-radius: 8px; overflow: hidden; background: var(--sea); border: 1px solid var(--line); }
.mapwrap svg { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.mapwrap.zoomed svg { touch-action: none; }
.mapwrap.done svg { cursor: grab; }
.zoom-btns { position: absolute; right: 8px; top: 8px; display: grid; gap: 4px; }
.zoom-btns button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 16px; line-height: 1; padding: 0; }
.map-msg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); padding: 16px; text-align: center; background: var(--sea); }
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 10px; font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-guess { background: var(--accent); }
.dot-truth { background: var(--truth); }
.sphere { fill: var(--sea); }
.graticule { fill: none; stroke: var(--line); stroke-width: .5; vector-effect: non-scaling-stroke; }
.country { fill: var(--land); stroke: var(--land-line); stroke-width: .6; vector-effect: non-scaling-stroke; }
.country.answer { fill: var(--truth-soft); stroke: var(--truth); stroke-width: 1.2; }
.arc { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; opacity: .75; }
.pin-guess { fill: var(--accent); stroke: var(--surface); }
.pin-truth { fill: var(--truth); stroke: var(--surface); }
.guess-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.result { display: grid; gap: 10px; }
.result-title { display: grid; gap: 2px; }
.result-title h3 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.05; text-wrap: balance; }
.result-title .place { font-size: 14px; color: var(--muted); }
.result-title .place b { color: var(--ink); font-weight: 600; }
.result-stats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.result-stats div { background: var(--bg); border-radius: 8px; padding: 6px 10px; min-width: 0; }
.result-stats b { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-stats b.good { color: var(--good); }
.result-stats b.bad { color: var(--warn); }
.result-stats span { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.ext { font-weight: 600; text-decoration: none; font-size: 14px; }
.ext:hover { text-decoration: underline; }

/* ---------- Dialogs ---------- */
dialog.sheet {
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  padding: 20px; width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet::backdrop { background: rgba(8, 14, 14, .55); }
dialog.sheet form { display: grid; gap: 10px; }
dialog.sheet h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1.05; }
dialog.sheet p { margin: 0; }
.sum-total { display: flex; align-items: baseline; gap: 8px; color: var(--muted); }
.sum-total b { font-family: var(--font-display); font-size: 48px; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.sum-note { color: var(--muted); font-size: 14px; }
.sum-rounds { margin: 0; padding: 0; list-style: none; counter-reset: round; display: grid; gap: 4px; }
.sum-rounds li {
  counter-increment: round; display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; column-gap: 8px;
  background: var(--bg); border-radius: 8px; padding: 4px 10px; font-size: 14px; line-height: 1.3; align-items: baseline;
}
.sum-rounds li::before { content: counter(round); grid-row: span 2; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.sum-rounds li > span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-rounds li b { grid-column: 3; grid-row: 1 / span 2; align-self: center; font-family: var(--font-display); font-size: 20px; font-variant-numeric: tabular-nums; }
.sum-detail { grid-column: 2; font-size: 12px; color: var(--muted); }
.sum-mapwrap { position: relative; border-radius: 8px; overflow: hidden; background: var(--sea); border: 1px solid var(--line); }
.sum-mapwrap svg { display: block; width: 100%; height: auto; }
.sum-mapwrap .legend { position: static; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: var(--surface); padding: 4px 10px; }
.round-pin text { font-family: var(--font-mono); font-size: 11px; font-weight: 500; fill: #fff; }
#summary { width: min(560px, calc(100% - 32px)); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); overflow-wrap: anywhere; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  html, body { height: auto; }
  .app { display: block; height: auto; }
  .stage { height: 50vh; min-height: 300px; }
  .panel, .panel-head { border-left: 0; }
  .scroll { overflow: visible; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
