:root {
  color-scheme: light;
  --dark-slate: #283d3b;
  --stormy-teal: #197278;
  --powder-petal: #edddd4;
  --tomato-jam: #c44536;
  --chestnut: #772e25;
  --bg: #f7f2ed;
  --panel: #fffdf9;
  --ink: var(--dark-slate);
  --muted: #687570;
  --line: rgba(40, 61, 59, 0.2);
  --line-strong: rgba(40, 61, 59, 0.38);
  --accent: var(--stormy-teal);
  --soft: #f3ece6;
  --surface: #fbf6f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #fbf6f1 0, var(--bg) 320px);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.has-open-modal {
  overflow: hidden;
}

button,
select {
  font: inherit;
}

.shell {
  width: min(1240px, calc(100% - 72px));
  margin: 0 auto;
  padding: 42px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 36px;
}

.intro {
  max-width: 820px;
}

.top-actions {
  display: grid;
  gap: 14px;
  justify-items: end;
  align-self: flex-start;
}

.tagline {
  margin: 10px 0 0;
  max-width: 62ch;
  color: var(--stormy-teal);
  font-size: 0.98rem;
  line-height: 1.45;
  font-weight: 500;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 2.8vw, 3.15rem);
  line-height: 1.02;
  font-weight: 760;
}

h2 {
  font-size: 1.05rem;
  font-weight: 720;
  color: var(--dark-slate);
}

.source {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
  white-space: nowrap;
}

.election-control,
.round-control {
  width: 288px;
}

.round-control[hidden] {
  display: none;
}

.toolbar {
  margin-bottom: 32px;
}

.filters-card {
  border: 2px solid var(--stormy-teal);
  border-radius: 2px;
  background: rgba(255, 253, 249, 0.78);
  padding: 24px;
}

.filters-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.filters-head h2 {
  font-size: 1rem;
  color: var(--dark-slate);
}

.filters-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(170px, 1fr));
  gap: 18px 16px;
  align-items: end;
}

.scenario-notice {
  margin-top: 20px;
  border: 1px solid rgba(196, 69, 54, 0.46);
  border-radius: 2px;
  background: rgba(237, 221, 212, 0.55);
  color: var(--chestnut);
  padding: 12px 14px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.scenario-notice[hidden] {
  display: none;
}

.control {
  min-width: 0;
}

.control label {
  display: block;
  margin: 0 0 8px;
  color: var(--dark-slate);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.2;
}

.control select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 2px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 14px) 50% / 6px 6px no-repeat,
    var(--panel);
  color: var(--ink);
  padding: 0 34px 0 13px;
  outline: none;
  cursor: pointer;
  font-size: 0.92rem;
}

.control select:hover {
  border-color: var(--stormy-teal);
  background-color: var(--surface);
}

.control select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(25, 114, 120, 0.22);
  outline-offset: 1px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  padding: 0;
}

.segmented button {
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.87rem;
  font-weight: 650;
  padding: 0 6px;
  /* Un libellé qui passe à la ligne fait grandir le contrôle et casse
     l'alignement de la pile d'en-tête. */
  white-space: nowrap;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button:hover {
  background: rgba(237, 221, 212, 0.32);
  color: var(--ink);
}

.segmented button:focus-visible {
  outline: 2px solid rgba(25, 114, 120, 0.22);
  outline-offset: -2px;
}

/* À placer après `.segmented` : même spécificité, c'est l'ordre qui tranche. */
.election-switch {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.round-switch {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
}

.chart-panel {
  background: var(--panel);
  border: 2px solid var(--dark-slate);
  border-radius: 2px;
  overflow: visible;
  min-width: 0;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 32px 34px 0;
}

.chart-actions {
  flex: 0 0 260px;
  padding-top: 2px;
}

.chart-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 560px;
}

svg {
  display: block;
  width: 100%;
  height: clamp(580px, calc(100vh - 224px), 780px);
  min-height: 560px;
}

.axis text,
.axis-label,
.empty-state {
  fill: var(--muted);
  font-size: 12.5px;
}

.grid line {
  stroke: #e8e8e2;
  stroke-width: 1;
}

/* Second tour uniquement : au-dessus du seuil on l'emporte, en dessous non.
   Aplats volontairement très pâles, ils doivent situer la lecture sans
   concurrencer les couleurs de candidats. */
.majority-zone-win {
  fill: rgba(64, 138, 84, 0.17);
}

.majority-zone-lose {
  fill: rgba(198, 58, 42, 0.1);
}

/* Courbes miroir du camp sélectionné : un duel par courbe, dans la couleur de
   l'adversaire. Trait nettement plus fin que les courbes pleines et pointillé
   serré : elles accompagnent la lecture sans la disputer. */
.trend-mirror {
  stroke-width: 1.4;
  stroke-dasharray: 2.5 3.5;
}

.matchup-toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  align-self: end;
  color: var(--dark-slate);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.matchup-toggle[hidden] {
  display: none;
}

.matchup-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--stormy-teal);
  cursor: pointer;
}

.majority-line {
  stroke: var(--line-strong);
  stroke-width: 1.5;
}

.axis line,
.axis path {
  stroke: var(--line-strong);
  stroke-width: 1;
}

.trend {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
  transition: opacity 140ms ease, stroke-width 140ms ease;
}

.trend-band {
  opacity: 0.1;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.point {
  stroke: #ffffff;
  stroke-width: 1.6;
  transition: opacity 140ms ease, stroke-width 140ms ease;
}

.hit-trend {
  fill: none;
  stroke: rgba(0, 0, 0, 0.001);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 22;
  pointer-events: stroke;
}

.hit-point {
  fill: transparent;
  pointer-events: all;
}

.hover-dot {
  fill: var(--panel);
  stroke-width: 2.5;
  pointer-events: none;
}

.trend.is-hovered-series {
  opacity: 1;
  stroke-width: 4.2;
}

.point.is-hovered-series {
  opacity: 1;
  stroke-width: 2.2;
}

.trend-band.is-hovered-series {
  opacity: 0.14;
}

.trend.is-muted-series,
.point.is-muted-series,
.end-label.is-muted-series,
.label-leader.is-muted-series {
  opacity: 0.18;
}

.trend-band.is-muted-series {
  opacity: 0.025;
}

.end-label {
  font-size: 12.5px;
  font-weight: 680;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}

.label-leader {
  fill: none;
  stroke-width: 1;
  /* Trait plein : un pointillé de 2 px se lit mal sur les courtes amorces, et
     le trait continu suit mieux l'oeil quand l'étiquette a dû être décalée. */
  opacity: 0.45;
  pointer-events: none;
}

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(255, 253, 249, 0.97);
  padding: 10px 11px;
  pointer-events: none;
  font-size: 0.82rem;
}

.tooltip strong {
  display: block;
  margin-bottom: 2px;
}

.tooltip span {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

.legend-panel {
  padding: 18px 0 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 31px;
  border: 1px solid rgba(40, 61, 59, 0.34);
  border-bottom: 2px solid var(--tomato-jam);
  border-radius: 2px;
  background: rgba(255, 253, 249, 0.78);
  color: var(--dark-slate);
  padding: 5px 10px;
  cursor: pointer;
}

.legend-item:hover {
  background: rgba(237, 221, 212, 0.42);
  border-color: var(--stormy-teal);
}

.legend-item[aria-pressed="false"] {
  color: rgba(40, 61, 59, 0.58);
  border-color: rgba(119, 46, 37, 0.24);
  border-bottom-color: rgba(119, 46, 37, 0.24);
  background: rgba(237, 221, 212, 0.24);
  opacity: 1;
}

.swatch {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border-radius: 50%;
}

.legend-name {
  overflow-wrap: anywhere;
  font-size: 0.84rem;
  line-height: 1.1;
}

.comparison-panel {
  margin-top: 42px;
  border: 2px solid var(--chestnut);
  border-radius: 2px;
  background: var(--panel);
}

.comparison-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 28px 30px 0;
}

.comparison-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.action-button,
.icon-button {
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--dark-slate);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 680;
}

.action-button {
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

.action-button:hover,
.icon-button:hover {
  background: var(--stormy-teal);
}

.comparison-controls {
  display: grid;
  gap: 12px;
  padding: 22px 30px 0;
}

.comparison-row {
  display: grid;
  grid-template-columns: 13px minmax(126px, 0.42fr) minmax(210px, 1fr) 34px;
  gap: 12px;
  align-items: end;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(40, 61, 59, 0.12);
}

.comparison-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.comparison-swatch {
  width: 13px;
  height: 13px;
  margin-bottom: 14px;
  border-radius: 50%;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  max-width: 34px;
  height: 34px;
  min-height: 34px;
  max-height: 34px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button svg {
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  pointer-events: none;
}

.danger-icon-button {
  position: relative;
  align-self: end;
  justify-self: end;
  border-color: rgba(196, 69, 54, 0.64);
  background: rgba(196, 69, 54, 0.12);
  color: var(--tomato-jam);
}

.danger-icon-button:hover {
  border-color: var(--tomato-jam);
  background: var(--tomato-jam);
  color: #ffffff;
}

.comparison-chart-wrap {
  min-height: 500px;
}

.comparison-chart-wrap svg {
  height: 520px;
  min-height: 500px;
}

.comparison-modal[hidden] {
  display: none;
}

.comparison-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.comparison-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 61, 59, 0.46);
}

.comparison-modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 2px solid var(--dark-slate);
  border-radius: 2px;
  background: var(--panel);
  padding: 24px;
}

.comparison-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

.comparison-modal-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.comparison-modal-head .icon-button {
  flex: 0 0 34px;
}

.comparison-modal-tools {
  margin-bottom: 22px;
}

.comparison-modal-tools .time-control {
  width: min(100%, 280px);
}

.comparison-modal-card .comparison-controls {
  padding: 0;
}

.comparison-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.comparison-modal-actions .action-button {
  margin-top: 0;
}

.secondary-action {
  background: var(--panel);
  color: var(--dark-slate);
}

.secondary-action:hover {
  background: rgba(237, 221, 212, 0.42);
  color: var(--dark-slate);
}

.polls-table-panel {
  margin-top: 42px;
  border: 2px solid var(--stormy-teal);
  border-radius: 2px;
  background: var(--panel);
}

.polls-table-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px 28px;
  flex-wrap: wrap;
  padding: 28px 30px 0;
}

.polls-table-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.polls-table-tools {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}

.polls-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--dark-slate);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.polls-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--stormy-teal);
  cursor: pointer;
}

.polls-sort {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.polls-sort button {
  padding: 0 12px;
  white-space: nowrap;
}

.polls-table-wrap {
  margin-top: 20px;
  max-height: 70vh;
  overflow: auto;
}

.polls-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.82rem;
}

.polls-table th,
.polls-table td {
  border-bottom: 1px solid rgba(40, 61, 59, 0.12);
  white-space: nowrap;
}

.polls-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--soft);
  color: var(--dark-slate);
  font-weight: 700;
  text-align: center;
  padding: 9px 8px;
  border-bottom: 2px solid var(--line-strong);
  vertical-align: bottom;
}

.polls-th-meta {
  text-align: left !important;
}

.polls-th-candidate {
  font-weight: 650;
  min-width: 52px;
}

.polls-th-candidate span:last-child {
  display: block;
  line-height: 1.1;
}

.polls-th-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-bottom: 4px;
  border-radius: 50%;
}

.polls-table tbody td {
  padding: 7px 8px;
  vertical-align: middle;
}

.polls-table tbody tr.polls-poll-start td {
  border-top: 1px solid rgba(40, 61, 59, 0.16);
}

.polls-td-date {
  min-width: 118px;
}

.polls-date-label {
  display: block;
  font-weight: 650;
  color: var(--dark-slate);
}

.polls-source-link {
  display: inline-block;
  margin-top: 2px;
  color: var(--stormy-teal);
  font-size: 0.72rem;
  text-decoration: none;
}

.polls-source-link:hover {
  text-decoration: underline;
}

.polls-td-sondeur {
  font-weight: 600;
  color: var(--dark-slate);
}

.polls-td-sample {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.polls-td-score {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.polls-td-score.is-empty {
  color: var(--line);
}

.polls-td-score.is-rank-1 {
  font-weight: 750;
}

.polls-td-score.is-rank-2 {
  font-weight: 680;
}

@media (max-width: 860px) {
  .polls-table-head {
    padding: 18px 16px 0;
  }
}

@media (max-width: 1280px) {
  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .legend {
    flex-wrap: wrap;
  }
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 24px, 1360px);
    padding: 18px 0 24px;
  }

  .topbar,
  .chart-head,
  .comparison-head {
    display: block;
  }

  .topbar {
    margin-bottom: 22px;
  }

  .source {
    margin-top: 10px;
    text-align: left;
    white-space: normal;
  }

  .top-actions {
    justify-items: start;
    margin-top: 18px;
  }

  .election-control,
  .round-control {
    width: min(100%, 288px);
  }

  .filters-card {
    padding: 16px;
  }

  .chart-actions {
    width: min(100%, 320px);
    margin-top: 18px;
    padding-top: 0;
  }

  .action-button {
    margin-top: 16px;
  }

  .filters-head {
    display: block;
    margin-bottom: 15px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  svg {
    height: 560px;
  }

  .comparison-row {
    grid-template-columns: 13px minmax(100px, 0.48fr) minmax(170px, 1fr) 34px;
  }

  .comparison-modal-card {
    max-height: calc(100vh - 32px);
    padding: 18px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 2rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .scenario-notice {
    font-size: 0.82rem;
  }

  .chart-head {
    padding: 18px 16px 0;
  }

  .comparison-head,
  .comparison-controls {
    padding-left: 16px;
    padding-right: 16px;
  }

  .comparison-row {
    grid-template-columns: 13px minmax(0, 1fr) 34px;
  }

  .comparison-row .control:nth-of-type(2) {
    grid-column: 2 / 4;
  }

  .comparison-swatch {
    grid-row: 1 / 3;
  }

  .comparison-row > .icon-button {
    grid-column: 3;
    grid-row: 1;
  }

  .comparison-modal {
    padding: 12px;
  }

  .comparison-modal-head,
  .comparison-modal-actions {
    display: grid;
  }

  .comparison-modal-actions .action-button {
    width: 100%;
  }

  .chart-wrap {
    min-height: 500px;
  }

  svg {
    height: 500px;
    min-height: 500px;
  }

}
