/* Documento pensado para ancho de smartphone y lectura vertical. */
:root {
  --bg: #d8e6f5;
  --paper: #fbfcff;
  --paper-soft: #eef4fb;
  --ink: #1d2633;
  --muted: #607286;
  --accent: #1f6fa0;
  --accent-2: #d57fa8;
  --line: #d4dfef;
  --shadow: 0 22px 58px rgba(39, 67, 104, 0.16);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.56), transparent 24%),
    linear-gradient(180deg, #9fc4e8 0%, #d8e6f5 42%, #efc5db 100%);
}
.document-shell {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}
.motion-ready .reveal-item {
  opacity: 0;
  transform: translateY(22px) scale(0.985);
  transition:
    opacity 0.56s ease,
    transform 0.56s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: var(--reveal-delay, 0ms);
  will-change: opacity, transform;
}
.motion-ready .reveal-item.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Cada página replica una pantalla de móvil vertical. */
.phone-page {
  margin: 0 auto 18px;
  width: 100%;
}
.page-frame {
  min-height: 820px;
  padding: 22px 18px 20px;
  border-radius: 28px;
  background:
    linear-gradient(155deg, rgba(159, 196, 232, 0.22), rgba(239, 197, 219, 0.18)),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-soft) 100%);
  border: 1px solid rgba(129, 157, 192, 0.22);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.municipio-page .page-frame {
  min-height: auto;
  padding-left: 16px;
  padding-right: 16px;
}
.cover-page .page-frame {
  min-height: 500px;
  background: linear-gradient(180deg, #d9e8f6 0%, #f4d1e1 100%);
  display: flex;
  flex-direction: column;
  position: relative;
}
.cover-background {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(24, 92, 140, 0.24), rgba(213, 127, 168, 0.30)),
    url("salida/assets/cover-background.png") center / cover no-repeat;
}
.cover-overlay {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding-top: 34px;
}
.eyebrow {
  margin: 0 0 10px;
  font-size: 0.76rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-2);
}
h1, h2, h3 { margin: 0; }
h1 {
  font-size: 2.5rem;
  line-height: 0.96;
  letter-spacing: -0.04em;
  margin-bottom: 14px;
}
h2 {
  font-size: 1.8rem;
  line-height: 1;
  margin-bottom: 12px;
}
.lead, .note {
  line-height: 1.72;
  color: #445a72;
}
.text-block {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.text-block p {
  margin: 0;
  line-height: 1.62;
  color: #445a72;
  font-size: 0.97rem;
}
.summary-page h2 {
  margin-bottom: 18px;
}
.essay-page .page-frame {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.water-page .page-frame {
  display: flex;
  flex-direction: column;
}
.essay-page h2 {
  margin-bottom: 18px;
}
.essay-page .text-block {
  gap: 12px;
}
.slide-footnote {
  margin-top: auto;
  padding-top: 16px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #52677f;
}
.slide-sources {
  margin-top: auto;
  padding-top: 16px;
  font-size: 0.76rem;
  line-height: 1.35;
  color: #6b7d92;
  border-top: 1px solid rgba(200, 214, 232, 0.75);
}
.ranking-page .page-frame {
  min-height: 700px;
}
.ranking-page .ranking-select {
  margin-bottom: 18px;
}
.section-title {
  margin-top: 34px;
  padding-top: 18px;
  margin-bottom: 18px;
  border-top: 1px solid rgba(212, 223, 239, 0.9);
}
.cover-page h1,
.cover-page .lead {
  color: #ffffff;
  text-shadow: 0 8px 24px rgba(26, 51, 78, 0.34);
  text-align: center;
}
.cover-page h1 {
  font-size: 2.45rem;
  margin-bottom: 16px;
}
.cover-page .lead {
  max-width: 27ch;
  font-size: 1.1rem;
  margin-bottom: 0;
  margin-left: auto;
  margin-right: auto;
}
.subhead {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.55;
}
.cover-spacer {
  flex: 1;
  min-height: 110px;
}
.cover-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: auto;
  padding: 18px 0 0;
}
.cover-logo img {
  display: block;
  width: min(150px, 52%);
  height: auto;
  object-fit: contain;
}
.cover-lang-switch {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 14px auto 0;
}
.lang-btn {
  min-width: 58px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.42);
  background: rgba(255,255,255,0.18);
  color: #ffffff;
  font-family: Arial, sans-serif;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px rgba(16, 39, 63, 0.18);
}
.lang-btn.is-active {
  background: rgba(255,255,255,0.92);
  color: var(--accent);
  border-color: rgba(255,255,255,0.92);
}

/* Tarjetas de datos adaptadas a lectura táctil. */
.stat-stack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 14px;
}
.compact-stack {
  margin-top: 14px;
}
.stat-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.56);
}
.stat-card span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.84rem;
  color: var(--muted);
}
.stat-card strong {
  font-size: 1.55rem;
}
.hero-map {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, #f7fbff, #e8f0fa);
  padding: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}
.hero-map.compact {
  margin-top: 14px;
}
.hero-map svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  will-change: viewBox;
}
.ficha-map svg {
  cursor: grab;
}
.ficha-map svg.is-dragging {
  cursor: grabbing;
}
.map-ortho {
  opacity: 0.96;
  filter: url(#baseSoftener);
}
.map-base-tint {
  fill: rgba(244, 249, 255, 0.22);
}
.municipio-shape {
  stroke: rgba(255,255,255,0.96);
  stroke-width: 6;
  stroke-linejoin: round;
}
.municipio-label {
  font-family: Arial, sans-serif;
  font-size: 24px;
  font-weight: 700;
  text-anchor: middle;
  fill: rgba(28, 43, 58, 0.82);
}
.selector-label {
  display: block;
  margin: 18px 0 8px;
  font-family: Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.municipio-select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.82);
  color: var(--ink);
  font-family: Arial, sans-serif;
  font-size: 1rem;
}
.municipio-viewer {
  margin-top: 16px;
}
.municipio-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,0.52);
  padding: 14px;
}
.map-block {
  margin-top: 18px;
}
.map-block-shared {
  margin-top: 22px;
  margin-left: 0;
  margin-right: 0;
}
.map-zoom-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 0 10px;
}
.map-zoom-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.86);
  color: var(--ink);
  font-family: Arial, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(39, 67, 104, 0.12);
}
.map-caption {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}
.subhead-tight {
  margin-bottom: 12px;
}
.ficha-map {
  aspect-ratio: 1 / 1;
  min-height: 400px;
}
.ficha-map svg.is-dragging {
  shape-rendering: optimizeSpeed;
}
.municipio-context-shape {
  fill: rgba(238,245,252,0.18);
  fill-opacity: 0.96;
  stroke: rgba(255,255,255,0.88);
  stroke-width: 2;
}
.municipio-context-shape.is-active {
  fill: rgba(220,236,249,0.34);
  stroke: #f2d24b;
  stroke-width: 2.4;
}
.municipio-context-label {
  fill: #ffffff;
  font-size: 22px;
  font-weight: 700;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(35, 58, 79, 0.38);
  stroke-width: 7;
  pointer-events: none;
  opacity: 0.88;
  transition: opacity 0.25s ease;
}
.municipio-context-label.is-hidden {
  opacity: 0;
}
.pool-polygon {
  fill: rgba(0, 112, 191, 0.72);
  stroke: rgba(0, 63, 108, 0.82);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

/* Tabla comprimida para no exigir zoom en móvil. */
.mini-table-wrap {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,0.62);
  padding: 10px 12px;
  overflow: hidden;
}
.mini-table-wrap + .section-title,
.mini-table-wrap + h2.section-title {
  margin-top: 20px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: Arial, sans-serif;
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 9px 4px;
  border-bottom: 1px solid #eadfd0;
}
th {
  color: var(--muted);
  font-weight: 600;
}
.municipio-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.municipio-link:hover {
  text-decoration: underline;
}

/* Al imprimir, cada bloque sale como una página independiente del PDF. */
@page {
  size: 108mm 192mm;
  margin: 0;
}
@media (max-width: 360px) {
  .stat-stack {
    grid-template-columns: 1fr;
  }
}
@media print {
  body { background: white; }
  .motion-ready .reveal-item {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .document-shell {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .phone-page {
    break-after: page;
    margin: 0;
  }
  .page-frame {
    min-height: 192mm;
    border-radius: 0;
    box-shadow: none;
    border: 0;
  }
}


/* Ajustes de escritorio: mismo documento, más aire y mejor uso del ancho. */
body {
  overflow: hidden;
}
.desktop-book {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.slide-viewport {
  position: relative;
  width: min(86vw, 1120px);
  aspect-ratio: 16 / 7.6;
  margin: 0;
}
.slide-nav {
  width: 50px;
  height: 50px;
  border: 1px solid rgba(212, 223, 239, 0.92);
  border-radius: 50%;
  background: rgba(255,255,255,0.84);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  line-height: 1;
  box-shadow: 0 16px 28px rgba(39, 67, 104, 0.15);
}
.slide-nav:disabled {
  opacity: 0;
  pointer-events: none;
}
.slide-nav-bar {
  position: absolute;
  left: 34px;
  right: 34px;
  bottom: 18px;
  z-index: 4;
  pointer-events: none;
}
.slide-nav-bar .slide-nav {
  position: absolute;
  bottom: 0;
  pointer-events: auto;
}
.slide-nav-bar .slide-nav-prev {
  left: 18px;
}
.slide-nav-bar .slide-nav-next {
  right: 18px;
}
.document-shell {
  max-width: none;
  padding: 0;
  width: 100%;
  height: 100%;
}
.phone-page {
  display: none;
  margin: 0;
  width: 100%;
  height: 100%;
}
.phone-page.is-active-slide {
  display: block;
}
.page-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 22px 26px 20px;
  border-radius: 28px;
}
.phone-page:not(.cover-page) .page-frame {
  padding: 24px 28px 22px;
}
.cover-overlay {
  padding-top: 40px;
}
h1 {
  font-size: 3.35rem;
  margin-bottom: 12px;
}
h2 {
  font-size: 1.95rem;
  margin-bottom: 11px;
}
.lead,
.note {
  font-size: 0.96rem;
}
.text-block {
  gap: 9px;
  margin-top: 10px;
  max-width: 88ch;
}
.text-block p {
  font-size: 0.94rem;
  line-height: 1.54;
}
.summary-page .page-frame {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 22px;
  padding-top: 32px;
  align-content: start;
  align-items: start;
}
.summary-column {
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  gap: 10px;
  align-self: start;
}
.summary-column .text-block {
  margin-top: 0;
}
.summary-page h2 {
  font-size: 2.08rem;
  margin-bottom: 14px;
}
.summary-page .text-block {
  gap: 12px;
}
.summary-page .text-block p {
  font-size: 1rem;
  line-height: 1.65;
}
.essay-page .page-frame {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.essay-page .text-block {
  max-width: none;
  width: 100%;
  gap: 11px;
}
.essay-page .text-block p {
  max-width: none;
  font-size: 0.94rem;
  line-height: 1.54;
}
.model-page .text-block p {
  font-size: 1rem;
}
.essay-page h2 {
  max-width: none;
}
.water-page h2 {
  max-width: none;
}
.water-page .slide-sources {
  max-width: none;
  margin-top: 10px;
  padding-top: 10px;
}
.ranking-page .page-frame {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  row-gap: 14px;
  align-content: start;
  align-items: start;
  padding: 18px 24px 16px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.ranking-page .ranking-select-desktop {
  width: min(620px, 100%);
  margin-bottom: 4px;
}
.ranking-page .ranking-desktop-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  min-height: 0;
}
.ranking-page .mini-table-wrap {
  padding: 14px 16px;
  height: 100%;
}
.ranking-page table {
  font-size: 0.9rem;
}
.ranking-page th,
.ranking-page td {
  padding: 8px 6px;
}
.ranking-page td:first-child,
.ranking-page th:first-child {
  width: 34px;
}
.ranking-page .ranking-desktop-columns .mini-table-wrap th:last-child,
.ranking-page .ranking-desktop-columns .mini-table-wrap td:last-child {
  text-align: right;
  padding-right: 12px;
}
.cover-page h1 {
  font-size: 2.9rem;
  line-height: 0.98;
  max-width: 17ch;
  margin-left: auto;
  margin-right: auto;
}
.cover-page .lead {
  display: none;
}
.cover-spacer {
  min-height: 0;
}
.cover-logo {
  padding-top: 4px;
}
.cover-logo img {
  width: min(154px, 25%);
}
.cover-lang-switch {
  margin-top: 6px;
}
.stat-stack {
  gap: 9px;
  margin: 12px 0 11px;
}
.stat-card {
  padding: 13px;
  border-radius: 17px;
}
.stat-card span {
  font-size: 0.8rem;
}
.stat-card strong {
  font-size: 1.5rem;
}
.hero-map {
  border-radius: 22px;
  aspect-ratio: 16 / 10;
}
.municipio-page .page-frame {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px 18px;
  align-items: stretch;
}
.municipio-select {
  grid-column: 1 / -1;
  grid-row: 1;
  width: min(340px, 100%);
  padding: 12px 15px;
  border-radius: 15px;
  font-size: 0.93rem;
}
.municipio-viewer {
  display: grid;
  grid-column: 1;
  grid-row: 2;
  margin-top: 0;
  min-height: 0;
}
.municipio-card {
  padding: 16px;
  border-radius: 20px;
  position: static;
  height: 100%;
}
.map-block-shared {
  grid-column: 2;
  grid-row: 2;
  margin-top: 0;
  display: block;
  position: relative;
  min-height: 0;
  height: 100%;
  align-self: stretch;
}
.ficha-map {
  aspect-ratio: 16 / 10;
  min-height: 390px;
}
.map-block-shared .hero-map {
  margin-top: 0;
  height: 100%;
  min-height: 0;
}
.map-block-shared .map-zoom-controls {
  position: absolute;
  top: -56px;
  right: 28px;
  z-index: 5;
  margin: 0;
  justify-content: flex-end;
}
.mini-table-wrap {
  padding: 12px 14px;
  border-radius: 19px;
}
table {
  font-size: 0.86rem;
}
th,
td {
  padding: 8px 5px;
}

/* Impresión pensada para PDF apaisado de escritorio. */
@page {
  size: A4 landscape;
  margin: 0;
}

/* Tablet y portátil estrecho: se rompe a una columna en fichas. */
@media (max-width: 1120px) {
  body {
    overflow: auto;
  }
  .desktop-book {
    display: flex;
    padding: 10px 8px;
  }
  .slide-viewport {
    width: min(100vw - 14px, 980px);
    aspect-ratio: auto;
  }
  .slide-nav-bar {
    left: 20px;
    right: 20px;
    bottom: 16px;
  }
  .slide-nav-bar .slide-nav-prev {
    left: 14px;
  }
  .slide-nav-bar .slide-nav-next {
    right: 14px;
  }
  .document-shell {
    padding-left: 0;
    padding-right: 0;
  }
  .municipio-page .page-frame {
    grid-template-columns: 1fr;
  }
  .summary-page .page-frame {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .ranking-page .page-frame {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .summary-column {
    gap: 10px;
  }
  .summary-column + .summary-column {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(212, 223, 239, 0.9);
  }
  .ranking-page .page-frame > h2:first-of-type,
  .ranking-page .page-frame > .mini-table-wrap:first-of-type,
  .ranking-page .page-frame > .section-title,
  .ranking-page .page-frame > .section-title + .mini-table-wrap {
    grid-column: 1;
  }
  .ranking-page .page-frame > .section-title {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(212, 223, 239, 0.9);
  }
  .municipio-card {
    position: static;
  }
  .ficha-map {
    min-height: 460px;
  }
}

/* Si se abre en móvil, mantiene un comportamiento muy parecido al original. */
@media (max-width: 760px) {
  body {
    overflow: auto;
  }
  .desktop-book {
    display: block;
    min-height: auto;
    padding: 0;
  }
  .slide-viewport {
    width: auto;
    aspect-ratio: auto;
  }
  .slide-nav-bar {
    display: none;
  }
  .document-shell {
    max-width: 460px;
    padding: 16px 12px 40px;
  }
  .phone-page,
  .phone-page.is-active-slide {
    display: block;
    height: auto;
  }
  .page-frame {
    height: auto;
    min-height: 820px;
    padding: 22px 18px 20px;
    border-radius: 28px;
  }
  .municipio-page .page-frame {
    min-height: auto;
    gap: 18px;
  }
  h1 {
    font-size: 2.5rem;
  }
  h2 {
    font-size: 1.8rem;
  }
  .cover-page .page-frame {
    min-height: 500px;
  }
  .cover-page h1 {
    font-size: 2.45rem;
  }
  .cover-page .lead {
    max-width: 27ch;
    font-size: 1.1rem;
  }
  .cover-spacer {
    min-height: 110px;
  }
  .cover-logo img {
    width: min(150px, 52%);
  }
  .stat-stack {
    gap: 10px;
    margin: 16px 0 14px;
  }
  .stat-card {
    padding: 14px;
    border-radius: 18px;
  }
  .stat-card strong {
    font-size: 1.55rem;
  }
  .hero-map,
  .ficha-map {
    aspect-ratio: 1 / 1;
    min-height: 400px;
  }
  .municipio-select {
    width: 100%;
    padding: 14px 16px;
    border-radius: 18px;
  }
  .mini-table-wrap {
    padding: 10px 12px;
    border-radius: 18px;
  }
  table {
    font-size: 0.85rem;
  }
  th,
  td {
    padding: 9px 4px;
  }
}

@media print {
  .municipio-card {
    position: static;
  }
  .page-frame {
    min-height: 210mm;
  }
}
