*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Visually hidden but available to screen readers and crawlers (e.g. the page <h1>) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --red: #d32f2f;
  --red-light: #fce4e4;
  --blue: #1565c0;
  --green: #2e7d32;
  --green-bg: #f1f8e9;
  --green-border: #c5e1a5;
  --orange-bg: #fff8e1;
  --orange-border: #ffe082;
  --lsd-bg: #fff3f3;
  --lsd-border: #ffcdd2;
  --text: #212121;
  --text-muted: #757575;
  --border: #e0e0e0;
  --radius: 16px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.12);
  --shadow-md: 0 4px 20px rgba(0,0,0,.16);

  /* Surfaces & fills */
  --app-bg: #f4f4f4;
  --surface: #ffffff;
  --surface-alt: #fafafa;
  --fill: #f0f0f0;
  --fill-active: #e4e4e4;
  --overlay-bg: rgba(255,255,255,.92);
  --handle: #d0d0d0;
  --placeholder: #bdbdbd;
  --icon-muted: #9e9e9e;
  --chip-border: #ececec;
  --route-active-bg: #fff5f5;
  --dest-bg: #fff3c4;
  --dest-text: #5d4037;
  --sea-border: #dcedc8;
  --sda-border: #ffe9b3;
  --lsd-chip-border: #ffcdd2;

  /* Redesign tokens */
  --red-dark: #b71c1c;
  --glass-bg: rgba(255,255,255,.82);
  --glass-border: rgba(255,255,255,.55);
  --glass-shadow: 0 4px 20px rgba(0,0,0,.16);
  --load-seats: #2e7d32;
  --load-standing: #b26a00;
  --load-limited: #c62828;
  --seg-off: #e6e6e6;
}

/* Dark theme values — shared by the auto (system) and forced-dark selectors. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --red: #ef5350;
    --red-light: rgba(239,83,80,.18);
    --blue: #64b5f6;
    --green: #81c784;
    --green-bg: rgba(102,187,106,.16);
    --green-border: rgba(102,187,106,.35);
    --orange-bg: rgba(255,167,38,.16);
    --orange-border: rgba(255,167,38,.35);
    --lsd-bg: rgba(239,83,80,.16);
    --lsd-border: rgba(239,83,80,.4);
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --border: #383838;
    --shadow-sm: 0 2px 8px rgba(0,0,0,.5);
    --shadow-md: 0 4px 20px rgba(0,0,0,.55);
    --app-bg: #121212;
    --surface: #1e1e1e;
    --surface-alt: #262626;
    --fill: #2c2c2c;
    --fill-active: #383838;
    --overlay-bg: rgba(18,18,18,.92);
    --handle: #4a4a4a;
    --placeholder: #6b6b6b;
    --icon-muted: #8a8a8a;
    --chip-border: #333333;
    --route-active-bg: rgba(239,83,80,.15);
    --dest-bg: #3a3524;
    --dest-text: #ffd98a;
    --sea-border: rgba(102,187,106,.4);
    --sda-border: rgba(255,167,38,.4);
    --lsd-chip-border: rgba(239,83,80,.4);

    --red-dark: #c62828;
    --glass-bg: rgba(28,32,38,.72);
    --glass-border: rgba(255,255,255,.09);
    --glass-shadow: 0 4px 20px rgba(0,0,0,.55);
    --load-seats: #81c784;
    --load-standing: #ffb74d;
    --load-limited: #ef5350;
    --seg-off: #333a42;
  }
}

:root[data-theme="dark"] {
  --red: #ef5350;
  --red-light: rgba(239,83,80,.18);
  --blue: #64b5f6;
  --green: #81c784;
  --green-bg: rgba(102,187,106,.16);
  --green-border: rgba(102,187,106,.35);
  --orange-bg: rgba(255,167,38,.16);
  --orange-border: rgba(255,167,38,.35);
  --lsd-bg: rgba(239,83,80,.16);
  --lsd-border: rgba(239,83,80,.4);
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --border: #383838;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.5);
  --shadow-md: 0 4px 20px rgba(0,0,0,.55);
  --app-bg: #121212;
  --surface: #1e1e1e;
  --surface-alt: #262626;
  --fill: #2c2c2c;
  --fill-active: #383838;
  --overlay-bg: rgba(18,18,18,.92);
  --handle: #4a4a4a;
  --placeholder: #6b6b6b;
  --icon-muted: #8a8a8a;
  --chip-border: #333333;
  --route-active-bg: rgba(239,83,80,.15);
  --dest-bg: #3a3524;
  --dest-text: #ffd98a;
  --sea-border: rgba(102,187,106,.4);
  --sda-border: rgba(255,167,38,.4);
  --lsd-chip-border: rgba(239,83,80,.4);

  --red-dark: #c62828;
  --glass-bg: rgba(28,32,38,.72);
  --glass-border: rgba(255,255,255,.09);
  --glass-shadow: 0 4px 20px rgba(0,0,0,.55);
  --load-seats: #81c784;
  --load-standing: #ffb74d;
  --load-limited: #ef5350;
  --seg-off: #333a42;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Frosted-glass treatment for floating controls that hover over the map. */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  backdrop-filter: blur(12px) saturate(1.35);
  border: 1px solid var(--glass-border);
}

/* ── Loading overlay ──────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading-overlay.hidden { display: none; }

#loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: 0 32px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 280px;
  line-height: 1.5;
}

/* ── Location permission prompt ─────────────────────────────────────────── */
#location-prompt {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(0,0,0,.38);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in .2s ease;
}

#location-prompt.hidden { display: none; }

#location-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 340px;
  width: 100%;
  padding: 28px 24px 20px;
  text-align: center;
  animation: pop-in .22s cubic-bezier(.2,.9,.3,1.2);
}

#location-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--red-light);
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
}

#location-welcome {
  margin-bottom: 4px;
}

#location-welcome .welcome-hi {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .02em;
}

#location-welcome strong {
  display: block;
  font-size: 44px;
  font-weight: 800;
  color: var(--red);
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 4px 0 10px;
}

#location-welcome .welcome-sub {
  display: block;
  max-width: 250px;
  margin: 0 auto;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.5;
}

.location-divider {
  width: 44px;
  height: 3px;
  border-radius: 3px;
  background: var(--fill);
  margin: 22px auto;
}

#location-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

#location-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 22px;
}

#location-actions {
  display: flex;
  gap: 10px;
}

#location-actions button {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, box-shadow .15s;
}

#location-skip {
  background: var(--fill);
  color: var(--text-muted);
}
#location-skip:active { background: var(--fill-active); }

#location-enable {
  background: var(--red);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
#location-enable:active { background: #b71c1c; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: scale(.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── iOS "Add to Home Screen" hint ─────────────────────────────────── */
#install-hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 1600;
  width: calc(100% - 24px);
  max-width: 400px;
  padding: 14px 42px 14px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
#install-hint.hidden { display: none; }

#install-hint-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--fill);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#install-hint-close:active { background: var(--fill-active); }

#install-hint-body {
  display: flex;
  align-items: center;
  gap: 12px;
}
#install-hint-body .buski-mascot { flex: none; }
/* Let the text column shrink so long lines wrap inside the card instead of
   overflowing past its right edge (flexbox min-width:auto default). */
#install-hint-text { min-width: 0; }

#install-hint-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 3px;
}
#install-hint-steps {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}
#install-hint-steps b { color: var(--text); font-weight: 600; }

.ios-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: -4px;
  width: 20px;
  height: 20px;
  margin: 0 1px;
  border-radius: 5px;
  background: var(--fill);
  color: var(--red);
}

#install-hint-arrow {
  position: absolute;
  right: 26px;
  bottom: -22px;
  color: var(--red);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.18));
}

@keyframes install-slide {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes install-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(5px); }
}
@media (prefers-reduced-motion: no-preference) {
  #install-hint { animation: install-slide .3s cubic-bezier(.2,.9,.3,1.2); }
  #install-hint-arrow { animation: install-bob 1.4s ease-in-out infinite; }
}

/* ── Buy me a coffee button ────────────────────────────────────────── */
/* Top-left, mirroring the right-hand control stack. Kept out of that stack
   so the bottom sheet (which grows up from the bottom) never covers it. */
#kopi-btn {
  position: fixed;
  /* Same top as #map-controls so it lines up with the theme toggle opposite. */
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  left: 12px;
  z-index: 400;
  color: var(--text);
  text-decoration: none;
}

#loading-link {
  font-size: 14px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}

#loading-link.hidden { display: none; }

/* ── Map ─────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ── Search bar ──────────────────────────────────────────────────── */
#search-bar {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  /* Above the Leaflet controls (z-index 800) so the results dropdown covers
     the top-right zoom/locate/theme buttons while searching. */
  z-index: 900;
  max-width: 480px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
}

#search-box {
  border-radius: 14px;
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 50px;
}

.icon-search { color: var(--icon-muted); flex-shrink: 0; }

#search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text);
  background: transparent;
  min-width: 0;
}

#search-input::placeholder { color: var(--placeholder); }

#clear-btn {
  border: none;
  background: var(--fill);
  color: var(--text-muted);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

#clear-btn.hidden { display: none; }

#search-results {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  margin-top: 8px;
  overflow: hidden;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#search-results.hidden { display: none; }

.result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: auto auto;
  gap: 2px 10px;
}

.result-item:last-child { border-bottom: none; }
.result-item:active { background: var(--surface-alt); }

.result-code {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  font-feature-settings: "tnum";
  background: var(--red-light);
  padding: 3px 6px;
  border-radius: 6px;
  text-align: center;
}

.result-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-road {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Zoom hint ───────────────────────────────────────────────────── */
#zoom-hint {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  backdrop-filter: blur(12px) saturate(1.35);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}

#zoom-hint.hidden { display: none; }

/* ── Map controls (top-right glass stack) ────────────────────────── */
#map-controls {
  position: fixed;
  right: 12px;
  /* Below the search bar: search top (12) + height (50). */
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.map-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s, box-shadow .15s, background .15s;
}

.map-btn.glass { box-shadow: var(--glass-shadow); }
.map-btn:active { transform: scale(.9); }
.map-btn.glass:active { background: var(--fill); }

#locate-btn { color: var(--blue); }
/* Filled "active" state once the map is centred on the user. */
#locate-btn.located { background: var(--blue); color: #fff; }
#locate-btn.located:active { background: var(--blue); }

/* Spin the crosshair while acquiring a fix. */
.map-btn.locating { cursor: progress; }
@media (prefers-reduced-motion: no-preference) {
  .map-btn.locating svg { animation: locate-spin .9s linear infinite; transform-origin: 50% 50%; }
}
@keyframes locate-spin { to { transform: rotate(360deg); } }

/* Pulsing "you are here" location marker. */
.user-loc { position: relative; background: none; border: 0; }
.user-loc-dot {
  position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--blue); border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.user-loc-pulse {
  position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--blue);
}
@media (prefers-reduced-motion: no-preference) {
  .user-loc-pulse { animation: user-loc-pulse 2s ease-out infinite; }
}
@keyframes user-loc-pulse {
  0%   { transform: scale(1);   opacity: .45; }
  100% { transform: scale(3.2); opacity: 0; }
}

.zoom-group {
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
}
.zoom-group .map-btn { border-radius: 0; box-shadow: none; }
.zoom-group .map-btn:active { background: var(--fill); }
.zoom-group #zoom-in { border-bottom: 1px solid var(--glass-border); }

/* Show the icon for the mode you'd switch TO: moon in light, sun in dark. */
#theme-toggle .icon-sun { display: none; }
#theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) #theme-toggle .icon-moon { display: none; }
}

/* ── Clear route button ──────────────────────────────────────────── */
#clear-route-btn {
  position: fixed;
  top: max(74px, calc(env(safe-area-inset-top) + 74px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 350;
  background: var(--red);
  color: white;
  border: none;
  border-radius: 22px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-md);
  font-family: inherit;
  white-space: nowrap;
}

#clear-route-btn:active { background: var(--red-dark); }
#clear-route-btn.hidden { display: none; }

/* ── Stop markers ────────────────────────────────────────────────── */
.stop-marker {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--red);
  border: 2.5px solid white;
  box-shadow: 0 1px 5px rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform .15s, background .15s;
  will-change: transform;
}

.stop-marker:hover { transform: scale(1.5); }

.stop-marker.selected {
  background: var(--blue);
  border-color: white;
  transform: scale(1.8);
  box-shadow: 0 2px 10px rgba(21,101,192,.45);
}

/* ── Nearby sheet (drag-up panel) ────────────────────────────────── */
#nearby-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 350;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -2px 14px rgba(0,0,0,.10);
  transform: translateY(calc(100% - 56px));
  transition: transform .35s cubic-bezier(.32,.72,0,1);
  max-height: 55vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#nearby-sheet.expanded { transform: translateY(0); }
#nearby-sheet.dragging  { transition: none; }

#nearby-handle {
  padding: 8px 0 10px;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  touch-action: none;
}

#nearby-handle:active { cursor: grabbing; }

#nearby-handle .handle-bar {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--handle);
  margin: 0 auto 8px;
}

.nearby-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.nearby-title .chevron {
  color: var(--text-muted);
  transition: transform .3s;
}

#nearby-sheet.expanded .nearby-title .chevron { transform: rotate(180deg); }

#nearby-list {
  overflow-y: auto;
  padding: 4px 12px 16px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.nearby-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface-alt);
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
}

.nearby-item:active { background: var(--fill); }

.ni-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ni-main { flex: 1; min-width: 0; }

.nearby-code {
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--red);
  background: var(--red-light);
  padding: 6px;
  border-radius: 6px;
  text-align: center;
  font-feature-settings: "tnum";
}

.nearby-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nearby-road {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nearby-distance {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
  text-align: right;
}

/* Live ETA pills under each nearby stop — a horizontal, swipeable scroller */
.nearby-eta {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  scrollbar-width: none;               /* Firefox */
}
.nearby-eta::-webkit-scrollbar { display: none; } /* Chrome/Safari */
.nearby-eta:empty { display: none; }
.ne-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  flex: 0 0 auto;                      /* keep full size; peek/cut-off hints scroll */
  scroll-snap-align: start;
  background: var(--fill);
  border-radius: 8px;
  padding: 3px 8px;
}
.ne-no { font-size: 12px; font-weight: 800; color: var(--red); font-feature-settings: "tnum"; }
.ne-min { font-size: 12px; font-weight: 600; color: var(--text); font-feature-settings: "tnum"; }
.ne-pill.seats    .ne-min { color: var(--load-seats); }
.ne-pill.standing .ne-min { color: var(--load-standing); }
.ne-pill.limited  .ne-min { color: var(--load-limited); }
/* Favourited service: sorts first (see nearbyEtaHtml) + a gold star marker. */
.ne-pill.fav { box-shadow: inset 0 0 0 1px color-mix(in srgb, #f5a623 55%, transparent); }
.ne-pill.fav::before {
  content: "★";
  align-self: center;
  color: #f5a623;
  font-size: 10px;
  line-height: 1;
  margin-right: -1px;
}
.ne-none { font-size: 12px; color: var(--text-muted); }

.nearby-section-label {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nearby-empty {
  text-align: center;
  padding: 18px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

#load-more-btn {
  display: block;
  width: 100%;
  margin: 4px 0 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--blue);
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}

#load-more-btn:hover { border-color: #b0bec5; }
#load-more-btn:active { background: var(--fill); }

/* ── Bottom sheet ────────────────────────────────────────────────── */
#bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--app-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.14);
  transform: translateY(100%);
  transition: transform .38s cubic-bezier(.32,.72,0,1);
  height: 92vh;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#bottom-sheet.open { transform: translateY(0); }

#drag-handle {
  width: 100%;
  padding: 10px 0 6px;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
}
#drag-handle::before {
  content: "";
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--handle);
}
#drag-handle:active { cursor: grabbing; }
#bottom-sheet.dragging { transition: none !important; }

#sheet-header {
  background: var(--surface);
  padding: 10px 16px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-shrink: 0;
}

#stop-details { min-width: 0; flex: 0 1 auto; }

#close-btn { margin-left: auto; }

#stop-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

#stop-code-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--red);
  background: var(--red-light);
  padding: 2px 7px;
  border-radius: 5px;
  font-feature-settings: "tnum";
  flex-shrink: 0;
}

#stop-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

#stop-road {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

#close-btn {
  border: none;
  background: var(--fill);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

#back-btn {
  border: none;
  background: var(--fill);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

#back-btn:active { background: var(--fill-active); }
#back-btn.hidden { display: none; }

#meta-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#updated-label {
  font-size: 12px;
  color: var(--text-muted);
}

#refresh-btn {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 6px;
}

#refresh-btn:active { background: var(--fill); }

@media (prefers-reduced-motion: no-preference) {
  #refresh-btn.spinning svg { animation: spin .7s linear infinite; }
}

#filter-chips {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#filter-chips::-webkit-scrollbar { display: none; }

.filter-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.filter-chip:active { transform: scale(.95); }
.filter-chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.filter-chip .chip-star { fill: currentColor; }

/* ── Services list ───────────────────────────────────────────────── */
#services-list {
  overflow-y: auto;
  flex: 1;
  /* Extra bottom padding so the last card can scroll into view when the sheet
     sits at a partial (mid/peek) snap and its lower edge is off-screen. */
  padding: 12px 12px calc(35vh + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.service-card {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 40px 12px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .12s;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 12px;
}
.service-card:active { transform: scale(0.995); }
.service-card.route-active {
  border-color: var(--red);
  background: var(--route-active-bg);
  box-shadow: 0 2px 10px rgba(211,47,47,.18);
}

/* Left identity column: number, operator, bus-type icon */
.svc-id {
  flex-shrink: 0;
  width: 62px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}
.svc-no {
  font-size: 22px;
  font-weight: 800;
  color: var(--red);
  line-height: 1;
  font-feature-settings: "tnum";
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.svc-operator {
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  padding: 2px 6px;
  border-radius: 5px;
  letter-spacing: .4px;
  text-transform: uppercase;
  line-height: 1.35;
}
.type-icon {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  align-self: center;
  margin-left: 3px;
}

/* Live (dynamic) half: hero countdown + crowding, then a full-width dest row */
.svc-live {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.svc-live-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.svc-eta { flex: 1; min-width: 0; }
.eta-hero { display: flex; align-items: baseline; gap: 3px; }
.eta-num {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: .95;
  font-feature-settings: "tnum";
  letter-spacing: -1px;
}
.eta-unit { font-size: 13px; color: var(--text-muted); }
.eta-now { font-size: 26px; font-weight: 800; color: var(--green); line-height: 1; }
.eta-none { font-size: 26px; font-weight: 700; color: var(--text-muted); }
.svc-eta.scheduled .eta-num { color: var(--text-muted); }
.eta-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
  font-feature-settings: "tnum";
}

.svc-side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.svc-dest-row { min-width: 0; }
.svc-dest {
  display: inline-block;
  max-width: 100%;
  background: var(--dest-bg);
  color: var(--dest-text);
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.crowd { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.crowd-bar { display: flex; gap: 2px; }
.crowd-seg { width: 12px; height: 5px; border-radius: 2px; background: var(--seg-off); }
.crowd.seats    .crowd-seg.on { background: #66bb6a; }
.crowd.standing .crowd-seg.on { background: #ffa726; }
.crowd.limited  .crowd-seg.on { background: #ef5350; }
.crowd-word { font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.crowd.seats    .crowd-word { color: var(--load-seats); }
.crowd.standing .crowd-word { color: var(--load-standing); }
.crowd.limited  .crowd-word { color: var(--load-limited); }

/* Live pulse dot = real-time tracking */
.pdot {
  position: relative;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex: none;
  align-self: center;
  margin-left: 5px;
}
@media (prefers-reduced-motion: no-preference) {
  .pdot::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: inherit;
    animation: pdot-pulse 1.7s ease-out infinite;
  }
}
@keyframes pdot-pulse { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(2.6); opacity: 0; } }

/* Per-service favourite star sits in the card's top-right corner */
.service-card > .star-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px;
  margin: 0;
}

/* ── Favourites (star) ───────────────────────────────────────────── */
.star-btn {
  border: none;
  background: none;
  padding: 4px;
  margin: -4px 0;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s;
}
.star-icon { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.star-btn.starred { color: #f5a623; }
.star-btn.starred .star-icon { fill: currentColor; stroke: currentColor; }
.star-btn:active { transform: scale(.85); }

/* Push the stop's star (and the close button after it) to the right.
   Only the star takes the auto margin so the two stay grouped together. */
#fav-stop-btn { margin-left: auto; }
#sheet-header #close-btn { margin-left: 0; }

.fav-mark { color: #f5a623; }

/* ── Route stop list ─────────────────────────────────────────────── */
#route-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* Swap arrivals UI for the route view when a bus number is tapped */
#bottom-sheet.route-mode #meta-bar,
#bottom-sheet.route-mode #filter-chips,
#bottom-sheet.route-mode #services-list { display: none; }
#bottom-sheet.route-mode #route-panel { display: flex; }

#route-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#route-back-btn {
  border: none;
  background: var(--fill);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
#route-back-btn:active { background: var(--fill-active); }

#route-panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--red);
}

#route-panel-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

#route-stops {
  overflow-y: auto;
  flex: 1;
  padding: 8px 16px calc(35vh + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.route-stop {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 40px;
}

/* Timeline rail + dot */
.rs-track {
  position: relative;
  align-self: stretch;
  display: flex;
  justify-content: center;
}
.rs-track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.route-stop:first-child .rs-track::before { top: 50%; }
.route-stop:last-child  .rs-track::before { bottom: 50%; }

.rs-dot {
  position: relative;
  z-index: 1;
  align-self: center;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--red);
}

.rs-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rs-road {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rs-code {
  font-size: 11px;
  font-weight: 700;
  color: var(--red);
  background: var(--red-light);
  padding: 3px 6px;
  border-radius: 6px;
  font-feature-settings: "tnum";
}

/* Passed stops — dimmed */
.route-stop.passed .rs-name,
.route-stop.passed .rs-road { opacity: .45; }
.route-stop.passed .rs-dot { background: var(--border); border-color: var(--border); }
.route-stop.passed .rs-code { opacity: .5; }

/* Current stop — emphasised */
.route-stop.current .rs-dot {
  width: 15px;
  height: 15px;
  background: var(--blue);
  border-color: var(--surface);
  box-shadow: 0 0 0 2px var(--blue);
}
.route-stop.current .rs-name { font-weight: 700; color: var(--blue); }

/* Tapped-in-list row + its map marker */
.route-stop.sel { background: var(--fill); border-radius: 8px; }
.route-stop.sel .rs-name { color: var(--blue); font-weight: 700; }

.route-stop-pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--blue), 0 1px 6px rgba(0,0,0,.45);
}

/* Live vehicle markers (buses gliding toward the stop on the active route) */
.live-bus {
  min-width: 26px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--red);
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.live-bus.seats    { background: #2e7d32; }
.live-bus.standing { background: #ef8f00; }
.live-bus.limited  { background: #c62828; }
.live-bus-no {
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  font-feature-settings: "tnum";
}

.rs-here {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--blue);
  padding: 1px 6px;
  border-radius: 10px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .3px;
}

/* ── Empty/error states ──────────────────────────────────────────── */
.state-msg {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.state-msg.error { color: var(--red); }

.empty-state { text-align: center; padding: 30px 20px; }
.buski-mascot { display: block; margin: 0 auto 12px; }
@media (prefers-reduced-motion: no-preference) {
  .buski-mascot { animation: buski-bob 3s ease-in-out infinite; }
}
@keyframes buski-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--text-muted); line-height: 1.5; max-width: 260px; margin: 0 auto; }

/* ── Toast ────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(10px);
  z-index: 1400;
  max-width: calc(100% - 32px);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  backdrop-filter: blur(12px) saturate(1.35);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.hidden { display: none; }

/* ── Leaflet overrides ───────────────────────────────────────────── */
.leaflet-control-attribution {
  font-size: 10px !important;
  opacity: .6;
  background: var(--surface) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--blue) !important; }

/* Popups & tooltips ("You are here", route stop labels) */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip,
.leaflet-tooltip {
  background: var(--surface) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-md) !important;
}
.leaflet-tooltip { border-color: var(--border) !important; }
.leaflet-tooltip-top::before    { border-top-color: var(--surface) !important; }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--surface) !important; }
.leaflet-tooltip-left::before   { border-left-color: var(--surface) !important; }
.leaflet-tooltip-right::before  { border-right-color: var(--surface) !important; }

@media (min-width: 600px) {
  #bottom-sheet {
    max-width: 420px;
    left: auto;
    right: 16px;
    border-radius: var(--radius);
    bottom: 16px;
    max-height: 75vh;
    transform: translateX(calc(100% + 16px));
    box-shadow: var(--shadow-md);
  }

  #bottom-sheet.open { transform: translateX(0); }

  /* With a stop selected, the vertical stack would run down behind the
     right-side arrivals panel. Move the controls up into a horizontal row on
     the same level as the search bar (42px buttons centred against its 50px
     height), clear of the panel. animateControlsReflow() FLIP-animates the
     buttons between this layout and the default stack so they flow up and back. */
  body:has(#bottom-sheet.open) #map-controls {
    flex-direction: row;
    top: calc(max(12px, env(safe-area-inset-top)) + 4px);
  }
  body:has(#bottom-sheet.open) .zoom-group { flex-direction: row; }
  body:has(#bottom-sheet.open) .zoom-group #zoom-in {
    border-bottom: none;
    border-right: 1px solid var(--glass-border);
  }

  #drag-handle { display: none; }

  /* Sheet is fully visible on desktop — no need for the mobile scroll buffer. */
  #services-list { padding-bottom: 12px; }

  #nearby-sheet {
    max-width: 360px;
    left: 16px;
    right: auto;
    bottom: 16px;
    border-radius: var(--radius);
    transform: translateY(calc(100% + 16px - 56px));
  }

  #nearby-sheet.expanded { transform: translateY(0); }

  #zoom-hint  { bottom: 70px; }
}
