:root {
  --glass-tint: rgba(15, 23, 42, 0.6);
  --text-body: #e2e8f0;
  --nicole-cyan: #a5f3fc;
  --jecka-pink: #fbcfe8;
  --glow-anxious: 0 0 4px rgba(165, 243, 252, 0.5);
  --glow-warm: 0 0 15px rgba(251, 207, 232, 0.6);
  --glass-border: rgba(255, 255, 255, 0.22);
  --frost-blur: 12px;
  --max-width: 760px;
  --side-pad: clamp(20px, 5vw, 64px);
  --act-gap: clamp(32px, 6vw, 72px);
}

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

body {
  min-height: 100vh;
  background-color: #0f1215;
  color: var(--text-body);
  font-family: "EB Garamond", serif;
  position: relative;
  z-index: 0;
  user-select: none;
  transition: color 0.8s ease, background 0.8s ease;
}

body.act-1 {
  --glass-tint: rgba(15, 23, 42, 0.6);
  --text-body: #e2e8f0;
  --frost-blur: 12px;
}

body.act-2 {
  --glass-tint: rgba(18, 24, 30, 0.62);
  --text-body: #e7ecf4;
  --frost-blur: 12px;
}

body.act-3 {
  --glass-tint: rgba(16, 18, 30, 0.62);
  --text-body: #f1f5f9;
  --frost-blur: 20px;
}

body.act-4 {
  --glass-tint: rgba(245, 248, 255, 0.75);
  --text-body: #1f2937;
  --glass-border: rgba(15, 23, 42, 0.15);
  --frost-blur: 14px;
  background: #e9eef6;
}

.bg-layer {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.02);
  transition: opacity 1.4s ease, filter 1.4s ease;
  z-index: 0;
}

.bg-layer.night {
  background-image: url("assets/bg-night.jpg");
  opacity: 1;
}

.bg-layer.morning {
  background-image: url("assets/bg-night.jpg");
  opacity: 0;
  filter: brightness(1.25) saturate(0.9) contrast(0.95) hue-rotate(-10deg);
}

.bg-layer.morning::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.55), transparent 55%),
    radial-gradient(circle at 70% 40%, rgba(240, 220, 190, 0.45), transparent 60%),
    linear-gradient(180deg, rgba(220, 230, 245, 0.55), rgba(245, 245, 245, 0.25));
  mix-blend-mode: screen;
  opacity: 0.9;
}

.bg-layer.night::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 40%, rgba(247, 158, 99, 0.4), transparent 60%),
    radial-gradient(circle at 70% 60%, rgba(36, 17, 12, 0.55), transparent 65%);
  opacity: 0;
  transition: opacity 1.2s ease;
}

.bg-layer.night::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 30%, rgba(162, 127, 255, 0.2), transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(226, 160, 255, 0.18), transparent 55%),
    radial-gradient(circle at 60% 80%, rgba(136, 188, 255, 0.18), transparent 55%);
  opacity: 0;
  transition: opacity 1.2s ease;
}

body.act-2 .bg-layer.night::after,
body.act-3 .bg-layer.night::after {
  opacity: 0.6;
}

body.act-3 .bg-layer.night::before {
  opacity: 0.7;
}

body.act-3 .bg-layer.night {
  filter: blur(1px) saturate(1.1);
}

body.act-4 .bg-layer.night {
  opacity: 0;
}

body.act-4 .bg-layer.morning {
  opacity: 1;
}

.cursor-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    circle at var(--cursor-x, 50%) var(--cursor-y, 50%),
    rgba(251, 207, 232, 0.2),
    rgba(247, 158, 99, 0.1) 12%,
    transparent 28%
  );
  mix-blend-mode: screen;
  opacity: 0.65;
  transition: opacity 0.6s ease;
}

#ambient-canvas,
#snow-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#ambient-canvas {
  z-index: 1;
}

#snow-canvas {
  z-index: 2;
}

.story-container {
  position: relative;
  z-index: 5;
  max-width: var(--max-width);
  margin: clamp(24px, 6vh, 56px) auto;
  padding: var(--side-pad);
  background: var(--glass-tint);
  border-radius: 28px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 20px 60px rgba(8, 12, 20, 0.45);
  backdrop-filter: blur(var(--frost-blur));
  -webkit-backdrop-filter: blur(var(--frost-blur));
  transition: background 0.8s ease, box-shadow 0.8s ease, backdrop-filter 0.8s ease,
    filter 1.2s ease, opacity 1.2s ease;
}

.story-header {
  text-align: center;
  margin-bottom: var(--act-gap);
}

.eyebrow {
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-size: 0.75rem;
  margin: 0 0 12px;
  opacity: 0.75;
}

h1 {
  font-family: "Cormorant Upright", serif;
  font-weight: 600;
  font-size: clamp(2.4rem, 4vw, 3.4rem);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.subhead {
  font-size: 1rem;
  opacity: 0.8;
}

h2 {
  font-family: "Cormorant Upright", serif;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 1rem;
  margin: 0 0 18px;
  opacity: 0.85;
}

p {
  font-size: clamp(1.05rem, 1.2vw + 0.8rem, 1.2rem);
  line-height: 1.7;
  margin: 0 0 16px;
}

.timestamp {
  font-style: italic;
  opacity: 0.75;
}

.act-divider {
  height: 1px;
  margin: var(--act-gap) 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  opacity: 0.5;
}

span.voice {
  font-weight: 600;
  transition: text-shadow 0.4s ease;
}

span.voice.nicole {
  color: var(--nicole-cyan);
  text-shadow: var(--glow-anxious);
}

span.voice.jecka {
  color: var(--jecka-pink);
  text-shadow: var(--glow-warm);
}

body.act-3 span.voice {
  text-shadow: 0 0 20px currentColor;
}

body.act-4 span.voice {
  text-shadow: 0 0 10px rgba(20, 40, 60, 0.25);
}

.act-illustrations {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 32px;
}

.act-illustrations img {
  width: clamp(120px, 20vw, 180px);
  opacity: 0.85;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.15));
}

.chapter-nav {
  position: fixed;
  top: clamp(24px, 6vh, 48px);
  left: clamp(16px, 4vw, 48px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(10, 14, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 6;
  max-width: 220px;
  transition: filter 1.2s ease, opacity 1.2s ease;
}

.chapter-nav .nav-title {
  font-family: "Cormorant Upright", serif;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.8;
}

.chapter-nav a {
  color: inherit;
  text-decoration: none;
  font-size: 0.95rem;
  opacity: 0.85;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.chapter-nav a:hover {
  opacity: 1;
  transform: translateX(4px);
}

.chapter-nav a.active {
  opacity: 1;
  font-weight: 600;
  transform: translateX(6px);
}

.volume-slider {
  width: 100%;
  max-width: 200px;
  margin-top: 10px;
  appearance: none;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(251, 207, 232, 0.75), rgba(165, 243, 252, 0.55));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 10px rgba(251, 207, 232, 0.35);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 10px rgba(251, 207, 232, 0.35);
  cursor: pointer;
}

body.act-4 .chapter-nav {
  background: rgba(245, 248, 255, 0.7);
  border-color: rgba(15, 23, 42, 0.12);
}

body.act-4 .act-divider {
  background: linear-gradient(90deg, transparent, rgba(10, 20, 40, 0.2), transparent);
}

.enter-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 21, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  color: #ecf0f1;
  cursor: pointer;
  transition: opacity 1s ease, visibility 1s ease;
}

.enter-text {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  text-transform: lowercase;
  display: inline-block;
  white-space: nowrap;
  will-change: opacity, letter-spacing, filter, transform;
  opacity: 0.6;
  filter: blur(2px);
  transform: scale(0.98);
  transition: opacity 1.2s cubic-bezier(0.2, 1, 0.3, 1),
    letter-spacing 1.2s cubic-bezier(0.2, 1, 0.3, 1),
    filter 1.2s cubic-bezier(0.2, 1, 0.3, 1),
    transform 1.2s cubic-bezier(0.2, 1, 0.3, 1);
}

.enter-overlay:hover .enter-text,
.enter-overlay:focus-visible .enter-text {
  opacity: 1;
  letter-spacing: 0.35em;
  filter: blur(0);
  transform: scale(1);
}

.enter-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.blurred .story-container,
body.blurred .chapter-nav {
  filter: blur(8px);
  opacity: 0.55;
}

.film-grain {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
  animation: grainShift 1s steps(2) infinite;
}

body.reduce-motion:not(.force-motion) #snow-canvas,
body.reduce-motion:not(.force-motion) #ambient-canvas,
body.reduce-motion:not(.force-motion) .cursor-glow {
  display: none;
}

@media (max-width: 640px) {
  .story-container {
    margin: 16px;
    padding: clamp(18px, 6vw, 28px);
  }

  .story-header {
    margin-bottom: 28px;
  }

  .chapter-nav {
    position: static;
    margin: 16px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #snow-canvas {
    display: none;
  }
}

@keyframes grainShift {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-2%, -1%);
  }
  40% {
    transform: translate(1%, 2%);
  }
  60% {
    transform: translate(-1%, 1%);
  }
  80% {
    transform: translate(2%, -2%);
  }
  100% {
    transform: translate(0, 0);
  }
}
