:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f2f4f7;
  --ink: #16191d;
  --ink-2: #5b6470;
  --ink-3: #8a929d;
  --line: #e2e6ec;
  --accent: #1f4ed8;
  --accent-soft: #e8edfb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);

  --ontime: #1f8a4c;
  --minor: #b07d00;
  --moderate: #d2600a;
  --major: #cf2e2e;
  --unknown: #78828f;
  --network: #000000;
  --train: #1f8a4c;

  /* Straight out of the logo artwork. */
  --brand-ink: #013d6a;
  --brand-accent: #fe920c;
}
[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1b222c;
  --ink: #e8ecf1;
  --ink-2: #a3adba;
  --ink-3: #737d8a;
  --line: #262f3b;
  --accent: #6b93ff;
  --accent-soft: #1d2941;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);

  --ontime: #3fbf75;
  --minor: #e0ae32;
  --moderate: #f2883d;
  --major: #ff6b6b;
  --unknown: #8b95a3;
  --network: #000000;
  --train: #3fbf75;

  /* The logo navy is unreadable on a dark panel; this is its light tint from
     the same artwork. The orange carries over unchanged. */
  --brand-ink: #7cbbe4;
  --brand-accent: #fe920c;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  grid-template-areas: "panel map";
  height: 100%;
}

/* ---------- panel bar (replaces the old top header) ---------- */
.panel-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px 16px;
}
/* Mark above, wordmark below, as one centred unit; the close button is taken
   out of flow so it cannot pull them off centre. The mark is the artwork from
   design/logo.svg; the wordmark is live text, so it stays crisp at any zoom
   and is selectable and translatable. */
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand-mark { height: 64px; width: auto; display: block; }
.brand-name {
  margin: 0;
  font-family: Montserrat, ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  font-size: 19px;
  line-height: 1;
  letter-spacing: .005em;
  white-space: nowrap;
  color: var(--brand-ink);
}
/* Two-tone, as in the logo. */
.brand-name span { color: var(--brand-accent); }

.bar-actions {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 6px;
}
.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }
.icon-btn svg { width: 15px; height: 15px; fill: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }

.only-narrow { display: none; }

/* ---------- panel ---------- */
#panel {
  grid-area: panel;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
  display: flex;
  flex-direction: column;
  z-index: 1100;
}
#list-view, #detail-view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#detail-view[hidden] { display: none; }


.list-scroll, .detail-scroll { overflow-y: auto; overscroll-behavior: contain; flex: 1; }

/* ---------- panel footer: the legal note and the source link ---------- */
.panel-foot {
  flex: none;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.4;
}
.panel-foot p { margin: 0; }
.panel-foot p + p { margin-top: 6px; }
.panel-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }
.panel-foot a:hover { color: var(--accent); }

.group-head {
  position: sticky; top: 0; z-index: 2;
  padding: 9px 12px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3);
}
.group-head small { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-3); }

.row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 7px 12px;
  border: 0; border-bottom: 1px solid var(--line);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.row:hover { background: var(--panel-2); }
.row.selected { background: var(--accent-soft); }
.row.untracked { opacity: .72; }
.num {
  min-width: 42px; padding: 4px 7px;
  border-radius: 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-weight: 650; font-variant-numeric: tabular-nums; text-align: center;
}
.row.selected .num { border-color: var(--accent); }
.route { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 24px 16px; color: var(--ink-3); text-align: center; }

/* ---------- detail ---------- */
.back-btn {
  display: flex; align-items: center; gap: 4px;
  width: 100%; padding: 10px 12px;
  border: 0; border-bottom: 1px solid var(--line);
  background: var(--panel); color: var(--accent); font: inherit; font-weight: 550;
  cursor: pointer; text-align: left;
}
.back-btn svg { width: 16px; height: 16px; fill: currentColor; }
.detail-head { padding: 14px 14px 12px; border-bottom: 1px solid var(--line); }
.detail-head .title { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.detail-head h2 { margin: 0; font-size: 16px; }
.detail-head .when { color: var(--ink-3); font-size: 12.5px; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.fact { background: var(--panel); padding: 9px 14px; }
.fact .k { color: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.fact .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.alerts { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.alert { border-left: 3px solid var(--minor); padding: 2px 0 2px 10px; margin-bottom: 10px; }
.alert:last-child { margin-bottom: 0; }
.alert b { display: block; margin-bottom: 2px; }
.alert p { margin: 0; color: var(--ink-2); font-size: 12.5px; white-space: pre-wrap; }

.stops { padding: 6px 0 24px; }
.stop {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  padding: 7px 14px;
  align-items: baseline;
}
.stop .dot { position: relative; align-self: stretch; }
.stop .dot::before {
  content: ""; position: absolute; left: 6px; top: 7px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3); box-shadow: 0 0 0 2px var(--panel);
}
.stop .dot::after {
  content: ""; position: absolute; left: 9px; top: 7px;
  width: 1px; height: calc(100% + 14px); background: var(--line);
}
.stop:last-child .dot::after { display: none; }
.stop.done .dot::before { background: var(--ontime); }
.stop.next .dot::before { background: var(--accent); width: 11px; height: 11px; left: 4px; }
.stop.done .name { color: var(--ink-3); }
.stop.next { background: var(--accent-soft); }
.stop.next .name { font-weight: 650; }
.stop .times { text-align: right; font-variant-numeric: tabular-nums; font-size: 12.5px; white-space: nowrap; }
.stop .sched { color: var(--ink-3); text-decoration: line-through; margin-right: 5px; }
.stop .eta-chip { color: var(--accent); font-size: 12px; }

/* ---------- map ---------- */
#map-wrap { grid-area: map; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.maplibregl-map { font: inherit; }
.maplibregl-canvas:focus { outline: none; }
.maplibregl-ctrl-group {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
/* Our own control button: MapLibre's icons are background images it inverts for
   dark mode, so this one draws from currentColor and follows the theme directly. */
.gmaps-ctrl { color: var(--ink-2); }
.gmaps-ctrl:hover { color: var(--ink); }
.gmaps-ctrl svg { width: 17px; height: 17px; fill: currentColor; display: block; margin: auto; }
[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
[data-theme="dark"] .maplibregl-ctrl-attrib {
  background: rgba(21, 27, 35, .85); color: var(--ink-2);
}
[data-theme="dark"] .maplibregl-ctrl-attrib a { color: var(--ink-2); }

/* A floating entry point to the train list, now that the header is gone. */
.panel-toggle {
  position: absolute; left: 12px; top: 12px; z-index: 900;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.panel-toggle svg { width: 16px; height: 16px; fill: currentColor; }

.train-marker { width: 30px; height: 30px; }
.train-marker .arrow { width: 30px; height: 30px; transform: rotate(var(--rot, 0deg)); transform-origin: 50% 50%; transition: transform .4s ease; }
.train-marker .arrow path { fill: var(--c, var(--unknown)); stroke: #fff; stroke-width: 1.4; }
[data-theme="dark"] .train-marker .arrow path { stroke: #0d1117; }
.train-marker .tag {
  position: absolute; left: 50%; top: 27px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; line-height: 1.25;
  padding: 1px 5px; border-radius: 5px;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  white-space: nowrap; pointer-events: none;
}
.train-marker .tag-speed { font-size: 9.5px; font-weight: 600; color: var(--ink-2); }
/* Only present when the position has gone stale, so it is allowed to shout a
   little; red once it has been silent long enough to mean something. */
.train-marker .tag-age { font-size: 9.5px; font-weight: 600; color: var(--minor); }
.train-marker .tag-age.cold { color: var(--major); }
.train-marker.selected { z-index: 900 !important; }
.train-marker.selected .arrow { filter: drop-shadow(0 0 0 #fff); }
/* MapLibre positions the marker element itself; keep our ring anchored to it. */
.maplibregl-marker.train-marker { position: absolute; will-change: transform; }
.train-marker.selected::before {
  content: ""; position: absolute; inset: -7px;
  border: 2px solid var(--accent); border-radius: 50%;
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.8); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }


.banner {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  z-index: 950; max-width: min(520px, calc(100% - 24px));
  padding: 8px 14px; border-radius: 10px;
  background: var(--major); color: #fff; box-shadow: var(--shadow);
  font-size: 13px;
}

/* ---------- narrow ---------- */
@media (max-width: 780px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "map"; }
  .only-narrow { display: flex; }
  #panel {
    position: absolute; inset: 0;
    border-right: 0;
    transform: translateY(100%); transition: transform .22s ease;
    z-index: 1300;
  }
  #panel.open { transform: none; }
  }
