:root {
  /* One theme for everyone, regardless of system light/dark: "Sagebrush & Ochre".
     Contrast-checked: text pairs ≥ 4.5:1, chart colours pass the dataviz palette checks. */
  --bg: #e5e3d6;        /* sage-grey paper */
  --surface: #f2f0e6;   /* cards, inputs */
  --surface-2: #d9d7c7; /* tracks, inactive fills */
  --ink: #2a2c25;
  --muted: #5e5f53;
  --line: #cdcab9;
  --accent: #8e5f1f;    /* ochre */
  --accent-ink: #ffffff;
  --warm: #81532a;
  --shape: #66704c;     /* boundary fill on the plain Boundary view */
  --precip: #3577b5;
  --temp: #b4532c;
  --win: #4f6b30;
  --radius: 12px;
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Young Serif", ui-serif, Georgia, serif; /* display only: logo, answer, headings (one weight) */
  /* both faces are self-hosted: see css/fonts.css */
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}
a { color: var(--accent); }
img { max-width: 100%; height: auto; display: block; }
button { font: inherit; color: inherit; }
.loading, .load-error { text-align: center; padding: 4rem 1rem; color: var(--muted); }

/* ---------------------------------------------------------------- header */

.top {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.countries { display: flex; gap: 4px; margin-left: auto; }
.countries a {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.countries a[aria-current] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.tools { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  font-weight: 700;
}
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* Phones: one header row, so the coming-soon countries are hidden. */
@media (max-width: 520px) {
  .countries .soon { display: none; }
}

/* ---------------------------------------------------------------- game */

.game { max-width: 1360px; margin: 0 auto; padding: 12px 16px 16px; }

/* Play area: map on the left, hints + guessing on the right, sized so it all fits on one screen.
   The guess box and guess rows never move: the hint card has a fixed share of the height and
   scrolls inside itself, and all five guess rows are always drawn. */
.play { display: grid; gap: 12px; }
.side { display: flex; flex-direction: column; min-width: 0; }
.side > * { flex-shrink: 0; }
.hints { display: flex; flex-direction: column; margin-bottom: 8px; }
.hint-card { overflow-y: auto; }
.map-col .map { margin: 0; }
@media (max-width: 899px) {
  .hint-card { height: 34vh; }
}
/* Phones: the hint card takes what's left of the visible screen (dvh excludes Safari's bars) after the
   header + padding (67px), the 4:3 map, tabs (87px) and the guess box (66px), so the guess box stays above the fold. */
@media (max-width: 520px) {
  .hint-card { height: max(120px, calc(100dvh - 220px - (100vw - 32px) * 3 / 4)); }
}
@media (min-width: 900px) {
  .play {
    --play-h: max(460px, calc(100dvh - 84px));
    grid-template-columns: minmax(0, calc(var(--play-h) * 4 / 3)) clamp(340px, 30vw, 440px);
    justify-content: center;
    gap: 16px;
  }
  /* size containment: the side panel takes the map's height instead of growing the row */
  .side { contain: size; }
  .side > .hints { flex: 1 1 0; min-height: 0; }
  .hints .hint-card { flex: 1 1 0; min-height: 0; }
  .side.done { overflow-y: auto; }
  /* the guess box sits low in the panel, so suggestions open upward over the hint card */
  .side .combo ul { top: auto; bottom: calc(100% + 4px); }
}

.hint-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 8px; } /* 6 tabs, 3 per row */
.hint-tab {
  min-width: 0;
  padding: 5px 6px;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.hint-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 480px) { .brand { font-size: 1.5rem; } }
.hint-tab:disabled { cursor: default; opacity: 0.4; background: transparent; border-style: dashed; }
.hint-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
}
.hint-card h2 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.hint-card p { margin: 0 0 8px; }
.hint-card .note { font-size: 0.75rem; color: var(--muted); text-align: center; margin: 4px 0 0; }

/* map panel: pre-rendered base image + boundary SVG in the same 800×600 frame */
.map {
  position: relative;
  margin: 0 0 10px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  container-type: inline-size;
}
.map img, .map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map .halo { fill: none; }
.map .line { stroke-linejoin: round; }
.map[data-layer="boundary"] .line { fill: var(--shape); stroke: var(--shape); stroke-width: 1px; }
.map[data-layer="topo"] .halo { stroke: rgb(255 255 255 / 0.85); stroke-width: 5px; }
.map[data-layer="topo"] .line { fill: rgb(200 50 30 / 0.07); stroke: #c4321f; stroke-width: 2.25px; }
.map[data-layer="sat"] .halo { stroke: rgb(0 0 0 / 0.55); stroke-width: 5px; }
.map[data-layer="sat"] .line { fill: rgb(255 214 64 / 0.06); stroke: #ffd640; stroke-width: 2.25px; }
.map .scale {
  position: absolute;
  left: 8px;
  bottom: 22px;
  padding: 2px 6px 3px;
  border-radius: 4px;
  background: rgb(255 255 255 / 0.85);
  color: #222;
  font-size: 11px;
  line-height: 1.2;
}
.map .scale i {
  display: block;
  width: calc(var(--f) * 100cqw);
  height: 5px;
  margin-bottom: 2px;
  border: 1.5px solid #222;
  border-top: 0;
}
.map figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  padding: 3px 8px;
  font-size: 9.5px;
  color: #333;
  background: rgb(255 255 255 / 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layer-switch {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  padding: 2px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.88);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.2);
}
.layer-switch button {
  border: 0;
  background: transparent;
  color: #333;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.layer-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.basics { margin: 0; display: grid; gap: 0; font-size: 0.88rem; line-height: 1.35; }
.basics div { display: grid; grid-template-columns: 84px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.basics div:last-child { border: 0; }
.basics dt { color: var(--muted); font-size: 0.8rem; padding-top: 2px; }
.basics dd { margin: 0; }
@media (max-width: 420px) { .basics div { grid-template-columns: 82px 1fr; gap: 8px; } }
.cover-bar { display: flex; height: 6px; margin: 4px 0 2px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.cover-bar .land { background: #b9a77e; }
.cover-bar .lake { background: #6fa8d6; }
.cover-bar .sea { background: #2f5f8f; }
.established { font-size: 1.15rem; margin: 0 0 6px; }
.tidbits { margin: 0; padding-left: 20px; font-size: 1rem; line-height: 1.5; }
.tidbits li { margin-bottom: 8px; }

/* photo carousel: native horizontal scroll with snap, so swiping just works */
.carousel { position: relative; }
/* In the hint card the carousel takes whatever height the card has, so the card never scrolls. */
.hint-card:has(.carousel) { display: flex; flex-direction: column; }
.hint-card .carousel { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.hint-card .slides { flex: 1 1 0; min-height: 0; }
.hint-card .slide img { flex: 1 1 0; min-height: 0; height: 100%; aspect-ratio: auto; }
/* Photos hint: the photo fills the card edge to edge; arrows, counter and species tag float on it,
   and the credit shows on hover (or tap, which focuses the photo). */
.hint-card:has(.carousel) { padding: 0; overflow: hidden; }
.carousel.overlay .slides { border-radius: 0; }
.carousel.overlay .slide { position: relative; outline: none; }
.carousel.overlay figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 12px 8px;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.78));
  color: #eee;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.carousel.overlay .slide:hover figcaption,
.carousel.overlay .slide:focus figcaption { opacity: 1; }
.carousel.overlay .tag, .carousel.overlay .count {
  position: absolute;
  top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}
.carousel.overlay .tag { left: 8px; max-width: calc(100% - 80px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.carousel.overlay .count { right: 8px; font-variant-numeric: tabular-nums; }
.carousel.overlay .car-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
}
.carousel.overlay .car-btn:hover { background: rgb(0 0 0 / 0.7); }
.carousel.overlay .prev { left: 8px; }
.carousel.overlay .next { right: 8px; }
@media (prefers-reduced-motion: reduce) { .carousel.overlay figcaption { transition: none; } }
.slides {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  border-radius: 8px;
  background: #111;
}
.slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; margin: 0; scroll-snap-align: start; display: flex; flex-direction: column; }
.slide img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #111; }
.slide figcaption { padding: 6px 10px 8px; color: #ccc; background: #111; margin: 0; }
.slide figcaption a { color: #ddd; }
.carousel-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 8px; }
.car-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.dots { display: flex; gap: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }

.spark { display: block; width: 100%; overflow: visible; font: 10px var(--font); }
.spark .t-line { fill: none; stroke: var(--temp); stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .dot { fill: var(--temp); stroke: var(--surface); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.spark .bar { fill: var(--precip); }
.spark .base { stroke: var(--line); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.spark .val { fill: var(--ink); font-weight: 600; text-anchor: middle; }
.spark .months text { fill: var(--muted); text-anchor: middle; }
.spark .hit { fill: transparent; }
.spark .hit:hover { fill: var(--ink); fill-opacity: 0.07; }
.climate-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }
.climate-pair figure { margin: 0; min-width: 0; }
.climate-pair figcaption { margin-bottom: 1px; font-size: 0.76rem; line-height: 1.3; color: var(--muted); }
.climate-pair figcaption b { display: block; color: var(--ink); font-size: 0.85rem; font-weight: 600; }
.factsheet .climate-pair { margin-top: 14px; }

figcaption { font-size: 0.72rem; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
figcaption a { color: inherit; }

/* guess input */
.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; }
.combo input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* avoids iOS zoom */
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.combo input:focus { outline: none; border-color: var(--accent); }
.combo ul {
  position: absolute;
  z-index: 5;
  left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
  max-height: 260px;
  overflow-y: auto;
}
.combo ul.up { top: auto; bottom: calc(100% + 4px); }
.combo li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.combo li small { color: var(--muted); white-space: nowrap; }
.combo li[aria-selected="true"] { background: var(--surface-2); }
.primary {
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  cursor: pointer;
}
.form-msg { min-height: 1.2em; margin: 2px 0 4px; font-size: 0.8rem; color: var(--warm); }

/* guess rows */
.guesses { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.guess {
  height: 34px; /* same for empty and filled rows, so nothing shifts as guesses come in */
  display: grid;
  grid-template-columns: 1fr auto 28px 56px;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.9rem;
}
.guess.empty { background: transparent; border-style: dashed; color: var(--muted); font-size: 0.78rem; display: flex; align-items: center; padding: 0 10px; }
.g-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.g-dist { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.g-dir { display: inline-block; text-align: center; font-weight: 700; color: var(--warm); transform: rotate(var(--deg, 0deg)); }
.g-prox {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 6px;
  padding: 2px 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 35%, transparent) var(--p), var(--surface-2) var(--p));
}
.guess.win { border-color: var(--win); }
.guess.win .g-dist { color: var(--win); font-weight: 600; }
@media (max-width: 420px) {
  .guess { grid-template-columns: 1fr auto 20px 48px; gap: 6px; padding: 8px 10px; font-size: 0.88rem; }
}

/* ---------------------------------------------------------------- brochure */

.brochure {
  max-width: 1040px;
  margin: 20px auto 0;
  scroll-margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.result {
  margin-bottom: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.result.won { border-color: var(--win); }
.result-line { margin: 0; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.result.won .result-line { color: var(--win); font-weight: 650; }
.result h2 { margin: 2px 0 0; font-family: var(--serif); font-weight: 400; font-size: 1.5rem; line-height: 1.15; }
.result .sub { margin: 4px 0 12px; color: var(--muted); }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.next { margin: 10px 0 0; color: var(--muted); font-size: 0.85rem; }
.next b { color: var(--ink); font-variant-numeric: tabular-nums; }

.brochure-title { margin: 0; padding: 14px 18px 12px; font-family: var(--serif); font-weight: 400; font-size: 1.6rem; }
.brochure .carousel { padding: 0 0 4px; }
.brochure .slide img { aspect-ratio: 16 / 9; }
.brochure .slides { border-radius: 0; }
.brochure-body {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  padding: 16px 18px;
}
@media (max-width: 640px) { .brochure-body { grid-template-columns: 1fr; } }
/* Phones: unwrap .about so its links can drop below the factsheet, to the bottom of the page. */
@media (max-width: 520px) {
  .brochure-body { gap: 0; }
  .about { display: contents; }
  .factsheet { margin-top: 6px; }
  .brochure-body .links { order: 1; margin-top: 20px; }
}
.about p { margin: 0 0 12px; font-size: 1rem; line-height: 1.6; }
.about h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 8px; }
.about .tidbits { margin-bottom: 14px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.link-btn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font);
  font-size: 0.85rem;
  text-decoration: none;
  background: var(--surface-2);
}
.factsheet dl { margin: 8px 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 0.88rem; }
.factsheet dt { color: var(--muted); }
.factsheet dd { margin: 0; }

/* ---------------------------------------------------------------- ads */

/* Space is reserved up front so a late-loading ad never shifts the board. */
.ad-slot { margin: 18px auto 0; min-height: 100px; max-width: 728px; display: grid; place-items: center; }
.ad-slot[data-slot="result"] { margin: 12px 0 0; min-height: 250px; width: 100%; flex-shrink: 0; }
.ad-slot.is-placeholder {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---------------------------------------------------------------- dialogs, footer */

.dlg {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 20px 22px;
}
.dlg::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg h2 { margin: 0 0 8px; font-family: var(--serif); font-weight: 400; }
.dlg h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; }
.dlg ul { padding-left: 18px; }
.dlg li { margin-bottom: 6px; }
.dlg form { text-align: right; margin-top: 12px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.stat-row b { display: block; font-size: 1.6rem; }
.stat-row span { font-size: 0.75rem; color: var(--muted); }
.dist { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.dist li { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font-size: 0.85rem; }
.dist .bar {
  width: max(var(--w), 24px);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 4px;
  padding: 1px 6px;
  text-align: right;
  font-weight: 600;
}

.foot {
  max-width: 760px;
  margin: 24px auto 0;
  padding: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

/* ---------------------------------------------------------------- landing */

.landing-main { max-width: 760px; margin: 0 auto; padding: 12vh 16px 32px; text-align: center; }
.landing-title { margin: 0; font-family: var(--serif); font-weight: 400; font-size: clamp(2rem, 6vw, 3rem); }
.landing-sub { color: var(--muted); margin: 8px 0 32px; }
.country-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.country-card {
  display: grid;
  gap: 4px;
  padding: 22px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}
.country-card:hover { border-color: var(--accent); }
.country-card.is-last { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.country-card .flag { font-size: 2.2rem; }
.country-card small { color: var(--muted); }
.country-card.soon { opacity: 0.55; filter: grayscale(1); cursor: default; }
.country-card.soon:hover { border-color: var(--line); }
.soon-tag { justify-self: center; margin-top: 4px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.countries .soon { padding: 4px 8px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; opacity: 0.45; filter: grayscale(1); cursor: default; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.coming-soon { max-width: 34rem; margin: 0 auto; padding: 4rem 16px; text-align: center; display: grid; gap: 12px; }
.coming-soon h1 { margin: 0; font-family: var(--serif); font-weight: 400; }
.coming-soon p { margin: 0; color: var(--muted); }
.coming-soon .cta { display: inline-block; margin-top: 8px; padding: 10px 18px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 600; }
