:root {
  --ink: #1f2933;
  --muted: #5f6b76;
  --line: #d9dee3;
  --bg: #fff;
  --soft: #f3f5f7;
  --accent: #8e3fb5;
  --accent-ink: #6a1b9a;
  --danger: #b3261e;
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  --app-bg: #e9ecef;
  --row-line: var(--row-line);
  --solid: #1f2933;        /* dark buttons/pills */
  --solid-ink: #fff;
  --handle: #c4cad0;
  --hl-bg: #f3e8fa;        /* timetable: this station's row */
  --sel: #fff5cc;          /* timetable: selected trip */
  --sel-hl: #ffe680;
  --past: #a4acb4;
  --past-hl: #b99bcc;
  --dim: #c3c8cd;
  --next: #2e7d32;
  --danger-line: #e8b4b0;
  --label-ink: #111;       /* station names on the map */
  --label-halo: #fff;
  --hub-ink: #1d4f91;
  --tag-edge: #fff;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
html.dark {
  --ink: #e6e9ec;
  --muted: #9aa5b1;
  --line: #3a424b;
  --bg: #1e2328;
  --soft: #2a3037;
  --accent: #a45bc9;
  --accent-ink: #e1bdf5;
  --danger: #e0574d;
  --shadow: 0 2px 10px rgba(0, 0, 0, .55);
  --app-bg: #14171a;
  --row-line: #2c333a;
  --solid: #e6e9ec;
  --solid-ink: #14171a;
  --handle: #4a535c;
  --hl-bg: #3a2548;
  --sel: #4a4220;
  --sel-hl: #6b5a14;
  --past: #6c7680;
  --past-hl: #9b7fae;
  --dim: #4f5861;
  --next: #66bb6a;
  --danger-line: #7a3530;
  --label-ink: #f1f3f5;
  --label-halo: #111;
  --hub-ink: #8ab4f8;
  --tag-edge: #15191d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--app-bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#map { position: fixed; inset: 0; }

/* ------------------------------------------------ top bar */
#topbar {
  position: fixed; z-index: 1005; /* above the side panels so search results aren't hidden behind them */
  top: calc(10px + var(--safe-t)); left: 10px; right: 68px;
  display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.search { position: relative; flex: 1 1 220px; max-width: 420px; }
#search {
  width: 100%; height: 46px; border: 0; border-radius: 23px; padding: 0 18px;
  background: var(--bg); box-shadow: var(--shadow); outline: none; font-size: 16px;
}
#search-results {
  position: absolute; top: 52px; left: 0; right: 0; margin: 0; padding: 6px 0; list-style: none;
  background: var(--bg); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto;
}
#search-results li { padding: 9px 14px; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
#search-results li:hover { background: var(--soft); }
#search-results li small { flex-basis: 100%; color: var(--muted); padding-left: 20px; }
#search-results li.empty { color: var(--muted); cursor: default; }
.k { width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--hub-ink); background: #fff; flex: none; }
.k.rail { border-color: #222; }
.chip {
  height: 46px; border: 0; border-radius: 23px; padding: 0 16px; background: var(--accent); color: #fff;
  box-shadow: var(--shadow); font-weight: 600; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ------------------------------------------------ floating buttons */
#fabs {
  position: fixed; z-index: 1000; top: calc(10px + var(--safe-t)); right: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--bg);
  box-shadow: var(--shadow); display: grid; place-items: center; padding: 0;
}
.fab svg { width: 24px; height: 24px; fill: var(--ink); }
.fab.on { background: var(--solid); }
.fab.on svg { fill: var(--solid-ink); }
#btn-locate.on svg { fill: #1a73e8; }

.card {
  position: fixed; z-index: 1001; top: calc(10px + var(--safe-t)); right: 66px;
  width: min(320px, calc(100vw - 80px)); max-height: calc(100vh - 30px); overflow-y: auto;
  background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 14px 12px;
}
.card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 4px; }
.opt { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.opt input { width: 18px; height: 18px; accent-color: var(--ink); }
.legend div { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 13px; }
.swatch { width: 28px; height: 5px; background: var(--c); border-radius: 3px; flex: none; }
.swatch.cr { background: repeating-linear-gradient(90deg, var(--c) 0 9px, transparent 9px 12px); }
.help-link { display: block; margin: 8px 0 2px; padding: 9px 12px; border-radius: 10px; background: var(--soft); color: var(--ink); font-weight: 700; text-decoration: none; }
.fine { font-size: 11px; color: var(--muted); margin: 12px 0 0; }

/* ------------------------------------------------ bottom sheet (mobile) / side panel (desktop) */
.sheet {
  position: fixed; z-index: 1002; left: 0; right: 0; bottom: 0;
  height: 60vh; height: 60dvh;
  background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: 0 -2px 14px rgba(0, 0, 0, .2);
  display: flex; flex-direction: column; padding: 0 14px var(--safe-b);
  transition: height .2s ease;
}
body.sheet-full #sheet { height: 88vh; height: 88dvh; }
.sheet.measure { height: auto; max-height: 55vh; max-height: 55dvh; overflow-y: auto; padding-bottom: calc(12px + var(--safe-b)); }
.handle { border: 0; background: none; padding: 8px 0 2px; display: grid; place-items: center; flex: none; }
.handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--handle); }
.sheet.measure .sheet-head { padding-top: 12px; }
.sheet-head { display: flex; align-items: flex-start; gap: 8px; flex: none; }
.titles { flex: 1; min-width: 0; }
.kind { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sheet h2 { margin: 1px 0 4px; font-size: 19px; line-height: 1.2; }
.icon-btn { border: 0; background: var(--soft); width: 36px; height: 36px; border-radius: 50%; font-size: 22px; line-height: 1; flex: none; }
.icon-btn.small { width: 28px; height: 28px; font-size: 18px; }
.st-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2px 0 8px; flex: none; }
#st-mine { padding: 5px 12px; font-size: 14px; }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 20px; padding: 8px 14px; font-weight: 600; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.small { padding: 4px 10px; font-size: 13px; margin-top: 6px; }
.muted { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; flex: none; padding-bottom: 6px; scrollbar-width: thin; }
.tab {
  border: 2px solid var(--c); background: var(--bg); color: var(--ink); border-radius: 10px;
  min-width: 44px; height: 36px; padding: 0 10px; font-weight: 700; flex: none;
}
.tab.active { background: var(--c); color: var(--t); }
/* same shapes as the tags on the map: ovals for rail, rounded boxes for bus */
.tab.rail { border-radius: 50%; min-width: 42px; padding: 0 8px; }
.tab.bus { border-radius: 8px; }
.tt-controls { display: flex; gap: 8px; align-items: stretch; margin: 2px 0 6px; flex: none; }
.dir-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left;
  border: 1px solid var(--solid); background: var(--solid); color: var(--solid-ink); border-radius: 8px; padding: 6px 10px; font-size: 14px;
}
.dir-btn span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-btn b { flex: none; font-size: 16px; }
.dir-btn:disabled { opacity: .85; cursor: default; }
#tt-day { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); font-size: 14px; }
.note { font-size: 12.5px; max-height: 3.2em; overflow-y: auto; color: var(--muted); flex: none; }
.note:not(:empty) { margin-bottom: 6px; }

/* timetable: stops down the side, trips across; the station's row sticks */
.tt-wrap { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tt-msg { padding: 20px; color: var(--muted); }
table.tt { border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.tt th, .tt td { padding: 5px 7px; white-space: nowrap; border-bottom: 1px solid var(--row-line); background: var(--bg); }
.tt td { text-align: right; cursor: pointer; }
.tt td.x { color: var(--dim); cursor: default; text-align: center; }
.tt thead th { position: sticky; top: 0; z-index: 3; height: 26px; font-size: 11px; color: var(--muted); font-weight: 600; background: var(--soft); }
.tt th.stop {
  position: sticky; left: 0; z-index: 2; text-align: left; font-weight: 500;
  max-width: 11.5em; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line); cursor: pointer;
}
.tt thead th.stop { z-index: 4; }
.tt tr.hl > * { background: var(--hl-bg); font-weight: 700; color: var(--accent-ink); border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent); }
.tt tr.stick > * { position: sticky; top: 26px; bottom: 0; z-index: 2; }
.tt tr.stick > th.stop { z-index: 3; left: 0; }
.tt td.past { color: var(--past); }
.tt tr.hl td.past { color: var(--past-hl); }
.tt td.next { box-shadow: inset 2px 0 0 var(--next); }
.tt th.next { color: var(--next); }
.tt .sel { background: var(--sel) !important; }
.tt tr.hl .sel { background: var(--sel-hl) !important; }
.tt td:hover { background: var(--soft); }

/* measure */
.m-list { list-style: none; margin: 8px 0; padding: 0; }
.m-list li { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--row-line); }
.m-list li .m-seg { flex: 1; color: var(--muted); }
.m-list li .m-seg b { color: var(--ink); }
.m-list li:not(:has(.m-seg)) .pin-dot { margin-right: auto; }
.m-total { justify-content: flex-end; }
.pin-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; flex: none; }
.m-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; margin-top: 8px; }
.m-matrix-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 4px; }
.scroll-x { overflow-x: auto; }
#m-matrix table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#m-matrix th, #m-matrix td { padding: 4px 8px; border: 1px solid var(--row-line); text-align: right; white-space: nowrap; }
#m-matrix th { background: var(--soft); text-align: center; }

.pin-icon .pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--danger); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
  display: grid; place-items: center;
}
.pin-icon .pin b { transform: rotate(45deg); color: #fff; font-size: 13px; font-weight: 800; }
.leaflet-tooltip.seg-label { background: var(--solid); color: var(--solid-ink); border: 0; font-weight: 700; padding: 2px 7px; border-radius: 10px; box-shadow: none; }
.leaflet-tooltip.seg-label::before { display: none; }
.measuring { cursor: crosshair; }

/* station labels */
.leaflet-tooltip.stn-label {
  background: none; border: 0; box-shadow: none; padding: 0; font-weight: 700; font-size: 12px; color: var(--label-ink);
  text-shadow: 0 0 2px var(--label-halo), 0 0 2px var(--label-halo), 0 0 3px var(--label-halo), 0 0 4px var(--label-halo); display: none;
}
.leaflet-tooltip.stn-label::before { display: none; }
.z-labels .leaflet-tooltip.stn-label.rail { display: block; }
.z-hub-labels .leaflet-tooltip.stn-label.hub { display: block; color: var(--hub-ink); font-size: 11px; }
.hide-hubs .hub-marker { display: none; }

#loading {
  position: fixed; z-index: 2000; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--bg); padding: 14px 20px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600;
}

.leaflet-control-scale { margin-bottom: 8px !important; }
.leaflet-control-attribution { font-size: 10px; }
body.sheet-open .leaflet-bottom, body.measure-open .leaflet-bottom { display: none; }

@media (min-width: 820px) {
  .sheet {
    left: 12px; right: auto; top: calc(68px + var(--safe-t)); bottom: 12px; width: 440px; height: auto;
    border-radius: var(--radius); padding-bottom: 0;
  }
  body.sheet-full #sheet { height: auto; }
  .sheet .handle { display: none; }
  #sheet .sheet-head { padding-top: 14px; }
  .sheet.measure { bottom: auto; max-height: calc(100vh - 90px); }
  body.sheet-open .leaflet-bottom, body.measure-open .leaflet-bottom { display: block; }
}

.route-pop .leaflet-popup-content { margin: 8px 12px; font-size: 14px; }
.rtag { display: inline-block; color: #fff; font-weight: 800; border-radius: 6px; padding: 1px 7px; margin-right: 4px; }

/* route tags along the lines (js/labels.js) */
.line-tag { width: 0; height: 0; }
.line-tag span {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font: 700 11px/14px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 1px 5px; border-radius: 5px; border: 1.5px solid var(--tag-edge); box-shadow: 0 0 2px rgba(0, 0, 0, .35);
}
.line-tag.rail span { font-size: 12px; padding: 1px 6px; border-radius: 50%; min-width: 20px; text-align: center; }

/* ------------------------------------------------ dark mode */
.fab .i-sun { display: none; }
html.dark .fab .i-sun { display: block; }
html.dark .fab .i-moon { display: none; }
.leaflet-container { background: var(--app-bg); }
/* street-style basemaps get darkened in place (colours rotated back so parks stay green, water blue) */
html.dark .leaflet-tile-pane.darken { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.7); }
html.dark path.rail-case { stroke: #101418; }
html.dark path.measure-line { stroke: #f1f3f5; }
html.dark .leaflet-bar a { background: var(--bg); color: var(--ink); border-bottom-color: var(--line); }
html.dark .leaflet-control-attribution { background: rgba(30, 35, 40, .8); color: var(--muted); }
html.dark .leaflet-control-attribution a { color: #8ab4f8; }
html.dark .leaflet-control-scale-line { background: rgba(30, 35, 40, .75); color: var(--ink); border-color: var(--ink); }
html.dark .leaflet-popup-content-wrapper, html.dark .leaflet-popup-tip { background: var(--bg); color: var(--ink); }
html.dark .leaflet-tooltip:not(.stn-label):not(.seg-label) { background: var(--bg); color: var(--ink); border-color: var(--line); }

/* ------------------------------------------------ pins */
.m-label { display: block; color: var(--ink); font-weight: 600; font-size: 13px; }
.m-list li.live { background: var(--soft); border-radius: 8px; padding-left: 4px; }
.pin-dot.live { background: var(--c); width: auto; min-width: 26px; padding: 0 6px; border-radius: 13px; font-size: 11px; }
.m-actions .btn { flex: 1 1 auto; }
.m-actions .btn:disabled { opacity: .45; cursor: default; }
.pin-pop .pin-pop-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pin-pop .btn.small { margin-top: 0; }
.pin-icon.moving .pin { animation: pin-pulse 1s ease-in-out infinite; }
@keyframes pin-pulse { 50% { transform: rotate(-45deg) scale(1.25); } }
.banner {
  position: fixed; z-index: 1003; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-t));
  display: flex; align-items: center; gap: 10px; background: var(--solid); color: var(--solid-ink);
  padding: 8px 8px 8px 16px; border-radius: 24px; box-shadow: var(--shadow); font-weight: 600; max-width: calc(100vw - 24px);
}
.banner .btn { background: var(--bg); color: var(--ink); }
.toast {
  position: fixed; z-index: 2001; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--safe-b));
  background: var(--solid); color: var(--solid-ink); padding: 10px 18px; border-radius: 22px; box-shadow: var(--shadow);
  font-weight: 600; max-width: calc(100vw - 32px); text-align: center;
}

/* ------------------------------------------------ pin layers, borders, nearby */
.poi-icon span {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--c); color: #fff; font-size: 13px; font-weight: 800; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
.poi-swatch { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #fff; font-size: 11px; font-weight: 800; }
.leaflet-tooltip.area-label {
  background: none; border: 0; box-shadow: none; padding: 0; display: none; white-space: nowrap;
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  text-shadow: 0 0 2px var(--label-halo), 0 0 3px var(--label-halo), 0 0 4px var(--label-halo);
}
.leaflet-tooltip.area-label::before { display: none; }
.leaflet-tooltip.area-label.county { color: #37474f; font-size: 13px; }
.leaflet-tooltip.area-label.city { color: #7b1fa2; font-size: 11px; }
.z-county-labels .leaflet-tooltip.area-label.county, .z-city-labels .leaflet-tooltip.area-label.city { display: block; }
html.dark path.border-county { stroke: #cfd8dc; }
html.dark path.border-city { stroke: #ce93d8; }
html.dark .leaflet-tooltip.area-label.county { color: #cfd8dc; }
html.dark .leaflet-tooltip.area-label.city { color: #ce93d8; }

.sheet.nearby { padding-top: 12px; }
.nb-ref-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 2px 0 6px; flex: none; }
.nb-ref-row select { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); font-size: 14px; }
.chip-btn { flex: none; border: 2px solid var(--c); background: var(--bg); border-radius: 18px; padding: 5px 12px; font-weight: 600; font-size: 13px; }
.chip-btn.active { background: var(--c); color: #fff; }
.chip-btn small { opacity: .7; font-weight: 500; }
.nb-list { list-style: none; margin: 4px 0 10px; padding: 0; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.nb-list li[data-i] { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--row-line); cursor: pointer; }
.nb-list li[data-i]:active, .nb-list li[data-i]:hover { background: var(--soft); }
.nb-rank { width: 24px; text-align: right; color: var(--muted); font-size: 12px; flex: none; }
.nb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-d { flex: none; font-variant-numeric: tabular-nums; }
.nb-more { text-align: center; padding: 8px; }
body.nearby-open .leaflet-bottom { display: none; }
@media (min-width: 820px) { body.nearby-open .leaflet-bottom { display: block; } }

/* ------------------------------------------------ live game (js/live.js) */
.live-chip { background: #1b5e20; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.live-chip.bad { background: var(--danger); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #69f0ae; box-shadow: 0 0 0 0 rgba(105, 240, 174, .7); animation: live-pulse 2s infinite; }
.live-chip.bad .live-dot { background: #fff; animation: none; }
@keyframes live-pulse { 70% { box-shadow: 0 0 0 8px rgba(105, 240, 174, 0); } 100% { box-shadow: 0 0 0 0 rgba(105, 240, 174, 0); } }
.live-panel { left: 10px; right: auto; top: calc(64px + var(--safe-t)); width: min(360px, calc(100vw - 20px)); z-index: 1004; }
.live-panel h3 { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.live-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--row-line); }
.live-info { flex: 1; min-width: 0; }
.live-info .stale { color: var(--danger); }
.seeker-dot {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--c); color: #fff;
  font-weight: 800; font-size: 13px; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--c), 0 2px 6px rgba(0, 0, 0, .45);
}
.seeker-dot.small { width: 28px; height: 28px; font-size: 11px; border-width: 2px; flex: none; }
.seeker-icon { position: relative; }
.seeker-icon .seeker-name {
  position: absolute; left: 50%; top: 38px; transform: translateX(-50%); white-space: nowrap; font-weight: 700; font-size: 12px;
  color: var(--label-ink); text-shadow: 0 0 2px var(--label-halo), 0 0 3px var(--label-halo), 0 0 4px var(--label-halo);
}
.seeker-icon.stale .seeker-dot { filter: grayscale(.85); opacity: .7; }

/* border side labels: the area on each side of a county / city line */
.side-label-icon { width: 0; height: 0; }
.side-label {
  position: absolute; white-space: nowrap; font-weight: 800; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  text-shadow: 0 0 2px var(--label-halo), 0 0 3px var(--label-halo), 0 0 4px var(--label-halo);
}
.side-label.county { color: #37474f; font-size: 11.5px; }
.side-label.city { color: #7b1fa2; }
html.dark .side-label.county { color: #cfd8dc; }
html.dark .side-label.city { color: #ce93d8; }
html.dark path.border-halo { stroke: #000; }
