/* styles.css — layout and chrome only. Every colour is a custom property
   emitted by src/palette.js (installPalette), which is the single source of
   truth; nothing here hard-codes a hex.

   Composition (DESIGN §6): header · 340 px rail (headline → ranking →
   factors) · map taking every remaining pixel · a drawer that starts closed
   and is resized by its grip. */

:root {
  /* A humanist sans for UI text; monospace is reserved for figures that have
     to align in a column (table cells, axis ticks, the ranking numerals).
     `ui-sans-serif` is deliberately NOT first: several Linux builds resolve it
     to the fixed-width default, which is what made the old page read as a
     terminal. */
  --font-ui: Inter, "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Liberation Sans", Arial, sans-serif;
  --font-num: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --rail-w: 340px;
  --strip-h: 40px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  background: var(--surface);
  color: var(--ink);
  font: 400 13.5px/1.5 var(--font-ui);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  /* the single column must be allowed to shrink below its content's max-content
     width, or a wide header stretches the whole page on a phone */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--panel); color: var(--ink); padding: 8px 12px; border: 1px solid var(--border);
}
.skip-link:focus { left: 8px; top: 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { min-width: 0; display: flex; align-items: center; gap: 12px; }
.brand-logo { flex: none; display: inline-flex; line-height: 0; border-radius: 6px; }
.brand-logo .logo { width: 40px; height: 40px; display: block; }
.brand-logo .logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo .logo-light { display: none; }
:root[data-theme="dark"] .brand-logo .logo-dark { display: block; }
.brand-text { min-width: 0; }
.brand-org { margin: 0; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-secondary); }
.brand-org a { color: inherit; text-decoration: none; }
.brand-org a:hover, .brand-org a:focus-visible { color: var(--text-primary); }
.brand h1 { margin: 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 640; letter-spacing: -0.012em; }
.brand .sub { margin: 1px 0 0; font-size: 11.5px; color: var(--text-muted); }
.brand .sub-link { color: var(--accent, var(--text-secondary)); text-decoration: none; border-bottom: 1px solid currentColor; }
.brand .sub-link:hover, .brand .sub-link:focus-visible { color: var(--text-primary); }
.header-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; max-width: 100%; }

.field { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.field-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.ghost-btn, .primary-btn, .map-btn, .seg-btn {
  font: inherit; font-size: 12px; line-height: 1;
  padding: 7px 10px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink);
}
.ghost-btn.tiny { padding: 3px 7px; font-size: 11px; }
.ghost-btn:hover, .primary-btn:hover, .map-btn:hover { background: var(--panel-alt); }
.ghost-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.primary-btn { background: var(--dusk); border-color: var(--dusk); color: var(--panel); font-weight: 560; }
:root[data-theme="dark"] .primary-btn { color: var(--surface); }

.seg-group { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg-btn { border: 0; border-radius: 0; padding: 7px 11px; color: var(--text-muted); }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

.preset-select, .mini-select {
  font: inherit; font-size: 12px; padding: 6px 7px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink); max-width: 190px;
}

/* ------------------------------ main ------------------------------- */

.app-main { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 0; min-width: 0; }
.work-col { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; min-width: 0; }

.rail {
  overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 10px 10px 28px;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-gutter: stable;
}

.map-col { position: relative; min-width: 0; min-height: 0; }
.map { position: absolute; inset: 0; background: var(--map-surface); }
.map-notice {
  position: absolute; left: 12px; bottom: 12px; z-index: 5; margin: 0;
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 6px 10px; font-size: 12px; border-radius: 4px; max-width: 46ch; color: var(--ink);
}

/* ------------------------------ cards ------------------------------ */

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px 12px;
}
.card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.card-title { margin: 0; font-size: 12px; font-weight: 640; flex: 1; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.card-hint { margin: 0 0 8px; font-size: 11.5px; color: var(--text-muted); }

/* --------------------------- headline card -------------------------- */
/* One vertical rhythm (6 px), one left edge, numerals in tabular figures where
   they sit in a column and proportional only for the hero. */

.headline-card { padding: 12px 14px 10px; }
.hl-eyebrow { justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: nowrap; }
.hl-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.eyebrow-basis {
  font-size: 10.5px; color: var(--text-secondary); padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-alt); white-space: nowrap;
}
.eyebrow-basis.is-custom { color: var(--accent); border-color: var(--accent); font-weight: 600; }

.headline-top { margin: 0; display: flex; align-items: center; gap: 8px; }
.headline-name { font-size: 20px; font-weight: 680; letter-spacing: -0.015em; }
.headline-rank {
  margin-left: auto; font-family: var(--font-num); font-size: 11px; color: var(--text-secondary);
  padding: 1px 7px; border-radius: 999px; background: var(--panel-alt); border: 1px solid var(--border);
}

.hero-row { margin: 2px 0 10px; display: flex; flex-direction: column; gap: 0; }
/* proportional figures: tabular-nums makes a display number look loose */
.hero-num { font-size: 48px; line-height: 1; font-weight: 620; letter-spacing: -0.03em; }
.hero-unit { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.hl-stats {
  display: grid; grid-template-columns: 5fr 6fr; gap: 0 12px;
  padding: 8px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.hl-stat { display: flex; flex-direction: column; min-width: 0; }
.hl-stat + .hl-stat { padding-left: 12px; border-left: 1px solid var(--border); }
.hl-stat-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.hl-stat-val { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 620; line-height: 1.15; margin-top: 2px; }
.hl-stat-sub { font-size: 11px; color: var(--text-muted); line-height: 1.35; margin-top: 1px; }
.hl-stat-sub .route-swatch { margin: 0 3px 0 1px; vertical-align: -1px; }
.hl-sub-line { display: block; }
.hl-sub-name { color: var(--ink); font-weight: 600; }
.hl-sub-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.headline-was { margin: 6px 0 0; font-size: 12px; color: var(--accent); }
.headline-was strong { color: var(--accent); }
.was-glyph { margin-right: 2px; }
.computing-note { font-style: italic; opacity: 0.75; }

.spark-wrap { margin-top: 10px; }
.spark-bar { display: flex; gap: 2px; height: 8px; border-radius: 2px; overflow: hidden; }
.spark-seg { display: block; min-width: 3px; background: var(--muted); }
.spark-seg.is-other { background: var(--muted); opacity: 0.55; }
.spark-labels { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.spark-label { display: inline-flex; align-items: baseline; gap: 4px; }
.spark-label .route-swatch { align-self: center; }
.spark-label-val { font-family: var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink); }
.spark-label.is-other .spark-label-val { color: var(--text-muted); }
.route-swatch.sm.is-other { background: var(--muted); opacity: 0.55; }

.hl-foot { display: flex; justify-content: flex-end; margin-top: 6px; }
.hl-more { font-size: 11.5px; }

.headline-card.is-computing .spark-bar { opacity: 0.45; }

.link-btn {
  font: inherit; font-size: 11.5px; background: none; border: 0; padding: 6px 0 0;
  color: var(--dusk); cursor: pointer; text-align: left;
}
.link-btn:hover { text-decoration: underline; }

/* ----------------------------- ranking ------------------------------ */

.route-swatch { width: 11px; height: 11px; border-radius: 2px; flex: none; display: inline-block; }
.route-swatch.sm { width: 9px; height: 9px; border-radius: 2px; }
.route-swatch.lg { width: 15px; height: 15px; border-radius: 3px; }

.rank-list { display: grid; gap: 1px; }
.rank-row {
  display: grid;
  grid-template-columns: 13px 11px 1fr auto auto;
  grid-template-areas: "n sw name obj delta" "bar bar bar bar bar";
  align-items: center; column-gap: 7px; row-gap: 4px;
  padding: 6px 7px; border-radius: 7px; cursor: pointer;
  border: 1px solid transparent;
}
.rank-row:hover { background: var(--panel-alt); }
.rank-row.is-pinned { border-color: var(--accent); background: var(--accent-soft); }
.rank-n { grid-area: n; font-family: var(--font-num); font-size: 11px; color: var(--text-muted); text-align: right; }
.rank-row > .route-swatch { grid-area: sw; }
.rank-name { grid-area: name; font-size: 13px; font-weight: 560; }
.rank-obj { grid-area: obj; font-family: var(--font-num); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-delta { grid-area: delta; font-family: var(--font-num); font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }
.rank-track { grid-area: bar; height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.rank-fill { display: block; height: 100%; background: var(--dusk); opacity: 0.4; border-radius: 2px; }
.rank-fill.is-lead { opacity: 0.95; }

/* --------------------------- factor rail --------------------------- */

.factor-list { display: grid; gap: 2px; }

.fgroup { border-top: 1px solid var(--grid); }
.fgroup:first-child { border-top: 0; }
.fgroup-head {
  display: flex; align-items: center; gap: 7px; padding: 7px 2px;
  cursor: pointer; list-style: none; user-select: none;
}
.fgroup-head::-webkit-details-marker { display: none; }
.fgroup-head:hover { color: var(--ink); }
.cat-dot { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.cat-name { font-size: 12px; font-weight: 600; flex: 1; }
.cat-sum { font-family: var(--font-num); font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cat-count { font-size: 10.5px; color: var(--text-muted); white-space: nowrap; }
.fgroup-chevron {
  width: 0; height: 0; flex: none; margin-left: 2px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  transition: transform 140ms ease;
}
.fgroup[open] .fgroup-chevron { transform: rotate(180deg); }

.factor-group { display: grid; gap: 1px; padding: 2px 0 8px; }
.factor-row { padding: 3px 6px; border-radius: 6px; }
.factor-row.is-hot { background: var(--panel-alt); }
.factor-row.is-off { opacity: 0.5; }
.factor-row-top { display: flex; align-items: center; gap: 6px; }
.factor-row-bot { display: flex; align-items: center; gap: 8px; padding-left: 20px; }
.factor-label { flex: 1; font-size: 12px; cursor: pointer; }
.factor-check { accent-color: var(--dusk); flex: none; }

.chip { font-size: 9.5px; padding: 1px 5px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); white-space: nowrap; }
.chip-reward { border-style: dashed; }
.info-dot {
  width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text-muted); font-size: 10px; line-height: 1; cursor: help; padding: 0; flex: none;
}
.inert-glyph { color: var(--text-muted); font-size: 11px; cursor: help; }

.weight-slider { flex: 1; accent-color: var(--dusk); min-width: 0; height: 16px; }
.weight-num {
  width: 58px; font: inherit; font-family: var(--font-num); font-size: 11px; padding: 2px 4px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* --------------------------- category legend ------------------------ */

.cat-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--text-muted); margin-bottom: 10px; }
.cat-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.cat-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; background: var(--muted); }
.cat-swatch.is-hatch {
  background: repeating-linear-gradient(45deg, var(--text-muted) 0 2px, transparent 2px 5px);
}

/* ------------------------ composition (drawer) ---------------------- */

.comp-list { display: grid; gap: 3px; }
.comp-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; }
.comp-rank { font-family: var(--font-num); font-size: 11px; color: var(--text-muted); width: 20px; }
.comp-name { font-size: 12px; font-weight: 560; width: 52px; }
.comp-total { font-family: var(--font-num); font-size: 12px; font-variant-numeric: tabular-nums; width: 52px; text-align: right; }
.contrib-bar { display: block; }
.contrib-seg { cursor: default; }
.contrib-seg.is-hot rect:first-child, .contrib-seg:hover rect:first-child { filter: brightness(1.15); }

/* ---------------------------- map tools ---------------------------- */

.map-tools {
  position: absolute; top: 10px; right: 10px; z-index: 4;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  max-height: calc(100% - 92px); pointer-events: none;
}
.map-tools > * { pointer-events: auto; }
.map-tool-row { display: flex; gap: 6px; }
.map-btn { box-shadow: 0 1px 4px var(--shadow); font-size: 11.5px; padding: 6px 9px; }
.map-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

.layer-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow); width: 236px;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.layer-panel.is-collapsed { width: auto; border: 0; background: none; box-shadow: none; overflow: visible; }
.layer-toggle { display: inline-flex; align-items: center; gap: 6px; }
.layer-panel:not(.is-collapsed) .layer-toggle {
  width: 100%; justify-content: flex-start; border: 0; border-bottom: 1px solid var(--border);
  border-radius: 0; box-shadow: none; background: var(--panel-alt); font-weight: 600;
}
.layer-badge {
  font-family: var(--font-num); font-size: 10px; line-height: 1; padding: 2px 5px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); border: 1px solid var(--accent);
}
.layer-caret {
  width: 0; height: 0; margin-left: auto;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
}
.layer-panel:not(.is-collapsed) .layer-caret { transform: rotate(180deg); }
.layer-panel.is-collapsed .layer-panel-body { display: none; }
.layer-panel-body { overflow-y: auto; padding: 6px 9px 9px; min-height: 0; }
.layer-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: 7px 0 3px; }
.layer-row { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 3px; border-radius: 4px; cursor: pointer; }
.layer-row:hover, .layer-row.is-hot { background: var(--panel-alt); }
.layer-row input { accent-color: var(--dusk); flex: none; }
.layer-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-count { font-size: 10px; color: var(--text-muted); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.layer-swatch { width: 12px; height: 12px; border-radius: 2px; flex: none; border: 1px solid transparent; }
.layer-swatch.is-line { height: 0; border-top: 2.5px solid var(--sw-color); border-radius: 0; }
.layer-swatch.is-point { border-radius: 50%; }
.nlcd-legend { display: flex; flex-wrap: wrap; gap: 3px 8px; margin-top: 6px; }
.nlcd-chip { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; color: var(--text-muted); }
.nlcd-swatch { width: 9px; height: 9px; border-radius: 2px; }

.terminal-marker { display: flex; align-items: center; gap: 4px; pointer-events: none; }
.terminal-marker.is-sink { flex-direction: row-reverse; }
.terminal-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--ink); }
.terminal-label {
  font-size: 11px; font-weight: 620; color: var(--ink);
  background: var(--panel); border: 1px solid var(--border); padding: 1px 5px; border-radius: 3px; white-space: nowrap;
}

.maplibregl-popup.map-popup .maplibregl-popup-content {
  background: var(--panel); color: var(--ink); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; box-shadow: 0 2px 10px var(--shadow); font-size: 12px;
}
.maplibregl-popup.map-popup .maplibregl-popup-tip { border-top-color: var(--panel); border-bottom-color: var(--panel); }
.route-pop-title { display: flex; align-items: center; gap: 6px; font-weight: 640; margin-bottom: 4px; }
.route-pop-swatch { width: 10px; height: 10px; border-radius: 2px; }
.route-pop-rank { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.route-pop-row { display: flex; gap: 12px; justify-content: space-between; color: var(--text-muted); }
.route-pop-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--border) !important; }
.maplibregl-ctrl-scale { background: var(--panel) !important; color: var(--ink) !important; border-color: var(--border) !important; }
.maplibregl-ctrl-attrib { background: var(--panel) !important; color: var(--text-muted) !important; font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--dusk) !important; }

/* ------------------------------ drawer ----------------------------- */

.drawer {
  --drawer-h: 38dvh;
  border-top: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.drawer[data-open="true"] { height: var(--drawer-h); }
.drawer[data-open="false"] .tab-panels,
.drawer[data-open="false"] .drawer-grip { display: none; }

.drawer-grip {
  height: 9px; flex: none; cursor: ns-resize; position: relative;
  background: var(--panel-alt); border-bottom: 1px solid var(--border);
}
.drawer-grip::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 42px; height: 3px;
  transform: translate(-50%, -50%); border-radius: 2px; background: var(--muted); opacity: 0.7;
}
.drawer-grip:hover::after, .drawer-grip:focus-visible::after { background: var(--accent); opacity: 1; }
.drawer.is-dragging { user-select: none; }

.tab-strip {
  display: flex; align-items: stretch; gap: 2px; padding: 0 8px 0 12px;
  height: var(--strip-h); flex: none; border-bottom: 1px solid var(--border); background: var(--panel);
}
.tab-list { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
.tab-btn {
  font: inherit; font-size: 12px; padding: 0 11px; border: 0; background: none; color: var(--text-muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn[aria-selected="true"] { color: var(--ink); font-weight: 640; border-bottom-color: var(--accent); }
.drawer[data-open="false"] .tab-btn[aria-selected="true"] { border-bottom-color: transparent; }

.drawer-toggle {
  font: inherit; font-size: 11.5px; display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto; padding: 0 8px; border: 0; background: none; color: var(--text-muted); cursor: pointer;
}
.drawer-toggle:hover { color: var(--ink); }
.drawer-caret {
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
}
.drawer[data-open="true"] .drawer-caret { transform: rotate(180deg); }

.tab-panels { overflow-y: auto; flex: 1; min-height: 0; }
.tab-panel { padding: 12px 16px 20px; }
.tab-body.is-busy { opacity: 0.55; }
.tab-status { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.headline { font-size: 14px; font-weight: 600; margin: 4px 0 12px; }

.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.busy-note { font-size: 11px; color: var(--text-muted); }

/* ------------------------------ charts ----------------------------- */

.chart-card { margin: 0 0 18px; }
.chart-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 2px; }
.chart-title { font-size: 13px; font-weight: 640; flex: 1; }
.chart-tools { display: flex; gap: 6px; }
.chart-note { font-size: 11px; color: var(--text-muted); margin: 0 0 8px; max-width: 92ch; }
.chart-body { overflow-x: auto; }

.axis-text { font-size: 11px; fill: var(--text-muted); font-family: var(--font-ui); }
.axis-text.strong { fill: var(--ink); font-weight: 600; }
.axis-title { font-size: 11px; fill: var(--text-muted); }
.axis-title.strong { fill: var(--ink); font-weight: 640; }

.scatter-wrap { position: relative; }
.scatter-density { position: absolute; inset: 0; }
.scatter-svg { position: relative; }
.frontier-pt { cursor: pointer; }
.frontier-pt:hover circle:nth-child(2), .frontier-pt:focus circle:nth-child(2) { r: 6; }
.bf-row { cursor: default; }
.bf-row:hover rect, .bf-row:focus rect { filter: brightness(1.12); }

.segment-list { margin-top: 10px; }
.seg-head { font-size: 12px; margin: 0 0 6px; }
.seg-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.seg-chip {
  font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-alt); font-family: var(--font-num); font-variant-numeric: tabular-nums;
}

/* butterfly legend — HTML so the two route names can never collide with marks */
.bf-wrap { position: relative; }
.bf-legend { position: relative; height: 20px; margin-bottom: 2px; font-size: 11px; font-weight: 640; }
.bf-legend-item { position: absolute; display: inline-flex; align-items: center; gap: 5px; top: 2px; color: var(--ink); }
.bf-legend-item.is-left { right: calc(100% - var(--bf-mid) + 10px); }
.bf-legend-item.is-right { left: calc(var(--bf-mid) + 10px); }
.bf-legend-name { white-space: nowrap; }

/* ------------------------------ tables ----------------------------- */

.table-wrap { overflow: auto; max-height: 40dvh; border: 1px solid var(--border); border-radius: 6px; }
.data-table { border-collapse: collapse; font-size: 12px; width: 100%; }
.data-table caption { text-align: left; font-size: 11px; color: var(--text-muted); padding: 6px 8px; }
.data-table th, .data-table td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.data-table thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; font-weight: 640; }
.data-table td.num, .data-table th.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--panel-alt); }
.th-sort { font: inherit; font-weight: 640; background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }

/* ------------------------------ method ----------------------------- */

.method h3 { font-size: 13px; margin: 16px 0 4px; }
.method p { max-width: 92ch; margin: 0 0 8px; }
.method .formula {
  font-family: var(--font-num); font-size: 12px;
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto;
}
.method a { color: var(--dusk); }
.swatch-row { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 10px; }
.swatch-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.swatch-chip code { font-size: 11px; color: var(--text-muted); font-family: var(--font-num); }

/* ----------------------------- tooltip ----------------------------- */

.tooltip {
  position: fixed; top: 0; left: 0; z-index: 200; pointer-events: none;
  background: var(--panel); color: var(--ink); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; font-size: 12px; box-shadow: 0 3px 14px var(--shadow);
  opacity: 0; transition: opacity 120ms ease; max-width: 44ch;
}
.tooltip.on { opacity: 1; }
.tip-title { font-weight: 640; margin-bottom: 3px; }
.tip-row { display: flex; align-items: baseline; gap: 8px; }
.tip-key, .tip-key-blank { width: 12px; flex: none; }
.tip-label { color: var(--text-muted); flex: 1; }
.tip-value { font-weight: 640; font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ------------------------------- boot ------------------------------ */

.boot {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center;
  background: var(--surface); color: var(--text-muted); font-size: 13px;
}
.fatal { max-width: 52ch; text-align: center; color: var(--ink); }
.fatal h1 { font-size: 16px; }

/* --------------------------- narrow desktop ------------------------ */

@media (max-width: 1099px) and (min-width: 820px) {
  :root { --rail-w: 300px; }
  .brand .sub { display: none; }
  .field-label { display: none; }
}

/* ------------------------------ phone ------------------------------ */

@media (max-width: 819px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 50dvh minmax(0, 1fr);
  }
  .work-col { grid-row: 1; grid-template-rows: minmax(0, 1fr); }
  .rail {
    grid-row: 2;
    position: relative; z-index: 6; margin-top: -14px;
    border-right: 0; border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0; box-shadow: 0 -4px 18px var(--shadow);
    background: var(--surface);
    padding: 12px 10px calc(var(--strip-h) + 20px);
    overscroll-behavior: contain;
  }
  .rail::before {
    content: ""; display: block; width: 36px; height: 4px; border-radius: 2px;
    background: var(--border); margin: -4px auto 8px;
  }
  #drawer-host { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; }
  .drawer { box-shadow: 0 -6px 20px var(--shadow); }
  .drawer[data-open="true"] { height: min(var(--drawer-h), 70dvh); }
  .map-tools { top: 8px; right: 8px; max-height: calc(100% - 70px); }
  .layer-panel { width: 200px; }
  .app-header { flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  .brand h1 { font-size: 13.5px; }
  .brand .sub { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header-tools { width: 100%; gap: 6px; }
  .field-label { display: none; }
  .ghost-btn, .primary-btn, .seg-btn { padding: 6px 8px; font-size: 11px; }
  /* min-width:0 or the select's min-content width ("Act 30 (report default)")
     keeps the row from wrapping the share button onto a third line */
  .field { flex: 1 1 88px; min-width: 0; }
  .preset-select { flex: 1 1 88px; min-width: 0; max-width: none; }
  .tab-btn { padding: 0 9px; }
  /* the caret alone; the five tab labels need every pixel of the strip */
  .drawer-toggle-label { display: none; }
  .drawer-toggle { padding: 0 10px; }
  .hero-num { font-size: 40px; }
  .tab-panel { padding: 10px 10px 16px; }
  .table-wrap { max-height: 44dvh; }
}

/* ----------------------------- footer ------------------------------ */

.app-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 5px 14px; font-size: 11px; line-height: 1.4; color: var(--text-muted);
  background: var(--panel); border-top: 1px solid var(--border);
}
.app-footer a { color: var(--text-secondary); text-decoration: none; border-bottom: 1px solid transparent; }
.app-footer a:hover, .app-footer a:focus-visible, .link-btn:hover, .link-btn:focus-visible { color: var(--text-primary); border-bottom-color: currentColor; }
.footer-links { display: flex; gap: 14px; flex: none; }
.link-btn { all: unset; cursor: pointer; color: var(--text-secondary); border-bottom: 1px solid transparent; font: inherit; }

.terms-dialog {
  max-width: min(640px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--ink); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}
.terms-dialog::backdrop { background: rgba(12, 15, 20, 0.55); }
.terms-body { padding: 22px 24px 18px; font-size: 13px; line-height: 1.55; }
.terms-body h2 { margin: 0 0 10px; font-size: 16px; }
.terms-body p { margin: 0 0 10px; color: var(--text-secondary); }
.terms-body a { color: var(--text-primary); }
.terms-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

@media (max-width: 820px) {
  .brand-logo .logo { width: 28px; height: 28px; }
  .brand-org { display: none; }
  .app-footer { padding: 4px 10px; font-size: 10px; }
  .app-footer > span { flex: 1 1 100%; }
}

/* --------------------------- map tool modes ------------------------- */
/* Navigate · Inspect · Region. The cursor is the mode's only persistent
   statement on the map itself, so it is set on the container rather than by
   whatever layer the pointer last crossed (routes.js sets `pointer` on its own
   hover and must not win here). */

.tool-modes { background: var(--panel); box-shadow: 0 1px 4px var(--shadow); }
.tool-btn { font-size: 11.5px; padding: 6px 9px; background: var(--panel); }
.tool-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 640; }

.map.is-tool-inspect .maplibregl-canvas,
.map.is-tool-inspect .maplibregl-canvas-container { cursor: crosshair !important; }
.map.is-tool-region .maplibregl-canvas,
.map.is-tool-region .maplibregl-canvas-container { cursor: cell !important; }

.inspect-marker {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--accent); background: transparent;
  box-shadow: 0 0 0 1px var(--panel), inset 0 0 0 1px var(--panel);
  pointer-events: none;
}
.inspect-marker::before, .inspect-marker::after {
  content: ""; position: absolute; background: var(--accent);
}
.inspect-marker::before { left: 50%; top: -6px; width: 1px; height: 30px; transform: translateX(-50%); }
.inspect-marker::after { top: 50%; left: -6px; height: 1px; width: 30px; transform: translateY(-50%); }

.inspect-pop .route-pop-row { color: var(--ink); gap: 6px; justify-content: flex-start; }
.inspect-pop-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.inspect-pop-more {
  font: inherit; font-size: 11px; margin-top: 6px; padding: 0; border: 0; background: none;
  color: var(--accent); cursor: pointer; border-bottom: 1px solid transparent;
}
.inspect-pop-more:hover, .inspect-pop-more:focus-visible { border-bottom-color: currentColor; }

/* ---------------------- Inspect / Region tabs ----------------------- */

.inspect-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 10px;
}
.inspect-coords { display: flex; align-items: baseline; gap: 8px; }
.inspect-coord-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.inspect-coord { font-family: var(--font-num); font-size: 13px; color: var(--ink); }
.inspect-head-tools { display: flex; align-items: center; gap: 8px; }
.region-stat { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.inspect-card { margin: 0 0 14px; }
.inspect-card-title { font-size: 12px; font-weight: 640; margin: 0 0 4px; }
.inspect-note { font-size: 11px; color: var(--text-muted); margin: 0 0 6px; max-width: 92ch; }
.inspect-empty { font-size: 11.5px; color: var(--text-muted); margin: 0; }
.inspect-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.inspect-item {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  padding: 3px 4px; border-radius: 4px;
}
.inspect-item:hover { background: var(--panel-alt); }
.inspect-item.is-muted { color: var(--text-muted); }
.inspect-item-name { font-weight: 560; flex: none; }
.inspect-item-meta { color: var(--text-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inspect-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; border: 1px solid var(--border); }
.inspect-toggle {
  font: inherit; font-size: 10.5px; margin-left: auto; flex: none; padding: 2px 6px;
  border: 1px solid var(--border); border-radius: 5px; background: var(--panel);
  color: var(--text-muted); cursor: pointer;
}
.inspect-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.region-caveats {
  border-left: 2px solid var(--accent); background: var(--panel-alt);
  padding: 8px 10px; border-radius: 0 6px 6px 0; margin: 0 0 14px;
}
.region-caveat { font-size: 11px; line-height: 1.5; color: var(--text-secondary, var(--text-muted)); margin: 0 0 5px; max-width: 100ch; }
.region-caveat:last-child { margin-bottom: 0; }
.region-caveat strong { color: var(--ink); }
.comp-share { font-size: 11px; color: var(--text-muted); width: 168px; text-align: right; font-variant-numeric: tabular-nums; }
.comp-mi { font-family: var(--font-num); font-size: 11px; color: var(--text-muted); width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 820px) {
  /* five buttons no longer fit on one line beside a 390 px map: let the
     cluster wrap onto a second row rather than run off the right edge */
  .map-tool-row { flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 16px); }
  .tool-btn { padding: 6px 7px; font-size: 11px; }
  .inspect-item { flex-wrap: wrap; }
  .inspect-toggle { margin-left: 0; }
  .comp-share, .comp-mi { width: auto; }
}
