:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5d6573;
  --border: #dde1e7;
  --accent: #0039a6;       /* Harlem blue */
  --hudson: #009b3a;
  --newhaven: #ee0034;
  --heritage: #b7791f;
  --good: #1b7f4b;
  --warn: #b45309;
  --bar: #c9d6f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --border: #2c313a;
    --accent: #7ea6ff;
    --heritage: #f0b44c;
    --good: #4ccf8b;
    --warn: #f59e0b;
    --bar: #2d3d63;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 700; color: var(--text); }
.brand .rr {
  font-weight: 600; font-size: 12px; margin-left: 4px; padding: 1px 7px; border-radius: 999px;
  color: var(--muted); border: 1px solid var(--border); vertical-align: 2px;
}
nav { display: flex; gap: 14px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; }
nav a.active { color: var(--text); border-bottom-color: var(--accent); }
#search { margin-left: auto; display: flex; gap: 6px; }
input, select, button {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
footer { max-width: 1200px; margin: 0 auto; padding: 8px 16px 32px; font-size: 13px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px;
  min-width: 0;
}
.card.heritage { border-left: 4px solid var(--heritage); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.unit-no { font-size: 24px; font-weight: 700; }
.scheme { color: var(--heritage); font-weight: 600; }
.badge {
  display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.badge.live { background: var(--good); border-color: var(--good); color: #fff; }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.badge.her { border-color: var(--heritage); color: var(--heritage); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.steps { list-style: none; margin: 6px 0 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 62px 56px 1fr 58px; gap: 6px; align-items: center; padding: 3px 0; }
.steps li.past { opacity: .5; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.prob { position: relative; height: 16px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.prob span { position: absolute; inset: 0 auto 0 0; background: var(--bar); }
.prob b { position: relative; font-size: 11px; font-weight: 500; padding-left: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); font-size: 13px; }
.chip.her { border-color: var(--heritage); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stop-done { color: var(--muted); }
.late { color: var(--warn); }
.empty { padding: 20px; text-align: center; color: var(--muted); }
/* ---- light & spotting ---- */
.badge.light-day { background: #fde68a; border-color: #f59e0b; color: #5b3a00; }
.badge.light-golden { background: #fdba74; border-color: #ea580c; color: #4a1d00; }
.badge.light-twilight { background: #c4b5fd; border-color: #7c3aed; color: #2e1065; }
.badge.light-night { background: #1f2937; border-color: #111827; color: #d1d5db; }
table.stops td { padding: 3px 6px; font-size: 14px; }
table.stops td:first-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.card.catch h3 { margin: 0; }
.card.catch .card-head { flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
#spots-form label { display: flex; gap: 6px; align-items: center; }

/* ---- map ---- */
main.wide { max-width: none; padding: 0; }
.map-layout { display: grid; grid-template-columns: 1fr 320px; height: calc(100vh - 53px); }
#map { height: 100%; min-height: 360px; background: var(--bg); }
.map-panel { overflow-y: auto; border-left: 1px solid var(--border); background: var(--surface); padding: 12px 14px; }
.map-panel h1 { font-size: 18px; margin: 0 0 4px; }
.map-panel label { display: block; font-size: 14px; margin: 4px 0; }
.unit-list { list-style: none; padding: 0; margin: 10px 0 0; }
.unit-list li { padding: 7px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.unit-list li:hover .u { text-decoration: underline; }
.unit-list .u { font-weight: 700; font-size: 16px; }
.unit-list .sub { font-size: 13px; color: var(--muted); }
.loco-pin {
  display: inline-flex; align-items: center; gap: 2px; transform: translate(-50%, -50%);
  font: 700 12px/1 system-ui, sans-serif; padding: 4px 6px; border-radius: 6px; white-space: nowrap;
  background: #1f2430; color: #fff; border: 2px solid var(--line, #888); box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.loco-pin.her { background: #f0b44c; color: #231a05; border-color: #7a4e0c; font-size: 14px; padding: 5px 8px; }
.loco-pin.focus { outline: 3px solid var(--accent); }
.emu-dot {
  width: 10px; height: 10px; border-radius: 50%; transform: translate(-50%, -50%);
  background: var(--line, #888); border: 1.5px solid #fff; box-shadow: 0 0 2px rgba(0,0,0,.5);
}
.leaflet-div-icon { background: none; border: none; }
/* Muted basemap so equipment and lines stand out; dimmed further in dark mode. */
.basemap { filter: grayscale(0.85) contrast(0.9) brightness(1.05); }
@media (prefers-color-scheme: dark) {
  .basemap { filter: grayscale(1) invert(1) brightness(0.85) contrast(0.9); }
}
.leaflet-popup-content { font: 14px/1.4 system-ui, sans-serif; margin: 10px 12px; min-width: 220px; }
.popup-unit { font-size: 18px; font-weight: 700; }
.popup-next { margin: 4px 0 0; padding-left: 16px; }
.leaflet-container a { color: #0039a6; }
@media (max-width: 800px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  .map-panel { border-left: none; border-top: 1px solid var(--border); }
}
@media (max-width: 640px) {
  #search { margin-left: 0; width: 100%; }
  #search input { flex: 1; }
  .grid { grid-template-columns: 1fr; }
}
