/* ═══════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --c-bg: #fafaf8;
  --c-text: #1a1a1a;
  --c-muted: #666;
  --c-accent: #c0392b;
  --c-line: #e0ddd8;

  /* NEP classification colours */
  --c-dominant: #1a9850;
  --c-bipartidismo: #91cf60;
  --c-leve: #fee08b;
  --c-media: #fc8d59;
  --c-alta: #d73027;

  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', system-ui, sans-serif;

  --prose-max: 680px;
  --section-pad: clamp(0.7rem, 1vw, 1rem);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-serif);
  font-weight: 300;
  font-size: clamp(1rem, 1.1vw, 1.125rem);
  line-height: 1.75;
  color: var(--c-text);
  background: var(--c-bg);
}

@media (min-width: 768px) {
  body {
    font-size: clamp(1rem, 1.25vw, 1.25rem);
  }
}

/* ═══════════════════════════════════════════════════════
   HERO
═══════════════════════════════════════════════════════ */
#hero {
  position: relative;
  height: 100vh;
  min-height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0f1923;
}

#hero-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 60%, #1e3a5f 0%, #0f1923 70%);
  z-index: 0;
}

/* ── Hero animated map ─────────────────────────────── */
#hero-map-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#hero-map-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

@media (min-width: 1200px) {
  #hero-map-canvas {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #hero-map-canvas svg {
    width: auto !important;
    height: 100% !important;
    max-height: 85vh !important;
    max-width: 55vw !important;
  }
}

@keyframes hero-heat {
  0% {
    fill: #0c1820;
  }

  8% {
    fill: #1a9850;
  }

  26% {
    fill: #91cf60;
  }

  46% {
    fill: #fee08b;
  }

  64% {
    fill: #fc8d59;
  }

  80% {
    fill: #d73027;
  }

  91% {
    fill: #5c0f0f;
  }

  100% {
    fill: #0c1820;
  }
}

/* subtle grid pattern */
#hero-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .03) 1px, transparent 1px);
  background-size: 40px 40px;
}

#hero-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem;
  max-width: 800px;
}

.hero-kicker {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #fc8d59;
  margin-bottom: 1.25rem;
}

#hero-content h1 {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  font-weight: 900;
  line-height: 1.1;
  color: #fff;
  margin-bottom: 1.25rem;
}

.hero-sub {
  font-family: var(--font-serif);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  color: rgba(255, 255, 255, .65);
  max-width: 520px;
  margin: 0 auto 2.5rem;
}

.hero-scroll-hint {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, .4);
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(6px);
  }
}

/* ═══════════════════════════════════════════════════════
   PROSE SECTIONS
═══════════════════════════════════════════════════════ */
.prose-section {
  padding: var(--section-pad) 1.5rem;
}

.prose {
  max-width: var(--prose-max);
  margin: 0 auto;
}

.byline {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 400;
  font-style: italic;
  color: var(--c-muted);
  text-align: right;
  padding: 0.75rem 0;
  margin-bottom: 0.25rem !important;
}

.prose h2 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  color: var(--c-text);
}

.prose h3 {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  margin: 1rem 0 0.75rem;
}

.prose p {
  margin-bottom: 1.25rem;
  color: #333;
}

.article-section > h2 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  color: var(--c-text);
}

.prose strong {
  font-weight: 600;
  color: var(--c-text);
}

.prose em {
  font-style: italic;
}

.formula-box {
  background: #f0ede8;
  border-left: 3px solid var(--c-accent);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}

.formula {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 0.5rem !important;
}

.formula-note {
  font-size: 0.875rem;
  color: var(--c-muted);
  margin: 0 !important;
}

/* Classification table */
.classification-table {
  margin: 1.5rem 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--c-line);
}

.class-row {
  display: flex;
  align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--c-line);
  gap: 1rem;
}

.class-row:last-child {
  border-bottom: none;
}

.class-row::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.class-row.dominant::before {
  background: var(--c-dominant);
}

.class-row.bipartidismo::before {
  background: var(--c-bipartidismo);
}

.class-row.leve::before {
  background: var(--c-leve);
}

.class-row.media::before {
  background: var(--c-media);
}

.class-row.alta::before {
  background: var(--c-alta);
}

.class-label {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  flex: 1;
}

.class-range {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--c-muted);
}

.note {
  font-size: 0.8rem;
  color: var(--c-muted);
  border-top: 1px solid var(--c-line);
  padding-top: 1rem;
  margin-top: 2rem !important;
}

/* ═══════════════════════════════════════════════════════
   ARTICLE LAYOUT
═══════════════════════════════════════════════════════ */
.article-section {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.5rem clamp(0.75rem, 2vw, 1.5rem);
}

.prose-step {
  padding: clamp(1rem, 2.5vw, 2rem) 0 1.25rem;
}

.section-title-step {
  padding-top: clamp(1rem, 2vw, 1.75rem);
  padding-bottom: 0.5rem;
}

.prose-step h2 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.5rem;
  color: var(--c-text);
}

.prose-step h3 {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 0.65rem;
  color: var(--c-text);
}

.prose-step p {
  line-height: 1.75;
  color: #333;
}

.prose-step strong {
  font-weight: 600;
  color: var(--c-text);
}

.prose-step em {
  font-style: italic;
}

/* chart container */
.chart-block {
  width: 100%;
  height: clamp(380px, 56vh, 560px);
  margin: 0 0 0.5rem;
  position: relative;
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  overflow: hidden;

  /* entrance animation */
  opacity: 0;
  transform: translateY(36px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.chart-block.visible {
  opacity: 1;
  transform: translateY(0);
}

/* taller variant for 33-item ranking bars */
.chart-block.chart-tall {
  height: clamp(520px, 72vh, 680px);
}

/* taller variant for boxplots */
.chart-block.chart-box {
  height: clamp(480px, 65vh, 680px);
}

/* choropleth map — portrait, no border, no background */
.chart-block.chart-map {
  height: clamp(560px, 80vh, 740px);
  background: transparent;
  border: none;
  box-shadow: none;
}

.chart-inner {
  width: 100%;
  height: 100%;
}

/* ═══════════════════════════════════════════════════════
   TOOLTIP
═══════════════════════════════════════════════════════ */
.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 200px;
}

.chart-tooltip.visible {
  opacity: 1;
}

.tooltip-title {
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 0.2rem;
  color: var(--c-text);
}

.tooltip-row {
  color: var(--c-muted);
  font-size: 0.75rem;
}

.tooltip-row span {
  font-weight: 500;
  color: var(--c-text);
}

/* ═══════════════════════════════════════════════════════
   CHART ELEMENTS
═══════════════════════════════════════════════════════ */
.chart-title {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  fill: var(--c-muted);
}

.chart-label {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  fill: #666;
}

.axis-label {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  fill: #999;
}

.median-line {
  stroke: #000;
  stroke-width: 2;
  stroke-dasharray: 5, 3;
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff);
}

.median-label {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  fill: #000;
  stroke: #fff;
  stroke-width: 1.1px;
  paint-order: stroke fill;
  font-weight: 600;
}

/* waffle squares */
.waffle-cell {
  stroke: #fff;
  stroke-width: 1;
  transition: opacity 0.2s;
  cursor: default;
}

.waffle-cell:hover {
  stroke: #333;
  stroke-width: 1.5;
}

/* bar chart bars */
.bar-rect {
  transition: opacity 0.2s;
  cursor: default;
}

.bar-rect:hover {
  opacity: 0.8;
}

/* boxplot */
.box-whisker {
  stroke-width: 1.5;
  fill: none;
}

.box-rect {
  stroke-width: 1;
}

.box-median {
  stroke-width: 2;
}

.dot-point {
  cursor: default;
  transition: r 0.15s;
}

.dot-point:hover {
  r: 5;
}

/* ═══════════════════════════════════════════════════════
   LEGEND
═══════════════════════════════════════════════════════ */
.legend-item text {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  fill: #555;
}

/* ═══════════════════════════════════════════════════════
   NEP FORMULA & EXAMPLES
═══════════════════════════════════════════════════════ */
.formula-explanation {
  list-style: none;
  margin: 0.75rem 0 0 0;
  padding: 0;
  font-size: 0.875rem;
  color: var(--c-muted);
}

.formula-explanation li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.formula-explanation strong {
  color: var(--c-text);
  font-weight: 600;
}

h4 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem 0;
  color: var(--c-text);
}

.nep-example {
  background: #f9f7f5;
  border-left: 3px solid #91cf60;
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  font-family: var(--font-serif);
}

.nep-example p {
  margin-bottom: 0.5rem;
}

.nep-example p:first-child {
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 0.75rem;
}

.nep-example ul {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
}

.nep-example li {
  margin-bottom: 0.25rem;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  color: var(--c-text);
  line-height: 1.4;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
}

.nep-example strong {
  color: var(--c-accent);
  font-weight: 700;
}

.note {
  font-style: italic;
  color: var(--c-muted);
  font-size: 0.9375rem;
  margin-top: 0.75rem !important;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(192, 57, 43, 0.15);
}

/* ═══════════════════════════════════════════════════════
   FOOTER
═══════════════════════════════════════════════════════ */
#footer {
  text-align: center;
  padding: 2rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--c-muted);
  border-top: 1px solid var(--c-line);
  background: #f5f3f0;
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════ */

/* Desktop: charts expand 30% beyond text width */
@media (min-width: 768px) {
  .article-section {
    max-width: min(936px, 95vw);
  }

  .prose-step {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 480px) {
  .article-section {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .chart-block {
    height: clamp(320px, 52vh, 480px);
  }

  .chart-block.chart-tall {
    height: clamp(440px, 65vh, 580px);
  }

  .chart-block.chart-box {
    height: clamp(460px, 70vh, 620px);
  }

  .chart-block.chart-map {
    /* Full-bleed: stretch to viewport edges cancelling any parent padding */
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    border-radius: 0;
    /* Height follows the viewBox aspect ratio (560 × 642) */
    height: auto;
    aspect-ratio: 560 / 642;
  }
}