:root {
  --panel: rgba(17, 20, 28, 0.8);
  --panel-solid: #151922;
  --border: rgba(255, 255, 255, 0.09);
  --text: #F3F0EA;
  --muted: #A4AAB6;
  --faint: rgba(255, 255, 255, 0.06);
  --hover: rgba(255, 255, 255, 0.11);
  --accent: #E2A341;
  --accent-ink: #1C1406;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --gutter: 16px;
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0D1320; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
kbd {
  font: 600 11px/1 Manrope, system-ui, sans-serif; padding: 3px 6px; border-radius: 6px;
  background: var(--faint); border: 1px solid var(--border); color: var(--muted);
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; }

.panel {
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------- top bar & search */
.topbar {
  position: fixed; top: var(--gutter); left: var(--gutter); z-index: 5;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; width: min(470px, calc(100vw - 2 * var(--gutter) - 64px));
}
.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); stroke: none; }
.brand div { display: flex; flex-direction: column; line-height: 1.05; }
.brand strong { font-weight: 800; font-size: 15px; letter-spacing: 0.02em; }
.brand span { font-size: 10.5px; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }

.search { position: relative; flex: 1; display: flex; align-items: center; gap: 8px; background: var(--faint); border-radius: 10px; padding: 0 8px 0 10px; border: 1px solid transparent; }
.search:focus-within { border-color: rgba(226, 163, 65, 0.6); background: rgba(255, 255, 255, 0.09); }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; height: 38px; background: none; border: 0; outline: none; font-size: 13.5px; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.results {
  position: absolute; left: -6px; right: -6px; top: calc(100% + 10px); margin: 0; padding: 6px; list-style: none;
  max-height: min(440px, 60vh); overflow: auto; background: var(--panel-solid);
}
.results li { display: grid; grid-template-columns: 10px 1fr; column-gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.results li[aria-selected="true"], .results li:hover { background: var(--hover); }
.results li i { grid-row: span 2; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.results .r-name { font-weight: 700; font-size: 13.5px; }
.results .r-sub { font-size: 11.5px; color: var(--muted); }

/* ------------------------------------------------------------- mode switch */
.modes {
  position: fixed; top: calc(var(--gutter) + 66px); left: var(--gutter); z-index: 4;
  display: flex; padding: 4px; gap: 2px; border-radius: 12px;
}
.modes button { border: 0; background: none; padding: 7px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.modes button:hover { color: var(--text); background: var(--faint); }
.modes button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------- layers panel */
.layers {
  position: fixed; z-index: 4; left: var(--gutter); top: calc(var(--gutter) + 118px); bottom: 64px; width: 316px;
  overflow: auto; padding: 6px 14px 14px; scrollbar-width: thin;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -6px; padding: 10px 0 6px; background: linear-gradient(var(--panel-solid) 70%, transparent); z-index: 1; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 800; }
.icon-btn { border: 0; background: var(--faint); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 15px; height: 15px; }
.layers section { padding: 8px 0 6px; border-top: 1px solid var(--border); }
.layers section:first-of-type { border-top: 0; }
.layers h3 { margin: 6px 0 6px; font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

.toggle { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.toggle:hover { background: var(--faint); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .sw { width: 30px; height: 18px; border-radius: 99px; background: rgba(255, 255, 255, 0.16); position: relative; transition: background .18s; }
.toggle .sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .18s; }
.toggle input:checked + .sw { background: var(--accent); }
.toggle input:checked + .sw::after { transform: translateX(12px); }
.toggle input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle .name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.toggle .meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toggle.disabled { opacity: 0.4; cursor: not-allowed; }
.swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.swatch.cycle { background: #0FA968; }
.swatch.metro { background: linear-gradient(90deg, #CC0000 50%, #00CC00 50%); }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 4px 2px; font-size: 12px; color: var(--muted); }
.slider input { grid-column: 1 / -1; accent-color: var(--accent); width: 100%; }
.slider output { grid-row: 1; grid-column: 2; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.seg { padding: 10px 4px 4px; font-size: 12px; color: var(--muted); }
.seg div { display: flex; gap: 2px; margin-top: 6px; padding: 3px; background: var(--faint); border-radius: 9px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--muted); }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: rgba(255, 255, 255, 0.14); color: var(--text); }

.legend .ramp { height: 8px; border-radius: 4px; background: linear-gradient(90deg, #F6F2EA, #E6E4DF 12%, #CCD6DF 30%, #A9BFD3 55%, #86A7C7); }
[data-theme="night"] .legend .ramp { background: linear-gradient(90deg, #161D2B, #1E2739 12%, #283752 30%, #344C78 55%, #4E74B0); }
[data-theme="dusk"] .legend .ramp { background: linear-gradient(90deg, #F8E0C8, #EDCBB4 12%, #D6B0A6 30%, #B396A8 55%, #8C84AE); }
.ramp-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin: 4px 0 10px; }
.lines { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; margin-bottom: 8px; }
.lines span { display: inline-flex; align-items: center; gap: 6px; }
.lines i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.credits { font-size: 11px; color: var(--muted); margin: 10px 4px 0; line-height: 1.5; }
.credits a { color: var(--text); }
.credits code { font-size: 10.5px; background: var(--faint); padding: 1px 5px; border-radius: 4px; }

/* ------------------------------------------------------------- toolbar */
.toolbar {
  position: fixed; z-index: 4; right: var(--gutter); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; padding: 5px; gap: 2px; border-radius: 13px;
}
.toolbar button { width: 38px; height: 38px; border: 0; background: none; border-radius: 9px; display: grid; place-items: center; color: var(--text); }
.toolbar button:hover { background: var(--hover); }
.toolbar button.active { background: var(--accent); color: var(--accent-ink); }
.toolbar hr { border: 0; height: 1px; background: var(--border); margin: 3px 6px; }
.toolbar .needle-n { fill: #E5484D; stroke: #E5484D; }
#compass-needle { transform-origin: 12px 12px; transition: transform .1s linear; }

/* ------------------------------------------------------------- info card */
.info {
  position: fixed; z-index: 5; right: calc(var(--gutter) + 62px); top: var(--gutter); width: 360px; max-height: calc(100vh - 2 * var(--gutter) - 50px);
  overflow: auto; padding: 18px 18px 16px; scrollbar-width: thin; animation: slide-in .22s ease-out;
}
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } }
.info-close { position: absolute; top: 12px; right: 12px; border: 0; background: var(--faint); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.info-close:hover { background: var(--hover); }
.info-close svg { width: 15px; height: 15px; }
.eyebrow { display: flex; align-items: center; gap: 8px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding-right: 34px; }
.eyebrow i { width: 9px; height: 9px; border-radius: 50%; }
.info h2 { margin: 8px 0 2px; font-size: 22px; line-height: 1.2; font-weight: 800; letter-spacing: -0.01em; }
.info .arabic { font-size: 16px; color: var(--muted); margin-top: 2px; }
.info .desc { margin: 10px 0 0; font-size: 13.5px; line-height: 1.5; color: #D9D5CD; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 16px 0 0; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.info dd a { color: var(--accent); text-decoration: none; }
.info dd a:hover { text-decoration: underline; }
.chips-title { margin: 16px 0 8px; font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--faint); border-radius: 99px; padding: 5px 10px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--hover); }
.chip i { width: 7px; height: 7px; border-radius: 50%; }
.info .note { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 14px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions button { border: 1px solid var(--border); background: var(--faint); border-radius: 9px; padding: 8px 12px; font-size: 12.5px; font-weight: 700; }
.actions button:hover { background: var(--hover); }
.actions button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.actions button.primary:hover { filter: brightness(1.08); }

/* ------------------------------------------------------------- tooltip, caption, toast */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 6; pointer-events: none; padding: 6px 10px; border-radius: 9px;
  background: rgba(17, 20, 28, 0.86); border: 1px solid var(--border); display: flex; flex-direction: column; font-size: 12.5px; white-space: nowrap;
}
.tooltip span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.caption {
  position: fixed; z-index: 5; left: 50%; bottom: 110px; transform: translateX(-50%); padding: 14px 22px; text-align: center;
  display: flex; flex-direction: column; gap: 2px; min-width: 280px; max-width: calc(100vw - 32px); animation: rise .4s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.caption span { font-size: 10.5px; letter-spacing: 0.16em; color: var(--accent); font-weight: 800; }
.caption strong { font-size: 20px; font-weight: 800; }
.caption em { font-style: normal; color: var(--muted); font-size: 13px; }
.toast { position: fixed; z-index: 7; top: var(--gutter); left: 50%; transform: translateX(-50%); padding: 9px 14px; font-size: 12.5px; font-weight: 600; }

/* ------------------------------------------------------------- destinations & status bar */
.dest {
  position: fixed; z-index: 3; bottom: 58px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px;
  max-width: min(980px, calc(100vw - 2 * var(--gutter))); overflow-x: auto; padding: 4px; scrollbar-width: none;
  mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}
.dest::-webkit-scrollbar { display: none; }
.dest button {
  flex: none; border: 1px solid var(--border); background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: 99px; padding: 7px 13px; font-size: 12.5px; font-weight: 700; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
.layers-open .dest { left: calc(316px + 2 * var(--gutter)); right: 76px; transform: none; max-width: none; }
.dest button:first-child { margin-left: 12px; }
.dest button:last-child { margin-right: 12px; }
.dest button:hover { background: var(--accent); color: var(--accent-ink); }

.statusbar {
  position: fixed; z-index: 3; left: var(--gutter); bottom: var(--gutter); display: flex; align-items: center; gap: 14px;
  padding: 7px 14px; border-radius: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
  max-width: calc(100vw - 2 * var(--gutter) - 140px); white-space: nowrap;
}
.statusbar .where { color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.statusbar .cursor { border: 0; background: none; padding: 0; color: inherit; font-size: inherit; font-variant-numeric: tabular-nums; }
.statusbar .cursor:hover { color: var(--text); }
.statusbar .osm { opacity: 0.7; }

/* ------------------------------------------------------------- help */
.help { position: fixed; z-index: 6; right: calc(var(--gutter) + 62px); bottom: var(--gutter); width: 300px; padding: 4px 16px 14px; }
.help .panel-head { background: none; position: static; }
.help dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 6px 0 0; font-size: 12.5px; }
.help dt { color: var(--muted); white-space: nowrap; }
.help dd { margin: 0; text-align: right; font-weight: 600; }

/* ------------------------------------------------------------- MapLibre controls */
.maplibregl-ctrl-bottom-right { right: 2px; bottom: 2px; }
.maplibregl-ctrl-attrib.maplibregl-compact { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.maplibregl-ctrl-attrib.maplibregl-compact a { color: var(--text); }
.maplibregl-ctrl-attrib-button { filter: invert(1) opacity(0.75); }
.maplibregl-ctrl-scale { background: rgba(17, 20, 28, 0.7); color: var(--text); border-color: var(--muted); font: 600 10.5px Manrope, system-ui, sans-serif; }

/* ------------------------------------------------------------- loader */
#loader {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: radial-gradient(ellipse at 50% 40%, #1E2638, #0B0F18 70%); transition: opacity .6s ease, visibility .6s;
}
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
#loader svg { width: 46px; height: 46px; fill: var(--accent); stroke: none; margin-bottom: 6px; }
#loader strong { font-size: 20px; font-weight: 800; letter-spacing: 0.02em; }
#loader span { color: var(--muted); font-size: 13px; }
#loader .bar { width: 180px; height: 3px; border-radius: 3px; background: var(--faint); overflow: hidden; margin-top: 10px; }
#loader .bar i { display: block; width: 40%; height: 100%; background: var(--accent); border-radius: 3px; animation: load 1.2s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ------------------------------------------------------------- small screens */
@media (max-width: 1100px) {
  .info { right: calc(var(--gutter) + 62px); width: 330px; }
}
@media (max-width: 760px) {
  :root { --gutter: 10px; }
  .topbar { width: auto; right: calc(var(--gutter) + 56px); padding: 6px 6px 6px 10px; }
  .brand div { display: none; }
  .search kbd { display: none; }
  .modes { top: calc(var(--gutter) + 58px); }
  .modes button { padding: 6px 10px; }
  .toolbar { top: var(--gutter); transform: none; }
  .toolbar button { width: 36px; height: 36px; }
  .toolbar [data-act="snapshot"], .toolbar [data-act="help"], .toolbar [data-act="fullscreen"] { display: none; }
  .layers, .info {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 62vh; border-radius: 18px 18px 0 0;
    animation: sheet .24s ease-out; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  @keyframes sheet { from { transform: translateY(30px); opacity: 0; } }
  .layers { z-index: 8; }
  .info { z-index: 9; }
  .dest { bottom: 50px; }
  .maplibregl-ctrl-bottom-right { bottom: 92px; }
  .statusbar { left: var(--gutter); right: var(--gutter); max-width: none; justify-content: space-between; }
  .statusbar .cursor, .statusbar .osm { display: none; }
  .caption { bottom: 100px; }
  .help { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
