/* ============================================================
   RunRoute — application stylesheet
   Requires theme.css (tokens) loaded first.

   Z-INDEX REGISTRY
     #map .................. 0
     .map-error ............ 4
     .statsbar ............. 10 desktop / 20 mobile
     .panel (sheet) ........ 15
     #moreMenu ............. inside .statsbar (position:relative)
     .run-ui ............... 40  (container pointer-events:none)
     .sv-overlay ........... 60 mobile (fixed) / 16 desktop dock (in flow) — see sim.css
                             inside .sv-stage: #svPano 0, .sv-dim 1, .sv-chevron 2, .sv-hudcol 3, .sv-card 4; .sv-topbar 5
     <dialog> .............. top layer (::backdrop = var(--scrim))
     .toast ................ 100

   BODY-LEVEL STATE
     body[data-sheet="peek|half|full"]  (mobile only)
     body.run-active, body.sv-open
     html[data-theme="light|dark"]      (absent = auto)
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font); cursor: pointer; }

/* ---------------- Side panel ---------------- */

.panel {
  width: 390px;
  min-width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 15;
}

.sheet-handle, .sheet-peek-row { display: none; }

.panel-scroll {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.panel-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
}

.panel-brand .wordmark {
  font-family: var(--font-mark);
  font-size: 24px;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.panel-brand .wordmark img { width: 26px; height: 26px; }

.brand-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-brand .back-link {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-faint);
  text-decoration: none;
}

.panel-brand .back-link:hover { color: var(--brand-hi); }

.panel-brand .icon-btn { width: 38px; height: 38px; }

.panel-controls {
  padding: 4px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 12px 0 6px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-family: var(--font);
  color: var(--ink);
  background: var(--field-bg);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.search-row input:not(:focus) { text-overflow: ellipsis; }

.search-row input:focus {
  border-color: var(--brand-hi);
  background: var(--field-bg-focus);
}

.home-caption {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 6px 2px 0;
}

.home-caption[hidden] { display: none; }

.home-caption svg {
  width: 13px;
  height: 13px;
  flex: none;
  margin-top: 2px;
  color: var(--ink-faint);
}

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field-bg);
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.icon-btn:hover { border-color: var(--brand-hi); color: var(--brand-hi); background: var(--field-bg-focus); }

.icon-btn svg { width: 20px; height: 20px; }

.icon-btn.busy { animation: pulse 1s ease-in-out infinite; pointer-events: none; }

/* Toggle icon buttons (#preVoice, #runVoiceBtn): on = tinted, off = faint + muted glyph */
.icon-btn[aria-pressed="true"],
.icon-btn[aria-pressed="true"]:hover {
  background: var(--brand-tint);
  border-color: var(--brand-hi);
  color: var(--brand-tint-ink);
}

.icon-btn[aria-pressed="false"],
.icon-btn[aria-pressed="false"]:hover {
  background: var(--field-bg);
  border-style: dashed;
  color: var(--ink-faint);
}

.icon-btn .ic-off,
.icon-btn[aria-pressed="false"] .ic-on { display: none; }

.icon-btn[aria-pressed="false"] .ic-off { display: block; }

@keyframes pulse { 50% { opacity: 0.4; } }

/* Radius */

.radius-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.radius-row input[type="range"] {
  flex: 1;
  accent-color: var(--brand-hi);
  min-width: 0;
}

.radius-value {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-soft);
  font-weight: 600;
}

.radius-value input {
  width: 72px;
  height: 36px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  text-align: right;
  font-family: var(--font);
  font-weight: 600;
  color: var(--ink);
  padding: 0 8px;
  background: var(--field-bg);
  outline: none;
}

.radius-value input:focus { border-color: var(--brand-hi); background: var(--field-bg-focus); }

/* Category chips (color-coded) */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Off = neutral outlined pill with a hollow category ring.
   On  = solid category fill (--cat-*-fill, contrast-checked against --chip-on-ink in
   both themes, see theme.css) + a check mark in place of the ring + a lift shadow,
   so the state never rests on hue alone. */
.chip {
  border: 1.5px solid var(--chip-line);
  background: var(--field-bg);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 7px 14px 7px 12px;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.chip[data-type="park"] { --cat: var(--cat-park); --cat-fill: var(--cat-park-fill); }
.chip[data-type="tourist_attraction"] { --cat: var(--cat-sight); --cat-fill: var(--cat-sight-fill); }
.chip[data-type="cafe"] { --cat: var(--cat-cafe); --cat-fill: var(--cat-cafe-fill); }
.chip[data-type="gym"] { --cat: var(--cat-gym); --cat-fill: var(--cat-gym-fill); }

.chip::before {
  content: "";
  box-sizing: border-box;
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--cat-fill);
  background: transparent;
  margin-right: 7px;
}

.chip:hover { border-color: var(--cat-fill); color: var(--ink); }

.chip[aria-pressed="true"] {
  background: var(--cat-fill);
  color: var(--chip-on-ink);
  border-color: var(--cat-fill);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), 0 3px 10px -2px var(--cat-fill);
}

/* Check mark drawn from two borders of a rotated box, in the chip's text color */
.chip[aria-pressed="true"]::before {
  width: 6px;
  height: 11px;
  border-radius: 0;
  border: solid currentColor;
  border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg);
  margin: 0 10px 0 3px;
}

.chip[aria-pressed="true"]:hover { color: var(--chip-on-ink); filter: brightness(1.06); }

/* ---------------- Saved routes ---------------- */

.saved { border-bottom: 1px solid var(--line); }

.saved-head {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.saved-head:hover { color: var(--ink-soft); }

.saved-head svg { width: 15px; height: 15px; flex: none; }

.saved-head .count { font-weight: 600; letter-spacing: 0; }

.saved-head .chev {
  margin-left: auto;
  transition: transform 0.2s;
}

.saved-head[aria-expanded="true"] .chev { transform: rotate(180deg); }

#savedList {
  list-style: none;
  margin: 0;
  padding: 0 10px 10px;
}

@media (min-width: 861px) {
  /* #places keeps room for ~3 tiles; when the panel can't fit that, the whole
     panel scrolls instead of squeezing the place list to nothing. */
  .panel-scroll { overflow-y: auto; }
  #places { min-height: 200px; }
  #savedList {
    max-height: 30vh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

#savedList .hint {
  padding: 10px 8px 14px;
  color: var(--ink-faint);
  font-size: 13.5px;
}

.saved-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 12px;
}

.saved-row:hover { background: var(--tile-bg); }

.saved-main {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  border-radius: 12px;
  font-family: var(--font);
  color: var(--ink);
}

.saved-name {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-meta { font-size: 12.5px; color: var(--ink-faint); }

.saved-del {
  flex: none;
  width: 44px;
  min-height: 44px;
  align-self: center;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--ink-faint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.saved-del svg { width: 17px; height: 17px; }

.saved-del:hover { color: var(--danger); }

.saved-row.confirm .saved-main { opacity: 0.45; }

.saved-row.confirm .saved-del {
  width: auto;
  padding: 0 14px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  background: var(--danger-fill);
}

/* ---------------- Places list ---------------- */

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 18px 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.list-head .count { font-weight: 600; letter-spacing: 0; text-transform: none; }

#places {
  list-style: none;
  margin: 0;
  padding: 0 0 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Classic location tiles (the original "Waypoint List"): full-width stacked
   buttons — tan-gray at rest, white on hover, light blue in a navy frame when
   picked. The frame is an inset shadow so selecting never shifts the layout. */
#places li.place {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px 18px;
  min-height: 64px;
  background: var(--tile-bg);
  color: var(--tile-ink);
  border-bottom: 1px solid var(--tile-line);
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}

#places li.place:first-child { border-top: 1px solid var(--tile-line); }

#places li.place:hover { background: var(--tile-hover); }

#places li.place[aria-selected="true"] {
  background: var(--tile-sel-bg);
  color: var(--tile-sel-ink);
  box-shadow: inset 0 0 0 2px var(--tile-sel-line);
}

#places li.place:focus-visible { outline-offset: -4px; }

li.place[data-cat="park"] { --cat: var(--cat-park); }
li.place[data-cat="sight"] { --cat: var(--cat-sight); }
li.place[data-cat="cafe"] { --cat: var(--cat-cafe); }
li.place[data-cat="gym"] { --cat: var(--cat-gym); }

.cat-dot {
  display: inline-block;
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cat, transparent);
  margin-right: 8px;
  vertical-align: 2px;
}

/* Classic tiles show selection by the tile itself (fill + frame + the ✓ badge),
   so the checkbox from the modern row isn't drawn. */
.place-check { display: none; }

.place-body { min-width: 0; flex: 1; }

.place-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  font-weight: 600;
  font-size: 16.5px;
  line-height: 1.3;
  padding-left: 17px; /* hanging indent: wrapped lines align past the category dot */
  text-indent: -17px;
}

.place-meta {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin-top: 4px;
  padding-left: 17px; /* aligns under the name, past the category dot */
}

.place-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  padding-top: 1px;
}

.place-dist {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--tile-pill);
  border: 1px solid var(--tile-line);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

li.place[aria-selected="true"] .place-dist {
  background: var(--tile-sel-line);
  border-color: var(--tile-sel-line);
  color: var(--tile-sel-bg);
}

li.place[aria-selected="true"] .place-dist::before { content: "\2713\00a0"; }

.place-rating {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

#places .hint, #placesHint {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
  line-height: 1.6;
}

#places .hint strong { color: var(--ink-soft); }

/* ---------------- Map area ---------------- */

#mapwrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--map-bg);
  z-index: 0;
}

/* ---------------- Stats bar ---------------- */

.statsbar {
  position: absolute;
  /* left+right+auto margins center a fit-content box; left:50% would cap its width at half the map */
  left: 16px;
  right: 16px;
  margin-left: auto;
  margin-right: auto;
  width: -webkit-fit-content;
  width: fit-content;
  bottom: 22px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 10px;
  column-gap: 16px;
  justify-content: center;
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  max-width: calc(100% - 32px);
  z-index: 10;
}

.statsbar[hidden] { display: none; }

.stats-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 8px;
  column-gap: 18px;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.stat { text-align: center; min-width: 64px; }

.stat .value {
  display: block;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.stat .label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.statsbar select {
  font-family: var(--font);
  font-weight: 600;
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--field-bg);
  padding: 8px;
  outline: none;
  min-width: 0;
  max-width: 180px;
  max-width: min(180px, 100%);
}

.statsbar .actions { display: flex; gap: 8px; align-items: center; max-width: 100%; }

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s;
  text-decoration: none;
}

.pill-btn:hover { background: var(--brand-dark); }

.pill-btn svg { width: 15px; height: 15px; flex: none; }

.pill-btn.secondary {
  background: var(--brand-tint);
  color: var(--brand-tint-ink);
}

.pill-btn.secondary:hover { background: var(--brand-tint-hover); }

.pill-btn.quiet {
  background: transparent;
  color: var(--ink-faint);
}

.pill-btn.quiet:hover { background: var(--bg); color: var(--ink-soft); }

.pill-btn.danger-solid {
  background: var(--danger-fill);
  color: #fff;
  min-height: 48px;
}

/* Overflow menu */

.menu-pop {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 12px;
  min-width: 230px;
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 5;
}

.menu-pop[hidden] { display: none; }

.menu-pop button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  background: none;
  border: none;
  border-radius: 9px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
}

.menu-pop button:hover, .menu-pop button:focus-visible { background: var(--bg); }

.menu-pop button svg { width: 18px; height: 18px; flex: none; color: var(--ink-soft); }

.menu-pop button.danger { color: var(--danger); }
.menu-pop button.danger svg { color: var(--danger); }

.menu-sep {
  height: 1px;
  background: var(--line);
  margin: 6px 4px;
}

/* Map error overlay */

.map-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 4; /* above the map, below statsbar (10) and the panel/sheet (15) */
  padding: 24px;
}

.map-error[hidden] { display: none; }

.map-error .card {
  max-width: 440px;
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}

.map-error h2 { margin: 0 0 8px; font-size: 20px; }

.map-error p { margin: 0 0 16px; color: var(--ink-soft); font-size: 14.5px; line-height: 1.6; }

/* ---------------- Street View overlay ---------------- */

.sv-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
}

.sv-overlay[hidden] { display: none; }

/* Google's pano builds its own positioned canvas layers; isolate it and lift
   the overlay chrome above it, or the canvas swallows every tap. */
#svPano { position: absolute; inset: 0; z-index: 0; isolation: isolate; }

.sv-topbar, .sv-gap, .sv-controls { z-index: 2; }

.sv-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 18px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
  color: #fff;
}

.sv-title { font-weight: 800; font-size: 15px; }

.sv-pos { font-size: 13.5px; font-weight: 600; opacity: 0.9; }

.sv-close {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sv-close svg { width: 18px; height: 18px; }

.sv-gap {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  max-width: calc(100% - 32px);
  text-align: center;
}

.sv-gap[hidden] { display: none; }

.sv-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px calc(14px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}

.sv-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 700;
}

.sv-btn svg { width: 20px; height: 20px; }

.sv-btn.primary {
  width: 56px;
  height: 56px;
  background: var(--brand);
}

.sv-btn.primary:hover { background: var(--brand-dark); }

#svScrub {
  flex: 1;
  min-width: 0;
  accent-color: #fff;
}

/* ---------------- Run UI ---------------- */

.run-ui {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

.run-ui[hidden] { display: none; }

.run-card {
  pointer-events: auto;
  margin: calc(10px + env(safe-area-inset-top, 0px)) 12px 0;
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 4px 12px;
  align-items: center;
  max-width: 560px;
}

@media (min-width: 861px) { .run-card { margin-left: auto; margin-right: auto; } }

.run-arrow {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand-tint);
  color: var(--brand-tint-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  grid-row: span 1;
}

.run-arrow svg { width: 24px; height: 24px; transition: transform 0.2s; }

.run-arrow.m-left svg { transform: rotate(-90deg); }
.run-arrow.m-right svg { transform: rotate(90deg); }
.run-arrow.m-slight-left svg { transform: rotate(-45deg); }
.run-arrow.m-slight-right svg { transform: rotate(45deg); }
.run-arrow.m-uturn svg { transform: rotate(180deg); }

.run-cue { min-width: 0; }

.run-dist {
  display: block;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--brand-hi);
}

.run-instr {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
  line-height: 1.35;
}

.run-next {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
}

.run-banner {
  pointer-events: auto;
  margin: 10px 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  max-width: 560px;
}

@media (min-width: 861px) { .run-banner { margin-left: auto; margin-right: auto; } }

.run-banner[hidden] { display: none; }

.run-banner.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid var(--warn-line);
}

.run-banner.info {
  background: var(--brand-tint);
  color: var(--brand-tint-ink);
  border: 1px solid var(--line);
}

.run-recenter {
  pointer-events: auto;
  position: absolute;
  right: 14px;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

.run-recenter[hidden] { display: none; }

.run-stats {
  pointer-events: auto;
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-raised);
  border-top: 1px solid var(--line);
  padding: 10px calc(14px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
}

.run-stats .rs {
  display: flex;
  flex-direction: column;
  min-width: 56px;
}

.run-stats .v { font-size: 17px; font-weight: 800; white-space: nowrap; }

.run-stats .l {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.run-stats .icon-btn { margin-left: auto; }

.run-stats .pill-btn { white-space: nowrap; }

/* Armed End: stats hide so the row never widens; End stays at the right edge, Resume to its left */
.run-stats.armed .rs { display: none; }

.run-stats .run-resume { min-height: 48px; }

body.run-active .statsbar { display: none; }

/* .run-stats (10+48+10 px + 1px border + inset) would otherwise cover the Google logo/attribution */
body.run-active #map { bottom: calc(69px + env(safe-area-inset-bottom, 0px)); }

@media (min-width: 861px) {
  body.run-active .panel { opacity: 0.45; pointer-events: none; }
}

/* ---------------- Dialogs ---------------- */

dialog {
  border: none;
  border-radius: 18px;
  background: var(--card-raised);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(420px, calc(100vw - 40px));
  font-family: var(--font);
}

dialog::backdrop { background: var(--scrim); }

dialog h2 { margin: 0 0 10px; font-size: 20px; }

dialog p { color: var(--ink-soft); font-size: 14.5px; line-height: 1.55; }

dialog .dlg-summary { font-weight: 700; color: var(--ink); margin: 0 0 12px; }

dialog ul.dlg-bullets {
  margin: 12px 0;
  padding: 0 0 0 18px;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.6;
}

dialog .dlg-privacy { font-size: 13px; color: var(--ink-soft); margin: 10px 0 0; }

dialog .dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

dialog .dlg-actions .pill-btn { min-height: 44px; padding: 10px 18px; }

dialog .dlg-actions .primary-big { min-height: 52px; flex: 1; font-size: 15.5px; }

dialog input[type="text"] {
  width: 100%;
  height: 46px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-family: var(--font);
  color: var(--ink);
  background: var(--field-bg);
  outline: none;
}

dialog input[type="text"]:focus { border-color: var(--brand-hi); background: var(--field-bg-focus); }

dialog label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: 0 0 6px; }

.voice-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 0;
  font-size: 14.5px;
  font-weight: 600;
}

.summary-rows { margin: 14px 0 4px; }

.summary-rows .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}

.summary-rows .row:last-child { border-bottom: none; }

.summary-rows .row .k { color: var(--ink-soft); }
.summary-rows .row .v { font-weight: 800; }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%) translateY(-8px);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Mobile: bottom sheet ---------------- */

@media (max-width: 860px) {
  body {
    position: fixed;
    inset: 0;
    display: block;
  }

  /* The map ends where the sheet begins so Google's logo and attribution stay visible
     (Maps Platform terms). sheet.js fires the map resize after each state change. */
  #mapwrap {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 48vh;
    bottom: 48svh;
  }

  body[data-sheet="peek"] #mapwrap { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }

  body.run-active #mapwrap { bottom: 0; }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    min-width: 0;
    z-index: 15;
    height: calc(100vh - 56px);
    height: calc(100svh - 56px);
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow);
    transition: transform 0.28s cubic-bezier(0.33, 1, 0.22, 1);
    transform: translateY(calc(100% - 48vh));
    transform: translateY(calc(100% - 48svh));
  }

  body[data-sheet="full"] .panel { transform: translateY(0); }
  body[data-sheet="half"] .panel {
    transform: translateY(calc(100% - 48vh));
    transform: translateY(calc(100% - 48svh));
  }
  body[data-sheet="peek"] .panel {
    transform: translateY(calc(100% - 88px - env(safe-area-inset-bottom, 0px)));
  }

  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    touch-action: none;
    cursor: grab;
  }

  .sheet-handle .bar {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
  }

  .sheet-peek-row {
    display: none;
    width: 100%;
    min-height: 48px;
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-soft);
    text-align: center;
  }

  body[data-sheet="peek"] .sheet-peek-row { display: block; }

  .panel-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body[data-sheet="peek"] .panel-scroll { overflow: hidden; }

  /* Half only translates the full-height panel down; cap the scroller to the on-screen part
     (48svh minus the 28px handle and 1px top border) so the last rows are reachable. */
  body[data-sheet="half"] .panel-scroll {
    max-height: calc(48vh - 29px);
    max-height: calc(48svh - 29px);
  }

  #places { overflow: visible; flex: none; }

  .search-row input { height: 48px; }

  .chip { min-height: 44px; }

  /* #mapwrap already ends at the sheet's top edge, so the bar sits a fixed distance above it: 32px clears
     Google's logo (66x26 at the map's bottom-left) and the attribution row, which the Maps terms keep visible
     (at 12px the bar hid half the wordmark in the planning state). */
  .statsbar {
    z-index: 20;
    left: 10px;
    right: 10px;
    bottom: 32px;
    max-width: calc(100% - 20px);
    column-gap: 12px;
    padding: 10px 12px;
    transition: opacity 0.2s;
  }

  body[data-sheet="full"] .statsbar { opacity: 0; pointer-events: none; }

  .stats-cluster { column-gap: 12px; }

  .stat { min-width: 56px; }
  .stat .value { font-size: 16px; }

  .statsbar .actions .pill-btn { min-height: 48px; }
  .statsbar select { min-height: 44px; }

  #startRunBtn { flex: 1; justify-content: center; }

  .menu-pop { right: 8px; }

  body.run-active .panel { display: none; }
}

@media (max-width: 480px) {
  #previewBtn .btn-text, #saveRouteBtn .btn-text { display: none; }
  #previewBtn, #saveRouteBtn { width: 48px; padding: 9px 0; }
  /* Stats + pace on ONE row (it used to wrap the pace select onto a row of its own, a
     164 px bar that left the half-state route ~190 px of map). Still flex-wrap, so an
     unusually long value degrades to the old two-row layout rather than overflowing. */
  .statsbar { row-gap: 8px; }
  .stats-cluster { column-gap: 10px; }
  .stat { min-width: 0; }
  .stat .value { font-size: 15px; }
  .stat .label { font-size: 10px; letter-spacing: 0.4px; }
  .statsbar select { max-width: 132px; font-size: 13px; padding: 6px 4px; }
}

@media (max-width: 360px) {
  .statsbar { padding: 10px 8px; }
  .stats-cluster { column-gap: 10px; }
  .statsbar .actions { gap: 6px; }
}

@media (max-width: 360px) {
  .run-stats { gap: 8px; }
  .run-stats .rs { min-width: 46px; }
  .run-stats .v { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .statsbar, .toast, .run-arrow svg, .saved-head .chev { transition: none; }
}
