/* ---------- tokens ---------- */
:root {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --text: #0d1626;
  --muted: #5a667a;
  --faint: #8792a5;
  --line: #e3e7ef;
  --brand: #2f55e6;
  --brand-ink: #ffffff;
  --brand-soft: #e9eeff;
  --ok: #0c8a52;
  --ok-soft: #e0f6ea;
  --warn: #a85a00;
  --warn-soft: #fff1d6;
  --bad: #c7352b;
  --bad-soft: #fde9e7;
  --shadow: 0 1px 2px rgba(13, 22, 38, .05), 0 8px 28px rgba(13, 22, 38, .06);
  --shadow-pop: 0 12px 40px rgba(13, 22, 38, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --rail: #cfd6e2;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #090d15;
  --surface: #111725;
  --surface-2: #171f30;
  --text: #edf1f8;
  --muted: #93a0b5;
  --faint: #6b778c;
  --line: #222b3d;
  --brand: #7c9cff;
  --brand-ink: #0a1020;
  --brand-soft: #1b2748;
  --ok: #3fd391;
  --ok-soft: #12301f;
  --warn: #f6b450;
  --warn-soft: #382a10;
  --bad: #ff8176;
  --bad-soft: #3b1a18;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02) inset;
  --shadow-pop: 0 16px 48px rgba(0, 0, 0, .6);
  --rail: #2c374c;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.num, time, .tnum { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 14px; border-radius: 10px; z-index: 100; }
.skip:focus { left: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.card-head h2, .alert-copy h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.01em; }
.section-title { font-size: .76rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin-bottom: 10px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.top-row { display: flex; align-items: center; gap: 12px; height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.02em; font-size: 1.02rem; flex-shrink: 0; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: #fff; background: linear-gradient(135deg, #3b5bfd, #1a2466); }
.trip-pill {
  margin-left: auto; min-width: 0; display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 12px 0 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: .88rem;
}
.trip-pill .route { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-pill .route span { color: var(--muted); font-weight: 500; }
.trip-pill svg { flex-shrink: 0; color: var(--muted); }
.trip-pill:hover { border-color: var(--brand); }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--faint); }
.trip-pill[hidden] + .icon-btn { margin-left: auto; }

main { display: grid; gap: 18px; padding-top: 22px; padding-bottom: calc(48px + env(safe-area-inset-bottom)); }

/* ---------- landing ---------- */
.landing { text-align: center; padding: 34px 0 6px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.landing h1 { font-size: clamp(2.2rem, 7vw, 3.6rem); line-height: 1.04; letter-spacing: -.045em; font-weight: 800; margin-top: 18px; }
.lede { max-width: 520px; margin: 14px auto 0; color: var(--muted); font-size: 1.05rem; }

/* ---------- search ---------- */
.search { padding: 18px; max-width: 880px; width: 100%; margin: 0 auto; }
#form { display: grid; grid-template-columns: 1.35fr 1fr 1fr auto; gap: 12px; align-items: end; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: .76rem; font-weight: 650; color: var(--muted); letter-spacing: .02em; }
.field input, .field select {
  width: 100%; height: 50px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface-2); padding: 0 14px; min-width: 0; font-weight: 550;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field select { appearance: none; -webkit-appearance: none; padding-right: 36px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238792a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.field select:disabled { color: var(--faint); font-weight: 450; }
.field input::placeholder { color: var(--faint); font-weight: 450; }
.field input:hover, .field select:not(:disabled):hover { border-color: var(--faint); }
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.combo { position: relative; }
.combo input { padding-left: 42px; }
.combo-ico { position: absolute; left: 14px; top: 16px; color: var(--faint); pointer-events: none; }
.suggest {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 8px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-pop);
  padding: 6px; max-height: 340px; overflow: auto;
}
.suggest li { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--surface-2); }
.suggest .s-num { grid-row: span 2; align-self: center; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--brand-soft); color: var(--brand); padding: 4px 8px; border-radius: 8px; font-size: .86rem; }
.suggest .s-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-route { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-empty { display: block; color: var(--muted); cursor: default; }
.suggest .s-empty:hover { background: none; }

.primary {
  position: relative; height: 50px; padding: 0 24px; border: 0; border-radius: var(--radius-sm);
  background: var(--brand); color: var(--brand-ink); font-weight: 650; white-space: nowrap;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 35%, transparent);
  transition: transform .12s, filter .15s;
}
.primary:hover { filter: brightness(1.07); }
.primary:active { transform: translateY(1px); }
.primary:disabled { cursor: progress; }
.primary .spinner { display: none; }
.primary.busy .btn-label { visibility: hidden; }
.primary.busy .spinner { display: block; position: absolute; inset: 0; margin: auto; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { margin-top: 12px; font-size: .88rem; color: var(--muted); }
.hint:empty { display: none; }
.hint.err { color: var(--bad); font-weight: 550; }
.hint b { color: var(--text); font-weight: 650; }

/* ---------- landing extras ---------- */
.extras { display: grid; gap: 26px; max-width: 880px; width: 100%; margin: 6px auto 0; }
.trip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.trip {
  position: relative; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; align-items: center; text-align: left;
  padding: 12px 40px 12px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, transform .15s, box-shadow .15s; cursor: pointer;
}
.trip:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.trip .t-num { grid-row: span 2; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--brand-soft); color: var(--brand); padding: 8px 9px; border-radius: 10px; font-size: .88rem; }
.trip .t-route { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip .t-name { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip .t-x { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; border: 0; background: transparent; color: var(--faint); display: grid; place-items: center; font-size: 1.1rem; line-height: 1; }
.trip .t-x:hover { background: var(--bad-soft); color: var(--bad); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.example { display: inline-flex; gap: 8px; align-items: center; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .88rem; font-weight: 550; }
.example b { font-variant-numeric: tabular-nums; color: var(--brand); }
.example:hover { border-color: var(--brand); }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.features li { display: grid; gap: 4px; padding: 16px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 60%, transparent); border: 1px dashed var(--line); }
.features b { font-weight: 650; }
.features span { color: var(--muted); font-size: .88rem; }

/* tracking mode: collapse the landing chrome */
body.tracking .landing, body.tracking .extras { display: none; }
body.tracking .search { display: none; }
body.tracking.editing .search { display: block; animation: drop .22s ease; max-width: none; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- banner / toast ---------- */
.banner { padding: 12px 16px; border-radius: 14px; background: var(--warn-soft); color: var(--warn); font-weight: 550; font-size: .92rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 32px); background: var(--text); color: var(--bg); padding: 12px 18px;
  border-radius: 14px; font-weight: 550; z-index: 1000; box-shadow: var(--shadow-pop); animation: rise .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- skeleton ---------- */
.skeleton { display: grid; gap: 18px; }
.sk { border-radius: var(--radius); background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; border: 1px solid var(--line); }
.sk-hero { height: 330px; }
.sk-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.sk-tile { height: 150px; }
.sk-list { height: 260px; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* ---------- hero ---------- */
#result { display: grid; gap: 18px; }
.hero {
  --st: #94a3b8;
  position: relative; overflow: hidden; color: #fff; border-radius: 26px; padding: 22px 24px 20px;
  background:
    radial-gradient(70% 90% at 100% 0%, color-mix(in srgb, var(--st) 26%, transparent) 0%, transparent 70%),
    radial-gradient(120% 140% at 0% 0%, #2a3a8c 0%, #141c44 46%, #0a0f24 100%);
  box-shadow: 0 20px 50px rgba(10, 15, 36, .28);
  transition: background .6s;
}
.hero[data-status="ok"] { --st: #34d399; }
.hero[data-status="warn"] { --st: #fbbf24; }
.hero[data-status="bad"] { --st: #fb7185; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.live-pill { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: rgba(255,255,255,.78); padding: 5px 11px 5px 9px; border-radius: 999px; background: rgba(255,255,255,.09); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex-shrink: 0; }
.dot.live { background: #34d399; animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); } 70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
.hero-actions { display: flex; gap: 8px; }
.hero-btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 999px; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: .84rem; font-weight: 600; transition: background .15s; }
.hero-btn:hover { background: rgba(255,255,255,.2); }
.hero-btn.spinning svg { animation: spin .8s linear infinite; }
.hero :focus-visible { outline-color: #fff; }

.hero-train { margin-top: 18px; font-size: .95rem; font-weight: 550; color: rgba(255,255,255,.82); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hero-train .num { font-weight: 700; color: #fff; background: rgba(255,255,255,.14); padding: 2px 9px; border-radius: 8px; letter-spacing: .02em; }
.hero-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-top: 14px; }
.hero-eyebrow { font-size: 1.05rem; font-weight: 550; color: rgba(255,255,255,.8); }
.hero-big { font-size: clamp(3rem, 12vw, 4.8rem); line-height: 1; font-weight: 800; letter-spacing: -.045em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero-sub { margin-top: 10px; color: rgba(255,255,255,.8); font-weight: 500; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px; font-weight: 650; font-size: .86rem; white-space: nowrap; }
.hero .pill { background: color-mix(in srgb, var(--st) 20%, rgba(255,255,255,.06)); color: color-mix(in srgb, var(--st) 72%, #fff); margin-bottom: 6px; }
.hero .pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--st); }

.where { display: flex; gap: 10px; align-items: flex-start; margin-top: 20px; padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.07); font-size: .94rem; }
.where svg { flex-shrink: 0; margin-top: 2px; color: var(--st); }
.where b { font-weight: 650; }
.where span { color: rgba(255,255,255,.72); }
.where .stale { color: #fbbf24; }

.track { position: relative; height: 34px; margin: 26px 12px 0; }
.track-line, .track-fill, .track-approach { position: absolute; top: 15px; height: 4px; border-radius: 4px; }
.track-line { left: var(--a, 0%); right: 0; background: rgba(255,255,255,.18); }
.track-approach { left: 0; width: var(--a, 0%); background: repeating-linear-gradient(90deg, rgba(255,255,255,.3) 0 6px, transparent 6px 12px); }
.track-fill { left: var(--a, 0%); width: calc(var(--p, 0%) - var(--a, 0%)); background: linear-gradient(90deg, #7c9cff, #fff); transition: width .8s cubic-bezier(.2,.8,.2,1); }
.track-tick { position: absolute; top: 13px; width: 2px; height: 8px; margin-left: -1px; border-radius: 2px; background: rgba(255,255,255,.3); }
.track-tick.passed { background: rgba(255,255,255,.75); }
.track-node { position: absolute; top: 10px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #0f1535; border: 3px solid #fff; }
.track-node.passed { background: #fff; }
.track-train {
  position: absolute; top: 1px; left: var(--t, 0%); width: 32px; height: 32px; margin-left: -16px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; color: #1a2466;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--st) 35%, transparent), 0 6px 16px rgba(0,0,0,.4);
  transition: left .8s cubic-bezier(.2,.8,.2,1);
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 20px; border-radius: 16px; overflow: hidden; background: rgba(255,255,255,.1); }
.stat { background: rgba(13, 19, 48, .72); padding: 12px 14px; min-width: 0; }
.stat dt { font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: rgba(255,255,255,.58); }
.stat dd { font-weight: 650; font-size: 1.02rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }

.runs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; font-size: .84rem; color: rgba(255,255,255,.65); }
.run { padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,.2); background: transparent; color: rgba(255,255,255,.85); font-size: .82rem; font-weight: 550; }
.run:hover { border-color: rgba(255,255,255,.5); }
.run[aria-pressed="true"] { background: #fff; color: #141c44; border-color: #fff; font-weight: 650; }

/* ---------- ETA tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.tile { padding: 18px 20px; display: grid; gap: 4px; align-content: start; }
.tile-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tile-label { font-size: .74rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); }
.pf { font-size: .8rem; font-weight: 650; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.tile-stn { font-size: 1.12rem; font-weight: 650; letter-spacing: -.015em; }
.tile-stn span { color: var(--faint); font-weight: 550; font-size: .86rem; margin-left: 4px; }
.tile-time { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; }
.tile-time strong { font-size: 2.3rem; line-height: 1; font-weight: 750; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.tile-time s { color: var(--faint); font-variant-numeric: tabular-nums; }
.tile-time em { font-style: normal; color: var(--muted); font-size: .88rem; }
.tile-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; font-weight: 600; }
.tile-line .count { color: var(--brand); }
.tile-line .count.done { color: var(--ok); }
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.tile-foot { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: .86rem; }

/* ---------- columns ---------- */
.cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 18px; align-items: start; }
.timeline-card { grid-column: 1; grid-row: 1; padding: 18px 20px 10px; }
.side { grid-column: 2; grid-row: 1; display: grid; gap: 18px; position: sticky; top: 78px; }

/* alert */
.alert-card { padding: 16px 18px; }
.alert-head { display: flex; align-items: center; gap: 12px; }
.alert-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); flex-shrink: 0; }
.alert-copy { flex: 1; min-width: 0; }
.toggle { position: relative; flex-shrink: 0; cursor: pointer; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle-ui { display: block; width: 50px; height: 30px; border-radius: 999px; background: var(--rail); transition: background .2s; }
.toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .2s cubic-bezier(.3,1.4,.6,1); }
.toggle input:checked + .toggle-ui { background: var(--ok); }
.toggle input:checked + .toggle-ui::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--brand); outline-offset: 2px; }
.segmented { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 14px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented label { position: relative; text-align: center; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: 7px 0; border-radius: 9px; font-size: .84rem; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }
.alert-card.off .segmented { opacity: .55; }

/* map */
.map-card { position: relative; overflow: hidden; padding: 0; }
#map { height: 380px; background: var(--surface-2); z-index: 0; }
#map .leaflet-tile-pane { filter: saturate(.55) contrast(.96); }
#map.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(195deg) saturate(.45) brightness(.82) contrast(.92); }
.map-btn { position: absolute; right: 12px; top: 12px; z-index: 5; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .82rem; font-weight: 600; box-shadow: var(--shadow); }
.map-btn:hover { border-color: var(--brand); }
.train-pin { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #fff; color: #1a2466; border: 2px solid #2f55e6; box-shadow: 0 0 0 6px rgba(47, 85, 230, .22), 0 4px 12px rgba(0,0,0,.35); }
.leaflet-container { font: inherit; }
.leaflet-tooltip { border: 0; border-radius: 8px; box-shadow: var(--shadow-pop); font-weight: 600; padding: 5px 9px; }
:root[data-theme="dark"] .leaflet-control-zoom a, :root[data-theme="dark"] .leaflet-control-attribution { background: #111725; color: #93a0b5; border-color: #222b3d; }
:root[data-theme="dark"] .leaflet-control-attribution a { color: #7c9cff; }

/* ---------- timeline ---------- */
.timeline { margin-top: 8px; }
.tl { display: grid; grid-template-columns: 52px 24px minmax(0, 1fr); column-gap: 10px; position: relative; padding: 10px 0; }
.tl::before { content: ""; position: absolute; left: 73px; top: 0; bottom: 0; width: 2px; background: var(--rail); }
.tl.passed::before { background: var(--brand); }
.tl.first::before { top: 20px; }
.tl.last::before { bottom: calc(100% - 20px); }
.tl-time { text-align: right; font-variant-numeric: tabular-nums; line-height: 1.25; padding-top: 1px; }
.tl-time b { display: block; font-weight: 650; }
.tl-time s, .tl-time small { display: block; font-size: .76rem; color: var(--faint); }
.tl-time b.late { color: var(--bad); }
.tl-node { position: relative; z-index: 1; width: 12px; height: 12px; margin: 5px auto 0; border-radius: 50%; background: var(--surface); border: 2px solid var(--rail); }
.tl.passed .tl-node { background: var(--brand); border-color: var(--brand); }
.tl.key .tl-node { width: 16px; height: 16px; margin-top: 3px; border-width: 4px; border-color: var(--brand); background: var(--surface); }
.tl.here .tl-node { border-color: var(--ok); background: var(--ok); box-shadow: 0 0 0 5px var(--ok-soft); }
.tl-body { min-width: 0; }
.tl-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-weight: 600; }
.tl.passed .tl-name, .tl.passed .tl-time b { color: var(--muted); }
.tl.key .tl-name { font-weight: 700; color: var(--text); }
.tl.next .tl-name { color: var(--text); }
.tag { padding: 2px 8px; border-radius: 6px; font-size: .68rem; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; background: var(--brand); color: var(--brand-ink); }
.tag.soft { background: var(--ok-soft); color: var(--ok); }
.tl-meta { color: var(--muted); font-size: .82rem; margin-top: 1px; }
.tl.out { opacity: .62; }

.tl-train { display: grid; grid-template-columns: 52px 24px minmax(0, 1fr); column-gap: 10px; position: relative; padding: 6px 0; align-items: center; }
.tl-train::before { content: ""; position: absolute; left: 73px; top: 0; bottom: 0; width: 2px; background: linear-gradient(var(--brand) 50%, var(--rail) 50%); }
.tl-train .ico { grid-column: 2; position: relative; z-index: 1; width: 26px; height: 26px; margin-left: -1px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #fff; box-shadow: 0 0 0 5px var(--ok-soft); animation: bob 2.4s ease-in-out infinite; }
.tl-train .txt { color: var(--ok); font-weight: 650; font-size: .9rem; }
@keyframes bob { 50% { transform: translateY(2px); } }

.tl-toggle { position: relative; padding: 4px 0; }
.tl-toggle::before { content: ""; position: absolute; left: 73px; top: 0; bottom: 0; border-left: 2px dotted var(--rail); }
.tl-toggle button { display: inline-flex; align-items: center; gap: 8px; margin-left: 96px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: .82rem; font-weight: 600; }
.tl-toggle button:hover { color: var(--text); border-color: var(--faint); }
.tl-toggle svg { transition: transform .2s; }
.tl-toggle button[aria-expanded="true"] svg { transform: rotate(180deg); }

.foot { text-align: center; line-height: 1.6; padding: 4px 12px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .timeline-card, .side { grid-column: 1; grid-row: auto; }
  .side { position: static; }
  #map { height: 300px; }
}
@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  main { gap: 14px; padding-top: 14px; }
  #result, .cols, .side, .tiles { gap: 14px; }
  #form { grid-template-columns: 1fr 1fr; }
  .field-train, .primary { grid-column: 1 / -1; }
  .landing { padding-top: 18px; text-align: left; }
  .lede { margin-left: 0; }
  .features { grid-template-columns: 1fr; }
  .brand-name { display: none; }
  body:not(.tracking) .brand-name { display: inline; }
  .hero { padding: 18px 16px 16px; border-radius: 22px; }
  .hero-btn span { display: none; }
  .hero-btn { width: 36px; padding: 0; justify-content: center; }
  .hero-main { flex-direction: column; align-items: flex-start; gap: 12px; }
  .hero .pill { order: -1; margin: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat dd { white-space: normal; font-size: .96rem; line-height: 1.3; }
  .tile { padding: 16px; }
  .tile-time strong { font-size: 2rem; }
  .timeline-card { padding: 16px 14px 8px; }
  .tl, .tl-train { grid-template-columns: 46px 22px minmax(0, 1fr); column-gap: 8px; }
  .tl::before, .tl-train::before, .tl-toggle::before { left: 64px; }
  .tl-toggle button { margin-left: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- hero: boarding & arrival times ---------- */
.hero-times { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; margin-top: 22px; }
.ht { display: grid; gap: 1px; min-width: 0; }
.ht.right { text-align: right; justify-items: end; }
.ht-label { font-size: .7rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.58); }
.ht-time { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.ht-time b { font-size: clamp(1.7rem, 6.4vw, 2.3rem); line-height: 1.1; font-weight: 750; letter-spacing: -.035em; }
.ht-time s { color: rgba(255,255,255,.5); font-size: .88rem; }
.ht-stn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.ht-meta { font-size: .82rem; color: rgba(255,255,255,.66); }
.ht-mid { display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,.7); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.ht-mid::before, .ht-mid::after { content: ""; width: clamp(10px, 4vw, 44px); height: 1px; background: rgba(255,255,255,.28); }
.ht-mid span { padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.1); }
.hero .track { margin-top: 14px; }
.hero .where { margin-top: 14px; }
.stats { grid-template-columns: repeat(3, 1fr); }

.map-hint { display: none; position: absolute; left: 10px; top: 12px; z-index: 5; padding: 5px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--muted); border: 1px solid var(--line); pointer-events: none; }
.map-card.touch .map-hint { display: block; }

/* ---------- mobile & touch ---------- */
html { -webkit-tap-highlight-color: transparent; }
button, a, select, input, label { touch-action: manipulation; }
.wrap { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
.runs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; margin-right: -24px; padding-right: 24px; }
.runs::-webkit-scrollbar { display: none; }
.runs > * { flex-shrink: 0; }
.trip-pill { flex-shrink: 1; }

@media (hover: none) {
  .trip:hover { transform: none; box-shadow: none; }
}
@media (pointer: coarse) {
  .hero-btn { height: 42px; min-width: 42px; }
  .run { padding: 10px 14px; }
  .tl-toggle button { padding: 11px 14px; }
  .segmented span { padding: 11px 0; }
  .example { padding: 11px 15px; }
  .map-btn { height: 40px; padding: 0 14px; }
  .trip { padding-top: 14px; padding-bottom: 14px; }
  .trip .t-x { width: 40px; height: 40px; right: 2px; }
  .icon-btn, .trip-pill { height: 42px; }
  .icon-btn { width: 42px; }
  .leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
}

@media (max-width: 900px) {
  /* Single column: alert, then the timeline, then the map. */
  .side { display: contents; }
  .alert-card { order: 1; }
  .timeline-card { order: 2; }
  .map-card { order: 3; }
}
@media (max-width: 720px) {
  html { scroll-padding-top: 64px; }
  .wrap { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .top-row { height: 54px; gap: 8px; }
  /* 16px inputs stop iOS Safari zooming the page on focus. */
  .field input, .field select { font-size: 16px; height: 52px; }
  .primary { height: 52px; font-size: 1rem; }
  .search { padding: 14px; }
  .landing h1 { font-size: clamp(2.1rem, 10.5vw, 3rem); }
  .lede { font-size: 1rem; }
  .trip-grid { grid-template-columns: 1fr; }
  .examples { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px; }
  .examples::-webkit-scrollbar { display: none; }
  .example { flex-shrink: 0; }
  .hero-train { margin-top: 14px; font-size: .9rem; }
  .hero-eyebrow { font-size: 1rem; }
  .hero-big { font-size: clamp(2.7rem, 15vw, 4rem); }
  .hero-sub { margin-top: 6px; font-size: .92rem; }
  .hero-times { margin-top: 18px; gap: 8px; padding: 14px; border-radius: 16px; background: rgba(255,255,255,.07); }
  .ht-mid::before, .ht-mid::after { width: 8px; }
  .ht-mid span { padding: 3px 8px; font-size: .74rem; }
  .ht-stn { font-size: .9rem; }
  .ht-meta { font-size: .76rem; }
  .hero .track { margin: 16px 14px 0; }
  .hero .where { padding: 11px 12px; font-size: .9rem; }
  .stats { grid-template-columns: 1fr 1fr; margin-top: 14px; }
  .stat:last-child { grid-column: 1 / -1; }
  .stat { padding: 10px 12px; }
  .runs { margin-right: -16px; padding-right: 16px; }
  .runs > span { display: none; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 14px; }
  .tile-top { flex-direction: column; align-items: flex-start; gap: 6px; }
  .tile-stn { font-size: 1rem; }
  .tile-stn span { display: none; }
  .tile-time strong { font-size: 1.75rem; }
  .tile-line { gap: 4px 8px; font-size: .88rem; }
  .tile-foot { font-size: .8rem; }
  .alert-card { padding: 14px; }
  .segmented { margin-top: 12px; }
  #map { height: 46vh; min-height: 260px; max-height: 380px; }
  .timeline-card { padding: 16px 12px 8px; }
  .card-head { padding: 0 2px; }
  .tl { padding: 11px 0; }
  .tl-meta { font-size: .8rem; }
  .foot { font-size: .78rem; }
  .toast { left: 14px; right: 14px; transform: none; max-width: none; text-align: center; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
@media (max-width: 360px) {
  #form { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr; }
  .ht-mid span { display: none; }
  .ht-time s { display: none; }
  .brand-name { display: none !important; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .top { position: static; }
  .hero-big { font-size: 2.6rem; }
}

/* Grid children must be allowed to shrink, or a no-wrap row widens the page. */
main, #result, .extras, .skeleton { grid-template-columns: minmax(0, 1fr); }
.hero-times { align-items: start; }
.ht-mid { align-self: center; }
@media (max-width: 360px) {
  .hero-times { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ht-mid { display: none; }
}
.ht-time { flex-wrap: wrap; }
.ht.right .ht-time { justify-content: flex-end; }
@media (max-width: 720px) {
  .ht-time { gap: 0 6px; }
  .ht-time b { font-size: 1.6rem; }
  .ht-time s { font-size: .8rem; }
}
.ht-stn { white-space: normal; overflow-wrap: anywhere; line-height: 1.25; }

/* ---------- FAQ (landing) ---------- */
.faq details { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); margin-bottom: 8px; }
.faq summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; font-weight: 600; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 1.3rem; line-height: 1; color: var(--faint); font-weight: 400; transition: transform .2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { padding: 0 16px 16px; color: var(--muted); max-width: 68ch; }

/* ---------- searchable station picker ---------- */
.picker { position: relative; min-width: 0; }
.picker-btn {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 0; text-align: left;
  width: 100%; height: 50px; padding: 0 36px 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background-color: var(--surface-2); min-width: 0; line-height: 1.2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238792a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.picker-btn:not(:disabled):hover { border-color: var(--faint); }
.picker-btn:focus-visible, .picker-btn[aria-expanded="true"] { outline: none; border-color: var(--brand); background-color: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.picker-btn:disabled { cursor: not-allowed; }
.picker-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-name { font-weight: 600; }
.pb-meta { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pb-placeholder { color: var(--faint); }

.picker-pop {
  position: absolute; z-index: 40; left: 0; top: calc(100% + 8px); width: max(100%, 320px); max-width: calc(100vw - 28px);
  display: flex; flex-direction: column; max-height: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-pop); overflow: hidden;
  animation: drop .16s ease;
}
.field:last-of-type .picker-pop { left: auto; right: 0; }
.picker-head { display: none; }
.picker-search { position: relative; padding: 8px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.picker-search svg { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.picker-search input { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px 0 36px; font-weight: 500; }
.picker-search input:focus { outline: none; border-color: var(--brand); }
.picker-search input::placeholder { color: var(--faint); font-weight: 450; }
.picker-pop ul { overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.picker-pop li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.picker-pop li.active { background: var(--surface-2); }
.picker-pop li[aria-selected="true"] .p-name { color: var(--brand); font-weight: 700; }
.p-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-code { font-size: .74rem; font-weight: 650; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
.picker-pop li.active .p-code { background: var(--surface); }
.p-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .86rem; min-width: 3.1em; text-align: right; }
.picker-empty { padding: 18px 16px; color: var(--muted); text-align: center; }

@media (hover: hover) { .picker-pop li:hover { background: var(--surface-2); } }
@media (max-width: 720px) {
  .picker-btn { height: 52px; }
  /* Full-screen sheet on phones: easy to scroll and safe from the keyboard. */
  .picker-pop { position: fixed; inset: 0; z-index: 200; width: auto; max-width: none; max-height: none; height: 100dvh; border: 0; border-radius: 0; animation: rise-sheet .2s ease;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .field:last-of-type .picker-pop { left: 0; }
  .picker-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px 16px; font-size: 1.05rem; flex-shrink: 0; }
  .picker-close { width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; line-height: 1; border-radius: 50%; }
  .picker-search { padding: 8px 12px 12px; }
  .picker-search svg { left: 26px; }
  .picker-search input { height: 48px; font-size: 16px; padding-left: 40px; }
  .picker-pop ul { flex: 1; padding: 6px 8px 24px; }
  .picker-pop li { padding: 14px 10px; }
  body.picker-open { overflow: hidden; }
}
@keyframes rise-sheet { from { opacity: 0; transform: translateY(16px); } }

/* ---------- no sideways scrolling ---------- */
/* Clip at the page level (clip, unlike hidden, keeps the sticky header working). */
html, body { overflow-x: clip; max-width: 100%; }
/* Vertical lists must never scroll sideways. */
.suggest, .picker-pop ul { overflow-x: hidden; }
.suggest li > *, .picker-pop li > * { min-width: 0; }
/* Swipeable rows are for touch screens only; with a mouse they wrap instead,
   so no horizontal scrollbar can appear. */
@media (hover: hover) and (pointer: fine) {
  .runs, .examples { flex-wrap: wrap; overflow: visible; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .runs > *, .example { flex-shrink: 1; }
}
