/* Depth: the site as layers in space (every public page; not the admin or its live previews).
     Ken Burns  photos that are already cropped (hero, About) slowly push in and drift
     scroll     layers move at different speeds, panels tip up into place and tip away as they leave
     pointer    the home hero leans toward the mouse (public/js/hero-depth.js)
   Scroll motion is CSS only (view timelines), so it runs off the main thread; a browser without them shows everything at
   rest. Rules for adding to it:
   - Animate translate / rotate / scale, never transform: that belongs to the builds, hovers and tilts, and both add up.
   - Name the timeline on the outer box (view-timeline) when something inside overflow: hidden moves; view() would pick
     that box as the scroller and never move.
   - A panel is flat once it's fully on screen, or 45vh in if it's taller, so text at the end of a page is never left tipped.
   - Never zoom posters, boards or infographics: it would crop their text. */

@media screen and (prefers-reduced-motion: no-preference) {
  :root { --depth: 1; }
  @media (max-width: 767px) { :root { --depth: .5; } }

  /* ── Ken Burns ── each step's drift stays inside what its zoom hides, so an edge never shows */
  .hero__shot { animation: ken-burns 24s cubic-bezier(.4, 0, .6, 1) infinite alternate; will-change: translate, scale; }
  .hero.is-away .hero__shot { animation-play-state: paused; }
  .about__photo img { transform-origin: 50% 35%; animation: ken-burns-near 18s cubic-bezier(.4, 0, .6, 1) infinite alternate; }
  @keyframes ken-burns {
    from { scale: 1.04; translate: 1.6% 1%; }
    50% { scale: 1.13; translate: -2.4% 1.6%; }
    to { scale: 1.22; translate: -1% -4%; }
  }
  @keyframes ken-burns-near { from { scale: 1.02; translate: .5% .5%; } to { scale: 1.14; translate: -1.5% -1%; } }

  @supports (animation-timeline: view()) {
    /* ── behind every page: the photo is far away, the colours float in front of it. The range is never shorter than
       2400px, so a short page doesn't rush through it. ── */
    .backdrop::before { bottom: calc(-40px - 12vh); animation: depth-far linear both; animation-timeline: scroll(root block); animation-range: 0 max(100%, 2400px); }
    .photo-theme .backdrop::before { animation: backdrop-drift 70s ease-in-out infinite alternate, depth-far linear both; animation-timeline: auto, scroll(root block); animation-range: normal, 0 max(100%, 2400px); }
    @keyframes depth-far { to { translate: 0 -10vh; } }
    @media (min-width: 768px) {
      .blob { animation: depth-blob linear both; animation-timeline: scroll(root block); animation-range: 0 max(100%, 2400px); }
      .blob--1 { --to: 10vw -30vh; }
      .blob--2 { --to: -12vw 42vh; }
      .blob--3 { --to: -16vw -38vh; }
    }
    @keyframes depth-blob { to { translate: var(--to); } }

    /* ── home hero: the photo falls behind, the panel tips back, and what's on it leaves at its own speed ── */
    .hero { view-timeline: --hero block; }
    .hero__inner { perspective: 1200px; }
    .hero :is(.hero__depth, .hero__panel, .hero__linkedin, h1, .btn-row) { animation: linear both; animation-timeline: --hero; animation-range: exit; }
    .hero .hero__depth { animation-name: depth-hero-photo; }
    .hero .hero__panel { animation-name: depth-hero-panel; }
    .hero .hero__linkedin { animation-name: depth-lift; --lift: -34px; }
    .hero .hero__panel h1 { animation-name: depth-lift; --lift: -16px; }
    .hero .hero__panel .btn-row { animation-name: depth-lift; --lift: 12px; }
    @keyframes depth-hero-photo { to { translate: 0 22%; scale: 1.1; } }
    @keyframes depth-hero-panel { to { translate: 0 calc(var(--depth) * -80px); rotate: x calc(var(--depth) * 18deg); scale: .9; } }
    @keyframes depth-lift { to { translate: 0 calc(var(--depth) * var(--lift)); } }

    /* ── section panels: planes that tip up out of the distance, lie flat to be read, then tip away ── */
    main > .section:not(.page-hero) > .container:has(> :is(.glass, .travels__card)) { perspective: 1300px; }
    main > .section:not(.page-hero) > .container > :is(.glass, .travels__card) {
      view-timeline: --plane block;
      transform-origin: 50% 50%;
      animation: depth-arrive cubic-bezier(.2, .6, .3, 1) both, depth-leave cubic-bezier(.6, 0, .8, .4) forwards;
      animation-timeline: --plane, --plane;
      animation-range: entry 0% entry min(100%, 45vh), exit max(0%, 100% - 45vh) exit 100%;
    }
    @keyframes depth-arrive { from { translate: 0 calc(var(--depth) * 70px) calc(var(--depth) * -160px); rotate: x calc(var(--depth) * -16deg); } to { translate: 0 0 0; rotate: x 0deg; } }
    @keyframes depth-leave { from { translate: 0 0 0; rotate: x 0deg; } to { translate: 0 calc(var(--depth) * -30px) calc(var(--depth) * -140px); rotate: x calc(var(--depth) * 14deg); } }

    /* ── layers: --float is how near a layer is. Near layers pass faster than the page, far ones (negative) slower. ── */
    @keyframes depth-float {
      from { translate: 0 calc(var(--depth) * var(--float)); }
      to { translate: 0 calc(var(--depth) * var(--float) * -1); }
    }
    main > .section:not(.page-hero) > .container > :is(.section-head, .story-title) { --float: 26px; animation: depth-float linear both; animation-timeline: view(block); }
    .about__photo { --float: 30px; }
    .travels__preview { --float: 56px; }
    .travels__text { --float: -14px; }
    :is(.about__photo, .travels__preview, .travels__text) { animation: depth-float linear both; animation-timeline: --plane; }
    @media (min-width: 768px) {
      .project-feature__media { --float: 34px; }
      .project-feature__text, .story-section .story-text { --float: -12px; }
      :is(.project-feature__media, .project-feature__text, .story-section .story-text) { animation: depth-float linear both; animation-timeline: view(block); }
    }

    /* ── windows: news photos slide behind their frames ── */
    .nw-pic { view-timeline: --pic block; }
    .nw-pic img { animation: depth-window linear both; animation-timeline: --pic; }
    @keyframes depth-window { from { scale: 1.16; translate: 0 -7%; } to { scale: 1.16; translate: 0 7%; } }

    /* ── 3D rows: scrolling moves the eye, so the side and back cards shift against the front one ── */
    .work-carousel { view-timeline: --deck block; overflow-x: clip; overflow-y: visible; }
    .is-coverflow .work-grid { animation: depth-eye linear both; animation-timeline: --deck; }
    .quotes__deck { view-timeline: --deck block; }
    .is-spatial .quotes__stage { animation: depth-eye linear both; animation-timeline: --deck; }
    @keyframes depth-eye { from { perspective-origin: 50% 110%; } to { perspective-origin: 50% -10%; } }
    .quotes__orb { animation: depth-float linear both; animation-timeline: --deck; }
    .quotes__orb--1 { --float: -60px; }
    .quotes__orb--2 { --float: 90px; }
    .quotes__orb--3 { --float: 140px; }
  }
}
