/* =============================================================================
   02-base.css  —  Reset, layout engine, shared UI, responsive
   ========================================================================== */

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

html, body { height: 100%; }

body {
  font-family: var(--font-serif);
  background: var(--night);
  color: var(--moon);
  overflow: hidden;                 /* the chapter engine handles flow */
  -webkit-font-smoothing: antialiased;
  transition: background var(--med) var(--ease);
}

/* Body theme groups (set by navigation.js) */
body.story-mode { background: var(--night); color: var(--moon); }
body.hr-mode    { background: var(--hr-bg);  color: var(--hr-slate); }

img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ---- Screen (chapter) engine ------------------------------------------ */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;            /* horizontal centering */
  padding: clamp(20px, 6vw, 64px);
  overflow-y: auto;
}
/* margin:auto centers short content vertically, but collapses when content is
   taller than the viewport so the top stays reachable (avoids the flexbox clip bug) */
.screen__inner { margin: auto 0; }
.screen.active {
  display: flex;
  animation: screen-in var(--med) var(--ease) both;
}
.screen.leaving { animation: screen-out var(--fast) var(--ease) both; }

@keyframes screen-in  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes screen-out { from { opacity: 1; } to { opacity: 0; } }

.screen__inner {
  width: 100%;
  max-width: var(--maxw);
  text-align: center;
}

/* ---- Shared reveal utility -------------------------------------------- */
.reveal { opacity: 0; transform: translateY(20px); }
.reveal.in { opacity: 1; transform: none; transition: opacity var(--slow) var(--ease), transform var(--slow) var(--ease); }

/* ---- Typewriter line -------------------------------------------------- */
.tw-line { opacity: 0; }
.tw-line.show { opacity: 1; }
.caret::after {
  content: '';
  display: inline-block;
  width: 2px; height: 1em;
  margin-left: 2px;
  background: currentColor;
  vertical-align: -2px;
  animation: blink 900ms steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- Buttons ---------------------------------------------------------- */
.btn-moon {
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--star-gold);
  padding: 14px 30px;
  border: 1px solid rgba(244, 201, 93, 0.5);
  border-radius: 999px;
  background: rgba(244, 201, 93, 0.04);
  transition: all var(--fast) var(--ease);
}
.btn-moon:hover {
  background: rgba(244, 201, 93, 0.14);
  box-shadow: 0 0 26px rgba(244, 201, 93, 0.28);
  transform: translateY(-1px);
}

.btn-hr {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.95rem;
  color: #fff;
  background: var(--hr-blue);
  padding: 12px 22px;
  border-radius: 8px;
  transition: all var(--fast) var(--ease);
}
.btn-hr:hover { background: var(--hr-blue-dark); }
.btn-hr::after { content: '  →'; }

/* ---- Media placeholder slots ------------------------------------------ */
.media {
  position: relative;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: var(--twilight);
  border: 1px solid rgba(244, 201, 93, 0.18);
  display: grid;
  place-items: center;
  min-height: 200px;
}
.media img, .media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.media img.hidden, .media video.hidden { display: none; }
.media__label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--lavender);
  padding: 16px;
  text-align: center;
  line-height: 1.6;
  z-index: 1;
}
.media__label b { color: var(--star-gold); display: block; margin-bottom: 6px; letter-spacing: 0.05em; }
.media.has-media .media__label { display: none; }
body.hr-mode .media { background: var(--hr-border); border-color: var(--hr-border); }
body.hr-mode .media__label { color: var(--hr-muted); }
body.hr-mode .media__label b { color: var(--hr-blue); }

/* ---- Progress bar + music toggle (persistent chrome) ------------------ */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--star-gold), var(--rose));
  z-index: 50; transition: width var(--med) var(--ease); opacity: 0;
}
#progress.show { opacity: 1; }

#music-toggle {
  position: fixed; top: 16px; right: 16px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  border: 1px solid rgba(244,201,93,0.4); background: rgba(11,16,38,0.6);
  color: var(--star-gold); font-size: 1.1rem; backdrop-filter: blur(6px);
  transition: all var(--fast) var(--ease);
}
#music-toggle.show { display: flex; }
#music-toggle:hover { box-shadow: 0 0 18px rgba(244,201,93,0.4); }
body.hr-mode #music-toggle { border-color: var(--hr-border); background: #fff; color: var(--hr-blue); }

#back-btn {
  position: fixed; top: 16px; left: 16px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  border: 1px solid rgba(244,201,93,0.4); background: rgba(11,16,38,0.6);
  color: var(--star-gold); font-size: 1.6rem; line-height: 1; padding-bottom: 3px;
  backdrop-filter: blur(6px); transition: all var(--fast) var(--ease);
}
#back-btn.show { display: flex; }
#back-btn:hover { box-shadow: 0 0 18px rgba(244,201,93,0.4); }
body.hr-mode #back-btn { border-color: var(--hr-border); background: #fff; color: var(--hr-blue); }

/* ---- Gold glowing string (access screen: ties the Star to the Moon) --- */
#string { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; z-index: 0; }
#string.show { display: block; }
#string path {
  fill: none;
  stroke: var(--star-gold); stroke-width: 1.8; stroke-linecap: round;
  filter: drop-shadow(0 0 7px rgba(244,201,93,0.85));
  animation: string-pulse 2.6s ease-in-out infinite alternate;
}
@keyframes string-pulse { from { opacity: 0.45; } to { opacity: 1; } }
/* A bright bead of light travels along the string, star → moon, on a loop */
#string path.string-spark {
  stroke: #fff7da; stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 3 97;                 /* pathLength=100 → one short bright dash */
  filter: drop-shadow(0 0 7px rgba(255, 247, 200, 0.95));
  animation: string-shoot 2.2s linear infinite;
  opacity: 0.95;
}
@keyframes string-shoot { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -100; } }

/* ---- Click sparkle burst (on next / continue buttons) ----------------- */
.spark-bit {
  position: fixed; z-index: 90; pointer-events: none; line-height: 1;
  transform: translate(-50%, -50%);
  text-shadow: 0 0 6px currentColor;
  animation: spark-fly 760ms ease-out forwards;
}
@keyframes spark-fly {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.3) rotate(0deg); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--tx, 0px)), calc(-50% + var(--ty, 0px))) scale(1.15) rotate(150deg); }
}

/* ---- Starfield + moon (story background) ------------------------------ */
#sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; transition: opacity var(--med) var(--ease); }
body.hr-mode #sky { opacity: 0; }
.star {
  position: absolute; background: #fff; border-radius: 50%;
  animation: twinkle var(--dur, 3s) ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.2; } to { opacity: 1; } }

/* The brighter stars get a real 4-point sparkle shape that shimmers + slowly turns */
.star.sparkle {
  border-radius: 0;
  background: #fff;
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.85));
  animation: twinkle var(--dur, 3s) ease-in-out infinite alternate, sparkle-spin 16s linear infinite;
}
@keyframes sparkle-spin { to { transform: rotate(360deg); } }
#moon {
  position: fixed; top: 8%; right: 10%; width: 120px; height: 120px; border-radius: 50%;
  background:
    radial-gradient(circle at 62% 30%, rgba(150,148,188,0.55) 0 6px, transparent 7px),
    radial-gradient(circle at 40% 58%, rgba(150,148,188,0.5) 0 9px, transparent 10px),
    radial-gradient(circle at 70% 66%, rgba(150,148,188,0.45) 0 5px, transparent 6px),
    radial-gradient(circle at 30% 40%, rgba(150,148,188,0.4) 0 4px, transparent 5px),
    radial-gradient(circle at 52% 78%, rgba(150,148,188,0.35) 0 3px, transparent 4px),
    radial-gradient(circle at 35% 35%, #fff, var(--moon) 45%, #9a98c0 100%);
  box-shadow: 0 0 80px 20px rgba(232, 230, 240, 0.25); z-index: -1;
  transition: opacity var(--med) var(--ease);
}
body.hr-mode #moon { opacity: 0; }

/* ---- Typography helpers ----------------------------------------------- */
.eyebrow { font-family: var(--font-script); color: var(--star-gold); font-size: 1.6rem; }
h1.title, .title {
  font-family: var(--font-display); font-weight: 500;
  font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.1; margin-bottom: 0.4em;
}
.subtitle { font-style: italic; color: var(--lavender); font-size: 1.15rem; margin-bottom: 1.5em; }
.prose p { font-size: clamp(1.1rem, 3.4vw, 1.45rem); line-height: 1.6; margin: 0.6em 0; color: var(--moon); }
.signature { font-family: var(--font-script); color: var(--star-gold); font-size: 1.5rem; margin-top: 1em; }
.spacer { height: 1.8rem; }

.name-star { color: var(--star-gold); }

/* ---- Sparkle cursor / touch trail ------------------------------------- */
.trail-bit {
  position: fixed; z-index: 85; pointer-events: none; font-size: 12px;
  transform: translate(-50%, -50%); text-shadow: 0 0 5px currentColor;
  animation: trail-fade 700ms ease-out forwards;
}
@keyframes trail-fade {
  from { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, 8px) scale(0.4); }
}

/* ---- Shooting stars --------------------------------------------------- */
.shooting-star {
  position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 8px 2px rgba(255, 255, 255, 0.9);
  animation: shoot 1.3s ease-in forwards;
}
/* Tail trails out behind the head (local +x); the whole streak is rotated to its travel angle */
.shooting-star::after {
  content: ''; position: absolute; top: 50%; left: 2px; width: 120px; height: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.95), transparent);
  transform: translateY(-50%); border-radius: 2px;
}
@keyframes shoot {
  0%   { opacity: 0; transform: rotate(-28deg) translateX(0); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: rotate(-28deg) translateX(-340px); }
}

/* ---- "Yes" celebration: petals + confetti ----------------------------- */
.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 120; overflow: hidden; }
.petal { position: fixed; top: -6vh; will-change: transform; animation: petal-fall linear forwards; }
@keyframes petal-fall {
  0%   { opacity: 0; transform: translate(0, -6vh) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0.9; transform: translate(var(--sway, 0), 112vh) rotate(420deg); }
}
.confetti {
  position: fixed; left: 50vw; top: 58vh; width: 9px; height: 14px; border-radius: 2px;
  opacity: 0; animation: confetti-burst 1.7s ease-out forwards;
}
@keyframes confetti-burst {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--tx, 0), var(--ty, 0)) rotate(560deg); }
}

/* ---- Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 1ms !important; }
}
