:root {
  --bg: #0b1017;
  --panel: rgba(13, 19, 28, 0.92);
  --line: #1f2b3a;
  --fg: #e6edf6;
  --muted: #8b9bb0;
  --accent: #38bdf8;
  --ok: #34d399;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

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

/* OSM raster tiles inverted into a dark basemap - no tile API key needed */
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(.93) contrast(.9) saturate(.5);
}

/* sits inside Leaflet's overlay pane, positioned by setPosition/setTransform,
   so it must not be stretched by `inset` */
canvas.train-canvas {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 200;   /* above the selected train's route line */
}

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

#panel {
  position: absolute;
  z-index: 1000;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: 330px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}

#panel header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .04em;
  font-weight: 700;
  text-transform: uppercase;
}
h1 span { color: var(--accent); font-weight: 300; }

.status { font-size: 11px; color: var(--muted); white-space: nowrap; }
.status.bad { color: #f87171; }
.status b { color: var(--ok); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat {
  background: #111a26;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 4px;
  text-align: center;
}
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

#search {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0e151f;
  color: var(--fg);
  font-size: 13px;
}
#search:focus { outline: none; border-color: var(--accent); }

/* ---------- detail ---------- */

.detail {
  border: 1px solid #23405a;
  background: linear-gradient(180deg, #10202e, #0e1723);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 12.5px;
}
.detail.hidden { display: none; }
.detail h2 { margin: 0 0 2px; font-size: 15px; }
.detail .route { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-variant-numeric: tabular-nums; }
.bar { height: 4px; border-radius: 3px; background: #1c2836; margin-top: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.detail .actions { margin-top: 9px; display: flex; gap: 6px; }
.detail button, .warp button {
  border: 1px solid var(--line);
  background: #16202d;
  color: var(--fg);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 11.5px;
  cursor: pointer;
}
.detail button:hover, .warp button:hover { border-color: var(--accent); }
.detail button.on, .warp button.on { background: #1d4d66; border-color: var(--accent); }

/* ---------- list ---------- */

#list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}
#list li {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #141d29;
  cursor: pointer;
  font-size: 12px;
}
#list li:hover { background: #131d2a; }
#list li.sel { background: #17303f; }
#list .nm { font-weight: 600; font-variant-numeric: tabular-nums; }
#list .rt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .dl { font-variant-numeric: tabular-nums; font-size: 11.5px; }

#list::-webkit-scrollbar { width: 8px; }
#list::-webkit-scrollbar-thumb { background: #22303f; border-radius: 4px; }

/* ---------- footer ---------- */

footer { border-top: 1px solid var(--line); padding-top: 8px; }
.warp { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.warp span { margin-right: auto; }
.legend { display: flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 10px; color: var(--muted); }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.legend i:first-child { margin-left: 0; }
.src { margin: 7px 0 0; font-size: 10px; color: #667a91; line-height: 1.4; }
.src a { color: #7aa7c7; }

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

#clock {
  position: absolute;
  z-index: 1000;
  right: 14px;
  top: 12px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  letter-spacing: .05em;
}
#clock.warped { color: #fbbf24; border-color: #5a4713; }

.leaflet-container { background: var(--bg); }
.leaflet-control-attribution { background: rgba(11, 16, 23, .8) !important; color: #6d8098 !important; }
.leaflet-control-attribution a { color: #8fb4d0 !important; }

@media (max-width: 760px) {
  #panel { width: auto; right: 12px; bottom: 12px; top: auto; max-height: 52vh; }
}
