// scenes.jsx — X3EDGE-N solar data flow animation
// Total runtime: 58 seconds, 1920x1080

const STAGE_W = 1920;
const STAGE_H = 1080;
const e = Easing;

// Scene timing (start → end)
const T = {
  s1: [0, 8.0],          // 1 · Hook — solar at every scale (sunrise→sunset)
  s2: [7.8, 13.5],       // 2a · Configure on-site (BLE pair) — phase A of merged "solution+commission"
  s3: [13.3, 21.0],      // 2b · One device, 32 assets (daisy chain) — phase B
  s6: [20.8, 29.0],      // 3 · Edge AI funnel — drastically lower cloud spend
  s5: [28.8, 36.0],      // 4 · Connectivity — Wi-Fi + 4G failover
  s7: [35.8, 44.0],      // 5 · SynergyOT — API or platform
  s9: [43.8, 53.0],      // 6 · CTA — kW → multi-MW
  s8: [-1, -0.5],        // retired (Problem) — hidden
  s4: [-1, -0.5],        // retired (MQTT code) — hidden
};

// Caption helper to keep typography consistent
function Caption({ step, title, accent, sub, color, opacity, x = 120, y = 100, maxWidth = 900, subMaxWidth = 780 }) {
  return (
    <div style={{
      position: 'absolute', left: x, top: y,
      opacity, maxWidth,
      transform: `translateY(${(1-opacity)*10}px)`,
    }}>
      {step && <Pill x={0} y={0} text={step} color={color}/>}
      <div style={{
        marginTop: step ? 50 : 0,
        fontFamily: sansFont, fontSize: 60, fontWeight: 700,
        color: X3.text, letterSpacing: '-0.022em', lineHeight: 1.02,
      }}>
        {title}{accent && <><br/><span style={{ color }}>{accent}</span></>}
      </div>
      {sub && (
        <div style={{
          marginTop: 22, maxWidth: subMaxWidth,
          fontFamily: sansFont, fontSize: 18, lineHeight: 1.5,
          color: X3.textDim,
        }}>{sub}</div>
      )}
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 1 — Real solar installation (residential + commercial)
// ───────────────────────────────────────────────────────────────────
function Scene1() {
  return (
    <Sprite start={T.s1[0]} end={T.s1[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        // Slow camera pan from residential (left) to commercial (right)
        const camX = animate({ from: 40, to: -260, start: 0, end: duration })(lt);
        // Sun arcs from sunrise (low-left) to sunset (low-right)
        // Progress 0..1 across the scene
        const p = clamp(lt / duration, 0, 1);
        // Horizontal: 200 (left horizon) → 1900 (right horizon)
        const sunX = 200 + p * 1700;
        // Vertical arc: parabola, peak at p=0.5 → top=80, edges → top=560 (just above horizon)
        // y = bottom - 4*(bottom-top)*p*(1-p)
        const sunY = 560 - 4 * (560 - 80) * p * (1 - p);
        // Color temperature shift: warm-cool-warm
        // 0..0.15: sunrise pink/orange
        // 0.15..0.4: morning warm
        // 0.4..0.6: midday golden
        // 0.6..0.85: afternoon amber
        // 0.85..1: sunset red/violet
        // Build sky gradient by interpolating control colors
        let skyGrad;
        if (p < 0.15) {
          // Sunrise: deep violet top, magenta/pink mid, orange horizon
          skyGrad = 'linear-gradient(180deg, #1a1438 0%, #3a2050 14%, #7a3858 32%, #c46050 50%, #e88a4a 65%, #b86838 78%, #2a1810 92%, #0a0606 100%)';
        } else if (p < 0.4) {
          // Morning: warm but lighter, less pink
          skyGrad = 'linear-gradient(180deg, #1c2050 0%, #3a4072 18%, #8a7060 38%, #d99a5a 55%, #ecb868 68%, #c98a48 78%, #2a1c12 92%, #0a0808 100%)';
        } else if (p < 0.6) {
          // Midday golden hour: highest sun, brightest, warmest
          skyGrad = 'linear-gradient(180deg, #2a3870 0%, #4860a0 18%, #a89080 35%, #f0c878 55%, #ffe4a0 65%, #d8a060 78%, #2c1e14 92%, #0a0808 100%)';
        } else if (p < 0.85) {
          // Afternoon → sunset: warmer amber, mid-sky deepening
          skyGrad = 'linear-gradient(180deg, #1f1a40 0%, #4a2c50 18%, #9a4838 38%, #e8783a 55%, #f09848 68%, #b85838 78%, #2a1410 92%, #0a0606 100%)';
        } else {
          // Sunset: deep dusk — much darker, less red, more indigo/charcoal
          skyGrad = 'linear-gradient(180deg, #050414 0%, #0e0a24 16%, #1c142e 34%, #3a2030 50%, #5a2820 62%, #2a1410 76%, #0a0606 90%, #030202 100%)';
        }
        // Lighting tint over scene (warm at sunrise/sunset, neutral midday)
        const tintOpacity = p < 0.15 ? 0.35 : p > 0.85 ? 0.55 : 0.0;
        const tintColor = p < 0.5 ? 'rgba(255,150,90,1)' : 'rgba(20,15,30,1)';

        return (
          <div style={{
            position: 'absolute', inset: 0,
            opacity: op,
            overflow: 'hidden',
            background: '#000',
          }}>
            {/* Sunrise/sunset sky — color shifts across the scene */}
            <div style={{
              position: 'absolute', inset: 0,
              background: skyGrad,
              transition: 'background 0.4s linear',
            }}/>

            {/* Warm/cool tint overlay during sunrise/sunset */}
            {tintOpacity > 0 && (
              <div style={{
                position: 'absolute', inset: 0,
                background: tintColor,
                opacity: tintOpacity,
                mixBlendMode: 'soft-light',
                pointerEvents: 'none',
              }}/>
            )}

            {/* Sun (positioned by arc) */}
            <div style={{
              position: 'absolute', left: sunX, top: sunY,
              width: 90, height: 90, borderRadius: 45,
              background: p < 0.15
                ? 'radial-gradient(circle, #ffe0a8 0%, #ff9e58 50%, #d04830 95%)'
                : p > 0.85
                ? 'radial-gradient(circle, #f0a878 0%, #b04830 55%, #4a1810 95%)'
                : 'radial-gradient(circle, #fffce0 0%, #ffd76a 40%, #ff8a2a 90%)',
              boxShadow: '0 0 160px 80px rgba(255,180,80,0.55), 0 0 60px 30px rgba(255,220,140,0.7)',
            }}/>

            {/* Volumetric sun glow — anchored to sun position */}
            <div style={{
              position: 'absolute', left: sunX - 200, top: sunY - 220,
              width: 600, height: 600,
              background: 'radial-gradient(circle at 50% 50%, rgba(255,200,120,0.35) 0%, transparent 60%)',
              filter: 'blur(20px)',
              pointerEvents: 'none',
            }}/>

            {/* Lens flare ghost orbs */}
            <div style={{
              position: 'absolute', left: sunX - 380, top: 520,
              width: 60, height: 60, borderRadius: 30,
              background: 'radial-gradient(circle, rgba(255,200,120,0.25) 0%, transparent 70%)',
              filter: 'blur(8px)',
            }}/>
            <div style={{
              position: 'absolute', left: sunX - 700, top: 700,
              width: 100, height: 100, borderRadius: 50,
              background: 'radial-gradient(circle, rgba(255,140,80,0.18) 0%, transparent 70%)',
              filter: 'blur(12px)',
            }}/>

            {/* Distant mountain silhouettes — multiple layers for depth */}
            <svg style={{ position: 'absolute', left: 0, top: 560, width: '100%', height: 140 }} viewBox="0 0 2200 140" preserveAspectRatio="none">
              <path d="M0 140 L0 90 L240 30 L420 80 L640 20 L880 90 L1120 40 L1380 85 L1620 50 L1880 75 L2200 90 L2200 140 Z"
                fill="#1a0e1a" opacity="0.5"/>
            </svg>
            <svg style={{ position: 'absolute', left: 0, top: 640, width: '100%', height: 120 }} viewBox="0 0 2200 120" preserveAspectRatio="none">
              <path d="M0 120 L0 70 L180 20 L360 60 L580 30 L820 70 L1080 25 L1340 65 L1600 35 L1900 55 L2200 70 L2200 120 Z"
                fill="#0d0610" opacity="0.85"/>
            </svg>

            {/* Ground haze */}
            <div style={{
              position: 'absolute', left: 0, right: 0, top: 700,
              height: 100,
              background: 'linear-gradient(180deg, rgba(255,140,80,0.15) 0%, transparent 100%)',
              filter: 'blur(20px)',
              pointerEvents: 'none',
            }}/>

            <div style={{ position: 'absolute', inset: 0, transform: `translateX(${camX}px)` }}>

              {/* RESIDENTIAL: house with rooftop panels */}
              <div style={{ position: 'absolute', left: 60, top: 540, width: 440 }}>
                <House/>
                <div style={{
                  position: 'absolute', left: 0, right: 0, top: 332,
                  margin: '0 auto',
                  width: 'fit-content',
                  fontFamily: monoFont, fontSize: 16, color: X3.amber,
                  letterSpacing: '0.22em', textTransform: 'uppercase',
                  background: 'rgba(0,0,0,0.7)',
                  padding: '8px 18px', borderRadius: 4,
                  border: `1px solid ${X3.amber}88`,
                  fontWeight: 600,
                  textAlign: 'center',
                  whiteSpace: 'nowrap',
                  boxShadow: `0 0 16px ${X3.amber}33`,
                }}>Residential · 8 kW</div>
              </div>

              {/* COMMERCIAL: multi-story building with rooftop solar */}
              <div style={{ position: 'absolute', left: 600, top: 540, width: 460 }}>
                <CommercialBuilding/>
                <div style={{
                  position: 'absolute', left: 0, right: 0, top: 332,
                  margin: '0 auto',
                  width: 'fit-content',
                  fontFamily: monoFont, fontSize: 16, color: X3.amber,
                  letterSpacing: '0.22em', textTransform: 'uppercase',
                  background: 'rgba(0,0,0,0.7)',
                  padding: '8px 18px', borderRadius: 4,
                  border: `1px solid ${X3.amber}88`,
                  fontWeight: 600,
                  textAlign: 'center',
                  whiteSpace: 'nowrap',
                  boxShadow: `0 0 16px ${X3.amber}33`,
                }}>Commercial · 300 kW</div>
              </div>

              {/* Utility-scale solar farm — contained front-facing panel array */}
              <div style={{ position: 'absolute', left: 1180, top: 540, width: 840 }}>
                <SolarFarm/>
                <div style={{
                  position: 'absolute', left: 0, right: 0, top: 352,
                  margin: '0 auto',
                  width: 'fit-content',
                  fontFamily: monoFont, fontSize: 18, color: X3.amber,
                  letterSpacing: '0.22em', textTransform: 'uppercase',
                  background: 'rgba(0,0,0,0.7)',
                  padding: '10px 22px', borderRadius: 4,
                  border: `1px solid ${X3.amber}88`,
                  fontWeight: 600,
                  textAlign: 'center',
                  whiteSpace: 'nowrap',
                  boxShadow: `0 0 20px ${X3.amber}44`,
                }}>Utility-scale · 2.4 MW</div>
              </div>

              {/* Foreground silhouettes — long grass / scrub for depth */}
              <svg style={{ position: 'absolute', left: -200, bottom: 0, width: 'calc(100% + 400px)', height: 160 }} viewBox="0 0 2600 160" preserveAspectRatio="none">
                <path d="M0 160 L0 100 Q200 60 380 90 Q540 70 720 110 Q920 80 1120 100 Q1320 70 1540 110 Q1760 90 1980 105 Q2200 80 2400 100 L2600 110 L2600 160 Z"
                  fill="#050505"/>
              </svg>

              {/* Vignette ground gradient */}
              <div style={{
                position: 'absolute', left: -200, right: -200, bottom: 0,
                height: 280,
                background: 'linear-gradient(180deg, rgba(8,8,12,0) 0%, rgba(8,8,12,0.85) 70%, #050505 100%)',
              }}/>
            </div>

            {/* Cinematic vignette */}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.55) 100%)',
              pointerEvents: 'none',
            }}/>

            {/* Title overlay */}
            <Sprite start={0.4} end={duration - 0.4}>
              {({ localTime: lt2, duration: d2 }) => {
                const titleT = e.easeOutCubic(clamp(lt2 / 0.7, 0, 1));
                const fadeOut = lt2 > d2 - 0.5 ? (lt2 - (d2 - 0.5)) / 0.5 : 0;
                const op2 = titleT * (1 - fadeOut);
                return (
                  <div style={{
                    position: 'absolute',
                    left: 120, top: 130,
                    opacity: op2,
                    transform: `translateY(${(1-titleT)*12}px)`,
                  }}>
                    <Pill x={0} y={0} text="EVERY SOLAR ASSET, CONNECTED" color={X3.amber}/>
                    <div style={{
                      marginTop: 56,
                      fontFamily: sansFont, fontSize: 96, fontWeight: 700,
                      color: X3.text, letterSpacing: '-0.025em', lineHeight: 0.95,
                      textShadow: '0 4px 32px rgba(0,0,0,0.7), 0 2px 8px rgba(0,0,0,0.5)',
                    }}>
                      From rooftop<br/>
                      to <span style={{ color: X3.amber }}>utility-scale.</span>
                    </div>
                    <div style={{
                      marginTop: 24,
                      fontFamily: monoFont, fontSize: 14,
                      color: X3.text, letterSpacing: '0.18em',
                      textTransform: 'uppercase',
                      textShadow: '0 2px 8px rgba(0,0,0,0.7)',
                    }}>
                      X3EDGE-N · The path from inverter to cloud
                    </div>
                  </div>
                );
              }}
            </Sprite>
          </div>
        );
      }}
    </Sprite>
  );
}

function House() {
  // Realistic suburban home: gabled roof seen from front-3/4, with a tightly
  // packed solar array on the sunlit right slope. Two rows of full-size panels
  // with visible cell grid + busbars + sunset glint.
  return (
    <div style={{ position: 'relative', width: 440, height: 320 }}>
      <svg width="440" height="320" viewBox="0 0 440 320" style={{ position: 'absolute', inset: 0 }}>
        <defs>
          <linearGradient id="hWall" x1="0" y1="0" x2="1" y2="0">
            <stop offset="0%" stopColor="#3a2a1c"/>
            <stop offset="100%" stopColor="#8a5638"/>
          </linearGradient>
          <linearGradient id="hRoofR" x1="0" y1="0" x2="1" y2="0.6">
            <stop offset="0%" stopColor="#2a1c12"/>
            <stop offset="100%" stopColor="#5a3a22"/>
          </linearGradient>
          <linearGradient id="hRoofL" x1="0" y1="0" x2="1" y2="0">
            <stop offset="0%" stopColor="#4a3220"/>
            <stop offset="100%" stopColor="#1a1108"/>
          </linearGradient>
          {/* Realistic mono-Si panel: dark blue with cell grid, busbars, sunset glint */}
          <linearGradient id="hCell" x1="0" y1="0" x2="0.6" y2="1">
            <stop offset="0%" stopColor="#1f3a66"/>
            <stop offset="55%" stopColor="#142a4e"/>
            <stop offset="100%" stopColor="#0a1830"/>
          </linearGradient>
          <pattern id="hCellGrid" patternUnits="userSpaceOnUse" width="11" height="11">
            <rect width="11" height="11" fill="url(#hCell)"/>
            <rect x="0.5" y="0.5" width="10" height="10" fill="none" stroke="#0a1428" strokeWidth="0.5"/>
            <line x1="5.5" y1="0" x2="5.5" y2="11" stroke="#9eb6d8" strokeWidth="0.25" opacity="0.5"/>
          </pattern>
          <linearGradient id="hGlint" x1="0" y1="0" x2="1" y2="1">
            <stop offset="55%" stopColor="rgba(255,210,140,0)"/>
            <stop offset="74%" stopColor="rgba(255,220,160,0.45)"/>
            <stop offset="92%" stopColor="rgba(255,210,140,0)"/>
          </linearGradient>
          {/* Clip the panel array to the left (front-facing) roof triangle */}
          <clipPath id="hLeftRoofClip">
            <polygon points="50,150 215,55 215,150"/>
          </clipPath>
          {/* Clip the panel array to the right roof triangle */}
          <clipPath id="hRightRoofClip">
            <polygon points="215,55 370,150 215,150"/>
          </clipPath>
        </defs>

        {/* Walls */}
        <polygon points="70,150 350,150 350,300 70,300" fill="url(#hWall)" stroke="#1a1410" strokeWidth="1"/>
        {/* Roof — left slope (shadowed) */}
        <polygon points="50,150 215,55 215,150" fill="url(#hRoofL)" stroke="#0a0604" strokeWidth="1"/>
        {/* Roof — right slope (sunlit, hosts panels) */}
        <polygon points="215,55 370,150 215,150" fill="url(#hRoofR)" stroke="#0a0604" strokeWidth="1"/>
        {/* Eave shadow line */}
        <line x1="70" y1="150" x2="350" y2="150" stroke="#000" strokeWidth="1.5" opacity="0.7"/>

        {/* Door */}
        <rect x="190" y="220" width="50" height="80" fill="#0a0604"/>
        <rect x="194" y="224" width="42" height="72" fill="none" stroke="#1a1108" strokeWidth="1"/>
        <circle cx="232" cy="262" r="1.4" fill="#c98a4a"/>
        {/* Windows — warm interior glow with frame */}
        <rect x="98" y="180" width="48" height="40" fill="#e6a04a" opacity="0.88"/>
        <rect x="98" y="180" width="48" height="40" fill="none" stroke="#0a0604" strokeWidth="1.5"/>
        <line x1="122" y1="180" x2="122" y2="220" stroke="#0a0604" strokeWidth="1"/>
        <line x1="98" y1="200" x2="146" y2="200" stroke="#0a0604" strokeWidth="0.8"/>
        <rect x="270" y="180" width="48" height="40" fill="#e6a04a" opacity="0.88"/>
        <rect x="270" y="180" width="48" height="40" fill="none" stroke="#0a0604" strokeWidth="1.5"/>
        <line x1="294" y1="180" x2="294" y2="220" stroke="#0a0604" strokeWidth="1"/>
        <line x1="270" y1="200" x2="318" y2="200" stroke="#0a0604" strokeWidth="0.8"/>

        {/* Chimney behind ridge */}
        <rect x="280" y="60" width="22" height="56" fill="#2a1c10" stroke="#0a0604" strokeWidth="1"/>
        <rect x="278" y="56" width="26" height="6" fill="#1a1208"/>

        {/* Front-facing (left) roof slope is fully solar-paneled.
            Triangle: ridge-top (215,55), eave-left (50,150), ridge-base (215,150).
            Down-slope axis: ridge-top → eave-left = (-165, 95)
            Along-ridge axis: ridge-top → ridge-base = (0, 95)
            Panels are laid in this basis and clipped to the triangle. */}
        {(() => {
          const O = { x: 215, y: 55 };          // ridge-top apex
          const uStep = { x: -10.5, y: 6.05 };  // down-slope per unit (toward eave)
          const vStep = { x: 0, y: 9.5 };       // along-ridge per unit (downward at ridge line)
          const cols = 4, rows = 4;             // 4×4 panel grid covers the slope
          const panelU = 3.6, panelV = 2.2;
          const gapU = 0.25, gapV = 0.25;
          const project = (u, v) => ({
            x: O.x + u * uStep.x + v * vStep.x,
            y: O.y + u * uStep.y + v * vStep.y,
          });
          const panels = [];
          for (let r = 0; r < rows; r++) {
            for (let c = 0; c < cols; c++) {
              const u0 = r * (panelU + gapU) + 0.4;
              const v0 = c * (panelV + gapV) + 0.3;
              const a = project(u0, v0);
              const b = project(u0 + panelU, v0);
              const cP = project(u0 + panelU, v0 + panelV);
              const d = project(u0, v0 + panelV);
              const cells = [];
              const cellRows = 4, cellCols = 2;
              for (let cr = 0; cr < cellRows; cr++) {
                for (let cc = 0; cc < cellCols; cc++) {
                  const cu = u0 + (cr / cellRows) * panelU;
                  const cv = v0 + (cc / cellCols) * panelV;
                  const cuN = u0 + ((cr + 1) / cellRows) * panelU;
                  const cvN = v0 + ((cc + 1) / cellCols) * panelV;
                  const ca = project(cu, cv);
                  const cb = project(cuN, cv);
                  const cc2 = project(cuN, cvN);
                  const cd = project(cu, cvN);
                  cells.push(
                    <polygon key={`cell-${r}-${c}-${cr}-${cc}`}
                      points={`${ca.x},${ca.y} ${cb.x},${cb.y} ${cc2.x},${cc2.y} ${cd.x},${cd.y}`}
                      fill="#16294a" stroke="#0a1428" strokeWidth="0.3"/>
                  );
                }
              }
              const bbA = project(u0 + panelU * 0.5, v0);
              const bbB = project(u0 + panelU * 0.5, v0 + panelV);
              panels.push(
                <g key={`p-${r}-${c}`}>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="#142a4e"/>
                  {cells}
                  <line x1={bbA.x} y1={bbA.y} x2={bbB.x} y2={bbB.y}
                    stroke="#9eb6d8" strokeWidth="0.35" opacity="0.5"/>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="none" stroke="#5a7098" strokeWidth="0.6"/>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="url(#hGlint)"/>
                </g>
              );
            }
          }
          return (
            <g clipPath="url(#hLeftRoofClip)">
              {/* Dark backing fill — the roof plane shows through gaps */}
              <polygon points="50,150 215,55 215,150" fill="#020610"/>
              {panels}
            </g>
          );
        })()}

        {/* Right roof slope — mirrored panel array */}
        {(() => {
          const O = { x: 215, y: 55 };          // ridge-top apex
          const uStep = { x: 9.85, y: 6.05 };   // down-slope per unit (toward eave-right)
          const vStep = { x: 0, y: 9.5 };       // along-ridge per unit (downward at ridge line)
          const cols = 4, rows = 4;
          const panelU = 3.6, panelV = 2.2;
          const gapU = 0.25, gapV = 0.25;
          const project = (u, v) => ({
            x: O.x + u * uStep.x + v * vStep.x,
            y: O.y + u * uStep.y + v * vStep.y,
          });
          const panels = [];
          for (let r = 0; r < rows; r++) {
            for (let c = 0; c < cols; c++) {
              const u0 = r * (panelU + gapU) + 0.4;
              const v0 = c * (panelV + gapV) + 0.3;
              const a = project(u0, v0);
              const b = project(u0 + panelU, v0);
              const cP = project(u0 + panelU, v0 + panelV);
              const d = project(u0, v0 + panelV);
              const cells = [];
              const cellRows = 4, cellCols = 2;
              for (let cr = 0; cr < cellRows; cr++) {
                for (let cc = 0; cc < cellCols; cc++) {
                  const cu = u0 + (cr / cellRows) * panelU;
                  const cv = v0 + (cc / cellCols) * panelV;
                  const cuN = u0 + ((cr + 1) / cellRows) * panelU;
                  const cvN = v0 + ((cc + 1) / cellCols) * panelV;
                  const ca = project(cu, cv);
                  const cb = project(cuN, cv);
                  const cc2 = project(cuN, cvN);
                  const cd = project(cu, cvN);
                  cells.push(
                    <polygon key={`rcell-${r}-${c}-${cr}-${cc}`}
                      points={`${ca.x},${ca.y} ${cb.x},${cb.y} ${cc2.x},${cc2.y} ${cd.x},${cd.y}`}
                      fill="#16294a" stroke="#0a1428" strokeWidth="0.3"/>
                  );
                }
              }
              const bbA = project(u0 + panelU * 0.5, v0);
              const bbB = project(u0 + panelU * 0.5, v0 + panelV);
              panels.push(
                <g key={`rp-${r}-${c}`}>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="#142a4e"/>
                  {cells}
                  <line x1={bbA.x} y1={bbA.y} x2={bbB.x} y2={bbB.y}
                    stroke="#9eb6d8" strokeWidth="0.35" opacity="0.5"/>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="none" stroke="#5a7098" strokeWidth="0.6"/>
                  <polygon points={`${a.x},${a.y} ${b.x},${b.y} ${cP.x},${cP.y} ${d.x},${d.y}`}
                    fill="url(#hGlint)"/>
                </g>
              );
            }
          }
          return (
            <g clipPath="url(#hRightRoofClip)">
              <polygon points="215,55 370,150 215,150" fill="#020610"/>
              {panels}
            </g>
          );
        })()}

        {/* Inverter on side wall (small grey box) */}
        <rect x="76" y="246" width="14" height="22" fill="#2a2a2a" stroke="#0a0a0a" strokeWidth="0.6"/>
        <circle cx="83" cy="252" r="1" fill="#3aff88" opacity="0.9"/>
      </svg>
    </div>
  );
}

function CommercialBuilding() {
  // 3-story commercial building, 460×360 footprint.
  // Rooftop top-down solar array, lit windows in regular grid, ground entrance.
  const W = 460, H = 360;
  const floors = 3;
  const winCols = 8;
  // Body sits on ground (top: 80 to leave room for rooftop solar above)
  const bodyTop = 80;
  const bodyH = 240; // 3 floors × 80
  const floorH = bodyH / floors;

  return (
    <div style={{ position: 'relative', width: W, height: H }}>
      {/* SVG body + façade detail */}
      <svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} style={{ position: 'absolute', inset: 0 }}>
        <defs>
          <linearGradient id="cbBody" x1="0" y1="0" x2="1" y2="0">
            <stop offset="0%" stopColor="#1a1208" stopOpacity="1"/>
            <stop offset="55%" stopColor="#3a2818" stopOpacity="1"/>
            <stop offset="100%" stopColor="#5a3a22" stopOpacity="1"/>
          </linearGradient>
          <linearGradient id="cbParapet" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#2a1c0e"/>
            <stop offset="100%" stopColor="#1a1208"/>
          </linearGradient>
        </defs>

        {/* Parapet wall (taller strip behind rooftop solar) */}
        <rect x="20" y={bodyTop - 14} width={W - 40} height="14" fill="url(#cbParapet)" stroke="#000" strokeWidth="1"/>

        {/* Building body */}
        <rect x="20" y={bodyTop} width={W - 40} height={bodyH} fill="url(#cbBody)" stroke="#0a0606" strokeWidth="1"/>

        {/* Floor separators */}
        {Array.from({ length: floors - 1 }).map((_, i) => {
          const y = bodyTop + (i + 1) * floorH;
          return <line key={i} x1="20" y1={y} x2={W - 20} y2={y} stroke="#0a0606" strokeWidth="1.5" opacity="0.7"/>;
        })}

        {/* Vertical column accents */}
        {[0.25, 0.5, 0.75].map((f, i) => {
          const x = 20 + (W - 40) * f;
          return <line key={`v${i}`} x1={x} y1={bodyTop} x2={x} y2={bodyTop + bodyH} stroke="#0a0606" strokeWidth="1" opacity="0.4"/>;
        })}

        {/* Ground entrance — central glass doors */}
        <rect x={W/2 - 36} y={bodyTop + bodyH - 56} width="72" height="56" fill="#0a0606"/>
        <line x1={W/2} y1={bodyTop + bodyH - 56} x2={W/2} y2={bodyTop + bodyH} stroke="#1a1208" strokeWidth="1"/>
        {/* Entrance lobby glow */}
        <rect x={W/2 - 34} y={bodyTop + bodyH - 54} width="68" height="52" fill="rgba(255,180,100,0.10)"/>

        {/* Building base shadow on ground */}
        <ellipse cx={W/2} cy={bodyTop + bodyH + 4} rx={(W - 40) / 2 + 10} ry="6" fill="rgba(0,0,0,0.55)"/>
      </svg>

      {/* Window grid — rendered as div overlay so we can vary lit/dim states */}
      {Array.from({ length: floors }).map((_, fi) => {
        // skip center 2 windows on ground floor where the entrance sits
        return Array.from({ length: winCols }).map((_, ci) => {
          const isGroundCenter = fi === floors - 1 && (ci === 3 || ci === 4);
          if (isGroundCenter) return null;
          // Pseudo-random lit pattern, seeded by fi*winCols+ci
          const seed = fi * 31 + ci * 7;
          const lit = (seed % 5) !== 0; // ~80% lit
          const warm = (seed % 3) === 0;
          const winW = (W - 80) / winCols - 8;
          const winH = floorH * 0.5;
          const winX = 40 + ci * ((W - 80) / winCols) + 4;
          const winY = bodyTop + fi * floorH + (floorH - winH) / 2;
          return (
            <div key={`${fi}-${ci}`} style={{
              position: 'absolute',
              left: winX, top: winY,
              width: winW, height: winH,
              background: lit
                ? (warm
                    ? 'linear-gradient(180deg, rgba(255,200,130,0.85), rgba(255,170,90,0.6))'
                    : 'linear-gradient(180deg, rgba(255,220,170,0.75), rgba(220,180,130,0.45))')
                : 'rgba(8,4,2,0.9)',
              border: '1px solid rgba(0,0,0,0.6)',
              boxShadow: lit ? `0 0 6px rgba(255,180,100,0.35)` : 'none',
            }}/>
          );
        });
      })}

      {/* Flat-roof solar array — top-down perspective, sits above parapet */}
      <div style={{
        position: 'absolute', left: 30, top: 0,
        width: 400, height: 64,
        transform: 'perspective(800px) rotateX(70deg)',
        transformOrigin: 'center bottom',
        display: 'grid',
        gridTemplateColumns: 'repeat(10, 1fr)',
        gridTemplateRows: 'repeat(3, 1fr)',
        gap: 2,
        padding: 2,
        background: '#040810',
      }}>
        {Array.from({ length: 30 }).map((_, i) => (
          <div key={i} style={{
            background: 'linear-gradient(135deg, oklch(26% 0.06 240) 0%, oklch(42% 0.09 235) 50%, oklch(20% 0.05 240) 100%)',
            borderRadius: 1,
            boxShadow: 'inset 0 0 0 0.5px rgba(120,170,220,0.35)',
          }}/>
        ))}
      </div>
    </div>
  );
}

function Warehouse() {
  return (
    <div style={{ position: 'relative', width: 460, height: 200 }}>
      <svg width="460" height="200" viewBox="0 0 460 200" style={{ position: 'absolute', inset: 0 }}>
        <defs>
          <linearGradient id="whGrad" x1="0" y1="0" x2="1" y2="0">
            <stop offset="0%" stopColor="#1a1208" stopOpacity="1"/>
            <stop offset="100%" stopColor="#5a3a22" stopOpacity="1"/>
          </linearGradient>
        </defs>
        {/* Warehouse body — wide, low */}
        <polygon points="20,60 440,60 440,180 20,180" fill="url(#whGrad)" stroke="#0a0606" strokeWidth="1"/>
        {/* Roof line subtle */}
        <line x1="20" y1="60" x2="440" y2="60" stroke="#000" strokeWidth="2"/>
        {/* Bay doors */}
        <rect x="60" y="120" width="60" height="60" fill="#0a0606"/>
        <rect x="180" y="120" width="60" height="60" fill="#0a0606"/>
        <rect x="300" y="120" width="60" height="60" fill="#0a0606"/>
        {/* Side stripes */}
        <line x1="20" y1="100" x2="440" y2="100" stroke="#0a0606" strokeWidth="1"/>
      </svg>
      {/* Flat-roof solar array — top-down perspective */}
      <div style={{
        position: 'absolute', left: 30, top: 0,
        width: 420, height: 50,
        transform: 'perspective(800px) rotateX(70deg)',
        transformOrigin: 'center bottom',
        display: 'grid',
        gridTemplateColumns: 'repeat(10, 1fr)',
        gridTemplateRows: 'repeat(2, 1fr)',
        gap: 2,
        padding: 2,
        background: '#040810',
      }}>
        {Array.from({ length: 20 }).map((_, i) => (
          <div key={i} style={{
            background: 'linear-gradient(135deg, oklch(26% 0.06 240) 0%, oklch(42% 0.09 235) 50%, oklch(20% 0.05 240) 100%)',
            borderRadius: 1,
            boxShadow: 'inset 0 0 0 0.5px rgba(120,170,220,0.35)',
          }}/>
        ))}
      </div>
    </div>
  );
}

function SolarFarm() {
  // Contained utility-scale farm: front-facing panel rows on a clean ground plot.
  // Footprint is fixed (840×340) and all panels stay inside it.
  const W = 840, H = 340;
  const cols = 9;
  const rows = 7;
  const panels = [];

  for (let r = 0; r < rows; r++) {
    // Slight perspective: deeper rows are smaller and dimmer
    const depth = r / (rows - 1);
    const rowScale = 1 - depth * 0.32;
    const rowOpacity = 1 - depth * 0.40;
    const rowY = 40 + r * 40;
    // Each row is centered, with shrinking width
    const panelW = (W - 80) / cols * rowScale;
    const panelH = 26 * rowScale;
    const gap = 8 * rowScale;
    const totalW = cols * panelW + (cols - 1) * gap;
    const startX = (W - totalW) / 2 + (depth * 8); // tiny shift for parallax

    for (let c = 0; c < cols; c++) {
      const px = startX + c * (panelW + gap);
      panels.push(
        <div key={`${r}-${c}`} style={{
          position: 'absolute', left: px, top: rowY,
          width: panelW, height: panelH * 1.4,
          opacity: rowOpacity,
        }}>
          {/* Tracker post */}
          <div style={{
            position: 'absolute', left: '50%', top: panelH * 1.05,
            width: 1.5, height: panelH * 0.5,
            background: '#0a0806',
            transform: 'translateX(-0.75px)',
          }}/>
          {/* Front-facing tilted panel */}
          <div style={{
            position: 'absolute', left: 0, top: 0,
            width: panelW, height: panelH,
            background: 'linear-gradient(180deg, #2a4a78 0%, #1e3a68 50%, #14284a 100%)',
            border: '1px solid #3a5a88',
            borderRadius: 1,
            boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.4), 0 0 6px rgba(255,180,100,0.15)',
            overflow: 'hidden',
          }}>
            {/* Cell grid (front-facing) */}
            <div style={{
              position: 'absolute', inset: 1,
              backgroundImage: `
                repeating-linear-gradient(90deg, transparent 0, transparent ${panelW/12 - 0.5}px, rgba(0,0,0,0.45) ${panelW/12 - 0.5}px, rgba(0,0,0,0.45) ${panelW/12}px),
                repeating-linear-gradient(0deg, transparent 0, transparent ${panelH/3 - 0.5}px, rgba(0,0,0,0.35) ${panelH/3 - 0.5}px, rgba(0,0,0,0.35) ${panelH/3}px)
              `,
            }}/>
            {/* Sunset glint sweeping across each panel */}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'linear-gradient(115deg, transparent 55%, rgba(255,210,140,0.35) 72%, transparent 88%)',
            }}/>
          </div>
        </div>
      );
    }
  }

  return (
    <div style={{ position: 'relative', width: W, height: H, overflow: 'hidden', borderRadius: 4 }}>
      {/* Ground plot — bounded sandy field, lightly tinted so sunset shows through */}
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg, rgba(120,75,38,0.35) 0%, rgba(80,48,22,0.42) 60%, rgba(40,24,12,0.55) 100%)',
      }}/>
      {/* Subtle perimeter fence line */}
      <div style={{
        position: 'absolute', left: 8, top: 8, right: 8, bottom: 8,
        border: '1px dashed rgba(255,180,100,0.18)',
        borderRadius: 3,
      }}/>
      {panels}
      {/* Inverter cabinet at bottom-right corner of plot */}
      <div style={{
        position: 'absolute', right: 28, bottom: 16,
        width: 28, height: 36,
        background: 'linear-gradient(180deg, #2a2a2a, #1a1a1a)',
        border: '1px solid #0a0a0a',
        borderRadius: 1,
        boxShadow: '0 0 8px rgba(255,180,100,0.25)',
      }}>
        <div style={{
          position: 'absolute', left: 4, top: 6,
          width: 20, height: 1.5, background: X3.amber, opacity: 0.8,
        }}/>
        <div style={{
          position: 'absolute', left: 4, top: 12,
          width: 20, height: 1.5, background: X3.teal, opacity: 0.6,
        }}/>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 2 — App-based BLE configuration (200+ inverters supported)
// ───────────────────────────────────────────────────────────────────
function Scene2() {
  return (
    <Sprite start={T.s2[0]} end={T.s2[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        const phoneX = 1000, phoneY = 150;
        const devX = 1500, devY = 410;

        // Stages drive timing
        const stages = [
          { t: 0.3,  name: 'scan' },
          { t: 1.1,  name: 'pair' },
          { t: 2.0,  name: 'asset' },
          { t: 3.0,  name: 'modbus' },
          { t: 4.0,  name: 'connectivity' },
          { t: 4.9,  name: 'done' },
        ];
        let stage = 'scan';
        for (const s of stages) if (lt >= s.t) stage = s.name;

        const totalSec = 5 * 60;
        const elapsedFrac = clamp((lt - 0.2) / 5.0, 0, 1);
        const remaining = Math.max(0, Math.round(totalSec * (1 - elapsedFrac)));
        const mm = Math.floor(remaining / 60), ss = remaining % 60;
        const timer = `${mm}:${String(ss).padStart(2,'0')}`;

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            <Caption
              title="Configure on-site,"
              accent="in under five minutes."
              sub={<>Pair over Bluetooth using the app on your phone. Pick from 200+ inverter models.<br/>Configure the comms port and join the network. No laptop, no cables.</>}
              color={X3.amber}
              opacity={entry}
            />

            {/* 200+ inverters supported badge */}
            <div style={{
              position: 'absolute', left: 120, top: 820,
              opacity: entry,
              padding: '24px 36px',
              background: 'rgba(20,20,20,0.85)',
              border: `1px solid ${X3.amber}55`,
              borderRadius: 18,
              display: 'flex', alignItems: 'center', gap: 28,
            }}>
              <div style={{
                fontFamily: sansFont, fontSize: 84, fontWeight: 700,
                color: X3.amber, letterSpacing: '-0.03em', lineHeight: 1,
              }}>200<span style={{ fontSize: 44 }}>+</span></div>
              <div style={{
                fontFamily: sansFont, fontSize: 20,
                color: X3.textDim, lineHeight: 1.4,
                maxWidth: 360,
              }}>
                <div style={{ color: X3.text, fontSize: 18, fontWeight: 600, marginBottom: 6, letterSpacing: '0.1em', textTransform: 'uppercase', fontFamily: monoFont }}>Inverters supported</div>
                Across every major brand
              </div>
            </div>

            {/* Brand logos strip */}
            <div style={{
              position: 'absolute', left: 120, top: 1010,
              display: 'flex', gap: 40, alignItems: 'center',
              opacity: entry * 0.85,
              fontFamily: sansFont, fontSize: 26, fontWeight: 700,
              color: X3.textDim, letterSpacing: '-0.01em',
            }}>
              {['Growatt', 'Solis', 'GoodWe', 'SMA', 'Huawei', 'Sungrow', 'Fronius'].map((n, i) => (
                <span key={n} style={{ opacity: 0.45 + 0.55 * Math.max(0, Math.sin(lt * 0.8 + i * 0.7)) }}>{n}</span>
              ))}
            </div>

            {/* Timer chip top-right */}
            <div style={{
              position: 'absolute', right: 80, top: 80,
              display: 'flex', alignItems: 'center', gap: 10,
              padding: '10px 18px',
              background: 'rgba(20,20,20,0.85)',
              border: `1px solid ${X3.amber}55`,
              borderRadius: 999,
              fontFamily: monoFont,
              opacity: entry,
            }}>
              <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
                <circle cx="7" cy="8" r="5" stroke={X3.amber} strokeWidth="1.5"/>
                <path d="M7 5.5 L7 8 L9 9" stroke={X3.amber} strokeWidth="1.5" strokeLinecap="round"/>
              </svg>
              <span style={{ fontSize: 11, color: X3.textDim, letterSpacing: '0.12em', textTransform: 'uppercase' }}>SETUP IN</span>
              <span style={{ fontSize: 18, color: X3.amber, fontVariantNumeric: 'tabular-nums', fontWeight: 600 }}>{timer}</span>
            </div>

            {/* Phone */}
            <Phone x={phoneX} y={phoneY} stage={stage} t={lt}/>

            {/* Device */}
            <DeviceFrame x={devX} y={devY} w={400} h={400} glowIntensity={0.6 + 0.4 * Math.sin(lt * 4)} status="ble"/>

            {/* BT link */}
            <BluetoothLink
              from={{ x: phoneX + 280, y: phoneY + 380 }}
              to={{ x: devX + 60, y: devY + 170 }}
              t={lt}
              active={stage !== 'done'}
            />

            <div style={{
              position: 'absolute',
              left: (phoneX + 280 + devX + 60) / 2 - 50,
              top: (phoneY + 380 + devY + 170) / 2 - 50,
              padding: '5px 11px',
              background: 'rgba(10,10,10,0.9)',
              border: `1px solid ${X3.blue}55`,
              borderRadius: 4,
              fontFamily: monoFont, fontSize: 11,
              color: X3.blue, letterSpacing: '0.15em',
              textTransform: 'uppercase',
              opacity: stage !== 'done' ? 1 : 0,
              transition: 'opacity 400ms',
            }}>BLE 5.0</div>
          </div>
        );
      }}
    </Sprite>
  );
}

function Phone({ x, y, stage, t }) {
  const W = 320, H = 660;
  return (
    <div style={{
      position: 'absolute', left: x, top: y,
      width: W, height: H,
      filter: 'drop-shadow(0 30px 60px rgba(0,0,0,0.7))',
    }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg, #2a2a2a, #0a0a0a)',
        borderRadius: 44,
        padding: 8,
        border: '1px solid #333',
      }}>
        <div style={{
          width: '100%', height: '100%',
          background: '#000',
          borderRadius: 36,
          overflow: 'hidden',
          position: 'relative',
        }}>
          <div style={{
            position: 'absolute', top: 0, left: 0, right: 0,
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
            padding: '14px 22px 8px',
            fontFamily: sansFont, fontSize: 12, fontWeight: 600,
            color: '#fff', zIndex: 5,
          }}>
            <span>9:41</span>
            <span style={{ display: 'flex', gap: 4, alignItems: 'center', fontSize: 9, color: X3.blue }}>
              <svg width="10" height="12" viewBox="0 0 10 12" fill="none">
                <path d="M5 1 L5 11 M5 1 L8 4 L2 8 M5 11 L8 8 L2 4" stroke={X3.blue} strokeWidth="1.2" fill="none" strokeLinejoin="round" strokeLinecap="round"/>
              </svg>
              <span>•••• 100%</span>
            </span>
          </div>
          <div style={{
            position: 'absolute', top: 8, left: '50%',
            transform: 'translateX(-50%)',
            width: 110, height: 28, background: '#000',
            borderRadius: 14, zIndex: 6,
          }}/>
          <PhoneScreen stage={stage} t={t}/>
        </div>
      </div>
    </div>
  );
}

function PhoneScreen({ stage, t }) {
  return (
    <div style={{
      position: 'absolute', inset: 0,
      paddingTop: 56,
      display: 'flex', flexDirection: 'column',
      background: '#000',
    }}>
      <div style={{
        padding: '4px 22px 10px',
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      }}>
        <div style={{
          fontFamily: sansFont, fontSize: 11, fontWeight: 700,
          letterSpacing: '0.08em',
        }}>
          <span style={{ color: '#fff' }}>X3</span><span style={{ color: X3.amber }}>EDGE</span>
          <span style={{ color: X3.textMute, marginLeft: 6, fontWeight: 500 }}>· <span style={{ color: 'rgb(242, 175, 40)' }}>IO</span></span>
        </div>
        <div style={{ fontFamily: monoFont, fontSize: 9, color: X3.textMute, letterSpacing: '0.1em' }}>v3.2.1</div>
      </div>
      <div style={{ flex: 1, padding: '6px 22px 22px', overflow: 'hidden' }}>
        {stage === 'scan' && <ScreenScan t={t}/>}
        {stage === 'pair' && <ScreenPair t={t}/>}
        {stage === 'asset' && <ScreenAsset t={t}/>}
        {stage === 'modbus' && <ScreenModbus t={t}/>}
        {stage === 'connectivity' && <ScreenConnectivity t={t}/>}
        {stage === 'done' && <ScreenDone t={t}/>}
      </div>
    </div>
  );
}

function ScreenTitle({ small, big, accent }) {
  return (
    <div style={{ marginBottom: 18 }}>
      <div style={{ fontFamily: monoFont, fontSize: 9, color: X3.amber, letterSpacing: '0.18em', textTransform: 'uppercase', marginBottom: 8 }}>{small}</div>
      <div style={{ fontFamily: sansFont, fontSize: 22, fontWeight: 700, color: '#fff', letterSpacing: '-0.02em', lineHeight: 1.15 }}>
        {big}{accent && <span style={{ color: X3.amber }}>{accent}</span>}
      </div>
    </div>
  );
}

function ScreenScan({ t }) {
  return (
    <>
      <ScreenTitle small="01 / DISCOVER" big="Scanning for" accent=" devices…"/>
      <div style={{ display: 'flex', justifyContent: 'center', margin: '24px 0' }}>
        <div style={{ position: 'relative', width: 130, height: 130 }}>
          {[0,1,2].map(i => {
            const phase = ((t * 0.8) + i / 3) % 1;
            return (
              <div key={i} style={{
                position: 'absolute', inset: 0,
                borderRadius: '50%',
                border: `1.5px solid ${X3.blue}`,
                opacity: (1 - phase) * 0.7,
                transform: `scale(${0.4 + phase * 0.8})`,
              }}/>
            );
          })}
          <div style={{
            position: 'absolute', inset: '40%',
            background: X3.blue, borderRadius: '50%',
            boxShadow: `0 0 20px ${X3.blue}`,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>
            <svg width="16" height="20" viewBox="0 0 10 12" fill="none">
              <path d="M5 1 L5 11 M5 1 L8 4 L2 8 M5 11 L8 8 L2 4" stroke="#fff" strokeWidth="1.2" fill="none" strokeLinejoin="round" strokeLinecap="round"/>
            </svg>
          </div>
        </div>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginTop: 8 }}>
        {['X3EDGE-N · A4:21', 'X3EDGE-N · 9F:88'].map((name, i) => {
          const reveal = clamp((t - 0.8 - i * 0.4) * 2, 0, 1);
          const isHot = i === 0 && t > 1.6;
          return (
            <div key={i} style={{
              padding: '10px 12px',
              background: isHot ? `${X3.amber}22` : 'rgba(255,255,255,0.04)',
              border: `1px solid ${isHot ? X3.amber : X3.border}`,
              borderRadius: 8,
              display: 'flex', alignItems: 'center', justifyContent: 'space-between',
              opacity: reveal,
              transform: `translateY(${(1-reveal)*8}px)`,
            }}>
              <div style={{ fontFamily: monoFont, fontSize: 11, color: '#fff' }}>{name}</div>
              <div style={{ fontFamily: monoFont, fontSize: 9, color: isHot ? X3.amber : X3.textMute, letterSpacing: '0.1em' }}>{isHot ? 'TAP TO PAIR' : '−42 dBm'}</div>
            </div>
          );
        })}
      </div>
    </>
  );
}

function ScreenPair({ t }) {
  const progress = clamp(t / 1.8, 0, 1);
  return (
    <>
      <ScreenTitle small="02 / PAIR" big="Secure" accent=" handshake"/>
      <div style={{ display: 'flex', justifyContent: 'center', margin: '40px 0 32px' }}>
        <div style={{ position: 'relative', width: 110, height: 110 }}>
          <svg width="110" height="110" viewBox="0 0 110 110">
            <circle cx="55" cy="55" r="46" stroke={X3.border} strokeWidth="4" fill="none"/>
            <circle cx="55" cy="55" r="46" stroke={X3.blue} strokeWidth="4" fill="none"
              strokeDasharray={2 * Math.PI * 46}
              strokeDashoffset={2 * Math.PI * 46 * (1 - progress)}
              strokeLinecap="round"
              transform="rotate(-90 55 55)"
            />
          </svg>
          <div style={{
            position: 'absolute', inset: 0,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: monoFont, fontSize: 24, fontWeight: 600,
            color: X3.blue, fontVariantNumeric: 'tabular-nums',
          }}>{Math.round(progress * 100)}%</div>
        </div>
      </div>
      <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textDim, textAlign: 'center', lineHeight: 1.7, letterSpacing: '0.04em' }}>
        <div>{progress > 0.2 ? '✓' : '·'} BLE link established</div>
        <div>{progress > 0.5 ? '✓' : '·'} Exchange certificates</div>
        <div>{progress > 0.85 ? '✓' : '·'} AES-256 channel ready</div>
      </div>
    </>
  );
}

function ScreenAsset({ t }) {
  // Real inverter compatibility list
  const models = [
    { brand: 'Growatt',  model: 'MIN 8500TL-X' },
    { brand: 'Solis',    model: 'S6-GR1P6K' },
    { brand: 'GoodWe',   model: 'GW10K-MS' },
    { brand: 'SMA',      model: 'Sunny Tripower 25000TL' },
    { brand: 'Huawei',   model: 'SUN2000-12KTL-M2' },
    { brand: 'Sungrow',  model: 'SG110CX' },
    { brand: 'Fronius',  model: 'Symo 15.0-3-M' },
  ];
  const selectedIdx = Math.min(models.length - 1, Math.floor(t * 1.6));
  return (
    <>
      <ScreenTitle small="03 / ASSET" big="Inverter" accent=" compatibility"/>
      {/* Search bar */}
      <div style={{
        padding: '8px 10px', marginBottom: 8,
        background: 'rgba(255,255,255,0.04)',
        border: `1px solid ${X3.border}`,
        borderRadius: 8,
        fontFamily: monoFont, fontSize: 11, color: X3.textDim,
        display: 'flex', alignItems: 'center', gap: 8,
      }}>
        <span style={{ color: X3.textMute }}>⌕</span>
        <span>Search 200+ models…</span>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 5, maxHeight: 240, overflow: 'hidden' }}>
        {models.map((m, i) => {
          const reveal = clamp((t - 0.15 - i * 0.08) * 3, 0, 1);
          const isSel = i === selectedIdx && t > 0.8;
          return (
            <div key={i} style={{
              padding: '8px 10px',
              background: isSel ? `${X3.amber}22` : 'rgba(255,255,255,0.025)',
              border: `1px solid ${isSel ? X3.amber : X3.border}`,
              borderRadius: 6,
              opacity: reveal,
              transform: `translateY(${(1-reveal)*6}px)`,
              boxShadow: isSel ? `0 0 14px ${X3.amber}44` : 'none',
              transition: 'all 180ms',
              display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            }}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
                <div style={{ fontFamily: monoFont, fontSize: 8.5, color: X3.textMute, letterSpacing: '0.1em', textTransform: 'uppercase' }}>{m.brand}</div>
                <div style={{ fontFamily: sansFont, fontSize: 11.5, color: '#fff', fontWeight: 500 }}>{m.model}</div>
              </div>
              {isSel && (
                <div style={{
                  width: 16, height: 16, borderRadius: 8,
                  background: X3.amber,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                }}>
                  <svg width="10" height="10" viewBox="0 0 10 10"><path d="M2 5 L4 7 L8 3" stroke="#000" strokeWidth="1.6" fill="none" strokeLinecap="round"/></svg>
                </div>
              )}
            </div>
          );
        })}
        {/* "+ more" row */}
        <div style={{
          padding: '8px 10px',
          background: 'rgba(255,255,255,0.02)',
          border: `1px dashed ${X3.border}`,
          borderRadius: 6,
          fontFamily: monoFont, fontSize: 10,
          color: X3.amber, letterSpacing: '0.08em',
          textAlign: 'center',
          opacity: clamp((t - 0.7) * 3, 0, 1),
        }}>+ 193 more models</div>
      </div>
    </>
  );
}

function ScreenModbus({ t }) {
  const fields = [
    { k: 'Slave ID', v: '1' },
    { k: 'Baud Rate', v: '9600' },
    { k: 'Parity', v: 'None' },
    { k: 'Data Bits', v: '8' },
  ];
  return (
    <>
      <ScreenTitle small="04 / MODBUS" big="Tune the" accent=" register map"/>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {fields.map((f, i) => {
          const reveal = clamp((t - 0.3 - i * 0.25) * 2.5, 0, 1);
          return (
            <div key={i} style={{
              display: 'flex', justifyContent: 'space-between', alignItems: 'center',
              padding: '11px 14px',
              background: 'rgba(255,255,255,0.03)',
              border: `1px solid ${X3.border}`,
              borderRadius: 8,
              opacity: reveal,
              transform: `translateY(${(1-reveal)*8}px)`,
            }}>
              <div style={{ fontFamily: sansFont, fontSize: 12, color: X3.textDim }}>{f.k}</div>
              <div style={{ fontFamily: monoFont, fontSize: 13, color: '#fff', fontWeight: 600 }}>{f.v}</div>
            </div>
          );
        })}
      </div>
      <div style={{
        marginTop: 14,
        fontFamily: monoFont, fontSize: 10,
        color: X3.teal, letterSpacing: '0.06em',
        display: 'flex', alignItems: 'center', gap: 6,
      }}>
        <div style={{ width: 6, height: 6, borderRadius: 3, background: X3.teal, boxShadow: `0 0 5px ${X3.teal}` }}/>
        TEST READ · 230.4 V · 36.6 A
      </div>
    </>
  );
}

function ScreenConnectivity({ t }) {
  return (
    <>
      <ScreenTitle small="05 / NETWORK" big="Wi-Fi +" accent=" 4G backhaul"/>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
        <div style={{
          padding: '12px 14px',
          background: `${X3.blue}1a`,
          border: `1px solid ${X3.blue}`,
          borderRadius: 10,
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
            <div style={{ fontFamily: sansFont, fontSize: 13, color: '#fff', fontWeight: 600 }}>Wi-Fi · Primary</div>
            <Toggle on color={X3.blue}/>
          </div>
          <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textDim }}>SITE-042-OPS · WPA3</div>
        </div>
        <div style={{
          padding: '12px 14px',
          background: `${X3.violet}1a`,
          border: `1px solid ${X3.violet}`,
          borderRadius: 10,
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
            <div style={{ fontFamily: sansFont, fontSize: 13, color: '#fff', fontWeight: 600 }}>4G LTE · Backhaul</div>
            <Toggle on color={X3.violet}/>
          </div>
          <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textDim }}>Auto-failover · −74 dBm</div>
        </div>
        {/* Energy Saver mode — for 4G data conservation */}
        <div style={{
          padding: '10px 14px',
          background: `${X3.amber}14`,
          border: `1px solid ${X3.amber}88`,
          borderRadius: 10,
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
              <svg width="11" height="13" viewBox="0 0 11 13" fill="none">
                <path d="M6 0 L0 8 L4.5 8 L3 13 L11 4 L6 4 Z" fill={X3.amber}/>
              </svg>
              <div style={{ fontFamily: sansFont, fontSize: 12, color: '#fff', fontWeight: 600 }}>Energy Saver</div>
            </div>
            <Toggle on color={X3.amber}/>
          </div>
          <div style={{ fontFamily: monoFont, fontSize: 9.5, color: X3.textDim, lineHeight: 1.4 }}>
            Throttle telemetry on 4G · 60s interval<br/>
            Batch + compress · −85% data
          </div>
        </div>
        <div style={{
          padding: '11px 14px',
          background: 'rgba(255,255,255,0.03)',
          border: `1px solid ${X3.border}`,
          borderRadius: 8,
        }}>
          <div style={{ fontFamily: monoFont, fontSize: 9, color: X3.textMute, letterSpacing: '0.12em', textTransform: 'uppercase', marginBottom: 4 }}>Broker (mTLS)</div>
          <div style={{ fontFamily: monoFont, fontSize: 11, color: '#fff' }}>mqtt.synergy.xeeed.io:8883</div>
        </div>
      </div>
    </>
  );
}

function Toggle({ on, color }) {
  return (
    <div style={{
      width: 26, height: 14, borderRadius: 7,
      background: on ? color : '#333',
      position: 'relative',
    }}>
      <div style={{
        position: 'absolute', right: on ? 2 : 14, top: 2,
        width: 10, height: 10, borderRadius: 5, background: '#fff',
        transition: 'all 200ms',
      }}/>
    </div>
  );
}

function ScreenDone({ t }) {
  return (
    <div style={{
      display: 'flex', flexDirection: 'column', alignItems: 'center',
      justifyContent: 'center', height: '100%',
      gap: 18, paddingBottom: 40,
    }}>
      <div style={{
        width: 84, height: 84, borderRadius: 42,
        background: `radial-gradient(circle, ${X3.status} 0%, #0e3a1f 100%)`,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        boxShadow: `0 0 40px ${X3.status}66`,
      }}>
        <svg width="40" height="40" viewBox="0 0 40 40" fill="none">
          <path d="M10 20 L17 27 L30 13" stroke="#fff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"/>
        </svg>
      </div>
      <div style={{ fontFamily: sansFont, fontSize: 22, fontWeight: 700, color: '#fff', textAlign: 'center', letterSpacing: '-0.02em' }}>Device live</div>
      <div style={{ fontFamily: monoFont, fontSize: 11, color: X3.textDim, textAlign: 'center', letterSpacing: '0.06em', lineHeight: 1.6 }}>
        Configuration pushed<br/>
        Publishing to broker<br/>
        Time elapsed: <span style={{ color: X3.amber }}>4m 12s</span>
      </div>
    </div>
  );
}

function BluetoothLink({ from, to, t, active }) {
  const dx = to.x - from.x, dy = to.y - from.y;
  const NUM = 5;
  const dots = [];
  for (let i = 0; i < NUM; i++) {
    const phase = ((t * 0.6) + i / NUM) % 1;
    const x = from.x + dx * phase;
    const y = from.y + dy * phase;
    const op = (1 - Math.abs(phase - 0.5) * 2) * 0.8;
    dots.push({ x, y, op });
  }
  return (
    <>
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none', overflow: 'visible' }}>
        <line x1={from.x} y1={from.y} x2={to.x} y2={to.y}
          stroke={X3.blue} strokeWidth="1.5" strokeDasharray="3 6"
          opacity={active ? 0.4 : 0.1}
          strokeDashoffset={-t * 30}
        />
      </svg>
      {active && dots.map((d, i) => (
        <div key={i} style={{
          position: 'absolute',
          left: d.x - 4, top: d.y - 4,
          width: 8, height: 8, borderRadius: 4,
          background: X3.blue,
          boxShadow: `0 0 12px ${X3.blue}`,
          opacity: d.op,
        }}/>
      ))}
    </>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 3 — One X3EDGE-N → many inverters (Modbus daisy chain, up to 32)
// ───────────────────────────────────────────────────────────────────
function Scene3() {
  return (
    <Sprite start={T.s3[0]} end={T.s3[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        // Layout: device left-center, daisy chain across right side
        const devX = 430, devY = 360;
        const devW = 240, devH = 240;

        // Inverters arranged as 4x2 grid — pulled left to fill empty space
        const cols = 4, rows = 2;
        const invStartX = 970, invStartY = 320;
        const invW = 130, invH = 200, gapX = 130, gapY = 80;

        // Count up animation
        const countT = clamp((lt - 0.4) / 1.4, 0, 1);
        const count = Math.round(1 + countT * 31);

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            <Caption
              title="One device,"
              accent="up to 32 assets."
              sub={<>Daisy-chain inverters, meters, trackers and BMS over RS-485 Modbus.<br/>One box, one config.</>}
              color={X3.teal}
              opacity={entry}
              maxWidth={780}
              subMaxWidth={760}
            />

            {/* Big counter — moved further down-left */}
            <div style={{
              position: 'absolute', left: 550, top: 660,
              transform: 'translateX(-50%)',
              opacity: entry,
              display: 'flex', alignItems: 'baseline', gap: 14,
            }}>
              <div style={{
                fontFamily: sansFont, fontSize: 120, fontWeight: 700,
                color: X3.teal, letterSpacing: '-0.04em', lineHeight: 1,
                fontVariantNumeric: 'tabular-nums',
                textShadow: `0 0 40px ${X3.teal}66`,
              }}>{count}</div>
              <div style={{
                fontFamily: monoFont, fontSize: 12, color: X3.textDim,
                letterSpacing: '0.16em', textTransform: 'uppercase',
                maxWidth: 140,
              }}>mixed assets per device</div>
            </div>

            {/* Asset legend — to the right of counter, horizontal */}
            <div style={{
              position: 'absolute', left: 350, top: 820,
              opacity: entry,
              display: 'flex', gap: 22,
              fontFamily: monoFont, fontSize: 11,
              color: X3.textDim, letterSpacing: '0.1em',
            }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ width: 10, height: 10, background: X3.amber, borderRadius: 2 }}/> INVERTERS
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ width: 10, height: 10, background: X3.teal, borderRadius: 2 }}/> METERS
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ width: 10, height: 10, background: X3.blue, borderRadius: 2 }}/> TRACKERS
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ width: 10, height: 10, background: X3.violet, borderRadius: 2 }}/> BMS
              </div>
            </div>

            <DeviceFrame x={devX} y={devY} w={devW} h={devH} glowIntensity={0.7} status="online"/>

            {/* RS-485 trunk line from device to inverters */}
            <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none' }}>
              <defs>
                <linearGradient id="trunkGrad">
                  <stop offset="0%" stopColor={X3.amber}/>
                  <stop offset="100%" stopColor={X3.teal}/>
                </linearGradient>
              </defs>
              {/* True daisy-chain trunk: device → top row L→R → drop down (center of last cards) → bottom row R→L */}
              {(() => {
                const yTop = invStartY + invH/2;
                const yBot = invStartY + invH + gapY + invH/2;
                const x0 = devX + devW;
                const xStart = invStartX - 20;
                // Drop column = horizontal center of the rightmost cards
                const xDrop = invStartX + (cols - 1) * gapX + invW/2;
                const xBotEnd = invStartX;
                const d = `
                  M ${x0} ${yTop}
                  L ${xStart} ${yTop}
                  L ${xDrop} ${yTop}
                  L ${xDrop} ${yBot}
                  L ${xBotEnd} ${yBot}
                `;
                return (
                  <>
                    <path d={d} stroke="url(#trunkGrad)" strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round" opacity="0.5"/>
                    <path d={d} stroke={X3.amber} strokeWidth="2" fill="none" strokeDasharray="6 14" strokeDashoffset={-lt * 80} opacity="0.85"/>
                  </>
                );
              })()}
            </svg>

            {/* RS-485 label — placed under the device */}
            <div style={{
              position: 'absolute', left: devX, top: devY + devH + 16,
              fontFamily: monoFont, fontSize: 12, color: X3.amber,
              letterSpacing: '0.18em', textTransform: 'uppercase',
              opacity: entry,
              padding: '6px 12px',
              background: 'rgba(20,20,20,0.85)',
              border: `1px solid ${X3.amber}66`,
              borderRadius: 4,
              display: 'inline-block',
              whiteSpace: 'nowrap',
            }}>RS-485 · Modbus</div>

            {/* Inverter grid */}
            {(() => {
              // Mixed asset types — distributed across the chain
              const assetTypes = [
                { kind: 'inverter', label: 'INV',   color: X3.amber,  v1: 'P: 8.4 kW',  v2: 'V: 230',     v3: 'I: 36.6' },
                { kind: 'inverter', label: 'INV',   color: X3.amber,  v1: 'P: 7.9 kW',  v2: 'V: 229',     v3: 'I: 34.5' },
                { kind: 'meter',    label: 'MTR',   color: X3.teal,   v1: 'kWh 14282',  v2: 'PF 0.98',    v3: 'Hz 50.0' },
                { kind: 'inverter', label: 'INV',   color: X3.amber,  v1: 'P: 8.1 kW',  v2: 'V: 231',     v3: 'I: 35.1' },
                { kind: 'tracker',  label: 'TRK',   color: X3.blue,   v1: 'AZ: 142°',   v2: 'EL: 38°',    v3: 'STAT OK' },
                { kind: 'inverter', label: 'INV',   color: X3.amber,  v1: 'P: 8.0 kW',  v2: 'V: 230',     v3: 'I: 34.8' },
                { kind: 'bms',      label: 'BMS',   color: X3.violet, v1: 'SOC 78%',    v2: 'V: 412',     v3: '24°C' },
                { kind: 'meter',    label: 'MTR',   color: X3.teal,   v1: 'kWh 8104',   v2: 'PF 0.99',    v3: 'Hz 50.0' },
              ];
              return Array.from({ length: rows }).map((_, r) => (
                Array.from({ length: cols }).map((_, c) => {
                  const idx = r * cols + c;
                  const asset = assetTypes[idx];
                  const ix = invStartX + c * gapX;
                  const iy = invStartY + r * (invH + gapY);
                  const introT = clamp((lt - 0.6 - idx * 0.08) * 3, 0, 1);
                  const pulsePhase = (lt + idx * 0.15) % 1.4;
                  const showPacket = pulsePhase < 0.3;
                  return (
                    <div key={idx} style={{
                      position: 'absolute', left: ix, top: iy,
                      opacity: introT,
                      transform: `scale(${0.85 + 0.15 * introT})`,
                      transformOrigin: 'center',
                    }}>
                      <SmallInverter w={invW} h={invH} idx={idx + 1}
                        pulse={showPacket ? 1 : 0} asset={asset}/>
                    </div>
                  );
                })
              ));
            })()}

            {/* "+24 more" indicator — centered below the grid */}
            <div style={{
              position: 'absolute',
              left: invStartX + (cols * gapX - gapX/2 + invW) / 2,
              top: invStartY + 2 * invH + gapY + 28,
              transform: 'translateX(-50%)',
              fontFamily: monoFont, fontSize: 13, color: X3.textDim,
              letterSpacing: '0.12em', textTransform: 'uppercase',
              whiteSpace: 'nowrap',
              opacity: entry * (lt > 1.5 ? 1 : 0),
              transition: 'opacity 400ms',
            }}>Up to 32 nodes per chain</div>
          </div>
        );
      }}
    </Sprite>
  );
}

function SmallInverter({ w = 130, h = 200, idx = 1, pulse = 0, asset }) {
  const a = asset || { kind: 'inverter', label: 'INV', color: X3.amber, v1: 'P: 8.4 kW', v2: 'V: 480', v3: 'I: 17.5' };

  // Asset-specific visual treatment
  const renderTop = () => {
    if (a.kind === 'inverter') {
      // Tall inverter chassis with vents — lighter for clarity
      return (
        <div style={{
          background: 'linear-gradient(180deg, #4a4a4a 0%, #2e2e2e 100%)',
          borderRadius: 3, height: 36,
          display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center',
          gap: 2,
          border: `1px solid ${a.color}44`,
          boxShadow: `inset 0 1px 0 rgba(255,255,255,0.08)`,
        }}>
          {Array.from({length: 3}).map((_, i) => (
            <div key={i} style={{ width: '70%', height: 1.5, background: `${a.color}88`, borderRadius: 1, boxShadow: `0 0 3px ${a.color}55` }}/>
          ))}
        </div>
      );
    }
    if (a.kind === 'meter') {
      // Round dial / digital meter face — brighter face
      return (
        <div style={{
          background: 'linear-gradient(180deg, #2a2a2a, #181818)',
          borderRadius: 3, height: 36,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          border: `1px solid ${a.color}99`,
          boxShadow: `inset 0 0 10px ${a.color}33`,
        }}>
          <div style={{
            width: 24, height: 24, borderRadius: 12,
            border: `1.5px solid ${a.color}`,
            background: `radial-gradient(circle, ${a.color}22 0%, transparent 70%)`,
            position: 'relative',
            boxShadow: `0 0 6px ${a.color}66`,
          }}>
            <div style={{
              position: 'absolute', left: '50%', top: '50%',
              width: 1.5, height: 9,
              background: a.color,
              boxShadow: `0 0 3px ${a.color}`,
              transformOrigin: 'top',
              transform: `translate(-50%, 0) rotate(${40 + (idx * 15) % 100}deg)`,
            }}/>
            <div style={{
              position: 'absolute', left: '50%', top: '50%',
              width: 3, height: 3, borderRadius: 2,
              background: '#fff',
              transform: 'translate(-50%, -50%)',
            }}/>
          </div>
        </div>
      );
    }
    if (a.kind === 'tracker') {
      // Solar panel on tilted post — brighter blue panel
      return (
        <div style={{
          height: 36, position: 'relative',
          background: 'linear-gradient(180deg, #2a2a2a, #181818)',
          borderRadius: 3,
          border: `1px solid ${a.color}66`,
          overflow: 'hidden',
        }}>
          <div style={{
            position: 'absolute', left: '50%', bottom: 4,
            width: 1.5, height: 12,
            background: '#666',
            transform: 'translateX(-50%)',
          }}/>
          <div style={{
            position: 'absolute', left: '15%', top: 6,
            width: '70%', height: 14,
            background: 'linear-gradient(180deg, oklch(70% 0.16 240), oklch(45% 0.12 240))',
            transform: `rotate(${-15 + (idx * 5) % 30}deg)`,
            boxShadow: `inset 0 0 0 0.5px rgba(180,210,255,0.7), 0 0 4px ${a.color}66`,
            borderRadius: 1,
          }}>
            {/* Cell grid */}
            <div style={{
              position: 'absolute', inset: 1,
              backgroundImage: 'repeating-linear-gradient(90deg, transparent 0, transparent 9px, rgba(0,0,0,0.35) 9px, rgba(0,0,0,0.35) 10px)',
            }}/>
          </div>
        </div>
      );
    }
    if (a.kind === 'bms') {
      // Battery cell rows — brighter
      return (
        <div style={{
          background: 'linear-gradient(180deg, #2a2a2a, #181818)',
          borderRadius: 3, height: 36,
          padding: 4, border: `1px solid ${a.color}99`,
          display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 2,
          boxShadow: `inset 0 0 8px ${a.color}33`,
        }}>
          {Array.from({length: 8}).map((_, i) => (
            <div key={i} style={{
              background: `linear-gradient(180deg, ${a.color}, ${a.color}66)`,
              borderRadius: 1,
              boxShadow: `inset 0 0 0 0.5px ${a.color}, 0 0 2px ${a.color}66`,
            }}/>
          ))}
        </div>
      );
    }
    return null;
  };

  return (
    <div style={{
      width: w, height: h,
      background: 'linear-gradient(180deg, #1f1f1f 0%, #131313 100%)',
      borderRadius: 6,
      border: `1px solid ${pulse ? a.color : '#383838'}`,
      boxShadow: pulse ? `0 0 24px ${a.color}55` : '0 6px 18px rgba(0,0,0,0.5)',
      padding: 10,
      display: 'flex', flexDirection: 'column',
      gap: 6,
      transition: 'all 200ms',
    }}>
      <div style={{
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        fontFamily: monoFont, fontSize: 8.5,
        color: X3.textMute, letterSpacing: '0.12em',
      }}>
        <span>{a.label}-{String(idx).padStart(2, '0')}</span>
        <span style={{ width: 6, height: 6, borderRadius: 3, background: a.color, boxShadow: `0 0 4px ${a.color}` }}/>
      </div>
      {renderTop()}
      <div style={{
        background: '#000', border: '1px solid #2a2a2a',
        borderRadius: 3, padding: '7px 8px', flex: 1,
        fontSize: 11, color: '#7fff7f', fontFamily: monoFont,
        textShadow: '0 0 4px rgba(127,255,127,0.4)',
        lineHeight: 1.45,
        letterSpacing: '0.02em',
      }}>
        <div>{a.v1}</div>
        <div>{a.v2}</div>
        <div>{a.v3}</div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 4 — Edge AI processing, MQTT/mTLS payload
// ───────────────────────────────────────────────────────────────────
function Scene4() {
  return (
    <Sprite start={T.s4[0]} end={T.s4[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        const devX = 760, devY = 280;
        const codeT = clamp((lt - 1.4) / 1.6, 0, 1);

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            <DeviceFrame x={devX} y={devY} w={460} h={460} glowIntensity={0.8 + 0.2 * Math.sin(lt * 5)} status="online" showLed={false}/>

            {/* AI badge floating near device */}
            <div style={{
              position: 'absolute', left: devX + 100, top: devY - 30,
              padding: '8px 14px',
              background: 'rgba(20,20,20,0.92)',
              border: `1px solid ${X3.teal}`,
              borderRadius: 999,
              fontFamily: monoFont, fontSize: 11,
              color: X3.teal, letterSpacing: '0.14em',
              boxShadow: `0 0 24px ${X3.teal}55`,
              display: 'flex', alignItems: 'center', gap: 8,
              opacity: clamp((lt - 0.4) * 2, 0, 1),
              transform: `translateY(${Math.sin(lt * 1.5) * 4}px)`,
            }}>
              <div style={{ width: 7, height: 7, borderRadius: 4, background: X3.teal, boxShadow: `0 0 8px ${X3.teal}` }}/>
              EDGE AI · ON-DEVICE INFERENCE
            </div>

            <Caption
              title="Filter, infer,"
              accent="and encrypt at the edge."
              sub={<>Lightweight on-device ML for anomaly, soiling and forecasting.<br/>Every MQTT payload signed with mTLS.</>}
              color={X3.teal}
              opacity={entry}
              maxWidth={780}
              subMaxWidth={760}
            />

            {/* Pipeline */}
            <div style={{
              position: 'absolute', left: 120, top: 460,
              display: 'flex', gap: 10, alignItems: 'center', opacity: entry,
              flexWrap: 'wrap', maxWidth: 600,
            }}>
              {['READ', 'NORMALIZE', 'EDGE AI', 'mTLS SIGN', 'PUBLISH'].map((step, i) => {
                const stepT = clamp((lt - 0.6 - i * 0.22) / 0.4, 0, 1);
                const active = stepT > 0;
                const isAI = step === 'EDGE AI';
                const isCrypto = step === 'mTLS SIGN';
                const c = isAI ? X3.teal : isCrypto ? X3.status : X3.text;
                return (
                  <React.Fragment key={i}>
                    <div style={{
                      padding: '8px 14px',
                      background: active ? `${c}22` : 'rgba(255,255,255,0.03)',
                      border: `1px solid ${active ? c : X3.border}`,
                      borderRadius: 6,
                      fontFamily: monoFont, fontSize: 11,
                      color: active ? c : X3.textMute,
                      letterSpacing: '0.1em',
                      opacity: 0.3 + 0.7 * stepT,
                    }}>{step}</div>
                    {i < 4 && <div style={{ fontFamily: monoFont, fontSize: 14, color: active ? c : X3.textMute, opacity: 0.4 + 0.6 * stepT }}>→</div>}
                  </React.Fragment>
                );
              })}
            </div>

            {/* MQTT payload */}
            <div style={{
              position: 'absolute', left: devX + 460, top: devY + 30,
              opacity: codeT,
              transform: `translateX(${(1-codeT)*-20}px)`,
            }}>
              <CodeBlock
                x={0} y={0} w={520} h={400}
                scrollT={codeT * 1.5}
                lines={[
                  { text: 'topic: synergy/site-042/inv-01/telemetry', color: X3.teal },
                  { text: 'qos:    1   ·  retain: false', color: X3.textDim },
                  { text: 'tls:    mTLS (cert-pinned)', color: X3.status },
                  { text: '' },
                  { text: '{', color: X3.text },
                  { text: '  "ts":         "2026-05-05T14:22:08Z",', color: X3.textDim },
                  { text: '  "site":       "042",', color: X3.textDim },
                  { text: '  "inv":        "01",', color: X3.textDim },
                  { text: '  "p_kw":       8.42,', color: X3.amber },
                  { text: '  "v_ac":       230.4,', color: X3.amber },
                  { text: '  "i_ac":       36.6,', color: X3.amber },
                  { text: '  "f_hz":       50.02,', color: X3.amber },
                  { text: '  "ai_anomaly": 0.02,', color: X3.teal },
                  { text: '  "ai_fcast":   8.50,', color: X3.teal },
                  { text: '  "sig":        "ed25519:7f3a..."', color: X3.status },
                  { text: '}', color: X3.text },
                ]}
              />
              {/* mTLS lock badge */}
              <div style={{
                position: 'absolute', right: 10, top: 10,
                padding: '4px 9px',
                background: `${X3.status}22`,
                border: `1px solid ${X3.status}`,
                borderRadius: 4,
                fontFamily: monoFont, fontSize: 9,
                color: X3.status, letterSpacing: '0.1em',
                display: 'flex', alignItems: 'center', gap: 5,
              }}>
                <svg width="9" height="11" viewBox="0 0 9 11" fill="none">
                  <rect x="1" y="5" width="7" height="5.5" rx="1" stroke={X3.status} strokeWidth="1" fill="none"/>
                  <path d="M2.5 5 V3 a2 2 0 0 1 4 0 V5" stroke={X3.status} strokeWidth="1" fill="none"/>
                </svg>
                mTLS
              </div>
            </div>
          </div>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 5 — WiFi primary + 4G backhaul (failover)
// ───────────────────────────────────────────────────────────────────
function Scene5() {
  return (
    <Sprite start={T.s5[0]} end={T.s5[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        // WiFi failure happens around lt=3.5, recovers around lt=5.0
        const wifiDown = lt > 3.5 && lt < 5.0;
        const using4G = wifiDown;
        // Brief offline window during failover handover
        const offlineWindow = lt > 3.5 && lt < 3.85;
        const deviceStatus = offlineWindow ? 'offline' : 'online';

        const devX = 220, devY = 440;
        const cloudX = 1240, cloudY = 480;
        const wifiY = 600;
        const fourGY = 780;

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            <Caption
              title="Wi-Fi primary."
              accent="4G backhaul."
              sub={<>MQTT travels over Wi-Fi by default. If the link drops, 4G LTE takes over.<br/>Telemetry never stops.</>}
              color={X3.blue}
              opacity={entry}
              maxWidth={780}
              subMaxWidth={760}
            />

            <DeviceFrame x={devX} y={devY} w={340} h={340} glowIntensity={0.6} status={deviceStatus}/>

            <Router x={760} y={wifiY - 30} kind="wifi" t={lt} disabled={wifiDown}/>
            <Router x={760} y={fourGY - 30} kind="4g" t={lt} active={using4G}/>

            <CloudInfra x={cloudX} y={cloudY - 40} t={lt}/>

            {/* WiFi path */}
            <PathFlow
              from={{ x: devX + 300, y: devY + 100 }}
              via={{ x: 820, y: wifiY }}
              to={{ x: cloudX - 20, y: cloudY + 60 }}
              color={wifiDown ? X3.textMute : X3.blue}
              label="Wi-Fi · MQTT/mTLS"
              t={lt}
              packetOffset={0}
              active={!wifiDown}
            />
            {/* 4G path */}
            <PathFlow
              from={{ x: devX + 300, y: devY + 200 }}
              via={{ x: 820, y: fourGY }}
              to={{ x: cloudX - 20, y: cloudY + 200 }}
              color={X3.violet}
              label="4G LTE · backhaul"
              t={lt}
              packetOffset={0.5}
              active={using4G}
              dim={!using4G}
            />

            {/* Status caption — centered below the 4G tower */}
            <div style={{
              position: 'absolute', left: 820, top: 1000,
              transform: 'translateX(-50%)',
              fontFamily: monoFont, fontSize: 16,
              color: X3.textMute, letterSpacing: '0.12em',
              textTransform: 'uppercase',
              display: 'flex', gap: 18, alignItems: 'center',
              opacity: entry,
              whiteSpace: 'nowrap',
            }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <div style={{
                  width: 10, height: 10, borderRadius: 5,
                  background: wifiDown ? '#666' : X3.status,
                  boxShadow: wifiDown ? 'none' : `0 0 8px ${X3.status}`,
                }}/>
                {wifiDown ? 'Wi-Fi DOWN' : 'Wi-Fi · primary'}
              </div>
              <span>·</span>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <div style={{
                  width: 10, height: 10, borderRadius: 5,
                  background: using4G ? X3.violet : '#444',
                  boxShadow: using4G ? `0 0 8px ${X3.violet}` : 'none',
                }}/>
                {using4G ? '4G ACTIVE · failover' : '4G · standby'}
              </div>
              <span>·</span>
              <span>mTLS · QoS 1</span>
            </div>

            {/* Failover banner during wifi-down */}
            {wifiDown && (
              <div style={{
                position: 'absolute', left: 820, top: 440,
                transform: 'translateX(-50%)',
                padding: '10px 22px',
                background: `${X3.violet}22`,
                border: `1px solid ${X3.violet}`,
                borderRadius: 999,
                fontFamily: monoFont, fontSize: 14,
                color: X3.violet, letterSpacing: '0.12em',
                textTransform: 'uppercase',
                fontWeight: 600,
              }}>FAILED OVER TO 4G · TELEMETRY CONTINUING</div>
            )}
          </div>
        );
      }}
    </Sprite>
  );
}

// Cloud infrastructure (multi-region)
function CloudInfra({ x, y, t }) {
  return (
    <div style={{
      position: 'absolute', left: x, top: y,
      width: 600, height: 510,
      background: 'linear-gradient(180deg, #181818 0%, #0e0e0e 100%)',
      border: `1px solid ${X3.border}`,
      borderRadius: 18,
      padding: 26,
      boxShadow: '0 16px 60px rgba(0,0,0,0.6)',
    }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 20 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <img src="assets/synergyot-logo.png" alt="SynergyOT" style={{ height: 32, filter: 'brightness(1.1)' }}/>
          <div style={{ fontFamily: monoFont, fontSize: 14, color: X3.textMute, letterSpacing: '0.14em' }}>CLOUD</div>
        </div>
        <div style={{
          fontFamily: monoFont, fontSize: 14,
          color: X3.status, letterSpacing: '0.12em',
          display: 'flex', alignItems: 'center', gap: 8,
        }}>
          <div style={{ width: 9, height: 9, borderRadius: 4.5, background: X3.status, boxShadow: `0 0 8px ${X3.status}` }}/>
          UPTIME 99.99%
        </div>
      </div>

      {/* MQTT broker tiles */}
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
        {[
          { name: 'Broker · ap-south-1', kind: 'broker' },
          { name: 'Broker · eu-west-1',  kind: 'broker' },
          { name: 'TimescaleDB · cluster', kind: 'db' },
          { name: 'AI Inference · GPU', kind: 'ai' },
        ].map((s, i) => {
          const blink = (Math.floor(t * 2) + i) % 4 === 0;
          return (
            <div key={i} style={{
              padding: '14px 16px',
              background: 'rgba(255,255,255,0.03)',
              border: `1px solid ${X3.border}`,
              borderRadius: 8,
              display: 'flex', flexDirection: 'column', gap: 6,
            }}>
              <div style={{
                fontFamily: monoFont, fontSize: 13,
                color: X3.textMute, letterSpacing: '0.1em', textTransform: 'uppercase',
              }}>{s.kind}</div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <div style={{
                  width: 9, height: 9, borderRadius: 4.5,
                  background: X3.status,
                  boxShadow: blink ? `0 0 8px ${X3.status}` : 'none',
                  opacity: blink ? 1 : 0.6,
                }}/>
                <div style={{ fontFamily: sansFont, fontSize: 16, color: '#fff', fontWeight: 500 }}>{s.name}</div>
              </div>
            </div>
          );
        })}
      </div>

      {/* Data flow indicator */}
      <div style={{ marginTop: 22, display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{ fontFamily: monoFont, fontSize: 13, color: X3.textMute, letterSpacing: '0.1em', textTransform: 'uppercase' }}>INGEST · LAST 60s</div>
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
          <div style={{ fontFamily: monoFont, fontSize: 44, fontWeight: 600, color: X3.teal, fontVariantNumeric: 'tabular-nums' }}>
            {Math.round(12400 + Math.sin(t * 1.5) * 200).toLocaleString()}
          </div>
          <div style={{ fontFamily: monoFont, fontSize: 16, color: X3.textDim }}>msg</div>
        </div>
      </div>

      <div style={{
        marginTop: 18,
        fontFamily: monoFont, fontSize: 13,
        color: X3.textMute, letterSpacing: '0.1em',
      }}>SOC 2 · ISO 27001 · GDPR · MQTT 5.0</div>
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 6 — Distributed AI: edge + cloud (cost savings)
// ───────────────────────────────────────────────────────────────────
function Scene6() {
  return (
    <Sprite start={T.s6[0]} end={T.s6[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        // Funnel layout — raw telemetry left, filter at center, sparse events right, cloud far right.
        const inletX = 100, inletY = 440;        // raw stream origin
        const filterCX = 760, filterCY = 600;    // center of edge device
        const outletX = 1180, outletY = 600;     // sparse stream start
        const cloudCX = 1620, cloudCY = 600;     // cloud target

        // Animated particle streams (deterministic, time-based)
        const rawCount = 60;
        const evtCount = 6;

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            <Caption
              title={<span style={{ whiteSpace: 'nowrap' }}>Compute where it costs less.</span>}
              accent=""
              sub={<>Inference runs at the edge. Raw telemetry stays local;<br/>only events and aggregates reach the cloud, drastically lower cloud spend.</>}
              color={X3.teal}
              opacity={entry}
              maxWidth={1100}
              subMaxWidth={820}
            />

            {/* SVG overlay for funnel + particle streams */}
            <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none' }}>
              <defs>
                <linearGradient id="funnelMouth" x1="0" x2="1">
                  <stop offset="0%" stopColor={X3.amber} stopOpacity="0"/>
                  <stop offset="35%" stopColor={X3.amber} stopOpacity="0.55"/>
                  <stop offset="100%" stopColor={X3.amber} stopOpacity="0.85"/>
                </linearGradient>
                <linearGradient id="funnelOut" x1="0" x2="1">
                  <stop offset="0%" stopColor={X3.teal} stopOpacity="0.9"/>
                  <stop offset="100%" stopColor={X3.teal} stopOpacity="0"/>
                </linearGradient>
                <radialGradient id="cloudGlow">
                  <stop offset="0%" stopColor={X3.teal} stopOpacity="0.25"/>
                  <stop offset="100%" stopColor={X3.teal} stopOpacity="0"/>
                </radialGradient>
                <marker id="evtArrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto">
                  <path d="M 0 0 L 10 5 L 0 10 z" fill={X3.teal}/>
                </marker>
              </defs>

              {/* Funnel mouth (wide on left, narrows toward edge device) */}
              <path
                d={`M ${inletX} ${inletY - 130} L ${filterCX - 110} ${filterCY - 110} L ${filterCX - 110} ${filterCY + 110} L ${inletX} ${inletY + 290} Z`}
                fill="url(#funnelMouth)" opacity={entry * 0.7}
              />
              {/* Outlet (narrow stream from device → cloud) */}
              <path
                d={`M ${filterCX + 110} ${filterCY - 14} L ${outletX} ${outletY - 6} L ${cloudCX - 90} ${cloudCY - 4} L ${cloudCX - 90} ${cloudCY + 4} L ${outletX} ${outletY + 6} L ${filterCX + 110} ${filterCY + 14} Z`}
                fill="url(#funnelOut)" opacity={entry * 0.6}
              />

              {/* Funnel guide rails */}
              <path d={`M ${inletX} ${inletY - 130} L ${filterCX - 110} ${filterCY - 110}`}
                stroke={X3.amber} strokeWidth="1.2" opacity="0.5"/>
              <path d={`M ${inletX} ${inletY + 290} L ${filterCX - 110} ${filterCY + 110}`}
                stroke={X3.amber} strokeWidth="1.2" opacity="0.5"/>

              {/* Raw telemetry particles streaming into funnel */}
              {Array.from({ length: rawCount }).map((_, i) => {
                const seed = i * 0.137;
                const speed = 0.22 + (i % 5) * 0.04;
                const phase = (lt * speed + seed) % 1;
                const yJitter = (Math.sin(i * 1.7) + 1) / 2; // 0..1
                // Particle x progresses from inletX → filterCX-110 over phase 0..1
                const px = inletX + phase * (filterCX - 110 - inletX);
                // y at funnel mouth (wide), narrowing to ±110 around filterCY
                const wideY = inletY - 130 + yJitter * 420;
                const narrowY = filterCY - 100 + yJitter * 200;
                const py = wideY + phase * (narrowY - wideY);
                const o = phase < 0.85 ? 0.7 : (1 - phase) / 0.15 * 0.7;
                return (
                  <circle key={`r${i}`} cx={px} cy={py} r="1.6" fill={X3.amber} opacity={o * entry}/>
                );
              })}

              {/* Sparse event packets streaming out to cloud */}
              {Array.from({ length: evtCount }).map((_, i) => {
                const phase = ((lt * 0.32) + i / evtCount) % 1;
                const px = (filterCX + 110) + phase * (cloudCX - 90 - (filterCX + 110));
                const py = filterCY + Math.sin(phase * Math.PI * 2 + i) * 2;
                return (
                  <g key={`e${i}`} opacity={entry}>
                    <rect x={px - 8} y={py - 5} width="16" height="10" rx="2"
                      fill={X3.teal} opacity="0.18" stroke={X3.teal} strokeWidth="1"/>
                  </g>
                );
              })}

              {/* Cloud glow */}
              <circle cx={cloudCX} cy={cloudCY} r="160" fill="url(#cloudGlow)" opacity={entry}/>
            </svg>

            {/* LABELS along the flow */}
            {/* Stage 1: Raw telemetry — sits inside the funnel body, closer to the narrow end */}
            <div style={{
              position: 'absolute', left: 200, top: 520,
              opacity: entry,
              fontFamily: monoFont, fontSize: 11,
              color: X3.amber, letterSpacing: '0.18em', textTransform: 'uppercase',
              textAlign: 'center',
              display: 'flex', flexDirection: 'column', alignItems: 'center',
            }}>
              <div style={{
                padding: '6px 12px',
                background: 'rgba(20,16,8,0.85)',
                border: `1px solid ${X3.amber}88`,
                borderRadius: 4,
                display: 'inline-block',
              }}>Raw telemetry · ~10k pts/min</div>
              <div style={{
                marginTop: 10,
                fontFamily: sansFont, fontSize: 56, fontWeight: 700,
                color: X3.amber, letterSpacing: '-0.03em',
                textTransform: 'none',
                textShadow: `0 0 24px ${X3.amber}55`,
              }}>100%</div>
              <div style={{
                fontFamily: sansFont, fontSize: 13, fontWeight: 400,
                color: X3.textDim, letterSpacing: 0,
                textTransform: 'none',
                marginTop: -4,
              }}>volts · amps · temps · strings</div>
            </div>

            {/* Stage 2: Edge device (filter) */}
            <DeviceFrame x={filterCX - 110} y={filterCY - 110} w={220} h={220} glowIntensity={0.85} status="online"/>
            <div style={{
              position: 'absolute', left: filterCX, top: filterCY - 200,
              transform: 'translateX(-50%)',
              opacity: entry,
              textAlign: 'center',
              whiteSpace: 'nowrap',
            }}>
              <div style={{
                padding: '6px 12px',
                background: 'rgba(8,16,16,0.9)',
                border: `1px solid ${X3.teal}aa`,
                borderRadius: 4,
                fontFamily: monoFont, fontSize: 11,
                color: X3.teal, letterSpacing: '0.16em', textTransform: 'uppercase',
                display: 'inline-block',
                boxShadow: `0 0 16px ${X3.teal}44`,
              }}>X3EDGE · Inference + filter</div>
            </div>
            {/* Floating model chips around device */}
            {['ANOMALY', 'FORECAST', 'SOILING'].map((m, i) => (
              <div key={m} style={{
                position: 'absolute',
                left: filterCX + [-180, 90, -50][i],
                top: filterCY + [-30, -60, 130][i],
                padding: '4px 9px',
                background: 'rgba(20,20,20,0.95)',
                border: `1px solid ${X3.teal}`,
                borderRadius: 4,
                fontFamily: monoFont, fontSize: 9,
                color: X3.teal, letterSpacing: '0.12em',
                transform: `translateY(${Math.sin(lt * 1.5 + i) * 4}px)`,
                boxShadow: `0 0 12px ${X3.teal}33`,
                opacity: entry,
              }}>{m}</div>
            ))}

            {/* Stage 3: Events to cloud */}
            <div style={{
              position: 'absolute', left: 1100, top: 440,
              opacity: entry,
              textAlign: 'center',
            }}>
              <div style={{
                padding: '6px 12px',
                background: 'rgba(8,16,16,0.85)',
                border: `1px solid ${X3.teal}aa`,
                borderRadius: 4,
                fontFamily: monoFont, fontSize: 11,
                color: X3.teal, letterSpacing: '0.18em', textTransform: 'uppercase',
                display: 'inline-block',
              }}>Events · aggregates · alerts</div>
              <div style={{
                marginTop: 10,
                fontFamily: sansFont, fontSize: 56, fontWeight: 700,
                color: X3.teal, letterSpacing: '-0.03em',
                textShadow: `0 0 24px ${X3.teal}aa`,
              }}>10%</div>
              <div style={{
                fontFamily: sansFont, fontSize: 13, fontWeight: 400,
                color: X3.textDim,
                marginTop: -4,
              }}>only what matters</div>
            </div>

            {/* Stage 4: Cloud icon */}
            <svg width="180" height="120" viewBox="0 0 180 120" style={{
              position: 'absolute', left: cloudCX - 90, top: cloudCY - 60,
              opacity: entry,
            }}>
              <path d="M40 80 a26 26 0 0 1 20 -44 a32 30 0 0 1 60 6 a22 22 0 0 1 22 38 Z"
                fill="rgba(20,28,28,0.85)" stroke={X3.teal} strokeWidth="1.6"/>
              <text x="90" y="68" textAnchor="middle"
                fontFamily={monoFont} fontSize="13" fill={X3.teal}
                letterSpacing="2.5" fontWeight="600">CLOUD</text>
            </svg>
            <div style={{
              position: 'absolute', left: cloudCX, top: cloudCY + 90,
              transform: 'translateX(-50%)',
              opacity: entry,
              fontFamily: monoFont, fontSize: 11,
              color: X3.textDim, letterSpacing: '0.18em', textTransform: 'uppercase',
              whiteSpace: 'nowrap',
              textAlign: 'center',
            }}>Training · Analytics</div>

            {/* HERO outcome strip — bottom */}
            <div style={{
              position: 'absolute', left: '50%', top: 950,
              transform: 'translateX(-50%)',
              opacity: entry,
              display: 'flex', alignItems: 'center', gap: 28,
              padding: '16px 36px',
              background: 'linear-gradient(180deg, rgba(20,40,38,0.7) 0%, rgba(8,16,16,0.95) 100%)',
              border: `1px solid ${X3.teal}88`,
              borderRadius: 14,
              boxShadow: `0 0 40px ${X3.teal}33`,
            }}>
              <div style={{
                fontFamily: sansFont, fontSize: 28, fontWeight: 700,
                color: X3.teal, letterSpacing: '-0.01em',
                textShadow: `0 0 14px ${X3.teal}88`,
                whiteSpace: 'nowrap',
              }}>10× lower cloud spend.</div>
              <div style={{
                width: 1, height: 32, background: `${X3.teal}55`,
              }}/>
              <div style={{
                fontFamily: monoFont, fontSize: 11,
                color: X3.textDim, letterSpacing: '0.14em', textTransform: 'uppercase',
                lineHeight: 1.55,
                maxWidth: 360,
              }}>Select between minute-level data to cloud<br/>or only edge AI-detected events</div>
            </div>
          </div>
        );
      }}
    </Sprite>
  );
}

function AIAlertsFeed({ lt }) {
  const allAlerts = [
    { sev: 'critical', icon: 'comm',     site: 'Mumbai-08',    msg: 'Communication loss · INV-14',    detail: 'No telemetry for 4m 12s · auto-ticket opened',   age: '2m ago' },
    { sev: 'warning',  icon: 'soiling',  site: 'Jaipur-02',    msg: 'Soiling detected · Block C',     detail: 'PR ↓ 7.4% vs cohort · cleaning recommended',     age: '14m ago' },
    { sev: 'warning',  icon: 'underperf',site: 'Pune-11',      msg: 'String underperformance · MPPT-3', detail: 'Output 18% below modeled · check connectors',  age: '38m ago' },
    { sev: 'info',     icon: 'forecast', site: 'Chennai-04',   msg: 'Generation forecast revised',    detail: 'Cloud cover ↑ · expected −12% next 6h',          age: '1h ago' },
    { sev: 'critical', icon: 'fault',    site: 'Hyderabad-01', msg: 'Ground fault detected',          detail: 'Riso below threshold · INV-07 isolated',         age: '1h ago' },
  ];
  // Stagger entry of alerts
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 7, overflow: 'hidden' }}>
      {allAlerts.map((a, i) => {
        const reveal = clamp((lt - 0.8 - i * 0.25) * 2.5, 0, 1);
        const sevColor = a.sev === 'critical' ? '#ff5555' : a.sev === 'warning' ? X3.amber : X3.blue;
        const sevBg = a.sev === 'critical' ? 'rgba(255,80,80,0.08)' : a.sev === 'warning' ? `${X3.amber}11` : `${X3.blue}11`;
        return (
          <div key={i} style={{
            display: 'flex', alignItems: 'center', gap: 12,
            padding: '8px 12px',
            background: sevBg,
            border: `1px solid ${sevColor}55`,
            borderLeft: `3px solid ${sevColor}`,
            borderRadius: 6,
            opacity: reveal,
            transform: `translateX(${(1 - reveal) * 12}px)`,
          }}>
            <AlertIcon kind={a.icon} color={sevColor}/>
            <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <div style={{ fontFamily: sansFont, fontSize: 12, color: '#fff', fontWeight: 600 }}>{a.msg}</div>
                <div style={{ fontFamily: monoFont, fontSize: 9, color: X3.textMute, letterSpacing: '0.1em' }}>· {a.site}</div>
              </div>
              <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textDim, lineHeight: 1.3, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{a.detail}</div>
            </div>
            <div style={{
              fontFamily: monoFont, fontSize: 9,
              color: X3.textMute, letterSpacing: '0.08em',
              whiteSpace: 'nowrap',
            }}>{a.age}</div>
          </div>
        );
      })}
    </div>
  );
}

function AlertIcon({ kind, color }) {
  const size = 22;
  const common = { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: color, strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' };
  const wrap = (children) => (
    <div style={{
      width: 32, height: 32, borderRadius: 6,
      background: `${color}18`, border: `1px solid ${color}55`,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      flexShrink: 0,
    }}>{children}</div>
  );
  if (kind === 'comm') return wrap(
    <svg {...common}>
      <path d="M3 3 L21 21"/>
      <path d="M5 13 Q12 7 15 9"/>
      <path d="M8 16 Q11 14 13 14.5"/>
      <circle cx="11" cy="19" r="1" fill={color}/>
    </svg>
  );
  if (kind === 'soiling') return wrap(
    <svg {...common}>
      <rect x="4" y="6" width="16" height="11" rx="1"/>
      <path d="M4 10 L20 10 M4 14 L20 14 M9 6 L9 17 M14 6 L14 17"/>
      <circle cx="8" cy="9" r="0.8" fill={color}/>
      <circle cx="16" cy="13" r="0.8" fill={color}/>
      <circle cx="11" cy="15" r="0.8" fill={color}/>
    </svg>
  );
  if (kind === 'underperf') return wrap(
    <svg {...common}>
      <path d="M3 6 L7 10 L12 7 L16 12 L21 17"/>
      <path d="M16 17 L21 17 L21 12"/>
    </svg>
  );
  if (kind === 'forecast') return wrap(
    <svg {...common}>
      <circle cx="8" cy="8" r="3"/>
      <path d="M14 14 a4 4 0 0 0 -8 0 a3 3 0 0 0 0 6 h11 a3 3 0 0 0 1 -5.8"/>
    </svg>
  );
  if (kind === 'fault') return wrap(
    <svg {...common}>
      <path d="M13 3 L5 13 L11 13 L10 21 L19 10 L13 10 Z" fill={`${color}44`}/>
    </svg>
  );
  return wrap(<svg {...common}><circle cx="12" cy="12" r="8"/></svg>);
}

function RupeeStack({ label, count, color, sub, t, highlight }) {
  // Render `count` stacked ₹ symbols growing in
  const rows = [];
  for (let i = 0; i < count; i++) {
    const reveal = clamp((t * count - i) / 0.6, 0, 1);
    rows.push(
      <span key={i} style={{
        fontFamily: sansFont, fontSize: 36, fontWeight: 700,
        color, opacity: reveal,
        textShadow: highlight ? `0 0 16px ${color}66` : 'none',
        transform: `translateY(${(1 - reveal) * 6}px)`,
        display: 'inline-block',
      }}>₹</span>
    );
  }
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 10, minWidth: 260 }}>
      <div style={{
        display: 'flex', flexWrap: 'wrap', gap: 6,
        maxWidth: 240, lineHeight: 1,
      }}>{rows}</div>
      <div style={{ fontFamily: monoFont, fontSize: 11, color: X3.textMute, letterSpacing: '0.16em', textTransform: 'uppercase' }}>{label}</div>
      <div style={{ fontFamily: monoFont, fontSize: 11, color: X3.textDim }}>{sub}</div>
    </div>
  );
}

function CostBar({ label, value, color, height, sub, highlight }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 8, minWidth: 220 }}>
      <div style={{
        height: Math.max(8, height), width: 200,
        background: `linear-gradient(180deg, ${color} 0%, ${color}55 100%)`,
        borderRadius: 4,
        boxShadow: highlight ? `0 0 24px ${color}66` : 'none',
        transition: 'height 200ms',
      }}/>
      <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textMute, letterSpacing: '0.14em', textTransform: 'uppercase' }}>{label}</div>
      <div style={{ fontFamily: monoFont, fontSize: 20, color: '#fff', fontWeight: 600, fontVariantNumeric: 'tabular-nums' }}>{value}</div>
      <div style={{ fontFamily: monoFont, fontSize: 10, color: X3.textDim }}>{sub}</div>
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 7 — SynergyOT: API or X3EDGE (MNRE compliant)
// ───────────────────────────────────────────────────────────────────
function Scene7() {
  return (
    <Sprite start={T.s7[0]} end={T.s7[1] + 0.4}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            {/* Animated SynergyOT logo with radiating glow + scanning shimmer */}
            <div style={{
              position: 'absolute', left: '50%', top: 110,
              transform: 'translateX(-50%)',
              opacity: entry,
              width: 660, height: 140,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
            }}>
              {/* Pulsing glow halo behind logo */}
              <div style={{
                position: 'absolute', inset: 0,
                background: `radial-gradient(ellipse at center, ${X3.amber}55 0%, transparent 60%)`,
                filter: 'blur(38px)',
                opacity: 0.5 + 0.5 * Math.sin(lt * 2.2),
                pointerEvents: 'none',
              }}/>
              {/* Radiating rays */}
              <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', overflow: 'visible' }} viewBox="0 0 660 140">
                {Array.from({ length: 10 }).map((_, i) => {
                  const angle = (i / 10) * Math.PI * 2;
                  const r1 = 76 + (lt * 50 + i * 10) % 100;
                  const r2 = r1 + 22;
                  const cx = 330 + Math.cos(angle) * r1;
                  const cy = 70 + Math.sin(angle) * r1 * 0.6;
                  const cx2 = 330 + Math.cos(angle) * r2;
                  const cy2 = 70 + Math.sin(angle) * r2 * 0.6;
                  const op = Math.max(0, 1 - ((r1 - 76) / 100));
                  return (
                    <line key={i} x1={cx} y1={cy} x2={cx2} y2={cy2}
                      stroke={X3.amber} strokeWidth="2.5" strokeLinecap="round" opacity={op * 0.5}/>
                  );
                })}
              </svg>
              <img src="assets/synergyot-logo.png" alt="SynergyOT" style={{
                height: 104,
                position: 'relative', zIndex: 2,
                transform: `scale(${1 + 0.015 * Math.sin(lt * 2.2)})`,
                filter: `drop-shadow(0 0 30px ${X3.amber}66)`,
              }}/>
            </div>

            <div style={{
              position: 'absolute', left: '50%', top: 270,
              transform: `translateX(-50%)`,
              opacity: entry,
              fontFamily: sansFont, fontSize: 60, fontWeight: 700,
              color: X3.text, letterSpacing: '-0.022em',
              textAlign: 'center',
              lineHeight: 1.1,
            }}>
              Two paths in.<br/>
              <span style={{ color: X3.amber, fontSize: 34, fontWeight: 500 }}>Pick whichever fits your fleet.</span>
            </div>

            {/* Two cards: API path & X3EDGE path */}
            <div style={{
              position: 'absolute', left: '50%', top: 470,
              transform: 'translateX(-50%)',
              display: 'flex', gap: 56,
              opacity: entry,
            }}>
              {/* Card 1: API */}
              <div style={{
                width: 700, padding: 38,
                background: 'linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01))',
                border: `1px solid ${X3.border}`,
                borderRadius: 20,
                display: 'flex', flexDirection: 'column', gap: 18,
              }}>
                <div style={{
                  fontFamily: monoFont, fontSize: 13,
                  color: X3.teal, letterSpacing: '0.16em', textTransform: 'uppercase',
                }}>OPTION A · Already on a portal?</div>
                <div style={{ fontFamily: sansFont, fontSize: 42, fontWeight: 700, color: X3.text, letterSpacing: '-0.02em', lineHeight: 1.05 }}>
                  Connect via <span style={{ color: X3.teal }}>API</span>.
                </div>
                <div style={{ fontFamily: sansFont, fontSize: 19, color: X3.textDim, lineHeight: 1.5 }}>
                  Use your existing Growatt, Solis, GoodWe, SMA or Sungrow portal credentials. SynergyOT pulls telemetry from each vendor cloud.
                </div>
                {/* Code snippet */}
                <div style={{
                  marginTop: 8,
                  background: 'rgba(0,0,0,0.6)',
                  border: `1px solid ${X3.border}`,
                  borderRadius: 10,
                  padding: '16px 18px',
                  fontFamily: monoFont, fontSize: 16,
                  color: X3.text,
                  lineHeight: 1.6,
                }}>
                  <div style={{ color: X3.textMute }}>// vendor: growatt</div>
                  <div><span style={{ color: X3.teal }}>POST</span> /v1/sources/connect</div>
                  <div><span style={{ color: X3.amber }}>{'{'}</span> &quot;api_key&quot;: &quot;***&quot; <span style={{ color: X3.amber }}>{'}'}</span></div>
                  <div style={{ color: X3.status, marginTop: 6 }}>✓ 4 inverters discovered</div>
                </div>
              </div>

              {/* Card 2: X3EDGE Device */}
              <div style={{
                width: 700, padding: 38,
                background: `linear-gradient(180deg, ${X3.amber}11, ${X3.amber}03)`,
                border: `1px solid ${X3.amber}66`,
                borderRadius: 20,
                display: 'flex', flexDirection: 'column', gap: 18,
                boxShadow: `0 0 50px ${X3.amber}22`,
                position: 'relative',
              }}>
                {/* Animated MNRE shield — top-right corner */}
                <div style={{
                  position: 'absolute', top: -22, right: -22,
                  width: 124, height: 124,
                  transform: `scale(${0.7 + 0.3 * clamp((lt - 0.5) / 0.5, 0, 1)}) rotate(${-6 + 2 * Math.sin(lt * 1.6)}deg)`,
                  opacity: clamp((lt - 0.5) / 0.5, 0, 1),
                }}>
                  {/* Pulsing halo */}
                  <div style={{
                    position: 'absolute', inset: -10,
                    background: `radial-gradient(circle, ${X3.amber}66 0%, transparent 70%)`,
                    filter: 'blur(10px)',
                    opacity: 0.5 + 0.5 * Math.sin(lt * 3),
                  }}/>
                  <svg viewBox="0 0 100 100" style={{ position: 'relative', width: '100%', height: '100%' }}>
                    {/* Shield shape */}
                    <defs>
                      <linearGradient id="mnreShield" x1="0" y1="0" x2="0" y2="1">
                        <stop offset="0%" stopColor={X3.amber} stopOpacity="1"/>
                        <stop offset="100%" stopColor="#c97a1f" stopOpacity="1"/>
                      </linearGradient>
                    </defs>
                    <path d="M50 5 L88 18 L88 52 Q88 78 50 95 Q12 78 12 52 L12 18 Z"
                      fill="url(#mnreShield)" stroke="#fff" strokeWidth="2"/>
                    {/* Ashoka chakra (24-spoke wheel) */}
                    <g transform="translate(50, 34)">
                      <circle r="14" fill="none" stroke="#fff" strokeWidth="1.5"/>
                      <circle r="3" fill="#fff"/>
                      {Array.from({length: 24}).map((_, i) => {
                        const a = (i * 15) * Math.PI / 180;
                        return (
                          <line key={i}
                            x1={Math.cos(a) * 3} y1={Math.sin(a) * 3}
                            x2={Math.cos(a) * 14} y2={Math.sin(a) * 14}
                            stroke="#fff" strokeWidth="0.8"/>
                        );
                      })}
                    </g>
                    <text x="50" y="68" textAnchor="middle"
                      fontFamily={monoFont} fontSize="12" fontWeight="800"
                      fill="#fff" letterSpacing="0.5">MNRE</text>
                    <text x="50" y="80" textAnchor="middle"
                      fontFamily={monoFont} fontSize="5" fontWeight="700"
                      fill="#fff" letterSpacing="0.1" opacity="0.85">COMPLIANT*</text>
                  </svg>
                </div>

                <div style={{
                  fontFamily: monoFont, fontSize: 13,
                  color: X3.amber, letterSpacing: '0.16em', textTransform: 'uppercase',
                  paddingRight: 110,
                }}>OPTION B · No portal?</div>
                <div style={{ fontFamily: sansFont, fontSize: 42, fontWeight: 700, color: X3.text, letterSpacing: '-0.02em', lineHeight: 1.05 }}>
                  Plug in the <span style={{ color: X3.amber }}>X3EDGE</span> device.
                </div>
                <div style={{ fontFamily: sansFont, fontSize: 19, color: X3.textDim, lineHeight: 1.5 }}>
                  For sites without vendor portals, or with mixed-brand fleets. The X3EDGE-N is <span style={{ color: X3.amber, fontWeight: 600 }}>MNRE-Compliant*</span> for Indian deployments under the <span style={{ color: X3.text }}>ALMM List-II</span> framework.
                </div>
                {/* Bullet list */}
                <div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginTop: 8 }}>
                  <div style={{ fontFamily: monoFont, fontSize: 16, color: X3.text, letterSpacing: '0.06em' }}>· Vendor agnostic · 200+ inverter models</div>
                  <div style={{ fontFamily: monoFont, fontSize: 16, color: X3.text, letterSpacing: '0.06em' }}>· Eligible for PM Surya Ghar / KUSUM subsidies</div>
                  <div style={{ fontFamily: monoFont, fontSize: 16, color: X3.text, letterSpacing: '0.06em' }}>· Edge AI on-device · works on selected legacy gear</div>
                </div>
                {/* Footnote — explains the asterisk on MNRE-Compliant* */}
                <div style={{
                  marginTop: 14,
                  paddingTop: 14,
                  borderTop: `1px solid ${X3.amber}33`,
                  fontFamily: monoFont, fontSize: 13,
                  color: X3.textMute, letterSpacing: '0.04em',
                  lineHeight: 1.5,
                }}>
                  <span style={{ color: X3.amber, fontWeight: 700 }}>*</span> In compliance with upcoming MNRE Firmware guidelines for data loggers.
                </div>
              </div>
            </div>
          </div>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────────────────────────────────────────────
// SCENE 8 — Beyond inverters: trackers, BMS, EV, meters
// ───────────────────────────────────────────────────────────────────
function Scene8() {
  return (
    <Sprite start={T.s8[0]} end={T.s8[1]}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.6, 0, 1));
        const exit = lt > duration - 0.6 ? clamp((lt - (duration - 0.6)) / 0.6, 0, 1) : 0;
        const op = entry * (1 - exit);

        const devX = 880, devY = 320;

        const assets = [
          { id: 0, name: 'Solar Inverters', icon: 'inverter',  angle: -90,  delay: 0.2,  color: X3.amber },
          { id: 1, name: 'Solar Trackers',  icon: 'tracker',   angle: -45,  delay: 0.4,  color: X3.amber },
          { id: 2, name: 'Battery / BMS',   icon: 'battery',   angle: 0,    delay: 0.6,  color: X3.teal },
          { id: 3, name: 'EV Chargers',     icon: 'ev',        angle: 45,   delay: 0.8,  color: X3.teal },
          { id: 4, name: 'Energy Meters',   icon: 'meter',     angle: 90,   delay: 1.0,  color: X3.blue },
          { id: 5, name: 'Wind Turbines',   icon: 'wind',      angle: 135,  delay: 1.2,  color: X3.blue },
          { id: 6, name: 'Sensors',         icon: 'sensor',    angle: 180,  delay: 1.4,  color: X3.violet },
          { id: 7, name: 'Gensets',         icon: 'genset',    angle: -135, delay: 1.6,  color: X3.violet },
        ];
        const radius = 320;

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#0a0a0a', opacity: op }}>
            <BackgroundGrid/>

            {/* Title */}
            <div style={{
              position: 'absolute', left: 80, top: 110,
              opacity: entry, transform: `translateY(${(1-entry)*10}px)`,
              maxWidth: 540,
            }}>
              <Pill x={0} y={0} text="ONE PLATFORM. EVERY ASSET." color={X3.amber}/>
              <div style={{
                marginTop: 50,
                fontFamily: sansFont, fontSize: 60, fontWeight: 700,
                color: X3.text, letterSpacing: '-0.022em', lineHeight: 1.02,
              }}>
                Not just<br/>
                <span style={{ color: X3.amber }}>solar inverters.</span>
              </div>
              <div style={{
                marginTop: 22, maxWidth: 480,
                fontFamily: sansFont, fontSize: 18, lineHeight: 1.5,
                color: X3.textDim,
              }}>
                X3EDGE-N speaks Modbus, CAN, OCPP and IEC 61850, connecting trackers, BMS, EV chargers and meters to SynergyOT.
              </div>

              {/* Brand strip */}
              <div style={{
                marginTop: 36,
                fontFamily: monoFont, fontSize: 11,
                color: X3.textMute, letterSpacing: '0.16em',
                textTransform: 'uppercase',
              }}>
                MODBUS · CAN · OCPP · IEC 61850 · BACNET
              </div>
            </div>

            {/* Center: device */}
            <DeviceFrame x={devX - 80} y={devY} w={340} h={340} glowIntensity={0.7 + 0.3 * Math.sin(lt * 4)} status="online"/>

            {/* Asset constellation */}
            {assets.map((a, i) => {
              const cx = devX + 90;
              const cy = devY + 170;
              const angleRad = (a.angle * Math.PI) / 180;
              const ax = cx + Math.cos(angleRad) * radius;
              const ay = cy + Math.sin(angleRad) * radius;
              const reveal = e.easeOutBack(clamp((lt - a.delay) / 0.6, 0, 1));
              if (reveal <= 0) return null;
              // Pulse a packet from asset → device
              const pulsePhase = ((lt + i * 0.3) * 0.6) % 1;
              return (
                <React.Fragment key={a.id}>
                  {/* Connection line */}
                  <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none' }}>
                    <line x1={cx} y1={cy} x2={ax} y2={ay}
                      stroke={a.color} strokeWidth="1" opacity={0.3 * reveal} strokeDasharray="3 6"/>
                  </svg>
                  {/* Traveling packet */}
                  <div style={{
                    position: 'absolute',
                    left: cx + (ax - cx) * (1 - pulsePhase) - 4,
                    top:  cy + (ay - cy) * (1 - pulsePhase) - 4,
                    width: 8, height: 8, borderRadius: 4,
                    background: a.color,
                    boxShadow: `0 0 12px ${a.color}`,
                    opacity: reveal,
                  }}/>
                  {/* Asset card */}
                  <div style={{
                    position: 'absolute',
                    left: ax - 80, top: ay - 56,
                    width: 160, height: 112,
                    background: 'linear-gradient(180deg, #181818, #0e0e0e)',
                    border: `1px solid ${a.color}55`,
                    borderRadius: 10,
                    padding: 12,
                    display: 'flex', flexDirection: 'column', gap: 8,
                    boxShadow: `0 0 24px ${a.color}33, 0 8px 24px rgba(0,0,0,0.5)`,
                    opacity: reveal,
                    transform: `scale(${0.85 + 0.15 * reveal})`,
                    transformOrigin: 'center',
                  }}>
                    <AssetIcon kind={a.icon} color={a.color}/>
                    <div style={{
                      fontFamily: sansFont, fontSize: 13, fontWeight: 600,
                      color: X3.text, letterSpacing: '-0.01em',
                    }}>{a.name}</div>
                  </div>
                </React.Fragment>
              );
            })}
          </div>
        );
      }}
    </Sprite>
  );
}

function AssetIcon({ kind, color }) {
  const props = { width: 26, height: 26, fill: 'none', stroke: color, strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' };
  switch (kind) {
    case 'inverter':
      return <svg viewBox="0 0 24 24" {...props}><rect x="4" y="5" width="16" height="14" rx="2"/><path d="M8 10 H16 M8 14 H13"/></svg>;
    case 'tracker':
      return <svg viewBox="0 0 24 24" {...props}><rect x="5" y="6" width="14" height="9" rx="1"/><path d="M12 15 V20 M9 20 H15 M5 4 L7 6 M19 4 L17 6"/></svg>;
    case 'battery':
      return <svg viewBox="0 0 24 24" {...props}><rect x="3" y="8" width="16" height="9" rx="1"/><rect x="19" y="11" width="2" height="3"/><path d="M7 12 L9 12 M12 10.5 L12 14.5 M14 12 L16 12"/></svg>;
    case 'ev':
      return <svg viewBox="0 0 24 24" {...props}><rect x="5" y="9" width="10" height="9" rx="1"/><path d="M5 13 H15 M15 11 H17 V14 M11 5 L9 9 H12 L10 13"/></svg>;
    case 'meter':
      return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="7"/><path d="M12 7 V12 L15 14"/></svg>;
    case 'wind':
      return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="9" r="1"/><path d="M12 9 L8 4 M12 9 L18 8 M12 9 L11 15 M11 15 L11 20 M9 20 H13"/></svg>;
    case 'sensor':
      return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="2.5"/><circle cx="12" cy="12" r="6" opacity="0.6"/><path d="M12 4 V6 M12 18 V20 M4 12 H6 M18 12 H20"/></svg>;
    case 'genset':
      return <svg viewBox="0 0 24 24" {...props}><rect x="4" y="8" width="16" height="10" rx="1"/><circle cx="9" cy="13" r="2"/><path d="M14 11 H17 M14 14 H17"/></svg>;
    default:
      return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="6"/></svg>;
  }
}

// ───────────────────────────────────────────────────────────────────
// SCENE 9 — Grow your portfolio: kW → multi-MW (CTA for EPCs / O&M)
// ───────────────────────────────────────────────────────────────────
function Scene9() {
  return (
    <Sprite start={T.s9[0]} end={T.s9[1]}>
      {({ localTime, duration }) => {
        const lt = localTime;
        const entry = e.easeOutCubic(clamp(lt / 0.7, 0, 1));
        const exit = lt > duration - 0.7 ? clamp((lt - (duration - 0.7)) / 0.7, 0, 1) : 0;
        const op = entry * (1 - exit);

        // Stage progression: 0 = single rooftop, 1 = small commercial, 2 = utility scale
        // 0..2.0s: stage 0 (kW)
        // 2.0..5.0s: stage 1 (hundreds of kW)
        // 5.0..end: stage 2 (multi-MW)
        const stage = lt < 2.0 ? 0 : lt < 5.0 ? 1 : 2;

        // Capacity ticker — eased exponential growth from 8 kW → 24 MW
        const growthT = clamp(lt / 7.0, 0, 1);
        const capacityKW = 8 * Math.pow(24000 / 8, growthT); // 8 → 24,000 kW
        const capStr = capacityKW < 1000
          ? `${capacityKW.toFixed(1)} kW`
          : `${(capacityKW / 1000).toFixed(2)} MW`;

        // Tile counts grow as portfolio scales
        const tilesShown = Math.min(96, Math.floor(growthT * 96) + 1);

        const tiles = Array.from({ length: 96 }).map((_, i) => {
          const col = i % 12;
          const row = Math.floor(i / 12);
          return { col, row, i };
        });

        return (
          <div style={{ position: 'absolute', inset: 0, background: '#070707', opacity: op }}>
            <BackgroundGrid/>

            {/* Caption */}
            <div style={{
              position: 'absolute', left: 100, top: 100,
              opacity: entry,
              transform: `translateY(${(1-entry)*10}px)`,
              maxWidth: 900,
            }}>
              {/* SynergyOT logo — large, prominent */}
              <div style={{
                marginTop: 0,
                display: 'flex', alignItems: 'center', gap: 24,
              }}>
                <img src="assets/synergyot-logo.png" alt="SynergyOT" style={{
                  height: 110,
                  filter: `drop-shadow(0 0 28px ${X3.amber}88)`,
                }}/>
                <div style={{
                  fontFamily: monoFont, fontSize: 13, color: X3.textMute,
                  letterSpacing: '0.22em', textTransform: 'uppercase',
                  borderLeft: `1px solid ${X3.amber}66`, paddingLeft: 20,
                  lineHeight: 1.6,
                }}>Powered by<br/><span style={{ color: X3.amber, fontSize: 16 }}>X3EDGE-N</span></div>
              </div>
              <div style={{
                marginTop: 36,
                fontFamily: sansFont, fontSize: 70, fontWeight: 700,
                color: X3.text, letterSpacing: '-0.025em', lineHeight: 0.96,
                whiteSpace: 'nowrap',
              }}>
                From kW to <span style={{ color: X3.amber }}>multi-MW.</span>
              </div>
              <div style={{
                marginTop: 22,
                fontFamily: sansFont, fontSize: 22, lineHeight: 1.4,
                color: X3.textDim, maxWidth: 700,
              }}>
                Built for EPCs and O&amp;M teams. One affordable device,
                one platform, one workflow that scales with every
                project you win.
              </div>
            </div>

            {/* Live capacity counter */}
            <div style={{
              position: 'absolute', left: 100, top: 480,
              opacity: entry,
              fontFamily: monoFont,
              padding: '20px 28px',
              background: 'rgba(20,20,20,0.85)',
              border: `1px solid ${X3.amber}66`,
              borderRadius: 8,
              boxShadow: `0 0 32px ${X3.amber}33`,
              minWidth: 360,
            }}>
              <div style={{ fontSize: 11, color: X3.textMute, letterSpacing: '0.22em', marginBottom: 8 }}>
                ▸ FLEET CAPACITY · LIVE
              </div>
              <div style={{
                fontSize: 60, fontWeight: 700,
                color: X3.amber,
                letterSpacing: '-0.02em',
                textShadow: `0 0 20px ${X3.amber}66`,
              }}>{capStr}</div>
              <div style={{ fontSize: 12, color: X3.teal, letterSpacing: '0.18em', marginTop: 6 }}>
                ↑ {(growthT * 100).toFixed(0)}% growth · {tilesShown} sites monitored
              </div>
            </div>

            {/* Stage labels */}
            <div style={{
              position: 'absolute', left: 100, top: 740,
              display: 'flex', gap: 18, opacity: entry,
            }}>
              {[
                { label: 'Residential · 8 kW', active: stage === 0, color: X3.amber },
                { label: 'C&I · 800 kW',       active: stage === 1, color: X3.teal },
                { label: 'Utility · 24 MW',    active: stage === 2, color: X3.blue },
              ].map((s, i) => (
                <div key={i} style={{
                  padding: '10px 16px',
                  border: `1px solid ${s.active ? s.color : X3.border}`,
                  background: s.active ? `${s.color}22` : 'rgba(255,255,255,0.02)',
                  borderRadius: 6,
                  fontFamily: monoFont, fontSize: 12,
                  color: s.active ? s.color : X3.textMute,
                  letterSpacing: '0.14em',
                  transition: 'all 0.4s',
                  boxShadow: s.active ? `0 0 16px ${s.color}55` : 'none',
                }}>
                  {s.label}
                </div>
              ))}
            </div>

            {/* Right side: growing site grid */}
            <div style={{
              position: 'absolute', right: 100, top: 180,
              width: 720, height: 600,
              opacity: entry,
            }}>
              <div style={{
                position: 'absolute', left: 0, top: -34,
                fontFamily: monoFont, fontSize: 11,
                color: X3.textMute, letterSpacing: '0.22em',
              }}>
                YOUR PORTFOLIO · ALL SITES, ONE PANE
              </div>

              {/* 12 × 8 grid of site tiles, lighting up over time */}
              <div style={{
                display: 'grid',
                gridTemplateColumns: 'repeat(12, 1fr)',
                gridTemplateRows: 'repeat(8, 1fr)',
                gap: 6,
                width: '100%', height: '100%',
              }}>
                {tiles.map(({ i, col, row }) => {
                  const active = i < tilesShown;
                  const fadeIn = active ? clamp((lt - (i / 96) * 6.5) * 6, 0, 1) : 0;
                  // Different asset color per tile
                  const colors = [X3.amber, X3.amber, X3.teal, X3.blue, X3.amber, X3.violet];
                  const tc = colors[i % colors.length];
                  // Mini live indicator pulse
                  const pulsePhase = ((lt * 1.2 + i * 0.07) % 1);
                  const pulseOn = pulsePhase < 0.4;
                  return (
                    <div key={i} style={{
                      borderRadius: 4,
                      background: active ? `${tc}1f` : 'rgba(255,255,255,0.02)',
                      border: `1px solid ${active ? `${tc}88` : X3.border}`,
                      opacity: active ? fadeIn : 0.25,
                      position: 'relative',
                      overflow: 'hidden',
                      transition: 'background 0.3s',
                    }}>
                      {active && (
                        <>
                          {/* Mini bar chart */}
                          <div style={{
                            position: 'absolute',
                            left: 4, right: 4, bottom: 4,
                            display: 'flex', gap: 1, alignItems: 'flex-end',
                            height: 16,
                          }}>
                            {[0, 1, 2, 3].map(b => {
                              const h = 30 + Math.abs(Math.sin(lt * 1.5 + i * 0.3 + b * 0.5)) * 70;
                              return (
                                <div key={b} style={{
                                  flex: 1,
                                  height: `${h}%`,
                                  background: tc,
                                  opacity: 0.7,
                                  borderRadius: 0.5,
                                }}/>
                              );
                            })}
                          </div>
                          {/* Live LED */}
                          <div style={{
                            position: 'absolute',
                            top: 4, right: 4,
                            width: 4, height: 4,
                            borderRadius: 2,
                            background: pulseOn ? '#22dd6e' : '#22dd6e44',
                            boxShadow: pulseOn ? '0 0 4px #22dd6e' : 'none',
                          }}/>
                        </>
                      )}
                    </div>
                  );
                })}
              </div>
            </div>

            {/* Bottom CTA bar */}
            <div style={{
              position: 'absolute', left: 100, bottom: 80,
              right: 100,
              display: 'flex', justifyContent: 'space-between', alignItems: 'center',
              opacity: clamp((lt - 1.5) / 1, 0, 1) * entry,
              padding: '20px 28px',
              background: 'linear-gradient(90deg, rgba(217,122,58,0.18) 0%, rgba(20,20,20,0.85) 100%)',
              border: `1px solid ${X3.amber}66`,
              borderRadius: 10,
            }}>
              <div>
                <div style={{
                  fontFamily: sansFont, fontSize: 28, fontWeight: 600,
                  color: X3.text, letterSpacing: '-0.01em',
                }}>
                  Win the next project. Onboard it in minutes.
                </div>
                <div style={{
                  fontFamily: monoFont, fontSize: 12, color: X3.textDim,
                  letterSpacing: '0.18em', marginTop: 8,
                }}>
                  X3EDGE-N · SYNERGYOT · BUILT IN INDIA · MNRE COMPLIANT
                </div>
              </div>
              <div style={{
                padding: '14px 28px',
                background: X3.amber,
                color: '#0a0a0a',
                fontFamily: sansFont, fontSize: 16, fontWeight: 700,
                letterSpacing: '0.06em',
                borderRadius: 6,
                boxShadow: `0 0 24px ${X3.amber}88`,
                textTransform: 'uppercase',
              }}>
                xeeed.io →
              </div>
            </div>
          </div>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────────────────────────────────────────────
// Shared sub-elements
// ───────────────────────────────────────────────────────────────────
function BackgroundGrid() {
  return (
    <div style={{
      position: 'absolute', inset: 0,
      backgroundImage: `linear-gradient(${X3.border} 1px, transparent 1px), linear-gradient(90deg, ${X3.border} 1px, transparent 1px)`,
      backgroundSize: '64px 64px',
      opacity: 0.5,
      maskImage: 'radial-gradient(ellipse at center, black 30%, transparent 80%)',
      WebkitMaskImage: 'radial-gradient(ellipse at center, black 30%, transparent 80%)',
    }}/>
  );
}

function DeviceFrame({ x, y, w, h, glowIntensity = 0.6, status = 'online', showLed = true }) {
  // Status colors: blue (BLE/pairing), green (online), red (offline)
  const ledColors = {
    ble:     { c: '#3a8dff', glow: 'rgba(58,141,255,0.9)' },
    online:  { c: '#22dd6e', glow: 'rgba(34,221,110,0.9)' },
    offline: { c: '#ff3b3b', glow: 'rgba(255,59,59,0.9)' },
  };
  const led = ledColors[status] || ledColors.online;
  // LED position on the device image (relative): the "STATUS" indicator dot
  // centroid sampled at (45.75%, 29.87%) of the 1080×1080 device image.
  const ledX = x + w * 0.4575;
  const ledY = y + h * 0.2987;
  const ledSize = Math.max(6, w * 0.024);

  // Pulse animation (driven by Date.now so it animates regardless of caller)
  const pulse = 0.55 + 0.45 * Math.sin(Date.now() / 280);

  return (
    <>
      <div style={{
        position: 'absolute',
        left: x - 60, top: y - 60,
        width: w + 120, height: h + 120,
        borderRadius: '50%',
        background: `radial-gradient(circle, ${X3.amber}33 0%, transparent 60%)`,
        filter: 'blur(30px)',
        opacity: glowIntensity,
        pointerEvents: 'none',
      }}/>
      <img
        src="assets/x3edge-device.png"
        alt="X3EDGE-N"
        style={{
          position: 'absolute',
          left: x, top: y, width: w, height: h,
          objectFit: 'contain',
          filter: 'drop-shadow(0 16px 32px rgba(0,0,0,0.6))',
        }}
      />
      {/* Status LED — pulsing colored dot, masking over the device's STATUS indicator */}
      {showLed && <div style={{
        position: 'absolute',
        left: ledX - ledSize / 2,
        top: ledY - ledSize / 2,
        width: ledSize, height: ledSize,
        borderRadius: '50%',
        background: `radial-gradient(circle, #fff 0%, ${led.c} 35%, ${led.c} 70%, ${led.c}88 100%)`,
        boxShadow: `0 0 ${ledSize * 1.4}px ${ledSize * 0.5}px ${led.glow}`,
        opacity: 0.85 + 0.15 * pulse,
        pointerEvents: 'none',
        zIndex: 4,
      }}/>}
      {/* Outer halo bloom (more dramatic) */}
      {showLed && <div style={{
        position: 'absolute',
        left: ledX - ledSize * 1.8,
        top: ledY - ledSize * 1.8,
        width: ledSize * 3.6, height: ledSize * 3.6,
        borderRadius: '50%',
        background: `radial-gradient(circle, ${led.c}55 0%, transparent 65%)`,
        filter: 'blur(2px)',
        opacity: 0.5 + 0.5 * pulse,
        pointerEvents: 'none',
        zIndex: 3,
      }}/>}
    </>
  );
}

function PathFlow({ from, via, to, color, label, t, packetOffset = 0, active = true, dim = false }) {
  const path = `M ${from.x} ${from.y} C ${(from.x + via.x) / 2} ${from.y}, ${(from.x + via.x) / 2} ${via.y}, ${via.x} ${via.y} S ${(via.x + to.x) / 2} ${to.y}, ${to.x} ${to.y}`;
  const NUM = 4;
  const sample = (u) => {
    if (u < 0.5) {
      const s = u * 2;
      const cx1 = (from.x + via.x) / 2, cy1 = from.y;
      const cx2 = (from.x + via.x) / 2, cy2 = via.y;
      const x = (1-s)**3 * from.x + 3*(1-s)**2*s*cx1 + 3*(1-s)*s**2*cx2 + s**3 * via.x;
      const y = (1-s)**3 * from.y + 3*(1-s)**2*s*cy1 + 3*(1-s)*s**2*cy2 + s**3 * via.y;
      return { x, y };
    } else {
      const s = (u - 0.5) * 2;
      const cx1 = (via.x + to.x) / 2, cy1 = via.y;
      const cx2 = (via.x + to.x) / 2, cy2 = to.y;
      const x = (1-s)**3 * via.x + 3*(1-s)**2*s*cx1 + 3*(1-s)*s**2*cx2 + s**3 * to.x;
      const y = (1-s)**3 * via.y + 3*(1-s)**2*s*cy1 + 3*(1-s)*s**2*cy2 + s**3 * to.y;
      return { x, y };
    }
  };
  const dimOp = dim ? 0.2 : 1;
  return (
    <>
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none', overflow: 'visible' }}>
        <path d={path} stroke={color} strokeWidth="6" fill="none" opacity={0.18 * dimOp} filter="blur(4px)"/>
        <path d={path} stroke={color} strokeWidth="1.5" fill="none" opacity={0.4 * dimOp} strokeDasharray="6 8" strokeDashoffset={-t * 50}/>
      </svg>

      {active && Array.from({ length: NUM }).map((_, i) => {
        const u = ((t * 0.4 + packetOffset + i / NUM) % 1);
        const p = sample(u);
        const fadeIn = clamp(u / 0.05, 0, 1);
        const fadeOut = u > 0.95 ? clamp((u - 0.95) / 0.05, 0, 1) : 0;
        const opP = fadeIn * (1 - fadeOut);
        return (
          <DataPacket key={i} x={p.x} y={p.y} label="MQTT" value="🔒" color={color} scale={0.85} opacity={opP}/>
        );
      })}

      <div style={{
        position: 'absolute', left: via.x, top: via.y - 80,
        transform: 'translateX(-50%)',
        fontFamily: monoFont, fontSize: 11,
        color, letterSpacing: '0.12em', textTransform: 'uppercase',
        background: 'rgba(10,10,10,0.85)',
        padding: '4px 10px', borderRadius: 4,
        border: `1px solid ${color}55`,
        opacity: dimOp,
      }}>{label}</div>
    </>
  );
}

function Router({ x, y, kind, t, disabled, active }) {
  const baseColor = kind === 'wifi' ? X3.blue : X3.violet;
  const color = disabled ? '#666' : baseColor;
  const label = kind === 'wifi' ? 'WI-FI AP' : '4G TOWER';
  return (
    <div style={{
      position: 'absolute', left: x, top: y, width: 120, height: 100,
      display: 'flex', flexDirection: 'column', alignItems: 'center',
      opacity: disabled ? 0.4 : 1,
    }}>
      {!disabled && <SignalWave x={60} y={20} t={t} color={color} maxR={50} period={1.2}/>}
      {kind === 'wifi' ? (
        <div style={{
          marginTop: 20,
          width: 80, height: 50,
          background: 'linear-gradient(180deg, #2a2a2a, #1a1a1a)',
          border: `1px solid ${X3.border}`,
          borderRadius: 6,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
            <path d="M5 10 Q12 5 19 10" stroke={color} strokeWidth="1.8" fill="none" strokeLinecap="round"/>
            <path d="M8 13 Q12 10 16 13" stroke={color} strokeWidth="1.8" fill="none" strokeLinecap="round"/>
            <circle cx="12" cy="17" r="1.5" fill={color}/>
          </svg>
        </div>
      ) : (
        <svg width="80" height="60" viewBox="0 0 80 60" style={{ marginTop: 14 }}>
          <path d="M40 5 L30 55 M40 5 L50 55 M30 55 L50 55" stroke={X3.borderHi} strokeWidth="2" fill="none"/>
          <path d="M34 25 L46 25 M32 40 L48 40" stroke={X3.borderHi} strokeWidth="1.5"/>
          <circle cx="40" cy="5" r="3" fill={color}/>
        </svg>
      )}
      <div style={{
        marginTop: 6,
        fontFamily: monoFont, fontSize: 9,
        color, letterSpacing: '0.15em',
      }}>{label}</div>
    </div>
  );
}

// ───────────────────────────────────────────────────────────────────
// Master scene
// ───────────────────────────────────────────────────────────────────
function MasterScene() {
  const t = useTime();
  React.useEffect(() => {
    const root = document.querySelector('[data-screen-label]');
    if (root) root.setAttribute('data-screen-label', `t=${Math.floor(t)}s`);
  }, [Math.floor(t)]);

  return (
    <>
      <Scene1/>
      <Scene2/>
      <Scene3/>
      <Scene4/>
      <Scene5/>
      <Scene6/>
      <Scene7/>
      <Scene8/>
      <Scene9/>
      <Watermark/>
    </>
  );
}

// ───────────────────────────────────────────────────────────────────
// Persistent brand watermark — bottom-right, low-opacity, non-interactive
// ───────────────────────────────────────────────────────────────────
function Watermark() {
  return (
    <div style={{
      position: 'absolute',
      right: 40,
      bottom: 30,
      width: 110,
      height: 26,
      opacity: 0.32,
      pointerEvents: 'none',
      zIndex: 50,
      mixBlendMode: 'screen',
    }}>
      <img
        src="assets/xeeed-logo.svg"
        alt=""
        style={{ width: '100%', height: '100%', display: 'block', objectFit: 'contain' }}
      />
    </div>
  );
}

Object.assign(window, { Scene1, Scene2, Scene3, Scene4, Scene5, Scene6, Scene7, Scene8, Scene9, MasterScene, STAGE_W, STAGE_H });
