  /* ---------------------------------------------------------------------
     "Ticket board": one dark instrument band (wordmark, view switch)
     instead of three stacked bars, and a plain paper manifest below it.
     Signage numerals (mono, tabular) carry the facts — times, track
     numbers, train numbers; a plain system sans carries the words —
     station names, status. Amber is reserved for "live"/predicted
     signals only; green carries "nothing to see here"; red is reserved
     for delay/cancel and is the one place this page raises its voice.
     Rows are divided by hairlines and whitespace, like a printed
     manifest, not boxed cards.
     ------------------------------------------------------------------- */
  /* Catppuccin (https://catppuccin.com, MIT): Latte for light, Mocha for
     dark. Surfaces, text and accents are the palette's own values. Two
     exceptions, both for contrast:
       - Latte's green, yellow and teal are only 2.3-3.3:1 on Base, so where
         they're used as *text* (the -text tokens) they're blended toward
         Crust just enough to reach 4.6:1. As fills and bars they're exact.
       - The instrument band (top bar, desktop footer) stays dark in both
         themes, using Mocha's Base/Mantle, since Latte has no dark surface.
     The train-line chips use the Catppuccin accent nearest each line's NJ
     TRANSIT map colour (see LINE_COLORS). */
  :root {
    color-scheme: light;
    --page: #dce0e8;     /* Latte Crust */
    --paper: #eff1f5;    /* Latte Base */
    --text: #4c4f69;     /* Latte Text */
    --muted: #5c5f77;    /* Latte Subtext 1 (Subtext 0 is under 4.5:1) */
    --rule: rgba(76, 79, 105, .16);
    --ink: #4c4f69;      /* solid fill: confirmed track, legend, tally bar */
    --on-ink: #eff1f5;
    --band: #1e1e2e;     /* Mocha Base */
    --band-fg: #cdd6f4;  /* Mocha Text */
    --band-line: rgba(205, 214, 244, .28);
    --band-hover: rgba(205, 214, 244, .14);
    --muted-ink: rgba(205, 214, 244, .66);
    --amber-ink: #94e2d5; /* Mocha Teal, wordmark accent on the band */
    --amber: #179299;    /* Latte Teal: live/predicted accent fill */
    --amber-text: #167880;
    --ok: #347b27;       /* Latte Green, text shade */
    --warn: #df8e1d;     /* Latte Yellow: delay fill + row flag */
    --warn-text: #95611c;
    --bad: #d20f39;      /* Latte Red */
    --on-bad: #eff1f5;
    --on-fill: #11111b;  /* text on the yellow/teal fills */
    --hover: rgba(76, 79, 105, .05);
    --shadow: rgba(76, 79, 105, .2);
    --shadow-pop: rgba(76, 79, 105, .32);
    --scrim: rgba(17, 17, 27, .5);
    --tint-bad: rgba(210, 15, 57, .07);
    --tint-adv: rgba(23, 146, 153, .09);
    --acc-blue: #1d62ea; /* Latte Blue */
    --mono: ui-monospace, "SF Mono", "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  }
  /* Mocha. Listed twice: OS dark with no stored choice, and an explicit
     dark choice. Every Mocha colour clears 7:1 on Base except Subtext 0
     (muted text), at 7.4:1. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --page: #11111b; --paper: #1e1e2e; --text: #cdd6f4; --muted: #a6adc8;
      --rule: rgba(205, 214, 244, .12);
      --ink: #cdd6f4; --on-ink: #11111b;
      --band: #313244; --band-fg: #cdd6f4; /* Surface 0 */
      --amber: #94e2d5; --amber-text: #94e2d5;
      --ok: #a6e3a1; --warn: #f9e2af; --warn-text: #f9e2af;
      --bad: #f38ba8; --on-bad: #11111b; --on-fill: #11111b;
      --hover: rgba(205, 214, 244, .045); --shadow: rgba(0, 0, 0, .45);
      --shadow-pop: rgba(0, 0, 0, .6); --scrim: rgba(0, 0, 0, .65);
      --tint-bad: rgba(243, 139, 168, .12); --tint-adv: #33414c; /* solid: Mocha Teal at 18% over Base */
      --acc-blue: #89b4fa;
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --page: #11111b; --paper: #1e1e2e; --text: #cdd6f4; --muted: #a6adc8;
    --rule: rgba(205, 214, 244, .12);
    --ink: #cdd6f4; --on-ink: #11111b;
    --band: #313244; --band-fg: #cdd6f4; /* Surface 0 */
    --amber: #94e2d5; --amber-text: #94e2d5;
    --ok: #a6e3a1; --warn: #f9e2af; --warn-text: #f9e2af;
    --bad: #f38ba8; --on-bad: #11111b; --on-fill: #11111b;
    --hover: rgba(205, 214, 244, .045); --shadow: rgba(0, 0, 0, .45);
    --shadow-pop: rgba(0, 0, 0, .6); --scrim: rgba(0, 0, 0, .65);
    --tint-bad: rgba(243, 139, 168, .12); --tint-adv: #33414c; /* solid: Mocha Teal at 18% over Base */
    --acc-blue: #89b4fa;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; }
  body {
    background: var(--page); color: var(--text); font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
  }
  img, svg { display: block; }

  .footer {
    padding: 28px 18px 48px;
    font-size: 12px; line-height: 1.6; color: var(--muted);
  }
  .footer-inner { max-width: 480px; margin: 0 auto; }
  .footer p { margin: 0 0 10px; }
  .footer p:last-child { margin-bottom: 0; }

  /* -------------------------------------------------- instrument band */
  .fascia {
    /* no margin-top here: on mobile the fascia should sit flush at the very
       top of the screen (it's sticky — a top margin would leave a gap
       before it too). The desktop media query below re-adds one, since
       there it's intentional: part of the floating-card look paired with
       .board's rounded bottom corners + shadow. */
    position: sticky; top: 0; z-index: 5;
    background: var(--band); color: var(--band-fg);
    padding: 12px 18px;
  }
  .fascia-inner { display: flex; align-items: center; gap: 12px; }
  @media (min-width: 481px) { .fascia { margin-top: 18px; border-radius: 14px 14px 0 0; } }
  .mark {
    font-family: var(--mono); font-weight: 700; font-size: 14px;
    letter-spacing: .06em; white-space: nowrap;
  }
  .mark b { color: var(--amber-ink); }
  a.mark { color: inherit; text-decoration: none; border-radius: 4px; }
  a.mark:focus-visible { outline: 2px solid var(--amber-ink); outline-offset: 3px; }

  /* view switcher — a single trigger + dropdown, not a segmented row that
     keeps growing as views are added. Scales to any number of pages. */
  .nav { margin-left: auto; position: relative; }
  .nav-btn {
    display: inline-flex; align-items: center; gap: 6px;
    appearance: none; border: 1px solid var(--band-line);
    background: var(--band-hover); color: var(--band-fg);
    font: inherit; font-family: var(--sans); font-size: 12.5px; font-weight: 600;
    padding: 6px 10px; border-radius: 8px; cursor: pointer;
  }
  .nav-btn:hover { background: rgba(205, 214, 244, .22); border-color: rgba(205, 214, 244, .45); }
  .nav-btn .chev { width: 13px; height: 13px; flex: none; transition: transform .15s ease; }
  .nav-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
  .nav-scrim { position: fixed; inset: 0; z-index: 6; background: transparent; }
  .nav-scrim[hidden] { display: none; }
  .nav-menu {
    position: absolute; top: calc(100% + 8px); z-index: 7;
    min-width: 190px; padding: 6px; background: var(--paper); color: var(--text);
    border-radius: 10px; box-shadow: 0 14px 34px var(--shadow-pop);
  }
  #navMenu { right: 0; }
  .nav-menu[hidden] { display: none; }
  .nav-item {
    display: flex; align-items: center; gap: 8px; width: 100%;
    appearance: none; border: 0; background: transparent; color: inherit;
    font: inherit; font-family: var(--sans); font-size: 13.5px; text-align: left;
    padding: 9px 10px; border-radius: 7px; cursor: pointer; text-decoration: none;
    margin-bottom: 3px;
  }
  .nav-item:last-child { margin-bottom: 0; }
  .nav-item[aria-current="true"] { font-weight: 700; background: var(--rule); }
  .nav-item:hover { background: var(--rule); }

  /* theme picker: light / dark / auto as a compact icon-only segmented
     control on the band, so it fits beside the view menu even on a phone.
     Sits before .nav and takes over its push-right margin. */
  .themesw {
    margin-left: auto; display: inline-flex; flex: none;
    border: 1px solid var(--band-line); border-radius: 8px; overflow: hidden;
  }
  .themesw + .nav { margin-left: 0; }
  .themesw button {
    appearance: none; border: 0; background: transparent; color: var(--muted-ink);
    width: 32px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 0;
  }
  .themesw button + button { border-left: 1px solid var(--band-line); }
  .themesw button:hover { color: var(--band-fg); background: var(--band-hover); }
  .themesw button[aria-pressed="true"] { color: var(--band); background: var(--band-fg); }
  .themesw button:focus-visible, .nav-btn:focus-visible {
    outline: 2px solid var(--amber-ink); outline-offset: -2px;
  }
  .themesw svg { width: 15px; height: 15px; }
  @media (max-width: 359px) { .themesw button { width: 27px; } .fascia-inner { gap: 8px; } }
  /* shadows barely show on Mocha's near-black page, so give the floating
     desktop cards a faint edge as well */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .fascia, :root:not([data-theme="light"]) .board { outline: 1px solid rgba(205, 214, 244, .08); }
  }
  :root[data-theme="dark"] .fascia, :root[data-theme="dark"] .board { outline: 1px solid rgba(205, 214, 244, .08); }

  /* -------------------------------------------------- manifest surface */
  .board {
    max-width: 480px; margin: 0 auto; background: var(--paper);
  }
  @media (min-width: 481px) {
    .board { border-radius: 0 0 14px 14px; box-shadow: 0 16px 40px var(--shadow); overflow: hidden; }
  }
  /* -------------------------------------------------- tablet landscape / desktop
     Below this, the board is a phone-width card floating on the page. Above
     it, the fascia and board both widen into matching floating cards and the
     board claims most of the viewport instead of staying phone-width. The
     view-switch dropdown stays put in the fascia at every width (#navBtn/
     #navMenu). Nothing here changes what's rendered — same #depRows/#trkList
     markup, same JS — only the container sizing. */
  @media (min-width: 880px) {
    .fascia {
      padding: 18px 28px; max-width: 1120px; margin: 24px auto 0;
      /* shorter than the cards' shadow: it must end inside the 24px gap,
         or it falls across the top of .board (the advisory bar sits there)
         and reads as a gradient, most visibly in dark mode */
      border-radius: 14px; box-shadow: 0 6px 16px var(--shadow);
      /* not sticky on desktop: the band scrolls away with the page. Still
         positioned (relative + its z-index) so the view menu drops over .board. */
      position: relative;
    }
    .mark { font-size: 20px; }
    .board {
      max-width: 1120px; margin-top: 24px; border-radius: 14px;
      box-shadow: 0 16px 40px var(--shadow); overflow: hidden;
    }
    .footer {
      background: var(--band); color: var(--muted-ink); padding: 32px 28px 56px;
      max-width: 1120px; margin: 24px auto; border-radius: 14px;
      box-shadow: 0 16px 40px var(--shadow);
    }
    /* the phone-width 480px column looked like a narrow strip inside the
       1120px card; use the card's full width, inset to match the top bar's
       28px so the text lines up under the wordmark */
    .footer-inner { max-width: none; }
    /* .board clips to its rounded corners (overflow: hidden, above), which
       also clips the line-filter dropdown if the tracker's own row list is
       short enough that .board's height ends before the dropdown's bottom
       edge would. A floor on the section's height keeps the dropdown's max
       possible reach inside .board's box no matter how few rows are showing. */
    #view-trk { min-height: 480px; }
    /* the legend bar matches the column-label bar directly below it. The
       labels' line-height is pinned (otherwise it follows whichever mono
       font the platform picks) so both come to 9 + 16 + 7 + 1px border =
       33px; mobile keeps the shorter, unpinned rows above. */
    #depTable > .cols > span, #trkTable > .cols > span { line-height: 16px; }
    .key { padding: 0 18px; min-height: 33px; }
  }

  /* -------------------------------------------------- messages / advisories */
  .msg {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 11px 18px; font-size: 12.5px; color: var(--text);
    border-bottom: 1px solid var(--rule);
  }
  .msg.alert { background: var(--tint-bad); }
  .msg.advisory { background: var(--tint-adv); }
  .msg .ico { flex: none; font-weight: 700; font-style: normal; width: 14px; text-align: center; }
  .msg.alert .ico { color: var(--bad); }
  .msg.advisory .ico { color: var(--amber-text); }
  .msg .msg-body { flex: 1; min-width: 0; }
  .msg-link { margin-left: 6px; color: inherit; text-decoration: underline; white-space: nowrap; }
  .msg-close {
    appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
    padding: 3px; flex: none; border-radius: 5px; margin: -3px;
  }
  .msg-close:hover { background: var(--rule); }
  .msg-close svg { width: 14px; height: 14px; display: block; }
  .adv-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 18px; font-size: 12.5px; font-weight: 600; color: var(--text);
    background: var(--tint-adv);
    border-bottom: 1px solid var(--rule); cursor: pointer;
  }
  .adv-toggle .care { display: inline-block; margin-right: 6px; transition: transform .15s; font-weight: 400; }
  .adv-toggle.open .care { transform: rotate(90deg); }

  /* printed column labels — no band of their own, just type on the paper.
     Shared markup with the tracker's header (below); the tracker's own
     rows use container-level padding so this default (container padding,
     its own independent grid) matches them. Departures overrides this —
     see #depTable — because its rows use a different, cell-level padding
     model where this wouldn't line up (see the long comment down there). */
  .cols {
    display: grid; grid-template-columns: 64px 1fr 70px;
    gap: 10px; padding: 9px 18px 7px;
    font-family: var(--mono); font-size: 10px; font-weight: 700;
    letter-spacing: .1em; color: var(--muted); text-transform: uppercase;
    border-bottom: 1px solid var(--rule);
  }
  .cols > span:first-child { text-align: center; }
  .cols .c3 { text-align: center; }

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

  /* -------------------------------------------------- departure rows */
  /* #depTable is the ONE real grid for the *entire* departures view —
     header included. A header with its own fixed-guess column width will
     never quite line up with a data column that's dynamically auto-sized
     (status text ranges from "On time" to a filled "Cancelled" badge), no
     matter how carefully the guess is tuned — their two boxes just don't
     share a width. Folding the header into the same grid as the rows
     removes the guessing entirely: one grid, one computed column width,
     used by the label and every row's content alike. .cols and #depRows
     are both `display: contents` so their children — 3 header cells, then
     each row's time/mid/end (+ detail panel) — flatten into #depTable's
     columns directly; auto-placement naturally puts the header on row 1
     since it's first in the DOM. */
  #depTable { display: grid; grid-template-columns: auto 1fr auto; align-items: stretch; }
  #depTable > .cols { display: contents; }
  #depTable > .cols > span { padding: 9px 0 7px; border-bottom: 1px solid var(--rule); }
  #depTable > .cols > span:first-child { padding-left: 18px; text-align: center; }
  /* matches .mid's own padding-left (10px) — without it "Train" starts
     right at the column edge, 10px left of where the destination text
     (which carries that inset itself) actually begins. */
  #depTable > .cols > span:nth-child(2) { padding-left: 10px; }
  #depTable > .cols > .c3 { padding-right: 18px; text-align: center; }
  #depRows { display: contents; }
  .dep { display: contents; cursor: pointer; }
  .dep > .time, .dep > .mid, .dep > .stat, .dep > .end { padding: 13px 0; }
  .dep > .time { padding-left: 18px; }
  .dep > .mid { padding-left: 10px; padding-right: 10px; }
  .dep > .end { padding-right: 18px; }
  /* the row divider belongs after the *whole* train's block — on the three
     cells when collapsed, but pushed onto the detail panel instead when
     open, since that panel renders as its own grid row right underneath */
  .dep:not(.open) > .time, .dep:not(.open) > .mid, .dep:not(.open) > .stat, .dep:not(.open) > .end { border-bottom: 1px solid var(--rule); }
  .dep:last-child > .time, .dep:last-child > .mid, .dep:last-child > .stat, .dep:last-child > .end { border-bottom: 0; }
  .dep.open .dep-detail { border-bottom: 1px solid var(--rule); background: var(--hover); }
  .dep.open:last-child .dep-detail { border-bottom: 0; }
  .dep:hover > .time, .dep:hover > .mid, .dep:hover > .stat, .dep:hover > .end,
  .dep.open > .time, .dep.open > .mid, .dep.open > .stat, .dep.open > .end { background: var(--hover); }
  .dep.flag-delay > .time { box-shadow: inset 4px 0 0 var(--warn); }
  .dep.flag-cancel > .time { box-shadow: inset 4px 0 0 var(--bad); }
  .dep .time {
    /* flex column + justify-content:center: the cell's own box is stretched
       to the full row height (see #depRows), but block content inside it
       would otherwise just sit at the top; this centers it vertically
       instead, same as .mid below. */
    display: flex; flex-direction: column; justify-content: center;
    font-family: var(--mono); font-weight: 700; font-size: 17px;
    font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap;
  }
  .dep .time s { color: var(--muted); font-weight: 600; font-size: 14px; text-decoration-color: var(--muted); }
  .dep .time .sub {
    display: block; font-family: var(--sans); font-size: 11px; font-weight: 500;
    color: var(--muted); margin-top: 2px;
  }
  .dep .time .sub.pushed { color: var(--warn-text); }
  .dep .mid { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
  .dep .mid .dest { font-size: 15.5px; font-weight: 600; line-height: 1.25; }
  .dep .mid .dest.cancelled { text-decoration: line-through; color: var(--muted); }
  .dep .mid .line {
    margin-top: 3px; display: flex; align-items: center; gap: 6px;
    font-family: var(--mono); font-size: 12px; color: var(--muted);
  }
  /* train-line colours: each line gets the Catppuccin accent closest to its
     colour on NJ TRANSIT's own rail map, no two lines sharing one — Latte
     (--lb/--lf) in light mode, Mocha (--lbd/--lfd) in dark. Catppuccin has
     no brown or sage, so Montclair-Boonton uses Rosewater (Latte's is a clay
     tan) and Port Jervis uses Sky, the nearest accent left once Green and
     Teal went to Bergen County and Main Line. Chip text is whichever of
     Latte Base / Crust reads better (all >= 4.6:1); on Mocha's pastels it's
     always Crust. Latte Blue is nudged 5% darker to clear 4.5:1. */
  .ln-nec   { --lb: #d20f39; --lf: #eff1f5; --lbd: #f38ba8; --lfd: #11111b; } /* Red */
  .ln-me    { --lb: #1d62ea; --lf: #eff1f5; --lbd: #89b4fa; --lfd: #11111b; } /* Morristown Line: Blue */
  .ln-glad  { --lb: #8839ef; --lf: #eff1f5; --lbd: #cba6f7; --lfd: #11111b; } /* Gladstone Branch: Mauve */
  .ln-njcl  { --lb: #209fb5; --lf: #11111b; --lbd: #74c7ec; --lfd: #11111b; } /* Sapphire */
  .ln-mobo  { --lb: #dc8a78; --lf: #11111b; --lbd: #f5e0dc; --lfd: #11111b; } /* Rosewater */
  .ln-rarv  { --lb: #df8e1d; --lf: #11111b; --lbd: #f9e2af; --lfd: #11111b; } /* Yellow */
  .ln-berg  { --lb: #40a02b; --lf: #11111b; --lbd: #a6e3a1; --lfd: #11111b; } /* Green */
  .ln-main  { --lb: #179299; --lf: #11111b; --lbd: #94e2d5; --lfd: #11111b; } /* Teal */
  .ln-pasc  { --lb: #ea76cb; --lf: #11111b; --lbd: #f5c2e7; --lfd: #11111b; } /* Pink */
  .ln-atlc  { --lb: #fe640b; --lf: #11111b; --lbd: #fab387; --lfd: #11111b; } /* Peach */
  .ln-pj    { --lb: #04a5e5; --lf: #11111b; --lbd: #89dceb; --lfd: #11111b; } /* Sky */
  .ln-other { --lb: #7c7f93; --lf: #11111b; --lbd: #9399b2; --lfd: #11111b; } /* Overlay 2 */
  .ln-none { --lb: var(--muted); --lbd: var(--muted); }
  .chip, .linef-sw { background: var(--lb); color: var(--lf); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .chip, :root:not([data-theme="light"]) .linef-sw { background: var(--lbd, var(--lb)); color: var(--lfd, var(--lf)); }
  }
  :root[data-theme="dark"] .chip, :root[data-theme="dark"] .linef-sw { background: var(--lbd, var(--lb)); color: var(--lfd, var(--lf)); }
  .chip {
    display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 4px;
    font-family: var(--sans); font-size: 10px; font-weight: 700; letter-spacing: .02em;
  }
  /* flex column, not just text-align:right: a column direction always
     stacks its items regardless of how much horizontal room the auto-sized
     cell has, while each item (track pill, status) still hugs its own
     content width rather than stretching full-width like a block would. */
  .dep .end { display: flex; flex-direction: column; align-items: center; }
  .dep .end.end-single { justify-content: center; }
  /* desktop-only pieces (see the 880px block): a Status column of its own,
     and a text label under the track saying what kind of track it is */
  #depTable > .cols > .c-stat, .dep > .stat, .track-kind { display: none; }
  /* after the base rules on purpose, so these win over the hiding above
     (the main 880px block sits earlier in the file) */
  @media (min-width: 880px) {
    /* status moves out from under the track into its own column, left of
       it; under the track, a label spells out what the box style means */
    #depTable { grid-template-columns: auto 1fr auto auto; }
    #depTable > .cols > .c-stat { display: block; text-align: center; padding-right: 22px; }
    .dep > .stat {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      padding-right: 22px;
    }
    .dep > .stat .state { margin-top: 0; }
    .dep > .end { justify-content: center; }
    .dep > .end > .state { display: none; }
    .track-kind {
      display: block; margin-top: 5px; font-size: 11px; font-weight: 600;
      color: var(--muted); white-space: nowrap;
    }
  }
  .track {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 30px; padding: 0 8px; border-radius: 7px;
    font-family: var(--mono); font-weight: 800; font-size: 16px;
    font-variant-numeric: tabular-nums;
  }
  .track.confirmed { background: var(--ink); color: var(--on-ink); }
  .track.predicted {
    background: transparent; border: 1.5px dashed var(--ink); color: var(--ink); cursor: help;
  }
  /* predicted, and the train is standing at that track right now: solid
     outline, sitting between the dashed guess and the filled confirmation */
  .track.predicted.ontrack { border-style: solid; }
  .track.tbd { color: var(--muted); font-weight: 600; font-size: 15px; background: none; }
  .state {
    display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700;
    letter-spacing: .01em; white-space: nowrap;
  }
  .state.ok { color: var(--ok); }
  .state.muted { color: var(--muted); font-weight: 600; }
  .state.delay, .state.cancel {
    padding: 3px 9px; border-radius: 6px; font-size: 12.5px; font-weight: 800;
  }
  .state.delay { background: var(--warn); color: var(--on-fill); }
  .state.cancel { background: var(--bad); color: var(--on-bad); }

  /* expand-to-stops panel, shared visual language between both views */
  .dep-detail, .stops {
    grid-column: 1 / -1; margin-top: 10px; padding-top: 10px;
    border-top: 1px dashed var(--rule); display: none;
  }
  /* .dep and .trk are both `display: contents` (no padding box of their
     own, see above), so their detail panels need the row inset spelled out
     explicitly. margin-top is zeroed here too — margin is never painted,
     and with no parent box to paint underneath it, the open-state
     background would stop short of the panel, leaving an unshaded strip
     above it. */
  .dep-detail, .stops { margin-top: 0; padding-left: 18px; padding-right: 18px; padding-bottom: 13px; }
  .dep.open .dep-detail, .trk.open .stops { display: block; }
  .stops-msg { padding: 2px 0; font-size: 12.5px; color: var(--muted); }
  .notice { display: flex; gap: 6px; font-size: 12px; color: var(--bad); margin-bottom: 8px; }
  .notice a { color: inherit; text-decoration: underline; }
  .notice.notice-cancel { background: var(--tint-bad); padding: 8px; border-radius: 6px; }
  .xfer { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
  .history-btn {
    display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
    appearance: none; border: 1px solid var(--rule); background: var(--page); color: var(--text);
    font: inherit; font-family: var(--sans); font-size: 12.5px; font-weight: 600;
    padding: 7px 12px; border-radius: 8px; cursor: pointer;
  }
  .history-btn:hover { background: var(--rule); }
  .history-btn svg { width: 14px; height: 14px; flex: none; }
  .detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
  .detail-actions .history-btn { margin-top: 0; }
  .stop-row {
    /* auto (not a fixed 54px): a plain time can be 8+ characters, and a
       delayed stop shows a struck original *and* the revised time together
       ("6:51 6:58"), both too wide for a guessed fixed column. */
    display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
    /* baseline, not the default stretch: the time column is mono, the name
       column is the body sans face — different font metrics mean their text
       doesn't sit at the same height even when both boxes are top-aligned. */
    align-items: baseline;
    padding: 4px 0; font-size: 12.5px; color: var(--muted);
  }
  .stop-row .st-time { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .stop-row .st-time s { color: var(--muted); }
  .stop-row .st-time b { color: var(--warn-text); font-weight: 700; }
  .stop-row.origin .st-name, .stop-row.dest .st-name { color: var(--text); font-weight: 700; }
  .stop-row.departed { opacity: .55; }
  .st-acc { color: var(--acc-blue); } /* conventional accessibility blue */
  .stop-row .gap { color: var(--warn-text); font-weight: 700; text-align: right; }

  /* -------------------------------------------------- tracker search + filter */
  .trk-search {
    position: relative; display: flex; gap: 8px; align-items: center;
    padding: 10px 18px; border-bottom: 1px solid var(--rule);
  }
  .search-box {
    flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0;
    background: var(--page); border: 1px solid var(--rule); border-radius: 8px;
    padding: 0 10px; height: 34px;
  }
  .search-box input {
    flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
    font: inherit; font-family: var(--sans); font-size: 13.5px; color: var(--text);
  }
  .search-box input::placeholder { color: var(--muted); }
  /* suppress the browser's own native clear button — we already render a
     custom one (#trkClear) styled to match, so without this a search input
     with text in it shows two X's */
  .search-box input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
  .search-box button {
    appearance: none; border: 0; background: transparent; color: var(--muted);
    font-size: 16px; line-height: 1; cursor: pointer; padding: 2px; border-radius: 4px;
  }
  .search-box button:hover { color: var(--text); }
  .linef-btn {
    flex: none; display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--rule);
    background: var(--page); color: var(--muted); cursor: pointer;
  }
  .linef-btn.active { background: var(--amber); border-color: var(--amber); color: var(--on-fill); }
  .linef-btn svg { width: 16px; height: 16px; }
  .linef-scrim { position: fixed; inset: 0; z-index: 6; background: transparent; }
  .linef-scrim[hidden] { display: none; }
  .linef-menu {
    position: absolute; z-index: 7; top: 100%; margin-top: 6px; right: 18px;
    min-width: 170px; padding: 6px; background: var(--paper); color: var(--text);
    border-radius: 10px; box-shadow: 0 14px 34px var(--shadow-pop);
  }
  .linef-menu[hidden] { display: none; }
  .linef-opt { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; font-size: 13px; cursor: pointer; }
  .linef-opt:hover { background: var(--rule); }
  .linef-sw { width: 16px; height: 11px; border-radius: 3px; flex: none; }
  .linef-clear {
    width: 100%; text-align: left; padding: 8px; margin-top: 2px; border: 0;
    background: transparent; color: var(--bad); font: inherit; font-size: 12.5px;
    cursor: pointer; border-radius: 7px;
  }
  .linef-clear:hover { background: var(--rule); }
  .linef-empty { padding: 8px; font-size: 12.5px; color: var(--muted); }

  /* -------------------------------------------------- tracker rows */
  /* #trkTable folds the header AND every row into ONE real grid, same
     reasoning as #depTable above: a header with its own fixed-guess column
     width never quite lines up with a dynamically-sized status column (it
     ranges from "On time" to a filled "7 min late" badge) — the two boxes
     just don't share a width no matter how the guess is tuned. One grid,
     one computed column, used by the label and every row alike removes the
     guessing entirely. .cols and .trk are both `display: contents` so
     their cells flatten directly into #trkTable's columns; the detail
     panel spans all three via grid-column: 1 / -1, same as departures. */
  #trkTable { display: grid; grid-template-columns: auto 1fr auto; align-items: stretch; }
  #trkTable > .cols { display: contents; }
  #trkTable > .cols > span { padding: 9px 0 7px; border-bottom: 1px solid var(--rule); }
  #trkTable > .cols > span:first-child { padding-left: 18px; text-align: center; }
  #trkTable > .cols > span:nth-child(2) { padding-left: 10px; }
  #trkTable > .cols > .c3 { padding-right: 18px; text-align: center; }
  #trkList { display: contents; }
  /* placeholder for a pinned train (#tracker/<id>) that isn't reporting a
     position yet: same columns as a live row, plus a note across the row */
  .trk.trk-pending { cursor: default; }
  .trk.trk-pending:hover > .dep-time, .trk.trk-pending:hover > .trk-mid, .trk.trk-pending:hover > .trk-end { background: transparent; }
  .trk.trk-pending > .dep-time, .trk.trk-pending > .trk-mid, .trk.trk-pending > .trk-end { border-bottom: 0; padding-bottom: 6px; }
  .trk-note {
    grid-column: 1 / -1; padding: 0 18px 16px; font-size: 12.5px; line-height: 1.5; color: var(--muted);
  }

  .trk { display: contents; cursor: pointer; }
  .trk > .dep-time, .trk > .trk-mid, .trk > .trk-end { padding: 13px 0; }
  .trk > .dep-time { padding-left: 18px; }
  .trk > .trk-mid { padding-left: 10px; padding-right: 10px; }
  .trk > .trk-end { padding-right: 18px; }
  .trk:not(.open) > .dep-time, .trk:not(.open) > .trk-mid, .trk:not(.open) > .trk-end { border-bottom: 1px solid var(--rule); }
  .trk:last-child > .dep-time, .trk:last-child > .trk-mid, .trk:last-child > .trk-end { border-bottom: 0; }
  .trk.open .stops { border-bottom: 1px solid var(--rule); background: var(--hover); }
  .trk.open:last-child .stops { border-bottom: 0; }
  .trk:hover > .dep-time, .trk:hover > .trk-mid, .trk:hover > .trk-end,
  .trk.open > .dep-time, .trk.open > .trk-mid, .trk.open > .trk-end { background: var(--hover); }
  .trk.flag > .dep-time { box-shadow: inset 4px 0 0 var(--warn); }

  .dep-time {
    display: flex; flex-direction: column; justify-content: center;
    font-family: var(--mono); font-weight: 700; font-size: 15px;
    font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .trk-mid { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
  .trk-dest {
    font-size: 14px; color: var(--text); display: flex; align-items: baseline; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .trk-dest .dst::before { content: "→"; margin: 0 6px; color: var(--muted); }
  .trk-line {
    margin-top: 3px; font-family: var(--mono); font-size: 12.5px; color: var(--muted);
    display: flex; align-items: center; gap: 6px;
  }
  .trk-end { display: flex; flex-direction: column; align-items: center; justify-content: center; }
  .status { font-size: 12.5px; font-weight: 700; text-align: center; white-space: nowrap; }
  .status.on { color: var(--ok); }
  /* yellow, not red — the tracker only ever flags delay here, never a
     cancellation, so red stays reserved for that (departures view only) */
  .status.late { color: var(--on-fill); background: var(--warn); padding: 3px 8px; border-radius: 6px; font-weight: 800; }
  .status.pending { color: var(--muted); font-weight: 400; }

  /* -------------------------------------------------- key / legend */
  /* sits in the same slot the tracker's search bar occupies — top of its
     own view — rather than floating below the board as a separate block.
     On mobile it's just its own compact row; the 880px breakpoint below
     pads it out to match .trk-search's 54px total height instead, since
     there the two views' headers sit in comparable desktop chrome. */
  .key {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 18px;
    padding: 7px 18px; border-bottom: 1px solid var(--rule);
    font-size: 11.5px; color: var(--muted);
  }
  .key span { display: inline-flex; align-items: center; gap: 6px; }
  .key .sw { width: 20px; height: 13px; border-radius: 4px; flex: none; }
  .sw.confirmed { background: var(--ink); }
  .sw.predicted { background: transparent; border: 1.5px dashed var(--ink); }
  .sw.ontrack { background: transparent; border: 1.5px solid var(--ink); }

  /* -------------------------------------------------- per-train history modal */
  .history-scrim {
    position: fixed; inset: 0; z-index: 8; background: var(--scrim);
    display: flex; align-items: center; justify-content: center; padding: 20px;
  }
  .history-scrim[hidden] { display: none; }
  .history-modal {
    width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto;
    background: var(--paper); color: var(--text); border-radius: 14px;
    box-shadow: 0 16px 40px var(--shadow-pop);
  }
  .history-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 16px; border-bottom: 1px solid var(--rule);
    position: sticky; top: 0; background: var(--paper);
  }
  .history-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
  .history-body { padding: 14px 16px; }
  .hist-section-label {
    font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; color: var(--muted); margin: 18px 0 8px;
  }
  .hist-section-label:first-child { margin-top: 0; }
  .hist-tally-row, .hist-day-row {
    display: flex; align-items: center; gap: 10px; padding: 6px 0;
    border-bottom: 1px solid var(--rule);
  }
  .hist-tally-row:last-child, .hist-day-row:last-child { border-bottom: 0; }
  .hist-tally-bar { flex: 1; height: 6px; background: var(--rule); border-radius: 3px; overflow: hidden; }
  .hist-tally-bar span { display: block; height: 100%; background: var(--ink); }
  .hist-tally-n { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .hist-day-row { justify-content: space-between; }
  .hist-day-date { font-size: 13px; color: var(--text); }
  .hist-day-track {
    font-family: var(--mono); font-weight: 800; font-size: 16px;
    font-variant-numeric: tabular-nums; color: var(--ink);
  }

  section[hidden] { display: none; }
