:root {
  --ink: #1b1f24;
  --ink-soft: #5b636d;
  --paper: #ffffff;
  --paper-2: #f1f3f5;
  --rule: #dfe3e8;
  --lane: #c8102e;        /* bus-lane red: first direction, primary action */
  --signal: #2b59c3;      /* second direction */
  --amber: #ffa31a;       /* LED destination display */
  --board: #000000;
  --seats: #1f9d55;       /* LTA crowd levels */
  --standing: #d99100;
  --packed: #d7263d;
  --net: #93a8bf;         /* route network: light blue-grey, drawn solid so overlaps don't darken */
  --shadow: 0 1px 2px rgba(27, 31, 36, .12), 0 8px 24px rgba(27, 31, 36, .12);
  --radius: 14px;
  --ui: "Overpass", "Helvetica Neue", Arial, sans-serif;
  --dots: "Doto", "Courier New", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef1f4;
    --ink-soft: #a3acb7;
    --paper: #1d2127;
    --paper-2: #262b33;
    --rule: #353c46;
    --lane: #ff4d5e;
    --signal: #6e9bff;
    --net: #52627a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 var(--ui);
  color: var(--ink);
  background: var(--paper-2);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
svg { stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; background: var(--paper-2); }
.leaflet-container { font: inherit; }
/* Fallback OneMap tiles draw MRT lines in colour; grey them so colour belongs
   to buses. Our own vector basemap has a gentle palette and needs no filter. */
body:not(.vector-map) .leaflet-tile-pane { filter: grayscale(1) contrast(.92) brightness(1.04); }
body.onemap-colour .leaflet-tile-pane { filter: saturate(.55) brightness(1.04) contrast(.95); }
@media (prefers-color-scheme: dark) {
  body:not(.vector-map) .leaflet-tile-pane { filter: grayscale(1) brightness(.9); }
  body.onemap-colour .leaflet-tile-pane { filter: saturate(.6) brightness(.95); }
}
.leaflet-control-attribution { font-size: 10px; }
.leaflet-top.leaflet-right { top: calc(env(safe-area-inset-top) + 4px); }

/* ---------- LED board: the one loud thing on screen ---------- */
.dock {
  position: fixed; z-index: 1000;
  top: calc(env(safe-area-inset-top) + 12px); left: 12px;
  width: min(540px, calc(100vw - 24px));
  display: grid; gap: 8px;
}
.led {
  display: flex; align-items: center; gap: 14px;
  min-height: 64px; padding: 10px 16px;
  background: var(--board);
  border: 3px solid #26282b; border-radius: 12px;
  box-shadow: var(--shadow), inset 0 0 24px rgba(255, 163, 26, .08);
  color: var(--amber); text-align: left;
  overflow: hidden; position: relative;
}
.led::after { /* the dot grid you see on a real display when you stand close */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle, transparent 55%, rgba(0,0,0,.55) 56%) 0 0 / 4px 4px;
  opacity: .5;
}
.led-num, .led-text {
  font-family: var(--dots); font-weight: 900;
  text-shadow: 0 0 6px rgba(255, 163, 26, .75), 0 0 18px rgba(255, 120, 0, .35);
  white-space: nowrap;
}
.led-num { font-size: 40px; line-height: 1; letter-spacing: .02em; }
.led-num:empty { display: none; }
.led-text {
  font-size: 22px; line-height: 1.1; letter-spacing: .04em;
  overflow: hidden; text-overflow: clip; flex: 1; min-width: 0;
}
.led.flip .led-text { animation: flip .32s steps(4) both; }
.led.busy .led-text { animation: blink 1s steps(2) infinite; }
@keyframes flip { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes blink { 50% { opacity: .35; } }

.finder { display: flex; gap: 6px; flex-wrap: wrap; }
.search { flex: 1 1 150px; }
.search input {
  width: 100%; height: 44px; padding: 0 14px;
  font: 800 17px var(--ui); color: var(--ink);
  background: var(--paper); border: 2px solid transparent; border-radius: 10px;
  box-shadow: var(--shadow); outline: none;
}
.search input:focus { border-color: var(--ink); }
.search input::placeholder { color: var(--ink-soft); font-weight: 400; }
.tool {
  height: 44px; display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--paper); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
}
.tool svg { width: 20px; height: 20px; fill: none; }
.tool:hover { background: var(--paper-2); }
.tool b { font-weight: 800; color: var(--lane); }

.suggest {
  list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto;
  background: var(--paper); border-radius: 12px; box-shadow: var(--shadow);
}
.suggest li { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--paper-2); }
.suggest .route-name { font-size: 13px; color: var(--ink-soft); line-height: 1.3; }

.suggest .sug-head { cursor: default; padding: 8px 8px 2px; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.suggest .sug-head:hover { background: none; }
.suggest .route-name b { color: var(--ink); font-weight: 800; }
.stop-ico { width: 48px; display: grid; place-items: center; flex: none; }
.stop-ico::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--ink); background: var(--paper); }

/* "Whole route": zoom back out after exploring (only in route mode) */
.fab {
  position: fixed; z-index: 950; left: 12px; top: calc(var(--dock-b, 130px) + 10px);
  display: none; align-items: center; gap: 6px; height: 40px; padding: 0 12px;
  border: 0; border-radius: 10px; background: var(--paper); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
}
.fab svg { width: 18px; height: 18px; fill: none; }
.route-mode .fab { display: inline-flex; }

/* Service number plate, as on a bus-stop pole */
.plate {
  display: inline-grid; place-items: center;
  min-width: 48px; height: 30px; padding: 2px 8px 0;
  font: 900 18px/1 var(--dots); color: var(--amber);
  background: var(--board); border-radius: 6px; border: 0;
  text-shadow: 0 0 5px rgba(255, 163, 26, .6);
}
button.plate:hover { outline: 2px solid var(--amber); }
.plate.small { min-width: 38px; height: 24px; font-size: 14px; border-radius: 5px; padding: 1px 6px 0; }

/* ---------- Route mode: one route in colour, everything else greyed ---------- */
.leaflet-tile-pane, .leaflet-net-pane { transition: opacity .45s ease, filter .45s ease; }
.route-mode .leaflet-tile-pane { opacity: .45; }
.route-mode .leaflet-net-pane { opacity: .12; }
@media (prefers-color-scheme: dark) {
  .route-mode .leaflet-tile-pane { opacity: .35; }
  .route-mode .leaflet-net-pane { opacity: .15; }
}
.route-mode #surprise, .route-mode #nearme { display: none; }
.route-mode.surprise-mode #surprise { display: inline-flex; }
#surprise.rolling svg { animation: roll .5s linear infinite; }
@keyframes roll { to { transform: rotate(360deg); } }
.tool.exit { background: var(--ink); color: var(--paper); }
.tool.exit:hover { background: var(--ink); opacity: .88; }

/* ---------- Side panel / bottom sheet ---------- */
.panel {
  position: fixed; z-index: 900;
  top: 12px; right: 12px; bottom: 12px;
  width: min(390px, calc(100vw - 24px));
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-body { overflow: auto; padding: 20px 20px 24px; flex: 1; overscroll-behavior: contain; }
.grab { display: none; }
.close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--paper-2);
}
.close svg { width: 18px; height: 18px; fill: none; }

.svc-head { display: flex; align-items: flex-end; gap: 14px; margin: 0 40px 6px 0; }
.svc-no { font: 900 56px/0.9 var(--dots); color: var(--ink); margin: 0; letter-spacing: -.01em; }
.svc-meta { font-size: 13px; color: var(--ink-soft); padding-bottom: 4px; }
.svc-meta b { color: var(--ink); font-weight: 800; display: block; font-size: 14px; }
.lede { font-size: 19px; line-height: 1.35; font-weight: 600; margin: 12px 0 4px; text-wrap: pretty; }
.lede strong { font-weight: 800; }
.sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 12px; }

.callout {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start;
  margin: 14px 0; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--lane) 9%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--lane) 30%, var(--paper));
  font-size: 14px;
}
.callout .ico { font-size: 22px; line-height: 1; }
.callout p { margin: 0; }
.callout b { font-weight: 800; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  text-decoration: none; color: var(--ink);
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border-radius: 10px; border: 2px solid var(--ink); background: var(--paper);
  font-weight: 800; font-size: 14px;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn svg { width: 18px; height: 18px; fill: none; }
.btn:disabled { opacity: .5; cursor: default; }

.dirs { display: flex; gap: 6px; margin: 18px 0 6px; }
.dirs button {
  flex: 1; text-align: left; padding: 8px 10px; border-radius: 10px;
  border: 2px solid var(--rule); background: var(--paper); font-size: 13px; line-height: 1.25;
}
.dirs button span { display: block; color: var(--ink-soft); font-size: 12px; }
.dirs button b { font-weight: 800; }
.dirs button[aria-pressed="true"] { border-color: var(--dir-color); box-shadow: inset 4px 0 0 var(--dir-color); }

/* The route as a line of stops, with buses riding between them */
.line { list-style: none; margin: 8px 0 0; padding: 0; position: relative; }
.line::before {
  content: ""; position: absolute; left: 13px; top: 12px; bottom: 12px; width: 4px;
  background: var(--dir-color); border-radius: 2px;
}
.line li { position: relative; padding-left: 40px; }
.stop-btn {
  width: 100%; display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 8px 7px 0; border: 0; background: none; text-align: left; font-size: 14px;
  border-radius: 8px;
}
.stop-btn::before {
  content: ""; position: absolute; left: 8px; top: 50%; translate: 0 -50%;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--dir-color);
}
.stop-btn:hover .stop-name { text-decoration: underline; }
.stop-code { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.line .bus-row {
  display: flex; align-items: center; gap: 8px; margin: 2px 0; padding: 6px 10px 5px;
  border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--paper-2); border: 0; width: 100%; text-align: left;
}
.line .bus-row::before {
  content: ""; position: absolute; left: 5px; top: 50%; translate: 0 -50%;
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--dir-color); border: 2px solid var(--paper);
}
.line .bus-row.picked { outline: 2px solid var(--ink); }
.load-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--net); }
.load-SEA { --load: var(--seats); }
.load-SDA { --load: var(--standing); }
.load-LSD { --load: var(--packed); }
.load-dot.load-SEA, .load-dot.load-SDA, .load-dot.load-LSD { background: var(--load); }

.foot {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 16px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--ink-soft);
}
.ring { width: 22px; height: 22px; flex: none; }
.ring circle { fill: none; stroke-width: 3; }
.ring .track { stroke: var(--rule); }
.ring .fill { stroke: var(--ink); stroke-dasharray: 56.5; transform: rotate(-90deg); transform-origin: center; } /* ticks once a second: a continuous transition kept the page repainting */
.foot .row { gap: 10px; flex-wrap: nowrap; }
.foot .btn { height: 34px; font-size: 13px; }

/* Bus card */
.bus-card { display: grid; gap: 10px; margin-top: 4px; }
.bc-head { display: flex; align-items: center; gap: 12px; }
.bc-head b { display: block; font-size: 16px; font-weight: 800; line-height: 1.25; }
.bc-head span:not(.plate) { display: block; font-size: 13px; color: var(--ink-soft); }
.bc-crowd { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.bc-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.bc-badges span { font-size: 12px; font-weight: 600; padding: 4px 9px 3px; border-radius: 999px; background: var(--paper-2); }
.trip p { margin: 6px 0 0; font-size: 14px; }
.trip-bar { height: 8px; border-radius: 4px; background: var(--paper-2); overflow: hidden; }
.trip-bar i { display: block; height: 100%; background: var(--dir-color); border-radius: 4px; }
.gaps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gaps div { padding: 8px 10px; border-radius: 10px; background: var(--paper-2); display: grid; grid-template-columns: 1fr auto; align-items: center; row-gap: 2px; }
.gaps span { grid-column: 1 / -1; font-size: 12px; color: var(--ink-soft); }
.gaps b { font-size: 18px; font-weight: 800; }
.bus-card .callout { margin: 0; }
.bc-sub { margin: 4px 0 0; font-size: 14px; font-weight: 800; }
.eta-list { list-style: none; margin: 0; padding: 0; display: grid; }
.eta-list li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--rule); }
.eta-list li:last-child { border-bottom: 0; }
.eta-stop { border: 0; background: none; padding: 5px 0; text-align: left; font-size: 14px; }
.eta-stop:hover { text-decoration: underline; }
.eta-t { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 14px; }
.bell { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--ink-soft); }
.bell svg { width: 17px; height: 17px; fill: none; }
.bell:hover { background: var(--paper-2); color: var(--ink); }
.bell.on { background: var(--board); color: var(--amber); }
.linkish { border: 0; background: none; padding: 2px 0; font-weight: 800; font-size: 13px; text-align: left; text-decoration: underline; }
.fine { margin: 0; font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

/* Hover preview on a bus */
.leaflet-tooltip.bus-tip {
  background: var(--paper); color: var(--ink); border: 0; border-radius: 10px;
  box-shadow: var(--shadow); padding: 9px 12px 8px; font: 13px/1.45 var(--ui); white-space: nowrap;
}
.bus-tip::before { border-top-color: var(--paper) !important; }
.bus-tip .tip-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 14px; }
.bus-tip .tip-hint { margin-top: 4px; font-size: 11px; color: var(--ink-soft); }

/* Stop arrivals */
.arrivals { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.arrivals li {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center;
  padding: 8px; border-radius: 10px; background: var(--paper-2);
}
.arrivals li.mine { outline: 2px solid var(--ink); }
.etas { display: flex; gap: 14px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.eta { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; font-size: 15px; }
.eta small { font-weight: 400; color: var(--ink-soft); font-size: 12px; }
.verdict {
  margin: 14px 0 6px; padding: 14px 16px; border-radius: 12px;
  background: var(--board); color: var(--amber);
}
.verdict .big { font: 900 34px/1 var(--dots); text-shadow: 0 0 8px rgba(255,163,26,.6); }
.verdict p { margin: 6px 0 0; color: #ffd9a3; font-size: 15px; }

.card-bus {
  margin: 12px 0; padding: 14px; border-radius: 12px; border: 2px solid var(--dir-color, var(--ink));
}
.card-bus h3 { margin: 0 0 6px; font-size: 16px; font-weight: 800; }
.facts { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 14px; }
.facts li { display: flex; align-items: center; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.near-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 14px; }
.near-list h4 { margin: 0 0 6px; font-size: 15px; font-weight: 800; }
.near-list h4 button { border: 0; background: none; padding: 0; font-weight: 800; text-align: left; }
.near-list h4 button:hover { text-decoration: underline; }
.near-list h4 span { font-weight: 400; color: var(--ink-soft); font-size: 13px; }

/* ---------- Map furniture ---------- */
.hint {
  position: fixed; z-index: 800; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 28px);
  translate: -50% 0; width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow);
  font-size: 14px;
}
.hint p { margin: 0; }
.hint b { font-weight: 800; }
.crowd {
  position: fixed; z-index: 800; left: 12px; bottom: calc(env(safe-area-inset-bottom) + 24px);
  padding: 7px 12px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow);
  font-size: 13px; display: flex; gap: 8px; align-items: center; max-width: calc(100vw - 24px);
}
.crowd .pulse { position: relative; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--seats); }
/* The ring grows and fades with transform/opacity only, so the GPU does it without repainting. */
.crowd .pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--seats); animation: pulse 2s ease-out 3; } /* a few beats each time the count updates, not forever */
@keyframes pulse { 0% { transform: scale(1); opacity: .6; } 70%, 100% { transform: scale(3); opacity: 0; } }

.pick { min-width: 190px; }
.pick-chips { max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; }
.more-chip {
  height: 24px; padding: 0 9px; border-radius: 5px; border: 1.5px dashed var(--ink-soft);
  background: var(--paper); font: 800 12px var(--ui); color: var(--ink);
}
.pick-zoom { margin-top: 10px; display: block; }
.pick p { margin: 0 0 8px; font-weight: 800; font-size: 14px; }
.leaflet-popup-content-wrapper { border-radius: 12px; background: var(--paper); color: var(--ink); }
.leaflet-popup-tip { background: var(--paper); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; }
.stop-pop h4 { margin: 0; font-size: 15px; font-weight: 800; }
.stop-pop .sub { margin: 0 0 8px; font-size: 12px; }
.stop-pop .btn { margin-top: 10px; height: 34px; }
.hover-tip {
  background: var(--board); color: var(--amber); border: 0; border-radius: 6px;
  font: 900 15px/1 var(--dots); padding: 6px 8px 4px; box-shadow: none;
  text-shadow: 0 0 5px rgba(255,163,26,.6);
}
.hover-tip::before { display: none; }

/* Stop names on the map (street level) */
.stop-label { display: flex; flex-direction: column; justify-content: center; white-space: nowrap; cursor: pointer; line-height: 1.1; }
.stop-label.l { align-items: flex-end; text-align: right; }
.stop-label .sl-code, .stop-label .sl-name {
  text-shadow: 0 0 2px var(--paper), 0 0 2px var(--paper), 0 0 3px var(--paper), 0 0 4px var(--paper);
}
.stop-label .sl-code { font: 600 11px/1.1 var(--ui); color: var(--ink-soft); }
.stop-label .sl-name { font: 800 13px/1.15 var(--ui); color: var(--ink); }
.stop-label:hover .sl-name { text-decoration: underline; }

/* Selected route: dashes flow in the direction of travel */
.flow { stroke-dasharray: 1 16; } /* marched along by app.js, 5 steps a second like LEDs: a CSS animation ticks every frame */
@keyframes flow { to { stroke-dashoffset: -17; } }

/* Bus markers */
.bus-icon { background: none; border: 0; }
.bus {
  position: relative; width: 0; height: 0;
  --c: var(--lane);
}
.bus.d1 { --c: var(--signal); }
.bus .body {
  position: absolute; left: 0; top: 0;
  transform: rotate(var(--rot, 0deg)) scaleX(var(--flip, 1)); /* left/top are set to minus half its size, so scaling stays centred */
  transition: transform .6s ease;
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.45));
}
.bus .body svg { display: block; stroke: none; }
.bus .tag {
  position: absolute; left: 12px; top: -26px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 7px 1px 5px; border-radius: 999px;
  background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.3);
  font: 800 12px/1.2 var(--ui); white-space: nowrap;
}
.far .bus .tag { display: none; }
/* The bus you tapped: bigger, glowing, with a sonar ring; the rest step back. */
.bus .body { transition: transform .6s ease, scale .25s ease, opacity .25s ease; }
.bus.picked .body { scale: 1.3; filter: drop-shadow(0 0 0 #fff) drop-shadow(0 0 8px var(--amber)); }
.bus.picked::before, .bus.picked::after {
  content: ""; position: absolute; left: 0; top: 0; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%; border: 3px solid var(--amber); pointer-events: none;
}
.bus.picked::before { background: rgba(255, 163, 26, .16); }
.bus.picked::after { animation: sonar 1.8s ease-out infinite; }
@keyframes sonar { 0% { transform: scale(.7); opacity: .9; } 100% { transform: scale(2.3); opacity: 0; } }
.bus-picked .bus:not(.picked) .body, .bus-picked .bus:not(.picked) .tag { opacity: .45; }
.bus.hop .body { animation: hop .55s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes hop { 0% { translate: 0 0; } 35% { translate: 0 -10px; } 100% { translate: 0 0; } }

/* The stop you tapped: amber ring, pulse, and an LED name tag above it. */
.stop-focus { position: relative; width: 0; height: 0; }
.stop-focus::before, .stop-focus::after {
  content: ""; position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none;
}
.stop-focus::before { width: 18px; height: 18px; margin: -9px 0 0 -9px; background: var(--amber); border: 3px solid var(--ink); box-shadow: 0 0 0 3px var(--paper); }
.stop-focus::after { width: 40px; height: 40px; margin: -20px 0 0 -20px; border: 3px solid var(--amber); animation: sonar 1.8s ease-out infinite; }
.stop-focus span {
  position: absolute; left: 0; bottom: 16px; translate: -50% 0; white-space: nowrap;
  padding: 5px 8px 3px; border-radius: 6px; background: var(--board); color: var(--amber);
  font: 900 13px/1 var(--dots); letter-spacing: .03em; text-shadow: 0 0 5px rgba(255, 163, 26, .6);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35); animation: drop .35s ease-out both;
}
.stop-btn.focused::before { background: var(--amber); border-color: var(--ink); }
.stop-btn.focused .stop-name { font-weight: 800; }

.card-bus { position: relative; }
.card-x {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--paper-2); color: var(--ink-soft);
}
.card-x svg { width: 15px; height: 15px; fill: none; }
.card-x:hover { color: var(--ink); }
.bus-card .bc-head, .stop-card h3 { padding-right: 34px; }
.bus.enter .body { animation: drop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes drop { from { opacity: 0; scale: 2.2; } }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }

.privacy { display: grid; gap: 8px; font-size: 14px; line-height: 1.5; margin: 4px 0 16px; }
.privacy p { margin: 0; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--paper-2); font-weight: 800; margin-bottom: 10px; cursor: pointer; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--ink); }

/* Off-route buses: faded, dashed tag, spelled out */
.bus.off .body { opacity: .55; }
.bus.off .tag, .tag-demo.off { background: var(--paper); box-shadow: none; outline: 1.5px dashed var(--ink-soft); }
.bus .tag .deck, .tag-demo .deck { margin-left: 3px; flex: none; color: var(--ink); }
.bus .tag small, .tag-demo small { font-weight: 600; color: var(--ink-soft); margin-left: 4px; font-size: 11px; }

/* Map key */
.fab-key { top: calc(var(--dock-b, 130px) + 58px); }
.key { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; gap: 12px; }
.key li { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; font-size: 14px; line-height: 1.45; }
.key b { font-weight: 800; }
.key-ic { position: relative; height: 40px; display: grid; place-items: center; }
.key-ic .bus { position: relative; width: 0; height: 0; }
.key-ic .bus .body { transform: translate(-50%, -50%); left: 0; top: 0; }
.key-ic.three { display: flex; gap: 8px; justify-content: center; }
.key-ic.three svg { stroke: none; }
.key-ic.three rect:first-child { fill: var(--lane); }
.key-dots { display: flex; gap: 6px; justify-content: center; }
.key-dots .load-dot { width: 12px; height: 12px; }
.key-flow { width: 64px; height: 8px; border-radius: 4px; background: repeating-linear-gradient(90deg, #fff 0 3px, var(--lane) 3px 12px); box-shadow: 0 0 0 2px var(--lane); }
.key-ring { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--amber); background: rgba(255, 163, 26, .16); }
.tag-demo {
  justify-self: center; display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 1px 5px; border-radius: 999px;
  background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.3); font: 800 12px/1.2 var(--ui); white-space: nowrap;
}
.report-line { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 14px 0 0; }

/* Report form */
.choices { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.choices legend { font-weight: 800; margin-bottom: 6px; padding: 0; }
.choice { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--paper-2); cursor: pointer; font-size: 14px; }
.choice input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }
.choice:has(input:checked) { outline: 2px solid var(--ink); }
.field { display: grid; gap: 6px; margin-bottom: 12px; font-weight: 800; font-size: 14px; }
.field small { font-weight: 400; color: var(--ink-soft); }
.field textarea {
  font: 400 15px/1.4 var(--ui); color: var(--ink); background: var(--paper); resize: vertical;
  border: 2px solid var(--rule); border-radius: 10px; padding: 10px 12px;
}
.field textarea:focus { outline: none; border-color: var(--ink); }
.form-err { color: var(--packed); font-weight: 600; margin: 0 0 10px; }

/* ---------- Toasts, sheets, pause ---------- */
.toasts {
  position: fixed; z-index: 1300; top: calc(env(safe-area-inset-top) + 12px); left: 50%; translate: -50% 0;
  display: grid; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 24px);
}
/* Desktop: toasts sit in the open map between the top-left controls and the
   side panel; on narrower windows, just below the controls. */
@media (min-width: 721px) {
  .toasts { top: calc(var(--dock-b, 130px) + 10px); left: 12px; translate: none; max-width: min(540px, calc(100vw - 440px)); }
}
@media (min-width: 1200px) {
  .toasts { top: 12px; left: calc(564px + (100vw - 564px - 414px) / 2); translate: -50% 0; max-width: calc(100vw - 564px - 414px - 24px); }
}
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 8px; border-radius: 10px;
  background: var(--board); color: var(--amber); box-shadow: var(--shadow);
  animation: toast-in .35s ease both;
}
.toast .led-text { font-size: 17px; flex: none; }
.toast span:last-child { color: #ffd9a3; font-size: 14px; }
.toast.out { animation: toast-out .3s ease both; }
@keyframes toast-in { from { opacity: 0; translate: 0 -12px; } }
@keyframes toast-out { to { opacity: 0; translate: 0 -12px; } }

.sheet {
  position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 12, 15, .45);
}
.sheet-card {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border-radius: 16px; padding: 24px; box-shadow: var(--shadow);
}
.sheet h2 { margin: 0 44px 4px 0; font-size: 24px; font-weight: 800; line-height: 1.2; }
.sheet .sub { margin-bottom: 16px; }
.badges { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.badges li { padding: 10px 12px; border-radius: 10px; background: var(--paper-2); font-size: 13px; line-height: 1.3; }
.badges li b { display: block; font-size: 14px; font-weight: 800; }
.badges li .em { font-size: 22px; display: block; margin-bottom: 4px; }
.badges li.locked { opacity: .45; }
.badges li.locked .em { filter: grayscale(1); }
.dex-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.meter { height: 10px; border-radius: 5px; background: var(--paper-2); overflow: hidden; margin: 8px 0 4px; }
.meter i { display: block; height: 100%; background: var(--lane); border-radius: 5px; }
.link-box { display: flex; gap: 8px; margin: 12px 0 14px; }
.link-box input {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 10px; border: 2px solid var(--rule);
  background: var(--paper-2); color: var(--ink); font: 600 14px var(--ui);
}
/* Busdex: sync + keeping progress safe */
.dex-sync, .dex-keep { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule); }
.dex-sync h3 { margin: 0 0 4px; font-size: 17px; font-weight: 800; }
.dex-keep p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }
.sync-code { font-family: var(--dots); font-weight: 900; letter-spacing: .06em; background: var(--board); color: var(--amber); padding: 1px 7px 0; border-radius: 5px; white-space: nowrap; }
.qr { width: 180px; max-width: 60%; margin: 12px 0 4px; background: #fff; border-radius: 10px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; stroke: none; }
.join-form { display: flex; gap: 8px; margin-top: 12px; }
.join-form input {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 10px; border: 2px solid var(--rule);
  background: var(--paper); color: var(--ink); font: 700 15px var(--ui); letter-spacing: .04em; text-transform: uppercase;
}
.join-form input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; }
.join-form input:focus { outline: none; border-color: var(--ink); }
.sync-actions { gap: 16px; margin-top: 8px; }
.linkish.danger { color: var(--packed); }

.share-img { width: 100%; border-radius: 12px; display: block; margin: 12px 0; box-shadow: 0 0 0 1px var(--rule); }

.paused {
  position: fixed; inset: 0; z-index: 1250; display: grid; place-items: center;
  background: rgba(10, 12, 15, .35); padding: 16px;
}
.paused button {
  display: grid; gap: 10px; max-width: 340px; padding: 22px; text-align: left;
  background: var(--board); color: #ffd9a3; border: 3px solid #26282b; border-radius: 14px;
}
.paused .led-text { color: var(--amber); font-size: 28px; }

/* ---------- Small screens: board on top, panel as a bottom sheet ---------- */
@media (max-width: 720px) {
  .dock { left: 8px; right: 8px; top: calc(env(safe-area-inset-top) + 8px); width: auto; gap: 6px; }
  .led { min-height: 54px; padding: 8px 12px; }
  .led-num { font-size: 32px; }
  .led-text { font-size: 18px; }
  .tool span { display: none; }
  .tool { width: 44px; justify-content: center; padding: 0; }
  .tool.exit { width: auto; padding: 0 14px; }
  .tool.exit span { display: inline; }

  /* Route mode: the board already shows the number, so the search row folds
     away and "All routes" sits inside the board. More map, same controls. */
  .route-mode .finder { position: absolute; top: 8px; right: 8px; }
  .route-mode .search, .route-mode #dexBtn { display: none; }
  .route-mode .tool.exit { height: 38px; padding: 0 12px; background: #26282b; color: #fff; box-shadow: none; }
  .route-mode .led { padding-right: 132px; }
  .route-mode.surprise-mode .led { padding-right: 180px; }
  .route-mode.surprise-mode #surprise { height: 38px; width: 42px; background: #26282b; color: var(--amber); box-shadow: none; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    height: 34vh; border-radius: 18px 18px 0 0;
    transition: height .3s cubic-bezier(.2, .8, .2, 1);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgba(27, 31, 36, .14);
  }
  .panel.dragging { transition: none; }
  .grab {
    display: block; height: 28px; border: 0; background: none; flex: none; position: relative;
    touch-action: none; cursor: grab;
  }
  .grab::after {
    content: ""; position: absolute; left: 50%; top: 10px; translate: -50% 0;
    width: 44px; height: 5px; border-radius: 3px; background: var(--ink-soft); opacity: .5; /* --rule vanished on the dark panel */
  }
  .panel .close { top: 12px; width: 34px; height: 34px; }
  .panel-body { padding: 0 16px 20px; }
  .svc-no { font-size: 44px; }
  .lede { font-size: 17px; }
  .foot { padding: 8px 14px; }
  .foot .next { display: none; }

  .hint { bottom: calc(env(safe-area-inset-bottom) + 64px); font-size: 13px; padding: 8px 14px; }
  .toasts { top: calc(var(--dock-b, 120px) + 8px); }
  .toast { flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 14px 7px; }
  .toast .led-text { font-size: 15px; }
  .toast span:last-child { font-size: 13px; }
  .crowd { bottom: calc(env(safe-area-inset-bottom) + 38px); font-size: 12px; }   /* clear of the two-line map credits */
  body.has-panel .crowd, body.has-panel .hint { display: none; }
  .leaflet-control-zoom { display: none; }
  .fab { left: 8px; top: calc(var(--dock-b, 70px) + 8px); width: 40px; padding: 0; justify-content: center; }
  .fab-key { top: calc(var(--dock-b, 70px) + 56px); }
  .field textarea { font-size: 16px; } /* no iOS zoom-on-focus */
  .fab span { display: none; }
  .leaflet-control-attribution { font-size: 9px; max-width: 100vw; }

  .sheet { padding: 0; align-items: end; }
  .sheet-card { width: 100%; max-height: 88vh; border-radius: 18px 18px 0 0; padding: 22px 18px calc(env(safe-area-inset-bottom) + 22px); }
  .badges { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .arrivals li { gap: 10px; }
  .eta-list li { padding: 2px 0; }
  .bell { width: 40px; height: 40px; }
}
@supports (height: 1dvh) {
  @media (max-width: 720px) { .panel { height: 34dvh; } .sheet-card { max-height: 88dvh; } }
}

/* Touch polish everywhere */
button, a, input { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.bus .hit { position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
  .flow { animation: none; }
}

/* Side-view buses (default; ?buses=top for the top-down ones) */
.side-buses .bus .tag { left: 0; top: -38px; translate: -50% 0; }
.side-buses .bus .body { filter: drop-shadow(0 1.5px 1.5px rgba(0,0,0,.4)); }
.key li.wide { grid-template-columns: 1fr; gap: 6px; }
.key li.wide .key-ic.three { justify-content: flex-start; gap: 12px; --c: var(--lane); }

/* Keep small animations from repainting the whole map: the map, the route
   line, the panel and the crowd pill each get their own compositor layer. */
.leaflet-tile-pane, .leaflet-route-pane, .panel, .crowd { will-change: transform; }

/* Saved buses and stops: the heart */
.fav {
  flex: none; margin-left: auto; width: 40px; height: 40px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--paper-2); color: var(--ink-soft);
}
.fav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.fav:hover { color: var(--lane); }
.fav.on { color: var(--lane); }
.fav.on svg { fill: currentColor; }
.fav.pop svg { animation: favpop .4s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes favpop { 0% { transform: scale(.5); } 100% { transform: scale(1); } }
.svc-head .fav { align-self: center; }
.stop-title { display: flex; align-items: center; gap: 10px; }
.stop-title > span { flex: 1; min-width: 0; }
.stop-title .fav { width: 36px; height: 36px; }
.stop-card:has(> .card-x) .stop-title { margin-right: 40px; }
.sug-head svg { width: 12px; height: 12px; fill: var(--lane); stroke: none; vertical-align: -1px; }

/* A full-height sheet covers the map, so its buttons step aside instead of sitting on the panel. */
.has-panel.sheet-full .fab { display: none !important; }

/* Busdex count on the trophy (phones hide the button labels) */
#dexBtn { position: relative; }
.dex-badge {
  display: none; position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: var(--lane); color: #fff; border: 2px solid var(--paper);
  font: 800 11px/15px var(--ui); font-style: normal; text-align: center;
}
@media (max-width: 720px) { .dex-badge:not([hidden]) { display: block; } }
#surprise.rolling svg { animation: roll .45s cubic-bezier(.4, 0, .6, 1) infinite; }

/* About button: home map only; Busdex footer links */
.route-mode #aboutBtn { display: none; }
.dex-foot { margin: 18px 0 4px; color: var(--ink-soft); text-align: center; }
.dex-foot .linkish, .dex-foot a { color: var(--ink-soft); font-weight: 800; font-size: 13px; text-decoration: underline; margin: 0 4px; }
