/* ═══════════════════════════════════════════════════════════════════════
   OUR FIRST CHAPTER — REALISTIC 3D PHYSICAL STORYBOOK
   Mandatory Side-by-Side 2-Page Spread Layout with Page-Flip Engine
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --mahogany-surface-1: #2e1d16;
  --mahogany-surface-2: #140c09;
  --cover-leather: #22130e;
  --cover-border: #d4af37;
  --paper-cream: #FDFBF7;
  --paper-parchment: #F4ECE1;
  --paper-aged: #EAE1D5;
  --ink-espresso: #2E211B;
  --ink-soft: #4A3E39;
  --gold-champagne: #C8A97E;
  --gold-foil: #D4AF37;
  --rose-dusty: #B5838D;
  --terracotta: #B85D38;
  --font-serif-title: 'Cormorant Garamond', Georgia, serif;
  --font-serif-body: 'Lora', Georgia, serif;
  --font-script: 'Caveat', cursive;
  
  --page-width: 420px;
  --page-height: 590px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--mahogany-surface-2);
  background: radial-gradient(circle at center, var(--mahogany-surface-1) 0%, var(--mahogany-surface-2) 100%);
  color: var(--ink-espresso);
  font-family: var(--font-serif-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ═══════════════════════════════════════════════
   AMBIENT BACKGROUND DUST MOTES
   ═══════════════════════════════════════════════ */
#ambient-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════
   DISCREET FLOATING HUD CONTROLS
   ═══════════════════════════════════════════════ */
.hud-controls {
  position: fixed;
  top: 14px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 999;
}

.hud-pill {
  background: rgba(30, 18, 13, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(200, 169, 126, 0.35);
  border-radius: 20px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--gold-champagne);
  font-family: var(--font-serif-body);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.hud-pill:hover {
  background: rgba(46, 29, 22, 0.95);
  border-color: var(--gold-foil);
  color: #fff;
  transform: translateY(-1px);
}

.hud-pill.active {
  background: rgba(184, 93, 56, 0.35);
  border-color: var(--terracotta);
  color: #fff;
}

/* ═══════════════════════════════════════════════
   ZERO-CLUTTER VIEWPORT & BOOK SCALER
   Ensures side-by-side spread is NEVER stacked
   ═══════════════════════════════════════════════ */
.viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  overflow: hidden;
  touch-action: pan-x pan-y pinch-zoom;
}

.book-scaler {
  position: relative;
  width: 840px;
  height: 590px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: transform 0.65s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

/* ═══════════════════════════════════════════════
   FLIP-BOOK CONTAINER
   ═══════════════════════════════════════════════ */
.flip-book {
  position: relative;
  display: none; /* Revealed by PageFlip on init */
  box-shadow:
    0 25px 60px -10px rgba(0, 0, 0, 0.85),
    0 12px 25px rgba(0, 0, 0, 0.55);
}

/* Base Page Setup for StPageFlip */
.page {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: var(--paper-cream);
  overflow: hidden;
  box-sizing: border-box;
}

/* Gutter Shadow Along Book Spine */
.page-left {
  box-shadow: inset -22px 0 25px -10px rgba(46, 33, 27, 0.16);
  border-right: 1px solid rgba(46, 33, 27, 0.12);
}

.page-right {
  box-shadow: inset 22px 0 25px -10px rgba(46, 33, 27, 0.16);
  border-left: 1px solid rgba(46, 33, 27, 0.12);
}

/* Procedural Parchment Texture Overlay */
.page-left::before, .page-right::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--paper-aged) 0.65px, transparent 0.65px);
  background-size: 14px 14px;
  opacity: 0.65;
  pointer-events: none;
  z-index: 1;
}

/* Page Numbers at Bottom */
.page-footer-num {
  position: absolute;
  bottom: 12px;
  font-family: var(--font-serif-title);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  color: var(--gold-champagne);
  z-index: 10;
}

.left-num {
  left: 18px;
}

.right-num {
  right: 18px;
}

/* ═══════════════════════════════════════════════
   PAGE 0: FRONT COVER (Closed Book)
   ═══════════════════════════════════════════════ */
.page-cover {
  background: radial-gradient(circle at 45% 30%, #3a1e15 0%, #1a0d08 100%);
  padding: 16px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.7);
}

.cover-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(212, 175, 55, 0.65);
  border-radius: 8px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow:
    inset 0 0 20px rgba(0, 0, 0, 0.5),
    0 0 12px rgba(212, 175, 55, 0.2);
}

.filigree {
  position: absolute;
  color: var(--gold-foil);
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.75;
}
.filigree.tl { top: 4px; left: 4px; }
.filigree.tr { top: 4px; right: 4px; }
.filigree.bl { bottom: 4px; left: 4px; }
.filigree.br { bottom: 4px; right: 4px; }

.cover-head {
  text-align: center;
}

.cover-tag {
  font-family: var(--font-serif-title);
  font-size: 0.68rem;
  letter-spacing: 0.25em;
  color: var(--gold-champagne);
  text-transform: uppercase;
  display: block;
  margin-bottom: 3px;
}

.cover-main-title {
  font-family: var(--font-serif-title);
  font-size: clamp(1.4rem, 3.5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #fff;
  background: linear-gradient(135deg, #fff 0%, #fae8b6 40%, #d4af37 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cover-bar {
  width: 50px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold-foil), transparent);
  margin: 5px auto;
}

.cover-desc {
  font-family: var(--font-serif-title);
  font-style: italic;
  font-size: 0.85rem;
  color: rgba(253, 251, 247, 0.85);
  line-height: 1.35;
  padding: 0 10px;
}

.cover-art-box {
  position: relative;
  width: 100%;
  flex: 1;
  max-height: 54%;
  margin: 8px 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  background: #0f0704;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.brass-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--gold-foil);
  z-index: 5;
}
.c-tl { top: 4px; left: 4px; border-right: none; border-bottom: none; }
.c-tr { top: 4px; right: 4px; border-left: none; border-bottom: none; }
.c-bl { bottom: 4px; left: 4px; border-right: none; border-top: none; }
.c-br { bottom: 4px; right: 4px; border-left: none; border-top: none; }

.cover-foot {
  text-align: center;
}

.cover-author {
  font-family: var(--font-script);
  font-size: 1.5rem;
  color: var(--rose-dusty);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.cover-callout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 4px 14px;
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 20px;
  color: #fae8b6;
  font-size: 0.72rem;
  animation: pulse-cover 2.2s infinite ease-in-out;
  cursor: pointer;
}

@keyframes pulse-cover {
  0%, 100% { transform: translateY(0); box-shadow: 0 0 0 rgba(212, 175, 55, 0); }
  50% { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(212, 175, 55, 0.28); }
}

/* ═══════════════════════════════════════════════
   LEFT PAGE: ILLUSTRATION FRAME (50% Width Spread)
   ═══════════════════════════════════════════════ */
.memory-illustration-page {
  padding: 18px 16px 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
}

.illustration-frame {
  position: relative;
  width: 100%;
  height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.art-mount {
  position: relative;
  width: 100%;
  height: 90%;
  background: #fff;
  border-radius: 6px;
  padding: 6px;
  box-shadow:
    0 4px 18px rgba(46, 33, 27, 0.15),
    0 1px 3px rgba(46, 33, 27, 0.08),
    0 0 0 1px rgba(200, 169, 126, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.spread-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: 4px;
  background: #fcfbf9;
  display: block;
}

.tape-corner {
  position: absolute;
  top: -6px;
  right: 12px;
  width: 45px;
  height: 14px;
  background: rgba(181, 131, 141, 0.35);
  border-left: 2px dashed rgba(255, 255, 255, 0.45);
  border-right: 2px dashed rgba(255, 255, 255, 0.45);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transform: rotate(3deg);
  z-index: 5;
}

.spread-caption {
  font-family: var(--font-script);
  font-size: 1.15rem;
  color: var(--rose-dusty);
  margin-top: 6px;
  letter-spacing: 0.04em;
}

/* ═══════════════════════════════════════════════
   RIGHT PAGE: STORY & QUOTE PAGE
   ═══════════════════════════════════════════════ */
.memory-quote-page {
  padding: 24px 22px 24px 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.story-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  z-index: 2;
}

.quote-symbol {
  font-family: var(--font-serif-title);
  font-size: 3rem;
  line-height: 0.6;
  color: var(--gold-champagne);
  opacity: 0.4;
  margin-bottom: 6px;
}

.quote-content {
  font-size: clamp(0.92rem, 1.4vw, 1.08rem);
  line-height: 1.68;
  color: var(--ink-espresso);
}

.quote-paragraph {
  margin-bottom: 12px;
}

.quote-paragraph:last-child {
  margin-bottom: 0;
}

.quote-question {
  font-weight: 600;
  color: var(--terracotta);
}

.highlight-thought {
  font-weight: 600;
  color: var(--terracotta);
}

/* Tamil Verses / Rhyme Card */
.poetry-card {
  margin: 10px 0;
  padding: 8px 12px;
  background: rgba(200, 169, 126, 0.12);
  border-left: 2px solid var(--gold-champagne);
  border-radius: 0 4px 4px 0;
}

.poetry-card p {
  font-size: 0.94rem;
  font-style: italic;
  line-height: 1.5;
  color: #3b261b;
  margin-bottom: 4px;
}
.poetry-card p:last-child {
  margin-bottom: 0;
}

.punchline {
  margin-top: 8px;
}

.accent-word {
  font-family: var(--font-script);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--terracotta);
  letter-spacing: 0.05em;
  display: inline-block;
  padding: 0 4px;
}

.quote-ornament {
  text-align: center;
  color: var(--gold-champagne);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  margin-top: 14px;
  opacity: 0.75;
}

/* ═══════════════════════════════════════════════
   SPREAD 11 (FINAL PAGE): SUNSET & BOO'S LETTER
   ═══════════════════════════════════════════════ */
.finale-art-page {
  padding: 16px 14px 22px 18px;
}

.finale-mount {
  height: 92%;
}

.finale-img {
  object-fit: cover;
  object-position: center bottom;
}

.finale-letter-page {
  padding: 20px 22px 24px 22px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  z-index: 2;
  overflow-y: auto;
}

.letter-scrollable {
  position: relative;
  z-index: 2;
  width: 100%;
}

.letter-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(200, 169, 126, 0.3);
  padding-bottom: 6px;
}

.wax-seal-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #c84b4b 0%, #872323 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffdada;
  font-family: var(--font-script);
  font-size: 0.65rem;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.letter-pretitle {
  font-family: var(--font-serif-title);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--terracotta);
  font-weight: 700;
}

.letter-greeting {
  font-family: var(--font-serif-title);
  font-size: 1.35rem;
  color: var(--ink-espresso);
  margin-bottom: 10px;
  font-weight: 700;
}

.letter-text-body p {
  font-size: clamp(0.85rem, 1.25vw, 0.98rem);
  line-height: 1.58;
  color: var(--ink-espresso);
  margin-bottom: 8px;
}

.letter-highlight {
  font-weight: 600;
  color: var(--terracotta) !important;
}

.letter-signoff {
  margin-top: 10px;
  text-align: right;
}

.signoff-signature {
  font-family: var(--font-script);
  font-size: 1.55rem;
  color: var(--rose-dusty);
  font-weight: 700;
}

/* Close Book & Read Again Ribbon */
.read-again-ribbon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  background: linear-gradient(135deg, #a63a50 0%, #7d2639 100%);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  padding: 6px 14px;
  color: #fff;
  font-family: var(--font-serif-body);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
  transition: all 0.25s ease;
  animation: pulse-ribbon 2.4s infinite ease-in-out;
}

@keyframes pulse-ribbon {
  0%, 100% { transform: translateY(0); box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35); }
  50% { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(166, 58, 80, 0.55); }
}

.read-again-ribbon:hover {
  background: linear-gradient(135deg, #bd4760 0%, #8e2c41 100%);
  transform: translateY(-2px);
}

/* ═══════════════════════════════════════════════
   PAGE 23: KEEPSAKE COLOPHON
   ═══════════════════════════════════════════════ */
.colophon-page {
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.colophon-inner {
  position: relative;
  z-index: 2;
  border: 1px dashed rgba(200, 169, 126, 0.4);
  border-radius: 8px;
  padding: 20px 16px;
  background: rgba(255, 255, 255, 0.4);
}

.colophon-ornament {
  color: var(--gold-foil);
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.colophon-title {
  font-family: var(--font-serif-title);
  font-size: 1.25rem;
  letter-spacing: 0.15em;
  color: var(--ink-espresso);
}

.colophon-text {
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.colophon-line {
  width: 40px;
  height: 1px;
  background: var(--gold-champagne);
  margin: 12px auto;
}

.colophon-names {
  font-family: var(--font-script);
  font-size: 1.6rem;
  color: var(--terracotta);
  font-weight: 700;
}

.colophon-date {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.colophon-quote {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-espresso);
  margin-top: 10px;
}

/* ═══════════════════════════════════════════════
   PAGE 24: HARDCOVER BACK
   ═══════════════════════════════════════════════ */
.page-cover-back {
  background: radial-gradient(circle at 55% 40%, #3a1e15 0%, #1a0d08 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-cover-inner {
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-cover-emblem {
  text-align: center;
}

.back-emblem-heart {
  color: var(--gold-foil);
  font-size: 2.2rem;
  display: block;
  margin-bottom: 6px;
  text-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
}

.back-emblem-text {
  font-family: var(--font-serif-title);
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  color: #fae8b6;
}

/* ═══════════════════════════════════════════════
   SPARKLE CELEBRATION PARTICLES
   ═══════════════════════════════════════════════ */
.sparkle-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  font-size: 1rem;
  animation: float-sparkle 1.2s forwards cubic-bezier(0.12, 0.84, 0.36, 1);
}

@keyframes float-sparkle {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.6) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(1.3) rotate(var(--rot));
  }
}
