:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #5f6570;
  --line-bg: #c8102e;
  --line-text: #ffffff;
  --accent: #0a7d3b;
  --warn: #a15c00;
  --danger: #b3261e;
  --border: #dedcd6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1013;
    --panel: #171a1f;
    --text: #f1f2f4;
    --muted: #9aa1ac;
    --line-bg: #d9253f;
    --accent: #3ddc84;
    --warn: #ffb74d;
    --danger: #ff6b61;
    --border: #2a2e35;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1013;
  --panel: #171a1f;
  --text: #f1f2f4;
  --muted: #9aa1ac;
  --line-bg: #d9253f;
  --accent: #3ddc84;
  --warn: #ffb74d;
  --danger: #ff6b61;
  --border: #2a2e35;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Board ---------- */
.board {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(12px, 3vw, 40px);
  gap: clamp(8px, 2vh, 24px);
  /* Scale with the smaller of width and height so ~8 rows fit a landscape screen. */
  font-size: clamp(16px, min(2.6vw, 3.2vh), 48px);
}
.board header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
}
.board h1 { margin: 0; font-size: 1.2em; font-weight: 700; }
.board .clock { font-variant-numeric: tabular-nums; font-size: 1.2em; font-weight: 600; }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25em; }
.row {
  display: grid;
  grid-template-columns: 3.2em 1fr auto;
  align-items: center;
  gap: 0.6em;
  padding: 0.35em 0.5em;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.3em;
}
.badge {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 2.6em;
  padding: 0.05em 0.3em;
  border-radius: 0.2em;
  background: var(--line-bg);
  color: var(--line-text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.dest { min-width: 0; }
.dest .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.dest .sub { display: block; font-size: 0.5em; color: var(--muted); }
.when { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.when .clocktime { display: block; font-size: 0.5em; font-weight: 500; color: var(--muted); }
.row.arriving .when { color: var(--accent); }
.row.at_stop { border-color: var(--accent); box-shadow: inset 0.25em 0 0 var(--accent); }
.row.at_stop .when { color: var(--accent); }
.row.at_stop .when .label { animation: pulse 1.6s ease-in-out infinite; }
.row.cancelled .name, .row.cancelled .when .label { text-decoration: line-through; color: var(--muted); }
.row.cancelled .sub { color: var(--danger); }
.late { color: var(--warn); }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .row.at_stop .when .label { animation: none; } }

.messages { font-size: 0.55em; color: var(--warn); }
.messages p { margin: 0.2em 0; }
.empty { color: var(--muted); font-size: 0.8em; padding: 1em 0; }
.board footer {
  margin-top: auto;
  font-size: 0.4em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 1em;
}
.board footer .stale { color: var(--danger); font-weight: 600; }

/* ---------- Setup ---------- */
.setup {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  line-height: 1.5;
}
.setup h1 { margin: 0 0 4px; }
.setup p.lead { margin: 0 0 24px; color: var(--muted); }
.setup label { display: block; font-weight: 600; margin: 20px 0 6px; }
.setup input[type="search"], .setup input[type="number"], .setup input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
.results { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.results:empty { display: none; }
.results button {
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  border: 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.results li:first-child button { border-top: 0; }
.results button:hover, .results button:focus-visible { background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label {
  margin: 0;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  cursor: pointer;
}
.options { display: flex; flex-direction: column; gap: 8px; }
.options label {
  margin: 0;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}
.options input { margin-top: 0.3em; }
.hint { color: var(--muted); font-size: 0.9em; margin: 6px 0 0; }
.output {
  margin-top: 28px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.output code { word-break: break-all; }
.output a.open {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--line-bg);
  color: var(--line-text);
  text-decoration: none;
  font-weight: 700;
}
.selected { margin-top: 8px; font-weight: 600; }
