/* ==========================================================
   Vintage Photo Album
   ========================================================== */
:root {
  --pw: 420px;            /* chiều rộng 1 trang (JS ghi đè) */
  --ph: 580px;            /* chiều cao trang  (JS ghi đè) */
  --flip: 1000ms;

  --paper: #eeebe3;
  --paper-edge: rgba(70, 65, 58, .22);
  --ink: #2c2a28;
  --ink-soft: #5c5853;
  --leather-1: #5b3a72;
  --leather-2: #432a57;
  --leather-3: #271834;
  --gold-1: #f7f7f5;
  --gold-2: #8f9198;
  --gold-3: #d3d5d9;

  --noise: url("noise.png?v=7");
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { height: 100dvh; -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-text-size-adjust: 100%; }

body {
  font-family: "EB Garamond", Georgia, serif;
  color: #dcdad6;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 244, 225, .09), transparent 55%),
    radial-gradient(ellipse at center, #2b2230 0%, #151018 60%, #070508 100%);
  -webkit-user-select: none;
  user-select: none;
}
body::before {               /* hạt nhiễu phim cũ */
  content: "";
  position: fixed; inset: 0;
  background: var(--noise);
  opacity: .35;
  pointer-events: none;
}

.scene {
  position: relative;
  width: 100%;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

/* ---------- Book geometry ---------- */
.stage { position: relative; }
.scaler {
  position: absolute; top: 0; left: 0;
  width: calc(var(--pw) * 2);
  height: var(--ph);
  transform-origin: 0 0;
}
.book {
  position: relative;
  width: 100%; height: 100%;
  transition: transform var(--flip) cubic-bezier(.645, .045, .355, 1);
}

.leaf {
  position: absolute;
  top: 0; left: 50%;
  width: 50%; height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transform: perspective(2600px) rotateY(0deg);
  transition: transform var(--flip) cubic-bezier(.645, .045, .355, 1);
  cursor: pointer;
}
.leaf.flipped { transform: perspective(2600px) rotateY(-180deg); }

/* Ruột album nhỏ hơn bìa một chút */
.leaf.inner { top: 10px; height: calc(100% - 20px); width: calc(50% - 12px); }

.face {
  position: absolute; inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); }

/* Bóng đổ khi đang lật */
.face::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity calc(var(--flip) / 2) ease;
}
.face.front::after { background: linear-gradient(to left, rgba(0,0,0,.28), transparent 55%); }
.face.back::after  { background: linear-gradient(to right, rgba(0,0,0,.28), transparent 55%); }
.leaf.turning .face::after { opacity: 1; }

/* ---------- Paper pages ---------- */
.page {
  background:
    radial-gradient(circle at 82% 14%, rgba(110, 100, 85, .07) 0 18px, transparent 40px),
    radial-gradient(circle at 18% 88%, rgba(110, 100, 85, .06) 0 12px, transparent 34px),
    radial-gradient(ellipse at center, transparent 58%, var(--paper-edge) 100%),
    var(--noise),
    var(--paper);
  color: var(--ink);
}
.face.front.page { border-radius: 0 3px 3px 0; box-shadow: 2px 3px 8px rgba(0,0,0,.35); }
.face.back.page  { border-radius: 3px 0 0 3px; box-shadow: -2px 3px 8px rgba(0,0,0,.35); }
/* Rãnh gáy sách */
.face.front.page::before,
.face.back.page::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 46px; pointer-events: none; z-index: 2;
}
.face.front.page::before { left: 0;  background: linear-gradient(to right, rgba(30,28,25,.28), rgba(30,28,25,.07) 40%, transparent); }
.face.back.page::before  { right: 0; background: linear-gradient(to left,  rgba(30,28,25,.28), rgba(30,28,25,.07) 40%, transparent); }

.page-inner {
  position: absolute; inset: 0;
  padding: 38px 34px 30px;
  display: flex; flex-direction: column;
}
.face.front .page-inner { padding-left: 44px; }
.face.back  .page-inner { padding-right: 44px; }

.page-title {
  font-family: "Dancing Script", cursive;
  font-weight: 700;
  font-size: 30px;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 12px;
}
.folio {
  margin-top: 14px;
  text-align: center;
  font-style: italic;
  font-size: 14px;
  letter-spacing: .15em;
  color: var(--ink-soft);
  opacity: .8;
}

/* ---------- Photo layouts ---------- */
.layout { flex: 1; min-height: 0; display: grid; gap: 22px; }
.layout-single { grid-template-rows: 1fr; padding: 16px 18px 6px; }
.layout-double { grid-template-rows: 1fr 1fr; padding: 4px 30px; }
.layout-grid   { grid-template: 1fr 1fr / 1fr 1fr; gap: 18px; }
.layout-trio   { grid-template: 1.15fr 1fr / 1fr 1fr; gap: 18px; }
.layout-trio .photo:first-child { grid-column: 1 / -1; }

.photo {
  position: relative;
  min-height: 0;
  display: flex; flex-direction: column;
  padding: 9px 9px 0;
  background: #fbfaf7;
  box-shadow: 0 1px 1px rgba(0,0,0,.15), 0 6px 14px rgba(20,18,15,.28);
}
.photo.t-l { transform: rotate(-1.6deg); }
.photo.t-r { transform: rotate(1.4deg); }
.photo.t-0 { transform: rotate(-.4deg); }

.shot { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #cfccc5; }
.shot img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(.2) sepia(.08) contrast(.97);
}
.photo figcaption {
  font-family: "Dancing Script", cursive;
  font-size: 19px;
  color: #45413d;
  text-align: center;
  line-height: 1.1;
  padding: 6px 4px 8px;
  min-height: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo figcaption:empty { padding: 0 0 9px; min-height: 0; }

/* Khung giữ chỗ */
.ph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: rgba(60, 57, 52, .6);
  background:
    repeating-linear-gradient(45deg, rgba(60,55,50,.05) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, #e2dfd8, #c6c1b7);
  outline: 1px dashed rgba(70, 65, 58, .45);
  outline-offset: -8px;
  font-style: italic;
  font-size: 15px;
}
.ph svg { width: 34px; height: 34px; opacity: .7; }

/* Góc dán ảnh kiểu cũ */
.pc {
  position: absolute; width: 26px; height: 26px; z-index: 3;
  background: linear-gradient(135deg, #2b2119, #46372a);
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.pc.tl { top: -5px; left: -5px;   clip-path: polygon(0 0, 100% 0, 0 100%); }
.pc.tr { top: -5px; right: -5px;  clip-path: polygon(0 0, 100% 0, 100% 100%); }
.pc.bl { bottom: -5px; left: -5px;  clip-path: polygon(0 0, 100% 100%, 0 100%); }
.pc.br { bottom: -5px; right: -5px; clip-path: polygon(100% 0, 100% 100%, 0 100%); }

/* Băng keo giấy */
.tape {
  position: absolute; top: -12px; left: 50%; z-index: 3;
  width: 92px; height: 26px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(236, 222, 184, .78);
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
  -webkit-mask: linear-gradient(90deg, transparent 0 2px, #000 2px calc(100% - 2px), transparent 0);
  mask: linear-gradient(90deg, transparent 0 2px, #000 2px calc(100% - 2px), transparent 0);
}

/* ---------- Text / title pages ---------- */
.text-page, .title-page {
  align-items: center; justify-content: center; text-align: center;
}
.text-page h2 {
  font-family: "Playfair Display", serif;
  font-weight: 500;
  font-style: italic;
  font-size: 40px;
  color: var(--ink);
}
.text-page p, .title-page .dedication {
  max-width: 270px;
  font-size: 19px;
  font-style: italic;
  line-height: 1.5;
  color: var(--ink-soft);
}
.orn { font-size: 34px; color: var(--ink-soft); opacity: .75; line-height: 1; }
.orn.small { font-size: 14px; letter-spacing: .6em; margin-top: 22px; }
.rule {
  width: 120px; height: 9px; margin: 16px auto 18px;
  border-top: 1px solid rgba(50,48,45,.45);
  border-bottom: 1px solid rgba(50,48,45,.25);
}
.text-page .folio, .title-page .folio { position: absolute; bottom: 30px; left: 0; right: 0; }

.title-page .kicker {
  font-size: 14px; letter-spacing: .4em; text-transform: uppercase; color: var(--ink-soft);
}
.title-page h1 { font-size: 42px !important;
  font-family: "Playfair Display", serif; font-weight: 700;
  font-size: 54px; color: var(--ink); margin: 10px 0 2px;
}
.title-page .year { margin-top: 26px; font-size: 15px; letter-spacing: .3em; color: var(--ink-soft); }

/* ---------- Leather covers ---------- */
.leather {
  background:
    radial-gradient(ellipse at 28% 18%, rgba(255, 255, 255, .07), transparent 55%),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.45) 100%),
    linear-gradient(rgba(20,6,30,.2), rgba(20,6,30,.2)),
    var(--noise),
    linear-gradient(135deg, var(--leather-1), var(--leather-2) 55%, var(--leather-3));
  color: var(--gold-3);
}
.face.front.leather { border-radius: 2px 8px 8px 2px; box-shadow: 0 22px 45px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.4); }
.face.back.leather  { border-radius: 8px 2px 2px 8px; box-shadow: 0 22px 45px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.4); }

/* Gáy bìa */
.cover-front::before, .cover-back::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 34px; z-index: 1;
}
.cover-front::before {
  left: 0;
  background: linear-gradient(to right, rgba(0,0,0,.55), rgba(255,255,255,.06) 55%, rgba(0,0,0,.35) 85%, transparent);
}
.cover-back::before {
  right: 0;
  background: linear-gradient(to left, rgba(0,0,0,.55), rgba(255,255,255,.06) 55%, rgba(0,0,0,.35) 85%, transparent);
}

.cover-frame {
  position: absolute; inset: 34px 30px 34px 52px;
  border: 2px solid rgba(200, 202, 207, .6);
  outline: 1px solid rgba(200, 202, 207, .32);
  outline-offset: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35), 0 0 0 1px rgba(0,0,0,.35);
}
.cover-back .cover-frame { inset: 34px 52px 34px 30px; }

.foil {
  background: linear-gradient(180deg, var(--gold-1) 0%, var(--gold-2) 55%, var(--gold-3) 80%, #7c7e85 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.65)) drop-shadow(0 -1px 0 rgba(255,255,255,.12));
}
.cover-orn { font-size: 40px; line-height: 1; }
.cover-kicker { margin-top: 20px; font-size: 15px; letter-spacing: .5em; text-transform: uppercase; padding-left: .5em; }
.cover-title {
  font-family: "Playfair Display", serif; font-weight: 700;
  font-size: 46px; line-height: 1.15; margin: 8px 0 6px;
}
.cover-divider { display: flex; align-items: center; gap: 12px; width: 62%; margin: 8px 0 14px; }
.cover-divider i { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(200,202,207,.8), transparent); }
.cover-divider span { font-size: 14px; }
.cover-sub { font-family: "Playfair Display", serif; font-size: 26px; letter-spacing: .12em; }
.cover-motto { margin-top: 26px; font-style: italic; font-size: 18px; letter-spacing: .06em; }

/* Thánh giá */
.cross-wrap { display: inline-block; line-height: 0; filter: drop-shadow(0 1px 0 rgba(0,0,0,.7)) drop-shadow(0 -1px 0 rgba(255,255,255,.12)); }
.cross {
  display: inline-block; width: 38px; height: 58px;
  background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 55%, var(--gold-3) 80%, #7c7e85);
  clip-path: polygon(43% 0, 57% 0, 57% 24%, 100% 24%, 100% 34%, 57% 34%, 57% 100%, 43% 100%, 43% 34%, 0 34%, 0 24%, 43% 24%);
}
.cross.lg { width: 52px; height: 80px; }
.cross.sm { width: 24px; height: 36px; }
.cross.ink { background: var(--ink-soft); opacity: .8; }
.verse-ref { margin-top: 8px; font-size: 14px; letter-spacing: .15em; color: var(--ink-soft); }
.cover-year { margin-top: 14px; font-size: 15px; letter-spacing: .4em; padding-left: .4em; }

/* Ọp góc kim loại */
.corner {
  position: absolute; width: 50px; height: 50px; z-index: 2;
  background: linear-gradient(135deg, #f2f2f0, #8a8c92 50%, #c9cbd0 75%, #6c6e74);
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.corner.tr { top: 0; right: 0; clip-path: polygon(0 0, 100% 0, 100% 100%); border-top-right-radius: 8px; }
.corner.br { bottom: 0; right: 0; clip-path: polygon(100% 0, 100% 100%, 0 100%); border-bottom-right-radius: 8px; }
.corner.tl { top: 0; left: 0; clip-path: polygon(0 0, 100% 0, 0 100%); border-top-left-radius: 8px; }
.corner.bl { bottom: 0; left: 0; clip-path: polygon(0 0, 100% 100%, 0 100%); border-bottom-left-radius: 8px; }

/* Bìa trong (giấy lót hoa văn) */
.endpaper {
  position: absolute; inset: 10px;
  background:
    radial-gradient(circle, rgba(60,58,55,.22) 0 2px, transparent 3.5px) 0 0 / 30px 30px,
    radial-gradient(circle, transparent 0 7px, rgba(60,58,55,.12) 7.5px 8.5px, transparent 9px) 15px 15px / 30px 30px,
    radial-gradient(ellipse at center, transparent 50%, rgba(40,38,35,.25) 100%),
    var(--noise),
    #d3cdd6;
  box-shadow: inset 0 0 12px rgba(20,18,15,.35);
}
.face.back .endpaper  { right: 0; }
.face.front .endpaper { left: 0; }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; gap: 18px; position: relative; z-index: 5; }
.btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(200,202,207,.45);
  background: radial-gradient(circle at 35% 30%, #5a3f6b, #1d1224);
  color: var(--gold-3);
  font-size: 28px; line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.15);
  transition: transform .15s ease, opacity .2s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .3; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--gold-3); outline-offset: 3px; }
.indicator {
  min-width: 120px; text-align: center;
  font-style: italic; font-size: 17px; letter-spacing: .08em; color: #cfd0d3;
}
.hint { font-size: 14px; font-style: italic; color: rgba(207,208,211,.5); position: relative; z-index: 5; }

@media (prefers-reduced-motion: reduce) {
  :root { --flip: 1ms; }
}

/* ---------- Tên thánh ---------- */
.cover-saint { margin-top: 18px; font-family: "Playfair Display", serif; font-style: italic; font-size: 26px; letter-spacing: .06em; }
.cover-saint + .cover-title { margin-top: 0; }
.title-page .saint { margin-top: 10px; font-family: "Playfair Display", serif; font-style: italic; font-size: 22px; color: var(--ink-soft); }
.title-page .saint + h1 { margin-top: 0; }

/* ---------- Điện thoại (màn hình dọc) ---------- */
body.portrait .scene { gap: 14px; }
/* Trang đã lật biến mất sau gáy (mép trái) */
body.portrait .stage { clip-path: inset(-60px -60px -60px 0); }
body.portrait .face.back.page { box-shadow: none; }
body.portrait .hint { font-size: 13px; }
body.portrait .indicator { min-width: 110px; font-size: 16px; }
body.portrait .controls { gap: 26px; }

/* 1 ảnh ngang giữa trang */
.layout-wide { display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.layout-wide .photo { width: 100%; }
.layout-wide .shot { flex: none; aspect-ratio: 3 / 2; }

/* Trang Kinh Thánh */
.verse-page { align-items: center; justify-content: center; text-align: center; padding-left: 52px; padding-right: 52px; }
.verse-page blockquote {
  margin-top: 26px;
  font-family: "Playfair Display", serif;
  font-style: italic;
  font-size: 25px;
  line-height: 1.5;
  color: var(--ink);
}
.verse-page .rule { width: 70px; margin: 24px auto 14px; }
.verse-page .verse-ref { font-size: 15px; letter-spacing: .2em; text-transform: uppercase; }
.verse-page .folio { position: absolute; bottom: 30px; left: 0; right: 0; }

/* Ẩn thanh nút & dòng hướng dẫn để album to hơn (vẫn lật bằng chạm/vuốt/phím) */
.controls, .hint { display: none !important; }

/* Điện thoại: lề trang hẹp lại để ảnh to hơn */
body.portrait .page-inner { padding: 22px 14px 18px 22px; }
body.portrait .face.front .page-inner { padding-left: 24px; }
body.portrait .layout-single { padding: 8px 4px 4px; }
body.portrait .layout-double { padding: 0 2px; gap: 16px; }
body.portrait .layout-wide { padding: 0; }
body.portrait .layout-grid, body.portrait .layout-trio { gap: 12px; }
body.portrait .photo { padding: 6px 6px 0; }
body.portrait .photo figcaption:empty { padding: 0 0 6px; }

/* Nút bật/tắt nhạc nền */
.music-btn {
  position: fixed; z-index: 20;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(200,202,207,.35);
  background: rgba(30,22,38,.55);
  color: #d3d5d9; cursor: pointer;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: .75; transition: opacity .2s ease;
}
.music-btn:hover { opacity: 1; }
.music-btn svg { width: 20px; height: 20px; }
.music-btn .ic-on { display: none; }
.music-btn.on .ic-on { display: block; }
.music-btn.on .ic-off { display: none; }

/* Vuốt mượt, không cuộn/zoom trang khi vuốt trên album */
.stage { touch-action: none; }
.leaf { cursor: pointer; }
.photo { cursor: zoom-in; }

/* ---------- Phóng to ảnh ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; display: none; cursor: zoom-out; }
.lightbox.open { display: block; }
.lb-backdrop {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(25,16,32,.88), rgba(6,4,8,.96));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.lb-img {
  position: absolute; object-fit: cover; border-radius: 6px;
  box-shadow: 0 30px 90px rgba(0,0,0,.65);
  will-change: left, top, width, height;   /* không lọc màu: hiện đúng màu ảnh gốc */
}



/* Ảnh đang mở: tự xử lý chụm/kéo, không để trình duyệt phóng to trang */
.lightbox { touch-action: none; }
.lb-img { transform-origin: center center; }
.lightbox.zoomed { cursor: grab; }
html { touch-action: manipulation; }

/* ---------- Trái tim (album tình yêu: ornament = 'heart') ---------- */
.heart {
  display: inline-block; width: 46px; height: 42px;
  background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 55%, var(--gold-3) 80%, var(--gold-2));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.3 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5L12 21.3z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.3 10.6 20C5.4 15.4 2 12.3 2 8.5 2 5.4 4.4 3 7.5 3c1.7 0 3.4.8 4.5 2.1C13.1 3.8 14.8 3 16.5 3 19.6 3 22 5.4 22 8.5c0 3.8-3.4 6.9-8.6 11.5L12 21.3z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.heart.lg { width: 64px; height: 58px; }
.heart.sm { width: 28px; height: 26px; }
.heart.ink { background: var(--ink-soft); opacity: .8; }

/* ---------- Video trong trang ---------- */
.shot video { display: block; width: 100%; height: 100%; object-fit: cover; background: #222; }
.vid-badge {
  position: absolute; right: 8px; bottom: 8px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 7v10l8-5z'/%3E%3C/svg%3E") center / 14px no-repeat;
  pointer-events: none;
}
.lightbox .lb-vid { display: none; background: #000; }
.lightbox.is-video .lb-vid { display: block; }
.lightbox.is-video img.lb-img { display: none; }

/* 2 ảnh dọc cạnh nhau */
.layout-pair { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; gap: 14px; padding: 40px 0; }
body.portrait .layout-pair { gap: 10px; padding: 30px 0; }
