// Hand-drawn SVG illustrations for peptides and articles
// Style: cream bg, ink 1.5px stroke, splat-green + accent fills, dot/grid patterns

const IL_COLORS = {
  ink: "#0F1F2C", cream: "#FAF6EC", cream2: "#F2EBD8", paper: "#FFFDF6",
  splat: "#5FBF5F", splatDeep: "#2F8C3A", splatSoft: "#C7ECBF", splatGlow: "#B6E4A8",
  coral: "#F26B4A", sun: "#F2C94C", sky: "#7FB8D6", lilac: "#B9A7D6", rose: "#E89AB1",
  muted: "#6B7A85",
};

const DotPattern = ({ id, color = "rgba(15,31,44,0.14)" }) => (
  <pattern id={id} width="10" height="10" patternUnits="userSpaceOnUse">
    <circle cx="1" cy="1" r="0.8" fill={color} />
  </pattern>
);

// ---- Peptide illustrations (200x140 viewBox) ----

const ILL_Retatrutide = () => (
  <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <defs><DotPattern id="dp-reta" /></defs>
    <rect width="200" height="140" fill={IL_COLORS.splatSoft} />
    <rect width="200" height="140" fill="url(#dp-reta)" />
    {/* three-circle agonist trio */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="70" cy="58" r="22" fill={IL_COLORS.splat} />
      <circle cx="110" cy="58" r="22" fill={IL_COLORS.sun} />
      <circle cx="90" cy="92" r="22" fill={IL_COLORS.coral} />
    </g>
    <text x="70" y="62" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.ink} fontWeight="600">GLP-1</text>
    <text x="110" y="62" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="10" fill={IL_COLORS.ink} fontWeight="600">GIP</text>
    <text x="90" y="96" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="10" fill="white" fontWeight="600">GCG</text>
    {/* connecting bonds */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.2" fill="none" strokeDasharray="2 2" opacity="0.5">
      <line x1="85" y1="68" x2="95" y2="82" />
      <line x1="95" y1="68" x2="85" y2="82" />
      <line x1="90" y1="58" x2="90" y2="58" />
    </g>
    {/* label tag */}
    <g transform="translate(142, 18) rotate(6)">
      <rect x="0" y="0" width="48" height="18" rx="9" fill={IL_COLORS.paper} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      <text x="24" y="12" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink} letterSpacing="1">TRIPLE</text>
    </g>
  </svg>
);

const ILL_GHKCu = () => (
  <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <defs><DotPattern id="dp-ghk" /></defs>
    <rect width="200" height="140" fill="#D4E7F2" />
    <rect width="200" height="140" fill="url(#dp-ghk)" />
    {/* copper helix coil */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none">
      <path d="M40 110 Q70 30 100 70 T160 30" strokeWidth="2" />
      <path d="M40 30 Q70 110 100 70 T160 110" strokeWidth="2" stroke={IL_COLORS.sky} />
    </g>
    {/* 3 amino acid nodes */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="60" cy="56" r="12" fill={IL_COLORS.sky} />
      <circle cx="100" cy="70" r="14" fill="#E89B5C" />
      <circle cx="140" cy="84" r="12" fill={IL_COLORS.lilac} />
    </g>
    <text x="60" y="60" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink} fontWeight="600">Gly</text>
    <text x="100" y="73" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="9" fill="white" fontWeight="700">Cu</text>
    <text x="140" y="88" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink} fontWeight="600">Lys</text>
    {/* sparkle */}
    <g stroke={IL_COLORS.ink} strokeWidth="1" fill={IL_COLORS.sun}>
      <path d="M170 24 l3 6 6 3 -6 3 -3 6 -3 -6 -6 -3 6 -3 z" />
    </g>
  </svg>
);

const ILL_MT2 = () => (
  <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <defs><DotPattern id="dp-mt2" /></defs>
    <rect width="200" height="140" fill="#DED0F0" />
    <rect width="200" height="140" fill="url(#dp-mt2)" />
    {/* sun with rays + gradient pigment swatches */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="100" cy="60" r="24" fill={IL_COLORS.sun} />
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" strokeLinecap="round">
      <line x1="100" y1="22" x2="100" y2="30" />
      <line x1="100" y1="90" x2="100" y2="98" />
      <line x1="62" y1="60" x2="70" y2="60" />
      <line x1="130" y1="60" x2="138" y2="60" />
      <line x1="74" y1="34" x2="80" y2="40" />
      <line x1="120" y1="80" x2="126" y2="86" />
      <line x1="126" y1="34" x2="120" y2="40" />
      <line x1="74" y1="86" x2="80" y2="80" />
    </g>
    {/* pigment gradient swatches */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.2">
      <rect x="34" y="108" width="22" height="22" rx="3" fill="#F6E6A8" />
      <rect x="58" y="108" width="22" height="22" rx="3" fill="#E8B47A" />
      <rect x="82" y="108" width="22" height="22" rx="3" fill="#B6844A" />
      <rect x="106" y="108" width="22" height="22" rx="3" fill="#7A5230" />
      <rect x="130" y="108" width="22" height="22" rx="3" fill="#4A3020" />
      <rect x="154" y="108" width="22" height="22" rx="3" fill="#2A1810" />
    </g>
  </svg>
);

const ILL_MotsC = () => (
  <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <defs><DotPattern id="dp-mots" /></defs>
    <rect width="200" height="140" fill="#F6E6A8" />
    <rect width="200" height="140" fill="url(#dp-mots)" />
    {/* mitochondrion shape */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <ellipse cx="100" cy="70" rx="60" ry="36" fill={IL_COLORS.coral} />
    </g>
    {/* inner cristae */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.4" fill="none" strokeLinecap="round">
      <path d="M55 70 Q65 56 75 70 Q85 84 95 70 Q105 56 115 70 Q125 84 135 70 Q145 56 145 70" />
    </g>
    {/* ATP label */}
    <g transform="translate(142, 106)">
      <rect width="44" height="20" rx="10" fill={IL_COLORS.paper} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      <text x="22" y="14" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="10" fontWeight="700" fill={IL_COLORS.ink}>ATP ⚡</text>
    </g>
    <text x="20" y="26" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.ink} letterSpacing="2">16 AA</text>
  </svg>
);

const ILL_Tesa = () => (
  <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <defs><DotPattern id="dp-tesa" /></defs>
    <rect width="200" height="140" fill="#FBDACF" />
    <rect width="200" height="140" fill="url(#dp-tesa)" />
    {/* moon/sleep + pituitary axis */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      {/* brain outline */}
      <path d="M60 50 Q40 50 40 70 Q40 90 60 92 Q62 100 72 100 Q82 104 92 98 Q100 100 100 90 L100 60 Q100 46 86 44 Q78 38 70 42 Q62 40 60 50 Z" fill={IL_COLORS.coral} />
      {/* pituitary blob dangling */}
      <circle cx="82" cy="108" r="8" fill={IL_COLORS.sun} />
      <line x1="82" y1="100" x2="82" y2="102" />
    </g>
    {/* moon */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <path d="M160 50 a20 20 0 1 0 0 -30 a16 16 0 0 1 0 30 z" fill={IL_COLORS.paper} />
    </g>
    {/* stars */}
    <g fill={IL_COLORS.ink}>
      <circle cx="135" cy="20" r="1.5" /><circle cx="175" cy="65" r="1.2" /><circle cx="150" cy="80" r="1" />
    </g>
    <text x="100" y="130" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.ink} letterSpacing="2">GHRH · 44-AA</text>
  </svg>
);

// ---- Article illustrations (160x120 viewBox) ----

const Chart_Titration = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill={IL_COLORS.splatSoft} />
    <g stroke="rgba(15,31,44,0.2)" strokeWidth="0.8" strokeDasharray="2 3">
      <line x1="10" y1="30" x2="150" y2="30" />
      <line x1="10" y1="60" x2="150" y2="60" />
      <line x1="10" y1="90" x2="150" y2="90" />
    </g>
    {/* axes */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" strokeLinecap="round">
      <line x1="14" y1="14" x2="14" y2="104" />
      <line x1="14" y1="104" x2="150" y2="104" />
    </g>
    {/* nausea curve peak week 2, decay */}
    <path d="M16 95 Q30 20 55 25 Q80 40 110 75 Q135 90 148 94" fill="none" stroke={IL_COLORS.coral} strokeWidth="2.5" strokeLinejoin="round" />
    {/* peak marker */}
    <g>
      <circle cx="42" cy="24" r="4" fill={IL_COLORS.coral} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      <line x1="42" y1="24" x2="42" y2="104" stroke={IL_COLORS.ink} strokeWidth="0.8" strokeDasharray="2 2" />
    </g>
    <text x="48" y="18" fontFamily="Instrument Serif" fontStyle="italic" fontSize="11" fill={IL_COLORS.ink}>peak</text>
    <text x="16" y="118" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>wk1</text>
    <text x="130" y="118" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>wk8</text>
  </svg>
);

const Chart_AminoChain = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#D4E7F2" />
    {/* amino acid beads on string */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none">
      <path d="M16 60 Q32 40 48 60 T80 60 T112 60 T144 60" />
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="16" cy="60" r="9" fill={IL_COLORS.splat} />
      <circle cx="48" cy="60" r="9" fill={IL_COLORS.sun} />
      <circle cx="80" cy="60" r="9" fill={IL_COLORS.coral} />
      <circle cx="112" cy="60" r="9" fill={IL_COLORS.lilac} />
      <circle cx="144" cy="60" r="9" fill={IL_COLORS.sky} />
    </g>
    {/* bracket */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.2" fill="none" strokeLinecap="round">
      <path d="M10 86 L10 92 L150 92 L150 86" />
    </g>
    <text x="80" y="106" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="13" fill={IL_COLORS.ink}>
      &lt;50 aa = peptide
    </text>
    <text x="80" y="22" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.muted} letterSpacing="1.5">AMINO ACIDS</text>
  </svg>
);

const Chart_Routine = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#FBDACF" />
    {/* 4 steps */}
    <g fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.ink}>
      {[
        { x: 20, i: "1", icon: "💧", l: "wash" },
        { x: 56, i: "2", icon: "🧪", l: "GHK" },
        { x: 92, i: "3", icon: "☀", l: "SPF" },
        { x: 128, i: "4", icon: "✨", l: "glow" },
      ].map((s, n) => (
        <g key={n}>
          <circle cx={s.x} cy={48} r="16" fill={IL_COLORS.paper} stroke={IL_COLORS.ink} strokeWidth="1.5" />
          <text x={s.x} y={54} textAnchor="middle" fontSize="16">{s.icon}</text>
          <text x={s.x} y={80} textAnchor="middle" fontSize="9" fill={IL_COLORS.ink} fontWeight="600">{s.l}</text>
        </g>
      ))}
    </g>
    {/* arrows */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
      <path d="M40 48 L52 48 M48 44 L52 48 L48 52" />
      <path d="M76 48 L88 48 M84 44 L88 48 L84 52" />
      <path d="M112 48 L124 48 M120 44 L124 48 L120 52" />
    </g>
    <text x="80" y="106" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="12" fill="#8C3821">
      3 minutes, no mess
    </text>
  </svg>
);

const Chart_MitoFlex = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#F6E6A8" />
    {/* mitochondrion + lightning */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <ellipse cx="60" cy="60" rx="36" ry="22" fill={IL_COLORS.coral} />
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.3" fill="none">
      <path d="M30 60 Q38 50 46 60 Q54 70 62 60 Q70 50 78 60 Q86 70 90 60" />
    </g>
    {/* arrow right */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" strokeLinecap="round" fill="none">
      <path d="M104 60 L124 60 M118 54 L124 60 L118 66" />
    </g>
    {/* bolt */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" strokeLinejoin="round">
      <path d="M140 40 L130 62 L138 62 L132 84 L148 56 L140 56 L146 40 Z" fill={IL_COLORS.sun} />
    </g>
    <text x="80" y="106" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="12" fill={IL_COLORS.ink}>
      exercise mimetic
    </text>
  </svg>
);

const Chart_Thermometer = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#DED0F0" />
    {/* thermometer */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <rect x="72" y="14" width="16" height="74" rx="8" fill={IL_COLORS.paper} />
      <circle cx="80" cy="94" r="14" fill={IL_COLORS.coral} />
      <rect x="76" y="44" width="8" height="46" fill={IL_COLORS.coral} />
    </g>
    {/* tick marks */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.2" strokeLinecap="round">
      <line x1="60" y1="22" x2="68" y2="22" />
      <line x1="60" y1="38" x2="68" y2="38" />
      <line x1="60" y1="54" x2="68" y2="54" />
      <line x1="60" y1="70" x2="68" y2="70" />
      <line x1="60" y1="86" x2="68" y2="86" />
    </g>
    <text x="56" y="26" textAnchor="end" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink}>-20°</text>
    <text x="56" y="58" textAnchor="end" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink}>4°</text>
    <text x="56" y="90" textAnchor="end" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink}>25°</text>
    {/* labels */}
    <g transform="translate(108, 40)">
      <rect width="44" height="16" rx="8" fill={IL_COLORS.splat} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      <text x="22" y="11" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill="white" fontWeight="700">SAFE</text>
    </g>
    <g transform="translate(108, 70)">
      <rect width="44" height="16" rx="8" fill={IL_COLORS.coral} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      <text x="22" y="11" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill="white" fontWeight="700">DEGRADES</text>
    </g>
  </svg>
);

const Chart_FAQ = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill={IL_COLORS.splatSoft} />
    {/* Speech bubbles */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <rect x="16" y="18" width="74" height="28" rx="6" fill={IL_COLORS.paper} />
      <path d="M30 46 L34 52 L40 46" fill={IL_COLORS.paper} />
      <rect x="70" y="56" width="74" height="28" rx="6" fill={IL_COLORS.splat} />
      <path d="M128 84 L124 90 L118 84" fill={IL_COLORS.splat} />
      <rect x="20" y="92" width="80" height="20" rx="6" fill={IL_COLORS.paper} />
    </g>
    <text x="53" y="36" textAnchor="middle" fontFamily="Instrument Serif" fontSize="14" fill={IL_COLORS.ink}>Q.</text>
    <text x="107" y="74" textAnchor="middle" fontFamily="Instrument Serif" fontSize="14" fill="white">A.</text>
    <text x="60" y="106" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.muted}>× 5 this week</text>
  </svg>
);

// Learn page — additional
const Chart_Receptor = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#D4E7F2" />
    {/* cell membrane */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none">
      <path d="M4 70 Q20 66 36 70 Q52 74 68 70 Q84 66 100 70 Q116 74 132 70 Q148 66 156 70" />
      <path d="M4 84 Q20 80 36 84 Q52 88 68 84 Q84 80 100 84 Q116 88 132 84 Q148 80 156 84" />
    </g>
    {/* receptor */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <path d="M70 78 L70 40 L90 40 L90 78 Z" fill={IL_COLORS.lilac} />
      <path d="M78 40 L78 28 L82 28 L82 40 Z" fill={IL_COLORS.lilac} />
    </g>
    {/* ligand */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="80" cy="20" r="10" fill={IL_COLORS.splat} />
    </g>
    <text x="80" y="108" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="12" fill={IL_COLORS.ink}>
      key meets lock
    </text>
  </svg>
);

const Chart_HalfLife = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#F6E6A8" />
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" strokeLinecap="round">
      <line x1="14" y1="100" x2="150" y2="100" />
      <line x1="14" y1="14" x2="14" y2="100" />
    </g>
    {/* decay curve */}
    <path d="M14 20 Q40 22 60 50 Q80 75 110 90 Q130 96 148 98" fill="none" stroke={IL_COLORS.coral} strokeWidth="2.5" strokeLinejoin="round" />
    {/* dose dots */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.2">
      <circle cx="30" cy="28" r="4" fill={IL_COLORS.splat} />
      <circle cx="70" cy="58" r="4" fill={IL_COLORS.splat} />
      <circle cx="110" cy="90" r="4" fill={IL_COLORS.splat} />
    </g>
    <text x="16" y="22" fontFamily="Instrument Serif" fontStyle="italic" fontSize="11" fill={IL_COLORS.ink}>100%</text>
    <text x="118" y="90" fontFamily="JetBrains Mono" fontSize="9" fill={IL_COLORS.muted}>→ 6.25%</text>
  </svg>
);

const Chart_Stacks = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#DED0F0" />
    {/* stacked bars */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <rect x="30" y="82" width="30" height="18" fill={IL_COLORS.splat} />
      <rect x="30" y="64" width="30" height="18" fill={IL_COLORS.sun} />
      <rect x="30" y="46" width="30" height="18" fill={IL_COLORS.coral} />
      <rect x="30" y="28" width="30" height="18" fill={IL_COLORS.sky} />

      <rect x="70" y="82" width="30" height="18" fill={IL_COLORS.splat} />
      <rect x="70" y="64" width="30" height="18" fill={IL_COLORS.sun} />

      <rect x="110" y="82" width="30" height="18" fill={IL_COLORS.splat} />
    </g>
    {/* checkmark over shortest */}
    <g stroke={IL_COLORS.splatDeep} strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round">
      <path d="M118 72 L123 78 L135 64" />
    </g>
    <text x="45" y="114" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>4</text>
    <text x="85" y="114" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>2</text>
    <text x="125" y="114" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>1 ✓</text>
  </svg>
);

const Chart_Bruise = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill={IL_COLORS.splatSoft} />
    {/* 4 bruise stages */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <circle cx="28" cy="60" r="14" fill="#D94545" />
      <circle cx="64" cy="60" r="14" fill="#8B4585" />
      <circle cx="100" cy="60" r="14" fill="#6B7A2F" />
      <circle cx="136" cy="60" r="14" fill="#C7B87A" />
    </g>
    <g fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted} textAnchor="middle">
      <text x="28" y="88">d1</text>
      <text x="64" y="88">d3</text>
      <text x="100" y="88">d5</text>
      <text x="136" y="88">d8</text>
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.2" strokeLinecap="round" fill="none">
      <path d="M42 60 L50 60" /><path d="M78 60 L86 60" /><path d="M114 60 L122 60" />
    </g>
    <text x="80" y="24" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="12" fill={IL_COLORS.ink}>
      normal color timeline
    </text>
  </svg>
);

// Small-size extra charts
const Chart_SubQ = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#D4E7F2" />
    {/* skin layers */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <rect x="16" y="24" width="128" height="16" fill="#F6D6B8" />
      <rect x="16" y="40" width="128" height="18" fill="#F2C4A4" />
      <rect x="16" y="58" width="128" height="20" fill={IL_COLORS.sun} />
      <rect x="16" y="78" width="128" height="18" fill="#C7928A" />
    </g>
    {/* needle */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <line x1="70" y1="6" x2="70" y2="68" strokeWidth="2" />
      <polygon points="66,68 74,68 70,72" fill={IL_COLORS.ink} />
      <circle cx="70" cy="6" r="4" fill={IL_COLORS.splat} />
    </g>
    {/* deep needle */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5">
      <line x1="120" y1="6" x2="120" y2="84" strokeWidth="2" />
      <polygon points="116,84 124,84 120,88" fill={IL_COLORS.ink} />
      <circle cx="120" cy="6" r="4" fill={IL_COLORS.coral} />
    </g>
    <text x="70" y="116" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink}>SubQ</text>
    <text x="120" y="116" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink}>IM</text>
  </svg>
);

const Chart_SkinProto = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#F6E6A8" />
    {/* 8 week cells */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.3">
      {[0,1,2,3,4,5,6,7].map(i => (
        <rect key={i} x={14 + i*17} y="38" width="15" height="44" fill={i < 6 ? IL_COLORS.splat : IL_COLORS.cream2} />
      ))}
    </g>
    {/* face icon */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill={IL_COLORS.paper}>
      <circle cx="80" cy="22" r="12" />
    </g>
    <g fill={IL_COLORS.ink}>
      <circle cx="76" cy="20" r="1.5" /><circle cx="84" cy="20" r="1.5" />
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.2" fill="none" strokeLinecap="round">
      <path d="M76 27 Q80 29 84 27" />
    </g>
    <text x="80" y="104" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted} letterSpacing="1">8 WEEKS · SKIN</text>
  </svg>
);

const Chart_QA = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#FBDACF" />
    <g fontFamily="Instrument Serif" fontSize="44" fill={IL_COLORS.coral} stroke={IL_COLORS.ink} strokeWidth="1.2">
      <text x="40" y="80" textAnchor="middle">?</text>
      <text x="110" y="80" textAnchor="middle">?</text>
    </g>
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill={IL_COLORS.splat}>
      <circle cx="75" cy="30" r="6" />
      <circle cx="140" cy="28" r="4" />
      <circle cx="25" cy="30" r="4" />
    </g>
    <text x="80" y="108" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted} letterSpacing="1.5">5 QUESTIONS</text>
  </svg>
);

const Chart_Sites = () => (
  <svg viewBox="0 0 160 120" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
    <rect width="160" height="120" fill="#DED0F0" />
    {/* body outline */}
    <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill={IL_COLORS.paper}>
      <circle cx="80" cy="22" r="8" />
      <path d="M72 30 L72 66 Q72 70 76 70 L76 98 L72 98 L72 106 M88 30 L88 66 Q88 70 84 70 L84 98 L88 98 L88 106 M66 38 L58 60 L62 62 M94 38 L102 60 L98 62" fill="none" />
      <rect x="72" y="30" width="16" height="40" rx="3" />
    </g>
    {/* injection sites dots */}
    <g stroke={IL_COLORS.ink} strokeWidth="1">
      <circle cx="74" cy="44" r="3" fill={IL_COLORS.splat} />
      <circle cx="86" cy="44" r="3" fill={IL_COLORS.sun} />
      <circle cx="74" cy="58" r="3" fill={IL_COLORS.coral} />
      <circle cx="86" cy="58" r="3" fill={IL_COLORS.sky} />
    </g>
    {/* arrow cycle */}
    <g stroke={IL_COLORS.splatDeep} strokeWidth="1.5" fill="none" strokeLinecap="round">
      <path d="M120 50 Q132 50 132 62 Q132 74 120 74" />
      <polygon points="116,70 124,74 116,78" fill={IL_COLORS.splatDeep} />
    </g>
    <text x="80" y="116" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.muted}>ROTATE · 4 SITES</text>
  </svg>
);

// Generic fallback — schematic amino acid chain
// Color picks a palette from IL_COLORS by name (e.g. "green", "coral", "sky", "sun", "lilac")
// Simple deterministic hash so each peptide id maps to a stable variant
function _hashId(id = "") {
  let h = 0;
  for (let i = 0; i < id.length; i++) h = (h * 31 + id.charCodeAt(i)) | 0;
  return Math.abs(h);
}

const ILL_Generic = ({ color = "green", id = "" }) => {
  const palettes = {
    green: { bg: IL_COLORS.splatSoft, bead: IL_COLORS.splat, accent: IL_COLORS.splatDeep, alt: IL_COLORS.sun },
    coral: { bg: "#FBDACF", bead: IL_COLORS.coral, accent: "#8C3821", alt: IL_COLORS.sun },
    sky: { bg: "#D4E7F2", bead: IL_COLORS.sky, accent: "#2F5A74", alt: IL_COLORS.lilac },
    sun: { bg: "#F6E6A8", bead: IL_COLORS.sun, accent: "#8A6A10", alt: IL_COLORS.coral },
    lilac: { bg: "#DED0F0", bead: IL_COLORS.lilac, accent: "#4A3470", alt: IL_COLORS.sky },
  };
  const p = palettes[color] || palettes.green;
  const h = _hashId(id);
  const variant = h % 8; // 0..7, each with a different layout
  const dpId = `dp-gen-${id || color}`;

  // ---- 8 distinct cartoon layouts ----
  const layouts = [];

  // 0 — wave chain, 6 beads (the original, slightly tweaked)
  layouts[0] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 78 Q40 50 60 78 T100 78 T140 78 T180 78" />
      </g>
      {[22,60,100,140,180].map((x,i) => (
        <g key={i}><circle cx={x} cy={78} r="10" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" /></g>
      ))}
      {/* sparkle */}
      <g transform="translate(168, 36)" stroke={IL_COLORS.ink} strokeWidth="1.4" strokeLinecap="round">
        <line x1="0" y1="-8" x2="0" y2="8" /><line x1="-8" y1="0" x2="8" y2="0" />
        <line x1="-5" y1="-5" x2="5" y2="5" /><line x1="-5" y1="5" x2="5" y2="-5" />
      </g>
    </g>
  );

  // 1 — diagonal arc rising, 5 beads + sparkle
  layouts[1] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 100 Q60 88 100 70 T180 36" />
      </g>
      {[{x:22,y:100},{x:60,y:88},{x:100,y:70},{x:140,y:50},{x:180,y:36}].map((b,i) => (
        <circle key={i} cx={b.x} cy={b.y} r="10" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      <g transform="translate(40, 44)" fill={p.accent}>
        <path d="M0 -8 L2 -2 L8 0 L2 2 L0 8 L-2 2 L-8 0 L-2 -2 Z" stroke={IL_COLORS.ink} strokeWidth="1" />
      </g>
    </g>
  );

  // 2 — DNA-like helix pair (two interlocking sine waves with bridges)
  layouts[2] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 56 Q60 88 100 56 T180 56" />
        <path d="M22 84 Q60 52 100 84 T180 84" />
        {[44,76,108,140,172].map((x,i) => (<line key={i} x1={x} y1={56+(i%2?14:-14)+(i%2?14:14)} x2={x} y2={84+(i%2?-14:14)-(i%2?14:14)} />))}
      </g>
      {[{x:22,y:56},{x:60,y:80},{x:100,y:56},{x:140,y:80},{x:180,y:56}].map((b,i) => (
        <circle key={`a${i}`} cx={b.x} cy={b.y} r="8" fill={p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      {[{x:22,y:84},{x:60,y:60},{x:100,y:84},{x:140,y:60},{x:180,y:84}].map((b,i) => (
        <circle key={`b${i}`} cx={b.x} cy={b.y} r="8" fill={p.alt} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
    </g>
  );

  // 3 — zigzag chain of 5 + flask icon
  layouts[3] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <polyline points="22,80 56,52 90,80 124,52 158,80" />
      </g>
      {[{x:22,y:80},{x:56,y:52},{x:90,y:80},{x:124,y:52},{x:158,y:80}].map((b,i) => (
        <circle key={i} cx={b.x} cy={b.y} r="10" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      {/* flask */}
      <g transform="translate(170, 30)" stroke={IL_COLORS.ink} strokeWidth="1.4" fill={p.bg} strokeLinejoin="round">
        <path d="M-6 -4 L-6 4 L-12 18 L12 18 L6 4 L6 -4 Z" />
        <line x1="-8" y1="-4" x2="8" y2="-4" />
        <path d="M-9 12 L9 12" stroke={p.accent} />
      </g>
    </g>
  );

  // 4 — closed loop (cyclic peptide), 6 beads in a ring
  layouts[4] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <circle cx="100" cy="70" r="42" />
      </g>
      {[0,1,2,3,4,5].map(i => {
        const a = (i / 6) * Math.PI * 2 - Math.PI / 2;
        const x = 100 + Math.cos(a) * 42;
        const y = 70 + Math.sin(a) * 42;
        return <circle key={i} cx={x} cy={y} r="10" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" />;
      })}
      {/* center cyclic label */}
      <text x="100" y="74" textAnchor="middle" fontFamily="Instrument Serif" fontStyle="italic" fontSize="14" fill={p.accent}>cyclic</text>
    </g>
  );

  // 5 — branched chain (Y-shape), 7 beads + small lightning bolt
  layouts[5] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 80 L60 80 L92 60 L132 60" />
        <path d="M92 60 L132 100" />
      </g>
      {[{x:22,y:80},{x:60,y:80},{x:92,y:60},{x:132,y:60},{x:172,y:60},{x:132,y:100},{x:166,y:106}].map((b,i) => (
        <circle key={i} cx={b.x} cy={b.y} r="9" fill={i<5 ? p.bead : p.alt} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      <g transform="translate(48, 30)" fill={p.accent} stroke={IL_COLORS.ink} strokeWidth="1.2" strokeLinejoin="round">
        <path d="M0 -10 L-6 2 L0 0 L-2 12 L8 -2 L2 0 Z" />
      </g>
    </g>
  );

  // 6 — fragments (two short chains, side by side) — for fragment peptides
  layouts[6] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 70 Q44 56 66 70 T110 70" />
        <path d="M132 70 Q154 56 176 70" />
      </g>
      {[{x:22,y:70},{x:44,y:60},{x:66,y:70},{x:88,y:60},{x:110,y:70}].map((b,i) => (
        <circle key={`l${i}`} cx={b.x} cy={b.y} r="8" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      {[{x:132,y:70},{x:154,y:60},{x:176,y:70}].map((b,i) => (
        <circle key={`r${i}`} cx={b.x} cy={b.y} r="8" fill={i%2 ? p.bead : p.alt} stroke={IL_COLORS.ink} strokeWidth="1.5" />
      ))}
      <text x="121" y="74" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="14" fill={IL_COLORS.ink} fontWeight="700">+</text>
    </g>
  );

  // 7 — ladder/comb (helix-like rungs along one chain)
  layouts[7] = (
    <g>
      <g stroke={IL_COLORS.ink} strokeWidth="1.5" fill="none" strokeLinecap="round">
        <path d="M22 50 H180" />
        <path d="M22 92 H180" />
        {[40,68,96,124,152,180].map((x,i) => (<line key={i} x1={x} y1={50} x2={x} y2={92} />))}
      </g>
      {[40,68,96,124,152].map((x,i) => (
        <circle key={i} cx={x} cy={71} r="6" fill={i%2 ? p.alt : p.bead} stroke={IL_COLORS.ink} strokeWidth="1.2" />
      ))}
    </g>
  );

  // ---- shared decoration: small label tag with the variant name ----
  const tagLabels = ["chain", "ascending", "helix", "zigzag", "cyclic", "branched", "fragment", "ladder"];
  const tagLabel = tagLabels[variant];

  return (
    <svg viewBox="0 0 200 140" preserveAspectRatio="xMidYMid slice" width="100%" height="100%">
      <defs><DotPattern id={dpId} /></defs>
      <rect width="200" height="140" fill={p.bg} />
      <rect width="200" height="140" fill={`url(#${dpId})`} />
      {layouts[variant]}
      {/* small label tag */}
      <g transform="translate(10, 14) rotate(-4)">
        <rect x="0" y="0" width="64" height="16" rx="8" fill={IL_COLORS.paper} stroke={IL_COLORS.ink} strokeWidth="1.2" />
        <text x="32" y="11" textAnchor="middle" fontFamily="JetBrains Mono" fontSize="8" fill={IL_COLORS.ink} letterSpacing="1.2">PEPTIDE</text>
      </g>
      <text x="180" y="128" textAnchor="end" fontFamily="Instrument Serif" fontStyle="italic" fontSize="11" fill={p.accent}>
        {tagLabel}
      </text>
    </svg>
  );
};

// Map registry
const PEPTIDE_ILLUSTRATIONS = {
  reta: ILL_Retatrutide,
  ghkcu: ILL_GHKCu,
  mt2: ILL_MT2,
  motsc: ILL_MotsC,
  tesa: ILL_Tesa,
};

// Category-tag → palette key
const TAG_COLOR_MAP = {
  "Metabolic": "green",
  "Skin": "coral",
  "Skin · Recovery": "coral",
  "GH axis": "sun",
  "GH · Body comp": "coral",
  "Mitochondrial": "sun",
  "Cognitive": "lilac",
  "Immune": "green",
  "Healing": "green",
  "Sleep": "lilac",
  "Longevity": "sun",
  "Antimicrobial": "sky",
  "Wellness": "coral",
  "Pigment · Novel": "lilac",
};

const PeptideArt = ({ id }) => {
  const Cmp = PEPTIDE_ILLUSTRATIONS[id];
  if (Cmp) return <Cmp />;
  // Look up the peptide's tag for category color
  const peptide = (typeof PEPTIDES !== "undefined" ? PEPTIDES : []).find(p => p.id === id);
  const color = (peptide && TAG_COLOR_MAP[peptide.tag]) || "green";
  return <ILL_Generic color={color} id={id} />;
};

Object.assign(window, {
  PeptideArt,
  Chart_Titration, Chart_AminoChain, Chart_Routine, Chart_MitoFlex,
  Chart_Thermometer, Chart_FAQ, Chart_Receptor, Chart_HalfLife,
  Chart_Stacks, Chart_Bruise, Chart_SubQ, Chart_SkinProto, Chart_QA, Chart_Sites,
});
