const { useEffect, useRef, useState } = React;

// ---------- Tiny icon set (inline SVG, hairline, matches type weight) ----------
const I = {
  arrow: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12h14"/><path d="m13 5 7 7-7 7"/></svg>
  ),
  spark: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3v4"/><path d="M12 17v4"/><path d="M3 12h4"/><path d="M17 12h4"/><path d="m5.6 5.6 2.8 2.8"/><path d="m15.6 15.6 2.8 2.8"/><path d="m5.6 18.4 2.8-2.8"/><path d="m15.6 8.4 2.8-2.8"/></svg>
  ),
  channels: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="4" width="18" height="13" rx="2.5"/><path d="M7 21h10"/><path d="M9 17v4"/><path d="M15 17v4"/><path d="M8 9h8"/><path d="M8 13h5"/></svg>
  ),
  plug: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M9 2v4"/><path d="M15 2v4"/><path d="M6 6h12v4a6 6 0 0 1-12 0z"/><path d="M12 16v6"/></svg>
  ),
  gauge: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z"/><path d="M12 14V8"/><path d="M3.5 16a9 9 0 1 1 17 0"/></svg>
  ),
  pilot: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12a7 7 0 0 1 14 0"/><circle cx="12" cy="12" r="2"/><path d="M12 19v3"/><path d="M9 22h6"/></svg>
  ),
  check: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m5 12 4 4 10-10"/></svg>
  ),
  alert: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M10.3 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
  ),
  cycle: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 12a9 9 0 1 1-3.5-7.1"/><path d="M21 4v5h-5"/></svg>
  ),
  doc: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M9 13h6"/><path d="M9 17h4"/></svg>
  ),
  shield: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"/><path d="m9 12 2 2 4-4"/></svg>
  ),
  search: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg>
  ),
};

// ---------- Reveal-on-scroll wrapper ----------
function Reveal({ children, className = "", delay = 0 }) {
  return <div className={`reveal ${className}`} style={{ animationDelay: `${delay}ms` }}>{children}</div>;
}

// ---------- Top nav ----------
function Nav() {
  return (
    <header className="sticky top-0 z-40 glass border-b border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-3.5 flex items-center justify-between">
        <a href="#top" className="flex items-center gap-2.5 group">
          <Logo />
          <span className="text-[15px] tracking-tight font-medium">GPTFrame</span>
          <span className="hidden sm:inline text-[11px] font-mono text-ink-500 tracking-widest ml-1">v0 · PILOT</span>
        </a>
        <nav className="hidden md:flex items-center gap-7 text-[14px] text-ink-300">
          <a href="#how" className="quiet">How it works</a>
          <a href="#pillars" className="quiet">Pillars</a>
          <a href="#evaluation" className="quiet">Evaluation</a>
          <a href="#pilot" className="quiet">Pilot</a>
        </nav>
        <a href="#enquiry" className="inline-flex items-center gap-2 rounded-full btn-primary text-[13.5px] font-medium px-4 py-2">
          Discuss a pilot <I.arrow className="h-4 w-4"/>
        </a>
      </div>
    </header>
  );
}

function Logo() {
  // Minimal "frame" mark: square bracket framing a node
  return (
    <svg width="22" height="22" viewBox="0 0 22 22" fill="none" aria-hidden>
      <rect x="1.25" y="1.25" width="19.5" height="19.5" rx="5" stroke="currentColor" strokeOpacity="0.45" strokeWidth="1.1"/>
      <path d="M6 5.5H4.5A1.5 1.5 0 0 0 3 7v2" stroke="oklch(0.78 0.14 220)" strokeWidth="1.4" strokeLinecap="round"/>
      <path d="M16 5.5h1.5A1.5 1.5 0 0 1 19 7v2" stroke="oklch(0.78 0.14 220)" strokeWidth="1.4" strokeLinecap="round"/>
      <path d="M6 16.5H4.5A1.5 1.5 0 0 1 3 15v-2" stroke="oklch(0.78 0.14 220)" strokeWidth="1.4" strokeLinecap="round"/>
      <path d="M16 16.5h1.5A1.5 1.5 0 0 0 19 15v-2" stroke="oklch(0.78 0.14 220)" strokeWidth="1.4" strokeLinecap="round"/>
      <circle cx="11" cy="11" r="2.6" fill="oklch(0.96 0.005 250)"/>
    </svg>
  );
}

// ---------- Hero ----------
function Hero() {
  return (
    <section id="top" className="relative overflow-hidden noise">
      <div className="absolute inset-0 aurora pointer-events-none" />
      <div className="absolute inset-0 grid-dots opacity-60 [mask-image:radial-gradient(70%_60%_at_50%_30%,black,transparent)] pointer-events-none" />
      <div className="relative mx-auto max-w-6xl px-6 pt-24 md:pt-32 pb-20 md:pb-28">
        <Reveal>
          <div className="flex items-center gap-3 mb-7">
            <span className="label-mono tick">Assistant infrastructure</span>
            <span className="hidden sm:inline text-ink-600 font-mono text-[11px]">/</span>
            <span className="hidden sm:inline label-mono">Multi-channel · Model-agnostic · Eval-first</span>
          </div>
        </Reveal>

        <Reveal delay={80}>
          <h1 className="max-w-5xl text-[44px] sm:text-[58px] md:text-[76px] leading-[0.98] tracking-[-0.025em] font-medium">
            You focus on the assistant.<br/>
            <span className="text-ink-400">We handle the </span>
            <span className="italic font-serif text-ink-100">deployment layer</span>
            <span className="text-ink-400">.</span>
          </h1>
        </Reveal>

        <Reveal delay={160}>
          <p className="mt-9 max-w-2xl text-[17px] md:text-[18px] leading-[1.65] text-ink-300">
            GPTFrame helps teams deploy custom AI assistants into the channels their audiences already use — with model flexibility, operational support, and evaluation loops that show what works, what fails, and what to improve next.
          </p>
        </Reveal>

        <Reveal delay={240}>
          <div className="mt-10 flex flex-col sm:flex-row gap-3">
            <a href="#enquiry" className="inline-flex items-center justify-center gap-2 rounded-full btn-primary text-[14.5px] font-medium px-5 py-3">
              Discuss a pilot <I.arrow className="h-4 w-4"/>
            </a>
            <a href="#how" className="inline-flex items-center justify-center gap-2 rounded-full text-[14.5px] text-ink-100 px-5 py-3 hairline hover:bg-white/[0.04] transition">
              See how it works
            </a>
          </div>
        </Reveal>

        <Reveal delay={320}>
          <div className="mt-16 grid grid-cols-2 md:grid-cols-4 gap-y-6 gap-x-10 text-[13px]">
            {[
              ["WhatsApp · Telegram · Web · Slack", "Channels"],
              ["OpenAI · Claude · Gemini · OpenRouter", "Models"],
              ["Review · Detect · Iterate · Audit", "Evaluation"],
              ["One assistant · One audience · One channel", "Pilot"],
            ].map(([v, k]) => (
              <div key={k} className="flex flex-col gap-1.5">
                <div className="label-mono">{k}</div>
                <div className="text-ink-200 leading-snug">{v}</div>
              </div>
            ))}
          </div>
        </Reveal>
      </div>
    </section>
  );
}

// ---------- Architecture diagram ----------
function Architecture() {
  // Three-column diagram: ASSISTANT -> GPTFRAME -> CHANNELS, with animated wires.
  const channels = [
    { name: "WhatsApp", note: "1:1 + groups" },
    { name: "Telegram", note: "1:1 + groups" },
    { name: "Web chat",  note: "embedded" },
    { name: "Slack",    note: "workspace" },
    { name: "Custom",   note: "via API"   },
  ];
  const sources = [
    { name: "System prompt", note: "behavior, tone" },
    { name: "Knowledge files", note: "RAG inputs" },
    { name: "Model setup", note: "your provider or agreed pilot usage" },
    { name: "Guardrails",    note: "safe limits"   },
  ];

  return (
    <section id="how" className="relative border-t border-white/[0.06]">
      <div className="absolute inset-0 grid-lines opacity-30 [mask-image:radial-gradient(75%_60%_at_50%_50%,black,transparent)] pointer-events-none" />
      <div className="relative mx-auto max-w-6xl px-6 py-24 md:py-32">
        <Reveal>
          <div className="flex items-end justify-between flex-wrap gap-4 mb-12">
            <div className="max-w-2xl">
              <div className="label-mono tick mb-4">The system</div>
              <h2 className="text-[34px] md:text-[46px] tracking-tight font-medium leading-[1.05]">
                Assistant <span className="text-ink-500">→</span> GPTFrame <span className="text-ink-500">→</span> wherever your users are.
              </h2>
              <p className="mt-5 text-ink-300 text-[16px] leading-relaxed">
                GPTFrame sits between your assistant and the real world: channels, model providers, hosting, routing, operations, and evaluation.
              </p>
            </div>
            <div className="hidden md:flex items-center gap-2 label-mono">
              <span className="h-px w-8 bg-white/15"/> Diagram · simplified
            </div>
          </div>
        </Reveal>

        <Reveal delay={120}>
          <DiagramFrame sources={sources} channels={channels} />
        </Reveal>
      </div>
    </section>
  );
}

function DiagramFrame({ sources, channels }) {
  return (
    <div className="relative rounded-[28px] hairline-strong bg-gradient-to-b from-white/[0.025] to-transparent p-5 md:p-8">
      {/* Mono caption bar */}
      <div className="flex items-center justify-between text-[11px] font-mono text-ink-500 mb-6 px-1">
        <div className="flex items-center gap-2">
          <span className="inline-flex h-2 w-2 rounded-full bg-accent shadow-[0_0_0_4px_oklch(0.78_0.14_220/0.18)]"/>
          msg.flow / inbound + outbound
        </div>
        <div className="tracking-widest">TLS · QUEUE · ROUTER · EVAL</div>
      </div>

      <div className="grid grid-cols-1 md:grid-cols-[1fr_1.1fr_1fr] gap-6 md:gap-4 items-stretch">
        {/* ASSISTANT column */}
        <DiagColumn title="Assistant" subtitle="Defined by you">
          {sources.map((s) => (
            <DiagItem key={s.name} label={s.name} note={s.note} side="left"/>
          ))}
        </DiagColumn>

        {/* CENTER: GPTFrame node */}
        <div className="relative flex md:items-center justify-center">
          <CenterNode />
          <Wires direction="left" />
          <Wires direction="right" />
        </div>

        {/* CHANNELS column */}
        <DiagColumn title="Channels" subtitle="Where users already are" align="right">
          {channels.map((c) => (
            <DiagItem key={c.name} label={c.name} note={c.note} side="right"/>
          ))}
        </DiagColumn>
      </div>

      {/* Bottom indicator strip */}
      <div className="mt-7 grid grid-cols-2 md:grid-cols-4 gap-3">
        {[
          ["Inbound", "encrypt → queue → route"],
          ["Model call", "chosen provider setup"],
          ["Outbound", "channel-specific render"],
          ["Usage signals", "reviewed for improvement"],
        ].map(([k, v]) => (
          <div key={k} className="rounded-xl bg-white/[0.025] hairline px-4 py-3">
            <div className="label-mono mb-1">{k}</div>
            <div className="font-mono text-[12px] text-ink-200">{v}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

function DiagColumn({ title, subtitle, align = "left", children }) {
  return (
    <div className={`rounded-2xl bg-white/[0.02] hairline p-4 md:p-5 ${align === 'right' ? 'md:text-right' : ''}`}>
      <div className="flex items-center justify-between mb-4">
        <div>
          <div className="col-head">{title}</div>
          <div className="text-[13px] text-ink-400 mt-1">{subtitle}</div>
        </div>
        <span className="hidden md:inline-flex h-7 w-7 items-center justify-center rounded-md bg-white/[0.04] hairline">
          <span className="h-1.5 w-1.5 rounded-full bg-accent"/>
        </span>
      </div>
      <div className="space-y-2.5">
        {children}
      </div>
    </div>
  );
}

function DiagItem({ label, note, side }) {
  return (
    <div className={`group flex items-center gap-3 rounded-xl bg-white/[0.03] hairline px-3.5 py-3 ${side==='right' ? 'md:flex-row-reverse md:text-right' : ''}`}>
      <span className={`h-1.5 w-1.5 rounded-full ${side==='right' ? 'bg-warn' : 'bg-accent'}`}/>
      <div className="flex-1 min-w-0">
        <div className="text-[14px] text-ink-100">{label}</div>
        <div className="font-mono text-[11px] text-ink-500 mt-0.5">{note}</div>
      </div>
    </div>
  );
}

function CenterNode() {
  return (
    <div className="relative z-10 w-full max-w-[260px] aspect-square mx-auto">
      <div className="absolute inset-0 rounded-[22px] bg-gradient-to-br from-white/[0.06] to-white/[0.01] hairline-strong" />
      <div className="absolute inset-2 rounded-[18px] grid-dots opacity-50 [mask-image:radial-gradient(70%_70%_at_50%_50%,black,transparent)]" />
      <div className="absolute inset-0 flex flex-col items-center justify-center px-5 text-center">
        <Logo />
        <div className="mt-3 font-mono text-[10px] tracking-[0.22em] text-ink-500">GPTFRAME · CORE</div>
        <div className="mt-3 text-[15px] text-ink-100 leading-snug">
          Routing, hosting,<br/>operations & evaluation
        </div>
        <div className="mt-4 flex items-center gap-1.5">
          {[0,1,2].map(i => (
            <span key={i} className="h-1 w-1 rounded-full bg-accent" style={{animation: `pulseBlink 1.6s ${i*0.2}s ease-in-out infinite`}}/>
          ))}
        </div>
      </div>
      <style>{`@keyframes pulseBlink { 0%,100%{opacity:.25} 50%{opacity:1}}`}</style>
    </div>
  );
}

function Wires({ direction }) {
  // Animated dashed wires fanning from center node toward column.
  const isLeft = direction === 'left';
  const offsets = [-60, -30, 0, 30, 60];
  return (
    <svg
      className="absolute top-0 bottom-0 hidden md:block pointer-events-none"
      style={{ [isLeft ? 'left' : 'right']: '-12px', width: 60, height: '100%' }}
      viewBox="0 0 60 200" preserveAspectRatio="none"
    >
      {offsets.map((o, i) => {
        // All flow left → right on screen, regardless of side.
        // Left side: y spreads on the column (left), converges at center (right)
        // Right side: y is centered at the center (left), spreads at channels (right)
        const x1 = 0, x2 = 60;
        const y1 = isLeft ? 100 + o * 1.4 : 100;
        const y2 = isLeft ? 100 : 100 + o * 1.4;
        return (
          <path
            key={i}
            d={`M${x1} ${y1} C ${x1 + 30} ${y1}, ${x2 - 30} ${y2}, ${x2} ${y2}`}
            stroke="oklch(0.78 0.14 220 / 0.45)"
            strokeWidth="1"
            fill="none"
            className="wire-anim"
            style={{ animationDelay: `${i * 0.18}s` }}
          />
        );
      })}
    </svg>
  );
}

// ---------- Wedge / "you focus / we handle" ----------
function Wedge() {
  const yours = ["Assistant logic", "Knowledge & data", "Brand voice & policy"];
  const ours  = [
    "Channel integration",
    "Model & API routing",
    "Hosting & operation",
    "Evaluation & iteration",
    "Guardrail audit",
  ];
  return (
    <section className="relative border-t border-white/[0.06] bg-white/[0.012]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-28">
        <Reveal>
          <div className="grid md:grid-cols-2 gap-10 md:gap-16">
            <div>
              <div className="label-mono tick mb-4">The wedge</div>
              <h2 className="text-[34px] md:text-[44px] tracking-tight font-medium leading-[1.05]">
                The hard part is not imagining the assistant. <span className="text-ink-500">It is getting it used.</span>
              </h2>
              <p className="mt-5 text-ink-300 text-[16px] leading-relaxed">
                Most teams can describe the assistant they want. The friction begins when that assistant needs to run in a real channel, with real users, real constraints, and a way to know whether it is actually helping.
              </p>
              <p className="mt-4 text-ink-300 text-[16px] leading-relaxed">
                GPTFrame handles that deployment and evaluation layer — so the team can focus on the assistant's value, not the plumbing.
              </p>
            </div>
            <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
              <Stack title="You" items={yours} accent="warm"/>
              <Stack title="GPTFrame" items={ours} accent="cool"/>
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function Stack({ title, items, accent }) {
  return (
    <div className="rounded-2xl bg-white/[0.025] hairline p-4">
      <div className="flex items-center justify-between mb-3">
        <div className="col-head">{title}</div>
        <span className={`h-1.5 w-1.5 rounded-full ${accent==='cool' ? 'bg-accent' : 'bg-warn'}`}/>
      </div>
      <ul className="space-y-2">
        {items.map((i) => (
          <li key={i} className="flex items-center gap-2.5 rounded-lg bg-white/[0.02] hairline px-3 py-2.5">
            <I.check className={`h-4 w-4 ${accent==='cool' ? 'text-accent' : 'text-warn'}`} />
            <span className="text-[14px] text-ink-100">{i}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}

// ---------- Pillars ----------
function Pillars() {
  const items = [
    {
      icon: I.channels,
      kicker: "01",
      title: "Multi-channel deployment",
      body: "Deploy one assistant across the channels your audience already uses — WhatsApp, Telegram, web chat, Slack, or a custom interface — without re-implementing each integration.",
      bullet: ["1:1 + group conversations", "Channel-aware rendering", "Add channels as the pilot proves out"],
    },
    {
      icon: I.plug,
      kicker: "02",
      title: "Model-agnostic backend",
      body: "Bring the model and API account that fits the use case. Optimize for quality, cost, privacy, or latency without rebuilding the assistant.",
      bullet: ["OpenAI · Claude · Gemini · OpenRouter", "Use your own provider account, or agree pilot usage billing", "Swap models without rewiring"],
    },
    {
      icon: I.gauge,
      kicker: "03",
      title: "Evaluation-first operation",
      body: "Every assistant should be measured, reviewed, and improved. Launch is the start of the loop, not the end.",
      bullet: ["Conversation review", "Failure pattern detection", "Prompt & version iteration"],
    },
    {
      icon: I.pilot,
      kicker: "04",
      title: "Pilot-first validation",
      body: "Start with one assistant, one audience, one channel, and explicit success criteria. The goal is not to launch big — it is to learn fast.",
      bullet: ["~1 week to first live setup", "Defined exit criteria", "No long-term lock-in"],
    },
  ];
  return (
    <section id="pillars" className="relative border-t border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-32">
        <Reveal>
          <div className="max-w-3xl mb-12">
            <div className="label-mono tick mb-4">Four pillars</div>
            <h2 className="text-[34px] md:text-[46px] tracking-tight font-medium leading-[1.05]">
              A small, opinionated stack — built around the things that actually break.
            </h2>
          </div>
        </Reveal>

        <div className="grid md:grid-cols-2 gap-5">
          {items.map((p, idx) => (
            <Reveal key={p.title} delay={idx*60}>
              <div className="card-hover h-full rounded-2xl bg-white/[0.025] hairline p-6 md:p-7 flex flex-col">
                <div className="flex items-start justify-between mb-5">
                  <div className="flex items-center gap-3">
                    <span className="num-ring inline-flex items-center justify-center h-10 w-10 rounded-xl text-accent">
                      <p.icon className="h-5 w-5" />
                    </span>
                    <div className="label-mono">PILLAR · {p.kicker}</div>
                  </div>
                </div>
                <h3 className="text-[22px] md:text-[24px] tracking-tight font-medium leading-tight">{p.title}</h3>
                <p className="mt-3 text-ink-300 text-[15px] leading-relaxed">{p.body}</p>
                <ul className="mt-5 space-y-1.5">
                  {p.bullet.map((b) => (
                    <li key={b} className="flex items-center gap-2.5 text-[13.5px] text-ink-200">
                      <span className="h-1 w-1 rounded-full bg-accent"/>
                      <span>{b}</span>
                    </li>
                  ))}
                </ul>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

// ---------- Channels & Models ----------
function ChannelsModels() {
  const channels = ["WhatsApp", "Telegram", "Web chat", "Slack", "Custom channels"];
  const models   = ["OpenAI", "Claude", "Gemini", "OpenRouter", "Client-owned APIs"];
  return (
    <section className="relative border-t border-white/[0.06] bg-white/[0.012]">
      <div className="mx-auto max-w-6xl px-6 py-20 md:py-24">
        <div className="grid md:grid-cols-2 gap-10">
          <Reveal>
            <div>
              <div className="label-mono mb-3">Supported channels</div>
              <h3 className="text-[22px] tracking-tight font-medium">Start with one. Expand when the assistant proves value.</h3>
              <div className="mt-5 flex flex-wrap gap-2.5">
                {channels.map((c) => <span key={c} className="tag"><span className="dot"/>{c}</span>)}
              </div>
              <p className="mt-5 text-[13px] text-ink-500 max-w-md leading-relaxed">
                Some channels rely on third-party platforms whose policies, rate-limits, and availability can change. We flag those before deployment.
              </p>
            </div>
          </Reveal>
          <Reveal delay={80}>
            <div>
              <div className="label-mono mb-3">Model flexibility</div>
              <h3 className="text-[22px] tracking-tight font-medium">Avoid locking the assistant to a single vendor.</h3>
              <div className="mt-5 flex flex-wrap gap-2.5">
                {models.map((m) => <span key={m} className="tag"><span className="dot" style={{background:'oklch(0.82 0.12 75)'}}/>{m}</span>)}
              </div>
              <p className="mt-5 text-[13px] text-ink-500 max-w-md leading-relaxed">
                Use your own provider account, or agree pilot usage billing. We don't proxy keys we don't need.
              </p>
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ---------- Evaluation loop ----------
function EvaluationLoop() {
  const nodes = [
    { icon: I.search,  label: "Observe",  note: "Review real conversations" },
    { icon: I.gauge,   label: "Detect",   note: "Find failure patterns" },
    { icon: I.doc,     label: "Iterate",  note: "Revise prompt / version" },
    { icon: I.shield,  label: "Audit",    note: "Re-check guardrails" },
  ];
  return (
    <section id="evaluation" className="relative border-t border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-32">
        <Reveal>
          <div className="max-w-3xl mb-12">
            <div className="label-mono tick mb-4">Evaluation loop</div>
            <h2 className="text-[34px] md:text-[46px] tracking-tight font-medium leading-[1.05]">
              Launch isn't the finish line.<br/>
              <span className="text-ink-500">It's where the work starts paying back.</span>
            </h2>
            <p className="mt-5 text-ink-300 text-[16px] leading-relaxed max-w-2xl">
              We treat every deployed assistant as a learning system. Real conversations reveal whether users are getting value, where the assistant breaks down, which questions repeat, and what needs to change in the prompt, knowledge base, model, or guardrails.
            </p>
          </div>
        </Reveal>

        <Reveal delay={120}>
          <div className="relative rounded-[28px] hairline-strong bg-gradient-to-b from-white/[0.025] to-transparent p-5 md:p-8 overflow-hidden">
            {/* Center diagram */}
            <div className="relative grid md:grid-cols-[1fr_auto_1fr] gap-8 items-center">
              {/* Left column: two nodes */}
              <div className="space-y-4">
                <LoopNode {...nodes[0]} step="01" />
                <LoopNode {...nodes[1]} step="02" />
              </div>

              {/* Center "cycle" graphic */}
              <div className="hidden md:flex items-center justify-center">
                <LoopGraphic />
              </div>

              {/* Right column: two nodes */}
              <div className="space-y-4">
                <LoopNode {...nodes[2]} step="03" right />
                <LoopNode {...nodes[3]} step="04" right />
              </div>
            </div>

            {/* Footer line */}
            <div className="mt-8 grid sm:grid-cols-3 gap-3 font-mono text-[12px] text-ink-300">
              <KV k="cadence" v="weekly review · ad-hoc on incident" />
              <KV k="surfaces" v="conversation logs · sampled" />
              <KV k="output"   v="prompt diffs · version notes" />
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function LoopNode({ icon: Icon, label, note, step, right }) {
  return (
    <div className={`flex items-start gap-4 rounded-2xl bg-white/[0.03] hairline p-5 ${right ? 'md:flex-row-reverse md:text-right' : ''}`}>
      <span className="num-ring inline-flex items-center justify-center h-11 w-11 rounded-xl text-accent shrink-0">
        <Icon className="h-5 w-5"/>
      </span>
      <div className="flex-1 min-w-0">
        <div className="flex items-center gap-2 mb-1 label-mono" style={right ? {justifyContent:'flex-end'} : null}>
          <span>STEP · {step}</span>
        </div>
        <div className="text-[19px] tracking-tight font-medium">{label}</div>
        <div className="text-[14px] text-ink-300 mt-1 leading-snug">{note}</div>
      </div>
    </div>
  );
}

function LoopGraphic() {
  return (
    <div className="relative w-[180px] h-[180px]">
      <svg viewBox="0 0 180 180" className="absolute inset-0">
        <defs>
          <linearGradient id="g1" x1="0" y1="0" x2="1" y2="1">
            <stop offset="0%" stopColor="oklch(0.78 0.14 220 / 0.9)"/>
            <stop offset="100%" stopColor="oklch(0.78 0.14 220 / 0.1)"/>
          </linearGradient>
        </defs>
        <circle cx="90" cy="90" r="78" stroke="oklch(1 0 0 / 0.08)" fill="none"/>
        <circle cx="90" cy="90" r="60" stroke="oklch(1 0 0 / 0.06)" fill="none" strokeDasharray="2 6"/>
        <circle cx="90" cy="90" r="78" stroke="url(#g1)" strokeWidth="1.5" fill="none"
                strokeLinecap="round" pathLength="100" strokeDasharray="55 100"
                style={{ transformOrigin: '50% 50%', animation: 'spin 7s linear infinite' }}/>
        <circle cx="90" cy="12" r="3" className="pulse-dot" />
        <style>{`@keyframes spin { to { transform: rotate(360deg);} }`}</style>
      </svg>
      <div className="absolute inset-0 flex flex-col items-center justify-center text-center">
        <I.cycle className="h-5 w-5 text-accent mb-1.5"/>
        <div className="label-mono">Eval loop</div>
        <div className="text-[13px] text-ink-300 mt-1">continuous</div>
      </div>
    </div>
  );
}

function KV({ k, v }) {
  return (
    <div className="rounded-xl hairline bg-white/[0.02] px-3.5 py-2.5">
      <div className="label-mono">{k}</div>
      <div className="text-ink-200 mt-0.5">{v}</div>
    </div>
  );
}

// ---------- Pilot workflow ----------
function Pilot() {
  const steps = [
    {
      n: "01",
      title: "Define the assistant",
      body: "Prompt, knowledge, model & API choice, channel, success criteria. We help shape the brief but the assistant is yours.",
      meta: "~2-3 working days",
    },
    {
      n: "02",
      title: "Deploy to real users",
      body: "A live setup in the channel your audience already uses, with the model account you provide. 1:1 or group.",
      meta: "~1 week to live",
    },
    {
      n: "03",
      title: "Evaluate & decide",
      body: "Review real conversations, surface failure patterns, tighten prompts, and decide what to expand, change, or shut down.",
      meta: "ongoing cadence",
    },
  ];
  return (
    <section id="pilot" className="relative border-t border-white/[0.06] bg-white/[0.012]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-32">
        <Reveal>
          <div className="max-w-3xl mb-12">
            <div className="label-mono tick mb-4">Pilot workflow</div>
            <h2 className="text-[34px] md:text-[46px] tracking-tight font-medium leading-[1.05]">
              Start small enough to learn cheaply.<br/>
              <span className="text-ink-500">Expand only what's earned it.</span>
            </h2>
          </div>
        </Reveal>

        <div className="relative">
          {/* connector line */}
          <div className="hidden md:block absolute top-12 left-6 right-6 h-px bg-gradient-to-r from-transparent via-white/15 to-transparent"/>
          <div className="grid md:grid-cols-3 gap-5">
            {steps.map((s, i) => (
              <Reveal key={s.n} delay={i*80}>
                <div className="card-hover relative h-full rounded-2xl bg-white/[0.025] hairline p-6 md:p-7">
                  <div className="flex items-center justify-between mb-6">
                    <div className="font-serif italic text-[44px] leading-none text-ink-100">{s.n}</div>
                    <div className="hidden md:inline-flex h-5 w-5 rounded-full bg-ink-950 hairline-strong relative">
                      <span className="absolute inset-1 rounded-full bg-accent"/>
                    </div>
                  </div>
                  <div className="text-[20px] tracking-tight font-medium">{s.title}</div>
                  <p className="mt-2.5 text-ink-300 text-[14.5px] leading-relaxed">{s.body}</p>
                  <div className="mt-5 inline-flex items-center gap-2 font-mono text-[11px] text-ink-400">
                    <span className="h-1 w-1 rounded-full bg-accent"/>{s.meta}
                  </div>
                </div>
              </Reveal>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ---------- Responsible deployment ----------
function Responsible() {
  const items = [
    {
      t: "Clients own the assistant",
      b: "Content, policy, and user-facing outcomes remain the client's responsibility. We can audit, but we don't underwrite.",
    },
    {
      t: "Channels have limits we don't control",
      b: "Some channels rely on third-party platforms whose policies and availability change. We flag those constraints before deployment.",
    },
    {
      t: "No magic, no oversold uptime",
      b: "We won't promise enterprise compliance, official platform partnerships, or guarantees we can't keep at this stage.",
    },
  ];
  return (
    <section className="relative border-t border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-20 md:py-24">
        <Reveal>
          <div className="rounded-[24px] hairline-strong bg-white/[0.02] p-6 md:p-8 relative overflow-hidden">
            <div className="absolute -top-12 -right-12 h-48 w-48 rounded-full"
                 style={{background:'radial-gradient(closest-side, oklch(0.82 0.12 75 / 0.18), transparent 70%)'}}/>
            <div className="flex items-start gap-4">
              <span className="num-ring h-10 w-10 rounded-xl inline-flex items-center justify-center text-warn shrink-0">
                <I.alert className="h-5 w-5"/>
              </span>
              <div>
                <div className="label-mono mb-1">Responsible deployment</div>
                <h3 className="text-[24px] tracking-tight font-medium leading-tight">We'd rather be transparent than impressive.</h3>
              </div>
            </div>
            <div className="mt-7 grid md:grid-cols-3 gap-4">
              {items.map((i) => (
                <div key={i.t} className="rounded-xl bg-white/[0.025] hairline p-4">
                  <div className="text-[15px] text-ink-100">{i.t}</div>
                  <div className="text-[13.5px] text-ink-400 mt-1.5 leading-relaxed">{i.b}</div>
                </div>
              ))}
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

// ---------- CTA ----------
function CTA() {
  return (
    <section id="contact" className="relative border-t border-white/[0.06] overflow-hidden">
      <div className="absolute inset-0 aurora opacity-90 pointer-events-none" />
      <div className="absolute inset-0 grid-dots opacity-40 [mask-image:radial-gradient(60%_60%_at_50%_50%,black,transparent)] pointer-events-none" />
      <div className="relative mx-auto max-w-5xl px-6 py-24 md:py-36 text-center">
        <Reveal>
          <div className="label-mono tick mx-auto inline-block mb-6">Pilot enquiries</div>
          <h2 className="text-[40px] md:text-[64px] leading-[1] tracking-[-0.025em] font-medium">
            If you can build the assistant —<br/>
            <span className="font-serif text-ink-100 whitespace-nowrap text-[32px] md:text-[52px]" style={{wordSpacing: '0.08em', letterSpacing: '0.005em'}}>We make it run where your audience already is.</span>
          </h2>
          <p className="mt-7 text-ink-300 text-[16px] max-w-xl mx-auto leading-relaxed">
            Tell us what assistant you want to deploy, who it is for, which channel matters first, and what would make the pilot worth continuing.
          </p>
          <div className="mt-10 flex flex-col sm:flex-row gap-3 justify-center">
            <a href="mailto:hello@gptframe.dev" className="inline-flex items-center justify-center gap-2 rounded-full btn-primary text-[14.5px] font-medium px-5 py-3">
              hello@gptframe.dev <I.arrow className="h-4 w-4"/>
            </a>
            <a href="#how" className="inline-flex items-center justify-center gap-2 rounded-full text-[14.5px] text-ink-100 px-5 py-3 hairline hover:bg-white/[0.04] transition">
              Review the system
            </a>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

// ---------- Footer ----------
function Footer() {
  return (
    <footer className="border-t border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-10 flex flex-col md:flex-row items-start md:items-center justify-between gap-6">
        <div className="flex items-center gap-2.5">
          <Logo />
          <span className="text-[14px]">GPTFrame</span>
          <span className="hidden sm:inline label-mono ml-2">© 2026 · Operated by Uri Grodzinski & Gal Efrati</span>
        </div>
        <div className="flex items-center gap-5 text-[13px] text-ink-400">
          <span className="hidden sm:inline font-mono">multi-channel</span>
          <span className="hidden sm:inline text-ink-700">·</span>
          <span className="hidden sm:inline font-mono">model-agnostic</span>
          <span className="hidden sm:inline text-ink-700">·</span>
          <span className="hidden sm:inline font-mono">evaluation-first</span>
        </div>
      </div>
    </footer>
  );
}

// ---------- Fit Check ----------
function FitCheck() {
  const yes = [
    "You already have a defined assistant use case",
    "Your audience already lives in a specific channel",
    "You want to test usage with real people",
    "You care about improving the assistant after launch",
    "You prefer a pilot before a big build",
  ];
  const no = [
    "You only have a vague AI idea",
    "You need a full product team replacement",
    "You need enterprise-grade SLA or formal compliance guarantees",
    "You want to avoid responsibility for assistant outputs",
    "You are not ready to define success criteria",
  ];
  return (
    <section id="fit" className="relative border-t border-white/[0.06]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-28">
        <Reveal>
          <div className="max-w-3xl mb-12">
            <div className="label-mono tick mb-4">Is this a fit?</div>
            <h2 className="text-[34px] md:text-[46px] tracking-tight font-medium leading-[1.05]">
              GPTFrame works best when the use case is focused.<br/>
              <span className="text-ink-500">A short honesty check before you write to us.</span>
            </h2>
          </div>
        </Reveal>
        <div className="grid md:grid-cols-2 gap-5">
          <Reveal>
            <div className="h-full rounded-2xl bg-white/[0.025] hairline p-6 md:p-7">
              <div className="flex items-center justify-between mb-5">
                <div className="flex items-center gap-2.5">
                  <span className="h-2 w-2 rounded-full bg-accent shadow-[0_0_0_4px_oklch(0.78_0.14_220/0.18)]"/>
                  <span className="label-mono">Good fit</span>
                </div>
                <span className="font-mono text-[11px] text-ink-500">YES /</span>
              </div>
              <ul className="space-y-2.5">
                {yes.map((t) => (
                  <li key={t} className="flex items-start gap-3 rounded-lg bg-white/[0.02] hairline px-3.5 py-3">
                    <I.check className="h-4 w-4 mt-0.5 text-accent shrink-0"/>
                    <span className="text-[14.5px] text-ink-100 leading-snug">{t}</span>
                  </li>
                ))}
              </ul>
            </div>
          </Reveal>
          <Reveal delay={80}>
            <div className="h-full rounded-2xl bg-white/[0.02] hairline p-6 md:p-7">
              <div className="flex items-center justify-between mb-5">
                <div className="flex items-center gap-2.5">
                  <span className="h-2 w-2 rounded-full bg-warn shadow-[0_0_0_4px_oklch(0.82_0.12_75/0.18)]"/>
                  <span className="label-mono">Probably not yet</span>
                </div>
                <span className="font-mono text-[11px] text-ink-500">/ NO</span>
              </div>
              <ul className="space-y-2.5">
                {no.map((t) => (
                  <li key={t} className="flex items-start gap-3 rounded-lg bg-white/[0.015] hairline px-3.5 py-3">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" className="h-4 w-4 mt-0.5 text-warn shrink-0"><path d="M6 6l12 12M18 6 6 18"/></svg>
                    <span className="text-[14.5px] text-ink-300 leading-snug">{t}</span>
                  </li>
                ))}
              </ul>
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ---------- Pilot Enquiry Form ----------
const FORMSPREE_ENDPOINT = "https://formspree.io/f/xrejjvgr";

function PilotForm() {
  const [state, setState] = useState({
    name: "", email: "", org: "", role: "",
    assistant: "", audience: "", repeated: "",
    today: "", painful: "", satisfied: "", urgent: "",
    channel: "", whyChannel: "", stage: "", help: [], modelConnect: "", modelHelp: [],
    pilotWorth: "", review: [],
    timeline: "", sensitive: "", pilotModel: [],
  });
  const [sent, setSent] = useState(false);
  const [error, setError] = useState(null);
  const [submitting, setSubmitting] = useState(false);
  const set = (k, v) => setState((s) => ({ ...s, [k]: v }));
  const toggle = (k, v) => setState((s) => ({
    ...s, [k]: s[k].includes(v) ? s[k].filter(x => x !== v) : [...s[k], v]
  }));

  const onSubmit = async (e) => {
    e.preventDefault();
    // Honeypot — bots fill hidden _honey field; silently drop and pretend success.
    if (e.currentTarget.elements._honey && e.currentTarget.elements._honey.value) {
      setSent(true);
      return;
    }
    setError(null);
    setSubmitting(true);
    try {
      const payload = {
        ...state,
        // Flatten array fields for readable email
        help: state.help.join(", "),
        modelHelp: state.modelHelp.join(", "),
        review: state.review.join(", "),
        pilotModel: state.pilotModel.join(", "),
        // Tracking
        source: "site_v1",
        page: "gptframe_home",
        version: "v1",
        // Formspree subject line
        _subject: `GPTFrame pilot enquiry — ${state.name || state.email || "(unknown)"}`,
      };
      const res = await fetch(FORMSPREE_ENDPOINT, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(payload),
      });
      if (!res.ok) {
        const data = await res.json().catch(() => ({}));
        throw new Error(data?.error || "Bad response");
      }
      setSent(true);
    } catch (err) {
      setError("Something went wrong. Please try again, or email us directly.");
    } finally {
      setSubmitting(false);
    }
  };

  const channelOpts  = ["WhatsApp","Telegram","Web chat","Slack","Other / not sure"];
  const painfulOpts  = [
    "Mild annoyance",
    "Costs noticeable time every week",
    "Blocks users from getting help",
    "Creates operational / reputational risk",
    "Not sure yet",
  ];
  const satisfiedOpts = [
    "Works well",
    "Good enough for now",
    "Frustrating but usable",
    "Not working well",
    "There is no current solution",
    "Not sure yet",
  ];
  const urgentOpts = ["Painful now", "Useful soon", "Exploring", "Just curious"];
  const stageOpts    = [
    "We already have a working assistant / prompt",
    "We have a clear use case but need help shaping the assistant",
    "We only have an early idea",
    "We are evaluating options",
  ];
  const helpOpts = [
    "Deployment only — we already have the assistant logic",
    "Help shaping the assistant — prompt, files, guardrails",
    "Evaluation support — review real usage and improve the assistant",
    "Full package — from idea to deployed assistant",
    "Not sure yet",
  ];
  const modelConnectOpts = [
    "Our organization will provide and pay for its own API key",
    "We prefer GPTFrame to provide access during the pilot and bill us for usage",
    "Not sure yet",
  ];
  const modelHelpOpts = [
    "Yes, help us choose between OpenAI / Claude / Gemini / OpenRouter / other providers",
    "Yes, help us compare quality, cost, latency, or privacy tradeoffs",
    "No, we already know what we want to use",
    "Not sure yet",
  ];
  const reviewOpts = [
    "Whether users get useful answers",
    "Repeated unanswered questions",
    "Failure patterns",
    "Prompt / knowledge base improvements",
    "Guardrail or safety issues",
    "User drop-off or low engagement",
    "Not sure yet",
  ];
  const timelineOpts = ["As soon as possible", "This month", "Next 1–2 months", "Exploring only"];
  const pilotModelOpts = [
    "Free exploratory call first",
    "One-time setup fee",
    "Monthly operation fee",
    "Usage-based pricing",
    "Paid evaluation / improvement reviews",
    "Custom build project",
    "Not ready to discuss budget yet",
    "Not sure yet",
  ];

  return (
    <section id="enquiry" className="relative border-t border-white/[0.06] bg-white/[0.012]">
      <div className="mx-auto max-w-6xl px-6 py-24 md:py-32">
        <div className="grid md:grid-cols-[1fr_1.5fr] gap-10 md:gap-14 items-start">
          <Reveal>
            <div className="md:sticky md:top-24">
              <div className="label-mono tick mb-4">Pilot enquiry</div>
              <h2 className="text-[30px] md:text-[40px] tracking-tight font-medium leading-[1.05]">
                Tell us enough to understand the assistant, the audience, and the deployment problem.
              </h2>
              <p className="mt-5 text-ink-300 text-[15.5px] leading-relaxed">
                We are especially interested in focused pilots where there is already a real audience, a repeated question or workflow, and a channel where users already communicate.
              </p>
              <div className="mt-7 rounded-xl bg-warn/[0.07] hairline p-4 flex items-start gap-3">
                <I.shield className="h-4 w-4 text-warn mt-0.5 shrink-0"/>
                <div className="text-[12.5px] text-ink-300 leading-relaxed">
                  Please do not include passwords, API keys, or confidential datasets in this form.
                </div>
              </div>
              <div className="mt-5 font-mono text-[11px] text-ink-500 space-y-1.5">
                <div>· manually reviewed</div>
                <div>· not a service agreement</div>
                <div>· typical reply within ~3 business days</div>
              </div>
            </div>
          </Reveal>

          <Reveal delay={80}>
            <form className="rounded-[24px] hairline-strong bg-white/[0.025] p-5 md:p-8 space-y-8"
                  onSubmit={onSubmit}>
              {/* Honeypot — hidden from real users; bots fill it and get silently dropped */}
              <input type="text" name="_honey" style={{display:'none'}} tabIndex={-1} autoComplete="off"/>
              {/* Hidden tracking inputs (mirrored in JSON payload as well) */}
              <input type="hidden" name="source" value="site_v1"/>
              <input type="hidden" name="page" value="gptframe_home"/>
              <input type="hidden" name="version" value="v1"/>

              {sent ? (
                <div className="py-16 text-center">
                  <div className="mx-auto h-12 w-12 rounded-full num-ring inline-flex items-center justify-center text-accent">
                    <I.check className="h-5 w-5"/>
                  </div>
                  <div className="mt-5 text-[22px] tracking-tight font-medium">Thanks — we'll be in touch.</div>
                  <div className="mt-2 text-ink-400 text-[14px]">We review pilot requests manually. A real human will reply.</div>
                </div>
              ) : (
              <React.Fragment>
                <FormStep n="01" title="About you">
                  <div className="grid sm:grid-cols-2 gap-3">
                    <Field label="Name">
                      <input className={inp} placeholder="Your name" value={state.name} onChange={(e)=>set("name", e.target.value)}/>
                    </Field>
                    <Field label="Email">
                      <input className={inp} type="email" placeholder="you@example.com" value={state.email} onChange={(e)=>set("email", e.target.value)}/>
                    </Field>
                  </div>
                  <div className="grid sm:grid-cols-2 gap-3 mt-3">
                    <Field label="Organization / project">
                      <input className={inp} placeholder="College, NGO, startup, community, creator project…" value={state.org} onChange={(e)=>set("org", e.target.value)}/>
                    </Field>
                    <Field label="Your role">
                      <input className={inp} placeholder="Founder, product lead, educator, ops lead, community manager…" value={state.role} onChange={(e)=>set("role", e.target.value)}/>
                    </Field>
                  </div>
                </FormStep>

                <FormStep n="02" title="The assistant">
                  <Field label="What assistant do you want to deploy?">
                    <textarea rows={3} className={inp} placeholder="What should the assistant help people do? What questions should it answer? What problem should it reduce?" value={state.assistant} onChange={(e)=>set("assistant", e.target.value)}/>
                  </Field>
                  <Field label="Who is the audience?" className="mt-3">
                    <textarea rows={2} className={inp} placeholder="Who will use it? Lecturers, students, customers, members, internal team, community…" value={state.audience} onChange={(e)=>set("audience", e.target.value)}/>
                  </Field>
                  <Field label="What question, task, or request keeps coming up?" className="mt-3">
                    <textarea rows={3} className={inp} placeholder="Example: lecturers asking the same AI questions in WhatsApp, customers asking support questions, members needing guidance, staff routing requests manually…" value={state.repeated} onChange={(e)=>set("repeated", e.target.value)}/>
                  </Field>
                </FormStep>

                <FormStep n="03" title="How this works today">
                  <Field label="How do people get help with this today?">
                    <textarea rows={3} className={inp} placeholder="Manual replies, WhatsApp group answers, shared docs, ChatGPT links, internal support, someone answering personally, or no real solution yet…" value={state.today} onChange={(e)=>set("today", e.target.value)}/>
                  </Field>
                  <Field label="How much of a problem is this today?" className="mt-3">
                    <RadioGroup name="painful" options={painfulOpts} value={state.painful} onChange={(v)=>set("painful", v)}/>
                  </Field>
                  <Field label="How well does the current way of handling this work?" className="mt-3">
                    <RadioGroup name="satisfied" options={satisfiedOpts} value={state.satisfied} onChange={(v)=>set("satisfied", v)}/>
                  </Field>
                  <Field label="How soon would this need to work?" className="mt-3">
                    <div className="flex flex-wrap gap-2">
                      {urgentOpts.map((c) => (
                        <Chip key={c} active={state.urgent === c} onClick={() => set("urgent", c)}>{c}</Chip>
                      ))}
                    </div>
                  </Field>
                </FormStep>

                <FormStep n="04" title="Deployment">
                  <Field label="Which channel matters first?">
                    <div className="flex flex-wrap gap-2">
                      {channelOpts.map((c) => (
                        <Chip key={c} active={state.channel === c} onClick={() => set("channel", c)}>{c}</Chip>
                      ))}
                    </div>
                  </Field>
                  <Field label="Why this channel?" className="mt-3">
                    <textarea rows={2} className={inp} placeholder="Why does this audience need the assistant here? Existing group, no app install, internal workflow, user habit, speed, accessibility…" value={state.whyChannel} onChange={(e)=>set("whyChannel", e.target.value)}/>
                  </Field>
                  <Field label="What stage are you at?" className="mt-3">
                    <RadioGroup name="stage" options={stageOpts} value={state.stage} onChange={(v)=>set("stage", v)}/>
                  </Field>
                  <Field label="What kind of help do you want?" className="mt-3">
                    <CheckboxGroup options={helpOpts} value={state.help} onToggle={(v)=>toggle("help", v)}/>
                  </Field>
                  <Field label="Who should pay the AI model usage costs?" className="mt-3">
                    <RadioGroup name="modelConnect" options={modelConnectOpts} value={state.modelConnect} onChange={(v)=>set("modelConnect", v)}/>
                    <p className="mt-2 font-mono text-[11px] text-ink-500 leading-relaxed">
                      Model usage is always paid by the client, either directly through your own provider account or through agreed usage billing.
                    </p>
                  </Field>
                  <Field label="Do you want help choosing the model or provider?" className="mt-3">
                    <CheckboxGroup options={modelHelpOpts} value={state.modelHelp} onToggle={(v)=>toggle("modelHelp", v)}/>
                  </Field>
                </FormStep>

                <FormStep n="05" title="Evaluation and success">
                  <Field label="What would make the pilot worth continuing?">
                    <textarea rows={3} className={inp} placeholder="Example: reduce repetitive questions, answer common cases well enough, validate demand, collect feedback, route users better, save staff time…" value={state.pilotWorth} onChange={(e)=>set("pilotWorth", e.target.value)}/>
                  </Field>
                  <Field label="What should we review after launch?" className="mt-3">
                    <CheckboxGroup options={reviewOpts} value={state.review} onToggle={(v)=>toggle("review", v)}/>
                  </Field>
                </FormStep>

                <FormStep n="06" title="Logistics and risk">
                  <Field label="Timeline">
                    <div className="flex flex-wrap gap-2">
                      {timelineOpts.map((c) => (
                        <Chip key={c} active={state.timeline === c} onClick={() => set("timeline", c)}>{c}</Chip>
                      ))}
                    </div>
                  </Field>
                  <Field label="Anything sensitive we should know?" className="mt-3">
                    <textarea rows={3} className={inp} placeholder="Personal data, regulated domain, minors, medical/legal/financial advice, political content, reputational risk, internal-only information…" value={state.sensitive} onChange={(e)=>set("sensitive", e.target.value)}/>
                  </Field>
                  <Field label="If this looks useful, what kind of pilot model would you consider?" className="mt-3">
                    <CheckboxGroup options={pilotModelOpts} value={state.pilotModel} onToggle={(v)=>toggle("pilotModel", v)} columns={2}/>
                  </Field>
                </FormStep>

                {error && (
                  <div className="rounded-lg bg-warn/[0.08] hairline px-4 py-3 flex items-start gap-3" role="alert">
                    <I.alert className="h-4 w-4 text-warn mt-0.5 shrink-0"/>
                    <div className="text-[13px] text-ink-200 leading-relaxed">{error}</div>
                  </div>
                )}
                <div className="pt-2 flex flex-col sm:flex-row sm:items-center gap-4 sm:justify-between">
                  <button
                    type="submit"
                    disabled={submitting}
                    className="inline-flex items-center justify-center gap-2 rounded-full btn-primary text-[14.5px] font-medium px-5 py-3 disabled:opacity-60 disabled:cursor-not-allowed">
                    {submitting ? "Sending…" : "Send pilot enquiry"} <I.arrow className="h-4 w-4"/>
                  </button>
                  <div className="text-[12px] text-ink-500 max-w-sm leading-relaxed">
                    We review pilot requests manually. Submitting this form does not create a service agreement.
                  </div>
                </div>
              </React.Fragment>
              )}
            </form>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

const inp = "w-full bg-white/[0.03] hairline rounded-lg px-3.5 py-2.5 text-[14.5px] text-ink-100 placeholder:text-ink-500 outline-none focus:bg-white/[0.05] focus:shadow-[inset_0_0_0_1px_oklch(0.78_0.14_220/0.55)] transition";

function Field({ label, children, className = "" }) {
  return (
    <label className={`block ${className}`}>
      <div className="label-mono mb-1.5">{label}</div>
      {children}
    </label>
  );
}

function FormStep({ n, title, children }) {
  return (
    <div className="border-t border-white/[0.06] first:border-t-0 first:pt-0 pt-7">
      <div className="flex items-baseline gap-3 mb-5">
        <span className="font-mono text-[10.5px] tracking-[0.18em] text-ink-500">SECTION · {n}</span>
        <span className="h-px flex-1 bg-white/[0.06]"/>
        <span className="text-[13px] text-ink-200">{title}</span>
      </div>
      {children}
    </div>
  );
}

function Chip({ active, onClick, children }) {
  return (
    <button type="button" onClick={onClick}
      className={`px-3.5 py-2 rounded-full text-[13px] transition ${active ? 'bg-white text-ink-950 shadow-[inset_0_0_0_1px_oklch(1_0_0_/0.2)]' : 'bg-white/[0.03] text-ink-200 hairline hover:bg-white/[0.06]'}`}>
      {children}
    </button>
  );
}

function RadioGroup({ name, options, value, onChange }) {
  return (
    <div className="grid gap-2">
      {options.map((opt) => {
        const checked = value === opt;
        return (
          <label key={opt} className={`flex items-start gap-3 rounded-lg px-3.5 py-2.5 cursor-pointer transition ${checked ? 'bg-white/[0.06] shadow-[inset_0_0_0_1px_oklch(0.78_0.14_220/0.5)]' : 'bg-white/[0.02] hairline hover:bg-white/[0.04]'}`}>
            <input type="radio" name={name} className="sr-only" checked={checked} onChange={() => onChange(opt)} />
            <span className={`h-3.5 w-3.5 mt-1 rounded-full inline-flex items-center justify-center hairline shrink-0 ${checked ? 'bg-accent/20' : ''}`}>
              {checked && <span className="h-1.5 w-1.5 rounded-full bg-accent"/>}
            </span>
            <span className="text-[14px] text-ink-100 leading-snug">{opt}</span>
          </label>
        );
      })}
    </div>
  );
}

function CheckboxGroup({ options, value, onToggle, columns = 1 }) {
  return (
    <div className={`grid gap-2 ${columns === 2 ? 'sm:grid-cols-2' : ''}`}>
      {options.map((opt) => {
        const checked = value.includes(opt);
        return (
          <label key={opt} className={`flex items-start gap-3 rounded-lg px-3.5 py-2.5 cursor-pointer transition ${checked ? 'bg-white/[0.06] shadow-[inset_0_0_0_1px_oklch(0.78_0.14_220/0.5)]' : 'bg-white/[0.02] hairline hover:bg-white/[0.04]'}`}>
            <input type="checkbox" className="sr-only" checked={checked} onChange={() => onToggle(opt)} />
            <span className={`h-3.5 w-3.5 mt-1 rounded-[4px] inline-flex items-center justify-center hairline shrink-0 ${checked ? 'bg-accent text-ink-950' : ''}`}>
              {checked && <svg viewBox="0 0 14 14" className="h-2.5 w-2.5" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="m3 7 3 3 5-6"/></svg>}
            </span>
            <span className="text-[14px] text-ink-100 leading-snug">{opt}</span>
          </label>
        );
      })}
    </div>
  );
}

// ---------- App ----------
function App() {
  return (
    <div className="min-h-screen">
      <Nav />
      <Hero />
      <Architecture />
      <Wedge />
      <Pillars />
      <ChannelsModels />
      <EvaluationLoop />
      <Pilot />
      <Responsible />
      <FitCheck />
      <PilotForm />
      <CTA />
      <Footer />
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById('app'));
root.render(<App />);
