/* ══════════════════════════════════════════════════════════════════
   RECETARIO PATRIMONIAL — style.css
   Diseño: Mobile-first, 100% moderno, dark editorial aesthetic
   ═════════════════════════════════════════════════════════════════ */

/* ── VARIABLES ──────────────────────────────────────────────────── */
:root {
  --bg-dark: #0f0d0a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --glass-bg: rgba(15, 13, 10, 0.72);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-shadow: rgba(0, 0, 0, 0.6);
  --accent: #d4a853;
  --accent-glow: rgba(212, 168, 83, 0.25);
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-muted: rgba(255, 255, 255, 0.45);
  --dock-height: 72px;
  --dock-radius: 24px;
  --page-shadow: 0 32px 80px rgba(0,0,0,0.7), 0 4px 16px rgba(0,0,0,0.5);
  --transition-page: 420ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── RESET & BASE ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── AMBIENT BACKGROUND ─────────────────────────────────────────── */
#ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--bg-dark);
}

.ambient-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  transition: background 1.8s ease, transform 2.5s ease;
  will-change: transform, background;
}

#blob1 {
  width: 70vw; height: 70vw;
  top: -20vw; left: -15vw;
  background: radial-gradient(circle, #d4a853, #8b4513);
}

#blob2 {
  width: 60vw; height: 60vw;
  bottom: -15vw; right: -15vw;
  background: radial-gradient(circle, #6b3d0e, #d4a853);
}

/* ── LOADING SCREEN ─────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  gap: 28px;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-book {
  position: relative;
  width: 56px;
  height: 44px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
}

.loader-page {
  width: 14px;
  height: 44px;
  background: var(--accent);
  border-radius: 3px;
  transform-origin: bottom center;
  animation: bookBounce 1.2s ease-in-out infinite;
  opacity: 0.8;
}

.loader-page:nth-child(1) { animation-delay: 0s; height: 28px; }
.loader-page:nth-child(2) { animation-delay: 0.15s; height: 44px; }
.loader-page:nth-child(3) { animation-delay: 0.30s; height: 34px; }

@keyframes bookBounce {
  0%, 100% { transform: scaleY(1); opacity: 0.6; }
  50% { transform: scaleY(1.25); opacity: 1; }
}

.loader-text {
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── BOOK VIEWER ────────────────────────────────────────────────── */
#book-viewer {
  position: fixed;
  inset: 0;
  bottom: calc(var(--dock-height) + 16px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── TOUCH SHIELD (anti-descarga) ───────────────────────────────── */
#touch-shield {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: transparent;
  -webkit-touch-callout: none;
  touch-action: none;
  /* Pointer events pass-through habilitado solo para el swiper */
  pointer-events: none;
}

/* ── SWIPER ─────────────────────────────────────────────────────── */
.swiper {
  width: 100%;
  height: 100%;
  z-index: 10;
}

/* ── SWIPER SLIDES ──────────────────────────────────────────────── */
.swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  /* overflow:visible — con fade effect el slide inactivo tiene opacity:0,
     así que nunca se ve aunque la imagen se salga del slide al hacer zoom */
  overflow: visible;
  background: transparent;
}

/* Imagen de cada página */
.swiper-slide img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: var(--page-shadow);
  /* transform-origin siempre al centro — el zoom se hace desde el centro */
  transform-origin: center center;
  will-change: transform;
  /* Protección anti-descarga */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;   /* los eventos van al slide, no a la imagen */
}

/* El slide activo sí recibe eventos táctiles */
.swiper-slide-active {
  pointer-events: auto;
}

/* Slides inactivos no reciben eventos */
.swiper-slide:not(.swiper-slide-active) {
  pointer-events: none;
}

/* Animación de entrada sutil.
   OJO: anima la propiedad individual `scale`, NO `transform`.
   Una animación con fill:both gana en la cascada al estilo inline, así que
   si aquí se animara `transform` el zoom (que usa transform inline) quedaría
   anulado mientras el slide estuviera activo. `scale` compone con `transform`. */
.swiper-slide-active img {
  animation: pageEnter 0.32s ease both;
}
@keyframes pageEnter {
  from { opacity: 0.4; scale: 0.97; }
  to   { opacity: 1;   scale: 1; }
}

/* ── EDGE SHADOWS ───────────────────────────────────────────────── */
.edge-shadow {
  position: absolute;
  top: 0; bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 15;
}

.edge-left {
  left: 0;
  background: linear-gradient(to right, rgba(15,13,10,0.5), transparent);
}

.edge-right {
  right: 0;
  background: linear-gradient(to left, rgba(15,13,10,0.5), transparent);
}

/* ── DOCK FLOTANTE ──────────────────────────────────────────────── */
#dock {
  position: fixed;
  bottom: 20px;
  left: 16px;
  right: 16px;
  height: var(--dock-height);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-radius: var(--dock-radius);
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 40px var(--glass-shadow), 0 1px 0 rgba(255,255,255,0.05) inset;
  /* Safe area para iPhones con notch */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Botones del dock */
.dock-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
  color: var(--text-primary);
}

.dock-btn svg {
  width: 18px;
  height: 18px;
}

.dock-btn:active {
  background: rgba(212, 168, 83, 0.2);
  transform: scale(0.92);
}

/* Contador de páginas */
.page-counter {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#current-page { color: var(--accent); }
.separator { color: var(--text-muted); font-weight: 300; }
#total-pages { color: var(--text-muted); }

/* Barra de progreso */
#progress-track {
  position: relative;
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  cursor: pointer;
  touch-action: none;
}

#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f0c060);
  border-radius: 8px;
  transition: width 0.3s ease;
  width: 0%;
}

#progress-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid rgba(15,13,10,0.8);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-glow);
  transition: left 0.3s ease, transform 0.15s ease;
  left: 0%;
}

#progress-thumb:active,
#progress-track:active #progress-thumb {
  transform: translate(-50%, -50%) scale(1.4);
}

/* ── ONDAS DE MÚSICA ─────────────────────────────────────────────── */
.music-waves {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 2px;
  align-items: flex-end;
  height: 6px;
}

.music-waves.active { display: flex; }

.music-waves span {
  width: 2px;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  animation: waveBar 0.8s ease-in-out infinite;
}

.music-waves span:nth-child(1) { animation-delay: 0s; }
.music-waves span:nth-child(2) { animation-delay: 0.15s; }
.music-waves span:nth-child(3) { animation-delay: 0.30s; }

@keyframes waveBar {
  0%, 100% { height: 3px; opacity: 0.5; }
  50% { height: 7px; opacity: 1; }
}

/* ── PANEL ÍNDICE ───────────────────────────────────────────────── */
#index-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

#index-panel {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  z-index: 210;
  max-height: 75vh;
  background: rgba(18, 16, 12, 0.97);
  backdrop-filter: blur(32px) saturate(2);
  -webkit-backdrop-filter: blur(32px) saturate(2);
  border-top: 1px solid var(--glass-border);
  border-radius: 28px 28px 0 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), visibility 0.4s ease;
  box-shadow: 0 -20px 60px rgba(0,0,0,0.7);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.panel-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#index-panel.panel-hidden { transform: translateY(100%); }
#index-panel:not(.panel-hidden) { transform: translateY(0); opacity: 1; visibility: visible; pointer-events: all; }
#index-backdrop:not(.panel-hidden) { opacity: 1; visibility: visible; pointer-events: all; }

.index-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.index-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-transform: uppercase;
}

.close-btn {
  width: 32px; height: 32px;
  border: none;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  transition: background 0.2s;
}

.close-btn svg { width: 14px; height: 14px; }
.close-btn:active { background: rgba(255,255,255,0.15); }

#index-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.index-thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  /* Técnica padding-top para relación A5 (10:14 = 140%) — compatible 100% navegadores */
  padding-top: 140%;
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  border: 1.5px solid transparent;
}

.index-thumb.active-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.index-thumb:active { transform: scale(0.95); }

/* La imagen se coloca absoluta DENTRO del contenedor de padding-top */
.index-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.index-page-num {
  position: absolute;
  bottom: 5px;
  right: 7px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  /* z-index para que quede sobre la imagen */
  z-index: 1;
}

/* ── SWIPER SLIDE + ZOOM ─────────────────────────────────────────── */


/* ── INDICADOR DE ZOOM (hint de doble tap) ───────────────────────── */
#zoom-hint {
  position: fixed;
  bottom: calc(var(--dock-height) + 28px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(15,13,10,0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(212,168,83,0.3);
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}

#zoom-hint.visible {
  opacity: 1;
}

/* ── LANDSCAPE LOCK NOTICE ──────────────────────────────────────── */
#landscape-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg-dark);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 32px;
}

@media (orientation: landscape) and (max-height: 500px) {
  #landscape-notice { display: flex; }
  #book-viewer, #dock { display: none; }
}

#landscape-notice svg {
  width: 56px; height: 56px;
  color: var(--accent);
  opacity: 0.7;
}

#landscape-notice p {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 260px;
  line-height: 1.6;
}

/* ── SCROLLBAR PERSONALIZADO ────────────────────────────────────── */
#index-grid::-webkit-scrollbar { width: 3px; }
#index-grid::-webkit-scrollbar-track { background: transparent; }
#index-grid::-webkit-scrollbar-thumb { background: rgba(212,168,83,0.3); border-radius: 4px; }
