/* Hill Router in the house style.

   The tokens (colours, type and spacing scales, radius, shadow) are
   house-style/tokens.css: a copy of
   https://robinmanhaeve.be/house-style/tokens.css, whose
   --house-style-version says which one. Don't edit the copy; replace it whole
   when the house style changes. HOUSE-STYLE.md in the personal-site
   repository says how to use it; this app follows its "In a web app with a
   map" section.

   What that means here: paper and ink, Figtree, rules rather than boxes, a
   3 px radius and a shadow only on what floats above the page. Magenta is the
   course, wherever it shows: on the map, as its profile, as its row in the
   list. Elsewhere in the interface it is only the focus ring and a link's
   underline on hover. Light and dark follow the system through the tokens'
   light-dark() pairs. */

:root {
  --font-sans: 'Figtree', system-ui, sans-serif;
  --sidebar-w: 22.5rem;
  --pad: var(--space-4);
}

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

[hidden], .hidden { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

body {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  line-height: 1.45;
  background: var(--paper);
  color: var(--ink);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 750; letter-spacing: -0.01em; line-height: 1.2; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--rule);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-color: var(--accent); }

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

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- App bar ---- */
.app-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.wordmark { font-size: var(--step-1); }
a.wordmark { font-weight: 750; letter-spacing: -0.01em; text-decoration: none; }
.home-link { font-size: var(--step--2); color: var(--muted); }
.home-link:hover { color: var(--ink); }

.layout { display: flex; flex: 1; min-height: 0; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}
.sheet-handle { display: none; }

/* Mode: text tabs, the chosen one underlined in ink. */
.mode-toggle {
  display: flex;
  gap: var(--space-5);
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.mode-btn {
  padding: var(--space-3) 0 var(--space-2);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 600;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.active { color: var(--ink); border-bottom-color: var(--ink); }

.controls {
  padding: var(--space-4) var(--pad) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow-y: auto;
  min-height: 0;
  max-height: 60vh;
}
/* In a flex column with a max-height smaller than content, the default
   flex-shrink:1 squeezes children to fit — clipping the <details> body
   instead of letting the controls box scroll. Pinning flex-shrink:0 on every
   direct child makes content overflow the container, so `overflow-y: auto`
   on .controls scrolls as intended. */
.controls > * { flex-shrink: 0; }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label { font-weight: 650; }
.field-label[title] { cursor: help; }
.sub-field { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-1); }
.sub-label { font-size: var(--step--2); color: var(--muted); }
.hint { font-size: var(--step--2); color: var(--muted); }

.filter-body-mode, .prefs { display: flex; flex-direction: column; gap: var(--space-4); }

/* ---- Inputs: a line to write on, not a box ---- */
input[type=text], input[type=number], select {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: var(--space-1) 0 var(--space-1);
  outline: none;
  font-variant-numeric: tabular-nums;
}
input[type=text]:hover, input[type=number]:hover, select:hover { border-bottom-color: var(--muted); }
input[type=text]:focus-visible, input[type=number]:focus-visible, select:focus-visible {
  outline: none;
  border-bottom: 2px solid var(--accent);
  padding-bottom: calc(var(--space-1) - 1px);   /* the thicker underline takes the pixel */
}
input::placeholder { color: var(--muted); opacity: 0.8; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--space-4);
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 5px center, right 1px center;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
select option { background: var(--paper); color: var(--ink); }

input[type=checkbox] { accent-color: var(--ink); width: 15px; height: 15px; cursor: pointer; }

.search-row { display: flex; gap: var(--space-2); align-items: flex-end; }
.search-row input { flex: 1; min-width: 0; }

/* Place search suggestions: a list under the field, rules between rows. */
.geocode-results { display: none; border-top: 1px solid var(--rule); }
.geocode-results.visible { display: block; }
.geocode-item {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  overflow-wrap: anywhere;
}
.geocode-item:hover { background: var(--paper-sunk); }

/* Range: a hairline track and an ink thumb. */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 22px;
  cursor: pointer;
  min-width: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--rule); border-radius: 1px; }
input[type=range]::-moz-range-track { height: 2px; background: var(--rule); border-radius: 1px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -7px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}
input[type=range]:focus-visible { outline-offset: 0; }

.radius-row { display: flex; align-items: center; gap: var(--space-3); }
.radius-row > input[type=range] { flex: 1; }
.radius-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 3.4rem;
  text-align: right;
  white-space: nowrap;
}

/* Distance: km and mi fields, stacked beside the slider. */
.distance-stack { display: flex; flex-direction: column; gap: 2px; }
.distance-input { display: inline-flex; align-items: baseline; gap: var(--space-1); }
.distance-input input { width: 3.2rem; text-align: right; font-weight: 700; padding: 2px 0; }
.distance-input .unit { font-size: var(--step--2); color: var(--muted); width: 1.4em; }

/* Two overlapping range inputs on a shared track: a dual-handle range. The
   inputs are transparent except for their thumbs; the band is .track + .fill. */
.range-dual { position: relative; height: 22px; flex: 1; }
.range-dual .track {
  position: absolute; top: 10px; left: 0; right: 0; height: 2px;
  background: var(--rule); border-radius: 1px;
}
.range-dual .track .fill { position: absolute; top: -1px; height: 4px; background: var(--ink); border-radius: 2px; }
.range-dual input[type=range] {
  position: absolute; inset: 0; width: 100%;
  pointer-events: none; margin: 0;
}
.range-dual input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.range-dual input[type=range]::-moz-range-track { background: transparent; }
.range-dual input[type=range]::-webkit-slider-thumb { pointer-events: auto; }
.range-dual input[type=range]::-moz-range-thumb { pointer-events: auto; }

.range-pair { display: flex; align-items: baseline; gap: var(--space-2); }
.range-pair input[type=number] { width: 3.2rem; text-align: right; font-weight: 700; }
.range-pair input[type=number].wide { width: 4.4rem; }
.range-pair .sep, .range-pair .unit { color: var(--muted); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 34px;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.12s;
}
.btn:hover { background: var(--paper-sunk); }
a.btn { text-decoration: none; }
.btn:disabled { cursor: not-allowed; color: var(--muted); border-color: var(--rule); background: transparent; }

.btn-primary {
  flex: 1;
  min-height: 40px;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  font-weight: 700;
}
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--paper)); }
.btn-primary:disabled { background: var(--paper-sunk); border-color: var(--paper-sunk); color: var(--muted); }

.btn-quiet {
  min-height: 28px;
  padding: 3px var(--space-2);
  border-color: var(--rule);
  color: var(--muted);
  font-size: var(--step--2);
}
.btn-quiet:hover { color: var(--ink); border-color: var(--muted); background: transparent; }

.btn-icon { width: 36px; min-height: 34px; padding: 0; }
.btn-icon svg { fill: none; stroke: currentColor; stroke-width: 1.6; }
.btn-icon svg .fill { fill: currentColor; stroke: none; }

/* ---- Chips: a row of choices. Unchosen ones are rule outlines, the chosen
   one an ink outline in heavier type. ---- */
.chip-row { display: flex; gap: var(--space-1); align-items: stretch; }
.chip {
  flex: 1 1 0;
  min-width: 0;
  min-height: 30px;
  padding: var(--space-1) 3px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--step--2);
  font-weight: 500;
  line-height: 1.12;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
  transition: border-color 0.12s, color 0.12s;
}
.chip:hover { color: var(--ink); border-color: var(--muted); }
.chip.active {
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  font-weight: 700;
}

/* Hilliness: one row per band, a label column and an avoid/ignore/prefer
   group, so the stack reads as a small matrix. */
.band-prefs { display: flex; flex-direction: column; gap: var(--space-1); }
.band-pref-row { display: grid; grid-template-columns: 7.2rem 1fr; align-items: center; gap: var(--space-2); }
.band-pref-lbl { font-size: var(--step--2); line-height: 1.2; cursor: help; }
.band-range { display: block; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip-row.band-level .chip { min-height: 28px; }

.check { display: flex; align-items: center; gap: var(--space-2); font-weight: 650; cursor: pointer; }
.resupply-controls { display: flex; flex-direction: column; gap: var(--space-2); margin-top: 2px; }

/* ---- Road and path types ---- */
details.filters { border-top: 1px solid var(--rule); padding-top: var(--space-3); }
details.filters summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-weight: 650;
  display: flex; align-items: center; justify-content: space-between;
}
details.filters summary::-webkit-details-marker { display: none; }
details.filters summary::after {
  content: ''; width: 6px; height: 6px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.12s;
}
details.filters[open] summary::after { transform: rotate(-135deg) translate(-1px, -1px); }
.filter-body { padding: var(--space-3) 0 2px; }
.hw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px var(--space-3); }
.hw-section-label {
  grid-column: 1 / -1;
  margin-top: var(--space-2);
  font-size: var(--step--2);
  color: var(--muted);
}
.hw-section-label:first-child { margin-top: 0; }
.hw-grid label { display: flex; align-items: center; gap: var(--space-2); padding: 2px 0; cursor: pointer; }

/* ---- Search action and the collapsed summary ---- */
.controls-wrap > .controls-actions {
  padding: var(--space-3) var(--pad);
  border-bottom: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: var(--space-3);
  flex-shrink: 0;
  background: var(--paper);
}

.controls-summary {
  display: none;
  align-items: baseline; gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--pad);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  flex-shrink: 0;
}
.controls-summary:hover { background: var(--paper-sunk); }
.cs-label { flex: 1; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-edit { color: var(--muted); font-size: var(--step--2); font-weight: 600; flex-shrink: 0; }
.controls-wrap.collapsed > .controls-summary,
.controls-wrap.has-results > .controls-summary { display: flex; }
.controls-wrap.collapsed > .controls { display: none; }
.controls-wrap.collapsed > .controls-actions { padding-top: var(--space-3); }

.error-msg {
  display: none;
  padding: var(--space-2) var(--space-3);
  background: var(--paper-sunk);
  box-shadow: inset 3px 0 0 var(--ink);
  border-radius: var(--radius);
}
.error-msg.visible { display: block; }

/* ---- Results ---- */
.results-bar {
  padding: var(--space-2) var(--pad);
  display: flex; align-items: center; gap: var(--space-2);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
  min-width: 0;
}
.results-count {
  font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
/* Push the share/sort group to the right edge. */
.sort-row { display: flex; align-items: center; gap: var(--space-3); margin-left: auto; }
.back-btn { display: none; }
.back-btn.visible { display: inline-flex; }

.results-list { overflow-y: auto; flex: 1; }

.empty-state { padding: var(--space-5) var(--pad); color: var(--muted); max-width: 22rem; }

.loading { padding: var(--space-4) var(--pad) var(--space-4); display: none; }
.loading.visible { display: block; }
.loading .label { color: var(--muted); margin-bottom: var(--space-2); }
.progress-bar {
  width: 100%; height: 3px; background: var(--rule);
  border-radius: 2px; overflow: hidden; position: relative;
}
.progress-bar .fill { height: 100%; width: 0%; background: var(--ink); transition: width 0.25s ease-out; }
.progress-bar.indeterminate .fill { width: 35%; animation: progress-slide 1.2s ease-in-out infinite; }
@keyframes progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(290%); }
}
@media (prefers-reduced-motion: reduce) {
  .progress-bar.indeterminate .fill { animation: none; width: 100%; opacity: 0.4; }
}

.maintenance-banner {
  margin: var(--space-3) var(--pad);
  padding: var(--space-3) var(--space-3);
  background: var(--paper-sunk);
  box-shadow: inset 3px 0 0 var(--ink);
  border-radius: var(--radius);
}
.maintenance-banner .mb-title { font-weight: 700; margin-bottom: 2px; }
.maintenance-banner .mb-body span { display: inline-block; margin-right: var(--space-3); }
.maintenance-banner .mb-retry { color: var(--muted); font-size: var(--step--2); margin-top: var(--space-1); }

/* ---- Result cards ---- */
.result-card {
  padding: var(--space-3) var(--pad) var(--space-3);
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background-color 0.1s;
}
.result-card:hover { background: var(--paper-sunk); }
.result-card:focus-visible { outline-offset: -2px; }
/* The open result: the one thing on screen that is also magenta on the map. */
.result-card.active { background: var(--paper-sunk); box-shadow: inset 3px 0 0 var(--accent); }

.card-top { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.card-name { flex: 1; min-width: 0; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.card-rank {
  font-size: var(--step--2);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* A route's number: the same ink pill as its badge on the map. */
.route-num, .route-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px;
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--map-marker);
  color: var(--map-marker-text);
  font-size: var(--step--2);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  flex-shrink: 0;
}

.source-badge, .dem-badge {
  display: inline-block;
  margin-right: var(--space-2);
  padding: 0 var(--space-1);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--step--2);
  font-weight: 600;
  line-height: 1.35;
  vertical-align: 1px;
  cursor: help;
}

.variations-toggle {
  padding: 1px var(--space-2);
  background: none;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--step--2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.variations-toggle:hover, details.cluster-section[open] .variations-toggle { color: var(--ink); border-color: var(--ink); }

.card-stats { display: flex; align-items: flex-end; gap: var(--space-4); }
.stat { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.2; }
.stat-val .unit { font-size: var(--step--2); font-weight: 500; color: var(--muted); }
.stat-lbl { font-size: var(--step--2); color: var(--muted); white-space: nowrap; }
.stat-spacer { flex: 1; }

.sparkline { display: block; flex-shrink: 0; }
.sparkline polyline {
  fill: none; stroke: var(--muted); stroke-width: 1.5;
  stroke-linejoin: round; stroke-linecap: round;
}
.result-card:hover .sparkline polyline, .result-card.active .sparkline polyline { stroke: var(--ink); }

/* Cluster sections (loops and routes). Multi-member clusters wrap the primary
   card in a <summary>; variations render inside .cluster-body when open,
   indented under the number. */
details.cluster-section { border-bottom: 1px solid var(--rule); }
details.cluster-section > summary { list-style: none; user-select: none; display: block; }
details.cluster-section > summary::-webkit-details-marker { display: none; }
details.cluster-section .result-card { border-bottom: 0; }
details.cluster-section > .cluster-body .result-card { padding-left: calc(var(--pad) + 22px + var(--space-2)); border-top: 1px solid var(--rule); }

/* ---- Route detail panel ---- */
.route-detail-panel { display: flex; flex-direction: column; flex: 1; overflow-y: auto; }
.route-detail-panel.hidden { display: none; }
.rdp-header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--pad) var(--space-2); flex-shrink: 0; }
.rdp-back-btn { flex-shrink: 0; }
.rdp-title { font-size: var(--step-1); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rdp-stats {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--pad) var(--space-4);
  flex-shrink: 0;
}
.rdp-stats .stat-val { font-size: var(--step-0); }
.rdp-stats .stat-val .unit { font-size: var(--step--1); }
.rdp-actions {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
  padding: 0 var(--pad) var(--space-4);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.rdp-actions .btn-primary { flex: 1 1 100%; }
.rdp-actions .btn:not(.btn-primary) { flex: 1 1 0; }

/* Elevation profile: the race sheets' profile (svg.js). */
.rdp-profile { padding: var(--space-4) var(--pad) var(--space-2); flex-shrink: 0; }
.pf-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.pf-title { font-weight: 650; }
.pf-readout {
  display: flex; gap: var(--space-3);
  font-size: var(--step--2);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.profile-svg { display: block; overflow: visible; touch-action: pan-y; }
.profile-svg text { font-family: var(--font-sans); }
.pf-grid { stroke: var(--rule); stroke-width: 1; shape-rendering: crispEdges; }
.pf-frame { fill: none; stroke: var(--rule); stroke-width: 1; shape-rendering: crispEdges; }
.pf-label { fill: var(--muted); font-size: var(--step--3); font-variant-numeric: tabular-nums; }
.pf-line { fill: none; stroke: var(--map-course); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pf-fill-top { stop-color: var(--map-course-fill); }
.pf-fill-bottom { stop-color: var(--map-course-fill-end); }
.pf-guide { stroke: var(--ink); stroke-width: 1; }
.pf-dot { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.pf-hit { fill: transparent; cursor: crosshair; }

.rdp-quality {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--pad) var(--space-4);
  flex-shrink: 0;
}
.rdp-quality .check { font-weight: 500; }
.quality-legend { display: flex; align-items: center; gap: var(--space-2); font-size: var(--step--2); color: var(--muted); }
.quality-legend .ramp {
  width: 64px; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--ramp-good), var(--ramp-mid), var(--ramp-poor));
}

/* Score breakdown: bars either side of zero, what lowers the score to the
   left, what raises it to the right. Position says the sign; the ends of the
   good-to-poor ramp repeat it, and the numbers stay ink. */
.rdp-breakdown { padding: var(--space-4) var(--pad) var(--space-5); border-top: 1px solid var(--rule); flex-shrink: 0; }
.bd-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--space-2); }
.bd-head h3 { font-size: var(--step--1); font-weight: 650; letter-spacing: 0; }
.bd-score { font-size: var(--step-0); font-weight: 700; font-variant-numeric: tabular-nums; }
.bd-row, .bd-scale {
  display: grid;
  grid-template-columns: 6.2rem 1fr 1fr 3.6rem;
  align-items: center;
  font-size: var(--step--2);
}
.bd-scale { color: var(--muted); margin-bottom: 2px; }
.bd-scale span:nth-child(2) { text-align: right; padding-right: var(--space-2); }
.bd-scale span:nth-child(3) { padding-left: var(--space-2); }
.bd-row { padding: 2px 0; }
.bd-lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: var(--space-2); }
.bd-neg, .bd-pos { display: flex; height: 16px; align-items: center; }
.bd-neg { justify-content: flex-end; }
.bd-pos { border-left: 1px solid var(--muted); }
.bd-fill { display: block; height: 7px; background: var(--ink); }
.bd-neg .bd-fill { background: var(--ramp-poor); }
.bd-pos .bd-fill { background: var(--ramp-good); }
.bd-val { text-align: right; font-variant-numeric: tabular-nums; }
.bd-base { color: var(--muted); }

/* ---- Shared route page (/map/{key}, route.html) ---- */
.route-sheet { flex: 1; overflow-y: auto; }
.rp-head { padding: var(--space-4) var(--pad) 0; }
.rp-kind { font-size: var(--step--2); color: var(--muted); margin-bottom: 2px; }
.rp-head .rdp-stats { padding: var(--space-3) 0 var(--space-4); }
.rp-section { padding: var(--space-4) var(--pad) var(--space-4); border-top: 1px solid var(--rule); }
.rp-section h2 { font-size: var(--step--1); font-weight: 650; letter-spacing: 0; margin-bottom: var(--space-3); }
.rp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3) var(--space-4); }
.gd-row {
  display: grid; grid-template-columns: 8.2rem 1fr 3.8rem; gap: var(--space-2);
  align-items: center; padding: 2px 0;
  font-size: var(--step--2);
}
.gd-track { display: flex; height: 16px; align-items: center; border-left: 1px solid var(--muted); }
.gd-bar { display: block; height: 7px; background: var(--ink); }
.gd-val { text-align: right; font-variant-numeric: tabular-nums; }
.rs-row {
  display: grid; grid-template-columns: 3.6rem 3.8rem 1fr; gap: var(--space-3);
  padding: var(--space-2) 0; border-bottom: 1px solid var(--rule);
}
.rs-km { font-weight: 700; font-variant-numeric: tabular-nums; }
.rs-kind { color: var(--muted); }
.rs-name { min-width: 0; overflow-wrap: anywhere; }
.rs-off { display: block; font-size: var(--step--2); color: var(--muted); }

/* ---- Map ---- */
.map-wrap { flex: 1; position: relative; display: flex; min-width: 0; }
#map { flex: 1; background: var(--paper); }

.leaflet-container { font-family: var(--font-sans); background: var(--paper); }
.leaflet-bar { border: 1px solid var(--rule) !important; border-radius: var(--radius); box-shadow: var(--shadow); }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--paper);
  color: var(--ink);
  border-bottom-color: var(--rule);
}
.leaflet-bar a:hover { background: var(--paper-sunk); }
.leaflet-bar a:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.leaflet-bar a:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.leaflet-control-attribution.leaflet-control-attribution {
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  color: var(--muted);
  font-size: var(--step--3);
}
.leaflet-control-attribution a { color: var(--ink); text-decoration-color: var(--rule); }

.leaflet-popup-content-wrapper {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--paper); box-shadow: none; }
.leaflet-popup-content { font-size: var(--step--1); line-height: 1.5; margin: var(--space-3) var(--space-4); }
.leaflet-popup-content h3 { font-size: var(--step--1); margin-bottom: var(--space-1); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup-row { color: var(--muted); }
.popup-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Tooltips are transient: ink with paper text. */
.leaflet-tooltip {
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: var(--step--2);
  padding: var(--space-1) var(--space-2);
}
.leaflet-tooltip-top::before { border-top-color: var(--ink); }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--ink); }
.leaflet-tooltip-left::before { border-left-color: var(--ink); }
.leaflet-tooltip-right::before { border-right-color: var(--ink); }

/* ---- Map symbols (HTML markers, so they follow the theme on their own) ---- */

/* A route's number on the map: an ink pill outlined in the casing colour,
   centred on its point. */
.route-badge-icon { width: 0; height: 0; }
.route-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1.5px var(--map-marker-outline);
  cursor: pointer;
  white-space: nowrap;
}

.sf-marker svg, .poi-marker svg {
  display: block;
  overflow: visible;
  filter: drop-shadow(0 0 0.7px var(--map-marker-outline)) drop-shadow(0 0 0.7px var(--map-marker-outline));
}
.sf-tri, .sf-dot { fill: var(--map-marker); }
.sf-ring { fill: none; stroke: var(--map-marker); stroke-width: 2.6; }

.course-arrow-marker svg { display: block; overflow: visible; }
.course-arrow { fill: var(--map-course-casing); }

.km-disc {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--map-km-disc);
  border: 2px solid var(--map-course);
  color: var(--map-km-text);
  font-size: var(--step--3);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.poi-disc { fill: var(--map-marker); }
.poi-glyph { fill: var(--map-marker-text); }
.poi-glyph .stroke { fill: none; stroke: var(--map-marker-text); stroke-width: 1.4; }
.poi-glyph text { font: 800 6.5px var(--font-sans); letter-spacing: -0.02em; }

.route-cursor {
  display: block;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--map-marker-outline);
  border: 3px solid var(--map-marker);
  box-shadow: var(--shadow);
}

/* ---- Modal: the alternatives picker ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgb(0 0 0 / 0.35);
  display: none;
  align-items: center; justify-content: center;
  z-index: 2000;
  padding: var(--space-5);
}
.conn-picker-backdrop:not(.hidden) { display: flex; }
.conn-picker {
  background: var(--paper);
  border-radius: var(--radius);
  width: min(560px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow), 0 24px 60px rgb(0 0 0 / 0.18);
}
.conn-picker-header {
  display: flex; align-items: center;
  padding: var(--space-3) var(--space-2) var(--space-3) var(--pad);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.conn-picker-title { flex: 1; font-size: var(--step-0); }
.conn-picker-map { height: 260px; flex-shrink: 0; }
.conn-picker-list { overflow-y: auto; flex: 1; }
.conn-empty { padding: var(--space-4) var(--pad); color: var(--muted); }
.conn-alt-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--pad);
  border-bottom: 1px solid var(--rule);
  cursor: default;
}
.conn-alt-card.highlighted { background: var(--paper-sunk); box-shadow: inset 3px 0 0 var(--accent); }
.conn-alt-info { flex: 1; min-width: 0; }
.conn-alt-label { font-weight: 650; }
.conn-alt-meta { font-size: var(--step--2); color: var(--muted); font-variant-numeric: tabular-nums; }
.conn-picker-tabs { display: flex; gap: var(--space-5); padding: 0 var(--pad); border-bottom: 1px solid var(--rule); flex-shrink: 0; }
.conn-tab {
  padding: var(--space-2) 0 var(--space-2);
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); font-weight: 600;
}
.conn-tab:hover { color: var(--ink); }
.conn-tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.modal-close {
  background: none; border: 0;
  width: 36px; height: 36px;
  color: var(--muted); font-size: 1rem;
  border-radius: var(--radius);
}
.modal-close:hover { background: var(--paper-sunk); color: var(--ink); }

/* ====================================================================
   Phones (≤ 768 px): the map fills the screen and the sidebar is a sheet
   over its lower part (ui/mobile.js sets --sheet-h and body[data-sheet]).
   The sheet scrolls as one; the Search button sticks to its bottom edge
   while the form is in view.
   ==================================================================== */
@media (max-width: 768px) {
  .app-bar { padding: var(--space-2) var(--pad) var(--space-2); }
  .home-link { display: none; }

  .layout { position: relative; }
  .map-wrap { position: absolute; inset: 0; }
  .leaflet-control-zoom { display: none; }

  .sidebar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 1100;
    width: auto;
    height: var(--sheet-h, 216px);
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 0;
    border-top: 1px solid var(--rule);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -2px 16px rgb(0 0 0 / 0.1);
    transition: height 0.24s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.dragging { transition: none; }
  @media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

  .sheet-handle {
    display: flex; align-items: center; justify-content: center;
    position: sticky; top: 0; z-index: 3;
    height: 24px;
    background: var(--paper);
    touch-action: none;
    cursor: grab;
  }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--rule); }
  .sheet-handle:focus-visible { outline-offset: -3px; }

  .controls { max-height: none; overflow: visible; }
  .results-list, .route-detail-panel, .route-sheet { overflow: visible; }
  .controls-wrap > .controls-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    border-top: 1px solid var(--rule);
  }
  /* With the form folded away, the summary line is enough: Edit opens the
     form, and its Search button with it. */
  .controls-wrap.collapsed > .controls-actions { display: none; }

  /* Touch-sized targets. */
  .btn { min-height: 42px; }
  .btn-primary { min-height: 48px; }
  .btn-quiet { min-height: 36px; }
  .chip { min-height: 38px; font-size: var(--step--1); }
  .chip-row.band-level .chip { min-height: 36px; }
  .band-pref-lbl { font-size: var(--step--1); }
  .mode-btn { padding: var(--space-3) 0 var(--space-3); }
  .geocode-item { padding: var(--space-3) 0; }
  .hw-grid label { padding: var(--space-1) 0; }
  input[type=text], input[type=number], select { font-size: 16px; }   /* no zoom-on-focus in iOS */

  .modal-backdrop { padding: var(--space-3); }
}
