# CSS editor with line numbers

> A code area with syntax colors, line numbers, a highlighted current line, auto indent and bracket closing.

- Category: [Inputs](https://library.aimran.es/components/inputs)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-in-code-editor
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A lightweight code field that needs no editor library. A transparent text area sits on top of a highlighted copy, so comments, properties, numbers and braces get their own colors while typing stays native. Line numbers and the current line band follow the caret, Enter keeps the indent and brackets and quotes close themselves.

The main color marks properties and the active line, the second color numbers and the language tag. Use it in theme builders, snippet forms and teaching pages; Tab inserts two spaces, and pressing Escape first lets keyboard users tab out.

## Code

### HTML

```html
<div class="uvq06-cd"><div class="tb" aria-hidden="true"><i></i><span>styles.css</span><b>CSS</b></div><div class="ed"><div class="gt" aria-hidden="true"></div><div class="ar"><i class="hl" aria-hidden="true"></i><pre class="hi" aria-hidden="true"></pre><label><span class="sr">CSS code</span><textarea wrap="off" spellcheck="false" autocomplete="off"></textarea></label></div></div><div class="sb"><span class="ps">Ln 1, Col 1</span><span>Esc then Tab to leave</span></div></div>
```

### CSS

```css
.uvq06-cd {
  --c1: #c026d3;
  --c2: #0d9488;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq06-cd {
  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;
  width: 20em;
  border-radius: .9em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
  transition: box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd:focus-within {
  box-shadow: 0 0 0 2px var(--c1),0 0 0 6px color-mix(in srgb,var(--c1) 16%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
}

.uvq06-cd .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq06-cd .tb {
  display: flex;
  align-items: center;
  gap: .5em;
  padding: .55em .8em;
  border-bottom: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font-size: .72em;
}

.uvq06-cd .tb i {
  width: .6em;
  height: .6em;
  border-radius: 50%;
  background: var(--c1);
}

.uvq06-cd .tb b {
  margin-left: auto;
  padding: .15em .45em;
  border-radius: .3em;
  font-weight: 800;
  color: var(--c2);
  background: color-mix(in srgb,var(--c2) 14%,transparent);
}

.uvq06-cd .ed {
  display: flex;
  height: 11em;
  font: 400 .8em/1.55 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq06-cd .gt {
  flex: none;
  width: 2.6em;
  padding: .6em .6em .6em 0;
  overflow: hidden;
  border-right: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  text-align: right;
  color: color-mix(in srgb,var(--fg) 32%,transparent);
  user-select: none;
}

.uvq06-cd .gt span {
  display: block;
  height: 1.55em;
}

.uvq06-cd .gt span.on {
  font-weight: 700;
  color: var(--fg);
}

.uvq06-cd .ar {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.uvq06-cd .hl {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(.6em + var(--ln,0) * 1.55em - var(--st,0px));
  height: 1.55em;
  background: color-mix(in srgb,var(--c1) 8%,transparent);
  box-shadow: inset 2px 0 0 var(--c1);
  transition: top calc(0.12s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd .hi,.uvq06-cd textarea {
  box-sizing: border-box;
  margin: 0;
  padding: .6em .8em;
  font: inherit;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre;
  tab-size: 2;
}

.uvq06-cd .hi {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--fg);
  pointer-events: none;
}

.uvq06-cd textarea {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  resize: none;
  overflow: auto;
  background: none;
  color: transparent;
  caret-color: var(--c1);
  scrollbar-width: none;
}

.uvq06-cd textarea::selection {
  color: transparent;
  background: color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq06-cd .hi i {
  font-style: normal;
}

.uvq06-cd .hi .c {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq06-cd .hi .p {
  color: var(--c1);
}

.uvq06-cd .hi .n {
  color: var(--c2);
}

.uvq06-cd .hi .b {
  font-weight: 700;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq06-cd .sb {
  display: flex;
  justify-content: space-between;
  padding: .5em .8em;
  border-top: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font: 500 .64em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}
```

### JavaScript

```js
document.querySelectorAll(".uvq06-cd").forEach(el => {
  const ta=el.querySelector("textarea"),hi=el.querySelector(".hi"),gt=el.querySelector(".gt"),ps=el.querySelector(".ps");let esc=false;
const H=s=>s.replace(/[&<>]/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[c]).replace(/(\/\*[\s\S]*?\*\/)|([\w-]+)(?=\s*:[^:])|(#[0-9a-fA-F]{3,8}\b|-?\b\d*\.?\d+(?:px|em|rem|%|s|ms|deg|vh|vw)?)|([{}()])/g,(m,c,p,n)=>'<i class="'+(c?"c":p?"p":n?"n":"b")+'">'+m+"</i>");
const sync=()=>{hi.scrollTop=gt.scrollTop=ta.scrollTop;hi.scrollLeft=ta.scrollLeft;el.style.setProperty("--st",ta.scrollTop+"px")};
const draw=()=>{hi.innerHTML=H(ta.value)+"\n ";const n=ta.value.split("\n").length,b=ta.value.slice(0,ta.selectionStart).split("\n"),ln=b.length-1;gt.innerHTML=Array.from({length:n},(_,k)=>"<span"+(k===ln?' class="on"':"")+">"+(k+1)+"</span>").join("");el.style.setProperty("--ln",String(ln));ps.textContent="Ln "+(ln+1)+", Col "+(b[ln].length+1);sync()};
const ins=(t,back)=>{ta.setRangeText(t,ta.selectionStart,ta.selectionEnd,"end");if(back)ta.selectionStart=ta.selectionEnd=ta.selectionEnd-back;draw()};
const P={"{":"}","(":")","[":"]",'"':'"'};
ta.addEventListener("keydown",e=>{if(e.key==="Escape"){esc=true;return}if(e.key==="Tab"){if(esc){esc=false;return}e.preventDefault();ins("  ");return}esc=false;if(e.ctrlKey||e.metaKey||e.altKey)return;
const nx=ta.value[ta.selectionStart];if((e.key==="}"||e.key===")"||e.key==="]"||e.key==='"')&&nx===e.key&&ta.selectionStart===ta.selectionEnd){e.preventDefault();ta.selectionStart=ta.selectionEnd=ta.selectionStart+1;draw();return}
if(Object.prototype.hasOwnProperty.call(P,e.key)){e.preventDefault();ins(e.key+P[e.key],1);return}
if(e.key==="Enter"){e.preventDefault();const s=ta.selectionStart,ind=ta.value.slice(0,s).split("\n").pop().match(/^\s*/)[0],o=ta.value[s-1]==="{";if(o&&nx==="}")ins("\n"+ind+"  \n"+ind,ind.length+1);else ins("\n"+ind+(o?"  ":""))}});
ta.addEventListener("input",draw);["keyup","click","focus"].forEach(n=>ta.addEventListener(n,draw));ta.addEventListener("scroll",sync);
ta.value=["/* Main button */",".btn {","  color: #fff;","  padding: 0.8em 1.6em;","  border-radius: 999px;","}"].join("\n");draw()
});
```

### 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 = `
.uvq06-cd {
  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;
  width: 20em;
  border-radius: .9em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
  transition: box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd:focus-within {
  box-shadow: 0 0 0 2px var(--c1),0 0 0 6px color-mix(in srgb,var(--c1) 16%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
}

.uvq06-cd .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq06-cd .tb {
  display: flex;
  align-items: center;
  gap: .5em;
  padding: .55em .8em;
  border-bottom: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font-size: .72em;
}

.uvq06-cd .tb i {
  width: .6em;
  height: .6em;
  border-radius: 50%;
  background: var(--c1);
}

.uvq06-cd .tb b {
  margin-left: auto;
  padding: .15em .45em;
  border-radius: .3em;
  font-weight: 800;
  color: var(--c2);
  background: color-mix(in srgb,var(--c2) 14%,transparent);
}

.uvq06-cd .ed {
  display: flex;
  height: 11em;
  font: 400 .8em/1.55 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq06-cd .gt {
  flex: none;
  width: 2.6em;
  padding: .6em .6em .6em 0;
  overflow: hidden;
  border-right: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  text-align: right;
  color: color-mix(in srgb,var(--fg) 32%,transparent);
  user-select: none;
}

.uvq06-cd .gt span {
  display: block;
  height: 1.55em;
}

.uvq06-cd .gt span.on {
  font-weight: 700;
  color: var(--fg);
}

.uvq06-cd .ar {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.uvq06-cd .hl {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(.6em + var(--ln,0) * 1.55em - var(--st,0px));
  height: 1.55em;
  background: color-mix(in srgb,var(--c1) 8%,transparent);
  box-shadow: inset 2px 0 0 var(--c1);
  transition: top calc(0.12s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd .hi,.uvq06-cd textarea {
  box-sizing: border-box;
  margin: 0;
  padding: .6em .8em;
  font: inherit;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre;
  tab-size: 2;
}

.uvq06-cd .hi {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--fg);
  pointer-events: none;
}

.uvq06-cd textarea {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  resize: none;
  overflow: auto;
  background: none;
  color: transparent;
  caret-color: var(--c1);
  scrollbar-width: none;
}

.uvq06-cd textarea::selection {
  color: transparent;
  background: color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq06-cd .hi i {
  font-style: normal;
}

.uvq06-cd .hi .c {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq06-cd .hi .p {
  color: var(--c1);
}

.uvq06-cd .hi .n {
  color: var(--c2);
}

.uvq06-cd .hi .b {
  font-weight: 700;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq06-cd .sb {
  display: flex;
  justify-content: space-between;
  padding: .5em .8em;
  border-top: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font: 500 .64em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}
`;

// 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 ta=el.querySelector("textarea"),hi=el.querySelector(".hi"),gt=el.querySelector(".gt"),ps=el.querySelector(".ps");let esc=false;
const H=s=>s.replace(/[&<>]/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[c]).replace(/(\/\*[\s\S]*?\*\/)|([\w-]+)(?=\s*:[^:])|(#[0-9a-fA-F]{3,8}\b|-?\b\d*\.?\d+(?:px|em|rem|%|s|ms|deg|vh|vw)?)|([{}()])/g,(m,c,p,n)=>'<i class="'+(c?"c":p?"p":n?"n":"b")+'">'+m+"</i>");
const sync=()=>{hi.scrollTop=gt.scrollTop=ta.scrollTop;hi.scrollLeft=ta.scrollLeft;el.style.setProperty("--st",ta.scrollTop+"px")};
const draw=()=>{hi.innerHTML=H(ta.value)+"\n ";const n=ta.value.split("\n").length,b=ta.value.slice(0,ta.selectionStart).split("\n"),ln=b.length-1;gt.innerHTML=Array.from({length:n},(_,k)=>"<span"+(k===ln?' class="on"':"")+">"+(k+1)+"</span>").join("");el.style.setProperty("--ln",String(ln));ps.textContent="Ln "+(ln+1)+", Col "+(b[ln].length+1);sync()};
const ins=(t,back)=>{ta.setRangeText(t,ta.selectionStart,ta.selectionEnd,"end");if(back)ta.selectionStart=ta.selectionEnd=ta.selectionEnd-back;draw()};
const P={"{":"}","(":")","[":"]",'"':'"'};
ta.addEventListener("keydown",e=>{if(e.key==="Escape"){esc=true;return}if(e.key==="Tab"){if(esc){esc=false;return}e.preventDefault();ins("  ");return}esc=false;if(e.ctrlKey||e.metaKey||e.altKey)return;
const nx=ta.value[ta.selectionStart];if((e.key==="}"||e.key===")"||e.key==="]"||e.key==='"')&&nx===e.key&&ta.selectionStart===ta.selectionEnd){e.preventDefault();ta.selectionStart=ta.selectionEnd=ta.selectionStart+1;draw();return}
if(Object.prototype.hasOwnProperty.call(P,e.key)){e.preventDefault();ins(e.key+P[e.key],1);return}
if(e.key==="Enter"){e.preventDefault();const s=ta.selectionStart,ind=ta.value.slice(0,s).split("\n").pop().match(/^\s*/)[0],o=ta.value[s-1]==="{";if(o&&nx==="}")ins("\n"+ind+"  \n"+ind,ind.length+1);else ins("\n"+ind+(o?"  ":""))}});
ta.addEventListener("input",draw);["keyup","click","focus"].forEach(n=>ta.addEventListener(n,draw));ta.addEventListener("scroll",sync);
ta.value=["/* Main button */",".btn {","  color: #fff;","  padding: 0.8em 1.6em;","  border-radius: 999px;","}"].join("\n");draw()
}

export default function InCodeEditor() {
  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": "#c026d3",
          "--c2": "#0d9488",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq06-cd"><div className="tb" aria-hidden="true"><i></i><span>styles.css</span><b>CSS</b></div><div className="ed"><div className="gt" aria-hidden="true"></div><div className="ar"><i className="hl" aria-hidden="true"></i><pre className="hi" aria-hidden="true"></pre><label><span className="sr">CSS code</span><textarea wrap="off" spellCheck="false" autoComplete="off"></textarea></label></div></div><div className="sb"><span className="ps">Ln 1, Col 1</span><span>Esc then Tab to leave</span></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 “CSS editor with line numbers” block (Inputs) from AIMRAN Library to my project.

## What it is
A code area with syntax colors, line numbers, a highlighted current line, auto indent and bracket closing.

## Chosen settings
- Main color: #c026d3
- Secondary color: #0d9488
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Código CSS"

## 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 = `
.uvq06-cd {
  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;
  width: 20em;
  border-radius: .9em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
  transition: box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd:focus-within {
  box-shadow: 0 0 0 2px var(--c1),0 0 0 6px color-mix(in srgb,var(--c1) 16%,transparent),0 1.2em 2em -1.2em rgba(0,0,0,.45);
}

.uvq06-cd .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq06-cd .tb {
  display: flex;
  align-items: center;
  gap: .5em;
  padding: .55em .8em;
  border-bottom: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font-size: .72em;
}

.uvq06-cd .tb i {
  width: .6em;
  height: .6em;
  border-radius: 50%;
  background: var(--c1);
}

.uvq06-cd .tb b {
  margin-left: auto;
  padding: .15em .45em;
  border-radius: .3em;
  font-weight: 800;
  color: var(--c2);
  background: color-mix(in srgb,var(--c2) 14%,transparent);
}

.uvq06-cd .ed {
  display: flex;
  height: 11em;
  font: 400 .8em/1.55 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq06-cd .gt {
  flex: none;
  width: 2.6em;
  padding: .6em .6em .6em 0;
  overflow: hidden;
  border-right: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  text-align: right;
  color: color-mix(in srgb,var(--fg) 32%,transparent);
  user-select: none;
}

.uvq06-cd .gt span {
  display: block;
  height: 1.55em;
}

.uvq06-cd .gt span.on {
  font-weight: 700;
  color: var(--fg);
}

.uvq06-cd .ar {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.uvq06-cd .hl {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(.6em + var(--ln,0) * 1.55em - var(--st,0px));
  height: 1.55em;
  background: color-mix(in srgb,var(--c1) 8%,transparent);
  box-shadow: inset 2px 0 0 var(--c1);
  transition: top calc(0.12s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq06-cd .hi,.uvq06-cd textarea {
  box-sizing: border-box;
  margin: 0;
  padding: .6em .8em;
  font: inherit;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre;
  tab-size: 2;
}

.uvq06-cd .hi {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--fg);
  pointer-events: none;
}

.uvq06-cd textarea {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  resize: none;
  overflow: auto;
  background: none;
  color: transparent;
  caret-color: var(--c1);
  scrollbar-width: none;
}

.uvq06-cd textarea::selection {
  color: transparent;
  background: color-mix(in srgb,var(--c1) 25%,transparent);
}

.uvq06-cd .hi i {
  font-style: normal;
}

.uvq06-cd .hi .c {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq06-cd .hi .p {
  color: var(--c1);
}

.uvq06-cd .hi .n {
  color: var(--c2);
}

.uvq06-cd .hi .b {
  font-weight: 700;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq06-cd .sb {
  display: flex;
  justify-content: space-between;
  padding: .5em .8em;
  border-top: 1px solid color-mix(in srgb,var(--fg) 12%,transparent);
  font: 500 .64em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}
`;

// 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 ta=el.querySelector("textarea"),hi=el.querySelector(".hi"),gt=el.querySelector(".gt"),ps=el.querySelector(".ps");let esc=false;
const H=s=>s.replace(/[&<>]/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[c]).replace(/(\/\*[\s\S]*?\*\/)|([\w-]+)(?=\s*:[^:])|(#[0-9a-fA-F]{3,8}\b|-?\b\d*\.?\d+(?:px|em|rem|%|s|ms|deg|vh|vw)?)|([{}()])/g,(m,c,p,n)=>'<i class="'+(c?"c":p?"p":n?"n":"b")+'">'+m+"</i>");
const sync=()=>{hi.scrollTop=gt.scrollTop=ta.scrollTop;hi.scrollLeft=ta.scrollLeft;el.style.setProperty("--st",ta.scrollTop+"px")};
const draw=()=>{hi.innerHTML=H(ta.value)+"\n ";const n=ta.value.split("\n").length,b=ta.value.slice(0,ta.selectionStart).split("\n"),ln=b.length-1;gt.innerHTML=Array.from({length:n},(_,k)=>"<span"+(k===ln?' class="on"':"")+">"+(k+1)+"</span>").join("");el.style.setProperty("--ln",String(ln));ps.textContent="Ln "+(ln+1)+", Col "+(b[ln].length+1);sync()};
const ins=(t,back)=>{ta.setRangeText(t,ta.selectionStart,ta.selectionEnd,"end");if(back)ta.selectionStart=ta.selectionEnd=ta.selectionEnd-back;draw()};
const P={"{":"}","(":")","[":"]",'"':'"'};
ta.addEventListener("keydown",e=>{if(e.key==="Escape"){esc=true;return}if(e.key==="Tab"){if(esc){esc=false;return}e.preventDefault();ins("  ");return}esc=false;if(e.ctrlKey||e.metaKey||e.altKey)return;
const nx=ta.value[ta.selectionStart];if((e.key==="}"||e.key===")"||e.key==="]"||e.key==='"')&&nx===e.key&&ta.selectionStart===ta.selectionEnd){e.preventDefault();ta.selectionStart=ta.selectionEnd=ta.selectionStart+1;draw();return}
if(Object.prototype.hasOwnProperty.call(P,e.key)){e.preventDefault();ins(e.key+P[e.key],1);return}
if(e.key==="Enter"){e.preventDefault();const s=ta.selectionStart,ind=ta.value.slice(0,s).split("\n").pop().match(/^\s*/)[0],o=ta.value[s-1]==="{";if(o&&nx==="}")ins("\n"+ind+"  \n"+ind,ind.length+1);else ins("\n"+ind+(o?"  ":""))}});
ta.addEventListener("input",draw);["keyup","click","focus"].forEach(n=>ta.addEventListener(n,draw));ta.addEventListener("scroll",sync);
ta.value=["/* Main button */",".btn {","  color: #fff;","  padding: 0.8em 1.6em;","  border-radius: 999px;","}"].join("\n");draw()
}

export default function InCodeEditor() {
  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": "#c026d3",
          "--c2": "#0d9488",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq06-cd"><div className="tb" aria-hidden="true"><i></i><span>styles.css</span><b>CSS</b></div><div className="ed"><div className="gt" aria-hidden="true"></div><div className="ar"><i className="hl" aria-hidden="true"></i><pre className="hi" aria-hidden="true"></pre><label><span className="sr">CSS code</span><textarea wrap="off" spellCheck="false" autoComplete="off"></textarea></label></div></div><div className="sb"><span className="ps">Ln 1, Col 1</span><span>Esc then Tab to leave</span></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.
````
