/* ============================================================
   Lumo Dreams — v1 styles
   Arctic / aurora / dreamy: deep blues, violet-green aurora accents,
   candle-gold title. Video behind full-bleed text with a tunable scrim.
   ============================================================ */

:root {
  /* palette */
  --night:        #060a16;
  --night-2:      #0b1326;
  --aurora-green: #6ff2c0;
  --aurora-violet:#b48bff;
  --ice:          #cfe6ff;
  --candle-gold:  #f2c879;
  --white:        #f6f9ff;

  /* per-chapter text legibility (overridable per section) */
  --ink: var(--white);
  /* drop-shadow for white text */
  --halo: 0 2px 14px rgba(0,0,0,0.75), 0 1px 3px rgba(0,0,0,0.9);
  /* scrim gradient over the video */
  --scrim: linear-gradient(180deg,
            rgba(6,10,22,0.35) 0%,
            rgba(6,10,22,0.55) 45%,
            rgba(6,10,22,0.78) 100%);

  --font-serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-sans:  "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

  --content-max: 42rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Scroll container: one chapter per viewport ---------- */
#story {
  height: 100dvh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  overscroll-behavior-y: contain;
}

.chapter {
  position: relative;
  min-height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: max(4vh, 2rem) 1.5rem;
}

/* ---------- Background layers ---------- */
.chapter video.bg,
.cover-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
/* Video morph: a second clip fades in over the first at a story cue. */
.chapter video.bg-morph {
  opacity: 0;
  transition: opacity 1600ms ease;
}
.chapter.is-morphed video.bg-morph { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .chapter video.bg-morph { transition: opacity 400ms ease; }
}

.cover-art {
  /* default backdrop = title-free "back" art (used by the preface modal) */
  background-image: url("interactive-back.jpg");
  background-size: cover;
  background-position: center;
}
/* cover screen carries the version with the title baked in */
.cover .cover-art { background-image: url("interactive-cover.jpg"); }
/* "The End" reuses the title-free back art (empty sky for the words) */
.theend .cover-art { background-image: url("interactive-back.jpg"); }
/* Preface: reuse cover but drift/zoom subtly so it reads as a living aurora */
.static-aurora { animation: driftAurora 40s ease-in-out infinite alternate; }
@keyframes driftAurora {
  from { transform: scale(1.02) translate3d(0,0,0); }
  to   { transform: scale(1.12) translate3d(-2%, -1%, 0); }
}

.scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--scrim);
  pointer-events: none;
}

/* decorative snow/stars on the cover screens (added by snow.js, desktop only) */
.snow-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.scrim-strong {
  --scrim: linear-gradient(180deg,
            rgba(6,10,22,0.55) 0%,
            rgba(6,10,22,0.7) 45%,
            rgba(6,10,22,0.88) 100%);
}

/* ---------- Text block ---------- */
.content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: var(--content-max);
  color: var(--ink);
  text-shadow: var(--halo);
}
.content.narrow { max-width: 40rem; }

/* Prose chapters: text lives in a frosted reading panel offset to the left,
   so the centred video subject stays visible on the right and the words
   stay legible over anything. (Cover and "The End" are excluded.) */
.chapter:not(.cover):not(.theend) {
  justify-content: flex-start;
  /* lighter, left-weighted scrim — the panel carries legibility, so the
     video shows through more, brightest on the right where the subject sits */
  --scrim: linear-gradient(90deg,
            rgba(6,10,22,0.55) 0%,
            rgba(6,10,22,0.28) 42%,
            rgba(6,10,22,0.06) 100%);
}
.chapter:not(.cover):not(.theend) .content {
  max-width: 34rem;
  padding: clamp(1.5rem, 3.5vw, 2.4rem) clamp(1.5rem, 3.5vw, 2.6rem);
  border-radius: 20px;
  background: rgba(8, 13, 28, 0.46);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  backdrop-filter: blur(12px) saturate(1.1);
}

.eyebrow {
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--candle-gold);
  margin: 0 0 0.6rem;
  text-shadow: 0 1px 10px rgba(0,0,0,0.8);
}

.content h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.05;
  margin: 0 0 1.1rem;
  letter-spacing: 0.5px;
}

.prose p {
  font-family: var(--font-serif);
  font-size: clamp(1.15rem, 2.5vw, 1.5rem);
  line-height: 1.62;
  margin: 0 0 1rem;
  max-width: 38rem;
}
.prose p:last-child { margin-bottom: 0; }
.prose em { font-style: italic; color: var(--ice); }
.coda {
  margin-top: 1.4rem !important;
  color: var(--candle-gold);
  font-size: clamp(1.25rem, 3vw, 1.7rem);
  line-height: 1.5;
}

/* v2: word-level read-along highlighting (see narration.js) */
.word { transition: color 140ms ease, text-shadow 140ms ease; }
.word.is-spoken { color: var(--ice); }                 /* already read */
.word.is-current {                                      /* being spoken now */
  font-weight: 700;
  background: linear-gradient(
    120deg,
    #f2c879 0%,
    #f2c879 38%,
    #ffffff 50%,
    #f2c879 62%,
    #f2c879 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: text-shimmer 6s linear infinite;
  filter: drop-shadow(0 0 8px rgba(242, 200, 121, 0.65)) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
  text-shadow: none !important;
  display: inline;
}

@keyframes text-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* "Read to me" control panel — centered at the bottom of the screen */
.narrate-panel {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(2.5rem, calc(env(safe-area-inset-bottom) + 1.25rem));
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  /* flight from the intro spot (transform set in JS) to the bottom-center spot */
  transition: transform 760ms cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: transform;
}

/* Black to 0% gradient behind the control pill */
.narrate-scrim {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.4) 60%, rgba(0, 0, 0, 0) 100%);
  z-index: 39;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease;
}
body.narrating .narrate-scrim {
  opacity: 1;
}
/* Intro: a large pill centred over the cover, before narration starts */
.narrate-panel.is-intro { animation: narrate-intro-in 600ms ease both; }
@keyframes narrate-intro-in { from { opacity: 0; } to { opacity: 1; } }
.narrate-panel.is-intro .narrate-toggle {
  font-size: 1.15rem;
  padding: 0.95rem 1.9rem;
  border-color: rgba(242, 200, 121, 0.5);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5), 0 0 34px rgba(242, 200, 121, 0.18);
}

.narrate-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--white);
  padding: 0.6rem 1.05rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(8, 13, 28, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 120ms ease,
    font-size 400ms ease, padding 400ms ease;
}
.narrate-toggle:hover { background: rgba(8, 13, 28, 0.8); border-color: rgba(255, 255, 255, 0.5); }
.narrate-toggle:active { transform: translateY(1px); }

.narrate-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(8, 13, 28, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  animation: narrate-slide-in 240ms cubic-bezier(.2,.7,.2,1);
}

@keyframes narrate-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.narrate-btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: transparent;
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 120ms ease, color 120ms ease;
}

.narrate-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.narrate-btn.is-active {
  background: var(--candle-gold);
  color: #2a1c05;
}

.narrate-ico { font-size: 0.8em; line-height: 1; }

@media (prefers-reduced-motion: reduce) {
  .narrate-panel { transition: none; }
  .narrate-panel.is-intro { animation: none; }
}

/* ---------- Cover & The End stacking ---------- */
.chapter.cover,
.chapter.theend {
  position: relative;
  z-index: 35;
}

/* ---------- Cover ---------- */
.cover .scrim {
  background: linear-gradient(180deg,
    rgba(6,10,22,0) 0%,
    rgba(6,10,22,0.15) 55%,
    rgba(6,10,22,0.85) 100%);
}
.cover-content {
  align-self: flex-end;
  text-align: center;
  padding-bottom: 3vh;
}
.byline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  color: var(--ice);
  margin: 0 0 1.4rem;
}
.cover-actions {
  display: flex;
  gap: 0.9rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- The End ---------- */
.theend .scrim {
  background: radial-gradient(ellipse 70% 60% at 50% 45%,
              rgba(6,10,22,0.62) 0%,
              rgba(6,10,22,0.34) 48%,
              rgba(6,10,22,0.12) 100%);
}
.theend-content {
  align-self: center;      /* middle centre */
  text-align: center;
  max-width: 30rem;
}
.theend-title {
  font-family: var(--font-serif);
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 500;
  color: var(--candle-gold);
  margin: 0 0 1.4rem;
  letter-spacing: 1px;
  text-shadow: 0 3px 24px rgba(0,0,0,0.8), 0 0 40px rgba(242,200,121,0.25);
}
.theend-actions { display: flex; flex-direction: column; gap: 0.7rem; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 120ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  text-shadow: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--candle-gold);
  color: #2a1c05;
  box-shadow: 0 6px 24px rgba(242,200,121,0.28);
}
.btn-primary:hover { background: #ffd98a; box-shadow: 0 8px 30px rgba(242,200,121,0.4); }
.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: var(--white);
  border-color: rgba(255,255,255,0.35);
  backdrop-filter: blur(6px);
}
.btn-ghost:hover { background: rgba(255,255,255,0.16); border-color: rgba(255,255,255,0.6); }

.scroll-hint {
  display: block;
  margin-top: 1.6rem;
  font-size: 1.6rem;
  color: var(--white);
  text-decoration: none;
  opacity: 0.85;
  animation: bob 2.2s ease-in-out infinite;
}
@keyframes bob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(8px);} }

/* ---------- Epilogue modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3,6,14,0.72); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  width: min(46rem, 100%);
  max-height: 88dvh;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  animation: rise 240ms cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98);} to { opacity:1; transform:none;} }
.modal-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.modal-scrim { position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(180deg, rgba(6,10,22,0.55), rgba(6,10,22,0.82)); }
.modal-body {
  position: relative; z-index: 2;
  padding: clamp(1.6rem, 4vw, 2.6rem);
  overflow-y: auto;
  max-height: 88dvh;
  color: var(--white);
  text-shadow: var(--halo);
}
.modal-body h2 { font-family: var(--font-serif); font-weight: 600; font-size: clamp(1.8rem,5vw,2.6rem); margin: 0 0 1rem; }
.modal-close {
  position: absolute; top: 0.6rem; right: 0.8rem; z-index: 3;
  width: 2.4rem; height: 2.4rem; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.35); color: var(--white);
  font-size: 1.4rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: rgba(0,0,0,0.55); }

body.modal-open { overflow: hidden; }

/* ---------- Motion / a11y ---------- */
@media (prefers-reduced-motion: reduce) {
  #story { scroll-behavior: auto; }
  .static-aurora, .scroll-hint, .modal-card { animation: none; }
}

/* ---------- Mobile layout (split screen) ---------- */
@media (max-width: 768px) {
  .chapter:not(.cover):not(.theend) {
    display: block;
    padding: 0 !important;
    min-height: 100dvh;
    background: #060a16;
    overflow: visible !important;
  }
  
  .chapter:not(.cover):not(.theend) video.bg {
    position: sticky;
    top: 0;
    height: 40dvh;
    width: 100%;
    margin-bottom: -40dvh;
    z-index: 10;
    object-fit: cover;
  }

  .chapter:not(.cover):not(.theend) .scrim {
    position: sticky;
    top: 0;
    height: 40dvh;
    width: 100%;
    margin-bottom: -40dvh;
    z-index: 11;
    pointer-events: none;
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .chapter:not(.cover):not(.theend) .content {
    position: relative;
    z-index: 5;
    margin-top: 0;
    padding: 43dvh 0 4rem;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    max-width: 100%;
    overflow: hidden;
  }

  /* Pad text content away from sides */
  .chapter:not(.cover):not(.theend) .content > * {
    position: relative;
    z-index: 2;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  /* Frosted ambient background using the back cover art */
  .chapter:not(.cover):not(.theend) .content::before {
    content: "";
    position: absolute;
    top: 40dvh;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    background-image: linear-gradient(180deg, rgba(8, 13, 28, 0.88) 0%, rgba(6, 10, 22, 0.94) 100%), url("interactive-back.jpg");
    background-size: cover;
    background-position: center;
    filter: blur(20px);
    transform: scale(1.15);
  }

  .chapter:not(.cover):not(.theend) .prose p {
    font-size: 1.22rem;
    line-height: 1.6;
    margin-bottom: 1.2rem;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  }
}

@media (max-width: 480px) {
  .chapter.cover, .chapter.theend { padding: max(3vh, 1.25rem) 1.15rem; }
  .prose p { font-size: 1.18rem; }
}

/* ---------- Desktop side-by-side split layout and sliding transitions ---------- */
@media (min-width: 769px) {
  .chapter:not(.cover):not(.theend) video.bg,
  .chapter:not(.cover):not(.theend) .scrim {
    transition: left 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                width 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                right 500ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }
  
  .chapter:not(.cover):not(.theend) .content {
    transition: width 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                max-width 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                background 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                border-radius 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                border-color 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                box-shadow 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                backdrop-filter 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                -webkit-backdrop-filter 500ms cubic-bezier(0.2, 0.7, 0.2, 1),
                padding 500ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  /* Split layout overrides for desktop */
  body.layout-split .chapter:not(.cover):not(.theend) {
    display: block;
    padding: 0 !important;
    min-height: 100dvh;
    height: auto;
    overflow: visible !important;
    background: #060a16;
  }
  
  body.layout-split .chapter:not(.cover):not(.theend) video.bg {
    position: sticky;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100dvh;
    margin-bottom: -100dvh;
    z-index: 10;
    object-fit: cover;
  }

  body.layout-split .chapter:not(.cover):not(.theend) .scrim {
    position: sticky;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100dvh;
    margin-bottom: -100dvh;
    z-index: 11;
    pointer-events: none;
    background: transparent;
    border-bottom: none;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
  }
  
  body.layout-split .chapter:not(.cover):not(.theend) .content {
    width: 50%;
    max-width: 50%;
    min-height: 100dvh;
    height: auto;
    margin: 0;
    border-radius: 0;
    background: rgba(6, 10, 22, 0.98);
    border: none;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    display: block;
    padding: 6rem clamp(2rem, 5vw, 6rem) 4rem;
    overflow: visible;
  }
}
