:root {
  --bg: #0b1020;
  --panel: rgba(14, 19, 36, 0.92);
  --fg: #e8ecf5;
  --muted: #8a93a8;
  --border: rgba(255, 255, 255, 0.08);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute; z-index: 2; top: 12px; left: 12px; width: 300px; max-height: calc(100% - 24px);
  overflow-y: auto; background: var(--panel); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; font-size: 14px;
}
.title-row { display: flex; align-items: center; gap: 8px; }
h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 700; }
h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 0 #3ddc84; animation: pulse 2s infinite; }
.live-dot.stale { background: #f5a524; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61,220,132,.6); } 70% { box-shadow: 0 0 0 8px rgba(61,220,132,0); } 100% { box-shadow: 0 0 0 0 rgba(61,220,132,0); } }
#summary { margin: 8px 0 2px; }
.muted { color: var(--muted); margin: 0; font-size: 12px; }
.roster-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 6px; }
.linkish { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; }
.linkish:hover { color: var(--fg); }
#panel-toggle { display: none; }
#roster { list-style: none; margin: 0; padding: 0; }
#roster li { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; border-radius: 8px; }
#roster li:hover { background: rgba(255,255,255,.04); }
#roster li.off .line-toggle { opacity: .35; }
.line-toggle { min-width: 0; display: flex; align-items: center; gap: 10px; padding: 5px 4px; color: inherit; background: none; border: 0; cursor: pointer; text-align: left; }
.badge { min-width: 38px; text-align: center; padding: 2px 6px; border-radius: 6px; font-weight: 700; font-size: 12px; }
#roster .name { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#roster .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.alert-toggle { align-self: center; width: 22px; height: 22px; margin-right: 2px; border: 1px solid #f5a524; border-radius: 50%; background: rgba(245,165,36,.12); color: #f5a524; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.alert-toggle.severe { border-color: #f05252; color: #f05252; background: rgba(240,82,82,.12); }
.alerts { grid-column: 1 / -1; padding: 2px 8px 8px 52px; }
.alerts article { border-left: 2px solid #f5a524; padding-left: 8px; margin: 5px 0 9px; font-size: 11px; line-height: 1.35; }
.alerts strong { color: #f5a524; }
.alerts p { margin: 3px 0 0; color: var(--muted); white-space: pre-line; }

#card {
  position: absolute; right: 12px; top: 12px; width: 330px; max-height: calc(100% - 24px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; font-size: 14px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent;
}
#card .head { position: sticky; top: -14px; z-index: 2; display: flex; align-items: center; gap: 8px; margin: -14px -16px 0; padding: 14px 16px 8px; background: rgb(14 19 36 / .97); }
#card .head .dest { flex: 1; font-size: 16px; font-weight: 700; line-height: 1.15; }
#card .close { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
#card .state { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.journey { list-style: none; padding: 0; margin: 8px 0 0; }
.journey li { position: relative; display: grid; grid-template-columns: 18px 1fr auto; min-height: 30px; align-items: start; padding: 4px 0; }
.journey li::before { content: ''; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.13); }
.journey li:first-child::before { top: 10px; }
.journey li:last-child::before { bottom: calc(100% - 10px); }
.journey .stop-dot { position: relative; z-index: 1; width: 10px; height: 10px; margin: 3px 0 0 2px; border: 2px solid var(--muted); border-radius: 50%; background: #0e1324; }
.journey .stop-name { padding-right: 8px; line-height: 1.2; }
.journey .eta { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.journey .past { color: #666f84; }
.journey .past .stop-dot { border-color: #596174; background: #596174; }
.journey .current { font-weight: 700; }
.journey .current .stop-dot { border-color: #fff; background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.16); }
.journey .current .eta { color: var(--fg); }
.occupancy { padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.occupancy h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 500; }
.cars { display: flex; gap: 4px; }
.car { flex: 1; display: grid; justify-items: center; gap: 2px; font-size: 9px; color: var(--muted); }
.car i { display: block; width: 100%; height: 14px; border: 1px solid var(--muted); border-radius: 3px; background: linear-gradient(to right, #3ddc84 var(--level), transparent var(--level)); }
.car b { font-size: 9px; font-weight: 500; }
.car small { font-size: 8px; }

#tip {
  position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; font-size: 12px; white-space: nowrap; transform: translate(10px, -50%);
}

@media (max-width: 640px) {
  #panel { top: auto; bottom: 12px; width: auto; left: 12px; right: 12px; max-height: calc(100% - 24px); }
  #clock, #updated { display: none; }
  #panel-toggle { display: block; position: absolute; right: 14px; top: 46px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,.06); color: var(--fg); font: inherit; font-size: 12px; font-weight: 600; }
  #panel-body { max-height: 48vh; overflow-y: auto; transition: max-height .2s ease; }
  #panel.mobile-collapsed #panel-body { display: none; }
  #panel.mobile-collapsed { padding-bottom: 12px; }
  #panel.mobile-collapsed #summary { margin-bottom: 0; }
  #card { z-index: 3; top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 62%; }
  #tip { display: none; }
}
