// App root — composes all sections + sticky mobile CTA + WhatsApp button + scroll observer

function StickyMobileCTA({ visible }) {
  return (
    <div style={{
      position: 'fixed', bottom: 0, left: 0, right: 0, zIndex: 70,
      transform: visible ? 'translateY(0)' : 'translateY(110%)',
      transition: 'transform .3s ease',
      background: 'rgba(10,9,8,0.92)',
      backdropFilter: 'blur(14px) saturate(140%)',
      WebkitBackdropFilter: 'blur(14px) saturate(140%)',
      borderTop: '1px solid var(--line-2)',
      padding: '12px 16px',
      display: 'flex', alignItems: 'center', gap: 12,
    }} className="sticky-cta">
      <div style={{ flex: 1, lineHeight: 1.2 }}>
        <div className="mono" style={{ fontSize: 10, letterSpacing: '0.14em', color: 'var(--fg-mute)' }}>
          <span style={{ textDecoration: 'line-through' }}>R$197</span> · LANÇAMENTO
        </div>
        <div style={{ fontSize: 18, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--coral)' }}>R$147</div>
      </div>
      <a href="https://pay.kiwify.com.br/iIkOFg8" target="_blank" rel="noopener noreferrer" className="btn btn-primary" style={{ padding: '12px 18px', fontSize: 14 }}>
        Liberar acesso
        <Icon.ArrowRight size={14} />
      </a>
      <style>{`
        @media (min-width: 760px) { .sticky-cta { display: none !important; } }
      `}</style>
    </div>
  );
}

function WhatsAppFAB() {
  return (
    <a
      href="https://wa.me/5511999999999"
      target="_blank"
      rel="noopener"
      aria-label="Falar no WhatsApp"
      style={{
        position: 'fixed', right: 20, bottom: 88, zIndex: 60,
        width: 54, height: 54, borderRadius: 50,
        background: '#25D366', color: '#fff',
        display: 'grid', placeItems: 'center',
        boxShadow: '0 12px 28px -10px rgba(37,211,102,0.55), 0 0 0 1px rgba(255,255,255,0.08) inset',
      }}
      className="whatsapp-fab"
    >
      <Icon.WhatsApp size={26} />
      <style>{`
        @media (min-width: 760px) {
          .whatsapp-fab { bottom: 24px !important; }
        }
      `}</style>
    </a>
  );
}

function App() {
  const [scrollPct, setScrollPct] = React.useState(0);

  React.useEffect(() => {
    // Scroll progress for sticky CTA
    const onScroll = () => {
      const max = document.body.scrollHeight - window.innerHeight;
      setScrollPct(window.scrollY / Math.max(1, max));
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  React.useEffect(() => {
    // IntersectionObserver for fade-up
    const els = document.querySelectorAll('.fade-up');
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' });
    els.forEach(el => io.observe(el));

    // Pointer-tracked card glow
    const cards = document.querySelectorAll('.card');
    const onMove = (e) => {
      const r = e.currentTarget.getBoundingClientRect();
      e.currentTarget.style.setProperty('--mx', ((e.clientX - r.left) / r.width * 100) + '%');
      e.currentTarget.style.setProperty('--my', ((e.clientY - r.top) / r.height * 100) + '%');
    };
    cards.forEach(c => c.addEventListener('pointermove', onMove));

    return () => {
      io.disconnect();
      cards.forEach(c => c.removeEventListener('pointermove', onMove));
    };
  });

  return (
    <>
      <Nav />
      <Hero />
      <TrustedBy />
      <DamagingAdmission />
      <WhatKitDoes />
      <DashboardShowcase />
      <StatsBlock />
      <CalcBlock />
      <Compliance />
      <Author />
      <Offer />
      <FAQ />
      <FinalCTA />
      <Footer />
      <StickyMobileCTA visible={scrollPct > 0.3} />
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
