{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"gift-card-with-a-silver-scratch-off-panel-a-brass-coin-and-foil-crumbs-that-scatter-as-you-rub","type":"registry:block","title":"Gift Card with a Silver Scratch off Panel, a Brass Coin and Foil Crumbs That Scatter as You Rub","description":"Scratch card on a canvas: rub the silver panel of a gift card with a brass coin and the foil comes off in streaks and crumbs. Free React and HTML to copy.","dependencies":[],"files":[{"path":"components/we-inc/gift-card-with-a-silver-scratch-off-panel-a-brass-coin-and-foil-crumbs-that-scatter-as-you-rub.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// The card. `codes` are handed out one per card dealt, then start again.\nconst gift = {\n  shop: \"Fenn & Marlowe\",\n  trade: \"FLORISTS\",\n  amount: \"$60\",\n  line: \"of seasonal stems, tied and delivered\",\n  hint: \"SCRATCH FOR YOUR CODE\",\n  coin: \"FM\",\n  photo: \"https://images.pexels.com/photos/11731228/pexels-photo-11731228.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n  alt: \"Pink, yellow and white ranunculus heads laid together on a dark cloth\",\n  tone: \"#3a2b2f\",\n  codes: [\"FM-7Q4K-92TD\", \"FM-3HX8-51LW\", \"FM-9BN2-06RC\"],\n};\nconst W = 460; // card size in CSS pixels\nconst H = 292;\nconst PANEL = { x: 206, y: 213, w: 232, h: 54 }; // the foil, measured from the card's top left\nconst TILT = -5; // degrees the card lies at on the table\nconst MARGIN = 150; // how far crumbs may travel past the card edge\nconst START_FILLED = 0.56; // how much of the panel is already scratched when the page loads\n\ntype Crumb = { x: number; y: number; vx: number; vy: number; r: number; a: number; va: number; curl: number; shade: number; flake: boolean; still: boolean };\n\nexport default function ScratchOffGiftCard() {\n  const root = useRef<HTMLDivElement>(null);\n  const fitBox = useRef<HTMLDivElement>(null);\n  const cardEl = useRef<HTMLDivElement>(null);\n  const foil = useRef<HTMLCanvasElement>(null);\n  const crumbsEl = useRef<HTMLCanvasElement>(null);\n  const coinEl = useRef<HTMLDivElement>(null);\n  const [scale, setScale] = useState(1);\n  const [deal, setDeal] = useState(0);\n  const [revealed, setRevealed] = useState(false);\n  const api = useRef<{ rub: () => void; fresh: () => void } | null>(null);\n  const code = gift.codes[deal % gift.codes.length];\n\n  useEffect(() => {\n    const el = root.current, box = fitBox.current, cv = foil.current, cc = crumbsEl.current, coin = coinEl.current, cardNode = cardEl.current;\n    if (!el || !box || !cv || !cc || !coin || !cardNode) return;\n    const ctx = cv.getContext(\"2d\"), cx = cc.getContext(\"2d\");\n    if (!ctx || !cx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const d = Math.min(2, window.devicePixelRatio || 1);\n    const PW = Math.round(PANEL.w * d), PH = Math.round(PANEL.h * d);\n    cv.width = PW; cv.height = PH;\n    const CW = W + MARGIN * 2, CH = H + MARGIN * 2;\n    cc.width = Math.round(CW * d); cc.height = Math.round(CH * d);\n    let seed = 23;\n    const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n    const make = (w: number, h: number) => { const c = document.createElement(\"canvas\"); c.width = w; c.height = h; return c; };\n\n    // The foil as printed: dull silver, a wave pattern and tiny repeated lettering.\n    const base = make(PW, PH), b = base.getContext(\"2d\");\n    if (b) {\n      b.scale(d, d);\n      const g = b.createLinearGradient(0, 0, PANEL.w, PANEL.h);\n      g.addColorStop(0, \"#cfd2d6\"); g.addColorStop(0.3, \"#9da1a8\"); g.addColorStop(0.55, \"#c6c9ce\"); g.addColorStop(0.8, \"#8f939b\"); g.addColorStop(1, \"#b4b8be\");\n      b.fillStyle = g; b.fillRect(0, 0, PANEL.w, PANEL.h);\n      for (let i = 0; i < 2600; i++) { const v = rand(); b.fillStyle = v > 0.5 ? `rgba(255,255,255,${(v - 0.5) * 0.5})` : `rgba(40,44,52,${(0.5 - v) * 0.36})`; b.fillRect(rand() * PANEL.w, rand() * PANEL.h, 0.7, 0.7); }\n      b.lineWidth = 0.6; b.strokeStyle = \"rgba(70,76,86,0.34)\";\n      for (let y = -4; y < PANEL.h + 6; y += 4.5) {\n        b.beginPath();\n        for (let x = 0; x <= PANEL.w; x += 3) { const yy = y + Math.sin(x * 0.11 + y * 0.6) * 2.2; if (x === 0) b.moveTo(x, yy); else b.lineTo(x, yy); }\n        b.stroke();\n      }\n      b.font = '700 6px \"Helvetica Neue\",Helvetica,Arial,sans-serif'; b.fillStyle = \"rgba(58,64,74,0.5)\"; b.textBaseline = \"middle\";\n      for (let row = 0; row < 5; row++) for (let x = -30 + (row % 2) * 22; x < PANEL.w; x += 46) b.fillText(\"S C R A T C H\", x, 7 + row * 10.5);\n    }\n    const mask = make(PW, PH), m = mask.getContext(\"2d\");\n    const probe = make(29, 7), pr = probe.getContext(\"2d\", { willReadFrequently: true });\n    if (!m || !pr) return;\n    m.scale(d, d); m.lineCap = \"round\"; m.strokeStyle = \"#000\"; m.fillStyle = \"#000\";\n\n    const s = {\n      coinX: W + 34, coinY: H - 8, toX: W + 34, toY: H - 8, press: 0, pressTo: 0,\n      down: false, lastX: 0, lastY: 0, lastUser: -1e9, hover: false,\n      path: [] as [number, number][], seg: 0, along: 0, wait: 0, startAfter: 3.3, doneFor: 0, done: false, dealing: false,\n      crumbs: [] as Crumb[], crumbsDirty: true, foilDirty: true, sheen: 0.3, t: 0, checkIn: 0,\n    };\n    // The route the coin takes by itself: a tight zigzag from left to right, in panel coordinates.\n    const route = () => {\n      const pts: [number, number][] = [];\n      for (let i = 0, x = 7; x < PANEL.w - 3; i++, x += 10.5) pts.push([x + (rand() - 0.5) * 5, i % 2 ? PANEL.h - 3 - rand() * 7 : 3 + rand() * 7]);\n      return pts;\n    };\n\n    const spawn = (x: number, y: number, dx: number, dy: number, settle: boolean) => {\n      const len = Math.hypot(dx, dy) || 1, n = Math.max(1, Math.round(len / 13));\n      for (let i = 0; i < n; i++) {\n        const sp = 130 + rand() * 330, side = (rand() - 0.5) * 300;\n        const c: Crumb = { x: PANEL.x + x + (rand() - 0.5) * 10, y: PANEL.y + y + (rand() - 0.5) * 10, vx: (dx / len) * sp - (dy / len) * side, vy: (dy / len) * sp + (dx / len) * side, r: 0.9 + rand() * 2.6, a: rand() * 6.3, va: (rand() - 0.5) * 22, curl: 0.9 + rand() * 2.6, shade: rand(), flake: rand() < 0.6, still: false };\n        if (settle) { c.x += c.vx / 5.5; c.y += c.vy / 5.5; c.a += c.va / 5.5; c.still = true; }\n        s.crumbs.push(c);\n      }\n      if (s.crumbs.length > 240) s.crumbs.splice(0, s.crumbs.length - 240);\n      s.crumbsDirty = true;\n    };\n    // One rub of the coin from a to b: a ragged core, streaks beside it and loose specks.\n    const rub = (x0: number, y0: number, x1: number, y1: number, settle: boolean) => {\n      const dx = x1 - x0, dy = y1 - y0, len = Math.hypot(dx, dy) || 1, nx = -dy / len, ny = dx / len;\n      for (let k = 0; k < 3; k++) {\n        const o = (rand() - 0.5) * 9;\n        m.globalAlpha = 1; m.lineWidth = 9 + rand() * 8;\n        m.beginPath(); m.moveTo(x0 + nx * o, y0 + ny * o); m.lineTo(x1 + nx * o, y1 + ny * o); m.stroke();\n      }\n      for (let k = 0; k < 9; k++) {\n        const o = (rand() - 0.5) * 30, t0 = rand() * 0.3, t1 = 0.7 + rand() * 0.3;\n        m.globalAlpha = 0.55 + rand() * 0.45; m.lineWidth = 0.8 + rand() * 1.8;\n        m.beginPath(); m.moveTo(x0 + dx * t0 + nx * o, y0 + dy * t0 + ny * o); m.lineTo(x0 + dx * t1 + nx * o, y0 + dy * t1 + ny * o); m.stroke();\n      }\n      m.globalAlpha = 1;\n      for (let k = 0; k < 5; k++) { const t = rand(), o = (rand() - 0.5) * 28; m.beginPath(); m.arc(x0 + dx * t + nx * o, y0 + dy * t + ny * o, 0.5 + rand() * 1.3, 0, 6.3); m.fill(); }\n      s.foilDirty = true;\n      spawn(x1, y1, dx, dy, settle);\n    };\n    const cleared = () => {\n      pr.clearRect(0, 0, 29, 7); pr.drawImage(mask, 0, 0, 29, 7);\n      const px = pr.getImageData(0, 0, 29, 7).data; let sum = 0;\n      for (let i = 3; i < px.length; i += 4) sum += px[i];\n      return sum / (255 * 29 * 7);\n    };\n    const finish = () => { if (!s.done) { s.done = true; s.doneFor = 0; setRevealed(true); } };\n\n    const drawFoil = () => {\n      s.foilDirty = false;\n      ctx.globalCompositeOperation = \"source-over\"; ctx.clearRect(0, 0, PW, PH); ctx.drawImage(base, 0, 0);\n      const c = s.sheen * PW, g = ctx.createLinearGradient(c - PW * 0.3, 0, c + PW * 0.3, PH);\n      g.addColorStop(0, \"rgba(255,255,255,0)\"); g.addColorStop(0.5, \"rgba(255,255,255,0.85)\"); g.addColorStop(1, \"rgba(255,255,255,0)\");\n      ctx.globalCompositeOperation = \"soft-light\"; ctx.fillStyle = g; ctx.fillRect(0, 0, PW, PH);\n      ctx.globalCompositeOperation = \"destination-out\"; ctx.drawImage(mask, 0, 0);\n    };\n    const drawCrumbs = () => {\n      s.crumbsDirty = false;\n      cx.setTransform(d, 0, 0, d, MARGIN * d, MARGIN * d);\n      cx.clearRect(-MARGIN, -MARGIN, CW, CH);\n      cx.lineCap = \"round\";\n      for (const c of s.crumbs) {\n        const v = 112 + c.shade * 84, tone = `rgb(${v | 0},${(v + 3) | 0},${(v + 8) | 0})`;\n        if (c.flake) {\n          // A flat flake: a small lopsided four-sided chip with a shadow under one edge.\n          const cos = Math.cos(c.a), sin = Math.sin(c.a), w = c.r * 0.95, h = c.r * (0.3 + c.curl * 0.16);\n          const chip = (ox: number, oy: number) => { cx.beginPath(); cx.moveTo(c.x + ox - cos * w - sin * h, c.y + oy - sin * w + cos * h); cx.lineTo(c.x + ox + cos * w - sin * h * 0.4, c.y + oy + sin * w + cos * h * 0.4); cx.lineTo(c.x + ox + cos * w * 0.7 + sin * h, c.y + oy + sin * w * 0.7 - cos * h); cx.lineTo(c.x + ox - cos * w * 0.8 + sin * h * 0.7, c.y + oy - sin * w * 0.8 - cos * h * 0.7); cx.closePath(); cx.fill(); };\n          cx.fillStyle = \"rgba(40,30,20,0.24)\"; chip(0.7, 1);\n          cx.fillStyle = tone; chip(0, 0);\n        } else {\n          cx.lineWidth = 1.2; cx.strokeStyle = \"rgba(40,30,20,0.24)\";\n          cx.beginPath(); cx.arc(c.x + 0.8, c.y + 1.1, c.r, c.a, c.a + c.curl); cx.stroke();\n          cx.lineWidth = 1; cx.strokeStyle = tone;\n          cx.beginPath(); cx.arc(c.x, c.y, c.r, c.a, c.a + c.curl); cx.stroke();\n          cx.lineWidth = 0.5; cx.strokeStyle = \"rgba(255,255,255,0.55)\";\n          cx.beginPath(); cx.arc(c.x, c.y, c.r, c.a + c.curl * 0.3, c.a + c.curl * 0.5); cx.stroke();\n        }\n      }\n    };\n    const placeCoin = () => {\n      const p = s.press;\n      coin.style.transform = `translate(${(s.coinX - 7).toFixed(1)}px, ${(s.coinY - 8).toFixed(1)}px) rotate(${(-TILT + (s.coinX - s.toX) * 0.25).toFixed(2)}deg) scale(${(1 - p * 0.05).toFixed(3)})`;\n      coin.style.filter = `drop-shadow(${(7 - p * 4).toFixed(1)}px ${(11 - p * 6).toFixed(1)}px ${(9 - p * 5).toFixed(1)}px rgba(52,34,12,${(0.34 + p * 0.14).toFixed(2)}))`;\n    };\n\n    const reset = (filled: number, settle: boolean) => {\n      m.clearRect(0, 0, PANEL.w, PANEL.h);\n      s.crumbs = []; s.path = route(); s.seg = 0; s.along = 0; s.wait = 0; s.done = false; s.doneFor = 0;\n      const upto = Math.floor((s.path.length - 1) * filled);\n      for (let i = 0; i < upto; i++) rub(s.path[i][0], s.path[i][1], s.path[i + 1][0], s.path[i + 1][1], true);\n      s.seg = upto;\n      if (filled >= 1) { s.done = true; s.toX = W + 34; s.toY = H - 8; }\n      else if (upto > 0) { s.toX = PANEL.x + s.path[upto][0]; s.toY = PANEL.y + s.path[upto][1]; }\n      else { s.toX = W + 34; s.toY = H - 8; }\n      if (settle) { s.coinX = s.toX; s.coinY = s.toY; }\n      s.foilDirty = true; s.crumbsDirty = true;\n    };\n    reset(reduce ? 1 : START_FILLED, true);\n    if (reduce) setRevealed(true);\n\n    const toLocal = (clientX: number, clientY: number) => {\n      const r = box.getBoundingClientRect(), k = r.width / W;\n      const dx = (clientX - (r.left + r.width / 2)) / k, dy = (clientY - (r.top + r.height / 2)) / k;\n      const a = (TILT * Math.PI) / 180, cos = Math.cos(a), sin = Math.sin(a);\n      return [dx * cos + dy * sin + W / 2, -dx * sin + dy * cos + H / 2];\n    };\n\n    const dealNew = () => {\n      if (s.dealing) return;\n      s.dealing = true; s.toX = W + 34; s.toY = H - 8;\n      const next = () => { setDeal((n) => n + 1); setRevealed(false); reset(0, false); s.startAfter = 1.3; };\n      if (reduce) { next(); s.dealing = false; paint(); return; }\n      cc.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 300, fill: \"forwards\" });\n      const out = cardNode.animate([{ transform: \"translate(0,0) rotate(0deg)\" }, { transform: \"translate(-150%,-20px) rotate(-9deg)\" }], { duration: 460, easing: \"cubic-bezier(.5,0,.9,.4)\", fill: \"forwards\" });\n      out.onfinish = () => {\n        next();\n        cc.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 10, fill: \"forwards\" });\n        const back = cardNode.animate([{ transform: \"translate(150%,24px) rotate(9deg)\" }, { transform: \"translate(0,0) rotate(0deg)\" }], { duration: 620, easing: \"cubic-bezier(.16,1,.3,1)\", fill: \"forwards\" });\n        back.onfinish = () => { s.dealing = false; };\n      };\n    };\n\n    const paint = () => { if (s.foilDirty) drawFoil(); if (s.crumbsDirty) drawCrumbs(); placeCoin(); };\n\n    let raf = 0, last = 0, visible = true;\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, last ? (now - last) / 1000 : 0.016); last = now; s.t += dt;\n      const userIdle = now - s.lastUser > 3600 && !s.down;\n      if (!reduce && userIdle && !s.dealing) {\n        if (s.done) { s.doneFor += dt; s.pressTo = 0; s.toX = W + 34; s.toY = H - 8; if (s.doneFor > 4.2) dealNew(); }\n        else {\n          s.wait += dt;\n          if (s.wait > s.startAfter && s.seg < s.path.length - 1) {\n            let travel = 250 * dt; s.pressTo = 1;\n            while (travel > 0 && s.seg < s.path.length - 1) {\n              const [ax, ay] = s.path[s.seg], [bx, by] = s.path[s.seg + 1], len = Math.hypot(bx - ax, by - ay);\n              const from = s.along, to = Math.min(len, from + travel);\n              rub(ax + ((bx - ax) * from) / len, ay + ((by - ay) * from) / len, ax + ((bx - ax) * to) / len, ay + ((by - ay) * to) / len, false);\n              s.toX = PANEL.x + ax + ((bx - ax) * to) / len; s.toY = PANEL.y + ay + ((by - ay) * to) / len;\n              travel -= to - from; s.along = to;\n              if (to >= len) { s.seg++; s.along = 0; }\n            }\n            s.coinX = s.toX; s.coinY = s.toY;\n            if (s.seg >= s.path.length - 1) finish();\n          } else if (s.seg === 0) { s.toX = W + 34; s.toY = H - 8; }\n        }\n      }\n      const k = Math.min(1, dt * (s.down ? 30 : 12));\n      s.coinX += (s.toX - s.coinX) * k; s.coinY += (s.toY - s.coinY) * k;\n      s.press += (s.pressTo - s.press) * Math.min(1, dt * 14);\n      const sh = Math.max(0, Math.min(1, (s.coinX - PANEL.x) / PANEL.w)) * 0.8 + 0.1 + Math.sin(s.t * 0.7) * 0.06;\n      if (Math.abs(sh - s.sheen) > 0.004) { s.sheen = sh; s.foilDirty = true; }\n      let moving = false; const f = Math.exp(-dt * 5.5);\n      for (const c of s.crumbs) {\n        if (c.still) continue;\n        c.x += c.vx * dt; c.y += c.vy * dt; c.a += c.va * dt; c.vx *= f; c.vy *= f; c.va *= f;\n        if (Math.abs(c.vx) + Math.abs(c.vy) < 3) c.still = true;\n        moving = true;\n      }\n      if (moving) s.crumbsDirty = true;\n      paint();\n      if (visible && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!raf && !reduce) { last = 0; raf = requestAnimationFrame(frame); } };\n\n    const inPanel = (x: number, y: number) => x > PANEL.x - 6 && x < PANEL.x + PANEL.w + 6 && y > PANEL.y - 6 && y < PANEL.y + PANEL.h + 6;\n    const down = (e: PointerEvent) => {\n      const [x, y] = toLocal(e.clientX, e.clientY);\n      s.lastUser = performance.now();\n      if (!inPanel(x, y) || s.dealing) return;\n      s.down = true; s.pressTo = 1; s.lastX = x; s.lastY = y; s.toX = x; s.toY = y;\n      el.setPointerCapture(e.pointerId); e.preventDefault(); wake();\n    };\n    const move = (e: PointerEvent) => {\n      const [x, y] = toLocal(e.clientX, e.clientY);\n      if (e.pointerType === \"mouse\" || s.down) { s.lastUser = performance.now(); s.toX = x; s.toY = y; if (!s.down) s.pressTo = 0; }\n      if (!s.down) return;\n      if (Math.hypot(x - s.lastX, y - s.lastY) < 2.5) return;\n      if (inPanel(x, y) || inPanel(s.lastX, s.lastY)) {\n        rub(s.lastX - PANEL.x, s.lastY - PANEL.y, x - PANEL.x, y - PANEL.y, reduce);\n        if ((s.checkIn = (s.checkIn + 1) % 5) === 0 && cleared() > 0.62) finish();\n      }\n      s.lastX = x; s.lastY = y;\n      if (reduce) { s.coinX = x; s.coinY = y; paint(); }\n    };\n    const up = () => { if (s.down) { s.down = false; s.pressTo = 0; if (cleared() > 0.62) finish(); } };\n    el.addEventListener(\"pointerdown\", down);\n    el.addEventListener(\"pointermove\", move);\n    el.addEventListener(\"pointerup\", up);\n    el.addEventListener(\"pointercancel\", up);\n\n    api.current = {\n      // The keyboard route: each press rubs a third of the panel.\n      rub: () => {\n        if (s.done || s.dealing) return;\n        s.lastUser = performance.now();\n        const stop = Math.min(s.path.length - 1, s.seg + Math.ceil(s.path.length / 3));\n        for (; s.seg < stop; s.seg++) rub(s.path[s.seg][0], s.path[s.seg][1], s.path[s.seg + 1][0], s.path[s.seg + 1][1], reduce);\n        s.along = 0; s.toX = PANEL.x + s.path[s.seg][0]; s.toY = PANEL.y + s.path[s.seg][1];\n        if (s.seg >= s.path.length - 1) finish();\n        if (reduce) { s.coinX = s.toX; s.coinY = s.toY; paint(); } else wake();\n      },\n      fresh: () => { s.lastUser = performance.now(); dealNew(); wake(); },\n    };\n\n    const fit = () => setScale(Math.min(1.25, (el.clientWidth - 56) / (W + 26)));\n    fit();\n    const ro = new ResizeObserver(fit); ro.observe(el);\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) wake(); });\n    io.observe(el);\n    const vis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", vis);\n    paint(); wake();\n\n    return () => {\n      cancelAnimationFrame(raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      el.removeEventListener(\"pointerdown\", down); el.removeEventListener(\"pointermove\", move);\n      el.removeEventListener(\"pointerup\", up); el.removeEventListener(\"pointercancel\", up);\n      api.current = null;\n    };\n  }, []);\n\n  return (\n    <div ref={root} className=\"relative flex min-h-[660px] w-full select-none items-center justify-center overflow-hidden bg-[#e9dfcf] py-20\">\n      <style>{`\n        .gift-card-scratch-gold { background-image: linear-gradient(100deg, #8a6420 0%, #e9c877 22%, #fff3c4 36%, #c79a3d 50%, #7d5a1b 64%, #e2bd66 82%, #9a7227 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }\n        .gift-card-scratch-milled { background: repeating-conic-gradient(#6b4a12 0deg 1.5deg, #f0cf7c 1.5deg 3deg); }\n      `}</style>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"radial-gradient(70% 60% at 38% 30%, #f6efe2 0%, #e9dfcf 55%, #d6c9b4 100%)\" }} />\n\n      <div ref={fitBox} className=\"relative\" style={{ width: W * scale, height: H * scale }}>\n        <div className=\"absolute left-1/2 top-1/2\" style={{ width: W, height: H, marginLeft: -W / 2, marginTop: -H / 2, transform: `scale(${scale}) rotate(${TILT}deg)` }}>\n          <div ref={cardEl} className=\"absolute inset-0\">\n            {/* Thickness: three stacked edges under the face, then the soft shadows of a card lying on a table. */}\n            <div className=\"absolute inset-0 overflow-hidden rounded-[16px] bg-[#f6f0e4]\" style={{ boxShadow: \"0 1px 0 #e3d8c6, 0 2px 0 #d2c6b1, 0 3.5px 0 #b7a98f, 0 5px 3px rgba(60,40,15,0.3), 0 18px 28px -6px rgba(70,48,20,0.34), 0 44px 60px -18px rgba(70,48,20,0.3)\" }}>\n              <div className=\"absolute inset-x-0 top-0 h-[190px]\" style={{ backgroundColor: gift.tone }}>\n                <img src={gift.photo} alt={gift.alt} width={460} height={190} loading=\"eager\" draggable={false} className=\"h-full w-full select-none object-cover\" style={{ objectPosition: \"50% 46%\" }} />\n                <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(180deg, rgba(20,10,14,0.05) 30%, rgba(20,10,14,0.72) 100%)\" }} />\n                <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(112deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 26%, rgba(255,255,255,0) 60%, rgba(255,255,255,0.09) 78%, rgba(255,255,255,0) 100%)\" }} />\n                <div className=\"absolute bottom-[14px] left-[24px]\">\n                  <p className=\"relative font-serif text-[31px] leading-none tracking-[-0.01em]\">\n                    <span aria-hidden=\"true\" className=\"absolute inset-0 text-black/60\" style={{ transform: \"translate(0.6px,1.1px)\" }}>{gift.shop}</span>\n                    <span className=\"gift-card-scratch-gold relative\">{gift.shop}</span>\n                  </p>\n                </div>\n                <p className=\"gift-card-scratch-gold absolute bottom-[19px] right-[24px] text-[8px] font-bold tracking-[0.34em]\">{gift.trade}</p>\n              </div>\n              <div aria-hidden=\"true\" className=\"absolute inset-x-0 top-[190px] h-px bg-[#b89243]\" />\n              <div className=\"absolute left-[24px] top-[207px]\">\n                <p className=\"text-[7.5px] font-bold tracking-[0.3em] text-[#6b5a3e]\">GIFT CARD</p>\n                <p className=\"mt-[3px] font-serif text-[36px] leading-none text-[#231c14]\">{gift.amount}</p>\n                <p className=\"mt-[5px] w-[150px] text-[8.5px] leading-[1.35] text-[#5d4f38]\">{gift.line}</p>\n              </div>\n              <p className=\"absolute text-[6.5px] font-bold tracking-[0.3em] text-[#6b5a3e]\" style={{ left: PANEL.x + 1, top: PANEL.y - 13 }}>{gift.hint}</p>\n              <div className=\"absolute overflow-hidden rounded-[5px]\" style={{ left: PANEL.x, top: PANEL.y, width: PANEL.w, height: PANEL.h, backgroundColor: \"#fbf8f1\", backgroundImage: \"repeating-linear-gradient(135deg, rgba(120,100,60,0.09) 0 1px, transparent 1px 5px)\", boxShadow: \"inset 0 0 0 1px rgba(90,70,40,0.28)\" }}>\n                <p className=\"flex h-full items-center justify-center font-mono text-[17px] font-bold tracking-[0.14em] text-[#231c14]\" aria-hidden={!revealed}>{code}</p>\n                <canvas ref={foil} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n                <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 rounded-[5px]\" style={{ boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -1px 0 rgba(0,0,0,0.18)\" }} />\n              </div>\n              <button\n                type=\"button\"\n                onClick={(e) => { if (e.detail === 0) api.current?.rub(); }}\n                aria-label={revealed ? `Scratch panel, already scratched. The code is ${code}.` : \"Scratch panel. Press to rub some of the foil away.\"}\n                className=\"absolute cursor-grab touch-none rounded-[5px] outline-none focus-visible:ring-2 focus-visible:ring-[#231c14] focus-visible:ring-offset-2 active:cursor-grabbing\"\n                style={{ left: PANEL.x, top: PANEL.y, width: PANEL.w, height: PANEL.h }}\n              />\n            </div>\n          </div>\n          <canvas ref={crumbsEl} aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ left: -MARGIN, top: -MARGIN, width: W + MARGIN * 2, height: H + MARGIN * 2 }} />\n          {/* The coin. It is drawn to the lower right of the point it rubs with. */}\n          <div ref={coinEl} aria-hidden=\"true\" className=\"pointer-events-none absolute left-0 top-0 h-[66px] w-[66px]\" style={{ willChange: \"transform\" }}>\n            <div className=\"gift-card-scratch-milled absolute inset-0 rounded-full\" />\n            <div className=\"absolute inset-[2.5px] rounded-full\" style={{ background: \"conic-gradient(from 210deg, #f7dd92, #b8872c 14%, #f3d481 30%, #8d6419 46%, #e6c26a 62%, #a87a25 78%, #f7dd92)\" }} />\n            <div className=\"absolute inset-[7px] rounded-full\" style={{ background: \"radial-gradient(circle at 34% 28%, #f6dc94 0%, #d3a747 46%, #a87a26 100%)\", boxShadow: \"inset 0 1.5px 1px rgba(255,255,255,0.6), inset 0 -2px 2px rgba(80,50,5,0.5), 0 0 0 0.6px rgba(80,50,5,0.6)\" }} />\n            <div className=\"absolute inset-[11px] rounded-full border border-dashed border-[#7a5615]/60\" />\n            <p className=\"absolute inset-0 flex items-center justify-center font-serif text-[21px] font-bold text-[#8a6218]\" style={{ textShadow: \"0 1px 0 rgba(255,240,190,0.9), 0 -0.8px 0 rgba(70,44,4,0.7)\" }}>{gift.coin}</p>\n          </div>\n        </div>\n      </div>\n\n      <p className=\"sr-only\" aria-live=\"polite\">{revealed ? `Code revealed: ${code}` : \"\"}</p>\n      <div className=\"absolute bottom-6 left-7 right-7 flex items-end justify-between gap-4\">\n        <p className=\"pointer-events-none font-mono text-[10px] font-semibold uppercase leading-5 tracking-[0.22em] text-[#231c14]\">\n          {gift.shop} gift card\n          <span className=\"block font-medium text-[#5d4f38]\">Rub the silver panel with the coin</span>\n        </p>\n        <button type=\"button\" onClick={() => api.current?.fresh()} className=\"min-h-[40px] shrink-0 whitespace-nowrap rounded-full border border-[#231c14]/25 bg-[#f6f0e4]/70 px-4 font-mono text-[10px] font-semibold uppercase tracking-[0.2em] text-[#231c14] outline-none transition-colors hover:bg-[#f6f0e4] focus-visible:ring-2 focus-visible:ring-[#231c14]\">\n          New card\n        </button>\n      </div>\n    </div>\n  );\n}\n"}]}
