:root {
  --fondo: #ecebe7;
  --tinta: #1d1d1b;
  --tenue: rgba(29, 29, 27, .3);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: var(--ancho-bandeja, 76px) minmax(0, 1fr) var(--ancho-lado, 300px);
  transition: grid-template-columns .3s ease;
  background: var(--fondo);
  color: var(--tinta);
  font: 11px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  user-select: none;
}

#bandeja {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  overflow-y: auto;
}

#bandeja img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  cursor: grab;
  -webkit-user-drag: none;
}

#soltar {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px dashed var(--tenue);
  color: var(--tenue);
  font-size: 18px;
  cursor: pointer;
}

#centro {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  padding-bottom: 16px;
}

/* Los discos: una grilla que ajustar() reparte según cuántos hay */
#escenario {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#discos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 24px;
  flex: none;
}

.disco {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.disco canvas { display: block; touch-action: none; }
.disco.silenciado canvas { opacity: .45; }

.pie {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  height: 22px;
  color: rgba(29, 29, 27, .55);
}

#discos.uno .pie { display: none; }

.pie .titulo {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.disco.elegido .titulo { color: var(--tinta); }
.disco.elegido .titulo::before { content: "● "; color: #e5482b; }

.pie button {
  flex: none;
  padding: 0 2px;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.pie button:hover { color: var(--tinta); }
.disco.silenciado .silenciar { color: #e5482b; }

/* Flechas para plegar paneles y botón de modo músico */
.plegar, #musico {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px dashed transparent;
  background: none;
  color: var(--tenue);
  cursor: pointer;
}

.plegar:hover, #musico:hover { color: var(--tinta); border-color: var(--tenue); }

.plegar svg, #musico svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plegar svg { width: 10px; height: 10px; transition: transform .3s ease; }

.plegar[data-panel="bandeja"] { left: 2px; top: 50%; width: 16px; height: 44px; margin-top: -22px; }
.plegar[data-panel="lado"] { right: 2px; top: 50%; width: 16px; height: 44px; margin-top: -22px; }
.plegar[data-panel="controles"] { bottom: 1px; left: 50%; width: 44px; height: 14px; margin-left: -22px; }

/* La flecha apunta hacia donde se va el panel */
.plegar[data-panel="bandeja"] svg { transform: rotate(180deg); }
body.sin-bandeja .plegar[data-panel="bandeja"] svg { transform: none; }
body.sin-lado .plegar[data-panel="lado"] svg { transform: rotate(180deg); }
.plegar[data-panel="controles"] svg { transform: rotate(90deg); }
body.sin-controles .plegar[data-panel="controles"] svg { transform: rotate(-90deg); }

#musico { top: 10px; right: 10px; width: 26px; height: 26px; }
#musico svg { width: 12px; height: 12px; }
body.musico #musico { color: var(--tinta); }

body.sin-bandeja { --ancho-bandeja: 0px; }
body.sin-lado { --ancho-lado: 0px; }
body.sin-bandeja #bandeja,
body.sin-lado #lado { opacity: 0; pointer-events: none; }
#bandeja, #lado { transition: opacity .2s ease; }
body.sin-controles #controles { display: none; }

#velocidad {
  display: flex;
  align-items: center;
  gap: 12px;
}

#velocidad button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px dashed var(--tenue);
  background: none;
  color: var(--tinta);
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

#velocidad button:hover:not(:disabled) { border-style: solid; }
#velocidad button:disabled { color: var(--tenue); cursor: default; }

#rpm {
  min-width: 8ch;
  text-align: center;
}

#rpm.pausa { color: var(--tenue); }

/* Barra bajo el disco: transporte, modo, escala y presets */
#controles {
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 0 16px;
}

#controles .fila {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 20px;
}

#controles .fila:last-child { gap: 8px; }

#controles .grupo {
  display: flex;
  align-items: center;
  gap: 10px;
}

#modo { gap: 0; }
#modo button + button { border-left: none; }

button.texto, a.texto {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px dashed var(--tenue);
  background: none;
  color: var(--tinta);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

button.texto:hover, a.texto:hover { border-style: solid; }
a.texto { text-decoration: none; }
button.texto:disabled { color: var(--tenue); cursor: default; border-style: dashed; }
button.texto.elegido { background: var(--tinta); color: var(--fondo); border-style: solid; border-color: var(--tinta); }

#controles label, #editor label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(29, 29, 27, .6);
}

#controles select, #editor input[type=text] {
  height: 28px;
  max-width: 180px;
  padding: 0 6px;
  border: 1px dashed var(--tenue);
  border-radius: 0;
  background: none;
  color: var(--tinta);
  font: inherit;
  cursor: pointer;
}

/* La escala y la tónica importan en la caja de música y en el modo figurativo */
body:not(.caja) .solo-caja { opacity: .35; pointer-events: none; }
/* La afinación solo existe en el modo figurativo */
body:not(.figurativo) .solo-fig { display: none; }
#afinacion { width: 110px; accent-color: var(--tinta); cursor: pointer; }
#afinacionValor { min-width: 3ch; text-align: right; color: var(--tinta); font-variant-numeric: tabular-nums; }

#aviso {
  min-width: 0;
  color: var(--acento, #e5482b);
}

#pausa { margin-right: 8px; }
#pausa svg { fill: currentColor; }
#pausa .icono-girar,
#pausa.detenido .icono-pausa { display: none; }
#pausa.detenido .icono-girar { display: block; }

#lado {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 20px 20px 0;
  min-height: 0;
  overflow-y: auto;
}

#vista {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

/* Perillas de la cámara, al estilo plugdata */
#ajustes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 4px;
  flex: none;
}

.perilla {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: ns-resize;
  touch-action: none;
}

.perilla svg { width: 48px; height: 48px; overflow: visible; }

.perilla .pista {
  fill: none;
  stroke: var(--tenue);
  stroke-width: 3;
}

.perilla .valor {
  fill: none;
  stroke: #e5482b;
  stroke-width: 3;
}

.perilla .cuerpo {
  fill: var(--fondo);
  stroke: var(--tinta);
  stroke-width: 1;
}

.perilla .aguja {
  stroke: var(--tinta);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.perilla.activa .cuerpo { fill: #fff; }

/* Botón ↺ para volver al valor inicial, en la esquina de cada perilla */
.perilla .reiniciar {
  position: absolute;
  top: -2px;
  right: 0;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  background: none;
  color: var(--tinta);
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.perilla .reiniciar:hover:not(:disabled) { color: #e5482b; }
.perilla .reiniciar:disabled { color: var(--tenue); cursor: default; }

/* Recuadro de número, con el triángulo de plugdata a la izquierda */
.perilla .caja {
  position: relative;
  width: 58px;
  padding: 1px 4px 1px 12px;
  border: 1px solid var(--tinta);
  text-align: right;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.perilla .caja::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7px;
  background: var(--tinta);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.perilla.cambiada .caja { color: #e5482b; }

.perilla .nombre {
  color: rgba(29, 29, 27, .6);
  font-size: 10px;
  white-space: nowrap;
}

#osc {
  width: 100%;
  aspect-ratio: 1;
  flex: none;
}

#datos {
  margin: 0;
  white-space: pre;
  font: inherit;
}

.fantasma {
  position: fixed;
  width: 64px;
  height: 64px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: .7;
  z-index: 10;
}

/* Editor de objeto nuevo */
#editor {
  max-width: min(860px, 94vw);
  padding: 20px;
  border: 1px solid var(--tinta);
  background: var(--fondo);
  color: var(--tinta);
  font: inherit;
}

#editor::backdrop { background: rgba(29, 29, 27, .35); }

.e-titulo { margin-bottom: 12px; color: rgba(29, 29, 27, .6); }

.e-cuerpo {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}

.e-cuerpo figure { margin: 0; }
.e-cuerpo canvas { display: block; width: 380px; max-width: 100%; height: 280px; }
.e-cuerpo figcaption { margin-top: 4px; color: rgba(29, 29, 27, .55); font-size: 10px; }

#ePerillas {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 18px 0 16px;
}

.e-pie {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.e-pie label { margin-right: auto; }
#editor input[type=text] { width: 180px; max-width: none; cursor: text; }
#editor input[type=text]:focus { outline: none; border-style: solid; }
#eAviso { color: #e5482b; }
