@font-face {
  font-family: 'Instrument Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../src/fonts/instrument-sans-latin.woff2') format('woff2');
}

@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../src/fonts/cormorant-garamond-latin.woff2') format('woff2');
}

/* CSS custom properties are injected at runtime from src/theme.js (single source of truth). */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(74, 123, 167, 0.14), transparent 28%),
    linear-gradient(180deg, #fbfcf9 0%, var(--paper) 32%, #fefefc 100%);
}

.page-shell {
  width: min(1440px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.hero {
  padding: 2rem 1.5rem 2.5rem;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 0.8rem;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: #4f6f53;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: var(--font-serif);
  max-width: 12ch;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.96;
  font-weight: 500;
}

.intro {
  max-width: 70ch;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.story-grid {
  display: grid;
  gap: 2rem;
  margin-top: 2rem;
}

.chapter-block {
  display: grid;
  gap: 1.5rem;
  padding: 0.25rem 0 0.5rem;
}

.chapter-block + .chapter-block {
  padding-top: 3rem;
}

.chapter-header {
  display: grid;
  gap: 0.5rem;
  padding: 0 1.5rem 0.8rem;
}

.chapter-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.45rem, 2vw, 2.2rem);
  line-height: 1.05;
  font-weight: 700;
}

.chapter-intro {
  max-width: 78ch;
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

.chapter-body {
  display: grid;
  gap: 1.25rem;
}

.chapter-body-tight {
  gap: 1rem;
}

.chapter-bridge,
.chapter-outro {
  max-width: 78ch;
  padding: 0.35rem 1.5rem 0.2rem;
}

.chapter-header {
  max-width: 78ch;
}

.chapter-bridge p,
.chapter-outro p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.chapter-outro {
  display: grid;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

.references-block {
  padding-bottom: 0;
}

.references-root {
  display: grid;
  gap: 1.5rem;
  padding: 0 1.5rem;
}

.references-loading {
  color: var(--muted);
}

.references-source {
  display: grid;
  gap: 1rem;
  min-width: 0;
  padding: 1.35rem 1.5rem 1.5rem;
  border: 1px solid rgba(214, 221, 211, 0.84);
  border-radius: 28px;
  background: rgba(248, 251, 246, 0.88);
  box-shadow: var(--shadow);
}

.references-source-title {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 600;
}

.references-file-group {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
}

.references-file-title {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.references-file-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.references-file-item {
  color: var(--muted);
  line-height: 1.55;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.references-file-item-dataset {
  list-style: none;
}

.references-link {
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-decoration-color: rgba(76, 112, 82, 0.26);
  text-underline-offset: 0.16em;
}

.references-link-dataset {
  display: inline;
  gap: 0.55rem;
  text-decoration: none;
}

.references-link-label {
  text-decoration: underline;
  text-decoration-color: rgba(76, 112, 82, 0.26);
  text-underline-offset: 0.16em;
}

.references-link-chip {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.45rem;
  padding: 0.14rem 0.45rem;
  border: 1px solid rgba(76, 112, 82, 0.2);
  border-radius: 999px;
  background: rgba(92, 126, 95, 0.1);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
}

.references-link:hover {
  text-decoration-color: rgba(76, 112, 82, 0.58);
}

.references-link-dataset:hover .references-link-label {
  text-decoration-color: rgba(76, 112, 82, 0.58);
}

.chart-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: start;
  padding: 1.35rem 1.5rem 1.5rem;
  border: 1px solid rgba(214, 221, 211, 0.84);
  border-radius: 28px;
  background: rgba(254, 255, 252, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.compact-two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-two-up-aligned {
  align-items: start;
}

.chart-package,
.chart-followup {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.chart-heading {
  display: flex;
  flex-direction: column;
}

.chart-package {
  gap: 0.55rem;
}

.chart-followup {
  gap: 0.75rem;
}

.compact-two-up-aligned .chart-stage {
  flex: 1 1 auto;
}

.compact-two-up-aligned .chart-frame {
  min-height: 360px;
}

.section-copy {
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.section-copy-wide {
  max-width: none;
}

.section-subtitle {
  max-width: 82rem;
  font-size: 1.08rem;
}

h2 {
  font-family: var(--font-sans);
  font-size: 1.2rem;
  font-weight: 400;
  margin-bottom: 0.55rem;
}

.chart-section p {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 1rem;
}

.chart-note {
  font-family: var(--font-sans);
  font-size: 0.83rem;
  color: var(--muted);
}

.chart-legend {
  font-family: var(--font-sans);
  display: grid;
  gap: 0.45rem;
  margin: 0 0 1rem;
  font-size: 0.83rem;
  color: var(--muted);
}

.chart-legend-featured {
  margin: 0;
}

.chart-legend.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.legend-swatch {
  display: inline-block;
  flex: 0 0 auto;
}

.legend-swatch.line {
  width: 1.1rem;
  height: 0;
  border-top: 2px solid currentColor;
}

.legend-swatch.dashed {
  border-top-style: dashed;
}

.legend-swatch.dot {
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 999px;
  background: currentColor;
}

.legend-swatch.area {
  width: 0.9rem;
  height: 0.7rem;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.88;
}

.legend-swatch.public-dark {
  color: var(--public-dark);
}

.legend-swatch.public-light {
  color: var(--public-light);
}

.legend-swatch.tinta {
  color: var(--ink);
}

.legend-swatch.private-dark {
  color: var(--private-dark);
}

.legend-swatch.private-light {
  color: var(--private-light);
}

.legend-swatch.private-soft {
  color: var(--private-soft);
}

.legend-swatch.agreement-dark {
  color: #d32f2f;
}

.legend-swatch.agreement-light {
  color: #c4756b;
}

.legend-swatch.personal-real {
  color: #4a7ba7;
}

.legend-swatch.personal-estimated {
  color: #7fb0d8;
}

.legend-swatch.accent {
  color: var(--accent);
}

.legend-swatch.agreement-band {
  color: #c4756b;
  background: rgba(196, 117, 107, 0.16);
  border: 1px solid rgba(196, 117, 107, 0.34);
}

.legend-swatch.personal-band {
  color: var(--public-light);
  background: rgba(74, 123, 167, 0.15);
  border: 1px solid rgba(74, 123, 167, 0.34);
}

.chart-frame {
  width: 100%;
  min-height: 280px;
}

.chart-frame-featured {
  min-height: 0;
}

.chart-stage {
  position: relative;
  width: 100%;
  padding-top: 0;
  display: flex;
  flex-direction: column;
}

.chart-stage-featured .chart-legend-featured {
  position: absolute;
  right: 1.9rem;
  bottom: 3.4rem;
  z-index: 2;
  align-self: flex-end;
  margin-top: 0;
  padding: 0.65rem 0.8rem;
  border-radius: 14px;
  background: rgba(251, 253, 248, 0.96);
  box-shadow: 0 8px 24px rgba(58, 88, 62, 0.1);
  text-align: left;
}

.chart-header-split {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  width: 100%;
}

.chart-header-split .section-copy {
  flex: 1 1 auto;
}

.chart-legend-external {
  position: static;
  flex: 0 0 auto;
  align-self: flex-end;
  margin: 0;
  padding: 0.65rem 0.8rem;
  border-radius: 14px;
  background: rgba(251, 253, 248, 0.96);
  box-shadow: 0 8px 24px rgba(58, 88, 62, 0.1);
  text-align: left;
}

.chart-stage-featured {
  min-height: auto;
}

.chart-section-scrolly .chart-stage {
  margin-bottom: 0;
}

.chart-stage-compact {
  min-height: 360px;
}

.chart-section > * {
  width: 100%;
}

.chart-frame svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-frame path,
.chart-frame circle,
.chart-frame line,
.chart-frame text {
  transition: opacity 160ms ease, transform 160ms ease;
}

.annotations-container {
  display: grid;
  gap: 0.75rem;
}

.annotations-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 0;
  width: 100%;
}

.annotations-grid-featured {
  flex-wrap: nowrap;
  align-items: stretch;
}

.annotations-grid-compact {
  flex-wrap: wrap;
}

.chart-meta {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0;
  width: 100%;
}

.chart-section-scrolly .chart-meta {
  max-width: none;
}

.chart-sources {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.annotation-card,
.annotation-disclosure,
.poster-annotation {
  font-family: var(--font-sans);
  border-left: 3px solid #6f9270;
  background: rgba(246, 250, 243, 0.96);
  padding: 0.9rem 1rem;
  box-shadow: 0 8px 24px rgba(76, 112, 82, 0.12);
}

.annotation-card {
  display: flex;
  flex-direction: column;
  min-height: auto;
  cursor: pointer;
  opacity: 0.72;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  flex: 1 1 0;
}

.annotation-card:hover {
  opacity: 0.92;
  border-left-color: #5f845f;
  box-shadow: 0 12px 32px rgba(76, 112, 82, 0.16);
}

.annotation-card.is-active {
  opacity: 1;
  transform: translateY(0);
  border-left-color: var(--public-dark);
  box-shadow: 0 18px 40px rgba(58, 88, 62, 0.16);
}

.hover-hint {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: auto;
  padding-top: 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
  justify-content: flex-end;
  pointer-events: none;
}

.hover-hint-icon {
  flex-shrink: 0;
}

.swipe-hint {
  display: none;
}

.annotation-kicker,
.annotation-year {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  justify-content: center;
  min-width: 3.2rem;
  margin-bottom: 0.45rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  background: rgba(92, 126, 95, 0.14);
  color: #587a5a;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.annotation-card h3,
.annotation-disclosure summary,
.poster-annotation strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.annotation-card p,
.annotation-disclosure p,
.poster-annotation p {
  margin: 0;
  font-size: 0.88rem;
}

.annotation-disclosure summary {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  list-style: none;
  cursor: pointer;
}

.annotation-summary-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.annotation-toggle {
  flex: 0 0 auto;
  margin-top: 0.1rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(92, 126, 95, 0.28);
  color: #587a5a;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.annotation-disclosure summary::-webkit-details-marker {
  display: none;
}

.annotation-disclosure[open] {
  border-left-color: var(--public-light);
}

.annotation-disclosure[open] .annotation-toggle {
  background: rgba(92, 126, 95, 0.12);
  border-color: rgba(92, 126, 95, 0.3);
  color: #587a5a;
}

.annotation-disclosure[open] .annotation-toggle::before {
  content: 'Cerrar';
}

.annotation-disclosure[open] .annotation-toggle {
  font-size: 0;
}

.annotation-disclosure[open] .annotation-toggle::before {
  font-size: 0.72rem;
}

.annotation-disclosure .annotation-year {
  margin-bottom: 0;
}

.annotation-panel {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(92, 126, 95, 0.18);
}

.tooltip {
  position: fixed;
  font-family: var(--font-sans);
  min-width: 180px;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  background: rgba(251, 253, 249, 0.97);
  box-shadow: 0 14px 35px rgba(58, 88, 62, 0.14);
  pointer-events: none;
  z-index: 10;
}

.tooltip .tooltip-year {
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.tooltip div + div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.tooltip strong {
  color: var(--ink);
}

@media (min-width: 901px) {
  .compact-two-up-aligned {
    align-items: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto;
    column-gap: 1.5rem;
    row-gap: 0.45rem;
  }

  .compact-two-up-aligned .chart-package {
    display: grid;
    grid-template-rows: minmax(0, auto) minmax(0, 1fr);
    height: 100%;
  }

  .compact-two-up-aligned .chart-heading {
    align-self: start;
  }

  .compact-two-up-aligned > .chart-package:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
  }

  .compact-two-up-aligned > .chart-package:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
  }

  .compact-two-up-aligned > .chart-followup:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
  }

  .compact-two-up-aligned > .chart-followup:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
  }

  .compact-two-up-aligned .chart-stage {
    flex: 1 1 auto;
  }

  .compact-two-up-aligned .chart-stage-compact {
    min-height: 360px;
  }

  .chart-section-scrolly .section-copy {
    max-width: min(40%, 36rem);
  }

  .compact-two-up .chart-heading {
    max-width: min(40vw, 36rem);
  }

  .chapter-header,
  .chapter-bridge,
  .chapter-outro {
    max-width: 66ch;
  }

  .chapter-header {
    padding-bottom: 0.8rem;
  }

  .chapter-bridge,
  .chapter-outro {
    padding-top: 0.35rem;
  }

  h2 {
    font-size: 1.28rem;
  }

  .section-subtitle,
  .chart-section p {
    font-size: 1.02rem;
  }

  .chart-legend {
    font-size: 0.9rem;
  }

  .chart-note,
  .chart-sources {
    font-size: 0.92rem;
  }
}

.error-banner {
  position: fixed;
  inset: auto 1rem 1rem 1rem;
  padding: 1rem;
  color: #7c1f1f;
  background: #fce9e9;
  border: 1px solid #d32f2f;
}

@media (max-width: 900px) {
  .chart-header-split {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .chart-legend-external {
    align-self: stretch;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  .chapter-block {
    padding: 0.1rem 0 0.35rem;
  }

  .chapter-block + .chapter-block {
    padding-top: 2.2rem;
  }

  .chapter-header {
    gap: 0.4rem;
    padding: 0 1.2rem 0.7rem;
  }

  .references-root {
    padding: 0 1.2rem;
  }

  .chart-section,
  .compact-two-up {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
    overflow: hidden;
  }

  .chart-package,
  .chart-followup {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .compact-two-up-aligned > .chart-followup {
    margin-top: 0.05rem;
  }

  .chart-package {
    padding-bottom: 0;
  }

  .chart-followup {
    padding-top: 0;
  }

  .chart-followup .annotations-container {
    margin-top: 0;
  }

  .compact-two-up-aligned > .chart-package:nth-child(1) {
    order: 1;
  }

  .compact-two-up-aligned > .chart-followup:nth-child(3) {
    order: 2;
  }

  .compact-two-up-aligned > .chart-package:nth-child(2) {
    order: 3;
  }

  .compact-two-up-aligned > .chart-followup:nth-child(4) {
    order: 4;
  }

  /* Legend above chart on mobile */
  .chart-stage-featured .chart-legend-featured {
    position: static;
    align-self: stretch;
    order: -1;
    margin-bottom: 0.5rem;
    margin-top: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
  }

  .chart-stage-featured,
  .chart-stage-compact {
    min-height: auto;
  }

  .compact-two-up-aligned .chart-stage,
  .compact-two-up-aligned .chart-stage-compact,
  .compact-two-up-aligned .chart-frame {
    display: block;
    flex: none;
    min-height: 0;
    height: auto;
  }

  .compact-two-up-aligned .chart-frame svg {
    display: block;
    width: 100%;
    height: auto;
  }

  /* ── Carousel for annotation cards on mobile ── */
  .annotations-container.carousel {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 9%;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.35rem;
    min-width: 0;
    max-width: 100%;
  }

  .carousel .annotation-card {
    flex: 0 0 82%;
    min-width: 0;
    min-height: auto;
    opacity: 0.55;
    transform: none;
    cursor: default;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    transition: opacity 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
  }

  .carousel .annotation-card.is-active {
    opacity: 1;
    border-left-color: var(--public-dark);
    box-shadow: 0 12px 28px rgba(58, 88, 62, 0.14);
  }

  /* Non-carousel fallback */
  .annotations-container:not(.carousel) .annotation-card {
    min-height: auto;
    opacity: 1;
    transform: none;
    cursor: default;
  }

  .annotations-grid:not(.carousel),
  .annotations-grid-featured:not(.carousel),
  .annotations-grid-compact:not(.carousel) {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .hover-hint {
    display: none;
  }

  /* Swipe hint (inside first card, pushed to bottom-right) */
  .swipe-hint {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    justify-content: flex-end;
    margin-top: auto;
    padding-top: 0.65rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--ink);
    pointer-events: none;
  }

  .swipe-hint-icon {
    flex-shrink: 0;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 1rem, 100%);
    padding-top: 1rem;
  }

  .story-grid {
    gap: 1.5rem;
  }

  .chapter-block {
    padding: 0.1rem 0 0.35rem;
  }

  .chapter-block + .chapter-block {
    padding-top: 1.8rem;
  }

  .chapter-header {
    padding: 0 1rem 0.65rem;
    gap: 0.45rem;
  }

  .chapter-bridge,
  .chapter-outro {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .references-root {
    padding: 0 1rem;
    gap: 1rem;
  }

  .references-source {
    padding: 1rem;
    border-radius: 20px;
  }

  .chapter-title {
    font-size: 1.4rem;
    line-height: 1.08;
  }

  .chapter-intro,
  .chapter-bridge p,
  .chapter-outro p {
    font-size: 0.98rem;
    line-height: 1.7;
  }

  .hero {
    padding: 1rem 1rem 2rem;
  }

  .chart-section {
    padding: 1rem;
    border-radius: 20px;
  }

  .chart-stage {
    flex: 0 0 auto;
  }

  .chart-frame {
    flex: 0 0 auto;
    min-height: 0;
    height: auto;
  }

  .chart-frame-featured,
  #chart-transferencias.chart-frame {
    min-height: 0;
  }

  .chart-frame svg {
    width: 100%;
    height: auto;
  }

  .chart-legend.two-column {
    grid-template-columns: 1fr;
  }

  .annotations-container {
    gap: 0.6rem;
  }

  .annotation-disclosure {
    padding: 0.8rem 0.9rem;
  }

  .tooltip {
    display: none;
  }
}

@media print {
  body {
    background: white;
  }

  .page-shell {
    width: 100%;
    padding: 0;
  }

  .chart-section,
  .compact-two-up,
  .chapter-block {
    box-shadow: none;
    background: white;
    border-radius: 0;
    border: 0;
    page-break-inside: avoid;
  }
}

body.poster-page {
  background: white;
}

.poster-page .page-shell {
  width: min(1480px, calc(100vw - 2rem));
}

.poster-page .story-grid {
  gap: 1.25rem;
}

.poster-page .chart-section,
.poster-page .compact-two-up,
.poster-page .chapter-block {
  grid-template-columns: 1fr;
  gap: 1rem;
  box-shadow: none;
  backdrop-filter: none;
  background: white;
}

.poster-page .section-copy {
  position: static;
}

.poster-page .annotations-container {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.poster-page .poster-annotation {
  min-height: 100%;
}
