// Ato 1 da página: Nav, Hero (phone vivo), A Onda (102x), Espelho da dor + HowItWorks (Ato 2 pendente).

// Breakpoints únicos da LP: mobile (≤640) e desktop (>960). Nada fora disso.
const BP = { mobile: 640, desktop: 960 };
window.BP = BP;

// ============================================
// useReveal — IntersectionObserver helper
// ============================================
const useReveal = (threshold = 0.08) => {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((entry) => {
          if (entry.isIntersecting) {
            el.classList.add("in");
            io.unobserve(el);
          }
        });
      },
      { threshold, rootMargin: "0px 0px -30px 0px" }
    );
    io.observe(el);
    return () => io.disconnect();
  }, [threshold]);
  return ref;
};
window.useReveal = useReveal;

// ============================================
// useMediaQuery — true quando a query casa; escuta mudanças (rotação, resize)
// ============================================
const useMediaQuery = (query) => {
  const [matches, setMatches] = React.useState(
    () => window.matchMedia(query).matches
  );
  React.useEffect(() => {
    const mq = window.matchMedia(query);
    const onChange = (e) => setMatches(e.matches);
    mq.addEventListener("change", onChange);
    setMatches(mq.matches);
    return () => mq.removeEventListener("change", onChange);
  }, [query]);
  return matches;
};
window.useMediaQuery = useMediaQuery;

// ============================================
// SplitReveal — word-by-word. EXCLUSIVO do H1 do hero (regra §4.2 do design).
// lines: [{ parts: [{text, color?}] }, ...]   each entry is a new line
// ============================================
const SplitReveal = ({
  lines,
  startImmediately = false,
  startDelay = 0,
  baseDelay = 0,
  wordDelay = 55,
  threshold = 0.35,
  className,
  ariaLabel,
}) => {
  const ref = React.useRef(null);
  const [active, setActive] = React.useState(false);

  React.useEffect(() => {
    if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
      setActive(true);
      return;
    }
    if (startImmediately) {
      const t = setTimeout(() => setActive(true), startDelay);
      return () => clearTimeout(t);
    }
    const el = ref.current;
    if (!el) return;
    let t;
    const io = new IntersectionObserver(
      (entries) => entries.forEach((e) => {
        if (e.isIntersecting) {
          t = setTimeout(() => setActive(true), startDelay);
          io.unobserve(el);
        }
      }),
      { threshold, rootMargin: "0px 0px -40px 0px" }
    );
    io.observe(el);
    return () => { io.disconnect(); clearTimeout(t); };
  }, [startImmediately, startDelay, threshold]);

  let wordIdx = 0;
  const fullText = lines.map((ln) => ln.parts.map((p) => p.text).join("")).join(" ");

  return (
    <span
      ref={ref}
      className={"split-reveal " + (active ? "is-active " : "") + (className || "")}
      aria-label={ariaLabel || fullText}
    >
      <span aria-hidden="true">
        {lines.map((line, li) => (
          <span className="sr-line" key={li}>
            {line.parts.map((part, pi) => {
              const tokens = part.text.split(/(\s+)/);
              return tokens.map((tok, ti) => {
                if (tok === "") return null;
                if (/^\s+$/.test(tok)) {
                  return <span className="sr-space" key={`${li}-${pi}-${ti}`}>{tok}</span>;
                }
                const d = baseDelay + wordIdx * wordDelay;
                wordIdx++;
                return (
                  <span
                    className="sr-word"
                    key={`${li}-${pi}-${ti}`}
                    style={{ "--d": `${d}ms`, color: part.color || undefined }}
                  >
                    {tok}
                  </span>
                );
              });
            })}
          </span>
        ))}
      </span>
    </span>
  );
};
window.SplitReveal = SplitReveal;

// ============================================
// Logo lockup
// ============================================
const Logo = ({ size = 38, onDark = false }) => (
  <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
    <img
      src="uploads/gocreators-icon-blue.png"
      alt="GoCreators"
      width={size}
      height={size}
      style={{
        width: size, height: size,
        borderRadius: 10,
        objectFit: "contain",
        flexShrink: 0,
        display: "block",
      }}
    />
    <div style={{ lineHeight: 1, display:"flex", flexDirection:"column", gap: 2 }}>
      <span className="display" style={{ color: onDark ? "white" : "var(--gc-blue)", fontSize: 22, fontWeight: 800, letterSpacing: "-0.01em" }}>
        GOCREATORS.
      </span>
      <span style={{ color: onDark ? "rgba(255,255,255,.55)" : "var(--ink-3)", fontSize: 10, letterSpacing: ".1em", textTransform: "uppercase", fontWeight: 500 }}>by gogroup</span>
    </div>
  </div>
);
window.Logo = Logo;

// ============================================
// Nav
// ============================================
const Nav = () => {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 40);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <nav className={"site-nav " + (scrolled ? "is-scrolled" : "")}>
      <style>{`
        .site-nav {
          position: sticky; top: 0; z-index: 50;
          padding: 18px 0;
          background: rgba(250, 250, 252, 0.78);
          backdrop-filter: blur(14px);
          -webkit-backdrop-filter: blur(14px);
          transition: box-shadow .2s var(--ease), background .2s var(--ease);
        }
        .site-nav.is-scrolled { padding: 12px 0; box-shadow: 0 1px 0 rgba(15,17,42,.06); background: rgba(255,255,255,.86); }
        .site-nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
        .site-nav-links {
          display: flex; gap: 4px; flex: 1;
          justify-content: center;
        }
        .site-nav-links a {
          padding: 10px 18px;
          border-radius: 999px;
          color: var(--ink-2);
          font-weight: 500;
          font-size: 15px;
          transition: background .15s var(--ease), color .15s var(--ease);
        }
        .site-nav-links a:hover { background: var(--gc-blue-050); color: var(--gc-blue); }
        @media (max-width: ${BP.desktop}px) {
          .site-nav-links { display: none; }
        }
        /* Mobile: chips de âncora roláveis no lugar dos links */
        .site-nav-chips { display: none; }
        @media (max-width: ${BP.desktop}px) {
          .site-nav-chips {
            display: flex;
            gap: 8px;
            margin-top: 10px;
            padding: 0 24px 2px;
            overflow-x: auto;
            scrollbar-width: none;
            -webkit-overflow-scrolling: touch;
          }
          .site-nav-chips::-webkit-scrollbar { display: none; }
          .site-nav-chips a {
            flex-shrink: 0;
            padding: 10px 16px;
            border-radius: 999px;
            border: 1px solid var(--line);
            background: white;
            font-size: 13px;
            font-weight: 600;
            color: var(--ink-2);
          }
        }
      `}</style>
      <div className="container site-nav-inner">
        <Logo />
        <div className="site-nav-links">
          <a href="#como-funciona">Como funciona</a>
          <a href="#marcas">Marcas</a>
          <a href="#recompensas">Prêmios</a>
          <a href="#educacao">Aprenda</a>
        </div>
        <a className="btn btn-primary btn-sm" href="/login">
          Criar conta <Icon name="arrow-up-right" size={15} />
        </a>
      </div>
      <div className="site-nav-chips" aria-label="Seções da página">
        <a href="#como-funciona">Como funciona</a>
        <a href="#marcas">Marcas</a>
        <a href="#recompensas">Prêmios</a>
        <a href="#educacao">Aprenda</a>
      </div>
    </nav>
  );
};
window.Nav = Nav;

// ============================================
// Hero — copy à esquerda, phone VIVO à direita (§3.1 do design).
// Orquestração total < 1.5s: eyebrow 0ms → H1 word-by-word 150ms →
// sub 500ms → CTAs 620ms → trust 740ms · phone entra em 400ms.
// ============================================
const Hero = () => {
  const [loaded, setLoaded] = React.useState(false);

  React.useEffect(() => {
    const t = setTimeout(() => setLoaded(true), 60);
    return () => clearTimeout(t);
  }, []);

  const cls = () => "fade-up" + (loaded ? " is-active" : "");

  return (
    <section className={"hero " + (loaded ? "is-loaded" : "")}>
      <style>{`
        .hero {
          position: relative;
          padding: 32px 0 80px;
          overflow: hidden;
          isolation: isolate;
          background: var(--bg);
        }
        .hero-grid {
          position: relative;
          display: grid;
          grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr);
          gap: 48px;
          align-items: center;
          z-index: 1;
        }
        @media (max-width: ${BP.desktop}px) { .hero-grid { grid-template-columns: 1fr; gap: 36px; } }

        .hero h1 {
          font-family: var(--display);
          font-size: clamp(32px, 4vw, 54px);
          font-weight: 800;
          letter-spacing: -0.03em;
          line-height: 1.06;
          margin: 22px 0 0;
          color: var(--ink);
          max-width: 21ch;
        }
        .hero h1 .split-reveal { line-height: 1.06; }
        @media (max-width: ${BP.desktop}px) { .hero h1 { max-width: none; } }

        .hero p.lead {
          margin: 22px 0 0;
          font-size: 17px;
          line-height: 1.55;
          color: var(--ink-3);
          max-width: 500px;
        }
        .hero p.lead strong { color: var(--ink); font-weight: 600; }

        .hero-cta { display:flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
        .hero-trust {
          margin-top: 20px;
          display: flex; flex-wrap: wrap; gap: 16px;
          color: var(--ink-3); font-size: 13px; font-weight: 500;
        }
        .hero-trust span { display: inline-flex; align-items: center; gap: 6px; }

        /* Palco do phone: arco de gradiente estático azul→roxo atrás (única forma do fundo) */
        .hero-stage { position: relative; padding: 24px 0; }
        .hero-arc {
          position: absolute;
          top: 50%; left: 50%;
          width: min(480px, 100%);
          aspect-ratio: 1;
          transform: translate(-50%, -50%) rotate(-24deg);
          border-radius: 50%;
          background: conic-gradient(from 180deg, transparent 12%, var(--gc-blue) 34%, var(--gc-purple) 58%, transparent 82%);
          -webkit-mask: radial-gradient(closest-side, transparent 68%, black 69%, black 82%, transparent 83%);
          mask: radial-gradient(closest-side, transparent 68%, black 69%, black 82%, transparent 83%);
          opacity: .8;
          z-index: 0;
          pointer-events: none;
        }
        .hero-phone-wrap {
          position: relative;
          z-index: 1;
          opacity: 0;
          transform: translateY(20px) scale(.97);
          transition: opacity .6s var(--ease-expo) .4s, transform .7s var(--ease-expo) .4s;
        }
        .hero.is-loaded .hero-phone-wrap { opacity: 1; transform: none; }

        /* 2 cards flutuantes MÁXIMO (desktop) */
        .hero-float {
          position: absolute;
          background: white;
          border: 1px solid var(--line);
          border-radius: 16px;
          padding: 12px 16px;
          display: flex; gap: 12px; align-items: center;
          box-shadow: 0 12px 32px -10px rgba(20,12,80,.18), 0 2px 8px -2px rgba(20,12,80,.06);
          z-index: 3;
          opacity: 0;
          transform: translateY(14px) scale(.94);
          transition:
            opacity .45s var(--ease-expo) var(--in-d, 0ms),
            transform .5s var(--ease-pop) var(--in-d, 0ms);
        }
        .hero.is-loaded .hero-float {
          opacity: 1;
          transform: translateY(0) scale(1);
          animation: float-y 6.5s ease-in-out infinite;
          animation-delay: var(--float-d, 0s);
        }
        .hero-float .iconbox { width: 36px; height: 36px; border-radius: 11px; display:grid; place-items:center; flex-shrink:0; }
        .hero-float .lbl { font-size: 12px; color: var(--ink-4); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
        .hero-float .val { font-size: 19px; font-weight: 700; font-family: var(--display); color: var(--ink); line-height: 1; margin-top: 2px; }

        .hero-float.f1 { bottom: 90px; left: -8px; }
        .hero-float.f2 { top: 70px; right: -8px; }

        @keyframes float-y {
          0%, 100% { transform: translateY(0); }
          50% { transform: translateY(-7px); }
        }

        /* Mobile: floats viram chips estáticos abaixo do phone */
        .hero-chips { display: none; }
        @media (max-width: ${BP.desktop}px) {
          .hero-float { display: none; }
          .hero-chips {
            display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
            margin-top: 20px;
          }
          .hero-chip {
            display: inline-flex; align-items: center; gap: 8px;
            background: white; border: 1px solid var(--line);
            border-radius: 999px; padding: 8px 14px;
            font-size: 13px; font-weight: 600; color: var(--ink-2);
            box-shadow: 0 6px 16px -8px rgba(20,12,80,.12);
          }
          .hero-chip .dot { display: grid; place-items: center; }
        }

        @media (prefers-reduced-motion: reduce) {
          .hero-phone-wrap, .hero-float {
            opacity: 1; transform: none; animation: none; transition: none;
          }
        }
      `}</style>

      <div className="container hero-grid">
          <div className="hero-copy">
            <span
              className={"eyebrow pop-eyebrow " + (loaded ? "is-active" : "")}
              style={{ "--d": "0ms" }}
            >
              As marcas top 1 em vendas do TikTok Shop
              <span className="dado-flag">[DADO: validar claim]</span>
            </span>
            <h1>
              <SplitReveal
                startImmediately
                startDelay={150}
                wordDelay={50}
                lines={[
                  { parts: [
                    { text: "Aprenda a vender e crescer com o " },
                    { text: "maior grupo de marcas ", color: "var(--gc-blue)" },
                    { text: "do TikTok Shop" },
                  ] },
                ]}
              />
            </h1>
            <p className={"lead " + cls()} style={{ "--d": "500ms" }}>
              Profissionalize seu perfil, aprenda com quem mais vende e venda os
              produtos de 6 marcas que já são febre no TikTok. Comissão, método e
              prêmios de verdade: <strong>do PIX ao Porsche</strong>.
            </p>
            <div className={"hero-cta " + cls()} style={{ "--d": "620ms" }}>
              <a className="btn btn-primary" href="/login">
                Quero vender mais <Icon name="arrow-up-right" size={16} />
              </a>
              <a className="btn btn-secondary" href="#como-funciona">
                Ver como funciona <Icon name="arrow-right" size={16} />
              </a>
            </div>
            <div className={"hero-trust " + cls()} style={{ "--d": "740ms" }}>
              <span>
                <Icon name="check-circle" size={16} style={{color:"var(--gc-blue)"}} /> Grátis pra sempre
              </span>
              <span>
                <Icon name="check-circle" size={16} style={{color:"var(--gc-blue)"}} /> Curso e comunidade inclusos
              </span>
              <span>
                <Icon name="check-circle" size={16} style={{color:"var(--gc-blue)"}} /> Comece a vender hoje
              </span>
            </div>
          </div>

          <FaixaMarcas noHero />

          <div className="hero-stage">
            <div className="hero-arc" aria-hidden="true" />
            <div className="hero-phone-wrap">
              <PhoneMock />
            </div>

            <div className="hero-float f1" style={{ "--in-d": "900ms", "--float-d": "2.3s" }}>
              <span className="iconbox" style={{ background: "#E6F8EE", color: "#1E8E4A" }}>
                <Icon name="pix" size={18} />
              </span>
              <div>
                <div className="lbl">PIX recebido</div>
                <div className="val">R$ 412</div>
              </div>
            </div>

            <div className="hero-float f2" style={{ "--in-d": "1050ms", "--float-d": "3.4s" }}>
              <span className="iconbox" style={{ background: "var(--gc-lime-soft)", color: "#54652A" }}>
                <Icon name="trophy" size={18} />
              </span>
              <div>
                <div className="lbl">Ranking</div>
                <div className="val">Top 3%</div>
              </div>
            </div>

            <div className="hero-chips">
              <span className="hero-chip">
                <span className="dot" style={{ color: "#1E8E4A" }}><Icon name="pix" size={15} /></span>
                PIX recebido · R$ 412
              </span>
              <span className="hero-chip">
                <span className="dot" style={{ color: "#9B7400" }}><Icon name="trophy" size={15} /></span>
                Top 3% do ranking
              </span>
            </div>
          </div>
        </div>
    </section>
  );
};
window.Hero = Hero;

// ============================================
// Faixa de marcas — marquee contínuo com as logos das 6 marcas do GoGroup.
// Duas variantes: solta (desktop, abaixo do hero, faixa full-bleed) e
// noHero (mobile, dentro do hero acima do phone, sem precisar de scroll).
// Vida contínua (regra §4.3). prefers-reduced-motion: fileira estática.
// ============================================
const FaixaMarcas = ({ noHero = false }) => {
  const logos = [
    { src: "assets/brands/gocase.png", alt: "Gocase", h: 34 },
    { src: "assets/brands/barbours.png", alt: "Barbours", h: 46 },
    { src: "assets/brands/lescent.png", alt: "Lescent", h: 24 },
    { src: "assets/brands/rituaria.png", alt: "Rituária", h: 34 },
    { src: "assets/brands/kokeshi.png", alt: "Kokeshi", h: 28 },
    { src: "assets/brands/apice.png", alt: "Ápice", h: 36 },
  ];
  return (
    <section
      className={"faixa " + (noHero ? "faixa-hero" : "faixa-solta")}
      aria-label="Marcas do GoGroup"
    >
      <style>{`
        .faixa {
          overflow: hidden;
          background: white;
          border-top: 1px solid var(--line);
          border-bottom: 1px solid var(--line);
        }
        .faixa-solta {
          padding: 26px 0;
          margin-bottom: 24px;
        }
        /* Variante do hero: só mobile, acima do phone, full-bleed (ponta a ponta) */
        .faixa-hero { display: none; }
        @media (max-width: ${BP.desktop}px) {
          .faixa-solta { display: none; }
          .faixa-hero {
            display: block;
            padding: 18px 0;
            margin-top: 28px;
            margin-inline: calc(50% - 50vw);
          }
        }
        .faixa-mask {
          -webkit-mask-image: linear-gradient(90deg, transparent 0%, black 12%, black 88%, transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0%, black 12%, black 88%, transparent 100%);
        }
        .faixa-track {
          display: flex;
          align-items: center;
          gap: 64px;
          width: max-content;
          padding-right: 64px;
          animation: faixa-scroll 48s linear infinite;
        }
        @keyframes faixa-scroll {
          to { transform: translateX(-50%); }
        }
        .faixa-track img {
          object-fit: contain;
          opacity: .85;
          flex-shrink: 0;
        }
        @media (max-width: ${BP.mobile}px) {
          .faixa-track { gap: 44px; padding-right: 44px; animation-duration: 36s; }
          .faixa-track img { transform: scale(.85); }
        }
        @media (prefers-reduced-motion: reduce) {
          .faixa-track { animation: none; }
        }
      `}</style>
      <div className="faixa-mask">
        <div className="faixa-track">
          {/* 6 cópias: metade do track (3 cópias ≈ 2.760px) precisa cobrir ultrawide 2560px.
              Se mudar o nº de cópias, escalar a duração de faixa-scroll na mesma proporção. */}
          {[0, 1, 2, 3, 4, 5].map((copia) => (
            <React.Fragment key={copia}>
              {logos.map((l) => (
                <img
                  key={`${copia}-${l.alt}`}
                  src={l.src}
                  alt={copia === 0 ? l.alt : ""}
                  aria-hidden={copia !== 0}
                  style={{ height: l.h }}
                />
              ))}
            </React.Fragment>
          ))}
        </div>
      </div>
    </section>
  );
};
window.FaixaMarcas = FaixaMarcas;

// ============================================
// A Onda (102x) — tipográfica pura, count-up scroll-scrubbed (§3.2).
// Única seção com scrub: o número varre 1x → 102x conforme a seção entra
// e crava em 102x quando 60% dela está visível.
// ============================================
const Onda = () => {
  const secRef = React.useRef(null);
  const reduced = React.useMemo(
    () => window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches,
    []
  );
  const [n, setN] = React.useState(reduced ? 102 : 1);

  React.useEffect(() => {
    if (reduced) return;
    let raf = null;
    const onScroll = () => {
      if (raf) return;
      raf = requestAnimationFrame(() => {
        raf = null;
        const el = secRef.current;
        if (!el) return;
        const r = el.getBoundingClientRect();
        const vh = window.innerHeight;
        const p = Math.min(1, Math.max(0, (vh - r.top) / (r.height * 0.6)));
        const eased = 1 - Math.pow(1 - p, 2);
        setN(Math.max(1, Math.round(1 + 101 * eased)));
      });
    };
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll, { passive: true });
    return () => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
      if (raf) cancelAnimationFrame(raf);
    };
  }, [reduced]);

  return (
    <section className="onda" ref={secRef}>
      <style>{`
        .onda { padding: 72px 0 96px; text-align: center; }
        .onda-kicker {
          font-family: var(--display);
          font-size: clamp(20px, 2.6vw, 30px);
          font-weight: 600;
          color: var(--ink-2);
          margin: 26px 0 0;
          letter-spacing: -0.02em;
        }
        .onda-num {
          font-family: var(--display);
          font-size: clamp(96px, 18vw, 240px);
          font-weight: 800;
          letter-spacing: -0.05em;
          line-height: 0.9;
          color: var(--gc-blue);
          font-variant-numeric: tabular-nums;
          margin: 4px 0;
        }
        .onda-line {
          font-family: var(--display);
          font-size: clamp(20px, 2.6vw, 30px);
          font-weight: 600;
          color: var(--ink-2);
          letter-spacing: -0.02em;
        }
        .onda-sub {
          max-width: 640px;
          margin: 28px auto 0;
          font-size: 16px;
          line-height: 1.6;
          color: var(--ink-3);
        }
        .onda-stats {
          margin-top: 36px;
          display: flex;
          justify-content: center;
          gap: 48px;
          flex-wrap: wrap;
        }
        .onda-stat .v {
          font-family: var(--display);
          font-size: 30px;
          font-weight: 800;
          color: var(--ink);
          letter-spacing: -0.02em;
        }
        .onda-stat .l { font-size: 13px; color: var(--ink-3); margin-top: 2px; max-width: 200px; }
        .onda-fonte {
          margin-top: 24px;
          font-size: 11px;
          color: var(--ink-4);
        }
      `}</style>
      <div className="container reveal" ref={useReveal(0.1)}>
        <span className="eyebrow">O momento é agora</span>
        <h2 style={{ margin: 0 }}>
          <span className="onda-kicker" style={{ display: "block" }}>O TikTok Shop cresceu</span>
          <span className="onda-num" style={{ display: "block" }} aria-label="102x">{n}x</span>
          <span className="onda-line" style={{ display: "block" }}>no primeiro ano de Brasil. E ainda está começando.</span>
        </h2>
        <p className="onda-sub">
          De US$ 1 milhão para US$ 46 milhões por mês em vendas. O número de criadores
          afiliados ganhando comissão cresceu 46x. Não é tarde demais: é o começo.
          A pergunta é se você entra com método ou fica olhando.
        </p>
        <div className="onda-stats">
          <div className="onda-stat">
            <div className="v">46x</div>
            <div className="l">mais criadores afiliados ativos ganhando comissão</div>
          </div>
          <div className="onda-stat">
            <div className="v">US$ 46 mi/mês</div>
            <div className="l">em vendas no primeiro ano (era US$ 1 mi/mês)</div>
          </div>
        </div>
        <div className="onda-fonte">fonte: TikTok Newsroom, mai/2026</div>
      </div>
    </section>
  );
};
window.Onda = Onda;

// ============================================
// Espelho da dor — objeções como bolhas de comentário de TikTok (§3.3).
// Cada bolha chega como mensagem (stagger), com "digitando…" de 300ms
// antes da resposta da GoCreators. Sem card container.
// ============================================
const EspelhoDaDor = () => {
  const ref = useReveal(0.25);
  const pares = [
    { ini: "J", q: "Não tenho seguidores suficiente.", r: "O TikTok pede 2 mil seguidores pra liberar o Shop. A gente te ajuda a chegar lá, e daí em diante vídeo bom vende com 200 views." },
    { ini: "T", q: "Não sei o que postar.", r: "A gente te mostra o que está vendendo agora, com roteiro." },
    { ini: "L", q: "Já tentei e não vendi.", r: "Vender é técnica, não sorte. Técnica se aprende." },
  ];

  return (
    <section className="dor reveal" ref={ref}>
      <style>{`
        .dor { padding: 32px 0 112px; }
        .dor-head {
          max-width: 760px;
          margin: 0 auto 48px;
          text-align: center;
        }
        .dor-head h2 {
          font-family: var(--display);
          font-size: clamp(30px, 4vw, 48px);
          font-weight: 800;
          letter-spacing: -0.03em;
          line-height: 1.08;
          margin: 0;
        }
        .dor-head h2 .q { color: var(--gc-blue); }

        .dor-feed {
          max-width: 560px;
          margin: 0 auto;
          display: flex;
          flex-direction: column;
          gap: 18px;
        }
        .dor-par { display: flex; flex-direction: column; gap: 10px; }

        .dor-c, .dor-r {
          display: flex; gap: 10px; align-items: flex-end;
          opacity: 0;
          transform: translateY(12px);
        }
        .dor.in .dor-c { animation: dor-in .4s var(--ease-expo) forwards; animation-delay: var(--dc); }
        .dor.in .dor-r { animation: dor-in .4s var(--ease-expo) forwards; animation-delay: var(--dt); }
        @keyframes dor-in { to { opacity: 1; transform: none; } }

        .dor-r { flex-direction: row-reverse; }

        .dor-av {
          width: 34px; height: 34px; border-radius: 50%;
          flex-shrink: 0;
          display: grid; place-items: center;
          font-family: var(--display); font-weight: 700; font-size: 14px;
        }
        .dor-c .dor-av { background: var(--gc-sky-soft); color: #2F6BA8; border: 1px solid var(--gc-sky); }
        .dor-r .dor-av { background: white; border: 1px solid var(--line); padding: 5px; }
        .dor-r .dor-av img { width: 100%; height: 100%; object-fit: contain; }

        .dor-bolha {
          padding: 12px 16px;
          border-radius: 18px;
          font-size: 15px;
          line-height: 1.45;
          max-width: 78%;
        }
        .dor-c .dor-bolha {
          background: white;
          border: 1px solid var(--line);
          border-bottom-left-radius: 6px;
          color: var(--ink-2);
        }
        .dor-r .dor-bolha {
          position: relative;
          background: var(--gc-blue);
          color: white;
          border-bottom-right-radius: 6px;
          font-weight: 500;
        }

        /* "digitando…": os 3 pontos cobrem o texto e somem quando a resposta "chega" */
        .dor-r .rtxt { opacity: 0; }
        .dor.in .dor-r .rtxt { animation: dor-show .25s var(--ease) forwards; animation-delay: var(--dr); }
        .dor-dots {
          position: absolute; inset: 0;
          display: flex; gap: 4px; align-items: center; justify-content: flex-start;
          padding-left: 16px;
        }
        .dor.in .dor-dots { animation: dor-hide .2s var(--ease) forwards; animation-delay: var(--dr); }
        .dor-dots span {
          width: 6px; height: 6px; border-radius: 50%;
          background: rgba(255,255,255,.75);
          animation: dor-dot 1s ease-in-out infinite;
        }
        .dor-dots span:nth-child(2) { animation-delay: .15s; }
        .dor-dots span:nth-child(3) { animation-delay: .3s; }
        @keyframes dor-dot { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
        @keyframes dor-show { to { opacity: 1; } }
        @keyframes dor-hide { to { opacity: 0; visibility: hidden; } }

        .dor-fecho {
          max-width: 720px;
          margin: 56px auto 0;
          text-align: center;
          font-family: var(--display);
          font-size: clamp(24px, 3.2vw, 38px);
          font-weight: 700;
          letter-spacing: -0.025em;
          line-height: 1.2;
          color: var(--ink);
        }
        .dor-fecho em { color: var(--gc-purple); font-style: italic; }

        @media (prefers-reduced-motion: reduce) {
          .dor-c, .dor-r, .dor.in .dor-c, .dor.in .dor-r { animation: none; opacity: 1; transform: none; }
          .dor-r .rtxt, .dor.in .dor-r .rtxt { animation: none; opacity: 1; }
          .dor-dots, .dor.in .dor-dots { display: none; }
        }
      `}</style>

      <div className="container">
        <div className="dor-head">
          <h2>
            Você já viu todo mundo vendendo no TikTok Shop.
            {" "}
            <span className="q">A pergunta é: por que ainda não você?</span>
          </h2>
        </div>

        <div className="dor-feed">
          {pares.map((p, i) => (
            <div className="dor-par" key={i}>
              <div className="dor-c" style={{ "--dc": `${i * 600}ms` }}>
                <span className="dor-av">{p.ini}</span>
                <div className="dor-bolha">"{p.q}"</div>
              </div>
              <div
                className="dor-r"
                style={{ "--dt": `${i * 600 + 200}ms`, "--dr": `${i * 600 + 550}ms` }}
              >
                <span className="dor-av">
                  <img src="uploads/gocreators-icon-blue.png" alt="GoCreators" />
                </span>
                <div className="dor-bolha">
                  <span className="dor-dots" aria-hidden="true"><span/><span/><span/></span>
                  <span className="rtxt">{p.r}</span>
                </div>
              </div>
            </div>
          ))}
        </div>

        <p className="dor-fecho">
          A diferença entre quem posta e quem fatura é <em>método</em>.
          É isso que você encontra aqui.
        </p>
      </div>
    </section>
  );
};
window.EspelhoDaDor = EspelhoDaDor;

// ============================================
// Como funciona — 4 passos ancorados numa linha desenhada no scroll (§3.4).
// Sem card branco: número grande Bricolage italic + título + 1 linha.
// Ícones 3D dos assets v3 (passo 1 usa o logo). Mobile: linha vertical à esquerda.
// ============================================
const HowItWorks = () => {
  const ref = useReveal();
  const stepsRef = useReveal(0.2);
  const steps = [
    { icon: "uploads/gocreators-icon-blue.png", logo: true, title: "Crie sua conta grátis", body: "Sem taxa e sem contrato. Dois minutos e você está dentro, com curso e comunidade inclusos." },
    { icon: "uploads/v3-icon-sacola.png", title: "Escolha o que vender", body: "Produtos de 6 marcas com alta demanda no TikTok Shop, comissão clara e amostra para quem performa." },
    { icon: "uploads/v3-icon-claquete.png", title: "Poste com método", body: "Roteiros, tendências e exemplos do que está convertendo agora. Você nunca mais posta no escuro." },
    { icon: "uploads/v3-icon-moeda-rs.png", title: "Receba comissão e prêmios", body: "Cada venda vira comissão. Cada avanço vira XP, ranking e prêmios reais: PIX, produtos, viagens." },
  ];
  return (
    <section className="how" id="como-funciona">
      <style>{`
        .how { padding: 64px 0 96px; }
        .how-head { text-align: center; margin-bottom: 64px; }
        .how-head h2 { font-family: var(--display); font-size: clamp(32px, 4.4vw, 54px); font-weight: 800; letter-spacing: -0.03em; margin: 16px 0 0; line-height: 1.05; }
        .how-head h2 .accent { color: var(--gc-blue); }

        .how-steps {
          position: relative;
          display: grid;
          grid-template-columns: repeat(4, 1fr);
          gap: 28px;
        }

        /* Linha horizontal desenhada no scroll (o .draw-on-view enfim em uso) */
        .how-line {
          position: absolute;
          top: 43px;
          left: 6%;
          right: 6%;
          height: 40px;
          z-index: 0;
          pointer-events: none;
        }
        .how-line path { stroke: #B9C2F7; }

        .stepv2 {
          position: relative;
          z-index: 1;
          opacity: 0;
          transform: translateY(16px);
          transition: opacity .4s var(--ease-expo), transform .4s var(--ease-expo);
        }
        .how-steps.in .stepv2 { opacity: 1; transform: none; }
        .how-steps.in .stepv2:nth-child(2) { transition-delay: 60ms; }
        .how-steps.in .stepv2:nth-child(3) { transition-delay: 180ms; }
        .how-steps.in .stepv2:nth-child(4) { transition-delay: 300ms; }
        .how-steps.in .stepv2:nth-child(5) { transition-delay: 420ms; }

        .stepv2 .node {
          width: 88px; height: 88px;
          border-radius: 50%;
          background: white;
          border: 1px solid var(--line);
          box-shadow: 0 14px 30px -16px rgba(76,93,240,.35);
          display: grid; place-items: center;
          overflow: hidden;
        }
        .stepv2 .node img { width: 100%; height: 100%; object-fit: cover; }
        .stepv2 .node.logo img { width: 54%; height: 54%; object-fit: contain; }

        .stepv2 .num {
          font-family: var(--display);
          font-style: italic;
          font-weight: 800;
          font-size: 42px;
          line-height: 1;
          color: var(--gc-blue);
          margin: 20px 0 8px;
        }
        .stepv2 h3 {
          font-family: var(--display);
          font-size: 19px; font-weight: 700;
          letter-spacing: -0.015em;
          margin: 0 0 8px;
          line-height: 1.2;
        }
        .stepv2 p { font-size: 14px; color: var(--ink-3); line-height: 1.55; margin: 0; max-width: 260px; }

        /* Tablet: 2x2, sem a linha desenhada */
        @media (max-width: ${BP.desktop}px) {
          .how-steps { grid-template-columns: repeat(2, 1fr); gap: 40px 24px; }
          .how-line { display: none; }
        }
        /* Mobile: linha vertical à esquerda, passos ancorados nela */
        @media (max-width: ${BP.mobile}px) {
          .how-steps { grid-template-columns: 1fr; gap: 36px; }
          .how-steps::before {
            content: "";
            position: absolute;
            left: 33px;
            top: 20px; bottom: 20px;
            width: 2px;
            background: #C9D0F8;
            transform: scaleY(0);
            transform-origin: top center;
            transition: transform 1.1s var(--ease) .15s;
          }
          .how-steps.in::before { transform: scaleY(1); }
          .stepv2 {
            display: grid;
            grid-template-columns: 68px 1fr;
            gap: 16px;
            align-items: start;
          }
          .stepv2 .node { width: 68px; height: 68px; }
          .stepv2 .conteudo { padding-top: 2px; }
          .stepv2 .num { font-size: 30px; margin: 0 0 4px; }
          .stepv2 p { max-width: none; }
        }
        @media (min-width: ${BP.mobile + 1}px) {
          .stepv2 .conteudo { display: contents; }
        }

        @media (prefers-reduced-motion: reduce) {
          .stepv2, .how-steps.in .stepv2 { opacity: 1; transform: none; transition: none; }
          .how-steps::before, .how-steps.in::before { transform: none; transition: none; }
        }
      `}</style>

      <div className="container">
        <div className="how-head reveal" ref={ref}>
          <span className="eyebrow">Como funciona</span>
          <h2>Do zero à primeira comissão em <span className="accent">4 passos</span>.</h2>
        </div>

        <div className="how-steps draw-on-view" ref={stepsRef}>
          <svg
            className="how-line"
            viewBox="0 0 1200 40"
            preserveAspectRatio="none"
            aria-hidden="true"
            fill="none"
            strokeWidth="2.5"
            strokeLinecap="round"
            style={{ "--len": 1210 }}
          >
            <path pathLength="1200" d="M0 20 C 120 4, 240 36, 400 20 S 640 4, 800 20 S 1080 36, 1200 20" strokeDasharray="1210" />
          </svg>
          {steps.map((s, i) => (
            <div className="stepv2" key={i}>
              <span className={"node" + (s.logo ? " logo" : "")}>
                <img src={s.icon} alt="" loading="lazy" />
              </span>
              <div className="conteudo">
                <div className="num">{i + 1}</div>
                <h3>{s.title}</h3>
                <p>{s.body}</p>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};
window.HowItWorks = HowItWorks;
