/* ============================================================
   The Dataset Atlas — token-driven theme (light-first)
   Palettes validated with the data-viz six-checks validator;
   the dark theme is a token override block, not a second stylesheet.
   ============================================================ */
:root {
  --bg: #eef2f6;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --panel-border: rgba(15, 27, 42, 0.1);
  --text: #16212e;
  --muted: #5b6673;
  --accent: #0e7490;            /* keep in sync with THEMES.light in js/config.js (CI-tested) */
  --accent-rgb: 14, 116, 144;
  --accent-dim: #1290b4;
  --danger: #d03b3b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(23, 36, 52, 0.12);
  --topbar-h: 58px;
  --right-panel-max: 400px; /* widest right-edge panel; the global pill offsets past it */

  --topbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.82));
  --stage-inner: #f6f9fb;
  --stage-outer: #e7edf3;
  --map-ocean: #e9f0f6;
  --map-country-stroke: rgba(255, 255, 255, 0.85);
  --map-graticule: rgba(23, 36, 52, 0.07);
  --node-text-halo: rgba(255, 255, 255, 0.88);
  --node-core-stroke: rgba(255, 255, 255, 0.95);

  --chip-bg: rgba(15, 27, 42, 0.04);
  --input-bg: rgba(15, 27, 42, 0.03);
  --hover-wash: rgba(15, 27, 42, 0.05);
  --card-bg: rgba(255, 255, 255, 0.75);
  --scroll-thumb: rgba(15, 27, 42, 0.18);

  --btn-primary-bg: var(--accent);
  --btn-primary-text: #ffffff;
  --btn-primary-border: transparent;
  --btn-primary-hover: #0b5e75;
}

:root[data-theme="dark"] {
  --bg: #070b14;
  --panel: rgba(13, 20, 36, 0.86);
  --panel-solid: #0d1424;
  --panel-border: rgba(148, 163, 184, 0.14);
  --text: #e6edf7;
  --muted: #8b98ad;
  --accent: #38e1ff;            /* keep in sync with THEMES.dark in js/config.js (CI-tested) */
  --accent-rgb: 56, 225, 255;
  --accent-dim: #1799b8;
  --danger: #fb7185;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);

  --topbar-bg: linear-gradient(180deg, rgba(7, 11, 20, 0.92), rgba(7, 11, 20, 0.75));
  --stage-inner: #0c1526;
  --stage-outer: #070b14;
  --map-ocean: #0a1120;
  --map-country-stroke: rgba(7, 11, 20, 0.85);
  --map-graticule: rgba(148, 163, 184, 0.07);
  --node-text-halo: rgba(7, 11, 20, 0.85);
  --node-core-stroke: rgba(230, 237, 247, 0.85);

  --chip-bg: rgba(148, 163, 184, 0.06);
  --input-bg: rgba(7, 11, 20, 0.6);
  --hover-wash: rgba(148, 163, 184, 0.1);
  --card-bg: rgba(7, 11, 20, 0.55);
  --scroll-thumb: rgba(148, 163, 184, 0.2);

  --btn-primary-bg: rgba(var(--accent-rgb), 0.14);
  --btn-primary-text: var(--accent);
  --btn-primary-border: rgba(var(--accent-rgb), 0.4);
  --btn-primary-hover: rgba(var(--accent-rgb), 0.25);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

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

:is(button, a, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============ Icons ============ */
.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  vertical-align: -2px;
}
/* the signature duotone under-layer: a soft fill beneath the strokes */
.icon .duo {
  fill: currentColor;
  stroke: none;
  opacity: 0.16;
}
.brand-mark .icon .duo { opacity: 0.38; }
.chip .icon { width: 13px; height: 13px; color: var(--chip-color, currentColor); }
.badge .icon { width: 11px; height: 11px; }
.tt-domain .icon { width: 11px; height: 11px; }
.brand-mark .icon {
  width: 17px;
  height: 17px;
  color: var(--panel-solid);
}
.pin-btn .icon { width: 14px; height: 14px; }
.pin-btn.pinned .icon { color: var(--accent); fill: rgba(var(--accent-rgb), 0.25); }
.get-btn .icon { width: 12px; height: 12px; }
.rail-header h2 .icon { width: 17px; height: 17px; color: var(--accent); vertical-align: -3px; }
#rail-close .icon, #passport-close .icon { width: 15px; height: 15px; }
.passport-item .pi-icon .icon { width: 16px; height: 16px; }
.passport-item button .icon { width: 13px; height: 13px; }
#rail-collapse .icon { width: 13px; height: 13px; }
#theme-toggle .icon { width: 15px; height: 15px; }
.search-wrap > [data-icon] {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  color: var(--muted);
  pointer-events: none;
}
.search-wrap > [data-icon] .icon { width: 14px; height: 14px; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ============ Top bar ============ */
#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 16px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--panel-border);
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.35);
}
.brand-text h1 { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; white-space: nowrap; }
.brand-text p { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ============ Domain dock ============
   A floating glass bar over the map: every domain is always visible as
   icon + live count; the active or hovered chip expands its label. */
#domain-dock {
  position: absolute;
  top: calc(var(--topbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  max-width: calc(100vw - 560px);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  z-index: 25;
}
#domain-dock::-webkit-scrollbar { display: none; }

.dock-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.dock-chip .icon { width: 15px; height: 15px; color: var(--chip-color, currentColor); }
.dock-chip .dock-label {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  font-weight: 600;
  transition: max-width 0.22s ease, opacity 0.16s ease;
}
.dock-chip:hover .dock-label,
.dock-chip:focus-visible .dock-label,
.dock-chip.active .dock-label { max-width: 110px; opacity: 1; }
.dock-chip:hover { background: var(--hover-wash); color: var(--text); }
.dock-chip.active {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 13%, transparent);
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 55%, transparent);
  color: var(--text);
}
.dock-chip .chip-count {
  font-size: 10.5px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--hover-wash);
  color: var(--muted);
  font-weight: 600;
}
.dock-chip.active .chip-count {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 18%, transparent);
  color: color-mix(in srgb, var(--chip-color, var(--accent)) 75%, var(--text));
}

/* quiet ghost chips; only the ACTIVE domain wears its color — the strip
   reads as one calm toolbar instead of nine competing outlined boxes */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.chip:hover { background: var(--hover-wash); color: var(--text); transform: translateY(-1px); }
.chip.active {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 13%, transparent);
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 55%, transparent);
  color: var(--text);
  font-weight: 600;
}
.chip .chip-count {
  font-size: 10.5px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--hover-wash);
  color: var(--muted);
  font-weight: 600;
}
.chip.active .chip-count {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 18%, transparent);
  color: color-mix(in srgb, var(--chip-color, var(--accent)) 75%, var(--text));
}

.top-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.proj-toggle {
  display: flex;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
}
.proj-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--chip-bg);
}
.proj-toggle .icon { width: 13px; height: 13px; }
.proj-toggle [data-icon] { display: inline-flex; }
.proj-toggle button.active { background: rgba(var(--accent-rgb), 0.15); color: var(--accent); font-weight: 600; }

#theme-toggle,
#passport-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 12.5px;
  background: var(--chip-bg);
  transition: border-color 0.15s, transform 0.15s;
}
#theme-toggle { padding: 6px 8px; }
#theme-toggle:hover, #passport-btn:hover { border-color: var(--accent); transform: translateY(-1px); }

.count-badge {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* ============ Left rail ============ */
#left-rail {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 12px;
  bottom: 12px;
  width: 248px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
  display: flex;
  flex-direction: column;
  visibility: visible;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0s;
}
#left-rail.collapsed {
  transform: translateX(-270px);
  opacity: 0;
  pointer-events: none;
  visibility: hidden; /* also removes it from tab order / a11y tree */
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0.25s;
}

#rail-collapse {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: var(--muted);
}
#rail-collapse:hover { background: var(--hover-wash); color: var(--text); }

#rail-expand {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 12px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}
#rail-expand:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }

.rail-inner { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 16px; }
.rail-inner::-webkit-scrollbar { width: 8px; }
.rail-inner::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }

.rail-section h3 {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 8px;
}

.search-wrap { position: relative; }
#search-input {
  width: 100%;
  padding: 8px 10px 8px 30px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent-dim); }
#search-input::placeholder { color: var(--muted); }

#preset-list { display: flex; flex-direction: column; gap: 5px; }
.preset-wrap { display: flex; flex-direction: column; gap: 4px; }
.preset {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--chip-bg);
  font-size: 12.5px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.preset:hover { border-color: var(--accent-dim); background: rgba(var(--accent-rgb), 0.08); transform: translateY(-1px); }
.preset.active { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.12); }
.preset small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.bundle-btn {
  align-self: flex-start;
  margin-left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--btn-primary-border);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-size: 11px;
  font-weight: 700;
  transition: background 0.15s, transform 0.15s;
}
.bundle-btn:hover { background: var(--btn-primary-hover); transform: translateY(-1px); }

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text);
  user-select: none;
  border-radius: 6px;
}
.filter-row:hover { background: var(--hover-wash); }
.filter-row input { accent-color: var(--accent); cursor: pointer; }
.filter-row .filter-count { margin-left: auto; color: var(--muted); font-size: 11px; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }
#license-label { font-size: 11.5px; color: var(--muted); min-width: 52px; text-align: right; }

.rail-footnote { border-top: 1px solid var(--panel-border); padding-top: 12px; }
#tally { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
#catalog-stamp { font-size: 10.5px; color: var(--muted); opacity: 0.8; margin: -4px 0 8px; }
.footnote-row { display: flex; gap: 6px; }
#reset-filters, #about-link {
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--panel-border);
  padding: 5px 10px;
  border-radius: 8px;
  transition: border-color 0.15s, color 0.15s;
}
#reset-filters:hover, #about-link:hover { color: var(--text); border-color: var(--accent-dim); }

#changes-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s;
}
#changes-pill:hover { background: rgba(var(--accent-rgb), 0.16); }
#changes-pill.active { background: var(--accent); color: var(--panel-solid); }
#changes-pill .icon { width: 12px; height: 12px; }

/* ============ Map stage ============ */
#stage {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 44%, var(--stage-inner) 0%, var(--stage-outer) 70%);
}
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.country { stroke: var(--map-country-stroke); stroke-width: 0.5; transition: fill 0.3s ease; }
.region-hover .country:not(.hovered-region) { opacity: 0.45; }
.country.hovered-country { stroke: var(--accent); stroke-width: 1.2; }

.graticule { fill: none; stroke: var(--map-graticule); stroke-width: 0.5; }
.sphere-fill { fill: var(--map-ocean); }
.sphere-glow { fill: none; stroke: rgba(var(--accent-rgb), 0.25); stroke-width: 1.5; }

.region-node { cursor: pointer; }
.region-node circle.halo {
  pointer-events: none;
  animation: halo-pulse 3.2s ease-in-out infinite;
}
@keyframes halo-pulse {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.26; }
}
.region-node circle.core {
  stroke: var(--node-core-stroke);
  stroke-width: 1.2;
}
.region-node text {
  fill: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--node-text-halo);
  stroke-width: 3px;
}
.region-node .count-badge rect {
  fill: var(--panel-solid);
  stroke-width: 1.4;
  filter: drop-shadow(0 1px 3px rgba(23, 36, 52, 0.18));
}
.region-node .count-badge text {
  fill: var(--text);
  font-size: 10.5px;
  font-weight: 700;
  text-anchor: middle;
  stroke: none;
  pointer-events: none;
}
.region-node.selected circle.core { stroke: var(--accent); stroke-width: 2; }
.region-node:focus { outline: none; }
.region-node:focus-visible circle.core { stroke: var(--accent); stroke-width: 2.5; }

#global-pill {
  position: absolute;
  top: calc(var(--topbar-h) + 12px);
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 20;
  transition: border-color 0.15s, right 0.2s ease, transform 0.15s;
}
#global-pill:hover { transform: translateY(-1px); }
#global-pill:hover, #global-pill.selected { border-color: var(--accent); }
@media (min-width: 700px) {
  /* keep it clickable beside whichever right panel is open (12px inset + panel + 12px gap) */
  body.rail-open #global-pill { right: calc(var(--right-panel-max) + 24px); }
}

#legend {
  position: absolute;
  right: 12px;
  bottom: 16px;
  width: 200px;
  padding: 9px 12px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  z-index: 21; /* above the hint, never underneath it */
  transition: right 0.2s ease;
}
@media (min-width: 700px) {
  /* slide clear of an open right panel, like the global pill */
  body.rail-open #legend { right: calc(var(--right-panel-max) + 24px); }
}
.legend-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-ramp {
  height: 7px;
  border-radius: 4px;
  /* gradient is set by MapView from the same ramp that paints the map */
}
.legend-ends {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  opacity: 0.75;
  margin-top: 4px;
}

#hint {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(60vw, 340px);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.4s;
  z-index: 20;
}
#hint.hidden { opacity: 0; }

#tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 240px;
}
#tooltip .tt-title { font-weight: 700; margin-bottom: 2px; }
#tooltip .tt-sub { color: var(--muted); font-size: 11px; }
#tooltip .tt-stats { display: flex; gap: 14px; margin-top: 6px; }
#tooltip .tt-stat b { display: block; font-size: 15px; line-height: 1.1; color: var(--accent); }
#tooltip .tt-stat span { font-size: 10px; color: var(--muted); }
#tooltip .tt-hint {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--panel-border);
  font-size: 10px;
  color: var(--muted);
}
#tooltip .tt-domains { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
#tooltip .tt-domain {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
}

/* ============ Right card rail ============ */
#card-rail {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 12px;
  bottom: 12px;
  width: 372px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 35;
  display: flex;
  flex-direction: column;
  animation: slide-in 0.22s ease;
}
@keyframes slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.rail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--panel-border);
}
.rail-header h2 { display: flex; align-items: center; gap: 7px; font-size: 16px; }
.rail-header p { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.rail-header button {
  display: grid;
  place-items: center;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
}
.rail-header button:hover { background: var(--hover-wash); color: var(--text); }

#rail-domain-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--panel-border);
}
#rail-domain-breakdown .chip { font-size: 11px; padding: 3px 9px; height: auto; }

#rail-tools {
  display: flex;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--panel-border);
}
.rail-tool { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.rail-tool > span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  flex-shrink: 0;
}
.rail-tool select {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 4px 6px;
}

#card-list {
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#card-list::-webkit-scrollbar { width: 8px; }
#card-list::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }
.empty-note { color: var(--muted); font-size: 12.5px; text-align: center; padding: 30px 10px; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 16px; }
.empty-state .empty-note { padding-bottom: 0; }
.active-filter-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--chip-bg);
  color: var(--text);
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s;
}
.filter-chip .icon { width: 11px; height: 11px; }
.filter-chip:hover { border-color: var(--danger); color: var(--danger); }
.filter-chip.reset-all { border-color: rgba(var(--accent-rgb), 0.5); color: var(--accent); }
.filter-chip.reset-all:hover { background: rgba(var(--accent-rgb), 0.1); }

.card-group-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 2px -2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.card-group-label span {
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  letter-spacing: 0;
}
.card-group-label::after { content: ""; flex: 1; height: 1px; background: var(--panel-border); }

/* ---- Dataset card ---- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover {
  border-color: rgba(var(--accent-rgb), 0.45);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(23, 36, 52, 0.1);
}

.card-top { display: flex; align-items: flex-start; gap: 4px; }
.card-title { font-size: 13px; font-weight: 600; line-height: 1.35; flex: 1; margin-right: 4px; }
.card-icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s;
}
.card-icon-btn:hover { opacity: 1; background: var(--hover-wash); }
.card-icon-btn.pinned { opacity: 1; color: var(--accent); }
.pin-btn.pinned .icon { color: var(--accent); fill: rgba(var(--accent-rgb), 0.25); }

.card-badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 7px 0 6px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--badge-color, var(--panel-border));
  color: var(--badge-color, var(--muted));
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge.plain { --badge-color: var(--muted); font-weight: 400; }
.badge.country-badge {
  --badge-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.1);
}
.badge.change-badge {
  --badge-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.12);
}
.badge.access-badge { --badge-color: #b45309; background: rgba(180, 83, 9, 0.1); }
:root[data-theme="dark"] .badge.access-badge { --badge-color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.badge.verified-badge { --badge-color: #0a7a3d; background: rgba(10, 122, 61, 0.08); }
:root[data-theme="dark"] .badge.verified-badge { --badge-color: #4ade80; background: rgba(74, 222, 128, 0.1); }

.card-desc { font-size: 12px; color: var(--muted); line-height: 1.45; margin-bottom: 9px; }

/* DNA strip (concept B) */
.dna { display: flex; gap: 5px; align-items: flex-end; height: 26px; margin-bottom: 10px; }
.dna-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; cursor: help; }
.dna-fill { border-radius: 2px; background: var(--accent-dim); min-height: 2px; }
.dna-bar span { font-size: 8px; color: var(--muted); text-align: center; letter-spacing: 0.5px; }

.card-actions { display: flex; gap: 7px; }
.card-actions a, .card-actions button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--panel-border);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.card-actions a:hover, .card-actions button:hover { transform: translateY(-1px); }
.card-actions .get-btn {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
}
.card-actions .get-btn:hover { background: var(--btn-primary-hover); }
.card-actions .cli-btn:hover { border-color: var(--accent-dim); }
.card-actions .cli-btn.copied { border-color: var(--accent); color: var(--accent); }

/* ============ Passport drawer ============ */
#passport-drawer {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 12px;
  bottom: 12px;
  width: var(--right-panel-max);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 45;
  display: flex;
  flex-direction: column;
  animation: slide-in 0.22s ease;
}
#passport-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.passport-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  font-size: 12.5px;
}
.passport-item .pi-icon { display: inline-flex; flex-shrink: 0; }
.passport-item .pi-meta { flex: 1; min-width: 0; }
.passport-item .pi-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.passport-item .pi-sub { color: var(--muted); font-size: 11px; }
.passport-item button { display: grid; place-items: center; color: var(--muted); }
.passport-item button:hover { color: var(--danger); }

.passport-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--panel-border);
}
.passport-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  font-size: 12px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.passport-actions .danger { grid-column: 1 / -1; }
.passport-actions button:hover { transform: translateY(-1px); }
.passport-actions .icon { width: 13px; height: 13px; }
.passport-actions .primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
}
.passport-actions .primary:hover { background: var(--btn-primary-hover); }
.passport-actions .danger:hover { border-color: var(--danger); color: var(--danger); }
.passport-actions button.copied { border-color: var(--accent); color: var(--accent); }

/* ============ Zoom controls ============ */
/* bottom-right, stacked above the legend — the left edge belongs to the
   filter rail, which would bury them */
#zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 88px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  z-index: 20;
  transition: right 0.2s ease;
}
@media (min-width: 700px) {
  body.rail-open #zoom-controls { right: calc(var(--right-panel-max) + 24px); }
}
#zoom-controls button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--muted);
}
#zoom-controls button:hover { background: var(--hover-wash); color: var(--text); }
#zoom-controls button:first-child { border-bottom: 1px solid var(--panel-border); }

/* ============ Welcome card ============ */
#welcome-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%);
  width: min(400px, calc(100vw - 32px));
  padding: 22px;
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 80;
}
#welcome-card h2 { font-size: 17px; margin-bottom: 14px; }
.welcome-steps { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.welcome-steps li { display: flex; align-items: flex-start; gap: 10px; }
.welcome-steps .icon { width: 18px; height: 18px; color: var(--accent); margin-top: 2px; }
.welcome-steps b { display: block; font-size: 13px; }
.welcome-steps span { font-size: 12px; color: var(--muted); }
.welcome-actions { display: flex; gap: 8px; }
.welcome-actions button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--panel-border);
  font-size: 12.5px;
  font-weight: 600;
}
.welcome-actions .primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
}
.welcome-actions .primary:hover { background: var(--btn-primary-hover); }

/* ============ Compare tray & modal ============ */
#compare-tray {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: 1px solid var(--btn-primary-border);
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 50;
  transition: transform 0.15s;
}
#compare-tray:hover { transform: translateX(-50%) translateY(-1px); }
#compare-tray .count-badge { background: rgba(255, 255, 255, 0.25); color: inherit; }
:root[data-theme="dark"] #compare-tray .count-badge { background: rgba(0, 0, 0, 0.25); }

#compare-modal, #about-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 18, 28, 0.45);
  backdrop-filter: blur(3px);
  z-index: 85;
  padding: 20px;
}
.compare-inner {
  width: min(880px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#compare-table-wrap { overflow: auto; padding: 4px 16px 16px; }
.compare-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.compare-table th, .compare-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: top;
  min-width: 130px;
}
.compare-table tbody th, .compare-table thead th:first-child { min-width: 90px; }
.compare-table tbody th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  font-weight: 600;
}
.compare-domain { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; }
.compare-name { font-size: 12.5px; font-weight: 600; margin-top: 3px; }
.compare-actions-cell { white-space: nowrap; }
.compare-actions-cell .get-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: 1px solid var(--btn-primary-border);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.compare-remove { color: var(--muted); vertical-align: middle; margin-left: 6px; }
.compare-remove:hover { color: var(--danger); }
.about-body { padding: 6px 18px 18px; overflow-y: auto; font-size: 13px; line-height: 1.6; color: var(--text); }
.about-body p { margin-bottom: 10px; }
.about-body a { color: var(--accent); }

/* ============ Boot fallback ============ */
#boot-fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 99;
}
#boot-fallback p { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.7; }
#boot-fallback code { color: var(--accent); }

/* ============ Toast ============ */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-solid);
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 70;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .region-node circle.halo { animation: none; }
  #card-rail, #passport-drawer, #toast { animation: none; }
  .country { transition: none; }
  .chip, .preset, .card, .card-actions a, .card-actions button,
  .passport-actions button, #global-pill, #rail-expand, #theme-toggle, #passport-btn,
  .dock-chip, .dock-chip .dock-label, .filter-chip, #compare-tray, #changes-pill { transition: none; }
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .brand-text p { display: none; }
  #left-rail { width: 220px; }
  #card-rail, #passport-drawer { width: min(372px, calc(100vw - 24px)); }
  /* the dock takes the full row under the header; side controls drop below it */
  #domain-dock {
    left: 12px;
    right: 12px;
    transform: none;
    max-width: none;
    border-radius: 14px;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent 100%);
  }
  #rail-expand, #left-rail { top: calc(var(--topbar-h) + 66px); }
  #global-pill { top: calc(var(--topbar-h) + 66px); }
}
@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; padding: 8px 12px; }

  /* right panels become bottom sheets so the map stays visible */
  #card-rail, #passport-drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(62dvh, 560px);
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    animation: sheet-up 0.24s ease;
  }
  .rail-header { cursor: grab; }
  #compare-modal, #about-panel { padding: 0; align-items: end; }
  #compare-modal .compare-inner, #about-panel .compare-inner {
    max-height: 80dvh;
    width: 100%;
    border-radius: 16px 16px 0 0;
  }
  #welcome-card { width: calc(100vw - 24px); }
}
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ============ Touch ergonomics ============ */
@media (pointer: coarse) {
  /* labels can't be hovered into view — keep them on */
  .dock-chip .dock-label { max-width: 110px; opacity: 1; }
  .dock-chip { height: 40px; }
  .card-icon-btn, #rail-collapse { width: 36px; height: 36px; }
  .rail-header button { width: 36px; height: 36px; }
  #zoom-controls button { width: 42px; height: 42px; }
  .card-actions a, .card-actions button { padding: 10px 8px; }
  .filter-row { padding: 8px 2px; }
  #theme-toggle, #passport-btn, .proj-toggle button { min-height: 40px; }
}

/* keep floating chrome above the iOS home indicator / toolbars */
#legend { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
#zoom-controls { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
#hint { bottom: calc(22px + env(safe-area-inset-bottom, 0px)); }
#compare-tray { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
#toast { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

/* a bottom sheet owns the bottom edge on phones — the tray yields to it */
@media (max-width: 640px) {
  body.rail-open #compare-tray { display: none; }
}

/* re-assert reduced motion AFTER the mobile block so the sheet animation
   cannot override it (equal specificity, later source order wins) */
@media (prefers-reduced-motion: reduce) {
  #card-rail, #passport-drawer { animation: none; }
}

/* below ~1100px the centered hint would sit on the bottom-right legend —
   lift it above the legend row. Kept LAST so the safe-area base rule above
   cannot override it (same specificity, source order decides). */
@media (max-width: 1100px) {
  #hint { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}
