// Three diagram visuals for Section 3 — Seed, Detect, Trace.
// Pure SVG + CSS, no images.

function SeedDiagram() {
  // Three sources feeding into a Snare node, then synthetic records inserted.
  return (
    <svg viewBox="0 0 480 280" width="100%" height="100%" style={{ display: 'block' }}>
      <defs>
        <pattern id="grid-seed" width="24" height="24" patternUnits="userSpaceOnUse">
          <path d="M 24 0 L 0 0 0 24" fill="none" stroke="rgba(232,230,225,0.05)" strokeWidth="1"/>
        </pattern>
      </defs>
      <rect width="480" height="280" fill="url(#grid-seed)" />

      {/* Source systems on the left */}
      {[
        { y: 50,  label: 'CRM / SALESFORCE' },
        { y: 110, label: 'CALL CTR / GENESYS' },
        { y: 170, label: 'SUPPORT / ZENDESK' },
      ].map((src, i) => (
        <g key={i}>
          <rect x="20" y={src.y} width="140" height="40" fill="none" stroke="rgba(232,230,225,0.22)" strokeWidth="1"/>
          <text x="30" y={src.y + 24} fontFamily="var(--mono)" fontSize="10" letterSpacing="1.4" fill="var(--fg-dim)">{src.label}</text>
          {/* connector to Snare node */}
          <line x1="160" y1={src.y + 20} x2="240" y2="140" stroke="rgba(232,230,225,0.18)" strokeWidth="1" strokeDasharray="2,3"/>
        </g>
      ))}

      {/* Snare node — center */}
      <g>
        <rect x="200" y="115" width="80" height="50" fill="#0A0B0D" stroke="#D4622A" strokeWidth="1"/>
        <text x="240" y="138" textAnchor="middle" fontFamily="var(--mono)" fontSize="10" letterSpacing="2.4" fill="#D4622A">SNARE</text>
        <text x="240" y="152" textAnchor="middle" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.4" fill="var(--fg-faint)">SEED ENGINE</text>
      </g>

      {/* Output records — synthetic identities flowing into the systems */}
      {[
        { y: 50, dx: 0, label: 'm.kovacs+a3f2@…' },
        { y: 110, dx: 12, label: 'l.tanaka+9b7c@…' },
        { y: 170, dx: -8, label: 'r.demir+4e1d@…' },
      ].map((rec, i) => (
        <g key={i}>
          <line x1="280" y1="140" x2="320" y2={rec.y + 20} stroke="#D4622A" strokeWidth="1" opacity="0.5"/>
          <rect x="320" y={rec.y + 8} width="140" height="24" fill="#0A0B0D" stroke="rgba(212,98,42,0.55)" strokeWidth="1"/>
          <text x="328" y={rec.y + 24} fontFamily="var(--mono)" fontSize="10" fill="#D4622A">{rec.label}</text>
        </g>
      ))}

      {/* Annotation */}
      <line x1="320" y1="220" x2="460" y2="220" stroke="rgba(232,230,225,0.18)" strokeWidth="1"/>
      <text x="320" y="244" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="var(--fg-faint)">SYNTHETIC PII INSERTED</text>
      <text x="320" y="258" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="var(--fg-faint)">REAL PHONES · REAL DOMAINS</text>
    </svg>
  );
}

function DetectDiagram() {
  // surveillance surfaces — concentric arcs, pings on the rim.
  const [pingIdx, setPingIdx] = React.useState(0);
  React.useEffect(() => {
    const reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (reduce) return;
    const t = setInterval(() => setPingIdx(i => (i + 1) % 5), 1400);
    return () => clearInterval(t);
  }, []);

  const surfaces = [
    { angle: -110, label: 'TELEGRAM' },
    { angle: -55,  label: 'DARKWEB MKT' },
    { angle: 0,    label: 'PHISHING' },
    { angle: 55,   label: 'COMPETITOR SMS' },
    { angle: 110,  label: 'BREACH DUMP' },
  ];

  return (
    <svg viewBox="0 0 480 280" width="100%" height="100%" style={{ display: 'block' }}>
      <defs>
        <pattern id="grid-det" width="24" height="24" patternUnits="userSpaceOnUse">
          <path d="M 24 0 L 0 0 0 24" fill="none" stroke="rgba(232,230,225,0.05)" strokeWidth="1"/>
        </pattern>
      </defs>
      <rect width="480" height="280" fill="url(#grid-det)" />

      {/* center node */}
      <g>
        <rect x="60" y="124" width="80" height="32" fill="#0A0B0D" stroke="#D4622A" strokeWidth="1"/>
        <text x="100" y="144" textAnchor="middle" fontFamily="var(--mono)" fontSize="10" letterSpacing="2" fill="#D4622A">SNARE</text>
        <text x="100" y="172" textAnchor="middle" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.4" fill="var(--fg-faint)">SURVEILLANCE</text>
      </g>

      {/* arcs / surfaces */}
      {surfaces.map((s, i) => {
        const r = 180;
        const cx = 100, cy = 140;
        const rad = (s.angle * Math.PI) / 180;
        const x = cx + Math.cos(rad) * r;
        const y = cy + Math.sin(rad) * r;
        const isActive = i === pingIdx;
        return (
          <g key={i}>
            <line x1={cx + 60} y1={cy} x2={x} y2={y}
              stroke={isActive ? '#D4622A' : 'rgba(232,230,225,0.14)'}
              strokeWidth="1"
              strokeDasharray={isActive ? '0' : '2,4'}
              style={{ transition: 'stroke 280ms' }}
            />
            <rect x={x - 6} y={y - 12} width="120" height="24"
              fill="#0A0B0D"
              stroke={isActive ? '#D4622A' : 'rgba(232,230,225,0.22)'}
              strokeWidth="1"
              style={{ transition: 'stroke 280ms' }}
            />
            <text x={x + 4} y={y + 4}
              fontFamily="var(--mono)" fontSize="10" letterSpacing="1.4"
              fill={isActive ? '#D4622A' : 'var(--fg-dim)'}
              style={{ transition: 'fill 280ms' }}
            >{s.label}</text>
            {isActive && (
              <circle cx={x} cy={y} r="4" fill="#D4622A">
                <animate attributeName="r" from="4" to="14" dur="1s" repeatCount="indefinite"/>
                <animate attributeName="opacity" from="0.8" to="0" dur="1s" repeatCount="indefinite"/>
              </circle>
            )}
          </g>
        );
      })}

      {/* event log on left */}
      <g>
        <text x="20" y="40" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="var(--fg-faint)">CAPTURE LOG</text>
        <text x="20" y="60" fontFamily="var(--mono)" fontSize="10" fill="var(--fg-dim)">14:22 · sms inbound</text>
        <text x="20" y="76" fontFamily="var(--mono)" fontSize="10" fill="var(--fg-dim)">14:22 · +44 7700 …</text>
        <text x="20" y="92" fontFamily="var(--mono)" fontSize="10" fill="#D4622A">→ token: m.kovacs+a3f2</text>
        <text x="20" y="108" fontFamily="var(--mono)" fontSize="10" fill="var(--fg-dim)">14:22 · matched</text>
      </g>
    </svg>
  );
}

function TraceDiagram() {
  // Funnel: persona → conversation → attribution
  return (
    <svg viewBox="0 0 480 280" width="100%" height="100%" style={{ display: 'block' }}>
      <defs>
        <pattern id="grid-trc" width="24" height="24" patternUnits="userSpaceOnUse">
          <path d="M 24 0 L 0 0 0 24" fill="none" stroke="rgba(232,230,225,0.05)" strokeWidth="1"/>
        </pattern>
      </defs>
      <rect width="480" height="280" fill="url(#grid-trc)" />

      {/* persona */}
      <g>
        <rect x="20" y="120" width="120" height="40" fill="#0A0B0D" stroke="#D4622A" strokeWidth="1"/>
        <text x="80" y="140" textAnchor="middle" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="#D4622A">AI PERSONA</text>
        <text x="80" y="153" textAnchor="middle" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.4" fill="var(--fg-faint)">QWEN-CLASS · LOCAL</text>
      </g>

      {/* conversation bubbles */}
      <g transform="translate(160, 30)">
        <rect x="0" y="0" width="180" height="22" fill="#0A0B0D" stroke="rgba(232,230,225,0.22)"/>
        <text x="8" y="14" fontFamily="var(--mono)" fontSize="9" fill="var(--fg-dim)">attacker:</text>
        <text x="56" y="14" fontFamily="var(--mono)" fontSize="9" fill="var(--fg)">are you mr kovacs?</text>

        <rect x="0" y="32" width="180" height="22" fill="#0A0B0D" stroke="rgba(232,230,225,0.22)"/>
        <text x="8" y="46" fontFamily="var(--mono)" fontSize="9" fill="#D4622A">snare:</text>
        <text x="42" y="46" fontFamily="var(--mono)" fontSize="9" fill="var(--fg)">yes — who's asking?</text>

        <rect x="0" y="64" width="180" height="22" fill="#0A0B0D" stroke="rgba(232,230,225,0.22)"/>
        <text x="8" y="78" fontFamily="var(--mono)" fontSize="9" fill="var(--fg-dim)">attacker:</text>
        <text x="56" y="78" fontFamily="var(--mono)" fontSize="9" fill="var(--fg)">we have an offer for VIPs…</text>

        <rect x="0" y="96" width="180" height="22" fill="#0A0B0D" stroke="rgba(212,98,42,0.6)"/>
        <text x="8" y="110" fontFamily="var(--mono)" fontSize="9" fill="#D4622A">capture:</text>
        <text x="50" y="110" fontFamily="var(--mono)" fontSize="9" fill="#D4622A">infra · TTPs · lang</text>
      </g>

      {/* attribution box */}
      <g transform="translate(360, 80)">
        <rect x="0" y="0" width="100" height="120" fill="#0A0B0D" stroke="#D4622A" strokeWidth="1"/>
        <text x="50" y="20" textAnchor="middle" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="#D4622A">ATTRIBUTION</text>
        <line x1="10" y1="28" x2="90" y2="28" stroke="rgba(232,230,225,0.22)"/>

        <text x="10" y="44" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.2" fill="var(--fg-faint)">SEGMENT</text>
        <text x="10" y="56" fontFamily="var(--mono)" fontSize="9" fill="var(--fg)">CRM / VIP</text>

        <text x="10" y="74" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.2" fill="var(--fg-faint)">WINDOW</text>
        <text x="10" y="86" fontFamily="var(--mono)" fontSize="9" fill="var(--fg)">12d ago</text>

        <text x="10" y="102" fontFamily="var(--mono)" fontSize="8" letterSpacing="1.2" fill="var(--fg-faint)">SOURCE</text>
        <text x="10" y="114" fontFamily="var(--mono)" fontSize="9" fill="#D4622A">agent_0473</text>
      </g>

      {/* connectors */}
      <line x1="140" y1="140" x2="160" y2="80" stroke="rgba(212,98,42,0.5)" strokeWidth="1"/>
      <line x1="340" y1="140" x2="360" y2="140" stroke="#D4622A" strokeWidth="1"/>

      {/* bottom annotation */}
      <text x="20" y="240" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="var(--fg-faint)">CONVERSATION CAPTURED ON-CHANNEL</text>
      <text x="20" y="256" fontFamily="var(--mono)" fontSize="9" letterSpacing="1.6" fill="var(--fg-faint)">CROSS-REFERENCED → SOURCE NAMED</text>
    </svg>
  );
}

window.SeedDiagram = SeedDiagram;
window.DetectDiagram = DetectDiagram;
window.TraceDiagram = TraceDiagram;
