// Bauhaus-poster geometric marks. Each is a minimal SVG mark that can live
// inside a blob. Organ "icons" are expressed in the same mark vocabulary
// (circle+dot = eye, chevron stack = ear, squiggle = mouth, etc).

const strokeColor = 'var(--ink)';

// --- Generic marks used as decoration inside blobs ---
const DotGrid = ({ cols = 5, rows = 5, gap = 14 }) => {
  const dots = [];
  for (let r = 0; r < rows; r++)
    for (let c = 0; c < cols; c++)
      dots.push(<circle key={`${r}-${c}`} cx={c * gap} cy={r * gap} r="2.2" fill="currentColor" />);
  return (
    <svg width={(cols - 1) * gap + 8} height={(rows - 1) * gap + 8} style={{ overflow: 'visible' }}>
      <g transform="translate(4,4)">{dots}</g>
    </svg>
  );
};

const Squiggle = ({ w = 60, amp = 10, cycles = 3 }) => {
  const pts = [];
  const step = w / (cycles * 20);
  for (let i = 0; i <= cycles * 20; i++) {
    const x = i * step;
    const y = Math.sin((i / 20) * Math.PI * 2) * amp;
    pts.push(`${i === 0 ? 'M' : 'L'} ${x} ${y}`);
  }
  return (
    <svg width={w} height={amp * 2 + 6} style={{ overflow: 'visible' }}>
      <g transform={`translate(0 ${amp + 3})`}>
        <path d={pts.join(' ')} stroke="currentColor" strokeWidth="2" fill="none" strokeLinecap="round" />
      </g>
    </svg>
  );
};

const Plus = ({ s = 24, w = 2 }) => (
  <svg width={s} height={s}>
    <line x1={s/2} y1="2" x2={s/2} y2={s-2} stroke="currentColor" strokeWidth={w} strokeLinecap="round" />
    <line x1="2" y1={s/2} x2={s-2} y2={s/2} stroke="currentColor" strokeWidth={w} strokeLinecap="round" />
  </svg>
);

const XMark = ({ s = 18, w = 2 }) => (
  <svg width={s} height={s}>
    <line x1="2" y1="2" x2={s-2} y2={s-2} stroke="currentColor" strokeWidth={w} strokeLinecap="round" />
    <line x1={s-2} y1="2" x2="2" y2={s-2} stroke="currentColor" strokeWidth={w} strokeLinecap="round" />
  </svg>
);

const Sunburst = ({ s = 60, rays = 16 }) => {
  const lines = [];
  const cx = s / 2, cy = s / 2, r1 = 4, r2 = s / 2 - 2;
  for (let i = 0; i < rays; i++) {
    const a = (i / rays) * Math.PI * 2;
    lines.push(
      <line key={i}
        x1={cx + Math.cos(a) * r1} y1={cy + Math.sin(a) * r1}
        x2={cx + Math.cos(a) * r2} y2={cy + Math.sin(a) * r2}
        stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
    );
  }
  return <svg width={s} height={s}>{lines}<circle cx={cx} cy={cy} r="2" fill="currentColor" /></svg>;
};

// Hatched parallel lines (top-right of yellow blob)
const Hatch = ({ w = 60, count = 5, gap = 5 }) => {
  const lines = [];
  for (let i = 0; i < count; i++) {
    lines.push(
      <line key={i} x1="0" y1={i * gap} x2={w} y2={i * gap}
        stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
    );
  }
  return <svg width={w} height={(count - 1) * gap + 2}>{lines}</svg>;
};

const Target = ({ s = 28 }) => (
  <svg width={s} height={s}>
    <circle cx={s/2} cy={s/2} r={s/2 - 2} stroke="currentColor" strokeWidth="2" fill="none" />
    <circle cx={s/2} cy={s/2} r="3" fill="currentColor" />
  </svg>
);

const Bowtie = ({ s = 26 }) => (
  <svg width={s} height={s}>
    <polygon points={`2,2 ${s-2},${s-2} ${s-2},2 2,${s-2}`} fill="none" stroke="currentColor" strokeWidth="1.8" />
  </svg>
);

const Arrow = ({ s = 28 }) => (
  <svg width={s} height={s}>
    <line x1={s-3} y1="3" x2="5" y2={s-5} stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" />
    <line x1="5" y1={s-5} x2="14" y2={s-5} stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" />
    <line x1="5" y1={s-5} x2="5" y2={s-16} stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" />
  </svg>
);

const SquareFilled = ({ s = 26 }) => (
  <svg width={s} height={s}>
    <rect x="0" y="0" width={s} height={s} fill="currentColor" />
    <rect x="5" y="5" width={s-10} height={s-10} fill="none" stroke="var(--paper)" strokeWidth="2" />
  </svg>
);

const Zigzag = ({ w = 70, h = 18 }) => (
  <svg width={w} height={h}>
    <polyline
      points={`0 ${h/2} ${w*0.2} 2 ${w*0.4} ${h-2} ${w*0.6} 2 ${w*0.8} ${h-2} ${w} ${h/2}`}
      fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"
    />
  </svg>
);

const SmallPlus = ({ s = 14 }) => (
  <svg width={s} height={s}>
    <line x1={s/2} y1="0" x2={s/2} y2={s} stroke="currentColor" strokeWidth="3" />
    <line x1="0" y1={s/2} x2={s} y2={s/2} stroke="currentColor" strokeWidth="3" />
    <rect x={s/2 - 1.5} y={s/2 - 1.5} width="3" height="3" fill="var(--paper)" />
  </svg>
);

// --- Organ glyphs in the same vocabulary ---

// EYE: Lucide-style line-art eye. Oval almond shape, iris circle, pupil tracks cursor.
const EyeGlyph = ({ pupilX = 0, pupilY = 0, blink = false, s = 160 }) => {
  const px = Math.max(-1, Math.min(1, pupilX)) * 3;
  const py = Math.max(-1, Math.min(1, pupilY)) * 1.6;
  return (
    <svg width={s} height={blink ? 14 : s * 0.62} viewBox="0 0 24 14"
      fill="none" stroke="currentColor" strokeWidth="1.6"
      strokeLinecap="round" strokeLinejoin="round"
      style={{ overflow: 'visible' }}>
      {blink ? (
        <path d="M1 7 Q 12 9 23 7" strokeWidth="1.8" />
      ) : (
        <g>
          {/* Lucide eye outline — almond shape */}
          <path d="M1 7s4-6 11-6 11 6 11 6-4 6-11 6S1 7 1 7z" />
          {/* iris */}
          <circle cx={12 + px} cy={7 + py} r="3" />
          {/* pupil */}
          <circle cx={12 + px} cy={7 + py} r="1.2" fill="currentColor" />
        </g>
      )}
    </svg>
  );
};

// MOUTH: a smooth squiggle that opens/closes by amplitude
// MOUTH: doodle-style three-line mouth (upper lip with cupid's bow, mid line,
// lower lip). When `open` rises, the lower curve drops to suggest an open mouth.
const MouthGlyph = ({ open = 0, s = 160 }) => {
  const drop = open * 18; // px in viewBox units
  return (
    <svg width={s} height={s} viewBox="0 0 400 400" fill="none"
      stroke="currentColor" strokeWidth="16"
      strokeLinecap="round" strokeLinejoin="round"
      style={{ overflow: 'visible' }}>
      {/* offset red lips fill — peeks out from behind the mouth lines */}
      <g transform="translate(12 10)" fill="#D64A4A" stroke="none">
        {/* upper lip filled shape */}
        <path d="M75 215 C100 215, 130 185, 160 178 C175 174, 188 182, 200 182 C212 182, 225 174, 240 178 C270 185, 300 215, 325 215 C280 225, 240 228, 200 228 C160 228, 120 225, 75 215 Z" />
        {/* lower lip filled shape */}
        <path d={`M75 215 C120 225, 160 228, 200 228 C240 228, 280 225, 325 215 C300 ${250 + drop}, 250 ${268 + drop * 1.4}, 200 ${270 + drop * 1.6} C150 ${268 + drop * 1.4}, 100 ${250 + drop}, 75 215 Z`} />
      </g>
      {/* upper lip — cupid's bow */}
      <path d="M75 215 C100 215, 130 185, 160 178 C175 174, 188 182, 200 182 C212 182, 225 174, 240 178 C270 185, 300 215, 325 215" />
      {/* mid line */}
      <path d="M75 215 C120 225, 160 228, 200 228 C240 228, 280 225, 325 215" />
      {/* lower lip — drops as mouth opens */}
      <path d={`M75 215 C100 ${250 + drop}, 150 ${268 + drop * 1.4}, 200 ${270 + drop * 1.6} C250 ${268 + drop * 1.4}, 300 ${250 + drop}, 325 215`} />
    </svg>
  );
};

// EAR: Lucide-style minimal line icon (MIT licensed).
// Clean single-stroke profile with inner curl — reads as an ear, not a face.
const EarGlyph = ({ listening = false, s = 110 }) => {
  const W = s, H = s;
  return (
    <svg width={W} height={H} viewBox="0 0 24 24" fill="none"
      stroke="currentColor" strokeWidth="1.8"
      strokeLinecap="round" strokeLinejoin="round"
      style={{ overflow: 'visible' }}>
      {/* Lucide "ear" path */}
      <path d="M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0" />
      <path d="M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4" />
      {/* listening indicator: sound waves to the left */}
      {listening && (
        <g>
          <path d="M3 10.5c-0.8 1-0.8 2 0 3" opacity="1" />
          <path d="M1 8.5c-1.5 2-1.5 5 0 7" opacity="0.6" />
        </g>
      )}
    </svg>
  );
};

// BRAIN: doodle-style line-art brain — twin lobes with scribbled inner folds.
// Pulse subtly scales the whole illustration for the thinking state.
const BrainGlyph = ({ pulse = 0, s = 150 }) => {
  const scale = 1 + pulse * 0.035;
  return (
    <svg width={s} height={s} viewBox="0 0 400 400" fill="none"
      stroke="currentColor" strokeWidth="16"
      strokeLinecap="round" strokeLinejoin="round"
      style={{ overflow: 'visible' }}>
      <g transform={`translate(200 200) scale(${scale}) translate(-200 -200)`}>
        {/* offset pink fill — peeks out from behind the brain */}
        <g transform="translate(14 12)" fill="#F4B8C8" stroke="none">
          <path d="M155.271 88.6788C148.578 71.6978 203.052 42.643 200.816 94.316C199.692 120.307 201.216 147.237 198.597 173.31C193.638 222.643 196.369 268.262 192.519 324.634C191.484 339.791 153.681 337.312 144.373 329.369C132.519 319.266 132.496 308.623 126.154 298.113C123.251 293.298 112.196 287.717 106.478 279.185C96.6827 264.568 98.6524 256.01 101.058 241.653C102.452 233.32 96.2186 222.932 98.5123 213.808C103.657 193.337 118.566 171.693 138.261 166.094 L 155.271 88.6788 Z" />
          <path d="M207.691 70.927C255.255 48.0489 255.255 88.2874 257.844 98.7349C258.934 103.122 283.731 120.451 287.938 128.227C295.575 142.341 280.846 160.494 283.758 167.828C288.2 179.027 301.732 183.042 302.981 198.162C303.568 205.269 289.646 229.414 290.443 231.025C295.841 241.907 301.363 246.298 297.132 260.516C290.792 281.822 272.749 285.937 260.353 298.438C253.699 305.142 257.15 315.547 246.979 322.871C235.839 330.893 219.453 319.357 219.394 319.503C215.432 329.484 194.984 345.112 189.304 327.929 L 207.691 70.927 Z" />
        </g>
        {/* left lobe outer */}
        <path d="M155.271 88.6788C148.578 71.6978 203.052 42.643 200.816 94.316C199.692 120.307 201.216 147.237 198.597 173.31C193.638 222.643 196.369 268.262 192.519 324.634C191.484 339.791 153.681 337.312 144.373 329.369C132.519 319.266 132.496 308.623 126.154 298.113C123.251 293.298 112.196 287.717 106.478 279.185C96.6827 264.568 98.6524 256.01 101.058 241.653C102.452 233.32 96.2186 222.932 98.5123 213.808C103.657 193.337 118.566 171.693 138.261 166.094" />
        {/* left inner folds */}
        <path d="M152.459 86.1075C119.801 88.8514 132.389 117.222 129.036 128.69C127.839 132.779 102.333 139.942 109.518 182.959" />
        <path d="M161.99 115.584C205.08 147.237 120.343 195.064 160.365 228.227" />
        <path d="M172.461 197.698C184.142 204.735 170.353 214.154 191.41 216.647" />
        <path d="M186.419 255.598C154.795 248.009 190.196 310.34 162.985 310.34" />
        <path d="M122.982 260.333C136.218 247.459 145.554 264.77 152.459 266.125" />
        <path d="M119.824 222.963C125.208 230.098 127.342 234.384 136.668 233.333" />
        {/* right lobe outer */}
        <path d="M207.691 70.927C255.255 48.0489 255.255 88.2874 257.844 98.7349C258.934 103.122 283.731 120.451 287.938 128.227C295.575 142.341 280.846 160.494 283.758 167.828C288.2 179.027 301.732 183.042 302.981 198.162C303.568 205.269 289.646 229.414 290.443 231.025C295.841 241.907 301.363 246.298 297.132 260.516C290.792 281.822 272.749 285.937 260.353 298.438C253.699 305.142 257.15 315.547 246.979 322.871C235.839 330.893 219.453 319.357 219.394 319.503C215.432 329.484 194.984 345.112 189.304 327.929" />
        {/* right inner folds */}
        <path d="M253.205 137.692C230.52 170.541 269.558 180.358 272.401 200.24C273.448 207.568 262.291 214.844 260.717 221.927C257.471 236.526 267.394 252.053 267.394 266.126" />
        <path d="M201.938 235.247C247.61 227.77 210.079 282.174 236.679 289.286" />
        <path d="M234.684 110.32C217.416 126.751 219.622 155.694 223.973 175.256C226.44 186.345 217.281 224.119 243.734 202.941" />
      </g>
    </svg>
  );
};

// HAND: Lucide "hand" icon — four fingers + thumb palm silhouette.
const HandGlyph = ({ s = 90 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none"
    stroke="currentColor" strokeWidth="1.8"
    strokeLinecap="round" strokeLinejoin="round"
    style={{ overflow: 'visible' }}>
    <path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2" />
    <path d="M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2" />
    <path d="M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8" />
    <path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" />
  </svg>
);

// --- minimalist scattered marks for the ear block ---

const TriangleOutline = ({ s = 24 }) => (
  <svg width={s} height={s * 0.92} viewBox="0 0 24 22" style={{ display: 'block', overflow: 'visible' }}>
    <polygon points="2,2 22,2 12,20" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" />
  </svg>
);

const DotPair = ({ s = 12 }) => (
  <svg width={s} height={s * 1.5} viewBox="0 0 12 18" style={{ display: 'block', overflow: 'visible' }}>
    <circle cx="6" cy="4"  r="1.6" fill="currentColor" />
    <circle cx="6" cy="14" r="1.6" fill="currentColor" />
  </svg>
);

const ArcMark = ({ s = 32 }) => (
  <svg width={s} height={s * 0.55} viewBox="0 0 32 18" style={{ display: 'block', overflow: 'visible' }}>
    <path d="M 2 16 A 14 14 0 0 1 30 16" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
  </svg>
);

const Paren = ({ s = 18 }) => (
  <svg width={s * 0.5} height={s} viewBox="0 0 9 18" style={{ display: 'block', overflow: 'visible' }}>
    <path d="M 2 2 Q 8 9, 2 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
  </svg>
);

const DashedLine = ({ w = 60, h = 4 }) => (
  <svg width={w} height={h + 2} viewBox={`0 0 ${w} ${h + 2}`} style={{ display: 'block', overflow: 'visible' }}>
    <line x1="0" y1={(h + 2) / 2} x2={w} y2={(h + 2) / 2} stroke="currentColor" strokeWidth="1.5" strokeDasharray="4 4" strokeLinecap="round" />
  </svg>
);

const Asterisk = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 18 18" style={{ display: 'block', overflow: 'visible' }}>
    <g stroke="currentColor" strokeWidth="1.5" strokeLinecap="round">
      <line x1="9" y1="2"  x2="9"  y2="16" />
      <line x1="2" y1="9"  x2="16" y2="9" />
      <line x1="3.5" y1="3.5" x2="14.5" y2="14.5" />
      <line x1="14.5" y1="3.5" x2="3.5" y2="14.5" />
    </g>
  </svg>
);

window.Marks = {
  DotGrid, Squiggle, Plus, XMark, Sunburst, Hatch, Target,
  Bowtie, Arrow, SquareFilled, Zigzag, SmallPlus,
  TriangleOutline, DotPair, ArcMark, Paren, DashedLine, Asterisk,
  EyeGlyph, MouthGlyph, EarGlyph, BrainGlyph, HandGlyph,
};
