/* Page transitions – Figma "0 · Transitions (Prototype)" (672:8306):
   each page starts with just its headline (+ menu) and smart-animates into the full hero,
   1 s ease-out. Here: cross-document view transition between pages, the header stays put,
   then the hero builds up around the headline. Nothing moves with reduced motion. */

@view-transition {
  navigation: auto;
}

.site-header {
  view-transition-name: site-header;
}


@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

@keyframes intro-title {
  from { translate: 0 6vh; }
}

@keyframes intro-item {
  from {
    opacity: 0;
    translate: 0 32px;
    scale: 0.94;
  }
}

@keyframes intro-fade {
  from { opacity: 0; }
}

/* slow drift for hero cutouts and bubbles; uses transform, so it stacks with the intro (translate/scale) */
@keyframes stage-float {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  50%  { transform: translate3d(4px, -10px, 0) rotate(0.8deg); }
  100% { transform: translate3d(-3px, 6px, 0) rotate(-0.6deg); }
}

@media (prefers-reduced-motion: no-preference) {
  /* the headline settles from the centre into its place */
  .home-hero__title,
  .stage-hero__title,
  .case-hero__title h1,
  .case-hero-compact__text,
  .backstage-hero h1,
  .contact-hero__title {
    animation: intro-title 1s var(--ease-out-soft) both;
  }

  /* everything else builds up around it */
  .home-hero .coverflow,
  .home-hero__text,
  .stage-hero__cutout,
  .case-hero__cutout,
  .case-hero__title > :not(h1),
  .case-hero-compact__image,
  .backstage-hero .text-lead,
  .contact-hero__direct,
  .contact-hero__buttons {
    animation: intro-item 1s var(--ease-out-soft) 0.15s both;
  }

  .home-hero__text,
  .contact-hero__buttons,
  .case-hero__title > :not(h1):last-child {
    animation-delay: 0.3s;
  }

  .stage-hero__cutout:nth-child(2n),
  .case-hero__cutout:nth-child(2n) { animation-delay: 0.22s; }
  .stage-hero__cutout:nth-child(3n),
  .case-hero__cutout:nth-child(3n) { animation-delay: 0.3s; }

  /* Projects + Services hero: images keep floating, each at its own pace */
  .stage-hero__cutout {
    --float: 8s;
    /* backwards only: afterwards the parallax owns translate */
    animation:
      intro-item 1s var(--ease-out-soft) 0.15s backwards,
      stage-float var(--float) ease-in-out 0s infinite alternate;
  }

  .stage-hero__cutout:nth-child(2n) { --float: 9.5s; animation-delay: 0.22s, -3s; }
  .stage-hero__cutout:nth-child(3n) { --float: 7s; animation-delay: 0.3s, -5s; }
  .stage-hero__cutout:nth-child(5n) { --float: 10s; animation-delay: 0.15s, -1.5s; }

  .service-bubble__card {
    animation:
      intro-item 1s var(--ease-out-soft) 0.45s both,
      stage-float 6s ease-in-out -2s infinite alternate;
  }

  .service-bubble:nth-child(2n) .service-bubble__card { animation-duration: 1s, 7.5s; }
  .service-bubble:nth-child(3n) .service-bubble__card { animation-duration: 1s, 5.5s; }

  .backstage-hero .logo-carousel,
  .scroll-hint {
    animation: intro-fade 1s ease-out 0.4s both;
  }
}

/* ---------- Motion layer (motion.js): scroll reveal, parallax, page mark ---------- */

@keyframes reveal-up {
  from {
    opacity: 0;
    translate: 0 48px;
  }
}

/* the heading rises out of an invisible line under it */
@keyframes reveal-line {
  from {
    clip-path: inset(-10% -4% 100% -4%);
    translate: 0 0.5em;
  }
  to {
    clip-path: inset(-10% -4% -25% -4%);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .reveal:not(.is-in) {
    opacity: 0;
  }

  .reveal--line:not(.is-in) {
    opacity: 1;
    clip-path: inset(0 0 100% 0);
  }

  /* backwards fill only: once done, hover and layout transforms own the element again */
  .reveal.is-in {
    animation: reveal-up 0.9s var(--ease-out-soft) calc(var(--reveal-i, 0) * 90ms) backwards;
  }

  .reveal--line.is-in {
    animation: reveal-line 0.9s var(--ease-out-soft) backwards;
  }

  /* parallax: each layer drifts by its own depth (--mx/--my run from -1 to 1, set by motion.js) */
  [data-parallax] [data-depth],
  .card-fan[data-parallax] > li,
  [data-parallax] .service-bubble,
  .service-hero__graphic[data-parallax] .service-graphic > g > g[filter],
  .service-hero__graphic[data-parallax] .service-graphic > g[filter] {
    --depth: 10px;
    transform: translate3d(calc(var(--mx, 0) * var(--depth)), calc(var(--my, 0) * var(--depth)), 0);
  }

  .card-fan[data-parallax] > li:nth-child(2n),
  [data-parallax] .service-bubble:nth-child(2n),
  .service-hero__graphic[data-parallax] .service-graphic > g > g[filter]:nth-of-type(2n),
  .service-hero__graphic[data-parallax] .service-graphic > g[filter]:nth-of-type(2n) { --depth: -14px; }

  .card-fan[data-parallax] > li:nth-child(3n),
  [data-parallax] .service-bubble:nth-child(3n),
  .service-hero__graphic[data-parallax] .service-graphic > g > g[filter]:nth-of-type(3n) { --depth: 18px; }

  [data-parallax] .service-bubble:nth-child(5n) { --depth: -22px; }

  /* hero cutouts float with transform (stage-float), so they drift via translate */
  [data-parallax] .stage-hero__cutout {
    --depth: 16px;
    translate: calc(var(--mx, 0) * var(--depth)) calc(var(--my, 0) * var(--depth));
  }

  /* case hero cutouts (no float there): each drifts by its own depth */
  [data-parallax] .case-hero__cutout {
    --depth: 16px;
    transform: translate3d(calc(var(--mx, 0) * var(--depth)), calc(var(--my, 0) * var(--depth)), 0);
  }

  [data-parallax] .case-hero__cutout:nth-child(2n) { --depth: -24px; }
  [data-parallax] .case-hero__cutout:nth-child(3n) { --depth: 30px; }
  [data-parallax] .case-hero__cutout:nth-child(5n) { --depth: -12px; }

  [data-parallax] .stage-hero__cutout:nth-child(2n) { --depth: -24px; }
  [data-parallax] .stage-hero__cutout:nth-child(3n) { --depth: 30px; }
}

/* ---------- Page change (askphill-style): the coral logo mark pops up in the middle, then the new page
   bursts open through the logo shape while the old page dims behind it.
   The mark and the mask share size and timing; --mark-end (set by motion.js) = 600vmax / 120px. ---------- */
.page-mark {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 200;
  display: none;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  background: var(--color-interactive-primary);
  mask: url("../icons/logo.svg") center / contain no-repeat;
  pointer-events: none;
  view-transition-name: page-mark;
}

/* 0–30 %: pop in, 30–100 %: burst; the same keyframes drive the mask on the new page */
@keyframes page-mark-size {
  0%   { scale: 0; animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); }
  30%  { scale: 1; animation-timing-function: cubic-bezier(0.7, 0, 0.84, 0); }
  100% { scale: var(--mark-end, 40); }
}

@keyframes page-mark-fade {
  0%, 34% { opacity: 1; }
  60%, 100% { opacity: 0; }
}

/* size and position move together, so the mask stays centred on --vt-mark-x/y (the mark's centre in
   snapshot coordinates, set by motion.js; on mobile the snapshot also covers the browser bars, so the
   box centre is not where the mark is). Fallback: the viewport centre. */
@keyframes vt-reveal {
  0% {
    mask-size: 0;
    mask-position: var(--vt-mark-x, 50vw) var(--vt-mark-y, 50vh);
    animation-timing-function: steps(1, end);
  }
  30% {
    mask-size: 120px;
    mask-position: calc(var(--vt-mark-x, 50vw) - 60px) calc(var(--vt-mark-y, 50vh) - 60px);
    animation-timing-function: cubic-bezier(0.7, 0, 0.84, 0);
  }
  100% {
    mask-size: 600vmax;
    mask-position: calc(var(--vt-mark-x, 50vw) - 300vmax) calc(var(--vt-mark-y, 50vh) - 300vmax);
  }
}

/* the old page dims while the mark pops, so the coral stands out */
@keyframes vt-dim {
  30%, 100% { filter: brightness(0.4) saturate(0.6); }
}

@media (prefers-reduced-motion: no-preference) {
  .is-arriving .page-mark {
    display: block;
    animation:
      page-mark-size 1.1s linear both,
      page-mark-fade 1.1s linear both;
  }

  /* the mark lives in its own layer above everything; its own keyframes do the work */
  ::view-transition-group(page-mark),
  ::view-transition-new(page-mark),
  ::view-transition-old(page-mark) {
    animation: none;
  }

  ::view-transition-old(root) {
    animation: vt-dim 1.1s ease-out both;
  }

  ::view-transition-new(root) {
    mask: url("../icons/logo.svg") 0 0 / 0 no-repeat;
    animation: vt-reveal 1.1s linear both;
  }
}

/* ---------- Projects hero: the project cards fly out from behind the title into their places ----------
   --fx/--fy ≈ 80 % of the way from each card's place to the centre of the stage */
@keyframes stage-fly-in {
  from {
    opacity: 0;
    translate: var(--fx, 0) var(--fy, 0);
    scale: 0.35;
    rotate: var(--fr, -10deg);
  }
  35% { opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .stage-hero--projects .stage-hero__cutout:nth-child(1) { --fx: 38vw;  --fy: 3svh;   --fr: -14deg; }
  .stage-hero--projects .stage-hero__cutout:nth-child(2) { --fx: 17vw;  --fy: 18svh;  --fr: 10deg; }
  .stage-hero--projects .stage-hero__cutout:nth-child(3) { --fx: -9vw;  --fy: 19svh;  --fr: -8deg; }
  .stage-hero--projects .stage-hero__cutout:nth-child(4) { --fx: -36vw; --fy: 8svh;   --fr: 12deg; }
  .stage-hero--projects .stage-hero__cutout:nth-child(5) { --fx: 21vw;  --fy: -27svh; --fr: 9deg; }
  .stage-hero--projects .stage-hero__cutout:nth-child(6) { --fx: -16vw; --fy: -34svh; --fr: -11deg; }

  .stage-hero--projects .stage-hero__cutout {
    animation:
      stage-fly-in 1.2s var(--ease-out-soft) calc(0.2s + var(--fly-i, 0) * 0.08s) backwards,
      stage-float var(--float) ease-in-out 0s infinite alternate;
  }

  .stage-hero--projects .stage-hero__cutout:nth-child(2) { --fly-i: 1; }
  .stage-hero--projects .stage-hero__cutout:nth-child(3) { --fly-i: 2; }
  .stage-hero--projects .stage-hero__cutout:nth-child(4) { --fly-i: 3; }
  .stage-hero--projects .stage-hero__cutout:nth-child(5) { --fly-i: 4; }
  .stage-hero--projects .stage-hero__cutout:nth-child(6) { --fly-i: 5; }

  /* the title waits a beat and lands on top */
  .stage-hero--projects .stage-hero__title {
    animation-delay: 0.1s;
  }
}
