:root {
  --bg: #F4F3EF; --panel: #fff; --ink: #16181D; --muted: #5B606B; --line: #E2E0DA; --rule: #ECEAE4;
  --field: #DCDAD3; --link: #1D4FB8; --live: #12A46B; --live-ink: #0B6B45; --live-bg: #E3F1EA;
  --warn: #C62828; --warn-bg: #FBE9E7; --notice-bg: #FFF4D6; --notice-line: #EFD48A; --notice-ink: #4D3A00;
  --mine: #EEF2FB; --seg: #E6E4DD; --star: #E0A100; --star-line: #B88400;
  --num: 'Space Grotesk', system-ui, sans-serif; --body: Inter, system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.4 var(--body); -webkit-tap-highlight-color: transparent; }
a { color: var(--ink); text-decoration: none; }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 0; }

/* Home */
.top { padding: 20px 20px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font: 700 24px/1.1 var(--num); letter-spacing: -0.5px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--live-bg);
  color: var(--live-ink); font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.off { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); flex: none; }
.off .dot, .dot.off { background: var(--warn); }
.search { margin: 0 16px 16px; position: relative; }
.search svg { position: absolute; left: 14px; top: 15px; pointer-events: none; }
.search input { width: 100%; height: 48px; border: 1px solid var(--field); border-radius: 12px; background: var(--panel);
  padding: 0 14px 0 42px; font: 500 16px var(--body); color: var(--ink); -webkit-appearance: none; appearance: none; }
.search input:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.body { flex: 1; padding: 0 16px 24px; display: flex; flex-direction: column; gap: 20px; }
.section { display: flex; flex-direction: column; gap: 8px; }
.h2row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
h2 { margin: 0; font: 600 13px var(--body); color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.card { display: flex; flex-direction: column; border-radius: 14px; background: var(--panel); box-shadow: 0 1px 0 var(--line); overflow: hidden; }
.fav { padding: 14px; gap: 10px; }
.item { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
.item + .item, .row + .row { border-top: 1px solid var(--rule); }
.namerow { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.name { font-weight: 600; font-size: 15px; }
.fav .name { font-size: 16px; }
.code { font-weight: 500; color: var(--muted); }
.meta { font-size: 13px; color: var(--muted); flex: none; }
.strip { display: flex; gap: 12px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; min-height: 24px; align-items: center; }
.strip::-webkit-scrollbar { display: none; }
/* a soft fade on the right says the row scrolls sideways */
.strip { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); padding-right: 24px; }
.eta { display: inline-flex; align-items: center; gap: 6px; flex: none; font: 600 15px var(--num); }
.eta.now { color: var(--live-ink); }
.chip { display: inline-block; min-width: 32px; height: 24px; padding: 0 6px; border-radius: 6px; background: var(--c, #888); color: var(--t, #fff);
  font: 700 12px/24px var(--num); text-align: center; flex: none; }
.chip.sm { min-width: 22px; height: 18px; padding: 0 4px; border-radius: 4px; font-size: 10px; line-height: 18px; }
.chip.lg { min-width: 48px; height: 48px; border-radius: 10px; font-size: 26px; line-height: 48px; }
.chip.plus { --c: var(--rule); --t: #3F444E; }
.note { font-size: 13px; color: var(--muted); }
.empty { padding: 14px; font-size: 14px; color: var(--muted); }
.linkbtn { align-self: center; padding: 10px 12px; font-size: 14px; font-weight: 600; color: var(--link); background: none; border: 0; cursor: pointer; min-height: 44px; }
.btn { height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; font-size: 15px; cursor: pointer; }
.nav { position: sticky; bottom: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line);
  background: #FBFAF7; padding-bottom: env(safe-area-inset-bottom); }
.nav a { height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 500; color: var(--muted); }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }

/* Stop and line screens */
.screen { flex: 1; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.bar { height: 52px; display: flex; align-items: center; justify-content: space-between; }
.back { display: flex; align-items: center; gap: 4px; height: 44px; padding-right: 12px; font-size: 15px; font-weight: 500; color: var(--link); }
.star { width: 44px; height: 44px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.star svg { fill: none; stroke: var(--muted); }
.star[aria-pressed="true"] svg { fill: var(--star); stroke: var(--star-line); }
h1 { margin: 0; font: 700 30px/1.1 var(--num); letter-spacing: -0.6px; }
.sub { font-size: 14px; color: var(--muted); }
.other { flex-direction: row; align-items: center; gap: 12px; padding: 12px 14px; }
.other .t { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.other .h { font-size: 14px; font-weight: 600; }
.liveline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.liveline b { color: var(--live-ink); font-weight: 600; }
.liveline.off b { color: var(--warn); }
.row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; column-gap: 10px; padding: 10px 14px; min-height: 58px; }
.row .chip { height: 28px; min-width: 40px; border-radius: 7px; font-size: 13px; line-height: 28px; justify-self: start; }
.row .chip.long { font-size: 11px; padding: 0 4px; }
.row .to { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row .to b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .to span { font-size: 13px; color: var(--muted); }
.big { font: 700 22px/1 var(--num); text-align: right; white-space: nowrap; }
.big small { font-size: 13px; font-weight: 600; color: var(--muted); }
.big.now { color: var(--live-ink); }
.row.dim { opacity: 0.6; }
.notice { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 14px; background: var(--notice-bg);
  border: 1px solid var(--notice-line); color: var(--notice-ink); font-size: 14px; }
.notice strong { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.notice u { text-decoration: none; font-weight: 600; color: var(--link); }
.alert { padding: 12px 14px; border-radius: 14px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }

.linehead { display: flex; align-items: center; gap: 12px; }
.linehead h1 { font-size: 24px; letter-spacing: -0.4px; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--seg); }
.seg a { min-height: 40px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px 6px; border-radius: 9px;
  font-size: 14px; font-weight: 500; color: #3F444E; }
.seg a[aria-current="true"] { background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,0.12); font-weight: 600; color: var(--ink); }
.rail { padding: 6px 0; }
.stopr { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; column-gap: 4px; min-height: 40px; padding-right: 14px; }
.stopr.mine { background: var(--mine); }
.stopr .nm { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stopr.mine .nm { font-weight: 700; }
.stopr .nm small { font-size: 12px; color: var(--muted); font-weight: 500; }
.stopr .cx { display: flex; gap: 4px; align-items: center; }
.tag { font-size: 12px; font-weight: 700; color: var(--link); }
.track { position: relative; justify-self: center; width: 24px; align-self: stretch; min-height: 40px; }
.track::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 4px; background: var(--lc); }
.track.first::before { top: 50%; } .track.last::before { bottom: 50%; }
.track i { position: absolute; left: 5px; top: calc(50% - 7px); width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--lc); }
.mine .track i { left: 3px; top: calc(50% - 9px); width: 18px; height: 18px; }
.busr { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; column-gap: 4px; min-height: 48px; padding-right: 14px; }
.busr .track b { position: absolute; left: -3px; top: calc(50% - 15px); width: 30px; height: 30px; border-radius: 50%; background: var(--lc);
  box-shadow: 0 0 0 4px var(--lh); display: flex; align-items: center; justify-content: center; }
.busr .l { font-size: 13px; color: #3F444E; }
.busr .w { font: 700 18px var(--num); }
.more { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; min-height: 40px; width: 100%; border: 0; background: transparent;
  padding: 0 14px 0 0; text-align: left; font-size: 13px; font-weight: 500; color: var(--link); cursor: pointer; }
.more .track::before { background: none; border-left: 4px dotted var(--lc); width: 0; }
.lines .item { flex-direction: row; align-items: center; gap: 12px; }
.lines .dirs { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.lines .dirs a { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 32px; }
.lines .dirs a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results .item { gap: 6px; }
.cx-list { display: flex; gap: 4px; flex-wrap: wrap; }

/* Maps (maps.js) */
.mapcard { position: relative; }
.minimap { position: relative; height: 184px; background: #ECE9E1; cursor: pointer; overflow: hidden; }
.minimap.tall { height: 300px; }
.mapopen { position: absolute; right: 8px; top: 8px; z-index: 2; width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,0.94);
  display: flex; align-items: center; justify-content: center; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,0.16); }
.credit { font-size: 10px; color: #6B6F78; background: rgba(255,255,255,0.78); padding: 1px 5px; border-radius: 4px; white-space: nowrap; }
.credit a { color: #6B6F78; }
.minimap .credit { position: absolute; left: 6px; bottom: 6px; z-index: 2; pointer-events: none; }
.mapcard .other { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--rule); }

body.mapmode #app { height: 100vh; height: 100dvh; overflow: hidden; }
.mapscreen { position: relative; flex: 1; min-height: 0; background: #ECE9E1; overflow: hidden; }
#bigmap { position: absolute; inset: 0; }  /* an id, so MapLibre's own .maplibregl-map { position: relative } doesn't win */
.msearch { position: absolute; left: 16px; right: 16px; top: 16px; margin: 0; z-index: 3; }
.msearch input { border: 0; box-shadow: 0 2px 10px rgba(0,0,0,0.12); }
.mresults[hidden] { display: none; }
.mresults { position: absolute; left: 16px; right: 16px; top: 70px; z-index: 3; max-height: 55%; overflow-y: auto; box-shadow: 0 4px 16px rgba(0,0,0,0.14); }
.mres { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.mres + .mres { border-top: 1px solid var(--rule); }
#mline { position: absolute; left: 16px; top: 72px; z-index: 2; }
.mline { display: inline-flex; align-items: center; gap: 8px; padding: 6px 6px 6px 8px; border-radius: 12px; background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12); font-size: 14px; font-weight: 600; }
.mline button { width: 32px; height: 32px; border: 0; border-radius: 8px; background: var(--rule); color: var(--muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer; }
.mapbottom { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; pointer-events: none; }
.mrow { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; padding: 0 16px 10px 8px; }
.mrow > * { pointer-events: auto; }
.locbtn { width: 44px; height: 44px; flex: none; border: 0; border-radius: 12px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.14);
  display: flex; align-items: center; justify-content: center; cursor: pointer; }
.sheet { pointer-events: auto; background: #fff; border-radius: 20px 20px 0 0; box-shadow: 0 -4px 18px rgba(0,0,0,0.12);
  padding: 10px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.grab { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: #D9D6CF; }
.sheet .namerow { align-items: center; }
.sheet .st { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sname { margin: 0; font: 700 20px/1.15 var(--num); color: var(--ink); text-transform: none; letter-spacing: 0; }
.sheet .note { margin: 0; }
.sbtns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sbtns.one { grid-template-columns: 1fr; }
.sbtns .btn, .btn2 { height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 600; font-size: 15px; }
.sbtns .btn { color: #fff; }
.btn2 { border: 0; background: #EEECE6; color: var(--ink); cursor: pointer; }

/* Map markers: a dot with a label pill on whichever side fits */
.mk { pointer-events: none; }
.mk .mlabel { position: absolute; top: 50%; left: calc(100% + 6px); transform: translateY(-50%); white-space: nowrap; height: 24px; padding: 0 9px;
  border-radius: 12px; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,0.1); font: 700 13px/22px var(--num); color: var(--ink); }
.mk.flip .mlabel { left: auto; right: calc(100% + 6px); }
.mk-this, .mk-sel { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.mk-other { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--ink); }
.mk-other .mlabel, .mk-you .mlabel { font-weight: 500; }
.mk-you { width: 18px; height: 18px; border-radius: 50%; background: #1D6FE8; border: 3px solid #fff;
  box-shadow: 0 0 0 12px rgba(29,111,232,0.16), 0 1px 3px rgba(0,0,0,0.3); }
.mk-you .mlabel { left: calc(100% + 14px); background: #1D6FE8; border-color: #1D6FE8; color: #fff; }
.mk-you.flip .mlabel { left: auto; right: calc(100% + 14px); }
.mk-bus { width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: var(--t, #fff); border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.mk-bus .mlabel { left: calc(100% + 6px); }
