/* Dark-first, phone-first. Sized for reading at arm's length on a platform. */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-sunken: #010409;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --text-dim: #9198a1;
  --text-faint: #6e7681;

  --accent: #58a6ff;
  --caltrain: #e31837;
  --muni: #d4462d;

  --early: #79c0ff;
  --ontime: #3fb950;
  --late: #d29922;
  --verylate: #f85149;
  --unknown: #6e7681;

  --radius: 12px;
  --gap: 12px;
  --tap: 44px;   /* minimum comfortable touch target */
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --bg-raised: #f6f8fa;
    --bg-sunken: #eaeef2;
    --border: #d0d7de;
    --border-soft: #e4e8ed;
    --text: #1f2328;
    --text-dim: #59636e;
    --text-faint: #818b98;
    --accent: #0969da;
    --early: #0969da;
    --ontime: #1a7f37;
    --late: #9a6700;
    --verylate: #cf222e;
    --unknown: #818b98;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }

.wrap {
  max-width: 720px; margin: 0 auto;
  padding: 0 12px calc(48px + env(safe-area-inset-bottom));
}
.wrap:focus { outline: none; }   /* focused only as a skip-link target */

/* Visible keyboard focus everywhere. :focus-visible keeps it off mouse taps. */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- skip link ---------- */
.skip {
  position: absolute; left: 8px; top: -60px; z-index: 1200;
  background: var(--accent); color: #fff; padding: 12px 18px;
  border-radius: 0 0 var(--radius) var(--radius); font-weight: 600;
  transition: top .12s ease;
}
.skip:focus { top: 0; }

/* ---------- nav (inside the sticky header) ---------- */
.nav {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg-raised);
  border-top: 1px solid var(--border-soft);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; min-height: 52px; padding: 7px 4px;
  color: var(--text-dim); text-align: center;
  /* Reserved so the active underline adds no layout shift. Underline rather
     than overline: sitting below the label, it reads as a tab. */
  border-bottom: 3px solid transparent;
}
.nav .l1 { font-size: 13px; font-weight: 600; line-height: 1.2; }
/* --text-faint would be prettier here but lands at 3.8:1 against the nav
   background; at 11px this is normal-size text and needs 4.5:1. */
.nav .l2 { font-size: 11px; color: var(--text-dim); line-height: 1.2; }
.nav a:active { background: var(--bg-sunken); }

/* Active state carries three cues -- colour, weight and the top bar -- so it
   survives greyscale, high-contrast mode and colour-blind vision. */
.nav a[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.nav a[aria-current="page"] .l1 { font-weight: 700; }
.nav a[aria-current="page"] .l2 { color: var(--accent); }
.nav a:focus-visible { outline-offset: -3px; }

@media (min-width: 480px) {
  .nav .l1 { font-size: 14px; }
  .nav .l2 { font-size: 12px; }
}

@media (prefers-contrast: more) {
  .nav a[aria-current="page"] { outline: 2px solid var(--accent); outline-offset: -2px; }
}

@media (prefers-reduced-motion: reduce) {
  .skip { transition: none; }
  * { scroll-behavior: auto !important; }
}

/* ---------- header ---------- */
/* Nav + freshness strip stick together as one block. Sticking them
   individually would mean hand-maintaining a `top:` offset per element that
   breaks the moment one of them changes height.
   z-index sits above Leaflet's control layer (1000) so a map never draws
   over the nav while scrolling. */
.header {
  position: sticky; top: 0; z-index: 1100;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

/* The page title now scrolls with the content. */
.pagetitle {
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em;
  margin: 16px 2px 0;
}
.pagetitle .sub {
  display: block; font-size: 13px; color: var(--text-dim); font-weight: 400;
  margin-top: 2px;
}

/* ---------- freshness strip ---------- */
.fresh {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-dim);
  padding: 6px 12px; background: var(--bg-sunken);
  border-top: 1px solid var(--border-soft);
}
.fresh .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ontime); flex: none; }
.fresh.is-stale .dot { background: var(--late); }
.fresh.is-dead .dot { background: var(--verylate); }
.fresh button {
  margin-left: auto; background: none; border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 999px; padding: 4px 12px;
  font-size: 12px; min-height: 30px;
}
.fresh button:active { background: var(--bg-raised); }

/* ---------- cards ---------- */
.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-top: var(--gap);
}
.card.flush { padding: 0; overflow: hidden; }
.card h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: 0 0 10px; font-weight: 600;
}

/* ---------- mode buttons ---------- */
.modes { display: grid; gap: var(--gap); margin-top: 16px; }
.mode {
  display: block; padding: 20px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--text);
}
.mode:active { background: var(--bg-sunken); }
.mode .badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff; margin-bottom: 8px;
}
.mode .badge.ct { background: var(--caltrain); }
.mode .badge.mu { background: var(--muni); }
.mode strong { display: block; font-size: 19px; margin-bottom: 3px; letter-spacing: -0.01em; }
.mode span.desc { color: var(--text-dim); font-size: 14px; }

/* ---------- train number entry ---------- */
.numform { display: flex; gap: 8px; margin-top: 4px; }
.numform input {
  /* min-width:0 lets the input actually shrink; without it the intrinsic
     size of a text input keeps the submit button pushed off screen. */
  flex: 1; min-width: 0; width: 100%;
  font-size: 26px; padding: 12px 14px; min-height: 56px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: .06em;
}
.numform input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.numform button {
  background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
  padding: 0 22px; font-size: 16px; font-weight: 600; min-height: 56px;
}

/* ---------- headline status ---------- */
.headline { text-align: center; padding: 8px 0 4px; }
.headline .num {
  font-size: 46px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.headline .route {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; margin-top: 8px;
}
.headline .where { color: var(--text-dim); font-size: 14px; margin-top: 8px; }
.headline .delay { font-size: 21px; font-weight: 700; margin-top: 10px; }

.early    { color: var(--early); }
.ontime   { color: var(--ontime); }
.late     { color: var(--late); }
.verylate { color: var(--verylate); }
.unknown  { color: var(--unknown); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.pill.early    { border-color: var(--early); }
.pill.ontime   { border-color: var(--ontime); }
.pill.late     { border-color: var(--late); }
.pill.verylate { border-color: var(--verylate); }

/* ---------- stat grid ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 1px;
         background: var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.stats div { background: var(--bg-raised); padding: 10px 12px; }
.stats dt { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.stats dd { margin: 3px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- stop strip ---------- */
.strip { list-style: none; margin: 0; padding: 0; }
.strip li {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px;
  align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--border-soft);
  position: relative;
}
.strip li:last-child { border-bottom: 0; }
.strip .marker { display: flex; justify-content: center; position: relative; height: 100%; }
.strip .marker::before {   /* the line down the middle */
  content: ""; position: absolute; top: -11px; bottom: -11px; width: 2px;
  background: var(--border); left: 50%; transform: translateX(-50%);
}
.strip li:first-child .marker::before { top: 50%; }
.strip li:last-child  .marker::before { bottom: 50%; }
.strip .dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--bg);
  border: 2px solid var(--border); position: relative; z-index: 1;
}
.strip li.passed { opacity: .45; }
.strip li.passed .dot { background: var(--border); }
.strip li.next .dot { background: var(--accent); border-color: var(--accent);
                      box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.strip li.skipped .name { text-decoration: line-through; color: var(--text-faint); }
.strip .name { font-size: 15px; font-weight: 500; }
.strip .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.strip .times { text-align: right; font-variant-numeric: tabular-nums; }
.strip .times .big { font-size: 15px; font-weight: 600; }
.strip .times .small { font-size: 11px; color: var(--text-dim); }
.strip .times .struck { text-decoration: line-through; color: var(--text-faint); }
.strip li.next { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* ---------- vehicle rows ---------- */
.veh { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
.veh:last-child { border-bottom: 0; }
.veh.seg { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.veh .row1 { display: flex; align-items: baseline; gap: 8px; }
.veh .eta { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.veh .car { font-size: 12px; color: var(--text-faint); margin-left: auto; font-variant-numeric: tabular-nums; }
.veh .row2 { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.veh .row3 { font-size: 12px; color: var(--text-faint); margin-top: 4px;
             display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- what the headline number refers to ---------- */
.veh .row-lead { font-size: 13px; margin-top: 5px; color: var(--text-dim); }
.veh .row-lead strong { color: var(--text); font-weight: 600; }
.veh .onboard {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: color-mix(in srgb, var(--ontime) 20%, transparent);
  color: var(--ontime); vertical-align: 1px;
}

/* ---------- per-train segment stop list ---------- */
.segtimes {
  list-style: none; margin: 10px 0 0; padding: 8px 0 0;
  border-top: 1px solid var(--border-soft);
}
.segtimes li {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; padding: 4px 0; font-size: 13px;
}
.segtimes .sname { color: var(--text-dim); }
.segtimes .stime { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.segtimes .stime b { font-size: 14px; }
.segtimes .stime small { color: var(--text-faint); margin-left: 6px; font-size: 11px; }
.segtimes .gone { color: var(--text-faint); font-size: 12px; }
.segtimes li.passed .sname { color: var(--text-faint); text-decoration: line-through; }
.segtimes li.boarding .sname { color: var(--text); font-weight: 600; }
.segtimes .tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent); vertical-align: 1px;
}

/* ---------- arrivals at a stop ---------- */
.stoprow { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
.stoprow:last-child { border-bottom: 0; }
.stoprow .sname { font-size: 14px; font-weight: 600; }
.stoprow .anchor { font-size: 11px; color: var(--accent); text-transform: uppercase;
                   letter-spacing: .05em; font-weight: 700; }
.stoprow .arrivals { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.stoprow .arr {
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 10px; font-size: 13px;
  font-variant-numeric: tabular-nums; min-width: 62px; text-align: center;
}
.stoprow .arr b { display: block; font-size: 16px; }
.stoprow .arr small { color: var(--text-faint); font-size: 10px; }

/* ---------- alerts ---------- */
.alert {
  padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
  border-left: 3px solid var(--late);
}
.alert:last-child { border-bottom: 0; }
.alert .src { font-size: 11px; color: var(--text-faint); text-transform: uppercase;
              letter-spacing: .05em; margin-bottom: 4px; }
.alert .hdr { font-size: 14px; font-weight: 600; }
.alert .body { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

/* ---------- map ---------- */
/* position+z-index gives the map its own stacking context, trapping Leaflet's
   internal z-indexes (panes 400, controls 1000) inside this box. Without it
   those layers are compared against the page's and the map's +/- buttons
   paint straight through the sticky nav. */
#map {
  height: 300px; border-radius: var(--radius); background: var(--bg-sunken);
  position: relative; z-index: 0; isolation: isolate; overflow: hidden;
}
.leaflet-container { background: var(--bg-sunken) !important; font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-raised); color: var(--text);
}
.leaflet-bar a { background: var(--bg-raised) !important; color: var(--text) !important;
                 border-color: var(--border) !important; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--text-dim); padding: 28px 16px; font-size: 14px; }
.note { font-size: 12px; color: var(--text-faint); margin-top: 8px; line-height: 1.5; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums; min-height: 40px; display: flex;
  align-items: center; gap: 6px;
}
.banner {
  padding: 11px 14px; border-radius: var(--radius); font-size: 13px;
  border: 1px solid var(--late); background: color-mix(in srgb, var(--late) 12%, transparent);
  margin-top: var(--gap); line-height: 1.45;
}
.banner.bad { border-color: var(--verylate);
              background: color-mix(in srgb, var(--verylate) 12%, transparent); }
table.src { width: 100%; border-collapse: collapse; font-size: 12px; }
table.src td { padding: 5px 0; border-bottom: 1px solid var(--border-soft); color: var(--text-dim); }
table.src td:last-child { text-align: right; color: var(--text); }
