/* =============================================================================
 *  Photobook — base styles (theme variables + reset + layout skeleton)
 *  Feature/visual styling is layered on top in later sections of this file.
 * ===========================================================================*/

:root {
  /* Vintage palette */
  --cream:        #f4ecd8;
  --paper:        #efe6cf;
  --paper-edge:   #d9caa6;
  --ink:          #3b2f2a;
  --ink-soft:     #6a5849;
  --leather:      #5c2e2e;
  --leather-hi:   #7a3b3b;
  --leather-lo:   #3f1f1f;
  --gold:         #c2a14d;
  --gold-hi:      #e6cf86;

  /* Type */
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body:    "EB Garamond", Georgia, serif;

  /* Metrics */
  --radius: 6px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);

  /* Procedural grain textures (no image files) */
  --grain-fine: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22160%22%20height%3D%22160%22%3E%3Cfilter%20id%3D%22n%22%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%220.9%22%20numOctaves%3D%222%22%20stitchTiles%3D%22stitch%22%2F%3E%3CfeColorMatrix%20type%3D%22saturate%22%20values%3D%220%22%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20filter%3D%22url(%23n)%22%2F%3E%3C%2Fsvg%3E");
  --grain-leather: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22300%22%20height%3D%22300%22%3E%3Cfilter%20id%3D%22n%22%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%220.45%22%20numOctaves%3D%222%22%20stitchTiles%3D%22stitch%22%2F%3E%3CfeColorMatrix%20type%3D%22saturate%22%20values%3D%220%22%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20filter%3D%22url(%23n)%22%20opacity%3D%220.6%22%2F%3E%3C%2Fsvg%3E");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  /* Warm, aged backdrop (a desk the book lies on) */
  background:
    radial-gradient(120% 120% at 50% 0%, #3a2c25 0%, #271c17 60%, #1c130f 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

[hidden] { display: none !important; }

/* --- Layout skeletons ----------------------------------------------------- */
.book-view { min-height: 100vh; display: flex; flex-direction: column; }
.stage-wrap { flex: 1; display: grid; place-items: center; padding: 2vmin; }
.gallery-view {
  min-height: 100vh;
  padding: clamp(1rem, 4vw, 2.5rem);
  color: var(--cream);
}
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto clamp(1.2rem, 4vw, 2.2rem);
  border-bottom: 1px solid rgba(194, 161, 77, 0.4);
  padding-bottom: 1rem;
}
.gallery-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  margin: 0;
  text-align: center;
  flex: 1 1 auto;
}
.text-btn {
  flex: 0 0 auto;
  font-family: var(--font-body);
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  color: var(--cream);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 0.45em 1em;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
}
.text-btn:hover:not(:disabled) { background: var(--gold); color: var(--leather-lo); }
.text-btn:disabled { opacity: 0.6; cursor: default; }

.gallery-grid {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: clamp(0.8rem, 2vw, 1.4rem);
}
.thumb {
  margin: 0;
  background: var(--cream);
  padding: 8px 8px 0;
  border-radius: 2px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  cursor: zoom-in;
  transition: transform 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
}
.thumb:hover,
.thumb:focus-visible {
  transform: translateY(-4px) rotate(-0.6deg);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.55);
  outline: none;
}
.thumb img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}
.thumb figcaption {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
  padding: 0.5em 0.3em 0.7em;
}

/* =============================================================================
 *  THE BOOK STAGE (3D)  —  structural + flip mechanics
 *  (vintage decoration is layered on in the styling section below)
 * ===========================================================================*/

.stage {
  --flip-ms: 720ms;
  position: relative;
}
.mode-double .stage { height: min(80vh, 58vw); aspect-ratio: 3 / 2; width: auto; }
.mode-single .stage { height: min(82vh, 122vw); aspect-ratio: 3 / 4; width: auto; }

/* Perspective lives on .book so its children (leaves) render in 3D while still
 * stacking by z-index (a preserve-3d parent would stack by depth instead). */
.book {
  position: absolute;
  inset: 0;
  perspective: 2600px;
}

/* ---- Pages (shared) ---- */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  padding: 5% 6%;
}

/* ---- DOUBLE: surfaces + leaves ---- */
.surface {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 0;
}
.surface-left  { left: 0; }
.surface-right { left: 50%; }

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--flip-ms) cubic-bezier(0.34, 0.05, 0.3, 1);
}
.leaf.no-anim { transition: none; }
.leaf.flipped { transform: rotateY(-180deg); }

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

/* The two pages of an open spread tuck toward the spine */
.leaf-front .page { box-shadow: inset 8px 0 18px -10px rgba(0,0,0,0.35); }
.surface-left  .page,
.leaf-back  .page { box-shadow: inset -8px 0 18px -10px rgba(0,0,0,0.35); }

/* ---- SINGLE: one page at a time ---- */
.single-stack {
  position: absolute;
  inset: 0;
  perspective: 2600px;
}
.single-page {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform var(--flip-ms) cubic-bezier(0.34, 0.05, 0.3, 1);
  z-index: 2;
}
.single-page.beneath { z-index: 1; transform: rotateY(0deg); }
.single-page.on-top  { z-index: 3; }
.single-page.turn-out      { transform: rotateY(-180deg); }
.single-page.turn-in-start { transform: rotateY(-180deg); }
.single-page.turn-in       { transform: rotateY(0deg); }

/* =============================================================================
 *  PAGE CONTENT (functional defaults; refined in styling pass)
 * ===========================================================================*/

/* Photos: centered, consistent top alignment, never cropped, caption below */
.page-photo { justify-content: flex-start; cursor: zoom-in; }
.photo-figure {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4%;
}
.photo-img {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  object-fit: contain;
  background: #fbf7ec;
  border: 6px solid #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.28);
}
.photo-caption {
  flex: 0 0 auto;
  font-family: var(--font-body);
  font-style: italic;
  font-size: clamp(0.8rem, 2.1vmin, 1.15rem);
  text-align: center;
  color: var(--ink-soft);
}

/* Cover / back cover */
.page-cover { background: none; padding: 0; }
.cover-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}
.cover-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
}
.cover-year { margin: 0.4em 0 0; font-family: var(--font-display); }
.cover-subtitle { margin: 0.6em 0 0; font-style: italic; }

/* Note */
.page-note { justify-content: center; }
.note-greeting { font-family: var(--font-display); font-size: clamp(1.1rem, 3vmin, 1.8rem); margin: 0 0 0.6em; }
.note-body { line-height: 1.65; font-size: clamp(0.85rem, 2vmin, 1.1rem); }
.note-signature { margin-top: 1.4em; font-style: italic; }

/* Blank filler */
.page-blank { justify-content: center; }
.blank-flourish { font-size: clamp(2rem, 8vmin, 4rem); color: var(--gold); opacity: 0.5; }

/* Open-the-book hint on the cover */
.open-hint {
  position: absolute;
  bottom: 7%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-style: italic;
  font-size: clamp(0.7rem, 1.7vmin, 0.95rem);
  letter-spacing: 0.04em;
  color: var(--gold-hi);
  opacity: 0.85;
  animation: hintPulse 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.35; transform: translateX(-50%) translateY(0); }
  50%      { opacity: 0.9;  transform: translateX(-50%) translateY(3px); }
}
@media (prefers-reduced-motion: reduce) {
  .open-hint { animation: none; }
  .leaf, .single-page { transition-duration: 0.001ms; }
}

/* See all */
.page-seeall { justify-content: center; background: none; }
.seeall-inner { text-align: center; display: grid; gap: 1rem; place-items: center; }
.seeall-kicker { font-style: italic; color: var(--cream); opacity: 0.8; margin: 0; }
.seeall-btn {
  font-family: var(--font-display);
  font-size: clamp(1rem, 3vmin, 1.5rem);
  padding: 0.6em 1.4em;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--cream);
  border-radius: 3px;
  transition: background 0.2s, color 0.2s;
}
.seeall-btn:hover { background: var(--gold); color: var(--leather-lo); }

/* =============================================================================
 *  CONTROLS (nav buttons, slider + thumbnail, see-all link)
 * ===========================================================================*/
.controls {
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 2vw, 1.4rem);
  width: min(92vw, 760px);
  margin: 0 auto;
  padding: 0.4rem 0 0.2rem;
}
.nav-btn {
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--gold);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
}
.nav-btn:hover:not(:disabled) { background: var(--leather); }
.nav-btn:active:not(:disabled) { transform: scale(0.94); }
.nav-btn:disabled { opacity: 0.25; cursor: default; }

.slider-wrap { position: relative; flex: 1 1 auto; }
.slider {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(var(--gold), var(--gold));
  background-size: 100% 100%;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--gold);
  cursor: grab;
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cream);
  border: 2px solid var(--gold);
  cursor: grab;
}
.slider-readout {
  text-align: center;
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: var(--cream);
  opacity: 0.7;
  margin-top: 0.35rem;
}
.slider-thumb {
  position: absolute;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: 96px;
  height: 72px;
  padding: 4px;
  background: var(--cream);
  border: 1px solid var(--gold);
  border-radius: 3px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 20;
}
.slider-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slider-thumb::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--cream);
}

.see-all-link {
  display: block;
  margin: 0 auto;
  padding: 0.7rem 0 1rem;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--cream);
  opacity: 0.5;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.2s;
}
.see-all-link:hover { opacity: 0.9; }

/* =============================================================================
 *  LIGHTBOX (shared enlarged photo view)
 * ===========================================================================*/
body.lightbox-open { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: clamp(1rem, 4vw, 3rem);
  background: rgba(20, 13, 10, 0.92);
  backdrop-filter: blur(3px);
}
.lightbox-figure {
  margin: 0;
  max-width: min(92vw, 1100px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.lightbox-img {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  border: 8px solid #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  background: #fff;
}
.lightbox-caption {
  font-family: var(--font-body);
  font-style: italic;
  font-size: clamp(0.9rem, 2.4vmin, 1.2rem);
  color: var(--cream);
  text-align: center;
  max-width: 60ch;
}
.lightbox-download {
  font-family: var(--font-body);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--cream);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 0.4em 1em;
  transition: background 0.2s, color 0.2s;
}
.lightbox-download:hover { background: var(--gold); color: var(--leather-lo); }

.lightbox-close {
  position: absolute;
  top: clamp(0.6rem, 2vw, 1.4rem);
  right: clamp(0.6rem, 2vw, 1.4rem);
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.3rem;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--gold);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}
.lightbox-close:hover { background: var(--leather); }

.lightbox-nav {
  flex: 0 0 auto;
  width: 3rem;
  height: 3rem;
  font-size: 1.8rem;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(194, 161, 77, 0.6);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s, opacity 0.2s;
}
.lightbox-nav:hover:not(:disabled) { background: var(--leather); }
.lightbox-nav:disabled { opacity: 0.2; cursor: default; }

@media (max-width: 600px) {
  .lightbox-nav {
    position: absolute;
    bottom: 1rem;
    z-index: 2;
  }
  .lightbox-prev { left: 1rem; }
  .lightbox-next { right: 1rem; }
}

/* =============================================================================
 *  VINTAGE STYLING PASS  (decoration layered over the functional defaults)
 * ===========================================================================*/

/* The desk the book lies on */
body {
  background:
    radial-gradient(125% 120% at 50% -10%, #4a382e 0%, #2c211b 55%, #160f0c 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--grain-fine);
  background-size: 200px 200px;
  opacity: 0.05;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 0;
}
.book-view, .gallery-view { position: relative; z-index: 1; }

/* Soft shadow cast by the book onto the desk */
.stage::before {
  content: "";
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: -4%;
  height: 14%;
  background: radial-gradient(60% 100% at 50% 0%, rgba(0,0,0,0.55), rgba(0,0,0,0) 70%);
  filter: blur(6px);
  z-index: -1;
}

/* ---- Aged paper pages ---- */
.page {
  background:
    var(--grain-fine),
    linear-gradient(115deg, #f6eed9 0%, #efe5cc 50%, #e7dcbf 100%);
  background-size: 180px 180px, cover;
  background-blend-mode: multiply, normal;
  box-shadow: inset 0 0 70px rgba(120, 92, 50, 0.16);
}
.page::after {
  /* faint darkening toward the outer edges (album vignette) */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 40px rgba(90, 64, 30, 0.14);
}

/* Page numbers */
.page-num {
  position: absolute;
  bottom: 3.5%;
  font-family: var(--font-body);
  font-size: clamp(0.65rem, 1.6vmin, 0.85rem);
  color: var(--ink-soft);
  opacity: 0.55;
  letter-spacing: 0.05em;
}
.leaf-front .page-num,
.surface-right .page-num,
.book-single .page-num { right: 7%; }
.leaf-back .page-num,
.surface-left .page-num { left: 7%; }

/* ---- Leather cover (opaque) + gold foil ---- */
.page-cover {
  padding: 0;
  color: var(--gold-hi);
  background:
    var(--grain-leather),
    radial-gradient(120% 90% at 30% 18%, #7e3d3d 0%, #5c2e2e 45%, #491f1f 78%, #371717 100%);
  background-size: 600px 600px, cover;
  background-blend-mode: soft-light, normal;
  box-shadow:
    inset 0 0 80px rgba(0,0,0,0.55),
    inset 0 2px 0 rgba(255,255,255,0.06);
}
.page-cover::after { box-shadow: none; }
.cover-frame { padding: 9% 8%; }
.cover-frame::before {
  content: "";
  position: absolute;
  inset: 6%;
  border: 1.5px solid rgba(194,161,77,0.65);
  box-shadow: inset 0 0 0 4px rgba(194,161,77,0.18);
  border-radius: 2px;
  pointer-events: none;
}
.cover-inner { position: relative; text-align: center; }
.cover-inner::before,
.cover-inner::after {
  content: "❦";
  display: block;
  color: var(--gold);
  opacity: 0.7;
  font-size: clamp(1rem, 3.4vmin, 1.8rem);
  margin: 0.2em 0;
}

.cover-title {
  font-size: clamp(1.6rem, 6.2vmin, 3.6rem);
  line-height: 1.1;
  background: linear-gradient(180deg, #f6e7ad 0%, #d8b85f 38%, #9c7a2f 56%, #e8d289 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.45));
}
.cover-year {
  font-size: clamp(1rem, 3.4vmin, 1.8rem);
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  background: linear-gradient(180deg, #f6e7ad 0%, #c2a14d 60%, #e8d289 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}
.cover-subtitle { color: var(--gold-hi); opacity: 0.85; }

/* Back cover: leather, with optional words */
.page-backcover .backcover-text {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 3.6vmin, 2rem);
  color: var(--gold-hi);
  opacity: 0.9;
  text-align: center;
  margin: 0;
}

/* ---- The opening note (a letter) ---- */
.page-note { padding: 9% 9%; }
.note-inner { max-width: 42ch; margin: 0 auto; }
.note-greeting { color: var(--ink); }
.note-body { color: var(--ink); }
.note-signature { color: var(--ink-soft); }
.note-inner::after {
  content: "";
  display: block;
  width: 38%;
  height: 1px;
  margin: 1.4em 0 0;
  background: linear-gradient(90deg, rgba(120,92,50,0.5), transparent);
}

/* ---- Photos mounted like prints ---- */
.photo-img {
  border-width: clamp(5px, 1.4vmin, 10px);
  border-color: #fffdf7;
  box-shadow:
    0 10px 22px rgba(60, 40, 20, 0.3),
    0 1px 0 rgba(0,0,0,0.1);
}

/* ---- The See-All end surface (closed book on the desk) ---- */
.page-seeall { color: var(--cream); }
.seeall-kicker { font-family: var(--font-display); font-size: clamp(0.95rem, 2.6vmin, 1.3rem); }
