:root {
  --bg-1: #f7f1e4;
  --bg-2: #f0e5d0;
  --ink: #1f2937;
  --muted: #5b6576;
  --card: #fffaf0;
  --line: #d8c9a8;
  --accent: #006d5b;
  --accent-soft: #d8efe9;
  --late: #b45309;
  --th-bg: #f8f0de;
  --th-ink: #374151;
  --row-alt: rgba(232, 218, 184, 0.25);
  --row-hover: rgba(0, 109, 91, 0.08);
  --static-banner-bg: #fef3c7;
  --static-banner-border: #f59e0b;
  --static-banner-ink: #92400e;
  --static-banner-dot: #f59e0b;
  --bg-glow: rgba(0, 109, 91, 0.14);
  --badge-ink: #0f4a3f;
  --badge-border: #a4d8cd;
  --btn-refresh-border: #a4d8cd;
  --btn-refresh-hover: #c2e8df;
  --status-ok: #166534;
  --status-cancelled: #991b1b;
  --error-ink: #c0392b;
  --seg-hover: rgba(0, 109, 91, 0.06);
  --seg-active-hover: #005a4a;
  --tooltip-bg: #1f2937;
  --tooltip-ink: #f9fafb;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-1: #13121e;
    --bg-2: #0d0c17;
    --ink: #ddd8f0;
    --muted: #7a738f;
    --card: #1a1929;
    --line: #2c2a40;
    --accent: #9b7fe8;
    --accent-soft: #1e1a35;
    --late: #d4855a;
    --th-bg: #1e1c30;
    --th-ink: #a89ec8;
    --row-alt: rgba(255, 255, 255, 0.02);
    --row-hover: rgba(155, 127, 232, 0.07);
    --static-banner-bg: #1c1628;
    --static-banner-border: #5a3f80;
    --static-banner-ink: #b89ad8;
    --static-banner-dot: #9b7fe8;
    --bg-glow: rgba(155, 127, 232, 0.10);
    --badge-ink: #c4b0f0;
    --badge-border: #3e3060;
    --btn-refresh-border: #3e3060;
    --btn-refresh-hover: #221e38;
    --status-ok: #6abf8e;
    --status-cancelled: #c07080;
    --error-ink: #c07080;
    --seg-hover: rgba(155, 127, 232, 0.08);
    --seg-active-hover: #7a60c8;
    --tooltip-bg: #0d0c17;
    --tooltip-ink: #ddd8f0;
  }
}

[data-theme="dark"] {
  --bg-1: #13121e;
  --bg-2: #0d0c17;
  --ink: #ddd8f0;
  --muted: #7a738f;
  --card: #1a1929;
  --line: #2c2a40;
  --accent: #9b7fe8;
  --accent-soft: #1e1a35;
  --late: #d4855a;
  --th-bg: #1e1c30;
  --th-ink: #a89ec8;
  --row-alt: rgba(255, 255, 255, 0.02);
  --row-hover: rgba(155, 127, 232, 0.07);
  --static-banner-bg: #1c1628;
  --static-banner-border: #5a3f80;
  --static-banner-ink: #b89ad8;
  --static-banner-dot: #9b7fe8;
  --bg-glow: rgba(155, 127, 232, 0.10);
  --badge-ink: #c4b0f0;
  --badge-border: #3e3060;
  --btn-refresh-border: #3e3060;
  --btn-refresh-hover: #221e38;
  --status-ok: #6abf8e;
  --status-cancelled: #c07080;
  --error-ink: #c07080;
  --seg-hover: rgba(155, 127, 232, 0.08);
  --seg-active-hover: #7a60c8;
  --tooltip-bg: #0d0c17;
  --tooltip-ink: #ddd8f0;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% 0%, var(--bg-glow) 0, transparent 35%),
    linear-gradient(170deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

.page {
  width: min(980px, 92vw);
  margin: 48px auto;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.4vw + 1rem, 3rem);
  line-height: 1.1;
}

.hero__eyebrow {
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.78rem;
}

.hero__eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.hero__eyebrow-row .hero__eyebrow {
  margin: 0;
}

.hero__subtitle {
  margin: 14px 0 0;
  color: var(--muted);
  max-width: 65ch;
}

/* ── Next-train card ─────────────────────────────────────── */
.next-train-card {
  margin-top: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 32px rgba(61, 45, 12, 0.08);
  padding: 24px 32px 28px;
}

.next-train-card__label {
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.78rem;
}

.next-train-card__values {
  display: flex;
  align-items: center;
  gap: 40px;
  flex-wrap: wrap;
}

.next-train-card__item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.next-train-card__value {
  font-size: clamp(3rem, 5vw + 1rem, 5.5rem);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.next-train-card__value--text {
  font-size: clamp(1.1rem, 2vw + 0.5rem, 1.75rem);
  letter-spacing: -0.01em;
  font-variant-numeric: normal;
  line-height: 1.15;
}

.next-train-card__sub {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}

.next-train-card__divider {
  width: 1px;
  height: 60px;
  background: var(--line);
  flex-shrink: 0;
}

/* ── Schedule card ───────────────────────────────────────── */
.card {
  margin-top: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 32px rgba(61, 45, 12, 0.08);
  overflow: hidden;
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.card__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.badge {
  background: var(--accent-soft);
  color: var(--badge-ink);
  border: 1px solid var(--badge-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 1;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--ink);
}

.tab--auto {
  flex: 0 0 auto;
  padding: 12px 16px;
  margin-left: auto;
  color: var(--muted);
  border-left: 1px solid var(--line);
  font-size: 0.88rem;
}

.tab--auto-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.tab--active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--line);
  border-radius: 10px;
  transition: background 0.2s;
}

.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle__track {
  background: var(--accent);
}

.toggle input:checked + .toggle__track .toggle__thumb {
  transform: translateX(16px);
}

.toggle__label {
  font-size: 0.88rem;
  color: var(--muted);
}

.tooltip {
  position: relative;
  display: inline-block;
  cursor: help;
  color: var(--accent);
  font-size: 0.85rem;
}

.tooltip::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 7px 10px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  white-space: normal;
}

.tooltip:hover::after,
.tooltip:focus::after {
  opacity: 1;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-left: auto;
}

.seg__btn {
  padding: 6px 14px;
  background: none;
  border: none;
  border-left: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.seg__btn:first-child {
  border-left: none;
}

.seg__btn:hover {
  background: var(--seg-hover);
}

.seg__btn--active {
  background: var(--accent);
  color: #fff;
}

.seg__btn--active:hover {
  background: var(--seg-active-hover);
}

.row--preferred {
  background: var(--accent-soft) !important;
}

.row--dimmed {
  opacity: 0.5;
}

.static-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  background: var(--static-banner-bg);
  border-bottom: 1px solid var(--static-banner-border);
  color: var(--static-banner-ink);
  font-size: 0.88rem;
  font-weight: 600;
}

.static-banner__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--static-banner-dot);
  flex-shrink: 0;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
}

th,
td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

th {
  background: var(--th-bg);
  font-weight: 600;
  color: var(--th-ink);
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--row-hover);
}

.route {
  font-weight: 600;
}

.status {
  font-weight: 600;
}

.status--on-time {
  color: var(--status-ok);
}

.status--boarding {
  color: var(--status-ok);
}

.status--delayed {
  color: var(--late);
}

.status--cancelled {
  color: var(--status-cancelled);
}

.row--past {
  opacity: 0.45;
}

.actual-time {
  color: var(--late);
  font-weight: 600;
}

.actual-time::before {
  content: "→ ";
}

.card__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-refresh {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--btn-refresh-border);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-refresh:hover {
  background: var(--btn-refresh-hover);
}

.error-msg {
  padding: 20px;
  text-align: center;
  color: var(--error-ink);
  font-weight: 500;
}

/* ── Theme toggle ────────────────────────────────────────── */
.theme-seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.theme-seg__btn {
  padding: 4px 10px;
  background: none;
  border: none;
  border-left: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-seg__btn:first-child {
  border-left: none;
}

.theme-seg__btn:hover {
  background: var(--seg-hover);
}

.theme-seg__btn--active {
  background: var(--accent);
  color: #fff;
}

.theme-seg__btn--active:hover {
  background: var(--accent);
  opacity: 0.9;
}

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .next-train-card__values {
    gap: 20px;
  }

  .next-train-card__value {
    font-size: clamp(2rem, 4vw + 0.5rem, 3rem);
  }

  .next-train-card__divider {
    height: 44px;
  }
}

@media (max-width: 640px) {
  .next-train-card {
    margin-top: 16px;
    padding: 18px 20px 22px;
    border-radius: 12px;
  }

  .next-train-card__values {
    gap: 14px;
  }

  .next-train-card__value {
    font-size: 2rem;
  }

  .next-train-card__divider {
    height: 36px;
  }

  .page {
    margin: 16px auto;
    width: min(96vw, 100% - 24px);
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  .hero__subtitle {
    font-size: 0.88rem;
  }

  .card {
    margin-top: 16px;
    border-radius: 12px;
  }

  .card__header {
    padding: 12px 16px;
  }

  /* Tabs: compact text */
  .tabs {
    gap: 0;
  }

  .tab {
    padding: 10px 8px;
    font-size: 0.82rem;
  }

  .tab--auto {
    padding: 10px 10px;
    font-size: 0.78rem;
  }

  /* Toolbar: stack vertically */
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 16px;
  }

  .seg {
    margin-left: 0;
    width: 100%;
  }

  .seg__btn {
    flex: 1;
    padding: 8px 6px;
    font-size: 0.75rem;
    text-align: center;
  }

  .static-banner {
    padding: 8px 16px;
    font-size: 0.82rem;
  }

  /* Card-based layout: hide table headers, stack cells */
  .table-wrap {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }

  tbody tr:hover {
    background: rgba(0, 109, 91, 0.05);
  }

  tbody td {
    border-bottom: none;
    padding: 2px 0;
    font-size: 0.88rem;
  }

  /* Route: full width top row */
  tbody td.route {
    grid-column: 1 / -1;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 2px;
  }

  /* Train name: prominent */
  tbody td:nth-child(2) {
    font-weight: 600;
    font-size: 0.95rem;
  }

  /* Status: right-aligned on same row as train */
  tbody td.status {
    text-align: right;
  }

  /* Dep/Arr labels */
  tbody td:nth-child(3)::before {
    content: "Dep ";
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
  }

  tbody td:nth-child(4)::before {
    content: "Arr ";
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
  }

  /* Duration + Platform: smaller, quieter */
  tbody td:nth-child(5),
  tbody td:nth-child(6) {
    font-size: 0.8rem;
    color: var(--muted);
  }

  tbody td:nth-child(5)::before {
    content: "⏱ ";
  }

  tbody td:nth-child(6)::before {
    content: "Pl. ";
  }

  .tooltip::after {
    left: auto;
    right: 0;
    transform: none;
    width: 200px;
  }
}
