:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f0ece3;
  --text: #17202a;
  --muted: #5d6875;
  --border: #ddd6c8;
  --accent: #0b6e6e;
  --accent-text: #ffffff;
  --accent-soft: #dcefec;
  --nec: #c62f35;
  --warn: #8a5a00;
  --good: #1d7a45;
  --mid: #d9a300;
  --bad: #c0392b;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #17212c;
    --surface-2: #1e2a37;
    --text: #edf1f5;
    --muted: #9aa7b5;
    --border: #2b3948;
    --accent: #4fd1c5;
    --accent-text: #06201f;
    --accent-soft: #163a3a;
    --nec: #e2575c;
    --warn: #f0c36a;
    --good: #4cc27d;
    --mid: #f2c230;
    --bad: #f0675c;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

main,
.top,
footer {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 18px;
  padding-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}

.line-badge {
  background: var(--nec);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: 6px;
}

.clock {
  color: var(--muted);
  font-size: 14px;
}

main {
  display: grid;
  gap: 16px;
}

h2 {
  margin: 0;
  font-size: 18px;
}

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

/* Route controls */
.route {
  display: grid;
  gap: 12px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.chip[aria-pressed="true"],
.chip[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.pickers {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: end;
}

.when {
  display: flex;
  gap: 10px;
  align-items: end;
}

.grow {
  flex: 1;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.field span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

select,
input[type="datetime-local"] {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.swap {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
}

.when .chip {
  height: 46px;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Next train */
.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
}

.hero .label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero .time {
  font-size: clamp(44px, 12vw, 64px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.hero .time small {
  font-size: 0.35em;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 4px;
}

.hero .meta {
  color: var(--muted);
  font-size: 15px;
}

.hero .side {
  text-align: right;
}

.hero .countdown {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

.hero.empty {
  grid-template-columns: 1fr;
  border-left-color: var(--warn);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
}

.link,
.links a,
.opt a {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

.link {
  white-space: nowrap;
}

.link:hover,
.links a:hover,
.opt a:hover {
  text-decoration: underline;
}

/* Departure rows */
.day {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 0 6px;
  border-top: 1px solid var(--border);
}

.row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.row .dep {
  font-size: 20px;
  font-weight: 700;
}

.row .sub {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

.row .soon {
  color: var(--accent);
  font-weight: 600;
}

.row .train {
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

.more {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.foot {
  margin-top: 12px;
  font-size: 13px;
}

/* Alternate routes */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.opt {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 10px;
}

.opt h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.opt ol {
  margin: 0;
  padding-left: 20px;
}

.opt li {
  margin: 3px 0;
}

.opt .note {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.opt .opt-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
}

.links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

footer {
  padding-top: 20px;
  padding-bottom: 32px;
  font-size: 13px;
}

@media (max-width: 560px) {
  .pickers {
    grid-template-columns: 1fr auto;
  }
  .pickers .field:first-child {
    grid-column: 1;
    grid-row: 1;
  }
  .pickers .field:last-child {
    grid-column: 1;
    grid-row: 2;
  }
  .pickers .swap {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }
  .hero {
    grid-template-columns: 1fr;
  }
  .hero .side {
    text-align: left;
  }
  .row {
    grid-template-columns: 1fr 1fr;
  }
  .row .train {
    text-align: left;
  }
  .card-head {
    flex-direction: column;
  }
}

/* ---------- Live train cards ---------- */
.live-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.live-state {
  font-size: 13px;
  color: var(--muted);
}

.live-state.on::before,
.live-state.off::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--good);
}

.live-state.off::before {
  background: var(--warn);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.tcard,
.empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.empty {
  grid-column: 1 / -1;
  border-top-color: var(--warn);
}

.empty .label {
  font-weight: 700;
}

.empty p {
  margin: 0;
  color: var(--muted);
}

.tcard.cancelled {
  border-top-color: var(--bad);
}

.tcard.cancelled .tc-time {
  text-decoration: line-through;
  color: var(--muted);
}

.tc-main {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
}

.tc-time {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.tc-time small {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 3px;
}

.tc-status {
  font-weight: 700;
  font-size: 15px;
  margin-top: 2px;
}

.st-ok {
  color: var(--good);
}
.st-warn {
  color: var(--warn);
}
.st-bad {
  color: var(--bad);
}
.st-plan {
  color: var(--accent);
}

.tc-note {
  font-size: 12px;
  color: var(--muted);
}

.tc-track {
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 10px;
  min-width: 54px;
}

.tc-track span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tc-track b {
  font-size: 24px;
  line-height: 1.1;
}

.tc-track.none b {
  color: var(--muted);
}

.tc-meta {
  font-size: 13px;
  color: var(--muted);
}

.tc-msg {
  font-size: 13px;
  color: var(--warn);
}

.tc-stops {
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.seats {
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.sec span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.sec.best span {
  color: var(--good);
}

.cars {
  display: flex;
  gap: 3px;
}

.car {
  display: inline-block;
  width: 14px;
  height: 20px;
  border-radius: 4px;
}

.car.l0 {
  background: var(--good);
}
.car.l1 {
  background: var(--mid);
}
.car.l2 {
  background: var(--bad);
}

.seat-tip {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
}

.seat-tip.muted {
  font-weight: 400;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend[hidden] {
  display: none;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend .car {
  width: 10px;
  height: 14px;
  border-radius: 3px;
}

.legend .link {
  margin-left: auto;
  font-size: 13px;
}

/* ---------- Collapsible timetable ---------- */
details.card > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

details.card > summary::-webkit-details-marker {
  display: none;
}

details.card > summary h2 {
  display: block;
}

.chev {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-right: 6px;
  flex: none;
}

details[open] > summary .chev {
  transform: rotate(-135deg);
}

details[open] > summary {
  margin-bottom: 12px;
}

.banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-left: 4px solid var(--warn);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 14px;
  white-space: pre-line;
}

@media (max-width: 720px) {
  .cards {
    grid-template-columns: 1fr;
  }
}
