/**
 * "The CON Application Nightmare: The Paper Chase", drawn in the style of
 * a 1950s newspaper strip: warm sepia paper, brown black ink of varied
 * weight, soft tone shading, crosshatching, halftone dots and one spot red.
 * A recurring hero (a healthcare entrepreneur: three quarter view, glossy
 * wavy pompadour, shaded suit, polka dot tie) goes from hopeful, to puzzled,
 * to swamped, to relieved. Each panel keeps open space for its balloon,
 * away from his face. Decorative only; each panel's balloon and caption
 * carry the story. Keys match the comic-panels collection's `art`.
 */
import type { ReactElement } from "react";

const INK = "#2a1d12";
const RED = "#a3262a";
const PAPER = "#f6ead0";
const SHEET = "#fbf3e1";
const SKIN_SHADE = "#c8915f";
const SHIRT = "#fffaf0";
const WALL = "#eadbb8";

const Svg = ({ children }: { children: React.ReactNode }) => (
  <svg viewBox="0 0 240 210" preserveAspectRatio="xMidYMid meet" aria-hidden="true" focusable="false">
    {children}
  </svg>
);

const FACE =
  "M-18 -34 C-24 -24 -26 -8 -24 6 C-22 18 -16 28 -6 34 C0 38 8 40 14 38 C20 36 23 30 24 24 C25 18 24 14 26 10 C28 6 29 2 28 -4 C27 -16 22 -30 10 -38 C2 -42 -10 -40 -18 -34 Z";

function Defs({ p }: { p: string }) {
  return (
    <defs>
      <pattern id={`${p}-dots`} width="5" height="5" patternUnits="userSpaceOnUse">
        <circle cx="2.5" cy="2.5" r=".9" fill={INK} opacity=".14" />
      </pattern>
      <pattern id={`${p}-reddots`} width="5" height="5" patternUnits="userSpaceOnUse">
        <circle cx="2.5" cy="2.5" r="1" fill={RED} opacity=".22" />
      </pattern>
      <pattern id={`${p}-hatch`} width="3" height="3" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
        <line x1="0" y1="0" x2="0" y2="3" stroke={INK} strokeWidth=".6" opacity=".5" />
      </pattern>
      <pattern id={`${p}-cross`} width="3.2" height="3.2" patternUnits="userSpaceOnUse" patternTransform="rotate(30)">
        <path d="M0 0 V3.2 M0 0 H3.2" stroke={INK} strokeWidth=".45" opacity=".45" />
      </pattern>
      <pattern id={`${p}-stripes`} width="10" height="10" patternUnits="userSpaceOnUse">
        <rect width="10" height="10" fill={WALL} />
        <rect width="3" height="10" fill="#e0cda4" />
      </pattern>
      <pattern id={`${p}-tie`} width="5" height="5" patternUnits="userSpaceOnUse">
        <rect width="5" height="5" fill={RED} />
        <circle cx="2.5" cy="2.5" r=".95" fill={SHIRT} />
      </pattern>
      <radialGradient id={`${p}-skin`} cx=".62" cy=".36" r=".78">
        <stop offset="0" stopColor="#f8e0bf" />
        <stop offset=".55" stopColor="#efc89c" />
        <stop offset="1" stopColor="#d6a271" />
      </radialGradient>
      <linearGradient id={`${p}-suit`} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor="#867159" />
        <stop offset=".6" stopColor="#65543f" />
        <stop offset="1" stopColor="#4b3d2e" />
      </linearGradient>
      <linearGradient id={`${p}-hair`} x1="0" y1="0" x2=".3" y2="1">
        <stop offset="0" stopColor="#4d3727" />
        <stop offset=".5" stopColor="#2a1c12" />
        <stop offset="1" stopColor="#140c06" />
      </linearGradient>
      <radialGradient id={`${p}-vignette`} cx=".5" cy=".45" r=".75">
        <stop offset=".6" stopColor="#7a5a2c" stopOpacity="0" />
        <stop offset="1" stopColor="#7a5a2c" stopOpacity=".28" />
      </radialGradient>
      <radialGradient id={`${p}-glow`} cx=".5" cy=".5" r=".5">
        <stop offset="0" stopColor="#fff6dc" stopOpacity=".95" />
        <stop offset="1" stopColor="#fff6dc" stopOpacity="0" />
      </radialGradient>
      <clipPath id={`${p}-face`}>
        <path d={FACE} />
      </clipPath>
    </defs>
  );
}

/** The aged edge every panel is printed with. */
const Vignette = ({ p }: { p: string }) => <rect width="240" height="210" fill={`url(#${p}-vignette)`} pointerEvents="none" />;

/** Rays from a point, for sunbursts and action bursts. */
function Burst({ cx, cy, n = 18, r1 = 10, r2 = 300, color = INK, opacity = 0.12, width = 0.06 }: { cx: number; cy: number; n?: number; r1?: number; r2?: number; color?: string; opacity?: number; width?: number }) {
  return (
    <g opacity={opacity}>
      {Array.from({ length: n }, (_, i) => {
        const a = (i / n) * Math.PI * 2;
        const w = (Math.PI / n) * width * 10;
        const p1 = [cx + Math.cos(a - w) * r2, cy + Math.sin(a - w) * r2];
        const p2 = [cx + Math.cos(a + w) * r2, cy + Math.sin(a + w) * r2];
        return <path key={i} d={`M${cx + Math.cos(a) * r1} ${cy + Math.sin(a) * r1} L${p1[0]} ${p1[1]} L${p2[0]} ${p2[1]} Z`} fill={color} />;
      })}
    </g>
  );
}

type Mood = "hopeful" | "puzzled" | "shocked" | "tired" | "happy";

const BROWS: Record<Mood, [string, string]> = {
  hopeful: ["M-14 -15 C-9 -20 -2 -19 2 -15 C-3 -17 -9 -17 -14 -15 Z", "M9 -15 C13 -19 18 -19 21.5 -14 C18 -16.5 13 -16.5 9 -15 Z"],
  puzzled: ["M-14 -11 C-9 -11.5 -3 -12 2 -14 C-3 -13 -9 -12.5 -14 -11 Z", "M9 -17 C13 -22 18 -21 21.5 -15 C18 -18.5 13 -19 9 -17 Z"],
  shocked: ["M-14 -19 C-9 -25 -2 -24 2 -19 C-3 -22 -9 -22 -14 -19 Z", "M9 -19 C13 -24 18 -23 21.5 -18 C18 -21 13 -21 9 -19 Z"],
  tired: ["M-14 -11 C-9 -15 -2 -15 2 -12 C-3 -13.5 -9 -13.5 -14 -11 Z", "M9 -12 C13 -15 17 -14 21.5 -10 C17 -12 13 -12.5 9 -12 Z"],
  happy: ["M-14 -14 C-9 -19 -2 -18 2 -14 C-3 -16 -9 -16 -14 -14 Z", "M9 -14 C13 -18 18 -18 21.5 -13 C18 -15.5 13 -15.5 9 -14 Z"]
};

/** The hero's head and shoulders, three quarter view facing right. Head
 *  centre at (0, 0); the face spans roughly x -26..29, y -53..40. */
function Man({ x, y, s = 1, mood, p, tilt = 0, look = [0, 0] }: { x: number; y: number; s?: number; mood: Mood; p: string; tilt?: number; look?: [number, number] }) {
  const [lx, ly] = look;
  const skin = `url(#${p}-skin)`;
  const iris = mood === "shocked" ? 1.9 : 2.6;
  return (
    <g transform={`translate(${x} ${y}) rotate(${tilt}) scale(${s})`}>
      {/* Jacket: tone, shadow side, folds, lapels, pocket square */}
      <path d="M-72 150 C-70 100 -56 72 -24 56 L-2 72 L4 114 L10 72 L26 54 C58 66 74 96 76 150 Z" fill={`url(#${p}-suit)`} stroke={INK} strokeWidth="2.4" strokeLinejoin="round" />
      <path d="M-72 150 C-70 100 -56 72 -24 56 L-14 80 L-30 150 Z" fill={`url(#${p}-cross)`} />
      <path d="M-60 92 C-52 84 -44 80 -36 78 M48 74 C56 80 62 88 66 98" fill="none" stroke="#a89277" strokeWidth="1.4" opacity=".7" strokeLinecap="round" />
      <path d="M-24 56 L-8 98 L-2 72 Z M26 54 L14 98 L10 72 Z" fill="#4b3d2e" opacity=".45" />
      <path d="M-24 56 L-8 98 L-2 72 M26 54 L14 98 L10 72" fill="none" stroke={INK} strokeWidth="1.7" strokeLinejoin="round" />
      <path d="M-46 76 C-44 96 -42 120 -44 150 M50 78 C50 100 50 124 52 150 M-30 120 C-26 128 -20 132 -12 134" fill="none" stroke={INK} strokeWidth=".9" opacity=".55" />
      <path d="M-50 104 L-36 104 L-38 96 L-44 92 L-48 97 Z" fill={SHIRT} stroke={INK} strokeWidth="1.1" strokeLinejoin="round" />
      <path d="M-52 104 H-34" stroke={INK} strokeWidth="1.2" />
      {/* Shirt, collar, tie */}
      <path d="M-14 52 L4 112 L22 50 L14 46 L4 58 L-6 46 Z" fill={SHIRT} stroke={INK} strokeWidth="1.4" />
      <path d="M-10 56 L2 98 L4 80 Z" fill="#e7dcc4" />
      <path d="M1 70 L9 70 L13 104 L5 116 L-3 104 Z" fill={`url(#${p}-tie)`} stroke={INK} strokeWidth="1.3" strokeLinejoin="round" />
      <path d="M1 70 L4 70 L2 106 L-3 104 Z" fill="#5e1214" opacity=".35" />
      <path d="M-1 59 L11 59 L9 70 L1 70 Z" fill={RED} stroke={INK} strokeWidth="1.3" strokeLinejoin="round" />
      <path d="M5 63 L5 69" stroke={INK} strokeWidth=".9" />
      <path d="M-16 50 L-1 62 L-7 46 Z M22 48 L11 62 L16 44 Z" fill={SHIRT} stroke={INK} strokeWidth="1.3" strokeLinejoin="round" />
      {/* Neck, with the jaw's shadow */}
      <path d="M-12 28 L-12 52 L4 60 L16 50 L17 32 Z" fill={skin} stroke={INK} strokeWidth="1.7" strokeLinejoin="round" />
      <path d="M-12 30 C-4 41 8 43 17 34 L17 42 C8 48 -4 48 -12 40 Z" fill={SKIN_SHADE} opacity=".6" />
      <path d="M2 44 L2 54" stroke={INK} strokeWidth=".7" opacity=".4" />
      {/* Face: tone, shadow side, cheek */}
      <path d={FACE} fill={skin} />
      <g clipPath={`url(#${p}-face)`}>
        <path d="M-30 -44 L-12 -44 C-18 -26 -18 -4 -12 14 C-6 28 4 36 16 40 L-30 46 Z" fill={SKIN_SHADE} opacity=".5" />
        <path d="M-30 -44 L-18 -44 C-22 -26 -22 -4 -16 14 C-10 28 0 36 12 42 L-30 46 Z" fill={`url(#${p}-cross)`} opacity=".7" />
        <ellipse cx="19" cy="9" rx="5.5" ry="3.4" fill="#e0906c" opacity=".3" />
        <path d="M-12 -10 C-8 -13 -2 -13 2 -10 C2 -6 -12 -6 -12 -10 Z M8 -10 C12 -12 18 -12 21 -9 C20 -6 9 -6 8 -10 Z" fill={SKIN_SHADE} opacity=".35" />
        <path d="M7 -2 C9 4 11 8 13 11 L8 12 C8 8 7 4 6 -2 Z" fill={SKIN_SHADE} opacity=".45" />
      </g>
      <path d={FACE} fill="none" stroke={INK} strokeWidth="2.3" strokeLinejoin="round" />
      {/* Ear */}
      <path d="M-20 -8 C-31 -13 -33 7 -24 13 C-22 15 -19 13 -19 10" fill={skin} stroke={INK} strokeWidth="1.8" strokeLinecap="round" />
      <path d="M-23 -3 C-27 -1 -26 6 -22 8 M-24 1 C-25 3 -24 5 -23 5" fill="none" stroke={INK} strokeWidth="1" />
      <path d="M-26 -4 C-29 0 -28 7 -24 10" fill="none" stroke={SKIN_SHADE} strokeWidth="2" opacity=".6" />
      {/* Glossy pompadour and sideburn */}
      <path d="M-27 4 C-31 -14 -29 -34 -15 -44 C-3 -53 16 -53 27 -43 C33 -37 33 -28 27 -24 C25 -30 19 -32 13 -30 C9 -34 1 -34 -5 -30 C-11 -26 -15 -19 -16 -11 C-16 -5 -18 1 -19 4 L-22 9 Z" fill={`url(#${p}-hair)`} stroke={INK} strokeWidth="1.2" />
      <path d="M-6 -46 C4 -50 15 -48 22 -42 C14 -45 4 -46 -6 -46 Z" fill="#a8896a" opacity=".75" />
      <path d="M-18 -36 C-12 -42 -4 -44 4 -43 C-4 -41 -12 -38 -18 -34 Z" fill="#a8896a" opacity=".55" />
      <path d="M-11 -43 C-1 -49 12 -49 22 -43 M-19 -35 C-11 -43 1 -45 12 -41 M-23 -24 C-19 -31 -12 -35 -4 -37 M-25 -12 C-23 -20 -19 -26 -13 -30" fill="none" stroke={PAPER} strokeWidth=".7" opacity=".45" strokeLinecap="round" />
      <path d="M24 -26 C26 -30 26 -34 22 -38" fill="none" stroke="#6b5038" strokeWidth="1" opacity=".8" />
      {/* Brows */}
      <path d={BROWS[mood][0]} fill={INK} stroke={INK} strokeWidth="1.2" strokeLinejoin="round" />
      <path d={BROWS[mood][1]} fill={INK} stroke={INK} strokeWidth="1" strokeLinejoin="round" />
      {/* Eyes */}
      {mood === "happy" ? (
        <>
          <path d="M-11 -6 C-8 -10.5 -2 -10.5 1 -6 M10 -6 C12 -9.5 17 -9.5 20 -6" fill="none" stroke={INK} strokeWidth="2" strokeLinecap="round" />
          <path d="M-10 -2.5 C-7 -1 -3 -1 0 -2.5 M11 -2.5 C13 -1.4 16 -1.4 18.5 -2.5" fill="none" stroke={INK} strokeWidth=".7" opacity=".55" />
        </>
      ) : (
        <>
          <path d="M-11 -6 C-8 -10 -2 -10 1 -6 C-2 -3.5 -8 -3.5 -11 -6 Z" fill={SHIRT} stroke={INK} strokeWidth="1" />
          <path d="M10 -6 C12 -9 17 -9 20 -6 C17 -4 12 -4 10 -6 Z" fill={SHIRT} stroke={INK} strokeWidth="1" />
          <circle cx={-4.5 + lx} cy={-6.4 + ly} r={iris} fill="#6a4a2c" />
          <circle cx={-4.5 + lx} cy={-6.4 + ly} r={iris * 0.5} fill={INK} />
          <circle cx={15 + lx * 0.8} cy={-6.4 + ly} r={iris * 0.85} fill="#6a4a2c" />
          <circle cx={15 + lx * 0.8} cy={-6.4 + ly} r={iris * 0.42} fill={INK} />
          <circle cx={-3.6 + lx} cy={-7.4 + ly} r=".75" fill={SHIRT} />
          <circle cx={15.7 + lx * 0.8} cy={-7.3 + ly} r=".6" fill={SHIRT} />
          {mood === "tired" && <path d="M-11.5 -6 C-8 -9.6 -2 -9.6 1.5 -6 C-2 -6.4 -8 -6.4 -11.5 -6 Z M9.5 -6 C12 -8.6 17 -8.6 20.5 -6 C17 -6.4 12 -6.4 9.5 -6 Z" fill={skin} stroke={INK} strokeWidth="1.1" />}
          <path d="M-11.8 -6.2 C-8 -11.2 -2 -11.2 1.8 -6.8 M9.6 -6.3 C12 -9.9 17 -9.9 20.6 -6.6" fill="none" stroke={INK} strokeWidth="1.9" strokeLinecap="round" />
          <path d="M-12 -6.4 L-13.5 -7.6 M1.6 -6.9 L3 -8" stroke={INK} strokeWidth="1" strokeLinecap="round" />
          <path d="M-10 -2.6 C-7 -1.4 -3 -1.4 0 -2.8" fill="none" stroke={INK} strokeWidth=".6" opacity=".5" />
        </>
      )}
      {mood === "tired" && <path d="M-10 0 C-6 2 -2 2 1 0 M11 0 C14 1.6 17 1.6 19 0" fill="none" stroke={INK} strokeWidth=".9" opacity=".6" />}
      {/* Nose */}
      <path d="M6 -5 C8 2 12 8 16 12 C14 15 10 15 8 13" fill="none" stroke={INK} strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" />
      <path d="M9 13.2 C10.4 11.6 12 11.6 13 12.4" fill="none" stroke={INK} strokeWidth="1" strokeLinecap="round" />
      {/* Smile line, cheekbone and chin */}
      <path d="M20 9 C19 15 20 19 22 21" fill="none" stroke={INK} strokeWidth="1" opacity=".75" />
      <path d="M-15 14 C-11 25 -4 32 4 35" fill="none" stroke={INK} strokeWidth=".8" opacity=".4" />
      <path d="M11 34 C13 36 16 36 17 34" fill="none" stroke={INK} strokeWidth=".9" opacity=".6" />
      {/* Mouth */}
      {(mood === "hopeful" || mood === "puzzled" || mood === "tired") && (
        <path
          d={mood === "hopeful" ? "M2 22 C6 20.4 9 21 10 21.6 C11 21 14 20.4 18 20 C13 24.6 7 25 2 22 Z" : mood === "puzzled" ? "M3 24 C6 22 9 22 10 22.6 C11 22 14 21.6 17 23 C12 24.4 7 24.8 3 24 Z" : "M3 25 C6 22.6 9 22.4 10 23 C11 22.4 14 22.4 17 24 C12 24.6 7 25.4 3 25 Z"}
          fill="#b86f55"
          opacity=".8"
        />
      )}
      {mood === "hopeful" && (
        <>
          <path d="M2 22 C7 25 13 24 18 20" fill="none" stroke={INK} strokeWidth="1.8" strokeLinecap="round" />
          <path d="M6 27.4 C10 28.4 13 27.4 15 26" fill="none" stroke={INK} strokeWidth=".9" opacity=".55" />
        </>
      )}
      {mood === "puzzled" && (
        <>
          <path d="M3 24 C7 22.6 12 21.8 17 23" fill="none" stroke={INK} strokeWidth="1.8" strokeLinecap="round" />
          <path d="M6 28 C10 28.6 13 28 15 27" fill="none" stroke={INK} strokeWidth=".9" opacity=".55" />
        </>
      )}
      {mood === "shocked" && (
        <>
          <ellipse cx="9.5" cy="24" rx="5.2" ry="6.6" fill={INK} />
          <path d="M6 28 C8 26.6 11 26.6 13 28" fill="none" stroke="#b86f55" strokeWidth="1.6" />
        </>
      )}
      {mood === "tired" && <path d="M3 25 C8 22.8 12 22.8 17 24" fill="none" stroke={INK} strokeWidth="1.8" strokeLinecap="round" />}
      {mood === "happy" && (
        <>
          <path d="M-1 18 C6 29 14 28 20 17 C13 20 6 20 -1 18 Z" fill={SHIRT} stroke={INK} strokeWidth="1.7" strokeLinejoin="round" />
          <path d="M2 23.6 C7 27 12 27 16.6 22.6 C12 24.6 7 24.8 2 23.6 Z" fill="#b86f55" opacity=".7" />
          <path d="M1 19.5 C7 21 13 21 18.5 18.8" fill="none" stroke={INK} strokeWidth=".7" />
        </>
      )}
    </g>
  );
}

/** A hand with fingers, knuckles and nails; (0,0) is the middle of the
 *  back of the hand, fingers pointing up. */
function Hand({ x, y, r = 0, s = 1, p }: { x: number; y: number; r?: number; s?: number; p: string }) {
  const skin = `url(#${p}-skin)`;
  return (
    <g transform={`translate(${x} ${y}) rotate(${r}) scale(${s})`}>
      {[-8.5, -3.8, 0.9, 5.6].map((fx, i) => {
        const top = -24 + (i === 0 || i === 3 ? 3 : 0);
        return (
          <g key={fx}>
            <rect x={fx} y={top} width="4.6" height="17" rx="2.3" fill={skin} stroke={INK} strokeWidth="1.2" />
            <path d={`M${fx + 1} ${top + 3.4} C${fx + 1.8} ${top + 1.6} ${fx + 2.8} ${top + 1.6} ${fx + 3.6} ${top + 3.4}`} fill="none" stroke={INK} strokeWidth=".6" opacity=".7" />
            <path d={`M${fx + 1} ${top + 9} H${fx + 3.6}`} stroke={INK} strokeWidth=".5" opacity=".5" />
          </g>
        );
      })}
      <path d="M-10 10 C-12 0 -11 -9 -8 -10 L10 -10 C12 -8 12 0 10 10 Z" fill={skin} stroke={INK} strokeWidth="1.5" strokeLinejoin="round" />
      <path d="M-10 10 C-11 4 -11 -2 -10 -8 L-6 -8 C-7 -2 -7 4 -6 10 Z" fill={SKIN_SHADE} opacity=".45" />
      <path d="M10 2 C16 -2 18 -9 15 -12 C12 -11 10 -7 9 -3" fill={skin} stroke={INK} strokeWidth="1.3" strokeLinejoin="round" />
      <path d="M-6.5 -8 C-6 -7 -5 -7 -4.6 -8 M-1.6 -8.6 C-1.1 -7.6 -0.1 -7.6 0.3 -8.6 M3.2 -8.6 C3.6 -7.6 4.6 -7.6 5.1 -8.6" fill="none" stroke={INK} strokeWidth=".6" opacity=".7" />
      <path d="M-4 0 C-1 2 3 2 6 0" fill="none" stroke={INK} strokeWidth=".6" opacity=".5" />
    </g>
  );
}

/** A sleeve from the shoulder to the wrist, with a cuff. */
function Sleeve({ d, p }: { d: string; p: string }) {
  return (
    <g>
      <path d={d} fill={`url(#${p}-suit)`} stroke={INK} strokeWidth="2" strokeLinejoin="round" />
      <path d={d} fill={`url(#${p}-cross)`} opacity=".45" />
    </g>
  );
}

/** A leafy tree, clustered and hatched. */
function Tree({ x, y, s = 1, p }: { x: number; y: number; s?: number; p: string }) {
  return (
    <g transform={`translate(${x} ${y}) scale(${s})`}>
      <path d="M-3 0 L-2 -18 L2 -18 L3 0 Z" fill="#6a4f33" stroke={INK} strokeWidth="1.2" />
      {([[-10, -24, 10], [6, -28, 11], [-2, -36, 10], [12, -18, 8], [-14, -14, 8]] as [number, number, number][]).map(([cx, cy, r], i) => (
        <circle key={i} cx={cx} cy={cy} r={r} fill="#d9c79c" stroke={INK} strokeWidth="1.3" />
      ))}
      <circle cx="10" cy="-22" r="8" fill={`url(#${p}-hatch)`} />
    </g>
  );
}

/** 1. Hopeful, the CON application held up, the healthcare building behind. */
function Entrepreneur() {
  const p = "pc1";
  return (
    <Svg>
      <Defs p={p} />
      <rect width="240" height="210" fill="#f3e3bf" />
      <Burst cx={200} cy={20} n={22} r1={14} opacity={0.1} />
      <circle cx="200" cy="20" r="30" fill={`url(#${p}-glow)`} />
      <rect width="240" height="210" fill={`url(#${p}-dots)`} />
      {/* Clouds */}
      <path d="M150 36 c4 -8 14 -8 18 -2 c4 -6 14 -4 14 4 c6 0 8 8 2 10 h-34 c-6 -2 -6 -10 0 -12 Z" fill={SHEET} stroke={INK} strokeWidth="1" opacity=".7" />
      {/* Building: cornice, columns, windows, door */}
      <path d="M144 112 H240 V104 H144 Z" fill={SHEET} stroke={INK} strokeWidth="1.6" />
      <rect x="148" y="112" width="92" height="90" fill={SHEET} stroke={INK} strokeWidth="2" />
      <rect x="212" y="112" width="28" height="90" fill={`url(#${p}-cross)`} />
      <rect x="154" y="117" width="78" height="22" fill={SHEET} stroke={INK} strokeWidth="1.4" />
      <text x="193" y="126" textAnchor="middle" fontFamily="'Patrick Hand SC', 'Courier Prime', sans-serif" fontSize="8.4" fill={INK}>HEALTHCARE</text>
      <text x="193" y="135.5" textAnchor="middle" fontFamily="'Patrick Hand SC', 'Courier Prime', sans-serif" fontSize="8.4" fill={INK}>SERVICES</text>
      {[158, 178, 198, 218].map((x) => (
        <g key={x}>
          <rect x={x} y="146" width="12" height="13" fill="#dccaa0" stroke={INK} strokeWidth="1.1" />
          <path d={`M${x + 6} 146 V159 M${x} 152.5 H${x + 12}`} stroke={INK} strokeWidth=".6" />
          <path d={`M${x + 1} 147 L${x + 5} 151`} stroke={SHIRT} strokeWidth=".8" opacity=".8" />
        </g>
      ))}
      <rect x="186" y="170" width="16" height="32" fill={INK} />
      <Tree x={226} y={202} s={0.9} p={p} />
      <Tree x={160} y={202} s={0.75} p={p} />
      <path d="M140 202 H240" stroke={INK} strokeWidth="1.8" />
      <path d="M150 34 q4 -4 8 0 q4 -4 8 0" fill="none" stroke={INK} strokeWidth="1.1" strokeLinecap="round" transform="translate(-30 10)" />
      <Man x={78} y={70} s={0.82} mood="hopeful" p={p} look={[1.4, -1.6]} tilt={-4} />
      {/* The application, held in both hands */}
      <g transform="rotate(-6 70 166)">
        <rect x="23" y="135" width="100" height="74" fill="#d9c8a2" />
        <rect x="20" y="132" width="100" height="74" fill={SHEET} stroke={INK} strokeWidth="2.2" />
        <path d="M24 137 H116 M24 140 H116" stroke={INK} strokeWidth=".6" opacity=".35" />
        <text x="70" y="162" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="16" fill={INK}>CON</text>
        <text x="70" y="180" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="10.5" fill={INK}>APPLICATION</text>
        <path d="M36 187 Q68 192 104 185" fill="none" stroke={RED} strokeWidth="2.4" strokeLinecap="round" />
        <path d="M30 196 H60 M30 200 H50" stroke={INK} strokeWidth=".8" opacity=".4" />
      </g>
      <Hand x={24} y={162} r={-8} s={0.9} p={p} />
      <Hand x={114} y={152} r={8} s={0.9} p={p} />
      <Vignette p={p} />
    </Svg>
  );
}

/** 2. Puzzled, scratching his head over the newspaper classifieds. */
function Classifieds() {
  const p = "pc2";
  return (
    <Svg>
      <Defs p={p} />
      <rect width="240" height="210" fill={`url(#${p}-stripes)`} />
      <rect width="240" height="210" fill={`url(#${p}-dots)`} />
      {/* A framed certificate on the wall */}
      <rect x="150" y="76" width="40" height="28" fill={SHEET} stroke={INK} strokeWidth="1.6" />
      <rect x="154" y="80" width="32" height="20" fill="none" stroke={INK} strokeWidth=".7" />
      <path d="M158 86 H182 M158 90 H178 M158 94 H174" stroke={INK} strokeWidth=".7" opacity=".6" />
      {/* Raised arm behind his head */}
      <Sleeve d="M30 120 C30 92 40 64 58 44 L76 50 C64 70 58 96 60 122 Z" p={p} />
      <Man x={98} y={64} s={0.78} mood="puzzled" p={p} look={[-0.6, 1]} tilt={6} />
      <Hand x={80} y={36} r={52} s={0.95} p={p} />
      {/* The question mark and its rays */}
      <text x="200" y="64" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="50" fill={INK} opacity=".25" transform="translate(2 2)">?</text>
      <text x="200" y="64" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="50" fill={RED} stroke={INK} strokeWidth="1.3">?</text>
      {([[-1, -1], [1, -1], [-1.3, 0.2], [1.3, 0.2], [0, -1.4]] as [number, number][]).map(([dx, dy], i) => (
        <path key={i} d={`M${200 + dx * 26} ${40 + dy * 24} l${dx * 8} ${dy * 8}`} stroke={INK} strokeWidth="1.8" strokeLinecap="round" />
      ))}
      {/* The newspaper, with a fold and shading */}
      <g transform="rotate(-4 120 154)">
        <rect x="13" y="107" width="224" height="106" fill="#cdbb92" />
        <rect x="10" y="104" width="224" height="106" fill={SHEET} stroke={INK} strokeWidth="2.4" />
        <path d="M122 104 V210" stroke={INK} strokeWidth=".8" opacity=".35" />
        <rect x="122" y="104" width="112" height="106" fill={`url(#${p}-dots)`} />
        <text x="122" y="123" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="12.5" fill={INK}>NEWSPAPER</text>
        <text x="122" y="137" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="12.5" fill={INK}>CLASSIFIEDS</text>
        <path d="M18 142 H226 M18 145 H226" stroke={INK} strokeWidth=".9" />
        {[153, 160, 167, 174, 181, 188, 195, 202].map((y) => (
          <path key={y} d={`M20 ${y} H70 M80 ${y} H150 M160 ${y} H224`} stroke={INK} strokeWidth="1.2" opacity=".3" />
        ))}
        <ellipse cx="62" cy="165" rx="41" ry="14" fill={SHEET} stroke={RED} strokeWidth="2.2" />
        <text x="62" y="169" textAnchor="middle" fontFamily="'Patrick Hand SC', sans-serif" fontSize="11" fill={INK}>LEGAL NOTICES?</text>
        <ellipse cx="177" cy="163" rx="43" ry="14" fill={SHEET} stroke={RED} strokeWidth="2.2" />
        <text x="177" y="167" textAnchor="middle" fontFamily="'Patrick Hand SC', sans-serif" fontSize="11" fill={INK}>PUBLIC NOTICES?</text>
        <ellipse cx="118" cy="193" rx="39" ry="12" fill={SHEET} stroke={RED} strokeWidth="2.2" />
        <text x="118" y="197" textAnchor="middle" fontFamily="'Patrick Hand SC', sans-serif" fontSize="11" fill={INK}>ADVERTISING?</text>
      </g>
      <Hand x={216} y={112} r={-12} s={0.85} p={p} />
      <Vignette p={p} />
    </Svg>
  );
}

/** A black rotary telephone on the desk. */
function Phone({ x, y }: { x: number; y: number }) {
  return (
    <g transform={`translate(${x} ${y})`}>
      <ellipse cx="0" cy="19" rx="32" ry="4" fill={INK} opacity=".25" />
      <path d="M-30 18 C-30 0 -18 -8 0 -8 C18 -8 30 0 30 18 Z" fill={INK} />
      <path d="M-22 6 C-16 -2 -6 -4 2 -4" fill="none" stroke={PAPER} strokeWidth="1.2" opacity=".55" strokeLinecap="round" />
      <circle cx="0" cy="6" r="11" fill={SHEET} stroke={INK} strokeWidth="1.5" />
      {Array.from({ length: 8 }, (_, i) => {
        const a = (i / 8) * Math.PI * 2;
        return <circle key={i} cx={Math.cos(a) * 7} cy={6 + Math.sin(a) * 7} r="1.6" fill={INK} />;
      })}
      <circle cx="0" cy="6" r="2.2" fill={RED} />
    </g>
  );
}

/** A handset held to the ear. */
function Handset({ x, y, r = 0 }: { x: number; y: number; r?: number }) {
  return (
    <g transform={`translate(${x} ${y}) rotate(${r})`}>
      <path d="M-6 -24 C-14 -22 -16 -14 -12 -10 L-4 -12 C-6 -14 -4 -18 0 -18 Z" fill={INK} />
      <path d="M-4 -18 C-10 -6 -10 6 -4 18 L2 16 C-3 6 -3 -6 2 -16 Z" fill={INK} />
      <path d="M-6 24 C-14 22 -16 14 -12 10 L-4 12 C-6 14 -4 18 0 18 Z" fill={INK} />
      <path d="M-6 -10 C-8 -2 -8 4 -6 10" fill="none" stroke={PAPER} strokeWidth=".9" opacity=".55" />
    </g>
  );
}

/** 3. Two phones at once, ringing off the hook. */
function PhoneFlurry() {
  const p = "pc3";
  return (
    <Svg>
      <Defs p={p} />
      <rect width="240" height="210" fill="#f6dcc4" />
      <Burst cx={118} cy={72} n={24} r1={30} color={RED} opacity={0.2} width={0.08} />
      <rect width="240" height="210" fill={`url(#${p}-reddots)`} />
      {/* Ring lines */}
      {([[-1, -1], [-0.3, -1.3], [0.4, -1.3], [1, -1], [-1.4, -0.3], [1.4, -0.3]] as [number, number][]).map(([dx, dy], i) => (
        <path key={i} d={`M${120 + dx * 56} ${50 + dy * 38} l${dx * 11} ${dy * 11}`} stroke={INK} strokeWidth="2.2" strokeLinecap="round" />
      ))}
      <text x="26" y="34" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="13" fill={RED} stroke={INK} strokeWidth=".6" transform="rotate(-14 26 34)">RING!</text>
      <text x="178" y="30" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="13" fill={RED} stroke={INK} strokeWidth=".6" transform="rotate(12 178 30)">RING!</text>
      {/* Arms up to both ears */}
      <Sleeve d="M44 170 L58 96 L80 92 L74 174 Z" p={p} />
      <Sleeve d="M196 170 L182 96 L160 94 L166 174 Z" p={p} />
      <Man x={118} y={78} s={0.78} mood="shocked" p={p} look={[1.4, 0]} />
      {/* Sweat drops */}
      <path d="M150 52 c-3 4 -3 7 0 8 c3 -1 3 -4 0 -8 Z M156 62 c-2 3 -2 5 0 6 c2 -1 2 -3 0 -6 Z" fill={SHIRT} stroke={INK} strokeWidth=".9" />
      <Hand x={90} y={92} r={-20} s={0.85} p={p} />
      <Hand x={152} y={92} r={20} s={0.85} p={p} />
      <Handset x={97} y={82} r={-8} />
      <Handset x={145} y={80} r={190} />
      {/* Curly cords */}
      <path d="M92 108 c-6 6 6 10 0 16 c-6 6 6 10 0 16 c-6 6 6 10 0 16 c-6 6 -10 10 -30 12" fill="none" stroke={INK} strokeWidth="1.7" />
      <path d="M150 108 c6 6 -6 10 0 16 c6 6 -6 10 0 16 c6 6 -6 10 0 16 c6 6 10 10 30 12" fill="none" stroke={INK} strokeWidth="1.7" />
      {/* Desk and phones */}
      <path d="M0 178 H240 V210 H0 Z" fill="#d8bf92" stroke={INK} strokeWidth="2" />
      <path d="M0 186 H240 M0 196 C60 192 180 200 240 194" stroke={INK} strokeWidth=".8" opacity=".45" fill="none" />
      <Phone x={46} y={172} />
      <Phone x={194} y={172} />
      <Vignette p={p} />
    </Svg>
  );
}

/** 4. Buried in forms, ad details, revisions and deadlines. */
function Deadlines() {
  const p = "pc4";
  const tabs = ["FORMS", "AD DETAILS", "REVISIONS", "DEADLINES"];
  return (
    <Svg>
      <Defs p={p} />
      <rect width="240" height="210" fill={`url(#${p}-stripes)`} />
      <rect width="240" height="210" fill={`url(#${p}-dots)`} />
      {/* Window with dusk light */}
      <rect x="8" y="10" width="62" height="56" fill="#e9c98f" stroke={INK} strokeWidth="1.8" />
      <path d="M39 10 V66 M8 38 H70" stroke={INK} strokeWidth="1.6" />
      <rect x="8" y="10" width="62" height="56" fill={`url(#${p}-hatch)`} opacity=".4" />
      {/* Calendar */}
      <g transform="rotate(3 192 46)">
        <path d="M192 2 L192 10" stroke={INK} strokeWidth="1.5" />
        <circle cx="192" cy="3" r="2" fill={INK} />
        <rect x="153" y="13" width="84" height="74" fill="#cdbb92" />
        <rect x="150" y="10" width="84" height="74" fill={SHEET} stroke={INK} strokeWidth="2" />
        <rect x="150" y="10" width="84" height="16" fill={RED} stroke={INK} strokeWidth="2" />
        <text x="192" y="22" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="9" fill={SHEET}>DEADLINE</text>
        {[0, 1, 2, 3].map((r) => [0, 1, 2, 3, 4, 5].map((c) => <rect key={`${r}${c}`} x={154 + c * 13} y={30 + r * 13} width="11" height="11" fill="none" stroke={INK} strokeWidth=".8" />))}
        <path d="M155 31 l9 9 M155 40 l9 -9 M168 31 l9 9 M168 40 l9 -9 M181 31 l9 9 M181 40 l9 -9" stroke={INK} strokeWidth=".9" opacity=".7" />
        <ellipse cx="199" cy="62" rx="9.5" ry="7.5" fill="none" stroke={RED} strokeWidth="2.2" />
      </g>
      {/* Elbow on the desk, hand to his forehead */}
      <Sleeve d="M142 168 L150 108 L132 70 L114 76 L128 112 L120 170 Z" p={p} />
      <Man x={88} y={84} s={0.76} mood="tired" p={p} tilt={-8} look={[0, 1]} />
      <Hand x={110} y={60} r={-120} s={0.95} p={p} />
      {/* Desk */}
      <path d="M0 160 H240 V210 H0 Z" fill="#d8bf92" stroke={INK} strokeWidth="2" />
      {/* Paper pile and scattered papers */}
      <path d="M124 160 C130 140 150 132 176 136 C200 132 226 140 236 160 Z" fill={SHEET} stroke={INK} strokeWidth="1.6" />
      <path d="M134 152 C150 144 170 142 190 146 M140 158 C160 150 190 150 226 156" fill="none" stroke={INK} strokeWidth=".8" opacity=".6" />
      {([[150, 168, 10], [178, 176, -14], [204, 166, 22], [132, 182, -6], [218, 186, 8]] as [number, number, number][]).map(([x, y, r], i) => (
        <g key={i} transform={`rotate(${r} ${x} ${y})`}>
          <rect x={x - 16} y={y - 11} width="32" height="22" fill={SHEET} stroke={INK} strokeWidth="1.2" />
          <path d={`M${x - 11} ${y - 5} h22 M${x - 11} ${y} h16 M${x - 11} ${y + 5} h19`} stroke={INK} strokeWidth=".8" />
        </g>
      ))}
      {/* Labelled stack */}
      {tabs.map((t, i) => (
        <g key={t} transform={`rotate(${i % 2 ? 2 : -2} 60 ${130 + i * 20})`}>
          <rect x="10" y={122 + i * 20} width="104" height="20" fill="#cdbb92" />
          <rect x="8" y={120 + i * 20} width="104" height="20" fill={SHEET} stroke={INK} strokeWidth="1.9" />
          <text x="60" y={134 + i * 20} textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="9.5" fill={INK}>{t}</text>
        </g>
      ))}
      <Vignette p={p} />
    </Svg>
  );
}

/** 5. Relief: leaning back, hands behind his head, mystateCONnews on the laptop. */
function Relief() {
  const p = "pc5";
  return (
    <Svg>
      <Defs p={p} />
      <rect width="240" height="210" fill={`url(#${p}-stripes)`} />
      <circle cx="78" cy="66" r="70" fill={`url(#${p}-glow)`} />
      <Burst cx={78} cy={66} n={20} r1={50} opacity={0.08} />
      <rect width="240" height="210" fill={`url(#${p}-dots)`} />
      {/* Potted plant, right */}
      <path d="M220 96 C214 76 218 60 226 52 M222 96 C226 78 234 70 240 66 M218 96 C208 84 200 80 194 80" fill="none" stroke={INK} strokeWidth="1.4" />
      <ellipse cx="226" cy="54" rx="5" ry="9" fill="#cdbb92" stroke={INK} strokeWidth="1.1" transform="rotate(20 226 54)" />
      <ellipse cx="238" cy="66" rx="4" ry="8" fill="#cdbb92" stroke={INK} strokeWidth="1.1" transform="rotate(60 238 66)" />
      <ellipse cx="196" cy="80" rx="4" ry="8" fill="#cdbb92" stroke={INK} strokeWidth="1.1" transform="rotate(-60 196 80)" />
      {/* Elbows out, hands behind his head */}
      {/* Upper arms start inside the jacket's shoulders, so arm and body join. */}
      <Sleeve d="M26 156 C18 124 10 88 13 58 C14 44 24 38 34 42 L66 56 L60 68 L36 60 C40 86 52 114 70 140 Z" p={p} />
      <Sleeve d="M132 146 C138 116 140 82 135 56 C132 42 122 36 112 40 L84 52 L88 64 L114 56 C113 82 108 110 96 136 Z" p={p} />
      <Man x={74} y={74} s={0.8} mood="happy" p={p} tilt={-10} />
      {/* Desk */}
      <path d="M0 180 H240 V210 H0 Z" fill="#d8bf92" stroke={INK} strokeWidth="2" />
      {/* Coffee */}
      <ellipse cx="34" cy="179" rx="16" ry="3" fill={INK} opacity=".2" />
      <path d="M18 150 H48 L45 178 H21 Z" fill={SHIRT} stroke={INK} strokeWidth="1.9" />
      <path d="M38 152 L36 176" stroke="#d8cbb0" strokeWidth="5" opacity=".7" />
      <path d="M48 156 C58 156 58 170 46 170" fill="none" stroke={INK} strokeWidth="1.9" />
      <path d="M26 144 q4 -6 0 -12 M36 144 q4 -6 0 -12" fill="none" stroke={INK} strokeWidth="1.2" strokeLinecap="round" />
      {/* Laptop, lower right (the balloon sits above it) */}
      <path d="M132 90 L232 84 L236 168 L136 174 Z" fill={INK} />
      <path d="M139 96 L226 90 L229 162 L142 167 Z" fill={SHEET} />
      <path d="M139 96 L226 90 L227 104 L140 110 Z" fill="#efe2c2" />
      <text x="184" y="104" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="8" fill={RED} transform="rotate(-4 184 104)">mystateCONnews</text>
      {["CON public notices", "Newspaper options", "Clear next steps"].map((t, i) => (
        <g key={t} transform={`rotate(-4 184 ${124 + i * 13})`}>
          <rect x="148" y={117 + i * 13} width="8" height="8" fill={SHEET} stroke={INK} strokeWidth="1.1" />
          <path d={`M149.2 ${121.5 + i * 13} l2.6 2.6 l4.4 -6`} fill="none" stroke={RED} strokeWidth="1.6" strokeLinecap="round" />
          <text x="160" y={124 + i * 13} fontFamily="'Patrick Hand SC', sans-serif" fontSize="9" fill={INK}>{t}</text>
        </g>
      ))}
      <path d="M124 174 L240 168 L240 184 L120 188 Z" fill="#cdbb92" stroke={INK} strokeWidth="1.9" />
      <path d="M166 176 H200" stroke={INK} strokeWidth="1.4" strokeLinecap="round" />
      <Vignette p={p} />
    </Svg>
  );
}

/** Banner decorations: the hospital on the left, the public notice on the right. */
export function BannerHospital() {
  return (
    <svg viewBox="0 0 140 80" aria-hidden="true" focusable="false">
      <path d="M8 76 H132" stroke={INK} strokeWidth="2" />
      <rect x="30" y="20" width="80" height="56" fill={SHEET} stroke={INK} strokeWidth="2" />
      <rect x="54" y="6" width="32" height="20" fill={SHEET} stroke={INK} strokeWidth="2" />
      <rect x="66" y="10" width="8" height="12" fill={RED} />
      <rect x="64" y="13" width="12" height="6" fill={RED} />
      {[38, 52, 78, 92].map((x) => (
        <g key={x}>
          <rect x={x} y="32" width="9" height="9" fill="#dccaa0" stroke={INK} strokeWidth="1.2" />
          <rect x={x} y="50" width="9" height="9" fill="#dccaa0" stroke={INK} strokeWidth="1.2" />
        </g>
      ))}
      <path d="M64 76 V60 H76 V76" fill={INK} />
      <circle cx="18" cy="62" r="12" fill="#d9c79c" stroke={INK} strokeWidth="1.6" />
      <circle cx="122" cy="64" r="10" fill="#d9c79c" stroke={INK} strokeWidth="1.6" />
    </svg>
  );
}
export function BannerNotice() {
  return (
    <svg viewBox="0 0 140 80" aria-hidden="true" focusable="false">
      <g transform="rotate(6 70 40)">
        <rect x="25" y="11" width="104" height="68" fill="#cdbb92" />
        <rect x="22" y="8" width="104" height="68" fill={SHEET} stroke={INK} strokeWidth="2" />
        <rect x="30" y="14" width="88" height="24" fill="none" stroke={INK} strokeWidth="1.6" />
        <text x="74" y="25" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="9" fill={INK}>PUBLIC</text>
        <text x="74" y="35" textAnchor="middle" fontFamily="'Alfa Slab One', Georgia, serif" fontSize="9" fill={INK}>NOTICE</text>
        {[46, 53, 60, 67].map((y) => (
          <path key={y} d={`M30 ${y} H70 M78 ${y} H118`} stroke={INK} strokeWidth="1.3" opacity=".45" />
        ))}
      </g>
    </svg>
  );
}

export const COMIC_STRIP_ART: Record<string, () => ReactElement> = {
  entrepreneur: Entrepreneur,
  classifieds: Classifieds,
  phones: PhoneFlurry,
  deadlines: Deadlines,
  relief: Relief
};
