:root {
  --hot: #ef4444;
  --hot-glow: #fb923c;
  --cold: #3b82f6;
  --cold-glow: #06b6d4;
  --accent: #6366f1;
  --green: #10b981;
  --bg-0: #0b1020;
  --bg-1: #111835;
  --bg-2: #1a2348;
  --card: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #e6ebff;
  --muted: #8b95c4;
  --land: #1f2a52;
  --land-stroke: #2d3a6b;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6),
            0 2px 6px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.25), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(239, 68, 68, 0.18), transparent 60%),
    radial-gradient(900px 500px at 50% 110%, rgba(59, 130, 246, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hero {
  text-align: center;
  padding: 1rem 1rem 0.25rem;
}
.hero h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.5vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fb923c 0%, #ef4444 35%, #a78bfa 65%, #06b6d4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.hero .logo {
  height: 1.4em;
  width: auto;
  vertical-align: middle;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 4px rgba(239, 68, 68, 0.35));
}
.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.75rem 1rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas:
      "controls controls"
      "map      side";
    height: calc(100vh - 70px);
  }
  .controls { grid-area: controls; }
  .map-wrap { grid-area: map; min-height: 0; }
  .side     { grid-area: side; min-height: 0; overflow-y: auto; }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.controls {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  padding: 0.55rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.controls .slider-wrap { flex: 1 1 220px; min-width: 180px; }
.controls .year-display { flex: 0 0 auto; }
.ctrl-select {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  flex: 0 0 auto;
}
@media (max-width: 1100px) {
  .controls { flex-wrap: wrap; }
  .controls .slider-wrap { flex: 1 1 100%; order: 10; }
  .controls .ticks { display: none; }
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s, box-shadow 0.15s, filter 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:active { transform: translateY(1px); }
.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}
.ic { width: 14px; height: 14px; display: block; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: white;
  box-shadow: 0 6px 20px -8px rgba(99, 102, 241, 0.7);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--card-border);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.1); }

.year-display {
  font-size: clamp(1.1rem, 2.2vw, 1.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fb923c, #ef4444);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: right;
  min-width: 4ch;
  position: relative;
}

.slider-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.slider-wrap .ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0 4px;
}
#yearSlider {
  width: 100%;
  height: 6px;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(90deg,
    rgba(59, 130, 246, 0.4),
    rgba(99, 102, 241, 0.4),
    rgba(239, 68, 68, 0.4));
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
#yearSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(99, 102, 241, 0.5);
  transition: transform 0.1s;
}
#yearSlider::-webkit-slider-thumb:hover { transform: scale(1.15); }
#yearSlider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(99, 102, 241, 0.5);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  font-size: 0.85rem;
  flex: 0 0 auto;
}
.chip:hover { background: rgba(255, 255, 255, 0.08); }
.chip input { accent-color: var(--accent); margin: 0; }
.chip.hot.on    { border-color: rgba(239, 68, 68, 0.5);  background: rgba(239, 68, 68, 0.12); }
.chip.cold.on   { border-color: rgba(59, 130, 246, 0.5); background: rgba(59, 130, 246, 0.12); }

.map-wrap {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.4), rgba(15, 23, 42, 0.1));
  border: 1px solid var(--card-border);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  padding: 0.5rem;
  position: relative;
  overflow: hidden;
  min-height: 320px;
}
@media (max-width: 899px) {
  .map-wrap { aspect-ratio: 1 / 1; max-height: 70vh; }
}
#map {
  width: 100%;
  height: 100%;
  display: block;
}
.france {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: 0.8;
  stroke-linejoin: round;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

.halo {
  pointer-events: none;
  mix-blend-mode: screen;
  transition: r 700ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.point {
  cursor: pointer;
  transition: opacity 400ms;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 0.8;
  filter: drop-shadow(0 0 3px currentColor);
}
.point.hot  { fill: var(--hot);  color: var(--hot-glow); }
.point.cold { fill: var(--cold); color: var(--cold-glow); }
.point.scope-national      { stroke-width: 1.6; stroke: white; }
.point.scope-departemental { stroke-width: 1.1; }
.point.scope-station       { opacity: 0.85; }
/* Pour les half-discs : pas de stroke sur le bord vertical (visuellement plus propre) */
.point.half-left  { stroke-linejoin: miter; }
.point.half-right { stroke-linejoin: miter; }
.point.new  { animation: pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse {
  0%, 100% { transform: scale(1);   filter: drop-shadow(0 0 6px currentColor); }
  50%      { transform: scale(1.5); filter: drop-shadow(0 0 14px currentColor); }
}

.tooltip {
  position: absolute;
  background: rgba(15, 19, 41, 0.95);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 0.82rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  max-width: 220px;
  z-index: 10;
  line-height: 1.4;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.tooltip strong { display: block; margin-bottom: 0.15rem; font-weight: 700; }
.tooltip .dept { color: var(--muted); font-size: 0.78rem; }
.tooltip .temp { font-size: 1.2rem; font-weight: 800; margin: 0.15rem 0; }
.tooltip .temp.hot  { color: var(--hot);  }
.tooltip .temp.cold { color: var(--cold); }
.tooltip .when { color: var(--muted); font-size: 0.78rem; }
.tooltip .delta-line {
  font-size: 0.78rem;
  font-weight: 600;
  margin: 0.1rem 0 0.15rem;
}
.tooltip .delta-line.hot  { color: #fb923c; }
.tooltip .delta-line.cold { color: #06b6d4; }
.tooltip .scope {
  margin-top: 0.4rem;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  display: inline-block;
}
.tooltip .scope-national      { background: rgba(99, 102, 241, 0.25); color: #c7d2fe; }
.tooltip .scope-departemental { background: rgba(255, 255, 255, 0.08); color: var(--muted); }
.tooltip .scope-station       { display: none; }

.side {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stats, .geo-card, .new-alert, .instructions, .dom-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.stats h2 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.stat {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--card-border);
}
.stat .label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}
.stat.hot  .value { color: var(--hot); }
.stat.cold .value { color: var(--cold); }
.stat .delta {
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 0.25rem;
  opacity: 0.85;
}
.stat.hot  .delta { color: #fb923c; }
.stat.cold .delta { color: #06b6d4; }
.stat .ref {
  margin-top: 0.15rem;
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.stat .dot {
  width: 7px; height: 7px; border-radius: 50%;
  display: inline-block;
}
.stat.hot  .dot { background: var(--hot);  box-shadow: 0 0 8px var(--hot); }
.stat.cold .dot { background: var(--cold); box-shadow: 0 0 8px var(--cold); }

.user-dot {
  fill: var(--green);
  stroke: white;
  stroke-width: 2;
  filter: drop-shadow(0 0 8px var(--green));
}
.user-halo {
  fill: var(--green);
  fill-opacity: 0.25;
  animation: halo 2s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes halo {
  0%   { transform: scale(0.4); opacity: 0.6; }
  100% { transform: scale(2.2); opacity: 0;   }
}
.user-label {
  font-size: 11px;
  font-weight: 700;
  fill: var(--green);
  paint-order: stroke;
  stroke: rgba(11, 16, 32, 0.85);
  stroke-width: 3;
  stroke-linejoin: round;
}

.geo-card {
  border-left: 3px solid var(--green);
  min-height: 165px;
  display: flex;
  flex-direction: column;
}
.geo-card p { flex: 1 1 auto; }
.geo-card h3 {
  margin: 0 0 0.3rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.geo-card p { margin: 0; font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.geo-card strong { color: var(--text); }
.near-line {
  display: block;
  padding: 0.3rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.82rem;
  line-height: 1.4;
}
.near-line:first-child { border-top: none; }
.near-line .dist { color: var(--muted); white-space: nowrap; }
.near-line.hot strong  { color: var(--hot); }
.near-line.cold strong { color: var(--cold); }

.new-alert {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
  border: 1px solid rgba(16, 185, 129, 0.3);
  animation: alertIn 0.4s ease-out;
}
@keyframes alertIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.new-alert {
  min-height: 200px;
}
.new-alert.empty {
  background: rgba(255, 255, 255, 0.025);
  border-color: var(--card-border);
}
.new-alert h3 { margin: 0 0 0.4rem; font-size: 0.9rem; color: var(--green); }
.new-alert.empty h3 { color: var(--muted); }
.new-alert ul { margin: 0; padding-left: 1.1rem; font-size: 0.82rem; color: var(--muted); }
.new-alert ul strong { color: var(--text); }
.empty-msg { list-style: none; margin-left: -1.1rem; color: var(--muted); font-style: italic; }

.dom-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}
.dom-card ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.dom-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  padding: 0.25rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.dom-line:first-child { border-top: none; }
.dom-line.empty .dom-vals { color: var(--muted); }
.dom-name { color: var(--text); }
.dom-vals { font-variant-numeric: tabular-nums; }
.dom-vals .hot  { color: var(--hot);  font-weight: 600; }
.dom-vals .cold { color: var(--cold); font-weight: 600; }
.dom-vals .muted { color: var(--muted); }

.instructions {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
.instructions p { margin: 0.15rem 0; }

.map-instructions {
  max-width: 220px;
  padding: 0.55rem 0.75rem;
  background: rgba(11, 16, 32, 0.55);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 0.72rem;
}
.map-instructions p { margin: 0.15rem 0; }
.instructions kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.75rem;
  color: var(--text);
}

/* Chart overlay : sparkline en bas de la carte, transparent, ne capte pas
   les clics. Hauteur volontairement contenue (~16% de la map) */
.chart-overlay {
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.5rem;
  height: 21%;
  width: calc(100% - 1rem);
  pointer-events: none;
  opacity: 0.9;
}
.map-overlay-left {
  position: absolute;
  left: 0.85rem;
  top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 5;
}
@media (max-width: 720px) {
  /* Mobile : on stack le bloc carte verticalement
     [map carrée] → [chart sparkline] → [légendes] → [instructions]
     pour qu'aucun overlay ne masque le territoire */
  .map-wrap {
    aspect-ratio: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: visible;
    padding: 0.5rem;
    gap: 0.5rem;
  }
  #map {
    width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    flex: 0 0 auto;
  }
  .chart-overlay {
    position: static;
    width: 100%;
    height: 90px;
    opacity: 1;
  }
  .chart-legend.chart-legend {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
    pointer-events: auto;
  }
  .map-overlay-left {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: auto;
  }
  .map-instructions { max-width: 100%; pointer-events: auto; }
}
.chart-legend {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(11, 16, 32, 0.55);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.chart-legend li { display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.sw {
  display: inline-block;
  width: 12px; height: 2px;
  border-radius: 1px;
}
.sw.mean     { background: #f8fafc; box-shadow: 0 0 4px rgba(248, 250, 252, 0.6); }
.sw.ssp1     { background: #22c55e; }
.sw.ssp2     { background: #a78bfa; }
.sw.ssp5     { background: #ef4444; }
.sw.canicule { background: #ef4444; }
.sw.doctrine { background: #a78bfa; }

.chart-line { fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.mean { stroke: #f8fafc; stroke-width: 2; filter: drop-shadow(0 0 3px rgba(248, 250, 252, 0.45)); }
.chart-line.ssp1 { stroke: #22c55e; stroke-width: 1; stroke-dasharray: 2 2.5; opacity: 0.4; }
.chart-line.ssp2 { stroke: #a78bfa; stroke-width: 1; stroke-dasharray: 2 2.5; opacity: 0.4; }
.chart-line.ssp5 { stroke: #ef4444; stroke-width: 1; stroke-dasharray: 2 2.5; opacity: 0.4; }

.event-line.event-canicule { stroke: rgba(239, 68, 68, 0.45); stroke-width: 0.9; stroke-dasharray: 1 2; }
.event-line.event-doctrine { stroke: rgba(167, 139, 250, 0.5);  stroke-width: 0.9; stroke-dasharray: 1 2; }
.event-label { font-size: 7.5px; font-weight: 600; letter-spacing: 0.02em; }
.event-label.event-canicule { fill: rgba(252, 165, 165, 0.85); }
.event-label.event-doctrine { fill: rgba(196, 181, 253, 0.85); }
.chart-cursor { stroke: rgba(255, 255, 255, 0.55); stroke-width: 1; stroke-dasharray: 2 3; }
.axis-tick  { stroke: rgba(255, 255, 255, 0.15); stroke-width: 0.8; }
.axis-grid  { stroke: rgba(255, 255, 255, 0.04); stroke-width: 0.6; }
.axis-now   { stroke: rgba(255, 255, 255, 0.18); stroke-width: 0.8; stroke-dasharray: 1 3; }
.axis-label { fill: var(--muted); font-size: 8px; }
.axis-marker { fill: rgba(255, 255, 255, 0.5); font-size: 7px; font-weight: 600; letter-spacing: 0.05em; }

/* Chandelles d'anomalie annuelle : rouge au-dessus du zéro, bleu en dessous */
.candle.hot  { fill: #ef4444; }
.candle.cold { fill: #3b82f6; }
.candle-axis {
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 0.6;
  stroke-dasharray: 1 2;
}

.method {
  max-width: 1100px;
  margin: 1.5rem auto 0;
  padding: 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}
.method details {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 0.75rem 1rem;
}
.method summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text);
  list-style: none;
  user-select: none;
}
.method summary::-webkit-details-marker { display: none; }
.method summary::after {
  content: "▾";
  margin-left: 0.4rem;
  display: inline-block;
  transition: transform 0.15s;
  opacity: 0.6;
}
.method details[open] summary::after { transform: rotate(180deg); }
.method-body {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--card-border);
}
.method-body h3 {
  margin: 1.1rem 0 0.3rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
}
.method-body h3:first-child { margin-top: 0; }
.method-body p, .method-body ul { margin: 0.3rem 0 0.5rem; }
.method-body ul { padding-left: 1.2rem; }
.method-body li { margin: 0.15rem 0; }
.method-body code {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.8em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.method-body a { color: var(--accent); text-decoration: none; }
.method-body a:hover { text-decoration: underline; }
.method-body strong { color: var(--text); }

.foot {
  text-align: center;
  padding: 0.5rem 1rem 1rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.foot a { color: var(--accent); text-decoration: none; }
.foot a:hover { text-decoration: underline; }
