:root {
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #18212d;
  --line: #243040;
  --text: #e9eff6;
  --muted: #8a98aa;
  --sp: #6cc6e9;
  --ip: #3ccf8e;
  --ok: #3ccf8e;
  --warn: #f5b041;
  --bad: #ff6b6b;
  --early: #8fb4ff;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.badge {
  background: var(--sp); color: #06202b; font-weight: 800; border-radius: 8px;
  padding: 6px 8px; font-size: 15px; letter-spacing: .02em;
}
.brand h1 { font-size: 15px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px;
  padding: 5px 10px; font-size: 12px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.alerts { color: var(--warn); border-color: #5b4520; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live i { background: var(--ok); animation: pulse 2s infinite; }
.status.stale i { background: var(--warn); }
.status.down i { background: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(60, 207, 142, .6); } 100% { box-shadow: 0 0 0 8px rgba(60, 207, 142, 0); } }
.clock { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; color: var(--text); }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.map-wrap { position: relative; height: 38vh; min-height: 200px; flex: none; transition: height .2s; }
.map-wrap.big { height: 68vh; }
#map { position: absolute; inset: 0; background: #0d131a; }
.map-btn {
  position: absolute; right: 10px; bottom: 10px; z-index: 500; width: 38px; height: 38px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); font-size: 18px;
}
.map-btn.fit { bottom: 56px; }

.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); border-top: 1px solid var(--line); }
.tabs { display: flex; flex: none; background: var(--panel); }
.tabs button {
  flex: 1 1 auto; padding: 11px 8px; font-weight: 600; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--sp); }
.filters { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; flex: none; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.filters button.on { background: var(--panel-2); color: var(--text); border-color: #3a4a60; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.sp { background: var(--sp); } .dot.ip { background: var(--ip); }

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.sec {
  position: sticky; top: 0; z-index: 2; background: var(--bg); color: var(--muted); font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; padding: 8px 12px 6px; display: flex; justify-content: space-between;
}
.sec a { color: var(--sp); text-decoration: none; text-transform: none; letter-spacing: 0; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; }

.row {
  display: grid; grid-template-columns: 78px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid #17202b; width: 100%; text-align: left;
}
.row:active { background: var(--panel); }
.row .t { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.row .t b { display: block; font-size: 15px; font-weight: 600; }
.row .t small { display: block; font-size: 11.5px; color: var(--muted); }
.row .t small.moved { text-decoration: line-through; }
.row .m { min-width: 0; }
.sub.dep { margin-top: 1px; }
.sub.dep b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.note { margin: 0; padding: 8px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid #17202b; }
.note b { color: var(--text); font-weight: 600; }
.stops .tm small { display: block; font-size: 11px; color: var(--muted); text-align: right; }
.dest { font-weight: 600; display: flex; align-items: center; gap: 7px; min-width: 0; }
.dest span.n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plat { font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; flex: none; }
.sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.cd { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; }
.cd.soon { color: var(--warn); }
.chip {
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700;
  padding: 1px 7px; border-radius: 6px; white-space: nowrap;
}
.chip.ok { color: var(--ok); background: rgba(60, 207, 142, .12); }
.chip.warn { color: var(--warn); background: rgba(245, 176, 65, .13); }
.chip.bad { color: var(--bad); background: rgba(255, 107, 107, .14); }
.chip.early { color: var(--early); background: rgba(143, 180, 255, .14); }
.chip.none { color: var(--muted); background: var(--panel-2); font-family: inherit; font-weight: 600; }
.row.past .t b, .row.past .dest { color: #b9c4d1; }
.row.dead .dest span.n { text-decoration: line-through; color: var(--muted); }

/* map */
.leaflet-container { background: #0d131a; font: inherit; }
.dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.85) saturate(.5); }
.leaflet-control-attribution { background: rgba(11, 15, 20, .7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--panel-2); color: var(--text); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); box-shadow: 0 6px 24px rgba(0, 0, 0, .5); }
.leaflet-popup-content { margin: 12px 14px; min-width: 190px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.stn-label {
  background: none; border: 0; box-shadow: none; color: #9fb0c3; font-size: 11px; font-weight: 600; padding: 0;
  text-shadow: 0 0 3px #0b0f14, 0 0 3px #0b0f14, 0 0 3px #0b0f14;
}
.stn-label::before { display: none; }
.stn-label.key { color: #fff; font-size: 12.5px; }
.train { position: relative; width: 30px; height: 30px; }
.train .arrow {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.train .arrow::before {
  content: ""; position: absolute; top: -5px; left: 50%; margin-left: -6px;
  border: 6px solid transparent; border-bottom: 9px solid var(--c); border-top: 0;
}
.train .arrow.none::before { display: none; }
.train .body {
  position: absolute; inset: 5px; border-radius: 50%; background: var(--c); border: 2px solid #0b0f14;
  box-shadow: 0 0 0 1.5px var(--c), 0 2px 8px rgba(0, 0, 0, .6);
}
.train.at .body { border-color: #fff; }
.train .lbl {
  position: absolute; top: 29px; left: 50%; transform: translateX(-50%); font: 700 10.5px var(--mono);
  color: #fff; background: rgba(11, 15, 20, .85); padding: 0 4px; border-radius: 4px; white-space: nowrap;
  border: 1px solid var(--line);
}
.lowzoom .train .lbl { display: none; }
.train .lbl.warn { color: var(--warn); } .train .lbl.bad { color: var(--bad); }
.pop h3 { margin: 0 0 2px; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.pop p { margin: 2px 0; color: var(--muted); font-size: 12.5px; }
.pop p b { color: var(--text); font-weight: 600; }
.pop .eta { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; margin-top: 4px; }
.pop .eta span:last-child { font-family: var(--mono); }
.pop button { margin-top: 8px; width: 100%; padding: 7px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; font-size: 13px; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card {
  position: relative; width: 100%; max-width: 520px; max-height: 82vh; overflow-y: auto; background: var(--panel);
  border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); border: 1px solid var(--line);
}
.sheet-close { position: absolute; top: 8px; right: 10px; font-size: 26px; color: var(--muted); width: 36px; height: 36px; }
.sheet h2 { margin: 0 30px 2px 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.sheet .meta { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.stops { list-style: none; margin: 0; padding: 0; }
.stops li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 7px 0 7px 18px; position: relative; font-size: 14px; }
.stops li::before { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.stops li::after { content: ""; position: absolute; left: 0; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%; background: var(--panel); border: 2px solid var(--sp); }
.stops li.passed { color: var(--muted); }
.stops li.passed::after { border-color: var(--line); background: var(--line); }
.stops li.key { font-weight: 700; }
.stops .tm { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; }
.alert { padding: 12px 0; border-bottom: 1px solid var(--line); }
.alert h3 { margin: 0 0 4px; font-size: 14.5px; }
.alert p { margin: 0; color: var(--muted); font-size: 13px; white-space: pre-line; }
.alert a { color: var(--sp); font-size: 13px; }

@media (min-width: 900px) {
  main { flex-direction: row; }
  .map-wrap, .map-wrap.big { height: auto; flex: 1; }
  #mapSize { display: none; }
  .map-btn.fit { bottom: 10px; }
  .panel { flex: none; width: 430px; border-top: 0; border-left: 1px solid var(--line); }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 16px; }
  .brand h1 { font-size: 16px; }
}
@media (max-width: 520px) {
  .alerts .w { display: none; }
  .pill { padding: 5px 9px; }
}
@media (max-width: 380px) {
  .brand p { display: none; }
  .row { grid-template-columns: 70px 1fr auto; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { .status.live i { animation: none; } .map-wrap { transition: none; } }
