/* A printed-map feel: warm paper, ink, hairline rules, square corners,
   serif names, and plain text controls instead of pills. */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --text: #22201c;
  --muted: #736d62;
  --line: #d9d1c2;
  --rule: #22201c;
  --land: #e7e0d1;
  --state-line: #f6f2ea;
  --dot-empty: #f6f2ea;
  --dot-empty-line: #8f877a;
  --accent: #2f6f4f;
  --tint: #ebe4d6;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Dark: follows the phone's setting unless the theme button has picked one
   (stored as data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #1f1d1a;
    --text: #ebe6dc;
    --muted: #a29b8e;
    --line: #38342d;
    --rule: #ebe6dc;
    --land: #2b2824;
    --state-line: #171614;
    --dot-empty: #171614;
    --dot-empty-line: #898275;
    --accent: #86c4a0;
    --tint: #26231f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171614;
  --surface: #1f1d1a;
  --text: #ebe6dc;
  --muted: #a29b8e;
  --line: #38342d;
  --rule: #ebe6dc;
  --land: #2b2824;
  --state-line: #171614;
  --dot-empty: #171614;
  --dot-empty-line: #898275;
  --accent: #86c4a0;
  --tint: #26231f;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
}

a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* One screen tall: names and map stay put, only the park list scrolls.
   Phones stack them; wide or sideways screens put the list beside the map.
   The page itself is left scrollable (it just has nothing to scroll), so the
   browser's pull-to-refresh still works when dragging down from the top. The
   map and list keep their own drags (touch-action, overscroll-behavior). */
.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1040px;
  margin: 0 auto;
}
@media (min-width: 900px), (orientation: landscape) and (min-width: 600px) {
  .page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(340px, 40%);
    grid-template-rows: auto minmax(0, 1fr);
    max-width: 1440px;
  }
  .chips { grid-column: 1 / -1; }
}

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

/* Who to show: names, the chosen one underlined in its colour. An even
   three-column grid on phones (outer columns flush with the edges), one
   row on wider screens. */
.chips {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: space-between;
  column-gap: 12px;
  padding: max(4px, env(safe-area-inset-top)) 16px 2px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
@media (min-width: 640px) {
  .chips { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 0 24px; }
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.9375rem;
  white-space: nowrap;
  cursor: pointer;
}
.chip .nm {
  padding: 2px 0;
  border-bottom: 2px solid transparent;
}
.chip[aria-pressed="true"] { color: var(--text); }
.chip[aria-pressed="true"] .nm { border-bottom-color: var(--c, var(--rule)); }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.chip .sw.all { background: conic-gradient(var(--stops)); }
.chip .ct { font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--muted); }
@media (min-width: 640px) {
  .chips { border-bottom: 0; padding-top: 8px; }
}
@media (max-width: 359px) {
  .chips { column-gap: 8px; }
  .chip { font-size: 0.875rem; }
}

/* Map: full-bleed on phones, its own pan/zoom surface */
.map-box {
  position: relative;
  height: clamp(260px, 100vw, 60dvh);
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.map-wrap { flex: none; }
@media (min-width: 640px) {
  .map-wrap { padding: 16px 16px 0; }
  .map-box { border: 1px solid var(--line); }
}
@media (min-width: 900px), (orientation: landscape) and (min-width: 600px) {
  .map-wrap { padding: 12px 0 max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .map-box { height: 100%; border: 1px solid var(--line); }
}
#map { display: block; width: 100%; height: 100%; cursor: grab; }
.map-box.dragging #map { cursor: grabbing; }
#map .land { fill: var(--land); }
#map .borders {
  fill: none;
  stroke: var(--state-line);
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.dot { cursor: pointer; }
.dot:focus { outline: none; }
.dot .ring { fill: none; stroke: transparent; stroke-width: 0.4; }
.dot.selected .ring,
.dot:focus-visible .ring { stroke: var(--rule); }
.dot.faded { opacity: 0.4; }
.mark-empty { fill: var(--dot-empty); stroke: var(--dot-empty-line); stroke-width: 0.3; }
.mark-edge { fill: none; stroke: var(--bg); stroke-width: 0.2; }

/* Zoom: one joined block, like the controls on a paper-map app */
.zoom {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
}
.zoom button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  cursor: pointer;
}
.zoom button + button { margin-left: -1px; }
#zoom-reset { margin-right: 6px; }
.zoom button[hidden] { display: none; }
.zoom button:disabled { color: var(--line); cursor: default; }
.zoom svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: square; }

.territories {
  position: absolute;
  left: 12px;
  bottom: 6px;
  display: flex;
  gap: 16px;
}
.terr {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.8125rem;
  cursor: pointer;
}
.terr.selected { color: var(--text); text-decoration: underline; text-underline-offset: 4px; }
.terr.faded { opacity: 0.55; }
svg.mini { width: 11px; height: 11px; flex: none; overflow: visible; }

/* Label for the selected park, pinned next to its dot: a plain tag */
.pop {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  width: max-content;
  max-width: min(240px, calc(100% - 16px));
  padding: 8px 12px 9px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--surface);
  font-size: 0.875rem;
  touch-action: auto;
}
.pop[hidden] { display: none; }
.pop h2 {
  margin: 0 0 4px;
  font: 600 1.0625rem/1.25 var(--serif);
}
.pop h2:focus { outline: none; }
.pop ul { margin: 0 0 5px; padding: 0; list-style: none; }
.pop li { display: flex; align-items: center; gap: 7px; line-height: 1.6; }
.pop li .year { margin-left: auto; padding-left: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pop li.none { color: var(--muted); font-style: italic; }
.pop a { font-size: 0.8125rem; text-underline-offset: 3px; }

/* List: a ledger of names, one line each; the only part that scrolls */
.list-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px 16px 0;
}
@media (min-width: 900px), (orientation: landscape) and (min-width: 600px) {
  .list-wrap { padding: 12px max(16px, env(safe-area-inset-right)) 0 24px; }
}
.list-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--line);
}
/* Sort: a joined two-part toggle like the zoom buttons; the chosen one is filled */
.seg { display: flex; }
.seg button {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.seg button + button { margin-left: -1px; }
.seg button[aria-pressed="true"] {
  position: relative;
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}
/* Light/dark switch: tucked into the empty end of the sort row */
.theme-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 32px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.theme-btn svg { width: 16px; height: 16px; }
.list {
  flex: 1;
  min-height: 0;
  margin: 0 -16px;
  padding: 0 16px env(safe-area-inset-bottom);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}
.list li { border-bottom: 1px solid var(--line); }
.row {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.row.selected { background: var(--tint); box-shadow: -8px 0 0 var(--tint), 8px 0 0 var(--tint); }
.row-text { display: flex; flex: 1; min-width: 0; align-items: baseline; gap: 8px; }
.row-name,
.row-meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name { flex: none; max-width: 100%; font: 1rem/1.35 var(--serif); }
.row-meta {
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.row.faded { opacity: 0.4; }
.pips { display: inline-flex; gap: 3px; flex: none; }
.pip { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }

.error { margin: 16px; color: var(--muted); }
