:root {
  --ink: #0A1230;          /* night Beck blue: the map ground */
  --panel: rgba(13, 21, 56, 0.84);
  --panel-solid: #111A45;
  --hair: rgba(226, 231, 250, 0.10);
  --text: #EEF0F8;
  --muted: #9AA2C6;
  --live: #E3342A;
  --warn: #FFB547;
  --focus: #8FB3FF;
  --font: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- map ---------- */

#map { position: fixed; inset: 0; background: var(--ink); }
.leaflet-container { background: var(--ink); font-family: var(--font); }
.leaflet-tile-pane { opacity: 0.6; filter: saturate(0.4); }
.train-layer {
  position: absolute; top: 0; left: 0;
  z-index: 450;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
}

.leaflet-control-zoom { border: 1px solid var(--hair) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-control-zoom a {
  background: var(--panel-solid) !important;
  color: var(--text) !important;
  border-color: var(--hair) !important;
  width: 34px !important; height: 34px !important; line-height: 34px !important;
}
.leaflet-control-zoom a:hover { background: #1A2458 !important; }
.leaflet-control-attribution {
  background: rgba(10, 18, 48, 0.72) !important;
  color: var(--muted) !important;
  font-size: 11px;
  border-top-left-radius: 6px;
}
.leaflet-control-attribution a { color: #C3CBEE !important; }

.leaflet-tooltip.st {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--hair);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font: 500 13px/1.3 var(--font);
  padding: 5px 9px;
}
.leaflet-tooltip.st::before { display: none; }

/* ---------- panel ---------- */

#panel {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  width: 304px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--hair);
  border-radius: 16px;
  z-index: 1000;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(3, 6, 22, 0.45);
}

.brand { padding: 18px 20px 16px; }
.title-row { display: flex; align-items: center; gap: 10px; }
h1 { flex: 1; margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -0.015em; }
#clock { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
#summary { margin: 10px 0 2px; font-size: 15px; line-height: 1.4; }
#summary strong { font-weight: 700; font-variant-numeric: tabular-nums; }
#updated { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.live-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(227, 52, 42, 0.55);
  animation: pulse 2.2s ease-out infinite;
}
.live-dot.stale { background: var(--muted); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(227, 52, 42, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(227, 52, 42, 0); }
  100% { box-shadow: 0 0 0 0 rgba(227, 52, 42, 0); }
}

.roster-wrap { display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--hair); }
.roster-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 20px 4px; }
h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.linkish {
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 13px;
  padding: 2px 5px; border-radius: 5px;
}
.linkish:hover { color: var(--text); }

#roster { list-style: none; margin: 0; padding: 4px 10px 10px; overflow-y: auto; flex: 1; min-height: 0; }
.row {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  padding: 7px 10px;
  background: none; border: 0; border-radius: 9px;
  text-align: left; cursor: pointer;
}
.row:hover { background: rgba(255, 255, 255, 0.05); }
.row .bar { grid-row: span 2; align-self: stretch; width: 6px; border-radius: 3px; background: var(--c); }
.row.dual .bar { background: linear-gradient(90deg, var(--c) 0 33%, transparent 33% 67%, var(--c) 67%); }
.row .name { font-size: 14.5px; font-weight: 600; }
.row .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .status { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.row .status.bad { color: var(--warn); }
.row[aria-pressed="false"] { opacity: 0.36; }

.footnote {
  margin: 0; padding: 12px 20px 16px;
  border-top: 1px solid var(--hair);
  font-size: 12px; line-height: 1.5; color: var(--muted);
}

.pill {
  display: none;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}

/* ---------- card ---------- */

#card {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 330px;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--hair);
  border-top: 3px solid var(--c, var(--text));
  border-radius: 16px;
  z-index: 1000;
  padding: 14px 18px 16px;
  box-shadow: 0 18px 48px rgba(3, 6, 22, 0.45);
}
.card-top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.card-top .sw { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.card-top .grow { flex: 1; }
.close {
  background: none; border: 0; cursor: pointer;
  width: 30px; height: 30px; margin: -6px -8px -6px 0;
  border-radius: 8px; font-size: 20px; line-height: 1; color: var(--muted);
}
.close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
#card h3 { margin: 6px 0 2px; font-size: 25px; line-height: 1.15; font-weight: 700; letter-spacing: -0.015em; }
#card .sub { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }

.stops { list-style: none; margin: 14px 0 0; padding: 0 0 0 20px; position: relative; }
.stops::before {
  content: ""; position: absolute; left: 5px; top: 12px; bottom: 12px;
  width: 2px; background: var(--c); opacity: 0.55;
}
.stops li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; }
.stops li::before {
  content: ""; position: absolute; left: -20px; top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-radius: 50%; background: var(--panel-solid); border: 2px solid var(--c);
}
.stops li:first-child::before { background: var(--c); }
.eta { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stops li:first-child .eta { color: var(--text); font-weight: 600; }

.arrivals { list-style: none; margin: 12px 0 0; padding: 0; }
.arrivals li {
  display: grid; grid-template-columns: 4px 1fr auto; column-gap: 10px;
  padding: 7px 0; border-top: 1px solid var(--hair); font-size: 14px;
}
.arrivals li:first-child { border-top: 0; }
.arrivals .bar { grid-row: span 2; border-radius: 2px; background: var(--c); }
.arrivals .plat { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); }

.card-actions { margin-top: 14px; display: flex; gap: 8px; }
.btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn[aria-pressed="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }

/* ---------- hover label, toast, loader ---------- */

#hover {
  position: fixed; z-index: 1001; pointer-events: none;
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--c);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px; white-space: nowrap;
  transform: translate(14px, -50%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(520px, calc(100% - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px; line-height: 1.45;
}

#loader {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-items: center;
  background: rgba(10, 18, 48, 0.9);
  transition: opacity 0.7s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; padding: 24px; }
#loader-text { margin: 0; font-size: 16px; color: var(--text); max-width: 440px; line-height: 1.5; }
#loader .bar { width: 240px; height: 3px; margin: 14px auto 0; background: rgba(255, 255, 255, 0.1); border-radius: 2px; overflow: hidden; }
#loader-bar { display: block; height: 100%; width: 0; background: var(--text); transition: width 0.3s ease; }
#loader code { background: rgba(255, 255, 255, 0.08); padding: 1px 6px; border-radius: 4px; }

/* ---------- small screens ---------- */

@media (max-width: 680px) {
  #panel {
    top: auto; left: 8px; right: 8px; width: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-height: 62%;
    border-radius: 14px;
  }
  .brand { padding: 14px 16px; }
  h1 { font-size: 20px; }
  .pill { display: inline-block; }
  #panel.collapsed .roster-wrap { display: none; }
  #card {
    left: 8px; right: 8px; width: auto;
    top: max(8px, env(safe-area-inset-top));
    max-height: 44%;
  }
  .leaflet-control-zoom { display: none; }
  .leaflet-bottom.leaflet-right { bottom: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  #loader, #loader-bar, .train-layer { transition: none; }
}
