# Comment thread anchored in the margin

> Click a highlighted sentence and its comment thread appears in the margin joined by a line, with replies and a resolve button.

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

## Where to use it

Shared documents keep discussion next to the text, and this overlay recreates that layout. Highlighted sentences carry a count badge in the margin, and opening one slides its thread alongside, aligned with the line and linked by a dashed curve. You can reply with Enter, and resolving removes the highlight and confirms with a small notice. It fits editors, review tools, contracts and design feedback.

The main color is the highlight and the connector, the second one the badges and actions. Wrap any sentence in a highlight button pointing at its thread, and Escape or a click outside closes the card and returns focus to the text.

## Code

### HTML

```html
<div class="uvq13-cmt"><div class="doc"><p class="kk">Document</p><p class="h" tabindex="-1">Redesign proposal</p><p class="tx"><span>The new home page must load in under two seconds.</span> <button type="button" class="hl" aria-expanded="false" aria-controls="uvq13-cmt-0">We propose removing the carousel and keeping a single still image.</button> <span>That way the main content shows up sooner.</span></p><p class="tx"><button type="button" class="hl" aria-expanded="false" aria-controls="uvq13-cmt-1">Buttons will have a single action color.</button> <span>All other links will be underlined.</span></p></div><span class="bg" aria-hidden="true">2</span><span class="bg" aria-hidden="true">1</span><svg class="ln" aria-hidden="true"><path/></svg><section class="cm" id="uvq13-cmt-0" role="dialog" aria-label="Comments"><ul><li><span class="av" style="--c:#db2777">S</span><div><b>Sara</b><small>hace 5 min</small><p>What if we keep the carousel on mobile only?</p></div></li><li><span class="av" style="--c:#0284c7">L</span><div><b>Leo</b><small>2 min ago</small><p>We will try it in the next version.</p></div></li><li class="tpl" hidden><span class="av" style="--c:#64748b">T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div class="rp"><input placeholder="Reply…" aria-label="Reply" autocomplete="off"><button type="button" class="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z"/></svg></button></div><button type="button" class="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><span>Resolve</span></button></section><section class="cm" id="uvq13-cmt-1" role="dialog" aria-label="Comments"><ul><li><span class="av" style="--c:#0284c7">L</span><div><b>Leo</b><small>1 h ago</small><p>Let's check the contrast of the new color.</p></div></li><li class="tpl" hidden><span class="av" style="--c:#64748b">T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div class="rp"><input placeholder="Reply…" aria-label="Reply" autocomplete="off"><button type="button" class="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z"/></svg></button></div><button type="button" class="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><span>Resolve</span></button></section><p class="toast" aria-live="polite"><span>Comment resolved</span></p></div>
```

### CSS

```css
.uvq13-cmt {
  --c1: #f59e0b;
  --c2: #0284c7;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq13-cmt {
  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: 18em;
  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-cmt .doc {
  position: absolute;
  left: 1em;
  top: 1em;
  bottom: 1em;
  width: 12.4em;
  padding: 1em 1.1em;
  box-sizing: border-box;
  border-radius: .6em;
  background: var(--bg);
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .5em 1.2em -.8em rgba(0,0,0,.3);
}

.uvq13-cmt .kk {
  margin: 0;
  font-size: .58em;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt .h {
  margin: .3em 0 .5em;
  font-size: .95em;
  font-weight: 800;
  line-height: 1.15;
  outline: 0;
}

.uvq13-cmt .tx {
  margin: 0 0 .6em;
  font-size: .66em;
  line-height: 1.6;
}

.uvq13-cmt .hl {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: inline;
  padding: 0 .1em;
  border-radius: .15em;
  text-align: left;
  background: color-mix(in srgb,var(--c1) 28%,transparent);
  box-shadow: inset 0 -2px 0 var(--c1);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt .hl:hover,.uvq13-cmt .hl[aria-expanded="true"] {
  background: color-mix(in srgb,var(--c1) 55%,transparent);
}

.uvq13-cmt .hl:disabled {
  color: inherit;
  background: none;
  box-shadow: none;
  cursor: text;
}

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

.uvq13-cmt .bg {
  position: absolute;
  left: 19.6em;
  display: grid;
  place-items: center;
  width: 1.7em;
  height: 1.5em;
  border-radius: .6em .6em .6em .15em;
  font-size: .72em;
  font-weight: 800;
  color: #fff;
  background: var(--c2);
  cursor: pointer;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-cmt .bg.on {
  opacity: 0;
  transform: scale(.5);
}

.uvq13-cmt .bg.done {
  display: none;
}

.uvq13-cmt .ln {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq13-cmt .ln path {
  fill: none;
  stroke: var(--c1);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt.open .ln path {
  opacity: 1;
}

.uvq13-cmt .cm {
  position: absolute;
  left: 14.1em;
  top: 1em;
  z-index: 3;
  width: 7.2em;
  padding: .6em;
  box-sizing: border-box;
  border-radius: .7em;
  background: color-mix(in srgb,var(--fg) 2%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 1.6em 3.2em -1.2em rgba(0,0,0,.5);
  background: var(--bg);
  opacity: 0;
  transform: translateX(.8em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),top calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .cm.on {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uvq13-cmt ul {
  list-style: none;
  display: grid;
  gap: .55em;
  margin: 0;
  padding: 0;
}

.uvq13-cmt li {
  display: flex;
  gap: .4em;
  font-size: .6em;
}

.uvq13-cmt .av {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  font-weight: 800;
  color: #fff;
  background: var(--c);
}

.uvq13-cmt li small {
  margin-left: .35em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt li p {
  margin: .15em 0 0;
  line-height: 1.35;
}

.uvq13-cmt .rp {
  display: flex;
  gap: .3em;
  margin-top: .6em;
}

.uvq13-cmt .rp input {
  flex: 1;
  min-width: 0;
  padding: .4em .5em;
  border: 0;
  outline: 0;
  border-radius: .5em;
  font: inherit;
  font-size: .6em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-cmt .rp input:focus {
  box-shadow: 0 0 0 2px var(--c2);
}

.uvq13-cmt .sd {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  color: #fff;
  background: var(--c2);
}

.uvq13-cmt .sd svg {
  width: .8em;
  height: .8em;
}

.uvq13-cmt .rs {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: .3em;
  margin-top: .55em;
  font-size: .62em;
  font-weight: 700;
  color: var(--c2);
}

.uvq13-cmt .rs svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq13-cmt .cm button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-cmt .toast {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 4;
  margin: 0;
  padding: .45em .9em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  white-space: nowrap;
  color: var(--bg);
  background: var(--fg);
  opacity: 0;
  transform: translate(-50%,.5em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .toast.on {
  opacity: 1;
  transform: translate(-50%,0);
}

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

### JavaScript

```js
document.querySelectorAll(".uvq13-cmt").forEach(el => {
  const hls=[...el.querySelectorAll(".hl")],cms=[...el.querySelectorAll(".cm")],pth=el.querySelector(".ln path"),bgs=[...el.querySelectorAll(".bg")],toast=el.querySelector(".toast");let cur=-1,tms=[];const later=(f,ms)=>tms.push(setTimeout(f,ms));
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const pos=r=>{const R=el.getBoundingClientRect(),s=sc();return{y:(r.top-R.top)/s,r:(r.right-R.left)/s,b:(r.bottom-R.top)/s}};
const place=i=>{const rs=hls[i].getClientRects(),f=pos(rs[0]),l=pos(rs[rs.length-1]),c=cms[i];const top=Math.max(8,Math.min(el.clientHeight-c.offsetHeight-8,f.y-6));c.style.top=top+"px";const cx=c.offsetLeft,cy=top+14,sx=l.r+2,sy=(l.y+l.b)/2;pth.setAttribute("d","M"+sx+" "+sy+"C"+(sx+24)+" "+sy+" "+(cx-24)+" "+cy+" "+cx+" "+cy)};
const badges=()=>hls.forEach((h,i)=>{const r=h.getClientRects()[0];if(r)bgs[i].style.top=pos(r).y+"px"});
const hide=back=>{if(cur<0)return;const i=cur;cur=-1;cms[i].classList.remove("on");cms[i].inert=true;hls[i].setAttribute("aria-expanded","false");el.classList.remove("open");bgs[i].classList.remove("on");back&&hls[i].focus({preventScroll:true})};
const show=(i,u)=>{if(cur===i){hide(true);return}hide(false);cur=i;place(i);cms[i].classList.add("on");cms[i].inert=false;hls[i].setAttribute("aria-expanded","true");el.classList.add("open");bgs[i].classList.add("on");u&&later(()=>cms[i].querySelector("input").focus({preventScroll:true}),260)};
hls.forEach((h,i)=>h.addEventListener("click",()=>show(i,true)));bgs.forEach((b,i)=>b.addEventListener("click",()=>!hls[i].disabled&&show(i,true)));
cms.forEach((c,i)=>{c.inert=true;const inp=c.querySelector("input"),ul=c.querySelector("ul");const send=()=>{const v=inp.value.trim();if(!v)return;const li=c.querySelector(".tpl").cloneNode(true);li.hidden=false;li.classList.remove("tpl");li.querySelector("p").textContent=v;ul.insertBefore(li,c.querySelector(".tpl"));inp.value="";place(i)};
inp.addEventListener("keydown",e=>{if(e.key==="Enter"){e.preventDefault();send()}});c.querySelector(".sd").addEventListener("click",send);
c.querySelector(".rs").addEventListener("click",()=>{hide(false);hls[i].disabled=true;bgs[i].classList.add("done");toast.classList.add("on");later(()=>toast.classList.remove("on"),1800);const n=hls.find(h=>!h.disabled);(n||el.querySelector(".h")).focus({preventScroll:true})})});
el.addEventListener("keydown",e=>{if(e.key==="Escape"&&cur>-1){e.preventDefault();hide(true)}});
el.addEventListener("pointerdown",e=>{if(cur>-1&&!e.target.closest(".cm,.hl,.bg"))hide(false)});
const ro=new ResizeObserver(()=>{badges();if(cur>-1)place(cur)});ro.observe(el);
badges();later(()=>show(0,false),700);return()=>{tms.forEach(clearTimeout);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-cmt {
  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: 18em;
  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-cmt .doc {
  position: absolute;
  left: 1em;
  top: 1em;
  bottom: 1em;
  width: 12.4em;
  padding: 1em 1.1em;
  box-sizing: border-box;
  border-radius: .6em;
  background: var(--bg);
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .5em 1.2em -.8em rgba(0,0,0,.3);
}

.uvq13-cmt .kk {
  margin: 0;
  font-size: .58em;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt .h {
  margin: .3em 0 .5em;
  font-size: .95em;
  font-weight: 800;
  line-height: 1.15;
  outline: 0;
}

.uvq13-cmt .tx {
  margin: 0 0 .6em;
  font-size: .66em;
  line-height: 1.6;
}

.uvq13-cmt .hl {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: inline;
  padding: 0 .1em;
  border-radius: .15em;
  text-align: left;
  background: color-mix(in srgb,var(--c1) 28%,transparent);
  box-shadow: inset 0 -2px 0 var(--c1);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt .hl:hover,.uvq13-cmt .hl[aria-expanded="true"] {
  background: color-mix(in srgb,var(--c1) 55%,transparent);
}

.uvq13-cmt .hl:disabled {
  color: inherit;
  background: none;
  box-shadow: none;
  cursor: text;
}

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

.uvq13-cmt .bg {
  position: absolute;
  left: 19.6em;
  display: grid;
  place-items: center;
  width: 1.7em;
  height: 1.5em;
  border-radius: .6em .6em .6em .15em;
  font-size: .72em;
  font-weight: 800;
  color: #fff;
  background: var(--c2);
  cursor: pointer;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-cmt .bg.on {
  opacity: 0;
  transform: scale(.5);
}

.uvq13-cmt .bg.done {
  display: none;
}

.uvq13-cmt .ln {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq13-cmt .ln path {
  fill: none;
  stroke: var(--c1);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt.open .ln path {
  opacity: 1;
}

.uvq13-cmt .cm {
  position: absolute;
  left: 14.1em;
  top: 1em;
  z-index: 3;
  width: 7.2em;
  padding: .6em;
  box-sizing: border-box;
  border-radius: .7em;
  background: color-mix(in srgb,var(--fg) 2%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 1.6em 3.2em -1.2em rgba(0,0,0,.5);
  background: var(--bg);
  opacity: 0;
  transform: translateX(.8em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),top calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .cm.on {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uvq13-cmt ul {
  list-style: none;
  display: grid;
  gap: .55em;
  margin: 0;
  padding: 0;
}

.uvq13-cmt li {
  display: flex;
  gap: .4em;
  font-size: .6em;
}

.uvq13-cmt .av {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  font-weight: 800;
  color: #fff;
  background: var(--c);
}

.uvq13-cmt li small {
  margin-left: .35em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt li p {
  margin: .15em 0 0;
  line-height: 1.35;
}

.uvq13-cmt .rp {
  display: flex;
  gap: .3em;
  margin-top: .6em;
}

.uvq13-cmt .rp input {
  flex: 1;
  min-width: 0;
  padding: .4em .5em;
  border: 0;
  outline: 0;
  border-radius: .5em;
  font: inherit;
  font-size: .6em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-cmt .rp input:focus {
  box-shadow: 0 0 0 2px var(--c2);
}

.uvq13-cmt .sd {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  color: #fff;
  background: var(--c2);
}

.uvq13-cmt .sd svg {
  width: .8em;
  height: .8em;
}

.uvq13-cmt .rs {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: .3em;
  margin-top: .55em;
  font-size: .62em;
  font-weight: 700;
  color: var(--c2);
}

.uvq13-cmt .rs svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq13-cmt .cm button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-cmt .toast {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 4;
  margin: 0;
  padding: .45em .9em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  white-space: nowrap;
  color: var(--bg);
  background: var(--fg);
  opacity: 0;
  transform: translate(-50%,.5em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .toast.on {
  opacity: 1;
  transform: translate(-50%,0);
}

@media (prefers-reduced-motion:reduce) {
  .uvq13-cmt,.uvq13-cmt *,.uvq13-cmt *::before,.uvq13-cmt *::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 hls=[...el.querySelectorAll(".hl")],cms=[...el.querySelectorAll(".cm")],pth=el.querySelector(".ln path"),bgs=[...el.querySelectorAll(".bg")],toast=el.querySelector(".toast");let cur=-1,tms=[];const later=(f,ms)=>tms.push(setTimeout(f,ms));
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const pos=r=>{const R=el.getBoundingClientRect(),s=sc();return{y:(r.top-R.top)/s,r:(r.right-R.left)/s,b:(r.bottom-R.top)/s}};
const place=i=>{const rs=hls[i].getClientRects(),f=pos(rs[0]),l=pos(rs[rs.length-1]),c=cms[i];const top=Math.max(8,Math.min(el.clientHeight-c.offsetHeight-8,f.y-6));c.style.top=top+"px";const cx=c.offsetLeft,cy=top+14,sx=l.r+2,sy=(l.y+l.b)/2;pth.setAttribute("d","M"+sx+" "+sy+"C"+(sx+24)+" "+sy+" "+(cx-24)+" "+cy+" "+cx+" "+cy)};
const badges=()=>hls.forEach((h,i)=>{const r=h.getClientRects()[0];if(r)bgs[i].style.top=pos(r).y+"px"});
const hide=back=>{if(cur<0)return;const i=cur;cur=-1;cms[i].classList.remove("on");cms[i].inert=true;hls[i].setAttribute("aria-expanded","false");el.classList.remove("open");bgs[i].classList.remove("on");back&&hls[i].focus({preventScroll:true})};
const show=(i,u)=>{if(cur===i){hide(true);return}hide(false);cur=i;place(i);cms[i].classList.add("on");cms[i].inert=false;hls[i].setAttribute("aria-expanded","true");el.classList.add("open");bgs[i].classList.add("on");u&&later(()=>cms[i].querySelector("input").focus({preventScroll:true}),260)};
hls.forEach((h,i)=>h.addEventListener("click",()=>show(i,true)));bgs.forEach((b,i)=>b.addEventListener("click",()=>!hls[i].disabled&&show(i,true)));
cms.forEach((c,i)=>{c.inert=true;const inp=c.querySelector("input"),ul=c.querySelector("ul");const send=()=>{const v=inp.value.trim();if(!v)return;const li=c.querySelector(".tpl").cloneNode(true);li.hidden=false;li.classList.remove("tpl");li.querySelector("p").textContent=v;ul.insertBefore(li,c.querySelector(".tpl"));inp.value="";place(i)};
inp.addEventListener("keydown",e=>{if(e.key==="Enter"){e.preventDefault();send()}});c.querySelector(".sd").addEventListener("click",send);
c.querySelector(".rs").addEventListener("click",()=>{hide(false);hls[i].disabled=true;bgs[i].classList.add("done");toast.classList.add("on");later(()=>toast.classList.remove("on"),1800);const n=hls.find(h=>!h.disabled);(n||el.querySelector(".h")).focus({preventScroll:true})})});
el.addEventListener("keydown",e=>{if(e.key==="Escape"&&cur>-1){e.preventDefault();hide(true)}});
el.addEventListener("pointerdown",e=>{if(cur>-1&&!e.target.closest(".cm,.hl,.bg"))hide(false)});
const ro=new ResizeObserver(()=>{badges();if(cur>-1)place(cur)});ro.observe(el);
badges();later(()=>show(0,false),700);return()=>{tms.forEach(clearTimeout);ro.disconnect()}
}

export default function OvMarginComment() {
  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": "#f59e0b",
          "--c2": "#0284c7",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq13-cmt"><div className="doc"><p className="kk">Document</p><p className="h" tabIndex={-1}>Redesign proposal</p><p className="tx"><span>The new home page must load in under two seconds.</span> <button type="button" className="hl" aria-expanded="false" aria-controls="uvq13-cmt-0">We propose removing the carousel and keeping a single still image.</button> <span>That way the main content shows up sooner.</span></p><p className="tx"><button type="button" className="hl" aria-expanded="false" aria-controls="uvq13-cmt-1">Buttons will have a single action color.</button> <span>All other links will be underlined.</span></p></div><span className="bg" aria-hidden="true">2</span><span className="bg" aria-hidden="true">1</span><svg className="ln" aria-hidden="true"><path /></svg><section className="cm" id="uvq13-cmt-0" role="dialog" aria-label="Comments"><ul><li><span className="av" style={{ "--c": "#db2777" } as CSSProperties}>S</span><div><b>Sara</b><small>hace 5 min</small><p>What if we keep the carousel on mobile only?</p></div></li><li><span className="av" style={{ "--c": "#0284c7" } as CSSProperties}>L</span><div><b>Leo</b><small>2 min ago</small><p>We will try it in the next version.</p></div></li><li className="tpl" hidden={true}><span className="av" style={{ "--c": "#64748b" } as CSSProperties}>T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div className="rp"><input placeholder="Reply…" aria-label="Reply" autoComplete="off" /><button type="button" className="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z" /></svg></button></div><button type="button" className="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg><span>Resolve</span></button></section><section className="cm" id="uvq13-cmt-1" role="dialog" aria-label="Comments"><ul><li><span className="av" style={{ "--c": "#0284c7" } as CSSProperties}>L</span><div><b>Leo</b><small>1 h ago</small><p>Let's check the contrast of the new color.</p></div></li><li className="tpl" hidden={true}><span className="av" style={{ "--c": "#64748b" } as CSSProperties}>T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div className="rp"><input placeholder="Reply…" aria-label="Reply" autoComplete="off" /><button type="button" className="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z" /></svg></button></div><button type="button" className="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg><span>Resolve</span></button></section><p className="toast" aria-live="polite"><span>Comment resolved</span></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 “Comment thread anchored in the margin” block (Overlays) from AIMRAN Library to my project.

## What it is
Click a highlighted sentence and its comment thread appears in the margin joined by a line, with replies and a resolve button.

## Chosen settings
- Main color: #f59e0b
- Secondary color: #0284c7
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Propuesta de rediseño"

## 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-cmt {
  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: 18em;
  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-cmt .doc {
  position: absolute;
  left: 1em;
  top: 1em;
  bottom: 1em;
  width: 12.4em;
  padding: 1em 1.1em;
  box-sizing: border-box;
  border-radius: .6em;
  background: var(--bg);
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .5em 1.2em -.8em rgba(0,0,0,.3);
}

.uvq13-cmt .kk {
  margin: 0;
  font-size: .58em;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt .h {
  margin: .3em 0 .5em;
  font-size: .95em;
  font-weight: 800;
  line-height: 1.15;
  outline: 0;
}

.uvq13-cmt .tx {
  margin: 0 0 .6em;
  font-size: .66em;
  line-height: 1.6;
}

.uvq13-cmt .hl {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: inline;
  padding: 0 .1em;
  border-radius: .15em;
  text-align: left;
  background: color-mix(in srgb,var(--c1) 28%,transparent);
  box-shadow: inset 0 -2px 0 var(--c1);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt .hl:hover,.uvq13-cmt .hl[aria-expanded="true"] {
  background: color-mix(in srgb,var(--c1) 55%,transparent);
}

.uvq13-cmt .hl:disabled {
  color: inherit;
  background: none;
  box-shadow: none;
  cursor: text;
}

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

.uvq13-cmt .bg {
  position: absolute;
  left: 19.6em;
  display: grid;
  place-items: center;
  width: 1.7em;
  height: 1.5em;
  border-radius: .6em .6em .6em .15em;
  font-size: .72em;
  font-weight: 800;
  color: #fff;
  background: var(--c2);
  cursor: pointer;
  transition: opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq13-cmt .bg.on {
  opacity: 0;
  transform: scale(.5);
}

.uvq13-cmt .bg.done {
  display: none;
}

.uvq13-cmt .ln {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.uvq13-cmt .ln path {
  fill: none;
  stroke: var(--c1);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq13-cmt.open .ln path {
  opacity: 1;
}

.uvq13-cmt .cm {
  position: absolute;
  left: 14.1em;
  top: 1em;
  z-index: 3;
  width: 7.2em;
  padding: .6em;
  box-sizing: border-box;
  border-radius: .7em;
  background: color-mix(in srgb,var(--fg) 2%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 1.6em 3.2em -1.2em rgba(0,0,0,.5);
  background: var(--bg);
  opacity: 0;
  transform: translateX(.8em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1),top calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .cm.on {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uvq13-cmt ul {
  list-style: none;
  display: grid;
  gap: .55em;
  margin: 0;
  padding: 0;
}

.uvq13-cmt li {
  display: flex;
  gap: .4em;
  font-size: .6em;
}

.uvq13-cmt .av {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  font-weight: 800;
  color: #fff;
  background: var(--c);
}

.uvq13-cmt li small {
  margin-left: .35em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq13-cmt li p {
  margin: .15em 0 0;
  line-height: 1.35;
}

.uvq13-cmt .rp {
  display: flex;
  gap: .3em;
  margin-top: .6em;
}

.uvq13-cmt .rp input {
  flex: 1;
  min-width: 0;
  padding: .4em .5em;
  border: 0;
  outline: 0;
  border-radius: .5em;
  font: inherit;
  font-size: .6em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
}

.uvq13-cmt .rp input:focus {
  box-shadow: 0 0 0 2px var(--c2);
}

.uvq13-cmt .sd {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  color: #fff;
  background: var(--c2);
}

.uvq13-cmt .sd svg {
  width: .8em;
  height: .8em;
}

.uvq13-cmt .rs {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: .3em;
  margin-top: .55em;
  font-size: .62em;
  font-weight: 700;
  color: var(--c2);
}

.uvq13-cmt .rs svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq13-cmt .cm button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq13-cmt .toast {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 4;
  margin: 0;
  padding: .45em .9em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  white-space: nowrap;
  color: var(--bg);
  background: var(--fg);
  opacity: 0;
  transform: translate(-50%,.5em);
  pointer-events: none;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.3s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq13-cmt .toast.on {
  opacity: 1;
  transform: translate(-50%,0);
}

@media (prefers-reduced-motion:reduce) {
  .uvq13-cmt,.uvq13-cmt *,.uvq13-cmt *::before,.uvq13-cmt *::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 hls=[...el.querySelectorAll(".hl")],cms=[...el.querySelectorAll(".cm")],pth=el.querySelector(".ln path"),bgs=[...el.querySelectorAll(".bg")],toast=el.querySelector(".toast");let cur=-1,tms=[];const later=(f,ms)=>tms.push(setTimeout(f,ms));
const sc=()=>el.getBoundingClientRect().width/el.offsetWidth||1;
const pos=r=>{const R=el.getBoundingClientRect(),s=sc();return{y:(r.top-R.top)/s,r:(r.right-R.left)/s,b:(r.bottom-R.top)/s}};
const place=i=>{const rs=hls[i].getClientRects(),f=pos(rs[0]),l=pos(rs[rs.length-1]),c=cms[i];const top=Math.max(8,Math.min(el.clientHeight-c.offsetHeight-8,f.y-6));c.style.top=top+"px";const cx=c.offsetLeft,cy=top+14,sx=l.r+2,sy=(l.y+l.b)/2;pth.setAttribute("d","M"+sx+" "+sy+"C"+(sx+24)+" "+sy+" "+(cx-24)+" "+cy+" "+cx+" "+cy)};
const badges=()=>hls.forEach((h,i)=>{const r=h.getClientRects()[0];if(r)bgs[i].style.top=pos(r).y+"px"});
const hide=back=>{if(cur<0)return;const i=cur;cur=-1;cms[i].classList.remove("on");cms[i].inert=true;hls[i].setAttribute("aria-expanded","false");el.classList.remove("open");bgs[i].classList.remove("on");back&&hls[i].focus({preventScroll:true})};
const show=(i,u)=>{if(cur===i){hide(true);return}hide(false);cur=i;place(i);cms[i].classList.add("on");cms[i].inert=false;hls[i].setAttribute("aria-expanded","true");el.classList.add("open");bgs[i].classList.add("on");u&&later(()=>cms[i].querySelector("input").focus({preventScroll:true}),260)};
hls.forEach((h,i)=>h.addEventListener("click",()=>show(i,true)));bgs.forEach((b,i)=>b.addEventListener("click",()=>!hls[i].disabled&&show(i,true)));
cms.forEach((c,i)=>{c.inert=true;const inp=c.querySelector("input"),ul=c.querySelector("ul");const send=()=>{const v=inp.value.trim();if(!v)return;const li=c.querySelector(".tpl").cloneNode(true);li.hidden=false;li.classList.remove("tpl");li.querySelector("p").textContent=v;ul.insertBefore(li,c.querySelector(".tpl"));inp.value="";place(i)};
inp.addEventListener("keydown",e=>{if(e.key==="Enter"){e.preventDefault();send()}});c.querySelector(".sd").addEventListener("click",send);
c.querySelector(".rs").addEventListener("click",()=>{hide(false);hls[i].disabled=true;bgs[i].classList.add("done");toast.classList.add("on");later(()=>toast.classList.remove("on"),1800);const n=hls.find(h=>!h.disabled);(n||el.querySelector(".h")).focus({preventScroll:true})})});
el.addEventListener("keydown",e=>{if(e.key==="Escape"&&cur>-1){e.preventDefault();hide(true)}});
el.addEventListener("pointerdown",e=>{if(cur>-1&&!e.target.closest(".cm,.hl,.bg"))hide(false)});
const ro=new ResizeObserver(()=>{badges();if(cur>-1)place(cur)});ro.observe(el);
badges();later(()=>show(0,false),700);return()=>{tms.forEach(clearTimeout);ro.disconnect()}
}

export default function OvMarginComment() {
  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": "#f59e0b",
          "--c2": "#0284c7",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq13-cmt"><div className="doc"><p className="kk">Document</p><p className="h" tabIndex={-1}>Redesign proposal</p><p className="tx"><span>The new home page must load in under two seconds.</span> <button type="button" className="hl" aria-expanded="false" aria-controls="uvq13-cmt-0">We propose removing the carousel and keeping a single still image.</button> <span>That way the main content shows up sooner.</span></p><p className="tx"><button type="button" className="hl" aria-expanded="false" aria-controls="uvq13-cmt-1">Buttons will have a single action color.</button> <span>All other links will be underlined.</span></p></div><span className="bg" aria-hidden="true">2</span><span className="bg" aria-hidden="true">1</span><svg className="ln" aria-hidden="true"><path /></svg><section className="cm" id="uvq13-cmt-0" role="dialog" aria-label="Comments"><ul><li><span className="av" style={{ "--c": "#db2777" } as CSSProperties}>S</span><div><b>Sara</b><small>hace 5 min</small><p>What if we keep the carousel on mobile only?</p></div></li><li><span className="av" style={{ "--c": "#0284c7" } as CSSProperties}>L</span><div><b>Leo</b><small>2 min ago</small><p>We will try it in the next version.</p></div></li><li className="tpl" hidden={true}><span className="av" style={{ "--c": "#64748b" } as CSSProperties}>T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div className="rp"><input placeholder="Reply…" aria-label="Reply" autoComplete="off" /><button type="button" className="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z" /></svg></button></div><button type="button" className="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg><span>Resolve</span></button></section><section className="cm" id="uvq13-cmt-1" role="dialog" aria-label="Comments"><ul><li><span className="av" style={{ "--c": "#0284c7" } as CSSProperties}>L</span><div><b>Leo</b><small>1 h ago</small><p>Let's check the contrast of the new color.</p></div></li><li className="tpl" hidden={true}><span className="av" style={{ "--c": "#64748b" } as CSSProperties}>T</span><div><b>You</b><small>now</small><p></p></div></li></ul><div className="rp"><input placeholder="Reply…" aria-label="Reply" autoComplete="off" /><button type="button" className="sd" aria-label="Send"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 12l16-8-6 16-2.5-6.5z" /></svg></button></div><button type="button" className="rs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" /></svg><span>Resolve</span></button></section><p className="toast" aria-live="polite"><span>Comment resolved</span></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.
````
