/* Sections below hero + modal + tweaks panel */

function Hero({ headline, onJoinWaitlist }) {
  return (
    <section className="snap hero-pad" style={{ padding: "60px 40px 40px", minHeight: "calc(100vh - 72px)", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 24 }}>
      <div style={{ maxWidth: 900, textAlign: "center" }}>
        <div style={{ display: "inline-flex", alignItems: "center", gap: 8, padding: "8px 14px", borderRadius: 4, background: "var(--accent-ink)", marginBottom: 24 }}>
          <span style={{ width: 7, height: 7, borderRadius: "50%", background: "var(--paper)" }} />
          <span style={{ fontFamily: "Prompt, sans-serif", fontSize: 12, fontWeight: 600, letterSpacing: "0.02em", color: "var(--paper)", textTransform: "uppercase" }}>Now piloting · looking for more agents to try us out</span>
        </div>
        <h1 className="hero-h" style={{
          fontFamily: "Prompt, sans-serif",
          fontWeight: 400,
          fontSize: "clamp(44px, 6.5vw, 84px)",
          lineHeight: 1.08,
          letterSpacing: "-0.02em",
          margin: "0 0 28px",
          paddingBottom: "0.1em",
        }}>
          {headline.split(" ").slice(0, -2).join(" ")}{" "}
          <em style={{ color: "var(--accent-ink)", fontStyle: "italic" }}>
            {headline.split(" ").slice(-2).join(" ")}
          </em>
        </h1>
        <p style={{ fontSize: 18, color: "var(--ink-2)", maxWidth: 620, margin: "0 auto", lineHeight: 1.5 }}>
          Activus reads an agent's calendar and inbox and classifies what they actually do to show info that clients can really trust. <a href="#story" onClick={(e) => { e.preventDefault(); const el = document.getElementById('story'); if (el) window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 20, behavior: 'smooth' }); }} style={{ color: "var(--accent-ink)", textDecoration: "underline", textDecorationThickness: "1px", textUnderlineOffset: "3px", cursor: "pointer" }}>It's GitHub, but for real estate.</a>
        </p>
        <div style={{ display: "flex", gap: 12, justifyContent: "center", marginTop: 28 }}>
          <button onClick={onJoinWaitlist} style={btnPrimary}>join waitlist →</button>
        </div>
        <div className="mono" style={{ fontSize: 11, color: "var(--mute)", marginTop: 18 }}>
          reads Calendar + Email · read-only · never shared without your approval
        </div>
        <div className="mono hide-sm" style={{ fontSize: 11, color: "var(--mute)", marginTop: 42, opacity: 0.7 }}>
          scroll to explore ↓
        </div>
      </div>
    </section>
  );
}

function ClientViewSection({ gridStyle, showDealColors }) {
  return (
    <section className="snap client-view-section" style={{ padding: "20px 24px 28px", minHeight: "calc(100vh - 72px)", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 12, borderTop: "1px solid var(--line)", background: "var(--paper-2)" }}>
      <div style={{ maxWidth: 1120, width: "100%", textAlign: "center" }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 4 }}>// WHAT YOUR CLIENTS SEE</div>
        <h2 className="section-h" style={{ fontFamily: "Prompt, sans-serif", fontWeight: 500, fontSize: 28, letterSpacing: "-0.02em", lineHeight: 1.1, margin: 0 }}>
          A live, verified view of an agent. <em style={{ color: "var(--accent-ink)", fontStyle: "italic" }}>Click any house.</em>
        </h2>
      </div>
      <PreviewWindow gridStyle={gridStyle} showDealColors={showDealColors} />
    </section>
  );
}

Object.assign(window, { ClientViewSection });

/* ---------- Feature strip (three-column) ---------- */
function FeatureStrip() {
  const items = [
    {
      k: "01",
      t: "The invisible hours",
      b: "MLS shows closed deals, months later. Social shows marketing. Everything in between — the tours, the builder calls, the pre-construction deposits, the 2am follow-ups, lives only in your inbox.",
    },
    {
      k: "02",
      t: "Specialization, in evidence",
      b: "A pre-construction specialist and a luxury re-sale agent look identical on a billboard. Activus surfaces what kind of agent you actually are, by property type, deal type, area, and client fit.",
    },
    {
      k: "03",
      t: "A profile that earns trust",
      b: "Share a link at your listing presentation. Clients see 487 verified activities, 14 builder relationships, a repeat-client rate in the top quartile — not a 5-star average from five of your friends.",
    },
  ];
  return (
    <section id="how" className="snap section-pad" style={{ padding: "80px 40px", borderTop: "1px solid var(--line)" }}>
      <div style={{ maxWidth: 1120, margin: "0 auto" }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// WHAT'S BROKEN</div>
        <h2 className="section-h" style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: 44, letterSpacing: "-0.02em", lineHeight: 1.05, maxWidth: 720, marginTop: 0 }}>
          MLS is a scoreboard. <em style={{ color: "var(--accent-ink)" }}>We show the game.</em>
        </h2>
        <div className="r-grid-3" style={{ marginTop: 56 }}>
          {items.map(it => (
            <div key={it.k}>
              <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", marginBottom: 10 }}>{it.k}</div>
              <div style={{ fontFamily: "Prompt, sans-serif", fontSize: 24, lineHeight: 1.15, marginBottom: 10 }}>{it.t}</div>
              <div style={{ fontSize: 14, color: "var(--ink-2)", lineHeight: 1.6 }}>{it.b}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- How it works: 3 steps, visual ---------- */
function Step({ n, title, blurb, children }) {
  return (
    <div className="r-stepgrid" style={{ padding: "60px 0", borderTop: "1px dashed var(--line)" }}>
      <div>
        <div className="mono" style={{ fontSize: 11, color: "var(--mute)" }}>STEP {n}</div>
        <h3 style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: 38, letterSpacing: "-0.015em", margin: "6px 0 12px", lineHeight: 1.05 }}>
          {title}
        </h3>
        <p style={{ fontSize: 15, color: "var(--ink-2)", maxWidth: 460, lineHeight: 1.55 }}>{blurb}</p>
        {n === "02" && (
          <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", marginTop: 10, padding: "6px 10px", background: "var(--accent-tint)", border: "1px solid var(--accent-tint-2)", borderRadius: 6, display: "inline-block" }}>
            → agent activity in real time · clients never see raw event data
          </div>
        )}
      </div>
      <div>{children}</div>
    </div>
  );
}

function StepConnect() {
  return (
    <div style={{ background: "var(--paper)", border: "1px solid var(--line-2)", borderRadius: 10, padding: 18, boxShadow: "0 8px 28px -12px rgba(26,23,20,0.12)" }}>
      <div className="mono" style={{ fontSize: 10, color: "var(--mute)" }}>$ activus connect</div>
      <div style={{ marginTop: 14, display: "flex", flexDirection: "column", gap: 8 }}>
        {[
          ["Google Calendar", "connected", true],
          ["Gmail", "connected", true],
          ["Follow Up Boss (coming soon!)", "optional", false],
          ["ShowingTime (coming soon!)", "optional", false],
        ].map(([n, s, ok]) => (
          <div key={n} style={{ display: "flex", alignItems: "center", padding: "10px 12px", background: "var(--paper-2)", borderRadius: 6 }}>
            <div style={{ width: 8, height: 8, borderRadius: "50%", background: ok ? "var(--accent)" : "var(--line-2)", marginRight: 10 }} />
            <div style={{ fontSize: 13 }}>{n}</div>
            <div style={{ flex: 1 }} />
            <div className="mono" style={{ fontSize: 10, color: ok ? "var(--accent-ink)" : "var(--mute)" }}>{s}</div>
          </div>
        ))}
      </div>
      <div className="mono" style={{ fontSize: 10, color: "var(--mute)", marginTop: 14 }}>
        // read-only scopes · we never send, modify, or delete
      </div>
    </div>
  );
}

function StepClassify() {
  const rows = [
    ["10:30am · Tour · 142 Bedford Rd", "precon", "Tridel · Bloor & Avenue launch"],
    ["12:00pm · Consultation", "resale", "buyer · downsizer · $1.8M"],
    ["2:15pm · Builder meeting", "precon", "Mattamy · VIP platinum access"],
    ["4:00pm · Client retention", "luxury", "follow-up · past client · Forest Hill"],
  ];
  return (
    <div style={{ background: "var(--paper)", border: "1px solid var(--line-2)", borderRadius: 10, padding: 16, boxShadow: "0 8px 28px -12px rgba(26,23,20,0.12)" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--mute)" }}>tuesday · apr 14</div>
        <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
          <span className="mono" style={{
            fontSize: 9, color: "var(--accent-ink)", letterSpacing: "0.06em",
            background: "var(--accent-tint)", border: "1px solid var(--accent-tint-2)",
            padding: "2px 7px", borderRadius: 999, textTransform: "uppercase",
          }}>agent view · private</span>
          <div className="mono" style={{ fontSize: 10, color: "var(--accent-ink)" }}>4 events classified</div>
        </div>
      </div>
      {rows.map(([label, type, sub], i) => (
        <div key={i} style={{ display: "flex", gap: 12, padding: "10px 0", borderTop: i === 0 ? "none" : "1px dashed var(--line)" }}>
          <div style={{ width: 3, borderRadius: 2, background: `var(--${type})`, alignSelf: "stretch" }} />
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 13 }}>{label}</div>
            <div className="mono" style={{ fontSize: 10, color: "var(--mute)", marginTop: 2 }}>{sub}</div>
          </div>
          <div style={{ alignSelf: "center" }}>
            <Tag tone={type}>{type}</Tag>
          </div>
        </div>
      ))}
    </div>
  );
}

function StepShare() {
  return (
    <div style={{ background: "var(--paper)", border: "1px solid var(--line-2)", borderRadius: 10, padding: 18, boxShadow: "0 8px 28px -12px rgba(26,23,20,0.12)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10, padding: "10px 12px", background: "var(--paper-2)", borderRadius: 6, marginBottom: 12 }}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--mute)" strokeWidth="2"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 0 1 0 18"/></svg>
        <div className="mono" style={{ fontSize: 12, color: "var(--ink-2)" }}>activusai.com/<span style={{ color: "var(--accent-ink)" }}>sarahchen</span></div>
        <div style={{ flex: 1 }} />
        <button className="mono" style={{ ...btnGhost, padding: "4px 10px", fontSize: 11 }}>copy</button>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 10, textAlign: "center" }}>
        {[["views", "1,284"], ["shares", "47"], ["signed", "9"]].map(([l, v]) => (
          <div key={l} style={{ background: "var(--paper-2)", borderRadius: 6, padding: "12px 8px" }}>
            <div style={{ fontFamily: "Prompt", fontSize: 24, color: "var(--ink)" }}>{v}</div>
            <div className="mono" style={{ fontSize: 9, color: "var(--mute)", letterSpacing: "0.08em" }}>{l.toUpperCase()}</div>
          </div>
        ))}
      </div>
      <div className="mono" style={{ fontSize: 10, color: "var(--mute)", marginTop: 14 }}>
        // drop your link in listing presentations, email signatures, or IG bio
      </div>
    </div>
  );
}

function HowSection() {
  return (
    <section id="profile" className="snap section-pad" style={{ padding: "40px 40px 80px" }}>
      <div style={{ maxWidth: 1120, margin: "0 auto" }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// HOW IT WORKS</div>
        <h2 className="section-h" style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: 44, letterSpacing: "-0.02em", lineHeight: 1.05, maxWidth: 720, marginTop: 0 }}>
          Three minutes to connect. <em style={{ color: "var(--accent-ink)" }}>A lifetime of work, finally visible.</em>
        </h2>
        <Step n="01" title="Connect your workflow" blurb="OAuth Google Calendar and Gmail in under 60 seconds. Read-only, revocable, scoped. Add ShowingTime, your CRM, or transaction tools any time, more sources, sharper signal.">
          <StepConnect />
        </Step>
        <Step n="02" title="We classify the noise" blurb="Every event, every thread gets a label for tour, consultation, listing prep, builder meeting, client retention — plus property type, deal type, and client fit. Cross-signal confirmation. Confidence scored. You review before anything goes public.">
          <StepClassify />
        </Step>
        <Step n="03" title="Share a link clients trust" blurb="Your profile lives at activusai.com/you. Put it in your listing presentation, your email signature, your DMs. Clients see specialization, evidence, and fit, not a 5-star average from paid ads.">
          <StepShare />
        </Step>
      </div>
    </section>
  );
}

/* ---------- Agents section with quotes ---------- */
function AgentQuote({ quote, role, city }) {
  return (
    <div style={{ background: "var(--paper)", border: "1px solid var(--line)", borderRadius: 12, padding: 24, display: "flex", flexDirection: "column", gap: 12 }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
        <div className="mono" style={{ fontSize: 10, color: "var(--accent-ink)", letterSpacing: "0.06em", textTransform: "uppercase" }}>{role} · {city}</div>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="var(--accent-tint-2)"><path d="M6 17h4l2-7H6zm8 0h4l2-7h-6z"/></svg>
      </div>
      <div style={{ fontFamily: "Prompt", fontSize: 20, lineHeight: 1.3, color: "var(--ink)" }}>"{quote}"</div>
      <div style={{ marginTop: "auto", height: 1 }} />
    </div>
  );
}

function AgentsSection() {
  return (
    <section id="agents" className="snap section-pad" style={{ padding: "80px 40px", borderTop: "1px solid var(--line)", background: "var(--paper-2)" }}>
      <div style={{ maxWidth: 1120, margin: "0 auto" }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// FROM PILOT AGENTS</div>
        <h2 className="section-h" style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: 44, letterSpacing: "-0.02em", lineHeight: 1.05, maxWidth: 720, marginTop: 0 }}>
          Agents know their worth. <em style={{ color: "var(--accent-ink)" }}>Now clients can too.</em>
        </h2>
        <div className="r-grid-3" style={{ marginTop: 40 }}>
          <AgentQuote
            quote="I describe myself as a full-service agent, but the classifier showed that I'm 70% re-sale. I didn't even know how specialized I'd become and now buyers see that it's my strong point."
            role="Veteran agent" city="Mississauga" />
          <AgentQuote
            quote="I shared my profile at a listing presentation with a buyer who was shopping with multiple agents, the client said 'I wish I'd had this for my last three agents.' That changed everything for them."
            role="Broker" city="Toronto" />
          <AgentQuote
            quote="When I first entered the investment market, it was difficult to know which agent knew the space and was connected to builders. Activus would have saved me months of searching for the right realtor."
            role="Property Investor" city="Oakville" />
        </div>
      </div>
    </section>
  );
}

/* ---------- Our story (what is GitHub + founders) ---------- */
function OurStory() {
  return (
    <section id="story" className="snap section-pad" style={{ padding: "80px 40px", borderTop: "1px solid var(--line)" }}>
      <div className="r-grid-2" style={{ maxWidth: 1120, margin: "0 auto", alignItems: "start" }}>
        <div>
          <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// WAIT — WHAT'S A GITHUB?</div>
          <h2 style={{ fontFamily: "Prompt, sans-serif", fontWeight: 500, fontSize: 40, letterSpacing: "-0.02em", lineHeight: 1.1, marginTop: 0, paddingBottom: "0.08em" }}>
            The little green squares <span style={{ color: "var(--accent-ink)" }}>tech hires by.</span>
          </h2>
          <p style={{ fontSize: 15, color: "var(--ink-2)", lineHeight: 1.6 }}>
            GitHub is where software engineers save their work. Every time they fix a bug or ship a feature, it shows up as a little square on a public calendar. Over the years, that grid becomes a visible track record — a signal any recruiter, founder, or client can read at a glance.
          </p>
          <p style={{ fontSize: 15, color: "var(--ink-2)", lineHeight: 1.6, marginTop: 12 }}>
            In tech, this is now table stakes. You don't say you're a great engineer, your contributions say it for you. Real estate has no such thing. We're building it.
          </p>
        </div>
        <div>
          <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// WHO'S BUILDING THIS</div>
          <h2 style={{ fontFamily: "Prompt, sans-serif", fontWeight: 500, fontSize: 40, letterSpacing: "-0.02em", lineHeight: 1.1, marginTop: 0, paddingBottom: "0.08em" }}>
            Two brothers, <span style={{ color: "var(--accent-ink)" }}>one real estate office.</span>
          </h2>
          <p style={{ fontSize: 15, color: "var(--ink-2)", lineHeight: 1.6 }}>
            We're students working in tech who grew up in a real estate office. We spent years watching great agents lose leads to flashier ones, and clients pick the loudest name on a billboard instead of the right person for their deal.
          </p>
          <p style={{ fontSize: 15, color: "var(--ink-2)", lineHeight: 1.6, marginTop: 12 }}>
            In the tech world we saw how GitHub's contribution graph built transparency and credibility almost overnight. We want to bring that same clarity — the kind that lets real work speak for itself — to the industry that raised us.
          </p>
        </div>
      </div>
    </section>
  );
}

/* ---------- FAQ ---------- */
function FAQItem({ q, a }) {
  const [open, setOpen] = useState(false);
  return (
    <div style={{ borderTop: "1px solid var(--line)", padding: "18px 0" }}>
      <button onClick={() => setOpen(!open)} style={{
        width: "100%", display: "flex", alignItems: "center", justifyContent: "space-between",
        background: "none", border: "none", padding: 0, cursor: "pointer", textAlign: "left",
      }}>
        <span style={{ fontFamily: "Prompt", fontSize: 22, color: "var(--ink)" }}>{q}</span>
        <span className="mono" style={{ fontSize: 20, color: "var(--accent-ink)" }}>{open ? "–" : "+"}</span>
      </button>
      {open && <div style={{ marginTop: 10, color: "var(--ink-2)", fontSize: 14, maxWidth: 720, lineHeight: 1.6 }}>{a}</div>}
    </div>
  );
}

function FAQ() {
  const items = [
    ["Is my calendar and email safe?", "Read-only OAuth scopes. We never modify, send, or delete. You can revoke access any time. Events are classified in aggregate, raw content never appears on your public profile."],
    ["What if a client's name shows up?", "It doesn't. Profiles show patterns, counts, and aggregates, never names, addresses, or thread content. You always have the option to review everything and make corrections to what we've shared."],
    ["How is this different from MLS or Zillow?", "MLS shows closed deals after the fact. Zillow shows reviews and paid placement. Activus shows the pre-close work: what you actually do, who you work with, what you specialize in, which is where agent quality lives."],
    ["Can I game the system?", "We always cross-confirm, a tour isn't just a calendar event, it's a calendar event + address + client thread + follow-up. Faking one signal is possible. Faking agent confluence is not."],
    ["What does it cost?", "Flat monthly subscription. Cheaper than a single billboard placement."],
  ];
  return (
    <section id="faq" className="snap section-pad" style={{ padding: "80px 40px", borderTop: "1px solid var(--line)" }}>
      <div style={{ maxWidth: 900, margin: "0 auto" }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em", marginBottom: 12 }}>// FAQ</div>
        <h2 className="section-h" style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: 44, letterSpacing: "-0.02em", lineHeight: 1.05, marginTop: 0, marginBottom: 24 }}>
          Questions, <em style={{ color: "var(--accent-ink)" }}>honestly answered.</em>
        </h2>
        <div>
          {items.map(([q, a]) => <FAQItem key={q} q={q} a={a} />)}
        </div>
      </div>
    </section>
  );
}

/* ---------- CTA ---------- */
function CTA({ onJoinWaitlist }) {
  return (
    <section className="snap section-pad" style={{ padding: "100px 40px", borderTop: "1px solid var(--line)", background: `linear-gradient(180deg, var(--bg), var(--accent-tint))` }}>
      <div style={{ maxWidth: 820, margin: "0 auto", textAlign: "center" }}>
        <h2 style={{ fontFamily: "Prompt, sans-serif", fontWeight: 400, fontSize: "clamp(40px, 5vw, 64px)", letterSpacing: "-0.02em", lineHeight: 1.05, margin: "0 0 18px" }}>
          The billboards are loud. <em style={{ color: "var(--accent-ink)" }}>Let your work speak.</em>
        </h2>
        <p style={{ fontSize: 16, color: "var(--ink-2)", maxWidth: 560, margin: "0 auto" }}>
          {"\n"}
        </p>
        <div style={{ display: "flex", gap: 12, justifyContent: "center", marginTop: 28 }}>
          <button onClick={onJoinWaitlist} style={btnPrimary}>join the waitlist →</button>
        </div>
      </div>
    </section>
  );
}

/* ---------- Footer ---------- */
function Footer() {
  return (
    <footer style={{ padding: "40px", borderTop: "1px solid var(--line)", background: "var(--paper)" }}>
      <div style={{ maxWidth: 1120, margin: "0 auto", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 20 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 20 }}>
          <Wordmark />
          <div className="mono" style={{ fontSize: 11, color: "var(--mute)" }}>© 2026 Activus AI · Toronto</div>
        </div>
      </div>
    </footer>
  );
}

/* ---------- Waitlist modal (email-only, compact) ---------- */
function WaitlistModal({ open, onClose }) {
  const [submitted, setSubmitted] = useState(false);
  const [email, setEmail] = useState("");
  const turnstileRef = useRef(null);
  const widgetIdRef = useRef(null);
  useEffect(() => {
    if (!open || submitted) return;
    let cancelled = false;
    const tryRender = () => {
      if (cancelled) return;
      const ts = window.turnstile;
      const el = turnstileRef.current;
      if (!ts || !el) { setTimeout(tryRender, 120); return; }
      if (widgetIdRef.current !== null) { try { ts.remove(widgetIdRef.current); } catch (e) {} widgetIdRef.current = null; }
      try {
        widgetIdRef.current = ts.render(el, {
          sitekey: "0x4AAAAAAC_3pM9tfi4ly_be",
          language: "en",
        });
      } catch (e) { /* already rendered */ }
    };
    tryRender();
    return () => {
      cancelled = true;
      const ts = window.turnstile;
      if (ts && widgetIdRef.current !== null) { try { ts.remove(widgetIdRef.current); } catch (e) {} }
      widgetIdRef.current = null;
    };
  }, [open, submitted]);
  if (!open) return null;
  return (
    <div onClick={onClose} style={{
      position: "fixed", inset: 0, zIndex: 100,
      background: "rgba(26,23,20,0.42)",
      backdropFilter: "blur(6px)",
      display: "grid", placeItems: "center", padding: 20,
      animation: "fadeIn 0.18s ease-out",
    }}>
      <style>{`@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } } @keyframes popIn { from { opacity:0; transform: translateY(8px) scale(0.98) } to { opacity:1; transform: none } }`}</style>
      <div onClick={e => e.stopPropagation()} style={{
        background: "var(--paper)", borderRadius: 14, maxWidth: 400, width: "100%",
        border: "1px solid var(--line-2)",
        boxShadow: "0 30px 80px -20px rgba(26,23,20,0.35)",
        overflow: "hidden", animation: "popIn 0.22s ease-out",
      }}>
        <div style={{ height: 5, background: "var(--accent)" }} />
        <div style={{ padding: 22 }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 2 }}>
            <div>
              <h3 style={{ fontFamily: "Prompt", fontWeight: 500, fontSize: 22, margin: 0, lineHeight: 1.2 }}>Join the waitlist</h3>
            </div>
            <button onClick={onClose} style={{ background: "none", border: "none", cursor: "pointer", color: "var(--mute)", fontSize: 20, lineHeight: 1, padding: 0 }} aria-label="close">×</button>
          </div>
          {submitted ? (
            <div style={{ padding: "18px 0 4px", textAlign: "center" }}>
              <div style={{ width: 40, height: 40, borderRadius: "50%", background: "var(--accent-tint)", margin: "0 auto 10px", display: "grid", placeItems: "center", color: "var(--accent-ink)" }}>
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M5 12l5 5L20 7"/></svg>
              </div>
              <div style={{ fontFamily: "Prompt", fontSize: 18, fontWeight: 500 }}>You're on the list.</div>
              <div style={{ color: "var(--ink-2)", marginTop: 4, fontSize: 13 }}>We'll email you when a pilot spot opens.</div>
            </div>
          ) : (
            <>
              <form
                action="https://e6691b89.sibforms.com/serve/MUIFAOWxewyRTUk2v4jQzxC6JLJL5QMfspgFnYVvC6Bxhg6s0Vq4VoEDUe8b4inNIODFONfWfYje5pn0lZiWUfQ0LQn6RWV5Zzhoe4P3uBhY6OzA0sa_epRjJ90WZcr7ktPFWVyy2YfiH95QccMF_KGwKPcXI0louEOztXFi_Kjcj08fZxQxq1PT84bMFzLdudskyjUo0M9YavVYuQ=="
                method="POST"
                target="_blank"
                onSubmit={(e) => {
                  const ts = window.turnstile;
                  const token = ts && widgetIdRef.current !== null ? ts.getResponse(widgetIdRef.current) : null;
                  if (!token) {
                    e.preventDefault();
                    alert("Please complete the captcha before submitting.");
                    return;
                  }
                  setTimeout(() => setSubmitted(true), 800);
                }}
                style={{ marginTop: 14, display: "flex", flexDirection: "column", gap: 10 }}
              >
                <input
                  type="email"
                  name="EMAIL"
                  required
                  value={email}
                  onChange={(e) => setEmail(e.target.value)}
                  placeholder="you@brokerage.com"
                  autoFocus
                  style={{
                    ...inputStyle,
                    padding: "12px 14px", fontSize: 15,
                  }}
                />
                <input type="text" name="email_address_check" defaultValue="" tabIndex={-1} autoComplete="off" style={{ position: "absolute", left: "-9999px", width: 1, height: 1, opacity: 0 }} />
                <input type="hidden" name="locale" value="en" />
                <div ref={turnstileRef} style={{ display: "flex", justifyContent: "center", minHeight: 65 }} />
                <button type="submit" style={{ ...btnPrimary, padding: "12px 16px", fontSize: 14 }}>
                  sign up →
                </button>
              </form>
            </>
          )}
        </div>
      </div>
    </div>
  );
}
const inputStyle = {
  border: "1px solid var(--line-2)", borderRadius: 7, padding: "10px 12px",
  background: "var(--paper-2)", fontSize: 14, fontFamily: "Inter, sans-serif",
  color: "var(--ink)", outline: "none", width: "100%",
};

/* ---------- Tweaks panel ---------- */
function TweaksPanel({ active, tweaks, update }) {
  if (!active) return null;
  return (
    <div style={{
      position: "fixed", right: 20, bottom: 20, zIndex: 200,
      background: "var(--paper)", borderRadius: 12, padding: 18, width: 280,
      border: "1px solid var(--line-2)",
      boxShadow: "0 20px 60px -15px rgba(26,23,20,0.35)",
      fontFamily: "Inter, sans-serif",
    }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
        <div className="mono" style={{ fontSize: 11, color: "var(--accent-ink)", letterSpacing: "0.08em" }}>// TWEAKS</div>
      </div>
      <div style={{ display: "flex", flexDirection: "column", gap: 14 }}>
        <div>
          <div className="mono" style={{ fontSize: 10, color: "var(--mute)", marginBottom: 6, letterSpacing: "0.06em", textTransform: "uppercase" }}>Color by deal type</div>
          <button onClick={() => update({ showDealColors: !tweaks.showDealColors })} className="mono"
            style={{ padding: "8px 10px", fontSize: 11, borderRadius: 6, cursor: "pointer", border: "1px solid var(--line-2)",
              background: tweaks.showDealColors ? "var(--accent-tint)" : "var(--paper-2)",
              color: tweaks.showDealColors ? "var(--accent-ink)" : "var(--ink-2)", width: "100%", textAlign: "left" }}>
            {tweaks.showDealColors ? "On — multi-color" : "Off — mono purple"}
          </button>
        </div>
        <div>
          <div className="mono" style={{ fontSize: 10, color: "var(--mute)", marginBottom: 6, letterSpacing: "0.06em", textTransform: "uppercase" }}>Accent hue · {tweaks.accentHue}</div>
          <input type="range" min="0" max="360" value={tweaks.accentHue} onChange={e => update({ accentHue: Number(e.target.value) })} style={{ width: "100%", accentColor: "var(--accent)" }} />
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { Hero, FeatureStrip, HowSection, AgentsSection, OurStory, FAQ, CTA, Footer, WaitlistModal, TweaksPanel });
