/* global React */
// IntroScene.jsx — pinned scrollytelling intro, retro letterpress feel.
// 4× viewport scroll height. Team-aware: shows pivo OR vejce scene.
// Bonus: pivo → foam overflows into "Na zdraví" word; vejce → 7th egg cracks open to reveal &.

const { useEffect, useRef, useState } = React;

// ============ SHARED — RETRO TEXTURES ===================================
// Reusable SVG <defs> block: dotted halftone fills + paper grain.
function RetroDefs() {
  return (
    <defs>
      {/* Halftone dot pattern — dark dots on transparent (for shading) */}
      <pattern id="dots-dark" width="6" height="6" patternUnits="userSpaceOnUse">
        <circle cx="3" cy="3" r="1.1" fill="rgba(26,22,19,0.55)"/>
      </pattern>
      <pattern id="dots-light" width="6" height="6" patternUnits="userSpaceOnUse">
        <circle cx="3" cy="3" r="0.9" fill="rgba(255,253,245,0.5)"/>
      </pattern>
      <pattern id="dots-paprika" width="5" height="5" patternUnits="userSpaceOnUse">
        <circle cx="2.5" cy="2.5" r="0.8" fill="rgba(200,50,30,0.7)"/>
      </pattern>
      {/* Paper grain — subtle noise via turbulence */}
      <filter id="grain" x="0" y="0" width="100%" height="100%">
        <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" seed="3"/>
        <feColorMatrix values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.07 0"/>
        <feComposite operator="in" in2="SourceGraphic"/>
        <feComposite operator="over" in2="SourceGraphic"/>
      </filter>
      {/* Liquid clip — used to clip beer fill to glass shape */}
      <clipPath id="glass-clip">
        <path d="M 86 124 L 314 124 L 296 612 L 104 612 Z"/>
      </clipPath>
    </defs>
  );
}

// ============ EASING ====================================================
const easeOut = (t) => 1 - Math.pow(1 - t, 3);
const easeInOut = (t) => t < 0.5 ? 2*t*t : 1 - Math.pow(-2*t + 2, 2)/2;
const clamp = (v, a=0, b=1) => Math.max(a, Math.min(b, v));
// progress within a sub-range [a,b] of overall p
const range = (p, a, b) => clamp((p - a) / (b - a));

// ============ PIVO SCENE ================================================
// Phases of progress p (0 → 1):
//  0.00–0.10  glass appears, tap descends from above
//  0.10–0.55  beer pours: fill rises, head builds, drip trails
//  0.55–0.70  glass full, head settles, slight wobble
//  0.70–0.90  BONUS: foam overflows, droplets fly, droplets reform into "NA ZDRAVÍ"
//  0.90–1.00  word locks, stamp drops in
function PivoScene({ p }) {
  // glass entrance
  const glassY = (1 - easeOut(range(p, 0, 0.08))) * 80;
  const glassOpacity = easeOut(range(p, 0, 0.06));
  // tap entrance
  const tapY = -100 + easeOut(range(p, 0.04, 0.12)) * 100;
  // pour active
  const pouring = p > 0.10 && p < 0.58;
  // beer fill height (0 = empty, 488 = full inside the clipPath)
  const fillProgress = easeInOut(range(p, 0.10, 0.55));
  const beerHeight = fillProgress * 488;
  const beerY = 612 - beerHeight;
  // head (foam) thickness on top — grows with pour, then plateaus
  const headThickness = Math.min(60, fillProgress * 78);
  // wobble
  const wobble = p > 0.55 && p < 0.70 ? Math.sin((p - 0.55) * 60) * 1.5 : 0;
  // overflow phase
  const overflowAmt = easeOut(range(p, 0.68, 0.85));
  // word reveal
  const wordOpacity = easeOut(range(p, 0.78, 0.92));
  const wordY = 40 + (1 - easeOut(range(p, 0.78, 0.92))) * 30;
  // stamp
  const stampScale = easeOut(range(p, 0.92, 1.0));
  const stampRot = -8 + (1 - easeOut(range(p, 0.92, 1.0))) * 30;

  // droplets — 14 droplets, each at staggered timing
  const droplets = [];
  for (let i = 0; i < 14; i++) {
    const start = 0.70 + (i / 14) * 0.10;
    const end = start + 0.08;
    const dp = range(p, start, end);
    if (dp <= 0 || dp >= 1) continue;
    const ix = (i % 2 === 0) ? -1 : 1;
    const dx = ix * (40 + (i * 13) % 80) * dp;
    const dy = -20 - dp * 80 + dp * dp * 220;
    const r = 4 + (i % 3) * 2;
    const op = 1 - dp * 0.3;
    droplets.push(
      <circle key={i} cx={200 + dx} cy={120 + dy} r={r} fill="var(--yolk)" stroke="var(--ink)" strokeWidth="2" opacity={op}/>
    );
  }

  return (
    <svg viewBox="0 0 400 720" preserveAspectRatio="xMidYMax meet" style={{ width:'100%', height:'100%', overflow:'visible' }}>
      <RetroDefs/>

      {/* Tap (pípa) — descends from top */}
      <g transform={`translate(0, ${tapY})`} opacity={glassOpacity}>
        {/* tap body */}
        <rect x="180" y="-20" width="40" height="60" fill="var(--ink)" stroke="var(--ink)" strokeWidth="3"/>
        <rect x="160" y="40" width="80" height="20" fill="var(--ink)"/>
        <rect x="160" y="40" width="80" height="20" fill="url(#dots-light)"/>
        {/* nozzle */}
        <rect x="190" y="60" width="20" height="40" fill="var(--ink)"/>
        <ellipse cx="200" cy="100" rx="14" ry="4" fill="var(--ink)"/>
        {/* handle */}
        <circle cx="200" cy="-30" r="14" fill="var(--paprika)" stroke="var(--ink)" strokeWidth="3"/>
        <circle cx="200" cy="-30" r="14" fill="url(#dots-dark)"/>
      </g>

      {/* Pour stream — visible while pouring */}
      {pouring && (
        <g opacity={easeOut(range(p, 0.10, 0.14))}>
          <rect x="194" y={tapY + 100} width="12" height={beerY - tapY - 100} fill="var(--yolk)" stroke="var(--ink)" strokeWidth="2"/>
          {/* shimmer dots inside stream */}
          <rect x="194" y={tapY + 100} width="12" height={beerY - tapY - 100} fill="url(#dots-light)"/>
        </g>
      )}

      {/* Glass + contents */}
      <g transform={`translate(${wobble}, ${glassY})`} opacity={glassOpacity}>
        {/* Glass back outline */}
        <path d="M 86 124 L 314 124 L 296 612 L 104 612 Z" fill="var(--foam)" stroke="var(--ink)" strokeWidth="5" strokeLinejoin="miter"/>

        {/* Beer fill (clipped to glass shape) */}
        <g clipPath="url(#glass-clip)">
          <rect x="86" y={beerY} width="228" height="488" fill="var(--yolk)"/>
          {/* halftone shading on right side of beer */}
          <rect x="220" y={beerY} width="94" height="488" fill="url(#dots-dark)" opacity="0.4"/>
          {/* light highlight on left */}
          <rect x="100" y={beerY + 20} width="22" height="450" fill="rgba(255,253,245,0.45)"/>
          {/* bubbles */}
          {fillProgress > 0.2 && [...Array(8)].map((_, i) => {
            const bp = ((p * 4 + i * 0.13) % 1);
            const bx = 110 + ((i * 31) % 180);
            const by = 600 - bp * (488 * fillProgress) + (i % 2) * 8;
            if (by < beerY) return null;
            return <circle key={i} cx={bx} cy={by} r={2.5 + (i%2)} fill="var(--foam)" opacity={0.7}/>;
          })}
          {/* head/foam — sits on top of beer */}
          {fillProgress > 0.05 && (
            <g>
              {/* foam body */}
              <rect x="86" y={beerY - headThickness} width="228" height={headThickness} fill="var(--foam)"/>
              {/* foam bumpy top — using small circles */}
              {[...Array(20)].map((_, i) => {
                const fx = 90 + i * 12;
                const fy = beerY - headThickness;
                const fr = 4 + ((i * 7) % 5);
                return <circle key={i} cx={fx} cy={fy} r={fr} fill="var(--foam)" stroke="var(--ink)" strokeWidth="1.5"/>;
              })}
              {/* foam shading dots */}
              <rect x="86" y={beerY - headThickness} width="228" height={headThickness} fill="url(#dots-dark)" opacity="0.18"/>
            </g>
          )}
        </g>

        {/* Glass front outline (over fill, but transparent inside) */}
        <path d="M 86 124 L 314 124 L 296 612 L 104 612 Z" fill="none" stroke="var(--ink)" strokeWidth="5"/>

        {/* Glass highlight stripe */}
        <path d="M 100 140 L 112 140 L 109 595 L 99 595 Z" fill="rgba(255,255,255,0.65)"/>

        {/* Embossed wordmark on glass (visible after fill) */}
        {fillProgress > 0.4 && (
          <g opacity={fillProgress * 0.85}>
            <text x="200" y="380" fontFamily="Archivo Black, Arial Black, sans-serif" fontSize="28" fill="var(--ink)" textAnchor="middle" letterSpacing="-1" opacity="0.55">PIVO</text>
            <text x="200" y="412" fontFamily="Fraunces, Georgia, serif" fontWeight="900" fontStyle="italic" fontSize="40" fill="var(--ink)" textAnchor="middle" opacity="0.55">&amp;</text>
            <text x="200" y="442" fontFamily="Archivo Black, Arial Black, sans-serif" fontSize="28" fill="var(--ink)" textAnchor="middle" letterSpacing="-1" opacity="0.55">VEJCE</text>
          </g>
        )}
      </g>

      {/* OVERFLOW DROPLETS — fly outward, BONUS phase */}
      {droplets}

      {/* Overflow foam dripping over rim */}
      {overflowAmt > 0 && (
        <g transform={`translate(${wobble}, ${glassY})`}>
          {[...Array(6)].map((_, i) => {
            const dx = 95 + i * 38;
            const len = 20 + overflowAmt * (40 + (i * 13) % 30);
            return (
              <g key={i}>
                <rect x={dx} y={124 - 8} width={20} height={8 + len} fill="var(--foam)" stroke="var(--ink)" strokeWidth="2"/>
                <circle cx={dx + 10} cy={124 - 8 + len + 8} r="6" fill="var(--foam)" stroke="var(--ink)" strokeWidth="2"/>
              </g>
            );
          })}
        </g>
      )}

      {/* BONUS WORD: NA ZDRAVÍ (foam-shaped) */}
      <g transform={`translate(0, ${wordY})`} opacity={wordOpacity}>
        <text x="200" y="60" fontFamily="Archivo Black, Arial Black, sans-serif" fontSize="56" fill="var(--foam)" stroke="var(--ink)" strokeWidth="4" textAnchor="middle" letterSpacing="-1" paintOrder="stroke">NA ZDRAVÍ</text>
        <text x="200" y="60" fontFamily="Archivo Black, Arial Black, sans-serif" fontSize="56" fill="url(#dots-paprika)" textAnchor="middle" letterSpacing="-1" opacity="0.4">NA ZDRAVÍ</text>
      </g>

      {/* Stamp */}
      <g transform={`translate(310, 600) scale(${stampScale}) rotate(${stampRot})`} opacity={stampScale}>
        <circle cx="0" cy="0" r="42" fill="none" stroke="var(--paprika)" strokeWidth="3"/>
        <circle cx="0" cy="0" r="34" fill="none" stroke="var(--paprika)" strokeWidth="1.5"/>
        <text x="0" y="-6" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="9" fill="var(--paprika)" textAnchor="middle" letterSpacing="2">0,5 L</text>
        <text x="0" y="8" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="9" fill="var(--paprika)" textAnchor="middle" letterSpacing="2">PRAHA</text>
        <text x="0" y="22" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="7" fill="var(--paprika)" textAnchor="middle" letterSpacing="1.5">OPRAVDU</text>
      </g>
    </svg>
  );
}

// ============ VEJCE SCENE ===============================================
// Phases:
//  0.00–0.08  basket appears
//  0.08–0.65  6 eggs fall in sequence, each lands & wobbles
//  0.65–0.78  basket settles, last wobble
//  0.78–0.92  BONUS: 7th egg falls, cracks open mid-air revealing huge "&"
//  0.92–1.00  & locks, stamp drops
function VejceScene({ p }) {
  const basketY = (1 - easeOut(range(p, 0, 0.08))) * 80;
  const basketOpacity = easeOut(range(p, 0, 0.06));

  // 6 eggs falling in sequence
  const eggs = [];
  // rest positions inside the basket — arranged in a 3-2-1 pyramid
  const eggPositions = [
    { x: 130, y: 510, rot: -10 },
    { x: 200, y: 510, rot: 4 },
    { x: 270, y: 510, rot: 12 },
    { x: 165, y: 470, rot: -6 },
    { x: 235, y: 470, rot: 8 },
    { x: 200, y: 432, rot: 2 },
  ];
  for (let i = 0; i < 6; i++) {
    const start = 0.10 + i * 0.085;
    const land = start + 0.06;
    const fp = range(p, start, land);
    if (fp <= 0) continue;
    const target = eggPositions[i];
    // fall: from y = -80 down to target.y
    const startY = -80 - (i % 2) * 30;
    const cy = startY + easeIn(fp) * (target.y - startY);
    // little wobble after landing
    const settled = range(p, land, land + 0.04);
    const wobble = settled > 0 && settled < 1 ? Math.sin(settled * 18) * 4 * (1 - settled) : 0;
    // rotation while falling
    const rot = (1 - fp) * (i % 2 === 0 ? -180 : 180) + target.rot + wobble;

    eggs.push(<Egg key={i} cx={target.x} cy={cy} rot={rot}/>);
  }

  // BONUS: 7th egg falls, cracks at peak
  const seventhFall = range(p, 0.78, 0.86);
  const seventhCrack = range(p, 0.86, 0.92);
  const seventhOpen = range(p, 0.88, 0.96);
  const seventhX = 200;
  const seventhY = -60 + easeIn(seventhFall) * 320;
  const seventhRot = seventhFall * 360;

  // Big "&" reveal
  const ampScale = easeOut(seventhOpen);
  const ampOpacity = easeOut(seventhOpen);

  // shell shards flying outward
  const shards = seventhCrack > 0 && seventhCrack < 1 ? [
    { dx: -1, dy: -1, rot: -45 },
    { dx: 1, dy: -1, rot: 45 },
    { dx: -1.2, dy: 0.3, rot: -90 },
    { dx: 1.2, dy: 0.4, rot: 90 },
    { dx: -0.6, dy: 1.3, rot: -160 },
    { dx: 0.7, dy: 1.4, rot: 160 },
  ] : [];

  // Stamp
  const stampScale = easeOut(range(p, 0.93, 1.0));
  const stampRot = -8 + (1 - easeOut(range(p, 0.93, 1.0))) * 30;

  return (
    <svg viewBox="0 0 400 720" preserveAspectRatio="xMidYMax meet" style={{ width:'100%', height:'100%', overflow:'visible' }}>
      <RetroDefs/>

      {/* Falling eggs above basket */}
      {eggs}

      {/* 7th egg — falls then cracks */}
      {seventhFall > 0 && seventhCrack === 0 && (
        <Egg cx={seventhX} cy={seventhY} rot={seventhRot} highlight/>
      )}

      {/* Cracked egg — two halves flying apart */}
      {seventhCrack > 0 && (
        <g opacity={1 - seventhOpen}>
          {shards.map((s, i) => {
            const dist = seventhCrack * 80;
            return (
              <g key={i} transform={`translate(${seventhX + s.dx * dist}, ${320 + s.dy * dist}) rotate(${s.rot * seventhCrack})`}>
                <path d="M -18 -10 L 18 -10 L 22 4 L -22 4 Z" fill="var(--foam)" stroke="var(--ink)" strokeWidth="2.5"/>
                <path d="M -16 -10 Q 0 -22 16 -10" fill="var(--foam)" stroke="var(--ink)" strokeWidth="2.5"/>
              </g>
            );
          })}
        </g>
      )}

      {/* BONUS: giant ampersand bursts out */}
      <g transform={`translate(200, 320) scale(${ampScale * 1.6})`} opacity={ampOpacity}>
        {/* radial burst lines */}
        {[...Array(12)].map((_, i) => {
          const a = (i / 12) * Math.PI * 2;
          const r1 = 80;
          const r2 = 130;
          return <line key={i} x1={Math.cos(a)*r1} y1={Math.sin(a)*r1} x2={Math.cos(a)*r2} y2={Math.sin(a)*r2} stroke="var(--paprika)" strokeWidth="3"/>;
        })}
        {/* yolk halo */}
        <circle cx="0" cy="0" r="78" fill="var(--yolk)" stroke="var(--ink)" strokeWidth="4"/>
        <circle cx="0" cy="0" r="78" fill="url(#dots-dark)" opacity="0.2"/>
        {/* the & */}
        <text x="0" y="38" fontFamily="Fraunces, Georgia, serif" fontWeight="900" fontStyle="italic" fontSize="140" fill="var(--ink)" textAnchor="middle">&amp;</text>
      </g>

      {/* Basket */}
      <g transform={`translate(0, ${basketY})`} opacity={basketOpacity}>
        {/* basket back rim */}
        <ellipse cx="200" cy="430" rx="160" ry="28" fill="#9A6B3D" stroke="var(--ink)" strokeWidth="4"/>
        {/* basket body — woven texture */}
        <path d="M 50 440 Q 50 600 200 620 Q 350 600 350 440 Z" fill="#B8845A" stroke="var(--ink)" strokeWidth="5" strokeLinejoin="round"/>
        {/* horizontal weave bands */}
        {[0, 1, 2, 3, 4].map(i => {
          const y = 460 + i * 28;
          const w = 290 - i * 18;
          return <ellipse key={i} cx="200" cy={y} rx={w/2} ry="6" fill="none" stroke="rgba(26,22,19,0.4)" strokeWidth="2"/>;
        })}
        {/* vertical reeds */}
        {[...Array(11)].map((_, i) => {
          const x = 60 + i * 28;
          return <line key={i} x1={x} y1="445" x2={x + (i-5)*1.5} y2="610" stroke="rgba(26,22,19,0.35)" strokeWidth="2"/>;
        })}
        {/* halftone shading on right */}
        <path d="M 200 440 Q 350 460 350 480 Q 350 600 200 620 Z" fill="url(#dots-dark)" opacity="0.25"/>
        {/* basket lip front */}
        <ellipse cx="200" cy="440" rx="155" ry="18" fill="none" stroke="var(--ink)" strokeWidth="4"/>

        {/* basket label tag */}
        <g transform="translate(305, 575) rotate(-12)">
          <rect x="-30" y="-14" width="60" height="28" fill="var(--foam)" stroke="var(--ink)" strokeWidth="2.5"/>
          <text x="0" y="-2" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="7" fill="var(--ink)" textAnchor="middle" letterSpacing="1">ČERSTVÉ</text>
          <text x="0" y="8" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="7" fill="var(--paprika)" textAnchor="middle" letterSpacing="1">PRAHA</text>
        </g>
      </g>

      {/* Stamp */}
      <g transform={`translate(310, 640) scale(${stampScale}) rotate(${stampRot})`} opacity={stampScale}>
        <circle cx="0" cy="0" r="42" fill="none" stroke="var(--paprika)" strokeWidth="3"/>
        <circle cx="0" cy="0" r="34" fill="none" stroke="var(--paprika)" strokeWidth="1.5"/>
        <text x="0" y="-6" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="9" fill="var(--paprika)" textAnchor="middle" letterSpacing="2">DVĚ</text>
        <text x="0" y="8" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="9" fill="var(--paprika)" textAnchor="middle" letterSpacing="2">VĚCI</text>
        <text x="0" y="22" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="7" fill="var(--paprika)" textAnchor="middle" letterSpacing="1.5">NAVŽDY</text>
      </g>
    </svg>
  );
}

// Egg helper — used by VejceScene
function Egg({ cx, cy, rot = 0, highlight = false }) {
  return (
    <g transform={`translate(${cx}, ${cy}) rotate(${rot})`}>
      <ellipse cx="0" cy="0" rx="28" ry="36" fill="var(--foam)" stroke="var(--ink)" strokeWidth="3"/>
      {/* shading dots on right */}
      <ellipse cx="6" cy="2" rx="22" ry="32" fill="url(#dots-dark)" opacity="0.3"/>
      {/* highlight */}
      <ellipse cx="-8" cy="-12" rx="6" ry="10" fill="rgba(255,255,255,0.7)"/>
      {highlight && <ellipse cx="0" cy="0" rx="32" ry="40" fill="none" stroke="var(--yolk)" strokeWidth="3" strokeDasharray="4 3"/>}
    </g>
  );
}

const easeIn = (t) => t * t;

// ============ INTRO SCROLL CONTAINER ====================================
function IntroScene() {
  const teamCtx = window.usePivoTeam ? window.usePivoTeam() : { team: 'pivo' };
  const team = teamCtx.team || 'pivo';
  const containerRef = useRef(null);
  const [progress, setProgress] = useState(0);

  useEffect(() => {
    const handleScroll = () => {
      const el = containerRef.current;
      if (!el) return;
      const rect = el.getBoundingClientRect();
      const total = el.offsetHeight - window.innerHeight;
      const scrolled = -rect.top;
      const p = clamp(scrolled / total);
      setProgress(p);
    };
    handleScroll();
    window.addEventListener('scroll', handleScroll, { passive: true });
    window.addEventListener('resize', handleScroll);
    return () => {
      window.removeEventListener('scroll', handleScroll);
      window.removeEventListener('resize', handleScroll);
    };
  }, []);

  // 4× viewport scroll height for dramatic pacing
  return (
    <section ref={containerRef} style={isStyles.container}>
      <div style={isStyles.sticky}>
        <div style={isStyles.bg}/>
        <div style={isStyles.scene}>
          <div style={isStyles.sceneInner}>
            {team === 'pivo' ? <PivoScene p={progress}/> : <VejceScene p={progress}/>}
          </div>
        </div>
        {/* HUD: scroll prompt + team title */}
        <div style={isStyles.hud}>
          <div style={isStyles.eyebrow}>★ {team === 'pivo' ? 'TÝM PIVO' : 'TÝM VEJCE'} ★</div>
          <h1 style={isStyles.title}>
            {team === 'pivo' ? <>Studené.<br/>Plzeňské.<br/><em style={isStyles.titleEm}>Ticho.</em></> : <>Měkká.<br/>Máslová.<br/><em style={isStyles.titleEm}>Ráno.</em></>}
          </h1>
        </div>
        {/* scroll hint — fades after first scroll */}
        <div style={{...isStyles.scrollHint, opacity: progress < 0.04 ? 1 : 0}}>
          <div style={isStyles.hintLine}/>
          <div style={isStyles.hintText}>SCROLLUJTE ↓</div>
        </div>
      </div>
    </section>
  );
}

const isStyles = {
  container: { position:'relative', height:'650vh', background:'var(--shell)' },
  sticky: { position:'sticky', top:0, height:'100vh', overflow:'hidden', borderBottom:'6px solid var(--ink)' },
  bg: { position:'absolute', inset:0, background:'var(--team-bg, var(--shell))', transition:'background 600ms ease' },
  scene: { position:'absolute', inset:0, display:'flex', alignItems:'center', justifyContent:'center', padding:'2vh 4vw' },
  sceneInner: { height:'min(86vh, 720px)', aspectRatio:'400 / 720', maxWidth:'92vw', position:'relative' },
  hud: { position:'absolute', top:'7vh', left:'4vw', maxWidth:'40vw', pointerEvents:'none' },
  eyebrow: { fontFamily:'var(--font-mono)', fontSize:13, letterSpacing:'0.24em', color:'var(--paprika)', fontWeight:700, marginBottom:14 },
  title: { fontFamily:'var(--font-display)', fontSize:'clamp(40px, 6.4vw, 88px)', lineHeight:0.92, color:'var(--ink)', letterSpacing:'-0.02em', margin:0 },
  titleEm: { fontFamily:'"Fraunces", serif', fontStyle:'italic', fontWeight:900, color:'var(--team-accent, var(--paprika))' },
  scrollHint: { position:'absolute', bottom:'5vh', left:'50%', transform:'translateX(-50%)', display:'flex', flexDirection:'column', alignItems:'center', gap:10, transition:'opacity 300ms', pointerEvents:'none' },
  hintLine: { width:2, height:40, background:'var(--ink)', animation:'pivoBounce 1.2s ease-in-out infinite' },
  hintText: { fontFamily:'var(--font-mono)', fontSize:11, letterSpacing:'0.22em', color:'var(--ink)', fontWeight:700 },
};

// inject keyframe + responsive tweaks
if (typeof document !== 'undefined' && !document.getElementById('intro-keyframes')) {
  const st = document.createElement('style');
  st.id = 'intro-keyframes';
  st.textContent = `
    @keyframes pivoBounce { 0%, 100% { transform: translateY(0); opacity: 1; } 50% { transform: translateY(8px); opacity: 0.4; } }
    @media (max-width: 720px) {
      .intro-hud { max-width: 80vw !important; }
    }
  `;
  document.head.appendChild(st);
}

Object.assign(window, { IntroScene });
