:root{
  --fondo:var(--mx-fondo);
  --panel:var(--mx-fondo);
  --sube:var(--mx-sup);
  --linea:var(--mx-linea);
  --linea-2:var(--mx-linea-2);
  --tenue:var(--mx-apagado);
  --texto:var(--mx-sec);
  --claro:var(--mx-texto);
  --acento:var(--mx-texto);
  --mono:var(--mx-sans);
  --sans:var(--mx-sans);
  color-scheme: dark;
}
*{ box-sizing: border-box; }
html, body{ height: 100%; margin: 0; background: var(--fondo); color: var(--texto); }
body{ font: 400 13px/1.35 var(--sans); -webkit-font-smoothing: antialiased; }
button, select, input{ font: inherit; color: inherit; }
button{ cursor: pointer; }
[hidden]{ display: none !important; }
:focus{ outline: none; }
:focus-visible{ outline: 2px solid var(--acento); outline-offset: 2px; }

#app{ display: grid; grid-template-columns: minmax(0, 1fr) 312px; height: 100dvh; }

/* Lienzo */
#escena{ position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--fondo); }
#marco{ position: absolute; }
#marco canvas{ position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#capa{ position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }
#capa:focus-visible{ outline: none; }
#capa.sobre{ cursor: grab; }
#capa.tira{ cursor: grabbing; }
#capa.dibuja{ cursor: crosshair; }

#riel{ position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; padding: 4px; background: var(--panel); border: 1px solid var(--linea); border-radius: 12px; }
#riel i{ display: block; height: 1px; margin: 4px 6px; background: var(--linea-2); }
.her{ width: 34px; height: 34px; padding: 7px; border: 0; border-radius:var(--mx-r); background: none; color: var(--texto); transition: background-color .15s, color .15s; }
.her svg, .ico svg{ display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.her:hover{ background: var(--sube); color: var(--claro); }
.her:active{ background: var(--linea-2); }
.her[data-t][aria-pressed="true"]{ background: var(--claro); color:var(--mx-fondo); }
#t-ver[aria-pressed="false"]{ color: var(--tenue); }

#pista{ position: absolute; left: 66px; right: 16px; bottom: 12px; margin: 0; font-size: 12px; color: var(--tenue); pointer-events: none; text-align: center; }
#suelta{ position: absolute; inset: 12px; display: grid; place-items: center; border: 1px dashed rgba(255,255,255,.7); border-radius: 12px; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; pointer-events: none; }

/* Panel */
#panel{ background: var(--panel); border-left: 1px solid var(--linea); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--linea-2) transparent; }
.cab{ position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; height: 48px; padding: 0 12px 0 16px; background: var(--panel); border-bottom: 1px solid var(--linea); }
.cab-der{ display: flex; align-items: center; gap: 4px; }
h1{ margin: 0;;;; }
h2{ margin: 0 0 10px;;; }
.grupo{ padding: 14px 16px; border-bottom: 1px solid var(--linea); }
.bloque{ margin-top: 8px; }
.ico{ width: 28px; height: 28px; padding: 5px; border: 0; border-radius:var(--mx-r); background: none; color: var(--texto); }
.ico:hover:not(:disabled){ background: var(--sube); color: var(--claro); }
.ico:disabled{ color:var(--mx-apagado); cursor: default; }
#azar{ height: 28px; margin-left: 4px; padding: 0 11px; background: var(--sube); border: 0; border-radius:var(--mx-r); color: var(--claro); font-weight: 500; transition: background-color .15s; }
#azar:hover{ background: var(--linea-2); }
#azar:active{ background: var(--mx-sup-2); }

/* Plantillas */
.plantillas{ display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pl{ all: unset; display: block; cursor: pointer; min-width: 0; border-radius:var(--mx-r); }
.pl canvas{ display: block; width: 100%; aspect-ratio: 4 / 5; background: #000; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.07); transition: opacity .15s; }
.pl span{ display: block; margin-top: 4px; font-size: 12px; line-height: 1.15; color: var(--tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl:hover span{ color: var(--claro); }
.pl[aria-pressed="true"] canvas{ box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--claro); }
.pl[aria-pressed="true"] span{ color: var(--claro); }
.pl:focus-visible{ outline: 2px solid var(--acento); outline-offset: 2px; }

/* Segmentados */
.seg{ display: grid; gap: 2px; padding: 2px; background: var(--fondo); border-radius:var(--mx-r); }
.seg.tres{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg.cuatro{ grid-template-columns: repeat(4, minmax(0, 1fr)); }
.seg.cinco{ grid-template-columns: repeat(5, minmax(0, 1fr)); }
.seg button{ height: 28px; padding: 0 2px; border: 0; border-radius:var(--mx-r); background: none; color: var(--texto); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background-color .15s, color .15s; }
.seg button:hover{ color: var(--claro); background: var(--sube); }
.seg button[aria-checked="true"]{ background: var(--linea-2); color: var(--claro); font-weight: 500; }
.sel-linea{ display: grid; grid-template-columns: 62px minmax(0, 1fr); align-items: center; gap: 8px; margin-top: 8px; font-size: 12.5px; }

/* Barra de degradado */
.barra{ position: relative; height: 38px; margin: 0 6px 8px; }
#barra-c{ position: absolute; left: -6px; top: 0; width: calc(100% + 12px); height: 22px; cursor: copy; border-radius:var(--mx-r); box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
#paradas{ position: absolute; left: 0; right: 0; top: 0; height: 38px; pointer-events: none; }
.parada{ position: absolute; top: 0; width: 14px; height: 38px; margin-left: -7px; padding: 0; background: none; border: 0; pointer-events: auto; cursor: ew-resize; touch-action: none; }
.parada::before{ content: ""; position: absolute; left: 6.5px; top: 0; width: 1px; height: 26px; background: #fff; box-shadow: 0 0 0 .5px rgba(0,0,0,.6); }
.parada i{ position: absolute; left: 1.500px; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; border: 1.500px solid #fff; box-shadow: 0 0 0 .5px rgba(0,0,0,.65); }
.parada.activa i{ box-shadow: 0 0 0 1.500px var(--acento); }

.fila-col{ display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muestras{ display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.muestra{ position: relative; display: block; width: 26px; height: 26px; border-radius:var(--mx-r); box-shadow: inset 0 0 0 1px rgba(255,255,255,.14); cursor: pointer; }
.muestra input{ position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.muestra:focus-within{ outline: 2px solid var(--acento); outline-offset: 2px; }
.muestra.activa{ box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--claro); }
.paso{ display: flex; flex: none; gap: 2px; padding: 2px; background: var(--fondo); border-radius:var(--mx-r); align-self: flex-start; }
.paso button{ width: 24px; height: 22px; padding: 0; border: 0; border-radius:var(--mx-r); background: none; font: 14px/1 var(--sans); }
.paso button:hover:not(:disabled){ background: var(--sube); color: var(--claro); }
.paso button:disabled{ color:var(--mx-apagado); cursor: default; }

.desde{ margin-top: 12px; }
.rot{ display: block; margin-bottom: 6px; font-size: 12px; color: var(--tenue); }
.fotos{ display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.foto{ position: relative; display: block; aspect-ratio: 3 / 2; padding: 0; border: 0; background: var(--sube); overflow: hidden; cursor: pointer; border-radius:var(--mx-r); }
.foto img{ display: block; width: 100%; height: 100%; object-fit: cover; }
.foto[aria-pressed="true"]{ box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--claro); }
.subir{ display: grid; place-items: center; color: var(--texto); font-size: 12px; transition: background-color .15s; }
.subir:hover{ background: var(--linea-2); }
.subir input{ position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.subir:focus-within{ outline: 2px solid var(--acento); outline-offset: 2px; }

/* Deslizadores */
.des{ display: grid; grid-template-columns: 76px minmax(0, 1fr) 36px; align-items: center; height: 28px; column-gap: 8px; }
.des label{ font-size: 12.5px; color: var(--texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.des output{ font: 12px/1 var(--mono); text-align: right; color: var(--tenue); font-variant-numeric: tabular-nums; }
.des:hover label, .des:hover output{ color: var(--claro); }

.linea{ width: 100%; height: 28px; margin-top: 6px; background: none; border: 1px solid var(--linea-2); border-radius:var(--mx-r); color: var(--texto); font-size: 12px; }
.linea:hover{ background: var(--sube); color: var(--claro); }

/* Salida */
.salida{ border-bottom: 0; padding-bottom: 24px; }
.bots{ display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 8px; }
.fuerte{ height: 34px; padding: 0; border: 0; border-radius:var(--mx-r); background: var(--claro); color:var(--mx-fondo); font-weight: 500; transition: background-color .15s; }
.fuerte:hover{ background: #fff; }
.fuerte.sec{ background: var(--sube); color: var(--claro); }
.fuerte.sec:hover{ background: var(--linea-2); }
#video[aria-busy="true"]{ color: var(--acento); }
.fuerte:disabled{ opacity: .5; cursor: default; }
.estado{ min-height: 16px; margin: 6px 0 0; font-size: 12px; color: var(--tenue); overflow-wrap: anywhere; }
.firma{ display: inline-block; margin-top: 8px; font-size: 12px; color: var(--tenue); text-decoration: none; }
.firma:hover{ color: var(--claro); }

/* Sin WebGL2 */
#sin-gl{ position: fixed; inset: 0; z-index: 9; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 460px; margin: auto; font-size: 15px; line-height: 1.45; color: var(--claro); }
#sin-gl p{ margin: 0 0 8px; }
#sin-gl p + p{ color: var(--texto); font-size: 13px; }

/* Pantallas chicas: lienzo arriba, herramientas bajo el lienzo, controles debajo */
@media (max-width: 860px) {
  html, body{ height: auto; }
  #app{ display: block; height: auto; }
  #escena{ position: sticky; top: 0; z-index: 3; height: 58vh; min-height: 300px; border-bottom: 1px solid var(--linea); }
  #riel{ left: 50%; top: auto; bottom: 8px; transform: translateX(-50%); flex-direction: row; max-width: calc(100% - 12px); }
  #riel i{ width: 1px; height: auto; margin: 6px 3px; }
  .her{ width: 32px; height: 36px; padding: 7px 6px; }
  #pista{ display: none; }
  #panel{ border-left: 0; overflow: visible; padding-bottom: env(safe-area-inset-bottom); }
  .cab{ position: static; }
  .des{ height: 36px; }
  .seg button{ height: 34px; }
  .paso button{ width: 32px; height: 28px; }
  .muestra{ width: 30px; height: 30px; }
  .fuerte{ height: 40px; }
  .plantillas{ gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *{ transition: none !important; }
}

/* Que arrastrar un deslizador no deje texto del panel seleccionado (el resaltado salía verde en el video) */
#panel{-webkit-user-select:none;user-select:none}
