:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #15232d;
  --muted: #5d6a72;
  --faint: #9aa4aa;
  --line: #e2ddd2;
  --accent: #0b3d5c;
  --accent-soft: #e3eef5;
  --on-accent: #ffffff;
  --warn-bg: #fff1d6;
  --warn-text: #7a4b00;
  --ok-bg: #e2f3e6;
  --ok-text: #22612f;
  --bad-bg: #fde3e1;
  --bad-text: #8f1d14;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1419;
    --surface: #152129;
    --text: #e8eef2;
    --muted: #9fb0bb;
    --faint: #5f717c;
    --line: #23343f;
    --accent: #7cc4ef;
    --accent-soft: #1b3445;
    --on-accent: #0d1419;
    --warn-bg: #3b2c0e;
    --warn-text: #f5c96a;
    --ok-bg: #143021;
    --ok-text: #8fd9a3;
    --bad-bg: #3d1714;
    --bad-text: #ffaaa3;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.masthead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 0 2px;
}
.brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-decoration: none;
}
.brand-sub { color: var(--muted); font-size: 14px; }

.status { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }
.warn { color: var(--warn-text); }

/* Alerts */
.alert {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 15px;
}
.alert summary { cursor: pointer; font-weight: 600; }
.alert p { margin: 8px 0 2px; white-space: pre-line; }

/* Next departures */
.cards { display: grid; gap: 12px; }
@media (min-width: 720px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 16px; }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px 6px;
  border: 1px solid var(--line);
}
.route {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.next-list, .times { list-style: none; margin: 0; padding: 0; }

.next-list li, .times li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.next-list li:first-child { border-top: 0; }

.t { font-size: 18px; font-weight: 600; }
.t small { font-size: 0.6em; font-weight: 500; margin-left: 2px; color: var(--muted); }
.in { color: var(--muted); font-size: 15px; white-space: nowrap; }

.next-list li.first { padding: 4px 0 12px; flex-wrap: wrap; row-gap: 6px; }
.next-list li.first .meta { flex-basis: 100%; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.next-list li.first .meta > * { margin-left: 0; }
.next-list li.first .t { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.next-list li.first .t small { font-size: 18px; }
.next-list li.first .in { font-size: 18px; color: var(--accent); font-weight: 600; }

.badge {
  display: inline-block;
  vertical-align: middle;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 999px;
  margin-left: 6px;
  letter-spacing: 0;
}
.first .badge { font-size: 13px; }
.route-tag {
  display: inline-block;
  vertical-align: middle;
  min-width: 2.6em;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  margin-left: 8px;
  background: var(--accent);
  color: var(--on-accent);
  letter-spacing: 0;
}
.first .route-tag { font-size: 15px; }
.stop-tag { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.first .stop-tag { font-size: 15px; }
.badge.live { background: var(--ok-bg); color: var(--ok-text); }
.badge.late { background: var(--warn-bg); color: var(--warn-text); }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); }
.canceled .t { text-decoration: line-through; text-decoration-thickness: 2px; }

.empty { color: var(--muted); margin: 8px 0 14px; }

/* Full schedule */
.schedule { margin-top: 28px; }
.schedule h2 { font-size: 18px; margin: 0 0 10px; }

.tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 6px;
}
.tabs a {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.tabs a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }


.day {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  margin: 0;
  padding: 14px 0 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.times { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px; }
.times li:first-child { border-top: 0; }
.times .t { font-size: 17px; font-weight: 500; }
.times li.past .t, .times li.past .in { color: var(--faint); }
.times li.next { position: relative; }
.times li.next::before {
  content: "";
  position: absolute;
  inset: 3px -10px;
  background: var(--accent-soft);
  border-radius: 10px;
  z-index: -1;
}
.times li.next .t { font-weight: 700; }
.times li.next .in { color: var(--accent); font-weight: 600; }
.times { position: relative; z-index: 0; }

.footnote { color: var(--muted); font-size: 13px; margin-top: 28px; }
.footnote p { margin: 4px 0; }
.other-lines { display: flex; flex-wrap: wrap; gap: 12px; margin: 4px 0; }
.other-lines a { color: var(--muted); }

.loading { padding: 40px 0; color: var(--muted); }
