:root {
  --bg: #f4f6f4;
  --card: #ffffff;
  --ink: #17211b;
  --muted: #5b6b61;
  --line: #e1e6e2;
  --brand: #14532d;
  --r1: #0f766e;
  --r2: #7c3aed;
  --r3: #db2777;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --tight: #a16207;
  --tight-bg: #fef3c7;
  --risky: #b91c1c;
  --risky-bg: #fee2e2;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411; --card: #18201b; --ink: #e8efe9; --muted: #9fb0a5; --line: #2a352e;
    --ok-bg: #12351f; --tight-bg: #3a2e0b; --risky-bg: #3d1414;
    --ok: #4ade80; --tight: #fbbf24; --risky: #f87171;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: var(--brand); color: #fff;
}
.top h1 { margin: 0; font-size: 1.3rem; }
.top .sub { margin: 0; opacity: .85; font-size: .9rem; }
.clock { font-size: 1.4rem; font-variant-numeric: tabular-nums; font-weight: 600; }
main { max-width: 640px; margin: 0 auto; padding: 14px; }
h2 { font-size: 1.05rem; margin: 26px 0 8px; }

.intro { margin: 4px 0 6px; color: var(--muted); }
.legend { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; font-size: .95rem; }

.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 99px; color: #fff; letter-spacing: .02em; white-space: nowrap; }
.tag.r1 { background: var(--r1); }
.tag.r2 { background: var(--r2); }
.tag.r3 { background: var(--r3); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.next { border-color: var(--brand); box-shadow: 0 2px 10px rgb(20 83 45 / .12); }
.card.empty, .card.skeleton { color: var(--muted); text-align: center; padding: 24px; }

.leave-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.leave-time { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card:not(.next) .leave-time { font-size: 1.4rem; }
.cd { font-size: 1rem; font-weight: 600; color: var(--ok); margin-left: 6px; }
.cd.urgent { color: var(--risky); }
.bus162 { margin: 4px 0 10px; color: var(--muted); font-size: .92rem; }
.delay { font-size: .75rem; font-weight: 600; }
.delay.late { color: var(--tight); }
.delay.early { color: var(--ok); }
.backup { color: var(--muted); }
s.was { color: var(--muted); font-weight: 400; }
.now-time.late { color: var(--risky); }
.now-time.early { color: var(--ok); }
.leave-line { font-size: 1.05rem; }
.nl-note { margin: -4px 0 8px; font-size: .85rem; color: var(--muted); }

.mode { display: inline-block; min-width: 2.6em; text-align: center; font-weight: 800; font-size: .8rem; padding: 2px 6px; border-radius: 6px; color: #fff; background: #334155; }
.mode.train { background: #1d4ed8; }

.pill { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.pill.live { background: var(--ok-bg); color: var(--ok); }
.pill.live::before { content: "● "; }
.pill.sched { background: var(--line); color: var(--muted); }

.route { border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; overflow: hidden; }
.route.best { border-color: var(--ok); background: color-mix(in srgb, var(--ok-bg) 45%, transparent); }
.route.none .route-head { color: var(--muted); font-size: .9rem; }
.route-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 10px 12px; cursor: pointer; list-style: none; }
.route-head::-webkit-details-marker { display: none; }
details.route > summary::after { content: "›"; margin-left: 4px; font-size: 1.3rem; color: var(--muted); transition: transform .15s; }
details.route[open] > summary::after { transform: rotate(90deg); }
.route-title { font-weight: 600; font-size: .95rem; }
.arrive { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.arrive b { font-size: 1.1rem; }
.arrive small { display: block; color: var(--muted); font-size: .75rem; }
.best-badge { background: var(--ok); color: #fff; font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 99px; }

.xfer { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.xfer.comfortable { background: var(--ok-bg); color: var(--ok); }
.xfer.tight { background: var(--tight-bg); color: var(--tight); }
.xfer.risky { background: var(--risky-bg); color: var(--risky); }
.xfer.tight.run { background: var(--risky-bg); color: var(--risky); }
.xfer.mini { font-size: .68rem; }

.steps { list-style: none; margin: 0; padding: 4px 12px 12px; border-top: 1px dashed var(--line); }
.step { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-size: .92rem; }
.step small, .step-xfer small { color: var(--muted); }
.step-xfer { padding: 2px 0 2px 2px; font-size: .85rem; color: var(--muted); }

.status-msg { background: var(--tight-bg); color: var(--tight); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: .9rem; }
.status-msg.stale { background: var(--risky-bg); color: var(--risky); }
.alert { background: var(--tight-bg); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: .9rem; }
.alert.warn { background: var(--risky-bg); color: var(--risky); }
.alert summary { cursor: pointer; }
.alert p { margin: 6px 0 0; white-space: pre-line; }

.install { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--brand); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: .92rem; }
.install[hidden] { display: none; }
.install span { flex: 1; }
button { font: inherit; border: 0; border-radius: 10px; padding: 8px 14px; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; }
button.link { background: none; color: var(--muted); padding: 4px 8px; }
button[hidden] { display: none; }

.guides details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.guides summary { cursor: pointer; font-weight: 600; }
.guides ol { padding-left: 20px; margin: 10px 0 4px; }
.guides li { margin-bottom: 6px; }
.tip { color: var(--muted); font-size: .9rem; }

footer { max-width: 640px; margin: 0 auto; padding: 8px 18px 28px; color: var(--muted); font-size: .8rem; }

/* ---- Stop counts ---- */
.ride-stops { font-size: .8rem; color: var(--muted); margin: 2px 0; }
.ride-stops::before { content: "↓ "; }

/* ---- Start trip ---- */
.start-row { padding: 0 12px 12px; }
button.start { width: 100%; }
button.board-btn { width: 100%; margin: 4px 0 10px; padding: 12px 14px; font-size: 1rem; }
button.miss-btn { width: 100%; justify-content: center; margin: 0 0 10px; padding: 10px 14px; }
button.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); width: auto; padding: 6px 10px; display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }

/* ---- Already on your way ---- */
.recent { background: var(--card); border: 1px dashed var(--brand); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.recent > summary { cursor: pointer; font-weight: 600; color: var(--brand); }
@media (prefers-color-scheme: dark) { .recent > summary { color: var(--ok); } }
.recent ul { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 10px; }
.recent li { font-size: .92rem; }
.recent-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* ---- Trip view ---- */
.trip-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.trip-route { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.trip-arrive { font-size: 1.05rem; margin-bottom: 10px; }
.card.now { border-width: 2px; border-color: var(--brand); }
.card.now.onboard { border-color: var(--r1); }
.card.now.approaching { border-color: var(--tight); }
.card.now p { margin: 6px 0; }
.big { font-size: 1.6rem; line-height: 1.2; margin: 0 0 6px; font-weight: 600; }
.big b { font-weight: 800; }
.bell { font-size: 1.15rem; font-weight: 700; color: var(--risky); }
.rush { font-weight: 600; color: var(--tight); }
.now-meta { margin-top: 8px; color: var(--muted); }
.card.now.done { text-align: center; }
.card.now.done button { margin-top: 8px; }

.timeline { list-style: none; padding: 0; margin: 14px 0; }
.tl { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; font-size: .92rem; }
.tl.current { background: var(--card); border: 1px solid var(--line); }
.tl.done { color: var(--muted); }
.tl.done .mode { opacity: .5; }
.tl-icon { width: 1.1em; text-align: center; font-weight: 700; color: var(--brand); }
.tl.done .tl-icon { color: var(--ok); }
/* The step in progress: a spinning ring. */
.spinner { display: inline-block; width: .95em; height: .95em; margin-top: .15em; border: 2.5px solid color-mix(in srgb, var(--brand) 25%, transparent); border-top-color: var(--brand); border-radius: 50%; animation: spin .9s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }
.tl-xfer { padding: 2px 0 2px 34px; font-size: .82rem; color: var(--muted); }

/* ---- Finding stops ---- */
.pill.plat { background: #1d4ed8; color: #fff; }
.find-wrap { margin-top: 4px; }
.find-wrap > summary { cursor: pointer; font-size: .8rem; color: var(--r1); font-weight: 600; }
.find { margin-top: 8px; padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: .9rem; }
.find p { margin: 0 0 6px; }
.find img { display: block; width: 100%; border-radius: 8px; margin: 6px 0; }
.find a { font-size: .85rem; font-weight: 600; color: var(--r1); }
.platform { font-weight: 600; }

.mode { flex-shrink: 0; }

/* ---- Offline / stale: don't claim "live" ---- */
.lbl-stale { display: none; }
body.stale .pill.live { background: var(--line); color: var(--muted); }
body.stale .pill.live::before { content: ""; }
body.stale .pill.live .lbl-live { display: none; }
body.stale .pill.live .lbl-stale { display: inline; }

/* ---- Full-screen stop photo ---- */
.find img { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom);
}
.lightbox img { max-width: 100%; max-height: 85vh; object-fit: contain; border-radius: 6px; }
.lightbox p { color: #cbd5e1; font-size: .85rem; margin: 10px 0 0; }
.lightbox-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; background: rgb(255 255 255 / .15); font-size: 1.1rem; padding: 6px 12px; }
@media (orientation: landscape) { .lightbox img { max-height: 92vh; } .lightbox p { display: none; } }
