// scenes.jsx — all scenes for the ForestStore portrait ad.
// Globals available: FS, Sapling, Tree, Receipt, PhoneStorefront, FeatureIcon, Pill,
//   Easing, interpolate, animate, clamp, useTime, useSprite, Sprite.

// ── Scene 1: HOOK ────────────────────────────────────────────────────────────
// "Want your own online store?" — slow, contemplative open.
function SceneHook() {
  const { localTime, progress } = useSprite();

  // Sapling grows from 0 → full over first 2.5s
  const saplingP = clamp(localTime / 2.5, 0, 1);

  // Camera drift: subtle slow scale on the whole frame
  const drift = 1 + 0.04 * Easing.easeOutQuad(progress);

  return (
    <div style={{
      position: 'absolute', inset: 0, background: FS.surface,
      transform: `scale(${drift})`, transformOrigin: 'center',
    }}>
      {/* Soft paper texture vignette */}
      <div style={{
        position: 'absolute', inset: 0,
        background: `radial-gradient(circle at 50% 40%, rgba(252,249,241,0) 0%, rgba(225,220,206,0.45) 100%)`,
        pointerEvents: 'none',
      }} />

      {/* Brand tag */}
      <Sprite start={0.4} end={4}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          return (
            <div style={{
              position: 'absolute', top: 140, left: 0, right: 0,
              display: 'flex', justifyContent: 'center',
              opacity: op,
            }}>
              <div style={{
                padding: '12px 24px',
                borderRadius: 999,
                border: `1.5px solid ${FS.outlineLight}`,
                background: FS.surfaceLow,
                fontFamily: 'Geist Mono, monospace',
                fontSize: 22,
                fontWeight: 600,
                letterSpacing: '0.18em',
                color: FS.primaryMid,
                textTransform: 'uppercase',
              }}>
                Made for Sri Lanka 🇱🇰
              </div>
            </div>
          );
        }}
      </Sprite>

      {/* Sapling growing */}
      <div style={{
        position: 'absolute', top: 280, left: 0, right: 0,
        display: 'flex', justifyContent: 'center',
      }}>
        <Sapling size={360} progress={saplingP} />
      </div>

      {/* Headline */}
      <Sprite start={1.4} end={4}>
        {({ localTime: t }) => {
          const a = Easing.easeOutBack(clamp(t / 0.7, 0, 1));
          return (
            <div style={{
              position: 'absolute', top: 700, left: 0, right: 0,
              padding: '0 80px',
              opacity: clamp(t / 0.4, 0, 1),
              transform: `translateY(${(1 - a) * 30}px)`,
              fontFamily: 'Instrument Serif, serif',
              fontSize: 140,
              lineHeight: 0.95,
              letterSpacing: '-0.025em',
              color: FS.primary,
              textAlign: 'center',
            }}>
              Want your<br/>own online<br/><i style={{ color: FS.secondary }}>store?</i>
            </div>
          );
        }}
      </Sprite>

      {/* Floating commerce stickers around the sapling */}
      <Sprite start={0.8} end={4}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const float = Math.sin(t * 1.4) * 6;
          return (
            <div style={{
              position: 'absolute', left: 60, top: 360,
              transform: `translateY(${(1 - op) * 20 + float}px) rotate(-8deg)`,
              opacity: op,
              background: FS.white,
              border: `1.5px solid ${FS.surfaceDeep}`,
              padding: '14px 20px',
              borderRadius: 16,
              boxShadow: '0 14px 28px rgba(0,38,26,0.10)',
              display: 'flex', alignItems: 'center', gap: 12,
            }}>
              <div style={{ width: 36, height: 36, borderRadius: 10, background: FS.sapling, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                <svg width="22" height="22" viewBox="0 0 24 24" fill="none">
                  <path d="M3 6h2l2 11h11l2-8H7" stroke={FS.primary} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
                  <circle cx="9" cy="20" r="1.5" fill={FS.primary}/>
                  <circle cx="17" cy="20" r="1.5" fill={FS.primary}/>
                </svg>
              </div>
              <div>
                <div style={{ fontFamily: 'Geist Mono, monospace', fontSize: 12, fontWeight: 600, color: FS.outline, letterSpacing: '0.12em' }}>NEW ORDER</div>
                <div style={{ fontFamily: 'Geist, sans-serif', fontSize: 20, fontWeight: 600, color: FS.ink }}>LKR 4,200</div>
              </div>
            </div>
          );
        }}
      </Sprite>

      <Sprite start={1.1} end={4}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const float = Math.sin(t * 1.7 + 1) * 6;
          return (
            <div style={{
              position: 'absolute', right: 50, top: 440,
              transform: `translateY(${(1 - op) * 20 + float}px) rotate(7deg)`,
              opacity: op,
              background: FS.primary,
              padding: '14px 22px',
              borderRadius: 16,
              boxShadow: '0 14px 28px rgba(0,38,26,0.18)',
              color: FS.surface,
              fontFamily: 'Geist, sans-serif',
              fontSize: 22,
              fontWeight: 500,
              display: 'flex', alignItems: 'center', gap: 10,
            }}>
              <span style={{ fontSize: 18, color: FS.sapling }}>★★★★★</span>
              <span>4.9 · 218 reviews</span>
            </div>
          );
        }}
      </Sprite>

      <Sprite start={1.4} end={4}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const float = Math.sin(t * 1.5 + 0.5) * 5;
          return (
            <div style={{
              position: 'absolute', left: 80, top: 1180,
              transform: `translateY(${(1 - op) * 20 + float}px) rotate(-5deg)`,
              opacity: op,
              background: FS.sapling,
              padding: '12px 22px',
              borderRadius: 999,
              fontFamily: 'Geist, sans-serif',
              fontSize: 22,
              fontWeight: 600,
              color: FS.primary,
              boxShadow: '0 12px 24px rgba(163,244,195,0.4)',
            }}>
              # 1,247 stores sold this week
            </div>
          );
        }}
      </Sprite>

      <Sprite start={1.7} end={4}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const float = Math.sin(t * 1.3 + 2) * 6;
          return (
            <div style={{
              position: 'absolute', right: 70, top: 1240,
              transform: `translateY(${(1 - op) * 20 + float}px) rotate(6deg)`,
              opacity: op,
              background: FS.white,
              border: `1.5px solid ${FS.surfaceDeep}`,
              padding: '12px 20px',
              borderRadius: 14,
              fontFamily: 'Geist Mono, monospace',
              fontSize: 18,
              fontWeight: 600,
              color: FS.secondary,
              letterSpacing: '0.06em',
              boxShadow: '0 10px 22px rgba(0,38,26,0.10)',
            }}>
              + LKR 12,450 today
            </div>
          );
        }}
      </Sprite>

      {/* Sub */}
      <Sprite start={2.4} end={4}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          return (
            <div style={{
              position: 'absolute', top: 1500, left: 0, right: 0,
              textAlign: 'center', padding: '0 100px',
              opacity: op,
              fontFamily: 'Geist, sans-serif',
              fontSize: 36,
              fontWeight: 400,
              color: FS.inkSoft,
              lineHeight: 1.3,
            }}>
              You think it's expensive.<br/>It used to be.
            </div>
          );
        }}
      </Sprite>

      {/* Tiny "scroll" hint at bottom */}
      <Sprite start={2.8} end={4}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          const bob = Math.sin(t * 4) * 4;
          return (
            <div style={{
              position: 'absolute', bottom: 100, left: 0, right: 0,
              display: 'flex', flexDirection: 'column', alignItems: 'center',
              opacity: op * 0.7,
              transform: `translateY(${bob}px)`,
              fontFamily: 'Geist Mono, monospace',
              fontSize: 18,
              letterSpacing: '0.2em',
              color: FS.outline,
              textTransform: 'uppercase',
              gap: 12,
            }}>
              <span>Keep watching</span>
              <svg width="22" height="14" viewBox="0 0 22 14" fill="none">
                <path d="M2 2l9 9 9-9" stroke={FS.outline} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
              </svg>
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 2: PROBLEM — costs stacking up ────────────────────────────────────
function SceneProblem() {
  const { localTime } = useSprite();

  // Total counter animates from 0 to 247500 over the scene
  const counterEnd = 247500;
  const counterStart = 1.8;
  const counterEndT = 7.0;
  const cp = clamp((localTime - counterStart) / (counterEndT - counterStart), 0, 1);
  const counterVal = Math.floor(Easing.easeOutCubic(cp) * counterEnd);
  const counterStr = counterVal.toLocaleString('en-US');

  // Shake at the end
  const shakeStart = 7.5;
  const sp = clamp((localTime - shakeStart) / 1.5, 0, 1);
  const shake = sp > 0 ? Math.sin(localTime * 60) * 6 * (1 - sp) : 0;

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: FS.surface,
    }}>
      {/* Title */}
      <Sprite start={0} end={10}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          return (
            <>
              <div style={{
                position: 'absolute', top: 120, left: 0, right: 0,
                textAlign: 'center',
                fontFamily: 'Geist Mono, monospace',
                fontSize: 24,
                fontWeight: 600,
                letterSpacing: '0.18em',
                color: FS.error,
                textTransform: 'uppercase',
                opacity: op,
              }}>
                The Old Way
              </div>
              <div style={{
                position: 'absolute', top: 180, left: 0, right: 0,
                textAlign: 'center', padding: '0 80px',
                fontFamily: 'Instrument Serif, serif',
                fontSize: 96,
                lineHeight: 0.95,
                letterSpacing: '-0.02em',
                color: FS.primary,
                opacity: op,
              }}>
                Costs <i style={{ color: FS.error }}>add up</i>.
              </div>
            </>
          );
        }}
      </Sprite>

      {/* Bills/receipts area — translates left for shake */}
      <div style={{
        position: 'absolute', top: 400, left: 0, right: 0, height: 900,
        transform: `translateX(${shake}px)`,
      }}>
        {/* Receipt 1 — Setup */}
        <Sprite start={0.6} end={10}>
          {({ localTime: t }) => {
            const a = Easing.easeOutBack(clamp(t / 0.5, 0, 1));
            return (
              <div style={{
                position: 'absolute', left: 90, top: 0,
                transform: `rotate(${-6 + (1 - a) * -10}deg) translate(${(1 - a) * -40}px, ${(1 - a) * -40}px)`,
                opacity: clamp(t / 0.3, 0, 1),
                filter: 'drop-shadow(0 18px 36px rgba(0,38,26,0.18))',
              }}>
                <Receipt label="SETUP FEE" subtitle="Custom build, design" amount="LKR 150,000" />
              </div>
            );
          }}
        </Sprite>

        {/* Receipt 2 — Hosting */}
        <Sprite start={1.6} end={10}>
          {({ localTime: t }) => {
            const a = Easing.easeOutBack(clamp(t / 0.5, 0, 1));
            return (
              <div style={{
                position: 'absolute', right: 60, top: 80,
                transform: `rotate(${8 + (1 - a) * 10}deg) translate(${(1 - a) * 40}px, ${(1 - a) * -40}px)`,
                opacity: clamp(t / 0.3, 0, 1),
                filter: 'drop-shadow(0 18px 36px rgba(0,38,26,0.18))',
              }}>
                <Receipt label="HOSTING" subtitle="Per year" amount="LKR 24,000" />
              </div>
            );
          }}
        </Sprite>

        {/* Receipt 3 — Maintenance */}
        <Sprite start={2.6} end={10}>
          {({ localTime: t }) => {
            const a = Easing.easeOutBack(clamp(t / 0.5, 0, 1));
            return (
              <div style={{
                position: 'absolute', left: 60, top: 350,
                transform: `rotate(${4 + (1 - a) * -8}deg) translate(${(1 - a) * -40}px, ${(1 - a) * 40}px)`,
                opacity: clamp(t / 0.3, 0, 1),
                filter: 'drop-shadow(0 18px 36px rgba(0,38,26,0.18))',
              }}>
                <Receipt label="MAINTENANCE" subtitle="Bugs, updates, fixes" amount="LKR 60,000" />
              </div>
            );
          }}
        </Sprite>

        {/* Receipt 4 — Domain & SSL */}
        <Sprite start={3.6} end={10}>
          {({ localTime: t }) => {
            const a = Easing.easeOutBack(clamp(t / 0.5, 0, 1));
            return (
              <div style={{
                position: 'absolute', right: 90, top: 420,
                transform: `rotate(${-7 + (1 - a) * 12}deg) translate(${(1 - a) * 40}px, ${(1 - a) * 40}px)`,
                opacity: clamp(t / 0.3, 0, 1),
                filter: 'drop-shadow(0 18px 36px rgba(0,38,26,0.18))',
              }}>
                <Receipt label="DOMAIN + SSL" subtitle="Yearly renewal" amount="LKR 13,500" />
              </div>
            );
          }}
        </Sprite>
      </div>

      {/* Total counter — bottom */}
      <Sprite start={1.5} end={10}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          return (
            <div style={{
              position: 'absolute', left: 60, right: 60, bottom: 80,
              background: FS.primary,
              borderRadius: 28,
              padding: '32px 40px',
              opacity: op,
              transform: `translateY(${(1 - op) * 40}px)`,
              boxShadow: '0 20px 50px rgba(0,38,26,0.25)',
            }}>
              <div style={{
                fontFamily: 'Geist Mono, monospace',
                fontSize: 20,
                fontWeight: 600,
                letterSpacing: '0.16em',
                color: FS.sapling,
                textTransform: 'uppercase',
                marginBottom: 12,
              }}>
                Year one ▸ total
              </div>
              <div style={{
                fontFamily: 'Instrument Serif, serif',
                fontSize: 130,
                lineHeight: 1,
                color: FS.surface,
                fontVariantNumeric: 'tabular-nums',
                letterSpacing: '-0.02em',
              }}>
                LKR {counterStr}
              </div>
              <div style={{
                fontFamily: 'Geist, sans-serif',
                fontSize: 28,
                color: FS.inverseGreen,
                marginTop: 8,
              }}>
                …and that's just to get started.
              </div>
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 3: TURN — "there's a better way" ───────────────────────────────────
function SceneTurn() {
  const { localTime, duration } = useSprite();

  // 0..1: bills sweep away, then big text appears
  const sweepP = Easing.easeInCubic(clamp(localTime / 0.8, 0, 1));
  const textP = clamp((localTime - 0.6) / 1.0, 0, 1);

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: FS.primary,
    }}>
      {/* Sweeping bills (echo of scene 2) — fly off */}
      {[
        { x: 90, y: 320, rot: -6, label: 'SETUP', amt: 'LKR 150,000', dir: -1 },
        { x: 760, y: 400, rot: 8, label: 'HOSTING', amt: 'LKR 24,000', dir: 1 },
        { x: 60, y: 720, rot: 4, label: 'MAINTENANCE', amt: 'LKR 60,000', dir: -1 },
        { x: 720, y: 800, rot: -7, label: 'DOMAIN', amt: 'LKR 13,500', dir: 1 },
      ].map((b, i) => {
        const off = sweepP * 1400 * b.dir;
        const drop = sweepP * 600;
        const op = 1 - sweepP;
        return (
          <div key={i} style={{
            position: 'absolute', left: b.x, top: b.y,
            transform: `translate(${off}px, ${drop}px) rotate(${b.rot + sweepP * b.dir * 60}deg)`,
            opacity: op,
            filter: 'drop-shadow(0 18px 36px rgba(0,0,0,0.4))',
          }}>
            <Receipt label={b.label} subtitle="" amount={b.amt} />
          </div>
        );
      })}

      {/* Big text */}
      <div style={{
        position: 'absolute', inset: 0,
        display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
        padding: '0 80px',
        textAlign: 'center',
        opacity: textP,
        transform: `scale(${0.92 + 0.08 * textP})`,
      }}>
        <div style={{
          fontFamily: 'Geist Mono, monospace',
          fontSize: 26,
          fontWeight: 600,
          letterSpacing: '0.2em',
          color: FS.sapling,
          textTransform: 'uppercase',
          marginBottom: 32,
        }}>
          There's a better way
        </div>
        <div style={{
          fontFamily: 'Instrument Serif, serif',
          fontSize: 200,
          lineHeight: 0.92,
          letterSpacing: '-0.03em',
          color: FS.surface,
        }}>
          What if<br/>your store<br/><i style={{ color: FS.sapling }}>just grew?</i>
        </div>
      </div>

      {/* Tiny sapling settling at the bottom */}
      <Sprite start={1.8} end={duration}>
        {({ localTime: t }) => {
          const p = clamp(t / 2.0, 0, 1);
          return (
            <div style={{
              position: 'absolute', bottom: 100, left: 0, right: 0,
              display: 'flex', justifyContent: 'center',
              opacity: Math.min(1, t / 0.4),
            }}>
              <Sapling size={220} progress={p} accent={FS.sapling} color={FS.inverseGreen} />
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 4: REVEAL — ForestStore wordmark + storefront ─────────────────────
function SceneReveal() {
  const { localTime } = useSprite();

  // Wordmark drops in 0..0.8
  const wm = Easing.easeOutBack(clamp(localTime / 0.8, 0, 1));
  // Phone fills in 1..6
  const phoneFill = clamp((localTime - 1.2) / 4.0, 0, 1);
  // Camera drift on phone
  const phoneDrift = clamp((localTime - 1.2) / 7, 0, 1);

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: `linear-gradient(180deg, ${FS.surface} 0%, ${FS.surfaceLow} 100%)`,
    }}>
      {/* Wordmark */}
      <div style={{
        position: 'absolute', top: 140, left: 0, right: 0,
        display: 'flex', flexDirection: 'column', alignItems: 'center',
        opacity: clamp(localTime / 0.4, 0, 1),
        transform: `translateY(${(1 - wm) * 40}px)`,
      }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 24,
        }}>
          {/* Mini sapling mark */}
          <div style={{ transform: 'translateY(8px)' }}>
            <Sapling size={120} progress={1} />
          </div>
          <div style={{
            fontFamily: 'Instrument Serif, serif',
            fontSize: 140,
            letterSpacing: '-0.03em',
            color: FS.primary,
            lineHeight: 0.9,
          }}>
            ForestStore
          </div>
        </div>
        <div style={{
          fontFamily: 'Geist, sans-serif',
          fontSize: 36,
          color: FS.inkSoft,
          marginTop: 24,
          fontWeight: 400,
        }}>
          Your store. <i style={{ fontFamily: 'Instrument Serif, serif', color: FS.secondary }}>Already grown.</i>
        </div>
      </div>

      {/* Website storefront */}
      <Sprite start={1.0} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const drift = 1 + 0.02 * Easing.easeOutQuad(phoneDrift);
          return (
            <div style={{
              position: 'absolute', top: 600, left: 0, right: 0,
              display: 'flex', justifyContent: 'center',
              opacity: op,
              transform: `translateY(${(1 - op) * 60}px) scale(${drift})`,
              transformOrigin: 'center top',
              filter: `drop-shadow(0 40px 80px rgba(0,38,26,0.22))`,
            }}>
              <WebsiteStorefront width={760} height={880} fillProgress={phoneFill} />
            </div>
          );
        }}
      </Sprite>

      {/* Floating callout badges — positioned around the browser frame */}
      <Sprite start={3.5} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.5, 0, 1));
          return (
            <div style={{
              position: 'absolute', left: 40, top: 520,
              transform: `translateY(${(1 - op) * 20}px)`,
              opacity: op,
            }}>
              <div style={{
                padding: '14px 22px',
                borderRadius: 999,
                background: FS.primary,
                color: FS.surface,
                fontFamily: 'Geist, sans-serif',
                fontSize: 22,
                fontWeight: 500,
                display: 'inline-flex',
                alignItems: 'center',
                gap: 10,
                boxShadow: '0 12px 30px rgba(0,38,26,0.25)',
              }}>
                <span style={{
                  width: 10, height: 10, borderRadius: 5, background: FS.sapling,
                }} />
                We build it for you
              </div>
            </div>
          );
        }}
      </Sprite>

      <Sprite start={3.9} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.5, 0, 1));
          return (
            <div style={{
              position: 'absolute', right: 40, top: 500,
              transform: `translateY(${(1 - op) * 20}px)`,
              opacity: op,
            }}>
              <div style={{
                padding: '14px 22px',
                borderRadius: 18,
                background: FS.white,
                border: `1.5px solid ${FS.surfaceDeep}`,
                fontFamily: 'Geist, sans-serif',
                fontSize: 22,
                fontWeight: 500,
                color: FS.ink,
                boxShadow: '0 12px 30px rgba(0,38,26,0.10)',
              }}>
                <div style={{ fontFamily: 'Geist Mono, monospace', fontSize: 12, fontWeight: 600, color: FS.outline, letterSpacing: '0.14em', marginBottom: 4 }}>SYNCS WITH</div>
                <div>Daraz · eBay · AliExpress</div>
              </div>
            </div>
          );
        }}
      </Sprite>

      <Sprite start={4.5} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.5, 0, 1));
          return (
            <div style={{
              position: 'absolute', left: 40, top: 1520,
              transform: `translateY(${(1 - op) * 20}px)`,
              opacity: op,
            }}>
              <div style={{
                padding: '14px 22px',
                borderRadius: 18,
                background: FS.primaryMid,
                fontFamily: 'Geist, sans-serif',
                fontSize: 22,
                fontWeight: 500,
                color: FS.surface,
                boxShadow: '0 12px 30px rgba(0,38,26,0.20)',
                display: 'flex', alignItems: 'center', gap: 12,
              }}>
                <FeatureIcon kind="ai" size={26} color={FS.sapling} />
                AI assistant <span style={{ color: FS.sapling }}>built-in</span>
              </div>
            </div>
          );
        }}
      </Sprite>

      <Sprite start={5.1} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.5, 0, 1));
          return (
            <div style={{
              position: 'absolute', right: 40, top: 1530,
              transform: `translateY(${(1 - op) * 20}px)`,
              opacity: op,
            }}>
              <div style={{
                padding: '14px 22px',
                borderRadius: 999,
                background: FS.sapling,
                color: FS.primary,
                fontFamily: 'Geist, sans-serif',
                fontSize: 22,
                fontWeight: 600,
                boxShadow: '0 12px 30px rgba(0,38,26,0.22)',
              }}>
                No code, no setup
              </div>
            </div>
          );
        }}
      </Sprite>

      {/* Bottom row of mini stat chips */}
      <Sprite start={5.6} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.5, 0, 1));
          return (
            <div style={{
              position: 'absolute', bottom: 60, left: 0, right: 0,
              display: 'flex', justifyContent: 'center', gap: 14,
              opacity: op,
              transform: `translateY(${(1 - op) * 16}px)`,
            }}>
              {[
                { k: 'Web', v: '✓' },
                { k: 'iOS', v: '✓' },
                { k: 'Android', v: '✓' },
                { k: 'POS', v: '✓' },
              ].map(s => (
                <div key={s.k} style={{
                  padding: '12px 18px',
                  borderRadius: 14,
                  background: FS.surfaceLow,
                  border: `1.5px solid ${FS.surfaceDeep}`,
                  display: 'flex', alignItems: 'center', gap: 8,
                  fontFamily: 'Geist, sans-serif',
                  fontSize: 20,
                  fontWeight: 500,
                  color: FS.ink,
                }}>
                  <span style={{ color: FS.secondary, fontWeight: 700 }}>{s.v}</span>
                  {s.k}
                </div>
              ))}
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 5: PRICE — LKR 4,500/month ─────────────────────────────────────────
function ScenePrice() {
  const { localTime } = useSprite();

  // Card pops in
  const cardP = Easing.easeOutBack(clamp(localTime / 0.7, 0, 1));
  // Price digits count up 0..4500
  const priceP = clamp((localTime - 0.8) / 1.4, 0, 1);
  const priceVal = Math.floor(Easing.easeOutQuart(priceP) * 4500);
  // Crossed-out items appear
  const lineP = clamp((localTime - 2.6) / 2.5, 0, 1);

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: FS.primary,
      overflow: 'hidden',
    }}>
      {/* Decorative sapling motif top corners */}
      <div style={{ position: 'absolute', top: -30, right: -30, opacity: 0.18, transform: 'rotate(20deg)' }}>
        <Sapling size={320} progress={1} color={FS.sapling} accent={FS.primaryMid} />
      </div>

      {/* Eyebrow */}
      <Sprite start={0} end={10}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          return (
            <div style={{
              position: 'absolute', top: 140, left: 0, right: 0,
              textAlign: 'center',
              opacity: op,
              fontFamily: 'Geist Mono, monospace',
              fontSize: 24,
              fontWeight: 600,
              letterSpacing: '0.2em',
              color: FS.sapling,
              textTransform: 'uppercase',
            }}>
              Starting Package
            </div>
          );
        }}
      </Sprite>

      {/* Main pricing card */}
      <div style={{
        position: 'absolute', top: 220, left: 60, right: 60,
        background: FS.surface,
        borderRadius: 36,
        padding: '64px 56px 56px',
        opacity: clamp(localTime / 0.3, 0, 1),
        transform: `scale(${0.86 + 0.14 * cardP}) translateY(${(1 - cardP) * 60}px)`,
        transformOrigin: 'center top',
        boxShadow: '0 32px 80px rgba(0,0,0,0.32)',
      }}>
        <div style={{
          fontFamily: 'Geist, sans-serif',
          fontSize: 30,
          fontWeight: 500,
          color: FS.inkSoft,
          marginBottom: 8,
        }}>
          Only
        </div>
        <div style={{
          fontFamily: 'Instrument Serif, serif',
          fontSize: 56,
          color: FS.inkSoft,
          lineHeight: 1,
          marginBottom: 4,
        }}>
          LKR
        </div>
        <div style={{
          fontFamily: 'Instrument Serif, serif',
          fontSize: 280,
          lineHeight: 0.9,
          letterSpacing: '-0.04em',
          color: FS.primary,
          fontVariantNumeric: 'tabular-nums',
        }}>
          {priceVal.toLocaleString('en-US')}
        </div>
        <div style={{
          fontFamily: 'Geist, sans-serif',
          fontSize: 36,
          color: FS.inkSoft,
          marginTop: 8,
          marginBottom: 36,
        }}>
          /month. <span style={{ color: FS.secondary, fontWeight: 600 }}>Everything in.</span>
        </div>

        {/* Crossed-out list */}
        <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
          {[
            'No setup fees',
            'No hosting bills',
            'No maintenance contracts',
            'No domain renewals to chase',
          ].map((label, i) => {
            const startT = i * 0.18;
            const lp = clamp((lineP * 4 - startT * 4), 0, 1);
            const op = clamp(lp * 2, 0, 1);
            return (
              <div key={label} style={{
                display: 'flex', alignItems: 'center', gap: 18,
                opacity: op,
                transform: `translateX(${(1 - op) * -20}px)`,
              }}>
                <FeatureIcon kind="check" size={42} />
                <div style={{
                  fontFamily: 'Geist, sans-serif',
                  fontSize: 32,
                  fontWeight: 500,
                  color: FS.ink,
                }}>{label}</div>
              </div>
            );
          })}
        </div>
      </div>

      {/* Comparison strip: Old way vs ForestStore */}
      <Sprite start={4.4} end={10}>
        {({ localTime: t }) => {
          const op = Easing.easeOutCubic(clamp(t / 0.6, 0, 1));
          const a = Easing.easeOutBack(clamp(t / 0.8, 0, 1));
          // Save counter
          const saveP = clamp((t - 1.2) / 1.2, 0, 1);
          const saveVal = Math.floor(Easing.easeOutCubic(saveP) * 193500);
          return (
            <div style={{
              position: 'absolute', left: 60, right: 60, bottom: 220,
              opacity: op,
              transform: `translateY(${(1 - a) * 30}px)`,
            }}>
              <div style={{
                fontFamily: 'Geist Mono, monospace',
                fontSize: 20,
                fontWeight: 600,
                letterSpacing: '0.2em',
                color: FS.inverseGreen,
                textTransform: 'uppercase',
                textAlign: 'center',
                marginBottom: 18,
              }}>
                Side by side · Year 1
              </div>
              <div style={{
                display: 'grid',
                gridTemplateColumns: '1fr auto 1fr',
                gap: 12,
                alignItems: 'stretch',
              }}>
                {/* Old way */}
                <div style={{
                  background: 'rgba(255,255,255,0.06)',
                  border: `1.5px solid rgba(255,255,255,0.16)`,
                  borderRadius: 22,
                  padding: '20px 22px',
                  position: 'relative',
                }}>
                  <div style={{
                    fontFamily: 'Geist Mono, monospace', fontSize: 13, fontWeight: 600,
                    color: FS.error, letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginBottom: 10,
                  }}>The old way</div>
                  <div style={{
                    fontFamily: 'Geist, sans-serif', fontSize: 22, fontWeight: 500,
                    color: 'rgba(252,249,241,0.7)', marginBottom: 2,
                  }}>LKR</div>
                  <div style={{
                    fontFamily: 'Instrument Serif, serif',
                    fontSize: 62,
                    lineHeight: 0.95,
                    color: FS.surface,
                    position: 'relative',
                    display: 'inline-block',
                    fontVariantNumeric: 'tabular-nums',
                  }}>
                    247,500
                    <div style={{
                      position: 'absolute', left: -6, right: -6, top: '52%',
                      height: 5, background: FS.error, borderRadius: 2,
                      transform: 'rotate(-3deg)',
                    }}/>
                  </div>
                  <div style={{
                    fontFamily: 'Geist, sans-serif', fontSize: 18, color: 'rgba(252,249,241,0.55)',
                    marginTop: 8,
                  }}>setup · hosting · upkeep</div>
                </div>
                {/* Arrow */}
                <div style={{
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  padding: '0 2px',
                }}>
                  <svg width="36" height="36" viewBox="0 0 40 40" fill="none">
                    <path d="M8 20h24M22 10l10 10-10 10" stroke={FS.sapling} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"/>
                  </svg>
                </div>
                {/* ForestStore */}
                <div style={{
                  background: FS.sapling,
                  borderRadius: 22,
                  padding: '20px 22px',
                  boxShadow: '0 16px 32px rgba(163,244,195,0.18)',
                }}>
                  <div style={{
                    fontFamily: 'Geist Mono, monospace', fontSize: 13, fontWeight: 700,
                    color: FS.primary, letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginBottom: 10,
                  }}>ForestStore</div>
                  <div style={{
                    fontFamily: 'Geist, sans-serif', fontSize: 22, fontWeight: 500,
                    color: FS.primaryMid, marginBottom: 2,
                  }}>LKR</div>
                  <div style={{
                    fontFamily: 'Instrument Serif, serif',
                    fontSize: 62,
                    lineHeight: 0.95,
                    color: FS.primary,
                    fontVariantNumeric: 'tabular-nums',
                  }}>
                    54,000
                  </div>
                  <div style={{
                    fontFamily: 'Geist, sans-serif', fontSize: 18, color: FS.primaryMid,
                    marginTop: 8, fontWeight: 500,
                  }}>4,500 × 12 · all in</div>
                </div>
              </div>

              {/* SAVE banner */}
              <div style={{
                marginTop: 14,
                background: FS.secondary,
                borderRadius: 22,
                padding: '18px 26px',
                display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12,
                flexWrap: 'nowrap',
              }}>
                <div style={{
                  fontFamily: 'Geist Mono, monospace',
                  fontSize: 16,
                  fontWeight: 700,
                  color: FS.sapling,
                  letterSpacing: '0.18em',
                  textTransform: 'uppercase',
                  whiteSpace: 'nowrap',
                }}>
                  You save
                </div>
                <div style={{
                  fontFamily: 'Instrument Serif, serif',
                  fontSize: 56,
                  lineHeight: 1,
                  color: FS.surface,
                  fontVariantNumeric: 'tabular-nums',
                  whiteSpace: 'nowrap',
                }}>
                  LKR {saveVal.toLocaleString('en-US')}
                </div>
              </div>
            </div>
          );
        }}
      </Sprite>

      {/* Footnote */}
      <Sprite start={5.0} end={10}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          return (
            <div style={{
              position: 'absolute', bottom: 70, left: 0, right: 0,
              textAlign: 'center', padding: '0 80px',
              opacity: op,
              fontFamily: 'Geist, sans-serif',
              fontSize: 28,
              color: FS.inverseGreen,
              lineHeight: 1.35,
            }}>
              One subscription. <span style={{ color: FS.sapling, fontWeight: 600 }}>Everything you need.</span>
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 6: FEATURES — cards rapid-fire ────────────────────────────────────
function SceneFeatures() {
  const { localTime, duration } = useSprite();

  const features = [
    { kind: 'admin',       label: 'Admin Panel',         note: 'One dashboard' },
    { kind: 'courier',     label: 'Courier & Stock',     note: 'Auto dispatch · live sync' },
    { kind: 'marketplace', label: 'Daraz · eBay',        note: 'Sync orders' },
    { kind: 'ai',          label: 'AI Assistant',        note: 'Answers customers' },
    { kind: 'seo',         label: 'Built-in SEO',        note: 'Found on Google' },
    { kind: 'email',       label: 'Email Marketing',     note: 'Win them back' },
    { kind: 'web',         label: 'Your Website',        note: 'Yours, your domain' },
    { kind: 'support',     label: '24/7 Support',        note: 'We have your back' },
  ];

  // Tree grows over the scene
  const treeP = clamp(localTime / 6, 0, 1);

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: FS.surface,
    }}>
      {/* Background tree */}
      <div style={{
        position: 'absolute', right: -120, bottom: -60,
        opacity: 0.16,
      }}>
        <Tree size={1100} progress={treeP} />
      </div>

      {/* Title */}
      <Sprite start={0} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          return (
            <>
              <div style={{
                position: 'absolute', top: 140, left: 0, right: 0,
                textAlign: 'center',
                fontFamily: 'Geist Mono, monospace',
                fontSize: 24,
                fontWeight: 600,
                letterSpacing: '0.2em',
                color: FS.secondary,
                textTransform: 'uppercase',
                opacity: op,
              }}>
                What's included
              </div>
              <div style={{
                position: 'absolute', top: 190, left: 0, right: 0,
                textAlign: 'center', padding: '0 80px',
                fontFamily: 'Instrument Serif, serif',
                fontSize: 96,
                lineHeight: 0.95,
                letterSpacing: '-0.02em',
                color: FS.primary,
                opacity: op,
              }}>
                Everything you'd<br/><i style={{ color: FS.secondary }}>normally pay extra for.</i>
              </div>
            </>
          );
        }}
      </Sprite>

      {/* Feature cards — 2 columns × 4 rows */}
      <div style={{
        position: 'absolute', top: 480, left: 50, right: 50,
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 24,
      }}>
        {features.map((f, i) => {
          const startT = 0.7 + i * 0.35;
          return (
            <Sprite key={f.kind} start={startT} end={duration}>
              {({ localTime: t }) => {
                const a = Easing.easeOutBack(clamp(t / 0.55, 0, 1));
                const op = clamp(t / 0.3, 0, 1);
                return (
                  <div style={{
                    background: FS.white,
                    border: `1.5px solid ${FS.surfaceDeep}`,
                    borderRadius: 22,
                    padding: '28px 28px 30px',
                    minHeight: 230,
                    opacity: op,
                    transform: `scale(${0.86 + 0.14 * a}) translateY(${(1 - a) * 20}px)`,
                    transformOrigin: 'center',
                    boxShadow: '0 12px 28px rgba(0,38,26,0.06)',
                    display: 'flex',
                    flexDirection: 'column',
                    justifyContent: 'space-between',
                  }}>
                    <div style={{
                      width: 64, height: 64,
                      borderRadius: 16,
                      background: FS.surfaceLow,
                      display: 'flex', alignItems: 'center', justifyContent: 'center',
                      marginBottom: 18,
                    }}>
                      <FeatureIcon kind={f.kind} size={36} />
                    </div>
                    <div>
                      <div style={{
                        fontFamily: 'Geist, sans-serif',
                        fontSize: 28,
                        fontWeight: 600,
                        color: FS.ink,
                        lineHeight: 1.1,
                        letterSpacing: '-0.01em',
                      }}>{f.label}</div>
                      <div style={{
                        fontFamily: 'Geist, sans-serif',
                        fontSize: 20,
                        fontWeight: 400,
                        color: FS.inkSoft,
                        marginTop: 6,
                      }}>{f.note}</div>
                    </div>
                  </div>
                );
              }}
            </Sprite>
          );
        })}
      </div>

      {/* Tag at bottom */}
      <Sprite start={5.0} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          return (
            <div style={{
              position: 'absolute', bottom: 50, left: 0, right: 0,
              display: 'flex', justifyContent: 'center',
              opacity: op,
            }}>
              <div style={{
                padding: '16px 28px',
                borderRadius: 999,
                background: FS.primary,
                color: FS.surface,
                fontFamily: 'Geist, sans-serif',
                fontSize: 26,
                fontWeight: 500,
              }}>
                + much more, all in one place
              </div>
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

// ── Scene 7: CTA ─────────────────────────────────────────────────────────────
function SceneCTA() {
  const { localTime, duration } = useSprite();

  // Big sapling that fills with confidence
  const saplingP = clamp(localTime / 1.8, 0, 1);
  // pulsing CTA
  const pulse = 1 + 0.04 * Math.sin(localTime * 4);

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: FS.primary,
    }}>
      {/* Feature recap chips */}
      <Sprite start={0.2} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          return (
            <div style={{
              position: 'absolute', top: 100, left: 0, right: 0,
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 14,
              opacity: op,
              transform: `translateY(${(1 - op) * 16}px)`,
            }}>
              <div style={{
                fontFamily: 'Geist Mono, monospace',
                fontSize: 20,
                fontWeight: 600,
                letterSpacing: '0.18em',
                color: FS.sapling,
                textTransform: 'uppercase',
                whiteSpace: 'nowrap',
              }}>
                All this · from LKR 4,500/mo
              </div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 10, justifyContent: 'center', maxWidth: 980, padding: '0 40px' }}>
                {['Admin Panel', 'AI Assistant', 'Daraz Sync', 'eBay · AliExpress', 'SEO', 'Email Marketing', 'Your Website', '24/7 Support'].map(label => (
                  <div key={label} style={{
                    padding: '10px 18px',
                    borderRadius: 999,
                    background: 'rgba(252,249,241,0.08)',
                    border: '1.5px solid rgba(252,249,241,0.18)',
                    fontFamily: 'Geist, sans-serif',
                    fontSize: 20,
                    fontWeight: 500,
                    color: FS.surface,
                    whiteSpace: 'nowrap',
                  }}>{label}</div>
                ))}
              </div>
            </div>
          );
        }}
      </Sprite>

      {/* Big sapling backdrop */}
      <div style={{
        position: 'absolute', top: 380, left: 0, right: 0,
        display: 'flex', justifyContent: 'center',
        opacity: clamp(localTime / 0.3, 0, 1),
      }}>
        <Sapling size={420} progress={saplingP} color={FS.inverseGreen} accent={FS.sapling} />
      </div>

      {/* Headline */}
      <Sprite start={0.4} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          const a = Easing.easeOutBack(clamp(t / 0.7, 0, 1));
          return (
            <div style={{
              position: 'absolute', top: 820, left: 0, right: 0,
              textAlign: 'center', padding: '0 80px',
              opacity: op,
              transform: `translateY(${(1 - a) * 40}px)`,
              fontFamily: 'Instrument Serif, serif',
              fontSize: 150,
              lineHeight: 0.92,
              letterSpacing: '-0.025em',
              color: FS.surface,
            }}>
              Start <i style={{ color: FS.sapling }}>growing</i><br/>today.
            </div>
          );
        }}
      </Sprite>

      {/* CTA button */}
      <Sprite start={1.4} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.4, 0, 1);
          const a = Easing.easeOutBack(clamp(t / 0.6, 0, 1));
          return (
            <div style={{
              position: 'absolute', top: 1330, left: 0, right: 0,
              display: 'flex', justifyContent: 'center',
              opacity: op,
              transform: `scale(${(0.8 + 0.2 * a) * pulse})`,
            }}>
              <div
                onClick={() => {
                  const msg = encodeURIComponent("Hi ForestStore! I'd like to get my own online store. Please get me started.");
                  window.open(`https://wa.me/94704260300?text=${msg}`, '_blank');
                }}
                style={{
                  padding: '30px 56px',
                  borderRadius: 999,
                  background: FS.sapling,
                  color: FS.primary,
                  fontFamily: 'Geist, sans-serif',
                  fontSize: 40,
                  fontWeight: 600,
                  letterSpacing: '-0.01em',
                  boxShadow: '0 20px 40px rgba(163,244,195,0.35)',
                  display: 'inline-flex', alignItems: 'center', gap: 16,
                  whiteSpace: 'nowrap',
                  cursor: 'pointer',
                }}>
                {/* WhatsApp icon */}
                <svg width="38" height="38" viewBox="0 0 38 38" fill="none">
                  <circle cx="19" cy="19" r="18" fill={FS.primary}/>
                  <path d="M27.5 10.5A11.5 11.5 0 0 0 8 19.4c0 2 .5 4 1.5 5.7L8 30l5.1-1.3a11.5 11.5 0 0 0 15.9-10.3c0-3.1-1.2-6-3.5-8.2v.3zM19 28.5a9.6 9.6 0 0 1-4.9-1.3l-.3-.2-3 .8.8-2.9-.2-.3A9.5 9.5 0 1 1 19 28.5zm5.2-7.1c-.3-.1-1.7-.8-1.9-.9s-.4-.1-.6.1l-.8 1c-.1.2-.3.2-.5.1a7.5 7.5 0 0 1-2.2-1.4 8.3 8.3 0 0 1-1.5-2c-.2-.3 0-.4.1-.6l.4-.5.3-.5v-.5l-.9-2.1c-.2-.5-.5-.4-.6-.4h-.5a1 1 0 0 0-.7.3 3 3 0 0 0-.9 2.2 5.2 5.2 0 0 0 1.1 2.8 11.8 11.8 0 0 0 4.5 4c.6.3 1.1.4 1.5.3.5-.1 1.5-.6 1.7-1.2s.2-1.1.1-1.2l-.6-.2z" fill={FS.sapling}/>
                </svg>
                Chat to Get Started
              </div>
            </div>
          );
        }}
      </Sprite>

      {/* URL + price line */}
      <Sprite start={2.0} end={duration}>
        {({ localTime: t }) => {
          const op = clamp(t / 0.5, 0, 1);
          return (
            <div style={{
              position: 'absolute', bottom: 140, left: 0, right: 0,
              textAlign: 'center', padding: '0 60px',
              opacity: op,
            }}>
              <div style={{
                fontFamily: 'Geist Mono, monospace',
                fontSize: 36,
                fontWeight: 600,
                color: FS.sapling,
                letterSpacing: '-0.01em',
                marginBottom: 12,
              }}>
                foreststore.co
              </div>
              <div style={{
                fontFamily: 'Geist, sans-serif',
                fontSize: 24,
                color: FS.inverseGreen,
                fontWeight: 400,
              }}>
                from LKR 4,500 / month
              </div>
            </div>
          );
        }}
      </Sprite>
    </div>
  );
}

Object.assign(window, {
  SceneHook, SceneProblem, SceneTurn, SceneReveal, ScenePrice, SceneFeatures, SceneCTA,
});
