:root {
  --bg: #10131a;
  --panel: #171b24;
  --panel-2: #1f2531;
  --line: #2b3342;
  --ink: #e6eaf2;
  --dim: #98a2b3;
  --accent: #ff6b35;
  --accent-2: #4da3ff;
  --warn: #ffb020;
  --radius: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  display: grid;
  grid-template-columns: 340px 1fr;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- avertissement ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 14, 0.82);
  backdrop-filter: blur(3px);
}

.modal {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal p { margin: 0 0 12px; color: #c8d0dd; font-size: 14px; line-height: 1.55; }
.modal .modal-key {
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(255, 107, 53, 0.09);
  color: var(--ink);
}
.modal-sign {
  margin: 16px 0 4px !important;
  color: var(--ink) !important;
  font-style: italic;
  text-align: right;
}
.modal button { margin-top: 8px; }

/* Le contrôle de zoom passe en bas à gauche : en haut il se retrouve sous le
   bandeau d'explication, qui occupe toute la largeur utile. */
.leaflet-top.leaflet-left { top: auto; bottom: 6px; }

/* ---------- panneau ---------- */

#panel {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 16px calc(24px + var(--safe-b));
}

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#panel header h1 { margin: 0; font-size: 19px; letter-spacing: -0.2px; }
#panel .sub { margin: 4px 0 0; color: var(--dim); font-size: 12.5px; }

.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel-2);
  color: var(--dim);
  font-size: 11px;
  vertical-align: 1px;
}

#panel section, #panel details, #panel footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

#panel h2, #panel summary {
  margin: 0 0 10px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#panel summary { cursor: pointer; padding: 4px 0; }
#panel summary::marker { color: var(--dim); }

.row { margin-bottom: 12px; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

label { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--ink); }

select, button, input[type="range"] { width: 100%; font: inherit; }

select {
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
}

button {
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: #3d4757; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a0c04; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.big { min-height: 46px; font-size: 15px; }
button:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  width: 34px;
  min-height: 34px;
  flex: none;
  padding: 0;
  border-radius: 50%;
  color: var(--dim);
  display: none;
}

.linklike {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-2);
  text-decoration: underline;
  font-size: inherit;
}

input[type="range"] { margin: 2px 0 0; accent-color: var(--accent); height: 26px; }

output { color: var(--accent); font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 10px; padding: 5px 0; cursor: pointer; }
.check input { width: auto; height: 18px; accent-color: var(--accent); }

.hint { margin: 8px 0 0; font-size: 12px; }
.dim { color: var(--dim); }

.status { margin: 8px 0 0; min-height: 16px; font-size: 12px; color: var(--dim); }
.status.err { color: #ff8a7a; }
.status.ok { color: #6ee7a8; }

.warn {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--warn);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(255, 176, 32, 0.09);
  color: #ffd489;
  font-size: 12px;
}

.hidden { display: none !important; }

/* ---------- boussole ---------- */

.compass-wrap { display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: center; }

#compass { width: 112px; height: 112px; }
.c-bg { fill: var(--panel-2); stroke: var(--line); }
.c-cross { stroke: var(--line); stroke-width: 1; }
.c-lab { fill: var(--dim); font-size: 11px; text-anchor: middle; }
.c-wind-arrow { stroke: var(--accent-2); stroke-width: 3; }
.c-wind-head { fill: var(--accent-2); }
.c-smoke-arrow { stroke: var(--accent); stroke-width: 5; opacity: 0.85; }
.c-smoke-head { fill: var(--accent); opacity: 0.85; }

.facts { margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.facts li { display: flex; justify-content: space-between; gap: 8px; padding: 2.5px 0; }
.facts span { color: var(--dim); }
.facts strong { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

/* ---------- pied ---------- */

.legend-title { margin: 0 0 8px; color: var(--dim); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.legend { margin: 0; padding: 0; list-style: none; font-size: 12px; color: var(--dim); }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.sw-emoji { width: 14px; flex: none; font-size: 13px; line-height: 1; text-align: center; }
.sw.grad { background: linear-gradient(90deg, #f2e34c, #f59e0b, #ef4444, #8b2fbf); }

.disclaimer { margin: 14px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--dim); }

/* ---------- carte ---------- */

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #0c0f15; }
.leaflet-container { background: #0c0f15; font: inherit; }

/* Fond légèrement désaturé : les couches panache et PM2.5 ressortent nettement
   mieux que sur les tuiles OSM d'origine, très colorées. */
.leaflet-tile-pane { filter: saturate(0.7) brightness(0.97); }

/* Pictogrammes de feu : un léger halo sombre les détache du fond de carte. */
.map-emoji {
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.65));
  cursor: pointer;
  transition: transform 0.12s ease;
}
.map-emoji:hover { transform: scale(1.25); }

/* Bandeau d'explication en haut de la carte. Volontairement en texte blanc et
   en phrases complètes : c'est le seul endroit lisible sans rien connaître aux
   roses des vents ni aux degrés. */
#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(560px, calc(100% - 24px));
  padding: 13px 18px 13px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(16, 19, 26, 0.9);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.hud-arrows { flex: none; text-align: center; }

.hud-arrow { width: 54px; height: 54px; display: block; margin: 0 auto; }
.hud-arrow path { stroke: var(--accent); stroke-width: 7; stroke-linecap: round; }
.hud-arrow polygon { fill: var(--accent); }
#hud-arrow-smoke { transform-origin: 32px 32px; transition: transform 0.3s ease; }

.hud-arrow-lab {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 10.5px;
  line-height: 1.25;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud-text { min-width: 0; }
.hud-when { margin: 0 0 3px; color: #aeb8c8; font-size: 12px; }
.hud-sentence {
  margin: 0;
  color: #fff;
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.35;
}
.hud-sentence b { color: var(--accent); }
.hud-detail { margin: 4px 0 0; color: #d5dce7; font-size: 13px; line-height: 1.4; }

.fab { display: none; }

#timebar {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#timebar button { width: auto; padding: 7px 12px; }
#timebar button.ghost { color: var(--dim); }
#time { accent-color: var(--accent-2); }

.time-label { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.time-label strong { font-variant-numeric: tabular-nums; }
.time-label span { color: var(--dim); font-size: 11.5px; }

#toast {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 27, 36, 0.96);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  font-size: 12.5px;
  z-index: 800;
}

/* ---------- mobile : carte plein écran, réglages en tiroir ---------- */

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }

  #panel {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1200;
    max-height: 85vh;
    padding-bottom: calc(28px + var(--safe-b));
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.55);
    transform: translateY(101%);
    transition: transform 0.24s ease;
    visibility: hidden;
  }

  body.panel-open #panel { transform: none; visibility: visible; }

  /* Poignée de préhension en haut du tiroir. */
  #panel header::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: -6px auto 14px;
    border-radius: 99px;
    background: var(--line);
  }

  .icon-btn { display: block; }

  .fab {
    display: block;
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 700;
    width: auto;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 99px;
    background: var(--accent);
    border-color: var(--accent);
    color: #1a0c04;
    font-weight: 600;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  }

  body.panel-open .fab { display: none; }

  /* Cibles tactiles : rien en dessous de 44 px. */
  select, button { min-height: 44px; }
  .check { padding: 9px 0; }
  .check input { width: 20px; height: 20px; }
  input[type="range"] { height: 34px; }

  #hud {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
    gap: 12px;
    padding: 11px 14px 11px 11px;
  }
  .hud-arrow { width: 44px; height: 44px; }
  .hud-arrow-lab { font-size: 9.5px; }
  .hud-sentence { font-size: 15px; }
  .hud-detail { font-size: 12.5px; }
  .hud-when { font-size: 11.5px; }

  /* Barre temporelle sur deux lignes : le curseur mérite toute la largeur. */
  #timebar {
    grid-template-columns: 44px 1fr auto;
    grid-template-areas: "play slider now" "label label label";
    gap: 8px 10px;
    padding: 8px 12px calc(8px + var(--safe-b));
  }
  #play { grid-area: play; }
  #time { grid-area: slider; }
  #now { grid-area: now; }
  .time-label {
    grid-area: label;
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    font-size: 12.5px;
  }
  #timebar button { padding: 7px 10px; font-size: 13px; }

  .compass-wrap { grid-template-columns: 100px 1fr; }
  #compass { width: 100px; height: 100px; }
  .facts { font-size: 13px; }
}

@media (max-width: 380px) {
  #now { display: none; }
  #timebar { grid-template-columns: 44px 1fr; grid-template-areas: "play slider" "label label"; }
}
