:root {
  color-scheme: dark;
  --bg: #0c1116;
  --panel: #151c26;
  --panel-2: #1d2733;
  --line: #2c3a4b;
  --text: #f4f7fb;
  --muted: #a9b6c4;
  --blue: #4da3ff;
  --amber: #ffb020;
  --red: #ff3344;
  --violet: #8b5cf6;
  --ok: #3dd68c;
  --dock: #10161d;
  --control: #1b2430;
  --input-bg: #0e141b;
  --legend-bg: rgba(12, 17, 22, 0.88);
  --legend-text: #d5dee8;
  --fab-bg: rgba(27, 36, 48, 0.94);
  --compass-bg: rgba(78, 89, 100, 0.30);
  --attr-bg: rgba(12, 17, 22, 0.88);
  --attr-text: #d5dee8;
  --attr-link: #9fd0ff;
  --sheet-scrim: rgba(0, 0, 0, 0.45);
  --note-bg: rgba(12, 17, 22, 0.82);
  --note-text: #c5d0dc;
  --action: #243140;
  --disabled-bg: #3a4452;
  --disabled-text: #9aa6b2;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --route: #7ec8ff;
  --route-done: #9aa0a6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  /* Boutons de carte : gris translucide et picto clair au repos, inversés quand le mode est armé. */
  /* 0,40 laisse voir le fond. L’anneau du picto le garde lisible. Sans flou, repli 0,66. */
  --btn-bg: rgba(78, 89, 100, 0.4);
  --btn-fg: #ffffff;
  --glyph-ring: #0c1116;
  --btn-bg-on: rgba(255, 255, 255, 0.94);
  --btn-fg-on: #3a4450;
  --btn-border: transparent;
  --btn-border-on: transparent;
  /* 1,3 dès qu’un téléphone courant (390×844) a la place. Plus bas, la colonne rétrécit. */
  --btn-scale: clamp(0.917, (100dvh - 340px) / 330px, 1.3);
  --tools-fold-size: max(44px, calc(36px * var(--btn-scale)));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@supports not ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  :root {
    --btn-bg: rgba(78, 89, 100, 0.66);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #e7eef5;
  --line: #d3dbe3;
  --text: #142033;
  --muted: #4c5d70;
  --blue: #0b6bcb;
  --amber: #b86e00;
  --dock: #ffffff;
  --control: #ffffff;
  --input-bg: #f7f9fb;
  --legend-bg: rgba(255, 255, 255, 0.96);
  --legend-text: #142033;
  --fab-bg: rgba(255, 255, 255, 0.96);
  --compass-bg: rgba(78, 89, 100, 0.30);
  --attr-bg: rgba(255, 255, 255, 0.94);
  --attr-text: #243244;
  --attr-link: #0b57b8;
  --sheet-scrim: rgba(20, 32, 51, 0.35);
  --note-bg: rgba(255, 255, 255, 0.96);
  --note-text: #243244;
  --action: #e4ebf2;
  --disabled-bg: #d5dde6;
  --disabled-text: #5c6b7a;
  --shadow: 0 8px 24px rgba(20, 32, 51, 0.16);
  --route: #0b57b8;
  --route-done: #9aa0a6;
  /* Glyphe sombre sur OSM clair et Plan épuré clair. L’anneau blanc le détache d’un bâtiment sombre. */
  --btn-fg: #142033;
  --glyph-ring: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

#banner {
  padding: 8px 16px 7px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

#banner.is-far { background: #6d4308; color: #f7f1ea; }
#banner.is-near { background: #8d1522; color: #fff5f6; }
#banner.is-far .caption,
#banner.is-far .meta { color: #ffe7c2; }
#banner.is-near .caption,
#banner.is-near .meta { color: #ffd5da; }
#banner.is-far .limit-hint,
#banner.is-near .limit-hint,
#banner.is-far .limit-hgv,
#banner.is-near .limit-hgv { color: #fff5f6; }

.banner-main {
  display: flex;
  gap: 18px;
  align-items: stretch;
}

.distance-block { flex: 1; min-width: 0; }
.limit-block {
  flex: 0 0 auto;
  align-self: center;
  min-width: 0;
  background: transparent;
  padding: 0;
}
.limit-sign {
  position: relative;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  box-sizing: border-box;
  border-radius: 50%;
  background: #f4f6f8;
  border: 7px solid #e10600;
  box-shadow: 0 0 0 2px #f4f6f8, 0 4px 12px rgba(0, 0, 0, 0.35);
}
.limit-sign .limit,
.limit-sign .limit.is-placeholder {
  font-size: 1.65rem;
  font-weight: 800;
  color: #161616;
  letter-spacing: -0.04em;
  line-height: 1;
}

.limit-hgv {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 750;
  text-align: center;
}

.limit-hgv[hidden] { display: none; }

.limit-hint {
  margin: 4px 0 0;
  max-width: 9rem;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
}

.limit-hint[hidden] { display: none; }
.limit-unit {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.distance, .limit {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.045em;
  line-height: 0.88;
}

.distance { font-size: clamp(2.94rem, 8.4vw, 5.95rem); }

#banner:has(#sim-note:not([hidden])) .distance { line-height: 1; }
.limit { font-size: clamp(3.4rem, 9vw, 6.5rem); }

.distance.is-placeholder,
.limit.is-placeholder {
  font-weight: 500;
  font-synthesis: none;
  letter-spacing: 0;
  line-height: 1;
}

.distance.is-placeholder { font-size: clamp(1.54rem, 4.2vw, 2.38rem); }
.limit.is-placeholder { font-size: clamp(2rem, 5.2vw, 3rem); }

.caption, .meta, .sim-note, .status-line, .fine, .lede, #load-state {
  margin: 0;
}

.caption {
  margin-top: 4px;
  font-size: clamp(0.735rem, 1.4vw, 1.015rem);
  font-weight: 650;
  line-height: 1.25;
}

.meta, .sim-note {
  margin-top: 6px;
  color: var(--text);
  font-size: 0.686rem;
  line-height: 1.25;
}

#banner.is-calm .meta,
#banner.is-calm .caption { color: var(--muted); }

#banner { touch-action: none; }

.banner-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.8;
  touch-action: none;
}

.banner-badge {
  display: none;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  color: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
  white-space: nowrap;
}

html.banner-collapsed #banner.is-far .banner-badge:not([hidden]),
html.banner-collapsed #banner.is-near .banner-badge:not([hidden]) {
  display: inline-flex;
}

.banner-grip {
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

html.banner-collapsed #banner {
  display: block;
  padding: 0;
}

html.banner-collapsed #banner .banner-main,
html.banner-collapsed #banner > #fix-meta,
html.banner-collapsed #banner > #sim-note {
  display: none !important;
}

html.banner-collapsed #limit-block {
  position: absolute;
  z-index: 620;
  right: 12px;
  /* Au-dessus du bouton du bas et de l’attribution, qui s’étale sur un écran étroit. */
  bottom: calc(36px + max(44px, calc(48px * var(--btn-scale))) + 14px);
}

html.banner-collapsed .limit-sign {
  width: 46px;
  height: 46px;
  border-width: 4px;
}

html.banner-collapsed .limit-sign .limit { font-size: 1rem; }

.alert {
  position: absolute;
  z-index: 1200;
  top: 12px;
  left: calc(10px + (48px + 10px) * var(--btn-scale));
  right: 14px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a1218;
  color: #ffd5da;
  border: 1px solid #ff3344;
  font-size: 1.02rem;
  font-weight: 650;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.alert[hidden] { display: none; }

.alert p { margin: 0; }

#geo-retry {
  align-self: stretch;
  min-width: 48px;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: #ffd5da;
  color: #3a1218;
  font-size: 1.15rem;
  font-weight: 800;
}

#geo-retry[hidden] { display: none; }

.tile-note {
  position: absolute;
  z-index: 650;
  left: calc(var(--settings-inset) + var(--settings-size) + 12px);
  bottom: var(--settings-inset);
  margin: 0;
  max-width: min(48vw, 340px);
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--note-bg);
  color: var(--note-text);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.3;
  pointer-events: none;
}

.sim-note {
  position: relative;
  z-index: 1;
  margin-top: 6px;
  color: var(--amber);
  font-weight: 700;
}

#banner.is-near .sim-note,
#banner.is-far .sim-note {
  color: #fff8ee;
}

#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  /* Hérite de --btn-scale (posé par le script sur cet élément). */
  --settings-size: max(44px, calc(48px * var(--btn-scale)));
  --settings-inset: 10px;
  --settings-gap: 8px;
}

#map { height: 100%; background: var(--map-under, var(--bg)); }

/* Fond du conteneur assorti au fond de carte : un joint résiduel ne redevient pas blanc ou noir. */
#map.tiles-osm { --map-under: #f2efe9; }
html:not([data-theme="light"]) #map.tiles-osm { --map-under: #1c242c; }
#map.tiles-plain { --map-under: #e6e4df; }
html:not([data-theme="light"]) #map.tiles-plain { --map-under: #2a2a2a; }
#map.tiles-satellite { --map-under: #24302a; }
html:not([data-theme="light"]) #map.tiles-satellite { --map-under: #141a16; }

html:not([data-theme="light"]) #map.tiles-osm .leaflet-tile-pane {
  /* Couleur terre OSM, filtrée avec les tuiles : le joint prend la même teinte. */
  background: #f2efe9;
  filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.95) saturate(0.25);
}

html[data-theme="dark"] #map.tiles-satellite .leaflet-tile-pane {
  background: #24302a;
  filter: brightness(0.58) contrast(1.08) saturate(0.82);
}

.leaflet-container,
.leaflet-pane,
.leaflet-tile-pane,
#map {
  background: var(--map-under, var(--bg));
}

/* Leaflet additionne les tuiles (plus-lighter) pour cacher un joint d’un pixel.
   Avec un débordement opaque, ça trace un filet clair — noir après le filtre. */
.leaflet-container img.leaflet-tile {
  mix-blend-mode: normal;
}

.leaflet-container { font: inherit; }

/* Pas de fondu d’opacité : il laisse voir le fond le temps qu’une tuile arrive. */
.leaflet-fade-anim .leaflet-tile,
.leaflet-zoom-anim .leaflet-tile {
  transition: none !important;
}

.leaflet-tile-pane,
.leaflet-tile-container,
.leaflet-tile-pane img.leaflet-tile,
.leaflet-map-pane {
  will-change: auto;
}

.leaflet-tile-pane img.leaflet-tile {
  opacity: 1 !important;
  image-rendering: auto;
}

/* Rotation : un seul canvas. L’image n’est masquée qu’une fois recopiée dedans. */
.leaflet-tile-pane img.leaflet-tile.is-baked {
  opacity: 0 !important;
}

canvas.tile-seam {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  pointer-events: none;
}

.leaflet-bottom.leaflet-right {
  /* À droite du bouton Réglages. La colonne d’outils s’arrête au-dessus de lui. */
  left: calc(var(--settings-inset) + var(--settings-size) + 14px);
  right: 8px;
  bottom: 6px;
}

.leaflet-control-attribution {
  background: var(--attr-bg) !important;
  color: var(--attr-text) !important;
  font-size: 11px !important;
  max-width: 100%;
  max-height: 4.8em;
  overflow: auto !important;
  white-space: normal !important;
  line-height: 1.3;
}

.leaflet-control-attribution a { color: var(--attr-link) !important; }

html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
  background: #151c26;
  color: #f4f7fb;
}

html[data-theme="dark"] .leaflet-popup-content-wrapper a {
  color: #9fd0ff;
}

html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button {
  color: #a9b6c4;
}

html[data-theme="dark"] .leaflet-tooltip {
  background: #151c26;
  color: #f4f7fb;
  border: 1px solid #2c3a4b;
}

html[data-theme="dark"] .leaflet-tooltip-top:before {
  border-top-color: #151c26;
}

html[data-theme="dark"] .leaflet-tooltip-bottom:before {
  border-bottom-color: #151c26;
}

html[data-theme="light"] .legend {
  border: 1px solid var(--line);
}

.leaflet-top.leaflet-left { top: calc(10px + (48px + 8px) * var(--btn-scale)); }

.leaflet-top.leaflet-left .leaflet-control-zoom {
  margin-top: calc(10px * var(--btn-scale)) !important;
}

.leaflet-bar,
.leaflet-touch .leaflet-bar {
  border: 0 !important;
  box-shadow: none;
}

.leaflet-control-zoom a {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: calc(48px * var(--btn-scale)) !important;
  height: calc(48px * var(--btn-scale)) !important;
  line-height: 1 !important;
  padding: 0 !important;
  font-size: calc(26px * var(--btn-scale)) !important;
  background: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
  border: 0 !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.leaflet-bar a {
  background: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
}

.leaflet-bar a:hover,
.leaflet-bar a:focus {
  background: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
}

.leaflet-bar a:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

/* + / − : uniquement le glyphe, sans plaque ni flou. La couleur suit le thème, l’anneau le détache du fond. */
.leaflet-control-zoom.leaflet-bar {
  display: flex !important;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
  border: 0 !important;
  background: transparent !important;
}

.leaflet-control-zoom a,
.leaflet-control-zoom a:hover,
.leaflet-control-zoom a:focus,
.leaflet-control-zoom a:focus-visible {
  background: transparent !important;
  background-color: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  color: var(--btn-fg) !important;
  text-shadow:
    -1px -1px 0 var(--glyph-ring),
    1px -1px 0 var(--glyph-ring),
    -1px 1px 0 var(--glyph-ring),
    1px 1px 0 var(--glyph-ring),
    0 1px 2px rgba(0, 0, 0, 0.65);
}

.leaflet-control-zoom a:focus,
.leaflet-control-zoom a:focus-visible {
  position: relative;
  z-index: 3;
}

/* Plan clair : le « + » reste sombre, avec un liseré blanc assez large pour un fond pâle. */
html[data-theme="light"] #map-wrap:not(.tiles-satellite) .leaflet-control-zoom a {
  color: #061018 !important;
  font-weight: 800;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
}

/* Imagerie + thème clair : picto clair, anneau sombre. Le plan photo avale un glyphe noir. */
html[data-theme="light"] #map-wrap.tiles-satellite {
  --btn-fg: #ffffff;
  --glyph-ring: #061018;
}

#map.tiles-satellite .me-arrow {
  color: #f7f9fb;
  filter:
    drop-shadow(0 0 1px #061018)
    drop-shadow(0 0 1px #061018)
    drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}

#map.tiles-satellite .me-arrow svg path {
  stroke: #061018;
  stroke-width: 2.4px;
}

/* className d'un divIcon remplace leaflet-div-icon : cibler la classe posée par l'application. */
.radar-dot {
  background: var(--red);
  border: 0;
  border-radius: 50%;
  box-sizing: border-box;
  box-shadow: none;
}

.radar-dot.is-target {
  border: 0;
  animation: radar-pulse 1.15s ease-out infinite;
}

.radar-dot.is-opposite {
  background: var(--violet);
  animation: none;
}

.radar-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--red);
  color: #fff;
  border: 0;
  border-radius: 50%;
  box-sizing: border-box;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.radar-cluster.is-opposite { background: var(--violet); }

.upright {
  display: inline-block;
  transform: rotate(calc(-1 * var(--map-bearing, 0deg)));
}

.legend {
  position: absolute;
  z-index: 450;
  top: 12px;
  right: 12px;
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--legend-bg);
  color: var(--legend-text);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
}

.legend .radar-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
}

.compass {
  position: absolute;
  z-index: 450;
  top: 52px;
  right: 12px;
  display: grid;
  place-items: center;
  width: calc(52px * var(--btn-scale));
  height: calc(52px * var(--btn-scale));
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 50%;
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: var(--shadow);
  pointer-events: auto;
  cursor: pointer;
}

.compass[hidden] { display: none; }

.compass-rose {
  position: relative;
  width: 100%;
  height: 100%;
  transform: rotate(var(--compass-angle, 0deg));
}

.compass-n {
  position: absolute;
  left: 50%;
  top: calc(6px * var(--btn-scale));
  color: var(--btn-fg);
  font-size: calc(0.95rem * var(--btn-scale));
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  filter: drop-shadow(0 0 1px var(--glyph-ring));
  transform: translateX(-50%) rotate(calc(-1 * var(--compass-angle, 0deg)));
}

.compass-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip-container {
  transform: rotate(calc(-1 * var(--map-bearing, 0deg)));
  transform-origin: 50% calc(100% + 14px);
}

@keyframes radar-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 51, 68, 0.75); }
  100% { box-shadow: 0 0 0 20px rgba(255, 51, 68, 0); }
}

.me-wrap {
  background: transparent;
  border: 0;
}

.me-glyph {
  width: 36px;
  height: 36px;
  transform: scale(var(--me-scale, 1));
  transform-origin: center center;
}

.me-dot {
  width: 18px;
  height: 18px;
  margin: 9px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
}

.me-arrow {
  width: 36px;
  height: 36px;
  margin: 0;
  color: var(--blue);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.8));
  transform: rotate(var(--me-heading, 0deg));
  transform-origin: center center;
}

.me-wrap.is-arrow .me-dot,
.me-wrap.is-dot .me-arrow { display: none; }

.me-arrow svg { display: block; width: 36px; height: 36px; }

.fab, .dock button, #start, .sheet button {
  border: 0;
  border-radius: 14px;
  background: var(--panel-2);
  min-height: 52px;
  padding: 0 18px;
  font-size: 1.15rem;
  font-weight: 700;
}

.fab {
  position: absolute;
  z-index: 500;
  right: 14px;
  bottom: 28px;
  min-width: 132px;
  background: var(--fab-bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

#recenter.fab {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: calc(48px * var(--btn-scale));
  height: calc(48px * var(--btn-scale));
  min-width: calc(48px * var(--btn-scale));
  min-height: calc(48px * var(--btn-scale));
  padding: 0;
  border-radius: calc(14px * var(--btn-scale));
}

#recenter.fab svg {
  display: block;
  width: calc(26px * var(--btn-scale));
  height: calc(26px * var(--btn-scale));
}

.dock button.is-armed {
  background: var(--amber);
  color: #1a1203;
}

.dock {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--dock);
  border-top: 1px solid var(--line);
}

.dock-buttons { display: flex; gap: 8px; align-items: center; }

.status-line {
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
}

#start-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 50% 0%, rgba(255, 51, 68, 0.18), transparent 60%),
    var(--bg);
}

#start-screen[hidden] { display: none; }

.start-card {
  width: min(640px, 100%);
  text-align: center;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: -0.04em;
}

.lede {
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.45;
}

#load-state {
  margin: 18px 0;
  font-size: 1.05rem;
  color: var(--amber);
}

#sim-intro {
  margin: 0 0 12px;
  color: var(--amber);
  font-weight: 700;
}

#start {
  width: min(100%, 420px);
  min-height: 84px;
  font-size: 2rem;
  background: var(--red);
  color: white;
}

#start.is-waiting,
#start:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: default;
}

#recenter.fab,
#recenter.fab.is-following {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 0;
  box-shadow: none;
}

.fine {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.sheet[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  box-sizing: border-box;
  padding: 12px 12px 16px;
  background: var(--sheet-scrim);
}

.sheet-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  margin: 0 auto env(safe-area-inset-bottom, 0px);
  padding: 0;
  max-height: calc(100vh - 28px - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 28px - env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.sheet-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px 6px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 14px 10px;
}

.sheet-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px 18px;
  align-items: start;
}

#close-settings.sheet-close {
  position: static;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}

.sheet-close-icon {
  display: block;
  width: 20px;
  height: 20px;
}

#close-settings.sheet-close:hover,
#close-settings.sheet-close:focus-visible {
  background: var(--panel-2);
  color: var(--text);
}

.sheet h2 { margin: 0; font-size: 1.2rem; line-height: 1.2; }

.basemap-choice,
.night-choice {
  margin: 2px 0 4px;
  padding: 0;
  border: 0;
  min-width: 0;
}

.basemap-choice legend,
.night-choice legend {
  margin-bottom: 2px;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.2;
}

.basemap-choice label,
.night-choice label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  font-size: 0.98rem;
  line-height: 1.2;
}

.basemap-choice input,
.night-choice input {
  width: 22px;
  height: 22px;
}

.sheet-help {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}

.field {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin: 4px 0;
  min-width: 0;
  font-size: 0.98rem;
  line-height: 1.2;
}

.field input[type="number"],
.field input[type="range"],
.field select {
  width: min(200px, 46vw);
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  padding: 0 10px;
  font-size: 1.05rem;
}

.checks { justify-content: flex-start; gap: 12px; }
.checks input { width: 28px; height: 28px; }

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 2px;
}

.sheet-actions button {
  background: var(--action);
  min-height: 44px;
}

@media (min-width: 700px) {
  .sheet-grid { grid-template-columns: 1fr 1fr; }
  .sheet-span { grid-column: 1 / -1; }
  .sheet-grid .field {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .sheet-grid .field select,
  .sheet-grid .field input[type="range"] { width: 100%; }
  .sheet-grid .checks {
    flex-direction: row;
    align-items: center;
  }
}

.leaflet-top.leaflet-right {
  top: 108px;
}

.heading-control {
  border: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: auto;
}

#map-wrap > #heading-up,
#map-wrap > #nav-mode {
  position: absolute;
  z-index: 500;
  left: 10px;
  right: auto;
}

#map-wrap > #heading-up { top: calc(10px + 222px * var(--btn-scale)); }
#map-wrap > #nav-mode { top: calc(10px + 276px * var(--btn-scale)); }

#heading-up,
#nav-mode,
#place-open,
#recenter.fab,
.tools-fold,
.compass {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#heading-up,
#nav-mode {
  display: grid;
  place-items: center;
  width: calc(48px * var(--btn-scale));
  height: calc(48px * var(--btn-scale));
  min-width: calc(48px * var(--btn-scale));
  min-height: calc(48px * var(--btn-scale));
  padding: 0;
  border: 0;
  border-radius: calc(8px * var(--btn-scale));
  box-shadow: none;
}

#heading-up.is-armed,
#nav-mode.is-armed {
  background: var(--btn-bg-on);
  color: var(--btn-fg-on);
  border: 0;
  box-shadow: none;
}

#recenter.fab.is-following {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 0;
  box-shadow: none;
}

#heading-up.is-armed svg,
#nav-mode.is-armed svg {
  filter: none;
}

.compass {
  background: var(--compass-bg);
  opacity: 1;
}

.compass-rose,
.compass-n {
  opacity: 1;
}

/* Suivi suspendu : même gris translucide, signalé par un point blanc, sans contour. */
#recenter.fab.is-armed:not(.is-following) {
  background-color: rgba(78, 89, 100, 0.48);
  background-image: radial-gradient(circle at calc(100% - 8px) 8px, #fff 0 3px, transparent 3.5px);
  box-shadow: none;
  animation: recenter-armed 1.8s ease-in-out infinite;
}

@keyframes recenter-armed {
  0%,
  100% { background-color: rgba(78, 89, 100, 0.48); }
  50% { background-color: rgba(78, 89, 100, 0.36); }
}

#heading-up svg,
#nav-mode svg,
#place-open svg,
#recenter.fab svg,
.tools-fold svg {
  display: block;
  margin: 0;
  width: calc(26px * var(--btn-scale));
  height: calc(26px * var(--btn-scale));
  filter:
    drop-shadow(0 0 1px var(--glyph-ring))
    drop-shadow(0 1px 1px rgba(0, 0, 0, 0.7));
}

.recenter-control,
.heading-control,
.nav-control {
  margin-top: calc(6px * var(--btn-scale)) !important;
  border: 0;
  background: transparent;
  box-shadow: none;
  clear: both;
  pointer-events: auto;
}

.tools-fold {
  position: absolute;
  z-index: 1100;
  top: 10px;
  left: 10px;
  display: grid;
  place-items: center;
  width: max(44px, calc(48px * var(--btn-scale)));
  height: var(--tools-fold-size);
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border-radius: calc(8px * var(--btn-scale));
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.tools-fold svg {
  display: block;
  width: calc(22px * var(--btn-scale));
  height: calc(22px * var(--btn-scale));
  transition: transform 200ms ease;
}

html.map-tools-collapsed .tools-fold svg {
  transform: rotate(180deg);
}

#open-settings {
  position: absolute;
  z-index: 1200;
  /* #app est déjà décalé de env(safe-area-inset-*) : le bouton reste dans l’écran utile. */
  left: var(--settings-inset);
  right: auto;
  bottom: var(--settings-inset);
  display: grid;
  place-items: center;
  width: var(--settings-size);
  height: var(--settings-size);
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: calc(8px * var(--btn-scale));
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#open-settings svg {
  display: block;
  width: calc(26px * var(--btn-scale));
  height: calc(26px * var(--btn-scale));
  filter:
    drop-shadow(0 0 1px var(--glyph-ring))
    drop-shadow(0 1px 1px rgba(0, 0, 0, 0.7));
}

.sheet-status {
  margin: 10px 0 2px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.map-tools {
  position: absolute;
  z-index: 1100;
  top: calc(10px + var(--tools-fold-size) + 6px * var(--btn-scale));
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: max-content;
  max-width: calc(100vw - 24px);
  max-height: calc(100% - 10px - var(--tools-fold-size) - 6px * var(--btn-scale) - var(--settings-inset) - var(--settings-size) - var(--settings-gap));
  pointer-events: none;
  transform-origin: top left;
  transition: opacity 200ms ease, transform 200ms ease, visibility 0s linear;
}

/* Carte trop basse pour une colonne de boutons à 44 px : une rangée,
   chaque bouton dans l’écran. display:contents laisse le zoom se séparer. */
.map-tools.is-wrapped {
  height: calc(100% - 10px - var(--tools-fold-size) - 6px * var(--btn-scale) - var(--settings-inset) - var(--settings-size) - var(--settings-gap));
  flex-flow: column wrap;
  align-content: flex-start;
  align-items: flex-start;
  gap: 6px;
}

.map-tools.is-wrapped .leaflet-top.leaflet-left,
.map-tools.is-wrapped .leaflet-control-zoom {
  display: contents;
}

.map-tools > * { pointer-events: auto; }

.map-tools .place-search {
  position: relative;
  top: auto;
  left: auto;
  z-index: 1;
}

.map-tools:has(.place-search.is-open) {
  right: 10px;
  z-index: 1300;
  width: auto;
  max-width: none;
}

/* La recherche ouverte ne rallonge plus la colonne : sinon Cap en haut
   descend et passe sous Réglages (z-index 1200). Le créneau du bouton loupe
   reste en flux ; le champ et la liste se superposent. */
.map-tools:has(.place-search.is-open)::before {
  content: "";
  flex: 0 0 auto;
  width: max(44px, calc(48px * var(--btn-scale)));
  height: max(44px, calc(48px * var(--btn-scale)));
}

#map-wrap:has(#compass:not([hidden])) .map-tools:has(.place-search.is-open) {
  right: calc(12px + max(44px, calc(52px * var(--btn-scale))) + 8px);
}

.map-tools .place-search.is-open {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  width: auto;
  max-width: none;
}

.map-tools .leaflet-top.leaflet-left {
  position: static;
  top: auto;
  left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: auto;
  margin-top: calc(8px * var(--btn-scale));
  pointer-events: none;
}

.map-tools .leaflet-left .leaflet-control {
  margin-left: 0;
  pointer-events: auto;
}

html.map-tools-collapsed .map-tools {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 200ms ease, transform 200ms ease, visibility 0s linear 200ms;
}

html.map-tools-collapsed .map-tools,
html.map-tools-collapsed .map-tools *,
html.map-tools-collapsed #place-search,
html.map-tools-collapsed #heading-up,
html.map-tools-collapsed #nav-mode,
html.map-tools-collapsed #recenter,
html.map-tools-collapsed .leaflet-control-zoom {
  pointer-events: none !important;
}

html.map-tools-collapsed #place-search,
html.map-tools-collapsed #heading-up,
html.map-tools-collapsed #nav-mode,
html.map-tools-collapsed #recenter,
html.map-tools-collapsed .leaflet-control-zoom {
  visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .map-tools,
  .tools-fold svg {
    transition: none;
  }

  #recenter.fab.is-armed:not(.is-following) { animation: none; }
  .place-mic.is-listening { animation: none; }
}

/* Zone tactile ≥ 44 px CSS, y compris au zoom navigateur. Le bouton lui-même fait cette taille :
   un ::after plafonné à −6,5 px restait sous 44 px dès que le visuel passait sous ~31 px. */
#heading-up,
#nav-mode,
#place-open,
#recenter.fab,
.leaflet-control-zoom a {
  position: relative;
  min-width: max(44px, calc(48px * var(--btn-scale)));
  min-height: max(44px, calc(48px * var(--btn-scale)));
}

.leaflet-control-zoom a {
  min-width: max(44px, calc(48px * var(--btn-scale))) !important;
  min-height: max(44px, calc(48px * var(--btn-scale))) !important;
}

#map .leaflet-pane svg { overflow: visible; }

.commune-label {
  background: none !important;
  border: 0 !important;
}

.commune-name {
  display: block;
  width: max-content;
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  transform-origin: 0 0;
  transform: rotate(calc(-1 * var(--map-bearing, 0deg))) translate(-50%, -50%);
  padding: 0 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.25;
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-shadow: none;
  -webkit-text-stroke: 0;
  pointer-events: none;
}

.commune-name.is-city {
  font-size: 15px;
  font-weight: 800;
}

.heading-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.place-search {
  position: absolute;
  z-index: 1100;
  top: 10px;
  left: 10px;
  width: max-content;
  max-width: min(440px, calc(100% - 20px));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: auto;
}

.place-search.is-open {
  width: 100%;
  max-width: none;
}

#place-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(8px * var(--btn-scale));
  width: calc(48px * var(--btn-scale));
  height: calc(48px * var(--btn-scale));
  min-width: calc(48px * var(--btn-scale));
  min-height: calc(48px * var(--btn-scale));
  padding: 0;
  border: 0;
  border-radius: calc(8px * var(--btn-scale));
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: none;
}

#place-open svg {
  display: block;
  flex: 0 0 auto;
  width: calc(26px * var(--btn-scale));
  height: calc(26px * var(--btn-scale));
}

#place-open:not(:has(.place-chip[hidden])) {
  width: auto;
  max-width: 220px;
  padding: 0 calc(12px * var(--btn-scale)) 0 calc(10px * var(--btn-scale));
  justify-content: flex-start;
}

.place-chip {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 750;
}

.place-search.is-open #place-open { display: none; }

.place-search.is-open .place-form,
.place-search.is-open .place-list,
.place-search.is-open .place-note { width: 100%; }

.place-form input:focus,
#place-clear:focus,
.place-mic:focus {
  outline: none;
}

.place-form input:focus-visible,
#place-clear:focus-visible,
.place-mic:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.place-form {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 4px 4px 4px 14px;
  border-radius: 14px;
  background: var(--legend-bg);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.place-form input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 650;
  appearance: none;
  -webkit-appearance: none;
}

.place-form input::placeholder { color: var(--muted); font-weight: 550; }

#place-input,
#place-input:focus,
#place-input:focus-visible {
  outline: none;
  outline-offset: 0;
  border: 0;
  box-shadow: none;
}

.place-form:focus-within {
  border-color: #8ebfff;
  box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.55);
}

.place-form input::-webkit-search-cancel-button,
.place-form input::-webkit-search-decoration { display: none; }

#place-clear {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 1.8rem;
  font-weight: 500;
  line-height: 1;
}

#place-clear:hover,
#place-clear:focus-visible { background: var(--panel-2); color: var(--text); }

.place-mic {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0 2px 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
}

html[data-theme="light"] .place-mic { color: var(--muted); }

.place-mic svg {
  display: block;
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.85));
}

.place-mic.is-listening {
  color: var(--blue);
  background: transparent;
  border: 0;
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%,
  100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(1.12); }
}

.place-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: min(240px, 36vh);
  overflow: auto;
  border-radius: 14px;
  background: var(--legend-bg);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.place-hint {
  padding: 6px 12px 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.place-list [role="option"] {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.place-list [aria-selected="true"] { background: var(--panel-2); }

.place-label {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
}

.place-context {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.3;
}

.place-note {
  margin: 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--legend-bg);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.35;
  box-shadow: var(--shadow);
}

.place-note.is-offline {
  color: var(--text);
  font-size: 1rem;
  border-color: var(--amber);
}

.route-recalc {
  align-self: center;
  width: max-content;
  max-width: 100%;
  margin: 0 0 6px;
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--legend-bg);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.3;
  box-shadow: var(--shadow);
}

.route-card {
  position: absolute;
  z-index: 620;
  left: 50%;
  bottom: calc(14px + max(44px, calc(48px * var(--btn-scale))) + 10px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: max-content;
  max-width: min(460px, calc(100% - 24px));
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  pointer-events: auto;
}

.route-detail {
  margin: 0 0 8px;
  padding: 8px 12px 10px;
  max-height: min(220px, 32vh);
  overflow: auto;
  border-radius: 14px;
  background: var(--legend-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.route-detail[hidden] { display: none !important; }

.route-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px 0 14px;
  border-radius: 999px;
  background: var(--legend-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

#route-toggle {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
}

#route-summary {
  display: block;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  font-weight: 750;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.route-arrival {
  display: inline-block;
  white-space: nowrap;
}

#route-stop {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--action);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 750;
}

.route-title {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.route-radars {
  margin: 0;
  padding: 0 0 0 1.3rem;
  max-height: none;
  overflow: visible;
}

.route-radars li {
  margin: 0;
  padding: 6px 4px 6px 0;
  font-size: 0.98rem;
  line-height: 1.3;
  cursor: pointer;
}

.route-radars li.route-empty {
  list-style: none;
  margin-left: -1.3rem;
  color: var(--muted);
  cursor: default;
}

.place-list[hidden],
.place-note[hidden],
.route-card[hidden],
.route-recalc[hidden],
#place-form[hidden],
#place-chip[hidden],
#place-clear[hidden],
#place-mic[hidden] { display: none !important; }

#map-wrap.is-nav .route-card {
  z-index: 1250;
  top: calc(8px + var(--tools-fold-size) + 6px);
  bottom: auto;
  left: calc(10px + max(44px, calc(48px * var(--btn-scale))) + 8px);
  right: 10px;
  transform: none;
  width: auto;
  max-width: none;
  align-items: center;
  pointer-events: none;
}

#map-wrap.is-nav:has(#compass:not([hidden])) .route-card {
  right: calc(12px + max(44px, calc(52px * var(--btn-scale))) + 8px);
}

#map-wrap.is-nav:has(.map-tools.is-wrapped) .route-card {
  left: calc(10px + 2 * (max(44px, calc(48px * var(--btn-scale))) + 8px));
}

#map-wrap.is-nav:has(.place-search.is-open) .route-card {
  top: calc(8px + var(--tools-fold-size) + 6px);
}

/* La liste « Destinations récentes » s’ouvre sous la barre, elle ne la recouvre pas.
   La colonne raccourcit d’autant, pour que Cap en haut ne tombe pas sur Réglages. */
#map-wrap.is-nav:has(.place-search.is-open) .map-tools {
  top: calc(8px + var(--tools-fold-size) + 6px + var(--nav-stack, 72px));
  max-height: calc(100% - 8px - var(--tools-fold-size) - 6px - var(--nav-stack, 72px) - var(--settings-inset) - var(--settings-size) - var(--settings-gap));
}

#map-wrap.is-nav:has(.place-search.is-open) .map-tools.is-wrapped {
  height: calc(100% - 8px - var(--tools-fold-size) - 6px - var(--nav-stack, 72px) - var(--settings-inset) - var(--settings-size) - var(--settings-gap));
}

#map-wrap.is-nav .route-card .nav-cue { order: -3; pointer-events: none; max-width: min(420px, 100%); }
#map-wrap.is-nav .route-card .route-recalc { order: -2; pointer-events: none; }
#map-wrap.is-nav .route-card .route-head { order: -1; pointer-events: auto; max-width: 100%; }

.nav-cue {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: 100%;
  margin: 0 0 6px;
  padding: 4px 12px 4px 6px;
  border-radius: 16px;
  background: var(--legend-bg);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.nav-cue[hidden] { display: none !important; }

.nav-cue-icon {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  color: var(--text);
}

.nav-cue-icon svg { display: block; width: 44px; height: 44px; }

.nav-cue-copy { min-width: 0; }

.nav-cue-action,
.nav-cue-detail { margin: 0; }

.nav-cue-action {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.15;
}

.nav-cue-detail {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
}
#map-wrap.is-nav #route-summary { white-space: normal; }

@media (max-width: 430px) {
  #map-wrap.is-nav .route-head {
    gap: 4px;
    padding-left: 10px;
  }

  #map-wrap.is-nav #route-summary {
    font-size: 0.78rem;
    letter-spacing: -0.02em;
    line-height: 1.15;
  }

  #map-wrap.is-nav #route-stop {
    padding: 0 10px;
    font-size: 0.82rem;
  }
}
#map-wrap.is-nav .route-card .route-detail {
  order: 1;
  pointer-events: auto;
  max-width: 100%;
  max-height: min(18vh, 120px);
}

.place-search:not(.is-open) .place-list { display: none !important; }

@media (max-width: 430px) {
  .leaflet-control-attribution {
    max-width: min(46vw, 200px);
    max-height: 2.7em;
    overflow: hidden;
  }

  html.banner-collapsed #limit-block {
    bottom: calc(48px + max(44px, calc(48px * var(--btn-scale))) + 16px);
  }
}

@media (max-width: 720px) {
  .banner-main { flex-direction: row; align-items: center; }
  .limit-sign { width: 64px; height: 64px; border-width: 6px; }
  .limit-sign .limit { font-size: 1.35rem; }
  html.banner-collapsed .limit-sign { width: 38px; height: 38px; border-width: 4px; }
  html.banner-collapsed .limit-sign .limit { font-size: 0.85rem; }
  .dock { flex-direction: column; align-items: stretch; }
  .status-line { text-align: left; }
  .distance { font-size: clamp(2.24rem, 11.2vw, 3.22rem); }
  .distance.is-placeholder { font-size: clamp(1.4rem, 5.6vw, 1.82rem); }
  .alert { left: calc(14px + (48px + 10px) * var(--btn-scale)); top: 12px; right: 14px; }
  .place-search { left: 10px; width: max-content; max-width: calc(100% - 20px); }
  .place-search.is-open { width: 100%; max-width: none; }
  #place-open:not(:has(.place-chip[hidden])) { max-width: 168px; }
  .place-chip { max-width: 96px; }
  .route-card {
    bottom: calc(12px + max(44px, calc(48px * var(--btn-scale))) + 8px);
    max-width: calc(100% - 16px);
  }
  .leaflet-top.leaflet-left { top: calc(10px + (48px + 8px) * var(--btn-scale)); }
  .sheet-card { margin-bottom: env(safe-area-inset-bottom, 0px); }
  #close-settings.sheet-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}
