{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "facet",
  "type": "registry:ui",
  "title": "Facet",
  "description": "A pointer-tracked 3D tilt card with spring-damped rotation and a hard-edged white-silver glare streak that sweeps the surface like light across brushed metal. Tilt disables on touch and under reduced motion, leaving a static subtle glare; a ghost light idles the tilt when untouched.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json",
    "https://crucibleui.com/r/use-visibility-pause.json"
  ],
  "files": [
    {
      "path": "registry/default/cards/facet/facet.tsx",
      "type": "registry:ui",
      "target": "components/crucible/facet.tsx",
      "content": "\"use client\";\n\nimport { motion, useMotionValue, useSpring, type HTMLMotionProps } from \"motion/react\";\nimport * as React from \"react\";\n\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { useVisibilityPause } from \"@/hooks/use-visibility-pause\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FacetProps extends Omit<HTMLMotionProps<\"div\">, \"children\" | \"ref\"> {\n  /** Content to render on the tilting surface. */\n  children: React.ReactNode;\n  /** Maximum rotation, in degrees, on either axis at the card's edge. @default 14 */\n  maxTilt?: number;\n  /** Container perspective distance in px — lower feels more extreme. @default 900 */\n  perspective?: number;\n  /** Peak opacity of the glare streak while hovered. @default 0.7 */\n  glareOpacity?: number;\n  /** Scale applied while hovered/tilting. @default 1.02 */\n  hoverScale?: number;\n  /**\n   * Idle autoplay: after 1.5s with no pointer on the card, a ghost light\n   * slowly rocks it through a shallow tilt with a dimmed glare, so the metal\n   * never reads as dead. A real pointer takes over instantly. Off under\n   * reduced motion; sleeps offscreen. @default true\n   */\n  idle?: boolean;\n}\n\nconst SPRING = { stiffness: 300, damping: 28, mass: 1 };\nconst IDLE_MS = 1500;\n/** Ghost tilt relative to a real pointer — deliberate, never a full hover. */\nconst GHOST_GAIN = 0.45;\n\n/** Stable per-instance phase from React's id, so sibling cards never ghost in lockstep. */\nfunction idPhase(id: string): number {\n  let h = 2166136261;\n  for (let i = 0; i < id.length; i++) h = Math.imul(h ^ id.charCodeAt(i), 16777619);\n  return ((h >>> 0) / 4294967296) * Math.PI * 2;\n}\n\n/**\n * Facet — a card that tilts in 3D toward the pointer with spring-damped\n * rotation, while a hard-edged white-silver anisotropic glare streak sweeps\n * the surface like light across brushed metal. Disables tilt for touch input, and under\n * `prefers-reduced-motion` falls back to a flat card with a static, subtle\n * glare instead of disappearing. Untouched, a ghost light idles the tilt\n * (`idle`) and hands over to the real pointer the moment it arrives.\n */\nexport function Facet({\n  children,\n  className,\n  style,\n  maxTilt = 14,\n  perspective = 900,\n  glareOpacity = 0.7,\n  hoverScale = 1.02,\n  idle = true,\n  ...props\n}: FacetProps) {\n  const reducedMotion = useReducedMotion();\n  const [hovering, setHovering] = React.useState(false);\n  const [ghosting, setGhosting] = React.useState(false);\n  const hoverRef = React.useRef(false);\n  const lastPointerRef = React.useRef(0);\n  const ghostRef = React.useRef({ presence: 0, last: 0, on: false });\n  const phase = idPhase(React.useId());\n\n  const rawRotateX = useMotionValue(0);\n  const rawRotateY = useMotionValue(0);\n  const rotateX = useSpring(rawRotateX, SPRING);\n  const rotateY = useSpring(rawRotateY, SPRING);\n  const scale = useSpring(1, SPRING);\n\n  // Ghost driver: a slow Lissajous light path at reduced strength.\n  // The observed element, mirrored for the rAF tick (set after commit).\n  const elRef = React.useRef<HTMLElement | null>(null);\n  const cardRef = useVisibilityPause<HTMLDivElement>(\n    (elapsed) => {\n      const node = elRef.current;\n      const g = ghostRef.current;\n      if (!node) return;\n      if (elapsed < g.last) g.last = elapsed;\n      const dt = Math.min(elapsed - g.last, 0.05);\n      g.last = elapsed;\n      if (hoverRef.current) {\n        g.presence = 0;\n        if (g.on) {\n          g.on = false;\n          setGhosting(false);\n        }\n        return;\n      }\n      const want = performance.now() - lastPointerRef.current > IDLE_MS ? 1 : 0;\n      g.presence += (want - g.presence) * Math.min(1, dt * 1.6);\n      if (!want && g.presence < 0.01) {\n        if (g.on) {\n          g.on = false;\n          setGhosting(false);\n        }\n        return;\n      }\n      if (!g.on) {\n        g.on = true;\n        setGhosting(true);\n      }\n      const px = 0.5 + 0.36 * Math.sin(elapsed * 0.43 + phase + 0.4);\n      const py = 0.45 + 0.32 * Math.sin(elapsed * 0.31 + 1.9 + phase * 1.7);\n      const k = g.presence * GHOST_GAIN;\n      rawRotateX.set(-(py - 0.5) * 2 * maxTilt * k);\n      rawRotateY.set((px - 0.5) * 2 * maxTilt * k);\n      node.style.setProperty(\"--facet-gx\", `${(px * 100).toFixed(2)}%`);\n      node.style.setProperty(\"--facet-gy\", `${(py * 100).toFixed(2)}%`);\n    },\n    { paused: !idle || reducedMotion }\n  );\n\n  React.useEffect(() => {\n    elRef.current = cardRef.current;\n  });\n\n  // Arm the idle clock at mount (the ghost waits 1.5s before its first pass).\n  React.useEffect(() => {\n    lastPointerRef.current = performance.now();\n  }, []);\n\n  const handlePointerMove = React.useCallback(\n    (event: React.PointerEvent<HTMLDivElement>) => {\n      if (reducedMotion || event.pointerType === \"touch\") return;\n      const node = cardRef.current;\n      if (!node) return;\n      lastPointerRef.current = performance.now();\n      if (!hoverRef.current) {\n        // Pointer started inside the card (no enter event): take over now.\n        hoverRef.current = true;\n        setHovering(true);\n        scale.set(hoverScale);\n      }\n\n      const rect = node.getBoundingClientRect();\n      const px = (event.clientX - rect.left) / rect.width;\n      const py = (event.clientY - rect.top) / rect.height;\n      const cx = px - 0.5;\n      const cy = py - 0.5;\n\n      rawRotateX.set(-cy * 2 * maxTilt);\n      rawRotateY.set(cx * 2 * maxTilt);\n      node.style.setProperty(\"--facet-gx\", `${(px * 100).toFixed(2)}%`);\n      node.style.setProperty(\"--facet-gy\", `${(py * 100).toFixed(2)}%`);\n    },\n    [reducedMotion, maxTilt, rawRotateX, rawRotateY, cardRef, scale, hoverScale]\n  );\n\n  const handlePointerEnter = React.useCallback(\n    (event: React.PointerEvent<HTMLDivElement>) => {\n      if (reducedMotion || event.pointerType === \"touch\") return;\n      hoverRef.current = true;\n      lastPointerRef.current = performance.now();\n      setHovering(true);\n      scale.set(hoverScale);\n    },\n    [reducedMotion, hoverScale, scale]\n  );\n\n  const handlePointerLeave = React.useCallback(() => {\n    hoverRef.current = false;\n    lastPointerRef.current = performance.now();\n    setHovering(false);\n    rawRotateX.set(0);\n    rawRotateY.set(0);\n    scale.set(1);\n  }, [rawRotateX, rawRotateY, scale]);\n\n  return (\n    <motion.div\n      ref={cardRef}\n      data-crucible=\"facet\"\n      onPointerMove={handlePointerMove}\n      onPointerEnter={handlePointerEnter}\n      onPointerLeave={handlePointerLeave}\n      className={cn(\n        \"relative isolate overflow-hidden rounded-2xl border border-white/10 bg-neutral-900\",\n        className\n      )}\n      style={{\n        transformStyle: \"preserve-3d\",\n        // `transformPerspective` bakes perspective() into this element's own\n        // transform. The CSS `perspective` property only affects descendants, so\n        // it never foreshortened the card's own rotateX/rotateY (the tilt read flat).\n        transformPerspective: reducedMotion ? undefined : perspective,\n        rotateX: reducedMotion ? 0 : rotateX,\n        rotateY: reducedMotion ? 0 : rotateY,\n        scale: reducedMotion ? 1 : scale,\n        [\"--facet-gx\" as string]: \"50%\",\n        [\"--facet-gy\" as string]: \"30%\",\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"relative z-10\">{children}</div>\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-300\"\n        style={{\n          opacity: reducedMotion ? 0.12 : hovering ? glareOpacity : ghosting ? glareOpacity * 0.55 : 0,\n          mixBlendMode: \"screen\",\n          background: [\n            \"radial-gradient(360px circle at var(--facet-gx) var(--facet-gy), rgba(255,255,255,0.35), transparent 40%)\",\n            \"linear-gradient(115deg, transparent 40%, rgba(255,255,255,0.5) 47%, rgba(196,204,215,0.38) 50%, rgba(148,158,172,0.34) 53%, transparent 60%)\",\n          ].join(\", \"),\n          backgroundSize: \"auto, 220% 220%\",\n          backgroundPosition: \"var(--facet-gx) var(--facet-gy)\",\n        }}\n      />\n    </motion.div>\n  );\n}\n"
    }
  ]
}