:root {
  --color-departures: steelblue;
  --color-arrivals: darkorange;
  --surface: rgba(255, 255, 255, 0.92);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 100%/1.5 system-ui, sans-serif;
}

/* Full-viewport map */
#map { position: fixed; inset: 0; }
#map svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

circle {
  fill-opacity: 0.6;
  stroke: white;
  stroke-width: 1px;
  pointer-events: auto;
  cursor: pointer;
  fill: color-mix(
    in oklch,
    var(--color-departures) calc(100% * var(--departure-ratio, 0.5)),
    var(--color-arrivals)
  );
  transition: r 120ms ease-out;
}

/* Floating top bar */
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em 1.5em;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5em 1em;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }

.controls { display: flex; align-items: center; gap: 0.75em; }

#play-btn {
  width: 2.2em;
  height: 2.2em;
  border: none;
  border-radius: 50%;
  background: var(--color-departures);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
#play-btn:hover { filter: brightness(1.1); }

#time-slider { width: min(240px, 40vw); accent-color: var(--color-departures); }

.time-readout { min-width: 80px; font-variant-numeric: tabular-nums; }
#any-time { color: #666; font-size: 0.9em; }

/* Legend */
.legend {
  position: fixed;
  bottom: 24px;
  left: 12px;
  z-index: 2;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  font-size: 0.8rem;
}
.legend-title { padding: 8px 10px; font-weight: 600; align-self: center; }
.legend-item {
  padding: 8px 12px;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  /* Same formula as the circles, so legend colors always match the map */
  background: color-mix(
    in oklch,
    var(--color-departures) calc(100% * var(--departure-ratio)),
    var(--color-arrivals)
  );
}

/* Tooltip */
#tooltip {
  display: none;
  position: fixed;
  z-index: 3;
  max-width: 260px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6em 0.8em;
  font-size: 0.85rem;
  pointer-events: none;
}

/* Pinned station panel */
#station-panel {
  position: fixed;
  right: 12px;
  bottom: 24px;
  z-index: 3;
  width: min(300px, calc(100vw - 24px));
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1em;
  transform: translateY(16px);
  opacity: 0;
  visibility: hidden;
  transition: transform 200ms ease, opacity 200ms ease, visibility 200ms;
}
#station-panel.open { transform: none; opacity: 1; visibility: visible; }
#station-panel h2 { font-size: 1rem; margin: 0 1.2em 0.5em 0; }
#station-panel h3 { font-size: 0.8rem; margin: 1em 0 0.25em; color: #555; }
#panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #666;
}

.stat { font-size: 0.85rem; }
.stat-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.dep .stat-num { color: var(--color-departures); }
.stat.arr .stat-num { color: var(--color-arrivals); }

.mini-chart rect { fill: var(--color-departures); opacity: 0.85; }
.mini-chart text { font-size: 9px; fill: #666; }

/* Loading overlay */
#loading {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 1em;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  color: #444;
}
#loading.done { display: none; }
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #ddd;
  border-top-color: var(--color-departures);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 11;
  display: none;
  background: #b3261e;
  color: white;
  padding: 0.6em 1em;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
#toast.show { display: block; }
