:root {
  --bg: #101114;
  --glass: rgba(20, 21, 25, 0.78);
  --glass-strong: rgba(20, 21, 25, 0.92);
  --ink: #f4f4f2;
  --ink-2: #b9b9b3;
  --ink-3: #85857f;
  --hair: rgba(255, 255, 255, 0.08);
  --fill: rgba(255, 255, 255, 0.06);
  --fill-2: rgba(255, 255, 255, 0.12);
  --accent: #f5c542;
  --live: #3ddc84;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-ui: cubic-bezier(0.2, 0, 0, 1);
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 8px 24px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  --r-card: 16px;
  --pad: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body {
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#map { position: absolute; inset: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- cards ---------- */
.card {
  position: absolute; z-index: 10;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: var(--pad);
}

.brand { top: 16px; left: 16px; width: 300px; }
.brand-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
.brand-ar { margin: 1px 0 0; color: var(--ink-3); font-size: 12px; text-align: left; }

.icon-btn {
  width: 32px; height: 32px; margin: -6px -6px 0 0; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); cursor: pointer;
  transition-property: background-color, color, scale;
  transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.icon-btn:hover { background: var(--fill); color: var(--ink); }
.icon-btn:active { scale: 0.96; }
.icon-btn svg, .seg svg, .search svg, .chev, .close svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}

.clock-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 10px; }
.clock { display: flex; flex-direction: column; }
#clock-time { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.clock-date { color: var(--ink-3); font-size: 12px; margin-top: 2px; }

.live-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 8px; border-radius: 999px;
  background: var(--fill); color: var(--ink-2);
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  transition-property: background-color, color; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.live-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); transition: background-color 150ms var(--ease-out); }
.live-chip[data-live="true"] { background: rgba(61, 220, 132, 0.14); color: var(--live); }
.live-chip[data-live="true"] i { background: var(--live); animation: pulse 2s var(--ease-out) infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); } 100% { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); } }

/* segmented control: outer radius 10 = inner 7 + padding 3 */
.controls { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--fill); }
.seg {
  flex: 1; height: 30px; min-width: 0; padding: 0 6px;
  border: 0; border-radius: 7px; background: transparent; color: var(--ink-2); cursor: pointer;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  transition-property: background-color, color, scale, box-shadow;
  transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.seg:hover { color: var(--ink); }
.seg:active { scale: 0.96; }
.seg[aria-pressed="true"] { background: var(--fill-2); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.seg-icon { flex: 0 0 38px; display: grid; place-items: center; }
.swap { position: relative; width: 18px; height: 18px; display: block; }
.swap svg { position: absolute; inset: 0; transition-property: opacity, scale, filter; transition-duration: 200ms; transition-timing-function: var(--ease-ui); }
.swap .ico-play { opacity: 0; scale: 0.25; filter: blur(4px); }
#pause-btn[aria-pressed="true"] .ico-pause { opacity: 0; scale: 0.25; filter: blur(4px); }
#pause-btn[aria-pressed="true"] .ico-play { opacity: 1; scale: 1; filter: blur(0); }

.scrub { display: block; margin-top: 12px; }
.scrub input { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; height: 20px; }
.scrub-ticks { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 10px; font-variant-numeric: tabular-nums; padding: 0 2px; }

/* ---------- legend ---------- */
.legend { left: 16px; bottom: 16px; width: 300px; padding: 6px; }
.legend-head {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 10px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-weight: 600; text-align: left;
  transition-property: background-color; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.legend-head:hover { background: var(--fill); }
.legend-total { margin-left: auto; color: var(--ink-3); font-weight: 500; font-size: 12px; font-variant-numeric: tabular-nums; }
.legend-total b { color: var(--ink); font-weight: 600; }
.chev { color: var(--ink-3); transition: rotate 200ms var(--ease-out); }
.legend[data-collapsed="true"] .chev { rotate: -90deg; }
.legend[data-collapsed="true"] #line-list, .legend[data-collapsed="true"] .search { display: none; }

#line-list { list-style: none; margin: 2px 0 4px; padding: 0; }
.line-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left;
  transition-property: background-color, opacity; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.line-item:hover { background: var(--fill); }
.line-item[aria-pressed="false"] { opacity: 0.42; }
.line-badge {
  flex: none; min-width: 34px; height: 20px; padding: 0 6px; border-radius: 6px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.line-text { min-width: 0; flex: 1; }
.line-name { display: block; font-weight: 600; }
.line-sub { display: block; color: var(--ink-3); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-count { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12px; }

.search { position: relative; margin: 2px 4px 4px; }
.search > svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 34px; padding: 0 10px 0 32px;
  border: 0; border-radius: 8px; background: var(--fill); color: var(--ink); font: inherit;
  outline: none; transition: box-shadow 150ms var(--ease-out);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus-visible { box-shadow: 0 0 0 2px rgba(245, 197, 66, 0.55); }
#search-results {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 2;
  list-style: none; margin: 0; padding: 4px; border-radius: 12px;
  background: var(--glass-strong); box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
#search-results:empty { display: none; }
#search-results li {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--fill-2); }
#search-results .dots { display: flex; gap: 3px; margin-left: auto; }
#search-results .dots i { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- detail panel ---------- */
.detail {
  top: 16px; right: 16px; width: 320px; max-height: calc(100vh - 32px - 110px);
  display: flex; flex-direction: column; padding: 0; overflow: hidden;
  transition-property: opacity, translate; transition-duration: 220ms; transition-timing-function: var(--ease-out);
}
.detail[data-state="enter"] { opacity: 0; translate: 0 -6px; }
.detail-head { padding: var(--pad) var(--pad) 12px; border-bottom: 1px solid var(--hair); }
.detail-top { display: flex; align-items: center; gap: 8px; }
.detail-title { font-size: 15px; font-weight: 650; margin: 8px 0 2px; text-wrap: balance; }
.detail-sub { color: var(--ink-2); margin: 0; }
.detail-sub [lang="ar"] { color: var(--ink-3); }
.close {
  margin-left: auto; width: 30px; height: 30px; border: 0; border-radius: 9px; background: transparent;
  display: grid; place-items: center; color: var(--ink-2); cursor: pointer;
  transition-property: background-color, color, scale; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.close:hover { background: var(--fill); color: var(--ink); }
.close:active { scale: 0.96; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--fill); border-radius: 10px; padding: 7px 9px; }
.stat b { display: block; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.25; overflow-wrap: anywhere; }
.stat span { color: var(--ink-3); font-size: 11px; }
.follow-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--ink-2); font-size: 12px; }
.follow-row button {
  margin-left: auto; flex: none; white-space: nowrap; height: 28px; padding: 0 10px; border: 0; border-radius: 8px; background: var(--fill-2); cursor: pointer; font-size: 12px; font-weight: 600;
  transition-property: background-color, scale; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.follow-row button:hover { background: rgba(255, 255, 255, 0.18); }
.follow-row button:active { scale: 0.96; }

.detail-body { overflow-y: auto; padding: 10px var(--pad) var(--pad); overscroll-behavior: contain; }
.stops { list-style: none; margin: 0; padding: 0; position: relative; }
.stop { position: relative; display: flex; align-items: baseline; gap: 10px; padding: 5px 0 5px 22px; color: var(--ink-2); }
.stop::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 3px; background: var(--c); opacity: 0.9; }
.stop:first-child::before { top: 50%; }
.stop:last-child::before { bottom: 50%; }
.stop::after {
  content: ""; position: absolute; left: 2px; top: calc(50% - 5.5px); width: 11px; height: 11px; border-radius: 50%;
  background: var(--bg); box-shadow: inset 0 0 0 2.5px var(--c);
}
.stop.passed { color: var(--ink-3); }
.stop.passed::before, .stop.passed::after { opacity: 0.35; }
.stop.next { color: var(--ink); font-weight: 600; }
.stop.next::after { background: var(--c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 30%, transparent); }
.stop .t { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 500; }
.stop.next .t { color: var(--ink); }
.stop.skip { display: none; }

.deps { list-style: none; margin: 0 0 12px; padding: 0; }
.deps h4 { margin: 12px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.dep { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.dep .dest { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .t { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.dep .in { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { color: var(--ink-3); padding: 8px 0; }

/* ---------- banner, tooltip, dialog ---------- */
.banner {
  position: absolute; z-index: 12; top: 16px; left: 16px; right: 16px; margin-inline: auto; width: fit-content;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; border-radius: 12px;
  background: var(--glass-strong); box-shadow: var(--shadow); text-wrap: pretty;
}
.banner-btn {
  height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--accent); color: #1a1a1a;
  font-weight: 650; cursor: pointer; white-space: nowrap;
  transition-property: scale, filter; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.banner-btn:hover { filter: brightness(1.06); }
.banner-btn:active { scale: 0.96; }

#tooltip {
  position: absolute; z-index: 20; pointer-events: none; display: none;
  padding: 6px 9px; border-radius: 8px; background: var(--glass-strong); box-shadow: var(--shadow);
  font-size: 12px; white-space: nowrap;
}
#tooltip .tt-sub { color: var(--ink-3); }

dialog {
  border: 0; padding: 0; border-radius: 18px; max-width: min(520px, calc(100vw - 32px));
  background: #17181c; color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px); }
dialog[open] { animation: dialog-in 260ms var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; translate: 0 8px; scale: 0.98; } }
.about-inner { padding: 22px 24px 20px; max-height: calc(100vh - 64px); overflow-y: auto; }
.about-inner h2 { margin: 0 0 8px; font-size: 18px; }
.about-inner h3 { margin: 16px 0 6px; font-size: 13px; color: var(--ink-2); }
.about-inner p, .about-inner li { color: var(--ink-2); }
.about-inner ul { padding-left: 18px; margin: 0; }
.about-inner li { margin: 4px 0; }
.about-inner a { color: var(--ink); }
.about-inner .fine { font-size: 11.5px; color: var(--ink-3); margin-top: 16px; }
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border-radius: 4px; background: var(--fill-2); }
.primary {
  margin-top: 8px; height: 36px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--accent); color: #1a1a1a;
  font-weight: 650; cursor: pointer;
  transition-property: scale, filter; transition-duration: 150ms; transition-timing-function: var(--ease-out);
}
.primary:active { scale: 0.96; }

/* ---------- maplibre chrome ---------- */
.maplibregl-ctrl-group { background: var(--glass) !important; backdrop-filter: blur(14px); border-radius: 12px !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.maplibregl-ctrl-group button { width: 34px; height: 34px; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--hair) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) opacity(0.85); }
.maplibregl-ctrl-attrib { background: rgba(20, 21, 25, 0.6) !important; color: var(--ink-3); border-radius: 8px 0 0 0; }
.maplibregl-ctrl-attrib a { color: var(--ink-2) !important; }
.maplibregl-ctrl-attrib-button { filter: invert(1); }
body.has-detail .maplibregl-ctrl-top-right { translate: -336px 0; }
.maplibregl-ctrl-top-right { transition: translate 220ms var(--ease-out); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  :root { --pad: 12px; }
  .brand { top: 12px; left: 12px; right: 12px; width: auto; }
  .brand-ar { display: none; }
  .clock-row { margin: 8px 0; }
  #clock-time { font-size: 24px; }
  .scrub { display: none; }
  .legend { left: 12px; right: 48px; bottom: 12px; width: auto; }
  .detail { top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 52vh; z-index: 11; }
  .detail[data-state="enter"] { translate: 0 8px; }
  body.has-detail .maplibregl-ctrl-top-right { translate: 0 0; }
  .maplibregl-ctrl-top-right { top: 176px; }
  .banner { top: auto; bottom: 84px; left: 12px; right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0ms !important; }
}
