:root {
  --bg: #f6f5f1;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #ffffff;
  --ink: #17201f;
  --ink-2: #4d5957;
  --muted: #7d8886;
  --line: #e4e2dc;
  --hover: #f1efe9;
  --raised: #ffffff;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --live: #e11d48;
  --shadow: 0 12px 40px rgba(20, 30, 28, 0.16), 0 2px 6px rgba(20, 30, 28, 0.08);
  --radius: 16px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101413;
    --panel: rgba(24, 29, 28, 0.93);
    --panel-solid: #181d1c;
    --ink: #edf2f0;
    --ink-2: #b6c0bd;
    --muted: #84908d;
    --line: #2b3331;
    --hover: #222a28;
    --raised: #343e3c;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 Manrope, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; background: var(--bg); }

/* ---------- panel ---------- */
.panel {
  position: fixed;
  top: 12px; left: 12px; bottom: 12px;
  width: 380px;
  display: flex; flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  overflow: hidden;
}
/* Docked card (desktop, landscape phones): the grabber is a strip along the card's foot
   that folds it up to the header and chips. The Sheet script sets .collapsed. */
.grab {
  order: 1; flex: none; display: grid; place-items: center; width: 100%; height: 22px; padding: 0;
  border: 0; border-top: 1px solid var(--line); background: none; color: var(--muted);
}
.grab:hover { background: var(--hover); color: var(--ink); }
.grab span { width: 8px; height: 8px; border: solid currentColor; border-width: 2px 0 0 2px; transform: translateY(2px) rotate(45deg); }
.panel.collapsed { bottom: auto; }
.panel.collapsed .view { display: none; }
.panel.collapsed .grab { border-top: 0; }
.panel.collapsed .grab span { transform: translateY(-2px) rotate(225deg); }

.sheet-head { display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 10px; }
.search-row { display: flex; align-items: center; gap: 8px; }
.city-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; padding: 0;
  border: 1px solid var(--line); background: var(--panel-solid);
  font-size: 11.5px; font-weight: 800; letter-spacing: .02em; color: var(--accent);
}
.city-btn:hover { background: var(--hover); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: var(--accent); display: grid; place-items: center;
}
.brand-mark svg { width: 22px; height: 22px; fill: var(--accent-ink); }
.brand h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.brand p { margin: 1px 0 0; font-size: 12px; }
.city-name { border: 0; background: none; padding: 0; font: inherit; border-radius: 6px; }
.city-name::after { content: "▾"; margin-left: 5px; font-size: 12px; color: var(--muted); }
.city-name:hover { color: var(--accent); }

/* Direction and Layers next to the chips (desktop only). */
.dock-tools { display: none; flex: none; gap: 4px; margin-left: auto; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 0; padding: 0;
  background: var(--hover); color: var(--ink-2); display: grid; place-items: center;
}
.icon-btn:hover { color: var(--ink); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Live status chip: the count, and a tap turns live buses on or off. */
.live-chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 26px; border: 0; border-radius: 8px; padding: 0 11px 0 9px;
  background: color-mix(in srgb, var(--live) 10%, var(--panel-solid));
  color: color-mix(in srgb, var(--live) 75%, var(--ink));
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.live-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); position: relative; }
.live-chip .dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--live); opacity: 0; animation: pulse 2s ease-out infinite;
}
.live-chip[aria-pressed="false"] { background: var(--hover); color: var(--muted); }
.live-chip[aria-pressed="false"] .dot { background: var(--muted); }
.live-chip[aria-pressed="false"] .dot::after { display: none; }
.live-chip.error .dot { background: #d97706; }
@keyframes pulse { 0% { transform: scale(0.6); opacity: 0.9; } 100% { transform: scale(1.6); opacity: 0; } }

.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.search { flex: 1; min-width: 0; position: relative; }
.search svg {
  position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 36px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel-solid); color: var(--ink);
  font: inherit; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

.seg { display: flex; background: var(--hover); border-radius: 10px; padding: 2px; }
.seg button {
  border: 0; background: transparent; border-radius: 8px;
  padding: 4px 9px; font-size: 12px; font-weight: 700; color: var(--ink-2);
}
.seg button[aria-checked="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.city-seg a {
  flex: 1; text-align: center; text-decoration: none; border-radius: 8px;
  padding: 5px 9px; font-size: 12.5px; font-weight: 700; color: var(--ink-2);
}
.city-seg a[aria-current="page"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chip-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 0 16px 10px;
  border-bottom: 1px solid var(--line); min-height: 40px;
}
/* Rows of chips wrap under each other; min-height lines the first row up with the live chip. */
.selected-strip { flex: 1; min-width: 0; min-height: 26px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.selected-strip .hint { font-size: 12px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 26px; border: 0; border-radius: 7px; padding: 0 4px 0 7px;
  font: 700 12px/1.2 var(--mono); color: #fff;
}
.chip .x { opacity: .75; font-family: Manrope, sans-serif; font-size: 13px; padding: 0 2px; }
.chip:hover .x { opacity: 1; }
.chip.ghost { background: var(--hover); color: var(--ink); font-family: Manrope, sans-serif; padding-right: 9px; }
.chip.ghost .x { margin-left: 2px; }
.chip.ghost:has(.x) { padding-right: 4px; }

.route-list { overflow-y: auto; flex: 1; padding: 4px 8px 12px; overscroll-behavior: contain; }
.cat { margin-top: 6px; }
.cat-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 6px; background: var(--panel-solid);
  border-radius: 8px;
}
.cat-head .cat-title { flex: 1; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.cat-head .cat-count { font-size: 11px; color: var(--muted); }
.cat-head button.collapse { border: 0; background: none; padding: 2px 4px; color: var(--muted); transition: transform .15s; }
.cat.collapsed .collapse { transform: rotate(-90deg); }
.cat.collapsed .rows { display: none; }

.tri {
  width: 18px; height: 18px; flex: none; border-radius: 5px;
  border: 1.5px solid var(--muted); background: transparent; padding: 0;
  display: grid; place-items: center;
}
.tri[data-state="all"], .tri[data-state="some"] { background: var(--accent); border-color: var(--accent); }
.tri[data-state="all"]::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.tri[data-state="some"]::after { content: ""; width: 8px; height: 2px; background: var(--accent-ink); border-radius: 1px; }

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 10px; cursor: pointer;
  user-select: none;
}
.row:hover, .row.hl { background: var(--hover); }
.badge {
  flex: none; min-width: 48px; text-align: center;
  font: 700 13px/1 var(--mono); letter-spacing: -0.02em;
  padding: 7px 6px; border-radius: 8px;
  color: var(--cat); background: color-mix(in srgb, var(--cat) 12%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--cat) 35%, transparent);
  transition: background .12s, color .12s;
}
.row.sel .badge { color: #fff; background: var(--c); border-color: var(--c); }
.row .meta { flex: 1; min-width: 0; }
.row .title { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.row .live-n {
  flex: none; font: 700 11px/1 var(--mono); color: var(--live);
  display: inline-flex; align-items: center; gap: 4px;
}
.row .live-n::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.row .info {
  flex: none; width: 28px; height: 28px; border-radius: 8px; border: 0; background: transparent;
  color: var(--muted); display: grid; place-items: center;
}
.row .info:hover { background: var(--panel-solid); color: var(--ink); }
.row .info svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.show-all {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin: 6px 0 2px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--accent);
  padding: 8px 10px; font-size: 13px; font-weight: 700;
}
.show-all:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.show-all kbd { font: 600 11px var(--mono); color: var(--muted); }
@media (hover: none) { .show-all kbd { display: none; } }

/* Round close button (cards, route detail). */
.x-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0;
  background: var(--hover); color: var(--ink-2); font-size: 20px; line-height: 1;
  display: grid; place-items: center;
}
.x-btn:hover { color: var(--ink); }

/* ---------- detail view ---------- */
/* Header, tabs and body scroll together; the tabs stick to the top. */
.detail-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.detail-head { padding: 4px 16px 12px; }
.detail-title { display: flex; gap: 12px; align-items: flex-start; }
.detail-name { flex: 1; min-width: 0; }
.detail-title .badge { font-size: 16px; padding: 9px 8px; min-width: 60px; }
.detail-title h2 { margin: 0; font-size: 16px; font-weight: 800; line-height: 1.3; }
.detail-title .cat-name { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--cat); margin-bottom: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.actions a, .actions button {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--panel-solid); color: var(--ink);
  border-radius: 9px; padding: 6px 10px; font-size: 12px; font-weight: 700; text-decoration: none;
}
.actions svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.actions a:hover, .actions button:hover { background: var(--hover); }
.actions .primary { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); color: #fff; }
.tabs {
  position: sticky; top: 0; z-index: 3; display: flex; gap: 2px; padding: 2px 16px 0;
  background: var(--panel-solid); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; padding: 8px 10px 10px; font-weight: 700; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--c, var(--accent)); }
.tab-body { padding: 12px 16px 20px; }

.variant { margin-bottom: 18px; }
.variant-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.variant-head .dir {
  font: 700 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 6px; border-radius: 5px; background: var(--hover); color: var(--ink-2);
}
.variant-head .vname { font-size: 12.5px; font-weight: 700; flex: 1; }
.variant-head .vtrips { font-size: 11px; color: var(--muted); white-space: nowrap; }
.variant-head input { accent-color: var(--c); }
.stops { list-style: none; margin: 0; padding: 0 0 0 6px; }
.stops li {
  position: relative; padding: 3px 0 3px 18px; font-size: 12.5px; cursor: pointer; border-radius: 6px;
}
.stops li::before {
  content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 3px; background: var(--c);
}
.stops li:first-child::before { top: 50%; }
.stops li:last-child::before { bottom: 50%; }
.stops li::after {
  content: ""; position: absolute; left: 0; top: 50%; width: 9px; height: 9px; margin-top: -4.5px;
  border-radius: 50%; background: var(--panel-solid); border: 2px solid var(--c); box-sizing: border-box;
}
.stops li:first-child::after, .stops li:last-child::after { background: var(--c); }
.stops li:hover { background: var(--hover); }
.stops li .code { font: 500 10.5px var(--mono); color: var(--muted); margin-left: 6px; }

.day-seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.day-seg button {
  border: 1px solid var(--line); background: var(--panel-solid); border-radius: 8px;
  padding: 5px 9px; font-size: 12px; font-weight: 700; color: var(--ink-2);
}
.day-seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel-solid); border-color: var(--ink); }
.day-label { font-size: 11.5px; color: var(--muted); margin: 0 0 12px; }
.times { display: flex; flex-wrap: wrap; gap: 4px; }
.times span {
  font: 500 12px/1 var(--mono); padding: 5px 6px; border-radius: 6px; background: var(--hover);
}
.times span.past { opacity: .4; }
.times span.next { background: var(--c); color: #fff; font-weight: 700; }
.times sup { font: 700 9.5px/0 var(--mono); color: var(--c); margin-left: 2px; }
.times span.next sup { color: #fff; }
.legend { margin: 7px 0 0; font-size: 11.5px; color: var(--muted); }
.legend b { font: 700 11px var(--mono); color: var(--c); }
.variant-head .via { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.notes { white-space: pre-wrap; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.notes-src { font-size: 11.5px; margin-top: 14px; }
.notes-src a { color: var(--accent); }

/* ---------- layers dialog ---------- */
.layers {
  width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel-solid); color: var(--ink); box-shadow: var(--shadow);
}
.layers::backdrop { background: rgba(10, 15, 14, 0.32); }
.layers-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 12px 18px; }
.layers-head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.layers-head .close {
  width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0;
  background: var(--hover); color: var(--ink-2); font-size: 18px; line-height: 1;
}
.layers-body { padding: 0 18px 18px; }
.layers-sec h3 {
  margin: 14px 0 8px; font-size: 11px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.layers-sec:first-child h3 { margin-top: 2px; }
.layers .seg { border-radius: 11px; padding: 3px; gap: 2px; }
.layers .seg :is(a, button) { flex: 1; min-height: 36px; padding: 0 8px; font-size: 13px; display: grid; place-items: center; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; border-top: 1px solid var(--line); cursor: pointer;
  font-size: 14.5px; font-weight: 650;
}
.toggle:first-of-type { border-top: 0; }
.toggle small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.toggle input {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative;
  transition: background .2s;
}
.toggle input::before {
  content: ""; position: absolute; left: 2px; top: 2px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.toggle input:checked { background: var(--accent); }
.toggle input:checked::before { transform: translateX(20px); }
.toggle input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.layers-foot { margin: 14px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.layers-foot span { display: block; }
.layers-foot a { color: var(--ink-2); }

/* ---------- map overlays ---------- */
.leaflet-container { font: inherit; background: var(--bg); }
.leaflet-control-zoom, .map-ctl {
  border: 1px solid var(--line) !important; border-radius: 12px !important; overflow: hidden;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a, .map-ctl button {
  background: var(--panel-solid) !important; color: var(--ink) !important;
  border-color: var(--line) !important; width: 36px !important; height: 36px !important; line-height: 36px !important;
}
.map-ctl { display: flex; flex-direction: column; background: var(--panel-solid); }
.map-ctl button { border: 0; display: grid; place-items: center; padding: 0; }
.map-ctl button + button { border-top: 1px solid var(--line) !important; }
.map-ctl button:hover { background: var(--hover) !important; }
.map-ctl svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--panel-solid) 80%, transparent) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--ink-2) !important; }

.leaflet-popup-content-wrapper, .leaflet-tooltip {
  background: var(--panel-solid); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--panel-solid); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; min-width: 220px; }
.leaflet-tooltip { border: 1px solid var(--line); padding: 5px 8px; font-weight: 600; font-size: 12px; }
.leaflet-tooltip-top::before { border-top-color: var(--panel-solid); }
.tt-num { font-family: var(--mono); font-weight: 700; color: var(--c); margin-right: 4px; }

.pop-title { font-weight: 800; font-size: 14px; margin-bottom: 2px; }
.pop-sub { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
.pop-routes { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.pop-routes .chip { padding: 3px 4px 3px 7px; background: var(--c); }
.pop-routes .chip.off { background: transparent; color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--line); }
/* Departures: badge, headsign over the variant hint, then "in N min" over the clock time. */
.dep { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.dep .dn {
  flex: none; min-width: 40px; text-align: center; padding: 4px 5px; border-radius: 7px;
  font: 700 12px/1.1 var(--mono); color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 35%, transparent);
}
.dep .dn.sel { color: #fff; background: var(--c); box-shadow: none; }
.dep .to { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep .to small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.dep .when { flex: none; text-align: right; font: 700 13px/1.15 var(--mono); white-space: nowrap; }
.dep .when small { display: block; font: 500 10.5px/1.35 var(--mono); color: var(--muted); }
.dep .when.soon { color: var(--accent); }
.live-mark { color: var(--live); font-weight: 700; }
.live-mark::before { content: "● "; }
.pop-empty { color: var(--muted); font-size: 12px; }
.pop-btn {
  margin-top: 10px; width: 100%; border: 0; border-radius: 9px; padding: 7px; font-weight: 700; font-size: 12px;
  background: var(--c, var(--accent)); color: #fff;
}
.pop-btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px var(--line); }

/* ---------- cards: stop, bus and route info in the sheet (phones) ---------- */
.card-view { position: relative; }
.card-x { position: absolute; top: 10px; right: 14px; z-index: 3; }
.card-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px 18px 16px; }
.card-body .pop-title { font-size: 19px; line-height: 1.2; letter-spacing: -.01em; padding-right: 44px; margin-bottom: 3px; }
.card-body .pop-sub { font-size: 12.5px; margin-bottom: 12px; padding-right: 44px; }
/* One swipeable row, so a big station's 30+ routes don't push the departures away. */
.card-body .pop-routes {
  gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  margin: 0 -18px 6px; padding: 0 18px 6px;
}
.card-body .pop-routes::-webkit-scrollbar { display: none; }
.card-body .pop-routes .chip { flex: none; }
.card-body .kv { font-size: 14px; gap: 6px 16px; }
.card-body .pop-btn { min-height: 44px; font-size: 14px; border-radius: 12px; }
.card-body .dep { min-height: 58px; gap: 12px; }
.card-body .dep .dn { min-width: 46px; padding: 7px 6px; font-size: 13px; border-radius: 8px; }
.card-body .dep .to { font-size: 14.5px; }
.card-body .dep .to small { font-size: 12px; margin-top: 1px; }
.card-body .dep .when { font-size: 16px; }
.card-body .dep .when small { font-size: 11.5px; margin-top: 2px; }
.card-body .pop-empty { font-size: 14px; padding: 12px 0; }
/* The stop a card is about. */
.stop-ring {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  border: 3px solid var(--ink); background: color-mix(in srgb, var(--panel-solid) 35%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--panel-solid) 75%, transparent), 0 2px 10px rgba(0, 0, 0, .3);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.late { color: #dc2626; } .early { color: #2563eb; } .ontime { color: #16a34a; }

/* hub stations */
.hub {
  display: flex; align-items: center; gap: 5px; white-space: nowrap;
  transform: translate(-9px, -9px);
}
.hub i {
  width: 18px; height: 18px; border-radius: 6px; flex: none;
  background: var(--ink); border: 2px solid var(--panel-solid); box-shadow: 0 1px 4px rgba(0,0,0,.35);
  display: grid; place-items: center;
}
.hub i::after { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--panel-solid); }
.hub b {
  font-size: 11.5px; font-weight: 800; color: var(--ink);
  text-shadow: 0 0 3px var(--panel-solid), 0 0 3px var(--panel-solid), 0 0 3px var(--panel-solid), 0 0 3px var(--panel-solid);
}

/* live buses */
.bus { position: relative; width: 0; height: 0; }
.bus .pill {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  font: 700 11px/1 var(--mono); color: #fff; background: var(--c);
  padding: 4px 6px; border-radius: 8px; border: 2px solid #fff; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.bus .arrow {
  position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; pointer-events: none;
}
.bus .arrow::before {
  content: ""; position: absolute; left: 50%; top: 0; margin-left: -6px;
  border: 6px solid transparent; border-bottom: 9px solid var(--c); border-top: 0;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1px #fff);
}
.zoomed-out .bus .pill { font-size: 9.5px; padding: 2px 4px; border-width: 1.5px; border-radius: 6px; }
.zoomed-out .bus .arrow { display: none; }
.bus.stale .pill { opacity: .55; }
.bus.dim .pill { background: #6b7280; }
.bus.dim .arrow::before { border-bottom-color: #6b7280; }
.leaflet-marker-icon.bus-icon { transition: transform 1.2s linear; }
.no-bus-anim .leaflet-marker-icon.bus-icon { transition: none; }
.leaflet-zoom-anim .leaflet-marker-icon.bus-icon { transition: transform .25s cubic-bezier(0, 0, .25, 1); }

.me { width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(37,99,235,.25); }

/* Pinch zooms on touch screens; +/− is for mouse users. */
@media (pointer: coarse) {
  .leaflet-control-zoom { display: none; }
}

/* The layouts below split the viewport three ways, matching app.js:
   phone portrait (bottom sheet), landscape phone (docked card) and desktop. */

/* ---------- desktop: one brand/city/live row, Direction and Layers by the chips ---------- */
@media (min-width: 721px) and (min-height: 501px) {
  .sheet-head { gap: 10px; padding: 14px 14px 10px; }
  .brand { gap: 10px; padding-right: 96px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-mark svg { width: 20px; height: 20px; }
  .brand h1 { font-size: 16px; line-height: 1.25; }
  .brand p { margin: 0; font-size: 11.5px; }
  .search-row .city-btn { display: none; }
  /* The live chip sits at the end of the brand row. */
  .chip-row { padding: 0 14px 10px; min-height: 38px; }
  .chip-row .live-chip { position: absolute; top: 16px; right: 14px; height: 30px; border-radius: 15px; }
  .selected-strip { min-height: 28px; }
  .dock-tools { display: flex; }
}

/* ---------- touch layouts: phone sheet and landscape dock ---------- */
@media (max-width: 720px), (orientation: landscape) and (max-height: 500px) {
  :root { --head-h: 52px; --chips-h: 44px; }

  /* Locked page: no rubber-band scroll or pull-to-refresh behind the map. */
  html, body { overflow: hidden; overscroll-behavior: none; }
  body { position: fixed; inset: 0; height: 100dvh; }

  .sheet-head .brand { display: none; }
  .search svg { width: 18px; height: 18px; }
  .search input { height: 44px; border-radius: 12px; padding-left: 38px; font-size: 16px; background: var(--hover); border-color: transparent; }
  .city-btn { width: 44px; height: 44px; background: var(--hover); border-color: transparent; }

  /* One line of 34 px chips; the row's padding makes each a 44 px target. */
  .chip-row {
    flex: none; height: var(--chips-h); min-height: 0; padding: 0 14px 10px; align-items: center;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; touch-action: pan-x;
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip-row .live-chip { height: 34px; border-radius: 10px; padding: 0 12px 0 10px; font-size: 13px; }
  .selected-strip { flex-wrap: nowrap; gap: 6px; }
  .selected-strip .hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
  .chip { flex: none; height: 34px; border-radius: 10px; padding: 0 6px 0 10px; font-size: 13px; position: relative; }
  .chip::after { content: ""; position: absolute; inset: -5px 0; }
  .chip .x { font-size: 15px; }

  .day-seg button { min-height: 36px; }

  /* Route detail: compact header, one scrolling row of actions. */
  .detail-head { padding: 10px 14px 12px; }
  .detail-title .badge { min-width: 56px; }
  .detail-title h2 { font-size: 16.5px; }
  .x-btn { width: 40px; height: 40px; }
  .card-x { top: 8px; right: 12px; }
  .actions {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 12px -14px 0; padding: 0 14px;
  }
  .actions::-webkit-scrollbar { display: none; }
  .actions a, .actions button { flex: none; min-height: 40px; padding: 0 13px; border-radius: 11px; font-size: 13px; white-space: nowrap; }
  .actions svg { width: 16px; height: 16px; }
  .tabs { padding: 0 14px; }
  .tabs button { min-height: 44px; padding: 0 12px; font-size: 14px; }
  .tab-body { padding: 12px 14px 20px; }
  .stops li { padding: 7px 0 7px 18px; font-size: 14px; }
  .show-all { min-height: 44px; }
  .layers .seg :is(a, button) { min-height: 40px; }
  .row { min-height: 56px; padding: 6px 4px 6px 8px; }
  .row .title { font-size: 14px; -webkit-line-clamp: 1; }
  .row .sub { font-size: 12px; }
  .row .info { width: 44px; height: 44px; }

  .leaflet-control-attribution { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10px; border-radius: 6px; }
  .map-ctl { background: none; border: 0 !important; box-shadow: none !important; overflow: visible; gap: 8px; }
  .map-ctl button {
    width: 46px !important; height: 46px !important; border-radius: 50%; border: 1px solid var(--line) !important;
    box-shadow: var(--shadow);
  }
  .map-ctl svg { width: 20px; height: 20px; }
  .layers-head .close { width: 44px; height: 44px; }
}

/* ---------- phone portrait: bottom sheet ----------
   The sheet is a viewport-tall panel slid down by --sheet-top, so moving it is a
   transform, never a relayout. --sheet-top is the sheet's top edge in viewport
   px; the map buttons and attribution sit on it. The Sheet script in app.js
   reads the detents below, drags --sheet-top and sets --sheet-rest and
   data-sheet once the sheet settles. */
@media (max-width: 720px) and (orientation: portrait), (max-width: 720px) and (min-height: 501px) {
  :root {
    --grab-h: 22px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --peek-h: calc(var(--grab-h) + var(--head-h) + var(--chips-h) + 14px + var(--safe-b));
    --y-peek: calc(100dvh - var(--peek-h));
    --y-half: 48dvh;
    --y-full: calc(env(safe-area-inset-top, 0px) + 40px);
    --sheet-top: var(--y-peek);
  }

  .panel {
    top: 0; left: 0; right: 0; bottom: auto; width: auto;
    height: 100vh; height: 100dvh;
    border-width: 1px 0 0; border-radius: 22px 22px 0 0;
    box-shadow: 0 -6px 28px rgba(20, 30, 28, 0.16);
    transform: translateY(var(--sheet-top));
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
    will-change: transform;
  }
  .sheet-dragging .panel { transition: none; }

  .grab {
    order: 0; height: var(--grab-h); border: 0; touch-action: none;
  }
  .grab:hover { background: none; }
  .grab span { width: 38px; height: 5px; border: 0; border-radius: 3px; background: var(--muted); opacity: .45; transform: none; }

  .sheet-head { flex: none; height: var(--head-h); padding: 0 14px 8px; touch-action: none; }

  /* Only the on-screen part of a view is reachable, so end it at the viewport bottom. */
  .sheet .view { padding-bottom: var(--sheet-rest, var(--sheet-top)); }
  .route-list, .tab-body, .card-body { padding-bottom: max(12px, var(--safe-b)); }

  /* Map buttons and attribution ride on the sheet's top edge. */
  .leaflet-top.leaflet-right, .leaflet-bottom {
    top: 0; bottom: auto; transform: translateY(calc(var(--sheet-top) - 100%));
    transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .2s;
  }
  .sheet-dragging :is(.leaflet-top.leaflet-right, .leaflet-bottom) { transition: opacity .2s; }
  /* At full they would sit under the status bar with almost no map to act on. */
  [data-sheet="full"] :is(.leaflet-top.leaflet-right, .leaflet-bottom) { opacity: 0; pointer-events: none; }
  .leaflet-top.leaflet-right .leaflet-control { margin: 0 12px 12px 0; }
  .leaflet-bottom.leaflet-right { left: 0; right: auto; }
  .leaflet-bottom.leaflet-right .leaflet-control { margin: 0 0 12px 10px; }
  .leaflet-control-attribution { max-width: calc(100vw - 90px); }

  .layers {
    width: 100%; max-width: none; margin: auto 0 0; max-height: calc(100dvh - var(--y-full));
    border-width: 1px 0 0; border-radius: 22px 22px 0 0;
    padding-bottom: var(--safe-b);
  }
}

/* ---------- landscape phone: the sheet docks as a left card ----------
   Same content, no detents; the foot strip folds it. Clear of the notch on either side. */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --dock-w: clamp(340px, 44vw, 360px); }
  .panel {
    top: max(8px, env(safe-area-inset-top)); bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left)); width: var(--dock-w);
  }
  .grab { height: 30px; }
  .grab span { width: 9px; height: 9px; }
  .sheet-head { flex: none; padding: 10px 10px 8px; }
  .chip-row { padding: 0 10px 10px; }

  /* Map buttons bottom-right, in thumb reach, above the attribution. */
  .leaflet-right { right: env(safe-area-inset-right, 0px); }
  .leaflet-top.leaflet-right { top: auto; bottom: 22px; }
  .leaflet-top.leaflet-right .leaflet-control { margin: 0 12px 8px 0; }
  .leaflet-control-attribution { max-width: calc(100vw - var(--dock-w) - 40px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }
  .layers { max-height: calc(100dvh - 16px); }
}
