# Scratch card toast

> A ticket with a silver layer you really scratch with a finger or mouse; clear half of it and the whole prize appears.

- Category: [Toasts](https://library.aimran.es/components/toasts)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-toast-scratch-card
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Scratch cards turn a discount into a small game, and this one actually scratches. The silver coating is drawn on a canvas, every pointer stroke erases it with destination-out compositing, and a cheap sampling of the pixels detects when about half is gone, then fades the rest and pops the prize. A Reveal button gives keyboard and screen reader users the same result.

The main color is the prize text and the second the ticket underneath. Change the brush width and the reveal threshold in the script, and replace the code line with a real coupon from your backend. Fits shops, newsletters and loyalty programs.

## Code

### HTML

```html
<div class="uvq09-scr"><button type="button" class="fire">Another ticket</button><div class="tt" role="status"><div class="hd"><b>Scratch to reveal your prize</b><button type="button" class="rv">Reveal</button></div><div class="tk"><p class="pz" aria-hidden="true"><span>Free shipping on your next order</span><small>Code RASCA-7Q2</small></p><canvas aria-hidden="true"></canvas></div><small class="hn">Rub the silver area with your finger or mouse</small></div></div>
```

### CSS

```css
.uvq09-scr {
  --c1: #c2410c;
  --c2: #fef3c7;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq09-scr {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  width: 21em;
  height: 15em;
}

.uvq09-scr .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  left: 50%;
  top: 1.2em;
  translate: -50% 0;
  padding: .6em 1.1em;
  border-radius: 2em;
  font-size: .82em;
  font-weight: 650;
  white-space: nowrap;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .fire:hover {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq09-scr .fire:active {
  scale: .96;
}

.uvq09-scr .fire:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tt {
  position: absolute;
  left: 50%;
  bottom: 1em;
  width: 19em;
  translate: -50% 0;
  border-radius: 1.1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 1.2em 2.4em -1em rgba(0,0,0,.45);
  padding: .8em .9em .75em;
  transform: translateY(130%) scale(.92);
  opacity: 0;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.22,1,.36,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.in {
  transform: none;
  opacity: 1;
}

.uvq09-scr .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6em;
}

.uvq09-scr .hd b {
  font-size: .88em;
}

.uvq09-scr .rv {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: none;
  padding: .42em .75em;
  border-radius: 2em;
  font-size: .72em;
  font-weight: 750;
  color: color-mix(in srgb,var(--c1) 80%,var(--fg));
  background: color-mix(in srgb,var(--c1) 13%,transparent);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .rv:hover {
  background: color-mix(in srgb,var(--c1) 22%,transparent);
}

.uvq09-scr .rv:active {
  scale: .94;
}

.uvq09-scr .rv:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tk {
  position: relative;
  height: 3.7em;
  margin-top: .6em;
  border-radius: .6em;
  overflow: hidden;
  background: radial-gradient(color-mix(in srgb,var(--c1) 18%,transparent) 1px,transparent 1.5px) 0 0/.6em .6em,var(--c2);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 35%,transparent);
}

.uvq09-scr .pz {
  display: grid;
  place-content: center;
  gap: .15em;
  height: 100%;
  margin: 0;
  padding: 0 .8em;
  text-align: center;
  color: var(--c1);
}

.uvq09-scr .pz span {
  font-size: .95em;
  font-weight: 850;
  line-height: 1.2;
}

.uvq09-scr .pz small {
  font: 600 .66em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--c1) 60%,#000);
}

.uvq09-scr canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  transition: opacity calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.won canvas {
  opacity: 0;
  pointer-events: none;
}

.uvq09-scr .tt.won .pz {
  animation: uvq09-scr-p calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq09-scr .hn {
  display: block;
  margin-top: .45em;
  font-size: .68em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq09-scr .tt.won .hn {
  visibility: hidden;
}

@keyframes uvq09-scr-p {
  40% {
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq09-scr,.uvq09-scr *,.uvq09-scr *::before,.uvq09-scr *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq09-scr").forEach(el => {
  const t=el.querySelector(".tt"),f=el.querySelector(".fire");let tm=[];const clr=()=>{tm.forEach(clearTimeout);tm=[]};const later=(fn,ms)=>tm.push(setTimeout(fn,ms));
const show=()=>{clr();t.classList.remove("in","out");void t.offsetWidth;later(()=>{t.classList.add("in");t.classList.remove('won');pz.setAttribute('aria-hidden','true');n=0;paint()},60)};
const hide=()=>{t.classList.remove("in");t.classList.add("out")};f.addEventListener("click",show);show();const cv=t.querySelector("canvas"),pz=t.querySelector(".pz"),cx=cv.getContext("2d");let down=false,n=0,px=0,py=0;const K=()=>window.devicePixelRatio||1;
const paint=()=>{const k=K(),W=cv.width=Math.max(1,Math.round(cv.offsetWidth*k)),H=cv.height=Math.max(1,Math.round(cv.offsetHeight*k));cx.globalCompositeOperation="source-over";const g=cx.createLinearGradient(0,0,W,H);g.addColorStop(0,"#c4c4cc");g.addColorStop(.45,"#f4f4f5");g.addColorStop(1,"#9a9aa3");cx.fillStyle=g;cx.fillRect(0,0,W,H);cx.strokeStyle="rgba(255,255,255,.35)";cx.lineWidth=k;for(let x=-H;x<W;x+=7*k){cx.beginPath();cx.moveTo(x,H);cx.lineTo(x+H,0);cx.stroke()}cx.fillStyle="#6b6b74";cx.font="800 "+13*k+"px system-ui,sans-serif";cx.textAlign="center";cx.textBaseline="middle";cx.fillText("SCRATCH HERE",W/2,H/2)};
const win=()=>{t.classList.add("won");pz.removeAttribute("aria-hidden")};
const check=()=>{const d=cx.getImageData(0,0,cv.width,cv.height).data;let c=0,s=0;for(let i=3;i<d.length;i+=80){s++;if(d[i]<40)c++}if(s&&c/s>.5)win()};
const at=e=>{const r=cv.getBoundingClientRect();return[(e.clientX-r.left)*cv.width/r.width,(e.clientY-r.top)*cv.height/r.height]};
const dig=(x,y)=>{cx.globalCompositeOperation="destination-out";cx.lineWidth=30*K();cx.lineCap="round";cx.beginPath();cx.moveTo(px,py);cx.lineTo(x,y);cx.stroke();px=x;py=y;if(++n%5===0)check()};
cv.addEventListener("pointerdown",e=>{down=true;cv.setPointerCapture(e.pointerId);[px,py]=at(e);dig(px,py)});
cv.addEventListener("pointermove",e=>{if(down){const[x,y]=at(e);dig(x,y)}});
const up=()=>{down=false};cv.addEventListener("pointerup",up);cv.addEventListener("pointercancel",up);
t.querySelector(".rv").addEventListener("click",win);return clr
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq09-scr {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  width: 21em;
  height: 15em;
}

.uvq09-scr .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  left: 50%;
  top: 1.2em;
  translate: -50% 0;
  padding: .6em 1.1em;
  border-radius: 2em;
  font-size: .82em;
  font-weight: 650;
  white-space: nowrap;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .fire:hover {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq09-scr .fire:active {
  scale: .96;
}

.uvq09-scr .fire:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tt {
  position: absolute;
  left: 50%;
  bottom: 1em;
  width: 19em;
  translate: -50% 0;
  border-radius: 1.1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 1.2em 2.4em -1em rgba(0,0,0,.45);
  padding: .8em .9em .75em;
  transform: translateY(130%) scale(.92);
  opacity: 0;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.22,1,.36,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.in {
  transform: none;
  opacity: 1;
}

.uvq09-scr .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6em;
}

.uvq09-scr .hd b {
  font-size: .88em;
}

.uvq09-scr .rv {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: none;
  padding: .42em .75em;
  border-radius: 2em;
  font-size: .72em;
  font-weight: 750;
  color: color-mix(in srgb,var(--c1) 80%,var(--fg));
  background: color-mix(in srgb,var(--c1) 13%,transparent);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .rv:hover {
  background: color-mix(in srgb,var(--c1) 22%,transparent);
}

.uvq09-scr .rv:active {
  scale: .94;
}

.uvq09-scr .rv:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tk {
  position: relative;
  height: 3.7em;
  margin-top: .6em;
  border-radius: .6em;
  overflow: hidden;
  background: radial-gradient(color-mix(in srgb,var(--c1) 18%,transparent) 1px,transparent 1.5px) 0 0/.6em .6em,var(--c2);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 35%,transparent);
}

.uvq09-scr .pz {
  display: grid;
  place-content: center;
  gap: .15em;
  height: 100%;
  margin: 0;
  padding: 0 .8em;
  text-align: center;
  color: var(--c1);
}

.uvq09-scr .pz span {
  font-size: .95em;
  font-weight: 850;
  line-height: 1.2;
}

.uvq09-scr .pz small {
  font: 600 .66em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--c1) 60%,#000);
}

.uvq09-scr canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  transition: opacity calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.won canvas {
  opacity: 0;
  pointer-events: none;
}

.uvq09-scr .tt.won .pz {
  animation: uvq09-scr-p calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq09-scr .hn {
  display: block;
  margin-top: .45em;
  font-size: .68em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq09-scr .tt.won .hn {
  visibility: hidden;
}

@keyframes uvq09-scr-p {
  40% {
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq09-scr,.uvq09-scr *,.uvq09-scr *::before,.uvq09-scr *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const t=el.querySelector(".tt"),f=el.querySelector(".fire");let tm=[];const clr=()=>{tm.forEach(clearTimeout);tm=[]};const later=(fn,ms)=>tm.push(setTimeout(fn,ms));
const show=()=>{clr();t.classList.remove("in","out");void t.offsetWidth;later(()=>{t.classList.add("in");t.classList.remove('won');pz.setAttribute('aria-hidden','true');n=0;paint()},60)};
const hide=()=>{t.classList.remove("in");t.classList.add("out")};f.addEventListener("click",show);show();const cv=t.querySelector("canvas"),pz=t.querySelector(".pz"),cx=cv.getContext("2d");let down=false,n=0,px=0,py=0;const K=()=>window.devicePixelRatio||1;
const paint=()=>{const k=K(),W=cv.width=Math.max(1,Math.round(cv.offsetWidth*k)),H=cv.height=Math.max(1,Math.round(cv.offsetHeight*k));cx.globalCompositeOperation="source-over";const g=cx.createLinearGradient(0,0,W,H);g.addColorStop(0,"#c4c4cc");g.addColorStop(.45,"#f4f4f5");g.addColorStop(1,"#9a9aa3");cx.fillStyle=g;cx.fillRect(0,0,W,H);cx.strokeStyle="rgba(255,255,255,.35)";cx.lineWidth=k;for(let x=-H;x<W;x+=7*k){cx.beginPath();cx.moveTo(x,H);cx.lineTo(x+H,0);cx.stroke()}cx.fillStyle="#6b6b74";cx.font="800 "+13*k+"px system-ui,sans-serif";cx.textAlign="center";cx.textBaseline="middle";cx.fillText("SCRATCH HERE",W/2,H/2)};
const win=()=>{t.classList.add("won");pz.removeAttribute("aria-hidden")};
const check=()=>{const d=cx.getImageData(0,0,cv.width,cv.height).data;let c=0,s=0;for(let i=3;i<d.length;i+=80){s++;if(d[i]<40)c++}if(s&&c/s>.5)win()};
const at=e=>{const r=cv.getBoundingClientRect();return[(e.clientX-r.left)*cv.width/r.width,(e.clientY-r.top)*cv.height/r.height]};
const dig=(x,y)=>{cx.globalCompositeOperation="destination-out";cx.lineWidth=30*K();cx.lineCap="round";cx.beginPath();cx.moveTo(px,py);cx.lineTo(x,y);cx.stroke();px=x;py=y;if(++n%5===0)check()};
cv.addEventListener("pointerdown",e=>{down=true;cv.setPointerCapture(e.pointerId);[px,py]=at(e);dig(px,py)});
cv.addEventListener("pointermove",e=>{if(down){const[x,y]=at(e);dig(x,y)}});
const up=()=>{down=false};cv.addEventListener("pointerup",up);cv.addEventListener("pointercancel",up);
t.querySelector(".rv").addEventListener("click",win);return clr
}

export default function ToastScratchCard() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#c2410c",
          "--c2": "#fef3c7",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq09-scr"><button type="button" className="fire">Another ticket</button><div className="tt" role="status"><div className="hd"><b>Scratch to reveal your prize</b><button type="button" className="rv">Reveal</button></div><div className="tk"><p className="pz" aria-hidden="true"><span>Free shipping on your next order</span><small>Code RASCA-7Q2</small></p><canvas aria-hidden="true"></canvas></div><small className="hn">Rub the silver area with your finger or mouse</small></div></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Scratch card toast” block (Toasts) from AIMRAN Library to my project.

## What it is
A ticket with a silver layer you really scratch with a finger or mouse; clear half of it and the whole prize appears.

## Chosen settings
- Main color: #c2410c
- Secondary color: #fef3c7
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Envío gratis en tu próximo pedido"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq09-scr {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  width: 21em;
  height: 15em;
}

.uvq09-scr .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  left: 50%;
  top: 1.2em;
  translate: -50% 0;
  padding: .6em 1.1em;
  border-radius: 2em;
  font-size: .82em;
  font-weight: 650;
  white-space: nowrap;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .fire:hover {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq09-scr .fire:active {
  scale: .96;
}

.uvq09-scr .fire:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tt {
  position: absolute;
  left: 50%;
  bottom: 1em;
  width: 19em;
  translate: -50% 0;
  border-radius: 1.1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent),0 1.2em 2.4em -1em rgba(0,0,0,.45);
  padding: .8em .9em .75em;
  transform: translateY(130%) scale(.92);
  opacity: 0;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.22,1,.36,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.in {
  transform: none;
  opacity: 1;
}

.uvq09-scr .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6em;
}

.uvq09-scr .hd b {
  font-size: .88em;
}

.uvq09-scr .rv {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: none;
  padding: .42em .75em;
  border-radius: 2em;
  font-size: .72em;
  font-weight: 750;
  color: color-mix(in srgb,var(--c1) 80%,var(--fg));
  background: color-mix(in srgb,var(--c1) 13%,transparent);
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .rv:hover {
  background: color-mix(in srgb,var(--c1) 22%,transparent);
}

.uvq09-scr .rv:active {
  scale: .94;
}

.uvq09-scr .rv:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq09-scr .tk {
  position: relative;
  height: 3.7em;
  margin-top: .6em;
  border-radius: .6em;
  overflow: hidden;
  background: radial-gradient(color-mix(in srgb,var(--c1) 18%,transparent) 1px,transparent 1.5px) 0 0/.6em .6em,var(--c2);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 35%,transparent);
}

.uvq09-scr .pz {
  display: grid;
  place-content: center;
  gap: .15em;
  height: 100%;
  margin: 0;
  padding: 0 .8em;
  text-align: center;
  color: var(--c1);
}

.uvq09-scr .pz span {
  font-size: .95em;
  font-weight: 850;
  line-height: 1.2;
}

.uvq09-scr .pz small {
  font: 600 .66em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--c1) 60%,#000);
}

.uvq09-scr canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  transition: opacity calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq09-scr .tt.won canvas {
  opacity: 0;
  pointer-events: none;
}

.uvq09-scr .tt.won .pz {
  animation: uvq09-scr-p calc(0.5s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq09-scr .hn {
  display: block;
  margin-top: .45em;
  font-size: .68em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq09-scr .tt.won .hn {
  visibility: hidden;
}

@keyframes uvq09-scr-p {
  40% {
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq09-scr,.uvq09-scr *,.uvq09-scr *::before,.uvq09-scr *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const t=el.querySelector(".tt"),f=el.querySelector(".fire");let tm=[];const clr=()=>{tm.forEach(clearTimeout);tm=[]};const later=(fn,ms)=>tm.push(setTimeout(fn,ms));
const show=()=>{clr();t.classList.remove("in","out");void t.offsetWidth;later(()=>{t.classList.add("in");t.classList.remove('won');pz.setAttribute('aria-hidden','true');n=0;paint()},60)};
const hide=()=>{t.classList.remove("in");t.classList.add("out")};f.addEventListener("click",show);show();const cv=t.querySelector("canvas"),pz=t.querySelector(".pz"),cx=cv.getContext("2d");let down=false,n=0,px=0,py=0;const K=()=>window.devicePixelRatio||1;
const paint=()=>{const k=K(),W=cv.width=Math.max(1,Math.round(cv.offsetWidth*k)),H=cv.height=Math.max(1,Math.round(cv.offsetHeight*k));cx.globalCompositeOperation="source-over";const g=cx.createLinearGradient(0,0,W,H);g.addColorStop(0,"#c4c4cc");g.addColorStop(.45,"#f4f4f5");g.addColorStop(1,"#9a9aa3");cx.fillStyle=g;cx.fillRect(0,0,W,H);cx.strokeStyle="rgba(255,255,255,.35)";cx.lineWidth=k;for(let x=-H;x<W;x+=7*k){cx.beginPath();cx.moveTo(x,H);cx.lineTo(x+H,0);cx.stroke()}cx.fillStyle="#6b6b74";cx.font="800 "+13*k+"px system-ui,sans-serif";cx.textAlign="center";cx.textBaseline="middle";cx.fillText("SCRATCH HERE",W/2,H/2)};
const win=()=>{t.classList.add("won");pz.removeAttribute("aria-hidden")};
const check=()=>{const d=cx.getImageData(0,0,cv.width,cv.height).data;let c=0,s=0;for(let i=3;i<d.length;i+=80){s++;if(d[i]<40)c++}if(s&&c/s>.5)win()};
const at=e=>{const r=cv.getBoundingClientRect();return[(e.clientX-r.left)*cv.width/r.width,(e.clientY-r.top)*cv.height/r.height]};
const dig=(x,y)=>{cx.globalCompositeOperation="destination-out";cx.lineWidth=30*K();cx.lineCap="round";cx.beginPath();cx.moveTo(px,py);cx.lineTo(x,y);cx.stroke();px=x;py=y;if(++n%5===0)check()};
cv.addEventListener("pointerdown",e=>{down=true;cv.setPointerCapture(e.pointerId);[px,py]=at(e);dig(px,py)});
cv.addEventListener("pointermove",e=>{if(down){const[x,y]=at(e);dig(x,y)}});
const up=()=>{down=false};cv.addEventListener("pointerup",up);cv.addEventListener("pointercancel",up);
t.querySelector(".rv").addEventListener("click",win);return clr
}

export default function ToastScratchCard() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#c2410c",
          "--c2": "#fef3c7",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq09-scr"><button type="button" className="fire">Another ticket</button><div className="tt" role="status"><div className="hd"><b>Scratch to reveal your prize</b><button type="button" className="rv">Reveal</button></div><div className="tk"><p className="pz" aria-hidden="true"><span>Free shipping on your next order</span><small>Code RASCA-7Q2</small></p><canvas aria-hidden="true"></canvas></div><small className="hn">Rub the silver area with your finger or mouse</small></div></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
