# Corner-snapping mini video player

> A floating video you drag with inertia that snaps to the nearest corner; double-click it to blow it up in the middle.

- Category: [Overlays](https://library.aimran.es/components/overlays)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-ov-pip-player
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Picture in picture players follow you around a page, and this one behaves like the native kind. Drag it with mouse or finger and let go: it keeps its momentum and lands in the closest corner with a spring. A double click enlarges it over a dimmed page, the controls appear on hover and the scene is painted in CSS. It fits course platforms, news sites and live streams.

The two colors set the sunset and the hills of the placeholder scene, so swap it for a real video element when you use it. Arrow keys move it between corners, Enter enlarges it and Escape shrinks or hides it.

## Code

### HTML

```html
<div class="uvq13-pip"><div class="pg" aria-hidden="true"><i class="h"></i><i></i><i></i><i></i><i></i><i class="s"></i></div><p class="hn">Drag the video to another corner</p><div class="scr"></div><button type="button" class="fire">Show video</button><div class="pw" role="region" aria-label="Floating player" tabindex="0"><div class="vd" aria-hidden="true"><i class="sun"></i><i class="cl"></i><i class="h1"></i><i class="h2"></i></div><div class="ct"><button type="button" class="ex" aria-label="Enlarge" aria-pressed="false"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 4h6v6M10 20H4v-6M20 4l-6.5 6.5M4 20l6.5-6.5"/></svg></button><button type="button" class="x" aria-label="Close video"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 7l10 10M17 7L7 17"/></svg></button><button type="button" class="pl" aria-label="Play" aria-pressed="true"><svg class="i1" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l10.5-6.5z" fill="currentColor"/></svg><svg class="i2" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5v14M16 5v14" stroke="currentColor" stroke-width="3.2" stroke-linecap="round"/></svg></button></div><i class="pb" aria-hidden="true"><b></b></i></div></div>
```

### CSS

```css
.uvq13-pip {
  --c1: #fb7a3c;
  --c2: #0f766e;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq13-pip {
  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: 22em;
  height: 17em;
  border-radius: 1.2em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent);
}

.uvq13-pip .pg {
  position: absolute;
  inset: 0;
  padding: 1.2em;
  display: grid;
  align-content: start;
  gap: .55em;
}

.uvq13-pip .pg i {
  height: .6em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-pip .pg .h {
  width: 45%;
  height: 1em;
  margin-bottom: .4em;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uvq13-pip .pg .s {
  width: 60%;
}

.uvq13-pip .scr {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(10,12,20,.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip.open .scr {
  opacity: 1;
  pointer-events: auto;
}

.uvq13-pip .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  right: 1em;
  top: 1em;
  z-index: 1;
  padding: .55em .95em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 650;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .fire:active {
  transform: scale(.96);
}

.uvq13-pip button:focus-visible,.uvq13-pip a:focus-visible,.uvq13-pip input:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .hn {
  position: absolute;
  left: 1.2em;
  bottom: 1.2em;
  margin: 0;
  font-size: .74em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-pip .fire {
  opacity: 0;
  pointer-events: none;
  transform: scale(.9);
}

.uvq13-pip.gone .fire {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.uvq13-pip .pw {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: 9.6em;
  aspect-ratio: 16/9;
  border-radius: .8em;
  overflow: hidden;
  background: #111;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08),0 1em 2em -.8em rgba(0,0,0,.65);
  transform-origin: 0 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),border-radius calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw.dr {
  transition: none;
  cursor: grabbing;
}

.uvq13-pip .pw.big {
  cursor: default;
}

.uvq13-pip.gone .pw {
  opacity: 0;
  pointer-events: none;
}

.uvq13-pip .pw:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .vd {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg,#26335f 0%,#7a4a7e 42%,var(--c1) 72%,#ffd08a 80%);
}

.uvq13-pip .vd i {
  position: absolute;
  display: block;
}

.uvq13-pip .sun {
  left: 56%;
  top: 48%;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: radial-gradient(circle,#fff7d6,#ffd27a 55%,transparent 70%);
}

.uvq13-pip .cl {
  left: -3em;
  top: 16%;
  width: 2.6em;
  height: .65em;
  border-radius: 1em;
  background: rgba(255,255,255,.55);
  box-shadow: 4em .7em 0 -.1em rgba(255,255,255,.4),8.5em -.2em 0 -.15em rgba(255,255,255,.35);
  animation: uvq13-pip-c calc(9s / var(--k)) linear infinite;
}

.uvq13-pip .h1 {
  left: -10%;
  right: 20%;
  bottom: -38%;
  height: 75%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 80%,#000);
}

.uvq13-pip .h2 {
  left: 35%;
  right: -30%;
  bottom: -48%;
  height: 80%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 45%,#000);
}

.uvq13-pip .pa .vd *,.uvq13-pip .pa .pb b {
  animation-play-state: paused;
}

.uvq13-pip .ct {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  gap: .3em;
  padding: .4em;
  background: linear-gradient(180deg,rgba(0,0,0,.45),transparent 45%,transparent 70%,rgba(0,0,0,.4));
  opacity: 0;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw:hover .ct,.uvq13-pip .pw:focus-within .ct,.uvq13-pip .big .ct,.uvq13-pip .pa .ct {
  opacity: 1;
}

@media (hover:none) {
  .uvq13-pip .ct {
    opacity: 1;
  }
}

.uvq13-pip .ct button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  color: #fff;
  background: rgba(0,0,0,.38);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-pip .ct button:hover {
  transform: scale(1.1);
}

.uvq13-pip .ct button svg {
  width: .9em;
  height: .9em;
}

.uvq13-pip .ct .pl {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.2em;
  height: 2.2em;
  margin: -1.1em;
}

.uvq13-pip .ct .pl svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq13-pip .pl .i1,.uvq13-pip .pa .pl .i2 {
  display: none;
}

.uvq13-pip .pa .pl .i1 {
  display: block;
}

.uvq13-pip .ct button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.uvq13-pip .pb {
  position: absolute;
  left: .55em;
  right: .55em;
  bottom: .45em;
  height: .18em;
  border-radius: 1em;
  background: rgba(255,255,255,.3);
  overflow: hidden;
}

.uvq13-pip .pb b {
  display: block;
  height: 100%;
  background: #fff;
  transform-origin: 0 0;
  animation: uvq13-pip-p calc(40s / var(--k)) linear infinite;
}

@keyframes uvq13-pip-c {
  to {
    transform: translateX(15em);
  }
}

@keyframes uvq13-pip-p {
  from {
    transform: scaleX(0);
  }
}

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

### JavaScript

```js
document.querySelectorAll(".uvq13-pip").forEach(el => {
  const pw=el.querySelector(".pw"),fire=el.querySelector(".fire"),scr=el.querySelector(".scr"),pl=el.querySelector(".pl"),ex=el.querySelector(".ex");let cx=1,cy=1,big=false,x=0,y=0,d=null;const M=12;
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const put=(nx,ny,s)=>{x=nx;y=ny;pw.style.transform="translate("+nx+"px,"+ny+"px) scale("+(s||1)+")"};
const snap=()=>{const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;if(big){const s=Math.min(W*.86/w,H*.8/h);put((W-w*s)/2,(H-h*s)/2,s)}else put(cx?W-w-M:M,cy?H-h-M:M)};
const setBig=b=>{big=b;el.classList.toggle("open",b);pw.classList.toggle("big",b);ex.setAttribute("aria-pressed",String(b));snap()};
pw.addEventListener("pointerdown",e=>{if(big||e.button>0||e.target.closest("button"))return;d={px:e.clientX,py:e.clientY,ox:x,oy:y,s:sc(),lx:e.clientX,ly:e.clientY,lt:performance.now(),vx:0,vy:0};pw.setPointerCapture(e.pointerId);pw.classList.add("dr")});
pw.addEventListener("pointermove",e=>{if(!d)return;const t=performance.now(),dt=Math.max(1,t-d.lt);d.vx=(e.clientX-d.lx)/d.s/dt;d.vy=(e.clientY-d.ly)/d.s/dt;d.lx=e.clientX;d.ly=e.clientY;d.lt=t;put(d.ox+(e.clientX-d.px)/d.s,d.oy+(e.clientY-d.py)/d.s)});
const up=()=>{if(!d)return;pw.classList.remove("dr");const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;cx=x+d.vx*200+w/2>W/2?1:0;cy=y+d.vy*200+h/2>H/2?1:0;d=null;snap()};
pw.addEventListener("pointerup",up);pw.addEventListener("pointercancel",up);
pw.addEventListener("dblclick",e=>{if(!e.target.closest("button"))setBig(!big)});
const hide=()=>{setBig(false);el.classList.add("gone");fire.focus({preventScroll:true})};
fire.addEventListener("click",()=>{el.classList.remove("gone");pw.focus({preventScroll:true})});
el.querySelector(".x").addEventListener("click",hide);ex.addEventListener("click",()=>setBig(!big));scr.addEventListener("click",()=>setBig(false));
pl.addEventListener("click",()=>{const p=pl.getAttribute("aria-pressed")==="true";pl.setAttribute("aria-pressed",String(!p));pw.classList.toggle("pa",p)});
pw.addEventListener("keydown",e=>{if(e.target!==pw)return;const m={ArrowLeft:[0,cy],ArrowRight:[1,cy],ArrowUp:[cx,0],ArrowDown:[cx,1]}[e.key];if(m&&!big){e.preventDefault();cx=m[0];cy=m[1];snap()}else if(e.key==="Enter"||e.key===" "){e.preventDefault();setBig(!big)}});
el.addEventListener("keydown",e=>{if(e.key!=="Escape")return;if(big){e.preventDefault();setBig(false);pw.focus({preventScroll:true})}else if(pw.contains(document.activeElement)){e.preventDefault();hide()}});
const ro=new ResizeObserver(()=>{if(d)return;pw.classList.add("dr");snap();requestAnimationFrame(()=>pw.classList.remove("dr"))});ro.observe(el);
pw.classList.add("dr");snap();requestAnimationFrame(()=>requestAnimationFrame(()=>pw.classList.remove("dr")));return()=>ro.disconnect()
});
```

### 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 = `
.uvq13-pip {
  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: 22em;
  height: 17em;
  border-radius: 1.2em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent);
}

.uvq13-pip .pg {
  position: absolute;
  inset: 0;
  padding: 1.2em;
  display: grid;
  align-content: start;
  gap: .55em;
}

.uvq13-pip .pg i {
  height: .6em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-pip .pg .h {
  width: 45%;
  height: 1em;
  margin-bottom: .4em;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uvq13-pip .pg .s {
  width: 60%;
}

.uvq13-pip .scr {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(10,12,20,.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip.open .scr {
  opacity: 1;
  pointer-events: auto;
}

.uvq13-pip .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  right: 1em;
  top: 1em;
  z-index: 1;
  padding: .55em .95em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 650;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .fire:active {
  transform: scale(.96);
}

.uvq13-pip button:focus-visible,.uvq13-pip a:focus-visible,.uvq13-pip input:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .hn {
  position: absolute;
  left: 1.2em;
  bottom: 1.2em;
  margin: 0;
  font-size: .74em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-pip .fire {
  opacity: 0;
  pointer-events: none;
  transform: scale(.9);
}

.uvq13-pip.gone .fire {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.uvq13-pip .pw {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: 9.6em;
  aspect-ratio: 16/9;
  border-radius: .8em;
  overflow: hidden;
  background: #111;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08),0 1em 2em -.8em rgba(0,0,0,.65);
  transform-origin: 0 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),border-radius calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw.dr {
  transition: none;
  cursor: grabbing;
}

.uvq13-pip .pw.big {
  cursor: default;
}

.uvq13-pip.gone .pw {
  opacity: 0;
  pointer-events: none;
}

.uvq13-pip .pw:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .vd {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg,#26335f 0%,#7a4a7e 42%,var(--c1) 72%,#ffd08a 80%);
}

.uvq13-pip .vd i {
  position: absolute;
  display: block;
}

.uvq13-pip .sun {
  left: 56%;
  top: 48%;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: radial-gradient(circle,#fff7d6,#ffd27a 55%,transparent 70%);
}

.uvq13-pip .cl {
  left: -3em;
  top: 16%;
  width: 2.6em;
  height: .65em;
  border-radius: 1em;
  background: rgba(255,255,255,.55);
  box-shadow: 4em .7em 0 -.1em rgba(255,255,255,.4),8.5em -.2em 0 -.15em rgba(255,255,255,.35);
  animation: uvq13-pip-c calc(9s / var(--k)) linear infinite;
}

.uvq13-pip .h1 {
  left: -10%;
  right: 20%;
  bottom: -38%;
  height: 75%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 80%,#000);
}

.uvq13-pip .h2 {
  left: 35%;
  right: -30%;
  bottom: -48%;
  height: 80%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 45%,#000);
}

.uvq13-pip .pa .vd *,.uvq13-pip .pa .pb b {
  animation-play-state: paused;
}

.uvq13-pip .ct {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  gap: .3em;
  padding: .4em;
  background: linear-gradient(180deg,rgba(0,0,0,.45),transparent 45%,transparent 70%,rgba(0,0,0,.4));
  opacity: 0;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw:hover .ct,.uvq13-pip .pw:focus-within .ct,.uvq13-pip .big .ct,.uvq13-pip .pa .ct {
  opacity: 1;
}

@media (hover:none) {
  .uvq13-pip .ct {
    opacity: 1;
  }
}

.uvq13-pip .ct button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  color: #fff;
  background: rgba(0,0,0,.38);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-pip .ct button:hover {
  transform: scale(1.1);
}

.uvq13-pip .ct button svg {
  width: .9em;
  height: .9em;
}

.uvq13-pip .ct .pl {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.2em;
  height: 2.2em;
  margin: -1.1em;
}

.uvq13-pip .ct .pl svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq13-pip .pl .i1,.uvq13-pip .pa .pl .i2 {
  display: none;
}

.uvq13-pip .pa .pl .i1 {
  display: block;
}

.uvq13-pip .ct button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.uvq13-pip .pb {
  position: absolute;
  left: .55em;
  right: .55em;
  bottom: .45em;
  height: .18em;
  border-radius: 1em;
  background: rgba(255,255,255,.3);
  overflow: hidden;
}

.uvq13-pip .pb b {
  display: block;
  height: 100%;
  background: #fff;
  transform-origin: 0 0;
  animation: uvq13-pip-p calc(40s / var(--k)) linear infinite;
}

@keyframes uvq13-pip-c {
  to {
    transform: translateX(15em);
  }
}

@keyframes uvq13-pip-p {
  from {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq13-pip,.uvq13-pip *,.uvq13-pip *::before,.uvq13-pip *::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 pw=el.querySelector(".pw"),fire=el.querySelector(".fire"),scr=el.querySelector(".scr"),pl=el.querySelector(".pl"),ex=el.querySelector(".ex");let cx=1,cy=1,big=false,x=0,y=0,d=null;const M=12;
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const put=(nx,ny,s)=>{x=nx;y=ny;pw.style.transform="translate("+nx+"px,"+ny+"px) scale("+(s||1)+")"};
const snap=()=>{const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;if(big){const s=Math.min(W*.86/w,H*.8/h);put((W-w*s)/2,(H-h*s)/2,s)}else put(cx?W-w-M:M,cy?H-h-M:M)};
const setBig=b=>{big=b;el.classList.toggle("open",b);pw.classList.toggle("big",b);ex.setAttribute("aria-pressed",String(b));snap()};
pw.addEventListener("pointerdown",e=>{if(big||e.button>0||e.target.closest("button"))return;d={px:e.clientX,py:e.clientY,ox:x,oy:y,s:sc(),lx:e.clientX,ly:e.clientY,lt:performance.now(),vx:0,vy:0};pw.setPointerCapture(e.pointerId);pw.classList.add("dr")});
pw.addEventListener("pointermove",e=>{if(!d)return;const t=performance.now(),dt=Math.max(1,t-d.lt);d.vx=(e.clientX-d.lx)/d.s/dt;d.vy=(e.clientY-d.ly)/d.s/dt;d.lx=e.clientX;d.ly=e.clientY;d.lt=t;put(d.ox+(e.clientX-d.px)/d.s,d.oy+(e.clientY-d.py)/d.s)});
const up=()=>{if(!d)return;pw.classList.remove("dr");const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;cx=x+d.vx*200+w/2>W/2?1:0;cy=y+d.vy*200+h/2>H/2?1:0;d=null;snap()};
pw.addEventListener("pointerup",up);pw.addEventListener("pointercancel",up);
pw.addEventListener("dblclick",e=>{if(!e.target.closest("button"))setBig(!big)});
const hide=()=>{setBig(false);el.classList.add("gone");fire.focus({preventScroll:true})};
fire.addEventListener("click",()=>{el.classList.remove("gone");pw.focus({preventScroll:true})});
el.querySelector(".x").addEventListener("click",hide);ex.addEventListener("click",()=>setBig(!big));scr.addEventListener("click",()=>setBig(false));
pl.addEventListener("click",()=>{const p=pl.getAttribute("aria-pressed")==="true";pl.setAttribute("aria-pressed",String(!p));pw.classList.toggle("pa",p)});
pw.addEventListener("keydown",e=>{if(e.target!==pw)return;const m={ArrowLeft:[0,cy],ArrowRight:[1,cy],ArrowUp:[cx,0],ArrowDown:[cx,1]}[e.key];if(m&&!big){e.preventDefault();cx=m[0];cy=m[1];snap()}else if(e.key==="Enter"||e.key===" "){e.preventDefault();setBig(!big)}});
el.addEventListener("keydown",e=>{if(e.key!=="Escape")return;if(big){e.preventDefault();setBig(false);pw.focus({preventScroll:true})}else if(pw.contains(document.activeElement)){e.preventDefault();hide()}});
const ro=new ResizeObserver(()=>{if(d)return;pw.classList.add("dr");snap();requestAnimationFrame(()=>pw.classList.remove("dr"))});ro.observe(el);
pw.classList.add("dr");snap();requestAnimationFrame(()=>requestAnimationFrame(()=>pw.classList.remove("dr")));return()=>ro.disconnect()
}

export default function OvPipPlayer() {
  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": "#fb7a3c",
          "--c2": "#0f766e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq13-pip"><div className="pg" aria-hidden="true"><i className="h"></i><i></i><i></i><i></i><i></i><i className="s"></i></div><p className="hn">Drag the video to another corner</p><div className="scr"></div><button type="button" className="fire">Show video</button><div className="pw" role="region" aria-label="Floating player" tabIndex={0}><div className="vd" aria-hidden="true"><i className="sun"></i><i className="cl"></i><i className="h1"></i><i className="h2"></i></div><div className="ct"><button type="button" className="ex" aria-label="Enlarge" aria-pressed="false"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M14 4h6v6M10 20H4v-6M20 4l-6.5 6.5M4 20l6.5-6.5" /></svg></button><button type="button" className="x" aria-label="Close video"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M7 7l10 10M17 7L7 17" /></svg></button><button type="button" className="pl" aria-label="Play" aria-pressed="true"><svg className="i1" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l10.5-6.5z" fill="currentColor" /></svg><svg className="i2" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5v14M16 5v14" stroke="currentColor" strokeWidth="3.2" strokeLinecap="round" /></svg></button></div><i className="pb" aria-hidden="true"><b></b></i></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 “Corner-snapping mini video player” block (Overlays) from AIMRAN Library to my project.

## What it is
A floating video you drag with inertia that snaps to the nearest corner; double-click it to blow it up in the middle.

## Chosen settings
- Main color: #fb7a3c
- Secondary color: #0f766e
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Reproductor flotante"

## 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 = `
.uvq13-pip {
  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: 22em;
  height: 17em;
  border-radius: 1.2em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent);
}

.uvq13-pip .pg {
  position: absolute;
  inset: 0;
  padding: 1.2em;
  display: grid;
  align-content: start;
  gap: .55em;
}

.uvq13-pip .pg i {
  height: .6em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-pip .pg .h {
  width: 45%;
  height: 1em;
  margin-bottom: .4em;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uvq13-pip .pg .s {
  width: 60%;
}

.uvq13-pip .scr {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(10,12,20,.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip.open .scr {
  opacity: 1;
  pointer-events: auto;
}

.uvq13-pip .fire {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  right: 1em;
  top: 1em;
  z-index: 1;
  padding: .55em .95em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 650;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .fire:active {
  transform: scale(.96);
}

.uvq13-pip button:focus-visible,.uvq13-pip a:focus-visible,.uvq13-pip input:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .hn {
  position: absolute;
  left: 1.2em;
  bottom: 1.2em;
  margin: 0;
  font-size: .74em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-pip .fire {
  opacity: 0;
  pointer-events: none;
  transform: scale(.9);
}

.uvq13-pip.gone .fire {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.uvq13-pip .pw {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: 9.6em;
  aspect-ratio: 16/9;
  border-radius: .8em;
  overflow: hidden;
  background: #111;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08),0 1em 2em -.8em rgba(0,0,0,.65);
  transform-origin: 0 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),border-radius calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw.dr {
  transition: none;
  cursor: grabbing;
}

.uvq13-pip .pw.big {
  cursor: default;
}

.uvq13-pip.gone .pw {
  opacity: 0;
  pointer-events: none;
}

.uvq13-pip .pw:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-pip .vd {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg,#26335f 0%,#7a4a7e 42%,var(--c1) 72%,#ffd08a 80%);
}

.uvq13-pip .vd i {
  position: absolute;
  display: block;
}

.uvq13-pip .sun {
  left: 56%;
  top: 48%;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: radial-gradient(circle,#fff7d6,#ffd27a 55%,transparent 70%);
}

.uvq13-pip .cl {
  left: -3em;
  top: 16%;
  width: 2.6em;
  height: .65em;
  border-radius: 1em;
  background: rgba(255,255,255,.55);
  box-shadow: 4em .7em 0 -.1em rgba(255,255,255,.4),8.5em -.2em 0 -.15em rgba(255,255,255,.35);
  animation: uvq13-pip-c calc(9s / var(--k)) linear infinite;
}

.uvq13-pip .h1 {
  left: -10%;
  right: 20%;
  bottom: -38%;
  height: 75%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 80%,#000);
}

.uvq13-pip .h2 {
  left: 35%;
  right: -30%;
  bottom: -48%;
  height: 80%;
  border-radius: 50% 50% 0 0;
  background: color-mix(in srgb,var(--c2) 45%,#000);
}

.uvq13-pip .pa .vd *,.uvq13-pip .pa .pb b {
  animation-play-state: paused;
}

.uvq13-pip .ct {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  gap: .3em;
  padding: .4em;
  background: linear-gradient(180deg,rgba(0,0,0,.45),transparent 45%,transparent 70%,rgba(0,0,0,.4));
  opacity: 0;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-pip .pw:hover .ct,.uvq13-pip .pw:focus-within .ct,.uvq13-pip .big .ct,.uvq13-pip .pa .ct {
  opacity: 1;
}

@media (hover:none) {
  .uvq13-pip .ct {
    opacity: 1;
  }
}

.uvq13-pip .ct button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  color: #fff;
  background: rgba(0,0,0,.38);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-pip .ct button:hover {
  transform: scale(1.1);
}

.uvq13-pip .ct button svg {
  width: .9em;
  height: .9em;
}

.uvq13-pip .ct .pl {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.2em;
  height: 2.2em;
  margin: -1.1em;
}

.uvq13-pip .ct .pl svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq13-pip .pl .i1,.uvq13-pip .pa .pl .i2 {
  display: none;
}

.uvq13-pip .pa .pl .i1 {
  display: block;
}

.uvq13-pip .ct button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.uvq13-pip .pb {
  position: absolute;
  left: .55em;
  right: .55em;
  bottom: .45em;
  height: .18em;
  border-radius: 1em;
  background: rgba(255,255,255,.3);
  overflow: hidden;
}

.uvq13-pip .pb b {
  display: block;
  height: 100%;
  background: #fff;
  transform-origin: 0 0;
  animation: uvq13-pip-p calc(40s / var(--k)) linear infinite;
}

@keyframes uvq13-pip-c {
  to {
    transform: translateX(15em);
  }
}

@keyframes uvq13-pip-p {
  from {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq13-pip,.uvq13-pip *,.uvq13-pip *::before,.uvq13-pip *::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 pw=el.querySelector(".pw"),fire=el.querySelector(".fire"),scr=el.querySelector(".scr"),pl=el.querySelector(".pl"),ex=el.querySelector(".ex");let cx=1,cy=1,big=false,x=0,y=0,d=null;const M=12;
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const put=(nx,ny,s)=>{x=nx;y=ny;pw.style.transform="translate("+nx+"px,"+ny+"px) scale("+(s||1)+")"};
const snap=()=>{const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;if(big){const s=Math.min(W*.86/w,H*.8/h);put((W-w*s)/2,(H-h*s)/2,s)}else put(cx?W-w-M:M,cy?H-h-M:M)};
const setBig=b=>{big=b;el.classList.toggle("open",b);pw.classList.toggle("big",b);ex.setAttribute("aria-pressed",String(b));snap()};
pw.addEventListener("pointerdown",e=>{if(big||e.button>0||e.target.closest("button"))return;d={px:e.clientX,py:e.clientY,ox:x,oy:y,s:sc(),lx:e.clientX,ly:e.clientY,lt:performance.now(),vx:0,vy:0};pw.setPointerCapture(e.pointerId);pw.classList.add("dr")});
pw.addEventListener("pointermove",e=>{if(!d)return;const t=performance.now(),dt=Math.max(1,t-d.lt);d.vx=(e.clientX-d.lx)/d.s/dt;d.vy=(e.clientY-d.ly)/d.s/dt;d.lx=e.clientX;d.ly=e.clientY;d.lt=t;put(d.ox+(e.clientX-d.px)/d.s,d.oy+(e.clientY-d.py)/d.s)});
const up=()=>{if(!d)return;pw.classList.remove("dr");const W=el.clientWidth,H=el.clientHeight,w=pw.offsetWidth,h=pw.offsetHeight;cx=x+d.vx*200+w/2>W/2?1:0;cy=y+d.vy*200+h/2>H/2?1:0;d=null;snap()};
pw.addEventListener("pointerup",up);pw.addEventListener("pointercancel",up);
pw.addEventListener("dblclick",e=>{if(!e.target.closest("button"))setBig(!big)});
const hide=()=>{setBig(false);el.classList.add("gone");fire.focus({preventScroll:true})};
fire.addEventListener("click",()=>{el.classList.remove("gone");pw.focus({preventScroll:true})});
el.querySelector(".x").addEventListener("click",hide);ex.addEventListener("click",()=>setBig(!big));scr.addEventListener("click",()=>setBig(false));
pl.addEventListener("click",()=>{const p=pl.getAttribute("aria-pressed")==="true";pl.setAttribute("aria-pressed",String(!p));pw.classList.toggle("pa",p)});
pw.addEventListener("keydown",e=>{if(e.target!==pw)return;const m={ArrowLeft:[0,cy],ArrowRight:[1,cy],ArrowUp:[cx,0],ArrowDown:[cx,1]}[e.key];if(m&&!big){e.preventDefault();cx=m[0];cy=m[1];snap()}else if(e.key==="Enter"||e.key===" "){e.preventDefault();setBig(!big)}});
el.addEventListener("keydown",e=>{if(e.key!=="Escape")return;if(big){e.preventDefault();setBig(false);pw.focus({preventScroll:true})}else if(pw.contains(document.activeElement)){e.preventDefault();hide()}});
const ro=new ResizeObserver(()=>{if(d)return;pw.classList.add("dr");snap();requestAnimationFrame(()=>pw.classList.remove("dr"))});ro.observe(el);
pw.classList.add("dr");snap();requestAnimationFrame(()=>requestAnimationFrame(()=>pw.classList.remove("dr")));return()=>ro.disconnect()
}

export default function OvPipPlayer() {
  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": "#fb7a3c",
          "--c2": "#0f766e",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq13-pip"><div className="pg" aria-hidden="true"><i className="h"></i><i></i><i></i><i></i><i></i><i className="s"></i></div><p className="hn">Drag the video to another corner</p><div className="scr"></div><button type="button" className="fire">Show video</button><div className="pw" role="region" aria-label="Floating player" tabIndex={0}><div className="vd" aria-hidden="true"><i className="sun"></i><i className="cl"></i><i className="h1"></i><i className="h2"></i></div><div className="ct"><button type="button" className="ex" aria-label="Enlarge" aria-pressed="false"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M14 4h6v6M10 20H4v-6M20 4l-6.5 6.5M4 20l6.5-6.5" /></svg></button><button type="button" className="x" aria-label="Close video"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M7 7l10 10M17 7L7 17" /></svg></button><button type="button" className="pl" aria-label="Play" aria-pressed="true"><svg className="i1" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l10.5-6.5z" fill="currentColor" /></svg><svg className="i2" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5v14M16 5v14" stroke="currentColor" strokeWidth="3.2" strokeLinecap="round" /></svg></button></div><i className="pb" aria-hidden="true"><b></b></i></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.
````
