// ── Navbar + Hero + Stats + Marquee ───────────────────────────────
// Depends on: site-primitives.jsx

function Navbar({ bookingUrl, onAbout, onHome, currentView }) {
  const [activeSection, setActiveSection] = React.useState('');
  const [mobileOpen, setMobileOpen] = React.useState(false);
  const { width } = useWindowSize();
  const isMobile = width <= 768;

  const linksContainerRef = React.useRef(null);
  const linkRefs = React.useRef([]);
  const [pillStyle, setPillStyle] = React.useState({ left: 0, width: 0, top: 0, height: 0, opacity: 0 });
  const [scrollProgress, setScrollProgress] = React.useState({ current: 0, next: 0, t: 0 });

  // Active section tracking via scroll — whichever section center is closest
  // to the viewport center wins. Also computes progress (0-1) through each
  // section so the pill can interpolate between adjacent nav links.
  React.useEffect(() => {
    if (currentView !== 'home') return;
    const ids = ['problem', 'solution', 'process', 'proof', 'pricing'];
    let rafId;

    const update = () => {
      const viewportCenter = window.scrollY + window.innerHeight / 2;
      let bestId = '';
      let bestDist = Infinity;
      let bestProgress = 0;
      let bestIdx = -1;

      ids.forEach((id, idx) => {
        const el = document.getElementById(id);
        if (!el) return;
        const rect = el.getBoundingClientRect();
        const elTop = window.scrollY + rect.top;
        const elBottom = elTop + rect.height;
        const elCenter = elTop + rect.height / 2;
        const dist = Math.abs(elCenter - viewportCenter);
        if (dist < bestDist) {
          bestDist = dist;
          bestId = id;
          bestIdx = idx;
          // 0 = top of section at viewport center, 1 = bottom at viewport center
          bestProgress = Math.min(1, Math.max(0, (viewportCenter - elTop) / rect.height));
        }
      });

      if (bestId) {
        setActiveSection(bestId);
        // Interpolate pill between current section link and next section link
        // based on scroll progress (>= 0.5 starts shifting toward next)
        setScrollProgress({ current: bestIdx, next: bestIdx + 1 < ids.length ? bestIdx + 1 : bestIdx, t: Math.max(0, (bestProgress - 0.5) * 2) });
      }
    };

    const onScroll = () => {
      if (rafId) cancelAnimationFrame(rafId);
      rafId = requestAnimationFrame(update);
    };

    window.addEventListener('scroll', onScroll, { passive: true });
    update(); // initial
    return () => {
      window.removeEventListener('scroll', onScroll);
      if (rafId) cancelAnimationFrame(rafId);
    };
  }, [currentView]);

  const links = [
    { label: 'Problem', href: '#problem' },
    { label: 'Solution', href: '#solution' },
    { label: 'Process', href: '#process' },
    { label: 'Proof', href: '#proof' },
    { label: 'Pricing', href: '#pricing' },
    { label: 'About', onClick: onAbout },
  ];

  const logoClick = () => {
    if (currentView === 'about') onHome();
    else window.scrollTo({ top: 0, behavior: 'smooth' });
  };

  // Handle nav link clicks — if on About, switch to Home first, then scroll
  const handleNavClick = (e, href) => {
    if (currentView === 'about') {
      e.preventDefault();
      onHome();
      // Allow React to re-render Home, then scroll to section
      requestAnimationFrame(() => {
        setTimeout(() => {
          const id = href.replace('#', '');
          const el = document.getElementById(id);
          if (el) el.scrollIntoView({ behavior: 'smooth' });
        }, 80);
      });
    }
  };

  // Sliding pill indicator behind active nav link
  // Interpolates between current and next section links based on scroll progress
  React.useEffect(() => {
    if (isMobile) {
      setPillStyle(s => ({ ...s, opacity: 0 }));
      return;
    }
    const updatePill = () => {
      const container = linksContainerRef.current;
      if (!container) return;
      let activeIdx = -1;
      if (currentView === 'about') {
        activeIdx = links.findIndex(l => l.label === 'About');
      } else if (activeSection) {
        activeIdx = links.findIndex(l => l.label.toLowerCase() === activeSection);
      }
      const activeEl = activeIdx >= 0 ? linkRefs.current[activeIdx] : null;
      if (!activeEl) {
        setPillStyle(s => ({ ...s, opacity: 0 }));
        return;
      }
      const containerRect = container.getBoundingClientRect();
      const activeRect = activeEl.getBoundingClientRect();

      // If we're in the second half of a section, interpolate toward next link
      let targetLeft = activeRect.left - containerRect.left;
      let targetWidth = activeRect.width;
      if (currentView !== 'about' && scrollProgress.t > 0) {
        const nextEl = linkRefs.current[scrollProgress.next];
        if (nextEl) {
          const nextRect = nextEl.getBoundingClientRect();
          const t = scrollProgress.t;
          targetLeft = activeRect.left + (nextRect.left - activeRect.left) * t - containerRect.left;
          targetWidth = activeRect.width + (nextRect.width - activeRect.width) * t;
        }
      }

      setPillStyle({
        left: targetLeft,
        width: targetWidth,
        top: activeRect.top - containerRect.top,
        height: activeRect.height,
        opacity: 1,
      });
    };
    const raf = requestAnimationFrame(() => {
      const t = setTimeout(updatePill, 50);
      return () => clearTimeout(t);
    });
    return () => cancelAnimationFrame(raf);
  }, [activeSection, currentView, isMobile, width, scrollProgress.t]);

  return (
    <header role="banner">
    <nav style={{ position: 'fixed', top: 18, left: 0, right: 0, zIndex: 9000, display: 'flex', justifyContent: 'center', padding: '0 16px' }}>
      <div style={{
        display: 'flex', alignItems: 'center', gap: isMobile ? 12 : 32,
        padding: '10px 16px', borderRadius: 100,
        background: 'rgba(13,13,13,0.92)', backdropFilter: 'blur(22px)',
        border: `1px solid ${BORDER}`,
        width: isMobile ? '100%' : 'auto',
        justifyContent: isMobile ? 'space-between' : 'center',
        transition: 'all 0.4s cubic-bezier(0.25,0.46,0.45,0.94)',
        position: 'relative',
      }}>
        <span onClick={logoClick} style={{ fontWeight: 900, fontSize: '0.95rem', letterSpacing: '-0.03em', whiteSpace: 'nowrap', cursor: 'pointer' }}>
          <span style={{ color: ACCENT }}>●</span> Augment OS
        </span>

        {!isMobile && (
          <div ref={linksContainerRef} style={{ display: 'flex', gap: 4, alignItems: 'center', position: 'relative' }}>
            <div style={{
              position: 'absolute',
              left: pillStyle.left,
              width: pillStyle.width,
              top: pillStyle.top,
              height: pillStyle.height,
              borderRadius: 100,
              background: 'rgba(255,107,0,0.12)',
              border: '1px solid rgba(255,107,0,0.25)',
              transition: 'left 0.35s cubic-bezier(0.25,0.46,0.45,0.94), width 0.35s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.2s ease',
              pointerEvents: 'none',
              zIndex: 0,
              opacity: pillStyle.opacity,
            }} />
            {links.map((l, i) => {
              const isActive = activeSection === l.label.toLowerCase();
              if (l.onClick) {
                return (
                  <button key={l.label} ref={el => { linkRefs.current[i] = el; }} onClick={() => { l.onClick(); }} style={{
                    position: 'relative', zIndex: 1,
                    color: currentView === 'about' ? ACCENT : 'rgba(245,245,245,0.55)',
                    fontSize: '0.86rem', textDecoration: 'none', fontWeight: currentView === 'about' ? 600 : 500,
                    padding: '6px 14px', borderRadius: 100,
                    background: 'transparent',
                    transition: 'all 0.25s cubic-bezier(0.25,0.46,0.45,0.94)',
                    border: 'none', cursor: 'pointer', fontFamily: 'inherit',
                  }}
                    onMouseEnter={e => { if (currentView !== 'about') { e.currentTarget.style.color = TEXT_PRIMARY; e.currentTarget.style.background = 'rgba(255,255,255,0.05)'; } }}
                    onMouseLeave={e => { if (currentView !== 'about') { e.currentTarget.style.color = 'rgba(245,245,245,0.55)'; e.currentTarget.style.background = 'transparent'; } }}
                  >{l.label}</button>
                );
              }
              return (
                <a key={l.label} ref={el => { linkRefs.current[i] = el; }} href={l.href} onClick={(e) => handleNavClick(e, l.href)} style={{
                  position: 'relative', zIndex: 1,
                  color: isActive ? ACCENT : 'rgba(245,245,245,0.55)',
                  fontSize: '0.86rem', textDecoration: 'none', fontWeight: isActive ? 600 : 500,
                  padding: '6px 14px', borderRadius: 100,
                  background: 'transparent',
                  transition: 'all 0.25s cubic-bezier(0.25,0.46,0.45,0.94)',
                }}
                  onMouseEnter={e => { if (!isActive) { e.currentTarget.style.color = TEXT_PRIMARY; e.currentTarget.style.background = 'rgba(255,255,255,0.05)'; } }}
                  onMouseLeave={e => { if (!isActive) { e.currentTarget.style.color = 'rgba(245,245,245,0.55)'; e.currentTarget.style.background = 'transparent'; } }}
                >{l.label}</a>
              );
            })}
          </div>
        )}

        {!isMobile && (
          <Btn href={bookingUrl} style={{ padding: '9px 20px', fontSize: '0.83rem', animation: activeSection === 'process' ? 'ctaGlowPulse 2s ease-in-out infinite' : undefined }}>
            Increase My Revenue Per Employee →
          </Btn>
        )}

        {isMobile && (
          <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            <Btn href={bookingUrl} style={{ padding: '8px 14px', fontSize: '0.72rem', whiteSpace: 'nowrap', animation: activeSection === 'process' ? 'ctaGlowPulse 2s ease-in-out infinite' : undefined }}>Increase My RPE →</Btn>
            <button onClick={() => setMobileOpen(o => !o)} style={{ background: 'transparent', border: 'none', color: TEXT_PRIMARY, cursor: 'pointer', padding: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', minWidth: 44, minHeight: 44 }}>
              <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
                {mobileOpen
                  ? <><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></>
                  : <><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></>}
              </svg>
            </button>
          </div>
        )}

        {isMobile && mobileOpen && (
          <div style={{
            position: 'absolute', top: 60, left: 0, right: 0,
            background: 'rgba(13,13,13,0.97)', backdropFilter: 'blur(22px)',
            border: `1px solid ${BORDER}`, borderRadius: 16, padding: 16,
            display: 'flex', flexDirection: 'column', gap: 4, zIndex: 9001,
          }}>
            {links.map(l => {
              if (l.onClick) {
                return (
                  <button key={l.label} onClick={() => { l.onClick(); setMobileOpen(false); }} style={{
                    color: currentView === 'about' ? ACCENT : TEXT_SECONDARY,
                    fontSize: '0.9rem', textDecoration: 'none',
                    padding: '12px 16px', borderRadius: 8, fontWeight: 500, transition: 'all 0.2s',
                    background: 'transparent', border: 'none', cursor: 'pointer', fontFamily: 'inherit',
                    textAlign: 'left', width: '100%',
                  }}
                    onMouseEnter={e => { e.currentTarget.style.background = 'rgba(255,107,0,0.1)'; e.currentTarget.style.color = ACCENT; }}
                    onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = currentView === 'about' ? ACCENT : TEXT_SECONDARY; }}
                  >{l.label}</button>
                );
              }
              return (
                <a key={l.label} href={l.href} onClick={(e) => { handleNavClick(e, l.href); setMobileOpen(false); }} style={{
                  color: TEXT_SECONDARY, fontSize: '0.9rem', textDecoration: 'none',
                  padding: '12px 16px', borderRadius: 8, fontWeight: 500, transition: 'all 0.2s',
                }}
                  onMouseEnter={e => { e.target.style.background = 'rgba(255,107,0,0.1)'; e.target.style.color = ACCENT; }}
                  onMouseLeave={e => { e.target.style.background = 'transparent'; e.target.style.color = TEXT_SECONDARY; }}
                >{l.label}</a>
              );
            })}
          </div>
        )}
      </div>
    </nav>
    </header>
  );
}

// ── Hero ──────────────────────────────────────────────────────────
function Hero({ bookingUrl }) {
  const { width } = useWindowSize();
  const isMobile = width <= 768;
  const [text, setText] = React.useState('');
  const [mIdx, setMIdx] = React.useState(0);
  const [cIdx, setCIdx] = React.useState(0);
  const [scrollY, setScrollY] = React.useState(0);
  const [mouse, setMouse] = React.useState({ x: 0, y: 0 });
  const cardRef = React.useRef(null);
  const sectionRef = React.useRef(null);
  const reduced = usePrefersReducedMotion();

  // Scroll tracking for badge parallax
  React.useEffect(() => {
    const h = () => setScrollY(window.scrollY);
    window.addEventListener('scroll', h, { passive: true });
    return () => window.removeEventListener('scroll', h);
  }, []);

  // Mouse parallax tracking (rAF-throttled)
  React.useEffect(() => {
    if (reduced || isMobile) return;
    let raf;
    let pending = null;
    const h = (e) => {
      pending = e;
      if (raf) return;
      raf = requestAnimationFrame(() => {
        raf = null;
        if (!pending) return;
        const rect = sectionRef.current?.getBoundingClientRect();
        if (!rect) return;
        const x = ((pending.clientX - rect.left) / rect.width - 0.5) * 2;
        const y = ((pending.clientY - rect.top) / rect.height - 0.5) * 2;
        setMouse({ x, y });
        pending = null;
      });
    };
    window.addEventListener('mousemove', h);
    return () => { window.removeEventListener('mousemove', h); cancelAnimationFrame(raf); };
  }, [reduced, isMobile]);

  const msgs = ['Drafting follow-up for Acme Corp...', 'Logging call notes, Sarah Chen...', 'Scheduling proposal review...', 'Pipeline updated - 3 deals advanced...'];
  React.useEffect(() => {
    if (reduced) { setText(msgs[0]); return; }
    const msg = msgs[mIdx];
    if (cIdx <= msg.length) {
      const t = setTimeout(() => { setText(msg.slice(0, cIdx)); setCIdx(c => c + 1); }, cIdx === 0 ? 600 : 38);
      return () => clearTimeout(t);
    } else {
      const t = setTimeout(() => { setMIdx(m => (m + 1) % msgs.length); setCIdx(0); }, 1800);
      return () => clearTimeout(t);
    }
  }, [cIdx, mIdx, reduced]);

  // Parallax values
  const cardTiltX = reduced ? 0 : mouse.y * -6;
  const cardTiltY = reduced ? 0 : mouse.x * 8;
  const badgeDrift = reduced ? 0 : Math.min(scrollY * 0.12, 24);

  return (
    <section ref={sectionRef} style={{ minHeight: '100dvh', background: 'rgba(8,8,8,0.88)', display: 'flex', alignItems: 'center', position: 'relative', overflow: 'hidden' }}>

      {/* Radial orange glow behind content */}
      <div style={{
        position: 'absolute', right: '-5%', top: '20%',
        width: 700, height: 700, borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(255,107,0,0.07) 0%, transparent 70%)',
        pointerEvents: 'none',
      }} />

      <div style={{
        maxWidth: 1200, margin: '0 auto', width: '100%',
        padding: isMobile ? '120px 20px 60px' : '160px 64px 100px',
        display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '1fr 1fr',
        gap: isMobile ? 40 : 64, alignItems: 'center',
      }}>
        {/* Left: copy — entrance stagger via CSS animation */}
        <div>
          <div style={{ animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.1s both' }}>
            <div style={{
              display: 'inline-flex', alignItems: 'center', gap: 8,
              background: 'rgba(255,107,0,0.08)', border: '1px solid rgba(255,107,0,0.25)',
              color: ACCENT, fontSize: '0.7rem', letterSpacing: '0.12em', textTransform: 'uppercase',
              padding: '8px 18px', borderRadius: 100, marginBottom: 28,
              fontFamily: 'JetBrains Mono, monospace', fontWeight: 500,
            }}>
              <span style={{ width: 6, height: 6, borderRadius: '50%', background: ACCENT, display: 'inline-block', animation: 'pulse-dot 2s ease-in-out infinite' }} />
              2 Founding Partner Spots - May 2026
            </div>
          </div>

          <div style={{ animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.22s both' }}>
            <h1 style={{
              fontFamily: '"Bebas Neue", sans-serif', fontSize: 'clamp(2.6rem,5vw,4.8rem)',
              fontWeight: 400, lineHeight: 1.02, letterSpacing: '0.02em',
              textTransform: 'uppercase', margin: '0 0 8px', color: TEXT_PRIMARY,
            }}>40% of your team's week isn't selling, building, or thinking. It's admin.</h1>
          </div>

          <div style={{ animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.34s both' }}>
            <h2 style={{
              fontFamily: '"Bebas Neue", sans-serif', fontSize: 'clamp(1.4rem,2.5vw,2.2rem)',
              fontWeight: 400, lineHeight: 1.05, letterSpacing: '0.02em',
              textTransform: 'uppercase', margin: '0 0 20px', color: ACCENT,
            }}>Not because they're lazy. Because admin owns their calendar.</h2>
          </div>

          <div style={{ animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.46s both' }}>
            <p style={{ color: TEXT_SECONDARY, fontSize: 'clamp(1rem,1.2vw,1.1rem)', lineHeight: 1.75, maxWidth: 480, marginBottom: 32 }}>
              International Data Corporation (IDC): <strong style={{ color: TEXT_PRIMARY }}>40% of the week is mechanical work.</strong> Stanford-Carnegie: hybrid human–artificial intelligence teams outperform pure-human teams by 24.3%. Artificial intelligence operations reclaims those hours and redirects them to revenue. Same headcount. Higher revenue per employee.
            </p>
          </div>

          <div style={{ animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.58s both', display: 'flex', gap: 16, flexWrap: 'wrap' }}>
            <Btn href={bookingUrl} style={{ fontSize: '0.95rem', padding: '14px 28px' }}>Book a Free Call →</Btn>
            <BtnOutline href="#process">See How It Works</BtnOutline>
          </div>
        </div>

        {/* Right: Architecture card with mouse parallax */}
        {!isMobile && (
          <div style={{
            animation: 'heroFadeUp 0.9s cubic-bezier(0.25,0.46,0.45,0.94) 0.3s both',
            position: 'relative',
            perspective: 1200,
          }}>
            <div ref={cardRef} style={{
              background: SURFACE_LIGHT, border: `1px solid ${BORDER}`,
              borderRadius: 24, padding: '28px 28px 20px',
              boxShadow: `0 0 80px rgba(255,107,0,0.1), 0 24px 60px rgba(0,0,0,0.4)`,
              transform: `rotateX(${cardTiltX}deg) rotateY(${cardTiltY}deg)`,
              transition: reduced ? 'none' : 'transform 0.2s cubic-bezier(0.25,0.46,0.45,0.94)',
              transformStyle: 'preserve-3d',
            }}>
              {/* Live feed */}
              <div style={{ background: SURFACE_ELEVATED, border: '1px solid rgba(255,107,0,0.2)', borderRadius: 12, padding: '14px 18px', marginBottom: 16 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 }}>
                  <div style={{ width: 7, height: 7, borderRadius: '50%', background: '#22c55e', animation: 'pulse-dot 2s ease-in-out infinite' }} />
                  <span style={{ fontFamily: 'JetBrains Mono,monospace', fontSize: '0.6rem', color: MUTED, letterSpacing: '0.1em' }}>LIVE FEED, ARTIFICIAL INTELLIGENCE VOICE LAYER</span>
                </div>
                <div style={{ fontFamily: 'JetBrains Mono,monospace', fontSize: '0.78rem', color: TEXT_PRIMARY, lineHeight: 1.6 }}>
                  <span style={{ color: ACCENT, marginRight: 4 }}>▶</span>{text}
                  <span style={{ display: 'inline-block', width: 2, height: '0.8em', background: ACCENT, marginLeft: 2, verticalAlign: 'middle', animation: 'blink 1.1s step-end infinite' }} />
                </div>
              </div>
              <SystemArchitectureSVG />
            </div>

            {/* Floating RPE badge — drifts up on scroll */}
            <div style={{
              position: 'absolute', bottom: -16, left: -16,
              background: SURFACE_LIGHT, border: `1px solid ${BORDER}`,
              borderRadius: 14, padding: '12px 18px',
              display: 'flex', alignItems: 'center', gap: 12,
              boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
              transform: `translateY(${-badgeDrift}px)`,
              transition: 'transform 0.1s linear',
            }}>
              <div style={{ width: 36, height: 36, borderRadius: 10, background: ACCENT, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke={SURFACE2} strokeWidth="2.5"><path d="M23 6l-9.5 9.5-5-5L1 18"/><path d="M17 6h6v6"/></svg>
              </div>
              <div>
                <div style={{ fontFamily: '"Bebas Neue",sans-serif', fontSize: '1.2rem', color: TEXT_PRIMARY, lineHeight: 1 }}>2× Revenue Per Employee</div>
                <div style={{ fontSize: '0.7rem', color: MUTED }}>Same headcount. Higher output.</div>
              </div>
            </div>
          </div>
        )}
      </div>
    </section>
  );
}

// ── Stats ─────────────────────────────────────────────────────────
function StatsSection() {
  const reduced = usePrefersReducedMotion();
  const { width } = useWindowSize();
  const isMobile = width <= 768;
  const [vals, setVals] = React.useState([0, 0]);
  const ref = React.useRef(null);

  const targets = [10, 2];

  React.useEffect(() => {
    if (reduced) { setVals(targets); return; }
    const obs = new IntersectionObserver(([e]) => {
      if (!e.isIntersecting) return;
      obs.disconnect();
      targets.forEach((target, idx) => {
        const dur = 1400 + idx * 200;
        const t0 = performance.now();
        const tick = (now) => {
          const p = Math.min((now - t0) / dur, 1);
          const eased = 1 - Math.pow(1 - p, 3);
          setVals(prev => { const n = [...prev]; n[idx] = Math.round(target * eased); return n; });
          if (p < 1) requestAnimationFrame(tick);
        };
        requestAnimationFrame(tick);
      });
    }, { threshold: 0.4 });
    if (ref.current) obs.observe(ref.current);
    return () => obs.disconnect();
  }, [reduced]);

  const stats = [
    { val: vals[0], unit: '+ hrs', label: 'Reclaimed per person, every week', sub: 'International Data Corporation (IDC): 40% of the week is mechanical. Stanford-Carnegie: artificial intelligence-augmented teams outperform by 24.3%.' },
    { val: vals[1], unit: '× Revenue Per Employee', label: 'Same headcount, higher revenue', sub: 'National Bureau of Economic Research (NBER): artificial intelligence automates 1.4–34% of tasks per occupation. Sales roles average ~12 hrs/week.' },
  ];

  return (
    <section ref={ref} style={{ padding: isMobile ? '60px 20px' : '80px 64px', background: 'rgba(6,6,6,0.88)', borderTop: `1px solid ${BORDER}`, borderBottom: `1px solid ${BORDER}` }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '1fr 1fr', gap: isMobile ? 48 : 80, alignItems: 'center' }}>
        {stats.map((s, i) => (
          <FadeUp key={i} delay={i * 120}>
            <div style={{ display: 'flex', alignItems: 'flex-start', gap: 28 }}>
              <div>
                <div style={{ display: 'flex', alignItems: 'baseline', gap: 4, marginBottom: 10 }}>
                  <span style={{ fontFamily: '"Playfair Display",serif', fontSize: 'clamp(4rem,7vw,6rem)', fontWeight: 400, fontStyle: 'italic', color: TEXT_PRIMARY, lineHeight: 1 }}>{s.val}</span>
                  <span style={{ fontFamily: '"Playfair Display",serif', fontSize: 'clamp(2rem,3.5vw,3.5rem)', fontWeight: 400, fontStyle: 'italic', color: ACCENT, lineHeight: 1 }}>{s.unit}</span>
                </div>
                <div style={{ width: 40, height: 2, background: ACCENT, borderRadius: 2, marginBottom: 14 }} />
                <div style={{ fontWeight: 700, fontSize: '1.05rem', color: TEXT_PRIMARY, marginBottom: 6 }}>{s.label}</div>
                <div style={{ fontSize: '0.82rem', color: MUTED }}>{s.sub}</div>
              </div>
            </div>
          </FadeUp>
        ))}
      </div>
    </section>
  );
}

// ── Logo Marquee ──────────────────────────────────────────────────
function LogoMarquee() {
  const logos = [
    { name: 'Notion', src: 'logos/notion.svg' },
    { name: 'Claude', src: 'logos/claude-icon.png' },
    { name: 'Ollama', src: 'logos/ollama.png' },
    { name: 'Gmail', src: 'logos/gmail.svg' },
    { name: 'Calendar', src: 'logos/calendar.svg' },
    { name: 'n8n', src: 'logos/n8n.svg' },
    { name: 'Slack', src: 'logos/slack.svg' },
    { name: 'Apify', src: 'logos/apify-icon.png' }
  ];
  const { width } = useWindowSize();
  const isMobile = width <= 768;
  const trackLen = isMobile ? 15 : 100;
  const track = Array.from({ length: trackLen }, () => logos).flat();
  const trackRef = React.useRef(null);

  // RAF-driven marquee — impervious to CSS animation suppression
  React.useEffect(() => {
    const el = trackRef.current;
    if (!el) return;
    let raf;
    let x = 0;
    // Compute speed so one loop takes ~300s on mobile, ~2000s on desktop
    const computeSpeed = () => {
      const halfW = el.scrollWidth / 2;
      const targetSec = isMobile ? 300 : 2000;
      return halfW / (targetSec * 60); // px per frame at 60fps
    };
    let speed = computeSpeed();

    const step = () => {
      x -= speed;
      const halfW = el.scrollWidth / 2;
      if (Math.abs(x) >= halfW) x = 0;
      el.style.transform = `translateX(${x}px)`;
      raf = requestAnimationFrame(step);
    };

    // Recompute speed after first paint when scrollWidth is accurate
    const init = () => { speed = computeSpeed(); raf = requestAnimationFrame(step); };
    const to = setTimeout(init, 0);

    return () => { clearTimeout(to); cancelAnimationFrame(raf); };
  }, [isMobile]);

  return (
    <div style={{ background: SURFACE, borderTop: `1px solid ${BORDER}`, borderBottom: `1px solid ${BORDER}`, padding: '24px 0 40px', overflow: 'hidden' }}>
      <div style={{ textAlign: 'center', marginBottom: 24 }}>
        <span style={{
          display: 'inline-block', background: ACCENT, color: SURFACE,
          padding: '8px 22px', borderRadius: 100,
          fontFamily: '"JetBrains Mono",monospace', fontSize: '0.7rem',
          letterSpacing: '0.15em', textTransform: 'uppercase', fontWeight: 600,
        }}>Built on tools you already own</span>
      </div>
      <div ref={trackRef} style={{ display: 'flex', width: 'max-content', willChange: 'transform' }}>
        {track.map((logo, i) => (
          <div key={i} style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '0 48px', transition: 'transform 0.3s', flexShrink: 0 }}
            onMouseEnter={e => { e.currentTarget.style.transform = 'scale(1.15)'; }}
            onMouseLeave={e => { e.currentTarget.style.transform = 'scale(1)'; }}
          >
            <img
              src={logo.src}
              alt={logo.name}
              style={{
                height: 48,
                width: 'auto',
                maxWidth: 130,
                objectFit: 'contain',
                mixBlendMode: (logo.name === 'Claude' || logo.name === 'Apify') ? 'screen' : 'normal',
                filter: logo.name === 'Ollama' ? 'brightness(0) invert(1)' : 'none',
                opacity: logo.name === 'Ollama' ? 0.9 : 1,
              }}
            />
          </div>
        ))}
      </div>
    </div>
  );
}

Object.assign(window, { Navbar, Hero, StatsSection, LogoMarquee });
