/* ────────────────────────────────────────────────────────────
   Section 8 - CTA / Closer · "If you're building toward the
   same horizon, we'd like to hear from you."

   Full-viewport closer, redesigned per the new brief:
   - Plate header row (PLATE V - CONTACT · § 05)
   - H2 headline with forced two-line break
   - Subhead: Seed-round status
   - Primary CTA - REQUEST INVESTOR MATERIALS
   - Hairline divider
   - Two-column contact block (DIRECT · PARTNERSHIPS & RESEARCH)
   - Hairline divider
   - Footer row (wordmark · spec line)
   - Geothermal dusk BG, anchored low; no parallax (closer = still).
   - Staggered scroll reveal, ease-out-expo.
   ──────────────────────────────────────────────────────────── */

function SectionCTA() {
  // Reveal trigger - once the section's top crosses 70% of the viewport,
  // walk the staggered timeline on the elements tagged with data-cta-rev.
  const sectionRef = React.useRef(null);
  const bgRef = React.useRef(null);

  // Very-mild BG parallax - translate up to ~6% of viewport across the
  // section's transit. Closer should still feel grounded; this is
  // intentionally subtle.
  React.useEffect(() => {
    const sec = sectionRef.current;
    const bg = bgRef.current;
    if (!sec || !bg) return;
    const reduceMotion = window.matchMedia &&
    window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    if (reduceMotion) return;
    let ticking = false;
    const update = () => {
      ticking = false;
      const r = sec.getBoundingClientRect();
      const vh = window.innerHeight || 800;
      const center = r.top + r.height / 2;
      const progress = (center - vh / 2) / (vh / 2 + r.height / 2);
      const clamped = Math.max(-1, Math.min(1, progress));
      const y = -clamped * vh * 0.06;
      bg.style.transform = "translate3d(0, " + y.toFixed(1) + "px, 0)";
    };
    const onScroll = () => {
      if (ticking) return;
      ticking = true;
      requestAnimationFrame(update);
    };
    update();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    return () => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
    };
  }, []);
  React.useEffect(() => {
    const sec = sectionRef.current;
    if (!sec) return;
    const reduceMotion = window.matchMedia &&
    window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    if (reduceMotion) {
      sec.querySelectorAll("[data-cta-rev]").forEach((el) => el.classList.add("is-in"));
      return;
    }
    const io = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          sec.classList.add("is-in");
          io.disconnect();
        }
      });
    }, { rootMargin: "0px 0px -30% 0px", threshold: 0 });
    io.observe(sec);
    return () => io.disconnect();
  }, []);

  return (
    <section ref={sectionRef} className="cta-section" style={{
      position: "relative",
      minHeight: "100vh",
      backgroundColor: "#0A0A0A",
      borderTop: "1px solid rgba(237,234,226,0.08)",
      isolation: "isolate",
      overflow: "hidden",
      display: "flex",
      flexDirection: "column",
      color: "#EDEAE2",
      padding: "96px 80px 48px"
    }}>
      {/* ── BG image - geothermal dusk. Anchored at center 65% so the
                                           horizon sits in the lower third and the upper text zone
                                           stays the soft sky region. No parallax. ────────────────── */}
      <div aria-hidden="true" ref={bgRef} style={{
        position: "absolute",
        inset: "-8% 0",
        zIndex: 0,
        backgroundImage: "url(assets/section-8-rock-bg.png)",
        backgroundSize: "cover",
        backgroundPosition: "center 65%",
        backgroundRepeat: "no-repeat",
        pointerEvents: "none",
        willChange: "transform"
      }} />
      {/* ── Legibility overlay - top→bottom darken so the text zone
                                           above the horizon clears the sky and the footer sits on
                                           a deeper ground. ─────────────────────────────────────── */}
      <div aria-hidden="true" style={{
        position: "absolute",
        inset: 0,
        zIndex: 0,
        background:
        "linear-gradient(180deg, rgba(10,10,10,0.40) 0%, rgba(10,10,10,0.75) 100%)",
        pointerEvents: "none"
      }} />

      {/* ── Ambient particle field - same atmospheric layer as Section 5. */}
      {typeof PtParticles !== "undefined" && (
        <PtParticles style={{ zIndex: 0 }} density={0.0024} />
      )}

      {/* ── Corner register marks - match every other section
                 (14×14, 1px, bone @ 0.18). Inset uses the same
                 fluid clamp as SectionFrame so the mobile widening
                 (8px) and desktop position (20px) stay in sync. */}
      {[
      { top: "clamp(20px, 1.5vw, 24px)", left: "clamp(8px, 1.5vw, 20px)", s: "TL" },
      { top: "clamp(20px, 1.5vw, 24px)", right: "clamp(8px, 1.5vw, 20px)", s: "TR" },
      { bottom: "clamp(20px, 1.5vw, 24px)", left: "clamp(8px, 1.5vw, 20px)", s: "BL" },
      { bottom: "clamp(20px, 1.5vw, 24px)", right: "clamp(8px, 1.5vw, 20px)", s: "BR" }].
      map((c, i) =>
      <div key={i} aria-hidden="true" style={{
        position: "absolute", ...c, width: 14, height: 14,
        borderColor: "rgba(237,234,226,0.18)",
        borderStyle: "solid",
        borderWidth: 0,
        ...(c.s.includes("T") ? { borderTopWidth: 1 } : {}),
        ...(c.s.includes("B") ? { borderBottomWidth: 1 } : {}),
        ...(c.s.includes("L") ? { borderLeftWidth: 1 } : {}),
        ...(c.s.includes("R") ? { borderRightWidth: 1 } : {}),
        zIndex: 3
      }} />
      )}

      {/* ── Inner content column - capped at 1280px. ────────────── */}
      <div style={{
        position: "relative",
        zIndex: 1,
        flex: 1,
        width: "100%",
        maxWidth: 1280,
        margin: "0 auto",
        display: "flex",
        flexDirection: "column"
      }}>
        {/* ── Plate header row ───────────────────────────────── */}
        <div data-cta-rev="plate" className="cta-rev" style={{
          display: "flex",
          justifyContent: "space-between",
          alignItems: "baseline",
          fontFamily: "var(--font-mono)",
          fontSize: 12,
          fontWeight: 400,
          letterSpacing: "0.10em",
          textTransform: "uppercase"
        }}>
          <span style={{ color: "#A8A8A2" }}>Contact</span>
          <span style={{ color: "rgba(255,255,255,0.40)" }}>§ 05</span>
        </div>

        {/* ── Center stage - headline + subhead + CTA. Centered in
                                             the remaining vertical space between plate header and
                                             the first divider. ───────────────────────────────── */}
        <div style={{
          flex: 1,
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          justifyContent: "center",
          textAlign: "center",
          paddingTop: 80,
          paddingBottom: 80
        }}>
          <h2 data-cta-rev="headline" className="cta-rev" style={{




            letterSpacing: "-0.015em",
            color: "#FAFAFA",
            margin: 0,
            textWrap: "balance", fontFamily: "\"GT America\"", fontSize: "clamp(1.5rem, 1.26rem + 1.03vw, 2.1875rem)", fontWeight: "500", lineHeight: "1.1"
          }}>
            If you're building toward the same horizon,<br />we'd like to hear from you.
          </h2>

          <p data-cta-rev="subhead" className="cta-rev" style={{
            marginTop: 24,
            fontFamily: "var(--font-body)",
            fontWeight: 400,
            fontSize: 16,
            lineHeight: 1.5,
            color: "rgba(255,255,255,0.60)",
            margin: "24px 0 0"
          }}>
            We're currently raising our Seed round.
          </p>

          <a
            href="mailto:investors@axionldt.com?subject=Investor%20materials%20request"
            data-cta-rev="button"
            className="cta-rev cta-primary"
            style={{
              marginTop: 56,
              display: "inline-flex",
              alignItems: "center",
              padding: "10px 18px",
              borderRadius: 4,
              background: "transparent",
              border: "1px solid rgba(237,234,226,0.28)",
              color: "#EDEAE2",
              fontFamily: "var(--font-display)",
              fontWeight: 500,
              fontSize: 14,
              lineHeight: 1,
              letterSpacing: "0.01em",
              textDecoration: "none",
              transition: "background 120ms ease, border-color 120ms ease"
            }}>
            <span>Request Investor Materials</span>
          </a>
        </div>

        {/* ── First hairline divider ─────────────────────────── */}
        <div
          data-cta-rev="block"
          className="cta-rev"
          aria-hidden="true"
          style={{
            height: 1,
            background: "rgba(255,255,255,0.08)",
            marginTop: 0,
            marginBottom: 64
          }} />
        

        {/* ── Contact block - two columns ───────────────────── */}
        <div data-cta-rev="block" className="cta-rev cta-contact-grid" style={{
          display: "grid",
          gridTemplateColumns: "1fr 1fr",
          columnGap: 80,
          rowGap: 48,
          maxWidth: 720,
          width: "100%",
          margin: "0 auto"
        }}>
          {/* Direct */}
          <div>
            <div style={{
              fontFamily: "var(--font-mono)",
              fontSize: 11,
              fontWeight: 500,
              letterSpacing: "0.12em",
              textTransform: "uppercase",
              color: "#D4A24C",
              marginBottom: 16
            }}>
              Direct
            </div>
            <a href="mailto:investors@axionldt.com" className="cta-email" style={{
              fontFamily: "var(--font-body)",
              fontWeight: 500,
              fontSize: 18,
              color: "#FAFAFA",
              textDecoration: "none",
              display: "inline-flex",
              alignItems: "center",
              gap: 10,
              marginBottom: 8
            }}>
              <span>investors@axionldt.com</span>
              <span className="cta-email-arrow" style={{
                fontFamily: "var(--font-mono)",
                color: "rgba(255,255,255,0.55)",
                transition: "transform 200ms cubic-bezier(0.25, 1, 0.5, 1), color 200ms cubic-bezier(0.25, 1, 0.5, 1)",
                display: "inline-block"
              }}>→</span>
            </a>
            <div style={{
              fontFamily: "var(--font-body)",
              fontWeight: 400,
              fontSize: 14,
              lineHeight: 1.5,
              color: "rgba(255,255,255,0.50)"
            }}>
              Founding team - 48h response.
            </div>
          </div>

          {/* Partnerships & Research */}
          <div>
            <div style={{
              fontFamily: "var(--font-mono)",
              fontSize: 11,
              fontWeight: 500,
              letterSpacing: "0.12em",
              textTransform: "uppercase",
              color: "#D4A24C",
              marginBottom: 16
            }}>
              Partnerships &amp; Research
            </div>
            <a href="mailto:partnerships@axionldt.com" className="cta-email" style={{
              fontFamily: "var(--font-body)",
              fontWeight: 500,
              fontSize: 18,
              color: "#FAFAFA",
              textDecoration: "none",
              display: "inline-flex",
              alignItems: "center",
              gap: 10,
              marginBottom: 8
            }}>
              <span>partnerships@axionldt.com</span>
              <span className="cta-email-arrow" style={{
                fontFamily: "var(--font-mono)",
                color: "rgba(255,255,255,0.55)",
                transition: "transform 200ms cubic-bezier(0.25, 1, 0.5, 1), color 200ms cubic-bezier(0.25, 1, 0.5, 1)",
                display: "inline-block"
              }}>→</span>
            </a>
            <div style={{
              fontFamily: "var(--font-body)",
              fontWeight: 400,
              fontSize: 14,
              lineHeight: 1.5,
              color: "rgba(255,255,255,0.50)"
            }}>
              For developers, research partners, and field collaborators.
            </div>
          </div>
        </div>

        {/* ── Second hairline divider ───────────────────────── */}
        <div
          data-cta-rev="block"
          className="cta-rev"
          aria-hidden="true"
          style={{
            height: 1,
            background: "rgba(255,255,255,0.08)",
            marginTop: 64,
            marginBottom: 32
          }} />
        

        {/* ── Footer row ───────────────────────────────────── */}
        <div data-cta-rev="footer" className="cta-rev cta-footer" style={{
          display: "flex",
          justifyContent: "space-between",
          alignItems: "center",
          gap: 24
        }}>
          <img
            src="assets/axion-wordmark-bone.svg"
            alt="Axion"
            style={{ height: 20, width: "auto", display: "block" }} />
          
          <span style={{
            fontFamily: "var(--font-mono)",
            fontSize: 11,
            fontWeight: 400,
            letterSpacing: "0.10em",
            textTransform: "uppercase",
            color: "rgba(255,255,255,0.40)"
          }}>
            MMXXVI · USA &nbsp;·&nbsp; AXION_SYS · v1.02
          </span>
        </div>
      </div>

      {/* ── Reveal + hover styles ─────────────────────────────── */}
      <style>{`
        /* Stagger timeline - only fires once the section's top crosses
           ~70% of the viewport (controlled by the IO above flipping
           .is-in on the section). Easing: ease-out-expo. */
        .cta-section .cta-rev {
          opacity: 0;
          will-change: opacity, transform;
          transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
        }
        .cta-section [data-cta-rev="plate"]    { transform: translateY(12px); transition: opacity 600ms 0ms,   transform 600ms 0ms; }
        .cta-section [data-cta-rev="headline"] { transform: translateY(20px); transition: opacity 800ms 100ms, transform 800ms 100ms; }
        .cta-section [data-cta-rev="subhead"]  { transform: translateY(16px); transition: opacity 800ms 220ms, transform 800ms 220ms; }
        .cta-section [data-cta-rev="button"]   { transform: translateY(12px); transition: opacity 700ms 360ms, transform 700ms 360ms; }
        .cta-section [data-cta-rev="block"]    {                              transition: opacity 600ms 500ms; }
        .cta-section [data-cta-rev="footer"]   {                              transition: opacity 600ms 600ms; }

        .cta-section.is-in .cta-rev          { opacity: 1; transform: translateY(0); }

        /* Primary CTA - ghost variant from the design system.
           !important is required because the inline background
           transparent and border on the a element would otherwise
           win specificity-wise. */
        .cta-section .cta-primary {
          transition: background 120ms ease, border-color 120ms ease !important;
        }
        .cta-section .cta-primary:hover {
          background: rgba(237,234,226,0.06) !important;
          border-color: rgba(237,234,226,0.45) !important;
        }
        .cta-section .cta-primary:focus-visible {
          outline: 2px solid #D4A24C;
          outline-offset: 2px;
        }

        /* Email link hover - arrow translateX(4px), color shifts amber. */
        .cta-section .cta-email:hover { color: #D4A24C; }
        .cta-section .cta-email:hover .cta-email-arrow {
          transform: translateX(4px);
          color: #D4A24C;
        }

        /* Reduced motion - no transforms / staggers. */
        @media (prefers-reduced-motion: reduce) {
          .cta-section .cta-rev { opacity: 1 !important; transform: none !important; transition: none !important; }
          .cta-section .cta-primary,
          .cta-section .cta-primary-arrow,
          .cta-section .cta-email,
          .cta-section .cta-email-arrow { transition: none !important; }
        }

        /* Responsive - tablet padding + collapse contact grid on phones. */
        @media (max-width: 1024px) {
          .cta-section { padding: 96px 40px 48px !important; }
        }
        @media (max-width: 720px) {
          .cta-section { padding: 80px 24px 40px !important; }
          .cta-section .cta-contact-grid {
            grid-template-columns: 1fr !important;
            row-gap: 48px !important;
          }
          .cta-section .cta-footer {
            flex-direction: column !important;
            align-items: flex-start !important;
            gap: 16px !important;
          }
        }
      `}</style>
    </section>);

}

window.SectionCTA = SectionCTA;