:root {
  --bg: #0a0f1d;
  --panel: #10172a;
  --card: #161f35;
  --card-hi: #1b2640;
  --line: #26324d;
  --text: #f5f0e7;
  --muted: #a3aec4;
  --gold: #ffc35c;
  --gold-hi: #ffd68a;
  --ink: #1b1306;
  --soon: #9dbbff;
  --grey: #6d7891;
  --danger: #ff9b8a;
  --map-h: 56svh;
  --radius: 18px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: Fraunces, Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--gold-hi); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- map ---------- */
.map {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--map-h);
  z-index: 0;
  background: #0d1424;
}
.maplibregl-ctrl-attrib { background: rgba(10, 15, 29, .72) !important; color: var(--muted); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-ctrl-attrib-button { filter: invert(1); }
.map-fallback {
  position: fixed; inset: 0 0 auto 0; height: var(--map-h);
  display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted);
}
body.no-map { --map-h: 0px; }
body.no-map .map-controls { display: none; }

.map-controls {
  position: fixed;
  z-index: 1;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 12px;
  display: grid;
  gap: 8px;
}
.map-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 23, 42, .88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.map-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }
.map-btn svg .fill { fill: var(--gold); stroke: none; }
.map-btn.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* pins */
.pin-wrap { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; background: none; border: 0; border-radius: 50%; }
.pin {
  position: relative;
  display: grid; place-items: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  font: 700 13px/1 var(--font);
  color: var(--ink);
  transition: opacity .2s;
}
.pin.s-on {
  background: radial-gradient(circle, #fff6dc 0 22%, #ffd36b 40%, #ffb340 70%);
  box-shadow: 0 0 0 2px rgba(255, 195, 92, .3), 0 0 12px 4px rgba(255, 176, 64, .65), 0 0 28px 8px rgba(255, 176, 64, .25);
  animation: twinkle 3.2s ease-in-out infinite;
}
.pin.s-soon { background: #2c3c63; border: 2px solid var(--soon); }
.pin.s-over, .pin.s-unknown { background: #39435b; border: 2px solid var(--grey); }
.pin.ev { border-radius: 4px; transform: rotate(45deg) scale(.86); }
.pin.drive {
  width: 28px; height: 28px;
  background: var(--gold);
  border: 2px solid #fff4d6;
  transform: none;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 195, 92, .25), 0 0 22px 6px rgba(255, 176, 64, .6);
  animation: none;
}
.pin.faded { opacity: .22; animation: none; box-shadow: none; }
@keyframes twinkle { 50% { box-shadow: 0 0 0 2px rgba(255, 195, 92, .2), 0 0 8px 2px rgba(255, 176, 64, .5), 0 0 18px 4px rgba(255, 176, 64, .15); } }
.me {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  background: #4c8dff; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(76, 141, 255, .25);
}

/* popups */
.glow-pop .maplibregl-popup-content {
  padding: 12px 14px;
  background: var(--card-hi);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
  min-width: 190px;
}
.glow-pop.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--card-hi); }
.glow-pop.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--card-hi); }
.glow-pop.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--card-hi); }
.glow-pop.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--card-hi); }
.pop { display: grid; gap: 4px; justify-items: start; }
.pop strong { font-size: 15px; line-height: 1.25; }
.pop-where { color: var(--muted); font-size: 13px; }
.pop .btn { margin-top: 6px; }

/* ---------- panel ---------- */
.panel {
  position: relative;
  z-index: 2;
  margin-top: calc(var(--map-h) - 22px);
  min-height: calc(100svh - var(--map-h) + 22px);
  padding: 6px 16px calc(120px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.brand { display: flex; align-items: center; gap: 12px; }
.star {
  width: 34px; height: 34px; flex: none;
  background: var(--gold);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 8px rgba(255, 195, 92, .8));
}
h1 { margin: 0; font: 700 23px/1.1 var(--display); letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }

.search {
  position: relative;
  margin: 14px 0 10px;
}
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%;
  height: 48px;
  padding: 0 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-size: 16px; /* stops iOS zooming in */
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.clear {
  position: absolute; right: 4px; top: 4px;
  width: 40px; height: 40px;
  border: 0; background: none; color: var(--muted); font-size: 24px;
}

.chips {
  display: flex; gap: 8px;
  overflow-x: auto;
  margin: 0 -16px;
  padding: 2px 16px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.chip-gap { flex: none; width: 1px; background: var(--line); margin: 6px 2px; }

.summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 14px 0 8px; }
.summary p { margin: 0; color: var(--muted); font-size: 14px; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--gold-hi); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }

/* cards */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.card.picked { border-color: rgba(255, 195, 92, .55); box-shadow: inset 3px 0 0 var(--gold); }
.card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dist { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.card h3 { margin: 8px 0 2px; font-size: 17px; line-height: 1.25; }
.card-title { border: 0; background: none; padding: 0; text-align: left; font-weight: 700; }
.card-title:hover { color: var(--gold-hi); }
.where, .when { margin: 0; color: var(--muted); font-size: 14px; }
.when { color: var(--text); }
.note { margin: 6px 0 0; font-size: 14px; color: #cfd6e4; }
.card-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.card-actions .src { margin-left: auto; color: var(--muted); }

.pill, .tag {
  display: inline-flex; align-items: center;
  height: 24px; padding: 0 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .01em;
}
.pill.s-on { background: rgba(255, 195, 92, .16); color: var(--gold-hi); }
.pill.s-on::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 6px var(--gold); margin-right: 6px; }
.pill.s-soon { background: rgba(157, 187, 255, .14); color: var(--soon); }
.pill.s-over, .pill.s-unknown { background: rgba(109, 120, 145, .2); color: #b9c1d2; }
.tag { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.tag.new { border-color: rgba(157, 187, 255, .4); color: var(--soon); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700; font-size: 14.5px;
  text-decoration: none;
  white-space: nowrap;
}
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: var(--gold-hi); }
.btn.added { background: transparent; border-color: var(--gold); color: var(--gold-hi); }
.btn.added::before { content: "✓"; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; min-height: 50px; font-size: 16px; }

.empty { padding: 20px 16px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }
.empty h3 { margin: 0 0 4px; font-size: 17px; }
.empty p { margin: 0; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }

.more { margin-top: 28px; padding: 18px; border-radius: var(--radius); background: linear-gradient(135deg, #1a2440, #141c31); border: 1px solid var(--line); }
.more h2 { margin: 0 0 4px; font: 700 18px/1.2 var(--display); }
.more p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.foot { margin-top: 22px; color: var(--muted); font-size: 12.5px; }
.foot p { margin: 0 0 8px; }
.foot a { color: var(--muted); }

/* ---------- floating bits ---------- */
.back-to-map {
  position: fixed; z-index: 4;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgba(27, 38, 64, .95);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.back-to-map svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
body.has-dock .back-to-map { bottom: calc(env(safe-area-inset-bottom) + 92px); }

.dock {
  position: fixed; z-index: 5;
  left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex; gap: 8px; align-items: center;
  padding: 8px;
  border: 1px solid rgba(255, 195, 92, .35);
  border-radius: 20px;
  background: rgba(22, 31, 53, .96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
}
.dock-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 8px; border: 0; background: none; text-align: left; }
.dock-dots { display: grid; grid-template-columns: repeat(2, 9px); gap: 4px; flex: none; }
.dock-dots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--grey); }
.dock-dots i.on { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 6px var(--gold); }
.dock-text { display: grid; min-width: 0; }
.dock-text strong { font-size: 15px; }
.dock-text span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-go { min-height: 48px; padding: 0 22px; font-size: 16px; }

.toast {
  position: fixed; z-index: 20;
  left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 14px);
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 14px;
  background: #f5f0e7; color: #10172a;
  font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
}

/* ---------- sheets ---------- */
dialog.sheet {
  width: 100%; max-width: 100%;
  max-height: 90svh;
  margin: auto 0 0;
  padding: 0;
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  color: var(--text);
  overflow: auto;
}
dialog.sheet[open] { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
dialog::backdrop { background: rgba(4, 7, 15, .6); backdrop-filter: blur(2px); }
.sheet-inner { padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font: 700 22px/1.15 var(--display); }
.sheet-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card);
  font-size: 18px; line-height: 1;
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.stops { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stop { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.num { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--gold); color: var(--ink); font-weight: 800; font-size: 14px; }
.stop-text { flex: 1; min-width: 0; display: grid; }
.stop-text strong { font-size: 15px; line-height: 1.25; }
.stop-text span { color: var(--muted); font-size: 13px; }
.stop-text .warn { color: var(--danger); font-weight: 600; }
.stop-ctl { display: flex; gap: 4px; }
.stop-ctl .icon-btn { width: 36px; height: 36px; }
.hint { margin: -4px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row .btn { flex: 1 1 auto; }
.empty-drive { margin: 0; color: var(--muted); }
.presets h3 { margin: 6px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.preset {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 8px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); text-align: left;
}
.preset-text { display: grid; }
.preset-text small { color: var(--muted); font-size: 13px; }
.plus { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255, 195, 92, .16); color: var(--gold-hi); font-size: 20px; font-weight: 700; }
form.sheet-inner label { font-weight: 600; font-size: 14px; margin-bottom: -6px; }
form.sheet-inner label span { color: var(--muted); font-weight: 400; }
form.sheet-inner input { height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 16px; }

@media (max-width: 359px) {
  h1 { font-size: 20px; }
  .card-actions .btn { padding: 0 12px; }
}

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  :root { --map-h: 100vh; }
  body { overflow: hidden; }
  .map, .map-fallback { inset: 0 0 0 440px; height: auto; }
  .panel {
    position: fixed; inset: 0 auto 0 0;
    width: 440px;
    margin: 0; min-height: 0;
    overflow-y: auto;
    border-radius: 0;
    padding: 22px 22px 120px;
    border-right: 1px solid var(--line);
  }
  .grabber { display: none; }
  .chips { margin: 0; padding: 2px 0 4px; flex-wrap: wrap; }
  .dock { left: 16px; right: auto; width: 408px; bottom: 16px; }
  .back-to-map { display: none !important; }
  dialog.sheet { max-width: 460px; margin: auto; border-radius: 24px; border-bottom: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
