/* ==========================================================================
   SISTEMA DE DISEÑO — "el sitio es el libro"
   1. Estructura: portada arriba y cada sección es un capítulo numerado (01–05),
      igual que un índice. La navegación ES el índice.
   2. Lectura: texto grande (19 px, peso normal, tinta oscura) en una columna
      de ~68 caracteres. Nada de grises claros ni letra fina para leer.
   3. Color: los de la tapa. Índigo (cielo) y crema (papel) se alternan por
      sección para que el ritmo se lea solo. Naranja (resplandor) = SOLO "Comprar".
   4. Compacto: secciones de 64–96 px de alto de margen, títulos con el número
      de capítulo arriba, sin columnas vacías.
   ========================================================================== */
:root {
  --white: #ffffff;
  --cream: #f5efe6;
  --cream-2: #ebe2d4;
  --indigo: #1f1d5c;
  --indigo-2: #2c2a7a;
  --ink: #16152b;
  --ink-2: #3b3a4f;
  --ink-3: #6b6a7d;
  --line: #ddd6ca;
  --buy: #f0541e;
  --buy-hover: #d6420f;

  --font: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
  --t-display: clamp(2.6rem, 6vw, 4.5rem);
  --t-h2: clamp(2rem, 3.6vw, 2.75rem);
  --t-lead: clamp(1.3rem, 2vw, 1.6rem);
  --t-body: 1.1875rem;
  --t-label: .875rem;

  --max: 1120px;
  --text: 720px;
  --side: max(20px, calc((100% - var(--max)) / 2));
  --section: clamp(44px, 5.5vw, 68px);
  --nav-h: 68px;
  --radius: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--nav-h); overflow-x: clip; }
body {
  margin: 0; overflow-x: clip;
  font: 400 var(--t-body)/1.65 var(--font);
  color: var(--ink); background: var(--white);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; }
h1, h2, h3 { font-weight: 500; margin: 0; letter-spacing: -.02em; }
h2 { font-size: var(--t-h2); line-height: 1.12; margin-bottom: 18px; }
h3 { font-size: 1.3rem; line-height: 1.3; font-weight: 500; }
p { margin: 0 0 1em; }
.lead { font-size: var(--t-lead); line-height: 1.45; color: var(--ink); }
[hidden] { display: none !important; }

/* Contenedor: todo el contenido de una sección vive en el mismo ancho */
.grid { width: min(var(--max), 100% - 40px); margin-inline: auto; }

/* Etiqueta en mayúsculas: siempre igual */
.overline, .facts dt, .reasons legend, .field > span {
  font-size: var(--t-label); font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}

/* ---------- Botones: naranja = comprar, índigo = otras acciones, línea = secundario ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 56px; padding: 0 28px; border-radius: 999px; border: 1.5px solid transparent;
  font: 500 1.0625rem/1 var(--font); text-decoration: none; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-sm { height: 42px; padding: 0 20px; font-size: 1rem; }
.btn-buy { background: var(--buy); color: #fff; }
.btn-buy:hover { background: var(--buy-hover); }
.btn-dark { background: var(--indigo); color: #fff; }
.btn-dark:hover { background: var(--indigo-2); }
.btn-dark:disabled { opacity: .5; cursor: wait; }
.btn-line { border-color: var(--ink); color: var(--ink); }
.btn-line:hover { background: var(--ink); color: #fff; }
.link { font-weight: 500; color: var(--indigo); text-decoration: none; border-bottom: 2px solid currentColor; padding-bottom: 1px; }
.link:hover { color: var(--buy); }

/* ---------- Navegación = índice ---------- */
.nav {
  position: fixed; inset: 0 0 auto; z-index: 40; height: var(--nav-h);
  background: rgba(245,239,230,.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .3s, background .3s;
}
.nav.scrolled { border-color: var(--line); background: rgba(255,255,255,.95); }
.nav-inner { height: 100%; display: flex; align-items: center; gap: 32px; padding-inline: var(--side); }
.nav-brand { font-weight: 600; font-size: 1rem; letter-spacing: .12em; text-transform: uppercase; text-decoration: none; margin-right: auto; color: var(--indigo); }
.nav-index { display: flex; gap: 24px; }
.nav-index a { font-size: 1rem; font-weight: 500; text-decoration: none; color: var(--ink-2); transition: color .2s; }
.nav-index a span { color: var(--ink-3); margin-right: 6px; font-variant-numeric: tabular-nums; font-weight: 400; }
.nav-index a:hover, .nav-index a.active { color: var(--indigo); }
.nav-index a.active span { color: var(--buy); }
.nav-toggle { display: none; }

/* ---------- Portada (fondo crema, como el papel) ---------- */
.cover { background: var(--cream); padding: calc(var(--nav-h) + clamp(24px, 3.5vw, 44px)) 0 0; }
.cover-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 48px; align-items: center; }
.cover .overline { color: var(--indigo); }
.cover h1 { font-size: var(--t-display); line-height: 1.02; letter-spacing: -.03em; margin: 16px 0 20px; color: var(--indigo); }
.cover-sub { font-size: var(--t-lead); line-height: 1.4; color: var(--ink-2); max-width: 30ch; margin-bottom: 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.cover-book { margin: 0; justify-self: end; }
.cover-book img {
  width: 100%; max-width: 330px; border-radius: 3px 8px 8px 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,.08), 0 28px 50px -18px rgba(31,29,92,.55);
}

.facts {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: clamp(28px, 4vw, 44px) auto 0;
  border-top: 1px solid var(--line);
}
.facts > div { padding: 20px 20px 24px 0; }
.facts > div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.facts dt { margin-bottom: 4px; }
.facts dd { margin: 0; font-size: 1.0625rem; font-weight: 500; }

/* ---------- Capítulos ---------- */
.chapter { padding-block: var(--section); }
#autor { background: var(--cream); }
.chapter-mark {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  font-size: var(--t-label); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--indigo);
}
.chapter-mark span {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--indigo); color: #fff; font-size: .875rem; letter-spacing: 0; font-variant-numeric: tabular-nums;
}
.chapter-body { max-width: var(--text); }
.chapter-body > p, .cols p, .author-text > p:not(.lead) { color: var(--ink-2); }
.cols { margin-top: 20px; }

/* Los tres temas: tarjetas en fila, se leen de un vistazo */
.themes { list-style: none; padding: 0; margin: 28px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; width: min(var(--max), 100vw - 40px); }
.themes li { padding: 24px; border-radius: var(--radius); background: var(--cream); }
.themes li > span { display: block; color: var(--buy); font-weight: 600; margin-bottom: 10px; }
.themes p { margin: 8px 0 0; color: var(--ink-2); font-size: 1.0625rem; line-height: 1.5; }

/* Cita: franja índigo, el cielo de la tapa */
.quote { background: var(--indigo); color: #fff; padding-block: clamp(40px, 5vw, 60px); }
.quote blockquote { margin: 0; max-width: 860px; }
.quote p { font-size: clamp(1.6rem, 3.2vw, 2.4rem); line-height: 1.3; font-weight: 400; letter-spacing: -.015em; margin: 0; }
.quote p::before { content: ""; display: block; width: 56px; height: 3px; background: var(--buy); margin-bottom: 18px; }

/* Autor */
#autor .chapter-body { max-width: none; }
.author { display: grid; grid-template-columns: 380px 1fr; gap: 48px; align-items: start; }
.author-photo { margin: 0; }
.author-photo img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: 50% 30%; border-radius: var(--radius); }
.author-text { max-width: var(--text); }
.author-text h2 { margin-bottom: 16px; }
.creds { list-style: none; padding: 0; margin: 24px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.creds li { padding: 8px 14px; border-radius: 999px; background: var(--white); font-size: 1rem; font-weight: 500; color: var(--indigo); }

/* Lectores */
#lectores .chapter-body { max-width: none; }
.testimonials { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.testimonial { margin: 0; padding: 22px 24px; border-radius: var(--radius); background: var(--cream); display: flex; flex-direction: column; justify-content: space-between; }
.testimonial blockquote { margin: 0 0 20px; font-size: 1.1875rem; line-height: 1.55; }
.testimonial blockquote::before { content: ""; display: block; width: 32px; height: 3px; background: var(--buy); margin-bottom: 16px; }
.testimonial figcaption { display: flex; align-items: center; gap: 12px; font-size: 1rem; }
.testimonial figcaption img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.testimonial figcaption b { display: block; font-weight: 600; color: var(--indigo); }
.testimonial figcaption small { color: var(--ink-3); font-size: .9375rem; }

/* Galería: todas las fotos con la misma proporción para que la grilla sea ordenada */
#galeria .chapter-body { max-width: none; }
.gallery { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 8px; }
.gallery button { all: unset; cursor: zoom-in; display: block; overflow: hidden; border-radius: 12px; background: var(--cream-2); aspect-ratio: 4 / 5; }
.gallery button:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
.gallery img { width: 100%; height: 100%; object-fit: cover; transition: transform .8s cubic-bezier(.2,.7,.2,1); }
.gallery button:hover img { transform: scale(1.04); }

/* Comprar: índigo con el resplandor naranja abajo, como la tapa */
.buy {
  color: #fff; padding-block: clamp(40px, 5vw, 60px);
  background: radial-gradient(ellipse 80% 120% at 50% 120%, rgba(240,84,30,.55), transparent 60%), var(--indigo);
}
.buy-grid { display: grid; grid-template-columns: 200px 1fr; gap: 48px; align-items: center; max-width: 860px; }
.buy-grid img { width: 100%; border-radius: 3px 6px 6px 3px; box-shadow: 0 20px 40px -12px rgba(0,0,0,.5); }
.buy h2 { margin-bottom: 12px; }
.buy p { color: rgba(255,255,255,.85); margin-bottom: 28px; max-width: 42ch; }

/* Capítulos con formulario (Lectores, Contacto): centrados, el formulario es el protagonista */
.chapter-center .chapter-mark { justify-content: center; }
.chapter-center .chapter-body { margin-inline: auto; text-align: center; }
.chapter-center .lead { color: var(--ink-2); max-width: 46ch; margin: 0 auto 22px; }
.chapter-center .form { text-align: left; max-width: var(--text); margin-inline: auto; }
.chapter-center .reasons { justify-content: center; }
.chapter-center .reasons legend { width: 100%; text-align: center; }
.chapter-center .form-end { justify-content: center; flex-direction: column; gap: 12px; }
.chapter-center .form-msg { text-align: center; }
.chapter-center .btn-dark { min-width: 220px; }

/* Redes del autor */
.socials { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; font-weight: 500; margin: 0; }
.socials span { color: var(--ink-3); font-weight: 400; }

/* Reseñas de ejemplo: solo las ve el admin logueado */
.testimonial.is-sample { position: relative; outline: 2px dashed rgba(240,84,30,.5); outline-offset: -2px; }
.sample-tag { align-self: flex-start; margin-bottom: 12px; font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--buy); }

/* Lectores: tarjetas de ancho normal, centradas */
/* Slider de reseñas: N por vista (--per), la pista se desplaza de a una tarjeta */
.slider { --per: 3; --gap: 16px; text-align: left; }
.slider-viewport { overflow: hidden; padding: 4px; margin: -4px; }
#lectores .slider-track { display: flex; gap: var(--gap); transition: transform .7s cubic-bezier(.4, 0, .2, 1); will-change: transform; touch-action: pan-y; }
.slider-track.centered { justify-content: center; }
.slider-track .testimonial { flex: 0 0 calc((100% - var(--gap) * (var(--per) - 1)) / var(--per)); min-width: 0; user-select: none; }
.slider-controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 20px; }
.slider-btn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--white); color: var(--indigo); cursor: pointer; display: grid; place-items: center; transition: border-color .2s, background .2s, color .2s; }
.slider-btn:hover { border-color: var(--indigo); background: var(--indigo); color: #fff; }
.slider-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.slider-dots { display: flex; gap: 8px; }
.slider-dots button { width: 10px; height: 10px; padding: 0; border: 0; border-radius: 5px; background: var(--line); cursor: pointer; transition: width .3s, background .3s; }
.slider-dots button[aria-selected=true] { width: 28px; background: var(--buy); }
.slider-btn:focus-visible, .slider-dots button:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
@media (max-width: 1000px) { .slider { --per: 2; } }
@media (max-width: 680px) { .slider { --per: 1; } }

/* Contacto */
#contacto { background: var(--white); }
.form { display: grid; gap: 18px; padding: 26px; border-radius: var(--radius); background: var(--cream); }
.reasons { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.reasons legend { margin-bottom: 12px; padding: 0; color: var(--ink-2); }
.reasons label { cursor: pointer; }
.reasons input { position: absolute; opacity: 0; pointer-events: none; }
.reasons span { display: inline-block; padding: 11px 18px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--white); font-size: 1rem; font-weight: 500; transition: all .2s; }
.reasons label:hover span { border-color: var(--indigo); }
.reasons input:checked + span { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.reasons input:focus-visible + span { outline: 3px solid var(--indigo); outline-offset: 2px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 22px 16px; }
.field { display: grid; gap: 6px; }
.field > span { color: var(--ink-2); }
.field input, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--white);
  padding: 13px 16px; font: 400 1.0625rem/1.4 var(--font); color: var(--ink); transition: border-color .2s;
}
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--indigo); }
.hp { position: absolute; left: -9999px; }
.form-end { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.form-msg { margin: 0; font-size: 1.0625rem; font-weight: 500; color: var(--indigo); }
.form-msg.error { color: #b3261e; }

/* Obligatorios y errores: el * en naranja; si un campo está mal, borde y mensaje en rojo */
.req { color: var(--buy); font-weight: 600; }
.form-note { margin: 0; font-size: .9375rem; color: var(--ink-3); }
.field > span .req { margin-left: 2px; }
.field-error { min-height: 0; font-size: .9375rem; font-weight: 500; color: #b3261e; line-height: 1.35; }
.field-error:empty { display: none; }
.field.invalid > span { color: #b3261e; }
.field.invalid input, .field.invalid textarea { border-color: #b3261e; background: #fff6f5; }
.field.invalid input:focus, .field.invalid textarea:focus { border-color: #b3261e; box-shadow: 0 0 0 3px rgba(179,38,30,.15); }

/* Footer */
.footer { background: var(--ink); color: rgba(255,255,255,.75); padding-block: 32px 100px; font-size: 1rem; }
.footer-grid { display: flex; flex-wrap: wrap; gap: 24px 48px; align-items: flex-start; }
.footer-grid > p:first-child { margin: 0 auto 0 0; }
.footer strong { font-weight: 600; color: #fff; }
.footer ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 24px; flex-wrap: wrap; }
.footer a { text-decoration: none; }
.footer a:hover { color: #fff; }
.copy { margin: 0; }

/* Barra de compra (solo celular) */
.buy-bar { display: none; }

/* Visor de fotos */
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; background: rgba(22,21,43,.95); }
.lightbox figure { margin: 0; display: grid; justify-items: center; gap: 14px; padding: 56px 0 24px; }
.lightbox img { max-height: 80vh; max-width: 100%; border-radius: 6px; }
.lightbox figcaption { font-size: 1rem; color: rgba(255,255,255,.8); min-height: 1.5em; }
.lb-btn { background: none; border: 0; font: 300 2.75rem/1 var(--font); color: #fff; cursor: pointer; height: 64px; }
.lb-close { position: absolute; top: 12px; right: 16px; }

/* Aparición suave */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity .7s ease, transform .7s cubic-bezier(.2,.7,.2,1); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Tablet ---------- */
@media (max-width: 1000px) {
  .nav-index { gap: 18px; }
  .nav-index a span { display: none; }
  .themes { grid-template-columns: 1fr; width: auto; }
  .author { grid-template-columns: 280px 1fr; gap: 32px; }
  .gallery { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  :root { --nav-h: 60px; --t-body: 1.125rem; }

  .nav-buy { display: none; }
  .nav-toggle {
    display: grid; gap: 6px; place-content: center; width: 44px; height: 44px; margin-right: -10px;
    background: none; border: 0; cursor: pointer; position: relative; z-index: 2;
  }
  .nav-toggle span { display: block; width: 24px; height: 2px; background: var(--indigo); transition: transform .3s; }
  .nav.open .nav-toggle span:first-child { transform: translateY(4px) rotate(45deg); }
  .nav.open .nav-toggle span:last-child { transform: translateY(-4px) rotate(-45deg); }
  .nav-index {
    position: fixed; inset: 0; height: 100vh; z-index: 1; flex-direction: column; justify-content: center; gap: 0;
    padding: 0 24px; background: var(--cream); opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  .nav-index a { font-size: 1.75rem; padding: 16px 0; border-bottom: 1px solid var(--line); color: var(--indigo); }
  .nav-index a span { display: inline; font-size: 1rem; margin-right: 14px; }
  .nav.open .nav-index { opacity: 1; pointer-events: auto; }

  .cover { padding-top: calc(var(--nav-h) + 24px); }
  .cover-grid { grid-template-columns: 1fr; gap: 28px; }
  .cover-book { order: -1; justify-self: center; }
  .cover-book img { max-width: 200px; }
  .cover h1 { margin-top: 10px; }
  .actions .btn { flex: 1 1 100%; }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts > div { padding: 16px 12px 16px 0; }
  .facts > div:nth-child(3) { padding-left: 0; border-left: 0; }
  .facts > div:nth-child(n+3) { border-top: 1px solid var(--line); }

  .row { grid-template-columns: 1fr; }
  .author { grid-template-columns: 1fr; gap: 24px; }
  .author-photo img { aspect-ratio: 1; max-height: 360px; }
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .buy-grid { grid-template-columns: 1fr; gap: 24px; }
  .buy-grid img { max-width: 120px; }
  .buy-grid .btn { width: 100%; }
  .form { padding: 22px 18px; }
  .footer-grid { flex-direction: column; }

  .buy-bar {
    position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 30;
    display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 10px;
    background: var(--indigo); color: #fff; border-radius: 16px; text-decoration: none; font-size: 1rem; font-weight: 500;
    box-shadow: 0 12px 32px -8px rgba(0,0,0,.4);
    transform: translateY(140%); transition: transform .35s cubic-bezier(.2,.7,.2,1);
  }
  .buy-bar.show { transform: none; }
  .buy-bar img { width: 30px; border-radius: 2px; }
  .buy-bar span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .buy-bar b { font-weight: 600; background: var(--buy); padding: 12px 18px; border-radius: 12px; }
  .lightbox { grid-template-columns: 44px 1fr 44px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}
