/* ============ Reset & base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --paper-bg: #F7F1E6;
  --ink: #211E1B;
  --ink-soft: #5C554E;
  --burgundy: #7A4B4B;
  --night-bg: #313A50;
  --star-gold: #D9C389;

  --font-cn: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", serif;
  --font-en: "Cormorant Garamond", "EB Garamond", "Libre Baskerville", Georgia, serif;

  --transition-ms: 380ms;
  --stagger-ms: 110ms;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper-bg);
  color: var(--ink);
  font-family: var(--font-cn);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100dvh;
}

/* ============ Gate screen ============ */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-bg);
  z-index: 100;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.gate[hidden] {
  display: none;
}

.gate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  text-align: center;
  padding: 0 32px;
}

.gate-for-you {
  font-family: var(--font-en);
  font-style: italic;
  font-weight: 500;
  font-size: 28px;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.gate-input {
  width: 220px;
  max-width: 60vw;
  border: none;
  border-bottom: 1px solid var(--ink-soft);
  background: transparent;
  text-align: center;
  font-size: 18px;
  font-family: var(--font-en);
  color: var(--ink);
  padding: 6px 0;
  outline: none;
  letter-spacing: 0.3em;
}

.gate-input::placeholder {
  color: transparent;
}

.gate-error {
  min-height: 1.2em;
  font-size: 13px;
  color: var(--burgundy);
  font-family: var(--font-en);
  opacity: 0;
  transition: opacity 300ms ease;
}

.gate-error.show {
  opacity: 1;
}

/* ============ Book shell ============ */
.book {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper-bg);
  transition: background-color 600ms ease;
}

.book.theme-night {
  background: var(--night-bg);
  color: #EDE7D8;
}

/* ============ Night starfield (behind everything, only on night theme) === */
.stars {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 900ms ease;
}

.book.theme-night .stars {
  opacity: 1;
}

.stars .star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--star-gold);
  will-change: opacity;
  animation: star-twinkle linear infinite;
}

.stars .star.big {
  width: 3px;
  height: 3px;
  box-shadow: 0 0 3px rgba(217, 195, 137, 0.6);
}

@keyframes star-twinkle {
  0%, 100% { opacity: var(--star-min, 0.25); }
  50% { opacity: var(--star-max, 0.9); }
}

@media (prefers-reduced-motion: reduce) {
  .stars .star {
    animation: none;
    opacity: 0.6;
  }
}

.stage {
  position: absolute;
  inset: 0;
  padding: calc(env(safe-area-inset-top) + 32px) calc(env(safe-area-inset-right) + 28px) calc(env(safe-area-inset-bottom) + 40px) calc(env(safe-area-inset-left) + 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* Sits above the invisible full-page nav zones so interactive scene
     elements (cake tap, download link, etc.) can actually receive clicks.
     pointer-events:none lets normal taps fall through to .zone below for
     page-turn navigation; specific elements opt back in with pointer-events:auto. */
  z-index: 8;
  pointer-events: none;
}

/* ============ Scene / page ============ */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 36px) calc(env(safe-area-inset-right) + 30px) calc(env(safe-area-inset-bottom) + 44px) calc(env(safe-area-inset-left) + 30px);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity var(--transition-ms) ease, transform var(--transition-ms) ease;
  pointer-events: none;
}

.page.active {
  opacity: 1;
  transform: translateX(0);
  /* Stay pointer-events:none (inherited) so normal taps fall through to the
     .zone nav buttons underneath for page-turn navigation. Only specific
     interactive elements (cake image, download link) opt back in with
     their own pointer-events:auto. */
}

.page.leaving-prev {
  transform: translateX(-24px);
}

.page.leaving-next {
  transform: translateX(24px);
}

@media (prefers-reduced-motion: reduce) {
  .page {
    transition: opacity 200ms linear;
    transform: none !important;
  }
}

/* ============ Illustration ============ */
.scene-image {
  max-width: 82%;
  max-height: 42vh;
  object-fit: contain;
  margin-bottom: 28px;
  border-radius: 2px;
  filter: saturate(0.92);
}

.scene-image.small {
  max-height: 32vh;
}

/* ============ Wine label card (first scene of each chapter) ============ */
.label-card {
  position: relative;
  max-width: 78%;
  max-height: 42vh;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.label-card-bg {
  display: block;
  max-width: 100%;
  max-height: 42vh;
  object-fit: contain;
  filter: saturate(0.92);
  border-radius: 2px;
}

.label-card-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 14%;
  gap: 6px;
}

.label-card-producer {
  font-family: var(--font-en);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.label-card-region {
  font-family: var(--font-en);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.label-card-cuvee {
  font-family: var(--font-en);
  font-style: italic;
  font-size: 12px;
  color: var(--ink-soft);
}

.label-card-vintage {
  font-family: var(--font-en);
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--burgundy);
  margin-top: 2px;
}

.theme-night .label-card-producer,
.theme-night .label-card-region,
.theme-night .label-card-cuvee {
  color: var(--star-gold);
}
.theme-night .label-card-vintage {
  color: var(--star-gold);
}

/* ============ Text ============ */
.scene-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: 640px;
}

.line {
  font-size: 18px;
  line-height: 1.9;
  font-weight: 500;
  color: var(--ink);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 420ms ease, transform 420ms ease;
  white-space: pre-wrap;
}

.theme-night .line {
  color: #EDE7D8;
}

.line.empty {
  height: 0.9em;
}

.line.show {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .line {
    transition: opacity 200ms linear;
    transform: none !important;
  }
}

/* Chapter / wine meta */
.scene-meta {
  font-family: var(--font-en);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 18px;
  opacity: 0;
  transition: opacity 500ms ease;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.wine-crest {
  width: 18px;
  height: 18px;
  object-fit: contain;
  opacity: 0.9;
  filter: sepia(8%) saturate(90%);
  flex-shrink: 0;
}

.theme-night .wine-crest {
  opacity: 0.75;
  filter: sepia(8%) saturate(75%) brightness(0.92);
}

.scene-meta.show { opacity: 1; }

.theme-night .scene-meta { color: var(--star-gold); }

/* ============ Cover ============ */
.cover-title {
  font-family: var(--font-cn);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  opacity: 0;
  transition: opacity 900ms ease;
}

.cover-subtitle {
  font-family: var(--font-en);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-soft);
  margin-bottom: 60px;
  opacity: 0;
  transition: opacity 900ms ease 200ms;
}

.cover-hint {
  font-family: var(--font-en);
  font-size: 12px;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 1200ms ease 600ms;
  text-transform: uppercase;
}

.cover-title.show, .cover-subtitle.show, .cover-hint.show {
  opacity: 1;
}

/* ============ Year reveal ============ */
.year-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.year-item {
  font-family: var(--font-en);
  font-size: 22px;
  letter-spacing: 0.1em;
  color: var(--star-gold);
  opacity: 0;
  transition: opacity 600ms ease;
}

.year-item.show { opacity: 1; }

.year-single {
  font-family: var(--font-en);
  font-size: 48px;
  letter-spacing: 0.05em;
  color: var(--star-gold);
  opacity: 0;
  transition: opacity 900ms ease;
  margin-bottom: 28px;
}

.year-single.show { opacity: 1; }

/* ============ Cake scene ============ */
.cake-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fireworks-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  z-index: 30;
}

.cake-image {
  max-width: 78%;
  max-height: 46vh;
  object-fit: contain;
  cursor: pointer;
  transition: filter 800ms ease;
  position: relative;
  z-index: 6;
  pointer-events: auto;
  /* Gentle breathing glow so it's clear this is the one tappable thing
     on the page — stops the instant it's tapped. */
  animation: cakeGlow 2.6s ease-in-out infinite;
}

@keyframes cakeGlow {
  0%, 100% { filter: drop-shadow(0 0 0px rgba(217, 195, 137, 0)); }
  50% { filter: drop-shadow(0 0 18px rgba(217, 195, 137, 0.55)); }
}

.cake-image.blown {
  animation: none;
  filter: none;
}

@media (prefers-reduced-motion: reduce) {
  .cake-image { animation: none; }
}

.cake-download {
  position: relative;
  z-index: 6;
}

.cake-prompt {
  margin-top: 24px;
  font-size: 17px;
  color: #EDE7D8;
  opacity: 0;
  transition: opacity 700ms ease;
}
.cake-prompt.show { opacity: 1; }
.cake-prompt.hide { opacity: 0; }

.cake-tap-hint {
  font-family: var(--font-en);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #B9AF98;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 900ms ease;
  animation: cakeHintPulse 2.6s ease-in-out infinite;
}
.cake-tap-hint.show { opacity: 0.6; }
.cake-tap-hint.hide { opacity: 0 !important; animation: none; }

@keyframes cakeHintPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.75; }
}

@media (prefers-reduced-motion: reduce) {
  .cake-tap-hint { animation: none; }
}

.cake-reveal-title {
  font-family: var(--font-cn);
  font-size: 30px;
  font-weight: 600;
  color: #EDE7D8;
  margin-top: 24px;
  opacity: 0;
  transition: opacity 1200ms ease;
}
.cake-reveal-title.show { opacity: 1; }

.cake-reveal-sub {
  font-size: 14px;
  color: var(--star-gold);
  margin-top: 14px;
  opacity: 0;
  transition: opacity 1200ms ease;
  white-space: pre-line;
  line-height: 1.8;
}
.cake-reveal-sub.show { opacity: 1; }

.cake-download {
  margin-top: 32px;
  font-family: var(--font-en);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 1000ms ease;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  pointer-events: auto;
}

.theme-night .cake-download {
  color: #B9AF98;
}

.cake-download.show {
  opacity: 0.85;
  border-bottom: 1px solid currentColor;
}

/* ============ Nav zones ============ */
.zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background: transparent;
  border: none;
  z-index: 5;
}
.zone-prev { left: 0; }
.zone-next { right: 0; }

/* ============ Corner hint ============ */
.hint {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  right: calc(env(safe-area-inset-right) + 16px);
  z-index: 10;
  opacity: 0.35;
}

/* ============ Sound toggle ============ */
.sound-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  right: calc(env(safe-area-inset-right) + 14px);
  z-index: 20;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  opacity: 0.5;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 300ms ease, color 300ms ease;
  -webkit-tap-highlight-color: transparent;
}
.sound-toggle:active { opacity: 0.7; }
.book.theme-night .sound-toggle { color: var(--star-gold); }
.sound-toggle.on { opacity: 0.65; }
.sound-toggle.hidden-zone {
  opacity: 0 !important;
  pointer-events: none;
}

/* Gentle one-time pulse to draw the eye on the cover, so the music
   option isn't missed. Stops after a few cycles, never returns. */
.sound-toggle.pulse-hint {
  animation: soundPulse 2.2s ease-in-out 3;
}
@keyframes soundPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.12); }
}
@media (prefers-reduced-motion: reduce) {
  .sound-toggle.pulse-hint { animation: none; }
}

.hint-dot {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.theme-night .hint-dot {
  background: var(--star-gold);
}

/* ============ Edge hints (teach left/right = back/forward) ============ */
.edge-hint {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  font-family: var(--font-en);
  font-size: 22px;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 900ms ease;
  pointer-events: none;
  user-select: none;
}
.edge-hint.show { opacity: 0.3; }
.edge-hint-left { left: calc(env(safe-area-inset-left) + 10px); }
.edge-hint-right { right: calc(env(safe-area-inset-right) + 10px); }
.book.theme-night .edge-hint { color: var(--star-gold); }

@media (prefers-reduced-motion: reduce) {
  .edge-hint { transition: opacity 200ms linear; }
}

/* ============ Headphone / sound-toggle cue (cover page only) ============
   Points at the sound-toggle icon (top-right, ~14px inset, 44px button)
   and invites the user to put on headphones and tap it to start the
   music. Only ever shown on the cover (scene 0); stays faint. */
.headphone-cue {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 60px);
  right: calc(env(safe-area-inset-right, 0px) + 14px);
  width: 44px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 900ms ease;
  pointer-events: none;
  user-select: none;
  text-align: center;
}
.headphone-cue.show { opacity: 0.7; }
.headphone-cue-text {
  font-family: var(--font-cn);
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-soft);
  background: rgba(247, 241, 230, 0.88);
  padding: 6px 10px;
  border-radius: 3px;
  white-space: nowrap;
  width: max-content;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}
.headphone-cue-arrow {
  font-family: var(--font-en);
  font-size: 24px;
  line-height: 1;
  color: var(--ink-soft);
  animation: headphoneCueBob 1.6s ease-in-out infinite;
}
@keyframes headphoneCueBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.book.theme-night .headphone-cue-arrow,
.book.theme-night .headphone-cue-text {
  color: var(--star-gold);
}
.book.theme-night .headphone-cue-text {
  background: rgba(49, 58, 80, 0.88);
}

@media (prefers-reduced-motion: reduce) {
  .headphone-cue { transition: opacity 200ms linear; }
  .headphone-cue-arrow { animation: none; }
}
