:root {
  --ns-yellow: #ffc917;
  --ns-blue: #003082;
  --ic: #1f4fd1;
  --spr: #1ea05a;
  --bg: #0d1117;
  --panel: #11161f;
  --panel-2: #161d28;
  --ink: #e7edf5;
  --muted: #8a95a6;
  --line: #222c3a;
  --led: #ffd23f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 14px;
  flex: 1;
  min-height: 0;
  padding: 14px 14px 8px;
}

/* ---------- stage ---------- */
.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.nameplate {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(90deg, var(--ns-blue), #0a1f52);
  border: 1px solid #0a2a6e;
  border-radius: 10px;
  padding: 10px 14px;
}
.np-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--ns-yellow); box-shadow: 0 0 10px var(--ns-yellow); }
.np-name { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.np-live { margin-left: auto; color: #5dd58c; font-size: 12px; font-weight: 700; letter-spacing: 1px; }
.np-live::first-letter { color: #2bd66f; }

.stage {
  position: relative;
  flex: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a0f24;
  min-height: 0;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.4);
}
#scene {
  display: block;
  width: 100%;
  height: 100%;
}
#scene-labels { position: absolute; inset: 0; pointer-events: none; }

/* floating train tags */
.train-tag {
  position: absolute;
  transform: translate(-50%, -110%);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: rgba(10, 14, 24, 0.86);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
}
.train-tag::after {
  content: "";
  position: absolute;
  bottom: -5px; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(10,14,24,0.86);
}
.tag-cat { font-size: 10px; padding: 1px 5px; border-radius: 4px; color: #fff; }
.tag-ic { background: var(--ic); }
.tag-spr { background: var(--spr); }
.tag-dest { color: #fff; }
.tag-meta { color: var(--muted); font-weight: 500; }
.tag-delay { color: #ff6a6a; font-weight: 800; }

/* ---------- controls ---------- */
.controls { display: flex; align-items: center; gap: 8px; }
.ctrl {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ctrl:hover { border-color: #3a4a63; transform: translateY(-1px); }
.ctrl.on { background: var(--ns-blue); border-color: #1d56c0; }
.sky-phase { margin-left: auto; color: var(--muted); font-size: 13px; }
.sky-phase b { color: var(--ink); }

/* ---------- departures board ---------- */
.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.board-head {
  background: linear-gradient(180deg, #0a1330, #0a0f24);
  padding: 14px 16px;
  border-bottom: 2px solid var(--ns-yellow);
}
.clock {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--led);
  text-shadow: 0 0 14px rgba(255,210,63,0.4);
  line-height: 1;
}
.clock-date { color: var(--muted); font-size: 13px; margin-top: 4px; }
.board-title { margin-top: 8px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--ns-yellow); font-weight: 700; }

.board-cols, .row {
  display: grid;
  grid-template-columns: 64px 44px 1fr 38px 64px;
  gap: 6px;
  align-items: center;
}
.board-cols {
  padding: 8px 14px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.board-rows { flex: 1; overflow-y: auto; }
.row {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  animation: rowin 0.25s ease;
}
@keyframes rowin { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; } }

.c-time { font-family: ui-monospace, Menlo, monospace; font-weight: 700; display: flex; flex-direction: column; line-height: 1.15; }
.t-on { color: var(--ink); }
.t-planned { color: var(--muted); text-decoration: line-through; font-size: 11px; }
.t-delay { color: #ff6a6a; }

.badge { font-size: 11px; font-weight: 800; color: #fff; padding: 2px 6px; border-radius: 5px; }
.badge-ic { background: var(--ic); }
.badge-spr { background: var(--spr); }

.c-dest { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx { color: #ff6a6a; font-size: 11px; font-weight: 700; margin-left: 6px; }

.c-track { text-align: center; }
.trk {
  display: inline-block;
  min-width: 24px;
  padding: 2px 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-weight: 700;
  font-size: 13px;
}

.c-eta { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.eta-soon { color: var(--ns-yellow); }
.eta-now { color: #2bd66f; }
.eta-gone { color: #4a5568; font-size: 12px; }

.row.cancelled .c-dest, .row.cancelled .c-time { opacity: 0.55; }

.board-foot { padding: 10px 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- rotating scenes ---------- */
.scene-layer {
  position: absolute;
  inset: 0;
  transition: opacity 0.9s ease;
}
#scene { display: block; width: 100%; height: 100%; }
.scene-layer.is-hidden { opacity: 0; pointer-events: none; }

/* national map scene */
.nl-scene { background: radial-gradient(120% 120% at 50% 20%, #14233f, #070b16 70%); overflow: hidden; }
.nl-radar, .nl-markers {
  position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  height: 100%; aspect-ratio: 550 / 512;
}
.nl-radar { object-fit: fill; filter: saturate(1.15) contrast(1.05); image-rendering: auto; }
.nl-grad { position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(7,11,22,0.55) 0%, rgba(7,11,22,0) 22%, rgba(7,11,22,0) 70%, rgba(7,11,22,0.65) 100%); }
.nl-markers { pointer-events: none; }
.nl-dot {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 12px; font-weight: 700; color: #fff;
}
.nl-dot::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--d, #2bd66f); box-shadow: 0 0 0 3px rgba(0,0,0,0.35), 0 0 14px var(--d, #2bd66f);
  animation: pulse 2.2s ease-in-out infinite;
}
.nl-dot.major::before { animation-duration: 1.2s; }
.nl-dot .nl-tagtext { text-shadow: 0 1px 3px #000, 0 0 8px #000; font-size: 11px; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.35); } }

.nl-weather {
  position: absolute; top: 16px; left: 16px;
  background: rgba(8,12,22,0.66); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 12px 16px; backdrop-filter: blur(3px); min-width: 150px;
}
.nl-weather .w-temp { font-size: 34px; font-weight: 800; line-height: 1; }
.nl-weather .w-cond { color: var(--muted); font-size: 13px; margin-top: 3px; }
.nl-weather .w-rain { margin-top: 8px; font-size: 13px; font-weight: 700; }
.nl-weather .w-rain.soon { color: #7fb0ff; }
.nl-weather .w-rain.dry { color: #5dd58c; }

.nl-legend { position: absolute; bottom: 14px; left: 16px; display: flex; gap: 12px; font-size: 11px; color: var(--muted); }
.nl-legend .lg { display: flex; align-items: center; gap: 5px; }
.nl-legend .lg::before { content: ""; width: 9px; height: 9px; border-radius: 50%; }
.nl-legend .on-time::before { background: #2bd66f; }
.nl-legend .minor::before { background: #ffb020; }
.nl-legend .major::before { background: #ff5a5a; }
.nl-legend .rain::before { background: #4f8fe0; border-radius: 2px; }
.nl-title { position: absolute; top: 16px; right: 18px; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: rgba(255,255,255,0.6); font-weight: 700; }

/* ---------- always-on info panels ---------- */
.info-panels {
  position: absolute; top: 14px; left: 14px; display: flex; flex-direction: column; gap: 12px;
  width: 220px; pointer-events: none; z-index: 3;
}
.info-panel {
  background: #fbf7ef; border: 3px solid #11161f; border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 26px rgba(0,0,0,0.5);
}
.info-panel:nth-child(odd) { transform: rotate(-0.8deg); }
.info-panel:nth-child(even) { transform: rotate(0.7deg); }
.ip-hdr {
  background: var(--ns-yellow); color: #11161f; font-weight: 800; font-size: 11px;
  letter-spacing: 0.4px; padding: 5px 10px; text-transform: uppercase;
}
.ip-body { padding: 9px 11px 11px; color: #14110d; }
.ip-weather-top { display: flex; align-items: center; gap: 8px; }
.ip-weather-top .wx { font-size: 30px; line-height: 1; }
.ip-weather-top .tmp { font-size: 30px; font-weight: 800; line-height: 1; }
.ip-cond { font-size: 12.5px; font-weight: 600; margin-top: 4px; color: #3a352c; }
.ip-rain { margin-top: 6px; font-size: 12.5px; font-weight: 800; }
.ip-rain.wet { color: #1f6fc0; }
.ip-rain.dry { color: #1f8a4c; }
.ip-delay-row { display: flex; align-items: baseline; gap: 6px; font-size: 13px; font-weight: 700; padding: 2px 0; }
.ip-delay-row .nm { flex: 1; color: #14110d; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-delay-row .mn { font-variant-numeric: tabular-nums; }
.ip-delay-row.minor .mn { color: #c98300; }
.ip-delay-row.major .mn { color: #c01b1b; }
.ip-delay-row.cancel .mn { color: #9b30c0; }
.ip-allgood { font-size: 13px; font-weight: 700; color: #1f8a4c; }

/* ---------- comic-strip insets ---------- */
.comic-strip {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 14px; padding: 14px 16px; align-items: flex-end;
  pointer-events: none; flex-wrap: wrap;
}
.comic-panel {
  width: 248px; background: #fbf7ef; border: 3px solid #11161f; border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.55); overflow: hidden;
  transform-origin: bottom center; animation: panelIn 0.5s cubic-bezier(.2,1.2,.35,1);
}
.comic-panel:nth-child(odd) { transform: rotate(-1.2deg); }
.comic-panel:nth-child(even) { transform: rotate(1deg); }
.comic-panel.out { animation: panelOut 0.4s forwards; }
.comic-panel .hdr {
  display: flex; align-items: center; gap: 6px; padding: 5px 9px;
  background: var(--ns-yellow); color: #11161f; font-weight: 800; font-size: 11px; letter-spacing: 0.3px;
}
.comic-panel .hdr .pl { background: #11161f; color: #fff; border-radius: 4px; padding: 1px 5px; }
.comic-panel .hdr .badge { font-size: 10px; padding: 1px 5px; }
.comic-panel .hdr .late { margin-left: auto; color: #c01b1b; }
.comic-panel canvas { display: block; width: 100%; height: 132px; background: #0a0f24; }
.comic-panel .cap {
  padding: 8px 11px 10px; color: #14110d; font-size: 13.5px; line-height: 1.28; font-weight: 600;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe Print", system-ui, sans-serif;
}
@keyframes panelIn { from { transform: translateY(26px) scale(0.9); opacity: 0; } }
@keyframes panelOut { to { transform: translateY(26px) scale(0.9); opacity: 0; } }

/* ---------- ticker ---------- */
.ticker {
  display: flex; align-items: stretch; height: 42px; flex: 0 0 auto;
  background: linear-gradient(180deg, #0a1330, #070b18);
  border-top: 2px solid var(--ns-yellow);
}
.ticker-label {
  display: flex; align-items: center; padding: 0 16px; font-weight: 800;
  font-size: 13px; letter-spacing: 1px; color: #0a0f1c; background: var(--ns-yellow);
  white-space: nowrap;
}
.ticker-viewport { position: relative; flex: 1; overflow: hidden; }
.ticker-track {
  position: absolute; top: 0; left: 0; height: 100%; display: flex; align-items: center;
  white-space: nowrap; font-size: 14px; font-weight: 600; will-change: transform;
  animation: ticker-scroll 60s linear infinite;
}
.ticker-track:hover { animation-play-state: paused; }
.ticker-item { padding: 0 14px; }
.ticker-item .t-rail { color: var(--ns-yellow); }
.ticker-item .t-road { color: #7fc4ff; }
.ticker-item .t-sep { color: #3a4a63; padding: 0 4px; }
.ticker-item b { color: #ff7a7a; }
@keyframes ticker-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------- responsive: phones / narrow screens ---------- */
@media (max-width: 820px) {
  /* let the page grow + scroll instead of locking to one screen */
  body { height: auto; min-height: 100vh; min-height: 100dvh; overflow-y: auto; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;     /* stage, then board */
    gap: 10px;
    padding: 10px 10px 6px;
  }
  .stage-wrap { gap: 8px; }
  .nameplate { padding: 8px 12px; border-radius: 9px; }
  .np-name { font-size: 17px; }
  .np-live { font-size: 11px; }

  /* stage gets a fixed, tall-ish slice; canvas auto-sizes to it */
  .stage { height: 46vh; min-height: 260px; flex: none; }

  /* controls wrap to multiple rows */
  .controls { flex-wrap: wrap; gap: 6px; }
  .ctrl { padding: 6px 11px; font-size: 12px; }
  .sky-phase { width: 100%; margin-left: 0; order: 5; }

  /* info panels: smaller so they don't swamp the small stage */
  .info-panels { width: 44vw; max-width: 168px; top: 8px; left: 8px; gap: 8px; }
  .info-panel { border-width: 2px; border-radius: 9px; }
  .info-panel:nth-child(odd), .info-panel:nth-child(even) { transform: none; }
  .ip-hdr { font-size: 9px; padding: 4px 7px; letter-spacing: 0.2px; }
  .ip-body { padding: 6px 8px; }
  .ip-weather-top .wx, .ip-weather-top .tmp { font-size: 22px; }
  .ip-cond { font-size: 10.5px; margin-top: 2px; }
  .ip-rain, .ip-delay-row, .ip-allgood { font-size: 11px; }

  /* comic-strip panels: smaller, still legible */
  .comic-strip { gap: 8px; padding: 8px; }
  .comic-panel { width: 42vw; max-width: 188px; border-width: 2px; }
  .comic-panel canvas { height: 88px; }
  .comic-panel .hdr { font-size: 9px; padding: 4px 7px; }
  .comic-panel .cap { font-size: 11px; padding: 6px 8px 7px; }

  /* departures board full-width below the stage */
  .board { max-height: none; }
  .board-head { padding: 12px 14px; }
  .clock { font-size: 30px; }
  .board-cols, .row { grid-template-columns: 52px 40px 1fr 30px 54px; gap: 5px; padding-left: 12px; padding-right: 12px; }
  .row { font-size: 13px; padding-top: 9px; padding-bottom: 9px; }

  /* ticker sits naturally at the bottom of the page */
  .ticker { height: 38px; }
  .ticker-label { padding: 0 12px; font-size: 12px; }
  .ticker-track { font-size: 13px; }
}

/* very small phones */
@media (max-width: 380px) {
  .info-panels { max-width: 140px; }
  .clock { font-size: 26px; }
  .np-name { font-size: 15px; }
}
