{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tilt-card-with-a-moving-glare-layer","type":"registry:block","title":"Tilt Card With a Moving Glare Layer","description":"","dependencies":[],"files":[{"path":"components/we-inc/tilt-card-with-a-moving-glare-layer.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst MAX_TILT = 10; // degrees at the card's edge\nconst GLARE = 0.55; // brightest glare opacity\n\nexport default function TiltCardWithAMovingGlareLayer() {\n  const root = useRef<HTMLElement>(null);\n  const card = useRef<HTMLAnchorElement>(null);\n  const glare = useRef<HTMLSpanElement>(null);\n\n  useEffect(() => {\n    const el = root.current, c = card.current, g = glare.current;\n    if (!el || !c || !g) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const fine = window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches;\n    let tx = 0, ty = 0, x = 0, y = 0, live = false, frame = 0, visible = true;\n    const move = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") return;\n      const r = c.getBoundingClientRect();\n      // -1..1 across the card, clamped so the tilt eases off outside it\n      tx = Math.max(-1, Math.min(1, ((e.clientX - r.left) / r.width) * 2 - 1));\n      ty = Math.max(-1, Math.min(1, ((e.clientY - r.top) / r.height) * 2 - 1));\n      live = true;\n    };\n    const leave = () => { live = false; };\n    const tick = (now: number) => {\n      if (!live) { tx = Math.sin(now / 2100) * 0.8; ty = Math.sin(now / 1500 + 1) * 0.6; }\n      x += (tx - x) * 0.08;\n      y += (ty - y) * 0.08;\n      c.style.transform = `rotateX(${(-y * MAX_TILT).toFixed(2)}deg) rotateY(${(x * MAX_TILT).toFixed(2)}deg)`;\n      g.style.transform = `translate(${(x * 30).toFixed(1)}%, ${(y * 30).toFixed(1)}%)`;\n      g.style.opacity = (GLARE * (0.35 + 0.65 * Math.min(1, Math.hypot(x, y)))).toFixed(3);\n      frame = requestAnimationFrame(tick);\n    };\n    const play = () => { if (!frame && visible) frame = requestAnimationFrame(tick); };\n    const stop = () => { cancelAnimationFrame(frame); frame = 0; };\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) play(); else stop(); });\n    io.observe(el);\n    if (fine) { el.addEventListener(\"pointermove\", move); el.addEventListener(\"pointerleave\", leave); }\n    play();\n    return () => {\n      stop();\n      io.disconnect();\n      el.removeEventListener(\"pointermove\", move);\n      el.removeEventListener(\"pointerleave\", leave);\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"bg-[#26282b] px-5 py-16 sm:py-20\">\n      <style>{`\n        .w3tlt-stage { perspective: 900px; }\n        .w3tlt-card { transform-style: preserve-3d; will-change: transform; }\n        .w3tlt-glare { opacity: .25; background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.55), rgba(255,255,255,0) 45%); }\n        .w3tlt-card:focus-visible { outline: 2px solid #f1efe9; outline-offset: 6px; }\n        @media (prefers-reduced-motion: reduce) { .w3tlt-card { transform: rotateX(4deg) rotateY(-6deg) !important; will-change: auto; } .w3tlt-glare { transform: translate(-15%, -15%) !important; } }\n      `}</style>\n      <div className=\"mx-auto grid max-w-5xl items-center gap-12 md:grid-cols-2\">\n        <div className=\"text-[#f1efe9]\">\n          <p className=\"text-xs font-semibold uppercase tracking-[0.25em] text-[#b5b0a5]\">Ashgrove Bouldering</p>\n          <h2 className=\"mt-4 text-3xl font-semibold leading-tight tracking-tight sm:text-4xl\">One card for every wall in the city.</h2>\n          <p className=\"mt-5 max-w-md text-base leading-relaxed text-[#c9c5bc]\">Unlimited visits to our three gyms, two guest passes a month and shoe hire included.</p>\n        </div>\n        <div className=\"w3tlt-stage flex justify-center\">\n          <a\n            ref={card}\n            href=\"#\"\n            aria-label=\"Ashgrove all-gyms membership, 58 dollars a month, view details\"\n            className=\"w3tlt-card relative block aspect-[1.586] w-full max-w-sm overflow-hidden rounded-2xl bg-gradient-to-br from-[#4a4d52] via-[#2f3135] to-[#1b1c1f] p-6 text-[#f1efe9] shadow-[0_30px_60px_-20px_rgba(0,0,0,0.6)] ring-1 ring-white/10\"\n          >\n            <span aria-hidden=\"true\" className=\"absolute inset-0 opacity-30\" style={{ backgroundImage: \"repeating-linear-gradient(115deg, rgba(255,255,255,0.05) 0 2px, transparent 2px 9px)\" }} />\n            <span aria-hidden=\"true\" className=\"relative flex h-full flex-col justify-between\">\n              <span className=\"flex items-start justify-between\">\n                <span className=\"text-sm font-semibold uppercase tracking-[0.2em]\">Ashgrove</span>\n                <svg viewBox=\"0 0 32 24\" className=\"h-6 w-8\" fill=\"none\" stroke=\"#d6c49a\" strokeWidth=\"1.6\"><path d=\"M2 22 L11 6 L17 15 L21 9 L30 22 Z\" /></svg>\n              </span>\n              <span>\n                <span className=\"block text-xs uppercase tracking-[0.2em] text-[#c9c5bc]\">All gyms · monthly</span>\n                <span className=\"mt-1 flex items-end justify-between\">\n                  <span className=\"text-2xl font-semibold\">$58</span>\n                  <span className=\"font-mono text-sm tracking-widest text-[#d6c49a]\">No. 0412</span>\n                </span>\n              </span>\n            </span>\n            <span ref={glare} aria-hidden=\"true\" className=\"w3tlt-glare pointer-events-none absolute -inset-1/2\" />\n          </a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
