:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --ink: #242424;
  --muted: #68625a;
  --line: #d8d0c5;
  --ae: rgb(206, 116, 42);
  --icc: rgb(140, 55, 140);
  --sfv: rgb(241, 172, 34);
  --pvl: rgb(75, 175, 231);
  --missing: #c94343;
  --panel: #fffaf3;
  --font-ui: "Source Sans 3", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-editorial: "Newsreader", Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

.app-shell {
  width: min(1480px, calc(100vw - 18px));
  margin: 0 auto;
  padding: 9px 0;
}

.story-layout {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.story-panel {
  position: sticky;
  top: 9px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 18px);
}

.content-panel {
  min-width: 0;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: flex-start;
  gap: 24px;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--font-editorial);
  font-size: clamp(1.85rem, 2.4vw, 2.65rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.intro-copy {
  max-width: 34rem;
  margin: 16px 0 0;
  color: #464039;
  font-family: var(--font-editorial);
  font-size: clamp(1rem, 1.3vw, 1.12rem);
  font-weight: 500;
  line-height: 1.48;
}

.intro-copy p {
  margin: 0;
}

.intro-copy p + p {
  margin-top: 10px;
}

.intro-copy-mobile {
  display: none;
}

.credit-note {
  max-width: 34rem;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.38;
}

.credit-note a {
  color: var(--ink);
  text-decoration-color: rgba(36, 36, 36, 0.32);
  text-underline-offset: 3px;
}

.credit-note a:hover {
  text-decoration-color: var(--ink);
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.map-toolbar {
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
  justify-content: start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(216, 208, 197, 0.78);
  background: rgba(255, 250, 243, 0.94);
}

.map-legends {
  position: absolute;
  top: auto;
  left: 14px;
  bottom: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px 14px;
  min-width: 0;
  max-width: calc(100% - 28px);
  pointer-events: none;
}

.map-canvas {
  position: relative;
}

.map-legend {
  flex-wrap: wrap;
  justify-content: flex-start;
  min-width: 0;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.legend i {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
}

.legend .ae {
  background: var(--ae);
}

.legend .icc {
  background: var(--icc);
}

.legend .sfv {
  background: var(--sfv);
}

.legend .pvl {
  background: var(--pvl);
}

.page-tabs {
  display: flex;
  gap: 4px;
  margin-top: 18px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 243, 0.72);
}

.round-tabs {
  display: flex;
  gap: 0;
  margin-top: 8px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.52);
}

.page-tab {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.round-tab {
  flex: 1;
  min-width: 0;
  min-height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.05;
  cursor: pointer;
}

.page-tab:hover {
  background: rgba(36, 36, 36, 0.06);
  color: var(--ink);
}

.round-tab:hover {
  background: rgba(36, 36, 36, 0.06);
  color: var(--ink);
}

.page-tab.is-active {
  border-color: rgba(36, 36, 36, 0.16);
  background: var(--ink);
  color: var(--panel);
}

.round-tab.is-active {
  background: var(--ink);
  color: var(--panel);
}

.page-tab:focus-visible {
  outline: 2px solid rgba(75, 175, 231, 0.85);
  outline-offset: 2px;
}

.round-tab:focus-visible {
  outline: 2px solid rgba(75, 175, 231, 0.85);
  outline-offset: 2px;
}

.tab-panel[hidden] {
  display: none;
}

.round-placeholder {
  display: none;
}

.content-panel.is-second-round .map-toolbar,
.content-panel.is-second-round .map-canvas,
.content-panel.is-second-round .status,
.content-panel.is-second-round .resources-header,
.content-panel.is-second-round .resource-list {
  display: none;
}

.content-panel.is-second-round .round-placeholder {
  display: flex;
  min-height: min(88vh, 740px);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}

.round-placeholder p {
  margin: 0;
  color: var(--muted);
  font-size: 0.5rem;
  font-weight: 800;
  text-transform: uppercase;
}

.round-placeholder strong {
  color: var(--ink);
  font-family: var(--font-editorial);
  font-size: 3rem;
  line-height: 0.9;
}

.visualization {
  position: relative;
  margin-top: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.chart {
  width: 100%;
  height: min(88vh, 980px);
  min-height: 0;
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.chart svg:active {
  cursor: grabbing;
}

.map-controls {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.view-mode {
  display: inline-flex;
  align-items: stretch;
  gap: 10px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.view-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.view-group legend,
.map-controls legend {
  display: block;
  margin: 0 0 5px;
  padding: 0;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.05;
  text-transform: uppercase;
  white-space: nowrap;
}

.view-options,
.zoom-options {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid rgba(36, 36, 36, 0.1);
  border-radius: 7px;
  background: rgba(255, 250, 243, 0.62);
}

.zoom-options button,
.view-mode button {
  min-width: 34px;
  height: 32px;
  border: 1px solid rgba(36, 36, 36, 0.16);
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.view-mode button {
  min-width: 82px;
  padding: 0 12px;
  color: var(--muted);
}

.zoom-options button:hover,
.view-mode button:hover {
  background: #f0e6d8;
}

.view-mode button.is-active {
  background: #242424;
  border-color: #242424;
  color: #fffaf3;
}

.zoom-options button:focus-visible,
.view-mode button:focus-visible {
  outline: 2px solid rgba(75, 175, 231, 0.85);
  outline-offset: 2px;
}

.municipality {
  stroke: #fffaf3;
  stroke-width: 0;
  vector-effect: non-scaling-stroke;
}

.municipality.is-hovered {
  stroke: #171411;
  stroke-width: 1.2;
}

.municipality-boundary {
  fill: none;
  stroke: rgba(255, 250, 243, 0.7);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.department-boundary {
  fill: none;
  stroke: rgb(23, 20, 17);
  stroke-opacity: 1;
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.country-boundary {
  fill: none;
  stroke: #171411;
  stroke-linejoin: round;
  stroke-opacity: 0.95;
  stroke-width: 1.55;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.population-circle-layer {
  pointer-events: auto;
}

.population-circle {
  vector-effect: non-scaling-stroke;
}

.circle-size-legend {
  position: absolute;
  top: auto;
  right: auto;
  bottom: 42px;
  left: 14px;
  z-index: 2;
  display: none;
  align-items: end;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(340px, calc(100% - 28px));
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(255, 250, 243, 0.9);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}

.circle-size-legend.is-visible {
  display: inline-flex;
}

.circle-size-legend-title {
  flex: 0 0 100%;
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.circle-size-item {
  display: inline-grid;
  justify-items: center;
  align-items: end;
  gap: 3px;
}

.circle-size-shape {
  display: block;
  border: 1px solid rgba(36, 36, 36, 0.42);
  border-radius: 999px;
}

.circle-size-label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.map-tooltip {
  position: absolute;
  z-index: 3;
  width: min(285px, calc(100% - 24px));
  padding: 12px 34px 12px 13px;
  border: 1px solid rgba(36, 36, 36, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 243, 0.96);
  box-shadow: 0 18px 44px rgba(36, 36, 36, 0.18);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.map-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.map-tooltip.is-pinned {
  pointer-events: auto;
}

.map-tooltip.is-compact {
  width: min(220px, calc(100% - 24px));
  padding: 10px 31px 10px 11px;
}

.map-tooltip.is-compact .tooltip-title {
  font-size: 0.94rem;
}

.map-tooltip.is-compact .tooltip-winner {
  margin-top: 7px;
}

.map-tooltip.is-compact .tooltip-label {
  display: none;
}

.tooltip-close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: rgba(36, 36, 36, 0.08);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.tooltip-close:hover {
  background: rgba(36, 36, 36, 0.14);
}

.tooltip-kicker {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tooltip-title {
  margin-top: 2px;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.18;
}

.tooltip-winner {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 9px;
  color: #39342e;
  font-size: 0.86rem;
  line-height: 1.25;
}

.tooltip-swatch {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(36, 36, 36, 0.15);
  margin-top: 3px;
}

.tooltip-label {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.1;
}

.tooltip-winner strong {
  display: inline;
  font-size: 0.9rem;
  line-height: 1.2;
}

.tooltip-code {
  display: inline-block;
  margin-left: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.tooltip-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 11px 0 0;
  padding-top: 10px;
  border-top: 1px solid rgba(36, 36, 36, 0.12);
}

.tooltip-stats div {
  min-width: 0;
}

.tooltip-stats dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.1;
}

.tooltip-stats dd {
  margin: 4px 0 0;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.1;
}

.status {
  position: absolute;
  right: 14px;
  bottom: 12px;
  margin: 0;
  width: min(420px, calc(100% - 36px));
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.25;
  text-align: right;
}

.resources-panel {
  margin-top: 0;
  min-height: calc(100vh - 56px);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.resources-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.resources-header h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.resource-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.resource-card {
  min-height: 190px;
  padding: 14px;
  border: 1px solid rgba(36, 36, 36, 0.12);
  border-radius: 8px;
  background: #fffaf3;
}

.resource-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.resource-card p {
  margin: 9px 0 14px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.resource-card a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  text-decoration: none;
}

.resource-download {
  padding: 0 11px;
  border: 1px solid rgba(36, 36, 36, 0.16);
  background: var(--ink);
  color: var(--panel) !important;
}

.resource-download:hover {
  background: #3a332c;
}

.resource-source {
  display: flex !important;
  width: fit-content;
  margin-top: 8px;
  color: var(--muted) !important;
  font-weight: 700 !important;
}

.resource-source:hover {
  color: var(--ink) !important;
  text-decoration: underline;
}

.resource-card:hover {
  border-color: rgba(36, 36, 36, 0.24);
  background: #f0e6d8;
}

.resource-card a:focus-visible {
  outline: 2px solid rgba(75, 175, 231, 0.85);
  outline-offset: 2px;
}

@media (max-width: 980px) {
  .story-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .story-panel {
    display: block;
    min-height: 0;
    position: static;
  }

  .app-header {
    padding-top: 0;
  }

  .intro-copy {
    max-width: 760px;
  }

  .visualization,
  .resources-panel {
    min-height: auto;
  }

  .map-toolbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .map-legends {
    justify-content: flex-start;
  }

  .legend-item-sfv,
  .legend-item-pvl,
  .status {
    display: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100vw - 12px);
    padding: 8px 0;
  }

  .story-panel {
    position: relative;
  }

  .app-header {
    align-items: start;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 0;
  }

  .eyebrow {
    margin-bottom: 7px;
    font-size: 0.72rem;
  }

  h1 {
    max-width: calc(100% - 150px);
    font-size: clamp(1.72rem, 8vw, 2.25rem);
    line-height: 1.02;
  }

  .mobile-title-break {
    display: block;
  }

  .intro-copy {
    margin-top: 12px;
    font-size: 0.98rem;
    line-height: 1.36;
  }

  .intro-copy-desktop {
    display: none;
  }

  .intro-copy-mobile {
    display: block;
  }

  .intro-copy p + p {
    margin-top: 10px;
  }

  .credit-note {
    margin-top: 12px;
    font-size: 0.76rem;
    line-height: 1.32;
  }

  .legend {
    justify-content: flex-start;
  }

  .map-legend {
    font-size: 0.8rem;
    justify-content: center;
  }

  .page-tabs {
    position: absolute;
    top: 0;
    right: 0;
    display: inline-flex;
    width: auto;
    margin: 0;
    padding: 2px;
    border: 1px solid rgba(36, 36, 36, 0.12);
    border-radius: 999px;
    background: rgba(255, 250, 243, 0.82);
  }

  .page-tab {
    flex: 0 0 auto;
    min-width: 0;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    border: 0;
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
  }

  .page-tab.is-active {
    background: var(--ink);
    color: var(--panel);
  }

  .round-tabs {
    width: max-content;
    max-width: 100%;
    margin: 8px 0 2px auto;
    padding: 2px;
    border-radius: 999px;
    background: rgba(255, 250, 243, 0.66);
  }

  .round-tab {
    flex: 0 0 auto;
    min-width: 66px;
    min-height: 24px;
    padding: 0 8px;
    border: 0;
    border-radius: 999px;
    font-size: 0.66rem;
    white-space: nowrap;
  }

  .round-tab.is-active {
    background: var(--ink);
    color: var(--panel);
  }

  .content-panel.is-second-round .round-placeholder {
    min-height: 62vh;
    padding: 32px 18px;
  }

  .visualization {
    min-height: auto;
  }

  .map-toolbar {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    pointer-events: none;
  }

  .map-toolbar > * {
    pointer-events: auto;
  }

  .map-legends {
    position: absolute;
    top: auto;
    left: 50%;
    bottom: 34px;
    justify-content: center;
    width: max-content;
    max-width: calc(100% - 24px);
    transform: translateX(-50%);
  }

  .circle-size-legend {
    top: auto;
    right: auto;
    bottom: 60px;
    left: 50%;
    align-items: end;
    justify-content: center;
    max-width: min(280px, calc(100% - 24px));
    padding: 5px 6px;
    gap: 5px;
    background: rgba(255, 250, 243, 0.86);
    font-size: 0.62rem;
    transform: translateX(-50%);
  }

  .circle-size-legend.is-visible {
    display: inline-flex !important;
  }

  .circle-size-legend-title {
    width: 100%;
    margin-right: 0;
    font-size: 0.62rem;
    text-align: center;
  }

  .circle-size-item {
    gap: 2px;
  }

  .circle-size-label {
    font-size: 0.58rem;
  }

  .status {
    z-index: 2;
    display: block;
    right: auto;
    left: 50%;
    bottom: 10px;
    width: calc(100% - 24px);
    font-size: 0.62rem;
    line-height: 1.12;
    text-align: center;
    transform: translateX(-50%);
  }

  .chart {
    height: 62vh;
    min-height: 0;
  }

  .map-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    left: auto;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .map-controls legend {
    display: none;
  }

  .zoom-options {
    display: inline-flex;
    gap: 3px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .zoom-options button,
  .view-mode button {
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .zoom-options button {
    min-width: 24px;
    height: 24px;
    padding: 0 5px;
    font-size: 0.68rem;
  }

  .view-mode {
    position: absolute;
    top: 10px;
    right: auto;
    bottom: auto;
    left: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(250px, calc(100% - 94px));
    gap: 5px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
  }

  .view-mode button {
    flex: 1;
    min-width: 0;
    height: 23px;
    padding: 0 3px;
    font-size: 0.56rem;
  }

  .view-group {
    min-width: 0;
  }

  .view-group legend {
    margin-bottom: 2px;
    font-size: 0.48rem;
    text-align: left;
  }

  .view-options {
    display: flex;
    gap: 1px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .view-mode button.is-active {
    background: var(--ink);
    color: var(--panel);
  }

  .resources-panel {
    padding: 18px;
  }

  .resources-header {
    align-items: start;
    flex-direction: column;
    gap: 4px;
  }
}
