/* CSS · estilos propios */
body { overflow: hidden; }
.shell { display: grid; height: 100dvh; grid-template-columns: 220px minmax(0, 1fr) 340px; grid-template-rows: 48px minmax(0, 1fr); grid-template-areas: "top top top" "nav stage ctrl"; }
.topbar { grid-area: top; }

/* Lista de generadores */
.nav { grid-area: nav; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.nav-q { position: relative; padding: 10px 10px 6px; }
.nav-q .ic { position: absolute; left: 19px; top: 18px; width: 14px; height: 14px; color: var(--text-3); pointer-events: none; }
.nav-q input { width: 100%; height: 32px; padding: 0 10px 0 29px; border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); outline: none; }
.nav-q input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nav-q input::-webkit-search-cancel-button { display: none; }
.nav-list { position: relative; flex: 1; overflow: auto; padding: 2px 8px 14px; }
.nav-g { display: grid; gap: 1px; margin-bottom: 10px; }
.nav-gt { padding: 6px 10px 4px; color: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.nav-list button { height: 30px; padding: 0 10px; border: 0; border-radius: 7px; background: none; text-align: left; color: var(--text-2); font-size: 13px; }
.nav-list button:hover { background: var(--hover); color: var(--text); }
.nav-list button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-empty { padding: 10px; }

/* Zona central */
.stage-col { grid-area: stage; display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; padding: 12px; }
.stage-bar { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px 12px; }
.gen-title { flex: 1 1 240px; min-width: 0; }
.gen-title h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.gen-title p { margin: 2px 0 0; color: var(--text-2); font-size: 12.5px; line-height: 1.45; }
.bar-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.bar-acts .btn { gap: 6px; }
.badge { min-width: 18px; height: 18px; margin-left: 2px; padding: 0 5px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 11px; line-height: 18px; text-align: center; }
.badge[hidden] { display: none; }
.gen-pick { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px 0 14px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--panel); font-weight: 600; font-size: 15px; color: var(--text); }
.gen-pick .ic { width: 16px; height: 16px; color: var(--text-3); }

.stage-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.stage { position: relative; flex: 1; min-height: 240px; display: grid; place-items: center; border-radius: 14px; border: 1px solid var(--border); overflow: hidden; padding: 24px; background-size: cover; background-position: center; }
.stage-bg { position: absolute; right: 10px; top: 10px; z-index: 4; box-shadow: var(--shadow-sm); }
.stage-bg button { height: 26px; padding: 0 10px; font-size: 12px; }
.stage[data-bg="light"] { background-color: #f4f4f1; color: #1b1b19; }
.stage[data-bg="dark"] { background-color: #16171a; color: #ebeae6; }
.stage[data-bg="checker"] { background-color: #fff; background-image: conic-gradient(#e6e6e2 25%, transparent 0 50%, #e6e6e2 0 75%, transparent 0); background-size: 18px 18px; color: #1b1b19; }
.stage[data-bg="photo"] { color: #fff; }
.stage.dragging, .stage.dragging * { cursor: grabbing !important; user-select: none; }
.stage[data-drag="angle"] .pv, .stage[data-drag="shadow"] { cursor: grab; touch-action: none; }

/* Código */
.code { display: flex; flex-direction: column; min-height: 0; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); overflow: hidden; }
.code-h { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.code-h .input { height: 30px; width: auto; font-size: 12.5px; }
.code-h .sel-in { width: 120px; }
.code pre { margin: 0; max-height: 220px; overflow: auto; padding: 12px 16px; font: 400 12.5px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.tk-c { color: var(--text-3); font-style: italic; }
.tk-s { color: var(--accent); font-weight: 600; }
.tk-p { color: #b45309; }
:root[data-theme="dark"] .tk-p { color: #f0b860; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tk-p { color: #f0b860; } }
.cs { display: inline-block; width: .85em; height: .85em; margin: 0 4px -1px 0; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, .5); }

/* Controles */
.ctrl { grid-area: ctrl; overflow: auto; display: flex; flex-direction: column; gap: 14px; padding: 14px 16px; border-left: 1px solid var(--border); }
.presets { display: grid; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { height: 26px; padding: 0 10px; border: 1px solid var(--border-2); border-radius: 99px; background: var(--panel); font-size: 12px; color: var(--text-2); }
.chips button:hover { background: var(--hover); color: var(--text); }
.fields { display: grid; gap: 12px; }
.fld { display: grid; gap: 5px; }
.fl { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; font-size: 11.5px; font-weight: 500; color: var(--text-2); }
.num-w { display: inline-flex; align-items: center; gap: 3px; color: var(--text-3); font-size: 11px; }
.num-w i { font-style: normal; }
.num { width: 64px; height: 24px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); font: 500 12px var(--sans); font-variant-numeric: tabular-nums; text-align: right; -moz-appearance: textfield; }
.num::-webkit-inner-spin-button, .num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num:focus { outline: none; border-color: var(--accent); }
.fld input[type="range"] { width: 100%; }
.crow { display: flex; gap: 6px; }
.crow input[type="color"], .st-row input[type="color"] { flex: none; width: 34px; height: 30px; padding: 2px; border: 1px solid var(--border-2); border-radius: 6px; background: var(--panel); }
.fsep { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.pv-only .fl > span:first-child::after { content: " · vista previa"; color: var(--text-3); font-weight: 400; }
:lang(en) .pv-only .fl > span:first-child::after { content: " · preview"; }
.ctrl > .btn { align-self: flex-start; }

/* Listas (capas, manchas) */
.lst { display: grid; gap: 6px; }
.lst-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lst-it { border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.lst-it.open { border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.lst-ih { display: flex; align-items: center; gap: 2px; padding: 2px 4px 2px 2px; }
.lst-tg { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; height: 34px; padding: 0 8px; border: 0; border-radius: 8px; background: none; color: var(--text); font-size: 12.5px; font-weight: 500; text-align: left; }
.lst-tg small { overflow: hidden; color: var(--text-3); font-weight: 400; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.lst-tg .sw, .st-mk { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2); }
.lst-tg .sw { flex: none; width: 14px; height: 14px; border-radius: 4px; }
.lst-acts { display: flex; flex: none; }
.lst-acts .icon-btn { width: 26px; height: 26px; font-size: 13px; color: var(--text-3); }
.lst-acts .icon-btn:disabled { opacity: .3; }
.lst-b { display: grid; gap: 10px; padding: 6px 10px 12px; border-top: 1px solid var(--border); }

/* Paradas de color */
.stops { display: grid; gap: 8px; }
.st-bar { position: relative; height: 28px; margin: 4px 8px 6px; border-radius: 8px; background-image: conic-gradient(#e6e6e2 25%, #fff 0 50%, #e6e6e2 0 75%, #fff 0); background-size: 10px 10px; cursor: copy; touch-action: none; }
.st-fill { position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.st-mk { position: absolute; top: 50%; width: 18px; height: 34px; margin: -17px 0 0 -9px; padding: 0; border: 3px solid #fff; border-radius: 6px; background: var(--c); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); cursor: ew-resize; }
.st-mk.on { border-color: var(--accent); }
.st-rows { display: grid; gap: 4px; }
.st-row { display: flex; align-items: center; gap: 4px; padding: 2px; border-radius: 8px; }
.st-row.on { background: var(--accent-soft); }
.st-row .input { flex: 1; min-width: 0; height: 30px; font-size: 12px; }
.st-row .num { width: 52px; }

/* Puntos del recorte */
.pt-rows { display: grid; gap: 4px; max-height: 240px; overflow: auto; }
.pt-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.pt-row > b { width: 18px; color: var(--text-3); font-weight: 600; text-align: right; }
.pt-row .num { width: 52px; }
.pt-row .icon-btn { margin-left: auto; }

/* ───────── Vistas previas ───────── */
.demo { width: min(360px, 80%); aspect-ratio: 16 / 10; }
.demo.box { border-radius: 16px; }
.demo.box.big { width: min(440px, 88%); }
.demo.card { display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; padding: 20px; background: #fff; color: #1b1b19; }
.demo.card span { color: #6b6a65; font-size: 12.5px; }
.stage[data-bg="dark"] .demo.card:not([style]) { background: #232428; color: #ebeae6; }
.demo.shape { width: 220px; aspect-ratio: 1; background: linear-gradient(135deg, #2f5bea, #7c5cdb); }
.demo.img { width: min(440px, 90%); aspect-ratio: 400 / 260; border-radius: 12px; background-size: cover; background-position: center; }
.fill { position: absolute; inset: 0; }
.txt { max-width: 100%; line-height: 1.1; text-align: center; overflow-wrap: anywhere; }
.glass-bg { position: relative; width: min(480px, 95%); aspect-ratio: 16 / 10; border-radius: 16px; overflow: hidden; background: #1e1b4b; display: grid; place-items: center; }
.glass-bg.photo { background-size: cover; background-position: center; }
.glass-bg i { position: absolute; border-radius: 50%; }
.b1 { width: 55%; aspect-ratio: 1; left: -10%; top: -15%; background: #f43f5e; }
.b2 { width: 45%; aspect-ratio: 1; right: -5%; bottom: -20%; background: #0ea5e9; }
.b3 { width: 30%; aspect-ratio: 1; right: 25%; top: 10%; background: #eab308; }
.glass { position: relative; display: flex; flex-direction: column; gap: 4px; width: 62%; padding: 22px; color: #fff; }
.glass span { font-size: 12.5px; opacity: .85; }
.glass.plain { border-radius: 14px; border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .12); }
.neu-wrap { display: grid; place-items: center; width: 100%; height: 100%; min-height: 240px; margin: -24px; padding: 24px; box-sizing: content-box; }
.neu { width: 180px; aspect-ratio: 1; }
.type-sample { max-width: 640px; margin: 0; }
.mix-host { position: relative; overflow: hidden; }
.mix-layer { position: absolute; inset: 0; }
.scroll-demo { width: min(360px, 90%); height: 200px; overflow: auto; padding: 4px 14px; border-radius: 10px; background: #fff; color: #334155; font-size: 13px; }
.scroll-demo p { margin: 10px 0; }
.layout-box { width: min(560px, 100%); min-height: 220px; padding: 10px; border: 2px dashed rgba(128, 128, 128, .35); border-radius: 12px; }
.layout-box .li { display: grid; place-items: center; min-width: 36px; min-height: 36px; padding: 10px 14px; border-radius: 8px; background: #2f5bea; color: #fff; font-weight: 600; font-size: 14px; }
.layout-box .li:nth-child(3n + 2) { background: #7c5cdb; }
.layout-box .li:nth-child(3n) { background: #0f9d8a; }
.tf-wrap { position: relative; display: grid; place-items: center; width: min(360px, 80%); aspect-ratio: 16 / 10; }
.tf-wrap > * { grid-area: 1 / 1; width: 100%; height: 100%; }
.tf-ghost { border: 2px dashed rgba(128, 128, 128, .5); border-radius: 12px; }
.tf-wrap .demo.card { border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); }
.anim-wrap { display: grid; justify-items: center; gap: 20px; }
.anim-box { width: 120px; aspect-ratio: 1; border-radius: 22px; background: linear-gradient(135deg, #2f5bea, #7c5cdb); }
.clip-box { position: relative; width: min(400px, 86%); aspect-ratio: 400 / 260; }
.clip-box .demo.img { width: 100%; height: 100%; }
.clip-ghost { position: absolute; inset: 0; z-index: -1; border-radius: 12px; background-size: cover; opacity: .2; }
.hd { position: absolute; z-index: 2; width: 18px; height: 18px; margin: -9px 0 0 -9px; padding: 0; border: 3px solid #fff; border-radius: 50%; background: var(--c, #2f5bea); box-shadow: 0 1px 5px rgba(0, 0, 0, .45); cursor: grab; touch-action: none; }
.mesh-box { position: relative; width: min(440px, 88%); aspect-ratio: 16 / 10; }
.mesh-box .pv { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 16px; }

/* Curva y muelle */
.curve-wrap { display: grid; justify-items: center; gap: 14px; width: 100%; }
.curve, .spring-graph { width: 240px; overflow: visible; touch-action: none; }
.curve { height: 240px; }
.cv-box { fill: none; stroke: #c8c8c2; stroke-dasharray: 3 3; }
.cv-lin { stroke: #c8c8c2; stroke-width: 1; }
.cv-arm { stroke: #9a9893; stroke-width: 1.5; }
.cv-path, .spring-graph polyline { fill: none; stroke: #2f5bea; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.sg-target { stroke: #c8c8c2; stroke-dasharray: 4 4; }
.cv-h { fill: #fff; stroke: #2f5bea; stroke-width: 3; cursor: grab; }
.stage[data-bg="dark"] .cv-box, .stage[data-bg="dark"] .cv-lin { stroke: #45464b; }
.stage[data-bg="dark"] .cv-path, .stage[data-bg="dark"] .cv-h, .stage[data-bg="dark"] .spring-graph polyline { stroke: #7c9cff; }
.stage[data-bg="dark"] .cv-h { fill: #16171a; }
.tracks { display: grid; gap: 8px; width: min(420px, 90%); }
.track { position: relative; height: 40px; border-radius: 20px; background: rgba(128, 128, 128, .15); container-type: inline-size; }
.track.ghost { opacity: .55; }
.ball { position: absolute; left: 4px; top: 4px; width: 32px; height: 32px; border-radius: 50%; background: #2f5bea; }
.ball.lin { background: #94a3b8; }
.ball:not([data-prop="transform"]) { left: calc(50% - 16px); border-radius: 9px; }
.ball.go[data-prop="transform"] { transform: translateX(calc(100cqw - 40px)); }
.ball.go[data-prop="scale"] { transform: scale(1.9); }
.ball.go[data-prop="rotate"] { transform: rotate(360deg); }
.ball.go[data-prop="opacity"] { opacity: .08; }

/* Tamaño fluido y escala */
.fluid { display: grid; justify-items: center; gap: 10px; width: 100%; }
.fl-txt { font-weight: 700; line-height: 1.1; }
.fl-box { display: flex; gap: 10px; border: 2px dashed rgba(128, 128, 128, .4); border-radius: 10px; }
.fl-box i { width: 40px; height: 40px; border-radius: 8px; background: #2f5bea; }
.fl-now { margin: 0; font-size: 13px; }
.fl-graph { width: 260px; }
.fl-graph polyline { fill: none; stroke: #2f5bea; stroke-width: 3; stroke-linejoin: round; }
.fl-graph line { stroke: #e5484d; stroke-dasharray: 3 3; }
.scale-list { display: grid; gap: 4px; width: min(560px, 100%); max-height: 100%; overflow: auto; }
.sc-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: baseline; gap: 10px; border-bottom: 1px solid rgba(128, 128, 128, .2); padding-bottom: 2px; }
.sc-row small { color: #8a8984; font: 600 11px var(--mono); }
.sc-row span { overflow: hidden; white-space: nowrap; line-height: 1.2; font-weight: 600; }
.sc-row em { color: #8a8984; font: 400 11px var(--mono); }

/* Guardados e importar */
.saved-list { display: grid; gap: 4px; max-height: 60dvh; margin: 8px 0 0; padding: 0; overflow: auto; list-style: none; }
.saved-list li { display: flex; align-items: center; gap: 4px; }
.saved-list .empty { padding: 20px 0; color: var(--text-2); }
.sv-open { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; padding: 8px; border: 0; border-radius: 10px; background: none; text-align: left; color: var(--text); }
.sv-open:hover { background: var(--hover); }
.sv-open span { display: grid; min-width: 0; }
.sv-open b { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.sv-open small { color: var(--text-3); font-size: 12px; }
.sv-pv { flex: none; width: 44px; height: 30px; border-radius: 6px; background: #e2e8f0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.sv-pv.none { background: var(--sunken); }
#importDlg textarea { width: 100%; margin-top: 8px; font-size: 13px; }

/* ───────── Pantallas medianas ───────── */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 190px minmax(0, 1fr) 300px; }
  .bar-acts .btn { padding: 0 8px; }
}
@media (max-width: 1000px) {
  body { overflow: auto; }
  .shell { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px auto auto auto; grid-template-areas: "top" "nav" "stage" "ctrl"; }
  .nav { border: 0; border-bottom: 1px solid var(--border); }
  .nav-list { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
  .nav-g { display: flex; flex: none; align-items: center; margin: 0; }
  .nav-list button { flex: none; }
  .stage { min-height: 320px; }
  .ctrl { border-left: 0; }
}

/* ───────── Móvil: la vista previa se queda arriba mientras mueves los controles ───────── */
@media (max-width: 700px) {
  .shell { grid-template-rows: auto; grid-template-areas: "top" "bar" "stage" "ctrl" "code"; }
  .nav { display: none; }
  .stage-col { display: contents; }
  .stage-bar { grid-area: bar; padding: 10px 12px 8px; }
  .gen-title h1 { display: none; }
  .gen-title { flex-basis: 100%; order: 2; }
  .bar-acts { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  .bar-acts::-webkit-scrollbar { display: none; }
  .bar-acts > * { flex: none; }
  .stage-wrap { grid-area: stage; position: sticky; top: 0; z-index: 3; margin: 0 12px; }
  .stage { height: 230px; min-height: 0; padding: 14px; box-shadow: 0 10px 18px -12px rgba(0, 0, 0, .5); }
  .stage-wrap:has([data-gen="curva"]), .stage-wrap:has([data-gen="muelle"]), .stage-wrap:has([data-gen="escala"]), .stage-wrap:has([data-gen="fluido"]), .stage-wrap:has([data-gen="recorte"]) { position: relative; }
  .stage:is([data-gen="curva"], [data-gen="muelle"], [data-gen="fluido"]) { height: auto; }
  .stage[data-gen="recorte"] { height: 260px; }
  .stage-bg { right: 8px; top: 8px; }
  .code { grid-area: code; margin: 0 12px 16px; }
  .code pre { max-height: none; }
  .code-h .sel-in { flex: 1; min-width: 90px; }
  .ctrl { padding-top: 14px; }
  .demo, .demo.box.big, .mesh-box, .glass-bg, .clip-box { width: min(100%, 320px); }
  .neu { width: 130px; }
  .neu-wrap { min-height: 0; margin: -14px; padding: 14px; height: calc(100% + 28px); }
  .scroll-demo { height: 170px; }
  .layout-box { min-height: 0; max-height: 100%; overflow: auto; }
}

/* Pantallas táctiles */
:root[data-input="touch"] .nav-list button { min-height: 40px; }
:root[data-input="touch"] .num { width: 68px; height: 34px; font-size: 16px; }
:root[data-input="touch"] .st-row .num { width: 58px; }
:root[data-input="touch"] .pt-row .num { width: 60px; }
:root[data-input="touch"] .lst-tg { height: 42px; }
:root[data-input="touch"] .lst-acts .icon-btn { width: 36px; height: 36px; }
:root[data-input="touch"] .st-row .input, :root[data-input="touch"] .code-h .input { height: 38px; font-size: 16px; }
:root[data-input="touch"] .crow input[type="color"], :root[data-input="touch"] .st-row input[type="color"] { width: 42px; height: 38px; }
:root[data-input="touch"] .st-bar { height: 36px; }
:root[data-input="touch"] .st-mk { width: 24px; height: 44px; margin: -22px 0 0 -12px; }
:root[data-input="touch"] .hd { width: 28px; height: 28px; margin: -14px 0 0 -14px; }
:root[data-input="touch"] .cv-h { r: 13; }
:root[data-input="touch"] .stage-bg button { height: 34px; padding: 0 12px; }
/* Móvil: el fondo de la vista previa se elige con cuatro muestras pequeñas */
@media (max-width: 700px) {
  .stage-bg { gap: 6px; padding: 4px; border-radius: 99px; }
  .stage-bg button, :root[data-input="touch"] .stage-bg button { width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 50%; font-size: 0; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, .5); }
  .stage-bg button[data-sbg="light"] { background: #f4f4f1; }
  .stage-bg button[data-sbg="dark"] { background: #16171a; }
  .stage-bg button[data-sbg="checker"] { background: conic-gradient(#d4d4d0 25%, #fff 0 50%, #d4d4d0 0 75%, #fff 0) 0 0 / 10px 10px; }
  .stage-bg button[data-sbg="photo"] { background: linear-gradient(#ffb35c, #ff6f91 55%, #5b3f8c 56%); }
  .stage-bg button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
}
