:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --fg: #18181b;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e5e7eb;
  --accent: #b91c1c;
  --accent-bus: #1d4ed8;
  --soon: #166534;
  --gone: #9ca3af;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --fg: #f4f4f5;
    --muted: #9ca3af;
    --card: #161618;
    --border: #27272a;
    --accent: #f87171;
    --accent-bus: #60a5fa;
    --soon: #4ade80;
    --gone: #52525b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "ss01" 1;
  padding: 24px 16px 48px;
  max-width: 720px;
  margin-inline: auto;
}

header {
  margin-bottom: 24px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

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

.now {
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented button:hover {
  color: var(--fg);
}

.segmented button[aria-selected="true"] {
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  .segmented button[aria-selected="true"] {
    background: var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

.when {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 12px;
  margin: 0 0 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  gap: 0;
}

.when legend { display: none; }

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

.when-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.when-row + .when-row {
  border-top: 1px solid var(--border);
}

.when-row.inactive {
  opacity: 0.4;
}

.when-row.inactive .when-label,
.when-row.inactive input[type="time"],
.when-row.inactive input[type="date"] {
  cursor: pointer;
}

.when-row input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
}

.when-label {
  flex: 1;
  font-weight: 500;
}

.when-inputs {
  display: flex;
  gap: 6px;
  align-items: center;
}

.when-row input[type="time"],
.when-row input[type="date"] {
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.when-row input[type="time"] {
  min-width: 110px;
}

.when-row input[type="date"] {
  min-width: 140px;
}

.when-row input[type="time"]:focus,
.when-row input[type="date"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

.route {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.route header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 12px;
  gap: 12px;
}

.route h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.route .mode-train h2 { color: var(--accent); }
.route .mode-bus h2 { color: var(--accent-bus); }

.next {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.1;
}

.next .relative {
  font-size: 15px;
  font-weight: 500;
  color: var(--soon);
  margin-left: 8px;
}

.next.gone {
  color: var(--gone);
  font-size: 18px;
}

.upcoming {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.upcoming li {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.arrives {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.details {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.live-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
.live-link:hover { color: var(--fg); }

footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

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

.status.updating::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.skeleton .skel {
  background: var(--border);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.skeleton .skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.5) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s infinite;
}

@media (prefers-color-scheme: dark) {
  .skeleton .skel::after {
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.06) 50%,
      transparent 100%
    );
  }
}

.skel-header { height: 16px; width: 55%; margin-bottom: 14px; }
.skel-time   { height: 30px; width: 45%; margin-bottom: 8px; }
.skel-line   { height: 13px; width: 70%; }

@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton .skel::after,
  .status.updating::before { animation: none; }
}

.fine {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.fine a { color: var(--muted); }
.fine a:hover { color: var(--fg); }
