/* ===========================================================================
   KHSHN — motion
   One engine, three jobs: the entrance curtain, one-shot scroll reveals, and
   scroll-linked parallax. Every effect degrades to its finished state when the
   reader asks for reduced motion, so nothing is ever hidden behind an
   animation that will not run.
   =========================================================================== */

/* --- 1. entrance curtain -------------------------------------------------- */
.intro{
  position:fixed; inset:0; z-index:200;
  display:grid; place-items:center;
  background:var(--oxblood);
  transform:translateY(0);
  transition:transform 1.05s var(--e-fash) .25s;
}
.intro.is-done{ transform:translateY(-101%); }
.intro[hidden]{ display:none; }

.intro__mark{
  height:clamp(30px,4.4vw,56px); width:auto;
  opacity:0; transform:translateY(14px);
  animation:introMark .9s var(--e-fash) .08s forwards;
}
.intro__bar{
  position:absolute; inset-block-end:0; inset-inline-start:0;
  height:2px; width:0; background:var(--champagne); opacity:.75;
  animation:introBar 1.15s var(--e-soft) forwards;
}
@keyframes introMark{ to{ opacity:1; transform:none; } }
@keyframes introBar { to{ width:100%; } }

/* The shell stays still until the curtain starts lifting. */
html.is-intro body{ overflow:hidden; }

/* --- 2. scroll reveals ---------------------------------------------------- */
/* The resting state. `is-in` is added once, when the element first enters. */
/* No blanket will-change: it would promote every revealable element on the
   page to its own compositor layer and keep it there for the whole visit. */
[data-reveal]{
  opacity:0;
  transition:opacity var(--d-3) var(--e-fash), transform var(--d-3) var(--e-fash),
             clip-path var(--d-3) var(--e-fash);
  transition-delay:var(--delay, 0ms);
}
[data-reveal="rise"],
[data-reveal=""]{ transform:translateY(26px); }
[data-reveal="fade"]{ transform:none; }
[data-reveal="scale"]{ transform:scale(.94); }
[data-reveal="mask"]{ clip-path:inset(0 0 100% 0); opacity:1; }
[data-reveal="wipe"]{ clip-path:inset(0 100% 0 0); opacity:1; }
body[dir="rtl"] [data-reveal="wipe"]{ clip-path:inset(0 0 0 100%); }

[data-reveal].is-in{ opacity:1; transform:none; clip-path:inset(0 0 0 0); }

/* Failsafe. Every resting state above is a hidden state, and the curtain is
   opaque: if the scripts never run -- blocked, 404, a parse error -- the whole
   site would be a blank panel. An inline head script adds `js`, so the hidden
   states only apply where there is something able to undo them. */
html:not(.js) .intro{ display:none; }
html:not(.js).is-intro body{ overflow:auto; }
html:not(.js) [data-reveal],
html:not(.js) [data-stagger] > *,
html:not(.js) .lines > *{
  opacity:1; transform:none; clip-path:none; transition:none;
}

/* A container may stagger its own children. They need their own resting
   state, otherwise there is nothing for the staggered .is-in to animate. */
[data-stagger] > *{
  opacity:0; transform:translateY(18px);
  transition:opacity var(--d-2) var(--e-fash), transform var(--d-2) var(--e-fash);
  transition-delay:var(--delay, 0ms);
}
[data-stagger] > *.is-in{ opacity:1; transform:none; }

/* --- 3. line entrance ---------------------------------------------------- */
/* Display headings climb in a line at a time. Deliberately no per-word
   overflow mask: wrapping each word in a clipping box stopped the Arabic
   display face from rendering at all, and a line-level rise reads the same. */
.lines > *{
  display:block;
  opacity:0; transform:translateY(.5em);
  transition:opacity var(--d-2) var(--e-fash), transform .9s var(--e-fash);
  transition-delay:var(--delay, 0ms);
}
.lines.is-in > *{ opacity:1; transform:none; }

/* --- 4. parallax ---------------------------------------------------------- */
/* The element is overscaled so the offset never exposes an edge. */
/* Only the parallax layers are promoted: they move every frame. */
[data-parallax] > img,
[data-parallax] > .par__in{ will-change:transform; }
.par__in{ display:block; height:100%; width:100%; }

/* --- 5. scroll progress --------------------------------------------------- */
.sprog{
  position:fixed; inset-block-start:0; inset-inline-start:0; z-index:calc(var(--z-nav) + 1);
  height:2px; width:100%; transform:scaleX(0); transform-origin:left center;
  background:var(--oxblood); pointer-events:none;
}
body[dir="rtl"] .sprog{ transform-origin:right center; }

/* --- 6. reduced motion: show everything, animate nothing ------------------ */
/* `html.motion-on` is the ?motion=on preview flag and opts back in, so the
   rules below are written to be cancelled by it rather than to use !important. */
@media (prefers-reduced-motion: reduce){
  html:not(.motion-on) .intro{ display:none; }
  html:not(.motion-on).is-intro body{ overflow:auto; }
  html:not(.motion-on) [data-reveal],
  html:not(.motion-on) [data-reveal="mask"],
  html:not(.motion-on) [data-reveal="wipe"],
  html:not(.motion-on) [data-stagger] > *{
    opacity:1; transform:none; clip-path:none; transition:none;
  }
  html:not(.motion-on) .lines > *{ opacity:1; transform:none; transition:none; }
  html:not(.motion-on) [data-parallax] > img,
  html:not(.motion-on) [data-parallax] > .par__in{ transform:none; }
  html:not(.motion-on) .sprog{ display:none; }
}
