/* ==========================================================================
   Paint Scroller ("the stage") — home page single-page showcase
   A sticky viewport; scroll progress drives which chapter is painted.
   JS (stage.js) sets: --t (global progress), per-chapter --p (wipe 0..1),
   --u (hold progress), and positions the brush. Everything else is CSS.
   ========================================================================== */
.stage { position: relative; height: calc(var(--n, 6) * 100svh + 40svh); }
.stage__sticky { position: sticky; top: 0; height: 100svh; overflow: clip; isolation: isolate; background: var(--bg); }

.chapter { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: clamp(1rem, 4vw, 4rem); align-items: center; padding: clamp(5rem, 10vh, 7rem) var(--gutter) clamp(4rem, 9vh, 6rem); background: var(--c-bg, var(--bg)); color: var(--c-fg, var(--text)); visibility: hidden; }
.chapter[data-state="base"], .chapter[data-state="incoming"], .chapter[data-state="static"] { visibility: visible; }
.chapter[data-state="incoming"] { z-index: 2; pointer-events: none; /* masked-out pixels still catch clicks otherwise; the hero buttons sit underneath */
  -webkit-mask-image: var(--mask); mask-image: var(--mask);
  -webkit-mask-size: 300% 100%; mask-size: 300% 100%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: calc(var(--mp, 0) * 1%) 0; mask-position: calc(var(--mp, 0) * 1%) 0; }
.chapter[data-state="base"] { z-index: 1; }
@media (max-width: 860px) { .chapter { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: var(--s-4); padding-top: 5.5rem; } }

/* decorative splats per chapter, drift with --u */
.chapter__deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.chapter__deco svg { position: absolute; width: var(--w, 22vw); opacity: .22; transform: translate3d(0, calc(var(--u, 0) * var(--drift, -60px)), 0) rotate(calc(var(--u, 0) * var(--spin, 20deg))); }
.chapter__deco .d1 { left: -6vw; top: -8vh; --drift: 40px; --spin: -15deg; }
.chapter__deco .d2 { right: -8vw; bottom: -10vh; --w: 30vw; --drift: -80px; --spin: 25deg; }
.chapter__deco .d3 { left: 40%; top: -12vh; --w: 12vw; --drift: 120px; --spin: 90deg; }

.chapter__media { position: relative; z-index: 1; justify-self: center; width: min(100%, 44vw); max-height: 78svh; margin: 0; transform: translate3d(0, calc((.5 - var(--u, .5)) * 40px), 0) scale(calc(1.02 - var(--u, 0) * .02)); filter: drop-shadow(0 40px 60px rgba(5,8,26,.55)); }
.chapter__media img { width: 100%; height: 100%; max-height: 78svh; object-fit: contain; border-radius: var(--r-xl); box-shadow: var(--sticker); background: var(--navy-900); }
@media (max-width: 860px) { .chapter__media { width: min(100%, 78vw); max-height: 48svh; } .chapter__media img { max-height: 48svh; } }

.chapter__text { position: relative; z-index: 1; display: grid; gap: var(--s-3); align-content: center; }
.chapter__num { font-family: var(--font-display); font-weight: 600; letter-spacing: .2em; font-size: var(--fs-sm); opacity: .8; }
.chapter__title { font-size: var(--fs-2xl); line-height: .98; }
.chapter__sub { font-family: var(--font-display); font-weight: 500; font-size: var(--fs-lg); opacity: .85; }
.chapter__story { max-width: 46ch; opacity: .9; }
.chapter__text .btn { justify-self: start; }
/* text slides in as the wipe finishes (incoming) and is settled when base */
.chapter[data-state="incoming"] .chapter__text > * { opacity: calc((var(--p, 0) - .45) / .55); transform: translateX(calc((1 - var(--p, 0)) * var(--dir, 1) * 40px)); }
.chapter[data-state="incoming"] .chapter__text > :nth-child(2) { transition-delay: 60ms; }

/* Hero chapter */
.chapter--hero { grid-template-columns: 1fr; place-items: center; text-align: center; padding-top: 72px; padding-bottom: 56px; } /* 72 = header height once the stage is stuck; 56 leaves room for the scroll hint */
.chapter--hero .hero__bg { opacity: .6; }
.chapter--hero .hero__inner { position: relative; z-index: 1; display: grid; justify-items: center; gap: clamp(.6rem, 1.6svh, 1.25rem); max-width: 900px; transform: translate3d(0, calc(var(--u, 0) * -120px), 0); opacity: calc(1 - var(--u, 0) * .9); }
.chapter--hero .hero__wordmark { position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(3.5rem, 13vw, 15rem); line-height: 1; letter-spacing: -.04em; white-space: nowrap; -webkit-text-stroke: 2px rgba(195,166,255,.22); color: transparent; transform: translate3d(0, calc(var(--u, 0) * min(120px, 12svh)), 0) scale(calc(1 + var(--u, 0) * .2)); pointer-events: none; user-select: none; }
/* Everything in the hero, buttons and commissions line included, has to fit one screen: sizes scale with the viewport height. */
.chapter--hero .hero__logo { width: min(300px, 48vw, 24svh); filter: drop-shadow(0 24px 40px rgba(5,8,26,.7)); }
.chapter--hero .hero__title { font-size: min(var(--fs-2xl), 6.2svh); max-width: 16ch; }
.chapter--hero .lede { font-size: min(var(--fs-md), 2.6svh); }
@media (max-width: 480px) { .chapter--hero .hero__actions { gap: var(--s-2); } .chapter--hero .hero__actions .btn { padding: .75em 1.1em; font-size: var(--fs-sm); } }
.chapter--hero .floaters { z-index: 0; }

/* End chapter */
.chapter--end { grid-template-columns: 1fr; place-items: center; text-align: center; }
.chapter--end .end__inner { display: grid; justify-items: center; gap: var(--s-5); max-width: 760px; position: relative; z-index: 1; }
.chapter--end .end__thumbs { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s-2); max-width: 100%; }
.chapter--end .end__thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 14px; box-shadow: var(--sticker-sm); transform: rotate(var(--r, 0deg)); }

/* Brush sprite */
.brush { position: absolute; z-index: 5; left: 0; top: 0; width: clamp(120px, 14vw, 220px); pointer-events: none; opacity: 0; transform-origin: 50% 96%; filter: drop-shadow(0 18px 24px rgba(5,8,26,.6)); will-change: transform; }
.brush[data-active="true"] { opacity: 1; }
.brush svg { width: 100%; height: auto; overflow: visible; }
.brush__drip { transform-origin: 50% 0; animation: drip 1.2s ease-in infinite; }
@keyframes drip { 0% { transform: scaleY(.2); opacity: 0; } 30% { opacity: 1; } 100% { transform: scaleY(1.4) translateY(40px); opacity: 0; } }

/* Rail (chapter nav) + hint */
.stage__rail { position: absolute; right: clamp(.6rem, 2vw, 1.6rem); top: 50%; translate: 0 -50%; z-index: 6; display: grid; gap: 10px; }
.stage__rail button { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.35); box-shadow: 0 0 0 2px rgba(5,8,26,.4); transition: all var(--d-fast) var(--ease-pop); }
.stage__rail button:hover { transform: scale(1.3); background: #fff; }
.stage__rail button[aria-current="true"] { background: var(--yellow-400); transform: scale(1.5) rotate(45deg); border-radius: 3px; box-shadow: 0 0 0 2px var(--ink); }
.stage__counter { position: absolute; left: var(--gutter); bottom: clamp(1rem, 4vh, 2.5rem); z-index: 6; font-family: var(--font-display); font-weight: 600; letter-spacing: .18em; font-size: var(--fs-sm); color: var(--text); mix-blend-mode: difference; }
.stage__hint { position: absolute; left: 50%; bottom: clamp(1rem, 4vh, 2.5rem); translate: -50% 0; z-index: 6; display: inline-flex; align-items: center; gap: .5em; font-family: var(--font-display); font-weight: 600; font-size: var(--fs-xs); letter-spacing: .2em; text-transform: uppercase; color: var(--text-2); opacity: calc(1 - var(--t, 0) * 2); animation: hint 1.6s ease-in-out infinite; }
.stage__hint svg { width: 16px; height: 16px; }
@keyframes hint { 50% { translate: -50% 6px; } }
.stage__wheel-line { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; z-index: 7; background: linear-gradient(90deg, var(--pink-500), var(--yellow-400), var(--cyan-500), var(--lav-500)); transform-origin: 0 50%; transform: scaleX(var(--t, 0)); }

/* Reduced motion / no-JS fallback: chapters stack as plain sections */
.stage[data-static] { height: auto; }
.stage[data-static] .stage__sticky { position: static; height: auto; overflow: visible; }
.stage[data-static] .chapter { position: relative; min-height: 80svh; visibility: visible; --u: .5; --p: 1; }
.stage[data-static] .chapter[data-state="incoming"] { -webkit-mask-image: none; mask-image: none; }
.stage[data-static] .brush, .stage[data-static] .stage__rail, .stage[data-static] .stage__hint, .stage[data-static] .stage__counter, .stage[data-static] .stage__wheel-line { display: none; }

/* Short viewports (landscape phones, small laptop panes): compact hero */
@media (max-height: 700px) {
  .chapter--hero .hero__logo { width: min(170px, 36vw, 26svh); }
  .chapter--hero .hero__title { font-size: min(var(--fs-xl), 6svh); }
  .chapter--hero .lede { display: none; }
  .chapter { padding-top: 4.5rem; padding-bottom: 3.5rem; }
}

/* Phones: the chapter rail moves off the text and sits bottom-right; the scroll hint gives way to it */
@media (max-width: 700px) {
  .stage__rail { top: auto; translate: none; right: var(--gutter); bottom: clamp(1rem, 4vh, 2.5rem); display: flex; gap: 9px; align-items: center; }
  .stage__hint { display: none; }
  .chapter--end .end__thumbs img { width: 48px; height: 48px; }
}
