:root{
  --panel:#ffffff; --text:#14181f; --muted:#5b6472;
  --line:rgba(0,0,0,.12); --field:#fff; --shadow:0 3px 10px rgba(0,0,0,.16);
  --map-bg:#dfe3e8;
}
@media (prefers-color-scheme: dark){
  :root{
    --panel:#161a21; --text:#e8ecf2; --muted:#98a2b3;
    --line:rgba(255,255,255,.14); --field:#0f1319; --shadow:0 3px 10px rgba(0,0,0,.45);
    --map-bg:#dfe3e8;
  }
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
/* Mobile browsers grow and shrink the layout viewport as their toolbars slide in and
   out, so a percentage-height map leaves a gap at the bottom. Pin it to the viewport
   instead and stop the page itself from scrolling. */
html,body{overflow:hidden;overscroll-behavior:none}
body{
  font:14px/1.45 ui-sans-serif,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  color:var(--text);
}
#map{position:fixed;inset:0;background:var(--map-bg)}
/* Basemap stays the standard light OSM raster in both colour schemes. */

/* ---------- control panel ---------- */
/* No backdrop-filter here on purpose: the map under this card repaints constantly
   (hundreds of animating markers plus a canvas layer), and a blurred backdrop has to
   re-rasterise with it — which flickered badly and leaked an unclipped halo past the
   border radius. A near-opaque background costs nothing and renders cleanly. */
#panel{
  position:fixed;z-index:1200;
  top:calc(12px + env(safe-area-inset-top));
  left:calc(12px + env(safe-area-inset-left));
  width:288px;
  max-width:calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
  background:var(--panel);
  border:1px solid var(--line);border-radius:12px;box-shadow:var(--shadow);padding:12px;
}
h1{margin:0 0 2px;font-size:14px;font-weight:650;letter-spacing:-.01em}
.sub{margin:0 0 10px;font-size:11.5px;color:var(--muted)}
#preset-school{
  display:flex;align-items:center;gap:7px;width:100%;margin-bottom:2px;
  padding:8px 10px;font:inherit;font-size:11.5px;font-weight:600;line-height:1.3;
  text-align:left;color:var(--text);cursor:pointer;
  background:var(--field);border:1px solid var(--line);border-radius:8px;
}
#preset-school svg{width:16px;height:16px;flex:none;opacity:.75}
#preset-school:hover{border-color:#d97706}
#preset-school[aria-pressed="true"]{
  background:#d97706;border-color:#d97706;color:#fff;
}
#preset-school[aria-pressed="true"] svg{opacity:1}

.searchrow{display:flex;gap:6px;margin-top:9px}
#q{
  flex:1;min-width:0;padding:8px 10px;font:inherit;font-size:13px;color:var(--text);
  background:var(--field);border:1px solid var(--line);border-radius:8px;outline:none;
}
#q:focus{border-color:#6b8afd;box-shadow:0 0 0 3px rgba(107,138,253,.25)}
#clear,#toggle-stops,#toggle-routes{
  padding:8px 10px;font:inherit;font-size:12px;color:var(--muted);cursor:pointer;
  background:var(--field);border:1px solid var(--line);border-radius:8px;
}
#clear:hover,#toggle-stops:hover,#toggle-routes:hover{color:var(--text)}
#toggle-stops,#toggle-routes{display:flex;align-items:center;padding:8px}
#toggle-stops svg,#toggle-routes svg{width:15px;height:15px;display:block}
#toggle-stops[aria-pressed="true"]{background:#d97706;border-color:#d97706;color:#fff}
#toggle-routes[aria-pressed="true"]{background:#334155;border-color:#334155;color:#fff}
#toggle-stops[aria-busy="true"]{opacity:.55;cursor:progress}
.controls{display:flex;gap:6px;margin-top:6px}
#basemap{
  flex:1;min-width:0;padding:7px 9px;font:inherit;font-size:12.5px;color:var(--text);
  background:var(--field);border:1px solid var(--line);border-radius:8px;cursor:pointer;
}
#basemap:focus{outline:none;border-color:#6b8afd;box-shadow:0 0 0 3px rgba(107,138,253,.25)}
.chips{display:flex;flex-wrap:wrap;gap:5px;margin-top:9px;padding-bottom:1px}
.chip{
  display:inline-flex;align-items:center;gap:5px;cursor:pointer;user-select:none;
  padding:4px 8px;font:inherit;font-size:11.5px;font-weight:550;border-radius:999px;
  border:1px solid var(--line);background:var(--field);color:var(--text);
}
.chip .dot{width:9px;height:9px;border-radius:50%;background:var(--c);flex:none}
.chip .n{color:var(--muted);font-variant-numeric:tabular-nums}
.chip[aria-pressed="false"]{opacity:.4}
/* The status row doubles as the disclosure control for the per-type breakdown,
   which stays collapsed on load to keep the panel short on phones. */
#summary{margin-top:9px;border-top:1px solid var(--line)}
#status{
  position:relative;
  display:flex;align-items:center;gap:7px;cursor:pointer;user-select:none;
  padding-top:8px;
  font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums;
  list-style:none;
}
#status::-webkit-details-marker{display:none}
#status:hover{color:var(--text)}
#status:focus-visible{outline:2px solid #6b8afd;outline-offset:2px;border-radius:4px}
#status-text{flex:1;min-width:0}
.chev{width:12px;height:12px;flex:none;opacity:.7;transition:transform .18s ease}
#summary[open] .chev{transform:rotate(180deg)}
/* Countdown to the next poll, as a bar swept with transform:scaleX.
   This is deliberately NOT an SVG ring: animating anything inside SVG here rebuilt
   the compositing layer tree ~120x per second, which made the whole panel flicker.
   A transform on a plain div is handled by the compositor and costs nothing. */
#tick{
  position:absolute;left:0;right:0;bottom:-1px;height:2px;
  background:currentColor;opacity:.35;border-radius:1px;
  transform:scaleX(0);transform-origin:left;
  animation:tick-sweep 5s linear forwards;
}
@keyframes tick-sweep{from{transform:scaleX(0)}to{transform:scaleX(1)}}
#status.err{color:#e02424}
#status b{color:var(--text);font-weight:600}
@media (max-width:560px){
  #panel{width:auto;right:calc(12px + env(safe-area-inset-right));padding:10px}
  .sub{display:none}
}

/* Map attribution, moved off the map into the card. It stays outside <details> — the
   tile licences require it to be visible, so it must not be collapsible. */
#attrib{
  margin-top:8px;padding-top:7px;border-top:1px solid var(--line);
  font-size:9.5px;line-height:1.35;color:var(--muted);opacity:.85;
}
#attrib a{color:inherit;text-decoration:none}
#attrib a:hover{text-decoration:underline}

/* Leaflet's control corners need the same treatment, or the zoom buttons sit under
   the home indicator in landscape. */
.leaflet-bottom{margin-bottom:env(safe-area-inset-bottom)}
.leaflet-left{margin-left:env(safe-area-inset-left)}
.leaflet-right{margin-right:env(safe-area-inset-right)}

/* ---------- vehicle markers ---------- */
/* No transition here on purpose. Gliding each marker between fixes promotes every
   visible vehicle to its own GPU layer — with ~485 of them (plus their heading arrows)
   that is ~970 layers churning every 5 s, which made overlapping UI flicker. Markers
   now jump straight to the new fix. */
.veh-marker{}
.veh{position:relative;width:44px;height:44px}
.veh.t-bus{--c:#2563eb}
.veh.t-trol{--c:#e02424}
.veh.t-express{--c:#16a34a}
.veh.t-ferry{--c:#d926c9}
.dirwrap{position:absolute;inset:0}
.dir{
  position:absolute;left:50%;top:0;margin-left:-5px;width:0;height:0;
  border-left:5px solid transparent;border-right:5px solid transparent;
  border-bottom:9px solid var(--c);
  filter:drop-shadow(0 0 1.5px rgba(255,255,255,.9));
}
.veh.nodir .dir{display:none}
.pill{
  position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
  padding:2px 5px;min-width:20px;text-align:center;
  background:var(--c);color:#fff;border:1.5px solid rgba(255,255,255,.92);
  border-radius:7px;box-shadow:0 1px 4px rgba(0,0,0,.45);
  font-size:11px;font-weight:700;line-height:1.25;white-space:nowrap;
}
.veh.stopped .pill{opacity:.62}

/* ---------- bus stop markers ---------- */
/* Own pane below the vehicles, and a deliberately neutral shape so stops never
   read as a fifth vehicle type. */
.stop-pin{
  display:block;
  filter:drop-shadow(0 2px 3px rgba(0,0,0,.45));
  transition:transform .12s ease;
  transform-origin:50% 100%;
}
.stop-pin:hover{transform:scale(1.08)}
.leaflet-tooltip.stop-label{
  font:600 11px/1.2 ui-sans-serif,-apple-system,"Segoe UI",Roboto,sans-serif;
  padding:2px 6px;border:1px solid rgba(0,0,0,.15);border-radius:5px;
  background:#fff;color:#14181f;box-shadow:0 1px 4px rgba(0,0,0,.2);
}

/* ---------- my location ---------- */
.me-dot{
  width:14px;height:14px;border-radius:50%;
  background:#1a73e8;border:2.5px solid #fff;
  box-shadow:0 0 0 1px rgba(0,0,0,.25),0 1px 4px rgba(0,0,0,.4);
}
.locate-ctrl a{
  display:flex;align-items:center;justify-content:center;
  width:30px;height:30px;color:#333;
}
.locate-ctrl a svg{width:17px;height:17px;display:block}
.locate-ctrl.active a{color:#1a73e8}
.locate-ctrl.err a{color:#e02424}
.locate-ctrl.busy a{opacity:.5}

/* ---------- popup ---------- */
.leaflet-popup-content{margin:10px 12px;font-size:12.5px}
.pop-h{font-size:14px;font-weight:700;margin-bottom:2px}
.pop-t{font-size:11.5px;color:#666;margin-bottom:7px}
.pop-g{display:grid;grid-template-columns:auto 1fr;gap:2px 10px;font-variant-numeric:tabular-nums}
.pop-g span:nth-child(odd){color:#666}
.pop-a{margin-top:7px;display:flex;flex-wrap:wrap;gap:4px}
.pop-a i{font-style:normal;font-size:10.5px;padding:2px 6px;border-radius:5px;background:rgba(127,127,127,.16)}
