:root {
  --bg: #05070f;
  --ink: #eef2ff;
  --ink-dim: #8b94b8;
  --ink-faint: #5a6288;
  --board: #ff2d95;
  --alight: #21e7d6;
  --balance: #eaf0ff;
  --panel: rgba(12, 16, 32, 0.62);
  --panel-line: rgba(150, 170, 255, 0.16);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* Leaflet's own chrome has no place in a full-bleed piece. */
.leaflet-container { background: var(--bg); outline: none; }
.leaflet-control-container, .leaflet-control-attribution { display: none; }

/* Tiles get pushed back so the data reads as the foreground. */
.leaflet-tile-pane {
  filter: saturate(0.3) brightness(0.42) contrast(1.25);
  opacity: 0.95;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 400;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 38%, rgba(3, 5, 12, 0.5) 78%, rgba(3, 5, 12, 0.85) 100%);
}

/* ---------- shared panel treatment ---------- */

.panel, #titlecard, #clock, #totals, #legend, #controls {
  position: fixed;
  z-index: 600;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  animation: rise 0.7s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- title ---------- */

#titlecard {
  top: 24px;
  left: 24px;
  padding: 18px 24px 16px;
  max-width: 30ch;
}

#titlecard h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.024em;
  line-height: 1.1;
  background: linear-gradient(96deg, var(--board) 0%, #b57bff 45%, var(--alight) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#titlecard p {
  margin: 7px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-dim);
}

/* ---------- clock ---------- */

#clock {
  top: 24px;
  right: 24px;
  padding: 14px 22px 12px;
  text-align: right;
  min-width: 188px;
  animation-delay: 0.06s;
}

.clock-time {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
}

#clock-ap {
  font-size: 15px;
  font-weight: 400;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}

.clock-meta {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: color 0.5s var(--ease);
}

/* ---------- totals ---------- */

#totals {
  top: 132px;
  right: 24px;
  padding: 14px 22px;
  min-width: 188px;
  display: grid;
  gap: 12px;
  animation-delay: 0.12s;
}

.stat { text-align: right; }

.stat-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}

.stat-value {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-value--text {
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  display: block;
  line-height: 1.3;
}

#stat-entries { color: var(--board); }
#stat-exits { color: var(--alight); }

/* ---------- legend ---------- */

#legend {
  left: 24px;
  bottom: 128px;
  padding: 15px 20px 17px;
  width: 232px;
  animation-delay: 0.18s;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 9px;
}

.legend-title--spaced { margin-top: 18px; }

.legend-ramp {
  height: 9px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--alight) 0%, var(--balance) 50%, var(--board) 100%);
  box-shadow: 0 0 18px rgba(255, 45, 149, 0.25), 0 0 18px rgba(33, 231, 214, 0.2);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-size: 9.5px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.legend-labels span:nth-child(2) { color: var(--ink-dim); }

.legend-sizes {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend-sizes .dot {
  border-radius: 50%;
  background: rgba(234, 240, 255, 0.82);
  box-shadow: 0 0 10px rgba(234, 240, 255, 0.45);
  flex: none;
}

.dot-s { width: 5px; height: 5px; }
.dot-m { width: 11px; height: 11px; }
.dot-l { width: 19px; height: 19px; }

.legend-sizes em {
  font-style: normal;
  font-size: 9.5px;
  color: var(--ink-faint);
  margin-left: 3px;
  line-height: 1.3;
}

/* ---------- controls ---------- */

#controls {
  left: 24px;
  right: 24px;
  bottom: 24px;
  height: 76px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  animation-delay: 0.24s;
}

#play {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.25s var(--ease), transform 0.25s var(--ease), border-color 0.25s var(--ease);
}

#play:hover {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(180, 195, 255, 0.35);
  transform: scale(1.06);
}

#play:active { transform: scale(0.96); }

#play svg { width: 19px; height: 19px; fill: currentColor; }
#play .icon-play { display: none; margin-left: 2px; }
#play.is-paused .icon-pause { display: none; }
#play.is-paused .icon-play { display: block; }

.scrub {
  position: relative;
  flex: 1;
  height: 44px;
  display: flex;
  align-items: center;
}

.scrub-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 17px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.scrub-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #6f4dff, var(--board));
  box-shadow: 0 0 14px rgba(255, 45, 149, 0.5);
}

.scrub input[type="range"] {
  position: relative;
  z-index: 2;
  width: 100%;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.scrub input[type="range"]::-webkit-slider-runnable-track { height: 40px; background: transparent; }
.scrub input[type="range"]::-moz-range-track { height: 40px; background: transparent; }

.scrub input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: 12.5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--board);
  box-shadow: 0 0 14px rgba(255, 45, 149, 0.75);
  transition: transform 0.2s var(--ease);
}

.scrub input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.25); }

.scrub input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--board);
  box-shadow: 0 0 14px rgba(255, 45, 149, 0.75);
}

.scrub-ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: 30px;
  height: 18px;
  pointer-events: none;
}

.scrub-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  white-space: nowrap;
}

.scrub-ticks span::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -9px;
  width: 1px;
  height: 5px;
  background: rgba(255, 255, 255, 0.18);
}

.speeds {
  flex: none;
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
}

.speeds button {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.speeds button:hover { color: var(--ink); }

.speeds button.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

/* ---------- station marks ---------- */

#stations { pointer-events: none; }
#stations .station { pointer-events: auto; cursor: crosshair; }

.station-core { transition: stroke-opacity 0.2s var(--ease); }
.station.is-hover .station-core { stroke-opacity: 1; }

.station-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.005em;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(3, 5, 12, 0.85);
  stroke-width: 3.5px;
  stroke-linejoin: round;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
}

.station-label.is-shown { opacity: 0.92; }

/* ---------- tooltip ---------- */

#tooltip {
  position: fixed;
  z-index: 900;
  pointer-events: none;
  padding: 11px 14px;
  min-width: 176px;
  border-radius: 11px;
  background: rgba(10, 13, 27, 0.9);
  border: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transform: translate(-50%, calc(-100% - 14px));
  transition: opacity 0.16s var(--ease);
}

#tooltip[hidden] { display: none; }

.tt-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.tt-line {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 9px;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  font-size: 11.5px;
  line-height: 1.7;
}

.tt-row span:first-child { color: var(--ink-dim); }

.tt-row span:last-child {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tt-bar {
  margin-top: 9px;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--alight);
  display: flex;
}

.tt-bar i { display: block; height: 100%; background: var(--board); }

#credit {
  position: fixed;
  text-shadow: 0 1px 6px rgba(3, 5, 12, 0.95), 0 0 14px rgba(3, 5, 12, 0.9);
  z-index: 600;
  right: 24px;
  bottom: 112px;
  font-size: 9.5px;
  letter-spacing: 0.03em;
  color: rgba(120, 130, 165, 0.75);
  text-align: right;
  pointer-events: none;
}

@media (max-width: 900px) { #credit { display: none; } }

/* ---------- loader ---------- */

#loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--bg);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}

#loader.is-done { opacity: 0; visibility: hidden; }

.loader-ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--board);
  border-right-color: #7a5cff;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  #titlecard { padding: 14px 18px 12px; max-width: 44vw; }
  #titlecard h1 { font-size: 19px; }
  #titlecard p { font-size: 11px; }
  #clock { padding: 11px 16px 10px; min-width: 0; }
  .clock-time { font-size: 27px; }
  #totals { top: 112px; padding: 11px 16px; min-width: 0; gap: 9px; }
  .stat-value { font-size: 16px; }
  #legend { display: none; }
  #controls { height: 66px; padding: 0 14px; gap: 13px; left: 14px; right: 14px; bottom: 14px; }
  .scrub-ticks { display: none; }
  .speeds button { padding: 5px 7px; font-size: 10.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, #titlecard, #clock, #totals, #legend, #controls { animation: none; }
  .loader-ring { animation-duration: 2s; }
}
