// Original comic / urban-neon illustrations for clip tiles
// All hand-built SVG — no IP, no AI-image vibes. Halftone dots, splatters,
// speed lines, ben-day texture, sound-effect type.

// ── Shared SVG defs ────────────────────────────────────────────────────────
function ArtDefs({ id }) {
  return (
    <defs>
      {/* Ben-day halftone dot pattern */}
      <pattern id={`halftone-${id}`} x="0" y="0" width="6" height="6" patternUnits="userSpaceOnUse">
        <circle cx="3" cy="3" r="1.2" fill="rgba(0,0,0,0.35)" />
      </pattern>
      <pattern id={`halftone-light-${id}`} x="0" y="0" width="5" height="5" patternUnits="userSpaceOnUse">
        <circle cx="2.5" cy="2.5" r="0.9" fill="rgba(255,255,255,0.4)" />
      </pattern>
      {/* Speed line pattern */}
      <pattern id={`lines-${id}`} x="0" y="0" width="100" height="4" patternUnits="userSpaceOnUse">
        <rect width="60" height="1.5" y="1" fill="rgba(255,255,255,0.5)" />
      </pattern>
      {/* Radial vignette */}
      <radialGradient id={`vignette-${id}`} cx="50%" cy="50%" r="70%">
        <stop offset="60%" stopColor="rgba(0,0,0,0)" />
        <stop offset="100%" stopColor="rgba(0,0,0,0.6)" />
      </radialGradient>
    </defs>
  );
}

// ── Art 1: Neon skyline at dusk ────────────────────────────────────────────
function ArtSkyline() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="sk" />
      {/* Sky gradient */}
      <defs>
        <linearGradient id="sky-grad" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#1a0d3a" />
          <stop offset="40%" stopColor="#7a1f5e" />
          <stop offset="75%" stopColor="#f0593a" />
          <stop offset="100%" stopColor="#ffb347" />
        </linearGradient>
      </defs>
      <rect width="200" height="120" fill="url(#sky-grad)" />
      {/* Sun */}
      <circle cx="140" cy="78" r="22" fill="#ffe066" opacity="0.95" />
      <circle cx="140" cy="78" r="32" fill="#ffe066" opacity="0.18" />
      {/* Halftone over sky */}
      <rect width="200" height="80" fill={`url(#halftone-sk)`} opacity="0.5" />
      {/* Background buildings — silhouette */}
      <path d="M0,90 L0,70 L12,70 L12,55 L25,55 L25,75 L38,75 L38,60 L52,60 L52,72 L68,72 L68,50 L82,50 L82,68 L98,68 L98,58 L112,58 L112,72 L128,72 L128,62 L142,62 L142,75 L160,75 L160,55 L175,55 L175,70 L200,70 L200,90 Z"
            fill="#1a0824" />
      {/* Foreground buildings — taller, darker */}
      <path d="M0,120 L0,82 L18,82 L18,68 L32,68 L32,85 L48,85 L48,72 L64,72 L64,90 L80,90 L80,75 L96,75 L96,88 L114,88 L114,70 L130,70 L130,86 L150,86 L150,78 L168,78 L168,92 L185,92 L185,80 L200,80 L200,120 Z"
            fill="#0a0418" />
      {/* Building windows */}
      {[
        [22, 76], [25, 79], [28, 76],
        [38, 90], [41, 93], [44, 90],
        [70, 80], [73, 83], [76, 80],
        [100, 92], [103, 95],
        [120, 76], [123, 79], [126, 76],
        [155, 92], [158, 95],
        [173, 86], [176, 89],
      ].map(([x, y], i) => (
        <rect key={i} x={x} y={y} width="2" height="2" fill="#ffe066" opacity={0.7 + (i % 3) * 0.1} />
      ))}
      {/* Speed lines */}
      <rect x="0" y="20" width="200" height="3" fill={`url(#lines-sk)`} opacity="0.4" />
      <rect x="20" y="32" width="160" height="2" fill={`url(#lines-sk)`} opacity="0.3" />
      {/* Vignette */}
      <rect width="200" height="120" fill={`url(#vignette-sk)`} />
    </svg>
  );
}

// ── Art 2: Splatter burst ─────────────────────────────────────────────────
function ArtSplatter() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="sp" />
      <defs>
        <radialGradient id="sp-bg" cx="50%" cy="50%" r="70%">
          <stop offset="0%" stopColor="#3a1a6a" />
          <stop offset="100%" stopColor="#0a0418" />
        </radialGradient>
      </defs>
      <rect width="200" height="120" fill="url(#sp-bg)" />
      {/* Big splatter blobs */}
      <g>
        <circle cx="60" cy="55" r="32" fill="#ff2d8c" opacity="0.85" />
        <circle cx="130" cy="68" r="26" fill="#3ad6ff" opacity="0.8" />
        <circle cx="100" cy="40" r="14" fill="#ffe066" opacity="0.9" />
        <circle cx="155" cy="35" r="10" fill="#9d3aff" opacity="0.85" />
        <circle cx="38" cy="88" r="12" fill="#ffe066" opacity="0.85" />
        <circle cx="170" cy="92" r="14" fill="#ff2d8c" opacity="0.8" />
        {/* Drips & tails */}
        <ellipse cx="60" cy="92" rx="3" ry="14" fill="#ff2d8c" opacity="0.7" />
        <ellipse cx="130" cy="100" rx="2.5" ry="11" fill="#3ad6ff" opacity="0.7" />
        {/* Small dots */}
        {[
          [20, 30, 3, '#ffe066'], [180, 60, 2, '#ff2d8c'], [50, 110, 2.5, '#3ad6ff'],
          [115, 105, 2, '#9d3aff'], [85, 18, 2.5, '#3ad6ff'], [25, 70, 1.8, '#ff2d8c'],
          [195, 22, 2, '#ffe066'], [10, 105, 2, '#9d3aff'], [165, 110, 2.5, '#ffe066'],
        ].map(([x, y, r, c], i) => (
          <circle key={i} cx={x} cy={y} r={r} fill={c} opacity="0.85" />
        ))}
      </g>
      {/* Halftone overlay on big blobs */}
      <circle cx="60" cy="55" r="32" fill={`url(#halftone-sp)`} opacity="0.6" />
      <circle cx="130" cy="68" r="26" fill={`url(#halftone-sp)`} opacity="0.6" />
      {/* Sound effect */}
      <text x="100" y="70" textAnchor="middle"
            fontFamily="Impact, sans-serif" fontSize="34" fontWeight="900"
            fill="#fff" stroke="#0a0418" strokeWidth="2"
            transform="rotate(-8 100 65)">
        POW!
      </text>
      <rect width="200" height="120" fill={`url(#vignette-sp)`} />
    </svg>
  );
}

// ── Art 3: Speed lines / motion ────────────────────────────────────────────
function ArtSpeed() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="sd" />
      <defs>
        <radialGradient id="sd-bg" cx="80%" cy="50%" r="80%">
          <stop offset="0%" stopColor="#ffe066" />
          <stop offset="30%" stopColor="#ff6b3a" />
          <stop offset="70%" stopColor="#9d1a5c" />
          <stop offset="100%" stopColor="#1a0a2e" />
        </radialGradient>
      </defs>
      <rect width="200" height="120" fill="url(#sd-bg)" />
      {/* Radial speed lines from right side */}
      <g stroke="#fff" strokeWidth="1.5" opacity="0.7" fill="none">
        {Array.from({ length: 22 }).map((_, i) => {
          const angle = (i / 22) * Math.PI * 2;
          const r1 = 30 + (i % 3) * 8;
          const r2 = 80 + (i % 4) * 12;
          const cx = 160, cy = 60;
          const x1 = cx + Math.cos(angle) * r1;
          const y1 = cy + Math.sin(angle) * r1;
          const x2 = cx + Math.cos(angle) * r2;
          const y2 = cy + Math.sin(angle) * r2;
          return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} />;
        })}
      </g>
      {/* Center burst */}
      <circle cx="160" cy="60" r="14" fill="#fff" opacity="0.95" />
      <circle cx="160" cy="60" r="22" fill="#ffe066" opacity="0.5" />
      {/* Halftone */}
      <rect x="0" y="0" width="120" height="120" fill={`url(#halftone-sd)`} opacity="0.5" />
      {/* Diagonal accents */}
      <path d="M0,40 L60,30 L0,50 Z" fill="#fff" opacity="0.3" />
      <path d="M0,90 L70,80 L0,95 Z" fill="#fff" opacity="0.25" />
      {/* Small SFX */}
      <text x="35" y="68" textAnchor="middle"
            fontFamily="Impact, sans-serif" fontSize="22" fontWeight="900"
            fill="#ffe066" stroke="#1a0a2e" strokeWidth="1.5"
            transform="rotate(-12 35 68)">
        ZOOM
      </text>
      <rect width="200" height="120" fill={`url(#vignette-sd)`} />
    </svg>
  );
}

// ── Art 4: Glitch / chromatic ──────────────────────────────────────────────
function ArtGlitch() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="gl" />
      <rect width="200" height="120" fill="#04040a" />
      {/* Grid floor (synthwave perspective) */}
      <g stroke="#3ad6ff" strokeWidth="0.5" opacity="0.7" fill="none">
        {/* Horizontal lines */}
        {[60, 68, 78, 90, 105].map((y, i) => (
          <line key={`h${i}`} x1="0" y1={y} x2="200" y2={y} opacity={0.3 + i * 0.15} />
        ))}
        {/* Perspective verticals */}
        {Array.from({ length: 13 }).map((_, i) => {
          const x = (i - 6) * 30 + 100;
          return <line key={`v${i}`} x1="100" y1="60" x2={x * 1.5 - 50} y2="120" />;
        })}
      </g>
      {/* Sun with bands */}
      <defs>
        <linearGradient id="gl-sun" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ff2d8c" />
          <stop offset="100%" stopColor="#ffe066" />
        </linearGradient>
        <clipPath id="gl-sun-clip">
          <circle cx="100" cy="58" r="28" />
        </clipPath>
      </defs>
      <g clipPath="url(#gl-sun-clip)">
        <rect x="72" y="30" width="56" height="56" fill="url(#gl-sun)" />
        <rect x="72" y="44" width="56" height="2" fill="#04040a" />
        <rect x="72" y="50" width="56" height="3" fill="#04040a" />
        <rect x="72" y="58" width="56" height="3" fill="#04040a" />
        <rect x="72" y="68" width="56" height="4" fill="#04040a" />
      </g>
      {/* Chromatic offset duplicates */}
      <circle cx="98" cy="58" r="28" fill="none" stroke="#3ad6ff" strokeWidth="1" opacity="0.5" />
      <circle cx="102" cy="58" r="28" fill="none" stroke="#ff2d8c" strokeWidth="1" opacity="0.5" />
      {/* Glitch bars */}
      <rect x="0" y="22" width="200" height="2" fill="#3ad6ff" opacity="0.8" />
      <rect x="40" y="34" width="160" height="1" fill="#ff2d8c" opacity="0.7" />
      <rect x="0" y="100" width="120" height="1.5" fill="#ffe066" opacity="0.6" />
      {/* Stars */}
      {[[20, 18], [180, 14], [30, 40], [170, 28], [10, 30]].map(([x, y], i) => (
        <circle key={i} cx={x} cy={y} r="0.8" fill="#fff" opacity="0.9" />
      ))}
      <rect width="200" height="120" fill={`url(#vignette-gl)`} />
    </svg>
  );
}

// ── Art 5: Halftone alley ──────────────────────────────────────────────────
function ArtAlley() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="al" />
      <defs>
        <linearGradient id="al-bg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#0d0628" />
          <stop offset="100%" stopColor="#3a0d5c" />
        </linearGradient>
      </defs>
      <rect width="200" height="120" fill="url(#al-bg)" />
      {/* Alley walls — perspective */}
      <path d="M0,0 L60,30 L60,90 L0,120 Z" fill="#1a0a3a" />
      <path d="M200,0 L140,30 L140,90 L200,120 Z" fill="#1a0a3a" />
      {/* Wall windows / signs */}
      {[
        [10, 25, '#ff2d8c'], [22, 50, '#3ad6ff'], [10, 75, '#ffe066'],
        [165, 25, '#3ad6ff'], [180, 55, '#ff2d8c'], [168, 80, '#ffe066'],
      ].map(([x, y, c], i) => (
        <g key={i}>
          <rect x={x} y={y} width="14" height="6" fill={c} opacity="0.85" />
          <rect x={x} y={y} width="14" height="6" fill={c} opacity="0.4">
            <animate attributeName="opacity" values="0.4;0.9;0.4" dur="1.5s" repeatCount="indefinite" />
          </rect>
        </g>
      ))}
      {/* Far end glow */}
      <ellipse cx="100" cy="60" rx="40" ry="30" fill="#ff6b3a" opacity="0.55" />
      <ellipse cx="100" cy="60" rx="22" ry="18" fill="#ffe066" opacity="0.7" />
      {/* Far buildings */}
      <rect x="78" y="42" width="14" height="28" fill="#0a0418" />
      <rect x="92" y="38" width="10" height="32" fill="#0a0418" />
      <rect x="104" y="44" width="12" height="26" fill="#0a0418" />
      <rect x="118" y="40" width="8" height="30" fill="#0a0418" />
      {/* Windows in far buildings */}
      <rect x="82" y="48" width="2" height="2" fill="#ffe066" />
      <rect x="86" y="55" width="2" height="2" fill="#ffe066" />
      <rect x="95" y="50" width="2" height="2" fill="#ffe066" />
      <rect x="107" y="52" width="2" height="2" fill="#ffe066" />
      {/* Ground reflection */}
      <rect x="60" y="90" width="80" height="30" fill="#ff6b3a" opacity="0.15" />
      {/* Halftone over walls */}
      <path d="M0,0 L60,30 L60,90 L0,120 Z" fill={`url(#halftone-al)`} opacity="0.6" />
      <path d="M200,0 L140,30 L140,90 L200,120 Z" fill={`url(#halftone-al)`} opacity="0.6" />
      {/* Speed lines down the alley */}
      <line x1="100" y1="60" x2="20" y2="20" stroke="#fff" strokeWidth="0.5" opacity="0.4" />
      <line x1="100" y1="60" x2="180" y2="20" stroke="#fff" strokeWidth="0.5" opacity="0.4" />
      <line x1="100" y1="60" x2="10" y2="100" stroke="#fff" strokeWidth="0.5" opacity="0.4" />
      <line x1="100" y1="60" x2="190" y2="100" stroke="#fff" strokeWidth="0.5" opacity="0.4" />
      <rect width="200" height="120" fill={`url(#vignette-al)`} />
    </svg>
  );
}

// ── Art 6: Comic panel BOOM ────────────────────────────────────────────────
function ArtBoom() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice"
         style={{ display: 'block' }}>
      <ArtDefs id="bm" />
      <defs>
        <radialGradient id="bm-bg" cx="50%" cy="50%" r="80%">
          <stop offset="0%" stopColor="#ffe066" />
          <stop offset="40%" stopColor="#ff6b3a" />
          <stop offset="100%" stopColor="#7a1f3a" />
        </radialGradient>
      </defs>
      <rect width="200" height="120" fill="url(#bm-bg)" />
      {/* Star burst shape */}
      <g transform="translate(100 60)">
        <polygon points={
          Array.from({ length: 24 }).map((_, i) => {
            const angle = (i / 24) * Math.PI * 2;
            const r = i % 2 === 0 ? 60 : 30;
            return `${Math.cos(angle) * r},${Math.sin(angle) * r}`;
          }).join(' ')
        } fill="#ffe066" stroke="#0a0418" strokeWidth="2" />
        <polygon points={
          Array.from({ length: 16 }).map((_, i) => {
            const angle = (i / 16) * Math.PI * 2 + 0.1;
            const r = i % 2 === 0 ? 40 : 22;
            return `${Math.cos(angle) * r},${Math.sin(angle) * r}`;
          }).join(' ')
        } fill="#fff" />
      </g>
      {/* Halftone on burst edges */}
      <g transform="translate(100 60)">
        <polygon points={
          Array.from({ length: 24 }).map((_, i) => {
            const angle = (i / 24) * Math.PI * 2;
            const r = i % 2 === 0 ? 60 : 30;
            return `${Math.cos(angle) * r},${Math.sin(angle) * r}`;
          }).join(' ')
        } fill={`url(#halftone-bm)`} opacity="0.4" />
      </g>
      {/* BOOM text */}
      <text x="100" y="70" textAnchor="middle"
            fontFamily="Impact, sans-serif" fontSize="42" fontWeight="900"
            fill="#ff2d8c" stroke="#0a0418" strokeWidth="2.5"
            transform="rotate(-6 100 65)">
        BOOM
      </text>
      <rect width="200" height="120" fill={`url(#vignette-bm)`} />
    </svg>
  );
}

const ART_COMPONENTS = [
  ArtSkyline,
  ArtSplatter,
  ArtSpeed,
  ArtGlitch,
  ArtAlley,
  ArtBoom,
];

// Pick art by index (cycles)
function ClipArt({ idx }) {
  const Art = ART_COMPONENTS[idx % ART_COMPONENTS.length];
  return <Art />;
}

Object.assign(window, { ClipArt, ART_COMPONENTS });
