// Finale section — ported from the Claude Design handoff
// (Finale Section.html). A 220vh-tall pinned scroll-driven sequence:
//   - Full-bleed aero-wheel SVG dominates the landing view
//   - Wheel shrinks (scale 1.0 → 0.35) as the user scrolls
//   - Headline / sub / CTA fade in at staggered scroll thresholds
//   - Four telemetry callouts orbit the wheel and fade in too
//   - A featured "LIVE PRICING · Guangzhou showroom" callout grows
//     more prominent as the user scrolls toward the footer
//   - Near the end, the wheel enters a "charged" state (amber glow,
//     full LED ring) and a vignette darkens the transition out
//
// Two mechanical adaptations from the design source:
//   - React hooks aliased to F-prefixed names (the SPA loads all babel
//     files into one shared scope; useState/useEffect would collide)
//   - The standalone HTML's filler section and footer are NOT ported —
//     the SPA already has sections leading up to the finale and its
//     own Footer component. Only the finale itself.
//
// The "Start a build" CTA opens WhatsApp with a bilingual prefilled
// message and fires a lead in Odoo via window.fireAutoLead.

const {
  useState: useStateF,
  useEffect: useEffectF,
  useRef: useRefF,
} = React;

// Resolve the WhatsApp deeplinks for the two finale CTAs. Uses the
// numbers + prefilled messages defined in copy.jsx (window.WA), with
// UTM tracking appended so the team can attribute conversions from the
// finale section in WhatsApp Business / Odoo analytics.
function withUtm(url) {
  if (!url) return "#";
  var utm = "utm_source=site&utm_medium=button&utm_campaign=auto-finale";
  return url + (url.indexOf("?") === -1 ? "?" : "&") + utm;
}
function getWaUrls() {
  // Both targets resolve to the same +961 76 512 841 number now —
  // see copy.jsx WA_NUMBER. Kept as two keys so the existing button
  // markup (renderCTA below) doesn't need to change.
  var fallback = "https://wa.me/96176512841?text=" +
    encodeURIComponent("Hi China Bridge Auto, I'm interested in vehicle sourcing from China.");
  var WA = (typeof window !== "undefined" && window.WA) || {};
  var beirut = withUtm(WA.beirut || fallback);
  var china  = withUtm(WA.china  || fallback);
  return { beirut: beirut, china: china };
}

function FinaleSection() {
  const sectionRef = useRefF(null);
  const stickyRef = useRefF(null);
  const wheelStageRef = useRefF(null);
  const vignetteRef = useRefF(null);
  const ctaRef = useRefF(null);
  const subRef = useRefF(null);
  const lineRef = useRefF(null);
  const t1Ref = useRefF(null);
  const t2Ref = useRefF(null);
  const t3Ref = useRefF(null);
  const t4Ref = useRefF(null);

  const waUrls = useRefF(getWaUrls()).current;

  // Add `.finale-in` once the section enters the viewport (drives the
  // eyebrow fade-in that doesn't need scroll-tied interpolation).
  useEffectF(() => {
    if (!sectionRef.current || !stickyRef.current) return;
    const obs = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting && stickyRef.current) {
          stickyRef.current.classList.add("finale-in");
        }
      });
    }, { threshold: 0.05 });
    obs.observe(sectionRef.current);
    return () => obs.disconnect();
  }, []);

  // Scroll-tied animation: spin speed, wheel scale, copy reveals,
  // telemetry reveals, vignette, and the "charged" end-state.
  useEffectF(() => {
    const reveals = [
      { get: () => lineRef.current, s: 0.18, e: 0.32 },
      { get: () => subRef.current,  s: 0.26, e: 0.42 },
      { get: () => ctaRef.current,  s: 0.36, e: 0.50 },
    ];
    const telemReveals = [
      { get: () => t1Ref.current, s: 0.42 },
      { get: () => t2Ref.current, s: 0.50 },
      { get: () => t3Ref.current, s: 0.30 }, // Featured "LIVE PRICING" reveals earliest
      { get: () => t4Ref.current, s: 0.58 },
    ];

    let ticking = false;
    function onScroll() {
      if (ticking) return;
      ticking = true;
      requestAnimationFrame(() => {
        ticking = false;
        const section = sectionRef.current;
        if (!section) return;
        const rect = section.getBoundingClientRect();
        const vh = window.innerHeight;
        const travel = section.offsetHeight - vh;
        if (travel <= 0) return;
        const scrolled = Math.max(0, -rect.top);
        const p = Math.max(0, Math.min(1, scrolled / travel));

        // Spin speed: fastest at mid-progress (sine peak), slowest at edges.
        const speed = Math.sin(Math.max(0, Math.min(1, p)) * Math.PI);
        const dur = (6 - speed * 4.5).toFixed(2);
        document.documentElement.style.setProperty("--wheel-dur", dur + "s");

        // Wheel scale: huge on landing, ~35% by end of scroll.
        const scale = (1.0 - p * 0.65).toFixed(3);
        document.documentElement.style.setProperty("--wheel-scale", scale);

        // Featured showroom-pricing callout grows toward end.
        const featuredScale = (1.0 + p * 0.20).toFixed(3);
        document.documentElement.style.setProperty("--featured-scale", featuredScale);

        // Copy reveals (interpolated opacity + translateY).
        for (const r of reveals) {
          const el = r.get();
          if (!el) continue;
          const t = Math.max(0, Math.min(1, (p - r.s) / (r.e - r.s)));
          el.style.opacity = t.toFixed(3);
          el.style.transform = "translateY(" + ((1 - t) * 24).toFixed(1) + "px)";
        }

        // Telemetry reveals (binary at threshold).
        for (const tr of telemReveals) {
          const el = tr.get();
          if (!el) continue;
          if (p > tr.s) el.classList.add("in");
          else el.classList.remove("in");
        }

        // Vignette fades in at the end for footer transition.
        if (vignetteRef.current) {
          const vAmount = p > 0.86 ? Math.min(1, (p - 0.86) / 0.14) : 0;
          vignetteRef.current.style.opacity = vAmount.toFixed(3);
        }

        // Charged state near end of scroll.
        if (wheelStageRef.current) {
          if (p > 0.78) wheelStageRef.current.classList.add("charged");
          else wheelStageRef.current.classList.remove("charged");
        }
      });
    }

    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    onScroll();
    return () => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
    };
  }, []);

  // Fire-and-forget lead capture for each desk. Keeps the existing
  // auto_finalcta_* inquiry_source values so the team's CRM filters
  // and historical lead grouping continue to work after the standalone
  // FinalCTA section was removed.
  const onBeirutClick = () => {
    if (typeof window !== "undefined" && window.fireAutoLead) {
      window.fireAutoLead({
        inquiry_source: "auto_finalcta_beirut",
        request_kind: "WhatsApp interest",
        subject: "finale section · Beirut desk",
        whatsapp: waUrls.beirut,
      });
    }
  };
  const onChinaClick = () => {
    if (typeof window !== "undefined" && window.fireAutoLead) {
      window.fireAutoLead({
        inquiry_source: "auto_finalcta_china",
        request_kind: "WhatsApp interest",
        subject: "finale section · China desk",
        whatsapp: waUrls.china,
      });
    }
  };

  return (
    <section ref={sectionRef} className="finale" id="finale">
      <div ref={stickyRef} className="finale-sticky">
        <div className="finale-stage">

          {/* Background layers — radial glow + grid + concentric rings */}
          <div className="finale-bg" aria-hidden="true" />
          <div className="finale-rings" aria-hidden="true" />

          {/* Copy: floats centered at top, overlays the wheel */}
          <div className="finale-copy">
            <h1 className="finale-h">
              <span ref={lineRef} className="finale-line">Ready when you are.</span>
            </h1>
            <p ref={subRef} className="finale-sub">
              23 years of supplier relationships. 38 countries delivered. One WhatsApp away.
            </p>
            <div ref={ctaRef} className="finale-cta-row">
              <a
                className="finale-cta finale-cta-primary"
                href={waUrls.beirut}
                target="_blank"
                rel="noopener noreferrer"
                onClick={onBeirutClick}
              >
                WhatsApp our team
                <span aria-hidden="true">→</span>
              </a>
              <a
                className="finale-cta finale-cta-ghost"
                href={waUrls.china}
                target="_blank"
                rel="noopener noreferrer"
                onClick={onChinaClick}
              >
                WhatsApp China desk
                <span aria-hidden="true">→</span>
              </a>
            </div>
          </div>

          {/* Wheel stage — full-bleed SVG, scroll-shrinks */}
          <div ref={wheelStageRef} className="wheel-stage">
            <svg className="wheel-svg" viewBox="0 0 800 800" preserveAspectRatio="xMidYMid meet" aria-hidden="true">
              <defs>
                <linearGradient id="finSpokeFill" x1="1" y1="0" x2="0" y2="1" gradientUnits="objectBoundingBox">
                  <stop offset="0%"   stopColor="#ece5db" />
                  <stop offset="22%"  stopColor="#cbc3b8" />
                  <stop offset="27%"  stopColor="#3a352e" />
                  <stop offset="55%"  stopColor="#1a1714" />
                  <stop offset="100%" stopColor="#070608" />
                </linearGradient>
                <linearGradient id="finRimGrad" x1="0.25" y1="0.15" x2="0.75" y2="0.85">
                  <stop offset="0%"   stopColor="#9a9088" />
                  <stop offset="40%"  stopColor="#3a352e" />
                  <stop offset="100%" stopColor="#15120e" />
                </linearGradient>
                <linearGradient id="finTireGrad" x1="0.3" y1="0.1" x2="0.7" y2="0.9">
                  <stop offset="0%"   stopColor="#2a2622" />
                  <stop offset="40%"  stopColor="#161310" />
                  <stop offset="100%" stopColor="#0a0908" />
                </linearGradient>
                <radialGradient id="finTopGlow" cx="0.25" cy="0.22" r="0.65">
                  <stop offset="0%"   stopColor="rgba(255,238,200,0.22)" />
                  <stop offset="100%" stopColor="rgba(255,238,200,0)" />
                </radialGradient>
                <radialGradient id="finHubFace" cx="0.3" cy="0.3" r="0.75">
                  <stop offset="0%"   stopColor="#5a534b" />
                  <stop offset="100%" stopColor="#1a1814" />
                </radialGradient>
                <radialGradient id="finCapFace" cx="0.3" cy="0.3" r="0.8">
                  <stop offset="0%"   stopColor="#7a7268" />
                  <stop offset="100%" stopColor="#2a2622" />
                </radialGradient>
                <radialGradient id="finDiscGrad" cx="0.5" cy="0.5" r="0.5">
                  <stop offset="0%"   stopColor="#1a1714" />
                  <stop offset="100%" stopColor="#0a0908" />
                </radialGradient>
                <filter id="finWheelBlur">
                  <feGaussianBlur stdDeviation="2.5" />
                </filter>
                <path id="finTireText" d="M 38 400 A 362 362 0 0 1 762 400" fill="none" />
              </defs>

              {/* Tire: thick dark sidewall band */}
              <circle cx="400" cy="400" r="362" fill="none" stroke="url(#finTireGrad)" strokeWidth="52" />
              <g stroke="rgba(0,0,0,0.7)" strokeWidth="1.2" strokeLinecap="butt">
                {Array.from({ length: 60 }).map((_, i) => (
                  <line key={i} x1="400" y1="365" x2="400" y2="385" transform={`rotate(${i * 6} 400 400)`} />
                ))}
              </g>

              {/* Upper-left tire sheen */}
              <path d="M 88 400 A 362 362 0 0 1 400 88" fill="none" stroke="rgba(255,238,200,0.05)" strokeWidth="40" />
              {/* Embossed sidewall text */}
              <text fontFamily="IBM Plex Mono, monospace" fontSize="12" fill="rgba(239,233,221,0.11)" letterSpacing="3" fontWeight="600">
                <textPath href="#finTireText" startOffset="50%" textAnchor="middle">CHINA BRIDGE · 265/40 R20</textPath>
              </text>

              {/* LED ring: soft halo + crisp luminous line */}
              <circle cx="400" cy="400" r="336" fill="none" stroke="rgba(232,115,46,0.22)" strokeWidth="7" filter="url(#finWheelBlur)" />
              <circle cx="400" cy="400" r="336" fill="none" stroke="rgba(232,115,46,0.42)" strokeWidth="1.8" />
              <g className="wheel-led-orbit">
                <circle cx="400" cy="64" r="8" fill="var(--amber)" filter="url(#finWheelBlur)" />
                <circle cx="400" cy="64" r="2.8" fill="#fff5e8" />
              </g>

              {/* Full amber LED ring (visible only when charged) */}
              <circle className="led-full" cx="400" cy="400" r="336" fill="none" stroke="var(--amber)" strokeWidth="3" opacity="0" />
              {/* Ignition halo (one-time burst on charged) */}
              <circle className="ignition-halo" cx="400" cy="400" r="356" fill="none" stroke="var(--amber)" strokeWidth="2" filter="url(#finWheelBlur)" opacity="0" />

              {/* Rim band */}
              <circle cx="400" cy="400" r="335" fill="url(#finRimGrad)" />
              <circle cx="400" cy="400" r="335" fill="none" stroke="rgba(0,0,0,0.55)" strokeWidth="1.5" />
              <circle cx="400" cy="400" r="288" fill="none" stroke="rgba(0,0,0,0.7)" strokeWidth="1.8" />
              <path d="M 112 400 A 288 288 0 0 1 400 112" fill="none" stroke="rgba(255,238,200,0.5)" strokeWidth="2.5" />
              <path d="M 688 400 A 288 288 0 0 1 400 688" fill="none" stroke="rgba(0,0,0,0.55)" strokeWidth="2" />

              {/* Brake disc (visible through spoke gaps, spins slow) */}
              <g className="wheel-spin-slow">
                <circle cx="400" cy="400" r="270" fill="url(#finDiscGrad)" stroke="rgba(40,36,32,0.65)" strokeWidth="1.5" />
                <circle cx="400" cy="400" r="240" fill="none" stroke="rgba(50,46,40,0.4)" strokeWidth="0.8" />
                <circle cx="400" cy="400" r="205" fill="none" stroke="rgba(50,46,40,0.3)" strokeWidth="0.6" />
                <circle cx="400" cy="180" r="6" fill="#0a0908" />
                <circle cx="510" cy="209" r="6" fill="#0a0908" />
                <circle cx="591" cy="290" r="6" fill="#0a0908" />
                <circle cx="620" cy="400" r="6" fill="#0a0908" />
                <circle cx="591" cy="510" r="6" fill="#0a0908" />
                <circle cx="510" cy="591" r="6" fill="#0a0908" />
                <circle cx="400" cy="620" r="6" fill="#0a0908" />
                <circle cx="290" cy="591" r="6" fill="#0a0908" />
                <circle cx="209" cy="510" r="6" fill="#0a0908" />
                <circle cx="180" cy="400" r="6" fill="#0a0908" />
                <circle cx="209" cy="290" r="6" fill="#0a0908" />
                <circle cx="290" cy="209" r="6" fill="#0a0908" />
              </g>

              {/* Caliper (amber, top, between rim and disc) */}
              <path d="M 321.21 157.5 A 255 255 0 0 1 478.79 157.5 L 510.61 126.54 A 295 295 0 0 0 289.39 126.54 Z"
                    fill="rgba(232,115,46,0.92)" stroke="var(--amber)" strokeWidth="1" />
              <text x="400" y="148" textAnchor="middle"
                    fontFamily="IBM Plex Mono, monospace" fontSize="11"
                    fill="#0a0a0b" letterSpacing="4" fontWeight="600">CB · CARBON-CERAMIC</text>

              {/* 5 swept aero blades (pinwheel, spin fast) */}
              <g className="wheel-spin-fast">
                {[0, 72, 144, 216, 288].map((rot) => (
                  <g key={rot} transform={rot === 0 ? undefined : `rotate(${rot} 400 400)`}>
                    <path d="M 649.4 256 A 288 288 0 0 1 649.4 544 Q 555 510 469.5 435.4 A 78 78 0 0 0 477.9 395.9 Q 555 290 649.4 256 Z"
                          fill="url(#finSpokeFill)" stroke="rgba(0,0,0,0.78)" strokeWidth="1.5" strokeLinejoin="round" />
                    <path d="M 649.4 256 Q 555 290 477.9 395.9" fill="none" stroke="rgba(244,238,224,0.92)" strokeWidth="1.4" strokeLinecap="round" />
                    <path d="M 649.4 544 Q 555 510 469.5 435.4" fill="none" stroke="rgba(0,0,0,0.65)" strokeWidth="1.2" strokeLinecap="round" />
                  </g>
                ))}
              </g>

              {/* Upper-left key light (sits on top of spokes) */}
              <circle cx="400" cy="400" r="320" fill="url(#finTopGlow)" pointerEvents="none" />

              {/* Hub face */}
              <circle cx="400" cy="400" r="78" fill="url(#finHubFace)" stroke="rgba(0,0,0,0.7)" strokeWidth="1.5" />
              <circle cx="400" cy="400" r="62" fill="none" stroke="rgba(255,255,255,0.06)" strokeWidth="0.6" />

              {/* 5 lug nuts */}
              <g>
                <polygon points="447,428 452,431 452,437 447,440 442,437 442,431" fill="#0a0908" stroke="rgba(239,233,221,0.4)" strokeWidth="0.8" />
                <circle cx="446" cy="430" r="0.9" fill="rgba(255,255,255,0.4)" />
                <polygon points="382,449 387,452 387,458 382,461 377,458 377,452" fill="#0a0908" stroke="rgba(239,233,221,0.4)" strokeWidth="0.8" />
                <circle cx="381" cy="451" r="0.9" fill="rgba(255,255,255,0.4)" />
                <polygon points="342,394 347,397 347,403 342,406 337,403 337,397" fill="#0a0908" stroke="rgba(239,233,221,0.4)" strokeWidth="0.8" />
                <circle cx="341" cy="396" r="0.9" fill="rgba(255,255,255,0.4)" />
                <polygon points="382,339 387,342 387,348 382,351 377,348 377,342" fill="#0a0908" stroke="rgba(239,233,221,0.4)" strokeWidth="0.8" />
                <circle cx="381" cy="341" r="0.9" fill="rgba(255,255,255,0.4)" />
                <polygon points="447,360 452,363 452,369 447,372 442,369 442,363" fill="#0a0908" stroke="rgba(239,233,221,0.4)" strokeWidth="0.8" />
                <circle cx="446" cy="362" r="0.9" fill="rgba(255,255,255,0.4)" />
              </g>

              {/* Center cap (machined alloy, no wordmark) */}
              <circle cx="400" cy="400" r="32" fill="url(#finCapFace)" stroke="rgba(255,255,255,0.18)" strokeWidth="1.2" />
              <circle cx="397" cy="397" r="26" fill="none" stroke="rgba(255,255,255,0.1)" strokeWidth="0.8" />
              <circle cx="400" cy="400" r="5" fill="var(--amber)" opacity="0.65" />
            </svg>

            {/* Telemetry callouts orbiting the wheel */}
            <div ref={t1Ref} className="telem telem-1">
              OPERATING SINCE
              <b><span className="amber">2003</span> · 23 yrs</b>
            </div>
            <div ref={t2Ref} className="telem telem-2">
              SUPPORT · WHATSAPP
              <b><span className="amber">24/7</span> · always live</b>
            </div>
            <div ref={t3Ref} className="telem telem-3 telem-featured">
              <span className="telem-live">
                <span className="telem-live-dot" aria-hidden="true" />
                LIVE PRICING
              </span>
              <b>Guangzhou <span className="amber">showroom</span></b>
              <span className="telem-foot">Updated daily · no dealer markup</span>
            </div>
            <div ref={t4Ref} className="telem telem-4">
              DELIVERED TO
              <b><span className="amber">38</span> countries · 14 ports</b>
            </div>
          </div>

          {/* Vignette for end-of-section fade-out */}
          <div ref={vignetteRef} className="finale-vignette" aria-hidden="true" />
        </div>
      </div>

      <style>{`
        .finale {
          position: relative;
          height: 220vh;
          background: var(--ink-0);
        }
        .finale-sticky {
          position: sticky;
          top: 0;
          height: 100vh;
          overflow: hidden;
        }
        .finale-stage {
          position: absolute; inset: 0;
          display: block;
        }

        .finale-bg {
          position: absolute; inset: 0;
          background:
            radial-gradient(ellipse 80% 60% at 70% 50%, rgba(232,115,46,0.10), transparent 65%),
            radial-gradient(ellipse 110% 90% at 50% 110%, rgba(0,0,0,0.55), transparent 60%),
            linear-gradient(180deg, #0d0d10 0%, #0a0a0b 60%, #050506 100%);
          pointer-events: none;
        }
        .finale-bg::after {
          content: "";
          position: absolute; inset: 0;
          background-image:
            linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
          background-size: 56px 56px;
          -webkit-mask-image: radial-gradient(ellipse at 70% 50%, black 25%, transparent 75%);
                  mask-image: radial-gradient(ellipse at 70% 50%, black 25%, transparent 75%);
        }
        .finale-rings {
          position: absolute;
          left: 73%; top: 50%;
          width: 140vh; height: 140vh;
          transform: translate(-50%, -50%);
          pointer-events: none;
          opacity: 0.5;
        }
        .finale-rings::before,
        .finale-rings::after {
          content: "";
          position: absolute; inset: 0;
          border: 1px solid rgba(232,115,46,0.10);
          border-radius: 50%;
          animation: finRingPulse 6s ease-out infinite;
        }
        .finale-rings::after { animation-delay: 3s; }
        @keyframes finRingPulse {
          0%   { transform: scale(0.4); opacity: 0.6; }
          100% { transform: scale(1.0); opacity: 0; }
        }

        .finale-copy {
          position: absolute;
          top: 12vh; left: 0; right: 0;
          z-index: 5;
          padding: 0 6vw;
          text-align: center;
          max-width: none;
          pointer-events: none;
        }
        .finale-copy a, .finale-copy button { pointer-events: auto; }

        .finale-h {
          font-family: var(--serif);
          font-weight: 400;
          font-size: clamp(48px, 7.2vw, 124px);
          line-height: 1.0;
          letter-spacing: -0.03em;
          color: var(--bone);
          margin: 0 auto 28px;
          max-width: 18ch;
          text-shadow: 0 2px 32px rgba(0,0,0,0.5);
        }
        .finale-line {
          display: block;
          opacity: 0;
          transform: translateY(28px);
          will-change: opacity, transform;
        }
        .finale-line.amber { color: var(--amber); }

        .finale-sub {
          font-family: var(--sans);
          font-size: clamp(15px, 1.3vw, 19px);
          line-height: 1.55;
          color: var(--mute);
          margin: 0 auto 36px;
          max-width: 52ch;
          text-align: center;
          text-shadow: 0 2px 18px rgba(0,0,0,0.4);
          opacity: 0;
          transform: translateY(16px);
          will-change: opacity, transform;
        }

        .finale-cta-row {
          display: flex; justify-content: center; align-items: center;
          gap: 16px; flex-wrap: wrap;
          opacity: 0;
          transform: translateY(20px);
          will-change: opacity, transform;
        }
        .finale-cta {
          display: inline-flex; align-items: center; gap: 12px;
          padding: 16px 26px;
          text-decoration: none;
          font-family: var(--sans); font-size: 13px; font-weight: 600;
          letter-spacing: 0.14em; text-transform: uppercase;
          transition: transform .25s ease, background .25s ease, color .25s ease, border-color .25s ease, box-shadow .3s ease;
          min-width: 220px;
          justify-content: center;
        }
        .finale-cta-primary {
          background: var(--amber);
          color: var(--ink-0);
          border: 1px solid var(--amber);
        }
        .finale-cta-primary:hover {
          background: #ff8a48;
          border-color: #ff8a48;
          transform: translateY(-1px);
          box-shadow: 0 16px 36px -12px rgba(232,115,46,0.55);
        }
        .finale-cta-ghost {
          background: transparent;
          color: var(--bone);
          border: 1px solid var(--line-2);
        }
        .finale-cta-ghost:hover {
          color: var(--amber);
          border-color: var(--amber);
          transform: translateY(-1px);
        }

        .wheel-stage {
          position: absolute; inset: 0;
          z-index: 2;
          display: flex; align-items: center; justify-content: center;
          height: 100%;
          padding: 0;
        }
        .wheel-svg {
          width: min(95vh, 95vw);
          height: min(95vh, 95vw);
          display: block;
          will-change: transform;
          transform: scale(var(--wheel-scale, 1));
          transform-origin: center center;
          transition: transform 0.05s linear, filter .9s ease;
        }
        .wheel-spin-fast {
          transform-origin: 400px 400px;
          animation: finWSpin var(--wheel-dur, 6s) linear infinite;
        }
        .wheel-spin-slow {
          transform-origin: 400px 400px;
          animation: finWSpin calc(var(--wheel-dur, 6s) * 5) linear infinite;
        }
        .wheel-led-orbit {
          transform-origin: 400px 400px;
          animation: finWSpin 3.2s linear infinite;
        }
        @keyframes finWSpin { to { transform: rotate(360deg); } }

        .telem {
          position: absolute;
          font-family: var(--mono);
          font-size: 10px;
          letter-spacing: 0.22em;
          text-transform: uppercase;
          color: var(--mute);
          opacity: 0;
          transition: opacity .6s ease, transform .6s ease;
          will-change: opacity, transform;
          transform: translateY(6px);
          pointer-events: none;
          white-space: nowrap;
        }
        .telem b {
          display: block;
          font-family: var(--sans);
          font-weight: 500;
          font-size: 16px;
          letter-spacing: -0.005em;
          color: var(--bone);
          margin-top: 4px;
          font-variant-numeric: tabular-nums;
        }
        .telem b .amber { color: var(--amber); }
        .telem::before {
          content: "";
          position: absolute;
          width: 6px; height: 6px;
          border-radius: 50%;
          background: var(--amber);
          box-shadow: 0 0 8px rgba(232,115,46,0.7);
        }
        .telem.in { opacity: 1; transform: none; }

        .telem-featured {
          background: rgba(10,10,11,0.78);
          border: 1px solid rgba(232,115,46,0.45);
          padding: 16px 20px;
          backdrop-filter: blur(8px);
          box-shadow: 0 18px 40px -16px rgba(232,115,46,0.35),
                      0 0 0 1px rgba(232,115,46,0.06) inset;
          transform-origin: center;
        }
        .telem-featured.in {
          transform: scale(var(--featured-scale, 1.06));
        }
        .telem-featured::before, .telem-featured::after { display: none; }
        .telem-featured b {
          font-size: 22px !important;
          margin-top: 2px;
        }
        .telem-live {
          display: inline-flex; align-items: center; gap: 8px;
          font-family: var(--mono);
          font-size: 9.5px;
          letter-spacing: 0.24em;
          color: var(--amber);
          margin-bottom: 4px;
        }
        .telem-live-dot {
          width: 7px; height: 7px;
          border-radius: 50%;
          background: var(--amber);
          box-shadow: 0 0 8px rgba(232,115,46,0.7);
          animation: finFtPulse 1.4s ease-in-out infinite;
        }
        @keyframes finFtPulse {
          0%, 100% { box-shadow: 0 0 0 0 rgba(232,115,46,0.55); }
          70%      { box-shadow: 0 0 0 7px rgba(232,115,46,0); }
        }
        .telem-foot {
          display: block;
          font-family: var(--sans);
          font-size: 11.5px;
          color: var(--mute);
          margin-top: 6px;
          letter-spacing: 0;
          text-transform: none;
        }

        .telem-1 { top: 12%; right: 6%; }
        .telem-1::before { left: -14px; top: 8px; }
        .telem-1::after {
          content: ""; position: absolute;
          left: -86px; top: 11px;
          width: 72px; height: 1px;
          background: linear-gradient(to left, var(--amber) 0%, rgba(232,115,46,0.35) 50%, rgba(232,115,46,0) 100%);
        }
        .telem-2 { top: 36%; right: 2%; text-align: left; }
        .telem-2::before { left: -14px; top: 8px; }
        .telem-2::after {
          content: ""; position: absolute;
          left: -86px; top: 11px;
          width: 72px; height: 1px;
          background: linear-gradient(to left, var(--amber) 0%, rgba(232,115,46,0.35) 50%, rgba(232,115,46,0) 100%);
        }
        .telem-3 { top: 62%; right: 4%; }
        .telem-3::before { left: -22px; top: 8px; }
        .telem-3::after {
          content: ""; position: absolute;
          left: -16px; top: 11px;
          width: 12px; height: 1px;
          background: var(--amber);
        }
        .telem-4 { bottom: 14%; right: 10%; }
        .telem-4::before { left: -14px; top: 8px; }
        .telem-4::after {
          content: ""; position: absolute;
          left: -86px; top: 11px;
          width: 72px; height: 1px;
          background: linear-gradient(to left, var(--amber) 0%, rgba(232,115,46,0.35) 50%, rgba(232,115,46,0) 100%);
        }

        .finale-vignette {
          position: absolute; inset: 0;
          background: radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(0,0,0,0.85) 100%);
          opacity: 0;
          pointer-events: none;
          z-index: 5;
          will-change: opacity;
        }

        /* Charged state — fires near end of scroll */
        .wheel-stage.charged .led-full {
          opacity: 0.9;
          transition: opacity .7s ease;
          filter: drop-shadow(0 0 8px rgba(232,115,46,0.7));
        }
        .wheel-stage.charged .ignition-halo {
          animation: finIgniteFlash 1.4s cubic-bezier(.16,1,.3,1) forwards;
        }
        @keyframes finIgniteFlash {
          0%   { opacity: 0; stroke-width: 1; }
          18%  { opacity: 1; }
          100% { opacity: 0; stroke-width: 28; }
        }
        .wheel-stage.charged .wheel-svg {
          filter: drop-shadow(0 0 24px rgba(232,115,46,0.25));
        }
        .wheel-stage.charged .telem {
          color: var(--bone);
        }
        .wheel-stage.charged .telem::before {
          box-shadow: 0 0 14px rgba(232,115,46,0.9);
        }

        @media (max-width: 900px) {
          .finale { height: 200vh; }
          .finale-copy { max-width: 100%; padding: 16vh 6vw 4vh; }
          .finale-h { font-size: clamp(48px, 14vw, 88px); }
          .wheel-svg { width: 78vw; height: 78vw; }
          .telem { font-size: 8.5px; }
          .telem b { font-size: 13px; }
          .telem-1, .telem-2, .telem-3, .telem-4 { display: none; }
        }

        @media (prefers-reduced-motion: reduce) {
          .wheel-spin-fast, .wheel-spin-slow, .wheel-led-orbit,
          .finale-rings::before, .finale-rings::after { animation: none !important; }
          .finale-line, .finale-cta-row, .finale-sub { opacity: 1 !important; transform: none !important; }
        }
      `}</style>
    </section>
  );
}
