:root {
  color-scheme: dark;
  --bg: #0c1116;
  --panel: #151c26;
  --panel-2: #1d2733;
  --line: #2c3a4b;
  --text: #f4f7fb;
  --muted: #a9b6c4;
  --blue: #4da3ff;
  --amber: #ffb020;
  --red: #ff3344;
  --ok: #3dd68c;
  --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);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { 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: 12px 18px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

#banner.is-far { background: #6d4308; }
#banner.is-near { background: #8d1522; }

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

.distance-block { flex: 1.5; min-width: 0; }
.limit-block {
  flex: 0.8;
  min-width: 140px;
  background: rgba(8, 12, 16, 0.35);
  border-radius: 18px;
  padding: 8px 14px 10px;
  text-align: right;
}

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

.distance { font-size: clamp(4.2rem, 12vw, 8.5rem); }
.limit { font-size: clamp(3.4rem, 9vw, 6.5rem); }

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

.caption {
  margin-top: 6px;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  font-weight: 650;
}

.meta, .sim-note {
  margin-top: 8px;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.35;
}

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

.alert {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a1218;
  color: #ffd5da;
  font-size: 1.05rem;
  font-weight: 650;
}

.sim-note {
  color: var(--amber);
  font-weight: 700;
}

#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

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

.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.95) saturate(0.25);
}

.leaflet-container { background: #0c1116; font: inherit; }

.leaflet-control-attribution {
  background: rgba(12, 17, 22, 0.88) !important;
  color: #d5deE8 !important;
  font-size: 12px !important;
  max-width: 70vw;
}

.leaflet-control-attribution a { color: #9fd0ff !important; }

.leaflet-control-zoom a {
  width: 48px !important;
  height: 48px !important;
  line-height: 48px !important;
  font-size: 26px !important;
  background: #1b2430 !important;
  color: var(--text) !important;
  border-bottom-color: #2c3a4b !important;
}

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

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

@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-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: 0;
  height: 0;
  margin: 4px auto 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 26px solid var(--blue);
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.8));
}

.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: rgba(27, 36, 48, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

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

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

.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:disabled {
  background: #3a4452;
  color: #9aa6b2;
  cursor: default;
}

.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: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.45);
}

.sheet-card {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  border: 1px solid var(--line);
}

.sheet h2 { margin: 0 0 8px; font-size: 1.5rem; }

.sheet-help {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.4;
}

.field {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 10px 0;
  font-size: 1.1rem;
}

.field input[type="number"],
.field input[type="range"] {
  width: min(220px, 46vw);
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0e141b;
  padding: 0 10px;
  font-size: 1.2rem;
}

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

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

.sheet-actions button { background: #243140; }
#close-settings { background: var(--text); color: #12181f; }

@media (max-width: 720px) {
  .banner-main { flex-direction: column; }
  .limit-block { text-align: left; }
  .dock { flex-direction: column; align-items: stretch; }
  .status-line { text-align: left; }
  .distance { font-size: clamp(3.6rem, 18vw, 5.2rem); }
  .limit { font-size: clamp(3rem, 16vw, 4.4rem); }
}
