{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prism-light",
  "type": "registry:component",
  "title": "Prism Light",
  "description": "A real 3D scene in WebGL2: a glass prism (beveled mesh with fresnel and refraction) on a reflective vinyl floor. A light orb follows your cursor and fires a volumetric beam; the spectrum fans out by Snell's law, one ray per color, and lands on the wall and floor with its caustic. The camera parallaxes with the cursor.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Backgrounds"
  ],
  "docs": "Installed in components/furin/prism-light/. Docs, live controls and props table: https://furin.dev/components/prism-light/",
  "files": [
    {
      "path": "registry/prism-light/PrismLight.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./PrismLight.css\";\n\nexport interface PrismLightProps {\n  /** Cuánto se abre el espectro (0 a 2). */\n  dispersion?: number;\n  /** Brillo de la luz y del espectro (0 a 1.5). */\n  intensity?: number;\n  /** Resplandor suave alrededor de la luz (0 a 2). */\n  glow?: number;\n  /** Grosor del haz blanco, en px. */\n  beamWidth?: number;\n  /** Tinte del vidrio del prisma. */\n  tint?: string;\n  /** Si no hay cursor, el orbe de luz recorre la escena solo. */\n  autoplay?: boolean;\n  /** Si es true, el orbe de luz sigue al cursor y cambia el ángulo del haz. */\n  interactive?: boolean;\n  /** Contenido (p. ej. un titular) que se ilumina con los colores del espectro. */\n  children?: ReactNode;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\ntype V = [number, number];\ntype RGB = [number, number, number];\n\n/** Rayos de espectro (longitudes de onda) que se trazan con la ley de Snell. */\nconst N = 32;\nconst DEG = Math.PI / 180;\n// Ángulos del haz permitidos (la luz solo puede llegar desde abajo a la izquierda: arriba habría reflexión total).\nconst TH_MIN = -58 * DEG;\nconst TH_MAX = -13 * DEG;\n\n// ---- Escena en unidades de mundo: el prisma mide 1 de lado. x a la derecha, y arriba, z hacia la cámara.\nconst HH = Math.sqrt(3) / 2; // altura del triángulo equilátero\nconst HZ = 0.42; // medio espesor del prisma (extrusión en z)\nconst XR = 1.5; // pared derecha (x = XR)\nconst ZB = 2.7; // pared de fondo (z = -ZB)\nconst TANH = Math.tan(15 * DEG); // medio campo de visión vertical\nconst YAW0 = -17 * DEG; // la cámara arranca a la izquierda y un poco arriba\nconst PITCH0 = 10 * DEG;\nconst TARGET: [number, number, number] = [0.12, 0.6, 0];\nconst NIVELES = [1, 0.8, 0.64, 0.5]; // escalas de la resolución interna\n\nconst clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));\nconst add = (a: V, b: V): V => [a[0] + b[0], a[1] + b[1]];\nconst sub = (a: V, b: V): V => [a[0] - b[0], a[1] - b[1]];\nconst mul = (a: V, k: number): V => [a[0] * k, a[1] * k];\nconst dot = (a: V, b: V) => a[0] * b[0] + a[1] * b[1];\nconst unit = (a: V): V => { const l = Math.hypot(a[0], a[1]) || 1; return [a[0] / l, a[1] / l]; };\n\n// Triángulo del prisma en el plano medio (z = 0). El punto de entrada del haz está al 56 % de la cara izquierda.\nconst BL: V = [-0.5, 0];\nconst BR: V = [0.5, 0];\nconst AP: V = [0, HH];\nconst P1: V = add(BL, mul(sub(AP, BL), 0.56));\nconst outN = (a: V, b: V, c: V): V => {\n  const ed = sub(b, a);\n  let n = unit([ed[1], -ed[0]]);\n  if (dot(n, sub(mul(add(a, b), 0.5), c)) < 0) n = mul(n, -1);\n  return n;\n};\nconst CEN: V = [0, HH / 3];\nconst NL = outN(BL, AP, CEN); // normal exterior de la cara izquierda (por donde entra la luz)\nconst NR = outN(AP, BR, CEN); // normal exterior de la cara derecha (por donde sale el espectro)\n\n// Ley de Snell en 2D con escalares (sin crear arrays en el bucle). n debe apuntar contra el rayo.\nlet rfx = 0;\nlet rfy = 0;\nfunction refract2(dx: number, dy: number, nx: number, ny: number, eta: number): boolean {\n  const c = -(nx * dx + ny * dy);\n  const k = 1 - eta * eta * (1 - c * c);\n  if (k < 0) return false;\n  const a = eta * c - Math.sqrt(k);\n  rfx = dx * eta + nx * a;\n  rfy = dy * eta + ny * a;\n  return true;\n}\n// Intersección del rayo o + t·d con el segmento p→q. Devuelve t (o -1).\nfunction hitSeg(ox: number, oy: number, dx: number, dy: number, px: number, py: number, qx: number, qy: number): number {\n  const ex = qx - px, ey = qy - py, den = dx * ey - dy * ex;\n  if (Math.abs(den) < 1e-9) return -1;\n  const wx = px - ox, wy = py - oy;\n  const t = (wx * ey - wy * ex) / den, s = (wx * dy - wy * dx) / den;\n  return t > 1e-4 && s >= -1e-4 && s <= 1 + 1e-4 ? t : -1;\n}\n// Reflectancia de Fresnel (aprox. de Schlick) para el vidrio: lo que no se transmite.\nconst schlick = (cos: number) => 0.04 + 0.96 * Math.pow(1 - clamp(cos, 0, 1), 5);\n\nfunction parseColor(s: string): RGB {\n  let h = s.trim().replace(\"#\", \"\");\n  if (h.length === 3) h = h.split(\"\").map((x) => x + x).join(\"\");\n  const n = parseInt(h.slice(0, 6), 16);\n  if (h.length < 6 || Number.isNaN(n)) return [188, 217, 255];\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\n/**\n * Traza el abanico: un rayo por longitud de onda, con Snell en el plano medio del prisma.\n * rayA = (Qx, Qy, dx, dy) del punto de salida; rayB = (largo hasta el impacto, brillo, separación angular, tipo).\n * tipo: -1 sin rayo, 0 solo dentro del vidrio, 1 cae en la pared, 2 cae en el piso. Devuelve el centro del cáustico en x.\n */\nfunction trazarAbanico(O: V, disp: number, I: number, rayA: Float32Array, rayB: Float32Array): { tin: number; xc: number } {\n  const d0 = unit(sub(P1, O));\n  const cosI = -dot(d0, NL);\n  for (let i = 0; i < N; i++) rayB[i * 4 + 3] = -1;\n  if (cosI <= 0.03) return { tin: 0, xc: 1 };\n  const dn = Math.max(0.004, 0.15 * disp);\n  const tin = 1 - schlick(cosI);\n  const ang: number[] = [];\n  const idx: number[] = [];\n  let xc = XR - 0.3;\n  for (let i = 0; i < N; i++) {\n    const t = i / (N - 1);\n    const nG = 1.5 + dn * (1 - t);\n    if (!refract2(d0[0], d0[1], NL[0], NL[1], 1 / nG)) continue;\n    const d1x = rfx, d1y = rfy;\n    const tR = hitSeg(P1[0], P1[1], d1x, d1y, AP[0], AP[1], BR[0], BR[1]);\n    const tB = hitSeg(P1[0], P1[1], d1x, d1y, BR[0], BR[1], BL[0], BL[1]);\n    let tt = -1, onRight = false;\n    if (tR > 0 && (tB < 0 || tR < tB)) { tt = tR; onRight = true; } else if (tB > 0) tt = tB;\n    if (tt < 0) continue;\n    const qx = P1[0] + d1x * tt, qy = P1[1] + d1y * tt;\n    const o = i * 4;\n    rayA[o] = qx; rayA[o + 1] = qy; rayA[o + 2] = d1x; rayA[o + 3] = d1y;\n    rayB[o] = 0; rayB[o + 1] = 0; rayB[o + 2] = 0.01; rayB[o + 3] = 0;\n    if (!onRight || !refract2(d1x, d1y, -NR[0], -NR[1], nG)) continue;\n    const d2x = rfx, d2y = rfy;\n    if (d2x < 0.05) continue;\n    const T = tin * (1 - schlick(NR[0] * d1x + NR[1] * d1y));\n    const tw = (XR - qx) / d2x;\n    const yw = qy + d2y * tw;\n    let len = tw, kind = 1;\n    if (yw < 0 && d2y < 0) { len = -qy / d2y; kind = 2; }\n    rayA[o + 2] = d2x; rayA[o + 3] = d2y;\n    rayB[o] = len; rayB[o + 1] = I * T; rayB[o + 3] = kind;\n    ang.push(Math.atan2(d2y, d2x));\n    idx.push(i);\n    if (i === Math.floor(N / 2)) xc = d2y < -0.02 ? clamp(qx + d2x * (qy / -d2y), 0.7, XR - 0.12) : XR - 0.25;\n  }\n  // Separación angular entre rayos vecinos: sirve para que las bandas de color se fundan sin huecos.\n  for (let k = 0; k < idx.length; k++) {\n    const a = ang[Math.max(0, k - 1)], b = ang[Math.min(idx.length - 1, k + 1)];\n    const span = Math.max(1, Math.min(idx.length - 1, k + 1) - Math.max(0, k - 1));\n    rayB[idx[k] * 4 + 2] = Math.max(0.0007, Math.abs(b - a) / span);\n  }\n  return { tin, xc };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Sombreador: una sola pasada de pantalla completa que traza la escena 3D (prisma de vidrio como\n// sólido de 5 planos con normales, piso, dos paredes, haz volumétrico, orbe) con cámara en perspectiva.\n// ---------------------------------------------------------------------------------------------\nconst VERT = `#version 300 es\nvoid main() {\n  vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}`;\n\nconst FRAG = `#version 300 es\nprecision highp float;\nprecision highp int;\nout vec4 fragColor;\n\nconst int N = ${N};\nconst float HZ = ${HZ.toFixed(4)};\nconst float XR = ${XR.toFixed(4)};\nconst float ZB = ${ZB.toFixed(4)};\nconst float BW = 0.034;\nconst vec2 P1 = vec2(${P1[0].toFixed(5)}, ${P1[1].toFixed(5)});\nconst vec3 PN[5] = vec3[5](vec3(-0.8660254, 0.5, 0.0), vec3(0.8660254, 0.5, 0.0), vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0));\nconst float PD[5] = float[5](0.4330127, 0.4330127, 0.0, HZ, HZ);\n\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec3 uCam;\nuniform vec3 uCF;\nuniform vec3 uCR;\nuniform vec3 uCU;\nuniform vec2 uLens;    // tan(fov/2), aspecto\nuniform vec3 uOrb;     // posición del orbe (z = 0)\nuniform vec4 uCfg;     // intensidad, resplandor, sigma del haz (mundo), dispersión\nuniform vec3 uTint;    // tinte del vidrio (lineal)\nuniform vec4 uBeam;    // dirección del haz (xy), largo hasta el prisma, transmisión de entrada\nuniform vec4 uMisc;    // x: centro del cáustico, y: posición del ángulo (0 a 1), z: tamaño angular de un píxel (rad)\nuniform vec4 uBox;     // caja (xmin, ymin, xmax, ymax) en z = 0 que contiene todos los haces\nuniform vec4 uRA[N];\nuniform vec4 uRB[N];\n\nfloat gVL = 0.0;       // luz de haz acumulada: sirve de máscara del polvo\n\nfloat hash12(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.x + p3.y) * p3.z);\n}\nvec2 hash22(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy);\n}\nfloat lum(vec3 c) { return dot(c, vec3(0.3, 0.55, 0.15)); }\n\n// Color del espectro: t = 0 violeta (el que más se dobla), t = 1 rojo.\nvec3 spec(float t) {\n  float h = 0.77 * (1.0 - t);\n  vec3 k = clamp(abs(fract(h + vec3(0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0) - 1.0, 0.0, 1.0);\n  k = k * k * (3.0 - 2.0 * k);\n  return k * vec3(1.0, 1.0, 1.0) * (0.92 + 0.35 * (1.0 - t) * (1.0 - t));\n}\n\n// Entorno de estudio: paneles de luz verticales y una luz de techo, para reflejos en bisel y vidrio.\nvec3 studio(vec3 d) {\n  vec3 c = mix(vec3(0.004, 0.006, 0.012), vec3(0.03, 0.045, 0.085), smoothstep(-0.3, 0.9, d.y));\n  float az = atan(d.x, -d.z);\n  float band = smoothstep(-0.2, 0.15, d.y) * smoothstep(1.0, 0.5, d.y);\n  float s = smoothstep(0.11, 0.0, abs(az + 0.85)) * 0.9 + smoothstep(0.05, 0.0, abs(az - 0.35)) * 1.3 + smoothstep(0.16, 0.0, abs(az - 1.3)) * 0.55 + smoothstep(0.08, 0.0, abs(az + 2.2)) * 0.5;\n  c += vec3(0.85, 0.92, 1.0) * s * band;\n  c += vec3(0.9, 0.95, 1.0) * smoothstep(0.8, 0.96, d.y) * 0.7;\n  // Panel grande detrás de la cámara: da cuerpo a las tapas de vidrio.\n  c += vec3(0.7, 0.8, 1.0) * smoothstep(0.7, 0.0, abs(abs(az) - 2.8)) * 0.16 * smoothstep(-0.45, 0.05, d.y) * smoothstep(0.9, 0.2, d.y);\n  return c;\n}\n\n// El prisma: sólido convexo de 5 planos (dos caras inclinadas, base y dos tapas).\nbool prism(vec3 ro, vec3 rd, out float t0, out float t1, out vec3 n0, out vec3 n1) {\n  t0 = -1e9; t1 = 1e9; n0 = PN[0]; n1 = PN[0];\n  for (int i = 0; i < 5; i++) {\n    float nd = dot(PN[i], rd);\n    float no = dot(PN[i], ro) - PD[i];\n    if (abs(nd) < 1e-7) { if (no > 0.0) return false; continue; }\n    float t = -no / nd;\n    if (nd < 0.0) { if (t > t0) { t0 = t; n0 = PN[i]; } }\n    else { if (t < t1) { t1 = t; n1 = PN[i]; } }\n  }\n  return t1 > max(t0, 0.0);\n}\n\n// Bisel: junto a cada arista la normal se inclina hacia la cara vecina; rim = hilo especular de la arista.\nvec3 bevel(vec3 p, vec3 n, vec3 dir, float tt, out float rim) {\n  float md = 1e3;\n  vec3 nn = n;\n  for (int i = 0; i < 5; i++) {\n    float c = dot(PN[i], n);\n    if (abs(c) > 0.98) continue;\n    float e = (PD[i] - dot(PN[i], p)) / sqrt(1.0 - c * c);\n    if (e < md) { md = e; nn = PN[i]; }\n  }\n  float k = 1.0 - smoothstep(0.0, BW, max(md, 0.0));\n  // El hilo mide ~1.5 px en pantalla sin importar el ángulo de la cara: así no se ve punteado en diagonal.\n  float pw = tt * uMisc.z / max(abs(dot(n, dir)), 0.12);\n  rim = 1.0 - smoothstep(0.0, max(BW * 0.1, 1.6 * pw), max(md, 0.0));\n  return normalize(n + nn * (k * k * 1.2));\n}\n\n// Perfil gaussiano de un cilindro luminoso (o cinta) visto desde un rayo que cruza el plano z = 0:\n// dp = distancia en el plano al eje, c = pendiente transversal del rayo, sp/sz = grosor en el plano y en z.\nfloat tube(float dp, float c, float sp, float sz) {\n  float se2 = sp * sp + c * c * sz * sz;\n  return exp(-0.5 * dp * dp / se2) * sp * inversesqrt(se2);\n}\n\n// Todos los haces (blanco entrante, abanico interno y espectro saliente) evaluados en el punto (p) del plano z = 0.\nvec3 beams(vec2 p, vec2 m) {\n  float I = uCfg.x, G = uCfg.y, s0 = uCfg.z;\n  vec3 acc = vec3(0.0);\n  // Haz blanco: núcleo + dos lóbulos de dispersión en el aire.\n  {\n    vec2 b = uBeam.xy, q = p - uOrb.xy;\n    float s = dot(q, b), dp = q.x * b.y - q.y * b.x, c = m.x * b.y - m.y * b.x;\n    float w = smoothstep(0.03, 0.14, s) * (1.0 - smoothstep(uBeam.z - 0.02, uBeam.z + 0.01, s));\n    float k = tube(dp, c, s0, s0) * 2.4 + tube(dp, c, s0 * 3.2, s0 * 3.2) * 0.42 + tube(dp, c, s0 * 9.0, s0 * 9.0) * 0.1 * G;\n    acc += vec3(0.92, 0.96, 1.0) * k * w * I;\n    // Destello donde la luz toca el vidrio.\n    float dP = length(p - P1);\n    acc += vec3(0.9, 0.95, 1.0) * I * (0.9 * exp(-0.5 * dP * dP / 0.0007) + 0.14 * G * exp(-0.5 * dP * dP / 0.012)) * step(0.5, uBeam.w);\n  }\n  float aIn = 0.075 * I * uBeam.w;\n  bool inPrism = p.x < 0.36 && p.x > -0.5 && p.y < 0.92;\n  for (int i = 0; i < N; i++) {\n    vec4 A = uRA[i];\n    vec4 B = uRB[i];\n    if (B.w < -0.5) continue;\n    float t = float(i) / float(N - 1);\n    vec3 col = spec(t);\n    // Dentro del vidrio: el blanco ya empieza a abrirse.\n    if (inPrism) {\n      vec2 e = A.xy - P1;\n      float L = length(e);\n      vec2 bi = e / L, qi = p - P1;\n      float si = dot(qi, bi), di = qi.x * bi.y - qi.y * bi.x, ci = m.x * bi.y - m.y * bi.x;\n      float w = smoothstep(0.0, 0.03, si) * (1.0 - smoothstep(L - 0.012, L, si));\n      acc += col * aIn * w * (tube(di, ci, s0 * 1.3, s0 * 1.3) + 0.2 * G * tube(di, ci, s0 * 4.0, s0 * 4.0));\n    }\n    // Fuera del prisma: un rayo por color hasta la pared o el piso; se ensancha y se funde con sus vecinos.\n    vec2 bq = p - A.xy;\n    if (B.w > 0.5 && dot(bq, A.zw) > -0.05 && dot(bq, A.zw) < B.x + 0.05) {\n      vec2 b = A.zw, q = bq;\n      float s = dot(q, b), dp = q.x * b.y - q.y * b.x, c = m.x * b.y - m.y * b.x;\n      float ss = max(s, 0.0);\n      float sp = s0 * 1.1 + (0.55 * B.z + 0.004) * ss;\n      float sz = sp * 1.5 + 0.05 * ss;\n      float w = smoothstep(-0.004, 0.05, s) * (1.0 - smoothstep(B.x - 0.3, B.x - 0.005, s));\n      float k = tube(dp, c, sp, sz) + tube(dp, c, sp * 5.0, sz * 3.0) * 0.16 * G;\n      acc += col * B.y * w * k * 0.62 / (1.0 + 0.4 * ss);\n    }\n  }\n  return acc;\n}\n\n// Luz en el aire a lo largo de un tramo recto del rayo: orbe (núcleo y halo) y haces donde el rayo cruza el plano z = 0.\nvec3 airLight(vec3 ro, vec3 rd, float tmax) {\n  vec3 acc = vec3(0.0);\n  float I = uCfg.x, G = uCfg.y;\n  vec3 oc = uOrb - ro;\n  float tc = dot(oc, rd);\n  if (tc > 0.0 && tc < tmax) {\n    float dm2 = max(dot(oc, oc) - tc * tc, 0.0);\n    float dm = sqrt(dm2);\n    float core = 1.0 - smoothstep(0.036, 0.05, dm);\n    acc += vec3(1.0, 0.98, 0.95) * core * 9.0 * I;\n    acc += vec3(0.95, 0.97, 1.0) * I * (1.6 * G * exp(-0.5 * dm2 / 0.0030) + 0.38 * G * exp(-0.5 * dm2 / 0.045) + 0.08 * G * exp(-0.5 * dm2 / 0.45));\n  }\n  if (abs(rd.z) > 1e-4) {\n    float tz = -ro.z / rd.z;\n    if (tz > 0.0 && tz < tmax) {\n      vec3 pz = ro + rd * tz;\n      if (pz.x > uBox.x && pz.x < uBox.z && pz.y > uBox.y && pz.y < uBox.w) acc += beams(pz.xy, rd.xy / rd.z);\n    }\n  }\n  gVL += lum(acc);\n  return acc;\n}\n\n// Manchas del espectro sobre la pared derecha (impacto de cada rayo, con su baño de color).\nvec3 spotsWall(vec3 p) {\n  float G = uCfg.y, s0 = uCfg.z;\n  vec3 acc = vec3(0.0);\n  if (abs(p.z) > 2.8 || p.y > 1.8) return acc;\n  for (int i = 0; i < N; i++) {\n    vec4 A = uRA[i];\n    vec4 B = uRB[i];\n    if (B.w < 0.5 || B.w > 1.5) continue;\n    float t = float(i) / float(N - 1);\n    float sp = s0 * 1.1 + (0.55 * B.z + 0.004) * B.x;\n    float sy = sp / max(abs(A.z), 0.3);\n    float sz = 0.07 + 0.14 * B.x;\n    float ovl = max(1.0, 2.5066 * sy / (B.z * B.x * 1.3 + 1e-4));\n    float dy = p.y - (A.y + A.w * B.x);\n    float ey = dy * dy / (sy * sy);\n    float g = exp(-0.5 * (ey + p.z * p.z / (sz * sz * 0.1)));\n    float gw = exp(-0.5 * (ey + p.z * p.z / (sz * sz)));\n    float h = exp(-0.5 * (ey / 18.0 + p.z * p.z / (sz * sz * 5.0)));\n    acc += spec(t) * B.y * (1.2 * g + 0.75 * gw + 0.2 * G * h) / ovl;\n  }\n  return acc * 0.9;\n}\n// Lo mismo sobre el piso: la banda de color queda tendida a lo largo de x.\nvec3 spotsFloor(vec3 p) {\n  float G = uCfg.y, s0 = uCfg.z;\n  vec3 acc = vec3(0.0);\n  if (abs(p.z) > 2.2 || p.x < 0.1 || p.x > XR + 0.1) return acc;\n  for (int i = 0; i < N; i++) {\n    vec4 A = uRA[i];\n    vec4 B = uRB[i];\n    if (B.w < 1.5) continue;\n    float t = float(i) / float(N - 1);\n    float sp = s0 * 1.1 + (0.55 * B.z + 0.004) * B.x;\n    float sa = sp / max(abs(A.w), 0.14);\n    float sz = 0.06 + 0.12 * B.x;\n    float ovl = max(1.0, 2.5066 * sa / (B.z * B.x / max(abs(A.w), 0.14) * 1.3 + 1e-4));\n    float dx = p.x - (A.x + A.z * B.x);\n    float ex = dx * dx / (sa * sa);\n    float g = exp(-0.5 * (ex + p.z * p.z / (sz * sz * 0.1)));\n    float gw = exp(-0.5 * (ex + p.z * p.z / (sz * sz)));\n    float h = exp(-0.5 * (ex / 18.0 + p.z * p.z / (sz * sz * 5.0)));\n    acc += spec(t) * B.y * (1.2 * g + 0.75 * gw + 0.2 * G * h) / ovl;\n  }\n  return acc * 0.9;\n}\n\n// Sombra del prisma sobre el piso desde el orbe: la longitud de cuerda que la luz recorre dentro del vidrio\n// da una penumbra continua (sin ruido). El vidrio deja pasar algo de luz, teñida.\nvec3 shadowAt(vec3 p) {\n  vec3 Lv = uOrb - p;\n  float dist = length(Lv);\n  vec3 rd = Lv / dist, ro = p + vec3(0.0, 1e-3, 0.0);\n  float t0 = -1e9, t1 = 1e9;\n  for (int i = 0; i < 5; i++) {\n    float nd = dot(PN[i], rd);\n    float no = dot(PN[i], ro) - PD[i];\n    if (abs(nd) < 1e-7) { if (no > 0.0) return vec3(1.0); continue; }\n    float t = -no / nd;\n    if (nd < 0.0) t0 = max(t0, t); else t1 = min(t1, t);\n  }\n  float chord = max(min(t1, dist) - max(t0, 0.0), 0.0);\n  return mix(vec3(1.0), vec3(0.12) * mix(vec3(0.3), uTint, 0.7), smoothstep(0.0, 0.14, chord));\n}\n\nvec3 floorCol(vec3 p) {\n  float I = uCfg.x;\n  vec3 Lv = uOrb - p;\n  float d2 = dot(Lv, Lv);\n  float nl = max(Lv.y * inversesqrt(d2), 0.0);\n  vec3 sh = shadowAt(p);\n  vec2 bd = abs(p.xz) - vec2(0.5, HZ);\n  float sd = length(max(bd, 0.0));\n  float ao = 1.0 - 0.8 * exp(-sd * 15.0);\n  vec3 alb = vec3(0.05, 0.06, 0.088);\n  vec3 c = alb * (0.3 + 2.4 * I * nl / (1.0 + 2.2 * d2) * sh) * ao;\n  c += spotsFloor(p) * (0.5 + 0.5 * ao);\n  // Cáustico: la luz que atraviesa el prisma se concentra en un charco azulado detrás.\n  vec2 cq = vec2((p.x - uMisc.x) / 0.42, p.z / 0.24);\n  c += vec3(0.4, 0.58, 1.0) * 0.12 * I * exp(-0.5 * dot(cq, cq)) * step(0.0, uBeam.w);\n  return c;\n}\nvec3 wallBack(vec3 p) {\n  float I = uCfg.x;\n  float x = p.x, y = p.y;\n  vec3 c = mix(vec3(0.0075, 0.0105, 0.02), vec3(0.003, 0.0045, 0.009), smoothstep(0.0, 2.8, y));\n  c += vec3(0.06, 0.085, 0.15) * 0.2 * exp(-0.5 * (pow((x - 0.3) / 1.25, 2.0) + pow((y - 0.7) / 0.9, 2.0)));\n  float pn = smoothstep(0.16, 0.0, abs(x + 1.45)) * 0.9 + smoothstep(0.07, 0.0, abs(x - 0.4)) * 1.0 + smoothstep(0.12, 0.0, abs(x - 1.0)) * 0.55;\n  c += vec3(0.5, 0.62, 0.95) * pn * 0.04 * smoothstep(-0.05, 0.4, y) * (1.0 - smoothstep(1.7, 2.5, y));\n  vec3 L = uOrb - p;\n  float d2 = dot(L, L);\n  c += vec3(0.5, 0.62, 1.0) * 0.06 * I * max(L.z * inversesqrt(d2), 0.0) / (1.0 + 1.4 * d2);\n  c += vec3(0.4, 0.52, 0.85) * 0.15 * exp(-max(y, 0.0) * 55.0);\n  c *= 1.0 - 0.55 * exp(-(XR - x) * 5.0);\n  return c;\n}\nvec3 wallRight(vec3 p) {\n  float I = uCfg.x;\n  float z = p.z, y = p.y;\n  vec3 c = mix(vec3(0.0065, 0.009, 0.017), vec3(0.003, 0.0045, 0.009), smoothstep(0.0, 2.8, y));\n  c += vec3(0.06, 0.085, 0.15) * 0.13 * exp(-0.5 * (pow((z + 0.2) / 1.5, 2.0) + pow((y - 0.55) / 0.8, 2.0)));\n  float pn = smoothstep(0.12, 0.0, abs(z + 1.4)) * 0.8 + smoothstep(0.2, 0.0, abs(z - 0.9)) * 0.5;\n  c += vec3(0.5, 0.62, 0.95) * pn * 0.03 * smoothstep(-0.05, 0.4, y) * (1.0 - smoothstep(1.5, 2.3, y));\n  vec3 L = uOrb - p;\n  float d2 = dot(L, L);\n  c += vec3(0.5, 0.62, 1.0) * 0.045 * I * max(-L.x * inversesqrt(d2), 0.0) / (1.0 + 1.6 * d2);\n  c += vec3(0.4, 0.52, 0.85) * 0.13 * exp(-max(y, 0.0) * 55.0);\n  c *= 1.0 - 0.5 * exp(-(p.z + ZB) * 3.5);\n  c += spotsWall(p);\n  return c;\n}\n\n// El cuarto sin reflejos: primero se halla la superficie más cercana (piso, pared de fondo o pared derecha)...\nfloat roomT(vec3 ro, vec3 rd, out int kind) {\n  float tf = rd.y < -1e-5 ? -ro.y / rd.y : 1e9;\n  float tb = rd.z < -1e-5 ? (-ZB - ro.z) / rd.z : 1e9;\n  float tr = rd.x > 1e-5 ? (XR - ro.x) / rd.x : 1e9;\n  float t = tf; kind = 1;\n  if (tb < t) { t = tb; kind = 2; }\n  if (tr < t) { t = tr; kind = 3; }\n  if (t > 1e8) { kind = 0; return 60.0; }\n  return max(t, 0.0);\n}\n// ...y solo después se sombrea.\nvec3 roomShade(vec3 p, int kind) {\n  if (kind == 1) return floorCol(p);\n  if (kind == 2) return wallBack(p);\n  if (kind == 3) return wallRight(p);\n  return vec3(0.004, 0.006, 0.012);\n}\nvec3 roomCol(vec3 ro, vec3 rd, out float tHit, out int kind) {\n  tHit = roomT(ro, rd, kind);\n  return roomShade(ro + rd * tHit, kind);\n}\n\n// Vidrio: fresnel, refracción por canal de color (dispersión), rebotes internos con reflexión total,\n// absorción del tinte y bisel con hilo especular. Los haces dentro del vidrio se ven refractados.\nvec3 glassShade(vec3 ro, vec3 rd, float ta, vec3 na) {\n  float DSP = 0.006 + 0.01 * uCfg.w;\n  vec3 p = ro + rd * ta;\n  float rim0;\n  vec3 nb = bevel(p, na, rd, ta, rim0);\n  float ci = clamp(dot(-rd, nb), 0.0, 1.0);\n  float F = 0.04 + 0.96 * pow(1.0 - ci, 5.0);\n  vec3 rr = reflect(rd, nb);\n  vec3 refl = studio(rr) + vec3(1.0, 0.97, 0.92) * pow(max(dot(rr, normalize(uOrb - p)), 0.0), 120.0) * 6.0 * uCfg.x;\n  vec3 air = airLight(ro, rd, ta);\n  vec3 vol = vec3(0.0);\n  vec3 thr = vec3(0.0);\n  float plen = 0.0;\n  float rimE = 0.0;\n  for (int ch = 0; ch < 3; ch++) {\n    float ior = 1.5 + (float(ch) - 1.0) * DSP;\n    vec3 d = refract(rd, nb, 1.0 / ior);\n    vec3 q = p + d * 2e-4;\n    vec3 od = d;\n    float len = 0.0;\n    int nb = ch == 1 ? 3 : 2;\n    for (int b = 0; b < 3; b++) {\n      if (b >= nb) break;\n      float a0, a1; vec3 m0, m1;\n      prism(q, d, a0, a1, m0, m1);\n      float tx = max(a1, 1e-3);\n      if (ch == 1) vol += airLight(q, d, tx);\n      len += tx;\n      vec3 pe = q + d * tx;\n      float re;\n      vec3 ne = bevel(pe, m1, d, ta + len, re);\n      if (ch == 1) rimE = max(rimE, re * (b == 0 ? 1.0 : 0.6));\n      vec3 o = refract(d, -ne, ior);\n      if (dot(o, o) > 0.0) { q = pe; od = o; break; }\n      d = reflect(d, ne);\n      q = pe + d * 2e-4;\n      od = d;\n    }\n    float th; int kd;\n    vec3 rc = roomCol(q, od, th, kd);\n    if (ch == 1) { thr.g = rc.g; plen = len; vol += airLight(q, od, th); }\n    else if (ch == 0) thr.r = rc.r;\n    else thr.b = rc.b;\n  }\n  vec3 absorb = exp(-plen * (1.0 - uTint) * 1.5);\n  vec3 col = air + vol + mix(thr * absorb, refl, F);\n  float rl = 0.35 + 1.6 * lum(studio(rr));\n  col += vec3(0.8, 0.9, 1.0) * (rim0 * rl * 0.9 + rimE * 0.28);\n  return col;\n}\n\n// Escena sin el reflejo del piso (para el reflejo mismo y para lo que se ve a través del vidrio).\nvec3 scene1(vec3 ro, vec3 rd) {\n  float a0, a1; vec3 m0, m1;\n  int kd;\n  float th = roomT(ro, rd, kd);\n  if (prism(ro, rd, a0, a1, m0, m1) && a0 > 0.0 && a0 < th) return glassShade(ro, rd, a0, m0);\n  return roomShade(ro + rd * th, kd) + airLight(ro, rd, th);\n}\n\nvec3 aces(vec3 x) { return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\n\n// Polvo en suspensión: motas que solo se encienden donde hay luz del haz.\nfloat motes(vec2 frag, float mask) {\n  float acc = 0.0;\n  float u = uRes.y;\n  for (int k = 0; k < 2; k++) {\n    float cell = u * (k == 0 ? 0.052 : 0.083);\n    vec2 g = (frag + vec2(uTime * 5.0 * float(k + 1), -uTime * 3.0)) / cell;\n    vec2 id = floor(g);\n    vec2 f = fract(g) - 0.5;\n    vec2 h = hash22(id + float(k) * 17.0);\n    float on = step(0.8, hash12(id * 1.7 + float(k) * 5.0));\n    float d = length(f - (h - 0.5) * 0.7);\n    float tw = 0.5 + 0.5 * sin(uTime * (1.0 + h.x * 2.0) + h.y * 6.283);\n    acc += on * (0.35 + 0.65 * tw) * smoothstep(0.1, 0.0, d);\n  }\n  return acc * mask;\n}\n\nvoid main() {\n  vec2 frag = gl_FragCoord.xy;\n  vec2 ndc = frag / uRes * 2.0 - 1.0;\n  vec3 ro = uCam;\n  vec3 rd = normalize(uCF + uCR * (ndc.x * uLens.y * uLens.x) + uCU * (ndc.y * uLens.x));\n  vec3 col;\n  float a0, a1; vec3 m0, m1;\n  int kind;\n  float tr = roomT(ro, rd, kind);\n  if (prism(ro, rd, a0, a1, m0, m1) && a0 > 0.0 && a0 < tr) {\n    col = glassShade(ro, rd, a0, m0);\n  } else {\n    col = roomShade(ro + rd * tr, kind);\n    if (kind == 1) {\n      // Piso brillante tipo vinilo: reflejo de todo lo que hay arriba, más fuerte al ras.\n      float cs = clamp(-rd.y, 0.0, 1.0);\n      float F = clamp((0.05 + 0.95 * pow(1.0 - cs, 5.0)) * 1.4 + 0.06, 0.0, 0.85);\n      vec3 p = ro + rd * tr;\n      vec3 refl = scene1(p + vec3(0.0, 2e-4, 0.0), vec3(rd.x, -rd.y, rd.z));\n      col = col * (1.0 - F * 0.7) + refl * F;\n    }\n    col += airLight(ro, rd, tr);\n  }\n  col += vec3(0.9, 0.95, 1.0) * motes(frag, clamp(gVL * 0.7, 0.0, 1.0)) * 1.4 * uCfg.x;\n\n  col = aces(col);\n  col = pow(col, vec3(1.0 / 2.2));\n  vec2 uv = frag / uRes - 0.5;\n  col *= 1.0 - 0.6 * smoothstep(0.22, 0.95, length(uv * vec2(1.0, 1.1) * 1.3));\n  col += (hash12(frag + fract(uTime) * 91.7) - 0.5) * 0.024;\n  fragColor = vec4(max(col, 0.0), 1.0);\n}`;\n\nconst UNIFORMS = [\"uRes\", \"uTime\", \"uCam\", \"uCF\", \"uCR\", \"uCU\", \"uLens\", \"uOrb\", \"uCfg\", \"uTint\", \"uBeam\", \"uMisc\", \"uBox\", \"uRA\", \"uRB\"] as const;\n\n/** Un orbe de luz que sigue al cursor dispara un haz a un prisma de vidrio 3D; el espectro cae sobre la pared y el piso. */\nexport function PrismLight({\n  dispersion = 1,\n  intensity = 1,\n  glow = 1,\n  beamWidth = 2.5,\n  tint = \"#bcd9ff\",\n  autoplay = true,\n  interactive = true,\n  children,\n  className = \"\",\n  style,\n}: PrismLightProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const cvRef = useRef<HTMLCanvasElement>(null);\n  const opts = useRef({ dispersion, intensity, glow, beamWidth, tint, autoplay, interactive });\n  opts.current = { dispersion, intensity, glow, beamWidth, tint, autoplay, interactive };\n  const refresh = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const cv = cvRef.current;\n    if (!root || !cv) return;\n    const gl = cv.getContext(\"webgl2\", { alpha: false, antialias: false, depth: false, stencil: false, powerPreference: \"high-performance\", preserveDrawingBuffer: false });\n    if (!gl) {\n      // Sin WebGL2: queda el fondo oscuro de CSS con el titular.\n      root.setAttribute(\"data-sin-gl\", \"\");\n      return;\n    }\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Render por software (SwiftShader, llvmpipe): bajar la resolución no lo salva y solo empeora la imagen.\n    const dbgInfo = gl.getExtension(\"WEBGL_debug_renderer_info\");\n    const software = !!dbgInfo && /swiftshader|llvmpipe|software/i.test(String(gl.getParameter(dbgInfo.UNMASKED_RENDERER_WEBGL)));\n\n    let prog: WebGLProgram | null = null;\n    let vao: WebGLVertexArrayObject | null = null;\n    let U: Record<string, WebGLUniformLocation | null> = {};\n    let lost = false, ready = false, disposed = false, compRaf = 0;\n    let W = 0, H = 0, dpr = 1, raf = 0, visible = true, last = 0, time = 0, hover = false, inited = false, lastVars = \"\";\n    let cur: V = [0, 0];\n    let nivel = 0;\n    const orb = { x: 0, y: 0, vx: 0, vy: 0 };\n    const cam = { yaw: YAW0, pitch: PITCH0, vy: 0, vp: 0 };\n    const L = { dist: 6.6, rMin: 0.45, rMax: 1.4, rMid: 0.9 };\n    const rayA = new Float32Array(N * 4);\n    const rayB = new Float32Array(N * 4);\n\n    // ---- Medición de rendimiento: tiempo de GPU con timer query si existe; si no, el intervalo de rAF.\n    const ext = gl.getExtension(\"EXT_disjoint_timer_query_webgl2\") as { TIME_ELAPSED_EXT: number; GPU_DISJOINT_EXT: number } | null;\n    const pend: WebGLQuery[] = [];\n    let gpuAvg = 0, gpuN = 0, calmos = 0, espera = 60; // los primeros cuadros (compilación, calentamiento) no cuentan\n    let minInt = 1e9, prevRaf = 0;\n    const lentos: boolean[] = [];\n    const cambiarNivel = (d: number) => {\n      const n = clamp(nivel + d, 0, NIVELES.length - 1);\n      if (n === nivel) return;\n      nivel = n; gpuAvg = 0; gpuN = 0; calmos = 0; espera = 40; lentos.length = 0;\n      resize();\n      if (!raf) draw();\n    };\n    const medir = (now: number) => {\n      if (software) return;\n      if (espera > 0) espera--;\n      if (ext) {\n        while (pend.length) {\n          const q = pend[0];\n          if (!gl.getQueryParameter(q, gl.QUERY_RESULT_AVAILABLE)) break;\n          pend.shift();\n          const bad = gl.getParameter(ext.GPU_DISJOINT_EXT);\n          if (!bad) {\n            const ms = (gl.getQueryParameter(q, gl.QUERY_RESULT) as number) / 1e6;\n            gpuAvg = gpuN ? gpuAvg * 0.85 + ms * 0.15 : ms; gpuN++;\n          }\n          gl.deleteQuery(q);\n        }\n        if (espera === 0 && gpuN > 12) {\n          if (gpuAvg > 12) cambiarNivel(1);\n          else if (gpuAvg < 4 && nivel > 0) { if (++calmos > 150) cambiarNivel(-1); } else calmos = 0;\n        }\n        return;\n      }\n      // Sin timer query: intervalo de rAF relativo al mínimo observado (solo mientras el bucle corre seguido).\n      const dtr = prevRaf ? now - prevRaf : 0;\n      prevRaf = now;\n      // Más de ~140 ms por cuadro es render por software: bajar la resolución no salva la fluidez y solo empeora la imagen.\n      if (dtr < 2 || dtr > 140) return;\n      minInt = Math.min(minInt * 1.0008, dtr);\n      lentos.push(dtr > minInt * 1.5 + 2);\n      if (lentos.length > 30) lentos.shift();\n      if (espera === 0 && lentos.length === 30 && lentos.filter(Boolean).length > 20) cambiarNivel(1);\n    };\n\n    // ---- Programa y recursos de GL (se pueden reconstruir si el contexto se pierde y vuelve).\n    // La compilación es asíncrona si el navegador lo permite (KHR_parallel_shader_compile): la página no se congela.\n    const pk = gl.getExtension(\"KHR_parallel_shader_compile\") as { COMPLETION_STATUS_KHR: number } | null;\n    const start = () => {\n      ready = false;\n      const mk = (type: number, src: string) => {\n        const sh = gl.createShader(type);\n        if (sh) { gl.shaderSource(sh, src); gl.compileShader(sh); }\n        return sh;\n      };\n      const vs = mk(gl.VERTEX_SHADER, VERT), fs = mk(gl.FRAGMENT_SHADER, FRAG);\n      const pr = gl.createProgram();\n      if (!vs || !fs || !pr) { fallo(); return; }\n      gl.attachShader(pr, vs); gl.attachShader(pr, fs);\n      gl.linkProgram(pr);\n      const poll = () => {\n        compRaf = 0;\n        if (disposed || lost) return;\n        if (pk && !gl.getProgramParameter(pr, pk.COMPLETION_STATUS_KHR)) { compRaf = requestAnimationFrame(poll); return; }\n        if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) {\n          console.error(\"PrismLight: \" + (gl.getShaderInfoLog(fs) || gl.getProgramInfoLog(pr)));\n          fallo();\n          return;\n        }\n        gl.deleteShader(vs); gl.deleteShader(fs);\n        prog = pr;\n        vao = gl.createVertexArray();\n        U = {};\n        for (const n of UNIFORMS) U[n] = gl.getUniformLocation(pr, n);\n        ready = true;\n        resize();\n        draw();\n        wake();\n      };\n      poll();\n    };\n    // Sin programa utilizable: queda el fondo oscuro de CSS con el titular.\n    const fallo = () => { root.setAttribute(\"data-sin-gl\", \"\"); };\n\n    // ---- Cámara: órbita alrededor del prisma (el paralaje del cursor mueve yaw y pitch con un resorte).\n    const basis = () => {\n      const cp = Math.cos(cam.pitch), sp = Math.sin(cam.pitch), cy = Math.cos(cam.yaw), sy = Math.sin(cam.yaw);\n      const pos: [number, number, number] = [TARGET[0] + L.dist * sy * cp, TARGET[1] + L.dist * sp, TARGET[2] + L.dist * cy * cp];\n      let f: [number, number, number] = [TARGET[0] - pos[0], TARGET[1] - pos[1], TARGET[2] - pos[2]];\n      const fl = Math.hypot(f[0], f[1], f[2]);\n      f = [f[0] / fl, f[1] / fl, f[2] / fl];\n      // r = f × (0,1,0)\n      let r: [number, number, number] = [-f[2], 0, f[0]];\n      const rl = Math.hypot(r[0], r[2]) || 1;\n      r = [r[0] / rl, 0, r[2] / rl];\n      const u: [number, number, number] = [r[1] * f[2] - r[2] * f[1], r[2] * f[0] - r[0] * f[2], r[0] * f[1] - r[1] * f[0]];\n      return { pos, f, r, u };\n    };\n    // Proyecta un punto de la pantalla (px de CSS) al plano z = 0 del mundo con la cámara actual.\n    const unproject = (px: number, py: number): V | null => {\n      const b = basis();\n      const nx = (px / W) * 2 - 1, ny = 1 - (py / H) * 2;\n      const k1 = nx * (W / H) * TANH, k2 = ny * TANH;\n      const dx = b.f[0] + b.r[0] * k1 + b.u[0] * k2, dy = b.f[1] + b.r[1] * k1 + b.u[1] * k2, dz = b.f[2] + b.r[2] * k1 + b.u[2] * k2;\n      if (dz > -1e-4) return null;\n      const t = -b.pos[2] / dz;\n      return [b.pos[0] + dx * t, b.pos[1] + dy * t];\n    };\n\n    // ---- El orbe vive en coordenadas polares alrededor del punto de entrada: (ángulo del haz, distancia).\n    // Nunca baja del piso: si el ángulo es muy empinado, se acorta la distancia.\n    const limitar = (th: number, r: number): V => {\n      const s = -Math.sin(th);\n      const rf = s > 0.05 ? (P1[1] - 0.12) / s : 1e9;\n      return [th, clamp(Math.min(r, rf), 0.3, L.rMax)];\n    };\n    const aim = (px: number, py: number): V => {\n      const w = unproject(px, py) ?? [P1[0] - 1, P1[1] - 0.3];\n      const vx = Math.max(P1[0] - w[0], 0.25), vy = w[1] - P1[1];\n      return limitar(clamp(Math.atan2(vy, vx), TH_MIN, TH_MAX), clamp(Math.hypot(vx, vy), L.rMin, L.rMax));\n    };\n    const idle = (t: number): V => limitar((-34 + 11 * Math.sin(t * 0.33) + 3 * Math.sin(t * 0.91 + 1)) * DEG, L.rMid * (1 + 0.14 * Math.sin(t * 0.21 + 0.8)));\n    // Pose de reposo: la del instante 0 si el orbe pasea solo; una fija si no.\n    const rest = (t: number): V => (opts.current.autoplay ? idle(t) : limitar(-34 * DEG, L.rMid));\n    const place = (th: number, r: number): V => [P1[0] - r * Math.cos(th), P1[1] + r * Math.sin(th)];\n\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      W = Math.max(1, root.clientWidth); H = Math.max(1, root.clientHeight);\n      const sc = NIVELES[nivel];\n      cv.width = Math.max(2, Math.round(W * dpr * sc));\n      cv.height = Math.max(2, Math.round(H * dpr * sc));\n      gl.viewport(0, 0, cv.width, cv.height);\n      // Encuadre: el ancho visible a la distancia del prisma se mantiene en ~3.5 unidades; en lienzos bajos manda el alto.\n      L.dist = clamp(Math.max(1.75 / (TANH * (W / H)), 4.7), 4.7, 11);\n      const base = { yaw: cam.yaw, pitch: cam.pitch };\n      cam.yaw = YAW0; cam.pitch = PITCH0;\n      const wl = unproject(W * 0.07, H * 0.55);\n      cam.yaw = base.yaw; cam.pitch = base.pitch;\n      const xl = wl ? wl[0] : -1.5;\n      L.rMax = Math.max(L.rMin + 0.3, (P1[0] - xl) / Math.cos(TH_MAX));\n      L.rMid = Math.max(L.rMin + 0.1, L.rMax * 0.62);\n      const t = rest(time), p = place(t[0], t[1]);\n      if (!inited) { inited = true; orb.x = p[0]; orb.y = p[1]; orb.vx = orb.vy = 0; }\n      else if (hover && opts.current.interactive) { const a = aim(cur[0], cur[1]), q = place(a[0], a[1]); orb.x = q[0]; orb.y = q[1]; }\n      else { orb.x = p[0]; orb.y = p[1]; orb.vx = orb.vy = 0; }\n    };\n\n    const draw = () => {\n      if (lost || !ready || !prog) return;\n      const o = opts.current;\n      const b = basis();\n      const O: V = [orb.x, orb.y];\n      const { tin, xc } = trazarAbanico(O, o.dispersion, o.intensity, rayA, rayB);\n      const d0 = unit(sub(P1, O));\n      const th = Math.atan2(orb.y - P1[1], P1[0] - orb.x);\n      const q = clamp((th - TH_MIN) / (TH_MAX - TH_MIN), 0, 1);\n      // Grosor del haz: px de CSS → unidades de mundo a la distancia del prisma.\n      const wpp = (2 * TANH * L.dist) / H;\n      const sigma = Math.max(0.7 * wpp, Math.max(0.8, o.beamWidth) * wpp * 0.42);\n      const tc = parseColor(o.tint);\n      gl.useProgram(prog);\n      gl.bindVertexArray(vao);\n      gl.uniform2f(U.uRes, cv.width, cv.height);\n      gl.uniform1f(U.uTime, time);\n      gl.uniform3fv(U.uCam, b.pos); gl.uniform3fv(U.uCF, b.f); gl.uniform3fv(U.uCR, b.r); gl.uniform3fv(U.uCU, b.u);\n      gl.uniform2f(U.uLens, TANH, W / H);\n      gl.uniform3f(U.uOrb, orb.x, orb.y, 0);\n      gl.uniform4f(U.uCfg, o.intensity, o.glow, sigma, o.dispersion);\n      gl.uniform3f(U.uTint, Math.pow(tc[0] / 255, 2.2), Math.pow(tc[1] / 255, 2.2), Math.pow(tc[2] / 255, 2.2));\n      gl.uniform4f(U.uBeam, d0[0], d0[1], Math.hypot(P1[0] - O[0], P1[1] - O[1]), tin);\n      gl.uniform4f(U.uMisc, xc, q, (2 * TANH) / cv.height, 0);\n      let y1 = Math.max(O[1], P1[1]);\n      for (let i = 0; i < N; i++) {\n        const o4 = i * 4;\n        if (rayB[o4 + 3] > 0.5) y1 = Math.max(y1, rayA[o4 + 1] + Math.max(0, rayA[o4 + 3]) * rayB[o4]);\n      }\n      gl.uniform4f(U.uBox, Math.min(O[0], P1[0]) - 0.5, -0.1, XR + 0.03, y1 + 0.6);\n      gl.uniform4fv(U.uRA, rayA);\n      gl.uniform4fv(U.uRB, rayB);\n      let qy: WebGLQuery | null = null;\n      if (ext && pend.length < 4) { qy = gl.createQuery(); if (qy) gl.beginQuery(ext.TIME_ELAPSED_EXT, qy); }\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      if (qy) { gl.endQuery(ext!.TIME_ELAPSED_EXT); pend.push(qy); }\n\n      // El titular recibe el color: la franja del espectro se desplaza con el ángulo de la luz.\n      const vars = `${(10 + 80 * q).toFixed(1)}|${Math.round(272 * (1 - q))}`;\n      if (vars !== lastVars) {\n        lastVars = vars;\n        const [px, ph] = vars.split(\"|\");\n        root.style.setProperty(\"--pl-x\", `${px}%`);\n        root.style.setProperty(\"--pl-h\", ph);\n      }\n    };\n\n    // Objetivo de la cámara: el cursor la inclina un poco (paralaje); sin cursor, un vaivén lento.\n    const camTarget = (t: number, follow: boolean): V => {\n      if (follow) {\n        const nx = clamp((cur[0] / W) * 2 - 1, -1, 1), ny = clamp((cur[1] / H) * 2 - 1, -1, 1);\n        return [YAW0 + nx * 0.11, PITCH0 - ny * 0.06];\n      }\n      if (opts.current.autoplay) return [YAW0 + 0.045 * Math.sin(t * 0.23), PITCH0 + 0.022 * Math.sin(t * 0.31 + 1)];\n      return [YAW0, PITCH0];\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      // dt nunca negativo ni enorme: el timestamp de rAF puede ser anterior a performance.now().\n      const dt = Math.min(0.04, Math.max(0, (now - (last || now)) / 1000));\n      last = now;\n      time += dt;\n      const o = opts.current;\n      const follow = hover && o.interactive;\n      // Cámara con resorte suave.\n      const ct = camTarget(time, follow);\n      cam.vy += ((ct[0] - cam.yaw) * 38 - cam.vy * 9) * dt;\n      cam.vp += ((ct[1] - cam.pitch) * 38 - cam.vp * 9) * dt;\n      cam.yaw += cam.vy * dt; cam.pitch += cam.vp * dt;\n      let tgt: V;\n      if (follow) tgt = aim(cur[0], cur[1]);\n      else tgt = rest(time);\n      const T = place(tgt[0], tgt[1]);\n      // Resorte con un poco de rebote: la luz persigue al cursor, no se pega a él.\n      const k = 150, c = 17;\n      orb.vx += ((T[0] - orb.x) * k - orb.vx * c) * dt;\n      orb.vy += ((T[1] - orb.y) * k - orb.vy * c) * dt;\n      orb.x += orb.vx * dt; orb.y += orb.vy * dt;\n      draw();\n      medir(now);\n      const camQuieta = Math.abs(ct[0] - cam.yaw) < 0.0004 && Math.abs(ct[1] - cam.pitch) < 0.0004 && Math.abs(cam.vy) < 0.004 && Math.abs(cam.vp) < 0.004;\n      const settled = Math.hypot(T[0] - orb.x, T[1] - orb.y) < 0.0004 && Math.hypot(orb.vx, orb.vy) < 0.004 && camQuieta;\n      if (visible && !lost && ((!follow && o.autoplay) || !settled)) raf = requestAnimationFrame(tick);\n      else { last = 0; prevRaf = 0; }\n    };\n    const wake = () => { if (!raf && visible && !reduce && !lost && ready) raf = requestAnimationFrame(tick); };\n    // Con movimiento reducido no hay bucle: solo se repinta cuando algo cambia.\n    const still = () => {\n      if (raf || lost || !ready) return;\n      raf = requestAnimationFrame(() => {\n        raf = 0;\n        const o = opts.current;\n        const follow = hover && o.interactive;\n        const ct = camTarget(0, follow);\n        cam.yaw = ct[0]; cam.pitch = ct[1]; cam.vy = cam.vp = 0;\n        const tgt = follow ? aim(cur[0], cur[1]) : rest(0);\n        const p = place(tgt[0], tgt[1]);\n        orb.x = p[0]; orb.y = p[1]; orb.vx = orb.vy = 0;\n        draw();\n      });\n    };\n    refresh.current = () => { if (reduce) still(); else wake(); };\n\n    // Los eventos de puntero solo guardan la posición y despiertan el bucle.\n    const onMove = (ev: PointerEvent) => {\n      if (!opts.current.interactive) return;\n      const r = root.getBoundingClientRect();\n      cur = [ev.clientX - r.left, ev.clientY - r.top];\n      hover = true;\n      if (reduce) still(); else wake();\n    };\n    const onLeave = () => { hover = false; if (reduce) still(); else wake(); };\n    const onLost = (e: Event) => { e.preventDefault(); lost = true; ready = false; if (raf) cancelAnimationFrame(raf); if (compRaf) cancelAnimationFrame(compRaf); raf = 0; compRaf = 0; pend.length = 0; };\n    const onRestored = () => {\n      lost = false;\n      start();\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    cv.addEventListener(\"webglcontextlost\", onLost);\n    cv.addEventListener(\"webglcontextrestored\", onRestored);\n    const ro = new ResizeObserver(() => { resize(); draw(); });\n    ro.observe(root);\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) { if (reduce) draw(); else wake(); } }, { threshold: 0.01 });\n    io.observe(root);\n\n    resize();\n    start();\n    return () => {\n      disposed = true;\n      cancelAnimationFrame(raf);\n      cancelAnimationFrame(compRaf);\n      raf = 0;\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      cv.removeEventListener(\"webglcontextlost\", onLost);\n      cv.removeEventListener(\"webglcontextrestored\", onRestored);\n      refresh.current = () => {};\n      for (const q of pend) gl.deleteQuery(q);\n      if (prog) gl.deleteProgram(prog);\n      if (vao) gl.deleteVertexArray(vao);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, []);\n\n  // Si cambian las props mientras el bucle duerme, repinta.\n  useEffect(() => { refresh.current(); }, [dispersion, intensity, glow, beamWidth, tint, autoplay, interactive]);\n\n  return (\n    <div ref={rootRef} className={`furin-prism-light ${className}`} style={style}>\n      <canvas ref={cvRef} className=\"furin-prism-light__canvas\" aria-hidden />\n      {children != null && children !== false && <div className=\"furin-prism-light__content\">{children}</div>}\n    </div>\n  );\n}\n\nexport default PrismLight;\n",
      "type": "registry:component",
      "target": "components/furin/prism-light/PrismLight.tsx"
    },
    {
      "path": "registry/prism-light/PrismLight.css",
      "content": ".furin-prism-light {\n  --pl-x: 50%;\n  --pl-h: 200;\n  position: relative;\n  display: block;\n  width: 100%;\n  height: 100%;\n  min-height: 240px;\n  overflow: hidden;\n  isolation: isolate;\n  container-type: inline-size;\n  background: #06070b;\n  touch-action: pan-y;\n}\n/* Sin WebGL2: fondo de estudio oscuro de CSS y el titular encima. */\n.furin-prism-light[data-sin-gl] {\n  background:\n    radial-gradient(ellipse 70% 55% at 55% 45%, #121a2a 0%, #0a0e17 55%, #05060a 100%),\n    #06070b;\n}\n.furin-prism-light[data-sin-gl] .furin-prism-light__canvas {\n  display: none;\n}\n.furin-prism-light__canvas {\n  position: absolute;\n  inset: 0;\n  display: block;\n  width: 100%;\n  height: 100%;\n}\n/* El titular es plata fría con una franja de espectro que se desplaza según el ángulo de la luz. */\n.furin-prism-light__content {\n  position: absolute;\n  z-index: 1;\n  top: 7%;\n  left: 0;\n  right: 0;\n  padding: 0 8%;\n  text-align: center;\n  font-size: clamp(20px, 6.6cqw, 36px);\n  font-weight: 600;\n  line-height: 1.12;\n  letter-spacing: -0.025em;\n  text-wrap: balance;\n  pointer-events: none;\n  color: transparent;\n  background-image:\n    linear-gradient(\n      100deg,\n      transparent calc(var(--pl-x) - 24%),\n      hsl(272 100% 70% / 0.5) calc(var(--pl-x) - 17%),\n      hsl(215 100% 64% / 0.45) calc(var(--pl-x) - 10%),\n      hsl(150 90% 56% / 0.38) calc(var(--pl-x) - 3%),\n      hsl(55 100% 62% / 0.45) calc(var(--pl-x) + 4%),\n      hsl(8 100% 64% / 0.5) calc(var(--pl-x) + 11%),\n      transparent calc(var(--pl-x) + 20%)\n    ),\n    linear-gradient(180deg, #ffffff, #bcc4d8);\n  -webkit-background-clip: text;\n  background-clip: text;\n  -webkit-text-fill-color: transparent;\n  filter: drop-shadow(0 0 20px hsl(var(--pl-h) 100% 62% / 0.26));\n}\n",
      "type": "registry:file",
      "target": "components/furin/prism-light/PrismLight.css"
    }
  ]
}
