/* ═══════════════════════════════════════════════════
   Scroll Reveal — IntersectionObserver + CSS Transitions
   Portfolio v3 · 2026

   JS adds .is-visible when elements enter the viewport.
   CSS transitions handle the animation.
   ═══════════════════════════════════════════════════ */

/* ── Base: hidden state for scroll-reveal elements ── */
[data-reveal] {
  opacity: 0;
  transform: translateY(28px);
  transition:
    opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.9s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}

[data-reveal="left"] {
  transform: translateX(28px);
}

[data-reveal="scale"] {
  transform: scale(0.92);
}

[data-reveal="fade"] {
  transform: none;
}

/* ── Visible: transition in ── */
[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0) translateX(0) scale(1);
}

[data-reveal="left"].is-visible,
[data-reveal="scale"].is-visible,
[data-reveal="fade"].is-visible {
  transform: none;
}

/* ── Stagger delays ── */
[data-reveal-delay="1"] { transition-delay: 0.1s; }
[data-reveal-delay="2"] { transition-delay: 0.2s; }
[data-reveal-delay="3"] { transition-delay: 0.3s; }
[data-reveal-delay="4"] { transition-delay: 0.4s; }
[data-reveal-delay="5"] { transition-delay: 0.5s; }

/* ═══ Reduced Motion: show everything immediately ═══ */
@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    clip-path: none !important;
    filter: none !important;
    transition: none !important;
  }
}

/* ═══════════════════════════════════════════════════
   Per-Section Reveal Personalities
   Each section gets a distinct reveal character so
   consecutive sections don't feel identical on scroll.
   Scoped overrides only — base reveal still works.
   ═══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: no-preference) {

  /* ── Signal — crisp, technical. Left-slide, shorter distance, fast curve ── */
  .signal [data-reveal] {
    transform: translateX(-18px);
    transition-property: opacity, transform;
    transition-duration: 0.65s;
    transition-timing-function: cubic-bezier(0.19, 1, 0.22, 1);
  }
  .signal .signal__project[data-reveal] {
    transform: translateX(-32px);
    transition-duration: 0.85s;
  }
  .signal [data-reveal].is-visible {
    transform: translateX(0);
  }

  /* ── Projects — chapters landing. Deeper rise + gentle scale + longer hang ── */
  .projects [data-reveal="scale"] {
    transform: translateY(32px) scale(0.94);
    transition-property: opacity, transform;
    transition-duration: 1.1s;
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  .projects .projects__card--featured[data-reveal="scale"] {
    transform: translateY(40px) scale(0.95);
    transition-duration: 1.3s;
  }
  .projects [data-reveal="scale"].is-visible {
    transform: none;
  }

  /* ── Convictions — each claim lands slow, heavy, sequential, with focus resolve ── */
  .convictions__item[data-reveal] {
    transform: translateY(44px);
    filter: blur(3px);
    transition-property: opacity, transform, filter;
    transition-duration: 1.2s;
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  .convictions__item[data-reveal].is-visible {
    transform: none;
    filter: blur(0);
  }
  /* Sequential cadence — each conviction arrives a beat after the last */
  .convictions__list .convictions__item[data-reveal]:nth-child(1) { transition-delay: 0s; }
  .convictions__list .convictions__item[data-reveal]:nth-child(2) { transition-delay: 0.14s; }
  .convictions__list .convictions__item[data-reveal]:nth-child(3) { transition-delay: 0.28s; }
  .convictions__list .convictions__item[data-reveal]:nth-child(4) { transition-delay: 0.42s; }
  .convictions__list .convictions__item[data-reveal]:nth-child(5) { transition-delay: 0.56s; }

  /* ── Testimonials — lead heavy, secondaries light from the side ── */
  .testimonials .t-praise__item--lead[data-reveal] {
    transform: translateY(40px) scale(0.96);
    transition-property: opacity, transform;
    transition-duration: 1.1s;
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  .testimonials .t-praise__item--lead[data-reveal].is-visible {
    transform: none;
  }
  .testimonials .t-praise__item:not(.t-praise__item--lead)[data-reveal] {
    transform: translateX(28px);
    transition-property: opacity, transform;
    transition-duration: 0.55s;
    transition-timing-function: cubic-bezier(0.33, 1, 0.68, 1);
  }
  .testimonials .t-praise__item:not(.t-praise__item--lead)[data-reveal].is-visible {
    transform: none;
  }
  .t-praise .t-praise__item:not(.t-praise__item--lead)[data-reveal]:nth-of-type(2) { transition-delay: 0.1s; }
  .t-praise .t-praise__item:not(.t-praise__item--lead)[data-reveal]:nth-of-type(3) { transition-delay: 0.22s; }
}

/* ═══════════════════════════════════════════════════
   Scroll-linked Section Signatures
   One quiet element per section that moves WITH scroll
   progress (not on entry). Pure CSS via animation-timeline:
   view(). Chrome/Edge supported; Safari degrades silently.
   ═══════════════════════════════════════════════════ */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {

    /* ── Projects: faint neutral glow drifts diagonally through the section ── */
    .projects::after {
      content: '';
      position: absolute;
      width: clamp(280px, 32vw, 440px);
      aspect-ratio: 1;
      border-radius: 50%;
      background: radial-gradient(circle, color-mix(in oklch, var(--text-primary) 10%, transparent), transparent 65%);
      filter: blur(50px);
      pointer-events: none;
      z-index: 0;
      top: 8%;
      left: 4%;
      opacity: 0;
      animation: proj-glow-drift linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    @keyframes proj-glow-drift {
      0%   { top: 8%;  left: 4%;  opacity: 0; }
      20%  { opacity: 1; }
      80%  { opacity: 1; top: 62%; left: 62%; }
      100% { top: 68%; left: 68%; opacity: 0; }
    }

    /* ── Convictions: central neutral glow tracks top-to-bottom as reader passes claims ── */
    .convictions::after {
      content: '';
      position: absolute;
      left: 50%;
      width: clamp(260px, 32vw, 400px);
      aspect-ratio: 1;
      border-radius: 50%;
      background: radial-gradient(circle, color-mix(in oklch, var(--text-primary) 8%, transparent), transparent 70%);
      filter: blur(55px);
      pointer-events: none;
      z-index: 0;
      top: 10%;
      transform: translate(-50%, -50%);
      opacity: 0;
      animation: conv-glow-travel linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    @keyframes conv-glow-travel {
      0%   { top: 10%; opacity: 0; }
      18%  { opacity: 1; }
      82%  { opacity: 1; top: 90%; }
      100% { top: 95%; opacity: 0; }
    }
  }
}

/* ═══════════════════════════════════════════════════
   Word-by-word Editorial Reveal
   When a [data-word-reveal] element enters the viewport, each word
   fades and rises on a staggered 55ms cascade. Words are wrapped in
   <span class="wr-word"> by JS at load; CSS delivers the motion.
   ═══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: no-preference) {
  /* Parent does NOT perform its own opacity/transform reveal — only the words do */
  [data-reveal][data-word-reveal],
  [data-reveal][data-word-reveal].is-visible {
    opacity: 1;
    transform: none;
  }

  .wr-word {
    display: inline-block;
    opacity: 0;
    transform: translateY(0.35em);
    transition:
      opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
      transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
    transition-delay: calc(var(--wr-i, 0) * 55ms);
    will-change: opacity, transform;
  }

  [data-word-reveal].is-visible .wr-word {
    opacity: 1;
    transform: translateY(0);
  }

  /* ── Editorial punchline: on section H2 titles, the rust italic word
     waits an extra beat, then slides in slightly slower than its white
     siblings. Small margin adds a visual breath before it lands.
     Only applies to h2 titles — Statement paragraphs keep the uniform cascade. */
  h2[data-word-reveal] em {
    margin-left: 0.18em;
  }

  h2[data-word-reveal] em .wr-word {
    transition-duration: 0.9s;
    transition-delay: calc((var(--wr-i, 0) * 55ms) + 220ms);
  }
}

/* Reduced motion: words render immediately, no stagger */
@media (prefers-reduced-motion: reduce) {
  .wr-word {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ═══════════════════════════════════════════════════
   Cream / Reading Mode — Stillness with breath
   No movement, but type develops like ink on paper:
   opacity fades in slow, transform stays off. The page
   is calm, not airtight. Hover responses remain — those
   are conversation, not performance. Dark mode untouched.
   ═══════════════════════════════════════════════════ */
[data-theme="light"] [data-reveal] {
  transform: none !important;
  filter: none !important;
  transition: opacity 1.4s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

[data-theme="light"] [data-reveal].is-visible {
  opacity: 1 !important;
  transform: none !important;
  filter: none !important;
}

[data-theme="light"] .wr-word {
  transform: none !important;
  transition: opacity 1.1s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

[data-theme="light"] [data-word-reveal].is-visible .wr-word {
  opacity: 1 !important;
  transform: none !important;
}

[data-theme="light"] .projects::after,
[data-theme="light"] .convictions::after {
  display: none;
}

