:root {
  --card: rgba(25, 28, 22, .94);
  --card-brd: rgba(228, 218, 191, .28);
  --txt: #f0ebdc;
  --dim: #b1aa96;
  --hot: #b6411a;
  --accent: #8f9874;
  --radius: 2px;
  --pad: clamp(12px, 2.2vw, 20px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #181b16;
  color: var(--txt);
  font: 400 14px/1.45 "IBM Plex Sans", "Avenir Next", Avenir, system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map { position: absolute; inset: 0; }

/* Shared field-control panel */
.card {
  position: absolute;
  z-index: 5;
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

/* ── Title + legend ──────────────────────────────────────────── */
.panel-top {
  top: var(--pad);
  left: var(--pad);
  padding: 0;
  max-width: min(760px, calc(100vw - 2 * var(--pad)));
  overflow: hidden;
}

.legend-head {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 12px 9px 14px;
  background: transparent; border: 0; color: var(--txt);
  font: inherit; cursor: pointer; text-align: left;
}
.legend-head .ttl {
  font-size: 11px; font-weight: 750; letter-spacing: .12em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.legend-head .chev {
  width: 16px; height: 16px; flex: none; fill: var(--dim);
  transition: transform .2s;
}
.panel-top.collapsed .legend-head .chev { transform: rotate(-90deg); }
.legend-head:hover .chev { fill: var(--txt); }

.legend-grid {
  display: flex; flex-wrap: wrap; gap: 6px 34px;
  padding: 8px 14px 13px;
  border-top: 1px solid var(--card-brd);
}
.panel-top.collapsed .legend-grid { display: none; }
.legend-col { display: flex; flex-direction: column; gap: 7px; min-width: 215px; }

.lg {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(11px, 1.15vw, 13.5px);
  color: #d9d2c2;
  white-space: nowrap;
}

.sw-ramp { display: inline-flex; gap: 3px; }
.sw-ramp i { width: 11px; height: 11px; border-radius: 0; display: block; }

.sw-active {
  width: 13px; height: 13px; border-radius: 0;
  background: #6d130c;
  box-shadow: inset 0 0 0 3px #e4691a;
}

.sw-smoke {
  width: 14px; height: 14px; border-radius: 0;
  background: repeating-linear-gradient(45deg, #b9b6a8 0 2px, #72766b 2px 4px);
}

.sw-wind {
  width: 20px; height: 2px; position: relative;
  background: linear-gradient(90deg, transparent, var(--accent));
}
.sw-wind::after {
  content: ''; position: absolute; right: -1px; top: -3px;
  border: 4px solid transparent; border-left-color: var(--accent);
}

.sw-line { width: 20px; height: 3px; border-radius: 0; background: linear-gradient(90deg, #5b070b, #b9230c, #ff7c0b); }

.sw-sat {
  width: 14px; height: 14px; border-radius: 0;
  background: linear-gradient(135deg, #2f4f38, #6f7f52 60%, #b9a878);
  border: 1px solid rgba(255,255,255,.25);
}

/* ── Layer toggles ───────────────────────────────────────────── */
.panel-layers {
  right: var(--pad);
  top: calc(var(--pad) + 54px);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tgl {
  display: flex; align-items: center; gap: 9px;
  background: transparent; border: 0; color: var(--dim);
  font: inherit; font-size: 12px; font-weight: 650; letter-spacing: .035em;
  padding: 8px 14px 8px 10px; border-radius: 0;
  cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.tgl:hover { background: rgba(255,255,255,.06); color: var(--txt); }
.tgl .dot {
  width: 8px; height: 8px; border-radius: 0;
  background: rgba(255,255,255,.12);
  box-shadow: none;
  transition: background .15s, box-shadow .15s;
}
.tgl.on { color: var(--txt); background: rgba(255,255,255,.07); }
.tgl.on .dot { background: var(--hot); box-shadow: none; }
.layer-select { display: none; }

/* ── Timeline ────────────────────────────────────────────────── */
.panel-time {
  left: var(--pad);
  right: var(--pad);
  bottom: var(--pad);
  padding: 11px 15px 12px;
}

.time-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }

.play {
  width: 40px; height: 40px; flex: none;
  border-radius: 1px; border: 1px solid var(--card-brd);
  background: #262b22; color: var(--txt);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, transform .1s;
}
.play:hover { background: #343a2d; }
.play:active { transform: none; background: #1e231c; }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }

.stamp { flex: 1; display: flex; align-items: center; gap: 8px; font-size: clamp(14px, 1.7vw, 19px); }
.stamp strong { font-weight: 700; letter-spacing: .025em; }
#stamp-sun { font-size: .95em; opacity: .85; }
.readout {
  font-size: 12.5px; font-weight: 500; color: var(--dim);
  letter-spacing: .01em; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.readout b { color: #e16a2a; font-weight: 700; }

.time-actions { display: flex; gap: 8px; }
.mini {
  height: 32px; min-width: 38px; padding: 0 11px;
  border-radius: 1px; border: 1px solid var(--card-brd);
  background: #262b22; color: #d6d0c0;
  font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.mini:hover { background: #343a2d; color: var(--txt); }
.mini svg { width: 16px; height: 16px; fill: currentColor; }
.mini.busy svg { animation: spin 1s linear infinite; }
.mini.rate-limited { animation: refresh-limit .38s ease-in-out; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes refresh-limit {
  0%, 100% { border-color: var(--card-brd); box-shadow: none; transform: translateX(0); }
  25%, 75% { border-color: #d9533b; box-shadow: 0 0 0 1px rgba(217, 83, 59, .28); transform: translateX(-2px); }
  50% { border-color: #ef6a50; box-shadow: 0 0 0 2px rgba(217, 83, 59, .2); transform: translateX(2px); }
}

.scrub { position: relative; }

#slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0; display: block;
}
#slider::-webkit-slider-runnable-track {
  height: 3px; border-radius: 0;
  background: linear-gradient(90deg, var(--hot) 0 var(--pct, 100%), rgba(228,218,191,.25) var(--pct, 100%) 100%);
}
#slider::-moz-range-track { height: 4px; border-radius: 3px; background: rgba(255,255,255,.16); }
#slider::-moz-range-progress { height: 4px; border-radius: 3px; background: var(--hot); }
#slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; margin-top: -6.5px;
  border-radius: 1px; background: #c65120; border: 1px solid #f0dfbc;
  box-shadow: none;
}
#slider::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 1px;
  background: #c65120; border: 1px solid #f0dfbc;
  box-shadow: none;
}

.ticks { position: relative; height: 22px; margin-top: 2px; }
.ticks span {
  position: absolute; top: 0; transform: translateX(-50%);
  font-size: 11px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.ticks span::before {
  content: ''; position: absolute; left: 50%; top: -7px;
  width: 1px; height: 5px; background: rgba(255,255,255,.24);
}

/* ── Popup ───────────────────────────────────────────────────── */
.maplibregl-popup-content {
  background: #20241d; color: var(--txt);
  border: 1px solid var(--card-brd); border-radius: 1px;
  padding: 11px 13px; font-size: 12.5px; line-height: 1.5;
  backdrop-filter: none; box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
.maplibregl-popup-tip { border-top-color: var(--card) !important; border-bottom-color: var(--card) !important; }
.maplibregl-popup-content b { color: #ffab5e; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right { margin-bottom: 138px; }

/* ── Commune markers ─────────────────────────────────────────── */
.commune {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  pointer-events: none; text-shadow: 0 1px 4px #000, 0 0 10px rgba(0,0,0,.9);
}
.commune .pin { width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 6px rgba(0,0,0,.9); }
.commune .nm { font-size: 12px; font-weight: 600; letter-spacing: .01em; color: #fff; }
.commune.big .nm { font-size: 16px; font-weight: 700; }

/* ── Attribution / watermark ─────────────────────────────────── */
.brand {
  position: absolute; z-index: 4; bottom: calc(var(--pad) + 134px); right: var(--pad);
  font-size: 10.5px; color: rgba(255,255,255,.42); letter-spacing: .04em; pointer-events: none;
}

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: absolute; z-index: 20; left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(.96);
  background: #20241d; border: 1px solid var(--card-brd);
  padding: 11px 18px; border-radius: 1px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  backdrop-filter: none;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ── Boot overlay ────────────────────────────────────────────── */
.boot {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: #1b1e18;
  transition: opacity .5s;
}
.boot.gone { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
.flame { font-size: 34px; }
.boot-text { margin: 14px 0 16px; color: var(--dim); font-size: 13.5px; }
.boot-bar { width: 220px; height: 3px; border-radius: 0; background: rgba(255,255,255,.1); overflow: hidden; margin: 0 auto; }
.boot-bar i { display: block; height: 100%; width: 8%; background: var(--hot); border-radius: 0; transition: width .4s ease; }

/* ── Small screens ───────────────────────────────────────────── */
@media (max-width: 760px) {
  .panel-top { padding: 12px 14px; }
  .legend-grid { gap: 5px 20px; }
  .legend-col { min-width: 0; gap: 5px; }
  .lg { font-size: 10.5px; }
  .panel-layers {
    top: auto; right: var(--pad); bottom: calc(var(--pad) + 300px); left: auto;
    padding: 0;
  }
  .panel-layers .tgl { display: none; }
  .layer-select {
    display: block; width: 118px; height: 36px; padding: 0 26px 0 10px;
    appearance: auto; border: 0; border-radius: 1px; background: #262b22;
    color: var(--txt); font: inherit; font-size: 12px; font-weight: 650;
  }
  .brand { display: none; }
  .maplibregl-ctrl-bottom-right { margin-bottom: 116px; }
}
