{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metal-card",
  "type": "registry:component",
  "title": "Titanium Card",
  "description": "A brushed-titanium card whose reflection shifts as it tilts.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cards"
  ],
  "docs": "Installed in components/furin/metal-card/. Docs, live controls and props table: https://furin.dev/components/metal-card/",
  "files": [
    {
      "path": "registry/metal-card/MetalCard.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./MetalCard.css\";\n\nexport interface MetalCardProps {\n  /** Línea grabada abajo a la izquierda (nombre del titular). */\n  children?: string;\n  /** Marca grabada junto al emblema. */\n  title?: string;\n  /** Texto pequeño grabado abajo a la derecha. */\n  subtitle?: string;\n  /** Muestra el emblema grabado (una campana de viento). */\n  emblem?: boolean;\n  /** Ancho máximo de la tarjeta, en px. */\n  width?: number;\n  /** Inclinación máxima en grados. */\n  tilt?: number;\n  /** Color base del titanio. */\n  color?: string;\n  /** Pulido del reflejo: menor es satinado, mayor es espejo (0 a 1). */\n  gloss?: number;\n  /** Intensidad general de la luz. */\n  intensity?: number;\n  /** Deja que la tarjeta se mece sola cuando no hay cursor. */\n  sweep?: boolean;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\n/* ───────────── Shaders ───────────── */\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\n// Todo el sombreado ocurre en el marco local de la tarjeta (x derecha, y abajo, z hacia el espectador),\n// igual que CSS: así las luces del mundo se ven distintas según cómo esté inclinada.\nconst FRAG = `#version 300 es\nprecision highp float;\nuniform sampler2D u_campo;   // rg: pendientes del grabado, b: cavidad, a: máscara del grabado\nuniform vec2 u_res;\nuniform vec2 u_card;\nuniform float u_rc;\nuniform float u_bw;\nuniform mat3 u_Rt;           // mundo -> tarjeta\nuniform vec3 u_col;\nuniform float u_grain;\nuniform float u_gloss;\nuniform float u_int;\nuniform float u_dpr;\nout vec4 o;\n\nfloat hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\nfloat pn(vec2 p) {\n  vec2 i = floor(p), f = fract(p);\n  f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x), f.y);\n}\nfloat wrapd(float a) { return a - 6.2831853 * floor((a + 3.1415926) / 6.2831853); }\nfloat rbox(float az, float el, float caz, float cel, float hw, float hh, float soft) {\n  float a = abs(wrapd(az - caz)), e = abs(el - cel);\n  return smoothstep(hw + soft, hw - soft, a) * smoothstep(hh + soft, hh - soft, e);\n}\n\n// Estudio (y hacia arriba). \"soft\" ensancha los bordes de las cajas: para la cara cepillada, que difumina.\nvec3 studio(vec3 d, float soft) {\n  float el = asin(clamp(d.y, -1.0, 1.0));\n  float az = atan(d.x, d.z);\n  float up = clamp(el / 1.2, 0.0, 1.0);\n  vec3 sky = mix(vec3(0.62, 0.68, 0.76), vec3(0.10, 0.14, 0.24), pow(up, 0.55));\n  float dn = clamp(-el / 1.1, 0.0, 1.0);\n  vec3 gnd = mix(vec3(0.26, 0.25, 0.25), vec3(0.015, 0.016, 0.02), pow(dn, 0.5));\n  vec3 c = el >= 0.0 ? sky : gnd;\n  c += vec3(1.0, 0.98, 0.94) * 1.4 * exp(-pow(el / (0.03 * soft + 0.01), 2.0));\n  c += vec3(1.00, 0.96, 0.90) * 6.0 * rbox(az, el, -0.80, 0.52, 0.34, 0.22, 0.05 * soft);\n  c += vec3(0.86, 0.93, 1.00) * 5.0 * rbox(az, el, 1.05, 0.30, 0.09, 0.46, 0.04 * soft);\n  c += vec3(1.00) * 3.5 * rbox(az, el, 0.20, 1.10, 0.62, 0.10, 0.05 * soft);\n  c += vec3(1.00, 0.90, 0.80) * 2.5 * rbox(az, el, 2.60, 0.10, 0.10, 0.50, 0.06 * soft);\n  c += vec3(0.80, 0.88, 1.00) * 1.8 * rbox(az, el, -1.90, -0.38, 0.50, 0.07, 0.05 * soft);\n  return c;\n}\n\n// Reflejo anisotrópico (Kajiya-Kay): brilla donde la mitad-vector es perpendicular a la hebra.\nfloat aniso(vec3 T, vec3 L, vec3 V, float sh) {\n  vec3 H = normalize(L + V);\n  float th = dot(T, H);\n  return pow(sqrt(max(1.0 - th * th, 0.0)), sh) * max(L.z, 0.0);\n}\n\nvoid main() {\n  vec2 p = vec2(gl_FragCoord.x, u_res.y - gl_FragCoord.y);\n  vec2 pc = p - 0.5 * u_res;\n  vec2 q = abs(pc) - (0.5 * u_card - u_rc);\n  float sdf = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - u_rc;\n  float cov = clamp(0.5 - sdf, 0.0, 1.0);\n  if (cov <= 0.0) { o = vec4(0.0); return; }\n  float din = -sdf;\n\n  vec4 f = texture(u_campo, p / u_res);\n  vec2 g = f.rg;\n  float cav = f.b;\n  float eng = f.a;\n\n  vec3 pl = vec3(pc / (0.5 * u_card.x), 0.0);\n  vec3 V = normalize(u_Rt * vec3(0.0, 0.0, 5.5) - pl);\n\n  // Hebras del cepillado, horizontales. El grabado es más liso: allí casi no hay hebras.\n  float st = 0.50 * pn(vec2(p.x / (150.0 * u_dpr), p.y / 1.3))\n           + 0.30 * pn(vec2(p.x / (52.0 * u_dpr), p.y / 0.9 + 17.0))\n           + 0.20 * pn(vec2(p.x / (420.0 * u_dpr), p.y / 3.2 + 5.0));\n  float sg = (st - 0.5) * u_grain * (1.0 - 0.8 * eng);\n  vec3 T = normalize(vec3(1.0, 0.0, sg * 0.55));\n  vec3 N = normalize(vec3(-g.x, -g.y + sg * 0.35, 1.0));\n\n  // Tres luces puntuales fijas en el mundo; cada una se vuelve a expresar en el marco de la tarjeta.\n  vec3 lk = normalize(u_Rt * vec3(-1.7, -1.5, 1.7) - pl);\n  vec3 l2 = normalize(u_Rt * vec3(2.0, -0.5, 1.5) - pl);\n  vec3 l3 = normalize(u_Rt * vec3(0.5, 1.8, 1.3) - pl);\n  float core = aniso(T, lk, V, mix(30.0, 300.0, u_gloss)) * 1.9;\n  float halo = aniso(T, lk, V, mix(8.0, 38.0, u_gloss)) * 0.5;\n  float s2 = aniso(T, l2, V, mix(10.0, 60.0, u_gloss)) * 0.55;\n  float s3 = aniso(T, l3, V, mix(10.0, 60.0, u_gloss)) * 0.38;\n\n  vec3 white = mix(u_col, vec3(1.0), 0.4);\n  vec3 Rl = reflect(-V, N);\n  vec3 Rw = transpose(u_Rt) * Rl;\n  vec3 envF = studio(vec3(Rw.x, -Rw.y, Rw.z), 1.6);\n  float ndv = max(dot(N, V), 0.0);\n  vec3 Fr = u_col + (1.0 - u_col) * pow(1.0 - ndv, 5.0);\n\n  vec3 face = u_col * 0.13 * (1.0 + sg * 1.6);\n  face += white * (core + halo + s2 + s3);\n  face += envF * Fr * 0.30;\n  // Grabado: el fondo es más oscuro y las paredes que miran a la luz se encienden.\n  float wall = clamp(length(g) * 0.4, 0.0, 1.0);\n  float lit = dot(normalize(-g + vec2(1e-4)), lk.xy);\n  face *= 1.0 - 0.30 * eng - 0.40 * cav;\n  face *= 1.0 + wall * lit * 1.2;\n  face += white * wall * max(lit, 0.0) * 0.55;\n\n  // Bisel pulido de 45 grados: espejo que refleja el estudio con bordes nítidos.\n  vec2 g2 = (q.x > 0.0 && q.y > 0.0) ? normalize(q) : (q.x > q.y ? vec2(1.0, 0.0) : vec2(0.0, 1.0));\n  vec3 Nc = normalize(vec3(g2 * sign(pc) * 0.85, 0.55));\n  vec3 Rc = transpose(u_Rt) * reflect(-V, Nc);\n  vec3 envC = studio(vec3(Rc.x, -Rc.y, Rc.z), 0.4);\n  float ndc = max(dot(Nc, V), 0.0);\n  vec3 Fc = u_col + (1.0 - u_col) * pow(1.0 - ndc, 5.0);\n  vec3 chamfer = envC * Fc * 1.15;\n  chamfer += white * pow(max(dot(Nc, normalize(lk + V)), 0.0), 110.0) * 1.6;\n  float cm = smoothstep(u_bw + 0.75, u_bw - 0.75, din);\n\n  vec3 col = mix(face, chamfer, cm);\n  col *= 1.0 - 0.42 * exp(-pow((din - u_bw) / 0.9, 2.0));   // surco fino entre bisel y cara\n  col += white * 0.22 * exp(-din * din / 1.4);             // brillo del canto exterior\n  col *= u_int;\n  col = 1.0 - exp(-col * 1.7);\n  col = pow(col, vec3(0.94));\n  col += (hash(gl_FragCoord.xy + 3.7) - 0.5) / 255.0;\n  o = vec4(col * cov, cov);\n}`;\n\n/* ───────────── Campo del grabado (CPU) ───────────── */\n\nconst INF = 1e20;\n\n/** Transformada de distancia euclídea (Felzenszwalb): distancia² de cada píxel de \"dentro\" al \"fuera\" más cercano. */\nfunction edt(inside: Uint8Array, w: number, h: number): Float32Array {\n  const g = new Float32Array(w * h);\n  for (let i = 0; i < g.length; i++) g[i] = inside[i] ? INF : 0;\n  const n = Math.max(w, h);\n  const f = new Float32Array(n), d = new Float32Array(n), z = new Float32Array(n + 1), v = new Int32Array(n);\n  const pasada = (len: number) => {\n    let k = 0;\n    v[0] = 0; z[0] = -INF; z[1] = INF;\n    for (let q = 1; q < len; q++) {\n      let s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]);\n      while (s <= z[k]) { k--; s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]); }\n      k++; v[k] = q; z[k] = s; z[k + 1] = INF;\n    }\n    k = 0;\n    for (let q = 0; q < len; q++) {\n      while (z[k + 1] < q) k++;\n      d[q] = (q - v[k]) * (q - v[k]) + f[v[k]];\n    }\n  };\n  for (let x = 0; x < w; x++) {\n    for (let y = 0; y < h; y++) f[y] = g[y * w + x];\n    pasada(h);\n    for (let y = 0; y < h; y++) g[y * w + x] = d[y];\n  }\n  for (let y = 0; y < h; y++) {\n    for (let x = 0; x < w; x++) f[x] = g[y * w + x];\n    pasada(w);\n    for (let x = 0; x < w; x++) g[y * w + x] = d[x];\n  }\n  return g;\n}\n\n/** Desenfoque de caja separable (varias pasadas ≈ gaussiana). Modifica y devuelve `a`. */\nfunction blur(a: Float32Array, w: number, h: number, r: number, pasadas = 3): Float32Array {\n  r = Math.max(1, Math.round(r));\n  const t = new Float32Array(Math.max(w, h));\n  const inv = 1 / (2 * r + 1);\n  for (let p = 0; p < pasadas; p++) {\n    for (let y = 0; y < h; y++) {\n      const o = y * w;\n      let s = 0;\n      for (let i = -r; i <= r; i++) s += a[o + Math.min(w - 1, Math.max(0, i))];\n      for (let x = 0; x < w; x++) {\n        t[x] = s * inv;\n        s += a[o + Math.min(w - 1, x + r + 1)] - a[o + Math.max(0, x - r)];\n      }\n      for (let x = 0; x < w; x++) a[o + x] = t[x];\n    }\n    for (let x = 0; x < w; x++) {\n      let s = 0;\n      for (let i = -r; i <= r; i++) s += a[Math.min(h - 1, Math.max(0, i)) * w + x];\n      for (let y = 0; y < h; y++) {\n        t[y] = s * inv;\n        s += a[Math.min(h - 1, y + r + 1) * w + x] - a[Math.max(0, y - r) * w + x];\n      }\n      for (let y = 0; y < h; y++) a[y * w + x] = t[y];\n    }\n  }\n  return a;\n}\n\ninterface Textos { title: string; subtitle: string; holder: string; emblem: boolean; family: string }\n\n/** Una campana de viento (furin) hecha solo con curvas y círculos. */\nfunction campana(ctx: CanvasRenderingContext2D, cx: number, cy: number, r: number) {\n  ctx.beginPath();\n  ctx.moveTo(cx - 0.95 * r, cy + 0.55 * r);\n  ctx.bezierCurveTo(cx - 0.95 * r, cy - 0.25 * r, cx - 0.55 * r, cy - 0.85 * r, cx, cy - 0.85 * r);\n  ctx.bezierCurveTo(cx + 0.55 * r, cy - 0.85 * r, cx + 0.95 * r, cy - 0.25 * r, cx + 0.95 * r, cy + 0.55 * r);\n  ctx.lineTo(cx + 1.15 * r, cy + 0.74 * r);\n  ctx.lineTo(cx - 1.15 * r, cy + 0.74 * r);\n  ctx.closePath();\n  ctx.fill();\n  ctx.beginPath(); ctx.arc(cx, cy + 1.14 * r, 0.21 * r, 0, Math.PI * 2); ctx.fill();\n  ctx.beginPath(); ctx.arc(cx, cy - 1.02 * r, 0.14 * r, 0, Math.PI * 2); ctx.fill();\n}\n\ninterface Campo { w: number; h: number; datos: Float32Array }\n\n/** Dibuja el logo y los textos como máscara y la convierte en un grabado: pendientes de las paredes, cavidad y máscara. */\nfunction construirCampo(cw: number, ch: number, pad: number, dpr: number, t: Textos): Campo {\n  const W = Math.max(8, Math.ceil((cw + pad * 2) * dpr)), H = Math.max(8, Math.ceil((ch + pad * 2) * dpr));\n  const cv = document.createElement(\"canvas\");\n  cv.width = W; cv.height = H;\n  const ctx = cv.getContext(\"2d\", { willReadFrequently: true })!;\n  const u = cw * dpr;                 // ancho de la tarjeta en px de dispositivo\n  const ox = pad * dpr, oy = pad * dpr;\n  const m = 0.075 * u;\n  ctx.fillStyle = \"#fff\";\n  const setLs = (em: number, size: number) => { if (\"letterSpacing\" in ctx) (ctx as unknown as { letterSpacing: string }).letterSpacing = `${em * size}px`; };\n\n  const r = 0.05 * u;\n  const cyTop = oy + m + 0.045 * u;\n  if (t.emblem) campana(ctx, ox + m + r, cyTop - 0.1 * r, r);\n  ctx.textBaseline = \"middle\";\n  ctx.textAlign = \"left\";\n  let fs = 0.06 * u;\n  ctx.font = `600 ${fs}px ${t.family}`;\n  setLs(0.22, fs);\n  ctx.fillText(t.title, ox + m + (t.emblem ? 2.9 * r : 0), cyTop);\n\n  // Símbolo de pago sin contacto: cuatro arcos concéntricos hechos con trazos redondeados.\n  ctx.save();\n  ctx.strokeStyle = \"#fff\";\n  ctx.lineWidth = 0.0068 * u;\n  ctx.lineCap = \"round\";\n  const ax = ox + u - m - 0.052 * u;\n  for (let i = 0; i < 4; i++) {\n    const rr = (0.012 + i * 0.0155) * u;\n    ctx.beginPath();\n    ctx.arc(ax - 0.014 * u, cyTop, rr, -0.62, 0.62);\n    ctx.stroke();\n  }\n  ctx.restore();\n\n  const base = oy + ch * dpr - m * 0.95;\n  ctx.textBaseline = \"alphabetic\";\n  fs = 0.05 * u;\n  ctx.font = `500 ${fs}px ${t.family}`;\n  setLs(0.16, fs);\n  ctx.fillText(t.holder, ox + m, base);\n  fs = 0.03 * u;\n  ctx.font = `500 ${fs}px ${t.family}`;\n  setLs(0.34, fs);\n  ctx.textAlign = \"right\";\n  ctx.fillText(t.subtitle, ox + u - m + 0.34 * fs, base);\n\n  const img = ctx.getImageData(0, 0, W, H).data;\n  const n = W * H;\n  const alfa = new Float32Array(n);\n  const dentro = new Uint8Array(n);\n  for (let i = 0; i < n; i++) { alfa[i] = img[i * 4 + 3] / 255; dentro[i] = alfa[i] > 0.5 ? 1 : 0; }\n\n  // Grabado: perfil de cuarto de círculo hacia abajo desde el borde (pared empinada y fondo plano).\n  const R = Math.max(2, 0.0075 * u);\n  const d2 = edt(dentro, W, H);\n  const hgt = new Float32Array(n);\n  const cav = new Float32Array(n);\n  for (let i = 0; i < n; i++) {\n    if (!dentro[i]) continue;\n    const dist = Math.max(0, Math.sqrt(d2[i]) - 0.5);\n    const tt = Math.min(1, dist / R);\n    hgt[i] = -R * Math.sqrt(1 - (1 - tt) * (1 - tt));\n    cav[i] = Math.exp(-dist / (R * 1.6));\n  }\n  blur(hgt, W, H, Math.max(1, R * 0.28), 2);\n\n  const datos = new Float32Array(n * 4);\n  for (let y = 0; y < H; y++) {\n    for (let x = 0; x < W; x++) {\n      const i = y * W + x;\n      const xl = hgt[y * W + Math.max(0, x - 1)], xr = hgt[y * W + Math.min(W - 1, x + 1)];\n      const yu = hgt[Math.max(0, y - 1) * W + x], yd = hgt[Math.min(H - 1, y + 1) * W + x];\n      const o = i * 4;\n      datos[o] = Math.max(-5, Math.min(5, (xr - xl) * 0.5));\n      datos[o + 1] = Math.max(-5, Math.min(5, (yd - yu) * 0.5));\n      datos[o + 2] = cav[i];\n      datos[o + 3] = alfa[i];\n    }\n  }\n  return { w: W, h: H, datos };\n}\n\n/* ───────────── Utilidades ───────────── */\n\nfunction colorARgb(css: string): [number, number, number] {\n  try {\n    const c = document.createElement(\"canvas\");\n    c.width = c.height = 1;\n    const x = c.getContext(\"2d\", { willReadFrequently: true })!;\n    x.fillStyle = \"#80838a\";\n    x.fillStyle = css;\n    x.fillRect(0, 0, 1, 1);\n    const d = x.getImageData(0, 0, 1, 1).data;\n    return [d[0] / 255, d[1] / 255, d[2] / 255];\n  } catch {\n    return [0.56, 0.57, 0.6];\n  }\n}\n\nfunction compilar(gl: WebGL2RenderingContext, vs: string, fs: string): WebGLProgram | null {\n  const mk = (tipo: number, src: string) => {\n    const s = gl.createShader(tipo)!;\n    gl.shaderSource(s, src);\n    gl.compileShader(s);\n    if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) { console.error(gl.getShaderInfoLog(s)); return null; }\n    return s;\n  };\n  const a = mk(gl.VERTEX_SHADER, vs), b = mk(gl.FRAGMENT_SHADER, fs);\n  if (!a || !b) return null;\n  const p = gl.createProgram()!;\n  gl.attachShader(p, a); gl.attachShader(p, b);\n  gl.linkProgram(p);\n  gl.deleteShader(a); gl.deleteShader(b);\n  if (!gl.getProgramParameter(p, gl.LINK_STATUS)) { console.error(gl.getProgramInfoLog(p)); return null; }\n  return p;\n}\n\ntype M3 = number[];\nconst mul = (A: M3, B: M3): M3 => {\n  const C = new Array(9).fill(0);\n  for (let r = 0; r < 3; r++) for (let c = 0; c < 3; c++) for (let k = 0; k < 3; k++) C[r * 3 + c] += A[r * 3 + k] * B[k * 3 + c];\n  return C;\n};\n\n/** Matriz mundo→tarjeta (la transpuesta de rotateX(a) rotateY(b) de CSS), en columnas para WebGL. */\nfunction matrizInversa(aDeg: number, bDeg: number): Float32Array {\n  const a = (aDeg * Math.PI) / 180, b = (bDeg * Math.PI) / 180;\n  const ca = Math.cos(a), sa = Math.sin(a), cb = Math.cos(b), sb = Math.sin(b);\n  const Rx: M3 = [1, 0, 0, 0, ca, -sa, 0, sa, ca];\n  const Ry: M3 = [cb, 0, sb, 0, 1, 0, -sb, 0, cb];\n  const M = mul(Rx, Ry);\n  // Transpuesta, guardada por columnas: columna c de Mt = fila c de M.\n  return new Float32Array([M[0], M[1], M[2], M[3], M[4], M[5], M[6], M[7], M[8]]);\n}\n\nconst PAD = 8;\n\n/** Tarjeta de titanio cepillado: bisel pulido, logo grabado y un reflejo que viaja al inclinarla con el cursor. */\nexport function MetalCard({\n  children = \"MARIANA RIVERA\",\n  title = \"FURIN\",\n  subtitle = \"TITANIUM\",\n  emblem = true,\n  width = 400,\n  tilt = 16,\n  color = \"#80838a\",\n  gloss = 0.6,\n  intensity = 1,\n  sweep = true,\n  className = \"\",\n  style,\n}: MetalCardProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const tiltRef = useRef<HTMLDivElement>(null);\n  const sombraRef = useRef<HTMLDivElement>(null);\n  const vivo = useRef<{ rebuild: () => void; wake: () => void } | null>(null);\n  const props = useRef({ children, title, subtitle, emblem, tilt, color, gloss, intensity, sweep });\n  props.current = { children, title, subtitle, emblem, tilt, color, gloss, intensity, sweep };\n\n  useEffect(() => {\n    const root = rootRef.current, tiltEl = tiltRef.current, sombra = sombraRef.current;\n    if (!root || !tiltEl || !sombra) return;\n    const canvas = document.createElement(\"canvas\");\n    canvas.className = \"furin-metal-card__lienzo\";\n    canvas.setAttribute(\"aria-hidden\", \"true\");\n    const gl = canvas.getContext(\"webgl2\", { alpha: true, premultipliedAlpha: true, antialias: false });\n    if (!gl) return; // sin WebGL2 queda la placa de CSS\n    tiltEl.appendChild(canvas);\n\n    const reducido = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let prog: WebGLProgram | null = null;\n    let tex: WebGLTexture | null = null;\n    let U: Record<string, WebGLUniformLocation | null> = {};\n    let listo = false;\n    let visible = true;\n    let raf = 0;\n    let muerto = false;\n    let dpr = 1, cssW = 0, cssH = 0;\n\n    const iniciarGl = () => {\n      prog = compilar(gl, VERT, FRAG);\n      if (!prog) return;\n      for (const k of [\"u_campo\", \"u_res\", \"u_card\", \"u_rc\", \"u_bw\", \"u_Rt\", \"u_col\", \"u_grain\", \"u_gloss\", \"u_int\", \"u_dpr\"]) U[k] = gl.getUniformLocation(prog, k);\n      tex = gl.createTexture();\n      gl.useProgram(prog);\n      gl.uniform1i(U.u_campo, 0);\n      gl.disable(gl.DEPTH_TEST);\n      gl.disable(gl.BLEND);\n    };\n\n    // Estado de la inclinación (grados): un resorte por eje hacia el cursor, o hacia un balanceo lento.\n    const est = { rx: -3, ry: 6, vx: 0, vy: 0, tx: -3, ty: 6, sc: 1, vs: 0, tsc: 1, auto: true, t0: performance.now(), ult: 0 };\n\n    const aplicar = () => {\n      tiltEl.style.transform = `rotateX(${est.rx.toFixed(3)}deg) rotateY(${est.ry.toFixed(3)}deg) scale(${est.sc.toFixed(4)})`;\n      // La sombra se corre y se abre con la inclinación, como si la tarjeta flotara sobre la mesa.\n      sombra.style.transform = `translate(${(5 - est.ry * 0.9).toFixed(2)}px, ${(12 + est.rx * 0.9).toFixed(2)}px) scale(${(1 + (est.sc - 1) * 2).toFixed(4)})`;\n      sombra.style.opacity = String((0.5 + Math.min(0.2, (Math.abs(est.rx) + Math.abs(est.ry)) * 0.008)).toFixed(3));\n    };\n\n    const pintar = () => {\n      if (!prog || !listo || gl.isContextLost()) return;\n      const p = props.current;\n      gl.viewport(0, 0, canvas.width, canvas.height);\n      gl.useProgram(prog);\n      gl.uniform2f(U.u_res, canvas.width, canvas.height);\n      gl.uniform2f(U.u_card, cssW * dpr, cssH * dpr);\n      gl.uniform1f(U.u_rc, cssW * dpr * 0.037);\n      gl.uniform1f(U.u_bw, Math.max(2, cssW * dpr * 0.0075));\n      gl.uniformMatrix3fv(U.u_Rt, false, matrizInversa(est.rx, est.ry));\n      const [r, g, b] = colorARgb(p.color);\n      gl.uniform3f(U.u_col, r, g, b);\n      gl.uniform1f(U.u_grain, 0.65);\n      gl.uniform1f(U.u_gloss, p.gloss);\n      gl.uniform1f(U.u_int, p.intensity);\n      gl.uniform1f(U.u_dpr, dpr);\n      gl.clearColor(0, 0, 0, 0);\n      gl.clear(gl.COLOR_BUFFER_BIT);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const rebuild = () => {\n      if (muerto || gl.isContextLost() || !prog) return;\n      const p = props.current;\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      cssW = root.offsetWidth; cssH = root.offsetHeight;\n      if (!cssW || !cssH) return;\n      const campo = construirCampo(cssW, cssH, PAD, dpr, {\n        title: p.title, subtitle: p.subtitle, holder: p.children, emblem: p.emblem,\n        family: getComputedStyle(root).fontFamily,\n      });\n      canvas.width = campo.w; canvas.height = campo.h;\n      canvas.style.width = `${cssW + PAD * 2}px`;\n      canvas.style.height = `${cssH + PAD * 2}px`;\n      canvas.style.left = `${-PAD}px`;\n      canvas.style.top = `${-PAD}px`;\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D, tex);\n      gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, campo.w, campo.h, 0, gl.RGBA, gl.FLOAT, campo.datos);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n      listo = true;\n      aplicar();\n      pintar();\n      root.setAttribute(\"data-gl\", \"1\");\n      wake();\n    };\n\n    // ── Bucle: duerme fuera de pantalla o cuando el resorte se asentó ──\n    const balanceo = () => !!props.current.sweep && est.auto && !reducido;\n    const quieto = () => !balanceo() && Math.abs(est.vx) + Math.abs(est.vy) + Math.abs(est.vs) < 1e-2 && Math.abs(est.tx - est.rx) + Math.abs(est.ty - est.ry) + Math.abs(est.tsc - est.sc) * 100 < 2e-2;\n    const paso = (now: number) => {\n      raf = 0;\n      if (muerto || !visible || !listo) return;\n      const dt = Math.min(0.05, (now - (est.ult || now)) / 1000 || 0.016);\n      est.ult = now;\n      const T = props.current.tilt;\n      if (balanceo()) {\n        const t = (now - est.t0) / 1000;\n        est.tx = -Math.cos(t * 0.45) * 0.42 * T - 0.1 * T;\n        est.ty = Math.sin(t * 0.62) * 0.6 * T;\n      }\n      // Resorte subamortiguado: la tarjeta llega con un pequeño rebote, como un objeto con peso.\n      const k = 150, c = 17;\n      est.vx += ((est.tx - est.rx) * k - est.vx * c) * dt;\n      est.vy += ((est.ty - est.ry) * k - est.vy * c) * dt;\n      est.vs += ((est.tsc - est.sc) * 260 - est.vs * 22) * dt;\n      est.rx += est.vx * dt;\n      est.ry += est.vy * dt;\n      est.sc += est.vs * dt;\n      aplicar();\n      pintar();\n      if (!quieto()) raf = requestAnimationFrame(paso);\n      else est.ult = 0;\n    };\n    const wake = () => { if (!raf && visible && listo && !muerto && !reducido) { est.ult = 0; raf = requestAnimationFrame(paso); } };\n\n    // ── Cursor: la tarjeta se inclina hacia donde está, aunque el mouse ande cerca ──\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      if (!r.width) return;\n      const dx = Math.max(-1, Math.min(1, (e.clientX - (r.left + r.width / 2)) / (r.width * 0.9)));\n      const dy = Math.max(-1, Math.min(1, (e.clientY - (r.top + r.height / 2)) / (r.height * 1.3)));\n      const T = props.current.tilt;\n      // Metáfora de \"presionar\": el lado donde está el cursor se hunde.\n      est.ty = dx * T;\n      est.tx = -dy * T;\n      const dentro = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;\n      est.tsc = dentro ? 1.025 : 1;\n      est.auto = false;\n      wake();\n    };\n    const onLeave = () => { est.auto = true; est.tsc = 1; est.t0 = performance.now(); wake(); };\n    const onUp = (e: PointerEvent) => { if (e.pointerType !== \"mouse\") onLeave(); };\n    if (!reducido) {\n      window.addEventListener(\"pointermove\", onMove, { passive: true });\n      window.addEventListener(\"pointerdown\", onMove, { passive: true });\n      window.addEventListener(\"pointerup\", onUp, { passive: true });\n      document.documentElement.addEventListener(\"pointerleave\", onLeave);\n    }\n\n    const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; if (visible) wake(); }, { rootMargin: \"80px\" });\n    io.observe(root);\n    let pend = 0;\n    const pedirRebuild = () => { cancelAnimationFrame(pend); pend = requestAnimationFrame(rebuild); };\n    const ro = new ResizeObserver(pedirRebuild);\n    ro.observe(root);\n    document.fonts?.ready.then(pedirRebuild);\n    document.fonts?.addEventListener?.(\"loadingdone\", pedirRebuild);\n\n    canvas.addEventListener(\"webglcontextlost\", (e) => { e.preventDefault(); listo = false; cancelAnimationFrame(raf); raf = 0; });\n    canvas.addEventListener(\"webglcontextrestored\", () => { U = {}; iniciarGl(); rebuild(); });\n\n    iniciarGl();\n    vivo.current = { rebuild, wake };\n    rebuild();\n\n    return () => {\n      muerto = true;\n      vivo.current = null;\n      cancelAnimationFrame(raf);\n      cancelAnimationFrame(pend);\n      io.disconnect(); ro.disconnect();\n      document.fonts?.removeEventListener?.(\"loadingdone\", pedirRebuild);\n      window.removeEventListener(\"pointermove\", onMove);\n      window.removeEventListener(\"pointerdown\", onMove);\n      window.removeEventListener(\"pointerup\", onUp);\n      document.documentElement.removeEventListener(\"pointerleave\", onLeave);\n      root.removeAttribute(\"data-gl\");\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    };\n  }, []);\n\n  useEffect(() => { vivo.current?.rebuild(); }, [children, title, subtitle, emblem, width, tilt, color, gloss, intensity, sweep]);\n\n  const etiqueta = [title, children, subtitle].filter(Boolean).join(\" · \");\n  return (\n    <div\n      ref={rootRef}\n      className={`furin-metal-card ${className}`}\n      style={{ \"--furin-mc-w\": `${width}px`, ...style } as CSSProperties}\n      role=\"img\"\n      aria-label={etiqueta}\n    >\n      <div ref={sombraRef} className=\"furin-metal-card__sombra\" aria-hidden=\"true\" />\n      <div ref={tiltRef} className=\"furin-metal-card__inclinar\" />\n    </div>\n  );\n}\n\nexport default MetalCard;\n",
      "type": "registry:component",
      "target": "components/furin/metal-card/MetalCard.tsx"
    },
    {
      "path": "registry/metal-card/MetalCard.css",
      "content": ".furin-metal-card {\n  position: relative;\n  width: min(100%, var(--furin-mc-w, 400px));\n  aspect-ratio: 1.586 / 1;\n  perspective: 1100px;\n  font-family: \"Geist\", \"Inter\", \"SF Pro Display\", system-ui, -apple-system, \"Helvetica Neue\", Arial, sans-serif;\n  touch-action: pan-y;\n  -webkit-tap-highlight-color: transparent;\n}\n/* Sombra de contacto: se desplaza y se abre según la inclinación. */\n.furin-metal-card__sombra {\n  position: absolute;\n  inset: 8% 6% 0;\n  border-radius: 6%;\n  background: rgba(0, 0, 0, 0.7);\n  filter: blur(26px);\n  opacity: 0.55;\n  will-change: transform, opacity;\n  pointer-events: none;\n}\n.furin-metal-card__inclinar {\n  position: absolute;\n  inset: 0;\n  transform-style: preserve-3d;\n  will-change: transform;\n}\n/* Mientras WebGL no llega (o no existe) queda una placa de CSS con el mismo aire. */\n.furin-metal-card:not([data-gl]) .furin-metal-card__inclinar {\n  border-radius: 3.7% / 5.9%;\n  background:\n    linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.28) 48%, transparent 60%),\n    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 1px, rgba(0, 0, 0, 0.05) 1px 2px),\n    linear-gradient(160deg, #9a9ca2, #5b5d63);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);\n}\n.furin-metal-card__lienzo {\n  position: absolute;\n  pointer-events: none;\n  display: block;\n}\n",
      "type": "registry:file",
      "target": "components/furin/metal-card/MetalCard.css"
    }
  ]
}
