/* Deux ambiances qui suivent le réglage du téléphone :
   clair « Verre lumineux », sombre « Nuit radar » (carte IGN assombrie, accent cyan). */
:root {
  --bg: #eef2f8;
  --glass: rgba(255, 255, 255, 0.76);
  --glass-strong: rgba(255, 255, 255, 0.94);
  --glass-line: rgba(27, 100, 218, 0.14);
  --text: #1d2330;
  --muted: #66758a;
  --line: #dbe2ec;
  --accent: #1b64da;
  --accent-rgb: 27, 100, 218;
  --accent-ink: #ffffff;
  --accent-soft: rgba(27, 100, 218, 0.1);
  --point-stroke: #ffffff;
  --ok: #2e8f57;
  --warn: #b4540a;
  --radar-bg: #ffffff;
  --me: #1d2330;
  --accuracy: rgba(29, 35, 48, 0.08);
  --map-bg: #e9edf3;
  --map-filter: none;
  --shadow: 0 10px 30px rgba(20, 40, 80, 0.12), 0 2px 6px rgba(20, 40, 80, 0.08);
  --glow: 0 8px 24px rgba(27, 100, 218, 0.35);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Roboto Mono", Menlo, Consolas, monospace;
  --streets-filter: invert(1);
  --streets-opacity: 0.85;
  --radar-veil: rgba(255, 255, 255, 0.3);
  --top-h: 56px;
  --panel-h: 170px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070b14;
    --glass: rgba(12, 19, 33, 0.74);
    --glass-strong: rgba(12, 19, 33, 0.95);
    --glass-line: rgba(92, 208, 255, 0.18);
    --text: #e6edf7;
    --muted: #8ea0b8;
    --line: #1e2a40;
    --accent: #5cd0ff;
    --accent-rgb: 92, 208, 255;
    --accent-ink: #04121f;
    --accent-soft: rgba(92, 208, 255, 0.14);
    --point-stroke: #04121f;
    --ok: #6ee7a8;
    --warn: #f5b45e;
    --radar-bg: #0b1322;
    --me: #e6edf7;
    --accuracy: rgba(92, 208, 255, 0.1);
    --map-bg: #0b1322;
    --map-filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.92) saturate(0.4);
    --streets-filter: none;
    --streets-opacity: 0.9;
    --radar-veil: rgba(11, 19, 34, 0.2);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(92, 208, 255, 0.06);
    --glow: 0 0 0 1px rgba(92, 208, 255, 0.5), 0 8px 28px rgba(92, 208, 255, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.caption { margin: 0; color: var(--muted); font-size: 12px; font-family: var(--mono); letter-spacing: 0.02em; }
.caption:empty { display: none; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--glass-strong); }
}

/* Carte plein écran, commandes flottantes par-dessus */
main { position: fixed; inset: 0; }
#map-wrap, #map { position: absolute; inset: 0; }
#map, .leaflet-container { background: var(--map-bg); font: inherit; }
.leaflet-tile-pane { filter: var(--map-filter); }
.leaflet-top { top: calc(var(--safe-t) + var(--top-h) + 14px); }
.leaflet-bottom { bottom: calc(var(--safe-b) + var(--panel-h) + 12px); }
.leaflet-touch .leaflet-bar { border: 1px solid var(--glass-line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.leaflet-touch .leaflet-bar a { background: var(--glass-strong); color: var(--text); border-color: var(--line); }
.leaflet-control-attribution.leaflet-control {
  background: var(--glass);
  color: var(--muted);
  font-size: 10px;
  border-radius: 0 8px 8px 0;
  margin-left: 0;
}
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--glass-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}
.leaflet-popup-content-wrapper { border-radius: 18px; border: 1px solid var(--glass-line); }
.leaflet-popup-content { margin: 14px 16px; font-size: 14px; line-height: 1.45; min-width: 190px; }
.popup-title { display: block; font-weight: 650; margin-bottom: 2px; }
.popup-meta { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.popup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn-small {
  padding: 9px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-small.alt { background: var(--accent-soft); color: var(--accent); }

#cross {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: var(--glow), inset 0 0 0 6px rgba(var(--accent-rgb), 0.12);
  z-index: 500;
  pointer-events: none;
}
#cross::before, #cross::after {
  content: "";
  position: absolute;
  background: var(--accent);
  border-radius: 2px;
}
#cross::before { left: 50%; top: -10px; bottom: -10px; width: 2px; margin-left: -1px; opacity: 0.5; }
#cross::after { top: 50%; left: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; opacity: 1; }
body.placing #cross { display: block; }

/* En-tête flottant */
.top {
  position: fixed;
  z-index: 1000;
  top: calc(var(--safe-t) + 10px);
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
}
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--accent-soft); }
.seg button {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] {
  background: var(--glass-strong);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.status {
  margin-left: auto;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}
.status.off::before { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 25%, transparent); }
.icon { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.icon svg { width: 20px; height: 20px; }
.icon[aria-pressed="true"] { color: var(--accent); }
.icon[aria-pressed="true"] .off { display: none; }

.fab {
  position: fixed;
  z-index: 900;
  right: 12px;
  bottom: calc(var(--safe-b) + var(--panel-h) + 22px);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.fab svg { width: 24px; height: 24px; }
.fab.following { color: var(--accent); }
body.radar-on .fab, body.radar-on .leaflet-control-container { display: none; }

/* Radar */
#radar {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(var(--safe-t) + var(--top-h) + 14px) 16px calc(var(--safe-b) + var(--panel-h) + 16px);
  background: radial-gradient(circle at 50% 30%, rgba(var(--accent-rgb), 0.12), transparent 62%), var(--bg);
  overflow: hidden;
}
/* Radar carré, dimensionné pour laisser ~3 lignes visibles à la liste en dessous. */
.radar-stage {
  position: relative;
  flex: none;
  align-self: center;
  width: min(100%, 440px, calc(100vh - var(--safe-t) - var(--top-h) - var(--panel-h) - var(--safe-b) - 230px));
  width: min(100%, 440px, calc(100dvh - var(--safe-t) - var(--top-h) - var(--panel-h) - var(--safe-b) - 230px));
  min-width: 200px;
  aspect-ratio: 1;
}
.radar-map-clip { position: absolute; inset: 24px; -webkit-clip-path: circle(50%); clip-path: circle(50%); }
/* Carte plus grande que le disque pour couvrir les coins quand elle tourne avec la boussole. */
#radar-map { position: absolute; left: -21%; top: -21%; width: 142%; height: 142%; will-change: transform; }
#radar-map.leaflet-container { background: transparent; }
#radar-map .leaflet-tile-pane { filter: var(--streets-filter); opacity: var(--streets-opacity); }
#radar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }
body.placing-radar #radar-canvas { cursor: crosshair; }
.radar-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
}
.radar-bar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.round-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  color: var(--muted);
}
.round-btn svg { width: 20px; height: 20px; }
.round-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: rgba(var(--accent-rgb), 0.4); }
/* Liste de tous les points, du plus proche au plus loin : elle défile seule, le radar reste en place. */
#nearest {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#nearest li {
  flex: none;
  border-radius: 14px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
}
#nearest li.open { border-color: rgba(var(--accent-rgb), 0.45); background: var(--glass-strong); }
#nearest .row-main {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  text-align: left;
}
#nearest strong { min-width: 62px; color: var(--accent); font-family: var(--mono); font-weight: 600; }
#nearest .row-main span { flex: 1; color: var(--muted); font-size: 13px; }
#nearest .row-actions { display: none; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 0 10px 10px; }
#nearest li.open .row-actions { display: grid; }
#nearest li.empty { padding: 12px; text-align: center; color: var(--muted); border-style: dashed; background: none; }

/* Bandeaux */
.alert {
  position: fixed;
  z-index: 1100;
  left: 12px;
  right: 12px;
  top: calc(var(--safe-t) + var(--top-h) + 20px);
  padding: 13px 16px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  box-shadow: var(--glow);
  cursor: pointer;
  animation: drop 0.25s ease-out;
}
.toast {
  position: fixed;
  z-index: 1100;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + var(--panel-h) + 22px);
  width: max-content;
  max-width: calc(100% - 110px);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  text-align: center;
}
@keyframes drop { from { transform: translateY(-8px); opacity: 0; } }

/* Panneau du bas */
.panel {
  position: fixed;
  z-index: 1000;
  left: 10px;
  right: 10px;
  bottom: calc(var(--safe-b) + 10px);
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 26px;
}
#summary { margin: 0 4px; font-size: 14px; }
#summary b { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.actions { display: grid; }
.placing-actions { display: none; grid-template-columns: 1fr 2fr; gap: 10px; }
body.placing .placing-actions { display: grid; }
body.placing #btn-report { display: none; }
.primary {
  padding: 15px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: var(--glow);
  transition: transform 0.1s, filter 0.2s;
}
.primary:active { transform: scale(0.98); filter: brightness(0.95); }
.primary[aria-busy="true"] { filter: saturate(0.6); }
.secondary {
  padding: 15px 16px;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.link-btn { padding: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
#offline { margin: 0 4px; }

/* Fiches (position, partage) */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 10px 10px calc(var(--safe-b) + 10px);
  background: rgba(3, 8, 18, 0.45);
  animation: fade 0.2s ease-out;
}
.sheet {
  width: min(440px, 100%);
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  padding: 24px 20px 16px;
  border-radius: 28px;
  background: var(--glass-strong);
  animation: rise 0.25s ease-out;
}
.sheet p { margin: 0; color: var(--muted); font-size: 14px; }
.sheet .primary, .sheet .row { width: 100%; }
.sheet .row { display: flex; gap: 10px; }
.sheet .row > * { flex: 1; }
.sheet .row > .primary { flex: 2; }
.sheet-icon { width: 64px; height: 64px; fill: none; stroke: var(--accent); stroke-width: 2; }
.sheet-icon circle:nth-child(1) { opacity: 0.4; }
.sheet-icon .dot { fill: var(--accent); stroke: none; }
.help {
  width: 100%;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--text);
}
.help ol { margin: 6px 0 0; padding-left: 18px; }
.qr { width: 220px; height: 220px; padding: 10px; border-radius: 18px; background: #fff; }
#share-url { margin: 0; color: var(--text); font-size: 13px; word-break: break-all; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

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

