/* fx.css: premium motion layer for the home page (progressive enhancement; every rule is gated by .js and/or motion preference) */

/* 1. Smooth page transitions: soft arrival fade + leave veil (a pure CSS/JS fallback that works on every page without opt-in;
      the cross-document View Transitions API needs BOTH pages to opt in, so it is not enabled from the home page alone) */
@media (prefers-reduced-motion:no-preference){
  html.js{animation:fx-arrive .42s cubic-bezier(.16,1,.3,1) backwards}
}
@keyframes fx-arrive{from{opacity:0}to{opacity:1}}

/* page-leave veil (covers browsers/pages without cross-document view transitions) */
.fx-veil{position:fixed;inset:0;z-index:80;pointer-events:none;opacity:0;transition:opacity .28s cubic-bezier(.4,0,.2,1);
  background:radial-gradient(60% 60% at 50% 45%,rgba(255,255,255,.96),rgba(238,240,247,.98)),#eef0f7}
.fx-veil.on{opacity:1}

/* 2. Split-letter chrome reveal on the title (letters carry their own chrome so the shimmer travels across them) */
.js h1.fx-split:not(.in) .wi{transform:none;opacity:1}
.js h1.fx-split .wi{background:none;animation:none;perspective:700px}
.js h1.fx-done .w{overflow:visible}
.fx-ch{display:inline-block;will-change:transform;transform-origin:50% 100%;
  background:linear-gradient(180deg,#22252f 0%,#6b7286 24%,#f6f7fc 46%,#30333f 53%,#8f98ae 74%,#e1e5ef 88%,#454b5c 100%),linear-gradient(100deg,transparent 38%,rgba(255,255,255,.95) 50%,transparent 62%);
  background-blend-mode:screen;background-size:100% 100%,260% 100%;background-repeat:no-repeat;
  -webkit-background-clip:text;background-clip:text;color:transparent;-webkit-text-stroke:.6px rgba(30,32,48,.25);
  transition:transform 1.1s cubic-bezier(.16,1,.3,1) calc(var(--c)*55ms),opacity .7s ease calc(var(--c)*55ms),filter .9s ease calc(var(--c)*55ms);
  animation:fx-shim 5.5s ease-in-out calc(1.4s + var(--c)*.14s) infinite}
.js h1.fx-split:not(.fx-go) .fx-ch{transform:translate3d(0,112%,0) rotateX(-65deg) rotate(6deg);opacity:0;filter:blur(5px)}
@keyframes fx-shim{0%{background-position:0 0,170% 0}55%,100%{background-position:0 0,-70% 0}}

/* 3. Parallax depth: ambient blobs + existing lavender floor grid + orbit ring (uses the individual `translate` property so existing transform animations keep running) */
.amb .bl,.floorwrap,.floor,.orbit{will-change:transform,translate}

/* 4. Tilt on book / card hover (glare comes from the page's existing cursor spotlight) (fine pointers only; JS adds .fx-t) */
@media (hover:hover) and (pointer:fine){
  html.js body .fx-t.fx-on.fx-on.fx-on:hover{transform:perspective(900px) translate3d(0,-6px,0) rotateX(var(--fx-rx,0deg)) rotateY(var(--fx-ry,0deg));transition:transform .16s ease-out,box-shadow .6s cubic-bezier(.16,1,.3,1)}
  .book.fx-t img{transition:transform .8s var(--jelly),translate .25s ease-out,clip-path 1.2s cubic-bezier(.16,1,.3,1),opacity .9s ease,scale 1.4s cubic-bezier(.16,1,.3,1);translate:calc(var(--fx-px,0)*7px) calc(var(--fx-py,0)*7px)}
}

/* 5. Scroll-triggered curtain reveal for images (clip-path "open curtain" + counter-zoom) */
.js .fx-img:not(.fx-in){clip-path:inset(14% 10% 14% 10%);opacity:0;scale:1.14}
.js .fx-img{transition:clip-path 1.2s cubic-bezier(.16,1,.3,1),opacity .9s ease,scale 1.4s cubic-bezier(.16,1,.3,1)}
.js .fx-img.fx-in{clip-path:inset(0% 0% 0% 0%);opacity:1;scale:1}

/* 6. Magnetic pills / orb: nothing visual here, the JS drives `translate`; hint the compositor */
.pill,a.orb{will-change:translate}

@media (prefers-reduced-motion:reduce){
  .fx-ch{animation:none;transition:none}
  .js h1.fx-split:not(.fx-go) .fx-ch{transform:none;opacity:1;filter:none}
  .js .fx-img:not(.fx-in){clip-path:none;opacity:1;scale:1}
  .js .fx-img{transition:none}
  .fx-veil{display:none}
}

/* ===== Mobile fixes + polish ===== */

/* FIX: on phones/tablets the hero photo used to slide DOWN (up to ~108px) and tilt (rotateX) as the page scrolled, while the
   book card below it stays put, so the photo slid behind the "Meditating As Fuck" card. Photo parallax/tilt is turned off
   below 820px and on touch-first devices (the inline style from the page script is overridden), and the two layers get a
   fixed paint order so nothing can ever tuck behind the book card. */
@media (max-width:820px),(hover:none) and (pointer:coarse){
  .photo{transform:none!important;will-change:auto;transition:none}
  .stage{isolation:isolate;z-index:0}
  .newbook-wrap{position:relative;z-index:2}
}

/* Dynamic-viewport units, with the old vh values as fallbacks (web.dev/blog/viewport-units) */
@supports (height:100svh){
  .pin{height:calc(min(100svh,380px) + 180px)}
  .pin .sticky{top:calc(50svh - min(50svh,190px));height:min(100svh,380px)}
  .sheet{max-height:86dvh}
  .mbody img{max-height:56svh}
  .amb{bottom:auto;height:100lvh} /* fixed ambient layer sized to the LARGE viewport so it never resizes when Safari's toolbar slides */
}

/* Safe-area insets: viewport-fit=cover is set in the viewport meta, so keep content out of the notch / home-indicator area */
body{padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right)}
footer{padding-bottom:calc(46px + env(safe-area-inset-bottom))}

/* Touch + scroll feel */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;overscroll-behavior-x:none}
a,button,.btn,.pill,.soc,[data-pop]{touch-action:manipulation}
.sheet,.mbody,.dossier__sheet,.mcd-modal{overscroll-behavior:contain}
.links{overscroll-behavior-x:contain;scroll-snap-type:x proximity;scroll-padding-inline:12px}
.links a{scroll-snap-align:center}


/* ===== Scroll-glitch fix for phones/tablets (iOS Safari / in-app browsers) =====
   Causes: (1) fixed scanline overlay with mix-blend-mode + an animated sweep blended over the whole page every frame;
   (2) 18px backdrop-filter blur on every card + the sticky nav sitting above continuously animating, blurred background blobs, so Safari
   re-blurs everything on each scroll frame; (3) html background-attachment:fixed (repainted on every scroll on iOS);
   (4) cards' iridescent sheen was re-styled on every scroll frame via a root custom property.
   Same look, but static / opaque-ish on touch devices. Desktop is untouched. */
@media (pointer:coarse),(hover:none){
  .scan,.scan::after{display:none}
  .amb .bl{animation:none;will-change:auto}
  html{background-attachment:scroll}
  .glass,.card,.award,.book,.stat,.pf-card,.pf-games,#websites .pf-card,#websites .pf-games,nav .wrap,.dossier,.scrim{-webkit-backdrop-filter:none!important;backdrop-filter:none!important}
  nav .wrap{background:linear-gradient(180deg,rgba(255,255,255,.96),rgba(243,244,252,.92))}
  .glass,.card,.award,.book,.stat{background-color:rgba(250,249,255,.55)}
  .glass::after,.card::after,.award::after,.book::after,.stat::after{will-change:auto;transition:none;transform:none!important} /* was translate3d(): ~80 oversized (220% x 200%) GPU layers, the biggest memory hog on phones; with no pointer/scroll input the transform was the identity anyway, so the look is the same */
  .pill,a.orb,.wi,.fx-ch{will-change:auto}
}
