function Comparison() {
  const rows = [
    {
      cap: "Primary job",
      us: "Define, govern, execute",
      blurb: "One contract that carries business meaning all the way from definition to executed query — not three disconnected tools stitched together.",
      viz: "flow",
      others: { "Data catalog": "Document metadata", "Semantic layer": "Metrics in SQL", "BI tool": "Build dashboards", "AI analytics": "Answer questions" }
    },
    {
      cap: "Business context",
      us: "Approved, owned, versioned",
      blurb: "Every definition carries an owner, a status, and a version history — the context that survives team changes and acquisitions.",
      viz: "signed",
      others: { "Data catalog": "Manual descriptions", "Semantic layer": "Technical only", "BI tool": "Scattered", "AI analytics": "Guessed at" }
    },
    {
      cap: "Who consumes it",
      us: "Humans and AI agents",
      blurb: "One governed definition serves analysts, product code, and AI assistants — a single source feeding every downstream surface.",
      viz: "fanout",
      others: { "Data catalog": "Humans searching", "Semantic layer": "BI tools", "BI tool": "Humans only", "AI analytics": "Humans only" }
    },
    {
      cap: "Execution model",
      us: "Governed contracts",
      blurb: "Definitions are bound to the tables, columns, and joins they reference — they execute against your warehouse, they aren't documentation.",
      viz: "contract",
      others: { "Data catalog": "Passive text", "Semantic layer": "Query translation", "BI tool": "Chart config", "AI analytics": "SQL generation" }
    },
    {
      cap: "Follow-up analysis",
      us: "Governed exploration",
      blurb: "Analysts start from an approved definition on the Canvas and keep asking questions — no dashboard request, no queue.",
      viz: "branch",
      others: { "Data catalog": "Search & read", "Semantic layer": "Analyst-gated", "BI tool": "90+ min cycling", "AI analytics": "Ad-hoc Q&A" }
    },
    {
      cap: "AI-ready",
      us: "Grounded via MCP",
      blurb: "AI agents retrieve governed business meaning over MCP — answers carry citations back to the definition they came from.",
      viz: "ground",
      others: { "Data catalog": "No", "Semantic layer": "Not directly", "BI tool": "No", "AI analytics": "Hallucination risk" }
    },
  ];

  const [row, setRow] = React.useState(0);
  const active = rows[row];
  const cats = Object.keys(active.others);

  return (
    <section className="section" id="compare">
      <div className="wrap">
        <SectionHead num="06" kicker="How it compares">
          Clearmetric is a category-of-one — the only layer solving business meaning, execution, and AI context with a single contract.
        </SectionHead>

        <div className="cmp">
          <div className="cmp__rail">
            <div className="mono-label" style={{ marginBottom: 14 }}>Capability</div>
            {rows.map((r, i) => (
              <button
                key={i}
                className={"cmp__rail-item " + (row === i ? "active" : "")}
                onClick={() => setRow(i)}
                onMouseEnter={() => setRow(i)}
              >
                <span className="cmp__rail-num">0{i + 1}</span>
                <span>{r.cap}</span>
                <span className="cmp__rail-arrow">→</span>
              </button>
            ))}
          </div>

          <div className="cmp__stage">
            <div className="cmp__stage-head">
              <div className="mono-label">Capability · 0{row + 1}</div>
              <h3 className="cmp__stage-title">{active.cap}</h3>
            </div>

            <div className="cmp__hero2">
              <div className="cmp__viz">
                <CmpViz kind={active.viz} />
              </div>
              <div className="cmp__hero2-body">
                <div className="mono-label" style={{ color: 'var(--accent)' }}>Clearmetric</div>
                <div className="cmp__hero2-val">{active.us}</div>
                <p className="cmp__hero2-blurb">{active.blurb}</p>
              </div>
            </div>

            <div className="cmp__others">
              {cats.map((c) => (
                <div className="cmp__other" key={c}>
                  <div className="cmp__other-cat">{c}</div>
                  <div className="cmp__other-val">{active.others[c]}</div>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/*
  Visual language for CmpViz:
  - viewBox 0 0 320 200 — consistent canvas, scales fluidly
  - ~28px outer padding on all sides
  - Single accent (#E8704A) per viz, used sparingly
  - Ink stroke 1.25
  - Text lives OUTSIDE shapes as labels (11px mono) — never inside boxes
  - Subtle dot-grid backdrop for depth
  - 8px rounded corners, consistent geometry
*/
function CmpViz({ kind }) {
  const ink = "#1C1D1F";
  const soft = "#B7B3A8";
  const line = "#E8E4DA";
  const accent = "#E8704A";
  const accentSoft = "#FDEEE7";

  const Backdrop = () => (
    <defs>
      <pattern id="dotgrid" x="0" y="0" width="12" height="12" patternUnits="userSpaceOnUse">
        <circle cx="1" cy="1" r="0.6" fill="#D9D4C7"/>
      </pattern>
    </defs>
  );

  const svgProps = {
    viewBox: "0 0 320 200",
    fill: "none",
    xmlns: "http://www.w3.org/2000/svg",
    preserveAspectRatio: "xMidYMid meet"
  };

  if (kind === "flow") {
    // Three stages connected left→right. Labels UNDER each node.
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* connectors */}
        <line x1="84" y1="90" x2="132" y2="90" stroke={ink} strokeWidth="1.2"/>
        <path d="M126 86 L132 90 L126 94" stroke={ink} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round"/>
        <line x1="188" y1="90" x2="236" y2="90" stroke={ink} strokeWidth="1.2"/>
        <path d="M230 86 L236 90 L230 94" stroke={ink} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round"/>
        {/* nodes */}
        <circle cx="60" cy="90" r="24" stroke={ink} strokeWidth="1.25" fill="#fff"/>
        <rect x="136" y="66" width="52" height="48" rx="6" stroke={accent} strokeWidth="1.5" fill={accentSoft}/>
        <polygon points="240,66 282,90 240,114" stroke={ink} strokeWidth="1.25" fill="#fff" strokeLinejoin="round"/>
        {/* labels below */}
        <text x="60" y="146" fontSize="11" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.04em">DEFINE</text>
        <text x="162" y="146" fontSize="11" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.04em">GOVERN</text>
        <text x="258" y="146" fontSize="11" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.04em">EXECUTE</text>
        {/* pipeline base */}
        <line x1="36" y1="172" x2="284" y2="172" stroke={soft} strokeWidth="1" strokeDasharray="2 4"/>
        <text x="160" y="190" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.08em">ONE CONTRACT</text>
      </svg>
    );
  }

  if (kind === "signed") {
    // Document with header, three lines, bottom metadata strip — NO text inside narrow areas
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* doc */}
        <rect x="96" y="30" width="128" height="140" rx="4" stroke={ink} strokeWidth="1.25" fill="#fff"/>
        {/* header */}
        <rect x="96" y="30" width="128" height="28" fill={ink}/>
        <text x="108" y="48" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill="#fff" letterSpacing="0.08em">DEFINITION</text>
        <rect x="190" y="38" width="26" height="12" rx="2" fill={accent}/>
        <text x="203" y="47" fontSize="8" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill="#fff" letterSpacing="0.06em">v2.3</text>
        {/* body lines */}
        <line x1="108" y1="76" x2="212" y2="76" stroke={ink} strokeWidth="1.4"/>
        <line x1="108" y1="90" x2="200" y2="90" stroke={soft} strokeWidth="1"/>
        <line x1="108" y1="102" x2="208" y2="102" stroke={soft} strokeWidth="1"/>
        <line x1="108" y1="114" x2="188" y2="114" stroke={soft} strokeWidth="1"/>
        {/* footer divider */}
        <line x1="108" y1="134" x2="212" y2="134" stroke={line} strokeWidth="1"/>
        {/* owner badge */}
        <circle cx="118" cy="152" r="8" fill={accent}/>
        <text x="118" y="156" fontSize="8" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill="#fff">AM</text>
        <circle cx="130" cy="152" r="8" fill="#fff" stroke={ink} strokeWidth="1"/>
        <text x="130" y="156" fontSize="8" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink}>JK</text>
        {/* status dot */}
        <circle cx="206" cy="152" r="3" fill="#4A9D6E"/>
        <text x="200" y="156" fontSize="8" textAnchor="end" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.04em">APPROVED</text>
        {/* external caption */}
        <text x="160" y="190" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.08em">OWNED · VERSIONED</text>
      </svg>
    );
  }

  if (kind === "fanout") {
    // Single source on left → three consumers on right, labels outside icons
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* source */}
        <rect x="36" y="72" width="72" height="56" rx="6" stroke={accent} strokeWidth="1.6" fill={accentSoft}/>
        <text x="72" y="96" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.08em">SSOT</text>
        <text x="72" y="112" fontSize="8" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.04em">one definition</text>
        {/* connectors */}
        <path d="M108 100 C 150 100, 160 46, 204 46" stroke={ink} strokeWidth="1.1" fill="none"/>
        <path d="M108 100 L 204 100" stroke={ink} strokeWidth="1.1"/>
        <path d="M108 100 C 150 100, 160 154, 204 154" stroke={ink} strokeWidth="1.1" fill="none"/>
        {/* human */}
        <g transform="translate(204,28)">
          <circle cx="18" cy="10" r="6" stroke={ink} strokeWidth="1.25" fill="#fff"/>
          <path d="M6 30 Q18 18 30 30 L30 36 L6 36 Z" stroke={ink} strokeWidth="1.25" fill="#fff" strokeLinejoin="round"/>
        </g>
        <text x="254" y="52" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.06em">HUMANS</text>
        {/* agent */}
        <g transform="translate(204,82)">
          <rect x="0" y="0" width="36" height="36" rx="6" stroke={ink} strokeWidth="1.25" fill="#fff"/>
          <circle cx="12" cy="14" r="2" fill={ink}/>
          <circle cx="24" cy="14" r="2" fill={ink}/>
          <rect x="10" y="22" width="16" height="2" rx="1" fill={ink}/>
          <line x1="18" y1="-4" x2="18" y2="0" stroke={ink} strokeWidth="1.25"/>
          <circle cx="18" cy="-6" r="2" fill={accent}/>
        </g>
        <text x="254" y="104" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.06em">AI AGENTS</text>
        {/* api */}
        <g transform="translate(204,136)">
          <rect x="0" y="0" width="36" height="36" rx="6" stroke={ink} strokeWidth="1.25" fill="#fff"/>
          <text x="18" y="23" fontSize="11" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink}>{'{ }'}</text>
        </g>
        <text x="254" y="158" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.06em">API</text>
        {/* caption */}
        <text x="160" y="190" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.08em">ONE SOURCE · MANY SURFACES</text>
      </svg>
    );
  }

  if (kind === "contract") {
    // business term card → binds to table.column reference
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* business term */}
        <rect x="28" y="46" width="116" height="52" rx="8" stroke={accent} strokeWidth="1.6" fill={accentSoft}/>
        <text x="86" y="68" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.08em">BUSINESS TERM</text>
        <text x="86" y="86" fontSize="13" textAnchor="middle" fontFamily="Geist, ui-sans-serif" fontWeight="500" fill={ink}>Active customer</text>
        {/* binding arrow with lock glyph */}
        <line x1="146" y1="72" x2="174" y2="72" stroke={ink} strokeWidth="1.25"/>
        <path d="M168 68 L174 72 L168 76" stroke={ink} strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
        <g transform="translate(152,80)">
          <rect x="0" y="4" width="14" height="10" rx="1" fill="#fff" stroke={ink} strokeWidth="1"/>
          <path d="M3 4 V2 a4 4 0 0 1 8 0 V4" stroke={ink} strokeWidth="1" fill="none"/>
        </g>
        {/* executable binding */}
        <rect x="176" y="46" width="116" height="52" rx="8" stroke={ink} strokeWidth="1.25" fill="#fff"/>
        <text x="234" y="68" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.08em">BOUND TO</text>
        <text x="234" y="86" fontSize="11" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={ink}>orders.status</text>
        {/* runs on rail */}
        <line x1="28" y1="130" x2="292" y2="130" stroke={line} strokeWidth="1"/>
        <rect x="28" y="140" width="264" height="30" rx="6" stroke={soft} strokeWidth="1" fill="#FCFBF8"/>
        <circle cx="42" cy="155" r="3" fill={accent}/>
        <text x="54" y="159" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.04em">executes against your warehouse</text>
        <text x="160" y="190" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.08em">DEFINITION → EXECUTABLE</text>
      </svg>
    );
  }

  if (kind === "branch") {
    // definition tile → 3 follow-up explorations as mini-charts
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* root definition */}
        <rect x="28" y="82" width="84" height="44" rx="6" stroke={accent} strokeWidth="1.6" fill={accentSoft}/>
        <text x="70" y="100" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.08em">DEFINITION</text>
        <text x="70" y="116" fontSize="12" textAnchor="middle" fontFamily="Geist, ui-sans-serif" fontWeight="500" fill={ink}>MRR</text>
        {/* branches */}
        <path d="M112 104 C 146 104, 146 40, 180 40" stroke={ink} strokeWidth="1.1" fill="none"/>
        <path d="M112 104 L 180 104" stroke={ink} strokeWidth="1.1"/>
        <path d="M112 104 C 146 104, 146 168, 180 168" stroke={ink} strokeWidth="1.1" fill="none"/>
        {/* leaf 1 — trend */}
        <g transform="translate(180,22)">
          <rect width="112" height="36" rx="4" stroke={ink} strokeWidth="1" fill="#fff"/>
          <polyline points="8,28 24,20 40,24 56,12 72,16 88,8 104,12" stroke={accent} strokeWidth="1.4" fill="none" strokeLinejoin="round" strokeLinecap="round"/>
        </g>
        <text x="236" y="74" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.06em">OVER TIME</text>
        {/* leaf 2 — bar */}
        <g transform="translate(180,86)">
          <rect width="112" height="36" rx="4" stroke={ink} strokeWidth="1" fill="#fff"/>
          <rect x="10" y="20" width="10" height="10" fill={ink}/>
          <rect x="26" y="14" width="10" height="16" fill={ink}/>
          <rect x="42" y="18" width="10" height="12" fill={ink}/>
          <rect x="58" y="8" width="10" height="22" fill={accent}/>
          <rect x="74" y="16" width="10" height="14" fill={ink}/>
          <rect x="90" y="12" width="10" height="18" fill={ink}/>
        </g>
        <text x="236" y="138" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.06em">BY SEGMENT</text>
        {/* leaf 3 — cohort grid */}
        <g transform="translate(180,150)">
          <rect width="112" height="36" rx="4" stroke={ink} strokeWidth="1" fill="#fff"/>
          {[0,1,2,3].map(r => [0,1,2,3,4,5,6].map(c => (
            <rect key={`${r}${c}`} x={8 + c*14} y={6 + r*7} width="10" height="5" fill={`rgba(232,112,74,${0.15 + (c*0.12)})`}/>
          )))}
        </g>
      </svg>
    );
  }

  if (kind === "ground") {
    // AI answer bubble, grounded via dotted line to definition citation
    return (
      <svg {...svgProps}>
        <Backdrop/>
        <rect width="320" height="200" fill="url(#dotgrid)" opacity="0.35"/>
        {/* agent icon */}
        <g transform="translate(28,30)">
          <rect width="40" height="40" rx="8" stroke={ink} strokeWidth="1.25" fill="#fff"/>
          <circle cx="14" cy="18" r="2.5" fill={ink}/>
          <circle cx="26" cy="18" r="2.5" fill={ink}/>
          <rect x="12" y="26" width="16" height="2.5" rx="1.2" fill={ink}/>
        </g>
        <text x="80" y="44" fontSize="10" fontFamily="Geist Mono, ui-monospace" fill={ink} letterSpacing="0.06em">AI AGENT</text>
        <text x="80" y="60" fontSize="9" fontFamily="Geist Mono, ui-monospace" fill={soft} letterSpacing="0.04em">asks: what is MRR?</text>
        {/* answer bubble */}
        <rect x="96" y="82" width="196" height="52" rx="8" stroke={ink} strokeWidth="1.25" fill="#fff"/>
        <path d="M104 134 L 98 146 L 118 134 Z" stroke={ink} strokeWidth="1.25" fill="#fff"/>
        <text x="112" y="104" fontSize="12" fontFamily="Geist, ui-sans-serif" fontWeight="500" fill={ink}>$4.2M monthly</text>
        <rect x="112" y="112" width="72" height="16" rx="3" fill={accentSoft} stroke={accent} strokeWidth="1"/>
        <text x="148" y="123" fontSize="9" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.04em">cite: mrr v2.3</text>
        {/* dotted tether to ground */}
        <line x1="148" y1="130" x2="148" y2="160" stroke={soft} strokeWidth="1" strokeDasharray="2 3"/>
        {/* ground = governed definition */}
        <rect x="36" y="160" width="248" height="26" rx="6" stroke={accent} strokeWidth="1.5" fill={accentSoft}/>
        <text x="160" y="177" fontSize="10" textAnchor="middle" fontFamily="Geist Mono, ui-monospace" fill={accent} letterSpacing="0.08em">GOVERNED DEFINITION · MCP</text>
      </svg>
    );
  }

  return null;
}

window.Comparison = Comparison;
