:root {
  --left: #ae374d;
  --right: #216a9d;
  --decrease: #b54141;
  --neutral: #f4e39a;
  --increase: #24734e;
}

.story-head, .identity, .author-mark, .project-wordmark { display: flex; align-items: center; }
.story-head { gap: 12px; }
.identity { column-gap: 9px; row-gap: 4px; flex-wrap: wrap; }
.author-mark, .project-wordmark { gap: 5px; text-decoration: none; }
.author-mark { color: var(--muted); font-size: 13px; font-weight: 600; }
.project-wordmark { font-weight: 700; }
.brand-divider { color: var(--line); }
.language button { cursor: pointer; }
.story-hero { padding: 72px 0 48px; }
.story-hero .dek { margin: 0 0 18px; }
.story-hero .date { margin: 16px 0 12px; }
.story-hero #original { font-size: 14px; }
.story-figure { margin: 0; }
.story-figure .map { height: min(64vh, 650px); min-height: 445px; }
.story-figure .map-legend { bottom: 12px; left: 12px; width: 225px; max-width: calc(100% - 66px); }
#map-status:empty { display: none; }
.gradient-labels { gap: 18px; }
.arrows-key { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.arrows-key b { font-size: 17px; }
.arrows-key small { flex-basis: 100%; color: var(--muted); }
.missing-key { display: flex; align-items: center; gap: 5px; margin-top: 7px; color: var(--muted); }
.missing-key i { background: #caccc4; width: 11px; height: 11px; }
.left { color: var(--left); }
.right { color: var(--right); }
.decrease { color: var(--decrease); }
.increase { color: var(--increase); }
.section-card { margin-top: 24px; background: var(--soft); border: 1px solid var(--line); padding: clamp(12px, 2.5vw, 28px); }
.card-title { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.card-title p, .card-note { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.card-title button { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; padding: 3px 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; }
thead th { white-space: nowrap; font: 600 12px var(--mono); }
thead button { border: 0; background: transparent; cursor: pointer; color: inherit; font: inherit; padding: 5px 0; }
thead button:hover { text-decoration: underline; }
thead th[aria-sort] button::after { content: " ↑"; }
thead th[aria-sort="descending"] button::after { content: " ↓"; }
.section-results { margin-top: 14px; }
.section-results td small { display: block; color: var(--muted); }
.section-results th, .section-results td { padding-block: 5px; }
.section-results tr.primary { font-weight: 650; }
.section-results tr.divider > * { border-top: 2px solid #bfc4bf; }

.scatter-controls { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 12px 20px; }
.scatter-controls .segmented { margin-bottom: 14px; }
.chart-head { align-items: baseline; }
.chart-head p { color: var(--muted); font: 12px var(--mono); margin: 0; }
.plot-frame { position: relative; }
#scatter { height: clamp(330px, 52vw, 500px); }
#plot-tooltip { position: absolute; top: 4px; right: 4px; pointer-events: none; background: var(--paper); padding: 5px 8px; border: 1px solid var(--line); font-size: 13px; }

.story-footer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; color: var(--muted); padding: 14px 0; font-size: 13px; }
.story-footer .author { font-weight: 700; color: var(--ink); }
.story-footer .credit { text-align: center; }
.story-footer .fbrand { display: flex; justify-content: flex-end; align-items: center; gap: 6px; color: var(--ink); font-weight: 700; text-decoration: none; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--right); outline-offset: 3px; }

@media (max-width: 760px) {
  .story-head { align-items: center; padding: 12px 0; }
  .project-wordmark { font-size: 13px; }
  .language { gap: 4px; }
  .language button { padding: 5px 8px; }
  .story-hero { padding: 54px 0 38px; }
  .story-figure .map { height: 57vh; min-height: 345px; }
  .section-results, #district-results { font-size: 13px; }
  .section-results th, .section-results td, #district-results th, #district-results td { padding-inline: 4px; }
  .section-results thead th, #district-results thead th { font-size: 10px; }
  .story-footer { grid-template-columns: auto 1fr; }
  .story-footer .credit { text-align: right; }
  .story-footer .fbrand { display: none; }
}

.story-head {
  position: sticky;
  top: 0;
  z-index: 950;
  width: 100%;
  min-height: 38px;
  padding: 3px max(12px, calc((100% - 1180px) / 2));
  background: var(--paper);
}
.story-head .identity { min-width: 0; flex-wrap: nowrap; }
.author-mark { flex: 0 0 auto; color: #646762; gap: 6px; white-space: nowrap; }
.author-mark img { width: 16px; height: 16px; }
.project-wordmark { min-width: 0; white-space: nowrap; font-size: 14px; }
.project-wordmark span { overflow: hidden; text-overflow: ellipsis; }
.project-wordmark img { flex: 0 0 auto; width: 18px; height: 18px; }
.story-head .language { gap: 4px; }
.story-head .language button { border: 0; background: none; color: var(--muted); padding: 3px 5px; font-size: 12px; }
.story-head .language button[aria-pressed="true"] { font-weight: 700; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.story-hero { padding-block: clamp(34px, 5vw, 61px) 22px; }
#ciudad, #mapa { padding-block: 29px; }
#ciudad .section-intro, #mapa .section-intro { margin-bottom: 15px; }
#ciudad h2, #mapa h2 { margin-block: 6px 8px; }
#swing-arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
#map-status { z-index: 35; }

.table-wrap table { font-size: 12px; }
.table-wrap th, .table-wrap td { padding: 4px 6px; line-height: 1.25; }
.table-wrap thead th, .table-wrap thead button { font-size: 11px; }
#district-results { max-width: 760px; }
.section-results td small { display: inline; font-size: .9em; margin-inline-start: 2px; }
.section-results td, .section-results th:not(:first-child) { white-space: nowrap; }
.cell-value { white-space: nowrap; }
.bloc-left { background: var(--left); }
.bloc-right { background: var(--right); }
.bloc-rest { background: #a9ada8; }
.madrid-key { margin-inline-start: 10px; font-weight: 700; color: var(--ink); white-space: nowrap; }
[data-dani-support] { width: min(1180px, calc(100% - 24px)); margin: 0 auto; }
#scatter-axis { display: flex; flex-wrap: wrap; border-radius: 18px; }

@media(max-width: 760px) {
  .story-head { min-height: 35px; }
  .author-mark { font-size: 11px; }
  .story-head .identity { column-gap: 4px; }
  .project-wordmark { font-size: 12px; }
  .project-wordmark img { width: 15px; height: 15px; }
  #ciudad, #mapa { padding-block: 23px; }
  #ciudad .section-intro, #mapa .section-intro { gap: 5px; margin-bottom: 11px; }
  .section-results td, .section-results th { font-size: 11px; }
  #scatter-axis button { flex: 1 1 47%; }
}

:root { --heading: #264d40; --intro-ink: #54665d; }
main::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: clamp(250px, 33vw, 430px);
  background: radial-gradient(ellipse at 16% 0%, #e8efe2, transparent 76%);
}
main { position: relative; isolation: isolate; }
.story-hero { padding-block: clamp(31px, 5vw, 54px) 24px; }
.story-hero h1 { font-size: clamp(44px, 6.2vw, 78px); color: var(--heading); margin: 14px 0; }
.story-hero .dek { font-size: clamp(18px, 2vw, 23px); line-height: 1.35; color: #4d6257; }
main > section { padding-block: clamp(20px, 3vw, 33px) clamp(25px, 3.5vw, 38px); }
main > section h2 {
  color: var(--heading); font-size: clamp(26px, 3.2vw, 39px);
  line-height: 1.12; margin: 0; text-wrap: balance;
}
main > section .section-intro {
  gap: clamp(8px, 2vw, 22px); margin: 0 0 15px;
  align-items: center; grid-template-columns: minmax(0, 1fr) minmax(0, 42%);
}
main > section .section-intro p { font-size: 13px; line-height: 1.48; color: var(--intro-ink); }
#ciudad, #mapa { padding-block: clamp(20px, 3vw, 29px); }
#ciudad h2, #mapa h2 { margin: 0; }
#metodo h2 { margin-bottom: 12px; }
.chart-head h3 { color: var(--heading); font-size: clamp(21px, 2.6vw, 27px); }

.city-overview { display: grid; grid-template-columns: minmax(0, 0.93fr) minmax(0, 1.12fr); gap: 18px; align-items: stretch; }
.city-gauges { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.city-gauge {
  --gauge-negative: #e3b7ac; --gauge-positive: #8cc0a5; --gauge-ink: #285f49;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 12px 7px; margin: 0;
  background: #e7efe6; border: 1px solid #d8e4da; border-radius: 8px;
}
.gauge-swing { --gauge-negative: #df9ba7; --gauge-positive: #95bbd6; --gauge-ink: #285d80; background: #eaf0f4; border-color: #dae4ea; }
.city-gauge figcaption { margin: 0 0 5px; color: var(--gauge-ink); font-size: 12px; font-weight: 650; }
.gauge-visual { position: relative; width: min(118px, 92%); aspect-ratio: 2 / 1; }
.gauge-arc { position: absolute; inset: 0; overflow: hidden; }
.gauge-arc::before {
  content: ""; display: block; width: 100%; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(from -90deg, var(--gauge-negative), #f4efe0 25%, var(--gauge-positive) 50%, transparent 0);
  mask-image: radial-gradient(circle, transparent 57%, #000 59%);
}
.gauge-needle {
  position: absolute; bottom: 0; left: calc(50% - 1px); height: 86%; width: 2px;
  border-radius: 2px; background: var(--gauge-ink); transform-origin: center bottom; transform: rotate(var(--angle));
}
.gauge-hub { position: absolute; bottom: -3px; left: calc(50% - 3px); width: 6px; height: 6px; border-radius: 50%; background: var(--gauge-ink); }
.gauge-ticks { display: flex; justify-content: space-between; width: min(124px, 96%); margin-top: 4px; font: 9px var(--mono); color: var(--intro-ink); }
.city-gauge strong { font: 650 clamp(20px, 2.6vw, 28px) var(--mono); letter-spacing: -.06em; color: var(--gauge-ink); margin-top: 4px; }
.city-gauge p { font-size: 11px; margin: 2px 0; color: var(--intro-ink); white-space: nowrap; }
.constituency-chart { padding: 11px 13px 9px; border: 1px solid #e0e4dc; background: #f0f2eb; border-radius: 8px; }
.constituency-chart h3 { color: var(--heading); font: 650 13px var(--body); margin-bottom: 3px; letter-spacing: 0; }
.constituency-legend { display: flex; justify-content: space-between; margin-left: 56px; font: 9px var(--mono); text-transform: uppercase; color: #526359; }
.constituency-row { display: grid; grid-template-columns: 50px minmax(0, 1fr) 121px; align-items: center; gap: 6px; margin-block: 4px; font: 11px var(--body); }
.constituency-row > strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.constituency-vote { display: grid; grid-template-columns: minmax(30px, 1fr) 46px; gap: 4px; align-items: center; text-align: right; font: 10px var(--mono); white-space: nowrap; }
.constituency-track { background: #dde4dc; height: 7px; border-radius: 2px; overflow: hidden; }
.constituency-track i { display: block; height: 100%; border-radius: inherit; background: var(--party-color); }
.seat-group, .seat-dots { display: flex; align-items: center; justify-content: flex-end; }
.seat-group { gap: 4px; }
.seat-dots { gap: 1px; }
.seat-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--party-color); }
.seat-count { font: 10px var(--mono); color: #475a50; }

.section-results { table-layout: fixed; }
.section-results th:first-child { width: 31%; }
.section-results th:last-child { width: 19%; }
.party-cell { display: grid; grid-template-columns: min(42%, 95px) minmax(0, 1fr); gap: 5px; align-items: center; }
.party-bar-mini { display: block; max-width: 95px; width: 100%; height: 4px; background: #d9ddd7; }
.party-bar-mini i { display: block; background: var(--bar-color); width: var(--share); height: 100%; }
.section-results td small.increase { color: var(--increase); }
.section-results td small.decrease { color: var(--decrease); }
.bloc-bars { max-width: 780px; font: 11px var(--mono); margin: 12px 0; }
.bloc-bar-legend { display: flex; justify-content: space-between; margin: 0 0 3px 70px; }
.bloc-row { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 8px; align-items: center; margin-block: 4px; }
.bloc-track { display: flex; width: 100%; height: 20px; border-radius: 3px; overflow: hidden; color: #fff; font-size: 10px; font-weight: 600; }
.bloc-track > span { display: flex; align-items: center; min-width: 0; overflow: hidden; white-space: nowrap; }
.bloc-track .bloc-left { justify-content: flex-start; text-indent: 5px; }
.bloc-track .bloc-right { justify-content: flex-end; padding-inline-end: 5px; }

#district-results { max-width: 820px; }
#district-results .distribution-col { text-align: center; width: clamp(90px, 22vw, 220px); }
.district-box { position: relative; display: block; height: 14px; margin-inline: 3px; color: #376d5b; }
.district-box i { position: absolute; display: block; }
.box-zero { top: 0; height: 14px; left: 50%; border-left: 1px dashed #a0aca3; }
.box-range { left: var(--min); width: calc(var(--max) - var(--min)); top: 6px; height: 1px; background: currentColor; }
.box-range::before, .box-range::after { content: ""; position: absolute; top: -2px; height: 5px; width: 1px; background: currentColor; }
.box-range::before { left: 0; }
.box-range::after { right: 0; }
.box-middle { top: 3px; left: var(--q1); width: calc(var(--q3) - var(--q1)); height: 8px; background: #cbded2; border: 1px solid currentColor; }
.box-median { top: 3px; height: 8px; left: var(--median); width: 1px; background: currentColor; }
.distribution-note { font-size: 11px; color: var(--intro-ink); max-width: 820px; margin: 7px 0; }
.district-toggle { width: 100%; max-width: 820px; border: 1px solid #c9d7cd; border-radius: 4px; text-align: center;
  padding: 7px 10px; background: #e9efe8; color: #275443; font-size: 12px; font-weight: 650; cursor: pointer; }
.district-toggle:hover { background: #dae8dc; }

@media(max-width: 760px) {
  main > section .section-intro { grid-template-columns: 1fr; gap: 6px; }
  .city-overview { grid-template-columns: 1fr; gap: 9px; }
  .constituency-row { grid-template-columns: 42px minmax(0, 1fr) 113px; }
  .constituency-legend { margin-left: 48px; }
  .city-gauge { padding: 8px 4px; }
  .party-cell { grid-template-columns: 1fr; gap: 2px; text-align: right; }
  .party-bar-mini { height: 3px; max-width: none; }
  .bloc-row { gap: 5px; grid-template-columns: 52px minmax(0, 1fr); }
  .bloc-bar-legend { margin-left: 57px; }
  .section-results th:first-child { width: 29%; }
  .section-results th:last-child { width: 23%; }
  #district-results th, #district-results td { font-size: 10px; padding-inline: 3px; }
  #district-results thead button, #district-results thead th { font-size: 9px; }
  #district-results td:not(:first-child) { white-space: nowrap; }
}
