// =============================================================
// GRAPHICS LIBRARY — bespoke SVG illustrations & motifs
// All graphics use stroke-based, line-art aesthetic. Engraved.
// =============================================================

// ----- Photo portrait — real headshot inside an engraved-frame mount -----
// Renders one of the optimized portraits in /assets/, framed with the
// site's hairline + parchment treatment so it sits alongside the SVG art.
const PhotoPortrait = ({
  src = 'assets/dg-portrait.jpg',
  alt = 'Daniel B. Garrie, Esq.',
  caption = 'DANIEL B. GARRIE, ESQ.',
  cornerStamp = 'PORTRAIT · PLATE I',
  bg = 'var(--navy)',
  accent = 'var(--gold)',
}) => (
  <div style={{
    position: 'relative', width: '100%', height: '100%',
    background: bg, overflow: 'hidden',
  }}>
    {/* hairline frames */}
    <div style={{ position: 'absolute', inset: 14, border: '0.6px solid', borderColor: accent, opacity: 0.4, pointerEvents: 'none', zIndex: 2 }}/>
    <div style={{ position: 'absolute', inset: 20, border: '0.4px solid', borderColor: accent, opacity: 0.2, pointerEvents: 'none', zIndex: 2 }}/>
    {/* photo */}
    <img src={src} alt={alt} style={{
      width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 30%',
      display: 'block', filter: 'contrast(1.05) saturate(0.9)',
    }}/>
    {/* corner stamps */}
    <div className="mono" style={{
      position: 'absolute', top: 14, left: 16, fontSize: 9, letterSpacing: '0.22em',
      color: accent, opacity: 0.85, zIndex: 3,
    }}>№ 01</div>
    <div className="mono" style={{
      position: 'absolute', top: 14, right: 16, fontSize: 9, letterSpacing: '0.22em',
      color: accent, opacity: 0.85, zIndex: 3,
    }}>D.B.G.</div>
    <div className="mono" style={{
      position: 'absolute', bottom: 14, left: 16, fontSize: 9, letterSpacing: '0.22em',
      color: accent, opacity: 0.7, zIndex: 3,
    }}>{caption}</div>
    <div className="mono" style={{
      position: 'absolute', bottom: 14, right: 16, fontSize: 9, letterSpacing: '0.22em',
      color: accent, opacity: 0.7, zIndex: 3,
    }}>{cornerStamp}</div>
  </div>
);

// ----- Engraved portrait (line-etched silhouette of a man, suit, glasses) -----
// Stylized as a 19th-century engraving: parallel hatching, contour lines,
// no photographic content. Reads as a placeholder portrait of a jurist.
const EngravedPortrait = ({ accent = 'var(--gold)', bg = 'var(--navy)', ink = 'var(--paper)' }) => (
  <svg viewBox="0 0 400 500" preserveAspectRatio="xMidYMid slice"
       style={{ width: '100%', height: '100%', display: 'block', background: bg }}>
    <defs>
      <pattern id="engrave-h" width="3" height="3" patternUnits="userSpaceOnUse">
        <line x1="0" y1="1.5" x2="3" y2="1.5" stroke="rgba(244,240,230,0.18)" strokeWidth="0.4"/>
      </pattern>
      <pattern id="engrave-d" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(35)">
        <line x1="0" y1="2" x2="4" y2="2" stroke="rgba(244,240,230,0.22)" strokeWidth="0.4"/>
      </pattern>
      <radialGradient id="vignette" cx="0.5" cy="0.4" r="0.7">
        <stop offset="0.3" stopColor="rgba(0,0,0,0)"/>
        <stop offset="1" stopColor="rgba(0,0,0,0.45)"/>
      </radialGradient>
    </defs>
    {/* dot-grid background */}
    <rect width="400" height="500" fill={bg}/>
    <rect width="400" height="500" fill="url(#engrave-h)" opacity="0.5"/>
    {/* hairline frame */}
    <rect x="14" y="14" width="372" height="472" fill="none" stroke={accent} strokeOpacity="0.35" strokeWidth="0.6"/>
    <rect x="20" y="20" width="360" height="460" fill="none" stroke={accent} strokeOpacity="0.18" strokeWidth="0.4"/>

    {/* shoulders / suit — broader trapezoid */}
    <path d="M 60 500 L 90 360 Q 200 330 310 360 L 340 500 Z" fill={ink} fillOpacity="0.04"
          stroke={ink} strokeOpacity="0.7" strokeWidth="0.8"/>
    {/* lapels */}
    <path d="M 130 355 L 200 420 L 270 355" fill="none" stroke={ink} strokeOpacity="0.6" strokeWidth="0.6"/>
    <path d="M 200 420 L 200 500" stroke={ink} strokeOpacity="0.6" strokeWidth="0.6"/>
    {/* tie / pocket square hint */}
    <path d="M 192 360 L 200 420 L 208 360 Z" fill={accent} fillOpacity="0.25" stroke={accent} strokeOpacity="0.6" strokeWidth="0.5"/>
    {/* shirt collar */}
    <path d="M 165 360 L 200 380 L 235 360" fill="none" stroke={ink} strokeOpacity="0.7" strokeWidth="0.5"/>

    {/* neck */}
    <path d="M 178 320 L 178 360 Q 200 372 222 360 L 222 320" fill={ink} fillOpacity="0.05" stroke={ink} strokeOpacity="0.5" strokeWidth="0.5"/>

    {/* head — egg shape */}
    <ellipse cx="200" cy="225" rx="72" ry="92" fill={ink} fillOpacity="0.04"
             stroke={ink} strokeOpacity="0.85" strokeWidth="0.9"/>
    {/* hair / dome cap with hatching */}
    <path d="M 132 200 Q 132 140 200 132 Q 268 140 268 200 Q 256 165 200 162 Q 144 165 132 200 Z"
          fill="rgba(244,240,230,0.06)" stroke={ink} strokeOpacity="0.7" strokeWidth="0.6"/>
    {/* hair hatching strokes */}
    {[140, 150, 158, 165, 172, 180, 188, 196, 204, 212, 220, 228, 235, 242, 250, 258].map((x, i) => (
      <path key={i} d={`M ${x} ${175 - Math.abs(x - 200) * 0.18} Q ${x + 2} ${165 - Math.abs(x - 200) * 0.18} ${x + 4} ${175 - Math.abs(x - 200) * 0.18}`}
            stroke={ink} strokeOpacity="0.4" strokeWidth="0.5" fill="none"/>
    ))}
    {/* temples */}
    <path d="M 134 230 Q 130 250 138 270" stroke={ink} strokeOpacity="0.5" strokeWidth="0.5" fill="none"/>
    <path d="M 266 230 Q 270 250 262 270" stroke={ink} strokeOpacity="0.5" strokeWidth="0.5" fill="none"/>

    {/* eyebrows */}
    <path d="M 162 215 Q 175 210 188 214" stroke={ink} strokeOpacity="0.85" strokeWidth="1.2" fill="none" strokeLinecap="round"/>
    <path d="M 212 214 Q 225 210 238 215" stroke={ink} strokeOpacity="0.85" strokeWidth="1.2" fill="none" strokeLinecap="round"/>

    {/* glasses */}
    <g stroke={ink} strokeOpacity="0.85" strokeWidth="0.9" fill="none">
      <rect x="156" y="222" width="38" height="22" rx="2"/>
      <rect x="206" y="222" width="38" height="22" rx="2"/>
      <line x1="194" y1="232" x2="206" y2="232"/>
      <line x1="156" y1="228" x2="146" y2="228"/>
      <line x1="244" y1="228" x2="254" y2="228"/>
    </g>
    {/* eyes — pinpoints behind lenses */}
    <circle cx="175" cy="234" r="1.4" fill={ink} fillOpacity="0.85"/>
    <circle cx="225" cy="234" r="1.4" fill={ink} fillOpacity="0.85"/>

    {/* nose ridge */}
    <path d="M 200 240 L 197 270 L 203 273 L 200 282" stroke={ink} strokeOpacity="0.6" strokeWidth="0.6" fill="none"/>
    {/* nostrils */}
    <path d="M 192 282 Q 200 286 208 282" stroke={ink} strokeOpacity="0.55" strokeWidth="0.5" fill="none"/>

    {/* mouth — slight composed line */}
    <path d="M 184 302 Q 200 305 216 302" stroke={ink} strokeOpacity="0.75" strokeWidth="0.8" fill="none" strokeLinecap="round"/>
    {/* chin shadow */}
    <path d="M 178 310 Q 200 322 222 310" stroke={ink} strokeOpacity="0.3" strokeWidth="0.5" fill="none"/>

    {/* cheek hatching for dimensionality */}
    <g stroke={ink} strokeOpacity="0.18" strokeWidth="0.4" fill="none">
      {[0,1,2,3,4,5].map(i => <line key={i} x1={142 + i*2} y1={250 + i*4} x2={154 + i*2} y2={266 + i*4}/>)}
      {[0,1,2,3,4,5].map(i => <line key={i} x1={246 + i*2} y1={250 + i*4} x2={258 + i*2} y2={266 + i*4}/>)}
    </g>

    {/* vignette */}
    <rect width="400" height="500" fill="url(#vignette)" opacity="0.7"/>

    {/* corner stamps */}
    <g fontFamily="JetBrains Mono, monospace" fontSize="7" fill={accent} fillOpacity="0.7" letterSpacing="0.2em">
      <text x="28" y="38">№ 01</text>
      <text x="345" y="38">D.B.G.</text>
      <text x="28" y="476">PORTRAIT</text>
      <text x="320" y="476">PLATE.I</text>
    </g>
  </svg>
);

// ----- Compass rose / global reach mark -----
const CompassMark = ({ accent = 'var(--gold)', ink = 'var(--paper)', size = 220 }) => (
  <svg viewBox="0 0 240 240" width={size} height={size}>
    <g transform="translate(120,120)">
      {/* outer ring */}
      <circle r="110" fill="none" stroke={ink} strokeOpacity="0.6" strokeWidth="0.6"/>
      <circle r="100" fill="none" stroke={ink} strokeOpacity="0.3" strokeWidth="0.4" strokeDasharray="1 3"/>
      <circle r="78" fill="none" stroke={ink} strokeOpacity="0.5" strokeWidth="0.5"/>
      <circle r="42" fill="none" stroke={accent} strokeOpacity="0.7" strokeWidth="0.7"/>
      {/* tick marks */}
      {Array.from({ length: 36 }).map((_, i) => {
        const a = (i * 10) * Math.PI / 180;
        const r1 = 100, r2 = i % 9 === 0 ? 88 : i % 3 === 0 ? 92 : 95;
        return <line key={i}
          x1={r1 * Math.cos(a)} y1={r1 * Math.sin(a)}
          x2={r2 * Math.cos(a)} y2={r2 * Math.sin(a)}
          stroke={ink} strokeOpacity={i % 9 === 0 ? 0.85 : 0.4} strokeWidth="0.5"/>;
      })}
      {/* cardinal directions */}
      <g stroke={accent} strokeWidth="1" fill="none">
        <path d="M 0 -78 L -8 -10 L 0 0 L 8 -10 Z" fill={accent} fillOpacity="0.8"/>
        <path d="M 0 78 L -8 10 L 0 0 L 8 10 Z" fill={accent} fillOpacity="0.2"/>
        <path d="M -78 0 L -10 -8 L 0 0 L -10 8 Z" fill={accent} fillOpacity="0.4"/>
        <path d="M 78 0 L 10 -8 L 0 0 L 10 8 Z" fill={accent} fillOpacity="0.4"/>
      </g>
      <circle r="3" fill={accent}/>
      {/* labels */}
      <g fontFamily="JetBrains Mono, monospace" fontSize="9" fill={ink} fillOpacity="0.7" textAnchor="middle" letterSpacing="0.15em">
        <text y="-115">N</text>
        <text y="125">S</text>
        <text x="-115" y="3">W</text>
        <text x="115" y="3">E</text>
      </g>
    </g>
  </svg>
);

// ----- World jurisdiction map (abstract dotted continents) -----
const JurisdictionMap = ({ accent = 'var(--gold)', ink = 'var(--paper)' }) => (
  <svg viewBox="0 0 800 360" style={{ width: '100%', height: 'auto', display: 'block' }}>
    <defs>
      <pattern id="map-dots" width="6" height="6" patternUnits="userSpaceOnUse">
        <circle cx="1" cy="1" r="0.7" fill={ink} fillOpacity="0.35"/>
      </pattern>
    </defs>
    {/* equator + meridians */}
    <line x1="0" y1="180" x2="800" y2="180" stroke={ink} strokeOpacity="0.12" strokeWidth="0.5" strokeDasharray="2 4"/>
    {[100, 200, 300, 400, 500, 600, 700].map(x => (
      <line key={x} x1={x} y1="40" x2={x} y2="320" stroke={ink} strokeOpacity="0.08" strokeWidth="0.4"/>
    ))}
    {[80, 160, 240, 320].map(y => (
      <line key={y} x1="20" y1={y} x2="780" y2={y} stroke={ink} strokeOpacity="0.06" strokeWidth="0.4"/>
    ))}

    {/* abstract landmasses — clip to dot pattern */}
    <g fill="url(#map-dots)">
      {/* North America */}
      <path d="M 60 80 Q 90 60 140 70 L 200 90 Q 230 130 220 180 L 180 220 Q 130 230 100 200 L 70 160 Z"/>
      {/* South America */}
      <path d="M 200 220 Q 230 230 240 270 L 220 320 Q 195 320 185 290 L 190 250 Z"/>
      {/* Europe */}
      <path d="M 360 90 Q 400 80 430 95 L 440 130 Q 410 145 380 135 L 360 115 Z"/>
      {/* Africa */}
      <path d="M 380 150 Q 430 155 450 200 L 440 270 Q 410 290 390 260 L 375 200 Z"/>
      {/* Asia */}
      <path d="M 460 90 Q 540 70 620 90 L 660 140 Q 640 180 590 175 L 510 165 Q 460 145 460 110 Z"/>
      {/* Australia */}
      <path d="M 620 240 Q 660 235 690 250 L 685 280 Q 645 285 620 270 Z"/>
    </g>

    {/* Office markers — anchor venues (larger, bright) plus supporting venues (smaller) */}
    {[
      { x: 120, y: 175, label: 'LOS ANGELES', anchor: true },
      { x: 100, y: 138, label: 'SEATTLE',     anchor: false },
      { x: 160, y: 158, label: 'PARK CITY',   anchor: false },
      { x: 215, y: 168, label: 'MIAMI',       anchor: false },
      { x: 215, y: 138, label: 'NEW YORK',    anchor: true },
      { x: 388, y: 142, label: 'BARCELONA',   anchor: false },
      { x: 408, y: 124, label: 'GENEVA',      anchor: true },
      { x: 460, y: 152, label: 'TEL AVIV',    anchor: true },
      { x: 488, y: 168, label: 'DUBAI',       anchor: false },
      { x: 600, y: 184, label: 'SINGAPORE',   anchor: true },
      { x: 660, y: 142, label: 'TOKYO',       anchor: false },
    ].map((m, i) => (
      <g key={i}>
        {m.anchor ? (
          <>
            <circle cx={m.x} cy={m.y} r="9" fill="none" stroke={accent} strokeWidth="0.6" strokeOpacity="0.4"/>
            <circle cx={m.x} cy={m.y} r="6" fill="none" stroke={accent} strokeWidth="1.1"/>
            <circle cx={m.x} cy={m.y} r="3" fill={accent}/>
            <text x={m.x + 11} y={m.y + 3} fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={accent} fontWeight="500" letterSpacing="0.2em">{m.label}</text>
          </>
        ) : (
          <>
            <circle cx={m.x} cy={m.y} r="3" fill="none" stroke={accent} strokeWidth="0.7" strokeOpacity="0.55"/>
            <circle cx={m.x} cy={m.y} r="1.4" fill={accent} fillOpacity="0.7"/>
            <text x={m.x + 7} y={m.y + 3} fontFamily="JetBrains Mono, monospace"
              fontSize="7" fill={accent} fillOpacity="0.6" letterSpacing="0.16em">{m.label}</text>
          </>
        )}
      </g>
    ))}
    {/* Map legend */}
    <g fontFamily="JetBrains Mono, monospace" fontSize="7" fill={accent} letterSpacing="0.2em">
      <circle cx="32" cy="324" r="3.5" fill={accent}/>
      <text x="42" y="327" fillOpacity="0.85">ANCHOR</text>
      <circle cx="106" cy="324" r="1.4" fill={accent} fillOpacity="0.7"/>
      <text x="114" y="327" fillOpacity="0.5">BY ARRANGEMENT</text>
    </g>

    {/* corner stamps */}
    <g fontFamily="JetBrains Mono, monospace" fontSize="8" fill={ink} fillOpacity="0.5" letterSpacing="0.18em">
      <text x="20" y="30">FIG.04 · GLOBAL ENGAGEMENT</text>
      <text x="680" y="30">EQUIRECT.</text>
      <text x="20" y="350">LAT 0° EQUATOR</text>
      <text x="700" y="350">v.2026</text>
    </g>
  </svg>
);

// ----- Service-specific schematics -----

// 01 Mediation — two parties converging
// =============================================================
// SCHEMATICS — bold, low-noise, single-gesture diagrams.
// Each fits a 360x220 viewBox with generous whitespace.
// =============================================================

const Mono = ({ x, y, children, accent, opacity = 0.55, anchor = 'start', size = 9, color }) => (
  <text x={x} y={y} textAnchor={anchor}
    fontFamily="JetBrains Mono, monospace" fontSize={size} letterSpacing="0.18em"
    fill={color || (accent ? 'var(--gold-deep)' : 'var(--ink)')}
    fillOpacity={opacity}>{children}</text>
);

// 01 Mediation — two arcs converging into a single gold node.
const MediationSchematic = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)' }) => (
  <svg viewBox="0 0 360 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* left party arc */}
    <path d="M 30 60 Q 130 60 200 110" fill="none" stroke={ink} strokeOpacity="0.55" strokeWidth="1.2" strokeLinecap="round"/>
    {/* right party arc */}
    <path d="M 30 160 Q 130 160 200 110" fill="none" stroke={ink} strokeOpacity="0.55" strokeWidth="1.2" strokeLinecap="round" strokeDasharray="4 3"/>
    {/* origin nodes */}
    <circle cx="30" cy="60"  r="4" fill={ink} fillOpacity="0.7"/>
    <circle cx="30" cy="160" r="4" fill={ink} fillOpacity="0.7"/>
    {/* convergence at right */}
    <circle cx="200" cy="110" r="22" fill="none" stroke={accent} strokeOpacity="0.35" strokeWidth="1"/>
    <circle cx="200" cy="110" r="14" fill="none" stroke={accent} strokeOpacity="0.7" strokeWidth="1"/>
    <circle cx="200" cy="110" r="6"  fill={accent}/>
    {/* trailing gesture toward outcome */}
    <line x1="222" y1="110" x2="320" y2="110" stroke={accent} strokeOpacity="0.5" strokeWidth="0.8" strokeDasharray="2 4"/>
    <Mono x="40"  y="50"  color={ink} opacity="0.7">PARTY · A</Mono>
    <Mono x="40"  y="178" color={ink} opacity="0.7">PARTY · B</Mono>
    <Mono x="170" y="86"  color={accent} opacity="1" anchor="middle">CONVERGE</Mono>
    <Mono x="320" y="100" color={accent} opacity="0.85" anchor="end" size="8">OUTCOME →</Mono>
  </svg>
);

// 02 Special Master — three columns of evidence stacks ordered by a single horizontal bar.
const SpecialMasterSchematic = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)' }) => (
  <svg viewBox="0 0 360 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* header bar — the order */}
    <line x1="36" y1="48" x2="324" y2="48" stroke={accent} strokeWidth="1"/>
    <Mono x="180" y="38" anchor="middle" color={accent} opacity="1">PROTOCOL ORDER</Mono>
    {/* three columns of stacked rectangles, each capped with a gold seal */}
    {['CUSTODIANS','SOURCES','PRIVILEGE'].map((lab, ci) => {
      const cx = 80 + ci * 100;
      return (
        <g key={lab}>
          <line x1={cx} y1="48" x2={cx} y2="76" stroke={ink} strokeOpacity="0.4" strokeWidth="0.6"/>
          <circle cx={cx} cy="80" r="6" fill={accent}/>
          {[0,1,2,3,4].map(j => (
            <rect key={j} x={cx - 28} y={94 + j * 16} width="56" height="10"
                  fill="none" stroke={ink} strokeOpacity={0.4 - j*0.05} strokeWidth="0.6"/>
          ))}
          <Mono x={cx} y="190" anchor="middle" color={ink} opacity="0.7">{lab}</Mono>
        </g>
      );
    })}
  </svg>
);

// 03 Forensic — linear chain with a hash strip beneath.
const ForensicSchematic = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)' }) => (
  <svg viewBox="0 0 360 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
    <defs>
      <marker id="arr-f" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">
        <path d="M 0 0 L 10 5 L 0 10 z" fill={accent}/>
      </marker>
    </defs>
    {['ACQUIRE','HASH','PRESERVE','ANALYZE','REPORT'].map((label, i) => {
      const x = 44 + i * 68;
      return (
        <g key={label}>
          <circle cx={x} cy="100" r="20" fill="none" stroke={ink} strokeOpacity="0.5" strokeWidth="0.8"/>
          {i === 1 && <text x={x} y="106" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="14" fill={accent} fontWeight="500">#</text>}
          {i === 0 && <circle cx={x} cy="100" r="6" fill={accent}/>}
          {i === 2 && <rect x={x-7} y="93" width="14" height="14" fill="none" stroke={accent} strokeWidth="1"/>}
          {i === 3 && <g stroke={accent} strokeWidth="1" fill="none"><circle cx={x-2} cy="98" r="5"/><line x1={x+2} y1="102" x2={x+8} y2="108"/></g>}
          {i === 4 && <g stroke={accent} strokeWidth="1" fill="none"><line x1={x-7} y1="95" x2={x+7} y2="95"/><line x1={x-7} y1="100" x2={x+5} y2="100"/><line x1={x-7} y1="105" x2={x+7} y2="105"/></g>}
          <Mono x={x} y="138" anchor="middle" color={ink} opacity="0.7">{label}</Mono>
          <Mono x={x} y="74"  anchor="middle" color={accent} opacity="1" size="8">{String(i+1).padStart(2,'0')}</Mono>
          {i < 4 && <line x1={x + 21} y1="100" x2={x + 47} y2="100" stroke={accent} strokeOpacity="0.7" strokeWidth="0.8" markerEnd="url(#arr-f)"/>}
        </g>
      );
    })}
    {/* hash strip */}
    <line x1="36" y1="170" x2="324" y2="170" stroke={ink} strokeOpacity="0.15" strokeWidth="0.5"/>
    <text x="180" y="186" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="8" fill={ink} fillOpacity="0.4" letterSpacing="0.16em">
      sha256 · 4f8a 7c1e b29d 3a55 90ee 12b7 6ad4 1f8c
    </text>
  </svg>
);

// 04 AI Disputes — sparse layered network, signal-bright.
const AISchematic = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)' }) => (
  <svg viewBox="0 0 360 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* three layers — input (3) hidden (5) output (1) */}
    {[
      { count: 3, x: 70 },
      { count: 5, x: 180 },
      { count: 1, x: 290 },
    ].map((layer, li, all) => {
      const ys = Array.from({ length: layer.count }).map((_, i) =>
        50 + i * (130 / Math.max(layer.count - 1, 1)));
      return (
        <g key={li}>
          {/* connections to next layer */}
          {li < all.length - 1 && ys.flatMap((y, yi) => {
            const next = all[li + 1];
            const nys = Array.from({ length: next.count }).map((_, i) =>
              50 + i * (130 / Math.max(next.count - 1, 1)));
            return nys.map((ny, ni) => (
              <line key={`${yi}-${ni}`} x1={layer.x + 6} y1={y} x2={next.x - 6} y2={ny}
                stroke={ink} strokeOpacity="0.1" strokeWidth="0.5"/>
            ));
          })}
          {/* nodes */}
          {ys.map((y, yi) => (
            <circle key={yi} cx={layer.x} cy={y} r={li === 2 ? 9 : 5}
              fill={li === 2 ? accent : 'var(--paper)'}
              stroke={li === 2 ? accent : ink}
              strokeOpacity={li === 2 ? 1 : 0.6}
              strokeWidth="1"/>
          ))}
        </g>
      );
    })}
    <Mono x="70"  y="200" anchor="middle" color={ink} opacity="0.6">x · INPUT</Mono>
    <Mono x="180" y="200" anchor="middle" color={ink} opacity="0.6">HIDDEN</Mono>
    <Mono x="290" y="200" anchor="middle" color={accent} opacity="1">y · OUTPUT</Mono>
  </svg>
);

// 05 Arbitration — three-arbitrator panel with parties below and award seal.
const ArbitrationSchematic = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)' }) => (
  <svg viewBox="0 0 360 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* bench */}
    <line x1="56" y1="78" x2="304" y2="78" stroke={ink} strokeOpacity="0.5" strokeWidth="1"/>
    {/* three arbitrators */}
    {[100, 180, 260].map((x, i) => {
      const isChair = i === 1;
      return (
        <g key={i}>
          <circle cx={x} cy="62" r={isChair ? 12 : 9}
            fill={isChair ? accent : 'var(--paper)'}
            stroke={isChair ? accent : ink}
            strokeOpacity={isChair ? 1 : 0.7}
            strokeWidth="1"/>
          <Mono x={x} y="42" anchor="middle"
            color={isChair ? accent : ink}
            opacity={isChair ? 1 : 0.6}>{['WING','CHAIR','WING'][i]}</Mono>
        </g>
      );
    })}
    {/* parties facing */}
    {[110, 250].map((x, i) => (
      <g key={i}>
        <rect x={x - 32} y="120" width="64" height="32" fill="none" stroke={ink} strokeOpacity="0.55" strokeWidth="0.8"/>
        <Mono x={x} y="140" anchor="middle" color={ink} opacity="0.7">
          {['CLAIMANT','RESPONDENT'][i]}
        </Mono>
        {/* sight-line up to chair */}
        <line x1={x} y1="120" x2="180" y2="74" stroke={ink} strokeOpacity="0.18" strokeWidth="0.5" strokeDasharray="2 3"/>
      </g>
    ))}
    {/* award seal below the chair */}
    <line x1="180" y1="78" x2="180" y2="170" stroke={accent} strokeOpacity="0.5" strokeWidth="0.8" strokeDasharray="2 3"/>
    <circle cx="180" cy="184" r="14" fill="none" stroke={accent} strokeWidth="1"/>
    <circle cx="180" cy="184" r="9"  fill="none" stroke={accent} strokeWidth="0.6" strokeOpacity="0.5"/>
    <Mono x="180" y="187" anchor="middle" color={accent} opacity="1" size="7">AWARD</Mono>
  </svg>
);

// ----- Generic article figure — supports many kinds -----
// kinds: 'line' · 'bars' · 'bars-h' · 'tiers' · 'flow' · 'compare' · 'world' · 'callout'
const ArticleFigurePlot = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)', title, caption, data, kind = 'line' }) => {
  const renderChart = () => {
    // VERTICAL BAR
    if (kind === 'bars' && data) {
      return (
        <svg viewBox="0 0 600 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
          <line x1="60" y1="180" x2="580" y2="180" stroke={ink} strokeOpacity="0.4" strokeWidth="0.6"/>
          <line x1="60" y1="20" x2="60" y2="180" stroke={ink} strokeOpacity="0.4" strokeWidth="0.6"/>
          {[40, 80, 120, 160].map(y => (
            <line key={y} x1="60" y1={y} x2="580" y2={y} stroke={ink} strokeOpacity="0.08" strokeWidth="0.4"/>
          ))}
          {data.bars.map((b, i) => (
            <g key={i}>
              <rect x={70 + i * 65} y={180 - b.h} width="40" height={b.h} fill={accent} fillOpacity={0.3 + i * 0.12} stroke={accent} strokeWidth="0.5"/>
              <text x={90 + i * 65} y="198" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="8" fill={ink} fillOpacity="0.6" letterSpacing="0.14em">{b.l}</text>
            </g>
          ))}
        </svg>
      );
    }
    // LINE
    if (kind === 'line' && data) {
      return (
        <svg viewBox="0 0 600 220" style={{ width: '100%', height: 'auto', display: 'block' }}>
          <line x1="60" y1="180" x2="580" y2="180" stroke={ink} strokeOpacity="0.4" strokeWidth="0.6"/>
          <line x1="60" y1="20" x2="60" y2="180" stroke={ink} strokeOpacity="0.4" strokeWidth="0.6"/>
          {[40, 80, 120, 160].map(y => (
            <line key={y} x1="60" y1={y} x2="580" y2={y} stroke={ink} strokeOpacity="0.08" strokeWidth="0.4"/>
          ))}
          <path d={data.path} fill="none" stroke={accent} strokeWidth="1.5"/>
          {data.points && data.points.map((p, i) => (
            <circle key={i} cx={p.x} cy={p.y} r="3" fill={accent}/>
          ))}
        </svg>
      );
    }
    // HORIZONTAL BARS
    if (kind === 'bars-h' && data) {
      const maxV = Math.max(...data.rows.map(r => r.v));
      return (
        <svg viewBox="0 0 600 240" style={{ width: '100%', height: 'auto', display: 'block' }}>
          {data.rows.map((r, i) => {
            const y = 24 + i * 38;
            const w = (r.v / maxV) * 380;
            return (
              <g key={i}>
                <text x="180" y={y + 14} textAnchor="end"
                  fontFamily="JetBrains Mono, monospace" fontSize="10"
                  fill={ink} fillOpacity="0.7" letterSpacing="0.14em">{r.l}</text>
                <rect x="190" y={y + 4} width={w} height="20"
                  fill={accent} fillOpacity={0.25 + i * 0.05}
                  stroke={accent} strokeWidth="0.6"/>
                <text x={196 + w} y={y + 18}
                  fontFamily="JetBrains Mono, monospace" fontSize="10"
                  fill={accent} fillOpacity="0.85" letterSpacing="0.1em">{r.v}{r.suffix || ''}</text>
              </g>
            );
          })}
        </svg>
      );
    }
    // TIERED ACCESS DIAGRAM
    if (kind === 'tiers' && data) {
      return (
        <svg viewBox="0 0 600 280" style={{ width: '100%', height: 'auto', display: 'block' }}>
          {data.tiers.map((t, i) => {
            const w = 200 + i * 60;
            const x = 300 - w / 2;
            const y = 24 + i * 44;
            return (
              <g key={i}>
                <rect x={x} y={y} width={w} height="32"
                  fill="none" stroke={accent} strokeOpacity={1 - i * 0.12} strokeWidth="1"/>
                <text x={x + 12} y={y + 21}
                  fontFamily="JetBrains Mono, monospace" fontSize="10"
                  fill={accent} fillOpacity="1" letterSpacing="0.14em">TIER {i + 1}</text>
                <text x="300" y={y + 21} textAnchor="middle"
                  fontFamily="Georgia, serif" fontSize="14" fill={ink}>{t.label}</text>
                <text x={x + w - 12} y={y + 21} textAnchor="end"
                  fontFamily="JetBrains Mono, monospace" fontSize="9"
                  fill={ink} fillOpacity="0.55">{t.access}</text>
              </g>
            );
          })}
        </svg>
      );
    }
    // SEQUENTIAL FLOW
    if (kind === 'flow' && data) {
      const n = data.steps.length;
      return (
        <svg viewBox="0 0 600 200" style={{ width: '100%', height: 'auto', display: 'block' }}>
          <defs>
            <marker id="art-arr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">
              <path d="M 0 0 L 10 5 L 0 10 z" fill={accent}/>
            </marker>
          </defs>
          {data.steps.map((s, i) => {
            const x = 60 + i * (480 / (n - 1));
            return (
              <g key={i}>
                <circle cx={x} cy="100" r="18"
                  fill={i === 0 || i === n - 1 ? accent : 'var(--paper)'}
                  stroke={accent} strokeWidth="1"/>
                {!(i === 0 || i === n - 1) && (
                  <text x={x} y="105" textAnchor="middle"
                    fontFamily="JetBrains Mono, monospace" fontSize="11" fill={accent}>
                    {String(i + 1).padStart(2, '0')}
                  </text>
                )}
                <text x={x} y="148" textAnchor="middle"
                  fontFamily="JetBrains Mono, monospace" fontSize="9"
                  fill={ink} fillOpacity="0.7" letterSpacing="0.16em">{s.label}</text>
                {s.detail && (
                  <text x={x} y="166" textAnchor="middle"
                    fontFamily="Georgia, serif" fontSize="11" fontStyle="italic"
                    fill={ink} fillOpacity="0.55">{s.detail}</text>
                )}
                {i < n - 1 && (
                  <line x1={x + 19} y1="100" x2={x + (480 / (n - 1)) - 19} y2="100"
                    stroke={accent} strokeOpacity="0.6" strokeWidth="1"
                    markerEnd="url(#art-arr)"/>
                )}
              </g>
            );
          })}
        </svg>
      );
    }
    // SIDE-BY-SIDE COMPARISON
    if (kind === 'compare' && data) {
      return (
        <svg viewBox="0 0 600 280" style={{ width: '100%', height: 'auto', display: 'block' }}>
          <line x1="300" y1="40" x2="300" y2="260" stroke={ink} strokeOpacity="0.2" strokeWidth="0.6"/>
          <text x="150" y="32" textAnchor="middle"
            fontFamily="JetBrains Mono, monospace" fontSize="11"
            fill={ink} fillOpacity="0.55" letterSpacing="0.18em">{data.left.title}</text>
          <text x="450" y="32" textAnchor="middle"
            fontFamily="JetBrains Mono, monospace" fontSize="11"
            fill={accent} letterSpacing="0.18em">{data.right.title}</text>
          {data.left.items.map((s, i) => (
            <text key={i} x="280" y={64 + i * 28} textAnchor="end"
              fontFamily="Georgia, serif" fontSize="14" fill={ink} fillOpacity="0.7">{s}</text>
          ))}
          {data.right.items.map((s, i) => (
            <text key={i} x="320" y={64 + i * 28}
              fontFamily="Georgia, serif" fontSize="14" fill={ink}>{s}</text>
          ))}
        </svg>
      );
    }
    // CALLOUT — single big number with caption
    if (kind === 'callout' && data) {
      return (
        <svg viewBox="0 0 600 240" style={{ width: '100%', height: 'auto', display: 'block' }}>
          <text x="300" y="120" textAnchor="middle"
            fontFamily="Georgia, serif" fontSize="120" fontWeight="300"
            fill={accent}>{data.value}</text>
          <line x1="200" y1="148" x2="400" y2="148" stroke={accent} strokeWidth="0.8"/>
          <text x="300" y="180" textAnchor="middle"
            fontFamily="JetBrains Mono, monospace" fontSize="11"
            fill={ink} fillOpacity="0.7" letterSpacing="0.2em">{data.label}</text>
          {data.sub && (
            <text x="300" y="210" textAnchor="middle"
              fontFamily="Georgia, serif" fontSize="14" fontStyle="italic"
              fill={ink} fillOpacity="0.55">{data.sub}</text>
          )}
        </svg>
      );
    }
    return null;
  };
  return (
    <figure style={{ margin: '48px 0', padding: 24, border: '1px solid var(--line-soft)', background: 'var(--paper-2)' }}>
      <div className="mono" style={{ fontSize: 10, color: 'var(--gold-deep)', letterSpacing: '0.18em', marginBottom: 12 }}>
        {title}
      </div>
      {renderChart()}
      <figcaption className="serif" style={{ fontSize: 14, color: 'var(--slate-700)', marginTop: 12, fontStyle: 'italic', lineHeight: 1.5 }}>
        {caption}
      </figcaption>
    </figure>
  );
};

// =============================================================
// BOOK COVER — stylized typographic SVG cover for a treatise/book.
// Used on the About page to show featured publications visually.
// =============================================================
const BookCover = ({ title, sub, year, publisher, accent = '#0F1B2D', tint = 'var(--gold)' }) => (
  <svg viewBox="0 0 240 320" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* spine shadow */}
    <rect x="14" y="6" width="220" height="308" fill={accent}/>
    {/* cover */}
    <rect x="0" y="0" width="220" height="308" fill={accent}/>
    {/* hairline top + bottom borders */}
    <rect x="14" y="14" width="192" height="280" fill="none" stroke={tint} strokeOpacity="0.55" strokeWidth="0.6"/>
    <rect x="20" y="20" width="180" height="268" fill="none" stroke={tint} strokeOpacity="0.3" strokeWidth="0.4"/>
    {/* publisher / year mono header */}
    <text x="30" y="44" fontFamily="JetBrains Mono, monospace" fontSize="9"
      fill={tint} letterSpacing="0.22em">{publisher}</text>
    {/* title — wrap manually if needed */}
    <foreignObject x="30" y="68" width="160" height="170">
      <div xmlns="http://www.w3.org/1999/xhtml" style={{
        fontFamily: 'Georgia, serif', fontSize: 22, lineHeight: 1.18,
        color: '#FAF7EE', fontWeight: 500, letterSpacing: '-0.005em',
      }}>
        {title}
      </div>
    </foreignObject>
    {/* subtitle */}
    {sub && (
      <foreignObject x="30" y="226" width="160" height="50">
        <div xmlns="http://www.w3.org/1999/xhtml" style={{
          fontFamily: 'Georgia, serif', fontSize: 12, lineHeight: 1.4,
          color: 'rgba(244,240,230,0.7)', fontStyle: 'italic',
        }}>
          {sub}
        </div>
      </foreignObject>
    )}
    {/* author bar */}
    <line x1="30" y1="280" x2="80" y2="280" stroke={tint} strokeWidth="0.8"/>
    <text x="30" y="296" fontFamily="JetBrains Mono, monospace" fontSize="9"
      fill={tint} letterSpacing="0.2em">D. B. GARRIE</text>
    <text x="190" y="296" textAnchor="end"
      fontFamily="JetBrains Mono, monospace" fontSize="9"
      fill={tint} fillOpacity="0.7" letterSpacing="0.2em">{year}</text>
  </svg>
);

// =============================================================
// ARTICLE MARKS — 12 distinct black-and-white diagrams.
// One per Insights article. Used on the index card and at the
// top of each article page. Stroke-based, no fill, no gold.
// =============================================================
const ArticleMark = ({ id, onDark = false, size = 'auto' }) => {
  const stroke = onDark ? 'rgba(244,240,230,0.85)' : 'rgba(15,27,45,0.85)';
  const muted  = onDark ? 'rgba(244,240,230,0.35)' : 'rgba(15,27,45,0.30)';
  const fill   = onDark ? 'rgba(244,240,230,0.85)' : 'rgba(15,27,45,0.85)';
  const sw = (n) => n;

  const wrap = (children) => (
    <svg viewBox="0 0 240 180" style={{
      width: size === 'auto' ? '100%' : size,
      height: size === 'auto' ? '100%' : 'auto',
      display: 'block',
    }}>
      {children}
    </svg>
  );

  switch (id) {
    case 'evolution': // Three-wave timeline
      return wrap(<>
        <line x1="20" y1="120" x2="220" y2="120" stroke={stroke} strokeWidth={sw(0.8)}/>
        {[0,1,2].map(i => (
          <g key={i}>
            <path d={`M ${30 + i*70} 120 Q ${65 + i*70} ${100 - i*16} ${100 + i*70} 120`}
                  fill="none" stroke={stroke} strokeWidth={sw(0.8 + i*0.3)}/>
            <line x1={30 + i*70} y1="115" x2={30 + i*70} y2="125" stroke={stroke} strokeWidth={sw(0.6)}/>
            <text x={30 + i*70 + 35} y="148" textAnchor="middle"
                  fontFamily="JetBrains Mono, monospace" fontSize="9" fill={muted} letterSpacing="0.16em">
              {['WAVE I','WAVE II','WAVE III'][i]}
            </text>
          </g>
        ))}
        <circle cx="200" cy="120" r="5" fill={fill}/>
      </>);

    case 'forensic-data': // Magnifier over data points
      return wrap(<>
        {Array.from({ length: 24 }).map((_, i) => {
          const x = 30 + (i % 8) * 22;
          const y = 50 + Math.floor(i / 8) * 22;
          return <rect key={i} x={x} y={y} width="3" height="3" fill={muted}/>;
        })}
        <circle cx="120" cy="90" r="34" fill="none" stroke={stroke} strokeWidth={sw(2)}/>
        <line x1="146" y1="116" x2="180" y2="150" stroke={stroke} strokeWidth={sw(3)} strokeLinecap="round"/>
        <line x1="100" y1="80" x2="140" y2="80" stroke={stroke} strokeWidth={sw(0.8)}/>
        <line x1="100" y1="92" x2="140" y2="92" stroke={stroke} strokeWidth={sw(0.8)}/>
        <line x1="100" y1="104" x2="125" y2="104" stroke={stroke} strokeWidth={sw(0.8)}/>
      </>);

    case 'hallucinations': // Fragmented signal
      return wrap(<>
        <line x1="20" y1="90" x2="100" y2="90" stroke={stroke} strokeWidth={sw(1.2)}/>
        {/* fragmented middle */}
        {[110,124,138,152,166,180].map((x, i) => (
          <line key={i} x1={x} y1={70 + (i % 2 === 0 ? 0 : 30)}
                x2={x + 6} y2={90 + (i % 3 === 0 ? -12 : 12)}
                stroke={stroke} strokeWidth={sw(1.2)}/>
        ))}
        <text x="120" y="150" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.2em">HALLUCINATION</text>
      </>);

    case 'deepfakes': // Split portrait — half real, half synthetic
      return wrap(<>
        <line x1="120" y1="20" x2="120" y2="160" stroke={stroke} strokeWidth={sw(1)} strokeDasharray="3 3"/>
        {/* left: real (clean lines) */}
        <ellipse cx="80" cy="80" rx="32" ry="42" fill="none" stroke={stroke} strokeWidth={sw(1.2)}/>
        <circle cx="72" cy="74" r="2" fill={fill}/>
        <circle cx="92" cy="74" r="2" fill={fill}/>
        <path d="M 70 96 Q 80 102 92 96" stroke={stroke} strokeWidth={sw(0.8)} fill="none"/>
        {/* right: synthetic (with artifacts) */}
        <ellipse cx="160" cy="80" rx="32" ry="42" fill="none" stroke={stroke} strokeWidth={sw(1.2)} strokeDasharray="2 2"/>
        <circle cx="152" cy="74" r="2" fill={fill}/>
        <circle cx="172" cy="74" r="2" fill={fill}/>
        <path d="M 150 96 Q 160 92 172 96" stroke={stroke} strokeWidth={sw(0.8)} fill="none"/>
        {/* glitch lines on synthetic */}
        {[60, 90, 110].map((y, i) => (
          <line key={i} x1="130" y1={y} x2="190" y2={y} stroke={stroke} strokeWidth={sw(0.4)} strokeDasharray="1 4"/>
        ))}
        <text x="80"  y="148" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="8" fill={muted} letterSpacing="0.18em">REAL</text>
        <text x="160" y="148" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="8" fill={muted} letterSpacing="0.18em">SYNTH</text>
      </>);

    case 'smart-contracts': // Chain link + code brackets
      return wrap(<>
        {/* chain — two interlocked ovals */}
        <ellipse cx="80" cy="90" rx="34" ry="20" fill="none" stroke={stroke} strokeWidth={sw(1.6)}/>
        <ellipse cx="140" cy="90" rx="34" ry="20" fill="none" stroke={stroke} strokeWidth={sw(1.6)}/>
        {/* code brackets above */}
        <text x="120" y="50" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="22" fill={fill} fontWeight="500">{'{ }'}</text>
        <text x="120" y="148" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">ON-CHAIN · OFF-CHAIN</text>
      </>);

    case 'cyber-insurance': // Cracked shield
      return wrap(<>
        <path d="M 120 28 L 180 50 L 180 95 Q 180 130 120 158 Q 60 130 60 95 L 60 50 Z"
              fill="none" stroke={stroke} strokeWidth={sw(1.6)}/>
        {/* crack */}
        <path d="M 120 50 L 105 75 L 130 95 L 110 130"
              fill="none" stroke={stroke} strokeWidth={sw(1.4)} strokeLinecap="round"/>
        <text x="120" y="172" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">COVERAGE</text>
      </>);

    case 'protective-order': // Five stacked tiers
      return wrap(<>
        {[0,1,2,3,4].map(i => {
          const w = 80 + i * 24;
          const x = 120 - w / 2;
          const y = 30 + i * 20;
          return <rect key={i} x={x} y={y} width={w} height="14"
                  fill="none" stroke={stroke} strokeWidth={sw(1)} strokeOpacity={1 - i*0.12}/>;
        })}
        <text x="120" y="160" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">5 TIERS</text>
      </>);

    case 'forensic-selection': // Question mark over a list
      return wrap(<>
        {[55, 75, 95, 115, 135].map((y, i) => (
          <g key={i}>
            <line x1="40" y1={y} x2="50" y2={y} stroke={stroke} strokeWidth={sw(1.2)}/>
            <line x1="60" y1={y} x2={i === 1 || i === 3 ? 130 : 110} y2={y} stroke={stroke} strokeWidth={sw(0.8)} strokeOpacity="0.5"/>
          </g>
        ))}
        <text x="180" y="105" textAnchor="middle" fontFamily="Georgia, serif"
              fontSize="80" fontWeight="500" fill={fill}>?</text>
      </>);

    case 'jams-ai-rules': // Framework grid with one filled cell
      return wrap(<>
        {Array.from({ length: 4 }).map((_, r) =>
          Array.from({ length: 4 }).map((__, c) => {
            const x = 50 + c * 35;
            const y = 30 + r * 30;
            const filled = (r === 1 && c === 2);
            return (
              <rect key={`${r}-${c}`} x={x} y={y} width="30" height="24"
                fill={filled ? fill : 'none'}
                stroke={stroke} strokeWidth={sw(0.8)}/>
            );
          })
        )}
        <text x="120" y="170" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">FRAMEWORK · GRID</text>
      </>);

    case 'special-master-tar': // Funnel
      return wrap(<>
        <path d="M 50 30 L 190 30 L 145 80 L 145 140 L 95 140 L 95 80 Z"
              fill="none" stroke={stroke} strokeWidth={sw(1.6)}/>
        {/* incoming dots */}
        {[80, 105, 120, 135, 160].map((x, i) => (
          <circle key={i} cx={x} cy="20" r="2" fill={fill}/>
        ))}
        {/* output */}
        <circle cx="120" cy="155" r="4" fill={fill}/>
        <text x="120" y="172" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">VALIDATE</text>
      </>);

    case 'cross-border': // Globe with arc paths
      return wrap(<>
        <circle cx="120" cy="85" r="50" fill="none" stroke={stroke} strokeWidth={sw(1.2)}/>
        {/* meridians */}
        <ellipse cx="120" cy="85" rx="50" ry="20" fill="none" stroke={stroke} strokeWidth={sw(0.6)}/>
        <ellipse cx="120" cy="85" rx="20" ry="50" fill="none" stroke={stroke} strokeWidth={sw(0.6)}/>
        <ellipse cx="120" cy="85" rx="40" ry="50" fill="none" stroke={stroke} strokeWidth={sw(0.4)} strokeOpacity="0.5"/>
        {/* path arcs */}
        <path d="M 80 60 Q 120 30 160 60" fill="none" stroke={stroke} strokeWidth={sw(1.2)} strokeDasharray="2 2"/>
        <path d="M 80 110 Q 120 140 160 110" fill="none" stroke={stroke} strokeWidth={sw(1.2)} strokeDasharray="2 2"/>
        <circle cx="80" cy="85" r="3" fill={fill}/>
        <circle cx="160" cy="85" r="3" fill={fill}/>
        <text x="120" y="160" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">CROSS-BORDER</text>
      </>);

    case 'special-master-economy': // Balance scale with clock
      return wrap(<>
        {/* scale */}
        <line x1="120" y1="30" x2="120" y2="80" stroke={stroke} strokeWidth={sw(1.4)}/>
        <line x1="60" y1="50" x2="180" y2="50" stroke={stroke} strokeWidth={sw(1.2)}/>
        <line x1="60" y1="50" x2="60" y2="65" stroke={stroke} strokeWidth={sw(0.8)}/>
        <line x1="180" y1="50" x2="180" y2="65" stroke={stroke} strokeWidth={sw(0.8)}/>
        <ellipse cx="60" cy="68" rx="14" ry="4" fill="none" stroke={stroke} strokeWidth={sw(1)}/>
        <ellipse cx="180" cy="68" rx="14" ry="4" fill="none" stroke={stroke} strokeWidth={sw(1)}/>
        {/* fulcrum */}
        <path d="M 110 80 L 120 60 L 130 80 Z" fill="none" stroke={stroke} strokeWidth={sw(1)}/>
        {/* clock — simplified */}
        <circle cx="120" cy="125" r="22" fill="none" stroke={stroke} strokeWidth={sw(1.2)}/>
        <line x1="120" y1="125" x2="120" y2="110" stroke={stroke} strokeWidth={sw(1.2)}/>
        <line x1="120" y1="125" x2="132" y2="125" stroke={stroke} strokeWidth={sw(1.2)}/>
        <text x="120" y="172" textAnchor="middle" fontFamily="JetBrains Mono, monospace"
              fontSize="9" fill={muted} letterSpacing="0.18em">90 / 60</text>
      </>);

    default:
      return wrap(<>
        <circle cx="120" cy="90" r="40" fill="none" stroke={stroke} strokeWidth={sw(1)}/>
        <circle cx="120" cy="90" r="6" fill={fill}/>
      </>);
  }
};

// ----- Code + Case Law convergence diagram (thesis visual) -----
// Top: source code lines. Middle: gold horizontal axis labeled.
// Bottom: a case-law citation excerpt. Reads as the thesis literally drawn.
const CodeMeetsLawDiagram = ({ accent = 'var(--gold-deep)', ink = 'var(--ink)', muted = 'var(--slate-700)' }) => (
  <svg viewBox="0 0 360 480" style={{ width: '100%', height: 'auto', display: 'block' }}>
    {/* hairline frame */}
    <rect x="6" y="6" width="348" height="468" fill="none" stroke="var(--line-soft)" strokeWidth="1"/>

    {/* TOP — code panel */}
    <rect x="6" y="6" width="348" height="220" fill="var(--paper-2)"/>
    <text x="22" y="36" fontFamily="JetBrains Mono, monospace" fontSize="9"
      fill={accent} letterSpacing="0.2em">SOURCE</text>
    {/* line numbers + code */}
    {[
      { ln: '01', t: 'function isEnforceable(contract) {' },
      { ln: '02', t: '  const signed = verify(contract.sig);' },
      { ln: '03', t: '  const cutoff = contract.term.expires;' },
      { ln: '04', t: '  if (signed && now() < cutoff) {' },
      { ln: '05', t: '    return ENFORCEABLE;' },
      { ln: '06', t: '  }' },
      { ln: '07', t: '  return CHALLENGED;' },
      { ln: '08', t: '}' },
    ].map((r, i) => {
      const y = 64 + i * 18;
      return (
        <g key={i}>
          <text x="22" y={y} fontFamily="JetBrains Mono, monospace" fontSize="9"
            fill={muted} fillOpacity="0.55">{r.ln}</text>
          <text x="50" y={y} fontFamily="JetBrains Mono, monospace" fontSize="11"
            fill={ink} fillOpacity="0.85">{r.t}</text>
        </g>
      );
    })}
    {/* gold highlight on key tokens (line 4: signed && now() < cutoff) */}
    <rect x="78" y={64 + 3 * 18 - 11} width="184" height="14" fill={accent} fillOpacity="0.16"/>

    {/* MIDDLE — convergence band */}
    <rect x="6" y="226" width="348" height="36" fill={ink} fillOpacity="0.94"/>
    <line x1="22" y1="244" x2="338" y2="244" stroke={accent} strokeWidth="1"/>
    <circle cx="180" cy="244" r="6" fill={accent}/>
    <text x="180" y="248" textAnchor="middle"
      fontFamily="JetBrains Mono, monospace" fontSize="8.5"
      fill="var(--paper)" letterSpacing="0.32em" fillOpacity="0.9">
      WHERE&nbsp;THEY&nbsp;MEET
    </text>
    {/* tick marks */}
    {[60, 120, 240, 300].map(x => (
      <line key={x} x1={x} y1="240" x2={x} y2="248"
        stroke={accent} strokeOpacity="0.65" strokeWidth="0.7"/>
    ))}

    {/* BOTTOM — case law panel */}
    <rect x="6" y="262" width="348" height="212" fill="var(--paper)"/>
    <text x="22" y="288" fontFamily="JetBrains Mono, monospace" fontSize="9"
      fill={accent} letterSpacing="0.2em">CASE LAW</text>
    {/* citation header */}
    <text x="22" y="312" fontFamily="Georgia, serif" fontSize="13" fontStyle="italic" fill={ink}>
      Genger v. T.R. Investors LLC,
    </text>
    <text x="22" y="328" fontFamily="Georgia, serif" fontSize="11" fill={muted}>
      26 A.3d 180 (Del. 2011).
    </text>
    {/* opinion excerpt */}
    <foreignObject x="22" y="338" width="316" height="120">
      <div xmlns="http://www.w3.org/1999/xhtml" style={{
        fontFamily: 'Georgia, serif', fontSize: 12.5, lineHeight: 1.55,
        color: 'var(--ink)',
      }}>
        “The integrity of digital evidence — its <em>existence, its preservation,
        and the reliability of its production</em> — turns on questions of computer
        science as much as questions of law. The court must understand both.”
      </div>
    </foreignObject>
    <text x="338" y="468" textAnchor="end" fontFamily="JetBrains Mono, monospace" fontSize="8"
      fill={muted} fillOpacity="0.6" letterSpacing="0.18em">
      — PARAPHRASED FOR ILLUSTRATION
    </text>
  </svg>
);

// ----- Wax-stamp seal -----
const Seal = ({ size = 130, accent = 'var(--gold)', ink = 'var(--paper)' }) => (
  <svg viewBox="0 0 160 160" width={size} height={size}>
    <defs>
      <path id="seal-arc-top" d="M 80 80 m -56 0 a 56 56 0 0 1 112 0"/>
      <path id="seal-arc-bot" d="M 80 80 m -56 0 a 56 56 0 0 0 112 0"/>
    </defs>
    <circle cx="80" cy="80" r="74" fill="none" stroke={accent} strokeOpacity="0.55" strokeWidth="0.6"/>
    <circle cx="80" cy="80" r="68" fill="none" stroke={accent} strokeWidth="1"/>
    <circle cx="80" cy="80" r="62" fill="none" stroke={accent} strokeOpacity="0.4" strokeWidth="0.4" strokeDasharray="1 2"/>
    {/* radiating ticks */}
    {Array.from({ length: 36 }).map((_, i) => {
      const a = (i * 10) * Math.PI / 180;
      return <line key={i}
        x1={80 + 56 * Math.cos(a)} y1={80 + 56 * Math.sin(a)}
        x2={80 + 60 * Math.cos(a)} y2={80 + 60 * Math.sin(a)}
        stroke={accent} strokeOpacity="0.6" strokeWidth="0.5"/>;
    })}
    {/* center monogram */}
    <g transform="translate(80,80)" stroke={accent} strokeWidth="1.2" fill="none">
      <line x1="-18" y1="-12" x2="18" y2="-12"/>
      <line x1="0" y1="-12" x2="0" y2="14"/>
      <line x1="-3" y1="14" x2="3" y2="14"/>
      <circle cx="0" cy="-12" r="2" fill={accent}/>
    </g>
    {/* curved text */}
    <text fill={accent} fontFamily="JetBrains Mono, monospace" fontSize="7.5" letterSpacing="0.32em">
      <textPath href="#seal-arc-top" startOffset="50%" textAnchor="middle">TAILORED MEDIATION · D.B.G.</textPath>
    </text>
    <text fill={accent} fontFamily="JetBrains Mono, monospace" fontSize="7.5" letterSpacing="0.32em">
      <textPath href="#seal-arc-bot" startOffset="50%" textAnchor="middle">· MEDIATOR · ARBITRATOR · NEUTRAL ·</textPath>
    </text>
  </svg>
);

// ----- Filigree divider -----
const Filigree = ({ color = 'var(--gold-deep)' }) => (
  <svg viewBox="0 0 240 14" style={{ display: 'block', margin: '0 auto', width: 240, height: 14 }}>
    <line x1="0" y1="7" x2="90" y2="7" stroke={color} strokeWidth="0.6" strokeOpacity="0.5"/>
    <line x1="150" y1="7" x2="240" y2="7" stroke={color} strokeWidth="0.6" strokeOpacity="0.5"/>
    <circle cx="100" cy="7" r="1.5" fill={color}/>
    <circle cx="120" cy="7" r="2.5" fill="none" stroke={color} strokeWidth="0.7"/>
    <circle cx="120" cy="7" r="0.8" fill={color}/>
    <circle cx="140" cy="7" r="1.5" fill={color}/>
  </svg>
);

// ----- Article figure: hallucination distribution (bar chart styled) -----
// (component inline above)

Object.assign(window, {
  EngravedPortrait,
  PhotoPortrait,
  CompassMark,
  JurisdictionMap,
  MediationSchematic,
  SpecialMasterSchematic,
  ForensicSchematic,
  AISchematic,
  ArbitrationSchematic,
  ArticleFigurePlot,
  ArticleMark,
  BookCover,
  CodeMeetsLawDiagram,
  Seal,
  Filigree,
});
