/* Compound — sections.jsx (Swiss/technical redesign) */

/* ============================================================
   META STRIP — runs at the very top, before nav.
   Live clock, coordinates, session, version.
============================================================ */

function MetaStrip() {
  return (
    <div className="frame" style={{ borderTop: "1px solid var(--rule-strong)", borderBottom: "1px solid var(--rule)" }}>
      <div className="wrap">
        <div className="flex items-center justify-between gap-4 py-2" data-comment-anchor="e2489c63b1-div-12-9">
          <Meta style={{ color: "var(--ink)" }}>COMPOUND // AI SYSTEMS STUDIO</Meta>
        </div>
      </div>
    </div>);

}

/* ============================================================
   NAV
============================================================ */

function TopNav() {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <header className="frame sticky top-0 z-40"
    style={{
      background: scrolled ? "rgba(242,239,232,0.92)" : "var(--bg)",
      backdropFilter: scrolled ? "blur(6px)" : "none",
      borderBottom: "1px solid var(--rule-strong)",
      transition: "background 200ms ease"
    }}>
      <div className="wrap">
        <div className="flex items-center justify-between gap-4 py-4 md:py-5">
          <a href="#top" className="flex items-center gap-3 group">
            <Mark size={20} className="shrink-0" style={{ color: "var(--ink)" }} />
            <span className="text-[16px] font-medium tracking-tight">Compound</span>
          </a>

          <nav className="hidden md:flex items-center gap-8">
            <a className="link-x meta" href="#thesis">01 Thesis</a>
            <a className="link-x meta" href="#build">02 Build</a>
            <a className="link-x meta" href="#work">03 Work</a>
            <a className="link-x meta" href="#process">04 Process</a>
            <a className="link-x meta" href="#studio">06 Studio</a>
          </nav>

          <a href="#contact" className="btn">
            <span>Get in touch</span>
            <span className="arrow">→</span>
          </a>
        </div>
      </div>
    </header>);

}

/* ============================================================
   HERO
   Animated wordreveal headline + animated coordinate mark.
   Parallax-shifted background grid.
============================================================ */

const HEADLINES = {
  ship: { line1: "We build the AI systems", line2: "our own businesses run on.", label: "Ship", em: "our own businesses run on." },
  own: { line1: "Operator-built AI", line2: "for the work that pays.", label: "Own", em: "for the work that pays." },
  run: { line1: "AI that lives inside", line2: "the work it runs.", label: "Run", em: "the work it runs." }
};

function Hero({ headline = "ship" }) {
  const h = HEADLINES[headline] || HEADLINES.ship;
  return (
    <section id="top" className="section frame relative overflow-hidden" style={{ background: "var(--bg)" }}>
      <div className="wrap">
        {/* Eyebrow */}
        <div className="flex items-center justify-center gap-3 pt-14 md:pt-20">
          <span className="block w-6 h-px" style={{ background: "var(--accent)" }}></span>
          <Meta style={{ color: "var(--accent)" }}>AI SYSTEMS STUDIO</Meta>
          <span className="block w-6 h-px" style={{ background: "var(--accent)" }}></span>
        </div>

        {/* Headline — centered */}
        <h1 className="display text-[44px] sm:text-[64px] md:text-[88px] lg:text-[104px] xl:text-[120px] mt-10 md:mt-14 text-center max-w-[18ch] mx-auto">
          <span className="block"><WordReveal text={h.line1} stagger={70} /></span>
          <span className="block" style={{ color: "var(--accent)" }}>
            <WordReveal text={h.line2} stagger={70} start={420} />
          </span>
        </h1>

        {/* Subhead — centered, restrained */}
        <Reveal className="mt-8 md:mt-10 max-w-[60ch] mx-auto text-center">
          <p className="text-[16px] md:text-[19px] leading-[1.5] tracking-tight" style={{ color: "var(--ink-2)", textWrap: "pretty" }}>
            A small studio designing AI systems for companies whose operations have outgrown spreadsheets, teams, and templates.
          </p>
        </Reveal>

        {/* CTAs — centered */}
        <Reveal className="mt-8 md:mt-10 flex flex-wrap items-center justify-center gap-6" delay={120}>
          <a href="#contact" className="btn">
            <span>Book a discovery call</span>
            <span className="arrow">→</span>
          </a>
          <a href="#work" className="link-x meta" style={{ color: "var(--ink-2)" }}>SEE THE WORK ↓</a>
        </Reveal>
      </div>

      {/* Flowlines — full bleed, sits at bottom of hero */}
      <div className="mt-12 md:mt-16 relative" style={{ overflow: "hidden" }}>
        <HeroFlowlines />
      </div>
    </section>);

}

/* ---------- Hero footer data row with counters + bars ---------- */
function DataStrip() {
  return (
    <div className="grid grid-cols-2 md:grid-cols-4 gap-0">
      {[
      { k: "TIME RECOVERED, WEEKLY", v: <><CountUp to={23} suffix="" /><span className="text-[14px] ml-2 mono" style={{ color: "var(--muted)" }}>hrs/operator</span></>, bar: 92, accent: true },
      { k: "MEDIAN APPEAL DRAFT", v: <><CountUp to={38} suffix="s" /></>, bar: 4 },
      { k: "QUOTE TURNAROUND", v: <>1:<CountUp to={47} suffix="" /></>, bar: 6 },
      { k: "FIELD WORKERS, LIVE", v: <><CountUp to={500} suffix="K+" /></>, bar: 78 }].
      map((row, i) =>
      <div key={i} className="py-5 md:py-7 px-4 md:px-6"
      style={{
        borderRight: (i + 1) % 4 !== 0 ? "1px solid var(--rule)" : "none",
        borderTop: i >= 2 ? "1px solid var(--rule)" : "none"
      }}>
          <Meta style={{ color: "var(--muted)" }}>{row.k}</Meta>
          <div className="mt-3 md:mt-4 text-[34px] md:text-[44px] num" style={{ color: "var(--ink)" }}>{row.v}</div>
          <div className="mt-4 md:mt-5">
            <BarFill to={row.bar} duration={1600} delay={i * 120} accent={row.accent} />
          </div>
        </div>
      )}
    </div>);

}

/* ============================================================
   THESIS
============================================================ */

function Thesis() {
  return (
    <section id="thesis" className="section frame relative" style={{ background: "var(--bg)" }}>
      <div className="wrap">
        <SectionHeader idx="01" label="THESIS" right="OPERATOR-LED · IRVINE, CA" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-16 md:py-28">
          <div className="col-span-12 md:col-span-3 mb-10 md:mb-0">
            <Meta style={{ color: "var(--muted)" }}>// 01.01</Meta>
          </div>
          <Reveal className="col-span-12 md:col-span-9">
            <p className="display text-[34px] md:text-[56px] lg:text-[68px] leading-[1.0]" style={{ textWrap: "balance" }}>
              We build for our own <em style={{ color: "var(--accent)", fontStyle: "normal" }}>portfolio companies first</em>. 
            </p>
          </Reveal>
        </div>

        <Hairline />

        <div className="grid grid-cols-1 md:grid-cols-3 gap-0">
          {[
          { k: "01.02", lbl: "OPERATORS", body: "We are operators first. Compound exists because the systems we built for our own portfolio companies turned out to be valuable to other operators too." },
          { k: "01.03", lbl: "SYSTEMS", body: "Configurators, quote builders, claim engines, dispatch layers. Each one designed for a specific workflow, integrated with your stack, owned by you on delivery." },
          { k: "01.04", lbl: "CADENCE", body: "We sit alongside your team through adoption, not just delivery, monitoring, refining, training, until the system is just how the work gets done." }].
          map((c, i) =>
          <Reveal key={c.k} delay={i * 100} className="p-8 md:p-10"
          style={{ borderRight: i < 2 ? "1px solid var(--rule)" : "none", minHeight: 320 }}>
              <div className="flex items-baseline justify-between mb-8">
                <Meta style={{ color: "var(--muted)" }}>// {c.k}</Meta>
                <Meta style={{ color: "var(--accent)" }}>{c.lbl}</Meta>
              </div>
              <p className="text-[15.5px] leading-[1.65] tracking-[-0.005em]" style={{ color: "var(--ink)" }}>{c.body}</p>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

/* ============================================================
   WHAT WE BUILD — 4 numbered offerings
============================================================ */

const CAPS = [
{ n: "01", cat: "DIAGNOSTIC", t: "AI Opportunity Audit", d: "A paid diagnostic. We map your workflows, identify the highest-ROI automation targets, and deliver a written report with build estimates and projected impact. Most clients start here.", typical: "1–2 WEEKS" },
{ n: "02", cat: "BUILD", t: "Custom AI Systems", d: "End-to-end build of a specific system: configurators, quote builders, AI support agents, sales automation, document processing, internal tools. Designed for your workflow, integrated with your stack, owned by you on delivery.", typical: "4 — 12 WEEKS" },
{ n: "03", cat: "MARKET ENTRY", t: "US Market-Entry Systems", d: "For international brands launching in the US. A complete operational stack — storefront, configurator, automated support, marketing, analytics — so a small founder-led team can run a credible US business from day one.", typical: "4 — 12 WEEKS" },
{ n: "04", cat: "PARTNERSHIP", t: "Ongoing Partnership", d: "For clients who want continuous access after a build. New systems, optimization, strategic advisory. We take on a limited number of these.", typical: "MONTHLY" }];


function WhatWeBuild() {
  return (
    <section id="build" className="section frame relative" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <SectionHeader idx="02" label="WHAT WE BUILD" right="04 OFFERINGS · BY ENGAGEMENT" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20">
          <div className="col-span-12 md:col-span-5">
            <h2 className="display text-[42px] md:text-[64px] lg:text-[80px]" style={{ textWrap: "balance" }}>
              Start with a question. <span style={{ color: "var(--accent)" }}>End with a system.</span>
            </h2>
          </div>
          <Reveal className="col-span-12 md:col-span-6 md:col-start-7 mt-6 md:mt-3">
            <p className="text-[16.5px] md:text-[18px] leading-[1.55] max-w-[52ch]" style={{ color: "var(--ink-2)" }}>
              Most engagements start with the audit and shape from there. Pricing is quoted per brief. Timelines below are typical, not contractual.
            </p>
          </Reveal>
        </div>

        <Hairline strong />

        <div className="grid grid-cols-1 md:grid-cols-2">
          {CAPS.map((c, i) =>
          <Reveal key={c.n} delay={i % 2 * 100}
          className="p-8 md:p-12 relative"
          style={{
            borderRight: i % 2 === 0 ? "1px solid var(--rule-strong)" : "none",
            borderBottom: i < 2 ? "1px solid var(--rule-strong)" : "none",
            minHeight: 380
          }}>
              <div className="flex items-baseline justify-between mb-12">
                <span className="num text-[88px] md:text-[120px]" style={{ color: "var(--ink)", lineHeight: 0.85 }}>{c.n}</span>
                <Meta style={{ color: "var(--muted)" }}>// {c.cat}</Meta>
              </div>
              <h3 className="display text-[28px] md:text-[36px] lg:text-[42px] leading-[1.0]" style={{ textWrap: "balance" }}>
                {c.t}
              </h3>
              <p className="mt-5 text-[15px] leading-[1.65] max-w-[46ch]" style={{ color: "var(--ink-2)" }}>
                {c.d}
              </p>
              <div className="mt-8 pt-5 flex items-baseline justify-between" style={{ borderTop: "1px solid var(--rule)" }}>
                <Meta style={{ color: "var(--muted)" }}>TYPICAL</Meta>
                <Meta style={{ color: "var(--ink)" }}>{c.typical}</Meta>
              </div>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

/* ============================================================
   SELECTED WORK — case studies with blueprint diagrams
============================================================ */

const WORK = [
{
  idx: "I",
  name: "Appealio",
  descriptor: "A vertical AI platform for healthcare insurance denial management.",
  problem: "Medical practices lose millions per year to denied insurance claims. The appeal process is manual, slow, and requires deep knowledge of payer-specific rules — so most denials are never appealed at all.",
  built: "A system that ingests denied claims (835/ERA files), identifies the denial reason, pulls the relevant clinical evidence and coverage policies, and generates a complete appeal letter in under sixty seconds. Used daily by medical billing teams.",
  outcomes: [
  ["38", "s", "median draft time"],
  ["~$1,800", "", "avg. claim value recovered"],
  ["4.2", "×", "faster than manual draft"]],

  url: "https://appealio.co",
  urlLabel: "appealio.co",
  tag: "VERTICAL SaaS · HEALTHCARE",
  year: "2025",
  Diagram: DiagramAppealio
},
{
  idx: "II",
  name: "Helmet Hygiene",
  descriptor: "An automated quote-and-configuration engine for a custom-manufactured product.",
  problem: "Selling custom products at scale is a logistics problem. Every quote requires manual back-and-forth — sizing, customization options, shipping calculations, lead times. Sales reps burn hours on quotes that may never close.",
  built: "A configurator that handles the entire quoting process automatically: customer specs in, complete quote with shipping and timeline out. The same system handles customer follow-up and order coordination after the sale.",
  outcomes: [
  ["Automated", "", "sales system"],
  ["0", " sales reps", "needed per quote"],
  ["100", "%", "quotes automated"]],

  url: "https://helmethygiene.com",
  urlLabel: "helmethygiene.com",
  tag: "DTC · MANUFACTURING",
  year: "2026",
  Diagram: DiagramHelmet
},
{
  idx: "III",
  name: "FieldLayer",
  descriptor: "A property operations platform for single-family rental and property-management companies.",
  problem: "Property managers run inspections, work orders, and unit turnovers manually across spreadsheets and disconnected tools. Critical issues fall through the cracks, and labor costs spiral as portfolios grow.",
  built: "An automated layer that coordinates field work end-to-end — inspections, task assignment, vendor coordination, reporting — built on top of an established field inspection network spanning all fifty states and Canada.",
  outcomes: [
  ["<24", "hr", "avg. dispatch + turnaround"],
  ["500", "K+", "field network"],
  ["End-to-end", "", "reporting"]],

  url: "https://fieldlayer.io",
  urlLabel: "fieldlayer.io",
  tag: "WORKFORCE API · REAL ESTATE",
  year: "2026",
  Diagram: DiagramField
}];


function SelectedWork() {
  return (
    <section id="work" className="section frame relative" style={{ background: "var(--bg)" }}>
      <div className="wrap">
        <SectionHeader idx="03" label="SELECTED WORK" right="03 LIVE SYSTEMS · IN PRODUCTION" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20">
          <div className="col-span-12 md:col-span-7">
            <h2 className="display text-[42px] md:text-[64px] lg:text-[80px]" style={{ textWrap: "balance" }}>
              Live systems. <span style={{ color: "var(--accent)" }}>Read the work,</span> not the deck.
            </h2>
          </div>
        </div>

        <Hairline strong />

        <div>
          {WORK.map((w, i) =>
          <WorkCase key={w.idx} {...w} reversed={i % 2 === 1} last={i === WORK.length - 1} />
          )}
        </div>
      </div>
    </section>);

}

function WorkCase({ idx, name, descriptor, problem, built, outcomes, url, urlLabel, tag, year, Diagram, reversed, last }) {
  return (
    <article style={{ borderBottom: last ? "none" : "1px solid var(--rule-strong)" }} className="py-14 md:py-20">
      {/* Header */}
      <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 mb-10 md:mb-14">
        <div className="col-span-12 md:col-span-3 flex md:block items-baseline gap-4 mb-4 md:mb-0">
          <span className="num text-[64px] md:text-[96px]" style={{ color: "var(--ink)", lineHeight: 0.85 }}>{idx}</span>
          <Meta style={{ color: "var(--muted)" }} className="md:block md:mt-4">{year}</Meta>
        </div>
        <div className="col-span-12 md:col-span-9">
          <Meta style={{ color: "var(--accent)" }}>// {tag}</Meta>
          <h3 className="mt-3 display text-[36px] md:text-[56px] lg:text-[72px]" style={{ textWrap: "balance" }}>
            {name}
          </h3>
          <p className="mt-4 text-[18px] md:text-[22px] leading-[1.35] max-w-[44ch]" style={{ color: "var(--ink-2)" }}>
            {descriptor}
          </p>
        </div>
      </div>

      <Hairline />

      {/* Body */}
      <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 gap-y-10 mt-10 md:mt-14">
        {/* Visual */}
        <Reveal className={"col-span-12 lg:col-span-7 " + (reversed ? "lg:order-2" : "")}>
          <Diagram />
        </Reveal>

        {/* Body text */}
        <div className={"col-span-12 lg:col-span-5 " + (reversed ? "lg:order-1" : "")}>
          <div className="space-y-8 md:space-y-10">
            <div>
              <div className="flex items-baseline justify-between mb-3" style={{ borderBottom: "1px solid var(--rule)", paddingBottom: 6 }}>
                <Meta style={{ color: "var(--muted)" }}>// PROBLEM</Meta>
                <Meta style={{ color: "var(--muted)" }}>01</Meta>
              </div>
              <p className="text-[15.5px] leading-[1.65]" style={{ color: "var(--ink)" }}>{problem}</p>
            </div>
            <div>
              <div className="flex items-baseline justify-between mb-3" style={{ borderBottom: "1px solid var(--rule)", paddingBottom: 6 }}>
                <Meta style={{ color: "var(--muted)" }}>// BUILT</Meta>
                <Meta style={{ color: "var(--muted)" }}>02</Meta>
              </div>
              <p className="text-[15.5px] leading-[1.65]" style={{ color: "var(--ink)" }}>{built}</p>
            </div>
            <div>
              <div className="flex items-baseline justify-between mb-4" style={{ borderBottom: "1px solid var(--rule)", paddingBottom: 6 }}>
                <Meta style={{ color: "var(--muted)" }}>// OUTCOME</Meta>
                <Meta style={{ color: "var(--accent)" }}>03</Meta>
              </div>
              <div className="grid grid-cols-3 gap-2">
                {outcomes.map(([v, s, l], oi) => {
                  // Value font sized on its own length; suffix sized independently.
                  // Long suffixes (>3 chars) drop to a second line so the big numeral
                  // stays the visual hero.
                  const vLen = v.length;
                  const sLen = (s || "").trim().length;
                  const vSize =
                    vLen <= 4 ? { mob: 26, desk: 32, tight: "-0.01em" } :
                    vLen <= 7 ? { mob: 22, desk: 28, tight: "-0.02em" } :
                    vLen <= 9 ? { mob: 18, desk: 24, tight: "-0.025em" } :
                                { mob: 15, desk: 22, tight: "-0.03em" };
                  const suffixStacked = sLen > 3;
                  return (
                    <div key={oi} className="py-3 px-3" style={{ background: "var(--bg-2)" }}>
                      <div
                        className="num"
                        style={{
                          color: "var(--accent)",
                          lineHeight: 1,
                          letterSpacing: vSize.tight,
                          fontSize: `clamp(${vSize.mob}px, 3.4vw, ${vSize.desk}px)`,
                          whiteSpace: "nowrap",
                          overflow: "hidden"
                        }}>
                        {v}
                        {s && !suffixStacked && (
                          <span style={{
                            color: "var(--accent)",
                            fontSize: `clamp(13px, 1.6vw, 16px)`,
                            marginLeft: 1
                          }}>{s}</span>
                        )}
                      </div>
                      {s && suffixStacked && (
                        <div className="mt-1" style={{
                          color: "var(--accent)",
                          opacity: 0.75,
                          fontSize: `clamp(11px, 1.4vw, 13px)`,
                          letterSpacing: "0.02em",
                          textTransform: "lowercase",
                          fontVariantNumeric: "tabular-nums"
                        }}>{s.trim()}</div>
                      )}
                      <Meta className="mt-3 block" style={{ color: "var(--muted)" }}>{l}</Meta>
                    </div>
                  );
                })}
              </div>
            </div>
            <div>
              <a href={url} target="_blank" rel="noreferrer" className="btn-ghost">
                <span>{urlLabel}</span>
                <span>↗</span>
              </a>
            </div>
          </div>
        </div>
      </div>
    </article>);

}

/* ============================================================
   PROCESS — system map (4 nodes)
============================================================ */

const STEPS = [
{ kind: "DISCOVER", t: "Discover", duration: "2 WEEKS", d: "A paid two-week diagnostic. We map the workflow, identify the highest-ROI build, and deliver a written plan with estimates and projected impact." },
{ kind: "DESIGN", t: "Design", duration: "1 WEEK", d: "We define the system, integrations, and success metrics in writing. You see the brief before we touch the keyboard." },
{ kind: "BUILD", t: "Build", duration: "6—12 WK", d: "Phased delivery, demos every two weeks. Real data, real environment, short iterations. You own everything on delivery." },
{ kind: "OPERATE", t: "Operate", duration: "MONTHLY", d: "Optional ongoing partnership. We sit alongside your team for optimization, new builds, and strategic advisory." }];


function Process() {
  return (
    <section id="process" className="section frame relative" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <SectionHeader idx="04" label="PROCESS" right="04 PHASES · END-TO-END" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20">
          <div className="col-span-12 md:col-span-7">
            <h2 className="display text-[42px] md:text-[64px] lg:text-[80px]" style={{ textWrap: "balance" }}>
              <span style={{ color: "var(--accent)" }}>The same process</span> we use on our own companies.
            </h2>
          </div>
        </div>

        <Hairline strong />

        {/* System map */}
        <div className="py-10 md:py-16" style={{ background: "var(--bg)", borderBottom: "1px solid var(--rule-strong)" }}>
          <div className="hidden md:block">
            <SystemMap nodes={STEPS} />
          </div>
          {/* mobile: vertical list */}
          <div className="md:hidden">
            {STEPS.map((s, i) =>
            <div key={i} className="p-6 flex gap-4" style={{ borderBottom: i < STEPS.length - 1 ? "1px solid var(--rule)" : "none" }}>
                <span className="num text-[32px]" style={{ color: "var(--ink)" }}>0{i + 1}</span>
                <div className="flex-1">
                  <Meta style={{ color: "var(--accent)" }}>{s.kind}</Meta>
                  <div className="display text-[28px] mt-1">{s.t}</div>
                  <Meta className="mt-2 block" style={{ color: "var(--muted)" }}>{s.duration}</Meta>
                </div>
              </div>
            )}
          </div>
        </div>

        {/* descriptions row */}
        <div className="grid grid-cols-1 md:grid-cols-4">
          {STEPS.map((s, i) =>
          <Reveal key={i} delay={i * 80}
          className="p-7 md:p-8"
          style={{ borderRight: i < 3 ? "1px solid var(--rule)" : "none" }}>
              <div className="flex items-baseline justify-between mb-5">
                <Meta style={{ color: "var(--muted)" }}>// 0{i + 1}</Meta>
                <Meta style={{ color: "var(--accent)" }}>{s.duration}</Meta>
              </div>
              <p className="text-[14.5px] leading-[1.6]" style={{ color: "var(--ink-2)" }}>{s.d}</p>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

/* ============================================================
   AUDIENCES
============================================================ */

function Audiences() {
  return (
    <section id="audiences" className="section frame relative" style={{ background: "var(--bg)" }}>
      <div className="wrap">
        <SectionHeader idx="05" label="WHO WE WORK WITH" right="2 BRIEF TYPES · EQUAL WEIGHT" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20">
          <div className="col-span-12 md:col-span-7">
            <h2 className="display text-[42px] md:text-[64px] lg:text-[80px]" style={{ textWrap: "balance" }}>
              Already in the US. <span style={{ color: "var(--accent)" }}>Or coming to the US.</span>
            </h2>
          </div>
        </div>

        <Hairline strong />

        <div className="grid grid-cols-1 md:grid-cols-2">
          {[
          {
            code: "US",
            region: "UNITED STATES",
            title: "Manufacturers, ecommerce brands, professional services, and SMBs.",
            body: "Operations that have outgrown manual processes. Common signs: you've hired your way to a ceiling, your team is buried in tools, or you're losing deals to slow execution. We build the system that takes the workflow off the floor without breaking what already works.",
            tags: ["MANUFACTURING", "DTC", "PRO SERVICES", "HEALTHCARE", "REAL ESTATE"]
          },
          {
            code: "INTL",
            region: "ENTERING THE US",
            title: "International brands launching stateside.",
            body: "Proven products that need credible US-facing infrastructure to sell. We build the operational stack — storefront, configurator, support, marketing automation — so a small founder-led team can run a serious US business from day one.",
            tags: ["EU → US", "ASIA → US", "LATAM → US", "FOUNDER-LED"]
          }].
          map((a, i) =>
          <Reveal key={a.code} delay={i * 100} className="p-8 md:p-12"
          style={{ borderRight: i === 0 ? "1px solid var(--rule-strong)" : "none", minHeight: 460 }}>
              <div className="flex items-baseline justify-between mb-10 md:mb-14">
                <div className="num text-[64px] md:text-[88px]" style={{ color: "var(--ink)", lineHeight: 0.85 }}>{a.code}</div>
                <Meta style={{ color: "var(--accent)" }}>// {a.region}</Meta>
              </div>
              <h3 className="display text-[26px] md:text-[34px] leading-[1.05]" style={{ textWrap: "balance" }}>{a.title}</h3>
              <p className="mt-5 text-[15px] leading-[1.65] max-w-[46ch]" style={{ color: "var(--ink-2)" }}>{a.body}</p>
              <div className="mt-8 pt-5 flex flex-wrap gap-2" style={{ borderTop: "1px solid var(--rule)" }}>
                {a.tags.map((t) =>
              <span key={t} className="meta px-2 py-1.5" style={{ border: "1px solid var(--rule-strong)", color: "var(--ink-2)" }}>{t}</span>
              )}
              </div>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

/* ============================================================
   STUDIO
============================================================ */

function Studio() {
  return (
    <section id="studio" className="section frame relative" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <SectionHeader idx="06" label="THE STUDIO" right="OPERATOR-LED · 1 PRINCIPAL" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 gap-y-12 py-14 md:py-20 items-start">
          <Reveal className="col-span-12 lg:col-span-7">
            <MediaArea
              tint="ink"
              labelTL="// PRINCIPAL"
              labelTR="EST · 2024"
              labelBL="FIG.04"
              labelBR="IRVINE · CA"
            >
              <img
                src="assets/principal.jpg"
                alt="Compound principal — founder portrait"
                loading="lazy"
                style={{
                  width: "100%",
                  maxWidth: 620,
                  height: "auto",
                  display: "block",
                  borderRadius: 12,
                  border: "1px solid rgba(255,255,255,0.10)",
                  boxShadow: "0 30px 60px -20px rgba(0,0,0,0.55), 0 1px 0 rgba(255,255,255,0.08) inset"
                }}
              />
            </MediaArea>
          </Reveal>

          <Reveal className="col-span-12 lg:col-span-5" delay={100}>
            <Meta style={{ color: "var(--muted)" }}>// 06.01 / CARTER DEMORE, FOUNDER</Meta>
            <p className="mt-6 display-thin text-[26px] md:text-[34px] lg:text-[38px] leading-[1.18]" style={{ textWrap: "balance" }}>
              I'm an entrepreneur running a portfolio of operating companies. Compound is where I bring the AI systems we've built for ourselves to other operators working on problems worth shipping.
            </p>

            <div className="mt-8 md:mt-10 flex items-center gap-5" style={{ borderTop: "1px solid var(--rule-strong)", paddingTop: 20 }}>
              <div style={{ fontFamily: "Helvetica Neue, Helvetica, Inter Tight", fontStyle: "italic", fontSize: 22, letterSpacing: "-0.02em" }}>— Compound Studio</div>
              <Hairline className="flex-1 max-w-[120px]" strong />
              <Meta style={{ color: "var(--muted)" }}>FOUNDER</Meta>
            </div>

            <dl className="mt-8 md:mt-10 max-w-[420px]">
              <div className="metarow"><dt className="k">Founded</dt><dd className="v">2024</dd></div>
              <div className="metarow"><dt className="k">Studio</dt><dd className="v">Irvine, CA</dd></div>
            </dl>
          </Reveal>
        </div>
      </div>
    </section>);

}

/* ============================================================
   FAQ
============================================================ */

const FAQS = [
{ q: "How is Compound different from other AI shops?",
  a: "We are operators first. Every system we offer to outside clients has already been deployed inside one of our own companies. By the time it reaches you, it's been on call inside a real P&L for a quarter." },
{ q: "How do you know we're ready for AI?",
  a: "You're ready if there's a workflow somebody has been hand-running for two or three years: a quote, a claim, an onboarding packet, a second draft of the same email. That's where AI earns its keep." },
{ q: "What happens after you ship?",
  a: "We don't hand off and vanish. We sit alongside your team, monitor how the system is actually used, and refine it until it runs smoothly without us." },
{ q: "How much internal time will this take?",
  a: "You hired us to take work off the floor, not add to it. We keep your team's involvement focused: enough to capture what matters, and we handle the rest." },
{ q: "How long until we see real results?",
  a: "A working pilot inside weeks, not months. We move fast, test early on real data, and scale only once it's proven." },
{ q: "We've already tried AI and it didn't work. Why would this be different?",
  a: "Most teams fail because they start with the wrong use cases, or stop at the prototype. We only pick up briefs worth building, and we stay through adoption so the work actually ships." }];


function Faq() {
  return (
    <section id="faq" className="section frame relative" style={{ background: "var(--bg)" }}>
      <div className="wrap">
        <SectionHeader idx="07" label="FAQ" right="06 ANSWERS · LIVE INDEX" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20">
          <div className="col-span-12 md:col-span-4">
            <h2 className="display text-[42px] md:text-[60px] lg:text-[72px]" style={{ textWrap: "balance" }}>
              Questions <span style={{ color: "var(--accent)" }}>worth answering.</span>
            </h2>
          </div>

          <div className="col-span-12 md:col-span-7 md:col-start-6 mt-10 md:mt-0">
            <Hairline strong />
            {FAQS.map((f, i) =>
            <Reveal key={i} delay={i * 30}>
                <details>
                  <summary className="py-6 md:py-7 flex items-start justify-between gap-6 group">
                    <span className="flex items-baseline gap-4">
                      <Meta style={{ color: "var(--muted)" }} className="tnum">0{i + 1}</Meta>
                      <span className="text-[18px] md:text-[20px] leading-[1.3] tracking-tight font-medium">
                        {f.q}
                      </span>
                    </span>
                    <span className="chev mt-1 select-none text-[20px]" style={{ color: "var(--accent)" }}>+</span>
                  </summary>
                  <div className="ans pb-7 pl-[42px] max-w-[640px] text-[15px] leading-[1.65]" style={{ color: "var(--ink-2)" }}>
                    {f.a}
                  </div>
                </details>
                <Hairline />
              </Reveal>
            )}
          </div>
        </div>
      </div>
    </section>);

}

/* ============================================================
   CONTACT
============================================================ */

function Contact() {
  const [form, setForm] = React.useState({ name: "", email: "", building: "", website: "" });
  const [sent, setSent] = React.useState(false);
  const [errors, setErrors] = React.useState({});
  const [submitting, setSubmitting] = React.useState(false);
  const [serverError, setServerError] = React.useState("");

  const onSubmit = async (e) => {
    e.preventDefault();
    if (submitting) return;
    const next = {};
    if (!form.name.trim()) next.name = "REQUIRED";
    if (!form.email.trim() || !/^\S+@\S+\.\S+$/.test(form.email)) next.email = "INVALID EMAIL";
    if (!form.building.trim() || form.building.trim().length < 12) next.building = "A SENTENCE OR TWO";
    setErrors(next);
    if (Object.keys(next).length > 0) return;

    setSubmitting(true);
    setServerError("");
    try {
      const r = await fetch("/api/contact", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          name: form.name.trim(),
          email: form.email.trim(),
          building: form.building.trim(),
          website: form.website
        })
      });
      if (!r.ok) {
        const data = await r.json().catch(() => ({}));
        throw new Error(data.error || "SEND_FAILED");
      }
      setSent(true);
    } catch (err) {
      setServerError("Couldn't send your note. Please try again in a moment.");
    } finally {
      setSubmitting(false);
    }
  };

  return (
    <section id="contact" className="section frame relative" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <SectionHeader idx="08" label="CONTACT" />

        <div className="grid grid-cols-12 gap-x-6 md:gap-x-10 py-14 md:py-20" data-comment-anchor="e90d7d1576-div-665-9">
          <div className="col-span-12 md:col-span-5">
            <h2 className="display text-[44px] md:text-[60px] lg:text-[76px]" style={{ textWrap: "balance" }}>
              Start a <span style={{ color: "var(--accent)" }}>conversation.</span>
            </h2>
            <p className="mt-6 text-[15.5px] leading-[1.65] max-w-[42ch]" style={{ color: "var(--ink-2)" }}>
              We take on a limited number of engagements each quarter. Tell us what you're working on — a few sentences is enough. We read every note personally and reply within two business days.
            </p>

            <dl className="mt-10 max-w-[420px]">
              <div className="metarow"><dt className="k">Reply</dt><dd className="v">≤ 2 business days</dd></div>
              <div className="metarow"><dt className="k">Location</dt><dd className="v">Irvine, California</dd></div>
            </dl>
          </div>

          <Reveal className="col-span-12 md:col-span-6 md:col-start-7 mt-10 md:mt-0" delay={100}>
            {sent ?
            <div className="p-8 md:p-10" style={{ background: "var(--bg)", border: "1px solid var(--rule-strong)" }}>
                <Meta style={{ color: "var(--accent)" }}>● RECEIVED · {new Date().toLocaleDateString()}</Meta>
                <h3 className="mt-5 display text-[32px] md:text-[40px] leading-[1.05]">
                  Thanks, {form.name.split(" ")[0] || "operator"}. We'll be in touch within two business days.
                </h3>
                <p className="mt-5 text-[14.5px] leading-[1.6]" style={{ color: "var(--ink-2)" }}>
                  Replies come from a real inbox, not an automation.
                </p>
              </div> :

            <form onSubmit={onSubmit} className="p-8 md:p-10" style={{ background: "var(--bg)", border: "1px solid var(--rule-strong)" }} noValidate>
                <div className="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-2">
                  <Field label="Name" name="name" form={form} setForm={setForm} placeholder="Your full name" error={errors.name} />
                  <Field label="Email" name="email" form={form} setForm={setForm} placeholder="you@company.com" error={errors.email} />
                </div>
                <div className="mt-6">
                  <Field label="What you're trying to build" name="building" form={form} setForm={setForm}
                placeholder="A short note about the workflow or system you have in mind." error={errors.building} textarea />
                </div>
                {/* honeypot — must stay empty; hidden from humans */}
                <div aria-hidden="true" style={{ position: "absolute", left: "-10000px", top: "auto", width: 1, height: 1, overflow: "hidden" }}>
                  <label>
                    Leave blank
                    <input
                      type="text"
                      tabIndex={-1}
                      autoComplete="off"
                      value={form.website}
                      onChange={(e) => setForm({ ...form, website: e.target.value })} />
                  </label>
                </div>
                <div className="mt-8 flex items-center justify-between gap-4">
                  <div className="meta" style={{ color: "var(--accent)", minHeight: 14 }}>
                    {serverError}
                  </div>
                  <button type="submit" className="btn" disabled={submitting} aria-busy={submitting}>
                    <span>{submitting ? "Sending…" : "Send note"}</span>
                    <span className="arrow">→</span>
                  </button>
                </div>
              </form>
            }
          </Reveal>
        </div>
      </div>
    </section>);

}

function Field({ label, name, form, setForm, placeholder, error, textarea }) {
  return (
    <div>
      <label className="meta block mb-1" style={{ color: "var(--muted)" }}>// {label.toUpperCase()}</label>
      {textarea ?
      <textarea className="field" value={form[name]}
      onChange={(e) => setForm({ ...form, [name]: e.target.value })} placeholder={placeholder} /> :

      <input className="field" type={name === "email" ? "email" : "text"} value={form[name]}
      onChange={(e) => setForm({ ...form, [name]: e.target.value })} placeholder={placeholder} />
      }
      <div className="meta mt-2" style={{ color: error ? "var(--accent)" : "transparent", minHeight: 14 }}>
        {error || "_"}
      </div>
    </div>);

}

/* ============================================================
   FOOTER + MARQUEE
============================================================ */

function FooterMarquee() {
  const items = [
  "AI SYSTEMS STUDIO",
  "★",
  "OPERATOR-LED",
  "★",
  "BUILT FOR OUR OWN P&L FIRST",
  "★",
  "IRVINE, CALIFORNIA",
  "★",
  "U.S. & INTERNATIONAL OPERATORS",
  "★"];

  const track = [...items, ...items, ...items];
  return (
    <div className="frame relative overflow-hidden" style={{ background: "var(--ink)", color: "var(--bg)", borderTop: "1px solid var(--rule-strong)" }}>
      <div className="py-5 md:py-8">
        <div className="marquee-track">
          {track.map((t, i) =>
          <span key={i} className={i % 2 === 1 ? "mono text-[14px]" : "display text-[28px] md:text-[44px]"}
          style={{ color: t === "★" ? "var(--accent)" : "var(--bg)" }}>
              {t}
            </span>
          )}
        </div>
      </div>
    </div>);

}

function Footer() {
  return (
    <footer className="frame relative" style={{ background: "var(--bg)", borderTop: "1px solid var(--rule-strong)" }}>
      <div className="wrap">
        <div className="grid grid-cols-12 gap-6 py-12 md:py-16">
          <div className="col-span-12 md:col-span-4">
            <div className="flex items-center gap-3 mb-5">
              <Mark size={20} style={{ color: "var(--ink)" }} />
              <span className="text-[20px] font-medium tracking-tight">Compound</span>
            </div>
            <Meta style={{ color: "var(--muted)" }}>AI SYSTEMS STUDIO · IRVINE, CA</Meta>
          </div>

          <div className="col-span-6 md:col-span-2">
            <Meta style={{ color: "var(--muted)" }}>// NAV</Meta>
            <div className="mt-4 flex flex-col gap-2">
              {[["Thesis", "#thesis"], ["Build", "#build"], ["Work", "#work"], ["Process", "#process"], ["Studio", "#studio"], ["FAQ", "#faq"]].map(([l, h]) =>
              <a key={l} href={h} className="link-x text-[14px]">{l}</a>
              )}
            </div>
          </div>

          <div className="col-span-6 md:col-span-2">
            <Meta style={{ color: "var(--muted)" }}>// WORK</Meta>
            <div className="mt-4 flex flex-col gap-2">
              {[["appealio.co", "https://appealio.co"], ["helmethygiene.com", "https://helmethygiene.com"], ["fieldlayer.io", "https://fieldlayer.io"]].map(([l, h]) =>
              <a key={l} href={h} target="_blank" rel="noreferrer" className="link-x text-[14px]">{l} <span className="arrow-text">↗</span></a>
              )}
            </div>
          </div>

          <div className="col-span-12 md:col-span-4">
            <Meta style={{ color: "var(--muted)" }}>// CONTACT</Meta>
            <div className="mt-4">
              <a href="#contact" className="link-x text-[20px] md:text-[24px] tracking-tight">Start a conversation →</a>
              <div className="mt-2 meta" style={{ color: "var(--muted)" }}>REPLIES WITHIN 2 BUSINESS DAYS</div>
            </div>
          </div>
        </div>

        <Hairline strong />

        <div className="py-6 flex flex-wrap items-baseline justify-between gap-y-3">
          <Meta style={{ color: "var(--muted)" }}>© {new Date().getFullYear()} COMPOUND STUDIO LLC</Meta>
          <Meta style={{ color: "var(--muted)" }}><LiveClock /> · IRVINE, CA</Meta>
        </div>
      </div>
    </footer>);

}

/* ============================================================
   Section header — shared component
============================================================ */

function SectionHeader({ idx, label, right }) {
  return (
    <div className="pt-8 md:pt-10 pb-2" style={{ borderTop: "1px solid var(--rule-strong)" }}>
      <div className="flex items-baseline justify-between gap-4">
        <div className="flex items-baseline gap-4">
          <span className="num text-[22px]" style={{ color: "var(--accent)" }}>§ {idx}</span>
          <Meta large style={{ color: "var(--ink)" }}>{label}</Meta>
        </div>
        <Meta className="hidden md:inline" style={{ color: "var(--muted)" }}>{right}</Meta>
      </div>
    </div>);

}

/* expose */
Object.assign(window, {
  MetaStrip, TopNav, Hero, Thesis, WhatWeBuild, SelectedWork, Process,
  Audiences, Studio, Faq, Contact, FooterMarquee, Footer, SectionHeader, HEADLINES
});