/* ────────────────────────────────────────────────────────────
   Section 7 - Space
   "One system. Two frontiers."
   Two cards side-by-side: "The same technology" and
   "The expansion opportunity." A subtle starfield and a
   horizon hairline divide the two.
   ──────────────────────────────────────────────────────────── */

function SectionSpace() {
  // Slow scroll-zoom treatment applied ONLY to the foreground capsule
  // (replaces the old image-wide zoom): as the section travels through
  // the viewport, the capsule starts tight (~1.10×) and pulls back to
  // (~1.00×). The starfield+earth bg behind it is height-locked and
  // anchored top-right so the earth is always visible regardless of
  // viewport size.
  const bgRef = React.useRef(null);
  const sectionRef = React.useRef(null);

  React.useEffect(() => {
    if (!sectionRef.current || !bgRef.current) return;
    let raf = 0;
    const tick = () => {
      raf = 0;
      const sec = sectionRef.current;
      const bg = bgRef.current;
      if (!sec || !bg) return;
      const r = sec.getBoundingClientRect();
      const vh = window.innerHeight || document.documentElement.clientHeight;
      // p = 0 when section is fully below viewport (entering),
      //   = 1 when section has fully exited the top.
      // Use the section's center vs viewport center so the curve
      // straddles the section symmetrically.
      const center = r.top + r.height / 2;
      const span = (r.height + vh) / 2;
      let p = 1 - (center / span + 0.5) / 1; // approx
      // simpler: progress based on top relative to viewport height
      p = 1 - (r.top + r.height) / (vh + r.height);
      p = Math.max(0, Math.min(1, p));
      // Ease the curve so the change feels deliberate, not linear.
      const eased = p * p * (3 - 2 * p); // smoothstep
      // Scroll-zoom: gentle camera pull-back from 1.10 → 1.00. We
      // never go BELOW 1.0 because the image is height-locked to the
      // section (auto 100%) and shrinking would expose the section
      // background above/below.
      const scale = 1.25 - eased * 0.25; // 1.25 → 1.00
      bg.style.transform = `scale(${scale.toFixed(4)})`;
    };
    const onScroll = () => {if (!raf) raf = requestAnimationFrame(tick);};
    tick();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    return () => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
      if (raf) cancelAnimationFrame(raf);
    };
  }, []);

  return (
    <div ref={sectionRef} style={{ position: "relative", overflow: "hidden", isolation: "isolate" }}>
    {/* Ambient particle field - same atmospheric layer used in
              sections 5 + 8. Sits above the BG image but below the section
              content; explicit zIndex keeps it as a quiet drifting layer. */}
    {typeof PtParticles !== "undefined" &&
      <PtParticles style={{ zIndex: 1 }} density={0.00437} speedScale={1.25} />
      }
    <SectionFrame
        index="07"
        plate="VII."
        dispatch="Domain expansion · § 07"
        bg="#0A0B0D">

      {/* ────────── 3-LAYER IMAGE SYSTEM (back → front) ──────────
             1. Starfield  : full-bleed atmospheric background
             2. Planet     : lit crescent, anchored top-right, bleeding
                             off the top + right edges so the night side
                             (transparent on the source PNG) never shows
             3. Capsule    : foreground hero, desktop scroll-zoom kept
                             intact; on mobile becomes a rotated banner
                             pinned upper-left of the establishing band */}

      {/* Layer 1 — Starfield. Plain cover; the planet is now its own
             layer so we no longer need a directional crop. */}
      <div aria-hidden="true" className="ax-space-starfield" style={{
          position: "absolute",
          inset: 0,
          pointerEvents: "none",
          zIndex: 0,
          backgroundImage: "url(assets/imagery/space-bg.png)",
          backgroundSize: "cover",
          backgroundPosition: "center",
          backgroundRepeat: "no-repeat",
          backgroundColor: "#0A0B0D"
        }} />

      {/* Layer 2 — Planet. The asset is a sphere whose lit crescent
             is rendered in the top-right of the PNG and whose night
             side fades to transparent toward the bottom-left.
             Therefore we position the box so the lit corner sits AT
             the section's top-right with only a hair of bleed — the
             transparent bottom-left of the image extends down/left
             into the section and reads as starfield (it's fully
             transparent, so the night side simply isn't drawn). No
             rotation: the lit limb shows in its natural orientation,
             matching the legacy desktop build. */}
      <div aria-hidden="true" className="ax-space-planet" style={{
          position: "absolute",
          zIndex: 1,
          pointerEvents: "none",
          backgroundImage: "url(assets/imagery/planet.png)",
          backgroundSize: "contain",
          backgroundPosition: "right top",
          backgroundRepeat: "no-repeat"
        }} />

      {/* Layer 3 — Capsule. ImageSettle gives it the §8 entrance; the
             inner div carries the desktop scroll-zoom (1.25 → 1.00).
             Desktop positioning is unchanged from the previous build.
             Mobile rules in <style> below re-pin the wrap upper-left
             and rotate the capsule into a banner. */}
      <ImageSettle aria-hidden="true" className="ax-space-capsule-wrap" style={{
          position: "absolute",
          top: 0,
          bottom: 0,
          right: "clamp(-20px, -1vw, 0px)",
          width: "clamp(420px, 46vw, 760px)",
          pointerEvents: "none",
          zIndex: 2
        }}>
        <div
            ref={bgRef}
            className="ax-space-capsule"
            style={{
              position: "absolute", inset: 0,
              backgroundImage: "url(assets/imagery/space-capsule.png)",
              backgroundSize: "contain",
              backgroundPosition: "center center",
              backgroundRepeat: "no-repeat",
              transformOrigin: "50% 50%",
              willChange: "transform",
              transition: "transform 80ms linear"
            }} />
      </ImageSettle>

      {/* Desktop overlays. The two-step darkening (horizontal lift on
             the left where the card lives, vertical lift near the
             bottom) stays exactly as built; both are suppressed under
             768 px in favour of a single mobile scrim. */}
      <div aria-hidden="true" className="ax-space-overlay-h" style={{
          position: "absolute", inset: 0,
          background: "linear-gradient(90deg, rgba(10,11,13,0.72) 0%, rgba(10,11,13,0.55) 45%, rgba(10,11,13,0.30) 70%, rgba(10,11,13,0.30) 100%)",
          pointerEvents: "none",
          zIndex: 3
        }} />
      <div aria-hidden="true" className="ax-space-overlay-v" style={{
          position: "absolute", inset: 0,
          background: "linear-gradient(180deg, rgba(10,11,13,0.0) 0%, rgba(10,11,13,0.0) 50%, rgba(10,11,13,0.45) 80%, rgba(10,11,13,0.85) 100%)",
          pointerEvents: "none",
          zIndex: 3
        }} />

      {/* Mobile scrim — single vertical ramp from transparent at the
             top of the imagery band to near-opaque #0A0B0D where the
             heading begins, holding solid behind the text + card.
             Hidden by default; activated under 768 px. */}
      <div aria-hidden="true" className="ax-space-mobile-scrim" style={{
          position: "absolute", inset: 0,
          pointerEvents: "none",
          zIndex: 3,
          display: "none"
        }} />

      <div className="ax-space-content" style={{ position: "relative", zIndex: 4, paddingBottom: 100 }}>
        <SectionEyebrow index="07" label="Domain expansion · space" />

        <SectionHeading size="xl">
          One system.<br />
          <span style={{ color: "#D4A24C" }}>Two frontiers.</span>
        </SectionHeading>

        {/* Two-paragraph intro - the second paragraph absorbs the bridge
                  copy from the (now-removed) "Same technology" card. */}
        <SectionDeck max={760}>
          The interplanetary economy is being built right now. NASA is
          accelerating lunar timelines. Capital is flowing into space
          infrastructure. And the single biggest constraint on sustained
          off-world operations is the same one that limits geothermal on
          Earth - the ability to access what's below the surface.
        </SectionDeck>
        <SectionDeck max={760}>
          Axion's encapsulated laser architecture was designed for the hardest
          places to drill - sealed against whatever surrounds it. Five kilometers
          down, that means crushing pressure and heat. On the Moon, it means
          vacuum, abrasive regolith, and no resupply. The hazards differ; the
          encapsulated system doesn't. The market does.
        </SectionDeck>

        {/* Single anchor card, lower-left, ~52% wide. The right side of
                  the section is intentionally empty so the drill rig + plate
                  tag in the BG read clean. */}
        <div className="ax-space-card" style={{
            marginTop: "var(--sp-fluid-xl)",
            width: "100%",
            maxWidth: 620,
            minWidth: 0,
            padding: "var(--sp-fluid-loose) var(--sp-fluid-base)",
            border: "1px solid rgba(237,234,226,0.18)",
            background: "rgba(10,11,13,0.78)",
            backdropFilter: "blur(6px)",
            WebkitBackdropFilter: "blur(6px)",
            display: "flex",
            flexDirection: "column",
            gap: 22
          }}>
          <div style={{
              fontFamily: "var(--font-mono)",
              fontSize: 11,
              color: "#D4A24C",
              letterSpacing: "0.22em",
              textTransform: "uppercase"
            }}>
            Expansion market
          </div>
          {/* Headline ~17% larger than the prior 24px (now 28px) - this
                    card is the section's single anchor. */}
          <h3 style={{
              fontFamily: "var(--font-display)",
              fontSize: 28,
              fontWeight: 500,
              lineHeight: 1.22,
              letterSpacing: "-0.015em",
              color: "#EDEAE2",
              margin: 0
            }}>
            Water, helium-3, and volatiles, locked in the lunar subsurface.
          </h3>
          <p style={{
              fontFamily: "var(--font-body)",
              fontSize: 15,
              lineHeight: 1.6,
              color: "#A8A8A2",
              margin: 0
            }}>
            These are the resources that make sustained off-world operations
            possible. Axion removes the bottleneck.
          </p>
          {/* Spec-sheet credibility block - slightly more vertical breathing
                    room between rows now that this is the section's anchor. */}
          <div data-meta-group style={{ display: "flex", flexDirection: "column", gap: 16, marginTop: 12, paddingTop: 20, borderTop: "1px solid rgba(237,234,226,0.10)" }}>
            <div data-meta-row style={{ display: "flex", gap: 12, fontFamily: "var(--font-mono)", fontSize: 12 }}>
              <span style={{ color: "#6F7178", letterSpacing: "0.16em", textTransform: "uppercase", minWidth: "clamp(70px, 18vw, 110px)" }}>VASER</span>
              <span style={{ color: "#EDEAE2", letterSpacing: "0.04em" }}>Volatile Access & Subsurface Excavation Rig</span>
            </div>
            <div data-meta-row style={{ display: "flex", gap: 12, fontFamily: "var(--font-mono)", fontSize: 12 }}>
              <span style={{ color: "#6F7178", letterSpacing: "0.16em", textTransform: "uppercase", minWidth: "clamp(70px, 18vw, 110px)" }}>Status</span>
              <span style={{ color: "#EDEAE2", letterSpacing: "0.04em" }}>TRL-5 demonstration underway</span>
            </div>
            <div data-meta-row style={{ display: "flex", gap: 12, fontFamily: "var(--font-mono)", fontSize: 12 }}>
              <span style={{ color: "#6F7178", letterSpacing: "0.16em", textTransform: "uppercase", minWidth: "clamp(70px, 18vw, 110px)" }}>Partner</span>
              <span style={{ color: "#EDEAE2", letterSpacing: "0.04em" }}>NASA Goddard</span>
            </div>
            <div data-meta-row style={{ display: "flex", gap: 12, fontFamily: "var(--font-mono)", fontSize: 12 }}>
              <span style={{ color: "#6F7178", letterSpacing: "0.16em", textTransform: "uppercase", minWidth: "clamp(70px, 18vw, 110px)" }}>IP</span>
              <span style={{ color: "#EDEAE2", letterSpacing: "0.04em" }}>Provisional patent filed · Defensible moat around laser drilling on the Moon, asteroids, & Mars</span>
            </div>
          </div>

          {/* ── VASER System Overview · request-by-email card ──
                    A framed thumbnail of the system schematic with a CTA
                    underneath. Both the thumbnail and the CTA open the same
                    mailto, so a click anywhere fires the contact intent.
                    Hover lifts the frame, brightens the schematic, and slides
                    the arrow on the CTA - all on the site's standard motion
                    vars so it sits inside the existing language. */}
          <a
              href="mailto:investors@axionldt.com?subject=VASER%20System%20Overview%20request&body=Hi%20Axion%20team%20%E2%80%94%20I%27d%20like%20to%20request%20the%20full%20VASER%20System%20Overview.%20Please%20send%20it%20over%20when%20you%20have%20a%20moment.%0A%0AThanks%2C"
              className="vaser-overview-card"
              style={{
                display: "block",
                marginTop: 8,
                paddingTop: 24,
                borderTop: "1px solid rgba(237,234,226,0.10)",
                textDecoration: "none",
                color: "inherit"
              }}>
              
            {/* Side-by-side layout: CTA on left (label + arrow stacked
                      vertically), thumbnail on right at a small fixed width.
                      The card container stays the same total width as the
                      rest of the Expansion Market box; the image is sized
                      down to fit alongside the text. */}
            {/* Compact CTA on the left, thumbnail tucked right beside
                      where the label ends. 'auto' on the left column lets the
                      CTA shrink to its content width so the image isn't
                      pushed out to the right edge of the card. */}
            <div className="vaser-overview-row" style={{
                display: "flex",
                flexDirection: "row",
                gap: 20,
                alignItems: "center",
                flexWrap: "wrap"
              }}>
            <div className="vaser-overview-cta" style={{
                  display: "flex",
                  flexDirection: "column",
                  gap: 10,
                  minWidth: 0,
                  flex: "0 0 auto"
                }}>
              <span style={{
                    fontFamily: "var(--font-mono)",
                    fontSize: 10,
                    letterSpacing: "0.22em",
                    textTransform: "uppercase",
                    color: "#6F7178"
                  }}>
                Investor materials
              </span>
              <span className="vaser-overview-cta-label" style={{
                    fontFamily: "var(--font-display)",
                    fontSize: 15,
                    fontWeight: 500,
                    lineHeight: 1.2,
                    letterSpacing: "-0.005em",
                    color: "#EDEAE2",
                    transition: "color var(--motion-fast) var(--ease-out-quart)"
                  }}>
                Request VASER System Overview
              </span>
              <span aria-hidden="true" className="vaser-overview-arrow" style={{
                    display: "inline-flex", alignItems: "center", gap: 8,
                    fontFamily: "var(--font-mono)",
                    fontSize: 11,
                    letterSpacing: "0.22em",
                    textTransform: "uppercase",
                    color: "#D4A24C",
                    marginTop: 4
                  }}>
                <span>Email</span>
                <span className="vaser-overview-arrow-glyph" style={{
                      display: "inline-block",
                      transition: "transform var(--motion-fast) var(--ease-out-quart)"
                    }}>↗</span>
              </span>
            </div>

            <div className="vaser-overview-frame" style={{
                  position: "relative",
                  border: "1px solid rgba(237,234,226,0.18)",
                  background: "#0A0B0D",
                  padding: 6,
                  width: 160,
                  flex: "0 0 auto",
                  overflow: "hidden",
                  transition:
                  "border-color var(--motion-fast) var(--ease-out-quart), " +
                  "transform var(--motion-fast) var(--ease-out-quart), " +
                  "box-shadow var(--motion-fast) var(--ease-out-quart)"
                }}>
              {/* Drafting-corner ticks - small institutional flourish.
                            Match the +-style registration marks used in the site's
                            spec language (eyebrow tags, hotspot frame). Hairline
                            lines on a brass dot. */}
              {[
                  { top: -1, left: -1, h: "8px 0 0 8px" },
                  { top: -1, right: -1, h: "0 8px 0 0" },
                  { bottom: -1, left: -1, h: "0 0 0 8px" },
                  { bottom: -1, right: -1, h: "0 0 8px 0" }].
                  map((c, i) =>
                  <span key={i} aria-hidden="true" style={{
                    position: "absolute",
                    width: 10, height: 10,
                    borderColor: "rgba(212,162,76,0.55)",
                    borderStyle: "solid",
                    borderWidth: c.h.split(" ").map((v) => v === "0" ? "0" : "1px").join(" "),
                    ...c
                  }} />
                  )}

              <div className="vaser-overview-img-wrap" style={{
                    position: "relative",
                    aspectRatio: "1672 / 941",
                    width: "100%",
                    overflow: "hidden",
                    background: "#15171A"
                  }}>
                <img
                      src="assets/imagery/vaser-system-overview-thumb.png"
                      alt="VASER System Overview · schematic preview"
                      className="vaser-overview-img"
                      style={{
                        position: "absolute", inset: 0,
                        width: "100%", height: "100%",
                        objectFit: "cover",
                        display: "block",
                        filter: "saturate(0.96) brightness(0.94)",
                        transform: "scale(1.0)",
                        transition:
                        "transform var(--motion-base) var(--ease-out-quart), " +
                        "filter var(--motion-fast) var(--ease-out-quart)"
                      }} />
                    
                {/* Subtle scan-veil that lifts on hover */}
              </div>
            </div>
            </div>
          </a>

          {/* Component-scoped hover behaviour. Kept inline so the card
                    ships as a single self-contained block. */}
          <style>{`
            .vaser-overview-card:hover .vaser-overview-frame {
              border-color: rgba(212,162,76,0.45);
              transform: translateY(-2px);
              box-shadow: 0 16px 40px rgba(0,0,0,0.55);
            }
            .vaser-overview-card:hover .vaser-overview-img {
              transform: scale(1.025);
              filter: saturate(1.02) brightness(1.02);
            }
            .vaser-overview-card:hover .vaser-overview-veil {
              opacity: 0.55;
            }
            .vaser-overview-card:hover .vaser-overview-cta-label {
              color: #D4A24C;
            }
            .vaser-overview-card:hover .vaser-overview-arrow-glyph {
              transform: translate(3px, -3px);
            }
            .vaser-overview-card:focus-visible {
              outline: 2px solid #D4A24C;
              outline-offset: 4px;
            }
            @media (max-width: 480px) {
              .ax-space-card .vaser-overview-frame {
                width: 100% !important;
              }
            }
          `}</style>
          <style>{`
            /* ── Layer 2: Planet — DESKTOP defaults ──
               Inset from the very corner so the planet drops down +
               left a notch (reads as "in the upper-right" rather than
               "wedged in the corner"). 20% larger than the prior
               accent. The lit limb (top-right of the PNG) anchors to
               the top-right of the box; the transparent bottom-left
               of the image extends harmlessly into the section. */
            .ax-space-planet {
              width:  290px;
              height: 290px;
              top:    5px;
              right:  5px;
            }

            /* ── MOBILE ──
               No banner treatment. Starfield spans the full section;
               planet pins tight to the top-right corner; capsule sits
               smaller in the same upper-right zone (zoom intact);
               copy starts at the section's normal top edge, with a
               vertical scrim that fades in behind the body copy where
               it overlaps the capsule. */
            @media (max-width: 768px) {
              /* Drop the desktop overlays — replaced below with a
                 single vertical scrim tuned for the body copy band. */
              .ax-space-overlay-h,
              .ax-space-overlay-v {
                display: none !important;
              }

              /* Planet — pinned to the top-right corner with a 2 px
                 inset on the top and right edges. */
              .ax-space-planet {
                width: 34vw !important;
                height: 34vw !important;
                top: 2px !important;
                right: 2px !important;
                left: auto !important;
                bottom: auto !important;
                z-index: 1 !important;
              }

              /* Capsule — smaller and offset DOWN so its top edge
                 reads just below the bottom of the planet. Sits in
                 FRONT of the planet (z-index 2) to add depth — the
                 planet recedes, the capsule advances. Scroll-zoom
                 (1.25 → 1.00) preserved.

                 Bottom-only mask: capsule reads sharp at the top
                 (next to the planet) and dissolves into the
                 starfield as it descends through the body-copy
                 band. Nudged a hair further off the right edge so
                 the first paragraph can sit on starfield rather
                 than fighting the capsule's metal edges. */
              .ax-space-capsule-wrap {
                top: 30vw !important;
                bottom: auto !important;
                right: -14vw !important;
                left: auto !important;
                width: 46vw !important;
                height: auto !important;
                aspect-ratio: 1400 / 1890;
                z-index: 2 !important;
                -webkit-mask-image: linear-gradient(180deg,
                  #000             0%,
                  #000             32%,
                  rgba(0,0,0,0.55) 55%,
                  rgba(0,0,0,0.15) 78%,
                  rgba(0,0,0,0)    95%);
                        mask-image: linear-gradient(180deg,
                  #000             0%,
                  #000             32%,
                  rgba(0,0,0,0.55) 55%,
                  rgba(0,0,0,0.15) 78%,
                  rgba(0,0,0,0)    95%);
              }

              .ax-space-capsule {
                /* Reserve 20% headroom inside the wrapper so the
                   1.25× scroll-zoom has room to grow on every side
                   without clipping. At scale 1.00 the capsule sits
                   with breathing room; at scale 1.25 it reaches the
                   wrapper edges exactly — never past them. */
                background-size: 80% auto !important;
              }

              /* First intro paragraph: capped narrower so its right
                 edge clears the capsule. The second paragraph sits
                 below the capsule's mask fade and can return to the
                 full SectionDeck width. */
              .ax-space-content [data-role="body"]:first-of-type {
                max-width: 85% !important;
              }

              /* Mobile scrim retired — paragraphs read against the
                 starfield in the lower half of the section where the
                 capsule has tapered out. */
              .ax-space-mobile-scrim { display: none !important; }
            }
          `}</style>
        </div>
      </div>
    </SectionFrame>
    </div>);

}

window.SectionSpace = SectionSpace;