/* ==========================================================================
   "The Stack" — embedded 3D section (homepage). Loaded in addition to
   style.css; reuses its tokens (--bg, --signal, --display, --mono, etc.)

   Desktop: GSAP ScrollTrigger pins .stack-section and scrubs a LEGO build
   animation (see js/stack-scene.js) — the scroll runway is created by
   ScrollTrigger itself (pinSpacing). .stack-sticky is a no-op wrapper here
   (position:relative, same box as .stack-section).

   Mobile: no ScrollTrigger (JS scroll-jacking pin is a bad time on a phone),
   but the build still needs a real scroll runway or it finishes within a
   swipe or two. .stack-section is a tall (280vh) scroll track and
   .stack-sticky is position:sticky within it — a native-CSS pin that holds
   the scene on screen while progress is computed from how far the page has
   scrolled through that track (see mobileProgress() in stack-scene.js).
   ========================================================================== */

.stack-section{
  position:relative; padding:0; height:92vh; min-height:620px; max-height:920px;
  border-top:1px solid var(--line-soft); border-bottom:1px solid var(--line-soft);
}
.stack-sticky{
  position:relative; height:100%; overflow:hidden;
  background:var(--bg);
}
.stack-canvas-wrap{
  position:relative; height:100%; overflow:hidden;
  background:radial-gradient(ellipse 70% 60% at 50% 40%, rgba(13,163,152,0.08), transparent 65%), var(--bg);
}
#stack-scene-container{position:absolute; inset:0; z-index:1;}
#stack-scene-container canvas{display:block;}

.stack-intro{
  position:absolute; top:56px; left:clamp(20px,5vw,64px); z-index:15; max-width:420px; pointer-events:none;
  background:radial-gradient(ellipse 130% 150% at 0% 0%, rgba(255,255,255,0.92) 0%, rgba(255,255,255,0.7) 45%, transparent 78%);
  padding:16px 24px 16px 0; margin:-16px 0 0 -4px;
}
:root[data-theme="dark"] .stack-intro{
  background:radial-gradient(ellipse 130% 150% at 0% 0%, rgba(6,8,11,0.88) 0%, rgba(6,8,11,0.62) 45%, transparent 78%);
}
.stack-intro .eyebrow{margin-bottom:14px;}
.stack-intro h2{font-family:var(--display); font-weight:700; font-size:clamp(1.6rem,3vw,2.6rem); line-height:1.1; margin:0 0 14px; letter-spacing:-.02em;}
.stack-intro h2 em{font-style:normal; color:var(--signal);}
.stack-intro p{font-size:14.5px; color:var(--ink-dim); line-height:1.6; margin:0;}
@media (max-width:760px){ .stack-intro{max-width:78vw;} }

.stack-progress{
  font-family:var(--mono); font-size:11.5px; color:var(--ink-faint);
  margin-top:22px; padding-top:16px; border-top:1px solid var(--line-soft);
  display:flex; align-items:baseline; gap:2px;
}
.stack-progress-n{color:var(--signal); font-weight:600; font-size:13px;}
.stack-progress-sep{margin-right:9px;}
.stack-progress-label{color:var(--ink-dim); text-transform:uppercase; letter-spacing:.05em;}

/* At the jackpot payoff the intro copy steps back so the reward — which can
   land anywhere near the top of the frame depending on viewport/camera —
   never has to fight the headline for the same space. Desktop only: on
   mobile the copy sits in its own block above the scene (see the media
   query below) and never competes with the jackpot for room. */
.stack-intro{transition:opacity .4s ease;}
@media (min-width:761px){
  .stack-section.is-celebrating .stack-intro{opacity:.28;}
}

/* ---- Mobile: tall scroll track + sticky pin (see file header) so the
   build has real scroll distance to react to, plus the static text fallback
   list rendered below (see .stack-fallback). Text and scene stack vertically
   here instead of the desktop's overlay — a minifig or brick could otherwise
   poke up into the copy with no readable boundary between them. .stack-intro
   sits in normal flow with a solid background and a divider; .stack-canvas-
   wrap takes the rest of the sticky block's height. ---- */
@media (max-width:760px){
  .stack-section{height:280vh; min-height:0; max-height:none;}
  .stack-sticky{
    position:sticky; top:0; height:92vh; min-height:480px; max-height:780px;
    display:flex; flex-direction:column;
  }

  .stack-intro{
    position:static; max-width:none; width:100%; flex:0 0 auto; pointer-events:auto;
    padding:20px clamp(20px,6vw,32px) 18px; margin:0;
    background:var(--bg); border-bottom:1px solid var(--line-soft);
  }
  .stack-intro .eyebrow{margin-bottom:10px;}
  .stack-intro h2{font-size:1.3rem; margin-bottom:8px;}
  .stack-intro p{font-size:13px; max-width:46ch;}
  .stack-progress{margin-top:12px; padding-top:12px;}

  .stack-canvas-wrap{flex:1 1 auto; min-height:0;}
}

/* ---- Jackpot flourish — plays once when the last brick lands. Reels are
   plain vertical strips clipped to one symbol's height; each is animated to
   a different duration so they "stop" in sequence, landing on a shared
   symbol like a slot-machine match. ---- */
.stack-jackpot{
  position:absolute; left:50%; top:8%; z-index:20; text-align:center;
  display:flex; flex-direction:column; align-items:center; gap:12px;
  /* translateY(-100%) anchors the widget's BOTTOM edge to `top`, set from JS
     to the tower's actual projected peak — the box always sits above it,
     not centered on it, so it can't land behind a tall build. */
  transform:translate(-50%,-100%) scale(0.85); opacity:0; pointer-events:none;
  transition:opacity .3s ease, transform .3s ease, top .3s ease;
}
.stack-jackpot.is-active, .stack-jackpot.is-static{opacity:1; transform:translate(-50%,-100%) scale(1);}
.jackpot-reels{
  position:relative; display:flex; gap:10px; background:rgba(255,255,255,0.95); border:2px solid var(--signal);
  border-radius:10px; padding:14px 16px 10px; box-shadow:0 16px 44px rgba(13,163,152,0.3);
}
:root[data-theme="dark"] .jackpot-reels{background:rgba(10,12,16,0.9);}
/* A row of studs along the top turns the housing into a little LEGO plate,
   echoing the tower it sits above. */
.jackpot-reels::before{
  content:''; position:absolute; left:16px; right:16px; top:-8px; height:8px;
  background-image:radial-gradient(circle, var(--signal) 0 5px, transparent 5.5px);
  background-size:24px 16px; background-repeat:repeat-x;
}
.jackpot-reel{width:50px; height:50px; overflow:hidden; border-radius:6px; background:var(--bg-raised); border:1px solid var(--line-soft);}
.jackpot-reel-strip{display:flex; flex-direction:column;}
.jackpot-reel-strip span{width:50px; height:50px; line-height:50px; font-size:27px; text-align:center;}
.is-active .jackpot-reel:nth-child(1) .jackpot-reel-strip{animation:jackpotSpin 1.1s cubic-bezier(.2,.85,.25,1) forwards;}
.is-active .jackpot-reel:nth-child(2) .jackpot-reel-strip{animation:jackpotSpin 1.45s cubic-bezier(.2,.85,.25,1) forwards;}
.is-active .jackpot-reel:nth-child(3) .jackpot-reel-strip{animation:jackpotSpin 1.8s cubic-bezier(.2,.85,.25,1) forwards;}
.is-static .jackpot-reel-strip{transform:translateY(-400px);}
@keyframes jackpotSpin{
  from{transform:translateY(0);}
  to{transform:translateY(-400px);}
}
.jackpot-label{
  font-family:var(--mono); font-size:12px; letter-spacing:.08em; text-transform:uppercase;
  color:var(--signal-deep); background:rgba(255,255,255,0.95); padding:7px 18px; border-radius:20px;
  border:1px solid var(--signal); opacity:0; transform:translateY(6px);
}
:root[data-theme="dark"] .jackpot-label{background:rgba(10,12,16,0.88); color:var(--signal);}
.is-active .jackpot-label{animation:jackpotLabelIn .4s ease 1.85s forwards;}
.is-static .jackpot-label{opacity:1; transform:none;}
@keyframes jackpotLabelIn{ to{opacity:1; transform:translateY(0);} }

.stack-confetti{position:absolute; inset:0; z-index:19; overflow:hidden; pointer-events:none;}
.confetti-coin{position:absolute; top:-8%; will-change:transform, opacity; animation:coinFall linear forwards;}
@keyframes coinFall{
  0%{transform:translateY(0) rotate(0deg); opacity:0;}
  8%{opacity:1;}
  100%{transform:translateY(100vh) rotate(380deg); opacity:0;}
}

/* ---- Static fallback list — hidden on desktop, shown on mobile below
   the 3D canvas. Content is injected from window.STACK_HOTSPOTS by
   js/stack-scene.js (same source of truth as the 3D scene), so it
   works even if WebGL/Three.js fails to load on a low-power device. ---- */
.stack-fallback{display:none;}
@media (max-width:760px){
  .stack-fallback{
    display:block; position:relative; z-index:20; padding:36px 0 8px;
  }
  .stack-fallback .eyebrow{margin-bottom:18px;}
  .stack-fallback-list{display:flex; flex-direction:column;}
  .stack-fallback-item{display:flex; gap:16px; padding:18px 0; border-top:1px solid var(--line-soft);}
  .stack-fallback-item:last-child{padding-bottom:0;}
  .stack-fallback-n{font-family:var(--mono); font-size:12px; color:var(--signal); flex-shrink:0; padding-top:2px; min-width:22px;}
  .stack-fallback-body h4{font-family:var(--display); font-weight:700; font-size:15px; margin:0 0 6px; color:var(--ink);}
  .stack-fallback-body p{font-size:13.5px; color:var(--ink-dim); margin:0; line-height:1.65;}
}
