:root {
  --bg: #f5f6f8;
  --text: #1f2430;
  --muted-text: #6b7280;
  --card-bg: #fff;
  --border-color: #e5e7eb;
  --accent: #0078d7;
  --live-color: #16a34a;
  --direction-a-bg: #e8f1fc;
  --direction-a-text: #0056a3;
  --direction-a-border: #bcdcfb;
  --direction-b-bg: #fdf1e7;
  --direction-b-text: #b1580a;
  --direction-b-border: #f8d9b8;
  --alert-bg: #fef2f2;
  --alert-border: #fca5a5;
  --alert-text: #991b1b;
  --toggle-bg: #1f2430;
  --toggle-text: #fff;
  --radius-sm: 6px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 8%);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 10%);
}

body.dark {
  --bg: #0f1115;
  --text: #e5e7eb;
  --muted-text: #9aa1ac;
  --card-bg: #1a1d23;
  --border-color: #2c2f36;
  --accent: #4da3ff;
  --live-color: #34d399;
  --direction-a-bg: #16324f;
  --direction-a-text: #8fc7ff;
  --direction-a-border: #234869;
  --direction-b-bg: #4a2f16;
  --direction-b-text: #ffbf80;
  --direction-b-border: #6b4322;
  --alert-bg: #3a1414;
  --alert-border: #7f1d1d;
  --alert-text: #fca5a5;
  --toggle-bg: #e5e7eb;
  --toggle-text: #0f1115;
}

body {
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 12px;
}

/* Several elements below set their own `display` (flex, etc.) at the same
   specificity as the browser's built-in [hidden] rule, which would
   otherwise stay visible when toggled via the hidden attribute/property. */
[hidden] {
  display: none !important;
}

main,
footer {
  margin: 0 auto 16px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
}

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

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

h3 {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-text);
  margin: 20px 0 10px;
}

.trip-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trip-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trip-field-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted-text);
}

.trip-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trip-button {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.trip-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.trip-message {
  margin: 0;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  font-size: 1rem;
}

.trip-loading {
  color: var(--muted-text);
  font-style: italic;
}

.trip-fallback {
  border-left: 4px solid var(--accent);
  margin-bottom: 10px;
}

.trip-total {
  margin: 0 0 16px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 15%, var(--card-bg));
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-sm);
}

.trip-total-summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.trip-total-summary::-webkit-details-marker {
  display: none;
}

.trip-total-summary::after {
  content: "▸";
  margin-left: 8px;
  font-size: 0.7rem;
  color: var(--muted-text);
}

.trip-total[open] .trip-total-summary::after {
  content: "▾";
}

.trip-total-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-text);
}

.trip-total-value {
  margin-left: auto;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.trip-total-value .unit {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted-text);
}

.trip-total-breakdown {
  list-style: none;
  margin: 12px 0 0;
  padding: 12px 0 0;
  border-top: 1px dashed var(--accent);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trip-total-breakdown li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text);
}

.trip-total-note {
  margin: -10px 0 16px;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--muted-text);
}

.trip-step {
  margin-bottom: 16px;
}

.trip-step-label {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.trip-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.trip-preview-card {
  flex: 1 1 200px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  opacity: 0.9;
}

.trip-preview-fastest {
  border-color: var(--live-color);
  opacity: 1;
}

.trip-recommendation {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--live-color) 12%, transparent);
  color: var(--text);
  font-size: 0.85rem;
}

.stop,
.rail-station {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stop-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.stop-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.stop-id {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-text);
}

.stop-loading,
.stop-error {
  font-size: 0.9rem;
  color: var(--muted-text);
  padding: 8px 0;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--direction-a-bg);
  color: var(--direction-a-text);
  border: 1px solid var(--direction-a-border);
  vertical-align: middle;
}

.connection-section {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
}

.connection-section:first-of-type {
  margin-top: 4px;
  padding-top: 0;
  border-top: none;
}

.connection-label {
  margin: 0 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-text);
}

.direction-group {
  margin-top: 10px;
}

.direction-group:first-of-type {
  margin-top: 4px;
}

.direction-group-muted {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
  opacity: 0.85;
}

.direction-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.direction-badge.direction-a {
  background: var(--direction-a-bg);
  color: var(--direction-a-text);
  border: 1px solid var(--direction-a-border);
}

.direction-badge.direction-b {
  background: var(--direction-b-bg);
  color: var(--direction-b-text);
  border: 1px solid var(--direction-b-border);
}

.direction-icon {
  flex-shrink: 0;
}

.prediction {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.live-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--live-color);
  animation: live-pulse 1.8s infinite;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--live-color) 45%, transparent);
  }

  70% {
    box-shadow: 0 0 0 6px transparent;
  }

  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.prediction-minutes {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.prediction-minutes .unit {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted-text);
}

.prediction-detail {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted-text);
}

.prediction-detail b {
  font-weight: 400;
}

.schedule-item {
  margin: 4px 0;
  font-size: 0.85rem;
  color: var(--muted-text);
}

.alert-banner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--alert-bg);
  border: 1px solid var(--alert-border);
  color: var(--alert-text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.alert-banner-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}

.alert-banner-header::-webkit-details-marker {
  display: none;
}

.alert-banner-header::after {
  content: "▾";
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0.7;
}

.alert-banner:not([open]) .alert-banner-header::after {
  content: "▸";
}

.alert-banner-header h2 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.alert-icon {
  flex-shrink: 0;
}

.alert-item {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
}

#theme-toggle {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 16px;
  background-color: var(--toggle-bg);
  color: var(--toggle-text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

#refresh-timer {
  width: fit-content;
  margin: 14px auto 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  font-size: 0.72rem;
  color: var(--muted-text);
}

.card-deck {
  position: relative;
}

.deck-bar {
  height: 2px;
  margin: 10px 0;
  border-radius: 2px;
  background: var(--border-color);
  overflow: hidden;
}

.deck-bar-fill {
  height: 100%;
  width: calc(var(--refresh-progress, 1) * 100%);
  background: var(--accent);
  opacity: 0.55;
  transition: width 1s linear;
}

@media (width >= 600px) {
  main,
  footer {
    max-width: 600px;
    margin: 20px auto;
    padding: 20px;
    box-shadow: var(--shadow-md);
  }
}
