@font-face { font-family: Caveat; font-weight: 500; src: url(/fonts/caveat-latin-500-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Caveat; font-weight: 700; src: url(/fonts/caveat-latin-700-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Montserrat; font-weight: 500; src: url(/fonts/montserrat-latin-500-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Montserrat; font-weight: 600; src: url(/fonts/montserrat-latin-600-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Montserrat; font-weight: 700; src: url(/fonts/montserrat-latin-700-normal.woff2) format("woff2"); font-display: swap; }

:root {
  --wine: #6d1a2a;
  --wine-dark: #2b0f14;
  --rose: #e8798f;
  --gold: #e7c27d;
  --paper: #fbf5ea;
  --ink: #3a2a26;
  --muted: #8b7a72;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Montserrat, system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 20%, #4a1620 0%, var(--wine-dark) 60%, #170709 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }

/* ---------- Entrada ---------- */
.login-card { width: min(360px, 100%); background: var(--paper); border-radius: 18px; padding: 36px 28px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-family: Caveat; font-size: 44px; color: var(--wine); line-height: 1; }
.login-card p { color: var(--muted); font-size: 14px; }
.heart { width: 54px; height: 54px; fill: var(--rose); margin: 0 auto; animation: beat 1.4s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }

input, textarea { width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border: 1.5px solid #e0d4c4; border-radius: 12px; background: #fff; color: var(--ink); }
input:focus, textarea:focus { outline: none; border-color: var(--rose); }
.btn { font: inherit; font-weight: 600; font-size: 15px; padding: 12px 18px; border-radius: 999px; border: 1.5px solid #e0d4c4; background: #fff; color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn:disabled { opacity: .6; }
.error { color: #b3261e; font-size: 14px; }

/* ---------- Libro ---------- */
#book-holder { width: 100%; max-width: 1100px; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding-top: 12px; }
.book { margin: 0 auto; }

.page { background: var(--paper); overflow: hidden; }
.page .inner { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 6% 7% 5%; }
/* Rayitas suaves de papel y sombra hacia el lomo */
.page.paper .inner { background:
  linear-gradient(90deg, rgba(0,0,0,.06), transparent 8%),
  repeating-linear-gradient(transparent 0 27px, rgba(160,130,100,.08) 27px 28px); }

.page.cover .inner, .page.back .inner {
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,.12), transparent 45%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.05) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, #8a2236, var(--wine) 50%, #4a0f1c);
  align-items: center; justify-content: center; text-align: center; color: var(--gold);
  border: 2px solid rgba(231,194,125,.35); }
.page.cover .frame { position: absolute; inset: 5%; border: 1.5px solid rgba(231,194,125,.6); border-radius: 6px; pointer-events: none; }
.page.cover h1 { font-family: Caveat; font-weight: 700; font-size: clamp(40px, 11cqw, 76px); line-height: .95; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.page.cover p { font-size: clamp(11px, 2.6cqw, 15px); letter-spacing: 3px; text-transform: uppercase; margin-top: 18px; opacity: .85; }
.page.cover .heart { width: 22%; height: auto; fill: var(--gold); margin-bottom: 8%; animation: none; filter: drop-shadow(0 2px 0 rgba(0,0,0,.3)); }
.page.back .heart { width: 14%; height: auto; fill: var(--gold); opacity: .7; animation: none; }
.page { container-type: inline-size; }

.memory-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.memory-date { font-size: clamp(10px, 3cqw, 14px); font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--wine); }
.memory-place { font-size: clamp(10px, 2.8cqw, 13px); color: var(--muted); margin-top: 2px; }
.menu { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px; cursor: pointer; }

.photos { flex: 1; min-height: 0; display: grid; gap: 4%; margin: 5% 0 4%; }
.photos.n1 { grid-template: 1fr / 1fr; }
.photos.n2 { grid-template: 1fr 1fr / 1fr; }
.photos.n3 { grid-template: 1.2fr 1fr / 1fr 1fr; }
.photos.n3 .photo:first-child { grid-column: 1 / 3; }
.photos.n4 { grid-template: 1fr 1fr / 1fr 1fr; }
/* Estilo polaroid con un pedacito de cinta */
.photo { position: relative; min-height: 0; border: 0; padding: 3.5%; padding-bottom: 7%; background: #fff; box-shadow: 0 3px 10px rgba(60,30,20,.25); cursor: zoom-in; }
.photo:nth-child(odd) { transform: rotate(-1.2deg); }
.photo:nth-child(even) { transform: rotate(1.4deg); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; background: #eee; }
.photo::before { content: ""; position: absolute; top: -8px; left: 50%; width: 34%; height: 16px; transform: translateX(-50%) rotate(-3deg); background: rgba(232,121,143,.45); z-index: 1; }

.memory-message { font-family: Caveat; font-weight: 500; font-size: clamp(18px, 6cqw, 28px); line-height: 1.1; color: var(--ink); max-height: 30%; overflow: hidden; }
.page-number { position: absolute; bottom: 2.5%; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }

.page.end .inner { align-items: center; justify-content: center; text-align: center; gap: 16px; }
.page.end h2 { font-family: Caveat; font-size: clamp(34px, 10cqw, 56px); color: var(--wine); line-height: 1; }
.page.end p { color: var(--muted); font-size: clamp(12px, 3.4cqw, 15px); }
.page.end .heart { width: 22%; height: auto; }

/* ---------- Controles ---------- */
.controls { display: flex; align-items: center; gap: 18px; padding: 14px 0 18px; color: #f3dfe3; font-size: 14px; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; }
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--rose); color: #fff; font-size: 34px; line-height: 1; box-shadow: 0 10px 30px rgba(0,0,0,.45); cursor: pointer; z-index: 10; }

/* ---------- Editor ---------- */
dialog { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100dvh; }
dialog::backdrop { background: rgba(20,5,8,.7); }
#editor form { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; background: var(--paper); border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
#editor h2 { font-family: Caveat; font-size: 34px; color: var(--wine); line-height: 1; }
#editor label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); position: relative; }
.photo-picker { border: 2px dashed #d9c7b3; border-radius: 14px; padding: 18px; text-align: center; cursor: pointer; color: var(--wine) !important; font-size: 15px !important; }
.photo-picker input { display: none; }
#previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
#previews:empty { display: none; }
.preview { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; cursor: pointer; }
.counter { position: absolute; right: 10px; bottom: 8px; font-weight: 500; }
.note { font-size: 13px; color: var(--muted); background: #f3eadb; padding: 10px 12px; border-radius: 10px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; }

#options { margin: auto auto 0; width: 100%; max-width: 440px; }
.sheet { background: var(--paper); border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.btn.danger { color: #b3261e; border-color: #f0c8c4; }

#viewer { margin: auto; }
#viewer img { max-width: 96vw; max-height: 92dvh; display: block; border-radius: 6px; }
