/**
 * SismoCol · Historia con scroll · "bitácora sísmica"
 * Los colores y medidas vienen de variables.css
 */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body.story {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--chapter-bg-paper);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

a { color: var(--accent); }

/* ── Zonas de fondo (papel milimetrado) ─────────────────────────────── */

.zone-paper,
.zone-sunken,
.zone-charcoal {
  background-image:
    linear-gradient(var(--zone-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--zone-grid) 1px, transparent 1px);
  background-size: var(--story-grid-size) var(--story-grid-size);
}

.zone-paper {
  --zone-grid: var(--story-grid);
  background-color: var(--chapter-bg-paper);
}

.zone-sunken {
  --zone-grid: var(--story-grid);
  background-color: var(--chapter-bg-sunken);
}

.zone-charcoal {
  --zone-grid: var(--story-grid-charcoal);
  --ink: var(--chapter-ink-charcoal);
  --muted: var(--chapter-muted-charcoal);
  --line-strong: var(--chapter-line-charcoal);
  --bg-raised: var(--chapter-card-charcoal);
  background-color: var(--chapter-bg-charcoal);
  color: var(--ink);
}

/* ── Encabezado fijo ────────────────────────────────────────────────── */

.story-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 1100;
  height: var(--story-header-h);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: var(--ink);
  background: color-mix(in srgb, var(--chapter-bg-paper) 92%, transparent);
  backdrop-filter: blur(6px);
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

.story-header[data-zone="sunken"] {
  background: color-mix(in srgb, var(--chapter-bg-sunken) 92%, transparent);
}

.story-header[data-zone="charcoal"] {
  color: var(--chapter-ink-charcoal);
  background: color-mix(in srgb, var(--chapter-bg-charcoal) 92%, transparent);
}

.story-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px 6px;
}

.story-brand {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  color: inherit;
  text-decoration: none;
}

.story-counter {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-seismo {
  display: block;
  width: 100%;
  height: 14px;
}

.story-seismo path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.55;
  transform-box: fill-box;
  transform-origin: center;
}

.story-seismo.is-shaking path {
  animation: seismo-shake 1.5s cubic-bezier(0.2, 0.7, 0.3, 1);
}

@keyframes seismo-shake {
  0% { transform: scaleY(1); }
  12% { transform: scaleY(3.2); }
  30% { transform: scaleY(1.6); }
  48% { transform: scaleY(2.4); }
  70% { transform: scaleY(1.3); }
  100% { transform: scaleY(1); }
}

/* ── Portada ────────────────────────────────────────────────────────── */

.story-cover {
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: calc(var(--story-header-h) + 48px) 24px 64px;
}

.cover-inner {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

.cover-kicker {
  margin: 0 0 20px;
  font-size: 0.8rem;
  color: var(--muted);
}

.cover-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(3rem, 10vw, 7.5rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.cover-reading {
  margin: 28px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-strong);
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  color: var(--mag-main);
}

.cover-note {
  max-width: 560px;
  margin: 28px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.cover-note strong { color: var(--ink); font-weight: 600; }

.cover-cutoff {
  margin: 20px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.cover-scroll {
  display: inline-block;
  margin-top: 48px;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 4px;
}

.cover-scroll span {
  display: inline-block;
  animation: scroll-hint 2s ease-in-out infinite;
}

@keyframes scroll-hint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

/* ── Capítulos ──────────────────────────────────────────────────────── */

.story-chapter {
  position: relative;
  padding: 0 24px;
}

.chapter-head {
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--story-header-h) + 12vh) 0 8vh;
  border-top: 1px solid var(--line-strong);
}

.story-chapter:first-child .chapter-head { border-top: 0; }

.chapter-kicker {
  margin: 0 0 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.chapter-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2.5rem, 7vw, 5rem);
  line-height: 1;
}

.chapter-body {
  display: grid;
  grid-template-columns: minmax(280px, 400px) 1fr;
  gap: 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.story-figure {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: calc(var(--story-header-h) + 16px);
  height: calc(100svh - var(--story-header-h) - 32px);
  margin: 0;
}

.story-steps {
  grid-column: 1;
  grid-row: 1;
  padding-bottom: 30svh;
}

.view-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0s linear 0.5s;
}

.view-layer.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s ease, visibility 0s;
}

/* ── Tarjeta-registro ───────────────────────────────────────────────── */

.step {
  min-height: 85svh;
  display: flex;
  align-items: flex-start;
}

.step:first-child { min-height: 70svh; }

.reg-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  opacity: 0.4;
  transition: opacity 0.35s ease;
}

.step.is-active .reg-card { opacity: 1; }

.reg-label {
  margin: 0;
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line-strong);
}

.reg-text {
  margin: 0;
  padding: 16px 16px 14px;
  font-size: 1.02rem;
}

.reg-sources {
  margin: 0;
  padding: 0 16px 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Dato clave resaltado con su color fijo */
.reg-text mark {
  background: none;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
}

.reg-text mark.m-red { color: var(--mag-main); }
.reg-text mark.m-orange { color: var(--mag-strong); }
.reg-text mark.m-amber { color: var(--mag-moderate); }
.reg-text mark.m-teal { color: var(--mag-light); }

/* ── Vista de mapa ──────────────────────────────────────────────────── */

.story-map {
  width: 100%;
  height: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--chapter-bg-sunken);
}

.zone-charcoal .story-map { background: var(--chapter-bg-charcoal); }

/* Mosaicos OSM en tono de registro: gris papel o invertidos a carbón */
.story-map-paper .leaflet-tile-pane { filter: grayscale(1) contrast(0.9) brightness(1.04); }
.story-map-charcoal .leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(0.62) contrast(1.15); }

.story-map .leaflet-control-attribution {
  font-family: var(--font-mono);
  font-size: 10px;
  background: rgba(16, 16, 20, 0.7);
  color: var(--chapter-muted-charcoal);
}

.zone-paper .story-map .leaflet-control-attribution,
.zone-sunken .story-map .leaflet-control-attribution {
  background: rgba(242, 241, 238, 0.8);
  color: var(--muted);
}

.story-map .leaflet-control-attribution a { color: inherit; }

.story-epicenter { position: relative; }

.story-epicenter-dot,
.story-epicenter-ring {
  position: absolute;
  border-radius: 50%;
}

.story-epicenter-dot {
  inset: 8px;
  background: var(--mag-main);
  border: 2px solid var(--chapter-ink-charcoal);
}

.story-epicenter-ring {
  inset: 0;
  border: 1px solid var(--mag-main);
  animation: epicenter-ring 2.4s ease-out infinite;
}

@keyframes epicenter-ring {
  0% { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(1.8); opacity: 0; }
}

.leaflet-tooltip.story-tooltip {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: var(--chapter-ink-charcoal);
  background: var(--chapter-card-charcoal);
  border: 1px solid var(--chapter-line-charcoal);
  border-radius: var(--radius-sm);
  box-shadow: none;
  padding: 6px 10px;
}

.leaflet-tooltip.story-tooltip strong { color: var(--mag-main); }
.leaflet-tooltip-right.story-tooltip::before { border-right-color: var(--chapter-line-charcoal); }
.leaflet-tooltip-top.story-tooltip::before { border-top-color: var(--chapter-line-charcoal); }

/* ── Corte del subsuelo ─────────────────────────────────────────────── */

.story-depth {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  font-family: var(--font-mono);
}

.band-fill { fill: currentColor; transition: opacity 0.5s ease; }
.band-fill-0 { opacity: 0.03; }
.band-fill-1 { opacity: 0.07; }
.band-fill-2 { opacity: 0.12; }

.band-edge {
  stroke: currentColor;
  stroke-opacity: 0.35;
  stroke-dasharray: 2 4;
}

.band-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  fill: var(--muted);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.band-name { fill: var(--ink); }
.band-count { opacity: 0; transition: opacity 0.5s ease; }

.story-depth[data-focus="foco"] .band-fill { opacity: 0.02; }
.story-depth[data-focus="foco"] .band-edge { stroke-opacity: 0.12; }
.story-depth[data-focus="rangos"] .band-label,
.story-depth[data-focus="replicas"] .band-label { opacity: 1; }
.story-depth[data-focus="replicas"] .band-count { opacity: 1; }

.depth-axis text {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--muted);
}

.depth-axis line { stroke: var(--muted); }

.depth-surface { stroke: currentColor; stroke-width: 1.5; }
.depth-epicenter { fill: var(--mag-main); }

.depth-surface-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  fill: var(--ink);
}

.depth-focus-line {
  stroke: var(--mag-main);
  stroke-width: 1.5;
}

.depth-hypocenter {
  fill: var(--mag-main);
  stroke: var(--chapter-bg-charcoal);
  stroke-width: 2;
}

.annotation-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
}

.annotation-dot { fill: currentColor; }

.annotation-text {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  fill: var(--muted);
}

.annotation-strong { fill: var(--ink); font-weight: 600; }

/* ── Vista de prueba ────────────────────────────────────────────────── */

.story-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}

/* ── Pie y estados ──────────────────────────────────────────────────── */

.story-loading {
  min-height: 40vh;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.story-footer {
  padding: 48px 24px 64px;
  border-top: 1px solid var(--line-strong);
  font-size: 0.85rem;
  color: var(--muted);
}

.story-footer p { max-width: 1200px; margin: 0 auto 8px; }

/* ── Ejes y anotaciones comunes de los gráficos ─────────────────────── */

.chart-axis text {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  fill: var(--muted);
}

.chart-axis line { stroke: var(--muted); }
.chart-axis .chart-grid { stroke: var(--line-strong); stroke-opacity: 0.5; stroke-dasharray: 2 4; }

.chart-caption {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  fill: var(--muted);
}

/* ── Curva acumulada ────────────────────────────────────────────────── */

.story-cumulative,
.story-bars {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  font-family: var(--font-mono);
}

.cum-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
}

.cum-span {
  fill: var(--ink);
  opacity: 0.06;
}

.cum-bar {
  fill: var(--ink);
  opacity: 0.22;
  transition: opacity 0.3s ease;
}

.cum-bar.is-highlight { opacity: 0.9; }

/* ── Barras por magnitud ────────────────────────────────────────────── */

.bar-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  fill: var(--muted);
}

.bar-value {
  font-size: 15px;
  font-weight: 600;
  fill: var(--ink);
}

/* ── Réplicas y enjambre por profundidad ─────────────────────────────── */

.story-depthsplit,
.story-rhythm {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  font-family: var(--font-mono);
}

.split-band { fill: var(--ink); opacity: 0.06; }

.split-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  fill: var(--ink);
}

.split-count {
  font-size: 10px;
  letter-spacing: 0.06em;
  fill: var(--muted);
}

.split-dot {
  stroke: var(--ink);
  stroke-width: 0.4;
  stroke-opacity: 0.5;
  fill-opacity: 0.8;
}

.split-median { stroke: var(--ink); stroke-width: 1.5; }
.split-main { stroke: var(--mag-main); stroke-width: 1.5; stroke-dasharray: 4 3; }

.split-main-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  fill: var(--mag-main);
}

/* ── Ritmo de réplicas y enjambre ───────────────────────────────────── */

.rhythm-line { fill: none; stroke-width: 2; }
.rhythm-line.rhythm-swarm { stroke: var(--ink); }
.rhythm-line.rhythm-aftershock { stroke: var(--muted); }
circle.rhythm-swarm, text.rhythm-swarm { fill: var(--ink); }
circle.rhythm-aftershock, text.rhythm-aftershock { fill: var(--muted); }
.rhythm-line.rhythm-aftershock { stroke-dasharray: 5 3; }

.rhythm-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  stroke: none;
}

/* ── Capítulos en flujo: tarjetas de gráfico y notas ────────────────── */

.chapter-flow {
  max-width: 820px;
  margin: 0 auto;
  padding-bottom: 20vh;
}

.chapter-flow .step {
  min-height: 0;
  display: block;
  padding-bottom: 14vh;
}

.chart-card {
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.chart-card-body { padding: 20px 20px 8px; }

.chart-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 3.6vw, 2.2rem);
  line-height: 1.1;
  text-wrap: balance;
}

.chart-subtitle {
  margin: 8px 0 20px;
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-note {
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.chart-foot {
  padding: 4px 0 0;
  border-top: 1px solid var(--line-strong);
}

.chart-foot .reg-sources { padding: 10px 20px 4px; }

.chart-data summary {
  padding: 8px 20px 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--accent);
  cursor: pointer;
}

.chart-data[open] summary { padding-bottom: 8px; }

.data-table-wrap {
  overflow-x: auto;
  padding: 0 20px 18px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 6px 10px 6px 0;
  text-align: left;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.data-table th {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Gráficos pequeños de la evolución del impacto */
.multiples {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.multiple-title {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.impact-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: var(--font-mono);
}

.impact-base { stroke: var(--line-strong); }
.impact-line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.impact-dot circle { fill: var(--ink); }

.impact-value {
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
}

.impact-date,
.city-extra {
  font-size: 10px;
  letter-spacing: 0.04em;
  fill: var(--muted);
}

.city-name {
  font-family: var(--font-sans);
  font-size: 13px;
  fill: var(--ink);
}

.city-bar { fill: var(--ink); }

.city-value {
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink);
}

/* Notas del cierre: texto apagado, sin gráfico */
.chapter-flow-notes { max-width: 680px; }
.chapter-flow-notes .step { padding-bottom: 8vh; }

.note {
  border-left: 1px solid var(--line-strong);
  padding-left: 20px;
}

.note .reg-label {
  padding: 0 0 8px;
  border: 0;
}

.note-text {
  color: var(--muted);
  font-size: 1rem;
}

.note-text strong { color: var(--ink); font-weight: 600; }

.note-sources {
  margin: 0 0 16px;
  padding-left: 18px;
}

.note-sources li { margin-bottom: 6px; }

.note-download {
  display: inline-block;
  padding: 10px 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--chapter-ink-charcoal);
  background: var(--accent);
  border-radius: var(--radius-sm);
}

/* ── Celular: el gráfico queda arriba y las tarjetas pasan por encima ─ */

@media (max-width: 767px) {
  body.story { font-size: 16px; }

  .story-header-row { padding: 0 16px 6px; }
  .story-cover { padding-inline: 16px; }
  .story-chapter { padding: 0 16px; }

  .chapter-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .story-figure {
    grid-column: 1;
    top: calc(var(--story-header-h) + 8px);
    height: calc(100svh - var(--story-header-h) - 16px);
  }

  /* Las vistas usan la parte de arriba; abajo entran las tarjetas */
  .view-layer { inset: 0 0 42% 0; }

  .story-steps {
    position: relative;
    z-index: 2;
  }

  /* Cada tarjeta entra por la parte de abajo y deja ver la vista antes de la siguiente */
  .step,
  .step:first-child { min-height: 0; padding-bottom: 75svh; }
  .step:first-child { padding-top: 58svh; }
  .story-steps { padding-bottom: 0; }

  /* Las tarjetas de gráfico y las notas no van sobre un gráfico fijo */
  .chapter-flow .step,
  .chapter-flow .step:first-child { padding: 0 0 10vh; }

  /* Sobre el gráfico la tarjeta no puede ser translúcida */
  .multiples { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .chart-card-body { padding: 16px 16px 8px; }
  .chart-foot .reg-sources,
  .chart-data summary { padding-inline: 16px; }
  .data-table-wrap { padding-inline: 16px; }

  .reg-card {
    max-width: none;
    opacity: 1;
    box-shadow: 0 6px 24px rgba(16, 16, 20, 0.18);
  }
}

/* ── Movimiento reducido ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .story-seismo.is-shaking path,
  .cover-scroll span,
  .story-epicenter-ring { animation: none; }

  .view-layer,
  .view-layer.is-active,
  .reg-card,
  .band-fill,
  .band-label,
  .band-count { transition: none; }
}
