/* ==========================================================================
   Shared motion CSS, for every page. Link it after styles.css.
   Works together with js/motion.js. Nothing here hides content unless the
   script has confirmed it can show it again (see .intro-pending).
   ========================================================================== */

/* Lenis smooth scroll (the script adds .lenis to <html> when it runs) */
html.lenis, html.lenis body { height: auto; }
html.lenis { scroll-behavior: auto !important; }
/* While the script drives the page it animates every scroll itself. Native smooth
   scrolling would fight ScrollTrigger's measuring and the chapter jumps (this matters
   when GSAP loaded but Lenis did not). Without the script, styles.css keeps it smooth. */
html.motion { scroll-behavior: auto; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-stopped { overflow: clip; }

/* Scroll lock while a dialog is open. The gutter stays so the page does not jump sideways. */
html.js { scrollbar-gutter: stable; }
html.is-locked { overflow: hidden; }

/* Things only useful when the script runs */
html:not(.js) .js-only { display: none !important; }

/* Intro: the head snippet sets .intro-pending before first paint, the script
   removes it when the intro starts, and a timer removes it after 2.5 s anyway. */
html.intro-pending [data-intro="name"] { opacity: 0.3; }
html.intro-pending [data-intro="cover"],
html.intro-pending [data-enter] { opacity: 0; }

/* Elements the script is animating get a compositor hint only while they move */
[data-reveal].is-revealing { will-change: transform, opacity; }

/* Page transition between the site's own pages.
   1. Browsers with cross-document view transitions: a short cross-fade with a small rise. */
@view-transition { navigation: auto; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-12px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(16px); } }
::view-transition-old(root) { animation: vt-out 0.28s cubic-bezier(0.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: vt-in 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.12s both; }

/* 2. Fallback: the script adds .is-leaving, waits, then navigates; the new page fades in. */
html.is-leaving body { opacity: 0; transform: translateY(-8px); transition: opacity 0.24s ease-in, transform 0.24s ease-in; }
@keyframes page-in { from { opacity: 0; } }
html.is-entering body { animation: page-in 0.45s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  html.is-leaving body { opacity: 1; transform: none; }
  html.is-entering body { animation: none; }
}

/* Printing a page that has not been scrolled to the end: blocks still waiting for
   their reveal carry an inline opacity of 0 from the script. Show them on paper. */
@media print {
  [data-reveal], [data-reveal="children"] > *, [data-enter], [data-intro] { opacity: 1 !important; transform: none !important; }
}
