/* sp3d.css: the layout and state rules every 3D section needs (Showpiece Mode).
   Copy to assets/css/. Tokens come from showpiece.css (--sp-*); fallbacks keep it standalone. */

[data-sp3d] { position: relative; isolation: isolate; }            /* own stacking context: the canvas can never leak over page UI */

/* Poster first. It is the LCP image and the complete fallback. */
[data-sp3d] .sp3d-poster,
[data-sp3d] .sp3d-src { display: block; width: 100%; height: 100%; object-fit: cover; }
[data-sp3d] .sp3d-poster { position: absolute; inset: 0; z-index: 0; }

/* Canvas sits over the poster, under the real content, and never takes the pointer unless a pattern asks. */
[data-sp3d] .sp3d-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;
  opacity: 0; transition: opacity .4s ease; pointer-events: none; }
[data-sp3d].is-3d-ready .sp3d-canvas { opacity: 1; }
[data-sp3d].is-3d-ready .sp3d-poster,
[data-sp3d].is-3d-ready .sp3d-src { opacity: 0; }                  /* faded, never removed: the alt text stays in the page */
[data-sp3d].is-3d-lost .sp3d-canvas { opacity: 0; }                 /* context lost: the poster shows again */
[data-sp3d].is-3d-lost .sp3d-poster,
[data-sp3d].is-3d-fallback .sp3d-poster { opacity: 1; }
[data-sp3d].is-3d-fallback .sp3d-canvas { display: none; }

/* Real content always above the canvas */
[data-sp3d] > :not(.sp3d-poster):not(.sp3d-canvas):not(.sp3d-pin) { position: relative; z-index: 2; }

/* P7: tall section, sticky stage, chapters in normal flow. No JS pin. */
.sp3d-scroll { height: 400vh; }
.sp3d-scroll .sp3d-pin { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; z-index: 0; }
.sp3d-scroll .sp3d-pin .sp3d-canvas { position: absolute; }
.sp3d-scroll [data-chapter] { position: relative; z-index: 2; min-height: 100vh; display: grid; align-content: center; padding: 0 var(--sp-gutter, 6vw); max-width: 38rem; }
.sp3d-scroll [data-chapter]:nth-of-type(even) { margin-left: auto; }

/* Fallback and reduced motion: no tall section, no sticky, poster plus all chapters stacked and readable */
@media (prefers-reduced-motion: reduce), (max-width: 767px) {
  .sp3d-scroll { height: auto; }
  .sp3d-scroll .sp3d-pin { position: relative; height: 60vh; }
  .sp3d-scroll [data-chapter] { min-height: 0; padding-block: 3rem; }
}
.sp3d-scroll.is-3d-fallback { height: auto; }
.sp3d-scroll.is-3d-fallback .sp3d-pin { position: relative; height: 60vh; }
.sp3d-scroll.is-3d-fallback [data-chapter] { min-height: 0; padding-block: 3rem; }

/* Loader: a progress cue, never a gate. Content is already under it. */
.sp3d-loader { position: fixed; inset: 0; z-index: 90; display: grid; place-items: end start; padding: 1.5rem;
  background: var(--sp-ink, #0b0b0b); color: var(--sp-paper, #fff); transition: opacity .4s ease; }
.sp3d-loader.is-done { opacity: 0; pointer-events: none; }
.sp3d-loader__bar { display: block; width: min(16rem, 60vw); height: 2px; background: currentColor; transform: scaleX(0); transform-origin: left; }

@media (prefers-reduced-motion: reduce) { .sp3d-canvas { transition: none; } .sp3d-loader { display: none; } }
