
// agent-core.jsx — faithful port of the 21st.dev "CPU Architecture" animation.
// Technique: each trace has a white-stroke mask; a radial-gradient orb (bright
// leading edge) rides the same path via CSS offset-path, revealed only over the
// line → a glowing comet that flows into the CPU. Wrapped in our navy section.
window.DZ = window.DZ || {};

function AgentCore() {
  const text = 'DELZ';
  const lineMarkerSize = 18;

  // Tools sit at each trace's outer origin (where its light is born).
  const NODES = [
    { x: 10,   y: 22.5, color: '#25D366', brand: 'whatsapp',  label: 'WhatsApp' },
    { x: 30,   y: 33, color: '#2AABEE', brand: 'telegram',  label: 'Telegram' },
    { x: 88,   y: 88,  color: '#0A84FF', mail: true,          label: 'Email' },
    { x: 94.8, y: 104, color: '#8B7CFF', brand: 'slack',     label: 'Slack' },
    { x: 130,  y: 20, color: '#F26A1F', lucide: 'calendar', label: 'Calendar' },
    { x: 180,  y: 12.5, color: '#3B82F6', lucide: 'database', label: 'CRM' },
    { x: 135,  y: 63, color: '#1F8A5B', lucide: 'globe',    label: 'Web' },
    { x: 170,  y: 80, color: '#E0529C', lucide: 'file-text',label: 'Docs' },
  ];
  const renderIcon = (n, size) => {
    if (n.mail) return (
      <svg viewBox="0 0 24 24" width={size} height={size} aria-hidden="true">
        <path fill="#fff" d="M4.2 6h15.6c1.05 0 1.9.85 1.9 1.9v8.2c0 1.05-.85 1.9-1.9 1.9H4.2A1.9 1.9 0 0 1 2.3 16.1V7.9C2.3 6.85 3.15 6 4.2 6Z" />
        <path fill="none" stroke={n.color} strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" d="M3.2 8.4 12 14.2l8.8-5.8" />
      </svg>
    );
    if (n.brand && window.BRAND_ICONS && window.BRAND_ICONS[n.brand]) return (
      <svg viewBox="0 0 24 24" width={size} height={size} fill="#fff" aria-hidden="true"><path d={window.BRAND_ICONS[n.brand]} /></svg>
    );
    return <i data-lucide={n.lucide} style={{ width: size, height: size, color: '#fff' }} />;
  };

  return (
    <section style={{ padding: 'clamp(20px, 5vw, 56px)' }}>
      <style>{`
        .cpu-architecture { offset-anchor: 10px 0px; animation: dz-cpu-move infinite; animation-timing-function: cubic-bezier(0.75, -0.01, 0, 0.99); }
        @keyframes dz-cpu-move { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } }
        .cpu-line-1 { offset-path: path("M 10 20 h 79.5 q 5 0 5 5 v 30"); animation-duration: 5s; animation-delay: 1s; }
        .cpu-line-2 { offset-path: path("M 180 10 h -69.7 q -5 0 -5 5 v 40"); animation-delay: 6s; animation-duration: 2s; }
        .cpu-line-3 { offset-path: path("M 130 20 v 21.8 q 0 5 -5 5 h -25"); animation-delay: 4s; animation-duration: 6s; }
        .cpu-line-4 { offset-path: path("M 170 80 v -21.8 q 0 -5 -5 -5 h -65"); animation-delay: 3s; animation-duration: 3s; }
        .cpu-line-5 { offset-path: path("M 135 65 h 15 q 5 0 5 5 v 10 q 0 5 -5 5 h -39.8 q -5 0 -5 -5 v -35"); animation-delay: 9s; animation-duration: 4s; }
        .cpu-line-6 { offset-path: path("M 94.8 104 v -55"); animation-delay: 3s; animation-duration: 7s; }
        .cpu-line-7 { offset-path: path("M 88 88 v -15 q 0 -5 -5 -5 h -10 q -5 0 -5 -5 v -5 q 0 -5 5 -5 h 28"); animation-delay: 4s; animation-duration: 4s; }
        .cpu-line-8 { offset-path: path("M 30 30 h 25 q 5 0 5 5 v 6.5 q 0 5 5 5 h 35"); animation-delay: 3s; animation-duration: 3s; }
        @media (prefers-reduced-motion: reduce) { .cpu-architecture { animation: none; opacity: 0; } }
      `}</style>

      <div style={{ position: 'relative', overflow: 'hidden', maxWidth: 'var(--container-xl)', margin: '0 auto', background: 'var(--navy-ink)', borderRadius: 'var(--radius-xl)', padding: 'clamp(40px, 6vw, 76px) clamp(20px, 5vw, 56px)' }}>
        <div aria-hidden style={{ position: 'absolute', inset: 0, background: 'radial-gradient(60% 90% at 50% 0%, rgba(242,106,31,0.16), transparent 55%), radial-gradient(70% 100% at 50% 120%, rgba(27,63,196,0.28), transparent 60%)' }} />

        <div style={{ position: 'relative', textAlign: 'center', maxWidth: 620, margin: '0 auto clamp(24px, 4vw, 44px)' }}>
          <div className="eyebrow" style={{ color: 'var(--orange-300)', marginBottom: 16 }}>THE AGENT CORE</div>
          <h2 style={{ color: '#fff', fontSize: 'clamp(28px, 4vw, 46px)', margin: '0 0 16px' }}>Every tool, one intelligent core</h2>
          <p style={{ color: 'rgba(255,255,255,0.70)', fontSize: 17, lineHeight: 1.65, margin: 0 }}>
            Your channels and tools stream into a single agent core. It reads the full picture, decides, and acts - everywhere at once.
          </p>
        </div>

        <div style={{ position: 'relative', width: '100%', maxWidth: 760, margin: '0 auto', marginBottom: 'clamp(26px, 6vw, 56px)' }}>
          <svg width="100%" height="100%" viewBox="0 0 200 100" aria-hidden="true" style={{ color: 'rgba(255,255,255,0.22)', display: 'block', overflow: 'visible' }}>
            {/* Paths */}
            <g stroke="currentColor" fill="none" strokeWidth="0.3" strokeDasharray="100 100" pathLength="100" markerStart="url(#cpu-circle-marker)">
              <path strokeDasharray="100 100" pathLength="100" d="M 10 20 h 79.5 q 5 0 5 5 v 30" />
              <path strokeDasharray="100 100" pathLength="100" d="M 180 10 h -69.7 q -5 0 -5 5 v 30" />
              <path d="M 130 20 v 21.8 q 0 5 -5 5 h -10" />
              <path d="M 170 80 v -21.8 q 0 -5 -5 -5 h -50" />
              <path strokeDasharray="100 100" pathLength="100" d="M 135 65 h 15 q 5 0 5 5 v 10 q 0 5 -5 5 h -39.8 q -5 0 -5 -5 v -20" />
              <path d="M 94.8 104 v -45" />
              <path d="M 88 88 v -15 q 0 -5 -5 -5 h -10 q -5 0 -5 -5 v -5 q 0 -5 5 -5 h 14" />
              <path d="M 30 30 h 25 q 5 0 5 5 v 6.5 q 0 5 5 5 h 20" />
              <animate attributeName="stroke-dashoffset" from="100" to="0" dur="1s" fill="freeze" calcMode="spline" keySplines="0.25,0.1,0.5,1" keyTimes="0; 1" />
            </g>

            {/* Light orbs (masked to each trace) */}
            <g mask="url(#cpu-mask-1)"><circle className="cpu-architecture cpu-line-1" cx="0" cy="0" r="8" fill="url(#cpu-blue-grad)" /></g>
            <g mask="url(#cpu-mask-2)"><circle className="cpu-architecture cpu-line-2" cx="0" cy="0" r="8" fill="url(#cpu-yellow-grad)" /></g>
            <g mask="url(#cpu-mask-3)"><circle className="cpu-architecture cpu-line-3" cx="0" cy="0" r="8" fill="url(#cpu-pinkish-grad)" /></g>
            <g mask="url(#cpu-mask-4)"><circle className="cpu-architecture cpu-line-4" cx="0" cy="0" r="8" fill="url(#cpu-white-grad)" /></g>
            <g mask="url(#cpu-mask-5)"><circle className="cpu-architecture cpu-line-5" cx="0" cy="0" r="8" fill="url(#cpu-green-grad)" /></g>
            <g mask="url(#cpu-mask-6)"><circle className="cpu-architecture cpu-line-6" cx="0" cy="0" r="8" fill="url(#cpu-orange-grad)" /></g>
            <g mask="url(#cpu-mask-7)"><circle className="cpu-architecture cpu-line-7" cx="0" cy="0" r="8" fill="url(#cpu-cyan-grad)" /></g>
            <g mask="url(#cpu-mask-8)"><circle className="cpu-architecture cpu-line-8" cx="0" cy="0" r="8" fill="url(#cpu-rose-grad)" /></g>

            {/* CPU Box */}
            <g>
              <g fill="url(#cpu-connection-gradient)">
                <rect x="93" y="37" width="2.5" height="5" rx="0.7" />
                <rect x="104" y="37" width="2.5" height="5" rx="0.7" />
                <rect x="116.3" y="44" width="2.5" height="5" rx="0.7" transform="rotate(90 116.25 45.5)" />
                <rect x="122.8" y="44" width="2.5" height="5" rx="0.7" transform="rotate(90 116.25 45.5)" />
                <rect x="104" y="16" width="2.5" height="5" rx="0.7" transform="rotate(180 105.25 39.5)" />
                <rect x="114.5" y="16" width="2.5" height="5" rx="0.7" transform="rotate(180 105.25 39.5)" />
                <rect x="80" y="-13.6" width="2.5" height="5" rx="0.7" transform="rotate(270 115.25 19.5)" />
                <rect x="87" y="-13.6" width="2.5" height="5" rx="0.7" transform="rotate(270 115.25 19.5)" />
              </g>
              <rect x="85" y="40" width="30" height="20" rx="2" fill="#0b1020" filter="url(#cpu-light-shadow)" stroke="rgba(255,255,255,0.10)" strokeWidth="0.3" />
              <image href="assets/logo-mark.png" xlinkHref="assets/logo-mark.png" x="93" y="43" width="14" height="14" preserveAspectRatio="xMidYMid meet" />
            </g>

            {/* Masks + gradients */}
            <defs>
              <mask id="cpu-mask-1"><path d="M 10 20 h 79.5 q 5 0 5 5 v 24" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-2"><path d="M 180 10 h -69.7 q -5 0 -5 5 v 24" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-3"><path d="M 130 20 v 21.8 q 0 5 -5 5 h -10" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-4"><path d="M 170 80 v -21.8 q 0 -5 -5 -5 h -50" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-5"><path d="M 135 65 h 15 q 5 0 5 5 v 10 q 0 5 -5 5 h -39.8 q -5 0 -5 -5 v -20" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-6"><path d="M 94.8 104 v -45" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-7"><path d="M 88 88 v -15 q 0 -5 -5 -5 h -10 q -5 0 -5 -5 v -5 q 0 -5 5 -5 h 14" strokeWidth="0.5" stroke="white" /></mask>
              <mask id="cpu-mask-8"><path d="M 30 30 h 25 q 5 0 5 5 v 6.5 q 0 5 5 5 h 20" strokeWidth="0.5" stroke="white" /></mask>

              <radialGradient id="cpu-blue-grad" fx="1"><stop offset="0%" stopColor="#00E8ED" /><stop offset="50%" stopColor="#08F" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-yellow-grad" fx="1"><stop offset="0%" stopColor="#FFD800" /><stop offset="50%" stopColor="#FFD800" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-pinkish-grad" fx="1"><stop offset="0%" stopColor="#830CD1" /><stop offset="50%" stopColor="#FF008B" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-white-grad" fx="1"><stop offset="0%" stopColor="white" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-green-grad" fx="1"><stop offset="0%" stopColor="#22c55e" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-orange-grad" fx="1"><stop offset="0%" stopColor="#f97316" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-cyan-grad" fx="1"><stop offset="0%" stopColor="#06b6d4" /><stop offset="100%" stopColor="transparent" /></radialGradient>
              <radialGradient id="cpu-rose-grad" fx="1"><stop offset="0%" stopColor="#f43f5e" /><stop offset="100%" stopColor="transparent" /></radialGradient>

              <filter id="cpu-light-shadow" x="-50%" y="-50%" width="200%" height="200%"><feDropShadow dx="1.5" dy="1.5" stdDeviation="1" floodColor="black" floodOpacity="0.3" /></filter>

              <marker id="cpu-circle-marker" viewBox="0 0 10 10" refX="5" refY="5" markerWidth={lineMarkerSize} markerHeight={lineMarkerSize}>
                <circle cx="5" cy="5" r="2" fill="#0b1020" stroke="#2a3350" strokeWidth="0.5">
                  <animate attributeName="r" values="0; 3; 2" dur="0.5s" />
                </circle>
              </marker>

              <linearGradient id="cpu-connection-gradient" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stopColor="#4F4F4F" /><stop offset="60%" stopColor="#121214" /></linearGradient>

              <linearGradient id="cpu-text-gradient" x1="0" y1="0" x2="1" y2="0">
                <stop offset="0%" stopColor="#7d88a8"><animate attributeName="offset" values="-2; -1; 0" dur="5s" repeatCount="indefinite" calcMode="spline" keyTimes="0; 0.5; 1" keySplines="0.4 0 0.2 1; 0.4 0 0.2 1" /></stop>
                <stop offset="25%" stopColor="#ffffff"><animate attributeName="offset" values="-1; 0; 1" dur="5s" repeatCount="indefinite" calcMode="spline" keyTimes="0; 0.5; 1" keySplines="0.4 0 0.2 1; 0.4 0 0.2 1" /></stop>
                <stop offset="50%" stopColor="#7d88a8"><animate attributeName="offset" values="0; 1; 2;" dur="5s" repeatCount="indefinite" calcMode="spline" keyTimes="0; 0.5; 1" keySplines="0.4 0 0.2 1; 0.4 0 0.2 1" /></stop>
              </linearGradient>
            </defs>
          </svg>

          {/* tool icons at each trace origin */}
          {NODES.map((n, i) => {
            const below = n.y < 50;
            return (
              <div key={i} style={{ position: 'absolute', left: (n.x / 200 * 100) + '%', top: (n.y / 100 * 100) + '%', transform: 'translate(-50%, -50%)', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 5 }}>
                {!below && <span style={{ fontSize: 'clamp(9px, 1.1vw, 11px)', fontWeight: 500, color: 'rgba(255,255,255,0.66)', whiteSpace: 'nowrap', order: -1 }}>{n.label}</span>}
                <span style={{ width: 'clamp(26px, 3.6vw, 36px)', height: 'clamp(26px, 3.6vw, 36px)', borderRadius: 'var(--radius-md)', background: n.color, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', boxShadow: `0 0 0 1px rgba(255,255,255,0.12), 0 5px 16px ${n.color}55` }}>
                  {renderIcon(n, 18)}
                </span>
                {below && <span style={{ fontSize: 'clamp(9px, 1.1vw, 11px)', fontWeight: 500, color: 'rgba(255,255,255,0.66)', whiteSpace: 'nowrap' }}>{n.label}</span>}
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}
window.DZ.AgentCore = AgentCore;














