{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tilt-card","type":"registry:ui","title":"Tilt Card","description":"A card that tilts in 3D toward the pointer with a moving glare, then springs back when the pointer leaves.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/tilt-card.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport type { PointerEvent, ReactNode } from \"react\";\n\ntype TiltCardProps = {\n  children: ReactNode;\n  /** Largest tilt on each axis, in degrees. */\n  maxTilt?: number;\n  /** Show a soft highlight that follows the pointer. */\n  glare?: boolean;\n  /** Color of the highlight. */\n  glareColor?: string;\n  /** Scale while the pointer is over the card. */\n  scale?: number;\n  className?: string;\n};\n\nconst SPRING = { stiffness: 240, damping: 22, mass: 0.6 };\n\n/** A card that tilts in 3D toward the pointer with a moving glare, and springs back when the pointer leaves. */\nexport function TiltCard({\n  children,\n  maxTilt = 12,\n  glare = true,\n  glareColor = \"#f4ede3\",\n  scale = 1.03,\n  className = \"\",\n}: TiltCardProps) {\n  const reduce = useReducedMotion();\n  const tilt = reduce ? 0 : maxTilt;\n\n  // Pointer position over the card, 0 to 1 on each axis. It rests at the center.\n  const px = useMotionValue(0.5);\n  const py = useMotionValue(0.5);\n  const over = useMotionValue(0);\n  const sx = useSpring(px, SPRING);\n  const sy = useSpring(py, SPRING);\n  const sOver = useSpring(over, SPRING);\n\n  // The side under the pointer dips away, so the card turns to face it.\n  const rotateX = useTransform(sy, [0, 1], [tilt, -tilt]);\n  const rotateY = useTransform(sx, [0, 1], [-tilt, tilt]);\n  const lift = useTransform(sOver, [0, 1], [1, reduce ? 1 : scale]);\n  const glareOpacity = useTransform(sOver, [0, 1], [0, 0.24]);\n  const gx = useTransform(sx, (v) => `${(v * 100).toFixed(1)}%`);\n  const gy = useTransform(sy, (v) => `${(v * 100).toFixed(1)}%`);\n  const glareBackground = useMotionTemplate`radial-gradient(circle at ${gx} ${gy}, ${glareColor}, transparent 62%)`;\n\n  function track(e: PointerEvent<HTMLDivElement>) {\n    const rect = e.currentTarget.getBoundingClientRect();\n    px.set(Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width)));\n    py.set(Math.min(1, Math.max(0, (e.clientY - rect.top) / rect.height)));\n  }\n\n  function enter(e: PointerEvent<HTMLDivElement>) {\n    over.set(1);\n    track(e);\n  }\n\n  function leave() {\n    over.set(0);\n    px.set(0.5);\n    py.set(0.5);\n  }\n\n  return (\n    // Pointer events live on the flat wrapper, so the hit area does not shift while the card tilts.\n    <div\n      className={`relative ${className}`}\n      style={{ perspective: 900 }}\n      onPointerEnter={enter}\n      onPointerMove={track}\n      onPointerLeave={leave}\n      onPointerCancel={leave}\n    >\n      <motion.div\n        style={{ rotateX, rotateY, scale: lift }}\n        className=\"relative h-full overflow-hidden rounded-3xl border border-ink-600 bg-ink-800 shadow-[0_30px_60px_-30px_rgb(0_0_0/0.85)] will-change-transform\"\n      >\n        {children}\n        {glare ? (\n          <motion.div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute inset-0\"\n            style={{ background: glareBackground, opacity: glareOpacity }}\n          />\n        ) : null}\n      </motion.div>\n    </div>\n  );\n}\n"}]}