:root {
  --gold: #c9a45c;
  --gold-soft: #e3cb94;
  --leather: #4a2a1e;
  --leather-dark: #2e1810;
  --paper: #f7f0e1;
  --ink: #4a3b2e;
  --bg: #16110e;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --script: 'Pinyon Script', 'Cormorant Garamond', cursive;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body {
  font-family: var(--serif);
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 40%, #3a2a20 0%, #1d1511 55%, #0f0b09 100%);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}

.stage {
  position: fixed; inset: 0 0 64px 0;
  display: flex; align-items: center; justify-content: center;
  padding: 14px 10px 6px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.book { width: 100%; height: 100%; max-width: 1440px; }
.stf__parent { margin: 0 auto; }
.empty { color: var(--gold-soft); text-align: center; font-size: 1.4rem; line-height: 1.6; }

/* ---------- Páginas ---------- */
.page { background: var(--paper); overflow: hidden; }
.page-in { position: absolute; inset: 0; }
.page.paper {
  background:
    radial-gradient(ellipse at 50% 50%, rgba(255,255,255,.55), rgba(0,0,0,0) 70%),
    repeating-linear-gradient(0deg, rgba(120,90,50,.025) 0 2px, rgba(0,0,0,0) 2px 4px),
    var(--paper);
}
/* sombra del lomo: página izquierda (par en índice base 0 impar) y derecha */
.page.--left.paper::after, .page.--right.paper::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 14%; pointer-events: none;
}
.page.--left.paper::after { right: 0; background: linear-gradient(to left, rgba(60,35,10,.22), transparent); }
.page.--right.paper::after { left: 0; background: linear-gradient(to right, rgba(60,35,10,.22), transparent); }
.pn {
  position: absolute; bottom: 2.2%; left: 0; right: 0; text-align: center;
  font-size: clamp(10px, 1.6vmin, 14px); color: rgba(74,59,46,.55); letter-spacing: .15em;
}

/* ---------- Tapas ---------- */
.page.cover {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.08), transparent 55%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.07) 0 1px, transparent 1px 3px),
    linear-gradient(135deg, #5b3425, var(--leather) 45%, var(--leather-dark));
  box-shadow: inset 0 0 40px rgba(0,0,0,.55);
}
.cover-in {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 14%;
  color: var(--gold);
}
.cover .frame {
  position: absolute; inset: 6%; border: 1px solid var(--gold);
  box-shadow: inset 0 0 0 5px rgba(0,0,0,0), inset 0 0 0 6px rgba(201,164,92,.5);
  border-radius: 2px; opacity: .85;
}
.c-sub { font-size: clamp(12px, 2.4vmin, 20px); letter-spacing: .35em; text-transform: uppercase; margin: 0 0 6%; }
.c-names {
  font-family: var(--script); font-weight: 400; margin: 0;
  font-size: clamp(24px, 5.6vmin, 58px); line-height: 1.15;
  background: linear-gradient(180deg, #f1dca4, var(--gold) 55%, #9c7a38);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.c-names span { display: block; font-size: .55em; margin: .1em 0; opacity: .9; }
.c-date { font-size: clamp(13px, 2.8vmin, 22px); letter-spacing: .3em; text-transform: uppercase; margin: 6% 0 0; }
.orn { width: 42%; height: 14px; margin: 7% 0 0; position: relative; }
.orn::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: linear-gradient(90deg, transparent, currentColor, transparent); }
.orn::after { content: '\2766'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -52%); padding: 0 .5em; font-size: 18px; line-height: 1; background: var(--orn-bg, transparent); }
.cover .orn::after { background: transparent; }
.orn.small { width: 36%; margin: 0; color: var(--gold); --orn-bg: var(--paper); }

/* ---------- Páginas de texto ---------- */
.blank { position: absolute; inset: 0; }
.dedic, .title-page, .thanks {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 16%; gap: 6%;
}
.dedic p { font-size: clamp(16px, 3.4vmin, 28px); font-style: italic; line-height: 1.5; margin: 0; }
.title-page .num { font-size: clamp(14px, 2.6vmin, 22px); letter-spacing: .4em; color: var(--gold); }
.title-page h2 { font-family: var(--script); font-weight: 400; margin: 0; font-size: clamp(34px, 8vmin, 70px); color: var(--leather); line-height: 1.1; }
.title-page .cnt { font-size: clamp(11px, 2vmin, 16px); letter-spacing: .25em; text-transform: uppercase; opacity: .6; }
.thanks h2 { font-family: var(--script); font-weight: 400; margin: 0; font-size: clamp(34px, 8vmin, 66px); color: var(--leather); }
.thanks p { margin: 0; font-size: clamp(14px, 2.8vmin, 22px); line-height: 1.55; }
.thanks .sign { font-family: var(--script); font-size: clamp(22px, 4.6vmin, 38px); color: var(--leather); }

/* ---------- Fotos ---------- */
.grid { position: absolute; inset: 6% 7%; display: grid; gap: 3.5%; }
.g1 { grid-template: 1fr / 1fr; place-items: center; }
.g2c { grid-template: 1fr 1fr / 1fr; }
.g2r { grid-template: 1fr / 1fr 1fr; }
.g3 { grid-template: 1.25fr 1fr / 1fr 1fr; }
.g3 .hero { grid-column: 1 / -1; }
.ph {
  margin: 0; position: relative; overflow: hidden; min-height: 0; min-width: 0;
  background: #e8dcc4; cursor: zoom-in;
  border: clamp(3px, .9vmin, 7px) solid #fffdf7;
  box-shadow: 0 3px 10px rgba(60,35,10,.35), 0 0 0 1px rgba(60,35,10,.12);
}
.g1 .ph { width: 100%; height: 100%; }
.ph img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block; pointer-events: none; opacity: 0; transition: opacity .5s; }
.ph img[src] { opacity: 1; }

/* ---------- Controles ---------- */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; height: 64px;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  z-index: 5;
}
.controls[hidden] { display: none; }
.controls button {
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(201,164,92,.55); background: rgba(30,20,14,.7); color: var(--gold-soft);
  font-size: 24px; line-height: 1; display: grid; place-items: center; padding: 0;
  transition: background .2s, transform .15s;
}
.controls button:hover:not(:disabled) { background: rgba(201,164,92,.25); }
.controls button:active:not(:disabled) { transform: scale(.92); }
.controls button:disabled { opacity: .3; cursor: default; }
.controls button[hidden] { display: none; }
#music.on { background: var(--gold); color: #2a1a10; animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(201,164,92,.2); } }
.counter { min-width: 84px; text-align: center; color: var(--gold-soft); font-size: 17px; letter-spacing: .12em; }
.sep { width: 1px; height: 24px; background: rgba(201,164,92,.35); margin: 0 4px; }
.hint {
  position: fixed; left: 0; right: 0; bottom: 74px; text-align: center; margin: 0; z-index: 4;
  color: var(--gold-soft); font-size: 15px; letter-spacing: .08em; pointer-events: none;
  text-shadow: 0 1px 4px #000; transition: opacity .8s;
}
.hint.off { opacity: 0; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 20; background: rgba(8,5,3,.94);
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 94vw; max-height: 92vh; object-fit: contain; box-shadow: 0 10px 50px #000; border: 6px solid #fffdf7; background: #222; }
.lightbox button { position: absolute; background: none; border: 0; color: var(--gold-soft); cursor: pointer; font-size: 54px; line-height: 1; padding: 10px 16px; opacity: .85; }
.lightbox button:hover { opacity: 1; }
.lb-close { top: 4px; right: 8px; font-size: 44px !important; }
.lb-nav { top: 50%; transform: translateY(-50%); }
.lb-prev { left: 4px; }
.lb-next { right: 4px; }

@media (max-width: 640px) {
  .stage { padding: 8px 4px 4px; }
  .lb-nav { font-size: 40px !important; }
  .counter { min-width: 70px; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) { #music.on { animation: none; } }

/* Lupa para ampliar */
.book { transition: transform .8s ease; }
.zoom {
  position: absolute; right: 6px; bottom: 6px; width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 0; background: rgba(30,20,14,.55); color: #fff; font-size: 16px; line-height: 1; cursor: zoom-in;
  display: grid; place-items: center; opacity: .75; transition: opacity .2s, background .2s;
}
.zoom:hover { opacity: 1; background: rgba(30,20,14,.85); }
.ph { cursor: inherit; }

/* Fotos completas, sin recorte: cada marco toma la proporción real de la foto */
.g3p { grid-template: 1fr / 1fr 1fr 1fr; }
.ph {
  display: flex; align-items: center; justify-content: center;
  background: none; border: 0; box-shadow: none; overflow: visible;
}
.ph img {
  width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: fill;
  border: clamp(3px, .9vmin, 7px) solid #fffdf7;
  box-shadow: 0 3px 10px rgba(60,35,10,.35), 0 0 0 1px rgba(60,35,10,.12);
  background: #e8dcc4;
}
.zoom { top: 8px; left: 8px; right: auto; bottom: auto; }

/* Logo en tapas */
.c-logo { width: 72%; height: auto; display: block; margin: 5% 0 4%; filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); -webkit-user-drag: none; }
.c-full { margin: 0; font-size: clamp(11px, 2.1vmin, 17px); letter-spacing: .28em; text-transform: uppercase; line-height: 1.7; color: var(--gold-soft); }
.c-logo + .c-full + .c-date { margin-top: 5%; }

/* Logo en tapas */
.c-logo { width: 78%; height: auto; display: block; margin: 4% 0; filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); pointer-events: none; }
.c-full { margin: 0; font-size: clamp(10px, 1.9vmin, 16px); letter-spacing: .26em; text-transform: uppercase; line-height: 1.7; color: var(--gold-soft); }
.c-full + .c-date { margin-top: 5%; }

/* Marca de agua con el logo en las hojas */
.page.paper.wm::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: var(--logo) center / 62% auto no-repeat;
  opacity: .13;
}

/* Celdas posicionadas por el algoritmo de distribución */
.grid { display: block; }
.grid .ph { position: absolute; }
