/* ============================================================================
   ASHFALL — styles
   State machine via <body> classes:
     (loading)        intro shows the loader
     .assets-ready    intro shows "scroll to begin" + sound note
     .started         intro fades out; scene text + chrome appear
     .idle            rail / controls / hint fade away
     .mode-story      linear "read the story" view (over the experience)
     .mode-fallback   permanent linear view when WebGL is unavailable
   ========================================================================== */

:root {
  --serif: 'Cormorant Garamond', 'Cormorant', 'Hoefler Text', Georgia, 'Times New Roman', serif;
  --sans: 'Helvetica Neue', 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  --ink: rgba(248, 244, 240, 0.96);
  --ink-soft: rgba(244, 238, 234, 0.7);
  --ink-faint: rgba(240, 235, 230, 0.42);
  --glow: 0 2px 30px rgba(0, 0, 0, 0.55), 0 0 60px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #07050a;
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { cursor: crosshair; }
body.mode-story, body.mode-fallback { cursor: auto; overflow: auto; }

/* ---- WebGL canvas --------------------------------------------------------- */
#c {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  z-index: 0;
}
body.mode-fallback #c { display: none; }

/* ---- UI overlay ----------------------------------------------------------- */
#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
/* only interactive chrome captures the pointer — the rest stays rippable */
#intro, .credits, .exit-story, .begin, .link-btn { pointer-events: auto; }
.scene-text, .seam-text, .hint { pointer-events: none; }

/* bottom scrim for text legibility on bright frames */
#ui::before {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 46vh;
  background: linear-gradient(to top, rgba(4, 2, 6, 0.62), rgba(4, 2, 6, 0) 100%);
  opacity: 0;
  transition: opacity 1.4s var(--ease);
  pointer-events: none;
}
body.started #ui::before { opacity: 1; }
body.mode-story #ui::before, body.mode-fallback #ui::before { opacity: 0; }

/* ============================================================================
   Entrance gate (black screen → "click to enter" → unlocks audio + reveals intro)
   ========================================================================== */
.gate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  text-align: center;
  background: #000;
  cursor: pointer;
  transition: opacity 1.3s var(--ease), visibility 1.3s var(--ease);
}
body.entered .gate { opacity: 0; visibility: hidden; pointer-events: none; }
.gate-inner { padding: 6vw; animation: gateIn 2.4s var(--ease) both; }
.gate-pre {
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 2.4em;
}
.gate-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(2.2rem, 7vw, 4.8rem);
  letter-spacing: 0.14em;
  text-indent: 0.07em;
  color: var(--ink);
  margin: 0;
  text-shadow: 0 0 50px rgba(255, 210, 170, 0.25), var(--glow);
  animation: gatePulse 3.6s ease-in-out infinite;
}
.gate-hint {
  display: block;
  margin-top: 2.6em;
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  text-transform: uppercase;
  color: var(--ink-faint);
  opacity: 0.55;
}

/* ============================================================================
   Intro / loader
   ========================================================================== */
#intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  background: radial-gradient(120% 120% at 50% 45%, rgba(6, 3, 8, 0.35), rgba(5, 2, 7, 0.78));
  backdrop-filter: blur(2px);
  transition: opacity 1.6s var(--ease), visibility 1.6s var(--ease);
}
body.started #intro { opacity: 0; visibility: hidden; }

.intro-inner { width: 100%; padding: clamp(1.5rem, 4vw, 3.5rem); }

.brand {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(2.6rem, 9vw, 7rem);
  letter-spacing: 0.3em;
  margin: 0 0 0.12em;
  text-indent: 0.15em; /* half the tracking re-centres the trailing letter-space */
  max-width: 100%;
  color: var(--ink);
  text-shadow: 0 0 60px rgba(255, 210, 170, 0.25), var(--glow);
  animation: breathe 9s ease-in-out infinite;
}
.subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  letter-spacing: 0.16em;
  text-indent: 0.08em;
  color: var(--ink-soft);
  margin: 0 0 2.6em;
}

#intro-status { min-height: 60px; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 1.1em; }
.bar {
  width: min(260px, 60vw);
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
#intro-bar {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  background: linear-gradient(90deg, rgba(255, 200, 150, 0.9), rgba(255, 245, 235, 0.95));
  transition: transform 0.35s var(--ease);
}
.loading-label {
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-indent: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.ready-row { display: none; flex-direction: column; align-items: center; gap: 1.8em; }
body.assets-ready .loading { display: none; }
body.assets-ready .ready-row { display: flex; }

.begin {
  appearance: none;
  background: none;
  border: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em; /* button text is left-aligned within its box; full tracking centres it */
  text-transform: uppercase;
  padding: 0.9em 0.7em;
  cursor: pointer;
  position: relative;
  animation: pulse 3.4s ease-in-out infinite;
}
.begin::after {
  content: '';
  position: absolute;
  left: 50%; bottom: 0;
  width: 1px; height: 26px;
  transform: translate(-50%, 100%);
  background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0));
}

/* ============================================================================
   Per-scene text
   ========================================================================== */
.scene-text {
  position: absolute;
  left: clamp(1.5rem, 6vw, 7rem);
  bottom: clamp(2.2rem, 9vh, 6rem);
  max-width: min(46ch, 80vw);
  opacity: 0;
  will-change: opacity, transform;
}
.scene-text .kicker {
  display: block;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.6em;
  color: var(--ink-faint);
  margin-bottom: 1.1em;
}
.scene-text .title {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: 0.04em;
  margin: 0 0 0.5em;
  text-shadow: var(--glow);
}
.scene-text .verse {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1rem, 2.2vw, 1.4rem);
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 0;
  text-shadow: 0 1px 20px rgba(0, 0, 0, 0.6);
}
body.mode-story .scene-text, body.mode-fallback .scene-text { display: none; }

/* loop-seam line */
.seam-text {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1.1rem, 3vw, 2rem);
  letter-spacing: 0.12em;
  color: rgba(40, 24, 30, 0.92); /* dark, legible over the white-out bloom */
  text-align: center;
  max-width: 80vw;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.6);
}

/* ============================================================================
   Landing-page links (the requiem · credits)
   ========================================================================== */
.intro-links { display: flex; align-items: center; gap: 0.9em; }
.intro-links .dot { color: var(--ink-faint); }
.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.3em 0.2em;
  transition: color 0.4s;
}
.link-btn:hover { color: var(--ink); }

/* ============================================================================
   Hint
   ========================================================================== */
.hint {
  position: absolute;
  left: 50%; bottom: clamp(1rem, 3vh, 2.2rem);
  transform: translateX(-50%);
  font-size: 0.62rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity 1s var(--ease);
  white-space: nowrap;
}
body.started .hint { opacity: 0.7; }
body.idle .hint, body.mode-story .hint, body.mode-fallback .hint { opacity: 0; }

/* ============================================================================
   Credits
   ========================================================================== */
.credits {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -46%);
  width: min(420px, 90vw);
  max-height: 84vh;
  overflow: auto;
  padding: 2.2rem 2.2rem 1.8rem;
  background: rgba(10, 7, 12, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  border-radius: 8px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease), visibility 0.5s;
  z-index: 60;
}
.credits.open { opacity: 1; visibility: visible; transform: translate(-50%, -50%); }
.credits h3 { font-family: var(--serif); font-weight: 300; letter-spacing: 0.3em; margin: 0 0 0.2em; }
.credits-tag { font-family: var(--serif); font-style: italic; color: var(--ink-soft); margin: 0 0 1.4em; }
.credits dl { margin: 0; display: grid; gap: 1em; }
.credits dt { font-size: 0.62rem; letter-spacing: 0.28em; text-transform: uppercase; color: var(--ink-faint); }
.credits dd { margin: 0.3em 0 0; font-size: 0.9rem; line-height: 1.5; color: var(--ink-soft); }
.credits .muted { color: var(--ink-faint); }
.credits-foot { margin: 1.6em 0 0; font-size: 0.72rem; color: var(--ink-faint); line-height: 1.5; }
.credits-close {
  position: absolute; top: 0.6rem; right: 0.9rem;
  background: none; border: none; color: var(--ink-soft);
  font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.credits-close:hover { color: var(--ink); }

/* ============================================================================
   Story / fallback (linear)
   ========================================================================== */
#story {
  position: relative;
  z-index: 5;
  display: none;
}
body.mode-story, body.mode-fallback { height: auto; min-height: 100%; overflow-y: auto; scroll-snap-type: y proximity; }
body.mode-story #story, body.mode-fallback #story { display: block; }
body.mode-story #intro, body.mode-fallback #intro { display: none; }
body.mode-story .scene-text, body.mode-story .seam-text, body.mode-story .hint,
body.mode-fallback .seam-text, body.mode-fallback .hint { display: none; }
/* dim the live canvas behind the reader for focus */
body.mode-story #c { opacity: 0.25; transition: opacity 0.6s var(--ease); }

.story-scene {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: end start;
  overflow: hidden;
  background: #07050a;
  scroll-snap-align: start;
}
.story-head { place-items: center; text-align: center; background: radial-gradient(120% 120% at 50% 45%, #160a12, #07050a 70%); }
.story-head .brand {
  font-family: var(--serif); font-weight: 300;
  font-size: clamp(2.6rem, 9vw, 6rem); letter-spacing: 0.3em; text-indent: 0.15em;
  margin: 0 0 0.2em; text-shadow: 0 0 60px rgba(255, 210, 170, 0.22), var(--glow);
}
.story-scrollhint { margin-top: 2.4em; font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.34em; text-transform: uppercase; color: var(--ink-faint); }
.story-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  will-change: transform;
}
.story-scene::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(4, 2, 6, 0.7), rgba(4, 2, 6, 0.05) 55%);
  z-index: 1;
}
.story-text {
  position: relative;
  z-index: 2;
  padding: clamp(2rem, 7vw, 6rem);
  max-width: 52ch;
}
.story-text .kicker { display: block; font-size: 0.72rem; letter-spacing: 0.6em; color: var(--ink-faint); margin-bottom: 1em; }
.story-text .title { font-family: var(--serif); font-weight: 300; font-size: clamp(2rem, 6vw, 4rem); margin: 0 0 0.4em; text-shadow: var(--glow); }
.story-text .verse { font-family: var(--serif); font-style: italic; font-size: clamp(1rem, 2.4vw, 1.4rem); line-height: 1.6; color: var(--ink-soft); margin: 0; }
.story-coda { place-items: center; text-align: center; }
.story-coda .verse { font-size: clamp(1.2rem, 3vw, 2rem); }

.exit-story {
  position: fixed;
  left: clamp(1rem, 2.4vw, 2rem);
  top: clamp(1rem, 2.4vw, 2rem);
  z-index: 50;
  display: none;
  background: rgba(10, 7, 12, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.6em 1.2em;
  font-size: 0.64rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
body.mode-story .exit-story { display: block; }
.exit-story:hover { color: var(--ink); }

/* ---- noscript ------------------------------------------------------------- */
.noscript {
  position: fixed; inset: 0; display: grid; place-items: center; text-align: center;
  background: #07050a; z-index: 999; padding: 2rem;
}
.noscript h1 { font-family: var(--serif); font-weight: 300; letter-spacing: 0.4em; }

/* ============================================================================
   Animations
   ========================================================================== */
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes gateIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes gatePulse {
  0%, 100% { opacity: 0.8; text-shadow: 0 0 40px rgba(255, 200, 160, 0.18), var(--glow); }
  50% { opacity: 1; text-shadow: 0 0 85px rgba(255, 215, 175, 0.42), var(--glow); }
}
@keyframes breathe { 0%, 100% { text-shadow: 0 0 50px rgba(255, 200, 160, 0.18), var(--glow); } 50% { text-shadow: 0 0 80px rgba(255, 215, 175, 0.38), var(--glow); } }

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 720px) {
  .hint { bottom: 2.4rem; font-size: 0.55rem; letter-spacing: 0.22em; }
  .scene-text { bottom: 3.4rem; }
  .credits { width: min(92vw, 420px); }
}

/* ============================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .brand, .begin, .gate-title, .gate-inner { animation: none; }
  * { scroll-behavior: auto; }
}
