/**
 * AlgoViz — estilos de la aplicación.
 *
 * Todo color, tipografía y radio sale de las variables del tema activo
 * (static/css/themes/*.css, elegido con <html data-theme="…">). Aquí no debe
 * aparecer ningún color fijo.
 */

/* ── BASE ─────────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--accent-text);
}

.text-accent { color: var(--accent); }
.text-done { color: var(--done); }
.text-strong { color: var(--text); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

/* ── ESTRUCTURA DE LA APP ────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.app-main {
  min-width: 0;
  overflow-y: auto;
}

.app-main--viz {
  overflow: hidden;
}

/* ── BARRA LATERAL ───────────────────────────────────────────────────── */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
  padding: 12px 0;
  background: var(--bg-rail);
  border-right: 1px solid var(--line);
}

.rail__logo {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  padding: 10px 8px;
  border: 1.5px solid var(--text);
  border-radius: var(--radius);
}

.rail__logo-bar {
  width: 5px;
  border: 1.5px solid var(--text);
  border-bottom: none;
}

.rail__logo-bar--accent {
  background: var(--accent);
  border-color: var(--accent);
}

.rail__current {
  display: none;
}

.rail__groups {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 2px 0;
}

.rail__group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail__group + .rail__group {
  padding-top: 12px;
  border-top: 1px solid var(--line-medium);
}

.rail__tile {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-body);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: color 150ms, border-color 150ms, background-color 150ms;
}

.rail__tile:hover {
  color: var(--text);
  border-color: var(--text);
}

.rail__tile[aria-current="page"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.rail__badge-3d {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  background: var(--accent);
}

.rail__icon-button {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-body);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.rail__icon-button:hover,
.rail__icon-button[aria-expanded="true"] {
  color: var(--text);
  border-color: var(--text);
}

.rail__menu-button {
  display: none;
}

/* Menú de algoritmos en móvil */

.nav-sheet {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-content: start;
  gap: 20px;
  background: var(--bg-rail);
}

.nav-sheet__title {
  padding-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-sheet__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 10px;
  font-size: 15px;
  text-decoration: none;
  color: var(--text-soft);
  border-radius: var(--radius);
}

.nav-sheet__link[aria-current="page"] {
  background: var(--text);
  color: var(--bg);
}

.nav-sheet__badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
}

/* ── AJUSTES DE APARIENCIA ───────────────────────────────────────────── */

.theme-popover {
  position: fixed;
  left: 84px;
  bottom: 12px;
  z-index: 50;
  width: 340px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--bg-panel);
  border: 1.5px solid var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-popover);
}

.theme-popover__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.theme-popover__options {
  border: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-popover__legend {
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.theme-option {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 2px;
  padding: 12px;
  border: 1px solid var(--line-medium);
  border-radius: var(--radius);
  cursor: pointer;
}

.theme-option:hover {
  border-color: var(--text);
}

.theme-option:has(.theme-option__input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.theme-option:has(.theme-option__input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.theme-option__input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-option__swatches {
  grid-row: 1 / 3;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(2, 14px);
  gap: 2px;
}

.theme-option__swatches span {
  width: 14px;
  height: 14px;
  outline: 1px solid var(--line);
}

.theme-option__name {
  font-weight: 600;
}

.theme-option__description {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
}

.theme-popover__note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

/* ── CONTROLES ───────────────────────────────────────────────────────── */

.ui-button {
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 150ms, border-color 150ms, color 150ms;
}

.ui-button:hover {
  background: var(--accent-soft);
  border-color: var(--text);
}

.ui-button[aria-pressed="true"],
.ui-button[aria-expanded="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.ui-button--primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: 600;
}

.ui-button--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.ui-button--icon {
  width: 44px;
  padding: 0;
}

.ui-button--compact {
  min-width: 44px;
  padding: 0 10px;
  border-width: 1px;
  text-transform: none;
  letter-spacing: 0.02em;
}

.ui-button--block {
  width: 100%;
}

.chip {
  padding: 5px 8px;
  border: 1px solid var(--line-medium);
  border-radius: var(--radius);
  color: var(--text-muted);
  white-space: nowrap;
}

.chip strong {
  color: var(--text);
  font-weight: 500;
}

.tag {
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.tag--accent {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── PORTADA ─────────────────────────────────────────────────────────── */

.home {
  min-height: 100%;
  padding: 56px clamp(16px, 5vw, 72px) 80px;
  display: flex;
  flex-direction: column;
  gap: 48px;
  background-color: var(--stage-bg);
  background-image: var(--stage-pattern);
  background-size: var(--stage-pattern-size);
}

.home__header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 860px;
}

.home__title {
  font-family: var(--font-display);
  font-size: clamp(34px, 5vw, 56px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.04;
}

.home__intro {
  max-width: 680px;
  font-size: 17px;
  line-height: 1.55;
  color: var(--text-body);
}

.home__group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.home__group-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.home__grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 16px;
}

.algo-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  text-decoration: none;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 150ms, transform 150ms;
}

.algo-card:hover {
  border-color: var(--text);
  transform: translateY(-2px);
}

.algo-card__tile {
  width: 46px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--text);
  border-radius: var(--radius);
}

.algo-card__name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.algo-card__summary {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-body);
}

.algo-card__meta {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.algo-card__complexity {
  margin-right: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

/* ── VISUALIZADOR A PANTALLA COMPLETA ────────────────────────────────── */

.viz {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 384px;
  grid-template-rows: 60px minmax(0, 1fr) 136px;
  height: 100vh;
}

.viz-top {
  grid-column: 1 / 3;
  grid-row: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 20px 0 28px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.viz-top__crumb {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  white-space: nowrap;
}

.viz-top__title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.viz-top__chips {
  list-style: none;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 11px;
}

.viz-top__spacer {
  flex: 1 1 auto;
}

/* Escenario */

.viz-stage {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 32px 16px;
  overflow: hidden;
  background-color: var(--stage-bg);
  background-image: var(--stage-pattern);
  background-size: var(--stage-pattern-size);
}

.viz-stage__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.viz-stage__status {
  display: flex;
  align-items: center;
  gap: 16px;
}

.viz-stage__pass {
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.viz-stage__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}

.status-badge {
  padding: 4px 8px;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.08em;
  background: var(--accent-soft);
  color: var(--text);
  border-radius: var(--radius);
  transition: background-color 200ms, color 200ms;
}

.status-badge[data-tone="active"] {
  background: var(--accent);
  color: var(--on-accent);
}

.status-badge[data-tone="done"] {
  background: var(--done);
  color: var(--on-accent);
}

.legend-inline {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--text-muted);
}

.legend-inline li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
}

.swatch--idle {
  border: 1.5px solid var(--bar-idle-border);
  background: var(--bar-idle-bg);
}

.swatch--active {
  border: 1.5px solid var(--bar-active-border);
  background: var(--bar-active-bg);
}

.swatch--done {
  background: var(--bar-done-bg);
}

.swatch--arc {
  width: 14px;
  height: 8px;
  border: 1.5px solid var(--accent);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.swatch--ordered {
  border: 1.5px solid var(--bar-ordered-border);
  background: var(--bar-ordered-bg);
}

.swatch--held {
  border: 1.5px solid var(--bar-held-border);
  background: var(--bar-held-bg);
}

.swatch--marked {
  border: 1.5px solid var(--bar-held-border);
  background: var(--bar-held-bg);
}

.swatch--beam {
  background: var(--beam-bg);
  border-top: 2px solid var(--beam-edge);
}

.swatch--faded {
  border: 1.5px solid var(--bar-idle-border);
  background: var(--bar-idle-bg);
  opacity: 0.38;
}

.swatch--band-less,
.swatch--band-greater {
  border-top: 2px solid;
}

.swatch--band-less {
  border-color: var(--band-less-border);
  background: var(--band-less-bg);
}

.swatch--band-greater {
  border-color: var(--band-greater-border);
  background: var(--band-greater-bg);
}

.swatch--call {
  width: 16px;
  height: 6px;
  border: 1.5px dashed var(--text-muted);
  border-top: none;
}

.swatch--target {
  width: 16px;
  height: 0;
  border-top: 1.5px dashed var(--accent);
}

.swatch--discarded {
  border: 1.5px dashed var(--bar-idle-border);
  opacity: 0.4;
}

.swatch--found {
  background: var(--bar-done-bg);
  box-shadow: 0 0 0 1.5px var(--bg), 0 0 0 3px var(--done);
}

.swatch--tile-frontier {
  background: var(--accent);
}

.swatch--tile-visited {
  background: linear-gradient(90deg, var(--scene-bar), var(--scene-ordered));
}

.swatch--tile-path {
  background: var(--done);
}

.swatch--tile-dead {
  background: var(--scene-grid);
  box-shadow: inset 0 0 0 1px var(--scene-line);
}

.swatch--wall {
  background: var(--scene-wall);
  box-shadow: inset 0 0 0 1px var(--scene-line);
}

.swatch--hill {
  width: 14px;
  background: linear-gradient(0deg, var(--scene-node) 0 30%, var(--scene-line) 30% 100%);
  clip-path: polygon(0 100%, 30% 30%, 55% 55%, 80% 0, 100% 100%);
}

.swatch--trail {
  width: 16px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.swatch--hole {
  border: 1.5px dashed var(--hole-border);
  border-bottom: none;
}

.swatch--sweep {
  position: relative;
  width: 12px;
  height: 3px;
  margin-right: 6px;
  background: var(--accent);
}

.swatch--sweep::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -7px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--accent);
  transform: translateY(-50%);
}

.swatch--scene-bar {
  background: var(--scene-bar);
  box-shadow: inset 0 0 0 1.5px var(--text);
}

.swatch--scene-ordered {
  background: var(--scene-ordered);
}

.swatch--front {
  background: var(--accent);
}

.swatch--ball-counted,
.swatch--ball-ordered,
.swatch--ball-done {
  border-radius: 50%;
}

.swatch--ball-ordered {
  background: var(--scene-ordered);
}

.swatch--ball-counted {
  background: var(--scene-bar);
  box-shadow: inset 0 0 0 1.5px var(--text);
}

.swatch--ball-done {
  background: var(--done);
}

.swatch--block {
  width: 16px;
  height: 6px;
  border: 1.5px solid var(--done);
  border-top: none;
}

.swatch--tray {
  width: 16px;
  height: 9px;
  border: 1.5px solid var(--scene-line);
  background: var(--done-soft);
}

.swatch--node,
.swatch--compared,
.swatch--largest {
  border-radius: 50%;
}

.swatch--node {
  background: var(--scene-node);
  box-shadow: inset 0 0 0 1.5px var(--text);
}

.swatch--compared {
  background: var(--accent);
}

.swatch--largest {
  width: 14px;
  height: 14px;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--accent);
}

/* Escenas 3D (render3d/sceneKit.js) */

.scene-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  margin-top: 12px;
}

.scene-stage__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.scene-stage__canvas:active {
  cursor: grabbing;
}

.scene-stage__labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.scene-stage__hint {
  position: absolute;
  right: 0;
  bottom: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  pointer-events: none;
}

.scene-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
  pointer-events: none;
  text-shadow: 0 0 3px var(--bg), 0 0 6px var(--bg);
}

.scene-label--node {
  font-size: 13px;
  text-shadow: none;
}

.scene-label--node[data-role="active"],
.scene-label--node[data-role="largest"] {
  color: var(--on-accent);
}

.scene-label--bar[data-role="active"],
.scene-label--bar[data-role="largest"],
.scene-label--index[data-role="active"] {
  color: var(--accent);
}

.scene-label--bar[data-role="done"] {
  color: var(--done);
}

.scene-label--index {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.scene-label--bar[data-role="ordered"] {
  color: var(--text-soft);
}

.scene-label--node[data-role="done"],
.scene-label--node[data-role="ordered"] {
  color: var(--on-accent);
}

/* Counting Sort: valor de cada tubo, su contador y los bloques de la salida. */
.scene-label--key {
  font-size: 14px;
}

.scene-label--count {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.scene-label--block {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--done-text);
}

.scene-label--key[data-active="true"],
.scene-label--count[data-active="true"],
.scene-label--block[data-active="true"] {
  color: var(--accent);
}

.scene-label__tag {
  margin-left: 1px;
  font-size: 9px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Caminos: valor de cada baldosa, entradas de la estructura y marcadores. */
.scene-label--tile {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-soft);
  text-shadow: 0 0 2px var(--bg), 0 0 4px var(--bg);
}

.scene-label--tile[data-state="current"],
.scene-label--tile[data-state="touched"] {
  color: var(--accent-text);
  font-weight: 600;
}

.scene-label--tile[data-state="3"] {
  color: var(--done-text);
}

.scene-label--entry {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-soft);
}

.scene-label--entry[data-next="true"] {
  color: var(--accent-text);
  font-weight: 600;
}

.scene-label--marker {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
}

.scene-label--rail-title {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--accent-text);
}

.scene-label--rail-caption {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Radix Sort: cada cifra en su span; la de la pasada actual, subrayada. */
.scene-label__digit[data-padding="true"] {
  opacity: 0.45;
}

.scene-label__digit[data-active="true"] {
  opacity: 1;
  text-decoration: underline 2px;
  text-underline-offset: 3px;
}

.scene-label--level {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  transition: color 200ms;
}

.scene-label--level[data-active="true"] {
  color: var(--accent-text);
}

.scene-label--limit {
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--done);
}

/* Barras (render2d/barStage.js) */

.bar-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 160px;
  margin: 100px 0 40px;
}

.bar-stage__zone {
  position: absolute;
  top: -100px;
  right: 0;
  bottom: 0;
  left: var(--zone-left, 100%);
  opacity: var(--zone-opacity, 0);
  background: var(--done-soft);
  border-left: 2px dashed var(--done);
  transition: left 420ms cubic-bezier(0.45, 0, 0.25, 1), opacity 300ms;
}

.bar-stage__zone-label {
  position: absolute;
  top: 6px;
  left: 6px;
  writing-mode: vertical-rl;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--done);
  white-space: nowrap;
}

/* Zona ordenada izquierda: solo la usan los algoritmos que fijan por los dos extremos. */
.bar-stage__zone--start {
  left: 0;
  right: auto;
  width: var(--zone-start-width, 0%);
  opacity: var(--zone-start-opacity, 0);
  border-left: none;
  border-right: 2px dashed var(--done);
  transition: width 420ms cubic-bezier(0.45, 0, 0.25, 1), opacity 300ms;
}

.bar-stage__zone--start .bar-stage__zone-label {
  left: auto;
  right: 6px;
}

/* Prefijo ordenado entre sí, todavía provisional (Insertion Sort). */
.bar-stage__zone--ordered {
  left: 0;
  right: auto;
  width: var(--zone-ordered-width, 0%);
  opacity: var(--zone-ordered-opacity, 0);
  background: var(--zone-ordered-bg);
  border-left: none;
  border-right: 2px dashed var(--zone-ordered-border);
  transition: width 420ms cubic-bezier(0.45, 0, 0.25, 1), opacity 300ms;
}

.bar-stage__zone--ordered .bar-stage__zone-label {
  color: var(--text-muted);
}

/* Quick Sort: zonas de la partición en curso. */
.bar-stage__band {
  position: absolute;
  top: -30px;
  bottom: 0;
  left: var(--band-left);
  width: var(--band-width);
  border-top: 2px solid var(--band-border);
  background: var(--band-bg);
  transition: left 300ms ease, width 300ms ease;
}

.bar-stage__band--less {
  --band-bg: var(--band-less-bg);
  --band-border: var(--band-less-border);
}

.bar-stage__band--greater {
  --band-bg: var(--band-greater-bg);
  --band-border: var(--band-greater-border);
}

.bar-stage__band-label {
  position: absolute;
  top: -18px;
  left: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--band-border);
  white-space: nowrap;
}

/* Quick Sort: la llamada en curso y las que esperan en la pila. */
.bar-stage[data-calls="true"] {
  margin-bottom: 68px;
}

.bar-stage__calls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -62px;
  height: 22px;
}

.bar-stage__call {
  position: absolute;
  top: 0;
  left: var(--call-left);
  width: var(--call-width);
  height: 7px;
  border: 1.5px dashed var(--text-muted);
  border-top: none;
  transition: left 300ms ease, width 300ms ease;
}

.bar-stage__call[data-state="active"] {
  border-style: solid;
  border-color: var(--accent);
}

.bar-stage__call-caption {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.bar-stage__call[data-state="active"] .bar-stage__call-caption {
  color: var(--accent-text);
}

/* Hueco que deja el elemento sostenido fuera de la fila. */
.bar-stage__hole {
  position: absolute;
  bottom: 0;
  left: var(--slot-left);
  width: var(--slot-width);
  height: 40px;
  transition: left 420ms cubic-bezier(0.45, 0, 0.25, 1);
}

.bar-stage__hole::before {
  content: "";
  position: absolute;
  inset: 0 var(--bar-inset, 12px);
  border: 1.5px dashed var(--hole-border);
  border-bottom: none;
}

.bar-stage__hole-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--accent-text);
}

.bar-stage[data-density="dense"] .bar-stage__hole-caption {
  display: none;
}

/* Haz de exploración: la columna del elemento que se está examinando. */
.bar-stage__beam {
  position: absolute;
  top: -30px;
  bottom: 0;
  left: var(--slot-left);
  width: var(--slot-width);
  background: var(--beam-bg);
  border-top: 2px solid var(--beam-edge);
  transition: left 260ms ease;
}

.bar-stage__beam-caption {
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}

/* Distintivo del elemento marcado (el mínimo provisional): salta a cada nuevo candidato. */
.bar-stage__marker {
  position: absolute;
  z-index: 2;
  left: calc(var(--slot-left) + var(--slot-width) / 2);
  bottom: var(--marker-bottom);
  padding: 1px 6px;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: var(--accent);
  color: var(--on-accent);
  transition: left 320ms cubic-bezier(0.45, 0, 0.25, 1), bottom 320ms cubic-bezier(0.45, 0, 0.25, 1);
}

/* Carril de la pasada: la ventana recorrida, con su sentido y lo que lleva hecho. */
.bar-stage__sweep {
  position: absolute;
  top: -66px;
  left: var(--sweep-left);
  width: var(--sweep-width);
  height: 12px;
  border-left: 1.5px solid var(--text-muted);
  border-right: 1.5px solid var(--text-muted);
  transition: left 420ms cubic-bezier(0.45, 0, 0.25, 1), width 420ms cubic-bezier(0.45, 0, 0.25, 1);
}

.bar-stage__sweep-track {
  position: absolute;
  top: 5px;
  left: 0;
  right: 0;
  border-top: 1.5px dashed var(--line-strong);
}

.bar-stage__sweep-progress {
  position: absolute;
  top: 4px;
  width: calc(var(--sweep-progress, 0) * 100%);
  height: 3px;
  background: var(--accent);
  transition: width 260ms ease;
}

.bar-stage__sweep[data-direction="forward"] .bar-stage__sweep-progress {
  left: 0;
}

.bar-stage__sweep[data-direction="backward"] .bar-stage__sweep-progress {
  right: 0;
}

.bar-stage__sweep-progress::after {
  content: "";
  position: absolute;
  top: 50%;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  transform: translateY(-50%);
}

.bar-stage__sweep[data-direction="forward"] .bar-stage__sweep-progress::after {
  right: -10px;
  border-left: 11px solid var(--accent);
}

.bar-stage__sweep[data-direction="backward"] .bar-stage__sweep-progress::after {
  left: -10px;
  border-right: 11px solid var(--accent);
}

.bar-stage__sweep-bound {
  position: absolute;
  bottom: 16px;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

.bar-stage__sweep-bound--start {
  left: 0;
}

.bar-stage__sweep-bound--end {
  left: 100%;
}

.bar-stage__sweep[data-captioned="false"] .bar-stage__sweep-bound {
  display: none;
}

.bar-stage__item {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--slot-left);
  width: var(--slot-width);
  transition: left 420ms cubic-bezier(0.45, 0, 0.25, 1), opacity 260ms;
}

.bar-stage__bar {
  position: absolute;
  bottom: 0;
  left: var(--bar-inset, 12px);
  right: var(--bar-inset, 12px);
  height: var(--bar-height);
  transform: translateY(var(--lift, 0px));
  background: var(--bar-idle-bg);
  border: 2px solid var(--bar-idle-border);
  border-bottom: none;
  border-radius: var(--bar-radius) var(--bar-radius) 0 0;
  transition: transform 260ms ease, height 300ms ease, background-color 200ms, border-color 200ms;
}

.bar-stage__item[data-role="active"] .bar-stage__bar {
  background: var(--bar-active-bg);
  border-color: var(--bar-active-border);
}

.bar-stage__item[data-role="done"] .bar-stage__bar {
  background: var(--bar-done-bg);
  border-color: var(--bar-done-border);
}

.bar-stage__item[data-role="ordered"] .bar-stage__bar {
  background: var(--bar-ordered-bg);
  border-color: var(--bar-ordered-border);
}

.bar-stage__item[data-role="held"] .bar-stage__bar,
.bar-stage__item[data-role="marked"] .bar-stage__bar {
  background: var(--bar-held-bg);
  border-color: var(--bar-held-border);
}

/* Lo que todavía no se ha examinado en esta pasada. */
.bar-stage__item[data-faded="true"] {
  opacity: 0.38;
}

/* Búsquedas: lo descartado se hunde y se apaga; lo encontrado brilla. */
.bar-stage__item[data-role="discarded"] {
  opacity: 0.3;
}

.bar-stage__item[data-role="discarded"] .bar-stage__bar {
  transform: translateY(6px);
  border-style: dashed;
}

.bar-stage__item[data-role="found"] .bar-stage__bar {
  background: var(--bar-done-bg);
  border-color: var(--bar-done-border);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--done);
}

.bar-stage__item[data-role="found"] .bar-stage__value {
  color: var(--done);
}

/* Línea de nivel del valor buscado. */
.bar-stage__target {
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: var(--target-bottom);
  height: 0;
  border-top: 1.5px dashed var(--accent);
  pointer-events: none;
  transition: bottom 300ms ease;
}

.bar-stage__target[data-found="true"] {
  border-top-color: var(--done);
}

.bar-stage__target-caption {
  position: absolute;
  right: 0;
  bottom: 4px;
  padding: 1px 6px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--accent-text);
  white-space: nowrap;
}

.bar-stage__target[data-found="true"] .bar-stage__target-caption {
  color: var(--done-text);
}

/* El elemento sostenido flota por encima del resto. */
.bar-stage__item[data-role="held"] {
  z-index: 1;
}

.bar-stage__value {
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: calc(var(--bar-height) + 8px);
  transform: translateY(var(--lift, 0px));
  text-align: center;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: transform 260ms ease, bottom 300ms ease, color 200ms, opacity 200ms;
}

.bar-stage__item[data-role="active"] .bar-stage__value,
.bar-stage__item[data-role="held"] .bar-stage__value,
.bar-stage__item[data-role="marked"] .bar-stage__value {
  color: var(--accent);
}

/* Letra que distingue valores repetidos (5a, 5b) para seguir su orden. */
.bar-stage__tag {
  margin-left: 1px;
  font-size: 10px;
  font-weight: 500;
  vertical-align: super;
  color: var(--text-muted);
}

.bar-stage__item[data-role="done"] .bar-stage__tag {
  color: var(--done-text);
}

.bar-stage__value[data-caption]::before {
  content: attr(data-caption);
  display: block;
  margin-bottom: 2px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--accent-text);
}

.bar-stage__item[data-role="done"] .bar-stage__value {
  color: var(--done);
}

.bar-stage[data-density="dense"] .bar-stage__value {
  opacity: 0;
}

.bar-stage[data-density="dense"] .bar-stage__bar {
  border-width: 1px;
}

.bar-stage__annotation {
  position: absolute;
  left: var(--annotation-left);
  width: var(--annotation-width);
  bottom: var(--annotation-bottom);
  height: 10px;
  border-left: 1.5px solid var(--accent);
  border-right: 1.5px solid var(--accent);
  transition: left 420ms cubic-bezier(0.45, 0, 0.25, 1), bottom 260ms ease;
}

.bar-stage__annotation::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  height: 1.5px;
  background: var(--accent);
}

.bar-stage__annotation-text {
  position: absolute;
  left: -90px;
  right: -90px;
  bottom: 14px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
}

.bar-stage__mark {
  position: absolute;
  bottom: -34px;
  height: 32px;
  left: var(--slot-left);
  width: var(--slot-width);
}

.bar-stage__mark::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  width: 1px;
  height: 8px;
  background: var(--line-strong);
}

.bar-stage__mark-label {
  position: absolute;
  top: 14px;
  left: -10px;
  right: -10px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.bar-stage__mark[data-active="true"] .bar-stage__mark-label {
  color: var(--accent);
  font-weight: 600;
}

/* Shell Sort: la subsecuencia de salto h que se está ordenando. */
.bar-stage__mark[data-focus="true"]::before {
  height: 11px;
  width: 2px;
  background: var(--accent);
}

.bar-stage__mark[data-focus="false"] .bar-stage__mark-label {
  opacity: 0.4;
}

.bar-stage__baseline {
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: -1px;
  height: 1.5px;
  background: var(--text);
}

/* Panel derecho */

.viz-panel {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
}

.panel-section {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
}

.panel-section--flush {
  padding-left: 0;
  padding-right: 0;
}

.panel-section--flush > .panel-section__header {
  padding: 0 22px;
}

.panel-section--grow {
  flex: 1 0 auto;
  border-bottom: none;
}

/*
 * En escritorio el panel tiene alto fijo: la sección de coste ocupa lo que dejan
 * las demás, la gráfica se encoge si hace falta y la nota se oculta si no cabe.
 */
@media (min-width: 901px) {
  .viz-panel .panel-section--grow {
    flex: 1 1 0;
    min-height: 150px;
    container-type: size;
  }

  .panel-section--grow .cost-chart {
    flex: 0 1 134px;
    min-height: 64px;
  }
}

@container (max-height: 190px) {
  .panel-section--grow .panel-section__footnote {
    display: none;
  }
}

.panel-section--narration {
  min-height: 132px;
  gap: 6px;
  padding-top: 16px;
  padding-bottom: 18px;
}

.panel-section__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 8px;
}

/* Si los contadores no caben, bajan enteros a la línea siguiente en vez de partir el título. */
.panel-section__header > .panel-section__title {
  white-space: nowrap;
}

.panel-section__header > .panel-section__meta {
  margin-left: auto;
}

.panel-section__title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-section__hint {
  color: var(--text-faint);
  text-transform: none;
  letter-spacing: 0.04em;
}

.panel-section__meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.panel-section__footnote {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}

.narration__title {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.narration__body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-body);
  text-wrap: pretty;
}

.pseudocode {
  list-style: none;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.35;
}

.pseudocode__line {
  display: flex;
  gap: 12px;
  padding: 2px 22px;
  white-space: pre;
  color: var(--text-soft);
  transition: background-color 200ms, color 200ms;
}

.pseudocode__number {
  flex-shrink: 0;
  width: 14px;
  text-align: right;
  color: var(--text-faint);
}

.pseudocode__line.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.pseudocode__line.is-active .pseudocode__number {
  color: var(--accent);
}

.variables-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line-medium);
  border-left: 1px solid var(--line-medium);
}

.variable-cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  border-right: 1px solid var(--line-medium);
  border-bottom: 1px solid var(--line-medium);
  transition: background-color 200ms;
}

.variable-cell__name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.variable-cell__value {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color 200ms;
}

.variable-cell[data-empty="true"] .variable-cell__value {
  color: var(--text-faint);
}

.variable-cell[data-changed="true"] {
  background: var(--accent-soft);
}

.variable-cell[data-changed="true"] .variable-cell__value {
  color: var(--accent);
}

/* Gráfica de coste (core/costChart.js) */

.cost-chart {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  overflow: visible;
}

.cost-chart__axis {
  stroke: var(--line-strong);
  stroke-width: 1;
}

.cost-chart__reference {
  stroke: var(--line-strong);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.cost-chart__label {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text-muted);
  paint-order: stroke;
  stroke: var(--bg-panel);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.cost-chart__line {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.cost-chart__line--future {
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0.35;
}

.cost-chart__line--comparisons { stroke: var(--accent); }
.cost-chart__line--swaps { stroke: var(--done); }

/* Curva de comparación: otro algoritmo con los mismos datos. */
.cost-chart__ghost {
  fill: none;
  stroke: var(--text-body);
  stroke-width: 1.6;
  stroke-dasharray: 0.5 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cost-chart__ghost-end {
  fill: var(--text-body);
}

.cost-chart__label--ghost {
  fill: var(--text-body);
}

.cost-chart__ghost.is-swaps {
  stroke: var(--done);
}

.cost-chart__ghost-end.is-swaps,
.cost-chart__label--ghost.is-swaps {
  fill: var(--done-text);
}

.cost-chart__marker {
  fill: var(--accent);
}

/* Barra inferior: reproducción y línea de tiempo */

.viz-dock {
  grid-column: 1 / 3;
  grid-row: 3;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px 0 28px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
}

.transport {
  display: flex;
  gap: 6px;
}

.transport__play {
  width: 60px;
}

.transport__icon-pause,
.transport__play[data-playing="true"] .transport__icon-play {
  display: none;
}

.transport__play[data-playing="true"] .transport__icon-pause {
  display: block;
}

.timeline {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timeline__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.timeline__header label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline__counter {
  white-space: nowrap;
}

.timeline__range,
.field__range {
  width: 100%;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.filmstrip {
  position: relative;
  height: 58px;
  display: flex;
  gap: 3px;
}

.filmstrip__segment {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
}

.filmstrip__box {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  gap: 1px;
  padding: 3px 3px 0;
  overflow: hidden;
  border: 1px solid var(--line-medium);
  border-radius: var(--radius);
}

.filmstrip[data-density="dense"] .filmstrip__box {
  gap: 0;
}

/* Miniaturas de mapa (páginas de caminos). */
.filmstrip__box--map {
  align-items: center;
  justify-content: center;
  padding: 3px;
}

.filmstrip__map {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
}

.filmstrip__thumb-bar {
  flex: 1 1 0;
  min-width: 0;
  background: var(--thumb-idle);
}

.filmstrip__thumb-bar.is-done {
  background: var(--done);
}

.filmstrip__thumb-bar.is-ordered {
  background: var(--thumb-ordered);
}

.filmstrip__thumb-bar.is-discarded {
  opacity: 0.25;
}

.filmstrip__label {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: left;
  white-space: nowrap;
  color: var(--text-muted);
}

.filmstrip__segment:hover .filmstrip__box {
  border-color: var(--text);
}

.filmstrip__segment[data-state="current"] .filmstrip__box {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.filmstrip__segment[data-state="current"] .filmstrip__label {
  color: var(--accent);
}

.filmstrip__segment[data-state="future"] {
  opacity: 0.4;
}

.filmstrip__playhead {
  position: absolute;
  top: -2px;
  bottom: 12px;
  left: var(--playhead-left, 0%);
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  pointer-events: none;
  transition: left 200ms;
}

.speed-group {
  display: flex;
  gap: 4px;
}

/* Paneles desplegables: datos y teoría */

.viz-drawer {
  position: absolute;
  top: 60px;
  right: 0;
  z-index: 20;
  width: min(440px, 100%);
  max-height: calc(100% - 60px);
  overflow-y: auto;
  background: var(--bg-panel);
  border-left: 1.5px solid var(--text);
  border-bottom: 1.5px solid var(--text);
  box-shadow: var(--shadow-popover);
}

.viz-drawer__header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 12px 22px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.viz-drawer__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.viz-drawer__body {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px 22px 26px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field__label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field__error {
  font-size: 13px;
  color: var(--accent-text);
}

.field__error:empty {
  display: none;
}

.text-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 14px;
}

.text-input[aria-invalid="true"] {
  border-color: var(--accent);
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Editor del mapa (cajón «Tu mapa» de las páginas de caminos). */
.grid-editor {
  display: grid;
  grid-template-columns: repeat(var(--editor-columns, 17), minmax(0, 1fr));
  gap: 1px;
  margin-top: 10px;
  padding: 1px;
  background: var(--line-medium);
  touch-action: none;
  user-select: none;
}

.grid-editor__cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: var(--scene-node);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
}

.grid-editor__cell:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.grid-editor__cell[data-kind="wall"] {
  background: var(--scene-wall);
}

.grid-editor__cell[data-kind="start"] {
  background: var(--done);
  color: var(--on-accent);
}

.grid-editor__cell[data-kind="goal"] {
  background: var(--accent);
  color: var(--on-accent);
}

.grid-editor__cell[data-kind="open"][data-weight="2"] {
  background: color-mix(in srgb, var(--scene-line) 18%, var(--scene-node));
}

.grid-editor__cell[data-kind="open"][data-weight="3"] {
  background: color-mix(in srgb, var(--scene-line) 32%, var(--scene-node));
}

.grid-editor__cell[data-kind="open"][data-weight="4"] {
  background: color-mix(in srgb, var(--scene-line) 46%, var(--scene-node));
}

.grid-editor__cell[data-kind="open"][data-weight="5"] {
  background: color-mix(in srgb, var(--scene-line) 60%, var(--scene-node));
  color: var(--bg);
}

.grid-editor__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.drawer-note {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.theory__section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theory h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.theory p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-soft);
}

.theory strong {
  color: var(--text);
}

.theory-steps {
  list-style: none;
  border-top: 1px solid var(--line);
}

.theory-steps li {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-soft);
  border-bottom: 1px solid var(--line);
}

.theory-steps__number {
  flex-shrink: 0;
  font-family: var(--font-mono);
  color: var(--accent);
}

.facts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line-medium);
  border-left: 1px solid var(--line-medium);
  font-family: var(--font-mono);
}

.facts-grid div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-right: 1px solid var(--line-medium);
  border-bottom: 1px solid var(--line-medium);
}

.facts-grid dt {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.facts-grid dd {
  font-size: 15px;
  font-weight: 600;
}

/* ── MÓVIL ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  /* En pantallas estrechas las etiquetas de nivel de la escena se quedan en «NIVEL n». */
  .scene-label__detail {
    display: none;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px auto;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .rail {
    position: sticky;
    top: 0;
    z-index: 45;
    flex-direction: row;
    height: 56px;
    padding: 0 12px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .rail__logo {
    width: 40px;
    height: 40px;
    padding: 8px 7px;
  }

  .rail__groups {
    display: none;
  }

  .rail__current {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
  }

  .rail__menu-button {
    display: flex;
  }

  .app-main,
  .app-main--viz {
    overflow: visible;
  }

  .viz {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    height: auto;
  }

  .viz-top {
    grid-column: 1;
    grid-row: 1;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 16px;
  }

  .viz-top__crumb,
  .viz-top__chips,
  .legend-inline {
    display: none;
  }

  .viz-top__title {
    font-size: 20px;
  }

  .viz-stage {
    grid-column: 1;
    grid-row: 2;
    min-height: 440px;
    padding: 16px;
  }

  .viz-dock {
    grid-column: 1;
    grid-row: 3;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }

  .timeline {
    order: 3;
    flex: 1 1 100%;
  }

  .timeline__header label {
    font-size: 10px;
  }

  .viz-panel {
    grid-column: 1;
    grid-row: 4;
    overflow: visible;
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .viz-drawer {
    position: fixed;
    top: 56px;
    bottom: 0;
    z-index: 44;
    width: 100%;
    max-height: none;
    border-left: none;
  }

  .theme-popover {
    left: 12px;
    right: 12px;
    top: 64px;
    bottom: auto;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
  }
}
