:root {
  --bg: #ffffff;
  --bg2: #f1f2f6;
  --section: #ffffff;
  --text: #111418;
  --hint: #7d8590;
  --link: #2481cc;
  --btn: #2481cc;
  --btn-text: #ffffff;
  --sep: rgba(127, 127, 127, .18);
  --live: #1aa251;
  --warn: #d9822b;
  --late: #d63b3b;
  --radius: 12px;
  --map-h: 52vh;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17191d; --bg2: #0e0f12; --section: #1f2227; --text: #eceef1; --hint: #8b929b;
    --link: #6ab3f3; --btn: #3e88d6; --sep: rgba(255, 255, 255, .08);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
a { color: var(--link); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.view { max-width: 720px; margin: 0 auto; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.bar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--sep);
}
.bar h1 { font-size: 20px; margin: 0; flex: 1; }
.route-bar { padding: 8px 8px 8px 4px; }
.title { flex: 1; min-width: 0; }
.title > div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { color: var(--hint); font-size: 13px; }

.group { margin: 14px 12px 0; }
.group h2 { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 0 4px 6px; }
.list { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 14px; border: 0; background: none; text-align: left; cursor: pointer;
}
.item + .item { border-top: 1px solid var(--sep); }
.item:active { background: var(--sep); }
.item .main { flex: 1; min-width: 0; }
.item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--hint); font-size: 13px; margin-top: 1px; }
.item .sub.live { color: var(--live); }
.empty { padding: 14px; color: var(--hint); }

.badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 36px; height: 28px; padding: 0 7px; border-radius: 8px;
  font-weight: 700; font-size: 15px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.badge.sm { min-width: 30px; height: 22px; font-size: 13px; border-radius: 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; cursor: pointer; color: var(--text);
}
.icon-btn:active { background: var(--sep); }
.star::before { content: "☆"; font-size: 24px; line-height: 1; color: var(--hint); }
.star.on::before { content: "★"; color: #f5b301; }

.wide-btn {
  width: 100%; padding: 12px; border: 0; border-radius: var(--radius);
  background: var(--btn); color: var(--btn-text); font-weight: 600; cursor: pointer;
}
.wide-btn + .list { margin-top: 8px; }
.attrib { margin: 18px 16px 0; font-size: 12px; color: var(--hint); text-align: center; }

/* segmented control */
.seg { display: flex; gap: 4px; margin: 8px 12px; padding: 3px; background: var(--sep); border-radius: 10px; }
.seg button {
  flex: 1; min-width: 0; padding: 7px 6px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
.seg button.on { background: var(--section); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.small { margin: 0 14px 6px; }
.seg.small button { padding: 5px; font-size: 13px; }

/* map */
#map-wrap { position: relative; margin: 0 12px; border-radius: var(--radius); overflow: hidden; }
#map { height: var(--map-h); min-height: 260px; background: var(--section); }
.upd {
  position: absolute; left: 8px; bottom: 8px; z-index: 500;
  padding: 3px 8px; border-radius: 8px; font-size: 12px;
  background: rgba(255, 255, 255, .9); color: #333; box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.upd.err { background: #fff1e5; color: #9a4b00; }
.dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.6); }
.dark .leaflet-container { background: #222; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.4; }
.leaflet-popup-content b { font-size: 14px; }

.bus-icon { background: none; border: 0; }
.bus {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.bus svg { display: block; }
.bus.other { opacity: .45; transform: scale(.8); }
.bus.stale { filter: grayscale(1); opacity: .6; }

/* stop list as a line diagram */
.stops { margin: 12px 12px 0; }
.stop-row { position: relative; padding-left: 40px; }
.stop-row::before {
  content: ""; position: absolute; left: 21px; top: 0; bottom: 0; width: 4px; background: var(--line, #888);
}
.stop-row:first-child::before { top: 50%; }
.stop-row:last-child::before { bottom: 50%; }
.stop-row::after {
  content: ""; position: absolute; left: 16px; top: 50%; width: 14px; height: 14px; margin-top: -7px;
  border-radius: 50%; background: var(--section); border: 3px solid var(--line, #888); box-sizing: border-box;
}
.stop-row .item { padding-left: 6px; }
.stop-row + .stop-row .item { border-top: 1px solid var(--sep); }
.bus-chip {
  display: inline-flex; align-items: center; gap: 4px; margin: 3px 4px 0 0; padding: 1px 7px;
  border-radius: 10px; font-size: 12px; background: rgba(26, 162, 81, .12); color: var(--live);
}

/* bottom sheet */
#sheet-backdrop { position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .3); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2001;
  max-width: 720px; margin: 0 auto; max-height: 72vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, .25);
  padding-bottom: env(safe-area-inset-bottom);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--sep); margin: 8px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 6px; padding: 4px 8px 8px 16px; }
.sheet-head .title > div:first-child { white-space: normal; font-size: 17px; }
.arrivals { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 12px; }
.arr { display: flex; align-items: center; gap: 10px; padding: 9px 2px; }
.arr + .arr { border-top: 1px solid var(--sep); }
.arr .main { flex: 1; min-width: 0; }
.arr .dest { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arr .meta { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arr .when { text-align: right; flex: none; }
.arr .clock { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.arr .in { font-size: 12px; color: var(--hint); }
.arr .clock.live { color: var(--live); }
.arr.canceled .clock { text-decoration: line-through; color: var(--hint); }
.tag { font-size: 11px; padding: 0 5px; border-radius: 5px; margin-right: 4px; }
.tag.live { color: var(--live); background: rgba(26, 162, 81, .12); }
.tag.sched { color: var(--hint); background: var(--sep); }
.tag.late { color: var(--late); }
.tag.early { color: var(--warn); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--live); margin-right: 4px; vertical-align: 1px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.s-foot { padding: 8px 16px 10px; font-size: 11px; }

/* journeys */
.journey-btns { display: flex; gap: 8px; padding: 0 14px 8px; }
.journey-btns button {
  flex: 1; padding: 8px 6px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--sep); color: var(--text); font-size: 14px;
}
.journey-btns button.on { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.pick-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500; display: flex; align-items: center; gap: 10px;
  max-width: 720px; margin: 0 auto; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--btn); color: var(--btn-text); font-size: 14px; box-shadow: 0 -2px 12px rgba(0, 0, 0, .2);
}
.pick-banner span { flex: 1; }
.pick-banner button { border: 0; background: rgba(255, 255, 255, .22); color: inherit; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.jcard .name b { font-weight: 600; }
.jcard .next { font-variant-numeric: tabular-nums; }
.en-route { display: block; padding: 12px 14px; }
.en-route + .en-route { border-top: 1px solid var(--sep); }
.en-route .top { display: flex; align-items: baseline; gap: 8px; }
.en-route .eta { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--live); }
.en-route .in { font-size: 15px; font-weight: 600; }
.en-route .who { margin-left: auto; text-align: right; font-size: 12px; color: var(--hint); white-space: nowrap; }
.en-route .top .in { white-space: nowrap; }
.en-route .line2 { font-size: 13px; color: var(--hint); margin-top: 3px; }
.progress { height: 4px; border-radius: 2px; background: var(--sep); margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--live); }
.arrivals-list .arr { padding: 9px 12px; }
#j-map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; }
#j-map { height: 240px; background: var(--section); }
.stop-pin { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45); }
.stop-pin.a { background: #2481cc; }
.stop-pin.b { background: #d63b3b; }
.eta-label { background: none; border: 0; }
.eta-bus { display: flex; align-items: center; gap: 4px; width: max-content; }
.eta-bus span {
  white-space: nowrap; padding: 1px 6px; border-radius: 8px; font-size: 12px; font-weight: 600;
  background: #fff; color: #111; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.jcard .live { color: var(--live); }
