/* ── BikeLoop — monochrome carbon / slate cockpit ────────────────────────────
   White → black. No hue in the chrome: light accents on carbon, slate greys,
   angular edges, instrumentation-grade labels. (Route lines on the map stay
   colour-coded — that's data identity, not chrome.) */
:root {
  /* monochrome — white → black, carbon & slate. No hue anywhere in the chrome. */
  --bg: #0c0e11;          /* near-black carbon */
  --panel: #14171c;       /* slate surface */
  --raised: #1b1f26;      /* raised element */
  --field: #0a0c0f;       /* recessed input slot */
  --border: #282d35;      /* slate line */
  --hair: rgba(255, 255, 255, 0.055);
  --text: #eef1f4;        /* near-white */
  --muted: #838a93;       /* slate gray */
  --accent: #eef1f4;      /* the "accent" is light — white on carbon */
  --accent-hover: #ffffff;
  --accent-soft: rgba(238, 241, 244, 0.14);
  --accent-ink: #0c0e11;  /* dark text on the light accent */
  --danger: #d16a6a;
  --warn: #c8a45a;
  --shadow: 0 14px 46px rgba(0, 0, 0, 0.6);
  --ctrl-icon-filter: invert(1) brightness(1.05);
  --r: 6px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px/1.5 var(--sans); color: var(--text); background: var(--bg); }
#map { position: absolute; inset: 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* micro instrumentation label */
label {
  display: block; margin: 11px 0 4px; font: 600 10px/1 var(--sans);
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap;
}
label .hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); opacity: 0.85; }

/* ── floating surfaces ─────────────────────────────────────────────────────── */
/* the hidden attribute must always win over a component's display rule */
[hidden] { display: none !important; }

.panel, .saved-panel, .legend, .routes-panel, .maplibregl-ctrl-group {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* generated routes: a horizontal, side-scrolling card strip under the menu, with
   a vertical side header so collapsing shrinks it horizontally to a thin tab */
.routes-panel { position: absolute; top: 14px; left: 328px; z-index: 5;
  max-width: calc(100vw - 342px); max-height: 54vh; display: flex; flex-direction: row;
  align-items: stretch; padding: 0; overflow: hidden; }
.routes-head { flex: none; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 9px 7px; border-right: 1px solid var(--border); }
.routes-head .collapse-btn { margin-left: 0; }
.routes-head .ttl { writing-mode: vertical-rl; transform: rotate(180deg);
  font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.14em; color: var(--text); }
.routes-head .grip { margin-top: auto; color: var(--muted); display: inline-flex; transition: color 0.12s; }
.routes-head:hover .grip { color: var(--accent); }
.routes-body { display: flex; flex-direction: column; align-items: stretch;
  width: fit-content; min-width: 244px; max-width: calc(100vw - 380px);
  padding: 10px 12px; overflow-y: auto; }
.routes-panel.collapsed .routes-body { display: none; }

.panel {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  width: 300px; max-width: calc(100vw - 28px); max-height: calc(100vh - 28px);
  overflow-y: auto; padding: 13px 15px 11px;
}
.panel-head, .legend-head { display: flex; align-items: center; gap: 8px; }
.panel-head .grip, .legend-head .grip { color: var(--muted); flex: none; display: inline-flex; }
.panel h1 {
  margin: 0; flex: 0 0 auto; font: 700 13px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.2em; color: var(--text);
}
.panel h1 span.mark { color: var(--accent); }

.drag-handle { cursor: grab; touch-action: none; user-select: none; }
.drag-handle:active { cursor: grabbing; }

/* alignment guides shown while dragging a panel (snap to edges/centres) */
.snap-guide { position: fixed; z-index: 40; background: var(--accent); pointer-events: none; opacity: 0.7; }
.snap-v { top: 0; bottom: 0; width: 1px; }
.snap-h { left: 0; right: 0; height: 1px; }

/* collapse toggles + collapsed states (map-first on mobile) */
.collapse-btn { flex: none; margin-left: auto; width: 22px; height: 22px; padding: 0;
  border: 1px solid var(--border); border-radius: 4px; background: var(--field); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; }
.collapse-btn::before { content: ""; width: 0; height: 0; transition: transform 0.15s;
  border-top: 5px solid var(--muted); border-left: 4px solid transparent; border-right: 4px solid transparent; }
.collapse-btn:hover { border-color: var(--accent); }
.collapse-btn:hover::before { border-top-color: var(--accent); }
.collapsed .collapse-btn::before { transform: rotate(-90deg); }
.panel.collapsed .panel-body, .panel.collapsed .panel-actions, .legend.collapsed .legend-body { display: none; }
.panel.collapsed { width: auto; }

/* info/about icon button — same footprint as .collapse-btn, no chevron */
.icon-btn { flex: none; width: 22px; height: 22px; padding: 0; border: 1px solid var(--border);
  border-radius: 4px; background: var(--field); color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: border-color 0.12s, color 0.12s; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── mode segmented control ────────────────────────────────────────────────── */
.modes { display: flex; gap: 3px; margin-bottom: 4px; background: var(--field);
  border: 1px solid var(--border); border-radius: var(--r); padding: 3px; }
.mode { flex: 1; padding: 6px; border: 0; border-radius: 4px; background: none;
  color: var(--muted); font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.07em;
  cursor: pointer; transition: background 0.12s, color 0.12s; }
.mode:hover { color: var(--text); }
.mode.active { background: var(--raised); color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--border), 0 1px 3px rgba(0, 0, 0, 0.4); }

/* target distance/time toggle: label on the left, compact toggle on the right */
.target-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.target-head label { margin: 0; }
.modes.tmode { flex: 0 0 auto; margin-bottom: 0; width: 108px; }
.modes.tmode .mode { padding: 4px 6px; font-size: 9px; }

/* click-to-type value labels */
.editable { cursor: text; border-bottom: 1px dotted var(--muted); }
.editable:hover { color: var(--accent); border-bottom-color: var(--accent); }
.editable[contenteditable="true"] { outline: none; border-bottom: 1px solid var(--accent); color: var(--text); }

/* Ironman-mode toggle */
.ironman-toggle { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px; cursor: pointer;
  font: 600 10px/1.4 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ironman-toggle input { width: auto; margin: 0; accent-color: var(--accent); cursor: pointer; }
.ironman-toggle .hint { text-transform: none; letter-spacing: 0; }
#snapMaxRow { margin: 2px 0 2px 22px; }
/* snapped loop-start: a small ringed dot at the main-road start of the loop */
.snap-dot { width: 13px; height: 13px; border-radius: 50%; background: var(--mark-start, #1a7f37);
  border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,0.35); cursor: help; }

/* ── address search ──────────────────────────────────────────────────────────── */
.search-wrap { position: relative; margin-bottom: 6px; }
.search-row { display: flex; gap: 6px; }
.search-row #searchBox { flex: 1; min-width: 0; }
.search-row #searchTarget { flex: 0 0 84px; width: 84px; padding-right: 4px; }
.search-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin-top: 3px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); max-height: 220px; overflow-y: auto; }
.search-item { display: block; width: 100%; text-align: left; border: 0; background: none;
  color: var(--text); font: 500 11px/1.3 var(--mono); padding: 7px 9px; cursor: pointer;
  border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: var(--accent-soft); }
.search-empty { padding: 8px 9px; color: var(--muted); font: 500 11px/1.3 var(--mono); }

/* ── inputs ────────────────────────────────────────────────────────────────── */
input[type="text"], input[type="number"], select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 5px;
  background: var(--field); color: var(--text); font: 500 12px/1.2 var(--mono);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus { outline: none; border-color: var(--muted);
  box-shadow: 0 0 0 2px var(--accent-soft); }
input::placeholder { color: var(--muted); opacity: 0.6; }
.row { display: flex; gap: 8px; }
.row > div { flex: 1; min-width: 0; }

/* sliders — sleek + simple: a hairline track, a small light thumb, no glow */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 2px;
  background: var(--border); border-radius: 2px; margin: 9px 0; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%;
  background: var(--text); cursor: pointer; transition: transform 0.1s; }
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border: 0; border-radius: 50%; background: var(--text); cursor: pointer; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--border); border-radius: 2px; }

/* ── stops ─────────────────────────────────────────────────────────────────── */
.stops-head { display: flex; align-items: center; justify-content: space-between; }
.shape-row { display: flex; align-items: center; gap: 8px; }
.shape-row .hint { font: 500 11px/1 var(--sans); color: var(--muted); }
button.ghost { display: inline-flex; align-items: center; gap: 5px; font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 9px; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
button.ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
button.ghost:disabled { opacity: 0.4; cursor: default; }
button.ghost.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
/* tap-a-road popup: two verb buttons stacked */
.shape-pop { display: flex; flex-direction: column; gap: 6px; }
.shape-pop .shape-hint { font: 700 9px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.shape-pop button { display: flex; align-items: center; gap: 8px; font: 600 12px/1 var(--sans); text-align: left; color: var(--text); background: none;
  border: 1px solid var(--border); border-radius: 4px; padding: 7px 9px; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.shape-pop button:hover { border-color: var(--accent); background: var(--accent-soft); }
.qr-panel { position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; align-items: center; max-width: 300px; }
.qr-head { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 12px; }
.qr-head strong { font: 700 12px/1.2 var(--sans); }
#qrCanvas { border-radius: 4px; background: #fff; image-rendering: pixelated; }
.qr-url { font: 500 9px/1.35 var(--mono); color: var(--muted); word-break: break-all; text-align: center; max-height: 40px; overflow: hidden; }

/* about / guide popup — same floating-card idiom as .qr-panel, wider + scrollable */
.about-panel { position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
  width: 420px; max-width: calc(100vw - 28px); max-height: calc(100vh - 28px); overflow: hidden; }
.about-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; font: 500 12px/1.55 var(--sans); color: var(--text); }
.about-body h4 { margin: 14px 0 4px; font: 700 10px/1 var(--sans); text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); }
.about-body h4:first-child { margin-top: 0; }
.about-body p { margin: 0 0 4px; color: var(--muted); }
.about-body strong { color: var(--text); font-weight: 600; }

/* standalone QR control, bottom-right, just left of the legend */
.btn-row { display: flex; gap: 6px; margin-top: 6px; }
.btn-row > button { flex: 1; padding: 7px; min-width: 0; }
.btn-row > #qrBtn { flex: 0 0 auto; padding: 7px 10px; }
.clear-btn { color: #d98a8a; }
.clear-btn:hover { border-color: #d98a8a; background: rgba(214, 69, 69, 0.12); }
.stop-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.stop-num { flex: none; width: 18px; height: 18px; border-radius: 4px; background: var(--accent);
  color: var(--accent-ink); font: 700 11px/18px var(--mono); text-align: center; }
.stop-row input { flex: 1; min-width: 0; }
.stop-del { flex: none; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 2px 4px; }
.stop-del:hover { color: var(--danger); }
.stop-marker { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font: 700 12px var(--mono);
  border: 2px solid var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,0.6); cursor: grab; }

/* ── advanced foldout ──────────────────────────────────────────────────────── */
.advanced { margin-top: 12px; border-top: 1px solid var(--hair); padding-top: 2px; }
.advanced > summary {
  display: flex; align-items: center; gap: 7px; cursor: pointer; padding: 6px 0;
  font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); list-style: none; user-select: none;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before { content: ""; flex: none; width: 0; height: 0;
  border-left: 4px solid currentColor; border-top: 3px solid transparent;
  border-bottom: 3px solid transparent; transition: transform 0.12s; }
.advanced[open] > summary::before { transform: rotate(90deg); }
.advanced > summary:hover { color: var(--text); }
.advanced label { margin: 9px 0 2px; }
.advanced input[type="range"] { margin: 2px 0; }
.advanced #advReset { margin-top: 11px; }

/* ── primary CTA ───────────────────────────────────────────────────────────── */
button.primary {
  width: 100%; margin-top: 15px; padding: 10px; border: 0; border-radius: 5px;
  background: var(--accent); color: var(--accent-ink);
  font: 700 11px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.1em;
  cursor: pointer; transition: background 0.12s, box-shadow 0.12s;
}
button.primary:hover { background: var(--accent-hover); box-shadow: none; }
button.primary:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

.status { margin-top: 10px; font: 500 11px/1.4 var(--mono); color: var(--muted); min-height: 0; }
.status:empty { margin: 0; }
.status.err { color: var(--danger); }
.notice { margin-top: 9px; font-size: 11px; color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--border); border-radius: 5px; padding: 6px 9px; }

/* ── result cards ──────────────────────────────────────────────────────────── */
/* master–detail: every route is a slim row; the active one expands its detail.
   The panel sizes to the widest detail line (kept in flow while collapsed via
   max-height:0 so the width stays stable), and never wraps that line. */
.results { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.route-card { background: var(--raised); border: 1px solid var(--border); border-radius: 5px;
  padding: 8px 10px; transition: border-color 0.12s, box-shadow 0.12s; }
.route-card:hover { border-color: #33404f; }
.route-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.route-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.row-sub { color: var(--muted); font: 500 10.5px/1.3 var(--mono); white-space: nowrap; }
.route-detail { max-height: 0; overflow: hidden; }
.route-card.active .route-detail { max-height: none; overflow: visible; margin-top: 8px; }
.stat-grid { display: flex; flex-wrap: wrap; gap: 4px 14px;
  margin-top: 8px; color: var(--muted); font: 500 11px/1.35 var(--mono); }
/* inline icon + text (not a flex row) — nudge the icon up to sit on the text baseline */
.stat-grid svg, .gpx svg, .notes svg, .legend .sub2 svg { vertical-align: -2px; }
/* labelled bikeability bar: label · track · value on one line */
.statbar { display: flex; align-items: center; gap: 8px; margin-top: 8px;
  font: 500 10.5px/1 var(--mono); color: var(--muted); }
.statbar-label { text-transform: uppercase; letter-spacing: 0.05em; font-size: 9px; flex: none; }
.statbar-track { flex: 1; height: 5px; border-radius: 3px; background: var(--field); overflow: hidden; }
.statbar-track > span { display: block; height: 100%; }
.statbar-val { flex: none; color: var(--text); font-weight: 600; min-width: 30px; text-align: right; }
.route-card .top { display: flex; align-items: center; gap: 8px; }
.conf { margin-left: auto; flex: none; display: flex; flex-direction: column; align-items: center;
  font: 600 8px/1.15 var(--sans); text-transform: uppercase; letter-spacing: 0.04em; text-align: center;
  padding: 3px 6px; border-radius: 3px; white-space: nowrap; }
.conf b { font: 700 11px/1.1 var(--mono); }
.conf.hi { color: #7fce9b; background: rgba(26,127,55,0.16); }
.conf.mid { color: #e0b968; background: rgba(224,165,46,0.16); }
.conf.lo { color: #e39494; background: rgba(214,69,69,0.16); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,0.15); }
.route-card .dist { font: 700 13px/1 var(--mono); letter-spacing: 0.01em; }
.lap-badge { font: 600 9.5px/1 var(--mono); color: var(--muted); background: var(--field);
  border: 1px solid var(--border); border-radius: 3px; padding: 3px 5px; white-space: nowrap; }
.laps-row { display: flex; align-items: center; gap: 10px; margin-top: 11px; }
.laps-row label { margin: 0; }
.laps-row input[type="number"] { width: 66px; flex: none; text-align: center; }
.laps-hint { margin-left: auto; font: 700 13px/1 var(--mono); color: var(--accent); white-space: nowrap; }
.route-card .sub { color: var(--muted); font: 500 11px/1.4 var(--mono); margin-top: 4px; }
/* score bar fills the card width proportionally (never dictates the card size) */
.bikebar { width: auto; height: 4px; border-radius: 2px; margin-top: 7px; background: var(--field); overflow: hidden; }
.bikebar > span { display: block; height: 100%; }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.rev, .cue-btn, .elev-btn, .edit-btn { display: inline-flex; align-items: center; gap: 4px; font: 600 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent);
  background: none; border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px; cursor: pointer; transition: border-color 0.12s; }
.rev:hover, .cue-btn:hover, .elev-btn:hover, .edit-btn:hover { border-color: var(--accent); }
.rev.on, .edit-btn.on { border-color: var(--accent); background: var(--accent-soft); }  /* active */
/* draggable vertex handle while editing a route */
.edit-handle { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--mark-start, #1a7f37);
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.4); cursor: grab; }
.edit-handle:active { cursor: grabbing; }
/* editor tools panel (shown while editing a route) */
.edit-tools { position: absolute; z-index: 55; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 22px rgba(0,0,0,0.45); }
.edit-tools .et-title { font: 700 9px/1 var(--sans); letter-spacing: 0.12em; color: var(--muted); }
.edit-tools button { display: inline-flex; align-items: center; gap: 5px; font: 600 11px/1 var(--sans); color: var(--accent); background: none;
  border: 1px solid var(--border); border-radius: 5px; padding: 6px 10px; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.edit-tools button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.edit-tools button:disabled { opacity: 0.4; cursor: default; }
.edit-tools .et-done { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.elevbox { margin-top: 8px; }
.elev-svg { width: 100%; height: 46px; display: block; }
.elev-area { fill: rgba(238, 241, 244, 0.10); }
.elev-line { fill: none; stroke: var(--accent); stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.elev-cap { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px;
  font: 500 9.5px/1.2 var(--mono); color: var(--muted); }
.elev-scrub { color: var(--accent); }
.elev-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--accent); }
.cuesheet { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; max-height: 220px; overflow-y: auto; }
.cue-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;
  font: 600 9px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.cue-copy { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; text-transform: uppercase; }
.cue-row { display: flex; align-items: baseline; gap: 8px; font: 500 11px/1.6 var(--mono); }
.cue-d { flex: none; width: 34px; text-align: right; color: var(--muted); }
.cue-n { color: var(--text); }
.cue-next { margin-left: auto; flex: none; color: var(--muted); font-size: 10px; white-space: nowrap; }
.rev:disabled { opacity: 0.5; cursor: default; }
.save-btn, .regen-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; display: inline-flex; align-items: center; }
.save-btn svg, .regen-btn svg { fill: none; stroke: currentColor; stroke-width: 2; }
.save-btn:hover, .save-btn.saved, .regen-btn:hover { color: var(--accent); }
.save-btn.saved svg { fill: currentColor; stroke: currentColor; }
.regen-btn:disabled { cursor: default; }
.regen-btn.spin svg { animation: bl-spin 0.7s linear infinite; transform-origin: 50% 50%; }
@keyframes bl-spin { to { transform: rotate(360deg); } }
.gpx { margin-left: auto; font: 600 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); text-decoration: none; }
.gpx:hover { color: var(--accent); }

.meta { width: 100%; box-sizing: border-box; margin-top: 12px; padding-top: 11px;
  border-top: 1px solid var(--hair); font: 500 10.5px/1.6 var(--mono); color: var(--muted); }
.meta-grid { display: grid; grid-template-columns: auto auto; gap: 2px 18px; justify-content: start; }
.meta-line { display: flex; gap: 14px; align-items: baseline; }
.meta-seed { color: var(--muted); opacity: 0.7; }
.meta code { background: var(--field); padding: 1px 5px; border-radius: 3px; color: var(--text); }
.notes { color: var(--warn); margin-top: 6px; }

/* ── saved routes panel ────────────────────────────────────────────────────── */
.saved-panel { position: absolute; top: 14px; left: 328px; z-index: 5; width: 236px;
  max-height: calc(100vh - 28px); overflow-y: auto; padding: 13px; }
.saved-head { display: flex; align-items: center; gap: 7px; cursor: grab; touch-action: none; user-select: none; }
.saved-head strong { flex: 1; font: 700 11px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.14em; }
.saved-head .grip { color: var(--muted); display: inline-flex; flex: none; }
.saved-head:active { cursor: grabbing; }
.saved-item { background: var(--raised); border: 1px solid var(--border); border-radius: 5px; padding: 8px 9px; margin-top: 8px; }
.saved-item.shown { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.saved-item .row1 { display: flex; align-items: center; gap: 7px; }
.saved-item .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,0.15); }
.saved-item .nm { flex: 1; font: 600 12px/1.2 var(--sans); background: none; border: 0; color: var(--text); min-width: 0; padding: 2px 0; }
.saved-item .nm:focus { outline: none; color: var(--accent); }
.saved-item .sub { color: var(--muted); font: 500 10.5px/1.5 var(--mono); margin-top: 3px; }
.saved-item .acts { display: flex; gap: 6px; margin-top: 7px; }
.saved-item .acts button { font: 600 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 4px; background: none; color: var(--accent); cursor: pointer; }
.saved-item .acts button:hover { border-color: var(--accent); }
.saved-item .acts .del { color: var(--muted); margin-left: auto; }
.saved-item .acts .del:hover { color: var(--danger); border-color: var(--danger); }
.saved-item .acts .show.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ── legend ────────────────────────────────────────────────────────────────── */
.legend { position: absolute; bottom: 16px; right: 16px; z-index: 5; padding: 9px 12px;
  font: 500 11px/1.5 var(--sans); max-width: 264px; }
.legend-head .ttl { flex: 0 0 auto; font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.12em; color: var(--text); }
.legend-body { margin-top: 8px; }
.legend .arrow { color: var(--accent); }
.legend .sub2 { color: var(--muted); margin: 3px 0 7px; font-size: 10.5px; }
.legend .grad-row { display: flex; align-items: center; gap: 8px; color: var(--muted);
  font: 600 9px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.06em; }
.legend .grad { flex: 1; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #3a3f47, #8a929c, #eef1f4); }

/* ── map controls (zoom, compass, layers) ──────────────────────────────────── */
.maplibregl-ctrl-group { overflow: hidden; }
.maplibregl-ctrl-group button { width: 30px; height: 30px; background: transparent; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border); }
.maplibregl-ctrl-group button:hover { background: var(--raised); }
.maplibregl-ctrl-group button:not(:disabled) .maplibregl-ctrl-icon { filter: var(--ctrl-icon-filter); }
.maplibregl-ctrl-attrib { background: rgba(20, 26, 33, 0.8); color: var(--muted); border-radius: 5px; font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--muted); }

.layer-ctrl { display: flex; align-items: center; gap: 7px; padding: 6px 9px; }
.layer-ctrl .layer-label { font: 700 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.layer-ctrl select { width: auto; font: 600 11px/1 var(--sans); color: var(--text); background: var(--field);
  border: 1px solid var(--border); border-radius: 4px; padding: 5px 6px; cursor: pointer; }

/* mirrors the floating .layer-ctrl as a form field — only shown on mobile,
   where the floating control sits behind the panel while it's expanded */
.mobile-only { display: none; }

/* ── colour-mode toggle + bikeability heatmap legend ─────────────────────────── */
.legend .cmode { display: flex; gap: 3px; margin-bottom: 8px; background: var(--field);
  border: 1px solid var(--border); border-radius: 5px; padding: 3px; }
.legend .cm { flex: 1; border: 0; background: none; color: var(--muted); cursor: pointer;
  font: 700 9px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; padding: 5px; border-radius: 3px; }
.legend .cm:hover { color: var(--text); }
.legend .cm.active { background: var(--raised); color: var(--text); }
.legend .qgrad { background: linear-gradient(90deg, #d64545, #e0a52e, #1a7f37); }

/* ── segment inspect popup ───────────────────────────────────────────────────── */
.bl-popup .maplibregl-popup-content { background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow);
  padding: 9px 26px 9px 11px; }  /* right gutter reserves space for the close button */
.bl-popup .maplibregl-popup-tip { display: none; }
.bl-popup .maplibregl-popup-close-button { color: var(--muted); font-size: 15px; line-height: 1;
  padding: 3px 6px; top: 2px; right: 2px; border-radius: 4px; }
.bl-popup .maplibregl-popup-close-button:hover { color: var(--text); background: none; }
.inspect .q { display: flex; align-items: center; gap: 7px; font: 700 12px/1 var(--mono); margin-bottom: 7px; }
.inspect .qdot { width: 11px; height: 11px; border-radius: 2px; flex: none; }
.inspect > div:not(.q) { display: flex; justify-content: space-between; gap: 14px; font: 500 11px/1.7 var(--sans); }
.inspect > div span { color: var(--muted); }
.inspect > div b { color: var(--text); font: 600 11px/1.7 var(--mono); }

/* ── avoid areas ─────────────────────────────────────────────────────────────── */
.avoid-row { display: flex; align-items: center; gap: 7px; margin-top: 6px; }
.avoid-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: rgba(209,106,106,0.2);
  border: 1.5px dashed #d16a6a; }
.avoid-shape { flex: none; width: 20px; height: 20px; border: 1px solid var(--border); border-radius: 4px;
  background: none; color: #d16a6a; cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; }
.avoid-shape:hover { border-color: #d16a6a; background: rgba(209,106,106,0.12); }
.avoid-row .avoid-r { flex: 1; min-width: 0; }
.avoid-row .avoid-rv { flex: none; width: 46px; text-align: right; font: 500 10.5px/1 var(--mono); color: var(--muted); }
.avoid-marker { width: 14px; height: 14px; border-radius: 50%; background: #d16a6a;
  border: 2px solid var(--bg); box-shadow: 0 1px 5px rgba(0,0,0,0.6); cursor: grab; }

/* ── mobile / narrow viewports ──────────────────────────────────────────────
   The layout is a set of absolutely-positioned overlays tuned for a wide screen;
   below ~700px reflow them so the map stays usable: the control panel becomes a
   full-width top sheet (collapsible → map-first), results a bottom strip, and the
   decorative legend hides. */
@media (max-width: 700px) {
  /* full-width top sheet with a docked header + footer and a scrolling middle
     (not the whole panel): a plain `position: sticky` Generate button doesn't
     work here — once the form is taller than the sheet, sticky pulls the
     button up to the visible bottom edge and paints it over whatever field
     sits there (Routes/Seed at rest) instead of staying clear of real
     content. */
  .panel {
    display: flex; flex-direction: column;
    top: 0; left: 0; right: 0; width: auto; max-width: none;
    max-height: 56vh; border-radius: 0 0 var(--r) var(--r);
    padding: 0 12px; overflow: hidden;
  }
  .panel-head { flex: 0 0 auto; padding: 10px 0 8px; }
  .panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 4px; }
  .panel-actions { flex: 0 0 auto; padding: 8px 0 10px; border-top: 1px solid var(--hair); }
  .panel.collapsed { width: auto; }  /* header-only → whole map visible */

  .routes-panel {
    top: auto; left: 6px; right: 6px; bottom: 6px; width: auto;
    max-width: none; max-height: 40vh;
  }
  .routes-body { width: auto; min-width: 0; max-width: none; }
  .route-card { min-width: 0; }

  .saved-panel { top: auto; left: 6px; right: 6px; bottom: 6px; width: auto; max-width: none; }

  /* legend hidden on mobile — not enough real estate to justify it */
  .legend { display: none; }

  /* the floating Layers control sits behind the panel whenever it's expanded
     (the panel is a full-width sheet covering that area) — swap it for the
     #basemapRow form field instead, which is reachable in either panel state */
  .layer-ctrl { display: none; }
  .mobile-only { display: block; }

  /* map controls (zoom/compass) sit just below the collapsed panel header, so
     they're visible whenever the panel isn't expanded (map-first state) */
  .maplibregl-ctrl-top-right { top: 52px; }

  /* the results strip is also bottom-anchored (see .routes-panel above) — pin
     edit tools to the free space under the header instead of fighting it there */
  .edit-tools { top: 60px; bottom: auto; gap: 6px; padding: 7px 9px; flex-wrap: wrap; justify-content: center; }

  /* touch targets: icon-only buttons sized for a mouse cursor read too small
     for a fingertip (Apple/Google guidance is ~44px) — grow the tap area
     without blowing up the visual weight of the chrome */
  .collapse-btn { width: 34px; height: 34px; }
  button.ghost { padding: 8px 11px; }
  .rev, .cue-btn, .elev-btn, .edit-btn { padding: 6px 10px; }
  .stop-del { padding: 6px 8px; }
  .avoid-shape { width: 30px; height: 30px; }
  .edit-handle { width: 20px; height: 20px; }
}

@media (max-width: 420px) {
  .panel { padding: 0 10px; font-size: 13px; }
  .panel-head { padding: 9px 0 7px; }
  .panel-actions { padding: 7px 0 9px; }
  .routes-body { padding: 9px 10px; }
}
