:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.97);
  --border: #1f2a44;
  --text: #e2e8f0;
  --muted: #94a3b8;

  /* MARC system-map line colours (keep in step with LINE_COLORS in config.js) */
  --penn: #C71E3F;
  --camden: #F15929;
  --brunswick: #EFAC1C;
  /* MARC logo colours */
  --marc-blue: #004F98;
  --marc-orange: #F26F21;
  /* Amtrak, from the Sand Patch ticker (navy chips) and the map line core */
  --amtrak-navy: #0b2a4d;
  --amtrak-line: #5b9bd5;

  --amber: #fbbf24;
  --red: #f87171;
  --ok: #8bc34a;
  /* Timing rings, from the Sand Patch ticker: early blue, on time green */
  --early: #4fc3f7;
  --ontime: #8bc34a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 'Archivo', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
#map { position: fixed; inset: 0; }

/* Header and notice text is not text: no selecting it, so clicking it never shows a blinking caret. */
#bar, #notice { user-select: none; -webkit-user-select: none; caret-color: transparent; }
#bar input { user-select: text; -webkit-user-select: text; caret-color: auto; }

/* Header: the dark page colour, with a stripe in the three line colours underneath */
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: #111a2e; color: #fff;
  border-width: 0 0 4px; border-style: solid;
  border-image: linear-gradient(90deg, var(--penn) 0 33.33%, var(--camden) 33.33% 66.66%, var(--brunswick) 66.66% 100%) 1;
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: #fff; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; flex: none; }
/* The mark's lamps take turns like a train working its way through blocks: red (stop, horizontal pair), then
   amber (approach, diagonal pair), then green (clear, vertical pair), about 20 seconds each over a 60 second
   cycle. Each pair is lit for a third of it, then goes out as the next one lights. */
.lamp { opacity: 0.15; animation: lamp-on 60s infinite; }
.lamp.h { fill: #e53935; animation-delay: 0s; }
.lamp.d { fill: #ffb300; animation-delay: -40s; }
.lamp.v { fill: #2ecc71; animation-delay: -20s; }
/* Lamps snap on and off (about half a second of fade), and the next pair lights as this one goes out. */
@keyframes lamp-on {
  0% { opacity: 0.15; }
  0.8% { opacity: 1; }
  32.5% { opacity: 1; }
  33.3% { opacity: 0.15; }
  100% { opacity: 0.15; }
}
@media (prefers-reduced-motion: reduce) {
  .lamp { animation: none; opacity: 1; }
}
.brand-main { font-weight: 800; font-style: italic; font-size: 22px; letter-spacing: -0.01em; }
.brand-word { font-weight: 500; font-size: 15px; letter-spacing: 0.14em; margin-left: -2px; }
#controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex: 1; }
#status { display: flex; gap: 8px; align-items: center; color: rgba(255, 255, 255, 0.85); font-size: 12px; margin-left: auto; }
/* Feed health: a small box per source, coloured by status. Desktop shows MARC / Amtrak;
   mobile (below) shows M / A. */
.dot {
  display: inline-flex; align-items: center; justify-content: center; height: 18px; padding: 0 7px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.35); color: var(--marc-blue); font: 800 11px/1 'Archivo', system-ui, sans-serif;
}
.dot .short { display: none; }
.dot[data-status="ok"] { background: var(--ok); }
.dot[data-status="stale"] { background: var(--amber); }
.dot[data-status="error"] { background: var(--red); color: #fff; }
.navlink { color: #fff; text-decoration: none; border: 1px solid rgba(255, 255, 255, 0.5); padding: 3px 10px; border-radius: 3px; font-weight: 700; font-size: 12px; }
.navlink:hover { background: rgba(255, 255, 255, 0.15); }

#notice {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--panel); border: 1px solid var(--amber); color: var(--amber);
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
}
#notice[hidden] { display: none; }

/* Train markers. MapLibre owns this element's positioning classes (maplibregl-marker...):
   never replace its class list, only add and remove ours (see marker.js). */
.train {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px 2px 5px; border-radius: 999px; cursor: pointer;
  font: 800 11px/1 'Archivo', system-ui, sans-serif; letter-spacing: 0.01em;
  color: #fff; background: var(--c, var(--marc-blue));
  border: 2px solid var(--ring, rgba(255, 255, 255, 0.9));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  white-space: nowrap; user-select: none;
}
.train.line-penn { --c: var(--penn); }
.train.line-camden { --c: var(--camden); }
.train.line-brunswick { --c: var(--brunswick); color: #1a1205; }
.train.marc { z-index: 2; }
/* Amtrak: the ticker's white ID chip with navy text and a navy outline */
.train.amtrak { background: #fff; color: var(--amtrak-navy); border-color: var(--ring, var(--amtrak-navy)); z-index: 0; }
.train.delay-early { --ring: var(--early); }
.train.delay-ontime { --ring: var(--ontime); }
.train.delay-amber { --ring: var(--amber); }
.train.delay-red { --ring: var(--red); }
.train { transition: opacity 0.4s; }
/* Parked or stale trains (see isFaded in lib.js): dimmed until they move or report again. */
.train.faded { opacity: 0.45; }
.train.faded.selected { opacity: 1; }
.train.selected { outline: 3px solid var(--marc-orange); outline-offset: 1px; z-index: 5; }
.labels-off .train .label { display: none; }
.labels-off .train { padding: 3px 4px; }
/* A small plain letter sitting low at the left of a larger number (A67, M538), in the chip's own
   colour and the Archivo font: A on Amtrak chips, M on Penn Line chips. Empty = no badge. */
.badge {
  display: none; align-self: flex-end; margin-right: -3px;
  color: currentColor; font: 800 8px/1 'Archivo', system-ui, sans-serif;
}
.badge:not(:empty) { display: inline-block; }
.train .label { font: 800 12px/1 'Archivo', system-ui, sans-serif; } /* the same size on every chip */
.labels-off .train .badge { display: none; }
/* Inbound MARC trains: a hollow dot while the leading cab end is not reported, filled once it is. */
.lead-dot { display: none; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.train.dot-hollow .lead-dot, .train.dot-filled .lead-dot { display: inline-block; }
.train.dot-filled .lead-dot { background: currentColor; }
.labels-off .train .lead-dot { display: none; }
.arrow {
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 9px solid currentColor; transition: transform 0.3s;
}

/* Controls (on the blue header) */
#q {
  background: rgba(255, 255, 255, 0.14); color: #fff; border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 3px; padding: 5px 9px; min-width: 190px; font: inherit;
}
#q::placeholder { color: rgba(255, 255, 255, 0.7); }
/* Buttons are controls, not text: no text selection, no blinking caret, no tap flash. */
button, .chip { user-select: none; -webkit-user-select: none; caret-color: transparent; -webkit-tap-highlight-color: transparent; }
.chip {
  background: transparent; color: rgba(255, 255, 255, 0.75); border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 3px; padding: 4px 10px; font: 700 12px 'Archivo', system-ui, sans-serif; cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--marc-blue); background: #fff; border-color: #fff; }
.chip.line-penn[aria-pressed="true"] { background: var(--penn); border-color: var(--penn); color: #fff; }
.chip.line-camden[aria-pressed="true"] { background: var(--camden); border-color: var(--camden); color: #fff; }
.chip.line-brunswick[aria-pressed="true"] { background: var(--brunswick); border-color: var(--brunswick); color: #1a1205; }
/* Mobile-only Filters button (desktop shows the controls inline) */
.filters-btn { display: none; }

/* Detail panel: top band takes the line colour */
#panel {
  position: fixed; z-index: 10; top: 66px; right: 12px; width: 320px;
  max-height: calc(100vh - 82px); overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-top: 6px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
#panel[hidden] { display: none; }
#panel[data-line="penn"] { border-top-color: var(--penn); }
#panel[data-line="camden"] { border-top-color: var(--camden); }
#panel[data-line="brunswick"] { border-top-color: var(--brunswick); }
#panel[data-line="amtrak"] { border-top-color: var(--amtrak-line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font: 800 20px/1.2 'Archivo', system-ui, sans-serif; }
.close { background: none; border: 0; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px; }
.panel-sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.gone { color: var(--amber); font-size: 12px; margin-bottom: 6px; }
.loco-block { margin-bottom: 10px; }
.loco-row { display: flex; align-items: baseline; gap: 8px; }
.loco-note { color: var(--muted); font-size: 11px; font-style: italic; margin-top: 2px; }
.lead-badge {
  display: inline-block; margin-top: 4px; padding: 1px 7px; border-radius: 3px;
  font: 800 11px/1.4 'Archivo', system-ui, sans-serif; color: #1a1205;
}
.lead-badge.leading { background: var(--ontime); }
.lead-badge.not-leading { background: var(--amber); }
.turn-note { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.reported-note { color: var(--muted); font-style: italic; }
.loco-model { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 1px; }
.loco-value { font-weight: 700; font-size: 16px; }
.history { margin-left: auto; color: #6fb1ff; font-size: 12px; font-weight: 600; }
.history + .history { margin-left: 0; } /* the loco row already has a gap; two auto margins would push History to the middle */
.stats { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat { display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat-value { font-weight: 700; }
.stat-value.big { font-size: 26px; line-height: 1.1; font-weight: 800; }
/* Panel delay text only: unscoped rules here would also recolour the chips' text */
.stat-value.delay-early { color: var(--early); }
.stat-value.delay-ontime { color: var(--ontime); }
.stat-value.delay-amber { color: var(--amber); }
.stat-value.delay-red { color: var(--red); }
.stops { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 8px; }
.stops th { text-align: left; color: var(--muted); font-weight: 600; padding: 2px 0; white-space: nowrap; }
.stops td { padding: 3px 0; border-top: 1px solid var(--border); }
.stops .time, .stops .delta { text-align: right; font-variant-numeric: tabular-nums; }
.stops .delta { font-weight: 700; }
/* Room before every column after the stop name, so a long stop name cannot jam the headers together */
.stops th:nth-child(n+2), .stops td:nth-child(n+2) { padding-left: 10px; }
.stops tr.depart td { border-top: 0; padding-top: 0; font-size: 11px; }
.stops tr.depart td.stop { color: var(--muted); padding-left: 10px; }
.stops.passed { margin-bottom: 10px; }
.stops.passed td.stop { color: var(--muted); }
/* Stop-table timing colours: the same scheme as the chip rings */
.stops .delay-early { color: var(--early); }
.stops .delay-ontime { color: var(--ontime); }
.stops .delay-amber { color: var(--amber); }
.stops .delay-red { color: var(--red); }
.stops th:nth-child(n+2) { text-align: right; }
.muted { color: var(--muted); font-size: 12px; }

@media (max-width: 700px) {
  /* One slim row; search and chips drop down from the Filters button. */
  #bar { flex-wrap: nowrap; padding: 6px 10px; gap: 8px; }
  .brand-main { font-size: 18px; }
  .brand-mark { width: 22px; height: 22px; }
  .brand-word { font-size: 12px; letter-spacing: 0.1em; }
  .filters-btn {
    display: inline-flex; align-items: center; gap: 5px; margin-left: auto;
    background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 3px;
    padding: 3px 10px; font: 700 12px 'Archivo', system-ui, sans-serif; cursor: pointer;
  }
  #bar.open .filters-btn { background: #fff; color: var(--marc-blue); }
  .filters-btn .count:not(:empty) {
    background: var(--marc-orange); color: #fff; border-radius: 3px; padding: 0 5px; font-size: 11px;
  }
  #status { margin-left: 0; }
  .dot { width: 18px; padding: 0; font-size: 10px; }
  .dot .short { display: inline; }
  .dot .full { display: none; }
  #controls {
    display: none; position: absolute; top: 100%; left: 0; right: 0; flex: none;
    flex-wrap: wrap; gap: 8px; padding: 10px; background: var(--marc-blue);
    border-bottom: 4px solid var(--marc-orange); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
  }
  #bar.open #controls { display: flex; }
  #q { min-width: 0; flex: 1 1 100%; }
  #notice { top: 56px; }
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh;
    border-radius: 10px 10px 0 0; border-width: 6px 0 0;
  }
}
