:root {
  --bg: #0a0f1a;
  --panel: #111827;
  --ink: #e8edf5;
  --muted: #8b95a8;
  --line: #24304a;
  --accent: #ffc857;
  --water: #0e2a47;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}
.top { padding: 14px 20px 8px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.top h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.brand-tld { color: var(--accent); font-weight: 600; }
/* Sits inline beside the wordmark so the desktop header keeps its height; it drops to its own
   line under 600px rather than wrapping raggedly. Never display:none - Google indexes the
   mobile rendering, so hiding it on phones would throw the signal away. */
.brand-tag { font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-left: 6px; }
@media (max-width: 600px) { .brand-tag { display: block; margin: 2px 0 0; font-size: 12px; } }
.top .sub { color: var(--muted); font-size: 14px; flex: 1 1 400px; }
/* align-items:center centres each flex item's BOX, so the 14px .sub and the 20px h1 end
   up on different baselines (.sub rode 3.6px high). Put just the two text items in a
   baseline group - the buttons keep centring, which is what they want. */
.top .brand, .top .sub { align-self: baseline; }
.debug-strip { width: 100%; max-width: 1200px; border: 1px solid var(--line); display: block; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr);
  gap: 0;
  min-height: 0;
}
@media (max-width: 860px) {
  /* Phones: the page scrolls as a whole; the globe takes a fixed share of the screen and the
     results flow underneath at full height (no inner scrolling strip). The stable scrollbar
     gutter matters on narrow DESKTOP windows: picking sets overflow hidden, and without it
     the classic scrollbar's removal widens the canvas and shifts the globe sideways
     (overlay-scrollbar phones are unaffected either way). */
  html { scrollbar-gutter: stable; }
  html, body { height: auto; min-height: 100%; }
  body { display: block; }
  .top { padding: 12px 16px 6px; }
  .top .sub { font-size: 12.5px; }
  .layout { display: block; }
  .globe-wrap { height: 56vh; min-height: 300px; }
  .panel { overflow: visible; border-left: 0; border-top: 1px solid var(--line); padding: 16px 16px 28px; }
  #chart { width: min(100%, 300px); }
  /* Header on phones: wordmark + Share on one line, the hint underneath. */
  .top { gap: 8px 12px; }
  .viewlink-wrap { order: 1; margin-left: auto; }
  .top .sub { order: 2; flex-basis: 100%; }
  /* Jump box and location button share one line: the select shrinks, the button doesn't. */
  .presets { flex-wrap: nowrap; }
  /* flex-basis auto + width, not `1 1 0`: Firefox sizes the dropdown popup from the select's
     flex basis, so a zero basis clipped the option text to the widest option's min width. */
  .presets select { flex: 1 1 auto; width: 100%; min-width: 0; max-width: none; font-size: 12.5px; }
  .presets button.locate { flex: 0 0 auto; font-size: 12px; }
}

.globe-wrap { position: relative; min-height: 420px; }
#globe { width: 100%; height: 100%; display: block; cursor: crosshair; }
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(10,15,26,0.85);
  color: var(--muted);
  font-size: 15px;
}
.overlay[hidden] { display: none; }
.loadbox { width: min(360px, 80%); display: flex; flex-direction: column; gap: 10px; align-items: center; }
#skipTerrain { font: inherit; font-size: 12px; font-weight: 600; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; margin-top: 10px; cursor: pointer; }
#skipTerrain:hover { border-color: var(--accent); }
.progress { width: 100%; height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.15s; }
.presets {
  position: absolute; left: 12px; bottom: 12px; right: 12px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.presets button {
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--ink); background: rgba(17,24,39,0.85);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; cursor: pointer;
}
.presets button:hover { border-color: var(--accent); }
.presets select {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink); background: rgba(17,24,39,0.92);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 32px 6px 12px; cursor: pointer; max-width: min(100%, 420px);
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.presets select:hover { border-color: var(--accent); }
.presets select option, .presets select optgroup { background: #111827; color: var(--ink); font-weight: 400; }
.presets button.locate { margin-left: auto; border-color: #3b82f6; color: #bfdbfe; }
.presets button.locate.on { background: #1d4ed8; color: #fff; }
.presets button.locate[hidden] { display: none; }

/* Compass mode: full-screen overlay, arrow always points the way the phone's top faces. */
.compass {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.compass[hidden] { display: none; }
.compass-close {
  position: absolute; top: 14px; right: 14px;
  width: 44px; height: 44px; border-radius: 50%;
  font: inherit; font-size: 26px; line-height: 1;
  display: grid; place-items: center; padding: 0 0 3px;   /* optically centre the × */
  color: var(--ink); background: var(--panel); border: 1px solid var(--line); cursor: pointer;
}
/* Inside the puzzle card the close button is smaller and the heading keeps clear of it. */
.puzzle-box .compass-close { top: 10px; right: 10px; width: 32px; height: 32px; font-size: 20px; }
.puzzle-box .puzzle-min.compass-close { right: 48px; font-size: 22px; }
.puzzle-title, .puzzle-sub { padding-right: 36px; }
.compass-body { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; max-width: 420px; width: 100%; }
.compass-dial { position: relative; width: min(70vw, 300px); aspect-ratio: 1; }
.compass-ring { position: absolute; inset: 0; width: 100%; height: 100%; transition: transform 0.12s linear; }
.compass-ring .compass-n { fill: var(--accent); font-size: 18px; font-weight: 700; }
.compass-ring .compass-l { fill: var(--muted); font-size: 14px; font-weight: 600; }
.compass-ring .tick { stroke: #3b4661; stroke-width: 2; }
.compass-arrow { position: absolute; inset: 22%; width: 56%; height: 56%; }
.compass-dial.noarrow .compass-arrow { display: none; }
.compass-heading { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.compass-mode { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 4px; }
.compass-mode select { font: inherit; font-size: 12.5px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; cursor: pointer; }
.compass-country { font-size: 24px; font-weight: 700; line-height: 1.25; min-height: 2.5em; }
.compass-note { font-size: 14px; color: var(--muted); max-width: 34ch; }

/* Country labels: HTML overlay projected from the globe each frame. */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  color: #f3f4f6; white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 6px #000, 0 1px 2px #000;
  will-change: transform;
}
.label.big { font-size: 13px; letter-spacing: 0.03em; }
.label[hidden] { display: none; }

/* Tooltip for great-circle paths. */
.tip {
  position: absolute; pointer-events: none; z-index: 2;
  background: rgba(17,24,39,0.95); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 9px; font-size: 12.5px; color: var(--ink); white-space: nowrap;
  transform: translate(12px, 12px);
}
.tip[hidden] { display: none; }
.tip .tip-country { font-weight: 700; }
.tip .tip-meta { color: var(--muted); }

.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 20px 24px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.place .name { font-size: 18px; font-weight: 700; }
.place .coords { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.place .hint { color: var(--muted); }
.viewlink-wrap { display: inline-flex; align-items: center; gap: 10px; margin-left: auto; }
.daily-btn {
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  color: var(--ink); background: transparent; border: 1px solid var(--accent);
  border-radius: 999px; padding: 7px 14px;
}
.daily-btn:hover { background: rgba(255, 200, 87, 0.12); }
.viewlink {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--bg); background: var(--accent); border: 0; border-radius: 999px;
  padding: 6px 14px; cursor: pointer; text-decoration: none; display: inline-block;
}
.viewlink[hidden] { display: none; }
.viewlink:hover:not(:disabled) { filter: brightness(1.08); }
.viewlink:disabled { opacity: 0.45; cursor: default; }
.viewlink-status { font-size: 12.5px; color: var(--muted); word-break: break-all; }

.chart-wrap { display: grid; place-items: center; }
#chart { width: min(100%, 340px); height: auto; }
#chart .ring, #puzzleChart .ring { fill: none; stroke: var(--line); stroke-width: 1; }
#chart .tick, #puzzleChart .tick { stroke: var(--line); stroke-width: 1; }
#chart .tick-label, #puzzleChart .tick-label { fill: var(--muted); font-size: 11px; text-anchor: middle; font-weight: 600; }
#chart .you, #puzzleChart .you { fill: var(--accent); }
#chart .wedge, #puzzleChart .wedge { stroke: none; }
#chart .wedge:hover, #puzzleChart .wedge:hover { opacity: 0.75; }

.legend-count { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--muted); }
.legend-head { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.step-ctl { display: inline-flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.step-ctl:first-of-type { margin-left: auto; }
/* While the puzzle is open the ordinary results panel is noise (and on a phone it sits right
   under the card) - hide it, keeping the globe interactive. */
body.puzzle-open .panel { visibility: hidden; }
.puzzle { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.puzzle-box {
  pointer-events: auto; position: absolute; top: 58px; right: 12px;
  width: min(400px, calc(100vw - 24px)); max-height: calc(100vh - 80px); overflow: auto;
  background: #111827; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
/* Collapsed: everything gives way to a one-line summary bar, so the globe is clear to aim at. */
.puzzle-box.collapsed > :not(.puzzle-mini) { display: none !important; } /* beats #puzzleChart { display: block } */
.puzzle-box.collapsed { padding: 0; overflow: hidden; }
.puzzle-mini {
  display: block; width: 100%; text-align: left; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink);
  background: transparent; border: 0; padding: 11px 14px;
}
.puzzle-mini::after { content: " ▴"; color: var(--muted); }
.puzzle-min { font-size: 22px; }
.puzzle-title { margin: 0 0 4px; font-size: 17px; }
.puzzle-sub { margin: 0 0 8px; color: var(--muted); font-size: 12.5px; }
#puzzleChart { width: min(100%, 300px); display: block; margin: 0 auto; }
#puzzleChart .wedge:hover { opacity: 0.75; }
.puzzle-guesses { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.puzzle-guesses li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.puzzle-guesses .sq { letter-spacing: 1px; }
.puzzle-status { margin: 8px 0 0; font-size: 13px; font-weight: 600; }
.puzzle-wedge { margin: 2px 0 0; min-height: 1.2em; font-size: 12.5px; color: var(--muted); text-align: center; }
#loading .retry {
  margin-top: 12px;
  padding: 8px 22px;
  font: inherit;
  color: var(--ink, #e8edf3);
  background: none;
  border: 1px solid currentColor;
  border-radius: 8px;
  cursor: pointer;
}
.puzzle-actions { display: flex; gap: 8px; margin-top: 10px; }
.puzzle-actions button { font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.puzzle-actions button:hover { border-color: var(--accent); }
@media (max-width: 860px) {
  .puzzle-box { top: auto; bottom: 10px; right: 12px; left: 12px; width: auto; max-height: 45vh; }
  #puzzleChart { width: min(100%, 210px); }
  .puzzle-sub { font-size: 12px; }
}
.layer-status { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; min-width: 3.5ch; }
.step-ctl select { font: inherit; font-size: 12px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; cursor: pointer; }
.legend { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.legend li { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: baseline; font-size: 14px; padding: 3px 6px; margin: 0 -6px; border-radius: 6px; cursor: default; }
.legend li.hl, .legend li:hover { background: rgba(255,200,87,0.12); }
#chart .wedge.hl, #puzzleChart .wedge.hl { stroke: #fff; stroke-width: 1.5; }
.legend .swatch { width: 14px; height: 14px; border-radius: 3px; transform: translateY(2px); }
.legend .country { font-weight: 600; }
.legend .country small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.legend .ranges { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; }
.legend .home .country::after { content: " (home)"; color: var(--accent); font-weight: 400; }
.legend .blocked { color: var(--muted); font-size: 12.5px; }

.note { color: var(--muted); font-size: 12.5px; }
.note-first { border-top: 1px solid var(--line); padding-top: 12px; }
.note strong { color: var(--ink); font-weight: 600; }
.note-h { display: inline; font-size: inherit; font-weight: 600; color: var(--ink); }
.note em { font-style: italic; }
.note a { color: var(--accent); }

/* Narrow layout overrides for the jump select, placed last so they beat the desktop rule above
   (same specificity, later wins). Firefox sizes the dropdown popup from the select box. */
@media (max-width: 480px) {
  /* Mode + Map don't fit beside the heading on a phone: wrap them to their own line. */
  .legend-head { flex-wrap: wrap; row-gap: 6px; }
  .step-ctl:first-of-type { margin-left: 0; }
}
@media (max-width: 860px) {
  .presets { flex-wrap: nowrap; }
  .presets select { flex: 1 1 auto; width: 100%; max-width: none; }
  .presets button.locate { flex: 0 0 auto; }
}

/* ---- Phone results: peek bar + on-demand sheet (desktop keeps the side panel) ---- */
.peek { display: none; }
.sheet-close { display: none; }
@media (max-width: 860px) {
  .peek {
    position: fixed; left: 12px; right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 30;
    display: flex; align-items: center; gap: 10px;
    font: inherit; text-align: left;
    color: var(--ink); background: rgba(17, 24, 39, 0.96);
    border: 1px solid var(--accent); border-radius: 14px;
    padding: 12px 14px; cursor: pointer;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
  .peek[hidden] { display: none; }
  .peek-name { font-weight: 700; font-size: 14px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .peek-count { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
  .peek-chev { color: var(--accent); font-weight: 700; flex: 0 0 auto; }
  .peek.pulse { animation: peekPulse 1.1s ease-out 2; }
  body.puzzle-open .peek { display: none; }

  /* Once something is picked, the peek/sheet owns the results: the in-flow panel below the
     globe disappears (no panel-on-panel). Pre-pick it stays, so Mode/Map/Detail and the
     explainer are still reachable by scrolling. */
  body.has-pick .panel { display: none; }
  /* With the panel gone the page would end mid-screen and the Jump/Locate pills would float
     oddly - let the globe fill the viewport and sit the pills just above the peek bar. */
  body.has-pick { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
  body.has-pick .layout { flex: 1 1 auto; min-height: 0; }
  body.has-pick .globe-wrap { height: 100%; min-height: 0; }
  body.has-pick .presets { bottom: calc(env(safe-area-inset-bottom, 0px) + 78px); }
  body.sheet-open { overflow: hidden; }
  body.has-pick.sheet-open .panel { display: block; }
  body.sheet-open .panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 82vh; overflow-y: auto; z-index: 35;
    border-radius: 16px 16px 0 0; border-top: 1px solid var(--line);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  }
  body.sheet-open .sheet-close {
    display: block;
    position: sticky; top: -16px; z-index: 2;
    width: calc(100% + 32px); margin: -16px -16px 10px;
    font: inherit; font-size: 13px; font-weight: 600;
    color: var(--muted); background: var(--panel);
    border: 0; border-bottom: 1px solid var(--line);
    padding: 12px; cursor: pointer;
  }
}
@keyframes peekPulse {
  0% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(96, 165, 250, 0); }
}

/* ---- FAQ: closed by default so it adds a single line to the panel on every screen ---- */
.faq { font-size: 12.5px; color: var(--muted); }
.faq > summary {
  cursor: pointer; list-style: none; color: var(--accent);
  font-weight: 600; padding: 2px 0;
}
.faq > summary::-webkit-details-marker { display: none; }
/* Border-drawn triangle: no glyph, so it cannot tofu on a device missing the symbol font. */
.faq > summary::before {
  content: ""; display: inline-block; width: 0; height: 0; margin-right: 8px;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-1px); transition: transform 0.15s;
}
.faq[open] > summary::before { transform: translateY(-1px) rotate(90deg); }
.faq > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.faq-body { padding-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.faq-body h3 { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: -6px; }
.faq-body p { color: var(--muted); }
