/* Dokter Tani motion layer. Linked AFTER every other stylesheet. Driven by src/scripts/motion.ts.
 *
 * Hard rule: nothing is hidden unless html.motion is present. A head script adds it only when
 * reduced motion is not requested, and removes it again after 2.5 s if motion.ts never started.
 * With JS disabled or reduced motion on, pages must look exactly like the reference. */

/* Initial (pre-animation) states. motion.ts adds .is-revealed / .is-hero-done when an element has played. */
html.motion [data-reveal]:not(.is-revealed) { opacity: 0; transform: translateY(32px); }
html.motion [data-reveal-stagger]:not(.is-revealed) > * { opacity: 0; transform: translateY(32px); }
html.motion [data-hero]:not(.is-hero-done) [data-hero-item] { opacity: 0; }
html.motion [data-hero]:not(.is-hero-done):not(:has([data-hero-item])) { opacity: 0; }
/* data-split headings wait (transparent) until motion.ts splits and reveals their lines. */
html.motion [data-split]:not(.is-split-done) { opacity: 0; }
/* A split hero item whose lines finished before the hero's own fade must stay visible. */
html.motion [data-hero]:not(.is-hero-done) [data-hero-item].is-split-done { opacity: 1; }
/* data-wipe photos start fully clipped; motion.ts wipes them open and clears the clip-path. */
html.motion [data-wipe]:not(.is-wiped) { clip-path: inset(0 0 100% 0); }
/* Lite mode (weak devices, motion.ts adds html.dt-lite): opacity-only reveals, so no 32 px rise in the hidden state
 * (otherwise the element would jump when the hidden rule lifts at the end). */
html.dt-lite [data-reveal]:not(.is-revealed) { transform: none; }
html.dt-lite [data-reveal-stagger]:not(.is-revealed) > * { transform: none; }
/* Masked lines (SplitText) must not clip descenders or italics. */
.dt-line { padding-bottom: .08em; margin-bottom: -.08em; }

/* data-pin-steps: only dimmed while the desktop pin is active (motion.ts adds .is-pin-steps). */
.is-pin-steps [data-step] { transition: opacity .45s cubic-bezier(.45, 0, .55, 1); }
.is-pin-steps [data-step]:not(.is-active):not(.is-done) { opacity: .38; }

/* ScrollSmoother is driving the scroll: native smooth scrolling must be off.
 * (position:sticky elements are inert inside the smoother's wrapper; motion.ts pins them instead.) */
html.dt-smooth { scroll-behavior: auto; }
/* A sticky element handed to a ScrollTrigger pin: ScrollTrigger copies its inset onto the pin-spacer,
 * so the sticky `top` offset must go (the pin start/end already encode it). z-index keeps applying. */
html.dt-smooth .dt-pinned { position: relative; top: auto; }

/* Never animate in print or for reduced motion. */
@media print, (prefers-reduced-motion: reduce) {
  html.motion [data-reveal], html.motion [data-reveal-stagger] > *,
  html.motion [data-hero] [data-hero-item], html.motion [data-hero] { opacity: 1 !important; transform: none !important; }
  html.motion [data-split], html.motion [data-wipe] { opacity: 1 !important; clip-path: none !important; }
}

/* ---- Cross-document view transitions (progressive enhancement; full page loads stay as they are) ----
 * Chromium cross-fades the old page out (slight upward drift) and the new page in (from slightly below).
 * The header is its own named layer so it stays put. Browsers without support just navigate normally. */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }

.header { view-transition-name: site-header; }
::view-transition-group(site-header) { animation-duration: 0s; }
::view-transition-old(root) { animation: dt-vt-out .4s cubic-bezier(.65, 0, .35, 1) both; }
::view-transition-new(root) { animation: dt-vt-in .5s cubic-bezier(.65, 0, .35, 1) both; }
@keyframes dt-vt-out { to { opacity: 0; transform: translateY(-14px); } }
@keyframes dt-vt-in { from { opacity: 0; transform: translateY(18px); } }
/* Phones: a short cross-fade (about 180 ms), no drift. Desktop keeps the 0.4 / 0.5 s version above. */
@media (max-width: 768px) {
  ::view-transition-old(root) { animation: dt-vt-fade-out .18s cubic-bezier(.45, 0, .55, 1) both; }
  ::view-transition-new(root) { animation: dt-vt-fade-in .18s cubic-bezier(.45, 0, .55, 1) both; }
  @keyframes dt-vt-fade-out { to { opacity: 0; } }
  @keyframes dt-vt-fade-in { from { opacity: 0; } }
}
/* The header persists across the transition: its intro must not replay (motion.ts sets html.dt-vt on pagereveal). */
html.dt-vt .header [data-hero-item], html.dt-vt .header[data-hero] { opacity: 1 !important; transform: none !important; }

/* ---- Lazy images fade in once loaded (motion.ts adds .dt-img-wait only to images still loading) ---- */
html.motion img.dt-img-wait { opacity: 0; }
html.motion img.dt-img-fade { transition: opacity .5s cubic-bezier(.45, 0, .55, 1); }

/* ---- Reading progress (article pages). Hidden unless motion runs; fixed, outside the smoother, no layout impact. ---- */
.read-progress { display: none; }
html.motion .read-progress { display: block; position: fixed; left: 0; right: 0; top: 90px; height: 3px; z-index: 19; pointer-events: none; }
.read-progress > span { display: block; height: 100%; background: var(--green, #2f7d4f); transform: scaleX(0); transform-origin: 0 50%; }
@media print, (prefers-reduced-motion: reduce) { html.motion .read-progress { display: none; } }
