:root {
  --bg: #0c1222;
  --panel: #141c30;
  --panel-2: #1b2540;
  --ink: #eef2fb;
  --muted: #8a97b4;
  --accent: #ffd23f;      /* trentbarton yellow-ish */
  --live: #2fd47a;
  --live-dim: #1c6b45;
  --line: #26324f;
  --south: #4aa3ff;
  --north: #ff8c5a;
  font-size: clamp(15px, 1.6vw, 20px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #182038 0%, transparent 60%), var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.9rem; }
.route-badge {
  background: var(--accent);
  color: #1a1400;
  font-weight: 800;
  font-size: 1.6rem;
  padding: 0.25rem 0.7rem;
  border-radius: 0.5rem;
  letter-spacing: 0.5px;
}
.brand-text h1 { margin: 0; font-size: 1.55rem; font-weight: 700; }
.brand-text p { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.6px; text-transform: uppercase; }
.clock { text-align: right; }
#clock-time { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
#clock-date { font-size: 0.85rem; margin-top: 0.15rem; }

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem 1.4rem;
  min-height: 0;
}
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  min-height: 0;
}
@media (max-width: 1000px) {
  .stage { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .board { grid-template-columns: 1fr; }
}

.column {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.column-head h2 { margin: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 0.5rem; }
.column.south .arrow { color: var(--south); }
.column.north .arrow { color: var(--north); }

.live-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--live-dim); color: #d8ffe9;
  font-size: 0.78rem; font-weight: 600;
  padding: 0.25rem 0.6rem; border-radius: 999px;
  border: 1px solid var(--live);
}
.live-pill.off { background: transparent; color: var(--muted); border-color: var(--line); }
.pulse { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 rgba(47,212,122,0.7); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,212,122,0.6);} 70%{box-shadow:0 0 0 8px rgba(47,212,122,0);} 100%{box-shadow:0 0 0 0 rgba(47,212,122,0);} }

.stops { list-style: none; margin: 0; padding: 0.3rem 0.4rem; overflow-y: auto; }
.stop {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.6rem;
  border-radius: 0.5rem;
}
.stop:nth-child(odd) { background: rgba(255,255,255,0.02); }
.stop-name { font-weight: 600; font-size: 1rem; }
.deps { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }

.dep {
  display: inline-flex; flex-direction: column; align-items: flex-end;
  min-width: 3.4rem; padding: 0.25rem 0.55rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.5rem;
}
.dep.first { background: #223154; border-color: #33456f; }
.dep .eta { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.dep .at { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dep.due .eta { color: var(--accent); }
.dep.live { border-color: var(--live); }
.dep.live .eta::after {
  content: ""; display: inline-block; width: 0.5rem; height: 0.5rem; margin-left: 0.35rem;
  border-radius: 50%; background: var(--live); vertical-align: middle;
}
.dep.tomorrow { opacity: 0.6; }
.dep.tomorrow .at::before { content: "+1 "; }
/* Live delay estimate (from bus position). Predicted chips show the shifted
   time in .at; this tag says how far off timetable the bus is running. */
.dep .delay { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.02em; line-height: 1.1; margin-top: 0.05rem; }
.dep .delay.late { color: #ffb24d; }
.dep .delay.early { color: #7fb4ff; }
.dep .delay.ontime { color: var(--live); }
.dep.predicted { border-color: var(--live); }
.none { color: var(--muted); font-style: italic; font-size: 0.9rem; }

/* ---- Ask the board ---- */
#ask {
  margin: 0 1.4rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.7rem 0.9rem;
}
#ask-form { display: flex; gap: 0.6rem; }
#ask-input {
  flex: 1; min-width: 0;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 0.6rem;
  padding: 0.65rem 0.8rem; font: inherit; font-size: 1rem;
}
#ask-input::placeholder { color: var(--muted); }
#ask-input:focus { outline: none; border-color: var(--accent); }
#ask-btn {
  background: var(--accent); color: #1a1400; font-weight: 700; font-size: 1rem;
  border: none; border-radius: 0.6rem; padding: 0 1.3rem; cursor: pointer;
}
#ask-btn:disabled { opacity: 0.5; cursor: default; }
.ask-answer {
  margin-top: 0.7rem; padding: 0.7rem 0.85rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.6rem;
  font-size: 1rem; line-height: 1.45; white-space: pre-wrap;
}
.ask-answer.thinking { color: var(--muted); font-style: italic; }
.ask-answer.error { border-color: #ff5d5d; }
.ask-answer .ask-icon { color: var(--accent); font-weight: 700; margin-right: 0.4rem; }

footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.6rem 1.4rem;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8rem;
}
#feed-status { display: inline-flex; align-items: center; gap: 0.45rem; }
#feed-status .dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); }
#feed-status.ok .dot { background: var(--live); }
#feed-status.stale .dot { background: var(--accent); }
#feed-status.err .dot { background: #ff5d5d; }
.muted { color: var(--muted); }
.loading { padding: 3rem; text-align: center; color: var(--muted); grid-column: 1 / -1; }

.veh-note { font-size: 0.78rem; color: #cfeede; padding: 0 1rem 0.5rem; }

/* ---- Live map ---- */
#map-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.map-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: 0.95rem; font-weight: 600;
}
.map-legend { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 500; color: var(--muted); font-size: 0.82rem; }
.map-legend .key { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.2rem; vertical-align: middle; }
.map-legend .key.south { background: var(--south); }
.map-legend .key.north { background: var(--north); }
.map-legend .key.stop { background: var(--accent); border: 1px solid #1a1400; }
#map { flex: 1; min-height: 260px; width: 100%; background: #0b1120; }
@media (max-width: 1000px) { #map { height: 42vh; flex: none; } }
.leaflet-container { background: #0b1120; font: inherit; }

/* OpenStreetMap's tiles are light. Inverting the tile pane only (not the whole
   map) darkens the basemap while leaving markers, popups and controls alone.
   hue-rotate puts the colours back the right way round after the invert. */
.leaflet-tile-pane {
  /* grayscale kills the olive cast the invert leaves on OSM's greens */
  filter: invert(1) hue-rotate(180deg) grayscale(0.75) brightness(0.88) contrast(1.05);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--ink); }
.leaflet-popup-content { margin: 0.6rem 0.8rem; font-size: 0.85rem; }
.bus-label { font-weight: 700; }
.no-buses-note { position: absolute; z-index: 500; top: 3rem; left: 50%; transform: translateX(-50%);
  background: rgba(20,28,48,0.9); border: 1px solid var(--line); color: var(--muted);
  padding: 0.3rem 0.8rem; border-radius: 999px; font-size: 0.8rem; pointer-events: none; }

/* Bus marker = triangular arrow pointing in the direction of travel (bearing). */
.bus-arrow {
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 18px solid var(--south);
  margin: 4px auto 0;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.7));
  transform-origin: 50% 60%;
}
.bus-arrow.north { border-bottom-color: var(--north); }
.bus-arrow.south { border-bottom-color: var(--south); }
.hatton-marker { width: 14px; height: 14px; background: var(--accent); border: 2px solid #1a1400; border-radius: 3px; box-shadow: 0 0 6px rgba(255,210,63,0.8); }
.hatton-text { color: var(--accent); font-size: 11px; font-weight: 700; text-shadow: 0 0 4px #000; white-space: nowrap; transform: translate(12px,-14px); }

/* ---- Phones ----
   The default layout is a fixed-height wall-dashboard: .stage fills the screen
   and each stop list scrolls inside its card. On a phone that hides all but one
   stop, so here we unwind that — let the PAGE scroll and every stop show. */
@media (max-width: 640px) {
  :root { font-size: 16px; }                    /* stable base; stop shrinking with vw */

  header { padding: 0.7rem 1rem; gap: 0.7rem; }
  .brand { gap: 0.6rem; }
  .route-badge { font-size: 1.25rem; padding: 0.18rem 0.5rem; }
  .brand-text h1 { font-size: 1.2rem; }
  .brand-text p { font-size: 0.66rem; letter-spacing: 0.4px; }
  #clock-time { font-size: 1.55rem; }
  #clock-date { font-size: 0.72rem; }

  .stage { flex: none; padding: 0.7rem 0.8rem; gap: 0.8rem; }
  .board { gap: 0.8rem; }

  /* Cards size to their content; the page scrolls instead of each list. */
  .column { overflow: visible; }
  .stops { overflow: visible; padding: 0.25rem 0.4rem; }

  .column-head { padding: 0.6rem 0.8rem; }
  .column-head h2 { font-size: 1.1rem; flex-shrink: 0; }
  .live-pill { font-size: 0.7rem; padding: 0.2rem 0.5rem; min-width: 0; }
  .live-pill .pulse { flex-shrink: 0; }

  .stop { padding: 0.5rem 0.55rem; gap: 0.5rem; }
  .stop-name { font-size: 0.98rem; }
  .deps { gap: 0.35rem; }
  .dep { min-width: 2.9rem; padding: 0.22rem 0.45rem; }
  .dep .eta { font-size: 1rem; }
  .dep .at { font-size: 0.68rem; }
  /* Keep the two soonest departures per stop on the narrowest phones so the
     card stays glanceable; the rest remain on the live map + board on desktop. */
  .deps .dep:nth-child(n+4) { display: none; }

  #ask { margin: 0 0.8rem 0.8rem; padding: 0.6rem 0.75rem; }
  #ask-btn { padding: 0 1rem; }
  #map { height: 46vh; min-height: 300px; }
  footer { padding: 0.6rem 0.9rem; font-size: 0.72rem; gap: 0.6rem; flex-wrap: wrap; }
}
