:root {
  color-scheme: light dark;
  --bg: #eceef2;
  --card: #ffffff;
  --text: #111418;
  --muted: #555d6b;
  --line: #e2e5ea;
  --soon: #0a7a3c;
  --warn-bg: #fff3dc;
  --warn-line: #f2cf8f;
  --warn-text: #7a4500;
  --bang: #e08a00;
  --skel: #e5e8ed;
  --btn: #111418;
  --btn-text: #ffffff;
  --knob-off: #9aa1ad;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 10px rgb(0 0 0 / 0.04);
  /* the header is dark in both themes */
  --bar: #121418;
  --bar-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0b0d;
    --card: #17191d;
    --text: #f1f3f6;
    --muted: #a3abb7;
    --line: #2a2e35;
    --soon: #4ade80;
    --warn-bg: #2a2010;
    --warn-line: #5c4419;
    --warn-text: #ffd27a;
    --bang: #f5a524;
    --skel: #24272d;
    --btn: #f1f3f6;
    --btn-text: #111418;
    --knob-off: #4b515c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
html, body { touch-action: pan-x pan-y; } /* no pinch or double-tap zoom */
/* an app, not a page: nothing to select, no long-press menu */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* App shell: the page itself never scrolls or bounces. The header stays put; only <main> under it scrolls. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- header ---- */
.top {
  flex: none; z-index: 2;
  background: var(--bar); color: var(--bar-text);
  padding-top: env(safe-area-inset-top);
}
.top-in {
  max-width: 1100px; margin: 0 auto;
  padding: 8px max(6px, env(safe-area-inset-right)) 9px max(16px, env(safe-area-inset-left));
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px;
}
h1 { grid-area: 1 / 1; margin: 0; font-size: 21px; line-height: 1.25; letter-spacing: -0.01em; }
.status {
  grid-area: 2 / 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  font-size: 14px; color: #c4cad4; font-variant-numeric: tabular-nums;
}
.gear {
  grid-area: 1 / 2 / 3 / 3; display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: #e4e8ee; cursor: pointer;
}
.gear:focus-visible { outline: 3px solid #4d92fb; outline-offset: -2px; }
.pulse { position: relative; width: 9px; height: 9px; border-radius: 50%; background: #9aa1ad; flex: none; }
.status[data-kind="live"] { color: #e9fbe9; }
.status[data-kind="live"] .pulse { background: #3ddc84; }
.status[data-kind="live"] .pulse::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid #3ddc84;
  animation: ping 2s ease-out infinite;
}
.status[data-kind="bad"] { color: #ffb4ab; }
.status[data-kind="bad"] .pulse { background: #ff6b5e; }
.status[data-kind="off"] { color: #ffd27a; }
.status[data-kind="off"] .pulse { background: #f5a524; }
@keyframes ping { from { opacity: 0.9; transform: scale(0.6); } to { opacity: 0; transform: scale(1.6); } }
@media (prefers-reduced-motion: reduce) { .status .pulse::after { animation: none; opacity: 0; } }
.lines { display: flex; height: 4px; }
.lines i { flex: 1; background: var(--c); }

/* ---- layout ---- */
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
.scroll:focus { outline: none; }
.scroll:focus-visible { outline: 3px solid #4d92fb; outline-offset: -3px; }
.wrap {
  max-width: 1100px; margin: 0 auto;
  padding: 12px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.foot { padding-top: 20px; padding-bottom: max(24px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 13px; text-align: center; }

.btn {
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--btn); color: var(--btn-text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:focus-visible, summary:focus-visible { outline: 3px solid #4d92fb; outline-offset: 2px; }

.notice {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px;
  margin: 0 0 12px; padding: 10px 12px 10px 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; color: var(--muted); font-size: 15px;
}
.notice p { flex: 1 1 200px; padding: 2px 0; }

/* ---- settings sheet (bottom sheet on phones, centred card on wider screens) ---- */
#settings {
  width: min(100%, 480px); max-width: 100%; max-height: 100%; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 18px 18px 0 0; background: var(--card); color: var(--text);
}
#settings::backdrop { background: rgb(0 0 0 / 0.5); }
@media (min-width: 600px) { #settings { margin: auto; border-radius: 18px; } }
.sheet { padding: 6px 12px max(16px, env(safe-area-inset-bottom)) 16px; }
.sheet:focus { outline: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
#controls { display: grid; gap: 8px; }
.close {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.close:focus-visible { outline: 3px solid #4d92fb; outline-offset: -2px; }

/* "only trains across the river" switch */
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  width: 100%; min-height: 56px; margin: 0; padding: 10px 14px 10px 16px;
  background: var(--bg); color: var(--text); border: 0; border-radius: 14px;
  font: inherit; text-align: left; cursor: pointer;
}
.sw-text { display: flex; flex-direction: column; min-width: 0; }
.sw-label { font-weight: 650; }
.sw-sub { font-size: 13px; color: var(--muted); }
.knob { flex: none; position: relative; width: 46px; height: 28px; border-radius: 999px; background: var(--knob-off); transition: background 0.15s; }
.knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.15s;
}
.switch[aria-checked="true"] .knob { background: var(--soon); }
.switch[aria-checked="true"] .knob::after { transform: translateX(18px); }
.switch:focus-visible { outline: 3px solid #4d92fb; outline-offset: 2px; }

/* ---- alerts ---- */
.calm { margin: 0 4px 12px; color: var(--muted); font-size: 14px; }
.calm .ok { color: var(--soon); font-weight: 700; margin-right: 6px; }
.alerts { margin: 0 0 12px; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 14px; color: var(--text); }
.alerts summary {
  display: flex; align-items: flex-start; gap: 12px; min-height: 44px; padding: 12px 14px 12px 14px;
  cursor: pointer; list-style: none;
}
.alerts summary::-webkit-details-marker { display: none; }
.bang {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; margin-top: 1px; border-radius: 50%;
  background: var(--bang); color: #1a1200; font-weight: 800; font-size: 15px;
}
.sum { flex: 1; min-width: 0; font-size: 15px; color: var(--warn-text); }
.sum b { color: var(--text); }
.first {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 2px; color: var(--text); font-size: 15px; overflow-wrap: anywhere;
}
details[open] .first { display: none; }
.chev { flex: none; width: 10px; height: 10px; margin: 6px 4px 0; border: solid var(--warn-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
details[open] .chev { transform: rotate(-135deg); margin-top: 10px; }
.alerts ul { list-style: none; margin: 0; padding: 0 14px 6px 50px; }
.alerts li { padding: 10px 0 12px; border-top: 1px solid var(--warn-line); }
.alerts .when { font-size: 13px; color: var(--warn-text); }
.alerts .open {
  display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 4px;
  background: var(--warn-text); color: var(--warn-bg); font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
}
.alerts .subj { font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.alerts .text { margin-top: 4px; font-size: 15px; overflow-wrap: anywhere; }

/* ---- stations ---- */
.stations {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
}
.station { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.station h2 {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 0; padding: 14px 16px 2px; font-size: 19px; line-height: 1.25;
}
.name { min-width: 0; overflow-wrap: anywhere; }
.tag {
  display: inline-block; vertical-align: 2px; margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  background: var(--text); color: var(--card); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
}
.dist { flex: none; font-size: 14px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }

.dir { padding: 6px 16px 10px; }
.dir + .dir { border-top: 1px solid var(--line); }
.dir h3 { margin: 4px 0 2px; font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.trains { list-style: none; margin: 0; padding: 0; }
.trains li { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.trains li + li { border-top: 1px dashed var(--line); }
.dot {
  flex: none; width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--a) 50%, var(--b) 50%);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
}
.head { flex: 1; min-width: 0; overflow-wrap: anywhere; }
/* PATH's own update time under a train (Settings) */
.upd {
  display: flex; align-items: center; gap: 4px; margin: 1px 0 3px;
  font-size: 12px; line-height: 1.3; color: var(--muted); font-variant-numeric: tabular-nums;
}
.upd svg { flex: none; width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.upd.old { color: var(--warn-text); }
.min { flex: none; font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.min small { font-size: 14px; font-weight: 600; color: var(--muted); }
.soon .min { color: var(--soon); }
.late .min { color: var(--warn-text); font-size: 15px; font-weight: 700; }
.dim .head, .dim .min, .dim .soon .min { color: var(--muted); font-weight: 500; }
.empty { padding: 8px 16px 14px; color: var(--muted); font-size: 15px; }
.dir .empty { padding: 4px 0 6px; }
.quiet { margin: 2px 0 4px; padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }

.skel { height: 14px; margin: 14px 0; border-radius: 7px; background: var(--skel); width: 80%; }
.skel.short { width: 55%; }
