:root {
  --bg: #fcfcfb;
  --surface: #ffffff;
  --ink: #1b1b1a;
  --ink-2: #4a4a47;
  --muted: #7a7a75;
  --rule: #e6e5e1;
  --grid: #eeede9;
  --minor: #b9b8b2;
  --pos: #c96a1b;
  --neg: #2f6fb5;

  /* Couleurs de parti (palette validée, mode clair) */
  --p-RN: #3b4aa0;
  --p-LFI: #c9243f;
  --p-HOR: #1a9fc9;
  --p-PS: #e05a8f;
  --p-NE: #7a68c9;
  --p-RE: #d98c00;
  --p-LR: #2f7bd6;
  --p-REC: #9a5b25;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a19; --surface: #212120; --ink: #ecebe6; --ink-2: #c3c2bc;
    --muted: #8f8e88; --rule: #34342f; --grid: #2a2a27;
    --minor: #5d5c57; --pos: #e08a3c; --neg: #5b95d6;
    --p-RN: #7180d8; --p-LFI: #e8475f; --p-HOR: #1f9cc4; --p-PS: #de5f92;
    --p-NE: #9483e0; --p-RE: #c08414; --p-LR: #4c8fe6; --p-REC: #b87a45;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1a19; --surface: #212120; --ink: #ecebe6; --ink-2: #c3c2bc;
  --muted: #8f8e88; --rule: #34342f; --grid: #2a2a27;
  --minor: #5d5c57; --pos: #e08a3c; --neg: #5b95d6;
  --p-RN: #7180d8; --p-LFI: #e8475f; --p-HOR: #1f9cc4; --p-PS: #de5f92;
  --p-NE: #9483e0; --p-RE: #c08414; --p-LR: #4c8fe6; --p-REC: #b87a45;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "IBM Plex Sans", system-ui, sans-serif;
}
a { color: inherit; text-decoration-color: var(--muted); text-underline-offset: 2px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

.masthead { border-bottom: 1px solid var(--rule); padding: 40px 0 28px; margin-bottom: 32px; }
.kicker { margin: 0 0 6px; font: 500 13px/1 "IBM Plex Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0 0 10px; font-size: clamp(28px, 5vw, 44px); line-height: 1.1; font-weight: 700; letter-spacing: -.01em; }
.dek { margin: 0; max-width: 680px; color: var(--ink-2); font-size: 18px; }

section { margin-bottom: 64px; }
.section-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; border-top: 2px solid var(--ink); padding-top: 12px; margin-bottom: 12px; }
h2 { margin: 0; font-size: 22px; font-weight: 700; }
.note { margin: 0 0 16px; color: var(--muted); font-size: 14px; max-width: 760px; }

.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button {
  font: 500 13px/1 "IBM Plex Sans", sans-serif; color: var(--ink-2); background: transparent;
  border: 0; padding: 8px 12px; cursor: pointer; min-height: 32px;
}
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.seg button:focus-visible, .check input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.check { font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

.chart { position: relative; width: 100%; min-height: 320px; }
.chart svg { display: block; overflow: visible; }
.axis text { font: 12px "IBM Plex Mono", monospace; fill: var(--muted); }
.axis line, .axis path { stroke: var(--rule); }
.grid line { stroke: var(--grid); }
.grid path { display: none; }
.trend { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend.minor { stroke: var(--minor); stroke-width: 1.25; }
.trend.dim { opacity: .15; }
.band { opacity: 0; transition: opacity .15s; }
.band.on { opacity: .16; }
.dot { opacity: .35; }
.dot.minor { fill: var(--minor); opacity: .5; }
.dot.dim { opacity: .05; }
.end-label { font: 600 13px "IBM Plex Sans", sans-serif; fill: var(--ink); cursor: pointer; }
.end-label .v { font: 500 13px "IBM Plex Mono", monospace; fill: var(--ink-2); }
.end-label.dim { opacity: .25; }
.end-label.minor { font-weight: 400; fill: var(--muted); font-size: 12px; }
.event-line { stroke: var(--rule); stroke-width: 1; }
.event-mark circle { fill: var(--bg); stroke: var(--muted); stroke-width: 1; }
.event-mark text { font: 500 10px "IBM Plex Mono", monospace; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.event-mark:hover circle, .event-mark:focus circle { fill: var(--ink); stroke: var(--ink); }
.event-mark:hover text, .event-mark:focus text { fill: var(--bg); }
.event-mark { cursor: help; outline: none; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; }
.ref50 { stroke: var(--muted); stroke-width: 1; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 300px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 6px; padding: 10px 12px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.tooltip .tt-date { font: 500 12px "IBM Plex Mono", monospace; color: var(--muted); margin-bottom: 6px; }
.tooltip .tt-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; line-height: 1.6; }
.tooltip .tt-v { font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
.tooltip .tt-foot { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 24px; }
table.data caption { text-align: left; font-weight: 700; font-size: 15px; padding-bottom: 8px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
table.data thead th { font: 500 12px "IBM Plex Mono", monospace; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--ink-2); }
table.data td.num, table.data th.num { text-align: right; font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover, table.data tbody tr.sel { background: var(--grid); }
table.compact { font-size: 13px; margin-top: 0; }
table.compact th, table.compact td { padding: 6px 8px; }
.cand { display: inline-flex; align-items: center; gap: 8px; }
.party { color: var(--muted); font-size: 12px; }
svg.sw { display: inline-block; flex: none; vertical-align: middle; }

.duels { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 28px 32px; }
.duel h3 { margin: 0 0 6px; font-size: 15px; }
.duel .score { display: flex; justify-content: space-between; align-items: baseline; font: 600 22px "IBM Plex Mono", monospace; margin-bottom: 4px; }
.duel .score span:last-child { text-align: right; }
.duel .score small { display: block; font: 400 12px "IBM Plex Sans", sans-serif; color: var(--muted); }
.duel .bar { display: flex; height: 8px; gap: 2px; margin-bottom: 6px; }
.duel .bar span { display: block; height: 100%; }
.duel .bar span:first-child { border-radius: 4px 0 0 4px; }
.duel .bar span:last-child { border-radius: 0 4px 4px 0; }
.duel .meta { font-size: 12px; color: var(--muted); margin: 0 0 4px; }

.heat { text-align: right; font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }

.prose { max-width: 720px; }
.prose h2 { border-top: 2px solid var(--ink); padding-top: 12px; margin-bottom: 8px; }
.prose h3 { font-size: 16px; margin: 24px 0 4px; }
.prose p, .prose li { color: var(--ink-2); }
.prose ul { padding-left: 20px; }
.foot { border-top: 1px solid var(--rule); padding-top: 16px; padding-bottom: 40px; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .masthead { padding-top: 24px; }
  .dek { font-size: 16px; }
  .seg button { padding: 8px 9px; }
}
@media (max-width: 640px) {
  .end-label, .end-label .v { font-size: 11.5px; }
}

/* Légende cliquable */
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.legend-items { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 30px;
  font: 500 13px "IBM Plex Sans", sans-serif; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 15px;
  padding: 4px 10px; cursor: pointer;
}
.chip.minor { color: var(--ink-2); }
.chip[aria-pressed="false"] { color: var(--muted); background: transparent; border-style: dashed; text-decoration: line-through; text-decoration-color: var(--muted); }
.chip[aria-pressed="false"] svg { opacity: .3; }
.chip:hover { border-color: var(--ink-2); }
.chip:focus-visible, .link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.legend-tools { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.link { font: 500 13px "IBM Plex Sans", sans-serif; color: var(--ink-2); background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
.link:hover { color: var(--ink); text-decoration-color: var(--ink-2); }
