/* Worklivewell — motion layer
 *
 * 1. Homepage scroll film + the chapter cards that read over it
 * 2. Header that slides away on scroll-down and returns on scroll-up
 * 3. Scroll-linked reveals and image parallax
 * 4. Hover motion
 *
 * Everything that moves is behind prefers-reduced-motion, and the scroll-linked
 * effects are behind @supports, so browsers without them simply show the page
 * at rest — nothing is ever left hidden.
 */

:root {
  --wlw-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --wlw-film-bg: #EEEDE6;
  --wlw-blush: #C79A97;
}

/* ── 1. Scroll film ─────────────────────────────────────────────────────── */

.wlw-film {
  --film-progress: 0;
  position: relative;
  isolation: isolate;
  background: var(--wlw-film-bg);
  color: var(--color-charcoal);
}

/* The film itself: pinned for the whole journey, one viewport tall. */
.wlw-film__stage {
  position: sticky;
  top: 0;
  z-index: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--wlw-film-bg);
}

.wlw-film__poster,
.wlw-film__video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
}

.wlw-film__video {
  z-index: 1;
}

.wlw-film__stage[data-video-painted="true"] .wlw-film__poster {
  visibility: hidden;
}

.wlw-film__progress {
  position: absolute;
  z-index: 5;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgb(33 37 41 / 0.14);
  pointer-events: none;
}

.wlw-film__progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--wlw-blush);
  transform: scaleX(var(--film-progress));
  transform-origin: left center;
}

/* Everything that scrolls over the film. Its height is the scroll distance
   the film plays across: taller = slower film. */
.wlw-film__story {
  position: relative;
  z-index: 3;
  min-height: 460vh;
  min-height: 460dvh;
  margin-top: -100vh;
  margin-top: -100dvh;
  pointer-events: none;
}

/* Opening copy: fills the first screen, then scrolls away. The 5rem is the
   fixed header's spacer above the film, so the copy and its buttons fit the
   visible area on load instead of running off the bottom. */
.wlw-film__hero {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 5rem);
  min-height: calc(100dvh - 5rem);
  padding: clamp(2rem, 5vw, 4rem) clamp(1.25rem, 6vw, 6rem) clamp(2.5rem, 6vw, 4rem);
  /* The glow behind the copy is wider than the copy; without this it pokes
     past the screen edge on phones and makes the page scroll sideways. */
  overflow-x: clip;
  text-align: center;
}

.wlw-film__copy {
  position: relative;
  width: min(44rem, 100%);
  pointer-events: auto;
}

/* Soft cream glow so dark copy stays readable over any frame of the film. */
.wlw-film__copy::before {
  position: absolute;
  z-index: -1;
  inset: -6rem -9rem;
  content: "";
  /* closest-side: the glow fades to nothing before the box edge, so no
     rectangular outline shows against the film. */
  background: radial-gradient(
    ellipse closest-side at center,
    rgb(238 237 230 / 0.92) 0%,
    rgb(238 237 230 / 0.78) 40%,
    rgb(238 237 230 / 0.4) 68%,
    rgb(238 237 230 / 0.12) 86%,
    transparent 100%
  );
  pointer-events: none;
}

.wlw-film__kicker {
  margin: 0 0 1rem;
  color: var(--color-accent);
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.wlw-film__title {
  margin: 0 auto;
  max-width: 14ch;
  font-size: clamp(2.75rem, 6vw, 4.75rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.wlw-film__body {
  margin: 1.25rem auto 0;
  max-width: 46ch;
  color: #3F454A;
  font-size: clamp(1rem, 1.3vw, 1.15rem);
  line-height: 1.55;
}

.wlw-film__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 2rem;
}

/* Chapter cards: laid over the rest of the film, alternating sides. */
.wlw-chapters {
  position: absolute;
  z-index: 2;
  inset: 0;
  padding-top: 118vh;
  padding-top: 118dvh;
  pointer-events: none;
}

.wlw-chapter {
  display: flex;
  align-items: center;
  min-height: 104vh;
  min-height: 104dvh;
  padding-inline: clamp(1.25rem, 6vw, 6rem);
}

.wlw-chapter[data-side="right"] {
  justify-content: flex-end;
}

.wlw-chapter__card {
  width: min(26rem, 100%);
  padding: clamp(1.75rem, 3vw, 2.5rem);
  background: rgb(238 237 230 / 0.88);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-left: 3px solid var(--wlw-blush);
  pointer-events: auto;
}

.wlw-chapter__card h2 {
  margin: 0;
  font-size: clamp(1.9rem, 3vw, 2.6rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.wlw-chapter__card p {
  margin: 0.9rem 0 1.5rem;
  color: #3F454A;
  line-height: 1.6;
}

@media (max-width: 720px) {
  .wlw-film__hero {
    align-items: flex-end;
  }

  .wlw-film__copy::before {
    inset: -3rem -2rem;
    background: linear-gradient(
      to top,
      rgb(238 237 230 / 0.96) 0%,
      rgb(238 237 230 / 0.82) 58%,
      transparent 100%
    );
  }

  .wlw-film__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .wlw-chapter,
  .wlw-chapter[data-side="right"] {
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12vh;
    padding-bottom: 12dvh;
  }
}

/* ── 2. Header hide / return ────────────────────────────────────────────── */

/* main.js adds .is-hidden while scrolling down and removes it on any scroll
   up. No transform is set at rest: a transformed header would become the
   containing block for the full-screen mobile menu inside it. */
#site-header.is-hidden {
  transform: translateY(-100%);
}

/* ── 3 & 4. Motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  #site-header {
    transition: transform 0.5s var(--wlw-ease);
  }

  /* Opening build of the hero copy: clip and slide only, so the text is
     never waiting invisible. */
  .wlw-film__kicker,
  .wlw-film__title,
  .wlw-film__body,
  .wlw-film__actions {
    animation: wlw-build 1.1s var(--wlw-ease) both;
  }
  .wlw-film__title { animation-delay: 0.08s; }
  .wlw-film__body { animation-delay: 0.18s; }
  .wlw-film__actions { animation-delay: 0.28s; }

  /* Scroll-linked: each element animates against its own position in the
     viewport, so it also plays backwards when scrolling up. */
  @supports (animation-timeline: view()) {
    .wlw-rise {
      animation: wlw-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 70%;
    }
    .wlw-rise[data-step="1"] { animation-range: entry 8% entry 82%; }
    .wlw-rise[data-step="2"] { animation-range: entry 16% entry 94%; }
    .wlw-rise[data-step="3"] { animation-range: entry 24% cover 30%; }
    .wlw-rise[data-step="4"] { animation-range: entry 32% cover 34%; }
    .wlw-rise[data-step="5"] { animation-range: entry 40% cover 38%; }

    /* Parallax: the image is slightly oversized and drifts inside its frame
       as the frame crosses the screen. It uses the standalone translate/scale
       properties, so it stacks with the existing hover zoom (which uses
       transform) instead of replacing it.

       The frame, and a full-width section holding one, must clip with
       `overflow: clip`, NOT `overflow: hidden`. A hidden box counts as a
       scroll container, so view() would measure the image against its own
       frame, which never scrolls, and the image would sit still. */
    /* Selector doubled on purpose: the frames also carry Tailwind's
       .overflow-hidden, whose stylesheet loads after this one. */
    .wlw-parallax.wlw-parallax,
    section:has(> .wlw-parallax) {
      overflow: clip;
    }

    .wlw-parallax img {
      scale: 1.14;
      animation: wlw-drift linear both;
      animation-timeline: view();
      animation-range: cover;
    }

    .wlw-chapter__card {
      animation: wlw-card linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 45%;
    }
  }

  /* Hover: desktop nav underline draws in from the left. */
  #desktop-nav > .group > a {
    position: relative;
  }
  #desktop-nav > .group > a::after {
    position: absolute;
    right: 0;
    bottom: -2px;
    left: 0;
    height: 1px;
    content: "";
    background: currentColor;
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform 0.45s var(--wlw-ease);
  }
  #desktop-nav > .group > a:hover::after,
  #desktop-nav > .group > a:focus-visible::after {
    transform: scaleX(1);
    transform-origin: left center;
  }

  /* Hover: chapter cards lift slightly. */
  .wlw-chapter__card {
    transition: box-shadow 0.4s ease;
  }
  .wlw-chapter__card:hover {
    box-shadow: 0 18px 40px rgb(33 37 41 / 0.12);
  }
}

@keyframes wlw-build {
  from {
    clip-path: inset(0 0 60% 0);
    transform: translateY(36px);
  }
  to {
    clip-path: inset(-20% -20% -20% -20%);
    transform: none;
  }
}

@keyframes wlw-rise {
  from {
    opacity: 0;
    transform: translateY(56px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes wlw-drift {
  from { translate: 0 -6%; }
  to { translate: 0 6%; }
}

@keyframes wlw-card {
  from { transform: translateY(40px) scale(0.96); }
  to { transform: none; }
}

/* Reduced motion: no film scrubbing, so collapse the long scroll distance and
   let the chapter cards read as ordinary stacked content over the still. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .wlw-film__story {
    min-height: 0;
  }

  .wlw-chapters {
    position: static;
    padding-top: 0;
  }

  .wlw-chapter {
    min-height: 0;
    padding-block: 2rem;
  }

  .wlw-film__progress {
    display: none;
  }
}
