// ── Hero — Brandly-style editorial, locked to viewport (desktop)
// + stacked composition on mobile so nothing overlaps. The composite
// shifts focus on small screens so Soong stays visible, and the
// corner content (top-right stat, bottom bio + date) reflows below
// the headline on phones instead of colliding with the CTA.

function useCountdown(targetIso) {
  const target = React.useMemo(() => new Date(targetIso).getTime(), [targetIso]);
  const [now, setNow] = React.useState(() => Date.now());
  React.useEffect(() => {
    const t = setInterval(() => setNow(Date.now()), 1000 * 60); // minute tick
    return () => clearInterval(t);
  }, []);
  let diff = Math.max(0, target - now);
  const d = Math.floor(diff / 86400000); diff -= d * 86400000;
  const h = Math.floor(diff / 3600000); diff -= h * 3600000;
  const m = Math.floor(diff / 60000);
  return { d, h, m, isPast: now >= target };
}

function Hero({ onCta }) {
  const cd = useCountdown("2026-06-21T14:00:00-03:00");
  return (
    <header
      className="pf-hero"
      style={{
        position: "relative",
        minHeight: "min(100svh, 1080px)",
        overflow: "hidden",
        background: "var(--abyss)",
        display: "grid",
        gridTemplateRows: "auto 1fr auto",
      }}
    >
      {/* hero composite — image is the protagonist. On phones we shift
          background-position so Soong stays roughly centered instead of
          being cropped left. */}
      <div
        className="pf-hero-bg"
        style={{
          position: "absolute",
          inset: 0,
          zIndex: 0,
          backgroundImage: "url(assets/hero-composite-v2.png)",
          backgroundPosition: "60% center",
          backgroundSize: "cover",
          backgroundRepeat: "no-repeat",
        }}
      />

      {/* ── SOONG — foreground subject, anchored bottom-center over the
          composite (between the China map upper-left and Brazil map upper-
          right). PNG with transparent background; sits above the bg
          and below the gradient washes so he reads as the presenter
          on stage with the trade visual behind him. */}
      <div className="pf-hero-soong" aria-hidden="false" style={{ position: "absolute", left: "50%", bottom: 0, transform: "translateX(-50%)", zIndex: 2, height: "min(92%, 880px)", pointerEvents: "none", display: "flex", alignItems: "flex-end" }}>
        <img src="assets/soong-hero.png" alt="Alexandre Soong" style={{ height: "100%", width: "auto", filter: "drop-shadow(0 30px 60px rgba(0,0,0,0.55)) drop-shadow(0 0 40px rgba(3,5,13,0.35))" }} />
      </div>

      {/* ── DELIVERY ARC — animated China → Brasil overlay ──── */}
      <svg className="pf-arc" viewBox="0 0 1440 900" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0, zIndex: 1, width: "100%", height: "100%", pointerEvents: "none", overflow: "visible" }} aria-hidden="true">
        <defs>
          <linearGradient id="pfArcGrad" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" stopColor="#EF4444" stopOpacity="0.0" />
            <stop offset="18%" stopColor="#EF4444" stopOpacity="0.85" />
            <stop offset="50%" stopColor="#FBBF24" stopOpacity="0.95" />
            <stop offset="82%" stopColor="#22D3EE" stopOpacity="0.85" />
            <stop offset="100%" stopColor="#22D3EE" stopOpacity="0.0" />
          </linearGradient>
          <radialGradient id="pfArcDot" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#FFFFFF" stopOpacity="1" />
            <stop offset="55%" stopColor="#FBBF24" stopOpacity="0.95" />
            <stop offset="100%" stopColor="#FBBF24" stopOpacity="0" />
          </radialGradient>
          <filter id="pfArcGlow" x="-30%" y="-30%" width="160%" height="160%">
            <feGaussianBlur stdDeviation="3" result="b" />
            <feMerge><feMergeNode in="b" /><feMergeNode in="SourceGraphic" /></feMerge>
          </filter>
        </defs>
        <path d="M 290 235 Q 720 30 1100 235" fill="none" stroke="rgba(251,191,36,0.18)" strokeWidth="3" strokeLinecap="round" />
        <path id="pfArcPath" d="M 290 235 Q 720 30 1100 235" fill="none" stroke="url(#pfArcGrad)" strokeWidth="2.4" strokeLinecap="round" strokeDasharray="8 10" filter="url(#pfArcGlow)" style={{ animation: "pfArcDash 6s linear infinite" }} />
        <circle cx="290" cy="235" r="6" fill="#EF4444" filter="url(#pfArcGlow)" />
        <circle cx="290" cy="235" r="11" fill="none" stroke="#EF4444" strokeWidth="1" opacity="0.6" style={{ transformOrigin: "290px 235px", animation: "pfPing 2.4s ease-out infinite" }} />
        <circle cx="1100" cy="235" r="6" fill="#22D3EE" filter="url(#pfArcGlow)" />
        <circle cx="1100" cy="235" r="11" fill="none" stroke="#22D3EE" strokeWidth="1" opacity="0.6" style={{ transformOrigin: "1100px 235px", animation: "pfPing 2.4s ease-out 1.2s infinite" }} />
        <circle r="9" fill="url(#pfArcDot)" filter="url(#pfArcGlow)">
          <animateMotion dur="5.6s" repeatCount="indefinite" rotate="auto" path="M 290 235 Q 720 30 1100 235" />
        </circle>
      </svg>

      {/* gradient washes (left + top/bottom + vignette + grain + bottom fade) */}
      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(90deg, rgba(3,5,13,0.62) 0%, rgba(3,5,13,0.32) 18%, rgba(3,5,13,0.08) 34%, transparent 50%)" }} />
      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(180deg, rgba(3,5,13,0.45) 0%, transparent 12%, transparent 55%, rgba(6,9,18,0.40) 75%, rgba(6,9,18,0.85) 92%, var(--void) 100%)" }} />
      <div style={{ position: "absolute", inset: 0, zIndex: 1, boxShadow: "inset 0 0 140px 20px rgba(3,5,13,0.35)" }} />
      <div className="pf-grain" style={{ position: "absolute", inset: 0, zIndex: 1, opacity: 0.04, mixBlendMode: "overlay", pointerEvents: "none" }} />
      <div aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: "180px", zIndex: 1, background: "linear-gradient(180deg, transparent 0%, rgba(6,9,18,0.5) 40%, rgba(3,5,13,0.92) 80%, var(--void) 100%)", pointerEvents: "none" }} />

      {/* ── TOP ROW: top-right stat ────────────────────── */}
      <div className="pf-hero-top" style={{ position: "relative", zIndex: 3, padding: "20px clamp(20px,3.5vw,44px) 0", display: "flex", justifyContent: "flex-end", alignItems: "flex-start", gap: "24px" }}>
        <Reveal delay={0.08}>
          <div className="pf-hero-stat" style={{ textAlign: "right", maxWidth: "240px", textShadow: "0 2px 14px rgba(3,5,13,0.85)" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontSize: "clamp(1.05rem,1.6vw,1.55rem)", color: "var(--txt-white)", letterSpacing: "-0.01em", lineHeight: 1 }}>
              +R$ 100 milhões
            </div>
            <div style={{ fontFamily: "var(--f-body)", fontSize: ".68rem", color: "var(--txt-soft)", lineHeight: 1.5, marginTop: "6px" }}>
              em mercadorias importadas direto da China nos últimos 19 anos.
            </div>
          </div>
        </Reveal>
      </div>

      {/* ── MIDDLE: event-name wordmark / sub-headline / body — left column ─ */}
      <div className="pf-hero-mid" style={{ position: "relative", zIndex: 2, padding: "0 clamp(20px,3.5vw,44px)", maxWidth: "560px", alignSelf: "center", display: "flex", flexDirection: "column", justifyContent: "center" }}>
        <Reveal delay={0.12}>
          <div style={{ marginBottom: "24px", display: "flex", flexDirection: "column", gap: "0px" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontStyle: "italic", fontWeight: 400, fontSize: "clamp(2rem,4.2vw,3.6rem)", lineHeight: 0.95, letterSpacing: "-0.02em", color: "var(--txt-white)", textShadow: "0 4px 24px rgba(3,5,13,0.95), 0 2px 8px rgba(3,5,13,0.85)" }}>
              Minha Primeira
            </div>
            <div style={{ fontFamily: "var(--f-serif)", fontStyle: "italic", fontWeight: 400, fontSize: "clamp(2.8rem,6vw,5.2rem)", lineHeight: 0.95, letterSpacing: "-0.025em", color: "var(--go-4)", textShadow: "0 2px 22px rgba(180,120,18,0.4), 0 6px 28px rgba(3,5,13,0.92)" }}>
              Importação<span style={{ color: "var(--go-3)" }}>.</span>
            </div>
          </div>
        </Reveal>
        <Reveal delay={0.2}>
          <h1 style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontStyle: "normal", fontSize: "clamp(1.15rem,2.1vw,1.95rem)", lineHeight: 1.15, letterSpacing: "-0.012em", color: "var(--txt-white)", margin: "0 0 16px", textShadow: "0 4px 24px rgba(3,5,13,0.95), 0 2px 8px rgba(3,5,13,0.8)" }}>
            Da China ao seu estoque.<br />
            <span className="pf-glow-text" style={{ fontStyle: "italic" }}>Sem achismo, sem prejuízo.</span>
          </h1>
        </Reveal>
        <Reveal delay={0.28}>
          <p style={{ fontFamily: "var(--f-body)", fontSize: "clamp(.86rem,.92vw,.95rem)", lineHeight: 1.6, color: "var(--txt-soft)", maxWidth: "440px", margin: 0, textShadow: "0 2px 10px rgba(3,5,13,0.75)" }}>
            Um encontro, presencial em Alphaville, com <strong style={{ color: "var(--txt-white)", fontWeight: 600 }}>Alexandre Soong.</strong> O método que já moveu mais de 100 milhões em mercadorias da China para o Brasil.
          </p>
        </Reveal>

        {/* MOBILE-ONLY inline CTA — visible only on phones (sized to text column) */}
        <Reveal delay={0.34}>
          <div className="pf-hero-cta-inline" style={{ display: "none", marginTop: "26px", flexDirection: "column", alignItems: "flex-start", gap: "10px" }}>
            <Button variant="primary" size="md" onClick={onCta} shimmer>Quero minha vaga →</Button>
            <div style={{ display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--f-mono)", fontSize: ".62rem", letterSpacing: ".06em", color: "var(--txt-soft)", textShadow: "0 2px 10px rgba(3,5,13,0.9)" }}>
              <span style={{ width: "7px", height: "7px", borderRadius: "50%", background: "var(--rd)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
              Vagas limitadas ao espaço físico
            </div>
          </div>
        </Reveal>
      </div>

      {/* ── CENTERED CTA — anchored bottom-center of hero (desktop) ───── */}
      <div className="pf-hero-cta" style={{ position: "absolute", left: "50%", bottom: "clamp(110px,16vh,160px)", transform: "translateX(-50%)", zIndex: 4, display: "flex", flexDirection: "column", alignItems: "center", gap: "12px", textAlign: "center" }}>
        <Reveal delay={0.36}>
          <Button variant="primary" size="md" onClick={onCta} shimmer>Quero minha vaga em São Paulo →</Button>
        </Reveal>
        <Reveal delay={0.42}>
          <div style={{ display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--f-mono)", fontSize: ".64rem", letterSpacing: ".06em", color: "var(--txt-soft)", textShadow: "0 2px 10px rgba(3,5,13,0.9)" }}>
            <span style={{ width: "7px", height: "7px", borderRadius: "50%", background: "var(--rd)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
            Vagas limitadas ao espaço físico da sala
          </div>
        </Reveal>
      </div>

      {/* ── BOTTOM ROW: bio · event stat + countdown ──────────────────────── */}
      <div className="pf-hero-bot" style={{ position: "relative", zIndex: 3, padding: "0 clamp(20px,3.5vw,44px) clamp(18px,3vh,28px)", display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: "32px" }}>
        <Reveal delay={0.44}>
          <div style={{ maxWidth: "300px", textShadow: "0 2px 12px rgba(3,5,13,0.85)" }}>
            <div style={{ fontFamily: "var(--f-mono)", fontSize: ".64rem", fontWeight: 500, letterSpacing: ".22em", textTransform: "uppercase", color: "var(--go-3)", marginBottom: "10px" }}>
              Quem conduz
            </div>
            <p style={{ fontFamily: "var(--f-body)", fontSize: ".76rem", lineHeight: 1.55, color: "var(--txt-soft)", margin: 0 }}>
              Alexandre Soong vive na China e sabe como funciona. Autor, empresário e referência para os brasileiros que aprenderam a importar com método e não com sorte.
            </p>
          </div>
        </Reveal>
        <Reveal delay={0.5}>
          <div style={{ textAlign: "right", maxWidth: "260px", textShadow: "0 2px 14px rgba(3,5,13,0.9)" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontSize: "clamp(1.2rem,1.9vw,1.75rem)", color: "var(--txt-white)", letterSpacing: "-0.01em", lineHeight: 1 }}>
              21 · Junho
            </div>
            <div style={{ fontFamily: "var(--f-body)", fontSize: ".7rem", color: "var(--txt-soft)", lineHeight: 1.5, marginTop: "6px" }}>
              14h às 19h · Alphaville Industrial · Barueri/SP.
            </div>
            {!cd.isPast && (
              <div style={{ marginTop: "10px", display: "inline-flex", alignItems: "center", gap: "8px", padding: "5px 10px", borderRadius: "99px", border: "1px solid rgba(245,158,11,0.35)", background: "rgba(245,158,11,0.06)", fontFamily: "var(--f-mono)", fontSize: ".6rem", letterSpacing: ".14em", textTransform: "uppercase", color: "var(--go-4)" }}>
                <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: "var(--go-4)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
                Faltam {cd.d}d {cd.h}h
              </div>
            )}
          </div>
        </Reveal>
      </div>

      <style>{`
        /* ─── Mobile hero — completely flex column composition ─────
           Flow (top → bottom):
             1. stat (compact, right-aligned chip)
             2. headline + body + inline CTA
             3. Soong portrait (centered, capped height, fades to bg)
             4. bottom row: bio + date in a 2-column compact band
        */
        @media (max-width: 760px) {
          .pf-hero {
            display: flex !important;
            flex-direction: column !important;
            min-height: auto !important;
            padding-bottom: 16px;
          }
          /* Absolute-positioned decorations stay (bg, arc, washes, grain, fades) */

          /* Re-skin gradient washes on mobile so the composite reads
             without a banded "seam" mid-hero. */
          .pf-hero > div[style*="linear-gradient(90deg"] {
            background: linear-gradient(180deg, rgba(3,5,13,0.55) 0%, rgba(3,5,13,0.15) 30%, rgba(3,5,13,0.15) 60%, rgba(3,5,13,0.78) 95%, var(--void) 100%) !important;
          }

          .pf-hero-bg {
            background-position: 55% 35% !important;
            background-size: cover !important;
          }

          /* Flow order */
          .pf-hero-top  { order: 1; padding: 18px 20px 0 !important; }
          .pf-hero-mid  { order: 2; padding: 16px 20px 8px !important; max-width: 100% !important; min-height: 0 !important; }
          .pf-hero-soong{ order: 3; }
          .pf-hero-bot  { order: 4; }

          .pf-hero-stat { max-width: 230px; }

          /* Soong: inline element, centered, capped height with bottom fade */
          .pf-hero-soong {
            position: relative !important;
            inset: auto !important;
            left: auto !important; right: auto !important; top: auto !important; bottom: auto !important;
            transform: none !important;
            margin: 0 auto !important;
            height: clamp(300px, 46svh, 460px) !important;
            display: flex !important;
            align-items: flex-end !important;
            justify-content: center !important;
            width: 100% !important;
            pointer-events: none;
            filter: drop-shadow(0 18px 40px rgba(0,0,0,0.55)) !important;
          }
          .pf-hero-soong img {
            height: 100% !important;
            width: auto !important;
            max-width: 92vw;
            -webkit-mask-image: linear-gradient(180deg, black 0%, black 86%, transparent 100%);
                    mask-image: linear-gradient(180deg, black 0%, black 86%, transparent 100%);
            filter: none !important;
          }

          /* desktop center CTA → hide; inline CTA in copy column → show */
          .pf-hero-cta { display: none !important; }
          .pf-hero-cta-inline { display: flex !important; }

          /* Bottom row on mobile: ditch the redundant Soong bio (his face
             is right above and his name appears in the body copy), keep
             only the date + countdown, full-width left-aligned. */
          .pf-hero-bot {
            display: flex !important;
            flex-direction: column !important;
            align-items: flex-start !important;
            gap: 6px !important;
            padding: 14px 20px 18px !important;
          }
          .pf-hero-bot > .pf-reveal:first-child { display: none !important; }
          .pf-hero-bot > .pf-reveal:last-child > div {
            text-align: left !important;
            max-width: 100% !important;
          }
        }
      `}</style>
    </header>
  );
}

window.Hero = Hero;
