// Original geometric character avatars — pure SVG, no copyrighted designs.
// Each avatar is a self-contained component rendered inside a circular pastel tile.

const AvatarBear = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <circle cx="28" cy="32" r="11" fill="#6B4A2B" />
    <circle cx="72" cy="32" r="11" fill="#6B4A2B" />
    <circle cx="28" cy="32" r="5" fill="#E8D2B4" />
    <circle cx="72" cy="32" r="5" fill="#E8D2B4" />
    <circle cx="50" cy="55" r="30" fill="#8B6240" />
    <ellipse cx="50" cy="62" rx="16" ry="13" fill="#E8D2B4" />
    <circle cx="40" cy="50" r="2.5" fill="#1B1A17" />
    <circle cx="60" cy="50" r="2.5" fill="#1B1A17" />
    <ellipse cx="50" cy="60" rx="3" ry="2" fill="#1B1A17" />
    <path d="M 44 66 Q 50 70 56 66" stroke="#1B1A17" strokeWidth="1.8" fill="none" strokeLinecap="round" />
  </svg>
);

const AvatarCat = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <path d="M 22 38 L 28 18 L 38 32 Z" fill="#D89B6A" />
    <path d="M 78 38 L 72 18 L 62 32 Z" fill="#D89B6A" />
    <path d="M 25 36 L 29 24 L 35 33 Z" fill="#F2C5A0" />
    <path d="M 75 36 L 71 24 L 65 33 Z" fill="#F2C5A0" />
    <circle cx="50" cy="55" r="30" fill="#E8AC7E" />
    <circle cx="40" cy="52" r="3" fill="#1B1A17" />
    <circle cx="60" cy="52" r="3" fill="#1B1A17" />
    <path d="M 47 62 L 50 65 L 53 62 Z" fill="#1B1A17" />
    <path d="M 50 65 Q 46 70 42 67" stroke="#1B1A17" strokeWidth="1.5" fill="none" strokeLinecap="round" />
    <path d="M 50 65 Q 54 70 58 67" stroke="#1B1A17" strokeWidth="1.5" fill="none" strokeLinecap="round" />
    <line x1="32" y1="58" x2="22" y2="56" stroke="#1B1A17" strokeWidth="1.2" strokeLinecap="round" />
    <line x1="32" y1="61" x2="22" y2="62" stroke="#1B1A17" strokeWidth="1.2" strokeLinecap="round" />
    <line x1="68" y1="58" x2="78" y2="56" stroke="#1B1A17" strokeWidth="1.2" strokeLinecap="round" />
    <line x1="68" y1="61" x2="78" y2="62" stroke="#1B1A17" strokeWidth="1.2" strokeLinecap="round" />
  </svg>
);

const AvatarFox = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <path d="M 20 35 L 30 16 L 40 32 Z" fill="#D86A3C" />
    <path d="M 80 35 L 70 16 L 60 32 Z" fill="#D86A3C" />
    <circle cx="50" cy="55" r="30" fill="#E8804A" />
    <path d="M 35 70 Q 50 78 65 70 Q 60 56 50 56 Q 40 56 35 70 Z" fill="#FAF1E4" />
    <ellipse cx="50" cy="68" rx="6" ry="8" fill="#FAF1E4" />
    <circle cx="40" cy="52" r="3" fill="#1B1A17" />
    <circle cx="60" cy="52" r="3" fill="#1B1A17" />
    <ellipse cx="50" cy="64" rx="3" ry="2.5" fill="#1B1A17" />
  </svg>
);

const AvatarBunny = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <ellipse cx="38" cy="20" rx="6" ry="16" fill="#F5F0EB" />
    <ellipse cx="62" cy="20" rx="6" ry="16" fill="#F5F0EB" />
    <ellipse cx="38" cy="22" rx="2.5" ry="10" fill="#F5C5C5" />
    <ellipse cx="62" cy="22" rx="2.5" ry="10" fill="#F5C5C5" />
    <circle cx="50" cy="55" r="28" fill="#FAF6F0" />
    <circle cx="40" cy="52" r="2.5" fill="#1B1A17" />
    <circle cx="60" cy="52" r="2.5" fill="#1B1A17" />
    <circle cx="36" cy="60" r="4" fill="#F5C5C5" opacity="0.6" />
    <circle cx="64" cy="60" r="4" fill="#F5C5C5" opacity="0.6" />
    <ellipse cx="50" cy="62" rx="2.5" ry="2" fill="#E89B9B" />
    <path d="M 50 64 L 50 67" stroke="#1B1A17" strokeWidth="1.2" />
    <path d="M 50 67 Q 46 70 44 68" stroke="#1B1A17" strokeWidth="1.2" fill="none" strokeLinecap="round" />
    <path d="M 50 67 Q 54 70 56 68" stroke="#1B1A17" strokeWidth="1.2" fill="none" strokeLinecap="round" />
  </svg>
);

const AvatarPanda = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <circle cx="26" cy="26" r="10" fill="#1B1A17" />
    <circle cx="74" cy="26" r="10" fill="#1B1A17" />
    <circle cx="50" cy="55" r="30" fill="#FAF6F0" />
    <ellipse cx="38" cy="52" rx="8" ry="10" fill="#1B1A17" transform="rotate(-15 38 52)" />
    <ellipse cx="62" cy="52" rx="8" ry="10" fill="#1B1A17" transform="rotate(15 62 52)" />
    <circle cx="38" cy="53" r="2.5" fill="#FAF6F0" />
    <circle cx="62" cy="53" r="2.5" fill="#FAF6F0" />
    <ellipse cx="50" cy="63" rx="3" ry="2" fill="#1B1A17" />
    <path d="M 47 67 Q 50 70 53 67" stroke="#1B1A17" strokeWidth="1.5" fill="none" strokeLinecap="round" />
  </svg>
);

const AvatarFrog = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <circle cx="32" cy="28" r="13" fill="#7CB87C" />
    <circle cx="68" cy="28" r="13" fill="#7CB87C" />
    <circle cx="32" cy="30" r="7" fill="#FAF6F0" />
    <circle cx="68" cy="30" r="7" fill="#FAF6F0" />
    <circle cx="32" cy="32" r="3" fill="#1B1A17" />
    <circle cx="68" cy="32" r="3" fill="#1B1A17" />
    <circle cx="50" cy="58" r="28" fill="#9BC98E" />
    <circle cx="40" cy="62" r="3" fill="#F5B5C5" opacity="0.5" />
    <circle cx="60" cy="62" r="3" fill="#F5B5C5" opacity="0.5" />
    <path d="M 38 65 Q 50 73 62 65" stroke="#1B1A17" strokeWidth="2" fill="none" strokeLinecap="round" />
  </svg>
);

const AvatarOwl = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <path d="M 22 30 L 28 16 L 36 30 Z" fill="#A8835C" />
    <path d="M 78 30 L 72 16 L 64 30 Z" fill="#A8835C" />
    <ellipse cx="50" cy="56" rx="30" ry="32" fill="#C9A47A" />
    <ellipse cx="50" cy="68" rx="22" ry="16" fill="#E8C9A0" />
    <circle cx="38" cy="48" r="11" fill="#FAF6F0" />
    <circle cx="62" cy="48" r="11" fill="#FAF6F0" />
    <circle cx="38" cy="48" r="6" fill="#1B1A17" />
    <circle cx="62" cy="48" r="6" fill="#1B1A17" />
    <circle cx="40" cy="46" r="2" fill="#FAF6F0" />
    <circle cx="64" cy="46" r="2" fill="#FAF6F0" />
    <path d="M 46 56 L 50 62 L 54 56 Z" fill="#E89B5C" />
  </svg>
);

const AvatarPenguin = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <ellipse cx="50" cy="55" rx="28" ry="32" fill="#2C3440" />
    <ellipse cx="50" cy="62" rx="18" ry="22" fill="#FAF6F0" />
    <circle cx="42" cy="46" r="3" fill="#1B1A17" />
    <circle cx="58" cy="46" r="3" fill="#1B1A17" />
    <circle cx="42" cy="45" r="1" fill="#FAF6F0" />
    <circle cx="58" cy="45" r="1" fill="#FAF6F0" />
    <path d="M 46 52 L 50 57 L 54 52 Z" fill="#E89B5C" />
    <circle cx="38" cy="58" r="3.5" fill="#F5C5C5" opacity="0.5" />
    <circle cx="62" cy="58" r="3.5" fill="#F5C5C5" opacity="0.5" />
  </svg>
);

const AvatarKoala = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <circle cx="24" cy="34" r="13" fill="#9CA3AE" />
    <circle cx="76" cy="34" r="13" fill="#9CA3AE" />
    <circle cx="24" cy="36" r="7" fill="#F5B5B5" opacity="0.6" />
    <circle cx="76" cy="36" r="7" fill="#F5B5B5" opacity="0.6" />
    <circle cx="50" cy="58" r="30" fill="#B5BCC4" />
    <circle cx="40" cy="55" r="3" fill="#1B1A17" />
    <circle cx="60" cy="55" r="3" fill="#1B1A17" />
    <ellipse cx="50" cy="65" rx="6" ry="4.5" fill="#1B1A17" />
  </svg>
);

const AvatarDeer = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <path d="M 28 22 L 24 8 M 28 22 L 18 14 M 28 22 L 32 12" stroke="#6B4A2B" strokeWidth="2.5" strokeLinecap="round" fill="none" />
    <path d="M 72 22 L 76 8 M 72 22 L 82 14 M 72 22 L 68 12" stroke="#6B4A2B" strokeWidth="2.5" strokeLinecap="round" fill="none" />
    <ellipse cx="32" cy="32" rx="5" ry="8" fill="#C99878" />
    <ellipse cx="68" cy="32" rx="5" ry="8" fill="#C99878" />
    <circle cx="50" cy="56" r="28" fill="#D8A988" />
    <circle cx="40" cy="52" r="2.5" fill="#1B1A17" />
    <circle cx="60" cy="52" r="2.5" fill="#1B1A17" />
    <circle cx="36" cy="62" r="3" fill="#FAF6F0" opacity="0.7" />
    <circle cx="64" cy="62" r="3" fill="#FAF6F0" opacity="0.7" />
    <ellipse cx="50" cy="65" rx="4" ry="3" fill="#1B1A17" />
  </svg>
);

const AvatarHedgehog = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <path d="M 20 60 L 14 48 M 25 50 L 18 38 M 32 42 L 28 28 M 42 36 L 42 22 M 52 34 L 56 20 M 62 36 L 68 24 M 72 42 L 80 32 M 78 50 L 86 42 M 80 60 L 88 56" stroke="#5C4530" strokeWidth="2.5" strokeLinecap="round" />
    <ellipse cx="50" cy="62" rx="32" ry="22" fill="#8B6F4E" />
    <ellipse cx="50" cy="64" rx="22" ry="16" fill="#E8C9A0" />
    <circle cx="42" cy="58" r="2.5" fill="#1B1A17" />
    <circle cx="58" cy="58" r="2.5" fill="#1B1A17" />
    <circle cx="50" cy="68" r="3" fill="#1B1A17" />
  </svg>
);

const AvatarSheep = ({ size = 96 }) => (
  <svg viewBox="0 0 100 100" width={size} height={size}>
    <circle cx="28" cy="40" r="10" fill="#FAF6F0" />
    <circle cx="22" cy="32" r="8" fill="#FAF6F0" />
    <circle cx="32" cy="26" r="9" fill="#FAF6F0" />
    <circle cx="68" cy="26" r="9" fill="#FAF6F0" />
    <circle cx="78" cy="32" r="8" fill="#FAF6F0" />
    <circle cx="72" cy="40" r="10" fill="#FAF6F0" />
    <circle cx="50" cy="22" r="10" fill="#FAF6F0" />
    <circle cx="50" cy="60" r="32" fill="#FAF6F0" />
    <circle cx="32" cy="74" r="9" fill="#FAF6F0" />
    <circle cx="68" cy="74" r="9" fill="#FAF6F0" />
    <ellipse cx="50" cy="62" rx="20" ry="18" fill="#3A2E26" />
    <circle cx="42" cy="58" r="3" fill="#FAF6F0" />
    <circle cx="58" cy="58" r="3" fill="#FAF6F0" />
    <ellipse cx="50" cy="68" rx="3.5" ry="2.5" fill="#FAF6F0" />
  </svg>
);

// Registry: id → { component, accent (pastel bg), name }
const AVATARS = [
  { id: "bear",     name: "Honey",   bg: "#F4E2C9", Comp: AvatarBear },
  { id: "cat",      name: "Mochi",   bg: "#F8DCC4", Comp: AvatarCat },
  { id: "fox",      name: "Cinder",  bg: "#FAD4BC", Comp: AvatarFox },
  { id: "bunny",    name: "Pip",     bg: "#FBE0E0", Comp: AvatarBunny },
  { id: "panda",    name: "Bao",     bg: "#ECECEC", Comp: AvatarPanda },
  { id: "frog",     name: "Pesto",   bg: "#DDEDD4", Comp: AvatarFrog },
  { id: "owl",      name: "Sage",    bg: "#EFE0CB", Comp: AvatarOwl },
  { id: "penguin",  name: "Pebble",  bg: "#D8E4EE", Comp: AvatarPenguin },
  { id: "koala",    name: "Eucy",    bg: "#E2E5EA", Comp: AvatarKoala },
  { id: "deer",     name: "Willow",  bg: "#EFD9C7", Comp: AvatarDeer },
  { id: "hedgehog", name: "Thistle", bg: "#E5D6BF", Comp: AvatarHedgehog },
  { id: "sheep",    name: "Cloud",   bg: "#F1ECE2", Comp: AvatarSheep },
];

// Egg tile — shown when no avatar has been summoned yet.
const EggTile = ({ size = 96, ring = false, ringClass = "ring-4 ring-white" }) => {
  const sw = Math.round(size * 0.60);
  const sh = Math.round(size * 0.72);
  return (
    <div
      className={`rounded-full egg-tile-pulse flex items-center justify-center overflow-hidden ${ring ? ringClass : ""}`}
      style={{ width: size, height: size, background: "#FFFDE8" }}
    >
      <svg viewBox="0 0 80 100" width={sw} height={sh}>
        <ellipse cx="40" cy="57" rx="28" ry="36" fill="#FFFDE8" />
        <ellipse cx="40" cy="57" rx="28" ry="36" fill="none" stroke="#EDE6B0" strokeWidth="3.5" />
        <ellipse cx="27" cy="37" rx="6" ry="9" fill="white" opacity="0.55" transform="rotate(-20 27 37)" />
        <path d="M 29 60 Q 33 55 37 60" stroke="#B8921E" strokeWidth="2.2" fill="none" strokeLinecap="round" />
        <path d="M 43 60 Q 47 55 51 60" stroke="#B8921E" strokeWidth="2.2" fill="none" strokeLinecap="round" />
        <circle cx="26" cy="67" r="5.5" fill="#FCA5A5" opacity="0.28" />
        <circle cx="54" cy="67" r="5.5" fill="#FCA5A5" opacity="0.28" />
        <text x="55" y="34" style={{ fontFamily: "system-ui", fontSize: "11px", fontWeight: 700, fill: "#C8A832", opacity: 0.75 }}>z</text>
      </svg>
    </div>
  );
};

// Renders an avatar inside a circular pastel tile. Handles "egg" id for first-time users.
const AvatarTile = ({ id, size = 96, ring = false, ringClass = "ring-4 ring-white" }) => {
  if (id === "egg") return <EggTile size={size} ring={ring} ringClass={ringClass} />;
  const a = AVATARS.find((x) => x.id === id) || AVATARS[0];
  const Comp = a.Comp;
  return (
    <div
      className={`rounded-full flex items-center justify-center overflow-hidden ${ring ? ringClass : ""}`}
      style={{ width: size, height: size, background: a.bg }}
    >
      <Comp size={Math.round(size * 0.92)} />
    </div>
  );
};

window.AVATARS    = AVATARS;
window.AvatarTile = AvatarTile;
window.EggTile    = EggTile;
