:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1b1f24; --muted: #5d6673;
  --border: #d9dde3; --accent: #1a73e8; --accent-text: #fff; --warn: #b3261e;
  --card-r: 8px; --danger: #d93025; --hover: rgba(60,64,67,.08); --tint: #e8f0fe;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --panel: #1f2329; --text: #e6e9ed; --muted: #9aa3ae;
    --border: #343a42; --accent: #8ab4f8; --accent-text: #0b1a33; --warn: #f2b8b5;
    --danger: #e46962; --hover: rgba(232,234,237,.08); --tint: rgba(138,180,248,.16);
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
html, body { overflow: hidden; overscroll-behavior: none; } /* no pull-to-refresh / rubber-banding: it's an app */
body { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input { font: inherit; color: var(--text); }
button {
  cursor: pointer; white-space: nowrap; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.danger:hover { filter: brightness(.94); }
button:disabled { opacity: .45; cursor: default; }
.icon { width: 22px; height: 22px; fill: currentColor; display: block; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--text);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small .icon { width: 18px; height: 18px; }
.icon-btn.play { width: 44px; height: 44px; background: var(--accent); color: var(--accent-text); }
.icon-btn.play:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.icon-btn.play .icon { width: 26px; height: 26px; }

/* ---------- layout ---------- */
.app {
  height: 100%; display: flex; flex-direction: column;
  /* Keep clear of notches / rounded corners (viewport-fit=cover). */
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.app main { flex: 1; display: flex; min-height: 0; }
.map-wrap { position: relative; flex: 1 1 50%; min-width: 0; }
.map { position: absolute; inset: 0; }
.sv { flex: 1 1 50%; display: flex; min-width: 0; border-left: 1px solid var(--border); }
/* Plan mode: map only. Street View appears once a route is started. */
.app.plan .sv { display: none; }

/* ---------- stops card ---------- */
.side {
  position: absolute; z-index: 2; left: 12px; top: calc(12px + env(safe-area-inset-top)); width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 48px - env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 10px;
}
/* The stack card and the search box share one shape. */
.search { flex: none; color-scheme: light; }
.search gmp-place-autocomplete { width: 100%; border-radius: var(--card-r); border-color: #dadce0; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.panel {
  flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border-radius: var(--card-r); box-shadow: 0 2px 10px rgba(0,0,0,.25); overflow: hidden;
}
.app.drive .side { max-height: min(60%, calc(100% - 48px - env(safe-area-inset-top))); }
.panel-head { padding: 10px 14px; cursor: pointer; user-select: none; }
.panel-head:hover { background: var(--hover); }
.panel-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.panel-row { display: flex; align-items: center; gap: 8px; }
.panel-title { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-size: 15px; }
.panel-clear {
  margin: -4px -8px -4px auto; padding: 4px 10px; border: 0; border-radius: 999px;
  background: transparent; color: var(--accent); font-size: 13px; font-weight: 500;
}
.panel-clear:hover { background: var(--hover); }
.panel-progress { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* Collapsed while driving: current leg and the next key point */
.brief { display: grid; gap: 4px; margin-top: 6px; font-size: 13px; }
.brief-leg, .brief-key { display: flex; align-items: center; gap: 6px; min-width: 0; }
.brief-leg .pin-badge { width: 18px; height: 18px; font-size: 10px; }
.brief-arrow { color: var(--muted); }
.brief-count { margin-left: auto; flex: none; color: var(--muted); font-size: 12px; }
.brief-leg .brief-text { font-weight: 600; margin-left: 2px; }
.brief-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-n.next { background: #e37400; }
.panel-body { overflow-y: auto; border-top: 1px solid var(--border); padding: 6px 0; }
.pin-badge {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font-size: 11px; font-weight: 700; box-shadow: 0 0 0 2px var(--panel), 0 1px 2px rgba(0,0,0,.3);
}
.stops, .itin, .turns { list-style: none; margin: 0; padding: 0; }
.stop { display: flex; align-items: center; gap: 10px; padding: 3px 6px 3px 14px; }
.stop-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Plan list: drag handle, badge, name, remove; dotted connector between stacked stops */
.stops .stop { position: relative; min-height: 42px; padding: 3px 6px 3px 14px; gap: 10px; background: var(--panel); }
.stops .stop .stop-name { margin-right: 2px; }
.drag-handle { flex: none; width: 26px; height: 30px; }
.drag-handle {
  display: grid; place-items: center; padding: 0; border: 0; background: transparent;
  color: var(--muted); cursor: grab; touch-action: none; border-radius: 6px;
}
.drag-handle .icon { width: 18px; height: 18px; }
.drag-handle:hover, .drag-handle:focus-visible { background: var(--hover); color: var(--text); }
.stop.dragging { box-shadow: 0 2px 8px rgba(0,0,0,.25); border-radius: 8px; z-index: 1; cursor: grabbing; }
.stop.dragging .drag-handle { cursor: grabbing; }
.stop:hover .drag-handle { color: var(--text); }

/* Drive itinerary: stops with each leg's turns between them; a rail fills as you go. */
.itin .stop { padding: 0; }
.stop-jump, .turn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; border-radius: 0; background: transparent; padding: 6px 14px;
}
.stop-jump:hover, .turn:hover { background: var(--hover); }
.stop-jump { min-height: 42px; } /* same row height as the plan list, so the badges stay put */
.stop-jump .stop-name { font-weight: 600; }
.leg { position: relative; padding: 2px 0 2px 34px; }
.leg.current { background: var(--tint); }
.rail { position: absolute; left: 23px; top: 0; bottom: 0; width: 4px; background: var(--border); border-radius: 2px; }
.fill { width: 100%; background: var(--accent); border-radius: 2px; transition: height .3s; }
.leg-dist { color: var(--muted); font-size: 12px; padding: 2px 14px 2px 10px; }
.turns .turn { padding: 4px 14px 4px 10px; gap: 8px; font-size: 13px; color: var(--text); }
.turn-n {
  flex: none; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: #1a73e8; color: #fff; font-size: 10px; font-weight: 700;
}
.turn-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn.passed { color: var(--muted); }
.turn.passed .turn-n { opacity: .5; }
.turn.next { font-weight: 600; }
.turn.next .turn-n { background: #e37400; }

/* ---------- street view ---------- */
.pano-wrap { position: relative; flex: 1; min-height: 240px; background: #000; }
.pano { position: absolute; inset: 0; }
.hud {
  position: absolute; left: 12px; top: calc(12px + env(safe-area-inset-top)); right: 64px; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.chip { background: rgba(0,0,0,.72); color: #fff; border-radius: 8px; padding: 6px 10px; max-width: 100%; }
.chip.next { font-size: 16px; font-weight: 600; }
.chip.next.soon { background: rgba(227,116,0,.92); }
.chip.small { font-size: 12px; }

/* ---------- Start / Stop row (bottom of the stops card) ---------- */
.panel-actions {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-top: 1px solid var(--border);
}
.status { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; }
.status.err { color: var(--warn); }
.panel-actions .route { flex: none; font-weight: 500; padding: 7px 20px; border-radius: 999px; }

/* ---------- player bar (drive mode only) ---------- */
.controls {
  background: var(--panel); border-top: 1px solid var(--border); padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px;
}
.recenter-btn { justify-self: start; }
.recenter-btn .icon { color: var(--accent); }
.nav { display: flex; align-items: center; gap: 4px; }
.speed { position: relative; justify-self: end; }
.speed-btn {
  min-width: 52px; padding: 6px 10px; border: 0; border-radius: 999px; background: transparent;
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.speed-btn:hover, .speed-btn[aria-expanded="true"] { background: var(--hover); }
.speed-menu {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 5; min-width: 88px; padding: 4px;
  display: grid; background: var(--panel); border: 1px solid var(--border); border-radius: var(--card-r);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.speed-menu button {
  border: 0; border-radius: 6px; background: transparent; padding: 7px 12px; text-align: left;
  font-variant-numeric: tabular-nums;
}
.speed-menu button:hover, .speed-menu button:focus-visible { background: var(--hover); outline: none; }
.speed-menu button[aria-checked="true"] { color: var(--accent); font-weight: 600; }
.speed-menu button[aria-checked="true"]::after { content: " ✓"; }

/* ---------- map overlays (always on a light map) ---------- */
/* Map / Satellite segmented switch */
.maptype {
  display: inline-flex; margin: calc(10px + env(safe-area-inset-top)) 10px 10px; padding: 3px; gap: 2px;
  background: rgba(255,255,255,.92); border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); backdrop-filter: blur(4px);
  font: 500 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.maptype button {
  border: 0; border-radius: 999px; padding: 7px 14px; background: transparent; color: #3c4043;
  font: inherit; transition: background-color .15s, color .15s;
}
.maptype button:hover:not(.on) { background: rgba(60,64,67,.08); }
.maptype button.on { background: #1a73e8; color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.maptype button:focus-visible { outline: 2px solid #1a73e8; outline-offset: 2px; }

/* Map popup (inside a Google InfoWindow, so always light) */
.pick-head { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-top: 2px; min-width: 0; }
.pick-title { font-size: 15px; font-weight: 600; color: #202124; line-height: 1.3; }
.pick-sub { font-size: 12px; color: #5f6368; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pick { display: grid; min-width: 200px; padding: 6px 0 4px; }
.pick .pick-main {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  font: 500 13px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff; background: #1a73e8; border: 0; border-radius: 10px; padding: 10px 14px;
}
.pick .pick-main:hover:not(:disabled) { background: #1765cc; }
.pick .pick-main:focus { outline: none; }
.pick .pick-main .pin-badge { box-shadow: 0 0 0 2px #fff; }

/* iOS Safari only (-webkit-touch-callout is WebKit-on-iOS): run the page under the
   status bar and Safari's floating bottom toolbar, like a native map app. 100lvh is the
   screen height including the toolbar area; --under is the part the toolbar covers, kept
   clear for the player bar. Elsewhere 100lvh would push content off-screen, hence the guard. */
@supports (-webkit-touch-callout: none) {
  :root { --under: max(0px, calc(100lvh - 100svh)); }
  html, body, #app { height: 100lvh; }
  .controls { padding-bottom: calc(6px + max(var(--under), env(safe-area-inset-bottom))); }
}

@media (max-width: 760px) {
  .app main { flex-direction: column-reverse; }
  .sv { border-left: 0; border-bottom: 1px solid var(--border); }
  /* Too narrow for map + Street View: while driving, drop the map and keep the
     progress card under Street View (the card shrinks and scrolls). */
  .app.drive .map-wrap { flex: 0 1 auto; max-height: 50%; display: flex; flex-direction: column; background: var(--bg); }
  .app.drive .map { display: none; }
  .app.drive .side { position: static; width: auto; max-height: none; min-height: 0; flex: 0 1 auto; margin: 8px; }
  .controls { padding: 4px 8px calc(4px + max(var(--under, 0px), env(safe-area-inset-bottom))); gap: 4px; }
  .nav { gap: 0; }
  .nav .icon-btn:not(.play) { width: 34px; height: 34px; }
}
