:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #0b6e4f;
  --accent-contrast: #ffffff;
  --notice-bg: #fff7e6;
  --notice-text: #8a5a00;
  --error-bg: #fdecec;
  --error-text: #b3261e;
  --best-bg: #e8f7ef;
  --alert-bg: #fdecec;
  --alert-text: #b3261e;
  --promo-bg: #eaf2ff;
  --promo-text: #1a4fa0;
  --express-bg: #1a4fa0;
  --express-contrast: #ffffff;
  --regular-bg: #e2e4e9;
  --regular-contrast: #4b5160;
  --warn-bg: #fff1e0;
  --warn-text: #9a5b00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1d2025;
    --text: #eceef1;
    --muted: #9aa1ab;
    --border: #2c3038;
    --accent: #2fbf82;
    --accent-contrast: #0a0c0e;
    --notice-bg: #3a2f10;
    --notice-text: #f3c968;
    --error-bg: #3a1616;
    --error-text: #ff8a80;
    --best-bg: #123425;
    --alert-bg: #3a1616;
    --alert-text: #ff8a80;
    --promo-bg: #16233a;
    --promo-text: #8ab4ff;
    --express-bg: #2f5fc7;
    --express-contrast: #ffffff;
    --regular-bg: #2c3038;
    --regular-contrast: #b7bcc6;
    --warn-bg: #3a2c10;
    --warn-text: #f3b968;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 32px;
}

.banner-stack {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
}

.banner.alert { background: var(--alert-bg); color: var(--alert-text); }
.banner.promo { background: var(--promo-bg); color: var(--promo-text); }
.banner.info { background: var(--notice-bg); color: var(--notice-text); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 560px;
}

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

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 4px;
}

#search-form {
  display: grid;
  gap: 14px;
}

.station-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}

#reverse-btn {
  height: 44px;
  width: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.mode-row {
  display: flex;
  gap: 16px;
  font-size: 0.9rem;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
}

select, input, button {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  font-weight: 600;
  cursor: pointer;
  width: auto;
}

#search-form > button[type="submit"] {
  width: 100%;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.time-relative {
  margin: -4px 0 0;
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--regular-bg);
  color: var(--muted);
}

.time-relative.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.time-relative.past {
  background: var(--error-bg);
  color: var(--error-text);
}

.notice {
  margin-top: 16px;
  background: var(--notice-bg);
  color: var(--notice-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.error {
  margin-top: 16px;
  background: var(--error-bg);
  color: var(--error-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.results-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tr.best {
  background: var(--best-bg);
}

.slot-tag {
  font-size: 0.72rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge.express { background: var(--express-bg); color: var(--express-contrast); }
.badge.regular { background: var(--regular-bg); color: var(--regular-contrast); }

.stops-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  padding: 6px 10px;
  font-weight: 600;
}

tr.stops-row td {
  white-space: normal;
  background: var(--bg);
}

.stops-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 8px 4px;
  font-size: 0.85rem;
}

.stops-list .stop {
  display: flex;
  gap: 6px;
  color: var(--muted);
}

.stops-list .stop .name {
  color: var(--text);
  font-weight: 500;
}

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

.notify-sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.notify-row {
  display: flex;
  gap: 8px;
}

.notify-row input {
  flex: 1;
}

/* ---- Mobile: card-style rows instead of a cramped table ---- */
@media (max-width: 560px) {
  body { padding: 12px 8px 24px; }

  .card { padding: 16px; border-radius: 10px; }

  .header-row { flex-direction: column; align-items: flex-start; gap: 2px; }

  table, thead, tbody, th, td, tr {
    display: block;
  }

  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  #results tbody tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 6px 10px;
  }

  #results tbody tr.stops-row {
    border: none;
    margin: -6px 0 10px;
    padding: 0 4px;
  }

  #results td {
    border-bottom: none;
    padding: 6px 0;
    white-space: normal;
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  #results td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
  }

  #results td.slot-cell::before,
  #results td.stops-cell::before {
    content: "";
  }

  .stops-list { padding: 4px 0; }
}
