{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glow-avatar",
  "title": "Glow Avatar",
  "description": "An expressive assistant that looks around, follows the pointer, and changes shape, mood, and motion.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "components/ui/glow-avatar.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useRef, type CSSProperties } from \"react\";\nimport { AI_BOT_SVG, createAiBot, type AiBot, type AiBotOptions } from \"./glow-avatar-engine\";\nimport s from \"./glow-avatar.module.css\";\n\nexport {\n  AI_BOT_EMOTIONS,\n  AI_BOT_MOTIONS,\n  AI_BOT_SHAPES,\n  type AiBotActivity,\n  type AiBotEmotion,\n  type AiBotMotion,\n  type AiBotShape,\n} from \"./glow-avatar-engine\";\n\nexport interface GlowAvatarProps extends AiBotOptions {\n  /** Gradient stops, light to dark. Defaults to the current Afterglow accent. */\n  colors?: readonly [string, string];\n  /** Diameter of the body in px. Motions spill outside this box. */\n  size?: number;\n  label?: string;\n  className?: string;\n  style?: CSSProperties;\n}\n\nexport function GlowAvatar({ colors, size = 120, label = \"AI assistant\", className, style, ...options }: GlowAvatarProps) {\n  const gradId = `bot-${useId().replace(/:/g, \"\")}`;\n  const svgRef = useRef<SVGSVGElement>(null);\n  const moverRef = useRef<SVGGElement>(null);\n  const bodyGroupRef = useRef<SVGGElement>(null);\n  const bodyRef = useRef<SVGPathElement>(null);\n  const faceRef = useRef<SVGGElement>(null);\n  const mouthRef = useRef<SVGPathElement>(null);\n  const groundRef = useRef<SVGEllipseElement>(null);\n  const coreRef = useRef<SVGEllipseElement>(null);\n  const eyes = useRef<(SVGPathElement | null)[]>([]);\n  const blush = useRef<(SVGEllipseElement | null)[]>([]);\n  const hearts = useRef<(SVGPathElement | null)[]>([]);\n  const bot = useRef<AiBot | null>(null);\n  const latest = useRef(options);\n\n  useEffect(() => {\n    latest.current = options;\n    bot.current?.update(options);\n  });\n\n  useEffect(() => {\n    const svg = svgRef.current;\n    const mover = moverRef.current;\n    const bodyGroup = bodyGroupRef.current;\n    const body = bodyRef.current;\n    const face = faceRef.current;\n    const mouth = mouthRef.current;\n    const ground = groundRef.current;\n    const core = coreRef.current;\n    if (!svg || !mover || !bodyGroup || !body || !face || !mouth || !ground || !core) return;\n    bot.current = createAiBot(\n      { svg, mover, bodyGroup, body, face, mouth, ground, core, eyes: eyes.current, blush: blush.current, hearts: hearts.current },\n      latest.current,\n    );\n    return () => {\n      bot.current?.destroy();\n      bot.current = null;\n    };\n  }, []);\n\n  const vars = {\n    \"--bot-size\": `${size}px`,\n    ...(colors ? { \"--bot-1\": colors[0], \"--bot-2\": colors[1] } : null),\n    ...style,\n  } as CSSProperties;\n\n  return (\n    <span className={`${s.root}${className ? ` ${className}` : \"\"}`} style={vars} role=\"img\" aria-label={label}>\n      <svg ref={svgRef} className={s.svg} viewBox={AI_BOT_SVG.viewBox} aria-hidden>\n        <defs>\n          <radialGradient id={gradId} gradientUnits=\"userSpaceOnUse\" cx=\"-4.8\" cy=\"-6.4\" r=\"24\">\n            <stop className={s.stop1} offset=\"0\" />\n            <stop className={s.stop2} offset=\"1\" />\n          </radialGradient>\n          <filter id={`${gradId}-soft`} x=\"-50%\" y=\"-300%\" width=\"200%\" height=\"700%\">\n            <feGaussianBlur stdDeviation=\"1.3\" />\n          </filter>\n          <filter id={`${gradId}-core`} x=\"-50%\" y=\"-300%\" width=\"200%\" height=\"700%\">\n            <feGaussianBlur stdDeviation=\"0.8\" />\n          </filter>\n          <filter id={`${gradId}-blush`} x=\"-100%\" y=\"-100%\" width=\"300%\" height=\"300%\">\n            <feGaussianBlur stdDeviation=\"0.55\" />\n          </filter>\n        </defs>\n        <ellipse\n          ref={groundRef}\n          className={s.ground}\n          cx=\"0\"\n          cy={AI_BOT_SVG.groundY}\n          rx=\"10\"\n          ry=\"2.1\"\n          filter={`url(#${gradId}-soft)`}\n        />\n        <ellipse\n          ref={coreRef}\n          className={s.core}\n          cx=\"0\"\n          cy={AI_BOT_SVG.groundY}\n          rx=\"6.5\"\n          ry=\"0.9\"\n          filter={`url(#${gradId}-core)`}\n        />\n        <g ref={moverRef}>\n          <g ref={bodyGroupRef}>\n            <path ref={bodyRef} d={AI_BOT_SVG.body} fill={`url(#${gradId})`} />\n          </g>\n          <g ref={faceRef}>\n            {AI_BOT_SVG.blush.map((b, i) => (\n              <ellipse\n                key={`blush${i}`}\n                ref={(node) => {\n                  blush.current[i] = node;\n                }}\n                className={s.blush}\n                cx={b.cx}\n                cy={b.cy}\n                rx=\"1.9\"\n                ry=\"1.1\"\n                opacity=\"0\"\n                filter={`url(#${gradId}-blush)`}\n              />\n            ))}\n            {AI_BOT_SVG.eyes.map((d, i) => (\n              <path\n                key={`eye${i}`}\n                ref={(node) => {\n                  eyes.current[i] = node;\n                }}\n                className={s.face}\n                d={d}\n                strokeWidth={0}\n                strokeLinejoin=\"round\"\n              />\n            ))}\n            <path\n              ref={mouthRef}\n              className={s.face}\n              d={AI_BOT_SVG.mouth}\n              strokeWidth={1.4}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n            />\n          </g>\n        </g>\n        {Array.from({ length: AI_BOT_SVG.hearts }, (_, i) => (\n          <path\n            key={i}\n            ref={(node) => {\n              hearts.current[i] = node;\n            }}\n            className={s.heart}\n            d={AI_BOT_SVG.heart}\n            opacity=\"0\"\n          />\n        ))}\n      </svg>\n    </span>\n  );\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/glow-avatar-engine.ts",
      "content": "/* ---------------------------------------------------------------- *\n * Public API\n * ---------------------------------------------------------------- */\n\nexport type AiBotEmotion =\n  | \"neutral\"\n  | \"happy\"\n  | \"love\"\n  | \"laugh\"\n  | \"surprised\"\n  | \"sad\"\n  | \"thinking\"\n  | \"sleepy\"\n  | \"wink\";\nexport type AiBotMotion = \"jump\" | \"spin\" | \"bounce\" | \"wiggle\" | \"float\";\nexport type AiBotActivity = \"idle\" | \"speaking\" | \"listening\";\nexport type AiBotShape = \"pebble\" | \"circle\" | \"squircle\" | \"flower\" | \"blob\";\n\nexport const AI_BOT_EMOTIONS: AiBotEmotion[] = [\n  \"neutral\",\n  \"laugh\",\n  \"surprised\",\n  \"wink\",\n  \"happy\",\n  \"thinking\",\n  \"love\",\n  \"sad\",\n  \"sleepy\",\n];\nexport const AI_BOT_MOTIONS: AiBotMotion[] = [\"jump\", \"spin\", \"bounce\", \"float\", \"wiggle\"];\nexport const AI_BOT_SHAPES: AiBotShape[] = [\"pebble\", \"circle\", \"squircle\", \"flower\", \"blob\"];\n\n/* ---------------------------------------------------------------- *\n * Geometry (body in viewBox -16 -16 32 32)\n * ---------------------------------------------------------------- */\n\nconst R0 = 13.4;\nconst POINTS = 96;\nconst EYES = [-3.2, 3.2];\nconst EYE_Y = -2.6;\nconst EYE_W = 2.4;\nconst EYE_H = 5.4;\nconst MOUTH_Y = 4.4;\nconst MORPH_MS = 380;\nconst GROUND_Y = R0 + 0.5;\nconst HEARTS = 4;\nconst HEART_EVERY = 2800;\nconst HEART_LIFE = 2200;\nconst HEART =\n  \"M0 1C-0.6 0.55-1.3 0.1-1.3-0.45C-1.3-0.95-0.9-1.2-0.55-1.2C-0.25-1.2-0.05-1 0-0.8C0.05-1 0.25-1.2 0.55-1.2C0.9-1.2 1.3-0.95 1.3-0.45C1.3 0.1 0.6 0.55 0 1Z\";\n\nconst smoothstep = (t: number) => t * t * (3 - 2 * t);\nconst clamp01 = (t: number) => Math.min(1, Math.max(0, t));\nconst easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);\nconst easeOut = (t: number) => 1 - (1 - t) ** 3;\n/** A half-sine from `a` to `b`, zero outside. */\nconst bump = (t: number, a: number, b: number) => (t <= a || t >= b ? 0 : Math.sin((Math.PI * (t - a)) / (b - a)));\n/** Eases in over a→b, holds, eases out over c→d. */\nconst hold = (t: number, a: number, b: number, c: number, d: number) =>\n  t <= a || t >= d ? 0 : t < b ? smoothstep((t - a) / (b - a)) : t <= c ? 1 : 1 - smoothstep((t - c) / (d - c));\n/** Stable pseudo-random 0–1 per integer, so each repeat of a cycle varies but never jitters. */\nconst hash = (n: number) => {\n  const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;\n  return x - Math.floor(x);\n};\n\n/** Radius at angle `th` as a multiple of R0. Every shape samples the same angles, so any two can blend. */\nfunction radius(shape: AiBotShape, th: number, t: number, level: number) {\n  const c = Math.cos;\n  switch (shape) {\n    case \"circle\":\n      return 0.97 + (0.012 + level * 0.03) * c(3 * th + t * 0.5) + 0.008 * c(5 * th - t * 0.6);\n    case \"squircle\": {\n      const x = Math.abs(c(th));\n      const y = Math.abs(Math.sin(th));\n      return 0.9 / (x ** 4 + y ** 4) ** 0.25 + (0.008 + level * 0.02) * c(4 * th + t * 0.6);\n    }\n    case \"flower\":\n      return 0.95 + (0.075 + level * 0.03) * c(8 * th) + 0.012 * c(3 * th + t * 0.6);\n    case \"blob\":\n      // The two-lobe term stretches the body into an oval, so it stays small to keep the blob from going thin.\n      // The three-lobe phase only sways around tip-up: past ±60° the triangle stands on its tip.\n      return (\n        0.97 +\n        (0.05 + level * 0.025) * c(3 * th + 1.5 * Math.PI + 0.75 * Math.sin(t * 0.3) + 0.25 * Math.sin(t * 0.71)) +\n        (0.022 + level * 0.012) * c(2 * th - t * 0.36) +\n        0.01 * c(5 * th + t * 0.5)\n      );\n    default:\n      // The five-lobe phase only sways around corner-up, so two corners always rest on the floor; past ±36° one would.\n      return (\n        1 +\n        (0.038 + level * 0.03) * c(5 * th + 0.5 * Math.PI + 0.75 * Math.sin(t * 0.27) + 0.25 * Math.sin(t * 0.63)) +\n        (0.02 + level * 0.02) * c(3 * th + t * 0.45) +\n        0.01 * c(7 * th - t * 0.6)\n      );\n  }\n}\n\nfunction bodyPath(r: Float32Array) {\n  let d = \"\";\n  for (let i = 0; i < POINTS; i++) {\n    const th = (i / POINTS) * Math.PI * 2;\n    const k = r[i] * R0;\n    d += `${i ? \"L\" : \"M\"}${(k * Math.cos(th)).toFixed(2)} ${(k * Math.sin(th)).toFixed(2)}`;\n  }\n  return `${d}Z`;\n}\n\nconst ROUND_BODY = bodyPath(new Float32Array(POINTS).fill(1));\n\n/**\n * An upright oval (squashed by `open`) that blends into a laughing crescent as `laugh` goes to 1.\n * `lidL` / `lidR` lower the top of the eye on that side, like a heavy or drooping eyelid.\n */\nfunction eyePath(x: number, y: number, open: number, laugh: number, scale: number, lidL: number, lidR: number) {\n  const a = (EYE_W / 2) * scale;\n  const b = Math.max(0.35, (EYE_H / 2) * open * scale) * (4 / 3);\n  const oval = [x - a, y, x - a, y - b * (1 - lidL), x + a, y - b * (1 - lidR), x + a, y, x + a, y + b, x - a, y + b];\n  const cy = y + 0.4;\n  const happy = [x - 1.7, cy + 1, x - 1.5, cy - 1.6, x + 1.5, cy - 1.6, x + 1.7, cy + 1, x + 1.1, cy - 0.3, x - 1.1, cy - 0.3];\n  const p = oval.map((v, i) => (v + (happy[i] - v) * laugh).toFixed(2));\n  return `M${p[0]} ${p[1]}C${p[2]} ${p[3]} ${p[4]} ${p[5]} ${p[6]} ${p[7]}C${p[8]} ${p[9]} ${p[10]} ${p[11]} ${p[0]} ${p[1]}Z`;\n}\n\n/**\n * Closed, a stroke curved by `smile` (-1 frown, 1 grin); open, the lips part into a filled mouth.\n * `skew` lifts the right corner and drops the left, for a smirk or a pursed, thinking mouth.\n * `taper` fills the closed mouth into a crescent, full in the middle and thin at the corners.\n */\nfunction mouthPath(cx: number, cy: number, open: number, smile: number, width: number, skew: number, taper = 0) {\n  const w = (2 + smile * 0.8 - open * 0.3) * width;\n  const ends = cy - smile * 0.4;\n  // A frown needs a deeper arch than a smile to read at icon sizes.\n  const curve = cy + 0.4 + smile * (smile < 0 ? 2.4 : 1.6);\n  const low = curve + open * 1.8 + taper;\n  const up = curve - open * 2.4 - taper;\n  const f = (n: number) => n.toFixed(2);\n  const l = ends + skew;\n  const r = ends - skew;\n  return `M${f(cx - w)} ${f(l)}Q${f(cx)} ${f(low)} ${f(cx + w)} ${f(r)}Q${f(cx)} ${f(up)} ${f(cx - w)} ${f(l)}Z`;\n}\n\n/* ---------------------------------------------------------------- *\n * Expressions: the resting face of each feeling\n * ---------------------------------------------------------------- */\n\ninterface Expression {\n  openL: number;\n  openR: number;\n  laughL: number;\n  laughR: number;\n  eyeScale: number;\n  eyeY: number;\n  /** Both upper lids lowered (tired, unimpressed). */\n  heavy: number;\n  /** Outer upper lids lowered (sad). */\n  droop: number;\n  smile: number;\n  mouth: number;\n  mouthW: number;\n  mouthX: number;\n  skew: number;\n  /** Closed lips drawn as a crescent that thins out toward the corners. */\n  taper: number;\n  blush: number;\n  /** Where the eyes rest; NaN leaves the gaze to the idle script. */\n  gazeX: number;\n  gazeY: number;\n  wobble: number;\n  bob: number;\n  tilt: number;\n  spin: number;\n}\n\nconst BASE: Expression = {\n  openL: 1,\n  openR: 1,\n  laughL: 0,\n  laughR: 0,\n  eyeScale: 1,\n  eyeY: 0,\n  heavy: 0,\n  droop: 0,\n  smile: 0.4,\n  mouth: 0,\n  mouthW: 1,\n  mouthX: 0,\n  skew: 0,\n  taper: 0,\n  blush: 0,\n  gazeX: Number.NaN,\n  gazeY: Number.NaN,\n  wobble: 0,\n  bob: 0,\n  tilt: 0,\n  spin: 1,\n};\n\nconst EXPRESSIONS: Record<AiBotEmotion, Expression> = {\n  neutral: BASE,\n  // Real smiles reach the eyes: the cheeks push the lower lids up into a soft curve.\n  happy: { ...BASE, openL: 0.9, openR: 0.9, laughL: 0.45, laughR: 0.45, smile: 1, wobble: 0.15, bob: -0.3 },\n  // Lovestruck: soft, half-melted eyes drifting up and to the left, daydreaming, a full smile and flushed cheeks.\n  love: {\n    ...BASE,\n    openL: 0.88,\n    openR: 0.88,\n    laughL: 0.55,\n    laughR: 0.55,\n    eyeScale: 1.03,\n    smile: 1,\n    mouthW: 0.9,\n    blush: 1,\n    gazeX: -0.6,\n    gazeY: -0.7,\n    wobble: 0.12,\n    bob: -0.2,\n    tilt: -3,\n    spin: 0.7,\n  },\n  laugh: { ...BASE, openL: 0.9, openR: 0.9, laughL: 0.5, laughR: 0.5, smile: 1, mouth: 0.1, wobble: 0.3, spin: 1.4 },\n  surprised: {\n    ...BASE,\n    openL: 1.03,\n    openR: 1.03,\n    eyeScale: 1.07,\n    eyeY: -0.5,\n    smile: 0,\n    mouth: 1,\n    mouthW: 0.95,\n    wobble: 0.12,\n    bob: -0.6,\n  },\n  sad: {\n    ...BASE,\n    openL: 0.75,\n    openR: 0.75,\n    eyeScale: 0.92,\n    droop: 0.85,\n    eyeY: 0.5,\n    smile: -1,\n    mouthW: 1.75,\n    gazeX: 0,\n    gazeY: 0.75,\n    bob: 0.8,\n    tilt: -4,\n    spin: 0.35,\n  },\n  thinking: {\n    ...BASE,\n    openL: 0.95,\n    openR: 0.8,\n    heavy: 0.2,\n    smile: 0.1,\n    mouthW: 0.6,\n    mouthX: 0.9,\n    skew: 0.5,\n    tilt: 5,\n    spin: 0.6,\n  },\n  sleepy: {\n    ...BASE,\n    openL: 0.6,\n    openR: 0.6,\n    heavy: 0.65,\n    eyeY: 0.5,\n    smile: -0.04,\n    mouthW: 0.8,\n    taper: 0.3,\n    gazeX: 0,\n    gazeY: 0.6,\n    bob: 0.5,\n    spin: 0.3,\n  },\n  wink: { ...BASE, smile: 0.9, skew: 0.1, tilt: 2, wobble: 0.1 },\n};\n\n/** How fast each expression settles in: surprise snaps, sadness and sleep seep in. */\nconst SETTLE: Partial<Record<AiBotEmotion, number>> = { surprised: 16, sad: 3.5, sleepy: 2.5 };\n\nconst KEYS = Object.keys(BASE) as (keyof Expression)[];\n\n/* ---------------------------------------------------------------- *\n * Acts: what a feeling does over time, on top of its resting face\n * ---------------------------------------------------------------- */\n\ninterface Act {\n  dy: number;\n  sy: number;\n  tilt: number;\n  /** Moves the whole face down, as when the head pitches forward. */\n  faceY: number;\n  scale: number;\n  openL: number;\n  openR: number;\n  laughL: number;\n  laughR: number;\n  mouth: number;\n  smile: number;\n  width: number;\n  skew: number;\n  mouthX: number;\n  yawn: number;\n  /** 0–1 lid closure on top of the natural blinks. */\n  blink: number;\n  /** Holds back natural blinks (a stare, or eyes already shut). */\n  steady: boolean;\n  gaze: readonly [number, number] | null;\n}\n\nconst still = (): Act => ({\n  dy: 0,\n  sy: 0,\n  tilt: 0,\n  faceY: 0,\n  scale: 0,\n  openL: 1,\n  openR: 1,\n  laughL: 0,\n  laughR: 0,\n  mouth: 0,\n  smile: 0,\n  width: 1,\n  skew: 0,\n  mouthX: 0,\n  yawn: 0,\n  blink: 0,\n  steady: false,\n  gaze: null,\n});\n\nconst PONDER = [\n  [0.75, -0.85],\n  [0.4, -1],\n  [-0.35, -0.85],\n] as const;\n\nfunction act(emotion: AiBotEmotion, age: number, now: number): Act {\n  const a = still();\n  switch (emotion) {\n    case \"happy\": {\n      if (age < 520) a.dy = -1.6 * Math.abs(Math.sin((Math.PI * 2 * age) / 520));\n      a.tilt = 3 * Math.sin((Math.PI * 2 * age) / 3600);\n      // Every few seconds the smile beams: cheeks lift further and the lips part.\n      const beam = hold(age % 3600, 1600, 1900, 2500, 2900);\n      a.laughL = a.laughR = 0.3 * beam;\n      a.mouth = 0.22 * beam;\n      a.dy -= 0.6 * beam;\n      break;\n    }\n    case \"love\": {\n      // A dreamy sway, and every few seconds a lovestruck sigh: the eyes melt, the chest lifts, the lips part.\n      if (age < 600) a.dy = -1.4 * bump(age, 0, 600);\n      a.tilt = 5 * Math.sin((Math.PI * 2 * age) / 4000);\n      const sigh = hold(age % 4000, 1400, 1900, 2500, 3200);\n      a.laughL = a.laughR = 0.3 * sigh;\n      a.scale += 0.05 * sigh;\n      a.sy += 0.03 * sigh;\n      a.dy -= 0.8 * sigh;\n      a.mouth += 0.1 * sigh;\n      break;\n    }\n    case \"laugh\": {\n      // Breath in, a burst of \"ha\"s that slows and fades, a few chuckles, then a breath out. Repeats, never the same.\n      const L = 5600;\n      const n = Math.floor(age / L);\n      const c = age % L;\n      const lean = hash(n) < 0.5 ? -1 : 1;\n      const inhale = bump(c, 0, 340);\n      a.dy -= 1.2 * inhale;\n      a.sy += 0.04 * inhale;\n      a.scale += 0.1 * inhale;\n      a.laughL = a.laughR = -0.5 * inhale;\n      a.mouth += 0.25 * inhale;\n      const shut = hold(c, 220, 380, 3000, 3700);\n      a.laughL += 0.5 * shut;\n      a.laughR += 0.5 * shut;\n      a.mouth += 0.25 * hold(c, 220, 400, 3400, 4400);\n      if (c > 260 && c < 2900) {\n        const q = (c - 260) / 2640;\n        const phase = 15 * q - 3 * q * q;\n        const ha = Math.abs(Math.sin(Math.PI * phase)) ** 0.8;\n        const amp = (1 - 0.7 * q) * (0.6 + 0.4 * hash(n * 17 + Math.floor(phase))) * smoothstep(Math.min(1, (c - 260) / 120));\n        a.mouth += 0.6 * ha * amp;\n        a.dy -= 1.4 * ha * amp;\n        a.sy -= 0.035 * ha * amp;\n        a.scale -= 0.1 * ha * amp;\n        a.tilt += 2.5 * ha * amp * lean;\n      } else if (c >= 2900 && c < 4300) {\n        const q = (c - 2900) / 1400;\n        const ha = Math.abs(Math.sin(Math.PI * q * 4.2));\n        const amp = 0.4 * (1 - q);\n        a.mouth += 0.4 * ha * amp;\n        a.dy -= 0.8 * ha * amp;\n      }\n      a.tilt -= 7 * lean * hold(c, 260, 600, 1800, 2900);\n      a.sy -= 0.02 * bump(c, 4300, 5300);\n      if (c > 4300) a.gaze = [0, 0];\n      a.steady = c < 3600;\n      break;\n    }\n    case \"surprised\": {\n      // Startle, freeze, a double take left and right, a disbelieving double blink, then the jaw slowly closes.\n      const startle = age < 900 ? (age < 120 ? smoothstep(age / 120) : 1 - smoothstep((age - 120) / 780)) : 0;\n      a.scale += 0.12 * startle;\n      a.dy -= 3 * bump(age, 0, 420);\n      a.sy += 0.06 * bump(age, 0, 380);\n      a.mouth += 0.3 * startle;\n      a.steady = age < 1800;\n      const g = age < 600 ? -1 : (age - 600) % 4200;\n      const left = hold(g, 300, 380, 640, 720);\n      const right = hold(g, 700, 780, 1090, 1170);\n      a.gaze = g >= 300 && g < 700 ? [-0.85, -0.1] : g >= 700 && g < 1150 ? [0.85, -0.1] : [0, 0];\n      a.tilt += -3 * left + 3 * right;\n      a.blink = Math.max(bump(g, 1700, 1850), bump(g, 1950, 2100));\n      const close = smoothstep(clamp01((age - 2600) / 900));\n      a.mouth -= 0.45 * close;\n      a.width *= 1 - 0.2 * close;\n      break;\n    }\n    case \"sad\": {\n      const c = age % 7000;\n      a.sy -= 0.045 * bump(c, 0, 1400);\n      a.dy += 0.5 * hold(c, 700, 1100, 1800, 2400);\n      // Now and then a look up, as if for comfort, then back down.\n      const up = hold(c, 3000, 3200, 3800, 4100);\n      a.gaze = [0, 0.75 - 0.9 * up];\n      a.openL = a.openR = 1 + 0.15 * up;\n      a.dy -= 0.4 * up;\n      const quiver = hold(c, 4400, 4600, 5300, 5600);\n      a.skew += 0.12 * Math.sin(now / 40) * quiver;\n      a.mouth += 0.05 * quiver;\n      a.smile -= 0.15 * quiver;\n      a.tilt += 1.5 * Math.sin(now / 2200);\n      break;\n    }\n    case \"thinking\": {\n      const c = age % 6400;\n      a.gaze = c < 1200 ? PONDER[0] : c < 2400 ? PONDER[1] : PONDER[2];\n      // \"Hmm\": the mouth slides to the other cheek and the head tips the other way.\n      const hmm = hold(c, 1200, 1500, 2100, 2400);\n      a.mouthX -= 1.8 * hmm;\n      a.skew -= hmm;\n      a.tilt -= 9 * hmm;\n      // Then it clicks: eyes open on the viewer, a smile, a little hop.\n      const idea = hold(c, 4100, 4250, 5600, 6200);\n      if (idea > 0.3) a.gaze = [0, 0];\n      a.openL *= 1 + 0.2 * idea;\n      a.openR *= 1 + 0.4 * idea;\n      a.scale += 0.08 * idea;\n      a.smile += 0.8 * idea;\n      a.mouthX -= 0.9 * idea;\n      a.skew -= 0.5 * idea;\n      a.width *= 1 + 0.5 * idea;\n      a.mouth += 0.15 * idea;\n      a.tilt -= 5 * idea;\n      a.dy -= 1.6 * bump(c, 4100, 4500);\n      a.tilt += 1.5 * Math.sin(now / 900);\n      break;\n    }\n    case \"sleepy\": {\n      // Dozes off, jolts awake, blinks it away, yawns, and starts drifting again.\n      const c = age % 9200;\n      const drift = c < 3000 ? smoothstep(c / 3000) : c < 3200 ? 1 - smoothstep((c - 3000) / 200) : 0;\n      a.openL = a.openR = 1 - 0.8 * drift;\n      a.dy += 1.6 * drift;\n      a.tilt += 6 * drift;\n      a.gaze = [0, 0.6 + 0.4 * drift];\n      const jolt = bump(c, 3000, 3350);\n      a.openL *= 1 + 0.9 * jolt;\n      a.openR *= 1 + 0.9 * jolt;\n      a.dy -= 1.4 * jolt;\n      a.scale += 0.1 * jolt;\n      if (c >= 3000 && c < 4200) a.gaze = [0, 0];\n      a.blink = Math.max(bump(c, 3550, 3780), bump(c, 3900, 4130));\n      a.yawn = hold(c, 5400, 6200, 6800, 7600);\n      a.tilt += 2 * Math.sin(now / 1700);\n      a.steady = c < 3000;\n      break;\n    }\n    case \"wink\": {\n      const c = age % 3200;\n      let w = 0;\n      if (c > 150 && c < 950) {\n        const q = (c - 150) / 800;\n        w = q < 0.2 ? smoothstep(q / 0.2) : q < 0.75 ? 1 : 1 - smoothstep((q - 0.75) / 0.25);\n      }\n      // The winking side's cheek and mouth corner lift; the other eye narrows a touch.\n      a.laughR += w;\n      a.laughL += 0.25 * w;\n      a.openL *= 1 - 0.12 * w;\n      a.skew += 0.45 * w;\n      a.smile += 0.1 * w;\n      a.tilt += 5 * w;\n      a.dy -= 0.9 * bump(c, 150, 450);\n      if (w > 0) a.gaze = [0, 0];\n      a.steady = w > 0;\n      break;\n    }\n  }\n  return a;\n}\n\n/* ---------------------------------------------------------------- *\n * Motions\n * ---------------------------------------------------------------- */\n\ninterface Pose {\n  dy: number;\n  rot: number;\n  sx: number;\n  sy: number;\n  /** Turn around the vertical axis, in degrees. The face travels around the body. */\n  yaw: number;\n  /** 0–1, how much the face lights up while moving. */\n  joy: number;\n  gaze: readonly [number, number] | null;\n}\n\nconst MOTION_MS: Record<AiBotMotion, number> = {\n  jump: 950,\n  spin: 600,\n  bounce: 1200,\n  wiggle: 800,\n  float: 2200,\n};\n\nconst FLOAT = 4.5;\n\nconst REST: Pose = { dy: 0, rot: 0, sx: 1, sy: 1, yaw: 0, joy: 0, gaze: null };\n\nfunction pose(motion: AiBotMotion, ms: number): Pose {\n  const p = clamp01(ms / MOTION_MS[motion]);\n  switch (motion) {\n    case \"jump\": {\n      if (ms < 160) {\n        const q = smoothstep(ms / 160);\n        return { ...REST, sx: 1 + 0.1 * q, sy: 1 - 0.14 * q, joy: q * 0.6 };\n      }\n      if (ms < 560) {\n        const q = (ms - 160) / 400;\n        const stretch = 0.09 * Math.abs(Math.cos(Math.PI * q));\n        return { ...REST, dy: -11 * 4 * q * (1 - q), sx: 1 - stretch * 0.6, sy: 1 + stretch, joy: 1 };\n      }\n      const r = (ms - 560) / 390;\n      const squash = 0.16 * Math.exp(-5 * r) * Math.cos(10 * r);\n      return { ...REST, sx: 1 + squash * 0.7, sy: 1 - squash, joy: 1 - smoothstep(r) };\n    }\n    case \"spin\": {\n      // Wind up the other way, turn a full circle on the spot with a small hop, settle.\n      if (ms < 90) {\n        const q = smoothstep(ms / 90);\n        return { ...REST, yaw: -30 * q, sx: 1 + 0.06 * q, sy: 1 - 0.08 * q, joy: 0.3 * q, gaze: [-0.6 * q, 0] };\n      }\n      if (ms < 440) {\n        const q = (ms - 90) / 350;\n        const hop = Math.sin(Math.PI * q) ** 2;\n        const crouch = 1 - smoothstep(Math.min(1, q * 4));\n        return {\n          ...REST,\n          yaw: -30 + 390 * easeInOut(q),\n          dy: -2.6 * hop,\n          sx: 1 + 0.06 * crouch,\n          sy: 1 - 0.08 * crouch + 0.04 * hop,\n          joy: 0.8,\n          gaze: [0.8 * hop, 0],\n        };\n      }\n      const r = (ms - 440) / 160;\n      const squash = 0.025 * Math.sin(Math.PI * r) * (1 - r);\n      return { ...REST, yaw: 360, sx: 1 + squash * 0.7, sy: 1 - squash, joy: 0.8 * (1 - r) };\n    }\n    case \"bounce\": {\n      const hop = Math.abs(Math.sin(Math.PI * 3 * p));\n      const squash = 0.08 * (1 - hop) ** 6;\n      return { ...REST, dy: -5 * hop, sx: 1 + squash * 0.8, sy: 1 - squash, joy: Math.sin(Math.PI * p) };\n    }\n    case \"wiggle\":\n      return { ...REST, rot: 14 * Math.sin(Math.PI * 8 * p) * (1 - p), joy: 0.6 * Math.sin(Math.PI * p) };\n    case \"float\": {\n      // Lifts off, hovers marvelling at the ground below, drifts back down and lands softly.\n      const down: readonly [number, number] = [0, 0.9];\n      if (ms < 520) {\n        const q = ms / 520;\n        const s = 0.05 * Math.sin(Math.PI * q);\n        return { ...REST, dy: -FLOAT * easeOut(q), sx: 1 - s * 0.6, sy: 1 + s, joy: 0.5 * q, gaze: q > 0.4 ? down : null };\n      }\n      if (ms < 1500) {\n        const h = (ms - 520) / 980;\n        return { ...REST, dy: -FLOAT + 0.8 * Math.sin(Math.PI * 3 * h), rot: 4 * Math.sin(Math.PI * 2 * h), joy: 0.5, gaze: down };\n      }\n      if (ms < 1820) {\n        const q = (ms - 1500) / 320;\n        return { ...REST, dy: -FLOAT * (1 - q * q), sx: 1 - 0.02 * q, sy: 1 + 0.04 * q, joy: 0.5, gaze: down };\n      }\n      const r = (ms - 1820) / 380;\n      const squash = 0.12 * Math.exp(-5 * r) * Math.cos(10 * r) * (1 - r);\n      return { ...REST, sx: 1 + squash * 0.7, sy: 1 - squash, joy: 0.5 * (1 - r) };\n    }\n  }\n}\n\nexport const AI_BOT_SVG = {\n  viewBox: \"-24 -24 48 48\",\n  body: ROUND_BODY,\n  eyes: EYES.map((x) => eyePath(x, EYE_Y, 1, 0, 1, 0, 0)),\n  blush: EYES.map((x) => ({ cx: x * 1.6, cy: EYE_Y + 4.6 })),\n  mouth: mouthPath(0, MOUTH_Y, 0, 0.4, 1, 0),\n  groundY: GROUND_Y,\n  heart: HEART,\n  hearts: HEARTS,\n} as const;\n\n/* ---------------------------------------------------------------- *\n * Engine: drives the SVG directly, once per frame, outside any framework render\n * ---------------------------------------------------------------- */\n\nexport interface AiBotElements {\n  svg: SVGSVGElement;\n  mover: SVGGElement;\n  bodyGroup: SVGGElement;\n  body: SVGPathElement;\n  face: SVGGElement;\n  eyes: readonly (SVGPathElement | null)[];\n  mouth: SVGPathElement;\n  ground: SVGEllipseElement;\n  core: SVGEllipseElement;\n  blush: readonly (SVGEllipseElement | null)[];\n  hearts: readonly (SVGPathElement | null)[];\n}\n\nexport interface AiBotOptions {\n  emotion?: AiBotEmotion;\n  activity?: AiBotActivity;\n  shape?: AiBotShape;\n  /** Plays once; change `motionKey` to replay the same motion. */\n  motion?: AiBotMotion | null;\n  motionKey?: number;\n  onMotionEnd?: (motion: AiBotMotion) => void;\n  /** Idle glances around the room. */\n  lookAround?: boolean;\n  /** Eyes follow the mouse pointer anywhere in the window. */\n  followCursor?: boolean;\n  /** Giggles when the pointer touches the body. */\n  hoverGiggle?: boolean;\n  /** Fires when the pointer starts a giggle. */\n  onTickle?: () => void;\n  /** Change to make the bot chuckle along softly, as if someone next to it were being tickled. */\n  chuckleKey?: number;\n}\n\nexport interface AiBot {\n  update(options: AiBotOptions): void;\n  destroy(): void;\n}\n\ninterface Config {\n  emotion: AiBotEmotion;\n  activity: AiBotActivity;\n  shape: AiBotShape;\n  lookAround: boolean;\n  followCursor: boolean;\n  hoverGiggle: boolean;\n}\n\nconst resolve = (o: AiBotOptions): Config => ({\n  emotion: o.emotion ?? \"neutral\",\n  activity: o.activity ?? \"idle\",\n  shape: o.shape ?? \"pebble\",\n  lookAround: o.lookAround ?? true,\n  followCursor: o.followCursor ?? false,\n  hoverGiggle: o.hoverGiggle ?? true,\n});\n\nexport function createAiBot(els: AiBotElements, options: AiBotOptions = {}): AiBot {\n  const state: {\n    config: Config;\n    playing: { name: AiBotMotion; start: number } | null;\n    morph: { from: Float32Array; start: number } | null;\n    onMotionEnd?: (motion: AiBotMotion) => void;\n    onTickle?: () => void;\n    tickledAt: number;\n    chuckledAt: number;\n  } = {\n    config: resolve(options),\n    playing: options.motion ? { name: options.motion, start: performance.now() } : null,\n    morph: null,\n    onMotionEnd: options.onMotionEnd,\n    onTickle: options.onTickle,\n    tickledAt: -Infinity,\n    chuckledAt: -Infinity,\n  };\n  const radii = new Float32Array(POINTS).fill(1);\n  let shown = state.config.shape;\n  let motionNow = options.motion ?? null;\n  let motionKeyNow = options.motionKey ?? 0;\n  let heard = options.chuckleKey ?? 0;\n\n  const onEnter = () => {\n    const now = performance.now();\n    if (state.config.hoverGiggle && now - state.tickledAt > 1300) {\n      state.tickledAt = now;\n      state.onTickle?.();\n    }\n  };\n  els.mover.addEventListener(\"pointerenter\", onEnter);\n\n  const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  let pointer: { x: number; y: number } | null = null;\n  const onMove = (e: PointerEvent) => {\n    pointer = e.pointerType === \"mouse\" ? { x: e.clientX, y: e.clientY } : null;\n  };\n  const onLeave = () => {\n    pointer = null;\n  };\n  window.addEventListener(\"pointermove\", onMove, { passive: true });\n  document.documentElement.addEventListener(\"pointerleave\", onLeave);\n\n  const cur: Expression = { ...EXPRESSIONS[state.config.emotion] };\n  // Each instance starts somewhere else in its wobble, turn and breath, so neighbours never move in lockstep.\n  const phase = Math.random() * 1000;\n  let raf = 0;\n  let last = performance.now();\n  let gx = 0;\n  let gy = 0;\n  let tx = 0;\n  let ty = 0;\n  let nextGaze = last + 600 + Math.random() * 1800;\n  let blinkAt = last + 800 + Math.random() * 2600;\n  let blinkStart = -1;\n  let second = false;\n  let grinAt = -Infinity;\n  let mgx = 0;\n  let mgy = 0;\n  let nextGrin = last + 4000 + Math.random() * 4000;\n  let spin = Math.random() * 360;\n  let seat = R0;\n  let footX = 0;\n  let footW = 7;\n  let level = 0;\n  let jaw = 0;\n  let syllable = 0;\n  let syllableRate = 5.5;\n  let syllableAmp = 1;\n  let vowel = 1;\n  // Scripted speech: words of a few syllables, short gaps, and a longer breath every few words.\n  let wordEnds = 0;\n  let gapEnds = 0;\n  let wordsLeft = 6;\n  let pausing = false;\n  let stressAt = -Infinity;\n  let nextNod = last + 900;\n  let nodStart = -Infinity;\n  let nods = 0;\n  // Null until the first frame, so the starting emotion gets a finite age like any later change.\n  let felt: AiBotEmotion | null = null;\n  let feltAt = last;\n  let lovedFrom = -Infinity;\n  let lovedUntil = -Infinity;\n\n  const frame = (now: number) => {\n    const dt = Math.min(0.064, (now - last) / 1000);\n    last = now;\n    const t = reduce ? 0 : now / 1000 + phase;\n    const cfg = state.config;\n    if (cfg.emotion !== felt) {\n      if (felt === \"love\") lovedUntil = now;\n      felt = cfg.emotion;\n      feltAt = now;\n      if (felt === \"love\") {\n        lovedFrom = now;\n        lovedUntil = Infinity;\n      }\n    }\n    const age = now - feltAt;\n    const target = EXPRESSIONS[felt];\n    const k = Math.min(1, dt * (SETTLE[felt] ?? 8));\n    for (const key of KEYS) {\n      const goal = target[key];\n      if (Number.isNaN(goal)) cur[key] = Number.NaN;\n      else if (Number.isNaN(cur[key])) cur[key] = goal;\n      else cur[key] += (goal - cur[key]) * k;\n    }\n    const a = reduce ? still() : act(felt, age, now);\n\n    // Activity drives the signal level and, while speaking, the jaw.\n    let levelTarget = 0;\n    let talkTarget = 0;\n    if (cfg.activity === \"speaking\") {\n      if (now > gapEnds && now > wordEnds) {\n        wordEnds = now + 160 + Math.random() * 260;\n        wordsLeft -= 1;\n        pausing = wordsLeft <= 0;\n        gapEnds = wordEnds + (pausing ? 520 + Math.random() * 420 : 60 + Math.random() * 120);\n        if (pausing) wordsLeft = 4 + Math.floor(Math.random() * 5);\n        if (Math.random() < 0.3) stressAt = now;\n      }\n      const inWord = now < wordEnds;\n      levelTarget = inWord ? 0.55 + 0.35 * Math.abs(Math.sin(now / 70)) : 0;\n      if (inWord) {\n        syllable += dt * syllableRate * Math.PI * 2;\n        if (syllable >= Math.PI * 2) {\n          syllable -= Math.PI * 2;\n          syllableRate = 4.6 + Math.random() * 2;\n          syllableAmp = Math.random() < 0.18 ? 0.12 : 0.55 + Math.random() * 0.45;\n          // Wide vowels stretch the mouth, round ones (o, u) purse it.\n          vowel = Math.random() < 0.4 ? 0.62 + Math.random() * 0.12 : 1 + Math.random() * 0.2;\n        }\n        talkTarget = Math.min(1, (0.35 + level) * syllableAmp * (0.5 - 0.5 * Math.cos(syllable)));\n      } else {\n        syllable = 0;\n      }\n      // Stressed words get a small head bob and brighter eyes.\n      const stress = bump(now - stressAt, 0, 280);\n      a.dy -= 0.7 * stress;\n      a.scale += 0.06 * stress;\n    } else if (cfg.activity === \"listening\") {\n      levelTarget = 0.18 + 0.14 * Math.sin(now / 240) * Math.sin(now / 610);\n    }\n    level += (levelTarget - level) * Math.min(1, dt * 12);\n    jaw += (talkTarget - jaw) * Math.min(1, dt * (talkTarget > jaw ? 30 : 20));\n\n    let move = REST;\n    const play = state.playing;\n    if (play && !reduce) {\n      const ms = now - play.start;\n      if (ms >= MOTION_MS[play.name]) {\n        state.playing = null;\n        state.onMotionEnd?.(play.name);\n      } else {\n        move = pose(play.name, ms);\n      }\n    }\n\n    // Listeners nod along: a double \"mhm\" nod, and every third time an interested \"oh?\" instead.\n    const listening = cfg.activity === \"listening\" ? 1 : 0;\n    if (listening && !play && now > nextNod) {\n      nodStart = now;\n      nods += 1;\n      nextNod = now + 2400 + Math.random() * 1800;\n    }\n    if (listening && !reduce) {\n      const n = now - nodStart;\n      if (nods % 3 === 0) {\n        const oh = hold(n, 0, 160, 700, 1000);\n        a.scale += 0.08 * oh;\n        a.faceY -= 0.6 * oh;\n        a.mouth += 0.18 * oh;\n        a.smile -= 0.3 * oh;\n        a.dy -= 0.5 * oh;\n      } else {\n        const dip = bump(n, 0, 300) + 0.7 * bump(n, 340, 640);\n        a.dy += 1.6 * dip;\n        a.faceY += 1.2 * dip;\n        a.sy -= 0.02 * dip;\n        a.openL *= 1 - 0.15 * dip;\n        a.openR *= 1 - 0.15 * dip;\n        a.smile += 0.1 * dip;\n      }\n      a.tilt += 4 + 1.5 * Math.sin(now / 2600);\n    }\n\n    // Gaze: the cursor wins, then a motion or act, then an expression's resting point, then the idle script.\n    let watching = false;\n    const box = cfg.followCursor && pointer ? els.svg.getBoundingClientRect() : undefined;\n    if (pointer && box && box.width > 0) {\n      const dx = pointer.x - (box.left + box.width / 2);\n      const dy = pointer.y - (box.top + box.height / 2);\n      // Soft falloff: the pupils travel fast near the face and ease toward the rim far away.\n      const reach = box.width * 0.9;\n      watching = true;\n      tx = dx / (Math.abs(dx) + reach);\n      ty = dy / (Math.abs(dy) + reach);\n      nextGaze = now + 700;\n    }\n    const scripted = move.gaze ?? a.gaze;\n    if (!watching) {\n      if (scripted) {\n        tx = scripted[0];\n        ty = scripted[1];\n      } else if (!Number.isNaN(cur.gazeX)) {\n        tx = cur.gazeX;\n        ty = cur.gazeY;\n      } else if (now > nextGaze) {\n        if (cfg.activity === \"listening\") {\n          tx = (Math.random() - 0.5) * 0.3;\n          ty = -0.05 + (Math.random() - 0.5) * 0.15;\n        } else if (cfg.activity === \"speaking\") {\n          // Speakers look away while they gather the next sentence, and back for the words.\n          tx = pausing ? (Math.random() < 0.5 ? -0.7 : 0.7) : (Math.random() - 0.5) * 0.5;\n          ty = pausing ? -0.5 : (Math.random() - 0.5) * 0.3;\n        } else if (cfg.lookAround) {\n          tx = [-1, -0.6, 0, 0, 0.6, 1][Math.floor(Math.random() * 6)];\n          ty = (Math.random() - 0.5) * 1.2;\n        } else {\n          tx = 0;\n          ty = 0;\n        }\n        nextGaze = now + (cfg.activity === \"speaking\" ? 500 + Math.random() * 900 : 900 + Math.random() * 2300);\n      }\n    }\n    // Eyes jump between points (saccades) rather than drifting.\n    const ease = Math.min(1, dt * (watching ? 14 : 16));\n    gx += (tx - gx) * ease;\n    gy += (ty - gy) * ease;\n    // The mouth rides on the face, which turns after the eyes and more softly.\n    const lag = Math.min(1, dt * 5);\n    mgx += (gx - mgx) * lag;\n    mgy += (gy - mgy) * lag;\n\n    // Blinks, with the odd double blink. Tired and sad eyes close slowly.\n    if (a.steady && blinkStart < 0) blinkAt = Math.max(blinkAt, now + 400);\n    if (blinkStart < 0 && now > blinkAt) blinkStart = now;\n    let blink = 1;\n    if (blinkStart >= 0) {\n      const p = (now - blinkStart) / (felt === \"sleepy\" ? 460 : felt === \"sad\" ? 280 : 170);\n      if (p >= 1) {\n        blinkStart = -1;\n        if (!second && Math.random() < 0.22) {\n          second = true;\n          blinkAt = now + 90;\n        } else {\n          second = false;\n          blinkAt = now + 2000 + Math.random() * 3200;\n        }\n      } else {\n        blink = 1 - Math.sin(p * Math.PI) * 0.88;\n      }\n    }\n    blink *= 1 - a.blink * 0.9;\n\n    // A short giggle per hover.\n    const since = now - state.tickledAt;\n    let tickle = 0;\n    let wiggle = 0;\n    if (cfg.hoverGiggle && since < 1300) {\n      tickle = since < 180 ? smoothstep(since / 180) : since < 800 ? 1 : 1 - smoothstep((since - 800) / 500);\n      wiggle = Math.sin(since / 42) * Math.max(0, 1 - since / 520);\n    }\n    // Chuckling along is a softer, longer, wiggle-free version of the giggle.\n    const heardFor = now - state.chuckledAt;\n    const amused = heardFor > 0 && heardFor < 1700 ? 0.45 * hold(heardFor, 0, 260, 1000, 1700) : 0;\n    tickle = Math.max(tickle, amused);\n\n    // The occasional grin, only when nothing else is going on.\n    if (felt === \"neutral\" && cfg.activity === \"idle\" && now > nextGrin) {\n      grinAt = now;\n      nextGrin = now + 5000 + Math.random() * 6000;\n    }\n    const grinning = felt === \"neutral\" ? hold(now - grinAt, 0, 380, 1100, 1600) : 0;\n\n    const sleepy = felt === \"sleepy\" ? 1 : 0;\n    const yawn = a.yawn;\n    const shapeNow = cfg.shape;\n\n    // Body.\n    const wob = cur.wobble + level * 0.6 + tickle * 0.25;\n    const snap = shapeNow === \"squircle\" ? 90 : shapeNow === \"blob\" ? 120 : shapeNow === \"pebble\" ? 72 : 0;\n    const rate = snap ? 0 : 3.5 + level * 18;\n    spin = reduce ? spin : (spin + dt * rate * cur.spin) % 360;\n    if (snap) spin += (Math.round(spin / snap) * snap - spin) * Math.min(1, dt * 4);\n    const m = state.morph;\n    const mix = m ? smoothstep(clamp01((now - m.start) / MORPH_MS)) : 1;\n    // The outline turns, not the fill, so the highlight stays top-left.\n    const turn = (spin * Math.PI) / 180;\n    const r = radii;\n    for (let i = 0; i < POINTS; i++) {\n      const live = radius(shapeNow, (i / POINTS) * Math.PI * 2 - turn, t, wob);\n      r[i] = m && mix < 1 ? m.from[i] + (live - m.from[i]) * mix : live;\n    }\n    if (m && mix >= 1) state.morph = null;\n    const breathe = reduce ? 0 : sleepy ? 0.03 * Math.sin(t / 1.1) : 0.015 * Math.sin(t / 0.9);\n    const swell = 1 + breathe + level * 0.04;\n    els.body.setAttribute(\"d\", bodyPath(r));\n    els.bodyGroup.setAttribute(\"transform\", `scale(${swell.toFixed(4)})`);\n\n    const yaw = (move.yaw * Math.PI) / 180;\n    const bob = cur.bob + sleepy * 0.4 * Math.sin(now / 1100) - tickle * 0.5 + jaw * 0.25 - yawn * 0.5;\n    const rot = cur.tilt + a.tilt + wiggle * 4 + move.rot;\n    const dy = move.dy + bob + a.dy;\n    // The floor is solid: rising lifts the body, sinking slumps it (flatter and a little wider) instead.\n    const rise = Math.min(0, dy);\n    const slump = (0.7 * Math.max(0, dy)) / (2 * R0);\n    const sy = move.sy * (1 + a.sy + yawn * 0.03) * (1 - slump);\n    const sx = move.sx * (1 - (a.sy + yawn * 0.03) * 0.5) * (1 - 0.04 * Math.abs(Math.sin(yaw))) * (1 + slump * 0.5);\n\n    // Find where the tilted outline actually touches down, and how wide that patch is.\n    const tilt = (rot * Math.PI) / 180;\n    let low = 0;\n    for (let i = 0; i < POINTS; i++) low = Math.max(low, r[i] * Math.sin((i / POINTS) * Math.PI * 2 + tilt));\n    low *= R0 * swell;\n    let left = Infinity;\n    let right = -Infinity;\n    for (let i = 0; i < POINTS; i++) {\n      const th = (i / POINTS) * Math.PI * 2 + tilt;\n      const k = r[i] * R0 * swell;\n      if (k * Math.sin(th) < low - 2.2) continue;\n      left = Math.min(left, k * Math.cos(th));\n      right = Math.max(right, k * Math.cos(th));\n    }\n    seat += (low - seat) * Math.min(1, dt * 12);\n    els.mover.setAttribute(\n      \"transform\",\n      `translate(0 ${rise.toFixed(2)}) translate(0 ${R0}) scale(${sx.toFixed(4)} ${sy.toFixed(4)}) translate(0 ${(-seat).toFixed(2)}) rotate(${rot.toFixed(2)})`,\n    );\n    // A contact shadow: a dense core under the patch that touches, inside a soft penumbra. Lifting off\n    // dissolves the core first while the penumbra spreads and pales; a wider footprint widens both.\n    const height = clamp01(-rise / 10);\n    const foot = ((right - left) / 2) * sx;\n    const under = ((left + right) / 2) * sx;\n    footX += (under - footX) * Math.min(1, dt * 12);\n    footW += (foot - footW) * Math.min(1, dt * 12);\n    const ground = els.ground;\n    if (ground) {\n      ground.setAttribute(\"cx\", (footX * (1 - height)).toFixed(2));\n      ground.setAttribute(\"rx\", ((footW + 3.2) * (1 + 0.25 * height)).toFixed(2));\n      ground.setAttribute(\"ry\", (2 * (1 + 0.2 * height)).toFixed(2));\n      ground.setAttribute(\"opacity\", ((1 - 0.65 * height) * (0.9 + 2 * slump)).toFixed(3));\n    }\n    const core = els.core;\n    if (core) {\n      core.setAttribute(\"cx\", footX.toFixed(2));\n      core.setAttribute(\"rx\", (footW * 0.95 * (1 - 0.4 * height)).toFixed(2));\n      core.setAttribute(\"ry\", (0.85 * (1 - 0.3 * height)).toFixed(2));\n      core.setAttribute(\"opacity\", ((1 - height) ** 2 * (0.9 + 3 * slump)).toFixed(3));\n    }\n\n    // The face sits on the front of a sphere: turning slides it across and foreshortens it, then hides it behind.\n    const face = els.face;\n    if (face) {\n      const front = Math.cos(yaw);\n      face.setAttribute(\n        \"transform\",\n        `translate(${(Math.sin(yaw) * R0 * 0.72).toFixed(2)} 0) scale(${Math.max(0.001, Math.abs(front)).toFixed(3)} 1)`,\n      );\n      face.setAttribute(\"opacity\", smoothstep(clamp01((front + 0.1) / 0.35)).toFixed(3));\n    }\n\n    // Hearts drift up past the cheeks, alternating sides; leaving love fades them out fast so they never carry over.\n    const gone = 1 - smoothstep(clamp01((now - lovedUntil) / 200));\n    els.hearts.forEach((heart, i) => {\n      if (!heart) return;\n      const since = now - lovedFrom - 250 - i * (HEART_EVERY / HEARTS);\n      const n = Math.floor(since / HEART_EVERY);\n      const p = (since - n * HEART_EVERY) / HEART_LIFE;\n      const born = lovedFrom + 250 + i * (HEART_EVERY / HEARTS) + n * HEART_EVERY;\n      if (reduce || !(since >= 0 && since < Infinity) || p >= 1 || born > lovedUntil || gone <= 0) {\n        heart.setAttribute(\"opacity\", \"0\");\n        return;\n      }\n      const side = (i + n) % 2 ? 1 : -1;\n      const seed = hash(n * HEARTS + i);\n      const x = side * (12 + 1.5 * seed + 2 * p) + 0.9 * Math.sin(Math.PI * 2 * (1.1 * p + seed));\n      const y = rise - 4 - seed * 2 - 14 * easeOut(p);\n      const grow = (0.75 + 0.35 * seed) * (0.5 + 0.5 * smoothstep(clamp01(p / 0.18)));\n      const sway = side * 10 + 14 * Math.sin(Math.PI * 2 * (0.9 * p + seed));\n      heart.setAttribute(\n        \"transform\",\n        `translate(${x.toFixed(2)} ${y.toFixed(2)}) rotate(${sway.toFixed(1)}) scale(${grow.toFixed(3)})`,\n      );\n      heart.setAttribute(\n        \"opacity\",\n        (gone * smoothstep(clamp01(p / 0.12)) * (1 - smoothstep(clamp01((p - 0.55) / 0.45)))).toFixed(3),\n      );\n    });\n\n    // Face.\n    const joy = Math.max(move.joy, grinning);\n    const look = 1 - tickle;\n    const base = Math.min(1, cur.smile + a.smile + (1 - cur.smile) * joy + listening * 0.15);\n    const smile = Math.max(-1, (base + (1 - base) * tickle) * (1 - yawn));\n    const squint = 1 - 0.18 * Math.max(0, (smile - 0.6) / 0.4);\n    const opens = [cur.openL * a.openL, cur.openR * a.openR];\n    const laughs = [cur.laughL + a.laughL, cur.laughR + a.laughR];\n    els.eyes.forEach((eye, i) => {\n      if (!eye) return;\n      const x = EYES[i] + gx * 1.8 * look;\n      const y = EYE_Y + cur.eyeY + a.faceY + gy * 1.1 * look;\n      const curl = clamp01(Math.max(laughs[i], tickle, move.joy * 0.8));\n      const outer = Math.min(0.9, cur.heavy + cur.droop);\n      const inner = Math.min(0.9, cur.heavy);\n      const open = opens[i] * blink * squint * (1 - yawn * 0.85);\n      eye.setAttribute(\n        \"d\",\n        eyePath(x, y, open, curl, cur.eyeScale + a.scale + listening * 0.04, i === 0 ? outer : inner, i === 0 ? inner : outer),\n      );\n      eye.setAttribute(\"stroke-width\", (curl * 0.7).toFixed(2));\n      const cheek = els.blush[i];\n      if (cheek) {\n        cheek.setAttribute(\"cx\", (EYES[i] * 1.6 + gx * 1.2 * look).toFixed(2));\n        cheek.setAttribute(\"cy\", (EYE_Y + 4.6 + a.faceY + gy * 0.7 * look).toFixed(2));\n        cheek.setAttribute(\"opacity\", clamp01(cur.blush).toFixed(3));\n      }\n    });\n    const giggle = tickle * (0.3 + 0.25 * Math.abs(Math.sin(now / 85)));\n    const mouthW = cur.mouthW * a.width * (1 + (vowel - 1) * jaw) * (1 - yawn * 0.1);\n    const lip = clamp01(-smile + cur.taper * (1 - yawn));\n    const mouth = els.mouth;\n    if (mouth) {\n      mouth.setAttribute(\n        \"d\",\n        mouthPath(\n          (cur.mouthX + a.mouthX) * (1 - yawn) + mgx * 1.2 * look,\n          MOUTH_Y + cur.eyeY * 0.5 + a.faceY + mgy * 0.6 * look,\n          Math.max(0, cur.mouth + a.mouth, jaw, giggle, move.joy * 0.35, yawn * 2.1),\n          smile,\n          mouthW,\n          (cur.skew + a.skew) * (1 - yawn),\n          0.9 * lip,\n        ),\n      );\n      // Short mouths get a finer line so they stay a line, not a dot.\n      const fine = Math.min(1, 0.55 + 0.45 * mouthW);\n      mouth.setAttribute(\"stroke-width\", (1.4 * fine * (1 - 0.6 * lip)).toFixed(2));\n    }\n\n    raf = requestAnimationFrame(frame);\n  };\n\n  raf = requestAnimationFrame(frame);\n  const stop = () => {\n    cancelAnimationFrame(raf);\n    window.removeEventListener(\"pointermove\", onMove);\n    document.documentElement.removeEventListener(\"pointerleave\", onLeave);\n  };\n\n  return {\n    update(next) {\n      state.config = resolve(next);\n      state.onMotionEnd = next.onMotionEnd;\n      state.onTickle = next.onTickle;\n      if (state.config.shape !== shown) {\n        shown = state.config.shape;\n        state.morph = { from: radii.slice(), start: performance.now() };\n      }\n      const motion = next.motion ?? null;\n      const key = next.motionKey ?? 0;\n      if (motion !== motionNow || key !== motionKeyNow) {\n        motionNow = motion;\n        motionKeyNow = key;\n        state.playing = motion ? { name: motion, start: performance.now() } : null;\n      }\n      const chuckle = next.chuckleKey ?? 0;\n      if (chuckle !== heard) {\n        heard = chuckle;\n        // A beat of reaction time before it catches on.\n        state.chuckledAt = performance.now() + 140 + Math.random() * 160;\n      }\n    },\n    destroy() {\n      stop();\n      els.mover.removeEventListener(\"pointerenter\", onEnter);\n    },\n  };\n}\n",
      "type": "registry:lib"
    },
    {
      "path": "components/ui/glow-avatar.module.css",
      "content": ".root {\n  --bot-1: color-mix(in oklch, var(--glow, oklch(0.72 0.18 45)) 82%, white);\n  --bot-2: color-mix(in oklch, var(--glow, oklch(0.72 0.18 45)) 68%, black);\n  --bot-face: var(--background, #faf9f7);\n  --bot-ground: color-mix(in oklch, var(--foreground, #171717) 7%, transparent);\n  --bot-ground-core: color-mix(in oklch, var(--foreground, #171717) 12%, transparent);\n  --bot-heart: var(--glow-2, var(--glow, oklch(0.72 0.18 45)));\n  --bot-blush: color-mix(in oklch, var(--glow-2, var(--glow, oklch(0.72 0.18 45))) 48%, transparent);\n\n  position: relative;\n  display: inline-block;\n  flex: none;\n  width: var(--bot-size, 120px);\n  height: var(--bot-size, 120px);\n  vertical-align: middle;\n}\n\n/* The drawing is half again the body's size, so jumps and squashes have room to spill. */\n.svg {\n  position: absolute;\n  inset: -25%;\n  display: block;\n  width: 150%;\n  height: 150%;\n  overflow: visible;\n}\n\n.stop1,\n.stop2 {\n  transition: stop-color 450ms ease;\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .stop1,\n  .stop2 {\n    transition: none;\n  }\n}\n\n.stop1 {\n  stop-color: var(--bot-1);\n}\n\n.stop2 {\n  stop-color: var(--bot-2);\n}\n\n.face {\n  fill: var(--bot-face);\n  stroke: var(--bot-face);\n}\n\n.ground {\n  fill: var(--bot-ground);\n}\n\n.core {\n  fill: var(--bot-ground-core);\n}\n\n.blush {\n  fill: var(--bot-blush);\n}\n\n.heart {\n  fill: var(--bot-heart);\n}\n",
      "type": "registry:file",
      "target": "components/ui/glow-avatar.module.css"
    }
  ],
  "cssVars": {
    "theme": {
      "color-glow": "var(--glow)",
      "color-glow-2": "var(--glow-2)"
    }
  },
  "type": "registry:ui"
}