/* ============================================================
   CIENCIAS APLICADAS I · Hoja de estilos
   - Vista de lectura (pantalla)
   - Impresión / PDF (@media print)
   - Modo diapositivas (.slideshow)
   ============================================================ */

/* ---------- Variables y tema ---------- */
:root {
  --azul:      #1f4e79;
  --azul-suave:#e8f0f8;
  --mat:       #2563ab;   /* matemáticas */
  --bio:       #2e7d46;   /* biología   */
  --fis:       #c2600a;   /* física     */
  --qui:       #7c3aed;   /* química    */
  --act:       #b4235e;   /* actividades */
  --texto:     #23272e;
  --texto-suave: #4b5563;
  --fondo:     #f7f6f3;
  --tarjeta:   #ffffff;
  --borde:     #e4e1da;
  --radio:     10px;
  --sombra:    0 1px 3px rgba(20, 30, 50, .08), 0 6px 20px rgba(20, 30, 50, .06);
  --fuente:    "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Reset básico ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--fuente);
  color: var(--texto);
  background: var(--fondo);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }

/* Las imágenes insertadas desde Markdown se muestran centradas. */
.slide img {
  display: block;
  height: auto;
  margin: 16px auto;
}

/* ============================================================
   BARRA SUPERIOR
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--borde);
}

.topbar__title { display: flex; align-items: center; gap: 10px; }

.topbar__brand {
  font-weight: 700;
  color: var(--azul);
  font-size: 1.05rem;
  white-space: nowrap;
}

.topbar__actions { display: flex; gap: 10px; }

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: .95rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--azul);
  color: #fff;
  box-shadow: 0 2px 8px rgba(31, 78, 121, .35);
}
.btn--primary:hover { background: #163c60; }

.btn--outline {
  background: #fff;
  color: var(--azul);
  border: 1px solid var(--borde);
}
.btn--outline:hover { background: var(--azul-suave); border-color: #c6d8ea; }

.btn--ghost {
  background: transparent;
  color: var(--azul);
  padding: 8px 10px;
  font-size: 1.15rem;
  display: none;
}

/* ============================================================
   ESTRUCTURA GENERAL
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 28px;
  max-width: 1150px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  align-items: start;
}

/* ============================================================
   ÍNDICE LATERAL
   ============================================================ */
.sidebar {
  position: sticky;
  top: 76px;
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 18px;
  box-shadow: var(--sombra);
}

.sidebar__title {
  margin: 0 0 12px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--texto-suave);
}

.toc { list-style: none; margin: 0; padding: 0; counter-reset: toc; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--texto);
  text-decoration: none;
  font-size: .92rem;
  border-left: 3px solid transparent;
}
.toc a:hover { background: var(--azul-suave); color: var(--azul); }
.toc a.is-active { background: var(--azul-suave); border-left-color: var(--azul); color: var(--azul); font-weight: 600; }

.toc .toc__materia {
  margin-top: 10px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--texto-suave);
  padding: 0 10px;
}

.toc .toc__seccion { margin-top: 10px; }
.toc__seccion-titulo {
  display: block;
  padding: 0 10px 3px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--azul);
}
.toc__sublista { list-style: none; margin: 0; padding: 0; }
.toc__sublista a {
  padding: 5px 10px 5px 20px;
  font-size: .86rem;
}

/* Estas portadas resumen los ### de cada ##. Se conservan en el DOM para
   el visor de diapositivas, pero no forman parte de la lectura ni la impresión.
   Si el ## no tiene texto propio, se muestra únicamente su título para no
   perder la jerarquía del documento; la lista sigue siendo exclusiva del visor. */
.content .slide.slide--seccion { display: none; }
.content .slide.slide--seccion--titulo-necesario { display: block; }
.content .slide--seccion--titulo-necesario .slide__indice-seccion { display: none; }

.slide-view .slide--seccion {
  margin-top: 24px;
  padding: 32px;
  background: var(--azul-suave);
  border: 1px solid #c6d8ea;
  border-radius: var(--radio);
}
.slide--seccion h2 { margin-bottom: 14px; }
.slide__indice-seccion { margin: 0; }
.slide__indice-seccion li { font-weight: 600; }

.sidebar__hint {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--borde);
  font-size: .8rem;
  color: var(--texto-suave);
}
kbd {
  background: #eef1f4;
  border: 1px solid #d4d9df;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .75rem;
  font-family: inherit;
}

/* ============================================================
   CONTENIDO
   ============================================================ */
.content {
  min-width: 0;
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: clamp(24px, 5vw, 56px);
}

/* Portada */
.cover {
  padding-bottom: 20px;
  border-bottom: 2px solid var(--borde);
  margin-bottom: 10px;
}
.cover__kicker {
  margin: 0 0 6px;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--texto-suave);
}
.cover__title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1.1;
  color: var(--azul);
  letter-spacing: -.02em;
}
.cover__subtitle {
  margin: 10px 0 0;
  font-size: clamp(1.05rem, 2.5vw, 1.4rem);
  color: var(--texto-suave);
  font-weight: 500;
}
.cover__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  margin-top: 18px;
  font-size: .92rem;
  color: var(--texto-suave);
}
.cover__note {
  margin-top: 22px;
  padding: 12px 16px;
  background: var(--azul-suave);
  border-radius: 8px;
  font-size: .92rem;
  color: var(--texto);
}

/* Secciones */
.slide { padding: 34px 0 8px; }

.slide h2 {
  font-size: clamp(1.4rem, 3vw, 1.85rem);
  color: var(--azul);
  margin: 0 0 16px;
  line-height: 1.25;
}
.slide h3 {
  font-size: 1.15rem;
  color: var(--texto);
  margin: 26px 0 8px;
  padding-left: 10px;
  border-left: 4px solid var(--azul);
}
.slide p { margin: 10px 0; }
.slide ul, .slide ol { margin: 10px 0; padding-left: 22px; }
.slide li { margin: 5px 0; }

/* Etiquetas de materia */
.tag {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: middle;
  color: #fff;
}
.tag--mat { background: var(--mat); }
.tag--bio { background: var(--bio); }
.tag--fis { background: var(--fis); }
.tag--qui { background: var(--qui); }
.tag--act { background: var(--act); }

/* Matemáticas en línea */
.math {
  margin: 12px 0;
  padding: 10px 16px;
  background: #f4f6f9;
  border-radius: 8px;
  font-size: 1.05rem;
}
.formula {
  text-align: center;
  font-weight: 600;
  color: var(--azul);
  border: 1px dashed #c6d8ea;
  background: var(--azul-suave);
}
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 3px; line-height: 1.1; }
.frac__num { padding: 0 6px; border-bottom: 1.5px solid currentColor; }
.frac__den { padding: 0 6px; }

/* KaTeX: fórmulas escritas con sintaxis LaTeX */
.math .katex-display { margin: .25em 0; }
.math .katex { font-size: 1.12em; }

/* Cajas */
.box {
  margin: 16px 0;
  padding: 14px 18px;
  border-radius: 8px;
  border-left: 5px solid var(--azul);
  background: #f4f6f9;
}
.box__title {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.box--example { border-left-color: var(--mat); background: #eef4fb; }
.box--example .box__title { color: var(--mat); }
.box--resumen { border-left-color: var(--bio); background: #eef7f0; }
.box--resumen .box__title { color: var(--bio); }
.box--dato { border-left-color: var(--fis); background: #fdf3e8; }
.box--dato .box__title { color: var(--fis); }
.box p { margin: 6px 0; }
.box ul { margin: 6px 0 0; }

/* Tablas */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: .95rem;
}
caption {
  caption-side: top;
  text-align: left;
  font-weight: 700;
  color: var(--texto-suave);
  padding-bottom: 6px;
  font-size: .9rem;
}
th, td {
  border: 1px solid var(--borde);
  padding: 9px 12px;
  text-align: left;
}
thead th { background: var(--azul); color: #fff; font-weight: 600; }
tbody tr:nth-child(even) { background: #f8f9fb; }

/* Actividades */
.actividades li { margin: 10px 0; }

/* Pie de página */
.page-footer {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--borde);
  text-align: center;
  color: var(--texto-suave);
  font-size: .85rem;
}

/* ============================================================
   VISOR DE DIAPOSITIVAS
   ============================================================ */
.slideshow {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--fondo);
  color: var(--texto);
  display: flex;
  flex-direction: column;
}
.slideshow[hidden] { display: none; }

.slideshow__progress {
  height: 5px;
  background: var(--borde);
}
.slideshow__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--azul), var(--qui));
  transition: width .25s ease;
}

.slideshow__close {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 10;
  background: var(--tarjeta);
  color: var(--azul);
  border: 1px solid var(--borde);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background .15s ease;
  box-shadow: var(--sombra);
}
.slideshow__close:hover { background: var(--azul-suave); }

.slideshow__stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 56px 70px;
}

.slide-view {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 60px 80px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease;
}
.slide-view.is-active { opacity: 1; visibility: visible; }

.slide-view__inner {
  width: min(100%, 920px);
  max-height: 100%;
  overflow: auto;
}

.slide-view h1 { font-size: clamp(2rem, 5vw, 3.4rem); margin: 0 0 10px; line-height: 1.1; }
.slide-view h2 { font-size: clamp(1.5rem, 3.6vw, 2.3rem); margin: 0 0 16px; line-height: 1.2; }
.slide-view h3 { font-size: 1.2rem; margin: 20px 0 8px; }
.slide-view p, .slide-view li { font-size: clamp(1rem, 2vw, 1.2rem); }
.slide-view table { font-size: 1rem; }

.slide-view--cover { text-align: center; }
.slide-view--cover .slide-view__kicker {
  font-size: .95rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--texto-suave);
  margin: 0 0 12px;
}
.slide-view--cover .slide-view__subtitle { color: var(--texto-suave); font-size: 1.25rem; }

/* Controles */
.slideshow__controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--borde);
  border-radius: 999px;
  padding: 8px 14px;
  backdrop-filter: blur(6px);
  box-shadow: var(--sombra);
}
.slideshow__nav {
  background: transparent;
  border: none;
  color: var(--azul);
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s ease;
  line-height: 1;
}
.slideshow__nav:hover { background: var(--azul-suave); }
.slideshow__counter { font-size: .9rem; color: var(--texto-suave); min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }

/* ============================================================
   ÍNDICE GENERAL (portada + tarjetas de capítulos)
   ============================================================ */
.indice {
  max-width: 1150px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.indice__portada { padding-bottom: 24px; margin-bottom: 24px; }
.indice__portada .cover__title { font-size: clamp(1.8rem, 4.5vw, 2.8rem); }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  text-decoration: none;
  color: var(--texto);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--azul);
  box-shadow: 0 8px 24px rgba(20, 30, 50, .12);
}
.chapter-card h2 { margin: 0; font-size: 1.2rem; color: var(--azul); }
.chapter-card p { margin: 0; font-size: .92rem; color: var(--texto-suave); }
.chapter-card .tag { align-self: flex-start; }

/* Etiqueta de materia dentro de la portada de un capítulo */
.cover__subtitle .tag {
  font-size: .85rem;
  padding: 5px 16px;
}

/* Portada clonada dentro del visor de diapositivas */
.slide-view--cover .cover__kicker {
  font-size: .95rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--texto-suave);
  margin: 0 0 12px;
}
.slide-view--cover .cover__title { color: var(--azul); }
.slide-view--cover .cover__subtitle { color: var(--texto-suave); font-size: 1.25rem; margin-top: 14px; }
.slide-view--cover .cover__subtitle .tag { font-size: .95rem; padding: 6px 18px; }
.slide-view--cover .cover__meta {
  justify-content: center;
  color: var(--texto-suave);
  margin-top: 18px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px 12px 40px; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    z-index: 60;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
  }
  .sidebar.is-open { transform: translateX(0); }
  .btn--ghost { display: inline-flex; }
  .btn__label { display: none; }
  .btn { padding: 10px 12px; }
  .topbar { padding: 8px 12px; }
  .slide-view { padding: 24px 22px 80px; }
  .slideshow__stage { padding: 10px 8px 64px; }
}

/* ============================================================
   IMPRESIÓN / PDF
   Nota: @page usa margin: 0 para que el navegador NO imprima
   su encabezado/pie (URL, fecha, nº de página). Los márgenes
   se simulan con padding interno.
   ============================================================ */
@media print {
  :root { --fondo: #fff; --tarjeta: #fff; }

  html, body { margin: 0; padding: 0; background: #fff; color: #000; font-size: 11pt; }

  /* Ocultar elementos interactivos */
  .topbar,
  .sidebar,
  .slideshow,
  .page-footer,
  .sidebar__hint {
    display: none !important;
  }

  .layout {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .content {
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0 2cm; /* márgenes laterales en todas las páginas */
    max-width: none;
  }

  /* La portada ocupa su propia página */
  .cover {
    page-break-after: always;
    break-after: page;
    border-bottom: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh; /* 100vh = una página al no haber margen en @page */
    padding: 0;
    text-align: center;
  }
  .cover__meta { justify-content: center; }
  .cover__note { display: none; }
  .cover__title { color: #000; }
  .cover__kicker, .cover__subtitle { color: #333; }

  /* Cada sección empieza en página nueva */
  .slide {
    page-break-before: always;
    break-before: page;
    padding: 2cm 0;
  }
  .slide:first-of-type { page-break-before: auto; }
  /* Las portadas-resumen de sección son exclusivas del visor de diapositivas.
     Solo se conserva el título de los ## que no tienen texto propio. */
  .slide.slide--seccion { display: none !important; }
  .slide.slide--seccion--titulo-necesario { display: block !important; }
  .slide--seccion--titulo-necesario .slide__indice-seccion { display: none; }

  .slide h2, .slide h3 { page-break-after: avoid; break-after: avoid; color: #000; }
  .slide h3 { border-left-color: #000; }

  p, li { orphans: 3; widows: 3; }

  table, .box, .math, img, figure {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Colores de cajas en escala de grises / claros */
  .tag { color: #000; background: #eee !important; border: 1px solid #999; }
  .math { background: #f2f2f2; }
  .formula { background: #f2f2f2; border: 1px solid #999; color: #000; }
  .box, .box--example, .box--resumen, .box--dato { background: #f4f4f4; border-left: 3px solid #555; }
  .box__title { color: #000; }

  thead th { background: #ddd !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  th, td { border-color: #bbb; }
  tbody tr:nth-child(even) { background: #f5f5f5; }

  .frac__num { border-bottom-color: #000; }

  a { color: #000; text-decoration: none; }

  /* Índice general impreso */
  .indice { max-width: none; padding: 0; }
  .chapter-card { break-inside: avoid; page-break-inside: avoid; }

  @page { size: A4; margin: 0; } /* margen 0 evita el encabezado/pie del navegador */
}
