function MobileStickyCTA() {
  const [show, setShow] = useState(false);

  useEffect(() => {
    const hero = document.getElementById('top');
    if (!hero) return;
    // Show once the hero section has fully left the viewport
    const io = new IntersectionObserver(
      ([entry]) => setShow(!entry.isIntersecting),
      { threshold: 0, rootMargin: '0px' }
    );
    io.observe(hero);
    return () => io.disconnect();
  }, []);

  return (
    <>
      <style>{`
        @media (min-width: 821px) { .mobile-sticky-cta { display: none !important; } }
        .mobile-sticky-cta {
          position: fixed;
          bottom: 0; left: 0; right: 0;
          z-index: 45;
          pointer-events: none;
          transition: transform .4s cubic-bezier(.2,.7,.2,1), opacity .4s;
        }
        .mobile-sticky-cta.visible { pointer-events: auto; }
        .mobile-sticky-cta-blur {
          padding: 20px 20px 28px;
          background: linear-gradient(
            to bottom,
            rgba(246,241,232,0) 0%,
            rgba(246,241,232,0.88) 28%,
            rgba(246,241,232,1) 100%
          );
          backdrop-filter: blur(0px);
          -webkit-backdrop-filter: blur(0px);
          display: flex;
          justify-content: center;
        }
        .mobile-sticky-cta.visible .mobile-sticky-cta-blur {
          backdrop-filter: blur(14px);
          -webkit-backdrop-filter: blur(14px);
        }
        .mobile-sticky-cta-btn {
          width: 100%;
          max-width: 400px;
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 10px;
          padding: 16px 24px;
          border-radius: 999px;
          background: var(--fg);
          color: var(--bg);
          font-family: var(--sans);
          font-size: 14px;
          font-weight: 500;
          letter-spacing: -0.01em;
          border: none;
          cursor: pointer;
          box-shadow: 0 4px 24px rgba(30,25,18,0.18);
          transition: transform .25s, box-shadow .25s;
        }
        .mobile-sticky-cta-btn:active { transform: scale(0.97); }
      `}</style>
      <div
        className={`mobile-sticky-cta${show ? ' visible' : ''}`}
        style={{ transform: show ? 'translateY(0)' : 'translateY(100%)', opacity: show ? 1 : 0 }}
      >
        <div className="mobile-sticky-cta-blur">
          <button
            className="mobile-sticky-cta-btn"
            onClick={() => window.__openContactModal()}
          >
            Diagnosticar meu produto
            <svg width="13" height="13" viewBox="0 0 13 13" fill="none">
              <path d="M2.5 10.5L10.5 2.5M10.5 2.5H5M10.5 2.5V8" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/>
            </svg>
          </button>
        </div>
      </div>
    </>
  );
}

function App() {
  const [tweaks, setTweaks] = useState(TWEAK_DEFAULTS);
  const [editMode, setEditMode] = useState(false);

  useEffect(() => {
    applyTweaks(tweaks);

    const handler = (e) => {
      if (!e.data) return;
      if (e.data.type === '__activate_edit_mode') setEditMode(true);
      if (e.data.type === '__deactivate_edit_mode') setEditMode(false);
    };
    window.addEventListener('message', handler);
    window.parent.postMessage({ type: '__edit_mode_available' }, '*');
    return () => window.removeEventListener('message', handler);
  }, []);

  return (
    <>
      <Nav />
      <main>
        <Hero />
        <Logos />
        <Problema />
        <Portrait />
        <Metodo />
        <Entregaveis />
        <Diferenca />
        <Cases />
        <Autoridade />
        <Objecoes />
        <CTAFinal />
      </main>
      <Footer />
      <TechOverlay />
      <TweakPanel tweaks={tweaks} setTweaks={setTweaks} visible={editMode} />
      <ContactModal />
      <MobileStickyCTA />
    </>
  );
}

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