# Dot pattern unlock

> Join the dots by dragging: the line follows your finger, a wrong pattern shakes in red and the right one opens the lock.

- Category: [Microinteractions](https://library.aimran.es/components/microinteractions)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-mi27-pattern-lock
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Pattern locks are a gesture people know from their phones, and this block rebuilds one with buttons and an SVG line. Dragging across the three by three grid links the dots, skipped middle dots join automatically, and on release the pattern is checked: wrong ones flash red and shake, the correct L turns green and the padlock opens.

The main color is the line and success state, the secondary one the error. With the keyboard, arrow keys move between dots, Enter adds them and Check submits. Change the expected sequence in the script; it uses dot indexes from zero to eight.

## Code

### HTML

```html
<div class="uvq15-ptn"><span class="lk" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path class="sh" d="M8 11V7a4 4 0 0 1 8 0v4"/><rect x="5" y="11" width="14" height="10" rx="2.5"/></svg></span><p class="msg" aria-live="polite">Draw your pattern</p><div class="pad" role="group" aria-label="Unlock pattern"><svg viewBox="0 0 300 300" aria-hidden="true"><polyline class="ln" points=""/><line class="tl" x1="0" y1="0" x2="0" y2="0"/></svg><button type="button" class="dt" style="left:16.667%;top:16.667%" aria-label="1" aria-pressed="false"></button><button type="button" class="dt" style="left:50.000%;top:16.667%" aria-label="2" aria-pressed="false"></button><button type="button" class="dt" style="left:83.333%;top:16.667%" aria-label="3" aria-pressed="false"></button><button type="button" class="dt" style="left:16.667%;top:50.000%" aria-label="4" aria-pressed="false"></button><button type="button" class="dt" style="left:50.000%;top:50.000%" aria-label="5" aria-pressed="false"></button><button type="button" class="dt" style="left:83.333%;top:50.000%" aria-label="6" aria-pressed="false"></button><button type="button" class="dt" style="left:16.667%;top:83.333%" aria-label="7" aria-pressed="false"></button><button type="button" class="dt" style="left:50.000%;top:83.333%" aria-label="8" aria-pressed="false"></button><button type="button" class="dt" style="left:83.333%;top:83.333%" aria-label="9" aria-pressed="false"></button></div><p class="ht"><span>Hint: draw an L</span><button type="button" class="ck" hidden>Check</button></p></div>
```

### CSS

```css
.uvq15-ptn {
  --c1: #a3e635;
  --c2: #f43f5e;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq15-ptn {
  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;
  display: grid;
  justify-items: center;
  gap: .5em;
  width: 15em;
  padding: 1.3em 1.2em 1em;
  border-radius: 1.6em;
  color: #f8fafc;
  background: radial-gradient(120% 80% at 50% 0,#312e81,#0b1020 70%);
  box-shadow: 0 1.4em 2.6em -1.6em rgba(0,0,0,.6),inset 0 0 0 1px rgba(255,255,255,.08);
}

.uvq15-ptn .lk {
  display: grid;
  place-items: center;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  color: #cbd5e1;
  background: rgba(255,255,255,.08);
  transition: color calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .lk svg {
  width: 1.3em;
  height: 1.3em;
  overflow: visible;
}

.uvq15-ptn .sh {
  transform-origin: 16px 11px;
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq15-ptn.good .lk {
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn.good .sh {
  transform: translateY(-2px) rotate(30deg);
}

.uvq15-ptn .msg {
  margin: 0;
  font-weight: 700;
  min-height: 1.3em;
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn.bad .msg {
  color: var(--c2);
}

.uvq15-ptn.good .msg {
  color: var(--c1);
}

.uvq15-ptn .pad {
  position: relative;
  width: 12em;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.uvq15-ptn .pad svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq15-ptn .ln,.uvq15-ptn .tl {
  fill: none;
  stroke: var(--c1);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .85;
}

.uvq15-ptn .tl {
  opacity: 0;
}

.uvq15-ptn.bad .ln {
  stroke: var(--c2);
}

.uvq15-ptn.bad .pad {
  animation: uvq15-ptn-x calc(0.45s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-x {
  20% {
    transform: translateX(-.4em);
  }
  40% {
    transform: translateX(.35em);
  }
  60% {
    transform: translateX(-.25em);
  }
  80% {
    transform: translateX(.12em);
  }
}

.uvq15-ptn .dt {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  width: 1.05em;
  height: 1.05em;
  margin: -.525em 0 0 -.525em;
  border-radius: 50%;
  background: rgba(255,255,255,.4);
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .dt::before {
  content: "";
  position: absolute;
  inset: -1em;
  border-radius: 50%;
}

.uvq15-ptn .dt:focus-visible {
  outline: 2px solid #fff;
  outline-offset: .35em;
}

.uvq15-ptn .dt.on {
  background: var(--c1);
  transform: scale(1.3);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq15-ptn .dt.hit {
  animation: uvq15-ptn-h calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uvq15-ptn-h {
  40% {
    transform: scale(1.7);
  }
}

.uvq15-ptn.bad .dt.on {
  background: var(--c2);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c2) 25%,transparent);
}

.uvq15-ptn.good .dt.on {
  animation: uvq15-ptn-g calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-g {
  50% {
    box-shadow: 0 0 0 .9em color-mix(in srgb,var(--c1) 0%,transparent);
  }
}

.uvq15-ptn .ht {
  display: flex;
  align-items: center;
  gap: .6em;
  min-height: 2em;
  margin: 0;
  font-size: .72em;
  color: #94a3b8;
}

.uvq15-ptn .ck {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .35em .8em;
  border-radius: 2em;
  font-weight: 700;
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn .ck[hidden] {
  display: none;
}

.uvq15-ptn .ck:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

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

### JavaScript

```js
document.querySelectorAll(".uvq15-ptn").forEach(el => {
  const k=parseFloat(getComputedStyle(el).getPropertyValue("--k"))||1,rm=matchMedia("(prefers-reduced-motion:reduce)").matches;const pad=el.querySelector(".pad"),ln=el.querySelector(".ln"),tl=el.querySelector(".tl"),msg=el.querySelector(".msg"),ck=el.querySelector(".ck"),ds=[...el.querySelectorAll(".dt")],t0=msg.textContent,KEY="0,3,6,7,8",P=ds.map((d,i)=>[50+(i%3)*100,50+Math.floor(i/3)*100]);let seq=[],on=false,tm=0;
const busy=()=>el.classList.contains("good")||el.classList.contains("bad");
const draw=()=>{ln.setAttribute("points",seq.map(i=>P[i].join(",")).join(" "));ds.forEach((d,i)=>{const s=seq.includes(i);d.classList.toggle("on",s);d.setAttribute("aria-pressed",String(s))});ck.hidden=!seq.length||on||busy()};
const add=i=>{if(seq.includes(i))return;const l=seq[seq.length-1];if(l!==undefined){const m=P.findIndex(p=>p[0]===(P[l][0]+P[i][0])/2&&p[1]===(P[l][1]+P[i][1])/2);if(m>-1&&!seq.includes(m))seq.push(m)}seq.push(i);const d=ds[i];d.classList.remove("hit");void d.offsetWidth;d.classList.add("hit");draw()};
const reset=()=>{clearTimeout(tm);seq=[];el.classList.remove("bad","good");msg.textContent=t0;draw()};
const check=()=>{if(!seq.length)return;const g=seq.join(",")===KEY;el.classList.add(g?"good":"bad");msg.textContent=g?"Unlocked":"Wrong pattern";draw();tm=setTimeout(reset,(g?1800:1000)/k)};
const pt=e=>{const r=pad.getBoundingClientRect();return[(e.clientX-r.left)/r.width*300,(e.clientY-r.top)/r.height*300]};
const near=p=>P.findIndex(q=>Math.hypot(q[0]-p[0],q[1]-p[1])<36);
const tail=p=>{const l=seq[seq.length-1];tl.style.opacity=l===undefined||!p?"0":".45";if(l===undefined||!p)return;tl.setAttribute("x1",String(P[l][0]));tl.setAttribute("y1",String(P[l][1]));tl.setAttribute("x2",String(p[0]));tl.setAttribute("y2",String(p[1]))};
pad.addEventListener("pointerdown",e=>{if(busy())return;e.preventDefault();reset();on=true;pad.setPointerCapture(e.pointerId);const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
pad.addEventListener("pointermove",e=>{if(!on)return;const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
const up=()=>{if(!on)return;on=false;tail(null);check()};pad.addEventListener("pointerup",up);pad.addEventListener("pointercancel",up);
ds.forEach((d,i)=>{d.addEventListener("click",e=>{if(e.detail||busy())return;add(i)});d.addEventListener("keydown",e=>{const m={ArrowRight:1,ArrowLeft:-1,ArrowDown:3,ArrowUp:-3}[e.key];if(m!==undefined){e.preventDefault();const j=i+m;if(j>=0&&j<9&&(Math.abs(m)===3||Math.floor(j/3)===Math.floor(i/3)))ds[j].focus()}else if(e.key==="Escape")reset()})});
ck.addEventListener("click",()=>{check();ds[0].focus()});tail(null);return()=>clearTimeout(tm)
});
```

### 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 = `
.uvq15-ptn {
  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;
  display: grid;
  justify-items: center;
  gap: .5em;
  width: 15em;
  padding: 1.3em 1.2em 1em;
  border-radius: 1.6em;
  color: #f8fafc;
  background: radial-gradient(120% 80% at 50% 0,#312e81,#0b1020 70%);
  box-shadow: 0 1.4em 2.6em -1.6em rgba(0,0,0,.6),inset 0 0 0 1px rgba(255,255,255,.08);
}

.uvq15-ptn .lk {
  display: grid;
  place-items: center;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  color: #cbd5e1;
  background: rgba(255,255,255,.08);
  transition: color calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .lk svg {
  width: 1.3em;
  height: 1.3em;
  overflow: visible;
}

.uvq15-ptn .sh {
  transform-origin: 16px 11px;
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq15-ptn.good .lk {
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn.good .sh {
  transform: translateY(-2px) rotate(30deg);
}

.uvq15-ptn .msg {
  margin: 0;
  font-weight: 700;
  min-height: 1.3em;
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn.bad .msg {
  color: var(--c2);
}

.uvq15-ptn.good .msg {
  color: var(--c1);
}

.uvq15-ptn .pad {
  position: relative;
  width: 12em;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.uvq15-ptn .pad svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq15-ptn .ln,.uvq15-ptn .tl {
  fill: none;
  stroke: var(--c1);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .85;
}

.uvq15-ptn .tl {
  opacity: 0;
}

.uvq15-ptn.bad .ln {
  stroke: var(--c2);
}

.uvq15-ptn.bad .pad {
  animation: uvq15-ptn-x calc(0.45s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-x {
  20% {
    transform: translateX(-.4em);
  }
  40% {
    transform: translateX(.35em);
  }
  60% {
    transform: translateX(-.25em);
  }
  80% {
    transform: translateX(.12em);
  }
}

.uvq15-ptn .dt {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  width: 1.05em;
  height: 1.05em;
  margin: -.525em 0 0 -.525em;
  border-radius: 50%;
  background: rgba(255,255,255,.4);
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .dt::before {
  content: "";
  position: absolute;
  inset: -1em;
  border-radius: 50%;
}

.uvq15-ptn .dt:focus-visible {
  outline: 2px solid #fff;
  outline-offset: .35em;
}

.uvq15-ptn .dt.on {
  background: var(--c1);
  transform: scale(1.3);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq15-ptn .dt.hit {
  animation: uvq15-ptn-h calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uvq15-ptn-h {
  40% {
    transform: scale(1.7);
  }
}

.uvq15-ptn.bad .dt.on {
  background: var(--c2);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c2) 25%,transparent);
}

.uvq15-ptn.good .dt.on {
  animation: uvq15-ptn-g calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-g {
  50% {
    box-shadow: 0 0 0 .9em color-mix(in srgb,var(--c1) 0%,transparent);
  }
}

.uvq15-ptn .ht {
  display: flex;
  align-items: center;
  gap: .6em;
  min-height: 2em;
  margin: 0;
  font-size: .72em;
  color: #94a3b8;
}

.uvq15-ptn .ck {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .35em .8em;
  border-radius: 2em;
  font-weight: 700;
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn .ck[hidden] {
  display: none;
}

.uvq15-ptn .ck:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq15-ptn,.uvq15-ptn *,.uvq15-ptn *::before,.uvq15-ptn *::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 k=parseFloat(getComputedStyle(el).getPropertyValue("--k"))||1,rm=matchMedia("(prefers-reduced-motion:reduce)").matches;const pad=el.querySelector(".pad"),ln=el.querySelector(".ln"),tl=el.querySelector(".tl"),msg=el.querySelector(".msg"),ck=el.querySelector(".ck"),ds=[...el.querySelectorAll(".dt")],t0=msg.textContent,KEY="0,3,6,7,8",P=ds.map((d,i)=>[50+(i%3)*100,50+Math.floor(i/3)*100]);let seq=[],on=false,tm=0;
const busy=()=>el.classList.contains("good")||el.classList.contains("bad");
const draw=()=>{ln.setAttribute("points",seq.map(i=>P[i].join(",")).join(" "));ds.forEach((d,i)=>{const s=seq.includes(i);d.classList.toggle("on",s);d.setAttribute("aria-pressed",String(s))});ck.hidden=!seq.length||on||busy()};
const add=i=>{if(seq.includes(i))return;const l=seq[seq.length-1];if(l!==undefined){const m=P.findIndex(p=>p[0]===(P[l][0]+P[i][0])/2&&p[1]===(P[l][1]+P[i][1])/2);if(m>-1&&!seq.includes(m))seq.push(m)}seq.push(i);const d=ds[i];d.classList.remove("hit");void d.offsetWidth;d.classList.add("hit");draw()};
const reset=()=>{clearTimeout(tm);seq=[];el.classList.remove("bad","good");msg.textContent=t0;draw()};
const check=()=>{if(!seq.length)return;const g=seq.join(",")===KEY;el.classList.add(g?"good":"bad");msg.textContent=g?"Unlocked":"Wrong pattern";draw();tm=setTimeout(reset,(g?1800:1000)/k)};
const pt=e=>{const r=pad.getBoundingClientRect();return[(e.clientX-r.left)/r.width*300,(e.clientY-r.top)/r.height*300]};
const near=p=>P.findIndex(q=>Math.hypot(q[0]-p[0],q[1]-p[1])<36);
const tail=p=>{const l=seq[seq.length-1];tl.style.opacity=l===undefined||!p?"0":".45";if(l===undefined||!p)return;tl.setAttribute("x1",String(P[l][0]));tl.setAttribute("y1",String(P[l][1]));tl.setAttribute("x2",String(p[0]));tl.setAttribute("y2",String(p[1]))};
pad.addEventListener("pointerdown",e=>{if(busy())return;e.preventDefault();reset();on=true;pad.setPointerCapture(e.pointerId);const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
pad.addEventListener("pointermove",e=>{if(!on)return;const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
const up=()=>{if(!on)return;on=false;tail(null);check()};pad.addEventListener("pointerup",up);pad.addEventListener("pointercancel",up);
ds.forEach((d,i)=>{d.addEventListener("click",e=>{if(e.detail||busy())return;add(i)});d.addEventListener("keydown",e=>{const m={ArrowRight:1,ArrowLeft:-1,ArrowDown:3,ArrowUp:-3}[e.key];if(m!==undefined){e.preventDefault();const j=i+m;if(j>=0&&j<9&&(Math.abs(m)===3||Math.floor(j/3)===Math.floor(i/3)))ds[j].focus()}else if(e.key==="Escape")reset()})});
ck.addEventListener("click",()=>{check();ds[0].focus()});tail(null);return()=>clearTimeout(tm)
}

export default function Mi27PatternLock() {
  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": "#a3e635",
          "--c2": "#f43f5e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq15-ptn"><span className="lk" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path className="sh" d="M8 11V7a4 4 0 0 1 8 0v4" /><rect x="5" y="11" width="14" height="10" rx="2.5" /></svg></span><p className="msg" aria-live="polite">Draw your pattern</p><div className="pad" role="group" aria-label="Unlock pattern"><svg viewBox="0 0 300 300" aria-hidden="true"><polyline className="ln" points="" /><line className="tl" x1="0" y1="0" x2="0" y2="0" /></svg><button type="button" className="dt" style={{ left: "16.667%", top: "16.667%" }} aria-label="1" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "16.667%" }} aria-label="2" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "16.667%" }} aria-label="3" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "16.667%", top: "50.000%" }} aria-label="4" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "50.000%" }} aria-label="5" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "50.000%" }} aria-label="6" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "16.667%", top: "83.333%" }} aria-label="7" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "83.333%" }} aria-label="8" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "83.333%" }} aria-label="9" aria-pressed="false"></button></div><p className="ht"><span>Hint: draw an L</span><button type="button" className="ck" hidden={true}>Check</button></p></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 “Dot pattern unlock” block (Microinteractions) from AIMRAN Library to my project.

## What it is
Join the dots by dragging: the line follows your finger, a wrong pattern shakes in red and the right one opens the lock.

## Chosen settings
- Main color: #a3e635
- Secondary color: #f43f5e
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Dibuja tu patrón"

## 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 = `
.uvq15-ptn {
  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;
  display: grid;
  justify-items: center;
  gap: .5em;
  width: 15em;
  padding: 1.3em 1.2em 1em;
  border-radius: 1.6em;
  color: #f8fafc;
  background: radial-gradient(120% 80% at 50% 0,#312e81,#0b1020 70%);
  box-shadow: 0 1.4em 2.6em -1.6em rgba(0,0,0,.6),inset 0 0 0 1px rgba(255,255,255,.08);
}

.uvq15-ptn .lk {
  display: grid;
  place-items: center;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  color: #cbd5e1;
  background: rgba(255,255,255,.08);
  transition: color calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .lk svg {
  width: 1.3em;
  height: 1.3em;
  overflow: visible;
}

.uvq15-ptn .sh {
  transform-origin: 16px 11px;
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq15-ptn.good .lk {
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn.good .sh {
  transform: translateY(-2px) rotate(30deg);
}

.uvq15-ptn .msg {
  margin: 0;
  font-weight: 700;
  min-height: 1.3em;
  transition: color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn.bad .msg {
  color: var(--c2);
}

.uvq15-ptn.good .msg {
  color: var(--c1);
}

.uvq15-ptn .pad {
  position: relative;
  width: 12em;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.uvq15-ptn .pad svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq15-ptn .ln,.uvq15-ptn .tl {
  fill: none;
  stroke: var(--c1);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .85;
}

.uvq15-ptn .tl {
  opacity: 0;
}

.uvq15-ptn.bad .ln {
  stroke: var(--c2);
}

.uvq15-ptn.bad .pad {
  animation: uvq15-ptn-x calc(0.45s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-x {
  20% {
    transform: translateX(-.4em);
  }
  40% {
    transform: translateX(.35em);
  }
  60% {
    transform: translateX(-.25em);
  }
  80% {
    transform: translateX(.12em);
  }
}

.uvq15-ptn .dt {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  width: 1.05em;
  height: 1.05em;
  margin: -.525em 0 0 -.525em;
  border-radius: 50%;
  background: rgba(255,255,255,.4);
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq15-ptn .dt::before {
  content: "";
  position: absolute;
  inset: -1em;
  border-radius: 50%;
}

.uvq15-ptn .dt:focus-visible {
  outline: 2px solid #fff;
  outline-offset: .35em;
}

.uvq15-ptn .dt.on {
  background: var(--c1);
  transform: scale(1.3);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq15-ptn .dt.hit {
  animation: uvq15-ptn-h calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uvq15-ptn-h {
  40% {
    transform: scale(1.7);
  }
}

.uvq15-ptn.bad .dt.on {
  background: var(--c2);
  box-shadow: 0 0 0 .45em color-mix(in srgb,var(--c2) 25%,transparent);
}

.uvq15-ptn.good .dt.on {
  animation: uvq15-ptn-g calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq15-ptn-g {
  50% {
    box-shadow: 0 0 0 .9em color-mix(in srgb,var(--c1) 0%,transparent);
  }
}

.uvq15-ptn .ht {
  display: flex;
  align-items: center;
  gap: .6em;
  min-height: 2em;
  margin: 0;
  font-size: .72em;
  color: #94a3b8;
}

.uvq15-ptn .ck {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .35em .8em;
  border-radius: 2em;
  font-weight: 700;
  color: #1a2e05;
  background: var(--c1);
}

.uvq15-ptn .ck[hidden] {
  display: none;
}

.uvq15-ptn .ck:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq15-ptn,.uvq15-ptn *,.uvq15-ptn *::before,.uvq15-ptn *::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 k=parseFloat(getComputedStyle(el).getPropertyValue("--k"))||1,rm=matchMedia("(prefers-reduced-motion:reduce)").matches;const pad=el.querySelector(".pad"),ln=el.querySelector(".ln"),tl=el.querySelector(".tl"),msg=el.querySelector(".msg"),ck=el.querySelector(".ck"),ds=[...el.querySelectorAll(".dt")],t0=msg.textContent,KEY="0,3,6,7,8",P=ds.map((d,i)=>[50+(i%3)*100,50+Math.floor(i/3)*100]);let seq=[],on=false,tm=0;
const busy=()=>el.classList.contains("good")||el.classList.contains("bad");
const draw=()=>{ln.setAttribute("points",seq.map(i=>P[i].join(",")).join(" "));ds.forEach((d,i)=>{const s=seq.includes(i);d.classList.toggle("on",s);d.setAttribute("aria-pressed",String(s))});ck.hidden=!seq.length||on||busy()};
const add=i=>{if(seq.includes(i))return;const l=seq[seq.length-1];if(l!==undefined){const m=P.findIndex(p=>p[0]===(P[l][0]+P[i][0])/2&&p[1]===(P[l][1]+P[i][1])/2);if(m>-1&&!seq.includes(m))seq.push(m)}seq.push(i);const d=ds[i];d.classList.remove("hit");void d.offsetWidth;d.classList.add("hit");draw()};
const reset=()=>{clearTimeout(tm);seq=[];el.classList.remove("bad","good");msg.textContent=t0;draw()};
const check=()=>{if(!seq.length)return;const g=seq.join(",")===KEY;el.classList.add(g?"good":"bad");msg.textContent=g?"Unlocked":"Wrong pattern";draw();tm=setTimeout(reset,(g?1800:1000)/k)};
const pt=e=>{const r=pad.getBoundingClientRect();return[(e.clientX-r.left)/r.width*300,(e.clientY-r.top)/r.height*300]};
const near=p=>P.findIndex(q=>Math.hypot(q[0]-p[0],q[1]-p[1])<36);
const tail=p=>{const l=seq[seq.length-1];tl.style.opacity=l===undefined||!p?"0":".45";if(l===undefined||!p)return;tl.setAttribute("x1",String(P[l][0]));tl.setAttribute("y1",String(P[l][1]));tl.setAttribute("x2",String(p[0]));tl.setAttribute("y2",String(p[1]))};
pad.addEventListener("pointerdown",e=>{if(busy())return;e.preventDefault();reset();on=true;pad.setPointerCapture(e.pointerId);const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
pad.addEventListener("pointermove",e=>{if(!on)return;const p=pt(e),i=near(p);if(i>-1)add(i);tail(p)});
const up=()=>{if(!on)return;on=false;tail(null);check()};pad.addEventListener("pointerup",up);pad.addEventListener("pointercancel",up);
ds.forEach((d,i)=>{d.addEventListener("click",e=>{if(e.detail||busy())return;add(i)});d.addEventListener("keydown",e=>{const m={ArrowRight:1,ArrowLeft:-1,ArrowDown:3,ArrowUp:-3}[e.key];if(m!==undefined){e.preventDefault();const j=i+m;if(j>=0&&j<9&&(Math.abs(m)===3||Math.floor(j/3)===Math.floor(i/3)))ds[j].focus()}else if(e.key==="Escape")reset()})});
ck.addEventListener("click",()=>{check();ds[0].focus()});tail(null);return()=>clearTimeout(tm)
}

export default function Mi27PatternLock() {
  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": "#a3e635",
          "--c2": "#f43f5e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq15-ptn"><span className="lk" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path className="sh" d="M8 11V7a4 4 0 0 1 8 0v4" /><rect x="5" y="11" width="14" height="10" rx="2.5" /></svg></span><p className="msg" aria-live="polite">Draw your pattern</p><div className="pad" role="group" aria-label="Unlock pattern"><svg viewBox="0 0 300 300" aria-hidden="true"><polyline className="ln" points="" /><line className="tl" x1="0" y1="0" x2="0" y2="0" /></svg><button type="button" className="dt" style={{ left: "16.667%", top: "16.667%" }} aria-label="1" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "16.667%" }} aria-label="2" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "16.667%" }} aria-label="3" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "16.667%", top: "50.000%" }} aria-label="4" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "50.000%" }} aria-label="5" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "50.000%" }} aria-label="6" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "16.667%", top: "83.333%" }} aria-label="7" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "50.000%", top: "83.333%" }} aria-label="8" aria-pressed="false"></button><button type="button" className="dt" style={{ left: "83.333%", top: "83.333%" }} aria-label="9" aria-pressed="false"></button></div><p className="ht"><span>Hint: draw an L</span><button type="button" className="ck" hidden={true}>Check</button></p></div>
      </div>
    </>
  );
}
```

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