/* global React, Button, Pill, Eyebrow, Icon */
const { useState: useSecState, useEffect: useSecEffect, useRef: useSecRef } = React;

/* Mobile breakpoint used for responsive calendar crop values */
const BM_MOBILE_BREAKPOINT = 760;

/* Keyframes + a11y-safe reduced-motion gate. Injected once. */
(function injectHeroAnims() {
  if (document.getElementById("bm-hero-anim-style")) return;
  const s = document.createElement("style");
  s.id = "bm-hero-anim-style";
  s.textContent = `
    @keyframes bm-ring {
      0%   { transform: scale(0.92); opacity: 0.55; }
      70%  { opacity: 0; }
      100% { transform: scale(1.8); opacity: 0; }
    }
    @keyframes bm-bar {
      0%, 100% { transform: scaleY(0.35); }
      50%      { transform: scaleY(1); }
    }
    /* Subtle idle breathing — small amplitude so bars feel alive before audio. */
    @keyframes bm-bar-idle {
      0%, 100% { transform: scaleY(0.5); }
      50%      { transform: scaleY(0.78); }
    }
    @keyframes bm-line-in {
      from { opacity: 0; transform: translateY(6px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes bm-dot {
      0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
      30%           { opacity: 1;    transform: translateY(-2px); }
    }
    @media (prefers-reduced-motion: reduce) {
      .bm-ring, .bm-bar, .bm-dot, .bm-orbit, .bm-shimmer, .bm-halo { animation: none !important; }
      .bm-bar-idle, .bm-ring-idle { animation: none !important; }
    }

    /* Futuristic avatar animations */
    @keyframes bm-orbit {
      from { transform: translate(-50%, -50%) rotate(0deg); }
      to   { transform: translate(-50%, -50%) rotate(360deg); }
    }
    @keyframes bm-shimmer {
      0%, 100% { transform: translate(-30%, -30%) scale(1);   opacity: 0.65; }
      50%      { transform: translate(-28%, -28%) scale(1.08); opacity: 0.9; }
    }
    @keyframes bm-halo {
      0%, 100% { opacity: 0.55; transform: scale(1); }
      50%      { opacity: 0.9;  transform: scale(1.04); }
    }

    /* Neon metric glow — two variants so Ruben can compare */
    .bm-neon-blue {
      color: #B3C6FF !important;
      text-shadow:
        0 0 6px rgba(109,145,242,0.85),
        0 0 14px rgba(109,145,242,0.65),
        0 0 28px rgba(109,145,242,0.45),
        0 0 56px rgba(109,145,242,0.28);
    }
    .bm-neon-white {
      color: #FFFFFF !important;
      text-shadow:
        0 0 6px rgba(255,255,255,0.9),
        0 0 14px rgba(255,255,255,0.6),
        0 0 28px rgba(255,255,255,0.35),
        0 0 56px rgba(179,198,255,0.25);
    }

    /* Modal */
    @keyframes bm-fade-in { from { opacity: 0; } to { opacity: 1; } }
    @keyframes bm-pop-in  { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

    /* Redesign — hero signature moment */
    @keyframes bm-shader-drift {
      0%   { transform: translate(-4%, -2%) scale(1.05); }
      50%  { transform: translate(4%, 3%)   scale(1.16); }
      100% { transform: translate(-4%, -2%) scale(1.05); }
    }
    @keyframes bm-draw     { from { stroke-dashoffset: 640; } to { stroke-dashoffset: 0; } }
    @keyframes bm-area-in  { from { opacity: 0; } to { opacity: 1; } }

    /* Testimonials marquee — seamless loop (track holds 2 copies, shifts -50%). */
    @keyframes bm-marquee  { from { transform: translateX(0); } to { transform: translateX(-50%); } }
    .bm-marquee-track { animation: bm-marquee 48s linear infinite; }
    .bm-marquee:hover .bm-marquee-track { animation-play-state: paused; }

    /* === Imported design (BeaverMind Sections.dc.html) — micro-visual + vertical-marquee keyframes === */
    @keyframes bmBar{0%,100%{transform:scaleY(0.28)}50%{transform:scaleY(1)}}
    @keyframes bmPulse{0%,100%{transform:scale(1);opacity:1}50%{transform:scale(1.09);opacity:0.82}}
    @keyframes bmRing{0%{transform:scale(0.55);opacity:0.7}100%{transform:scale(1.7);opacity:0}}
    @keyframes bmDots{0%,60%,100%{opacity:0.25;transform:translateY(0)}30%{opacity:1;transform:translateY(-4px)}}
    @keyframes bmDraw{0%{stroke-dashoffset:var(--len)}68%,100%{stroke-dashoffset:0}}
    @keyframes bmFill{0%{width:0}68%,100%{width:var(--w)}}
    @keyframes bmFade{0%{opacity:0}68%,100%{opacity:0.9}}
    @keyframes bmTick{0%,28%{opacity:0;transform:scale(0.4)}48%,100%{opacity:1;transform:scale(1)}}
    @keyframes bmTickBar{0%{width:0}48%,100%{width:100%}}
    @keyframes bmShimmer{0%,100%{opacity:0.3}50%{opacity:0.9}}
    @keyframes bmUp{0%{transform:translateY(0)}100%{transform:translateY(-50%)}}
    @keyframes bmDown{0%{transform:translateY(-50%)}100%{transform:translateY(0)}}
    @keyframes bmRevive{0%,18%{background:rgba(109,145,242,0.18)}55%,100%{background:#6D91F2}}
    @keyframes bmPop{0%,12%{opacity:0;transform:scale(0.4)}45%,100%{opacity:1;transform:scale(1)}}
    @keyframes bmGrowY{0%{transform:scaleY(0.12)}60%,100%{transform:scaleY(1)}}
    .bm-marq:hover .bm-marq-track{animation-play-state:paused;}

    @media (prefers-reduced-motion: reduce) {
      .bm-shader { animation: none !important; }
      .bm-marquee { overflow-x: auto !important; }
      .bm-marquee-track { animation: none !important; }
      .bm-marq-track { animation: none !important; }
    }

    /* Horizontal card rail — scroll-snap carousel (What we build, proof) */
    .bm-rail {
      scrollbar-width: thin;
      scrollbar-color: rgba(109,145,242,0.45) transparent;
    }
    .bm-rail::-webkit-scrollbar { height: 6px; }
    .bm-rail::-webkit-scrollbar-track { background: transparent; }
    .bm-rail::-webkit-scrollbar-thumb { background: rgba(109,145,242,0.35); border-radius: 999px; }
    .bm-rail::-webkit-scrollbar-thumb:hover { background: rgba(109,145,242,0.6); }

    /* Auto-scroll case rail — scrollbar hidden (controlled by drift + arrows) */
    .bm-no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
    .bm-no-scrollbar::-webkit-scrollbar { display: none; }
  `;
  document.head.appendChild(s);
})();

/* ------------------------------------------------------------------
   Shared config + helpers
------------------------------------------------------------------ */
const CANVAS_MAX = 1200;

/* GHL calendar: "Discovery Call With Ruben (Founder & CEO)" */
const GHL_CAL_ID = "u1ZRJUGOmDQknNvuHoKv";
const GHL_CAL_EMBED_URL = `https://api.leadconnectorhq.com/widget/booking/${GHL_CAL_ID}`;
/* Stable id in the GHL pattern "<calendarId>_<timestamp>" — computed once so
   the iframe isn't remounted on re-render. form_embed.js uses this id to
   postMessage height updates back into the iframe. */
const GHL_IFRAME_ID = `${GHL_CAL_ID}_${Date.now()}`;

/* Scroll directly to the calendar embed. Prefer the calendar iframe
   container itself over the enclosing "Let's Talk" section so users land on
   the booking widget, not the intro copy. Falls back sensibly for pages
   that host only one of them. */
function scrollToTalk() {
  const target =
    document.getElementById("calendar") ||      // homepage
    document.getElementById("cs-calendar") ||   // case-study subpages
    document.getElementById("talk");            // fallback
  if (target) target.scrollIntoView({ behavior: "smooth", block: "start" });
  else if (window.location.pathname !== "/") window.location.href = "/#calendar";
}

/* Open the "agent coming soon" modal — pub/sub via CustomEvent */
function openAgentModal() {
  window.dispatchEvent(new CustomEvent("bm:open-agent-modal"));
}

const eyebrowStyle = {
  fontSize: 11,
  fontWeight: 600,
  letterSpacing: "0.16em",
  textTransform: "uppercase",
  color: "var(--bm-accent)",
  lineHeight: 1,
};

const displayXL = {
  fontFamily: "var(--bm-font-display)",
  fontSize: "clamp(48px, 6.6vw, 88px)",
  fontWeight: 700,
  letterSpacing: "-0.03em",
  lineHeight: 1.02,
  color: "var(--bm-text)",
  margin: 0,
};

const displayL = {
  fontFamily: "var(--bm-font-display)",
  fontSize: "clamp(36px, 4.4vw, 56px)",
  fontWeight: 700,
  letterSpacing: "-0.025em",
  lineHeight: 1.06,
  color: "var(--bm-text)",
  margin: 0,
};

const displayM = {
  fontFamily: "var(--bm-font-display)",
  fontSize: "clamp(26px, 2.8vw, 36px)",
  fontWeight: 700,
  letterSpacing: "-0.02em",
  lineHeight: 1.12,
  color: "var(--bm-text)",
  margin: 0,
};

const bodyL = {
  fontSize: 19,
  lineHeight: 1.55,
  color: "var(--bm-text-muted)",
  fontWeight: 400,
  margin: 0,
};

const bodyM = {
  fontSize: 16,
  lineHeight: 1.6,
  color: "var(--bm-text-muted)",
  fontWeight: 400,
  margin: 0,
};

/* Signature radial glow, bottom-left */
function BottomLeftGlow() {
  return (
    <div
      aria-hidden
      style={{
        position: "absolute",
        inset: 0,
        pointerEvents: "none",
        background:
          "radial-gradient(ellipse 55% 50% at 0% 100%, rgba(0,24,125,0.72), rgba(0,11,69,0.28) 38%, rgba(0,3,34,0) 70%)",
      }}
    />
  );
}

/* ------------------------------------------------------------------
   Motion utilities — count-up, in-view, blueprint, shader, reveal init.
   All respect prefers-reduced-motion and degrade safely without JS.
------------------------------------------------------------------ */
const bmReducedMotion = () =>
  typeof window !== "undefined" &&
  typeof window.matchMedia === "function" &&
  window.matchMedia("(prefers-reduced-motion: reduce)").matches;

/* Split a transcript into short, caption-sized lines (YouTube-style).
   No per-word timing data — captions advance proportionally to playback.
   Greedy word-wrap (no regex lookbehind, for older Safari) + a natural
   break after sentence-ending punctuation. */
function bmCaptionChunks(text) {
  if (!text) return [];
  const MAX = 34;
  const words = String(text).trim().split(/\s+/);
  const out = [];
  let line = "";
  for (let i = 0; i < words.length; i++) {
    const w = words[i];
    const cand = line ? line + " " + w : w;
    if (cand.length > MAX && line) { out.push(line); line = w; }
    else { line = cand; }
    if (/[.?!\u2026]$/.test(w) && line.length >= 18) { out.push(line); line = ""; }
  }
  if (line) out.push(line);
  return out;
}

/* Fire once when `ref` first enters the viewport. */
function useInViewOnce(ref, threshold) {
  const [seen, setSeen] = useSecState(false);
  useSecEffect(() => {
    if (seen) return;
    const el = ref.current;
    if (!el || typeof IntersectionObserver === "undefined") { setSeen(true); return; }
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) { setSeen(true); io.disconnect(); } });
    }, { threshold: threshold || 0.4 });
    io.observe(el);
    return () => io.disconnect();
  }, [seen]);
  return seen;
}

/* Count-up with tabular figures. Animates 0 → `to` on first scroll-in.
   Reduced-motion / no rAF jumps straight to the final value. */
function CountUp({ to, decimals = 0, prefix = "", suffix = "", durationMs = 1100, style, className }) {
  const ref = useSecRef(null);
  const inView = useInViewOnce(ref, 0.5);
  const [val, setVal] = useSecState(0);
  useSecEffect(() => {
    if (!inView) return;
    if (bmReducedMotion() || typeof requestAnimationFrame === "undefined") { setVal(to); return; }
    let raf, start = null;
    const ease = (t) => 1 - Math.pow(1 - t, 3);
    const step = (ts) => {
      if (start === null) start = ts;
      const p = Math.min(1, (ts - start) / durationMs);
      setVal(to * ease(p));
      if (p < 1) raf = requestAnimationFrame(step); else setVal(to);
    };
    raf = requestAnimationFrame(step);
    return () => { if (raf) cancelAnimationFrame(raf); };
  }, [inView, to]);
  const formatted = Number(val).toLocaleString("en-US", {
    minimumFractionDigits: decimals, maximumFractionDigits: decimals,
  });
  return (
    <span ref={ref} className={"bm-tnum" + (className ? " " + className : "")} style={style}>
      {prefix}{formatted}{suffix}
    </span>
  );
}

/* Blueprint grid overlay — 1px lines at 24px, low opacity, masked to fade. */
function BlueprintGrid({ tone = "ink", style }) {
  const line = tone === "paper" ? "var(--bm-grid-paper)" : "var(--bm-grid-ink)";
  const mask = "radial-gradient(ellipse 95% 85% at 50% 25%, #000 35%, transparent 82%)";
  return (
    <div
      aria-hidden
      style={{
        position: "absolute", inset: 0, pointerEvents: "none",
        backgroundImage:
          `linear-gradient(${line} 1px, transparent 1px),` +
          `linear-gradient(90deg, ${line} 1px, transparent 1px)`,
        backgroundSize: "24px 24px",
        maskImage: mask, WebkitMaskImage: mask,
        ...style,
      }}
    />
  );
}

/* Hero shader — one slow low-contrast accent gradient that drifts.
   CSS disables the drift under reduced-motion (static fallback). */
function HeroShader() {
  return (
    <div aria-hidden style={{ position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none" }}>
      <div
        className="bm-shader"
        style={{
          position: "absolute", inset: "-25%",
          background:
            "radial-gradient(38% 38% at 28% 30%, rgba(109,145,242,0.18), transparent 70%)," +
            "radial-gradient(36% 36% at 76% 64%, rgba(0,24,125,0.55), transparent 72%)",
          filter: "blur(46px)",
          animation: "bm-shader-drift 24s var(--bm-ease) infinite",
        }}
      />
    </div>
  );
}

/* Faint grain over flat dark fills. */
function Grain({ opacity = 0.05 }) {
  const raw =
    "<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'>" +
    "<filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter>" +
    "<rect width='100%' height='100%' filter='url(#n)'/></svg>";
  const uri = "data:image/svg+xml," + encodeURIComponent(raw);
  return (
    <div aria-hidden style={{
      position: "absolute", inset: 0, pointerEvents: "none",
      backgroundImage: `url("${uri}")`, opacity, mixBlendMode: "overlay",
    }} />
  );
}

/* Signature — drifting "neural constellation": brand-blue nodes joined by
   proximity links, with a subtle cursor parallax. The living version of the
   blueprint grid; ties to the voice/AI product. Canvas + rAF, pauses when
   offscreen or the tab is hidden, renders a single static frame under
   prefers-reduced-motion. pointer-events: none, aria-hidden. */
function NeuralField() {
  const wrapRef = useSecRef(null);
  const canvasRef = useSecRef(null);
  useSecEffect(() => {
    const wrap = wrapRef.current, canvas = canvasRef.current;
    if (!wrap || !canvas || typeof window === "undefined") return;
    const ctx = canvas.getContext && canvas.getContext("2d");
    if (!ctx) return;
    const reduce = bmReducedMotion();
    const dpr = Math.min(window.devicePixelRatio || 1, 2);
    let w = 0, h = 0, nodes = [], raf = null, inView = true;
    let tx = 0.5, ty = 0.42, cx = 0.5, cy = 0.42;   // parallax target / smoothed
    const LINK = 130;

    function build() {
      const r = wrap.getBoundingClientRect();
      w = Math.max(1, r.width); h = Math.max(1, r.height);
      canvas.width = Math.round(w * dpr); canvas.height = Math.round(h * dpr);
      canvas.style.width = w + "px"; canvas.style.height = h + "px";
      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
      const n = Math.max(20, Math.min(44, Math.round(w / 36)));
      nodes = [];
      for (let i = 0; i < n; i++) {
        nodes.push({
          x: Math.random() * w, y: Math.random() * h,
          vx: (Math.random() - 0.5) * 0.16, vy: (Math.random() - 0.5) * 0.16,
          r: 1 + Math.random() * 1.5,
        });
      }
    }
    function frame(move) {
      cx += (tx - cx) * 0.045; cy += (ty - cy) * 0.045;
      const ox = (cx - 0.5) * 26, oy = (cy - 0.42) * 18;
      if (move) for (const p of nodes) {
        p.x += p.vx; p.y += p.vy;
        if (p.x < -20) p.x = w + 20; else if (p.x > w + 20) p.x = -20;
        if (p.y < -20) p.y = h + 20; else if (p.y > h + 20) p.y = -20;
      }
      ctx.clearRect(0, 0, w, h);
      for (let i = 0; i < nodes.length; i++) {
        for (let j = i + 1; j < nodes.length; j++) {
          const a = nodes[i], b = nodes[j];
          const dx = a.x - b.x, dy = a.y - b.y, d2 = dx * dx + dy * dy;
          if (d2 < LINK * LINK) {
            const al = (1 - Math.sqrt(d2) / LINK) * 0.16;
            ctx.strokeStyle = "rgba(109,145,242," + al.toFixed(3) + ")";
            ctx.lineWidth = 1;
            ctx.beginPath(); ctx.moveTo(a.x + ox, a.y + oy); ctx.lineTo(b.x + ox, b.y + oy); ctx.stroke();
          }
        }
      }
      ctx.fillStyle = "rgba(137,166,245,0.5)";
      for (const p of nodes) { ctx.beginPath(); ctx.arc(p.x + ox, p.y + oy, p.r, 0, 6.2832); ctx.fill(); }
    }
    function loop() { frame(true); raf = requestAnimationFrame(loop); }
    function start() { if (raf == null && !reduce) loop(); }
    function stop() { if (raf != null) { cancelAnimationFrame(raf); raf = null; } }

    build();
    if (reduce) frame(false); else loop();
    // Re-measure after the first layout pass — the canvas can mount before the
    // hero section has resolved its final width.
    if (typeof requestAnimationFrame !== "undefined") {
      requestAnimationFrame(() => { build(); if (reduce) frame(false); });
    }

    const onMove = (e) => { tx = e.clientX / window.innerWidth; ty = e.clientY / window.innerHeight; };
    const onResize = () => { build(); if (reduce) frame(false); };
    const onVis = () => { if (document.hidden) stop(); else if (inView) start(); };
    if (!reduce) window.addEventListener("mousemove", onMove, { passive: true });
    window.addEventListener("resize", onResize);
    document.addEventListener("visibilitychange", onVis);

    let ro = null;
    if (typeof ResizeObserver !== "undefined") { ro = new ResizeObserver(onResize); ro.observe(wrap); }

    let io = null;
    if (typeof IntersectionObserver !== "undefined") {
      io = new IntersectionObserver(([e]) => {
        inView = e.isIntersecting;
        if (!reduce) { if (inView) start(); else stop(); }
      }, { threshold: 0 });
      io.observe(wrap);
    }
    return () => {
      stop();
      window.removeEventListener("mousemove", onMove);
      window.removeEventListener("resize", onResize);
      document.removeEventListener("visibilitychange", onVis);
      if (ro) ro.disconnect();
      if (io) io.disconnect();
    };
    // eslint-disable-next-line
  }, []);
  return (
    <div ref={wrapRef} aria-hidden style={{ position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none" }}>
      <canvas ref={canvasRef} style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }} />
    </div>
  );
}

/* Arm scroll-reveal: hide .bm-reveal then play on intersect. Progressive
   enhancement — without this running, elements stay visible. */
function bmArmReveals() {
  try {
    if (bmReducedMotion() || typeof IntersectionObserver === "undefined") return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) { e.target.classList.add("is-in"); io.unobserve(e.target); }
      });
    }, { threshold: 0.15, rootMargin: "0px 0px -6% 0px" });
    document.querySelectorAll(".bm-reveal").forEach((el) => {
      el.classList.add("bm-armed");
      io.observe(el);
    });
  } catch (_) {}
}

/* ------------------------------------------------------------------
   1. Navigation
------------------------------------------------------------------ */
function SiteNav() {
  const [scrolled, setScrolled] = useSecState(false);
  const [menuOpen, setMenuOpen] = useSecState(false);
  useSecEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  /* Arm scroll-reveal once the React tree has painted (App renders in one go). */
  useSecEffect(() => {
    const id = requestAnimationFrame(bmArmReveals);
    return () => cancelAnimationFrame(id);
  }, []);
  /* Lock body scroll while mobile menu open */
  useSecEffect(() => {
    if (!menuOpen) return;
    const prev = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    return () => { document.body.style.overflow = prev; };
  }, [menuOpen]);

  const linkStyle = {
    color: "var(--bm-text-muted)",
    fontSize: 14,
    fontWeight: 500,
    textDecoration: "none",
    transition: "color 120ms var(--bm-ease-standard)",
  };

  const goTalk = () => {
    setMenuOpen(false);
    const target =
      document.getElementById("calendar") ||
      document.getElementById("cs-calendar");
    if (target) {
      target.scrollIntoView({ behavior: "smooth", block: "start" });
    } else {
      window.location.href = "/#calendar";
    }
  };

  return (
    <header
      data-screen-label="Nav"
      data-bm-nav="root"
      style={{
        position: "sticky",
        top: 0,
        zIndex: 50,
        padding: "16px 32px",
        background: scrolled || menuOpen ? "rgba(0,3,34,0.72)" : "transparent",
        backdropFilter: scrolled || menuOpen ? "blur(10px)" : "none",
        WebkitBackdropFilter: scrolled || menuOpen ? "blur(10px)" : "none",
        borderBottom: scrolled ? "1px solid var(--bm-hairline)" : "1px solid transparent",
        transition: "all 220ms var(--bm-ease-standard)",
      }}
    >
      <div
        style={{
          maxWidth: CANVAS_MAX,
          margin: "0 auto",
          display: "flex",
          alignItems: "center",
          justifyContent: "space-between",
          gap: 24,
        }}
      >
        <a href="/" style={{ display: "flex", alignItems: "center" }} onClick={() => setMenuOpen(false)}>
          <img
            src="/assets/beavermind-logo-white.svg"
            alt="BeaverMind.ai"
            style={{ height: 26, width: "auto", display: "block" }}
          />
        </a>

        {/* Desktop nav — hidden on tablet/mobile via mobile.css */}
        <nav data-bm-nav="desktop-links" style={{ display: "flex", gap: 28, alignItems: "center" }}>
          <a href="/#what"        style={linkStyle}>What we build</a>
          <a href="/proof"        style={linkStyle}>Proof</a>
          <a href="/#process"     style={linkStyle}>How we work</a>
          <a href="/about"       style={linkStyle}>About</a>
          <Button variant="primary" icon="arrow-right" onClick={goTalk}>Let's talk</Button>
        </nav>

        {/* Hamburger — shown on tablet/mobile via mobile.css */}
        <button
          data-bm-nav="hamburger"
          aria-label={menuOpen ? "Close menu" : "Open menu"}
          aria-expanded={menuOpen}
          onClick={() => setMenuOpen((o) => !o)}
          style={{
            display: "none",   /* shown via media query */
            alignItems: "center",
            justifyContent: "center",
            width: 44,
            height: 44,
            borderRadius: 12,
            border: "1px solid var(--bm-hairline-strong)",
            background: "transparent",
            color: "var(--bm-text)",
            cursor: "pointer",
            padding: 0,
          }}
        >
          <Icon name={menuOpen ? "x" : "menu"} size={20} color="currentColor" />
        </button>
      </div>

      {/* Mobile menu overlay — full-screen, fully opaque navy.
          Scroll is on the OUTER overlay (not an inner flex child) because
          iOS Safari is flaky with nested overflow inside a fixed element
          while body scroll is locked. Uses 100dvh so the Safari URL bar
          doesn't clip the CTA. */}
      {menuOpen && (
        <div
          style={{
            position: "fixed",
            inset: 0,
            height: "100dvh",
            background: "var(--bm-canvas)",
            zIndex: 60,
            overflowY: "auto",
            WebkitOverflowScrolling: "touch",
            overscrollBehavior: "contain",
            animation: "bm-fade-in 160ms var(--bm-ease-standard) both",
          }}
        >
          {/* Local top bar inside overlay — sticky so the close X stays
              reachable while the user scrolls the link list. */}
          <div
            style={{
              position: "sticky",
              top: 0,
              background: "var(--bm-canvas)",
              padding: "16px 20px",
              display: "flex",
              alignItems: "center",
              justifyContent: "space-between",
              borderBottom: "1px solid var(--bm-hairline)",
              zIndex: 1,
            }}
          >
            <a href="/" onClick={() => setMenuOpen(false)} style={{ display: "flex", alignItems: "center" }}>
              <img
                src="/assets/beavermind-logo-white.svg"
                alt="BeaverMind.ai"
                style={{ height: 24, width: "auto", display: "block" }}
              />
            </a>
            <button
              aria-label="Close menu"
              onClick={() => setMenuOpen(false)}
              style={{
                display: "inline-flex",
                alignItems: "center",
                justifyContent: "center",
                width: 44, height: 44,
                borderRadius: 12,
                border: "1px solid var(--bm-hairline-strong)",
                background: "transparent",
                color: "var(--bm-text)",
                cursor: "pointer",
                padding: 0,
              }}
            >
              <Icon name="x" size={20} color="currentColor" />
            </button>
          </div>

          {/* Link list + CTA — plain block flow, no flex:1 + overflow nesting */}
          <nav style={{ padding: "24px 24px 48px" }}>
            {[
              { label: "What we build", href: "/#what" },
              { label: "Proof",         href: "/proof" },
              { label: "How we work",   href: "/#process" },
              { label: "About",         href: "/about" },
            ].map((l) => (
              <a
                key={l.label}
                href={l.href}
                onClick={() => setMenuOpen(false)}
                style={{
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "space-between",
                  padding: "20px 4px",
                  fontFamily: "var(--bm-font-display)",
                  fontSize: 22,
                  fontWeight: 600,
                  letterSpacing: "-0.01em",
                  color: "var(--bm-text)",
                  textDecoration: "none",
                  borderBottom: "1px solid var(--bm-hairline)",
                }}
              >
                <span>{l.label}</span>
                <Icon name="arrow-up-right" size={18} color="var(--bm-text-muted)" />
              </a>
            ))}

            <div data-bm-cta-row style={{ marginTop: 28, display: "flex" }}>
              <Button variant="primary" icon="arrow-right" onClick={goTalk}>
                Let's talk
              </Button>
            </div>
          </nav>
        </div>
      )}
    </header>
  );
}

/* ------------------------------------------------------------------
   2. Hero
------------------------------------------------------------------ */
function Hero2() {
  return (
    <section
      id="top"
      data-screen-label="01 Hero"
      data-bm-section="hero"
      className="bm-section--ink"
      style={{ position: "relative", padding: "56px 32px 64px", overflow: "hidden" }}
    >
      <NeuralField />
      <HeroShader />
      <BottomLeftGlow />
      <Grain opacity={0.05} />
      <div style={{ position: "relative", maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div data-bm-hero-grid style={{ display: "grid", gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1.04fr)", gap: 56, alignItems: "center" }}>
          <div>
            <div data-bm-hero-eyebrow style={eyebrowStyle}>For 7–8 figure coaches &amp; consultants</div>

            <h1 data-bm-hero-title style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(36px, 4.4vw, 62px)", fontWeight: 700, letterSpacing: "-0.03em", lineHeight: 1.04, color: "var(--bm-text)", margin: 0, marginTop: 16 }}>
              A business that runs without you.
            </h1>

            <p style={{ fontSize: 19, lineHeight: 1.55, fontWeight: 400, color: "var(--bm-text)", margin: 0, marginTop: 20, maxWidth: 560 }}>
              We build and run the AI behind your sales, delivery, and operations —
              done-for-you, on your stack, so revenue keeps coming whether you show up
              or not.
            </p>

            <p style={{ fontSize: 15, lineHeight: 1.5, fontWeight: 400, color: "var(--bm-text-muted)", margin: 0, marginTop: 16, maxWidth: 560 }}>
              Here's one of those systems — a real outbound call, no human on the line.
            </p>

            <div data-bm-hero-ctas style={{ marginTop: 28 }}>
              <div data-bm-cta-row style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
                <Button variant="primary" icon="arrow-right" onClick={scrollToTalk}>Let's talk</Button>
              </div>
            </div>

            <div data-bm-hero-trust style={{ marginTop: 24, display: "flex", flexWrap: "wrap", alignItems: "center", gap: "10px 22px" }}>
              <span style={{ display: "inline-flex", alignItems: "center", gap: 8, fontSize: 14, fontWeight: 500, color: "var(--bm-text)", lineHeight: 1.4 }}>
                <Icon name="shield-check" size={16} color="var(--bm-good)" />
                Hit the KPIs we set in 90 days — or your money back
              </span>
            </div>
          </div>

          <HeroLiveCall embedded />
        </div>
      </div>
    </section>
  );
}

/* Signature moment 1 — abstract "leak → recovered" proof.
   A revenue-recovery curve draws in, three figures count up to a real
   result ($457 → $6,800 · 14.9x). Data-like, not illustrative. */
function HeroProof() {
  return (
    <div
      data-bm-hero-proof
      className="bm-reveal"
      style={{
        position: "relative",
        background: "rgba(11,15,46,0.72)",
        border: "1px solid var(--bm-hairline-strong)",
        borderRadius: 20,
        padding: 28,
        boxShadow: "0 40px 100px -50px rgba(109,145,242,0.5)",
        backdropFilter: "blur(2px)",
        WebkitBackdropFilter: "blur(2px)",
      }}
    >
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
        <span style={eyebrowStyle}>Dead-lead reactivation</span>
        <span style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--bm-text-muted)" }}>
          15 days
        </span>
      </div>

      <div style={{ position: "relative", marginTop: 18 }}>
        <svg viewBox="0 0 320 150" width="100%" height="auto" role="img"
          aria-label="Revenue recovered from a dead-lead list over 15 days: $457 ad spend returned $6,800, a 14.9x return">
          <defs>
            <linearGradient id="bm-proof-area" x1="0" y1="0" x2="0" y2="1">
              <stop offset="0%" stopColor="rgba(95,226,176,0.28)" />
              <stop offset="100%" stopColor="rgba(95,226,176,0)" />
            </linearGradient>
          </defs>
          <line x1="10" y1="138" x2="310" y2="138" stroke="var(--bm-hairline)" strokeWidth="1" />
          <path d="M10,132 C70,128 110,116 160,92 S250,34 310,18 L310,138 L10,138 Z"
            fill="url(#bm-proof-area)"
            style={{ opacity: 0, animation: "bm-area-in 900ms var(--bm-ease) 900ms both" }} />
          <path d="M10,132 C70,128 110,116 160,92 S250,34 310,18"
            fill="none" stroke="var(--bm-good)" strokeWidth="2.5" strokeLinecap="round"
            style={{ strokeDasharray: 640, strokeDashoffset: 640, animation: "bm-draw 1600ms var(--bm-ease) 200ms both" }} />
          <circle cx="310" cy="18" r="4" fill="var(--bm-good)"
            style={{ opacity: 0, animation: "bm-area-in 400ms var(--bm-ease) 1700ms both" }} />
        </svg>
      </div>

      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 12, marginTop: 18 }}>
        <ProofStat label="Ad spend" node={<CountUp to={457} prefix="$" />} />
        <ProofStat label="Recovered" tone="good" node={<CountUp to={6800} prefix="$" />} />
        <ProofStat label="ROI" tone="good" node={<CountUp to={14.9} decimals={1} suffix="x" />} />
      </div>
    </div>
  );
}

function ProofStat({ label, node, tone }) {
  const color = tone === "good" ? "var(--bm-good)" : "var(--bm-text)";
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
      <span style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--bm-text-muted)" }}>
        {label}
      </span>
      <span style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(22px, 2.4vw, 28px)", fontWeight: 700, letterSpacing: "-0.02em", color }}>
        {node}
      </span>
    </div>
  );
}

/* Hero secondary visual: live call + extraction panel.
   Picked up from the UI kit, tightened. Earns its space by
   showing what a voice agent actually does. */
function HeroLiveCall({ embedded }) {
  /* Real recorded "Emma" closed-deal calls (Ruben's public YouTube). Two
     selectable calls; play-on-demand, full audio, with the timestamped
     transcript scrolling in sync. Audio + transcript JSON both lazy-load —
     the click that starts playback is the iOS audio-unlock gesture. */
  const CALLS = {
    "2k":   { audio: "/assets/audio/emma-real-2k.mp3",   data: "/assets/call-2k.json",   amount: "$2,000", tab: "$2K deal" },
    "4800": { audio: "/assets/audio/emma-real-4800.mp3", data: "/assets/call-4800.json", amount: "$4,800", tab: "$4.8K deal" },
  };
  const [callKey, setCallKey]       = useSecState("2k");
  const [turnsByKey, setTurnsByKey] = useSecState({});
  const [playing, setPlaying]       = useSecState(false);
  const [cur, setCur]               = useSecState(0);
  const audioRef = useSecRef(null);
  const listRef  = useSecRef(null);
  const panelRef = useSecRef(null);
  const turns = turnsByKey[callKey] || null;

  const loadTurns = (key) => {
    if (turnsByKey[key]) return;
    fetch(CALLS[key].data).then((r) => r.json())
      .then((d) => setTurnsByKey((prev) => ({ ...prev, [key]: d })))
      .catch(() => {});
  };

  /* One audio element; mirror its events into state. */
  useSecEffect(() => {
    if (typeof Audio === "undefined") return;
    const a = new Audio();
    a.preload = "none";
    a.src = CALLS["2k"].audio;
    audioRef.current = a;
    const onTime  = () => setCur(a.currentTime || 0);
    const onPlay  = () => setPlaying(true);
    const onPause = () => setPlaying(false);
    const onEnd   = () => { setPlaying(false); setCur(0); };
    a.addEventListener("timeupdate", onTime);
    a.addEventListener("play", onPlay);
    a.addEventListener("pause", onPause);
    a.addEventListener("ended", onEnd);
    return () => {
      try { a.pause(); } catch (_) {}
      a.removeEventListener("timeupdate", onTime);
      a.removeEventListener("play", onPlay);
      a.removeEventListener("pause", onPause);
      a.removeEventListener("ended", onEnd);
    };
    // eslint-disable-next-line
  }, []);

  /* Load the default transcript up front so the panel reads as a real call
     before playback; pause audio when the panel scrolls offscreen. */
  useSecEffect(() => { loadTurns("2k"); /* eslint-disable-next-line */ }, []);
  useSecEffect(() => {
    if (!panelRef.current || typeof IntersectionObserver === "undefined") return;
    const io = new IntersectionObserver(([e]) => {
      if (!e.isIntersecting) { try { audioRef.current && audioRef.current.pause(); } catch (_) {} }
    }, { threshold: 0 });
    io.observe(panelRef.current);
    return () => io.disconnect();
  }, []);

  const selectCall = (key) => {
    if (key === callKey) return;
    const a = audioRef.current;
    try { a && a.pause(); } catch (_) {}
    if (a) a.src = CALLS[key].audio;
    setCallKey(key); setCur(0); setPlaying(false);
    loadTurns(key);
  };

  const togglePlay = () => {
    const a = audioRef.current;
    if (!a) return;
    if (!a.paused) { a.pause(); return; }
    const full = new URL(CALLS[callKey].audio, window.location.href).href;
    if (a.src !== full) a.src = CALLS[callKey].audio;
    loadTurns(callKey);
    const p = a.play();
    if (p && p.catch) p.catch(() => {});
  };

  let activeIdx = -1;
  if (turns) { for (let i = 0; i < turns.length; i++) { if (turns[i].t <= cur + 0.2) activeIdx = i; else break; } }
  const speaking = playing && activeIdx >= 0 && turns && turns[activeIdx] && turns[activeIdx].w === "a";

  /* Keep the active line centered — manual scrollTop so the page never jumps. */
  useSecEffect(() => {
    const c = listRef.current; if (!c || activeIdx < 0) return;
    const el = c.querySelector(`[data-turn="${activeIdx}"]`);
    if (el) c.scrollTop = el.offsetTop - c.clientHeight / 2 + el.clientHeight / 2;
  }, [activeIdx]);

  const mmss = (s) => `${String(Math.floor(s / 60)).padStart(2, "0")}:${String(Math.floor(s % 60)).padStart(2, "0")}`;

  return (
    <div
      data-bm-hero-livecall
      ref={panelRef}
      style={{
        position: "relative",
        marginTop: embedded ? 0 : 72,
        padding: 1,
        borderRadius: 22,
        background:
          "linear-gradient(160deg, rgba(109,145,242,0.45), rgba(109,145,242,0.04) 45%, transparent 75%)",
        boxShadow: "0 40px 100px -40px rgba(109,145,242,0.35)",
      }}
    >
      {/* Real-call badge */}
      <div style={{
        position: "absolute", top: 14, right: 14, zIndex: 3,
        display: "inline-flex", alignItems: "center", gap: 7,
        padding: "6px 11px", borderRadius: 999,
        border: "1px solid rgba(95,226,176,0.4)", background: "rgba(0,11,69,0.65)",
        color: "var(--bm-text)", fontSize: 10.5, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase",
        backdropFilter: "blur(6px)", WebkitBackdropFilter: "blur(6px)",
      }}>
        <span style={{ width: 6, height: 6, borderRadius: 999, background: "#5FE2B0", boxShadow: "0 0 0 3px rgba(95,226,176,0.18)" }} />
        Real call
      </div>

      <div
        data-bm-stack="hero-call"
        data-bm-hero-panel
        style={{
          background: "var(--bm-surface)",
          borderRadius: 22,
          padding: 32,
          display: "grid",
          gridTemplateColumns: "0.95fr 1.05fr",
          gap: 36,
          alignItems: "stretch",
        }}
      >
        {/* Agent + playback controls */}
        <div
          data-bm-hero-avatar-col
          style={{
            display: "flex", flexDirection: "column", alignItems: "center",
            justifyContent: "center", gap: 20,
            padding: "16px 8px",
            borderRight: "1px solid var(--bm-hairline)",
          }}
        >
          <VoiceAvatar speaking={speaking} idle />

          <div style={{ textAlign: "center" }}>
            <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 20, fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)" }}>
              Emma
            </div>
            <div style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-accent)", marginTop: 6 }}>
              AI Voice Agent
            </div>
            <div style={{ fontSize: 11.5, color: "var(--bm-text-muted)", marginTop: 5 }}>
              Appointment setter
            </div>
          </div>

          <SoundWave active={speaking} idle />

          <button
            data-bm-hero-play-btn
            onClick={togglePlay}
            aria-label={playing ? "Pause call" : "Play the real call"}
            style={{
              display: "inline-flex", alignItems: "center", gap: 9, cursor: "pointer",
              padding: "11px 18px", borderRadius: 999, border: "1px solid var(--bm-accent)",
              background: playing ? "rgba(109,145,242,0.18)" : "var(--bm-accent)",
              color: playing ? "var(--bm-text)" : "#00122E",
              fontFamily: "var(--bm-font-body)", fontSize: 13.5, fontWeight: 700, letterSpacing: "0.01em",
              transition: "background 160ms var(--bm-ease-standard)",
            }}
          >
            <Icon name={playing ? "pause" : "play"} size={15} color="currentColor" />
            {playing ? "Pause" : "Hear the real call"}
          </button>

          <div style={{
            display: "flex", alignItems: "center", gap: 10,
            fontSize: 11, color: "var(--bm-text-muted)",
            letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 600,
          }}>
            <span style={{
              width: 6, height: 6, borderRadius: 999,
              background: playing ? "#5FE2B0" : "var(--bm-text-dim)",
              boxShadow: playing ? "0 0 0 3px rgba(95,226,176,0.18)" : "none",
            }} />
            {playing ? "Live" : "Ready"} · {mmss(cur)}
          </div>
        </div>

        {/* Transcript + call selector — synced to the real audio. */}
        <div data-bm-hero-transcript style={{ display: "flex", flexDirection: "column", minWidth: 0 }}>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12, marginBottom: 10, flexWrap: "wrap" }}>
            <span style={{ fontSize: 11, color: "var(--bm-text-muted)", letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 600 }}>
              Unedited transcript
            </span>
            <div style={{ display: "inline-flex", gap: 6, background: "rgba(0,3,34,0.5)", border: "1px solid var(--bm-hairline)", borderRadius: 999, padding: 3 }}>
              {["2k", "4800"].map((k) => {
                const sel = k === callKey;
                return (
                  <button key={k} onClick={() => selectCall(k)} aria-pressed={sel} style={{
                    cursor: "pointer", border: "none", borderRadius: 999, padding: "5px 12px",
                    fontFamily: "var(--bm-font-body)", fontSize: 12, fontWeight: 700, letterSpacing: "0.02em",
                    background: sel ? "var(--bm-accent)" : "transparent",
                    color: sel ? "#00122E" : "var(--bm-text-muted)",
                    transition: "background 140ms var(--bm-ease), color 140ms var(--bm-ease)",
                  }}>{CALLS[k].tab}</button>
                );
              })}
            </div>
          </div>
          <div style={{ fontSize: 12, lineHeight: 1.5, color: "var(--bm-text-muted)", marginBottom: 10 }}>
            No one on your team was on this call. Emma reactivated a cold lead, qualified it, and booked it — a human closer took it from there. Closed at {CALLS[callKey].amount}.
          </div>
          <div
            ref={listRef}
            className="bm-rail"
            style={{
              position: "relative", display: "flex", flexDirection: "column", gap: 9,
              minWidth: 0, height: 318, overflowY: "auto", overflowX: "hidden", paddingRight: 6,
              maskImage: "linear-gradient(180deg, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%)",
              WebkitMaskImage: "linear-gradient(180deg, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%)",
            }}
          >
            {turns ? turns.map((tn, i) => {
              const isAgent = tn.w === "a";
              const active = i === activeIdx;
              return (
                <div key={i} data-turn={i} style={{
                  fontSize: 13.5, lineHeight: 1.55,
                  color: active ? "var(--bm-text)" : (isAgent ? "rgba(245,249,255,0.72)" : "var(--bm-text-muted)"),
                  padding: "10px 13px", borderRadius: 13,
                  background: active ? (isAgent ? "rgba(109,145,242,0.16)" : "rgba(245,249,255,0.06)") : (isAgent ? "rgba(109,145,242,0.05)" : "transparent"),
                  border: `1px solid ${active ? (isAgent ? "rgba(109,145,242,0.4)" : "var(--bm-hairline-strong)") : (isAgent ? "rgba(109,145,242,0.16)" : "var(--bm-hairline)")}`,
                  opacity: (active || activeIdx < 0) ? 1 : 0.8,
                  transition: "background 220ms var(--bm-ease), border-color 220ms var(--bm-ease), color 220ms var(--bm-ease), opacity 220ms var(--bm-ease)",
                }}>
                  <div style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 5, color: isAgent ? "var(--bm-accent)" : "var(--bm-text-muted)" }}>
                    {isAgent ? "Emma · AI" : "Prospect"}
                  </div>
                  {tn.x}
                </div>
              );
            }) : (
              <div style={{ fontSize: 13, color: "var(--bm-text-muted)", padding: "10px 2px" }}>Loading transcript…</div>
            )}
          </div>
          <a
            href="/case-studies/ai-voice-agent"
            style={{
              marginTop: 14, alignSelf: "flex-start",
              display: "inline-flex", alignItems: "center", gap: 7,
              fontSize: 13, fontWeight: 700, letterSpacing: "0.01em",
              color: "var(--bm-accent)", textDecoration: "none",
            }}
          >
            Watch the full case study
            <span aria-hidden="true">→</span>
          </a>
        </div>
      </div>
    </div>
  );
}

function VoiceAvatar({ speaking, avatarSrc, idle }) {
  /* Emma's canonical avatar — holographic-professional portrait with animated
     pulse rings, ambient halo, and rim glow. `speaking` = full motion;
     `idle` = subtle always-on motion (slower rings + gentle halo) so she draws
     attention before the call plays. */
  return (
    <div style={{ position: "relative", width: 132, height: 132 }}>
      {/* Ambient halo — always-on soft glow, pulses while speaking */}
      <span
        className="bm-halo"
        aria-hidden
        style={{
          position: "absolute",
          inset: -10,
          borderRadius: "50%",
          background:
            "radial-gradient(circle, rgba(109,145,242,0.35) 0%, rgba(109,145,242,0) 60%)",
          animation: speaking
            ? "bm-halo 1800ms ease-in-out infinite"
            : (idle ? "bm-halo 4200ms ease-in-out infinite" : "none"),
          opacity: speaking ? 1 : (idle ? 0.6 : 0.45),
          transition: "opacity 300ms var(--bm-ease-standard)",
          filter: "blur(6px)",
        }}
      />

      {/* Pulsing expansion rings — only while speaking */}
      {[0, 1, 2].map((i) => (
        <span
          key={i}
          className="bm-ring"
          aria-hidden
          style={{
            position: "absolute",
            inset: 0,
            borderRadius: "50%",
            border: "1px solid rgba(179,198,255,0.5)",
            animation: speaking
              ? `bm-ring 2400ms ${i * 800}ms cubic-bezier(0.2,0.7,0.2,1) infinite`
              : (idle ? `bm-ring 5200ms ${i * 1700}ms cubic-bezier(0.2,0.7,0.2,1) infinite` : "none"),
            opacity: speaking ? 1 : (idle ? 0.7 : 0),
            transition: "opacity 300ms var(--bm-ease-standard)",
          }}
        />
      ))}

      {/* Portrait disc — real rendered Emma, clipped to circle */}
      <div
        style={{
          position: "absolute",
          inset: 8,
          borderRadius: "50%",
          overflow: "hidden",
          border: "1px solid rgba(109,145,242,0.4)",
          boxShadow: speaking
            ? "0 0 0 1px rgba(179,198,255,0.5), 0 0 44px -4px rgba(109,145,242,0.65)"
            : (idle
              ? "0 0 0 1px rgba(109,145,242,0.4), 0 0 32px -4px rgba(109,145,242,0.5)"
              : "0 0 0 1px rgba(109,145,242,0.25), 0 0 18px -4px rgba(109,145,242,0.3)"),
          transition: "box-shadow 300ms var(--bm-ease-standard)",
          background: "#050c2b",
        }}
      >
        <img
          src={avatarSrc || "/assets/emma-avatar.png?v=2"}
          alt="AI agent"
          loading="lazy"
          style={{
            width: "100%",
            height: "100%",
            objectFit: "cover",
            objectPosition: "center 18%",
            display: "block",
          }}
        />

        {/* Subtle top-left specular wash for a holographic shine feel */}
        <span
          aria-hidden
          style={{
            position: "absolute",
            inset: 0,
            borderRadius: "50%",
            background:
              "radial-gradient(ellipse at 28% 22%, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 45%)",
            pointerEvents: "none",
            mixBlendMode: "screen",
          }}
        />
      </div>
    </div>
  );
}

function SoundWave({ active, idle }) {
  const bars = 14;
  return (
    <div
      aria-hidden
      style={{
        display: "flex", alignItems: "center", gap: 4,
        height: 28,
      }}
    >
      {Array.from({ length: bars }).map((_, i) => {
        const mid = (bars - 1) / 2;
        const falloff = 1 - Math.abs(i - mid) / (mid + 1);
        const h = 6 + Math.round(falloff * 20);
        const delay = (i * 70) % 700;
        return (
          <span
            key={i}
            className={idle && !active ? "bm-bar-idle" : "bm-bar"}
            style={{
              width: 3, height: h,
              borderRadius: 2,
              background: active
                ? "linear-gradient(180deg, #B3C6FF, #6D91F2)"
                : (idle ? "rgba(109,145,242,0.4)" : "rgba(109,145,242,0.22)"),
              transformOrigin: "center",
              animation: active
                ? `bm-bar ${700 + (i % 4) * 120}ms ${delay}ms cubic-bezier(0.4,0,0.2,1) infinite`
                : (idle ? `bm-bar-idle ${1500 + (i % 4) * 220}ms ${delay}ms ease-in-out infinite` : "none"),
              transition: "background 200ms var(--bm-ease-standard)",
              willChange: (active || idle) ? "transform" : "auto",
            }}
          />
        );
      })}
    </div>
  );
}

function TypingDots() {
  return (
    <div style={{
      display: "flex", alignItems: "center", gap: 6,
      padding: "10px 14px",
      fontSize: 10, fontWeight: 600, letterSpacing: "0.14em",
      textTransform: "uppercase",
      color: "var(--bm-text-muted)",
    }}>
      <span>Lead</span>
      <span style={{ display: "inline-flex", gap: 3, marginLeft: 6 }}>
        {[0, 1, 2].map((i) => (
          <span
            key={i}
            className="bm-dot"
            style={{
              width: 4, height: 4, borderRadius: 999,
              background: "var(--bm-text-muted)",
              animation: `bm-dot 1200ms ${i * 180}ms ease-in-out infinite`,
            }}
          />
        ))}
      </span>
    </div>
  );
}

/* ------------------------------------------------------------------
   3. The Contrarian Truth / why we disqualify  (paper)
------------------------------------------------------------------ */
function ContrarianTruth() {
  return (
    <section
      data-screen-label="02 Why we disqualify"
      data-bm-section="mid"
      className="bm-section--paper"
      style={{ padding: "120px 32px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Why we disqualify</div>
        <h2 className="bm-reveal" style={{ ...displayM, marginTop: 16, maxWidth: 880 }}>
          Most AI projects don't fail on the technology. They fail on the foundation.
        </h2>
        <p className="bm-reveal" style={{ ...bodyL, marginTop: 22, maxWidth: 720 }}>
          Your pipeline leaks somewhere you can't measure — dead leads, slow
          speed-to-lead, no-shows. But AI only amplifies what's already there.
          If your process doesn't work with humans, we won't take it on — we say no more often than we say yes.
        </p>

        <div
          className="bm-reveal"
          data-bm-stack="cols-2"
          style={{ marginTop: 44, display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 16 }}
        >
          <FoundationCard
            tone="warn"
            icon="circle-slash"
            stat="We disqualify"
            statLabel="on purpose"
            body="No consistent lead flow, no proven sales process, or a broken offer. We say no — before you spend anything."
          />
          <FoundationCard
            tone="good"
            icon="check-check"
            stat="Manual-first"
            statLabel="rule, every engagement"
            body="If it already works with humans, AI multiplies it. We automate what's proven, never the hypothetical."
          />
        </div>
      </div>
    </section>
  );
}

function FoundationCard({ tone, icon, stat, statLabel, body }) {
  const accent = tone === "warn" ? "var(--bm-warn)" : "var(--bm-good)";
  const tint = tone === "warn" ? "rgba(242,196,109,0.16)" : "rgba(95,226,176,0.16)";
  const iconColor = tone === "warn" ? "#8A6A1F" : "#157A57";
  return (
    <div style={{
      background: "var(--bm-surface)",
      border: "1px solid var(--bm-hairline)",
      borderTop: `3px solid ${accent}`,
      borderRadius: 16,
      padding: 28,
      display: "flex", flexDirection: "column", gap: 16,
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
        <span style={{
          width: 40, height: 40, borderRadius: 10, flexShrink: 0,
          display: "inline-flex", alignItems: "center", justifyContent: "center",
          background: tint, border: `1px solid ${accent}`,
        }}>
          <Icon name={icon} size={20} color={iconColor} />
        </span>
        <div style={{ display: "flex", flexDirection: "column" }}>
          <span style={{
            fontFamily: "var(--bm-font-display)", fontSize: "clamp(24px, 2.6vw, 31px)",
            fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)", lineHeight: 1,
          }}>
            {stat}
          </span>
          <span style={{ fontSize: 12, color: "var(--bm-text-muted)", marginTop: 6, letterSpacing: "0.03em" }}>
            {statLabel}
          </span>
        </div>
      </div>
      <p style={{ ...bodyM, fontSize: 15 }}>{body}</p>
    </div>
  );
}

/* ------------------------------------------------------------------
   3. Proof bar (slim) — social proof immediately under the hero.
   Three count-up metrics + a "proven first" line + client names (text).
------------------------------------------------------------------ */
function ProofBar() {
  const metrics = [
    { node: <CountUp to={14.9} decimals={1} suffix="x" />,  label: "ROI on a dead-lead list" },
    { node: <CountUp to={96} prefix="−" suffix="%" />,      label: "cost per outbound call" },
    { node: <CountUp to={60} prefix="30% → " suffix="%" />, label: "email open rate" },
  ];
  return (
    <section
      data-screen-label="02 Proof"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{
        padding: "40px 32px",
        borderTop: "1px solid var(--bm-hairline)",
        borderBottom: "1px solid var(--bm-hairline)",
      }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Proven in production</div>
        <div
          data-bm-proofbar
          style={{
            marginTop: 18, display: "flex", flexWrap: "wrap",
            alignItems: "center", justifyContent: "space-between", gap: "24px 40px",
          }}
        >
          <div style={{ display: "flex", flexWrap: "wrap", gap: "20px 40px" }}>
            {metrics.map((m, i) => (
              <div key={i} style={{ display: "flex", flexDirection: "column", gap: 6 }}>
                <span style={{
                  fontFamily: "var(--bm-font-display)", fontSize: "clamp(28px, 3vw, 40px)",
                  fontWeight: 700, letterSpacing: "-0.025em", lineHeight: 1, color: "var(--bm-good)",
                }}>
                  {m.node}
                </span>
                <span style={{ fontSize: 13, color: "var(--bm-text-muted)", lineHeight: 1.35 }}>{m.label}</span>
              </div>
            ))}
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 6, maxWidth: 340 }}>
            <span style={{ fontSize: 14, color: "var(--bm-text)", lineHeight: 1.45 }}>
              Every system proven inside a $3M+ business before it ships to yours.
            </span>
            <span style={{ fontSize: 12, color: "var(--bm-text-muted)", letterSpacing: "0.04em" }}>
              MovesMethod · Five50 Advisory · Dr Andrea Grandi
            </span>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ------------------------------------------------------------------
   4. What We Build
------------------------------------------------------------------ */
/* Animated micro-visuals ported from the Claude Design file
   (BeaverMind Sections.dc.html). Each returns a small React tree. */
function bmViz(type) {
  const h = React.createElement;
  const A = "#6D91F2";
  const FAINT = "rgba(109,145,242,0.18)";
  if (type === "face") {
    const n = 28, bars = [];
    for (let i = 0; i < n; i++) {
      const mid = (n - 1) / 2;
      const env = 1 - Math.abs(i - mid) / (mid + 1);
      const bh = 4 + Math.round(env * env * 22) + ((i % 3) * 2);
      bars.push(h("span", { key: i, style: { width: 2, height: bh, borderRadius: 2, background: "rgba(109,145,242,0.55)", transformOrigin: "center", animation: `bmBar ${0.8 + (i % 5) * 0.1}s ease-in-out ${(i % 7) * 0.06}s infinite` } }));
    }
    return h("div", { style: { width: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 14, padding: "10px 0" } },
      h("div", { key: "av", style: { width: 116, height: 116, borderRadius: "50%", backgroundImage: "url('/assets/emma-avatar.png?v=2')", backgroundSize: "cover", backgroundPosition: "center top", border: "2px solid rgba(109,145,242,0.55)", boxShadow: "0 0 0 6px rgba(0,3,34,0.55), 0 0 46px -6px rgba(109,145,242,0.6)" } }),
      h("div", { key: "name", style: { fontFamily: "'SF Pro Display'", fontWeight: 700, fontSize: 26, letterSpacing: "-0.02em", color: "#F5F9FF", lineHeight: 1, marginTop: 4 } }, "Emma"),
      h("div", { key: "role", style: { fontSize: 12, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6D91F2" } }, "AI Voice Agent"),
      h("div", { key: "wave", style: { display: "flex", alignItems: "center", gap: 2, height: 30, marginTop: 4 } }, bars),
      h("div", { key: "live", style: { display: "flex", alignItems: "center", gap: 9, fontSize: 12, fontWeight: 600, letterSpacing: "0.16em", color: "#8A94B4", marginTop: 2 } },
        h("span", { style: { width: 9, height: 9, borderRadius: "50%", background: "#34D399", boxShadow: "0 0 0 3px rgba(52,211,153,0.2)" } }),
        h("span", null, "LIVE · 00:21"))
    );
  }
  if (type === "wave") {
    const bars = [];
    for (let i = 0; i < 20; i++) bars.push(h("span", { key: i, style: { flex: 1, height: "100%", borderRadius: 2, background: i % 3 === 0 ? A : "rgba(109,145,242,0.4)", transformOrigin: "center", animation: `bmBar ${0.7 + (i % 5) * 0.12}s ease-in-out ${i * 0.05}s infinite` } }));
    return h("div", { style: { display: "flex", gap: 3, alignItems: "center", height: 40, width: "100%" } }, bars);
  }
  if (type === "ring") {
    const r = 34, c = 2 * Math.PI * r;
    return h("div", { style: { position: "relative", width: 100, height: 100, display: "flex", alignItems: "center", justifyContent: "center" } },
      h("svg", { key: "s", width: 100, height: 100, viewBox: "0 0 100 100", style: { transform: "rotate(-90deg)" } },
        h("circle", { cx: 50, cy: 50, r: r, fill: "none", stroke: "rgba(109,145,242,0.16)", strokeWidth: 6 }),
        h("circle", { cx: 50, cy: 50, r: r, fill: "none", stroke: A, strokeWidth: 6, strokeLinecap: "round", strokeDasharray: `${c * 0.92} ${c}`, style: { "--len": c + "px", strokeDashoffset: 0, animation: "bmDraw 3.4s ease-out infinite" } })),
      h("div", { key: "t", style: { position: "absolute", fontFamily: "'SF Pro Display'", fontWeight: 700, fontSize: 26, color: "#F5F9FF", letterSpacing: "-0.02em" } }, "92"));
  }
  if (type === "chat") {
    const dot = (d) => h("span", { key: d, style: { width: 7, height: 7, borderRadius: "50%", background: A, display: "inline-block", animation: `bmDots 1.4s ease-in-out ${d * 0.18}s infinite` } });
    return h("div", { style: { width: "100%", display: "flex", flexDirection: "column", gap: 12, justifyContent: "center" } },
      h("div", { key: "q", style: { alignSelf: "flex-start", maxWidth: "88%", background: "#001161", border: "1px solid rgba(109,145,242,0.14)", borderRadius: "14px 14px 14px 4px", padding: "12px 14px", fontSize: 13.5, lineHeight: 1.4, color: "#F5F9FF" } }, "How should I adjust my deload week?"),
      h("div", { key: "a", style: { alignSelf: "flex-end", background: "rgba(109,145,242,0.16)", border: "1px solid rgba(109,145,242,0.32)", borderRadius: "14px 14px 4px 14px", padding: "15px 17px", display: "flex", gap: 6, alignItems: "center" } }, dot(0), dot(1), dot(2)));
  }
  if (type === "spark") {
    const LINE = "M0,92 L36,72 L72,84 L108,52 L150,62 L192,30 L232,42 L280,18";
    const AREA = LINE + " L280,120 L0,120 Z";
    return h("div", { style: { width: "100%" } },
      h("svg", { viewBox: "0 0 280 120", width: "100%", height: 150, preserveAspectRatio: "none" },
        h("defs", null, h("linearGradient", { id: "bmsg", x1: 0, y1: 0, x2: 0, y2: 1 },
          h("stop", { offset: "0%", stopColor: "rgba(109,145,242,0.38)" }),
          h("stop", { offset: "100%", stopColor: "rgba(109,145,242,0)" }))),
        h("path", { d: AREA, fill: "url(#bmsg)", style: { animation: "bmFade 3.4s ease-out infinite" } }),
        h("path", { d: LINE, fill: "none", stroke: A, strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round", pathLength: 100, strokeDasharray: 100, style: { "--len": 100, strokeDashoffset: 0, animation: "bmDraw 3.4s ease-out infinite" } }),
        h("circle", { r: 4, fill: A, cx: 280, cy: 18, style: { animation: "bmPulse 2s ease-in-out infinite" } })));
  }
  if (type === "revive") {
    const row = (d) => h("div", { key: d, style: { display: "flex", alignItems: "center", gap: 8, width: 148 } },
      h("span", { style: { flex: "none", width: 9, height: 9, borderRadius: "50%", background: FAINT, animation: `bmRevive 3s ease-out ${d}s infinite` } }),
      h("span", { style: { flex: 1, height: 4, borderRadius: 3, background: FAINT } }));
    return h("div", { style: { width: "100%", height: "100%", display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", gap: 6 } }, row(0), row(0.5), row(1));
  }
  if (type === "calendar") {
    const cells = [];
    for (let i = 0; i < 8; i++) {
      const hit = i === 5;
      cells.push(h("span", { key: i, style: { width: 14, height: 11, borderRadius: 3, background: hit ? A : "rgba(0,3,34,0.4)", border: hit ? "none" : "1px solid rgba(109,145,242,0.25)", display: "flex", alignItems: "center", justifyContent: "center", animation: hit ? "bmPop 3s ease-out infinite" : "none" } },
        hit ? h("svg", { width: 8, height: 8, viewBox: "0 0 12 12", fill: "none" }, h("path", { d: "M2.5 6.5 L5 9 L9.5 3.5", stroke: "#000322", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" })) : null));
    }
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" } },
      h("div", { style: { display: "grid", gridTemplateColumns: "repeat(4, 14px)", gap: 4 } }, cells));
  }
  if (type === "inbound") {
    return h("div", { style: { position: "relative", width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" } },
      h("div", { key: "r1", style: { position: "absolute", width: 34, height: 34, borderRadius: "50%", border: "1px solid rgba(109,145,242,0.4)", animation: "bmRing 2.4s ease-out infinite" } }),
      h("div", { key: "r2", style: { position: "absolute", width: 34, height: 34, borderRadius: "50%", border: "1px solid rgba(109,145,242,0.3)", animation: "bmRing 2.4s ease-out 1.2s infinite" } }),
      h("div", { key: "c", style: { position: "relative", width: 27, height: 27, borderRadius: "50%", background: "rgba(109,145,242,0.16)", border: "1px solid rgba(109,145,242,0.5)", display: "flex", alignItems: "center", justifyContent: "center", animation: "bmPulse 2s ease-in-out infinite" } },
        h("svg", { width: 13, height: 13, viewBox: "0 0 24 24", fill: "none" }, h("path", { d: "M6.5 4 C5 4 4 5 4 6.5 C4 14 10 20 17.5 20 C19 20 20 19 20 17.5 L20 15 L15.5 13.5 L14 15.5 C12 14.5 9.5 12 8.5 10 L10.5 8.5 L9 4 Z", fill: A }))));
  }
  if (type === "funnel") {
    const dotRow = (n, lit, d) => {
      const arr = [];
      for (let i = 0; i < n; i++) arr.push(h("span", { key: i, style: { width: 7, height: 7, borderRadius: "50%", background: lit ? A : FAINT, animation: lit ? `bmPop 3s ease-out ${d}s infinite` : "none" } }));
      return h("div", { key: n, style: { display: "flex", gap: 5 } }, arr);
    };
    return h("div", { style: { width: "100%", height: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 5 } }, dotRow(5, false, 0), dotRow(3, false, 0), dotRow(1, true, 0.4));
  }
  if (type === "warm") {
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center", gap: 11 } },
      h("div", { style: { position: "relative", width: 14, height: 38 } },
        h("div", { key: "trk", style: { position: "absolute", top: 0, bottom: 8, left: "50%", transform: "translateX(-50%)", width: 8, borderRadius: 999, background: FAINT } }),
        h("div", { key: "fill", style: { position: "absolute", top: 4, bottom: 8, left: "50%", transform: "translateX(-50%) scaleY(1)", transformOrigin: "bottom", width: 8, borderRadius: 999, background: "linear-gradient(180deg,#6D91F2,#557CE8)", animation: "bmGrowY 3s ease-out infinite" } }),
        h("div", { key: "bulb", style: { position: "absolute", bottom: 0, left: "50%", transform: "translateX(-50%)", width: 14, height: 14, borderRadius: "50%", background: A } })),
      h("div", { style: { display: "flex", flexDirection: "column", gap: 4 } },
        h("span", { key: "a", style: { width: 24, height: 4, borderRadius: 3, background: FAINT } }),
        h("span", { key: "b", style: { width: 16, height: 4, borderRadius: 3, background: FAINT } }),
        h("span", { key: "c", style: { width: 28, height: 4, borderRadius: 3, background: A } })));
  }
  if (type === "loop") {
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" } },
      h("svg", { width: 120, height: 40, viewBox: "0 0 120 40" },
        h("rect", { key: "b1", x: 6, y: 7, width: 34, height: 18, rx: 6, fill: "rgba(109,145,242,0.16)", stroke: "rgba(109,145,242,0.4)", strokeWidth: 1 }),
        h("rect", { key: "b2", x: 80, y: 7, width: 34, height: 18, rx: 6, fill: A }),
        h("path", { key: "arc", d: "M40 27 C54 39 66 39 80 27", fill: "none", stroke: A, strokeWidth: 1.6, strokeLinecap: "round", pathLength: 100, strokeDasharray: 100, style: { "--len": 100, animation: "bmDraw 3s ease-out infinite" } }),
        h("path", { key: "ah", d: "M80 27 L73 26 M80 27 L78 34", fill: "none", stroke: A, strokeWidth: 1.6, strokeLinecap: "round" })));
  }
  if (type === "draft") {
    const line = (w, d) => h("div", { key: w, style: { width: w, height: 4, borderRadius: 2, background: "rgba(109,145,242,0.18)", position: "relative", overflow: "hidden" } },
      h("div", { style: { position: "absolute", inset: 0, width: 0, "--w": "100%", background: A, animation: `bmFill 3s ease-out ${d}s infinite` } }));
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center", gap: 12 } },
      h("div", { style: { width: 34, height: 40, borderRadius: 5, background: "rgba(0,3,34,0.5)", border: "1px solid rgba(109,145,242,0.28)", padding: 6, display: "flex", flexDirection: "column", gap: 4, boxSizing: "border-box", justifyContent: "center" } },
        line("100%", 0), line("78%", 0.25), line("90%", 0.5)),
      h("div", { style: { width: 20, height: 20, borderRadius: "50%", background: A, display: "flex", alignItems: "center", justifyContent: "center", animation: "bmTick 3s ease-out 0.8s infinite" } },
        h("svg", { width: 11, height: 11, viewBox: "0 0 12 12", fill: "none" }, h("path", { d: "M2.5 6.5 L5 9 L9.5 3.5", stroke: "#000322", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }))));
  }
  if (type === "program") {
    const heights = [2, 3, 1, 3, 2];
    const cols = heights.map((n, ci) => {
      const cells = [];
      for (let i = 0; i < n; i++) cells.push(h("span", { key: i, style: { width: 11, height: 7, borderRadius: 2, background: i === 0 ? A : FAINT, animation: `bmPop 3s ease-out ${ci * 0.18 + i * 0.1}s infinite` } }));
      return h("div", { key: ci, style: { display: "flex", flexDirection: "column-reverse", gap: 3 } }, cells);
    });
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "flex-end", justifyContent: "center", gap: 5 } }, cols);
  }
  if (type === "qc") {
    const bars = [0, 1, 2, 3].map((i) => h("div", { key: i, style: { width: 9, height: 30, borderRadius: 3, background: A, transformOrigin: "bottom", animation: `bmGrowY 2.6s ease-in-out ${i * 0.12}s infinite` } }));
    return h("div", { style: { position: "relative", width: "100%", height: "100%", display: "flex", alignItems: "flex-end", justifyContent: "center", gap: 7, paddingBottom: 5 } },
      bars,
      h("div", { key: "ln", style: { position: "absolute", left: "50%", top: "calc(50% - 13px)", transform: "translateX(-50%)", width: 62, borderTop: "1px dashed rgba(109,145,242,0.6)" } }));
  }
  if (type === "fanout") {
    const ty = [3, 13, 23, 33];
    const lines = ty.map((y, i) => h("path", { key: "l" + i, d: `M30 20 C70 20 80 ${y + 3} 108 ${y + 3}`, fill: "none", stroke: "rgba(109,145,242,0.4)", strokeWidth: 1.2, pathLength: 100, strokeDasharray: 100, style: { "--len": 100, animation: `bmDraw 3s ease-out ${i * 0.15}s infinite` } }));
    const tiles = ty.map((y, i) => h("rect", { key: "t" + i, x: 108, y: y, width: 28, height: 6, rx: 2, fill: A, style: { transformBox: "fill-box", transformOrigin: "center", animation: `bmPop 3s ease-out ${0.3 + i * 0.15}s infinite` } }));
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" } },
      h("svg", { width: 144, height: 40, viewBox: "0 0 144 40" }, lines,
        h("circle", { key: "n1", cx: 22, cy: 20, r: 8, fill: "rgba(109,145,242,0.16)", stroke: A, strokeWidth: 1.5 }),
        h("circle", { key: "n2", cx: 22, cy: 20, r: 3, fill: A, style: { animation: "bmPulse 2s ease-in-out infinite" } }), tiles));
  }
  if (type === "pipeline") {
    const env = (x) => h("g", { key: x },
      h("rect", { x: x, y: 5, width: 24, height: 16, rx: 3, fill: "rgba(109,145,242,0.14)", stroke: "rgba(109,145,242,0.45)", strokeWidth: 1 }),
      h("path", { d: `M${x + 1} 7 L${x + 12} 15 L${x + 23} 7`, fill: "none", stroke: "rgba(109,145,242,0.65)", strokeWidth: 1 }));
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" } },
      h("svg", { width: 132, height: 40, viewBox: "0 0 132 40" }, env(6), env(54), env(102),
        h("line", { key: "trk", x1: 8, y1: 33, x2: 124, y2: 33, stroke: "rgba(109,145,242,0.25)", strokeWidth: 1.5, strokeLinecap: "round" }),
        h("circle", { key: "dot", cx: 10, cy: 33, r: 3.5, fill: A }, h("animate", { attributeName: "cx", values: "12;120", dur: "2.4s", repeatCount: "indefinite" }))));
  }
  if (type === "dashboard") {
    const bars = [14, 22, 18, 28, 24].map((bh, i) => h("div", { key: i, style: { width: 6, height: bh, borderRadius: 2, background: i === 3 ? A : FAINT, transformOrigin: "bottom", animation: `bmGrowY 2.8s ease-in-out ${i * 0.1}s infinite` } }));
    return h("div", { style: { width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center", gap: 13 } },
      h("div", { style: { display: "flex", flexDirection: "column", gap: 5, alignItems: "flex-start" } },
        h("div", { key: "n", style: { fontFamily: "'SF Pro Display'", fontWeight: 700, fontSize: 18, color: "#F5F9FF", letterSpacing: "-0.02em", lineHeight: 1 } }, "94%"),
        h("div", { key: "u", style: { width: 32, height: 4, borderRadius: 3, background: FAINT } })),
      h("div", { style: { display: "flex", alignItems: "flex-end", gap: 4, height: 30 } }, bars));
  }
  return null;
}

/* Playable Emma demo — reuses the existing live-call audio. One demo, plays
   in place (no "see it work → calendar"). */
function VoicePlayer() {
  const lines = [
    "/assets/audio/01-emma.mp3?v=8", "/assets/audio/02-john.mp3?v=8", "/assets/audio/03-emma.mp3?v=8",
    "/assets/audio/04-john.mp3?v=8", "/assets/audio/05-emma.mp3?v=8", "/assets/audio/06-john.mp3?v=8", "/assets/audio/07-emma.mp3?v=8",
  ];
  const audioRef = useSecRef(null);
  const idxRef = useSecRef(0);
  const [playing, setPlaying] = useSecState(false);
  useSecEffect(() => {
    if (typeof Audio === "undefined") return;
    const a = new Audio(); a.preload = "auto"; audioRef.current = a;
    return () => { try { a.pause(); } catch (_) {} };
  }, []);
  const playFrom = (i) => {
    const a = audioRef.current; if (!a) return;
    if (i >= lines.length) { idxRef.current = 0; setPlaying(false); return; }
    idxRef.current = i; a.src = lines[i]; a.currentTime = 0;
    a.onended = () => playFrom(idxRef.current + 1);
    const p = a.play(); if (p && p.catch) p.catch(() => {});
  };
  const toggle = () => {
    const a = audioRef.current; if (!a) return;
    if (playing) { try { a.pause(); } catch (_) {} a.onended = null; setPlaying(false); }
    else { setPlaying(true); playFrom(idxRef.current >= lines.length ? 0 : idxRef.current); }
  };
  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 14, padding: "8px 0", width: "100%" }}>
      <VoiceAvatar speaking={playing} />
      <div style={{ textAlign: "center" }}>
        <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 20, fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)" }}>Emma</div>
        <div style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-accent)", marginTop: 6 }}>AI Voice Agent</div>
      </div>
      <SoundWave active={playing} />
      <button onClick={(e) => { e.preventDefault(); toggle(); }} aria-label={playing ? "Pause demo call" : "Play demo call"} style={{
        display: "inline-flex", alignItems: "center", gap: 9, padding: "10px 18px", borderRadius: 999, cursor: "pointer",
        background: playing ? "rgba(109,145,242,0.16)" : "var(--bm-accent)", color: playing ? "var(--bm-text)" : "#000322",
        border: `1px solid ${playing ? "rgba(109,145,242,0.5)" : "transparent"}`,
        fontFamily: "var(--bm-font-body)", fontSize: 14, fontWeight: 600,
        transition: "background 160ms var(--bm-ease)",
      }}>
        <Icon name={playing ? "pause" : "play"} size={15} color="currentColor" />
        {playing ? "Playing the call…" : "Play a real call"}
      </button>
    </div>
  );
}

function LeadTile({ title, body, vizType, demo }) {
  return (
    <div data-bm-lead-tile style={{
      marginTop: 28, position: "relative", overflow: "hidden",
      border: "1px solid var(--bm-hairline)", borderRadius: 18,
      background: "linear-gradient(135deg, rgba(109,145,242,0.16), rgba(0,11,69,0.35) 55%), #000B45",
      padding: 34, display: "grid", gridTemplateColumns: "1.05fr 0.95fr", gap: 28, alignItems: "center",
    }}>
      <div>
        <div style={{ display: "inline-flex", alignItems: "center", gap: 7, height: 26, padding: "0 11px", borderRadius: 999, background: "rgba(109,145,242,0.14)", border: "1px solid rgba(109,145,242,0.28)", fontSize: 11, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase", color: "#6D91F2" }}>
          <span style={{ width: 6, height: 6, borderRadius: 999, background: "#6D91F2" }} /> Lead system
        </div>
        <h3 style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(26px, 3vw, 30px)", fontWeight: 700, letterSpacing: "-0.025em", lineHeight: 1.1, margin: "18px 0 0", color: "var(--bm-text)" }}>{title}</h3>
        <p style={{ fontSize: 17, lineHeight: 1.55, color: "var(--bm-text-muted)", margin: "14px 0 0", maxWidth: "42ch" }}>{body}</p>
        {!demo && (
          <a href="#talk" onClick={(e) => { e.preventDefault(); scrollToTalk(); }} style={{ display: "inline-block", marginTop: 24, fontSize: 15, fontWeight: 600, color: "var(--bm-accent)", textDecoration: "none" }}>See it work →</a>
        )}
      </div>
      <div data-bm-lead-viz style={{ minHeight: 200, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 14, background: "rgba(0,3,34,0.4)", border: "1px solid var(--bm-hairline)", padding: 24 }}>
        {demo ? <VoicePlayer /> : bmViz(vizType)}
      </div>
    </div>
  );
}

function SupportCard({ title, body, vizType }) {
  const [hover, setHover] = useSecState(false);
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18, background: hover ? "#001161" : "#000B45", padding: 22,
        display: "flex", flexDirection: "column", gap: 14,
        transform: hover ? "translateY(-2px)" : "none",
        transition: "transform 200ms var(--bm-ease), border-color 200ms var(--bm-ease), background 200ms var(--bm-ease)",
      }}
    >
      <div style={{ height: 68, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,3,34,0.4)", border: "1px solid rgba(109,145,242,0.1)", padding: "12px 16px", overflow: "hidden" }}>
        {bmViz(vizType)}
      </div>
      <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 18, fontWeight: 600, letterSpacing: "-0.02em", lineHeight: 1.2, color: "var(--bm-text)" }}>{title}</div>
      <div style={{ fontSize: 14, lineHeight: 1.5, color: "var(--bm-text-muted)" }}>{body}</div>
    </div>
  );
}

/* Closer testimonial — a human closer on human vs AI setters. Lazy YouTube
   facade (poster + click-to-load) so the iframe never loads on first paint.
   Sits right after the hero: "here's the agent → here's the human vouching." */
function CloserProof() {
  const [playing, setPlaying] = useSecState(false);
  const VID = "aM8PIHUxNYo";
  return (
    <section data-screen-label="03 Closer" data-bm-section="mid" className="bm-section--ink" style={{ padding: "72px 32px" }}>
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div data-bm-stack="cols-2" style={{ display: "grid", gridTemplateColumns: "0.82fr 1.18fr", gap: 44, alignItems: "center" }}>
          <div>
            <div style={eyebrowStyle}>From the closer's chair</div>
            <h2 style={{ ...displayM, marginTop: 14 }}>We asked the closer if an AI setter made his job harder. Watch his answer.</h2>
            <p style={{ ...bodyM, marginTop: 16, maxWidth: 440 }}>
              Not our words. The closer who worked these booked calls — human setters vs the AI, unscripted.
            </p>
          </div>
          <div style={{ position: "relative", aspectRatio: "16 / 9", borderRadius: 18, overflow: "hidden", border: "1px solid var(--bm-hairline-strong)", background: "#000B45", boxShadow: "0 30px 80px -40px rgba(109,145,242,0.4)" }}>
            {playing ? (
              <iframe
                src={`https://www.youtube-nocookie.com/embed/${VID}?autoplay=1&rel=0&modestbranding=1`}
                title="The closer's experience — human vs AI setters"
                allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                allowFullScreen
                style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: 0 }}
              />
            ) : (
              <button
                onClick={() => setPlaying(true)}
                aria-label="Play the closer's testimonial"
                style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: "none", cursor: "pointer", padding: 0, background: "transparent", display: "flex", alignItems: "center", justifyContent: "center" }}
              >
                <img
                  src={`https://i.ytimg.com/vi/${VID}/maxresdefault.jpg`}
                  onError={(e) => { e.currentTarget.src = `https://i.ytimg.com/vi/${VID}/hqdefault.jpg`; }}
                  alt="" loading="lazy"
                  style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", opacity: 0.72 }}
                />
                <span style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse at center, rgba(0,3,34,0.15), rgba(0,3,34,0.55))" }} />
                <span style={{ position: "relative", display: "inline-flex", alignItems: "center", justifyContent: "center", width: 64, height: 64, borderRadius: 999, background: "var(--bm-accent)", color: "#00122E", boxShadow: "0 12px 40px -8px rgba(109,145,242,0.6)" }}>
                  <Icon name="play" size={26} color="currentColor" />
                </span>
              </button>
            )}
          </div>
        </div>
      </div>
    </section>
  );
}

/* Horizontal scroll-snap rail — one card-frame at a time, next one peeking,
   trackpad/touch drag + arrow buttons. Collapses dense card grids into a
   single scrollable row so the eye sees one thing and discovers it can scroll. */
function CardRail({ items, cardWidth = 300, render }) {
  const ref = useSecRef(null);
  const nudge = (dir) => {
    const el = ref.current;
    if (el) el.scrollBy({ left: dir * (cardWidth + 16), behavior: "smooth" });
  };
  return (
    <div style={{ position: "relative", marginTop: 16 }}>
      <div
        ref={ref}
        className="bm-rail"
        style={{
          display: "flex", gap: 16, overflowX: "auto", overflowY: "hidden",
          scrollSnapType: "x mandatory", paddingBottom: 14, WebkitOverflowScrolling: "touch",
        }}
      >
        {items.map((it, i) => (
          <div key={i} style={{ flex: `0 0 ${cardWidth}px`, scrollSnapAlign: "start" }}>
            {render(it)}
          </div>
        ))}
      </div>
      <div style={{ display: "flex", gap: 8, justifyContent: "flex-end", marginTop: 4 }}>
        {[-1, 1].map((d) => (
          <button
            key={d}
            onClick={() => nudge(d)}
            aria-label={d < 0 ? "Scroll left" : "Scroll right"}
            style={{
              width: 40, height: 40, borderRadius: 999, cursor: "pointer",
              background: "var(--bm-surface)", border: "1px solid var(--bm-hairline-strong)",
              color: "var(--bm-text)", display: "inline-flex", alignItems: "center", justifyContent: "center",
              transition: "background 160ms var(--bm-ease), border-color 160ms var(--bm-ease)",
            }}
            onMouseEnter={(e) => { e.currentTarget.style.background = "var(--bm-surface-2)"; e.currentTarget.style.borderColor = "var(--bm-accent)"; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = "var(--bm-surface)"; e.currentTarget.style.borderColor = "var(--bm-hairline-strong)"; }}
          >
            <Icon name={d < 0 ? "arrow-left" : "arrow-right"} size={18} color="currentColor" />
          </button>
        ))}
      </div>
    </div>
  );
}

/* Auto-scrolling case-study rail. Drifts left continuously; pauses on hover;
   ← → buttons jump one card so you can move faster. Native overflow-x scroll
   (NOT a width:max-content transform marquee) so card text wraps correctly.
   Items are duplicated once for a seamless infinite loop in both directions. */
function CaseRail({ items, cardWidth = 384, gap = 18 }) {
  const ref = useSecRef(null);
  const pausedRef = useSecRef(false);
  const inViewRef = useSecRef(false);
  useSecEffect(() => {
    const el = ref.current;
    if (!el) return;
    const reduce = typeof window !== "undefined" && window.matchMedia &&
      window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    // Only drift while the rail is on screen — so the first thing a visitor sees
    // when they reach the section is the start of the list (the live clients),
    // and it only begins sliding into the Tradacc builds once it's in view.
    let io;
    if (typeof IntersectionObserver !== "undefined") {
      io = new IntersectionObserver(([e]) => { inViewRef.current = e.isIntersecting; }, { threshold: 0.25 });
      io.observe(el);
    } else {
      inViewRef.current = true;
    }
    let raf;
    const step = () => {
      if (el) {
        const W = el.scrollWidth / 2; // width of one (un-duplicated) set
        if (!reduce && !pausedRef.current && inViewRef.current) el.scrollLeft += 0.6;
        // Right-edge wrap only — leftward looping is handled in nudge() so we
        // never oscillate at scrollLeft === 0 (browsers clamp it there).
        if (W > 0 && el.scrollLeft >= W) el.scrollLeft -= W;
      }
      raf = requestAnimationFrame(step);
    };
    raf = requestAnimationFrame(step);
    return () => { cancelAnimationFrame(raf); if (io) io.disconnect(); };
  }, []);
  const nudge = (dir) => {
    const el = ref.current;
    if (!el) return;
    const W = el.scrollWidth / 2;
    // Going left near the start? Jump one set forward first so there's room
    // to scroll left into the duplicated copy (seamless infinite-left).
    if (dir < 0 && W > 0 && el.scrollLeft < cardWidth + gap) el.scrollLeft += W;
    el.scrollBy({ left: dir * (cardWidth + gap), behavior: "smooth" });
  };
  const list = items.concat(items);
  return (
    <div
      style={{ position: "relative", marginTop: 36 }}
      onMouseEnter={() => { pausedRef.current = true; }}
      onMouseLeave={() => { pausedRef.current = false; }}
      onTouchStart={() => { pausedRef.current = true; }}
      onTouchEnd={() => { setTimeout(() => { pausedRef.current = false; }, 1200); }}
    >
      <div
        ref={ref}
        className="bm-no-scrollbar"
        style={{
          display: "flex", overflowX: "auto", overflowY: "hidden",
          WebkitOverflowScrolling: "touch",
          WebkitMaskImage: "linear-gradient(90deg, transparent, #000 3%, #000 97%, transparent)",
          maskImage: "linear-gradient(90deg, transparent, #000 3%, #000 97%, transparent)",
        }}
      >
        {list.map((c, i) => (
          <div key={i} data-bm-case-rail-item style={{ flex: `0 0 ${cardWidth}px`, width: cardWidth, minWidth: 0, marginRight: gap, display: "flex" }} aria-hidden={i >= items.length ? "true" : undefined}>
            <ProofCard {...c} />
          </div>
        ))}
      </div>
      {[-1, 1].map((d) => (
        <button
          key={d}
          data-bm-case-rail-arrow
          onClick={() => nudge(d)}
          aria-label={d < 0 ? "Previous case study" : "Next case study"}
          style={{
            position: "absolute", top: "50%", transform: "translateY(-50%)",
            [d < 0 ? "left" : "right"]: 8,
            width: 44, height: 44, borderRadius: 999, cursor: "pointer", zIndex: 2,
            background: "rgba(0,3,34,0.72)", border: "1px solid var(--bm-hairline-strong)",
            color: "var(--bm-text)", display: "inline-flex", alignItems: "center", justifyContent: "center",
            backdropFilter: "blur(4px)", WebkitBackdropFilter: "blur(4px)",
            transition: "background 160ms var(--bm-ease), border-color 160ms var(--bm-ease), color 160ms var(--bm-ease)",
          }}
          onMouseEnter={(e) => { e.currentTarget.style.background = "var(--bm-accent)"; e.currentTarget.style.color = "#00122E"; e.currentTarget.style.borderColor = "var(--bm-accent)"; }}
          onMouseLeave={(e) => { e.currentTarget.style.background = "rgba(0,3,34,0.72)"; e.currentTarget.style.color = "var(--bm-text)"; e.currentTarget.style.borderColor = "var(--bm-hairline-strong)"; }}
        >
          <Icon name={d < 0 ? "chevron-left" : "chevron-right"} size={20} color="currentColor" />
        </button>
      ))}
    </div>
  );
}

function FlagshipCard({ title, category, avatar, agentName, body, audio, transcript }) {
  const [hover, setHover]       = useSecState(false);
  const [isPlaying, setIsPlaying] = useSecState(false);
  const [progress, setProgress]  = useSecState(0);
  const audioRef = useSecRef(null);

  const catColor  = "var(--bm-accent)";
  const catBg     = "rgba(109,145,242,0.1)";
  const catBorder = "rgba(109,145,242,0.3)";
  const reduced  = bmReducedMotion();

  useSecEffect(() => {
    if (!audio || typeof Audio === "undefined") return;
    const a = new Audio(audio + "?v=1");
    a.preload = "none";
    audioRef.current = a;
    const onPlay  = () => setIsPlaying(true);
    const onPause = () => setIsPlaying(false);
    const onEnd   = () => { setIsPlaying(false); setProgress(0); };
    const onTime  = () => { if (a.duration) setProgress(a.currentTime / a.duration); };
    a.addEventListener("play",       onPlay);
    a.addEventListener("pause",      onPause);
    a.addEventListener("ended",      onEnd);
    a.addEventListener("timeupdate", onTime);
    const onOtherPlay = (e) => { if (e.detail !== audio) { try { a.pause(); } catch (_) {} } };
    window.addEventListener("bm:flagship-play", onOtherPlay);
    return () => {
      try { a.pause(); } catch (_) {}
      a.removeEventListener("play",       onPlay);
      a.removeEventListener("pause",      onPause);
      a.removeEventListener("ended",      onEnd);
      a.removeEventListener("timeupdate", onTime);
      window.removeEventListener("bm:flagship-play", onOtherPlay);
    };
  }, []);

  const togglePlay = () => {
    const a = audioRef.current;
    if (!a) return;
    if (!a.paused) { a.pause(); return; }
    window.dispatchEvent(new CustomEvent("bm:flagship-play", { detail: audio }));
    const p = a.play();
    if (p && p.catch) p.catch(() => {});
  };

  const speaking = isPlaying || hover;

  const captions = React.useMemo(() => bmCaptionChunks(transcript), [transcript]);
  const capIdx = captions.length
    ? Math.min(captions.length - 1, Math.floor(progress * captions.length))
    : 0;

  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        border: `1px solid ${(hover || isPlaying) ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18,
        background: "linear-gradient(135deg, rgba(109,145,242,0.14), rgba(0,11,69,0.35) 55%), #000B45",
        padding: 26, display: "flex", flexDirection: "column", gap: 16,
        transform: (hover || isPlaying) ? "translateY(-3px)" : "none",
        transition: "transform 200ms var(--bm-ease), border-color 200ms var(--bm-ease)",
      }}
    >
      {/* Category badge */}
      <div style={{
        alignSelf: "flex-start",
        fontSize: 10, fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase",
        color: catColor, padding: "4px 10px", borderRadius: 999,
        border: `1px solid ${catBorder}`, background: catBg,
      }}>
        {category}
      </div>

      {/* Avatar + play panel */}
      <div style={{
        display: "flex", flexDirection: "column", alignItems: "center", gap: 10,
        padding: "20px 0 16px",
        borderRadius: 12,
        background: "rgba(0,3,34,0.4)",
        border: "1px solid rgba(109,145,242,0.10)",
      }}>
        <VoiceAvatar speaking={speaking} avatarSrc={avatar} />
        {/* Caption — between photo and name; fixed-height slot so the card never resizes */}
        <div aria-live="polite" style={{
          height: 20, width: "100%", padding: "0 6px", boxSizing: "border-box",
          display: "flex", alignItems: "center", justifyContent: "center", overflow: "hidden",
        }}>
          {isPlaying && transcript && captions.length > 0 && (
            <span key={capIdx} style={{
              maxWidth: "100%", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
              fontSize: 12.5, lineHeight: "20px", textAlign: "center",
              color: "var(--bm-accent)", fontFamily: "var(--bm-font-body)", letterSpacing: "0.01em",
              animation: reduced ? "none" : "bm-fade-in 200ms ease-out both",
            }}>
              {captions[capIdx]}
            </span>
          )}
        </div>
        <div style={{ textAlign: "center" }}>
          <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 17, fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)" }}>
            {agentName}
          </div>
          <div style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-accent)", marginTop: 4 }}>
            AI Agent
          </div>
        </div>
        <SoundWave active={speaking} />
        {audio && (
          <button
            onClick={togglePlay}
            aria-label={isPlaying ? `Pause ${agentName}` : `Hear ${agentName}’s introduction`}
            style={{
              marginTop: 4,
              display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 7,
              cursor: "pointer",
              border: "1px solid var(--bm-accent)",
              borderRadius: 999,
              padding: "8px 18px",
              minHeight: 36, minWidth: 100,
              background: isPlaying ? "rgba(109,145,242,0.20)" : "rgba(109,145,242,0.06)",
              fontFamily: "var(--bm-font-body)", fontSize: 12, fontWeight: 700,
              color: "var(--bm-accent)", letterSpacing: "0.06em", textTransform: "uppercase",
              transition: reduced ? "none" : "background 200ms var(--bm-ease)",
            }}
          >
            {isPlaying ? (
              <>
                <span aria-hidden="true" style={{
                  display: "inline-block", width: 8, height: 8, borderRadius: 2,
                  background: "currentColor", boxShadow: "5px 0 0 currentColor", flex: "none",
                }} />
                Pause
              </>
            ) : (
              <>
                <span aria-hidden="true" style={{
                  display: "inline-block", width: 0, height: 0,
                  borderTop: "5px solid transparent",
                  borderBottom: "5px solid transparent",
                  borderLeft: "9px solid currentColor",
                  flex: "none",
                }} />
                Hear {agentName}
              </>
            )}
          </button>
        )}
      </div>

      <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 20, fontWeight: 700, letterSpacing: "-0.02em", lineHeight: 1.15, color: "var(--bm-text)" }}>
        {title}
      </div>


      <p style={{ fontSize: 14.5, lineHeight: 1.55, color: "var(--bm-text-muted)", flex: 1, margin: 0 }}>{body}</p>
    </div>
  );
}

function CatalogItem({ title, body, viz, channels }) {
  const [hover, setHover] = useSecState(false);
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 16, background: hover ? "#001161" : "#000B45", padding: "18px 18px 20px",
        display: "flex", flexDirection: "column", gap: 12,
        transform: hover ? "translateY(-2px)" : "none",
        transition: "transform 200ms var(--bm-ease), border-color 200ms var(--bm-ease), background 200ms var(--bm-ease)",
      }}
    >
      {viz && (
        <div style={{ height: 60, display: "flex", alignItems: "center", justifyContent: "center",
          borderRadius: 10, background: "rgba(0,3,34,0.4)", border: "1px solid rgba(109,145,242,0.10)",
          overflow: "hidden", padding: "8px 12px" }}>
          {bmViz(viz)}
        </div>
      )}
      <div style={{ fontSize: 15, fontWeight: 600, color: "var(--bm-text)", letterSpacing: "-0.01em", lineHeight: 1.25 }}>
        {title}
      </div>
      <div style={{ fontSize: 13, lineHeight: 1.5, color: "var(--bm-text-muted)" }}>{body}</div>
      {channels && channels.length > 0 && (
        <div style={{ display: "flex", gap: 6, marginTop: 2 }}>
          {channels.map((ch) => (
            <span key={ch} style={{
              display: "inline-flex", alignItems: "center", gap: 5,
              fontSize: 10.5, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase",
              color: "var(--bm-accent)", background: "rgba(109,145,242,0.10)",
              border: "1px solid rgba(109,145,242,0.22)", borderRadius: 999, padding: "3px 9px",
            }}>
              <Icon name={ch === "voice" ? "phone" : "message-square"} size={11} color="currentColor" />
              {ch === "voice" ? "Voice" : "Text"}
            </span>
          ))}
        </div>
      )}
    </div>
  );
}

function WhatWeBuild() {
  const flagships = [
    {
      title: "AI Voice Agent",
      category: "SALES",
      avatar: "/assets/emma-avatar.png?v=2",
      agentName: "Emma",
      body: "Calls or texts, qualifies, and books your pipeline all day, every business day — outbound and inbound, end to end.",
      audio: "/assets/audio/emma-card.mp3",
      transcript: "Hi, I'm Emma — I call, qualify, and book your leads, so your calendar stays full. Look — say a lead comes in at midnight: I call within a minute, make sure they're a fit, and drop them right onto a closer's calendar. So… honestly, think back on last month for a second — how many of those leads never got a call back?",
    },
    {
      title: "AI Performance Manager",
      category: "PERFORMANCE",
      avatar: "/assets/marcus-avatar.png?v=2",
      agentName: "Marcus",
      body: "Every call scored and coached back — sales or coaching. The 100% review a human manager never has time for.",
      audio: "/assets/audio/marcus-card.mp3",
      transcript: "I'm Marcus. The best teams get better by coaching every call — but let's be honest, no manager has time to sit through all of them, so most just never get heard. Sales calls, coaching calls — I score a hundred percent of them against your playbook, and I coach the fix. So… let me ask you something — what's really happening on the calls nobody's listening to?",
    },
    {
      title: "AI Q&A Clone",
      category: "DELIVERY",
      avatar: "/assets/coach-avatar.png?v=2",
      agentName: "Leo",
      body: "Your expertise answers every client 24/7, inside your portal — delivery that doesn't need you on the call.",
      audio: "/assets/audio/leo-card.mp3",
      transcript: "I'm Leo. Here's the thing — a lot of what your clients ask, it's already in your program. They just don't want to wait for the weekly call. So I answer those the moment they come in, any hour, in your voice — which means your live time goes to the coaching only you can give. So let me ask you — how much of your week, really, goes to questions you've already answered?",
    },
  ];
  const catalog = [
    { title: "Speed-to-Lead",          body: "Every new lead called in seconds, before a competitor gets there.",         viz: "ring",      category: "Sales", channels: ["voice", "text"] },
    { title: "Lead Scoring",           body: "One objective read on every lead — no more \"these leads are junk.\"",      viz: "qc",        category: "Sales" },
    { title: "Dead-Lead Reactivation", body: "Revenue from leads already in your CRM, not more ad spend.",               viz: "revive",    category: "Sales", channels: ["voice", "text"] },
    { title: "No-Show Recovery",       body: "Missed calls re-booked automatically, before the slot is lost.",           viz: "calendar",  category: "Sales", channels: ["voice", "text"] },
    { title: "Inbound Call Handling",  body: "Every inbound answered and qualified, none sent to voicemail.",            viz: "inbound",   category: "Sales", channels: ["voice"] },
    { title: "Post-Call Follow-Up",    body: "No closed-lost lead goes dark.",                                           viz: "warm",      category: "Sales", channels: ["voice", "text"] },
    { title: "Form-Feedback Drafts",   body: "Coach feedback drafted in seconds, approved in one click.",                viz: "draft",     category: "Delivery" },
    { title: "Program Generation",     body: "Personalized programs from each client's data.",                           viz: "program",   category: "Delivery" },
    { title: "Coaching QC",            body: "Your 40th coach delivers like your first.",                                viz: "qc",        category: "Delivery" },
    { title: "Content Engine",         body: "One recording becomes a week of content.",                                 viz: "fanout",    category: "Marketing" },
    { title: "Email Engine",           body: "Sequences that took weeks, live in hours.",                                viz: "pipeline",  category: "Marketing" },
    { title: "Reporting & Onboarding", body: "The admin that eats your team's week, on autopilot.",                     viz: "dashboard", category: "Operations" },
    { title: "Custom Apps & Dashboards", body: "The numbers that matter, in one place, real time.",                     viz: "spark",     category: "Operations" },
  ];
  const [catalogOpen, setCatalogOpen] = useSecState(false);
  return (
    <section
      id="what"
      data-screen-label="03 What We Build"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{ position: "relative", padding: "112px 32px 112px", overflow: "hidden" }}
    >
      <BlueprintGrid />
      <div style={{ position: "relative", maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>What we build</div>
        <h2 style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(28px, 3.4vw, 40px)", fontWeight: 700, letterSpacing: "-0.025em", lineHeight: 1.08, color: "var(--bm-text)", margin: "14px 0 0", maxWidth: "none" }}>
          The three AI agents most businesses start with.
        </h2>
        <p style={{ ...bodyM, marginTop: 18, maxWidth: 640 }}>
          One fills your pipeline, one scores and coaches every call, one answers your clients — the three jobs every business needs first.
        </p>
        <p style={{ ...bodyM, marginTop: 14, maxWidth: 640, color: "var(--bm-text-muted)" }}>
          No new tool for your team to learn, no dashboard to babysit. We build it on the stack you already run — and we run it for you.
        </p>

        <div style={{ marginTop: 22, display: "inline-flex", alignItems: "center", gap: 12 }}>
          <img src="/assets/ruben-profile.png" alt="Ruben Davoli" loading="lazy" style={{ width: 46, height: 46, borderRadius: "50%", objectFit: "cover", border: "1px solid var(--bm-hairline-strong)", flex: "none" }} />
          <div>
            <div style={{ fontSize: 14, fontWeight: 700, color: "var(--bm-text)", letterSpacing: "-0.01em" }}>Ruben Davoli</div>
            <div style={{ fontSize: 12.5, color: "var(--bm-text-muted)", marginTop: 1 }}>Founder · built &amp; exited a $3M coaching company</div>
          </div>
        </div>

        <div data-bm-stack="cols-3" style={{ marginTop: 44, display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 18, alignItems: "stretch" }}>
          {flagships.map((f) => <FlagshipCard key={f.title} {...f} />)}
        </div>

        <div style={{ marginTop: 44, display: "flex", alignItems: "center", gap: 16, flexWrap: "wrap" }}>
          <button
            data-bm-catalog-trigger
            onClick={() => setCatalogOpen(true)}
            style={{
              display: "inline-flex", alignItems: "center", gap: 10, cursor: "pointer",
              background: "var(--bm-surface)", border: "1px solid var(--bm-hairline-strong)",
              borderRadius: 999, padding: "12px 20px",
              fontFamily: "var(--bm-font-body)", fontSize: 14.5, fontWeight: 600, color: "var(--bm-text)",
              transition: "background 160ms var(--bm-ease), border-color 160ms var(--bm-ease)",
            }}
            onMouseEnter={(e) => { e.currentTarget.style.background = "var(--bm-surface-2)"; e.currentTarget.style.borderColor = "var(--bm-accent)"; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = "var(--bm-surface)"; e.currentTarget.style.borderColor = "var(--bm-hairline-strong)"; }}
          >
            <Icon name="layout-grid" size={16} color="var(--bm-accent)" />
            See everything else we build
            <Icon name="arrow-right" size={16} color="var(--bm-accent)" />
          </button>
          <span style={{ fontSize: 13, color: "var(--bm-text-muted)" }}>We have more in the catalog — and we'll build custom, as long as it makes a process you've already proven earn more or take less time.</span>
        </div>

        <CatalogModal open={catalogOpen} onClose={() => setCatalogOpen(false)} catalog={catalog} />
      </div>
    </section>
  );
}

/* Catalog pop-up — the full system catalog with category filter tabs, opened
   from the slim "See everything else we build" button so the section stays lean. */
function CatalogModal({ open, onClose, catalog }) {
  const [activeTab, setActiveTab] = useSecState("All");
  useSecEffect(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    document.addEventListener("keydown", onKey);
    const prev = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = prev; };
  }, [open]);
  if (!open) return null;
  const tabs = ["All", "Sales", "Marketing", "Delivery", "Operations"];
  const filtered = activeTab === "All" ? catalog : catalog.filter((c) => c.category === activeTab);
  return (
    <div
      onClick={onClose}
      className="bm-section--ink"
      style={{
        position: "fixed", inset: 0, zIndex: 1000,
        background: "rgba(0,3,34,0.74)", backdropFilter: "blur(6px)", WebkitBackdropFilter: "blur(6px)",
        display: "flex", alignItems: "flex-start", justifyContent: "center",
        padding: "6vh 20px 40px", overflowY: "auto",
      }}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        style={{
          width: "100%", maxWidth: 1040, background: "#00071f",
          border: "1px solid var(--bm-hairline-strong)", borderRadius: 20,
          padding: "26px 28px 32px", boxShadow: "0 40px 120px -30px rgba(0,0,0,0.7)",
        }}
      >
        <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: 16 }}>
          <div>
            <div style={eyebrowStyle}>The full catalog</div>
            <div style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(22px, 2.6vw, 30px)", fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)", marginTop: 10 }}>
              Everything else we build.
            </div>
          </div>
          <button onClick={onClose} aria-label="Close" style={{
            flex: "none", width: 44, height: 44, borderRadius: 999, cursor: "pointer",
            background: "var(--bm-surface)", border: "1px solid var(--bm-hairline-strong)",
            display: "flex", alignItems: "center", justifyContent: "center", color: "var(--bm-text)",
          }}>
            <Icon name="x" size={18} color="currentColor" />
          </button>
        </div>

        <div style={{ marginTop: 22, display: "inline-flex", flexWrap: "wrap", gap: 6, background: "rgba(0,3,34,0.5)", border: "1px solid var(--bm-hairline)", borderRadius: 999, padding: 4 }}>
          {tabs.map((tab) => (
            <button key={tab} data-bm-catalog-tab onClick={() => setActiveTab(tab)} style={{
              cursor: "pointer", border: "none", borderRadius: 999, padding: "6px 14px",
              fontFamily: "var(--bm-font-body)", fontSize: 12, fontWeight: 700,
              background: activeTab === tab ? "var(--bm-accent)" : "transparent",
              color: activeTab === tab ? "#00122E" : "var(--bm-text-muted)",
              transition: "background 140ms var(--bm-ease), color 140ms var(--bm-ease)",
            }}>{tab}</button>
          ))}
        </div>

        <div style={{ display: "flex", alignItems: "center", gap: 14, marginTop: 12, fontSize: 11.5, color: "var(--bm-text-muted)" }}>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
            <Icon name="phone" size={12} color="var(--bm-accent)" /> Voice
          </span>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
            <Icon name="message-square" size={12} color="var(--bm-accent)" /> Text
          </span>
          <span>— channels each agent can run on</span>
        </div>
        <div data-bm-stack="cols-2" style={{ marginTop: 22, display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 14 }}>
          {filtered.map((c) => <CatalogItem key={c.title} {...c} />)}
        </div>
      </div>
    </div>
  );
}

/* One-line system row that expands to a sentence of detail. */
function ExpandableRow({ title, detail, isOpen, onToggle, last }) {
  const [hover, setHover] = useSecState(false);
  return (
    <div style={{ borderBottom: last ? "none" : "1px solid var(--bm-hairline)" }}>
      <button
        onClick={onToggle}
        aria-expanded={isOpen}
        onMouseEnter={() => setHover(true)}
        onMouseLeave={() => setHover(false)}
        style={{
          width: "100%", textAlign: "left", cursor: "pointer",
          display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16,
          padding: "20px 24px", border: "none",
          background: hover || isOpen ? "var(--bm-surface-2)" : "transparent",
          color: "var(--bm-text)",
          transition: "background var(--bm-dur-btn) var(--bm-ease)",
        }}
      >
        <span style={{ display: "inline-flex", alignItems: "center", gap: 14, minWidth: 0 }}>
          <span style={{ width: 6, height: 6, borderRadius: 999, background: "var(--bm-accent)", flexShrink: 0 }} />
          <span style={{ fontSize: 16, fontWeight: 600, lineHeight: 1.3 }}>{title}</span>
        </span>
        <Icon name="chevron-down" size={18} color="var(--bm-text-muted)"
          style={{ flexShrink: 0, transform: isOpen ? "rotate(180deg)" : "none", transition: "transform var(--bm-dur-card) var(--bm-ease)" }} />
      </button>
      {isOpen && (
        <div style={{ padding: "0 24px 20px 44px", animation: "bm-line-in 240ms var(--bm-ease) both" }}>
          <p style={{ ...bodyM, fontSize: 15, maxWidth: 760 }}>{detail}</p>
        </div>
      )}
    </div>
  );
}

function BuildCard({ icon, title, body, tail }) {
  const [hover, setHover] = useSecState(false);
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        background: hover ? "var(--bm-surface-2)" : "var(--bm-surface)",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18,
        padding: 32,
        transition: "background 220ms var(--bm-ease-standard), border-color 220ms var(--bm-ease-standard)",
        display: "flex",
        flexDirection: "column",
        gap: 16,
        /* Grid stretch keeps both cards the same height; no forced minHeight
           padding the body to a large extra gap above the divider. */
      }}
    >
      <div
        style={{
          width: 48, height: 48, borderRadius: 12,
          background: "rgba(109,145,242,0.12)",
          border: "1px solid rgba(109,145,242,0.28)",
          display: "flex", alignItems: "center", justifyContent: "center",
        }}
      >
        <Icon name={icon} size={22} color="var(--bm-accent)" />
      </div>
      <div
        style={{
          fontFamily: "var(--bm-font-display)",
          fontSize: 26, fontWeight: 700, letterSpacing: "-0.02em",
          lineHeight: 1.15,
          color: "var(--bm-text)",
        }}
      >
        {title}
      </div>
      <div style={{ fontSize: 15, lineHeight: 1.6, color: "var(--bm-text-muted)", flex: 1 }}>
        {body}
      </div>
      <div
        style={{
          fontSize: 14,
          lineHeight: 1.5,
          color: "var(--bm-text)",
          paddingTop: 10,
          marginTop: 2,
          borderTop: "1px solid var(--bm-hairline)",
        }}
      >
        {tail}
      </div>
    </div>
  );
}

/* Featured variant — larger, full-width, with a "Use cases" pill row. */
function FeaturedBuildCard({ icon, eyebrow, title, body, tail, useCases }) {
  const [hover, setHover] = useSecState(false);
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      data-bm-featured-card
      style={{
        background: hover ? "var(--bm-surface-2)" : "var(--bm-surface)",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 22,
        padding: "40px 44px",
        transition: "background 220ms var(--bm-ease-standard), border-color 220ms var(--bm-ease-standard)",
        display: "grid",
        gridTemplateColumns: "1.1fr 1fr",
        gap: 48,
        alignItems: "center",
        position: "relative",
        overflow: "hidden",
        boxShadow: "0 40px 100px -50px rgba(109,145,242,0.35)",
      }}
    >
      {/* soft accent glow, top-right */}
      <div aria-hidden style={{
        position: "absolute",
        inset: 0,
        pointerEvents: "none",
        background:
          "radial-gradient(ellipse 60% 70% at 100% 0%, rgba(109,145,242,0.10), rgba(0,3,34,0) 70%)",
      }} />

      <div style={{ position: "relative", display: "flex", flexDirection: "column", gap: 18 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
          <div
            style={{
              width: 56, height: 56, borderRadius: 14,
              background: "rgba(109,145,242,0.14)",
              border: "1px solid rgba(109,145,242,0.32)",
              display: "flex", alignItems: "center", justifyContent: "center",
              flexShrink: 0,
            }}
          >
            <Icon name={icon} size={26} color="var(--bm-accent)" />
          </div>
          {eyebrow && (
            <span style={{
              fontSize: 11,
              fontWeight: 600,
              letterSpacing: "0.16em",
              textTransform: "uppercase",
              color: "var(--bm-accent)",
              padding: "6px 12px",
              borderRadius: 999,
              background: "rgba(109,145,242,0.12)",
              border: "1px solid rgba(109,145,242,0.28)",
              lineHeight: 1,
            }}>
              {eyebrow}
            </span>
          )}
        </div>
        <div
          style={{
            fontFamily: "var(--bm-font-display)",
            fontSize: "clamp(30px, 3.2vw, 40px)",
            fontWeight: 700,
            letterSpacing: "-0.02em",
            lineHeight: 1.1,
            color: "var(--bm-text)",
          }}
        >
          {title}
        </div>
        <div style={{ fontSize: 17, lineHeight: 1.55, color: "var(--bm-text-muted)" }}>
          {body}
        </div>
        <div
          style={{
            fontSize: 14,
            lineHeight: 1.5,
            color: "var(--bm-text)",
            paddingTop: 18,
            borderTop: "1px solid var(--bm-hairline)",
            fontWeight: 500,
          }}
        >
          {tail}
        </div>
      </div>

      {/* Use cases list — right column on desktop */}
      <div
        data-bm-featured-usecases
        style={{
          position: "relative",
          background: "rgba(0,11,69,0.45)",
          border: "1px solid var(--bm-hairline)",
          borderRadius: 16,
          padding: "24px 24px",
          display: "flex",
          flexDirection: "column",
          gap: 14,
        }}
      >
        <div style={{
          fontSize: 11,
          fontWeight: 600,
          letterSpacing: "0.16em",
          textTransform: "uppercase",
          color: "var(--bm-text-muted)",
        }}>
          Use Cases
        </div>
        <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 10 }}>
          {useCases.map((uc) => (
            <li key={uc} style={{
              display: "flex",
              alignItems: "center",
              gap: 12,
              fontSize: 15,
              lineHeight: 1.4,
              color: "var(--bm-text)",
            }}>
              <Icon name="check" size={16} color="var(--bm-accent)" />
              <span>{uc}</span>
            </li>
          ))}
        </ul>
      </div>
    </div>
  );
}

/* ------------------------------------------------------------------
   4.5. Voice Library — three real demo calls, clipped from YouTube.
   Ruben plays the prospect in each clip; the agent runs unedited.
   Each card is a lazy YouTube facade (thumbnail -> click -> clipped
   autoplay embed via ?start=&end=). Only one plays at a time —
   switching the active key unmounts the previous iframe, stopping it.
------------------------------------------------------------------ */
function VoiceLibrary() {
  const CLIPS = [
    {
      key: "rebecca", vid: "eVRu_GAgvXM",
      start: 119, end: 428, dur: "5:09",
      tag: "Speed-to-Lead",
      name: "Rebecca",
      sub: "Speed-to-Lead Agent",
      desc: "Calls within 60 seconds of opt-in. Qualifies, handles a curveball answer, and books — unedited.",
    },
    {
      key: "jessica", vid: "cJ731F84QMw",
      start: 184, end: 447, dur: "4:23",
      tag: "Appointment Setting",
      name: "Jessica",
      sub: "Appointment Setter",
      desc: "Runs the Hormozi BAND framework start to finish — budget, authority, need, timing. Books only when all four are met.",
    },
    {
      key: "kate", vid: "HNuMUeW2jhQ",
      start: 655, end: 818, dur: "2:43",
      tag: "Call Confirmation",
      name: "Kate",
      sub: "No-Show Recovery Agent",
      desc: "References the application answers, adds a pre-call bonus, and locks attendance with urgency. Two minutes, one clean close.",
    },
  ];

  const [playing, setPlaying] = useSecState(null);
  const MINT = "#5FE2B0";

  return (
    <section
      data-screen-label="04b Voice Library"
      data-bm-section="mid"
      className="bm-section--slate"
      style={{ padding: "96px 32px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Live demos</div>
        <h2 style={{ ...displayM, marginTop: 14, maxWidth: 560 }}>
          Watch the agent on a real call.
        </h2>
        <p style={{ ...bodyM, marginTop: 16, maxWidth: 560 }}>
          Ruben plays the prospect in each clip. The agent runs unedited — three use cases, three different call types.
        </p>

        <div data-bm-stack="cols-3" style={{ marginTop: 44, display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 18, alignItems: "stretch" }}>
          {CLIPS.map((clip) => {
            const isPlaying = playing === clip.key;
            return (
              <div
                key={clip.key}
                style={{
                  background: isPlaying
                    ? "linear-gradient(145deg, rgba(95,226,176,0.07), rgba(0,11,69,0.6))"
                    : "#000B45",
                  border: `1px solid ${isPlaying ? "rgba(95,226,176,0.4)" : "var(--bm-hairline)"}`,
                  borderRadius: 18,
                  padding: 16,
                  display: "flex", flexDirection: "column", gap: 14,
                  transition: "border-color 220ms var(--bm-ease), background 220ms var(--bm-ease)",
                }}
              >
                {/* 16:9 video — lazy facade until clicked */}
                <div style={{ position: "relative", aspectRatio: "16 / 9", borderRadius: 12, overflow: "hidden", border: "1px solid var(--bm-hairline-strong)", background: "#000B45" }}>
                  {isPlaying ? (
                    <iframe
                      src={`https://www.youtube-nocookie.com/embed/${clip.vid}?start=${clip.start}&end=${clip.end}&autoplay=1&rel=0&modestbranding=1`}
                      title={`${clip.name} — ${clip.tag} demo call`}
                      allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                      allowFullScreen
                      style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: 0 }}
                    />
                  ) : (
                    <button
                      onClick={() => setPlaying(clip.key)}
                      aria-label={`Play ${clip.name}'s call`}
                      style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: "none", cursor: "pointer", padding: 0, background: "transparent", display: "flex", alignItems: "center", justifyContent: "center" }}
                    >
                      <img
                        src={`https://i.ytimg.com/vi/${clip.vid}/maxresdefault.jpg`}
                        onError={(e) => { e.currentTarget.src = `https://i.ytimg.com/vi/${clip.vid}/hqdefault.jpg`; }}
                        alt="" loading="lazy"
                        style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", opacity: 0.72 }}
                      />
                      <span style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse at center, rgba(0,3,34,0.15), rgba(0,3,34,0.6))" }} />
                      <span style={{ position: "relative", display: "inline-flex", alignItems: "center", justifyContent: "center", width: 52, height: 52, borderRadius: 999, background: "var(--bm-accent)", color: "#00122E", boxShadow: "0 12px 40px -8px rgba(109,145,242,0.6)" }}>
                        <Icon name="play" size={22} color="currentColor" />
                      </span>
                      <span style={{ position: "absolute", bottom: 8, right: 8, fontSize: 11, fontWeight: 700, letterSpacing: "0.02em", color: "var(--bm-text)", background: "rgba(0,3,34,0.72)", border: "1px solid var(--bm-hairline-strong)", padding: "3px 8px", borderRadius: 999, backdropFilter: "blur(4px)", WebkitBackdropFilter: "blur(4px)" }}>
                        {clip.dur}
                      </span>
                    </button>
                  )}
                </div>

                {/* Tag */}
                <div style={{
                  alignSelf: "flex-start",
                  fontSize: 10, fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase",
                  color: isPlaying ? MINT : "var(--bm-accent)",
                  padding: "4px 10px", borderRadius: 999,
                  border: `1px solid ${isPlaying ? "rgba(95,226,176,0.3)" : "rgba(109,145,242,0.25)"}`,
                  background: isPlaying ? "rgba(95,226,176,0.06)" : "rgba(109,145,242,0.06)",
                  transition: "color 220ms, border-color 220ms, background 220ms",
                }}>
                  {clip.tag}
                </div>

                {/* Name + subtitle */}
                <div>
                  <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 22, fontWeight: 700, letterSpacing: "-0.025em", lineHeight: 1.1, color: "var(--bm-text)" }}>
                    {clip.name}
                  </div>
                  <div style={{ fontSize: 11.5, color: "var(--bm-text-muted)", marginTop: 4, letterSpacing: "0.02em" }}>
                    {clip.sub}
                  </div>
                </div>

                {/* Description */}
                <p style={{ fontSize: 13.5, lineHeight: 1.55, color: "var(--bm-text-muted)", margin: 0, flex: 1 }}>
                  {clip.desc}
                </p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

/* ------------------------------------------------------------------
   5. Case Studies — two-tier band
   SENSITIVITY: no client revenue / scale / headcount / at-risk counts.
   MovesMethod leads with throughput + low cost + quality.
------------------------------------------------------------------ */
function CaseStudies() {
  /* Each card carries a clear before → after. Live clients link to /work/<slug>;
     Tradacc systems link to the existing /case-studies/<slug> pages. */
  const clients = [
    {
      name: "MovesMethod", logo: "/assets/clients/movesmethod.png?v=2", logoH: 32,
      pic: "/assets/clients/movesmethod-screenshot.png",
      tag: "Coaching · delivery QC", href: "/work/movesmethod",
      line: "Every morning, it flags the clients about to churn and the coaches drifting from the method — before it costs a renewal.",
      ba: [
        { label: "Interactions reviewed", before: "A sample, by hand", after: "Every one" },
        { label: "At-risk clients caught", before: "After they churn", after: "Same day", tone: "good" },
        { label: "Cost each", before: "Coach time", after: "$0.15", tone: "good" },
      ],
    },
    {
      name: "Five50 Advisory", logo: "/assets/clients/five50.png", logoH: 24,
      pic: "/assets/clients/five50-screenshot.png",
      tag: "Consulting · outbound voice", href: "/work/five50-advisory",
      line: "The all-day job of calling leads and following up — now one agent that works the entire list, every business day.",
      ba: [
        { label: "Cost per call", before: "$1", after: "$0.04", tone: "good" },
        { label: "Manual follow-up", before: "A person's day", after: "Automated", tone: "good" },
        { label: "Coverage", before: "When a rep was free", after: "Every business day" },
      ],
    },
    {
      name: "Dr Andrea Grandi", logo: "/assets/clients/andrea-grandi.png", logoH: 28,
      pic: "/assets/clients/andrea-grandi-screenshot.png",
      tag: "Accelerator · AI sales system", href: "/work/andrea-grandi",
      line: "We replaced a tangle of disconnected tools with one AI-run sales system — new website included.",
      ba: [
        { label: "Email open rate", before: "30%", after: "60%", tone: "good" },
        { label: "Calls reviewed", before: "10%", after: "100%", tone: "good" },
        { label: "Sales stack", before: "Several tools", after: "One system", tone: "good" },
      ],
    },
  ];
  const tradacc = [
    {
      name: "Tradacc", logo: "/assets/clients/tradacc.png", logoH: 20,
      tag: "Sales · Voice", href: "/case-studies/ai-voice-agent",
      vid: "hXljA_sSljY", vidStart: 30,
      line: "AI Voice Agent — dead-lead reactivation, end to end.",
      ba: [
        { label: "Cost per booked call", before: "$200", after: "$20", tone: "good" },
        { label: "From $457 ad spend", before: "a dead list", after: "$6,800", tone: "good" },
        { label: "Appointments", before: "0", after: "22 in 15 days", tone: "good" },
      ],
    },
    {
      name: "Tradacc", logo: "/assets/clients/tradacc.png", logoH: 20,
      tag: "Sales · Email", href: "/case-studies/ai-email-engine",
      vid: "OXIF45DNZQU", vidStart: 20,
      line: "AI Email Engine — one webinar follow-up sequence.",
      ba: [
        { label: "Build time", before: "20–30 hrs", after: "4 hrs", tone: "good" },
        { label: "Revenue", before: "one sequence", after: "$85,532 / 30 days", tone: "good" },
      ],
    },
    {
      name: "Tradacc", logo: "/assets/clients/tradacc.png", logoH: 20,
      tag: "Operations · Content", href: "/case-studies/content-repurposing",
      vid: "U6qiJbdq6Gw", vidStart: 20,
      line: "Content Repurposing Engine — one video becomes a week of content.",
      ba: [
        { label: "Monthly cost", before: "$3,000", after: "$60", tone: "good" },
        { label: "Team time", before: "40 hrs/mo", after: "6 hrs/mo", tone: "good" },
      ],
    },
    {
      name: "Tradacc", logo: "/assets/clients/tradacc.png", logoH: 20,
      tag: "Delivery · Coaching", href: "/case-studies/ai-qa-clone",
      vid: "wD6k3140R7k", vidStart: 20,
      line: "AI Q&A Clone — the coach's expertise, cloned into the portal.",
      ba: [
        { label: "Member answers", before: "Weekly Q&A call", after: "24/7", tone: "good" },
        { label: "Answer quality", before: "—", after: "9 / 10", tone: "good" },
      ],
    },
  ];
  /* One unified set — every card is a case study. Some are paying clients,
     some are internal builds from Tradacc. Rendered in an auto-scrolling rail
     (uniform card size) so they read as one body of proof. */
  const all = clients.concat(tradacc);
  return (
    <section
      id="results"
      data-screen-label="04 Results"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{ padding: "104px 32px", overflow: "hidden" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Proof, not pitch</div>
        <h2 className="bm-reveal" style={{ ...displayM, marginTop: 16, maxWidth: 860 }}>
          Every number from a live CRM or real P&amp;L.
        </h2>
        <p className="bm-reveal" style={{ ...bodyM, marginTop: 18, maxWidth: 720 }}>
          Every card is a real case study. Some are paying clients; some are internal builds from Tradacc — Ruben's $3M education company, where each system was proven on a real P&amp;L before it ever shipped to a client.
        </p>
      </div>

      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto", padding: "0 0px" }}>
        <CaseRail items={all} />
      </div>
    </section>
  );
}

/* Unified proof card with a before → after block. Used for both live clients
   and Tradacc systems. Tradacc cards carry an optional `vid` prop — rendered
   as a static YouTube thumbnail (maxresdefault → hqdefault fallback) at the
   top of the card. Fast, no JS polling, works on both ink and paper sections.
   All background colors use CSS vars so the card adapts when the parent
   section switches to .bm-section--paper. Logo is wrapped in a dark pill so
   white-on-transparent logos remain visible on cream backgrounds. */
function ProofCard({ name, initials, logo, logoH, tag, line, ba, href, vid, pic }) {
  const [hover, setHover] = useSecState(false);
  const thumbSrc = pic || (vid ? `https://i.ytimg.com/vi/${vid}/maxresdefault.jpg` : null);
  const thumbFallback = vid ? `https://i.ytimg.com/vi/${vid}/hqdefault.jpg` : null;
  return (
    <a
      href={href}
      className="bm-reveal"
      data-bm-case-card
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        width: "100%", minWidth: 0, boxSizing: "border-box", whiteSpace: "normal",
        background: hover ? "var(--bm-surface-2)" : "var(--bm-surface)",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18, padding: 24, minHeight: 300,
        display: "flex", flexDirection: "column", gap: 14, textDecoration: "none",
        transition: "background 220ms var(--bm-ease), border-color 220ms var(--bm-ease)",
      }}
    >
      {thumbSrc && (
        <div style={{
          position: "relative", aspectRatio: "16 / 9",
          borderRadius: 10, overflow: "hidden",
          border: "1px solid var(--bm-hairline)", marginTop: -2,
        }}>
          <img
            src={thumbSrc}
            onError={thumbFallback ? (e) => { e.currentTarget.src = thumbFallback; } : undefined}
            alt=""
            loading="lazy"
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover" }}
          />
          {vid && (
            <span style={{
              position: "absolute", bottom: 8, left: 10,
              fontSize: 10, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase",
              color: "rgba(245,247,255,0.82)", background: "rgba(0,3,34,0.55)",
              padding: "3px 8px", borderRadius: 999, backdropFilter: "blur(4px)",
            }}>▶ Watch</span>
          )}
        </div>
      )}
      <div style={{ minHeight: 34, display: "flex", alignItems: "center" }}>
        {logo
          ? <img src={logo} alt={name} loading="lazy" style={{ height: logoH || 28, width: "auto", maxWidth: 170, objectFit: "contain", display: "block" }} />
          : initials
            ? <LogoLockup name={name} initials={initials} size={34} />
            : <span style={{ fontFamily: "var(--bm-font-display)", fontSize: 22, fontWeight: 700, letterSpacing: "-0.02em", color: "var(--bm-text)" }}>{name}</span>}
      </div>
      <span style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-accent)" }}>{tag}</span>
      <div style={{ fontSize: 16, fontWeight: 600, lineHeight: 1.35, color: "var(--bm-text)" }}>{line}</div>
      <BeforeAfter rows={ba} />
      <span style={{
        display: "inline-flex", alignItems: "center", gap: 8, fontSize: 13, fontWeight: 500,
        color: hover ? "var(--bm-accent-hover)" : "var(--bm-accent)", alignSelf: "flex-start",
        transition: "color 120ms var(--bm-ease)",
      }}>
        Read the case study
        <Icon name="arrow-up-right" size={14} color="currentColor" />
      </span>
    </a>
  );
}

function BeforeAfter({ rows }) {
  return (
    <div style={{ paddingTop: 16, borderTop: "1px solid var(--bm-hairline)", flex: 1 }}>
      <div style={{
        display: "grid",
        gridTemplateColumns: "minmax(0, 1fr) minmax(0, 0.9fr) auto minmax(0, 1.1fr)",
        columnGap: 8, rowGap: 11, alignItems: "baseline",
      }}>
        {rows.map((r, i) => (
          <React.Fragment key={i}>
            <span style={{ fontSize: 12, lineHeight: 1.3, color: "var(--bm-text-muted)", minWidth: 0 }}>{r.label}</span>
            <span style={{ fontSize: 12.5, lineHeight: 1.3, color: "var(--bm-text-dim)", textAlign: "right", minWidth: 0 }}>{r.before}</span>
            <span style={{ color: "var(--bm-text-dim)", fontSize: 12 }}>→</span>
            <span style={{ fontFamily: "var(--bm-font-display)", fontWeight: 700, fontSize: 15.5, lineHeight: 1.25, letterSpacing: "-0.01em", textAlign: "right", minWidth: 0, color: r.tone === "good" ? "var(--bm-good)" : "var(--bm-text)", textShadow: r.tone === "good" ? "0 0 18px rgba(95,226,176,0.5)" : "none" }}>{r.after}</span>
          </React.Fragment>
        ))}
      </div>
    </div>
  );
}

/* Small labelled divider used to separate the two case-study tiers. */
function CaseGroupLabel({ children, note }) {
  return (
    <div style={{ marginTop: 48 }}>
      <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
        <span style={{
          fontSize: 11, fontWeight: 600, letterSpacing: "0.16em",
          textTransform: "uppercase", color: "var(--bm-accent)", whiteSpace: "nowrap",
        }}>
          {children}
        </span>
        <span style={{ height: 1, background: "var(--bm-hairline)", flex: 1 }} />
      </div>
      {note && (
        <div style={{ fontSize: 14, color: "var(--bm-text-muted)", marginTop: 12, maxWidth: 720, lineHeight: 1.5 }}>
          {note}
        </div>
      )}
    </div>
  );
}

/* TODO(assets): replace the monogram tile with the supplied client logo
   once permission is confirmed. Wordmark placeholder until then. */
function LogoLockup({ name, initials, size = 40 }) {
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 12, minWidth: 0 }}>
      <span style={{
        width: size, height: size, borderRadius: 10, flexShrink: 0,
        background: "rgba(109,145,242,0.12)", border: "1px solid var(--bm-hairline-strong)",
        display: "inline-flex", alignItems: "center", justifyContent: "center",
        fontFamily: "var(--bm-font-display)", fontWeight: 700, fontSize: size * 0.38,
        letterSpacing: "-0.02em", color: "var(--bm-text)",
      }}>{initials}</span>
      <span style={{
        fontFamily: "var(--bm-font-display)", fontSize: 18, fontWeight: 600,
        letterSpacing: "-0.01em", color: "var(--bm-text)", lineHeight: 1.15,
      }}>{name}</span>
    </div>
  );
}

/* Tier-1 client card — logo lockup, one-line outcome, count-up figures, link. */
function ClientCard({ name, initials, tag, line, figures, slug, logo, logoH }) {
  const [hover, setHover] = useSecState(false);
  return (
    <a
      href={`/work/${slug}`}
      className="bm-reveal"
      data-bm-case-card
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        background: hover ? "var(--bm-surface-2)" : "#000B45",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18, padding: 30, minHeight: 320,
        display: "flex", flexDirection: "column", gap: 18, textDecoration: "none",
        transition: "background 220ms var(--bm-ease), border-color 220ms var(--bm-ease)",
      }}
    >
      <div style={{ height: 40, display: "flex", alignItems: "center" }}>
        {logo
          ? <img src={logo} alt={name} loading="lazy" style={{ height: logoH || 30, width: "auto", maxWidth: 180, objectFit: "contain", display: "block" }} />
          : <LogoLockup name={name} initials={initials} />}
      </div>
      <span style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-accent)" }}>
        {tag}
      </span>
      <div style={{ fontSize: 17, fontWeight: 600, lineHeight: 1.35, color: "var(--bm-text)", flex: 1 }}>
        {line}
      </div>
      <div style={{ display: "flex", flexWrap: "wrap", gap: "16px 22px", paddingTop: 16, borderTop: "1px solid var(--bm-hairline)" }}>
        {figures.map((f, i) => <FigureBlock key={i} f={f} />)}
      </div>
      <span style={{
        display: "inline-flex", alignItems: "center", gap: 8, fontSize: 13, fontWeight: 500,
        color: hover ? "var(--bm-accent-hover)" : "var(--bm-accent)", alignSelf: "flex-start",
        transition: "color 120ms var(--bm-ease)",
      }}>
        Read the case study
        <Icon name="arrow-up-right" size={14} color="currentColor" />
      </span>
    </a>
  );
}

function FigureBlock({ f }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
      <span style={{
        fontFamily: "var(--bm-font-display)", fontSize: "clamp(20px, 2.1vw, 26px)",
        fontWeight: 700, letterSpacing: "-0.02em", lineHeight: 1,
        color: f.tone === "good" ? "var(--bm-good)" : "var(--bm-text)",
      }}>
        <CountUp to={f.to} decimals={f.decimals || 0} prefix={f.prefix || ""} suffix={f.suffix || ""} />
      </span>
      <span style={{ fontSize: 12, color: "var(--bm-text-muted)", lineHeight: 1.35 }}>{f.label}</span>
    </div>
  );
}

/* Tier-2 — Tradacc, the founder's own exited business. One lockup header +
   metric tiles. Logo appears once (not repeated per tile). */
function TradaccBand({ tiles }) {
  return (
    <div className="bm-reveal" style={{
      marginTop: 24, border: "1px solid var(--bm-hairline-strong)", borderRadius: 20,
      background: "rgba(0,11,69,0.35)", padding: "32px 32px",
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 14, flexWrap: "wrap" }}>
        <img src="/assets/clients/tradacc.png" alt="Tradacc" loading="lazy" style={{ height: 26, width: "auto", display: "block" }} />
        <span style={{
          fontSize: 11, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase",
          color: "var(--bm-good)", padding: "6px 12px", borderRadius: 999,
          background: "rgba(95,226,176,0.10)", border: "1px solid rgba(95,226,176,0.28)",
        }}>
          $3M+ exit · proven first
        </span>
      </div>
      <p style={{ ...bodyM, marginTop: 16, maxWidth: 760 }}>
        The business Ruben built and exited — where every BeaverMind system was
        validated against a real P&amp;L before it shipped to a client.
      </p>
      <div style={{ marginTop: 24, display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(150px, 1fr))", gap: 16 }}>
        {tiles.map((f, i) => <TradaccTile key={i} f={f} />)}
      </div>
    </div>
  );
}

function TradaccTile({ f }) {
  return (
    <div style={{
      background: "#000B45", border: "1px solid var(--bm-hairline)", borderRadius: 14,
      padding: "20px 18px", display: "flex", flexDirection: "column", gap: 8,
    }}>
      <span style={{
        fontFamily: "var(--bm-font-display)", fontSize: "clamp(22px, 2.3vw, 30px)",
        fontWeight: 700, letterSpacing: "-0.02em", lineHeight: 1,
        color: f.tone === "good" ? "var(--bm-good)" : "var(--bm-text)",
      }}>
        <CountUp to={f.to} decimals={f.decimals || 0} prefix={f.prefix || ""} suffix={f.suffix || ""} />
      </span>
      <span style={{ fontSize: 12.5, color: "var(--bm-text-muted)", lineHeight: 1.4 }}>{f.label}</span>
    </div>
  );
}

/* ------------------------------------------------------------------
   5.5. Testimonials — social proof (5 LinkedIn recs + WhatsApp)
------------------------------------------------------------------ */
function Testimonials() {
  /* Real LinkedIn recommendations. Character proof — kept separate from the
     client-results numbers. Avatars in /assets/recs/. */
  const recs = [
    { name: "Bjorn van Reenen", photo: "/assets/recs/rec-bjorn.png", headline: "Agency Director @ SalesClosers · Head of Talent @ Movesmethod", rel: "Nov 2025", lead: "Incredibly strong focus on delivering high-quality service and results to any client that engages with him.", body: "A great leader and friend. I had the privilege of working with him for almost two years and would highly recommend collaboration to anyone looking into his services." },
    { name: "Dev Sethi", photo: "/assets/recs/rec-dev.png", headline: "I fix your revenue engine · $10M–$50M companies · Sales + Marketing + AI", rel: "May 2026", lead: "He automates and systemises customer acquisition — and adds millions into your business.", body: "Ruben has a unique ability to understand the underlying process that blocks growth. A great team player and someone you can rely on." },
    { name: "Ludwing Rondon", photo: "/assets/recs/rec-ludwing.png", headline: "CEO & Founder, AIRE Digital Solutions", rel: "Dec 2025", lead: "One of the smartest people I've ever met — a problem solver always seeking ways to improve systems.", body: "He's the best description of a great leader: someone who believes in his team and bets on them. I'm beyond grateful for the time we worked together." },
    { name: "Mattia Ludovico", photo: "/assets/recs/rec-mattia.png", headline: "Digital Marketing Consultant · Growth & Launch Strategy", rel: "Nov 2025", lead: "He understands business processes fast and goes straight to the actions that actually move the needle.", body: "Ruben avoids shiny distractions and never wastes time on anything that doesn't change results. Straightforward, reliable, and he acts with integrity. You'd be lucky to collaborate with him." },
    { name: "Maxim Bellos", photo: "/assets/recs/rec-maxim.png", headline: "Sales Manager at Motago", rel: "Nov 2025", lead: "Ruben is a man who turns problems into solutions.", body: "I've known Ruben for 5 years and was constantly impressed by his vision, drive, integrity and performance. He's adept in all aspects of IT and AI integration — a full package, sleeves-up operator." },
  ];
  const recsA = [recs[0], recs[1], recs[2]];
  const recsB = [recs[3], recs[4]];
  const vMask = "linear-gradient(180deg, transparent, #000 11%, #000 89%, transparent)";
  return (
    <section
      id="testimonials"
      data-screen-label="05 Testimonials"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{ padding: "100px 32px 112px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Working with us</div>
        <h2 style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(30px, 3.6vw, 40px)", fontWeight: 700, letterSpacing: "-0.025em", lineHeight: 1.1, color: "var(--bm-text)", margin: "14px 0 0", maxWidth: 680 }}>
          What it's like to work with us.
        </h2>
        <p style={{ ...bodyM, marginTop: 16, maxWidth: 600 }}>
          Unedited recommendations from people who've worked with us.
        </p>

        <div data-bm-testi-grid style={{ marginTop: 44, display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20, maxHeight: 580, overflow: "hidden", maskImage: vMask, WebkitMaskImage: vMask }}>
          <div className="bm-marq">
            <div className="bm-marq-track" style={{ display: "flex", flexDirection: "column", gap: 18, animation: "bmUp 38s linear infinite", willChange: "transform" }}>
              {recsA.concat(recsA).map((r, i) => <RecCard key={"a" + i} r={r} />)}
            </div>
          </div>
          <div className="bm-marq">
            <div className="bm-marq-track" style={{ display: "flex", flexDirection: "column", gap: 18, animation: "bmDown 44s linear infinite", willChange: "transform" }}>
              {recsB.concat(recsB).map((r, i) => <RecCard key={"b" + i} r={r} />)}
            </div>
          </div>
        </div>

        <p style={{ fontSize: 13, color: "var(--bm-text-dim)", margin: "24px 0 0", textAlign: "center" }}>
          Recommendations verified on LinkedIn.
        </p>
      </div>
    </section>
  );
}

function RecCard({ r }) {
  return (
    <div style={{ background: "#FFFFFF", border: "1px solid rgba(0,3,34,0.10)", borderRadius: 18, padding: 22 }}>
      <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
        <img src={r.photo} alt="" loading="lazy" style={{ flex: "none", width: 46, height: 46, borderRadius: 999, objectFit: "cover", border: "1px solid rgba(0,3,34,0.10)" }} />
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 7 }}>
            <span style={{ fontSize: 15, fontWeight: 600, color: "#000322" }}>{r.name}</span>
            <span style={{ flex: "none", width: 15, height: 15, borderRadius: 3, background: "var(--bm-accent)", color: "#fff", fontSize: 9, fontWeight: 700, display: "flex", alignItems: "center", justifyContent: "center" }}>in</span>
          </div>
          <div style={{ fontSize: 12.5, color: "rgba(0,3,34,0.6)", marginTop: 2, lineHeight: 1.35, display: "-webkit-box", WebkitLineClamp: 2, WebkitBoxOrient: "vertical", overflow: "hidden" }}>{r.headline}</div>
        </div>
      </div>
      <div style={{ fontSize: 11, color: "rgba(0,3,34,0.45)", marginTop: 11 }}>{r.rel}</div>
      <p style={{ fontFamily: "var(--bm-font-display)", fontSize: 17, fontWeight: 600, lineHeight: 1.42, letterSpacing: "-0.01em", color: "#000322", margin: "11px 0 0" }}>
        <mark style={{ background: "#5FE2B0", color: "#00231a", padding: "1px 6px", borderRadius: 5, boxDecorationBreak: "clone", WebkitBoxDecorationBreak: "clone" }}>{r.lead}</mark>
      </p>
      <p style={{ fontSize: 14, lineHeight: 1.6, color: "rgba(0,3,34,0.68)", margin: "12px 0 0" }}>{r.body}</p>
    </div>
  );
}

/* ------------------------------------------------------------------
   6. How We Work
------------------------------------------------------------------ */
function HowItWorks() {
  const steps = [
    {
      n: "01",
      title: "Audit",
      body:
        "On your real data. We rank every automation by ROI and effort. Credited to your first build.",
    },
    {
      n: "02",
      title: "Build",
      body:
        "The number-one leak from the audit, live in 14 days. Built on your stack, owned by you.",
    },
    {
      n: "03",
      title: "Launch",
      body:
        "90-day window against KPIs we set upfront. We optimize on live volume.",
    },
    {
      n: "04",
      title: "Partner",
      body:
        "Monthly retainer as your AI growth partner. Unlimited builds, one at a time.",
    },
  ];
  return (
    <section
      id="process"
      data-screen-label="05 Process"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{ padding: "96px 32px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>How we work</div>
        <h2 style={{ ...displayM, marginTop: 16, maxWidth: 820 }}>
          Audit. Build. Launch. Partner.
        </h2>

        <div
          style={{
            marginTop: 64,
            display: "grid",
            /* Auto-fit so 4 cols → 2 cols → 1 col cleanly as the viewport shrinks. */
            gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))",
            gap: 32,
            position: "relative",
          }}
        >
          {steps.map((s, i) => (
            <div key={s.n} style={{ position: "relative", display: "flex", flexDirection: "column", gap: 20 }}>
              {i < 3 && (
                <div style={{ position: "absolute", right: -20, top: 20, fontSize: 22, color: "var(--bm-accent)", opacity: 0.4, lineHeight: 1, pointerEvents: "none", userSelect: "none" }}>→</div>
              )}
              <div
                style={{
                  fontFamily: "var(--bm-font-display)",
                  fontSize: "clamp(56px, 6vw, 80px)",
                  fontWeight: 700,
                  letterSpacing: "-0.04em",
                  lineHeight: 1,
                  color: "var(--bm-accent)",
                }}
              >
                {s.n}
              </div>
              <div
                style={{
                  height: 1,
                  background: "var(--bm-hairline)",
                  width: "100%",
                }}
              />
              <div
                style={{
                  fontFamily: "var(--bm-font-display)",
                  fontSize: "clamp(26px, 2.4vw, 32px)",
                  fontWeight: 700,
                  letterSpacing: "-0.02em",
                  lineHeight: 1.1,
                  color: "var(--bm-text)",
                }}
              >
                {s.title}
              </div>
              <div style={bodyM}>{s.body}</div>
            </div>
          ))}
        </div>

        <div
          data-bm-stack="guarantee"
          style={{
            marginTop: 48,
            maxWidth: 860,
            display: "flex",
            alignItems: "center",
            gap: 18,
            background: "var(--bm-surface)",
            border: "1px solid var(--bm-hairline)",
            borderLeft: "3px solid #5FE2B0",
            borderRadius: 14,
            padding: "20px 24px",
          }}
        >
          <div style={{ width: 46, height: 46, borderRadius: 999, flex: "none", background: "rgba(95,226,176,0.12)", border: "1px solid rgba(95,226,176,0.4)", display: "flex", alignItems: "center", justifyContent: "center" }}>
            <Icon name="shield-check" size={22} color="#5FE2B0" />
          </div>
          <div>
            <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 17, fontWeight: 700, letterSpacing: "-0.01em", color: "var(--bm-text)" }}>
              90-Day Guarantee
            </div>
            <div style={{ fontSize: 14.5, lineHeight: 1.5, color: "var(--bm-text-muted)", marginTop: 3 }}>
              We agree the KPIs upfront. Miss them in 90 days and you get your money back — every dollar.
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ------------------------------------------------------------------
   7. Who It's For
------------------------------------------------------------------ */
function WhoItsFor() {
  /* Fit criteria (good / not-a-fit) now live in the GHL calendar event
     description — see the booking widget below. Kept out of the page body
     to cut text per the redesign. */
  /* GHL calendar resize listener (moved here from the former LetsTalk section).
     The widget posts height updates in two formats; we match the iframe and its
     #calendar container to the reported height so nothing ever clips. */
  useSecEffect(() => {
    const onMsg = (e) => {
      if (!e || !e.data) return;
      const ifr = document.getElementById(GHL_IFRAME_ID);
      if (!ifr) return;
      let targetHeight = null;
      if (typeof e.data === "string" && e.data.indexOf("[iFrameSizer]") === 0) {
        const parts = e.data.substring("[iFrameSizer]".length).split(":");
        if (parts.length >= 2) {
          const h = parseInt(parts[1], 10);
          if (!isNaN(h) && h > 0) targetHeight = h;
        }
      }
      let parsed = e.data;
      if (typeof parsed === "string") {
        try { parsed = JSON.parse(parsed); } catch (_) { /* not JSON */ }
      }
      if (Array.isArray(parsed) && parsed[0] === "highlevel.setHeight" && parsed[1]) {
        const h = parseInt(parsed[1].height, 10);
        if (!isNaN(h) && h > 0) targetHeight = h;
      }
      if (targetHeight) {
        ifr.style.height = targetHeight + "px";
        const container = document.getElementById("calendar");
        if (container) container.style.height = targetHeight + "px";
      }
    };
    window.addEventListener("message", onMsg);
    return () => window.removeEventListener("message", onMsg);
  }, []);
  return (
    <section
      id="talk"
      data-screen-label="06 Book"
      data-bm-section="cta"
      className="bm-section--ink"
      style={{ padding: "96px 32px 128px", position: "relative", overflow: "hidden" }}
    >
      <BottomLeftGlow />
      <img
        src="/assets/beavermind-logo-white.svg"
        alt=""
        aria-hidden="true"
        style={{ position: "absolute", right: -60, bottom: -28, width: 760, maxWidth: "62%", opacity: 0.045, pointerEvents: "none", userSelect: "none" }}
      />
      <div style={{ position: "relative", maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>See if you qualify</div>
        <h2 style={{ ...displayM, marginTop: 16, maxWidth: 760 }}>
          Book your free call.
        </h2>
        <p style={{ ...bodyM, marginTop: 18, maxWidth: 660 }}>
          A focused 30-minute call. If you're a fit, we map your highest-ROI leak on the spot. If you're not, we'll tell you why — before you spend anything.
        </p>
        <p style={{ fontSize: 13, color: "var(--bm-text-muted)", marginTop: 10 }}>
          Free · 30 minutes · no pitch
        </p>

        {/* Booking card — ONE seamless light card: GHL scheduler (left half) +
            custom fit panel (right half), both white so the seam disappears
            (drgrandiphd pattern). The fit content is our HTML, not GHL's.
            #calendar + GHL_IFRAME_ID kept for the resize listener + scroll targets. */}
        <div
          data-bm-stack="cols-2"
          style={{
            marginTop: 36, maxWidth: 1140, marginLeft: "auto", marginRight: "auto",
            display: "grid", gridTemplateColumns: "1fr 1fr", alignItems: "stretch",
            background: "#ffffff", borderRadius: 20, overflow: "hidden",
            border: "1px solid #E4E7EC", boxShadow: "0 30px 80px -30px rgba(109,145,242,0.28)",
          }}
        >
          {/* GHL scheduler — left half */}
          <div
            id="calendar"
            data-bm-calendar
            style={{ background: "#ffffff", position: "relative", borderRight: "1px solid #EEF0F3" }}
          >
            <iframe
              src={`${GHL_CAL_EMBED_URL}?notrack=true`}
              title="Discovery Call With Ruben (Founder & CEO)"
              style={{ width: "100%", border: "none", display: "block", background: "#ffffff", WebkitOverflowScrolling: "touch", minHeight: 760 }}
              id={GHL_IFRAME_ID}
            />
          </div>

          {/* Fit panel — right half, light to match the white scheduler */}
          <div style={{ background: "#ffffff", padding: "40px 40px 36px", display: "flex", flexDirection: "column" }}>
            {/* Header — VARIATION A (default; swap per choice) */}
            <div style={{ fontSize: 12, fontWeight: 700, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--bm-accent)", marginBottom: 10 }}>
              Discovery call
            </div>
            <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 25, fontWeight: 700, letterSpacing: "-0.02em", lineHeight: 1.15, color: "#0B1530", marginBottom: 10 }}>
              Find your biggest revenue leak
            </div>
            <p style={{ margin: "0 0 26px", fontSize: 14.5, lineHeight: 1.55, color: "#475467" }}>
              Thirty focused minutes on two things: where revenue is leaking, and where you and your team spend the most time. We map the highest-ROI fix — so you win back both and focus on higher-level work.
            </p>

            <div style={{ fontSize: 12, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase", color: "#101828", marginBottom: 14 }}>
              This call is for you if
            </div>
            <ul style={{ listStyle: "none", margin: "0 0 22px", padding: 0, display: "flex", flexDirection: "column", gap: 13 }}>
              {[
                "$1M–$50M a year in coaching or consulting",
                "A sales process that already works — with humans",
                "Consistent lead flow and a proven, paid offer",
                "One decision-maker who can move fast",
              ].map((t, i) => (
                <li key={i} style={{ display: "flex", alignItems: "flex-start", gap: 11, fontSize: 14.5, lineHeight: 1.5 }}>
                  <Icon name="check" size={16} color="#16A34A" style={{ marginTop: 2, flexShrink: 0 }} />
                  <span style={{ color: "#344054" }}>{t}</span>
                </li>
              ))}
            </ul>

            <div style={{ height: 1, background: "#EEF0F3", margin: "0 0 22px" }} />

            <div style={{ fontSize: 12, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase", color: "#101828", marginBottom: 14 }}>
              Not a fit
            </div>
            <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: 13 }}>
              {[
                "Pre-product-market-fit, still hunting the offer",
                "Without consistent lead flow to automate",
                "Without a proven sales process to systemize",
                "Counting on AI to fix a broken offer",
              ].map((t, i) => (
                <li key={i} style={{ display: "flex", alignItems: "flex-start", gap: 11, fontSize: 14.5, lineHeight: 1.5 }}>
                  <Icon name="x" size={16} color="#DC2626" style={{ marginTop: 2, flexShrink: 0 }} />
                  <span style={{ color: "#667085" }}>{t}</span>
                </li>
              ))}
            </ul>
          </div>
        </div>
      </div>
    </section>
  );
}

function FitCard({ kind, items }) {
  const good = kind === "good";
  return (
    <div
      style={{
        background: "var(--bm-surface)",
        border: "1px solid var(--bm-hairline)",
        borderRadius: 18,
        padding: 36,
      }}
    >
      <div
        style={{
          display: "flex",
          alignItems: "center",
          gap: 12,
          marginBottom: 24,
        }}
      >
        <div
          style={{
            width: 32,
            height: 32,
            borderRadius: 999,
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            background: good ? "rgba(95,226,176,0.12)" : "rgba(138,148,180,0.1)",
            border: good ? "1px solid rgba(95,226,176,0.32)" : "1px solid var(--bm-hairline-strong)",
          }}
        >
          <Icon
            name={good ? "check" : "x"}
            size={16}
            color={good ? "#5FE2B0" : "var(--bm-text-muted)"}
          />
        </div>
        <div
          style={{
            fontFamily: "var(--bm-font-display)",
            fontSize: 22,
            fontWeight: 700,
            letterSpacing: "-0.02em",
            color: "var(--bm-text)",
          }}
        >
          {good ? "Good fit" : "Not a fit"}
        </div>
      </div>

      <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: 14 }}>
        {items.map((text, i) => (
          <li
            key={i}
            style={{
              display: "flex",
              alignItems: "flex-start",
              gap: 12,
              fontSize: 15,
              lineHeight: 1.55,
              color: good ? "var(--bm-text)" : "var(--bm-text-muted)",
              paddingBottom: 14,
              borderBottom: i < items.length - 1 ? "1px solid var(--bm-hairline)" : "none",
            }}
          >
            <Icon
              name={good ? "check" : "x"}
              size={16}
              color={good ? "#5FE2B0" : "var(--bm-text-muted)"}
              style={{ marginTop: 3, flexShrink: 0 }}
            />
            <span style={{ fontWeight: good && i === 0 ? 700 : 400 }}>{text}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}

/* ------------------------------------------------------------------
   9. Voice Agent Demo
------------------------------------------------------------------ */
function VoiceDemo() {
  return (
    <section
      id="demo"
      data-screen-label="08 Demo"
      data-bm-section="mid"
      className="bm-section--ink"
      style={{ padding: "96px 32px 128px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Voice agent demo</div>
        <h2 style={{ ...displayM, marginTop: 16, maxWidth: 720 }}>
          Hear it for yourself.
        </h2>
        <p style={{ ...bodyM, marginTop: 18, maxWidth: 680 }}>
          A live outbound call, qualifying and booking end to end. Voice is one
          pattern in the catalog, not the whole offer.
        </p>

        <div style={{ marginTop: 28, display: "flex", flexDirection: "column", gap: 14 }}>
          <div data-bm-cta-row style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
            <Button variant="primary" icon="arrow-right" onClick={scrollToTalk}>See if you qualify</Button>
          </div>
        </div>

        <HeroLiveCall />

        <VideoFacade />
      </div>
    </section>
  );
}

/* Labeled slot for a future client-results video. Poster-frame facade now;
   TODO(assets): when a clip is supplied, swap to click-to-load iframe
   (facade stays as the poster, player mounts on click to save initial load). */
function VideoFacade() {
  return (
    <div
      data-bm-video-slot
      style={{
        marginTop: 28, position: "relative", aspectRatio: "16 / 9",
        maxWidth: 900, marginLeft: "auto", marginRight: "auto",
        borderRadius: 18, overflow: "hidden",
        border: "1px solid var(--bm-hairline-strong)",
        background: "radial-gradient(ellipse 60% 90% at 50% 25%, rgba(109,145,242,0.12), rgba(0,11,69,0.55))",
        display: "flex", alignItems: "center", justifyContent: "center",
      }}
    >
      <BlueprintGrid />
      <div style={{ position: "relative", textAlign: "center", display: "flex", flexDirection: "column", alignItems: "center", gap: 14 }}>
        <span style={{
          width: 64, height: 64, borderRadius: 999,
          background: "rgba(109,145,242,0.16)", border: "1px solid var(--bm-accent)",
          display: "inline-flex", alignItems: "center", justifyContent: "center",
        }}>
          <Icon name="play" size={24} color="var(--bm-accent)" />
        </span>
        <div style={{ fontFamily: "var(--bm-font-display)", fontSize: 18, fontWeight: 600, color: "var(--bm-text)" }}>
          Client results video
        </div>
        <div style={{ fontSize: 12, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-text-muted)", fontWeight: 600 }}>
          Coming soon
        </div>
      </div>
    </div>
  );
}

/* Agent icon card — a replica of the hero's animated avatar.
   Always "speaking" since this section is showing what a conversation feels like. */
function AgentIconCard() {
  return (
    <div
      style={{
        position: "relative",
        background: "rgba(0,3,34,0.6)",
        border: "1px solid var(--bm-hairline-strong)",
        borderRadius: 18,
        padding: "40px 28px",
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
        gap: 20,
        minHeight: 360,
      }}
    >
      <div style={{
        display: "flex", alignItems: "center", gap: 10,
        fontSize: 11, color: "var(--bm-text-muted)",
        letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 600,
        alignSelf: "flex-start",
      }}>
        <span style={{
          width: 6, height: 6, borderRadius: 999, background: "#5FE2B0",
          boxShadow: "0 0 0 3px rgba(95,226,176,0.18)",
        }} />
        Agent online
      </div>

      <div style={{ marginTop: 8 }}>
        <VoiceAvatar speaking={true} />
      </div>

      <div style={{ textAlign: "center" }}>
        <div style={{
          fontFamily: "var(--bm-font-display)",
          fontSize: 22, fontWeight: 700, letterSpacing: "-0.02em",
          color: "var(--bm-text)",
        }}>
          Emma
        </div>
        <div style={{
          fontSize: 11, fontWeight: 600,
          letterSpacing: "0.16em", textTransform: "uppercase",
          color: "var(--bm-accent)", marginTop: 6,
        }}>
          AI Voice Agent
        </div>
      </div>

      <SoundWave active={true} />

      <div style={{
        fontSize: 13, color: "var(--bm-text-muted)",
        textAlign: "center", maxWidth: 280, lineHeight: 1.55,
        marginTop: 4,
      }}>
        One click. Real conversation. Books into our calendar if you qualify.
      </div>
    </div>
  );
}

/* ------------------------------------------------------------------
   10. Footer
------------------------------------------------------------------ */
function SiteFooter() {
  const navLinks = [
    { label: "What we build", href: "/#what" },
    { label: "Proof",         href: "/proof" },
    { label: "How we work",   href: "/#process" },
    { label: "About",         href: "/about" },
  ];
  return (
    <footer
      data-screen-label="09 Footer"
      data-bm-section="mid"
      style={{
        padding: "72px 32px 48px",
        borderTop: "1px solid var(--bm-hairline)",
      }}
    >
      <div
        data-bm-stack="footer"
        style={{
          maxWidth: CANVAS_MAX,
          margin: "0 auto",
          display: "grid",
          gridTemplateColumns: "1.4fr 1fr 1fr",
          gap: 48,
        }}
      >
        <div>
          <img
            src="/assets/beavermind-logo-white.svg"
            alt="BeaverMind.ai"
            style={{ height: 26, width: "auto", display: "block", opacity: 0.95 }}
          />
          <p style={{ fontSize: 14, color: "var(--bm-text-muted)", marginTop: 18, maxWidth: 320, lineHeight: 1.55 }}>
            The AI growth partner for operator-led coaching and consulting businesses.
          </p>
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-text-muted)", fontWeight: 600 }}>
            Navigate
          </div>
          {navLinks.map((l) => (
            <a
              key={l.label}
              href={l.href}
              style={{ fontSize: 14, color: "var(--bm-text)", textDecoration: "none" }}
            >
              {l.label}
            </a>
          ))}
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--bm-text-muted)", fontWeight: 600 }}>
            Contact
          </div>
          <div style={{ display: "flex", gap: 10 }}>
            <SocialIcon name="brand:linkedin" href="https://www.linkedin.com/in/ruben-davoli/" label="LinkedIn — Ruben Davoli" />
            <SocialIcon name="brand:youtube"  href="https://www.youtube.com/@ruben_davoli"     label="YouTube — @ruben_davoli" />
            <SocialIcon name="mail"           href="mailto:support@beavermind.ai"              label="Email support@beavermind.ai" />
          </div>
        </div>
      </div>

      <div
        data-bm-footer-bottom
        style={{
          maxWidth: CANVAS_MAX,
          margin: "56px auto 0",
          paddingTop: 24,
          borderTop: "1px solid var(--bm-hairline)",
          display: "flex",
          justifyContent: "space-between",
          alignItems: "center",
          gap: 24,
          flexWrap: "wrap",
          fontSize: 12,
          color: "var(--bm-text-muted)",
          lineHeight: 1.6,
        }}
      >
        <div>
          © 2026 BeaverMind by RD Consulting Ltd · HK Co. No. 3129374 · All rights reserved.
        </div>
        <div style={{ display: "flex", gap: 20, flexWrap: "wrap" }}>
          <a href="/tos"                  style={{ color: "inherit", textDecoration: "none" }}>Terms</a>
          <a href="/privacy-policy"       style={{ color: "inherit", textDecoration: "none" }}>Privacy</a>
          <a href="/refund-policy"        style={{ color: "inherit", textDecoration: "none" }}>Refund Policy</a>
          <a href="/earnings-disclaimer"  style={{ color: "inherit", textDecoration: "none" }}>Earnings Disclaimer</a>
        </div>
      </div>
    </footer>
  );
}

function SocialIcon({ name, href = "#", label }) {
  const [hover, setHover] = useSecState(false);
  const external = href.startsWith("http");
  return (
    <a
      href={href}
      data-bm-social-icon
      target={external ? "_blank" : undefined}
      rel={external ? "noopener noreferrer" : undefined}
      aria-label={label || name}
      title={label || name}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        width: 36, height: 36,
        display: "inline-flex", alignItems: "center", justifyContent: "center",
        borderRadius: 10,
        background: hover ? "var(--bm-surface-2)" : "var(--bm-surface)",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        transition: "background 120ms var(--bm-ease-standard), border-color 120ms var(--bm-ease-standard)",
      }}
    >
      <Icon name={name} size={16} color={hover ? "var(--bm-accent)" : "var(--bm-text-muted)"} />
    </a>
  );
}

/* ------------------------------------------------------------------
   About — Two-person card layout (Ruben + Luca)
------------------------------------------------------------------ */
const TEAM = [
  {
    photo: "/assets/ruben-profile.png?v=6",
    name: "Ruben Davoli",
    role: "Founder & CEO",
    bio: [
      "Ruben Davoli scaled an education company from $0 to $3M with 15,000+ clients — by building the systems that ran it without him.",
      "After years working with agencies and being let down by most, one pattern kept repeating: the priority was protecting the retainer, not the client's results. BeaverMind exists to break that model. The golden rule here is simple — if a build doesn't produce a clear ROI in revenue gained or cost and time saved, we don't build it.",
    ],
    credentials: "2 Comma Club ClickFunnels Award · International Speaker",
  },
  {
    photo: "/assets/luke-profile.png",
    name: "Luke Cala",
    role: "Head of AI Solutions",
    bio: [
      "Luke is the technical architect behind every system BeaverMind ships — AI voice agents, automation workflows, custom applications, and the full AI infrastructure stack.",
      "He placed 2nd at the Liam Ottley AI hackathon, one of the most competitive AI builder programs running today. His background in paid media means he comes to every build with a distribution and acquisition lens — technical precision in service of revenue outcomes, not engineering for its own sake.",
    ],
    credentials: "Liam Ottley's Hackathon Finalist · AI Systems Architect",
  },
];

function TeamCard({ photo, name, role, bio, credentials }) {
  const [hover, setHover] = useSecState(false);
  return (
    <article
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        background: hover ? "var(--bm-surface-2)" : "var(--bm-surface)",
        border: `1px solid ${hover ? "var(--bm-hairline-strong)" : "var(--bm-hairline)"}`,
        borderRadius: 18,
        overflow: "hidden",
        display: "flex",
        flexDirection: "column",
        transition: "background 220ms var(--bm-ease-standard), border-color 220ms var(--bm-ease-standard)",
      }}
    >
      <div
        data-bm-team-image
        style={{
          position: "relative",
          width: "100%",
          aspectRatio: "1 / 1",
          background: "var(--bm-surface-2)",
          borderBottom: "1px solid var(--bm-hairline)",
        }}
      >
        <img
          src={photo}
          alt={name}
          loading="lazy"
          style={{
            position: "absolute",
            inset: 0,
            width: "100%",
            height: "100%",
            objectFit: "cover",
            objectPosition: "center 20%",
            display: "block",
          }}
        />
      </div>

      <div style={{ padding: "32px 32px 28px", display: "flex", flexDirection: "column", gap: 12, flex: 1 }}>
        <div>
          <h3 style={{
            fontFamily: "var(--bm-font-display)",
            fontSize: "clamp(22px, 2vw, 28px)",
            fontWeight: 700,
            letterSpacing: "-0.02em",
            lineHeight: 1.1,
            color: "var(--bm-text)",
            margin: 0,
          }}>{name}</h3>
          <div style={{
            marginTop: 6,
            fontSize: 11,
            fontWeight: 600,
            letterSpacing: "0.16em",
            textTransform: "uppercase",
            color: "var(--bm-accent)",
          }}>{role}</div>
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 12, flex: 1 }}>
          {bio.map((p, i) => (
            <p key={i} style={{ ...bodyM, fontSize: 15 }}>{p}</p>
          ))}
        </div>

        <div style={{
          marginTop: 14,
          paddingTop: 18,
          borderTop: "1px solid var(--bm-hairline)",
          fontSize: 11,
          fontWeight: 600,
          letterSpacing: "0.14em",
          textTransform: "uppercase",
          color: "var(--bm-accent)",
          lineHeight: 1.6,
        }}>
          {credentials}
        </div>
      </div>
    </article>
  );
}

function Founder() {
  return (
    <section
      id="about"
      data-screen-label="About Us"
      data-bm-section="mid"
      className="bm-section--paper"
      style={{ padding: "96px 32px" }}
    >
      <div style={{ maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>About Us</div>
        <h2 style={{ ...displayM, marginTop: 16, maxWidth: 900 }}>
          Anyone can build an AI agent.<br />
          Few understand the business it's supposed to fix.
        </h2>
        <p style={{ ...bodyM, marginTop: 18, maxWidth: 680 }}>
          BeaverMind starts with the revenue problem. AI is how we solve it.
        </p>

        <div
          data-bm-stack="cols-2"
          style={{
            marginTop: 56,
            display: "grid",
            gridTemplateColumns: "1fr 1fr",
            gap: 20,
          }}
        >
          {TEAM.map((m) => <TeamCard key={m.name} {...m} />)}
        </div>
      </div>
    </section>
  );
}

/* ------------------------------------------------------------------
   Let's Talk — GHL calendar embed (standalone CTA section)
   Used by /work and other standalone pages. The homepage merges this
   into WhoItsFor instead. Self-contained resize listener targets the
   #calendar container + GHL_IFRAME_ID. */
function LetsTalk() {
  useSecEffect(() => {
    const onMsg = (e) => {
      if (!e || !e.data) return;
      const ifr = document.getElementById(GHL_IFRAME_ID);
      if (!ifr) return;
      let targetHeight = null;
      if (typeof e.data === "string" && e.data.indexOf("[iFrameSizer]") === 0) {
        const parts = e.data.substring("[iFrameSizer]".length).split(":");
        if (parts.length >= 2) {
          const h = parseInt(parts[1], 10);
          if (!isNaN(h) && h > 0) targetHeight = h;
        }
      }
      let parsed = e.data;
      if (typeof parsed === "string") {
        try { parsed = JSON.parse(parsed); } catch (_) { /* not JSON */ }
      }
      if (Array.isArray(parsed) && parsed[0] === "highlevel.setHeight" && parsed[1]) {
        const h = parseInt(parsed[1].height, 10);
        if (!isNaN(h) && h > 0) targetHeight = h;
      }
      if (targetHeight) {
        ifr.style.height = targetHeight + "px";
        const container = document.getElementById("calendar");
        if (container) container.style.height = targetHeight + "px";
      }
    };
    window.addEventListener("message", onMsg);
    return () => window.removeEventListener("message", onMsg);
  }, []);

  return (
    <section
      id="talk"
      data-screen-label="Let's Talk"
      data-bm-section="cta"
      className="bm-section--ink"
      style={{ padding: "96px 32px 128px", position: "relative", overflow: "hidden" }}
    >
      <BottomLeftGlow />
      <img
        src="/assets/beavermind-logo-white.svg"
        alt=""
        aria-hidden="true"
        style={{ position: "absolute", right: -60, bottom: -28, width: 760, maxWidth: "62%", opacity: 0.045, pointerEvents: "none", userSelect: "none" }}
      />
      <div style={{ position: "relative", maxWidth: CANVAS_MAX, margin: "0 auto" }}>
        <div style={eyebrowStyle}>Contact</div>
        <h2 style={{ ...displayL, marginTop: 18, maxWidth: 960 }}>
          See if you qualify.
        </h2>
        <p style={{ ...bodyM, marginTop: 22, maxWidth: 680 }}>
          A 30-minute call against five preconditions. If you pass, we map your
          highest-ROI leak. If you don't, you'll leave knowing exactly what to
          fix first.
        </p>

        <div style={{ marginTop: 32, display: "flex", flexDirection: "column", gap: 14 }}>
          <div style={eyebrowStyle}>Free audit · 30 minutes · no pitch</div>
          <div data-bm-cta-row style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
            <Button variant="primary" icon="arrow-down" onClick={scrollToCalendar}>Let's talk</Button>
          </div>
        </div>

        <div
          id="calendar"
          data-bm-calendar
          style={{
            marginTop: 40,
            maxWidth: 1140,
            marginLeft: "auto",
            marginRight: "auto",
            background: "#ffffff",
            border: "none",
            borderRadius: 18,
            overflow: "hidden",
            position: "relative",
            boxShadow: "0 30px 80px -30px rgba(109,145,242,0.28)",
          }}
        >
          <iframe
            src={`${GHL_CAL_EMBED_URL}?notrack=true`}
            title="Discovery Call With Ruben (Founder & CEO)"
            style={{
              width: "100%",
              border: "none",
              display: "block",
              background: "#ffffff",
              WebkitOverflowScrolling: "touch",
            }}
            id={GHL_IFRAME_ID}
          />
        </div>
        <p
          style={{
            marginTop: 14,
            fontSize: 12,
            color: "var(--bm-text-muted)",
            textAlign: "center",
            letterSpacing: "0.08em",
            textTransform: "uppercase",
            fontWeight: 600,
          }}
        >
          Discovery call · 30 minutes · no pitch
        </p>
      </div>
    </section>
  );
}

/* Scroll to the embedded calendar iframe (used by the in-section button) */
function scrollToCalendar() {
  const el = document.getElementById("calendar");
  if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });
}

/* ------------------------------------------------------------------
   Agent Modal — "Try the agent first" friendly coming-soon popup
------------------------------------------------------------------ */
function AgentModal() {
  const [open, setOpen] = useSecState(false);

  useSecEffect(() => {
    const onOpen = () => setOpen(true);
    window.addEventListener("bm:open-agent-modal", onOpen);
    return () => window.removeEventListener("bm:open-agent-modal", onOpen);
  }, []);

  useSecEffect(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === "Escape") setOpen(false); };
    document.addEventListener("keydown", onKey);
    const prevOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    return () => {
      document.removeEventListener("keydown", onKey);
      document.body.style.overflow = prevOverflow;
    };
  }, [open]);

  if (!open) return null;

  const close = () => setOpen(false);
  const bookCall = () => { close(); scrollToTalk(); };

  return (
    <div
      role="dialog"
      aria-modal="true"
      aria-labelledby="bm-agent-modal-title"
      onClick={close}
      style={{
        position: "fixed",
        inset: 0,
        zIndex: 100,
        background: "rgba(0,3,34,0.72)",
        backdropFilter: "blur(8px)",
        WebkitBackdropFilter: "blur(8px)",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        padding: 24,
        animation: "bm-fade-in 180ms var(--bm-ease-standard) both",
      }}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        style={{
          position: "relative",
          maxWidth: 520,
          width: "100%",
          background: "var(--bm-surface)",
          border: "1px solid var(--bm-hairline-strong)",
          borderRadius: 22,
          padding: "40px 36px 32px",
          boxShadow: "0 40px 100px -20px rgba(0,0,0,0.6), 0 0 0 1px rgba(109,145,242,0.18)",
          animation: "bm-pop-in 240ms var(--bm-ease-standard) both",
        }}
      >
        {/* close button */}
        <button
          onClick={close}
          aria-label="Close"
          style={{
            position: "absolute",
            top: 14, right: 14,
            width: 44, height: 44,
            borderRadius: 10,
            border: "1px solid var(--bm-hairline)",
            background: "transparent",
            color: "var(--bm-text-muted)",
            cursor: "pointer",
            display: "inline-flex",
            alignItems: "center",
            justifyContent: "center",
            transition: "background 120ms var(--bm-ease-standard), color 120ms var(--bm-ease-standard)",
          }}
          onMouseEnter={(e) => { e.currentTarget.style.background = "var(--bm-surface-2)"; e.currentTarget.style.color = "var(--bm-text)"; }}
          onMouseLeave={(e) => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.color = "var(--bm-text-muted)"; }}
        >
          <Icon name="x" size={16} color="currentColor" />
        </button>

        {/* avatar */}
        <div style={{ display: "flex", justifyContent: "center", marginBottom: 20 }}>
          <VoiceAvatar speaking={true} />
        </div>

        <div style={{ textAlign: "center" }}>
          <div style={eyebrowStyle}>Coming Soon</div>
          <h3
            id="bm-agent-modal-title"
            style={{
              ...displayM,
              marginTop: 12,
              fontSize: "clamp(24px, 3vw, 30px)",
            }}
          >
            Meet Emma — live on this site soon.
          </h3>
          <p style={{ ...bodyM, marginTop: 16, maxWidth: 420, marginLeft: "auto", marginRight: "auto" }}>
            The agent will be embedded directly on this website soon.
            In the meantime, you can try it live with us by booking a call.
          </p>
        </div>

        <div
          style={{
            marginTop: 28,
            display: "flex",
            gap: 10,
            flexWrap: "wrap",
            justifyContent: "center",
          }}
        >
          <Button variant="primary" icon="calendar" onClick={bookCall}>
            Book a call instead
          </Button>
          <Button variant="secondary" onClick={close}>
            Maybe later
          </Button>
        </div>
      </div>
    </div>
  );
}

/* Inline pull quote — single recommendation strip between the case studies
   and the process section. Full testimonial wall lives on the future /proof page. */
function PullQuote() {
  return (
    <div style={{ padding: "64px 32px" }}>
      <div style={{
        maxWidth: 1200, margin: "0 auto",
        borderLeft: "3px solid var(--bm-accent)",
        paddingLeft: 28,
      }}>
        <p style={{ fontFamily: "var(--bm-font-display)", fontSize: "clamp(18px, 2vw, 24px)", fontWeight: 600, letterSpacing: "-0.01em", lineHeight: 1.42, color: "var(--bm-text)", margin: 0, fontStyle: "italic" }}>
          "He automates and systemises customer acquisition — and adds millions into your business."
        </p>
        <div style={{ marginTop: 18, display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap" }}>
          <img src="/assets/recs/rec-dev.png" alt="Dev Sethi" loading="lazy" style={{ width: 42, height: 42, borderRadius: "50%", objectFit: "cover", flex: "none", border: "1px solid var(--bm-hairline)" }} />
          <div style={{ fontSize: 13, color: "var(--bm-text-muted)" }}>
            <span style={{ fontWeight: 700, color: "var(--bm-text)" }}>Dev Sethi</span> — Revenue consultant, $10M–$50M companies
            <a href="/proof" style={{ color: "var(--bm-accent)", textDecoration: "none", marginLeft: 14, fontWeight: 600, whiteSpace: "nowrap" }}>
              See all recommendations →
            </a>
          </div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, {
  SiteNav, Hero2, CloserProof, ContrarianTruth, ProofBar, WhatWeBuild,
  VoiceLibrary, CaseStudies, Testimonials, PullQuote, HowItWorks, WhoItsFor,
  Founder, VoiceDemo, LetsTalk, SiteFooter,
  AgentModal,
  /* helpers used by case-study + /work pages in separate script files */
  scrollToTalk, openAgentModal,
  CountUp, LogoLockup, BlueprintGrid, VideoFacade, Grain,
  ClientCard, FigureBlock,
  GHL_CAL_ID, GHL_CAL_EMBED_URL,
});
