:root {
  --bg: #0a0a0a;
  --panel: #000;
  --panel-2: #141414;
  --line: #262626;
  --text: #fff;
  --muted: #8a8a8a;
  --dim: #555;
  --led: #ff3b1f;
  --ok: #34c759;
  --bad: #ff453a;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Inter, -apple-system, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.top { position: fixed; inset: 0 0 auto 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; pointer-events: none; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; font-weight: 700; font-size: 26px; letter-spacing: -.02em;
  text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.brand svg { width: 42px; height: 42px; filter: drop-shadow(0 1px 6px rgba(0,0,0,.5)); }
.tabs { display: flex; gap: 4px; padding: 5px; background: rgba(10,10,10,.92); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(10px); }
.tabs button { display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 15px; color: #ddd; }
.tabs button:hover { background: #1c1c1c; }
.tabs button.on { background: #fff; color: #000; }
.tabs svg, .search-box svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- views ---------- */
main, .view { position: fixed; inset: 0; }
#map { background: #0d0d0d; }
.leaflet-container { font-family: inherit; background: #0d0d0d; }
.leaflet-control-attribution { background: rgba(0,0,0,.7) !important; color: #777 !important; font-size: 10px; }
.leaflet-control-attribution a { color: #9bb !important; }
.leaflet-control-zoom { display: none; }

.train-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.train-icon { position: absolute; left: 0; top: 0; will-change: transform; cursor: pointer; }
.train-icon svg { display: block; overflow: visible; }
.train-icon.sel::before { content: ""; position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px; border-radius: 50%;
  background: var(--c); opacity: .28; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.25); opacity: .14; } }
.station-hit { cursor: pointer; }
/* Zoom-dependent sizes, set on the map container by applyLineScale(). */
.leaflet-overlay-pane path.metro-line { stroke-width: var(--lw, 7px); }
.leaflet-overlay-pane path.station-hit { transform-box: fill-box; transform-origin: center; transform: scale(var(--ds, 1)); }
.station-glow { pointer-events: none; animation: pulse 1.6s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }

/* ---------- panels ---------- */
.panel { position: fixed; z-index: 1001; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.card { top: 84px; right: 20px; width: 380px; max-height: calc(100vh - 110px); overflow: auto; }
body.view-linia .card.train-card { top: auto; right: auto; left: 50%; bottom: 112px; transform: translateX(-50%); width: min(760px, calc(100vw - 32px)); }
body.view-linia .card.station-card { top: auto; right: auto; left: 50%; bottom: 112px; transform: translateX(-50%); width: min(860px, calc(100vw - 32px)); max-height: 50vh; }

.card-head { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.card-head .grow { flex: 1; min-width: 0; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: #1e1e1e; display: grid; place-items: center; color: #ddd; flex: none; font-size: 15px; }
.icon-btn:hover { background: #2a2a2a; }
.icon-btn.on { background: #fff; color: #000; }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.badge { flex: none; display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 4px; font-weight: 800; font-size: 19px; letter-spacing: -.04em;
  color: #fff; border-radius: 2px; line-height: 1; }
.badge.lg { min-width: 46px; height: 46px; font-size: 30px; }
.badge.sm { min-width: 22px; height: 22px; font-size: 14px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.badge.ext { font-size: 11px; font-weight: 700; padding: 0 5px; min-width: 22px; height: 22px; border-radius: 3px; }
.badge.metro-ico { background: #e3001b; border-radius: 3px; padding: 0; width: 22px; min-width: 22px; height: 22px; }
.badge.metro-ico svg { width: 18px; height: 18px; }

.led { flex: none; font-family: Doto, monospace; font-weight: 900; color: var(--led); background: #120302; border: 1px solid #2a0d08; border-radius: 6px;
  padding: 2px 10px; font-size: 30px; line-height: 1.15; letter-spacing: .06em; text-shadow: 0 0 6px rgba(255,59,31,.65); }
.led.sm { font-size: 20px; padding: 0 6px; }

.lbl { color: var(--muted); font-size: 14px; margin-bottom: 4px; }
.val { font-size: 22px; font-weight: 700; }
.big { font-size: 52px; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }

.train-body { display: grid; }
.train-body section { padding: 20px 22px; }
.train-body section + section { border-top: 1px solid var(--line); }
.train-body .row { display: grid; grid-template-columns: 1fr auto auto; gap: 26px; }
body.view-linia .train-card .train-body { grid-template-columns: 1fr 1fr; }
body.view-linia .train-card .train-body section + section { border-top: 0; border-left: 1px solid var(--line); }
.mt { margin-top: 18px; }

.banner { position: relative; display: flex; align-items: center; justify-content: center; gap: 14px; padding: 26px 16px 18px; font-weight: 700; font-size: 20px;
  border-radius: 0 0 var(--radius) var(--radius); }
.banner::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 22px; }
.banner.M { background: #ffdf3a; color: #000; }
.banner.M::before { background: repeating-linear-gradient(-55deg, #000 0 14px, #ffdf3a 14px 34px); height: 24px; }
.banner.R { background: #2b4b94; color: #fff; }
.banner.R::before { background: #2b4b94 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='24'%3E%3Cpath d='M4 0h12l10 12-10 12H4l10-12z' fill='%23fff'/%3E%3C/svg%3E") repeat-x; background-size: 36px 24px; }
.banner.T { background: #2a2a2a; color: #ddd; font-size: 14px; font-weight: 600; padding: 16px 18px; }
.banner.T::before { display: none; }
.banner.T span { top: 0; gap: 10px; text-align: left; }
.banner.T svg { width: 22px; height: 22px; flex: none; }
.banner span { position: relative; top: 4px; display: flex; align-items: center; gap: 14px; }
.banner svg { width: 30px; height: 30px; }

.dir-group + .dir-group { border-top: 1px solid var(--line); }
.dir { padding: 16px 22px 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; align-items: end; }
.dir .head { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.dir .head small { display: block; color: var(--muted); font-size: 12px; }
.dir .head b { font-size: 19px; font-weight: 600; }
.dir .eta { font-size: 38px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 6px; }
.dir .eta.next { color: #5f5f5f; }
.dir .torn { color: var(--muted); font-size: 13px; }
.dir .torn.next { color: #444; }
.dir .none { grid-column: 1 / -1; color: var(--muted); font-size: 15px; padding: 6px 0; }
body.view-linia .station-card .dirs { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
body.view-linia .station-card .dir-group { display: contents; }
body.view-linia .station-card .dir { border-top: 0; }

/* ---------- search ---------- */
.search { top: 84px; right: 20px; width: 400px; max-height: calc(100vh - 110px); display: flex; flex-direction: column; overflow: hidden; }
.search-box { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-box input { flex: 1; background: none; border: 0; outline: 0; color: #fff; font: inherit; font-size: 17px; min-width: 0; }
.search-box input::-webkit-search-cancel-button { display: none; }
.results { list-style: none; margin: 0; padding: 6px; overflow: auto; }
.results li { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; }
.results li:hover, .results li.hl { background: #1a1a1a; }
.results .grow { flex: 1; min-width: 0; }
.results b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.results small { color: var(--muted); font-size: 12px; }
.results .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.results .empty { color: var(--muted); cursor: default; justify-content: center; padding: 22px; }
.results .empty:hover { background: none; }

/* ---------- line view ---------- */
#line { background: var(--bg); display: flex; flex-direction: column; padding: 76px 0 var(--pb, 112px); }
#line.carded .line-head { display: none; }
.line-head { flex: none; text-align: center; min-height: 64px; display: flex; justify-content: center; }
.line-head .in { display: flex; align-items: flex-end; gap: 14px; }
.line-head small { display: block; color: var(--muted); font-size: 14px; }
.line-head b { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.line-head .arrow { font-size: 34px; color: var(--c); line-height: 1.2; }
.line-scroll { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; overflow-x: auto; overflow-y: hidden; cursor: grab; scrollbar-width: none; touch-action: pan-x;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 90px, #000 calc(100% - 90px), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 90px, #000 calc(100% - 90px), transparent); }
.line-scroll::-webkit-scrollbar { display: none; }
.line-scroll.drag { cursor: grabbing; }
#line-svg { display: block; flex: none; }
#line-svg text { font-family: Inter, sans-serif; font-weight: 700; fill: #fff; user-select: none; }
#line-svg .st-label { font-size: 21px; cursor: pointer; }
#line-svg .st-label:hover { fill: #ddd; text-decoration: underline; }
#line-svg .eta-label { font-size: 15px; font-weight: 600; fill: #ddd; }
#line-svg .t { cursor: pointer; }
.line-foot { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 30px 28px; gap: 16px; pointer-events: none; }
.line-foot > * { pointer-events: auto; }
.picker { display: flex; gap: 8px; flex-wrap: wrap; }
.picker button { min-width: 58px; height: 58px; font-size: 36px; font-weight: 800; letter-spacing: -.05em; color: #fff; border-radius: 2px; opacity: .35; filter: saturate(.6); padding: 0 4px; }
.picker button:hover { opacity: .7; }
.picker button[data-long] { font-size: 24px; letter-spacing: -.06em; }
.picker button.on { opacity: 1; filter: none; outline: 3px solid #fff; outline-offset: 3px; }
.stats { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 0; }
.stats > div { padding: 0 28px; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats small { display: block; color: var(--muted); font-size: 14px; margin-bottom: 4px; }
.stats b { font-size: 22px; font-weight: 700; }
.stats .ok { color: var(--ok); }
.stats .bad { color: var(--bad); }
.stats .sched { color: #f0b429; }
.val.ok { color: var(--ok); }
.val.bad { color: var(--bad); }
.stops { font-size: 15px; color: #ccc; line-height: 1.5; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: currentColor; margin-right: 8px; vertical-align: 2px; }

.tip { position: fixed; z-index: 1002; pointer-events: none; background: #000; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 210px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.tip .led { font-size: 26px; display: inline-block; margin-bottom: 8px; }
.tip p { margin: 2px 0; font-size: 12px; color: var(--muted); }
.tip p b { color: #fff; }
.tip .row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; font-size: 12px; color: var(--muted); }
.tip .row b { color: #fff; font-size: 17px; font-variant-numeric: tabular-nums; }

.toast { position: fixed; z-index: 1003; left: 50%; bottom: 30px; transform: translateX(-50%); background: #fff; color: #000; font-weight: 600; padding: 12px 18px; border-radius: 12px; }
.loading { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: var(--bg); color: var(--muted); font-size: 18px; }

@media (min-width: 1700px) {
  body.view-linia .card.train-card, body.view-linia .card.station-card { bottom: 24px; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  .top { padding: 10px 12px; }
  .brand { font-size: 20px; gap: 8px; }
  .brand svg { width: 34px; height: 34px; }
  .tabs button { padding: 8px 10px; }
  .tabs button span { display: none; }
  .card, .search, body.view-linia .card.train-card, body.view-linia .card.station-card {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; transform: none; border-radius: var(--radius) var(--radius) 0 0; max-height: 62vh; }
  .search { top: 64px; bottom: auto; border-radius: var(--radius); left: 12px; right: 12px; max-height: calc(100vh - 80px); }
  .card-head h2 { font-size: 24px; }
  .big { font-size: 42px; }
  body.view-linia .train-card .train-body { grid-template-columns: 1fr; }
  body.view-linia .train-card .train-body section + section { border-left: 0; border-top: 1px solid var(--line); }
  #line { padding: 64px 0 var(--pb, 196px); }
  #line.carded .line-foot { display: none; }
  .line-head b { font-size: 24px; }
  .line-foot { flex-direction: column; align-items: stretch; padding: 0 16px 16px; }
  .picker button { min-width: 44px; height: 44px; font-size: 26px; }
  .picker button[data-long] { font-size: 17px; }
  .stats > div { padding: 0 16px; flex: 1; }
  .stats b { font-size: 16px; white-space: nowrap; }
}
