/* ============================================================
   STORY V3 — SCROLL-DRIVEN SLIDE PARALLAX
   Desktop : 350vh sticky container, 3 cinematic slides
   Mobile  : static stacked cards with scroll-reveal
   ============================================================ */

/* ── Shared content styles (desktop + mobile) ─────────────── */

.story-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: rgba(0, 170, 255, 0.62);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 0.15rem 0.65rem;
  border: 1px solid rgba(0, 170, 255, 0.18);
  border-radius: 3px;
  background: rgba(0, 170, 255, 0.05);
}

.story-title {
  font-family: var(--font-main);
  font-size: clamp(1.5rem, 2.8vw, 2.4rem);
  font-weight: 700;
  color: var(--text-light);
  line-height: 1.2;
  margin-top: 0.9rem;
  margin-bottom: 0;
}

.story-title em {
  font-family: 'Playfair Display', Georgia, serif;
  font-style: italic;
  font-weight: 700;
  color: var(--accent);
}

.story-rule {
  border: none;
  height: 1px;
  background: linear-gradient(to right,
    rgba(0, 170, 255, 0.45),
    rgba(0, 170, 255, 0.08) 55%,
    transparent
  );
  margin: 1.2rem 0 1.3rem;
}

.story-body {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.72;
  margin-bottom: 0.55rem;
}
.story-body:last-child { margin-bottom: 0; }

.story-body strong {
  color: var(--text-light);
  font-weight: 600;
}

.story-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 1.4rem;
}

.story-tags .tag {
  background: rgba(0, 80, 180, 0.10);
  border-color: rgba(0, 150, 255, 0.20);
  font-size: 0.74rem;
  padding: 0.16rem 0.62rem;
}

/* ── DESKTOP (≥ 769px) ─────────────────────────────────────── */
@media (min-width: 769px) {

  /* Outer wrapper — scroll budget set by JS (CHAPTERS × 100vh = 300vh).
     position:relative is the containing block for .is-past (absolute bottom). */
  .story-wrapper {
    height: 300vh; /* fallback; JS overrides with exact value */
    position: relative;
  }

  /* Pinned container — starts absolute, JS adds .is-pinned (fixed) / .is-past */
  .story-sticky {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template-columns: 320px 1fr;
    background: rgba(1, 6, 20, 0.52);
  }

  /* Fixed when inside the pin zone (body overflow-x:hidden breaks CSS sticky,
     so we manage pinning in JS instead) */
  .story-sticky.is-pinned {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10; /* above sections (z:1), below navbar (z:100) */
  }

  /* Absolute-bottom when scrolled past — anchors visually at wrapper end */
  .story-sticky.is-past {
    position: absolute;
    top: auto;
    bottom: 0;
  }

  /* Top/bottom feather — blends into surrounding sections */
  .story-sticky::before,
  .story-sticky::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 110px;
    z-index: 4;
    pointer-events: none;
  }
  .story-sticky::before {
    top: 0;
    background: linear-gradient(to bottom, var(--bg-deep) 0%, transparent 100%);
  }
  .story-sticky::after {
    bottom: 0;
    background: linear-gradient(to top, var(--bg-deep) 0%, transparent 100%);
  }

  /* ── Circuit background (inside sticky, parallaxes with JS) ── */
  .story-circuit-bg {
    position: absolute;
    inset: -25% -5%;
    z-index: 0;
    pointer-events: none;
    will-change: transform;
  }

  .story-circuit-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.055;
  }

  /* Ghost numbers: hidden on desktop (year panel handles this) */
  .story-ghost-num { display: none; }

  /* ── LEFT: Year panel ────────────────────────────────────── */
  .story-year-panel {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-right: 1px solid rgba(0, 170, 255, 0.09);
  }

  /* Radial ambient glow behind year */
  .story-year-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 70% 55% at 50% 55%,
      rgba(0, 60, 140, 0.22) 0%,
      transparent 70%
    );
    pointer-events: none;
  }

  /* Ghost year: massive outline behind the real number */
  .story-year-ghost {
    position: absolute;
    font-family: var(--font-mono);
    font-size: clamp(9rem, 17vw, 15rem);
    font-weight: 800;
    color: transparent;
    -webkit-text-stroke: 1px rgba(0, 170, 255, 0.08);
    line-height: 1;
    letter-spacing: -0.06em;
    user-select: none;
    pointer-events: none;
    transition: opacity 0.4s ease;
  }

  /* Real year display */
  .story-year-num {
    font-family: var(--font-mono);
    font-size: clamp(3.5rem, 6.5vw, 6rem);
    font-weight: 800;
    color: transparent;
    -webkit-text-stroke: 1.5px rgba(0, 170, 255, 0.72);
    line-height: 1;
    letter-spacing: -0.05em;
    user-select: none;
    position: relative;
    z-index: 1;
    text-shadow: 0 0 60px rgba(0, 130, 255, 0.25);
  }

  /* Year entrance animation — flip up from below with blur */
  @keyframes yearIn {
    from {
      opacity: 0;
      transform: translateY(28px);
      filter: blur(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
      filter: blur(0);
    }
  }
  .story-year-num.year-animate {
    animation: yearIn 0.52s cubic-bezier(0, 0, 0.2, 1) both;
  }

  /* Chapter counter: 01 / 03 */
  .story-chapter-idx-wrap {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    margin-top: 1.4rem;
    position: relative;
    z-index: 1;
  }
  .story-chapter-idx-current {
    color: var(--accent);
    font-weight: 600;
  }
  .story-chapter-idx-total {
    opacity: 0.5;
  }

  /* ── Vertical chronology timeline (inside year panel) ───── */
  .story-timeline-nodes {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 2.4rem;
    gap: 0;
  }

  .stn-track {
    position: absolute;
    top: 6px;       /* center of first node */
    bottom: 6px;    /* center of last node */
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    background: rgba(0, 170, 255, 0.13);
    pointer-events: none;
  }

  .stn-fill {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 0%;
    background: linear-gradient(to bottom,
      rgba(0, 170, 255, 0.85),
      rgba(0, 100, 220, 0.45)
    );
    transition: height 0.55s cubic-bezier(0, 0, 0.2, 1);
  }

  .stn-node {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1.5px solid rgba(0, 170, 255, 0.30);
    background: transparent;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    transition: background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, transform 0.4s ease;
  }

  .stn-node + .stn-node { margin-top: 30px; }

  .stn-node.is-done {
    background: rgba(0, 170, 255, 0.55);
    border-color: rgba(0, 170, 255, 0.75);
  }

  .stn-node.is-active {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.35);
    box-shadow:
      0 0 0 4px rgba(0, 170, 255, 0.15),
      0 0 16px rgba(0, 170, 255, 0.65);
    animation: stnPulse 2.2s ease-in-out infinite;
  }

  @keyframes stnPulse {
    0%, 100% {
      box-shadow: 0 0 0 4px rgba(0, 170, 255, 0.15), 0 0 16px rgba(0, 170, 255, 0.65);
    }
    50% {
      box-shadow: 0 0 0 8px rgba(0, 170, 255, 0.06), 0 0 28px rgba(0, 170, 255, 0.9);
    }
  }

  /* ── RIGHT: Slides panel ─────────────────────────────────── */
  .story-slides-panel {
    position: relative;
    z-index: 1;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 5rem;
    padding-top: 128px;
    padding-bottom: 3rem;
  }

  /* Section label: absolutely positioned over full sticky width so it
     sits at the same container-centred position as every other section */
  .story-label-wrap {
    position: absolute;
    top: 100px;   /* matches section { padding: 100px 0 } everywhere else */
    left: 0;
    right: 0;
    z-index: 5;
    pointer-events: none;
  }

  /* Slides container — fills remaining height between label and progress */
  .story-slides-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
    display: flex;
    align-items: flex-start; /* content grows downward, prevents top-clip on long titles */
    padding-top: 1.2rem;
  }

  /* ── Individual slides ── */
  .story-slide {
    position: absolute;
    width: 100%;
    max-width: 640px;
    opacity: 0;
    transform: translateX(62px);
    /* Smooth entrance */
    transition:
      opacity  500ms cubic-bezier(0, 0, 0.2, 1),
      transform 500ms cubic-bezier(0, 0, 0.2, 1);
    pointer-events: none;
  }

  /* Active state */
  .story-slide.is-active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
    position: relative; /* let wrap measure height */
  }

  /* Exit state — faster ease-in, goes to the left */
  .story-slide.is-exiting {
    opacity: 0;
    transform: translateX(-62px);
    transition:
      opacity  280ms cubic-bezier(0.4, 0, 1, 1),
      transform 280ms cubic-bezier(0.4, 0, 1, 1);
    pointer-events: none;
    position: absolute;
  }

  /* Already past (behind current) */
  .story-slide.is-past {
    opacity: 0;
    transform: translateX(-62px);
    pointer-events: none;
  }

  /* ── Staggered child enter animations ── */
  .story-slide .story-badge,
  .story-slide .story-title,
  .story-slide .story-rule,
  .story-slide .story-body-wrap,
  .story-slide .story-tags {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 380ms ease-out, transform 380ms ease-out;
  }

  .story-slide.is-active .story-badge     { opacity: 1; transform: none; transition-delay:  60ms; }
  .story-slide.is-active .story-title     { opacity: 1; transform: none; transition-delay: 130ms; }
  .story-slide.is-active .story-rule      { opacity: 1; transform: none; transition-delay: 185ms; }
  .story-slide.is-active .story-body-wrap { opacity: 1; transform: none; transition-delay: 220ms; }
  .story-slide.is-active .story-tags      { opacity: 1; transform: none; transition-delay: 285ms; }

  /* ── Progress row ── */
  .story-progress-row {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.2rem;
  }

  .story-dots {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .story-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    transition:
      background    0.35s ease,
      width         0.35s cubic-bezier(0.4, 0, 0.2, 1),
      border-radius 0.35s ease;
  }

  .story-dot.is-active {
    background: var(--accent);
    box-shadow: 0 0 10px rgba(0, 170, 255, 0.55);
    width: 22px;
    border-radius: 3px;
  }

  .story-scroll-cue {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--text-muted);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.5;
    transition: opacity 0.4s ease;
  }

} /* end @media desktop */

/* ── TABLET TWEAKS (769px – 1100px) ───────────────────────── */
@media (min-width: 769px) and (max-width: 1100px) {
  .story-sticky {
    grid-template-columns: 260px 1fr;
  }
  .story-slides-panel {
    padding-left: 3.5rem;
    padding-right: 3.5rem;
  }
}

/* ── MOBILE (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

  .story-wrapper { height: auto; }

  .story-sticky {
    position: relative;   /* containing block for circuit-bg */
    height: auto;
    display: block;
    padding: 80px 0 100px;
    overflow: hidden;
  }

  /* Depth overlay */
  .story-sticky::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg,
      transparent 0%,
      rgba(0, 8, 30, 0.56) 18%,
      rgba(0, 8, 30, 0.60) 82%,
      transparent 100%
    );
    z-index: 0;
    pointer-events: none;
  }

  /* Circuit bg: full-width behind mobile cards */
  .story-circuit-bg {
    position: absolute;
    inset: -30% 0;
    z-index: 0;
    pointer-events: none;
  }

  .story-circuit-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.05;
  }

  /* Ghost year numbers (mobile decorative) */
  .story-ghost-num {
    position: absolute;
    left: var(--ghost-x);
    top: var(--ghost-y);
    font-family: var(--font-mono);
    font-size: clamp(4.5rem, 22vw, 7.5rem);
    font-weight: 800;
    color: transparent;
    -webkit-text-stroke: 1px rgba(0, 170, 255, 0.07);
    line-height: 1;
    letter-spacing: -0.05em;
    user-select: none;
    pointer-events: none;
    white-space: nowrap;
  }

  /* Hide desktop-only elements */
  .story-year-panel,
  .story-progress-row { display: none; }

  /* Slides panel: full width, standard container margins */
  .story-slides-panel {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
    box-sizing: border-box;
    width: 100%;
  }

  .story-label-wrap {
    position: static;   /* back to normal flow on mobile */
    padding: 0 2rem;
    margin-bottom: 2.5rem;
  }

  /* Stack slides as visible cards */
  .story-slides-wrap {
    display: flex;
    flex-direction: column;
    gap: 2.8rem;
    overflow: visible;
  }

  /* Cards — same glassmorphism as v2 experience cards */
  .story-slide {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity 0.75s ease, transform 0.75s ease;
    background: rgba(9, 27, 55, 0.58);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.8rem 2.2rem;
    backdrop-filter: blur(16px) saturate(150%);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    border-left: 2px solid rgba(0, 170, 255, 0.40);
    /* All children visible on mobile */
  }

  .story-slide .story-badge,
  .story-slide .story-title,
  .story-slide .story-rule,
  .story-slide .story-body-wrap,
  .story-slide .story-tags {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .story-slide.slide-revealed {
    opacity: 1;
    transform: translateY(0);
  }

  /* Even chapters: flip accent border to right */
  .story-slide:nth-child(even) {
    border-left: 1px solid var(--border);
    border-right: 2px solid rgba(0, 170, 255, 0.40);
  }

}

/* ── prefers-reduced-motion ───────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  /* Collapse scroll budget, show everything statically */
  .story-wrapper { height: auto !important; }

  .story-sticky,
  .story-sticky.is-pinned,
  .story-sticky.is-past {
    position: relative !important;
    height: auto !important;
    display: block !important;
    padding: 80px 0 100px !important;
    overflow: visible !important;
  }

  .story-year-panel,
  .story-progress-row { display: none !important; }

  .story-slides-panel {
    max-width: 1100px !important;
    margin: 0 auto !important;
    padding: 0 2rem !important;
    display: block !important;
    height: auto !important;
  }

  .story-label-wrap { position: static !important; padding: 0 2rem !important; margin-bottom: 2.5rem !important; }

  .story-slides-wrap {
    display: flex !important;
    flex-direction: column !important;
    gap: 2.8rem !important;
    overflow: visible !important;
    position: static !important;
    align-items: stretch !important;
    min-height: unset !important;
  }

  .story-slide,
  .story-slide.is-active,
  .story-slide.is-exiting,
  .story-slide.is-past {
    position: static !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    transition: none !important;
    animation: none !important;
    background: rgba(9, 27, 55, 0.58) !important;
    border: 1px solid var(--border) !important;
    border-left: 2px solid rgba(0, 170, 255, 0.40) !important;
    border-radius: var(--radius) !important;
    padding: 1.8rem 2.2rem !important;
  }

  .story-slide .story-badge,
  .story-slide .story-title,
  .story-slide .story-rule,
  .story-slide .story-body-wrap,
  .story-slide .story-tags {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .story-year-num.year-animate { animation: none !important; }
}

/* ── Light theme overrides ───────────────────────────────── */
[data-theme="light"] .story-circuit-svg { opacity: 0.03; }

[data-theme="light"] .story-title        { color: #111d30; }
[data-theme="light"] .story-body strong  { color: #111d30; }

@media (min-width: 769px) {
  [data-theme="light"] .story-sticky {
    background: rgba(215, 230, 250, 0.38);
  }
  [data-theme="light"] .story-sticky::before {
    background: linear-gradient(to bottom, #dce8f5 0%, transparent 100%);
  }
  [data-theme="light"] .story-sticky::after {
    background: linear-gradient(to top, #dce8f5 0%, transparent 100%);
  }
  [data-theme="light"] .story-year-num {
    -webkit-text-stroke-color: rgba(0, 100, 200, 0.65);
  }
  [data-theme="light"] .story-year-ghost {
    -webkit-text-stroke-color: rgba(0, 100, 200, 0.06);
  }
  [data-theme="light"] .story-dot.is-active {
    background: var(--accent);
  }
}

@media (max-width: 768px) {
  [data-theme="light"] .story-sticky::before {
    background: linear-gradient(180deg,
      transparent 0%,
      rgba(200, 218, 248, 0.42) 18%,
      rgba(200, 218, 248, 0.48) 82%,
      transparent 100%
    );
  }
  [data-theme="light"] .story-slide {
    background: rgba(210, 228, 255, 0.55);
  }
}
