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

body {
  background: #050a1e;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#map {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Map starts invisible; placeholder is shown via viewBox.
   Once JS initializes, it hides the placeholder, removes viewBox,
   builds the dynamic map, then fades everything in via .map-ready. */
#map.map-loading {
  opacity: 0;
}

#map.map-ready {
  opacity: 1;
  transition: opacity 0.6s ease;
}

/* Canvas overlay — train visuals rendered here instead of SVG.
   pointer-events:none lets clicks pass through to the SVG below. */
#trains-canvas {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
}

/* --- Cursor flashlight overlay --- */
#cursor-light {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  background: black;
}

#cursor-light.active {
  background: radial-gradient(circle 850px at 50% 50%, transparent 0%, rgba(0, 0, 0, 0.9) 100%);
}

/* --- Close button (visible when tracking a train) --- */
#close-btn {
  display: none;
  position: fixed;
  top: 28px;
  right: 28px;
  z-index: 100;
  width: 70px;
  height: 70px;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 45px;
  font-weight: 100;
  line-height: 45px;
  text-align: center;
  cursor: pointer;
  transition: color 0.15s;
  padding: 0;
}

#close-btn:hover {
  color: #fff;
}

#close-btn.visible {
  display: block;
}

/* --- Bottom-of-screen line color glow (visible when a train is selected) --- */
#line-glow {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 35%;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.6s ease;
  background: linear-gradient(to top, var(--glow-line-color, transparent) 0%, transparent 100%);
}

#line-glow.visible {
  opacity: 0.25;
}

.lines-layer {
  opacity: .65;
}

/* --- Dimmed state (when a train is selected, non-matching elements dim) --- */
.line-path,
.station-marker {
  transition: opacity 0.4s ease;
}

.line-path.dimmed {
  opacity: 0.08 !important;
}

.station-marker.dimmed {
  opacity: 0.08 !important;
}

/* --- PR express path (hidden by default, shown only when Purple is focused) --- */
.line-path.pr-express-path {
  opacity: 0 !important;
}

.line-path.pr-express-path.pr-express-active {
  opacity: 0.9 !important;
}

/* --- Track lines --- */
.line-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  shape-rendering: geometricPrecision;
}

/* Promote the map container to its own compositor layer so zoom/pan
   transforms are GPU-composited without triggering paint. */
.map-container {
  will-change: transform;
}

/* --- Train hit area (SVG, invisible — canvas handles all visuals) --- */
.train-hit {
  cursor: pointer;
}

/* Trains fading out — no interaction */
.train-exiting {
  pointer-events: none !important;
  cursor: default;
}


/* --- DOM train label overlay --- */
#train-label {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  text-align: center;
  transform: translateX(-50%);
  font-family: 'Jersey 10', monospace;
  display: none;
  white-space: nowrap;
  min-width: 220px;
}

#train-label.visible {
  display: block;
}

#train-label.visible .tl-badge {
  animation: line-in 0.3s ease-out 0.15s both;
}

#train-label.visible .tl-info {
  animation: line-in 0.3s ease-out 0.35s both;
}

#train-label.visible .tl-status {
  animation: line-in 0.3s ease-out 0.55s both;
}

#train-label.visible .tl-stop-row {
  animation: line-in 0.25s ease-out both;
}

.tl-badge {
  display: inline-block;
  padding: 4px 10px 5px;
  border-radius: 8px;
}

.tl-dest {
  font-size: 40px;
}

.tl-plane {
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  vertical-align: middle;
  position: relative;
  top: -1px;
  margin-left: 2px;
}

.tl-info {
  color: rgba(255, 255, 255, 0.7);
  font-size: 30px;
  margin-top: 4px;
}

.tl-status {
  color: rgba(255, 255, 255, 0.7);
  font-size: 28px;
  line-height: 1.1;
  margin-top: -2px;
}

.tl-status strong {
  font-weight: 400;
  color: rgba(255, 255, 255, .9);
}

.tl-delayed {
  font-size: 20px;
  color: rgba(255, 180, 60, 0.7);
}

.tl-limited {
  display: block;
  font-size: 20px;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.15;
  white-space: normal;
}

.tl-stops {
  margin-top: 8px;
  width: 100%;
  display: none;
  flex-direction: column;
  gap: 1px;
  max-width: 320px;
  margin: 0 auto;
  white-space: normal;
}

#train-label.show-stops .tl-stops {
  display: flex;
}

.tl-stop-row {
  display: flex;
  justify-content: space-between;

  align-items: baseline;
  padding: 0 2px;
  gap: 16px;
  font-size: 20px;
  color: rgba(255, 255, 255, .8);
}

.tl-stop-name {
  text-align: left
}

.tl-stop-time {
  text-align: right;
  color: rgba(255, 255, 255, 0.5);
  font-size: 20px;
  letter-spacing: 0.02em;
}

@keyframes line-in {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* --- Station overlay (toggle with S key) --- */
.station-dot {
  opacity: 1;
}

.station-leader {
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 0.15;
}

.station-label {
  fill: rgba(255, 255, 255, 0.5);
  font-family: 'Jersey 25', monospace;
  pointer-events: none;
  stroke: rgba(0, 0, 0, 0.6);
  stroke-width: 0.5px;
  paint-order: stroke fill;
  stroke-linejoin: round;
}


/* ---- Embed / iframe backdrop mode (?embed=true or ?chrome=false) ---- */
/* Keep close button hidden even if JS adds .visible, and suppress the    */
/* train-label overlay so no interactive chrome appears over the iframe.  */
body.embed-mode #close-btn,
body.embed-mode #close-btn.visible {
  display: none !important;
}

body.embed-mode #train-label,
body.embed-mode #train-label.visible {
  display: none !important;
}


/* ---- Debug overlay (toggle with D key) ---- */
#debug-overlay {
  position: fixed;
  top: 0;
  right: 0;
  width: 560px;
  max-width: 100vw;
  max-height: 100vh;
  background: rgba(10, 10, 16, 0.93);
  border-left: 2px solid rgba(255,255,255,0.1);
  color: #e0e0e0;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

#debug-overlay.debug-hidden {
  display: none;
}

.dbg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
}

.dbg-title {
  font-weight: bold;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #aaa;
}

.dbg-hint {
  color: #666;
  font-size: 10px;
}

.dbg-hint a {
  color: #4af;
  text-decoration: none;
}

.dbg-summary {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: #aaa;
  font-size: 10px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dbg-table-wrap {
  overflow-y: auto;
  flex: 1;
}

.dbg-table {
  width: 100%;
  border-collapse: collapse;
}

.dbg-table th {
  position: sticky;
  top: 0;
  background: rgba(20, 20, 30, 0.97);
  color: #777;
  text-align: left;
  padding: 4px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.dbg-table td {
  padding: 2px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dbg-table tr:hover td {
  background: rgba(255,255,255,0.04);
}

.dbg-line-chip {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: bold;
  color: #fff;
}

.dbg-held-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: bold;
  background: #b91c1c;
  color: #fff;
}

.dbg-dir-method {
  font-size: 9px;
  color: #888;
}

.dbg-dir-method.probe   { color: #4ade80; }
.dbg-dir-method.walk    { color: #60a5fa; }
.dbg-dir-method.segment { color: #a78bfa; }
.dbg-dir-method.heading { color: #fb923c; }
.dbg-dir-method.prev    { color: #555; }

.dbg-retiring {
  opacity: 0.5;
  font-style: italic;
}

.dbg-row-selected td {
  background: rgba(255,255,255,0.07);
}

.dbg-rn-link {
  cursor: pointer;
  text-decoration: underline;
  color: #bbb;
}

.dbg-rn-link:hover {
  color: #fff;
}

.dbg-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.dbg-filter-btn {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  color: #aaa;
  cursor: pointer;
}

.dbg-filter-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.dbg-filter-btn.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-color: rgba(255,255,255,0.35);
}

/* ====================================================================
   Alerts widget — minimal floating hazard labels
   ==================================================================== */

#alerts-widget {
  position: fixed;
  top: 26px;
  left: 26px;
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#alerts-widget.alerts-visible {
  opacity: 1;
  pointer-events: auto;
}

#alerts-widget.alerts-train-selected {
  opacity: 0;
  pointer-events: none;
}

#alerts-widget.alerts-zoom-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Individual alert label ─────────────────────────────────────── */

@keyframes aw-pulse {
  0%, 100% { opacity: 0.75; }
  50%      { opacity: 0.45; }
}

.aw-item {
  display: flex;
  flex-direction: column;
}

.aw-label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  animation: aw-pulse 3.2s ease-in-out infinite;
}

/* Hazard triangle — line art */

.aw-hazard {
  width: 26px;
  height: 24px;
  flex-shrink: 0;
}

/* Summary text */

.aw-text {
  font-family: 'Jersey 25', sans-serif;
  font-size: 18px;
  color: var(--c, #888);
  line-height: 1;
  text-shadow: 0 0 10px var(--c, #888), 0 0 3px var(--c, #888);
  white-space: nowrap;
}

/* Expandable detail text */

.aw-detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease;
}

.aw-item.expanded .aw-detail {
  grid-template-rows: 1fr;
}

.aw-detail-inner {
  overflow: hidden;
  font-family: 'Jersey 25', sans-serif;
  font-size: 14px;
  color: var(--c, #888);
  line-height: 1.4;
  max-width: 240px;
  padding-top: 4px;
  padding-left: 33px; /* align with text, past the hazard icon */
  opacity: 0;
  transition: opacity 0.25s ease 0.1s;
}

.aw-item.expanded .aw-detail-inner {
  opacity: 1;
}
