/* ══════════════════════════════════════════════════════════════
   SIMULADOR INTERACTIVO DE PILAS — Sistema de Diseño CSS
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;500;600&display=swap');

/* ── Variables de Tema (Oscuro por defecto) ── */
:root {
  --primary: hsl(220, 90%, 56%);
  --primary-light: hsl(220, 85%, 68%);
  --primary-dark: hsl(220, 90%, 42%);
  --primary-glow: hsla(220, 90%, 56%, 0.35);

  --accent-green: hsl(160, 84%, 39%);
  --accent-green-light: hsl(160, 70%, 50%);
  --accent-purple: hsl(270, 76%, 60%);
  --accent-purple-light: hsl(270, 70%, 72%);
  --accent-orange: hsl(30, 95%, 55%);
  --accent-red: hsl(0, 78%, 55%);
  --accent-red-glow: hsla(0, 78%, 55%, 0.4);
  --accent-yellow: hsl(45, 95%, 55%);
  --accent-yellow-glow: hsla(45, 95%, 55%, 0.35);
  --accent-cyan: hsl(190, 90%, 50%);
  --accent-cyan-light: hsl(190, 80%, 65%);

  --bg-app: hsl(225, 28%, 8%);
  --bg-sidebar: hsl(225, 26%, 10%);
  --bg-surface: hsl(225, 22%, 13%);
  --bg-surface-alt: hsl(225, 20%, 16%);
  --bg-surface-hover: hsl(225, 18%, 20%);
  --bg-input: hsl(225, 22%, 11%);

  --text-main: hsl(220, 20%, 93%);
  --text-secondary: hsl(220, 15%, 62%);
  --text-muted: hsl(220, 10%, 42%);
  --text-inverse: hsl(225, 28%, 8%);

  --border: hsl(225, 18%, 20%);
  --border-subtle: hsl(225, 15%, 16%);
  --border-focus: var(--primary);

  --glass-bg: hsla(225, 22%, 13%, 0.75);
  --glass-border: hsla(220, 20%, 40%, 0.2);

  --shadow-xs: 0 1px 3px hsla(0,0%,0%,0.25);
  --shadow-sm: 0 2px 8px hsla(0,0%,0%,0.3);
  --shadow-md: 0 4px 20px hsla(0,0%,0%,0.35);
  --shadow-lg: 0 8px 40px hsla(0,0%,0%,0.45);

  --cell-empty: hsl(225, 18%, 16%);
  --cell-border: hsl(225, 15%, 24%);
  --cell-filled-a: hsl(210, 75%, 48%);
  --cell-filled-a-light: hsl(210, 75%, 62%);
  --cell-filled-b: hsl(275, 65%, 52%);
  --cell-filled-b-light: hsl(275, 60%, 68%);
  --cell-highlight: hsl(50, 90%, 52%);
  --cell-pop: hsl(0, 75%, 52%);

  --code-bg: hsl(225, 25%, 10%);
  --code-line-active: hsla(210, 80%, 50%, 0.2);
  --code-line-active-border: hsl(210, 80%, 50%);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);

  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --sidebar-width: 250px;
  --left-panel-width: 320px;
}

/* ── Tema Claro ── */
body.light-theme {
  --bg-app: hsl(220, 25%, 96%);
  --bg-sidebar: hsl(220, 30%, 98%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-surface-alt: hsl(220, 20%, 96%);
  --bg-surface-hover: hsl(220, 20%, 92%);
  --bg-input: hsl(220, 20%, 95%);

  --text-main: hsl(225, 30%, 14%);
  --text-secondary: hsl(220, 15%, 45%);
  --text-muted: hsl(220, 10%, 60%);

  --border: hsl(220, 20%, 88%);
  --border-subtle: hsl(220, 18%, 92%);

  --glass-bg: hsla(0, 0%, 100%, 0.8);
  --glass-border: hsla(220, 20%, 70%, 0.25);

  --shadow-xs: 0 1px 3px hsla(220,20%,50%,0.08);
  --shadow-sm: 0 2px 8px hsla(220,20%,50%,0.1);
  --shadow-md: 0 4px 20px hsla(220,20%,50%,0.12);
  --shadow-lg: 0 8px 40px hsla(220,20%,50%,0.15);

  --cell-empty: hsl(220, 15%, 94%);
  --cell-border: hsl(220, 15%, 82%);

  --code-bg: hsl(220, 20%, 97%);
  --code-line-active: hsla(210, 80%, 50%, 0.12);
  --code-line-active-border: hsl(210, 80%, 50%);
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  transition: background var(--transition), color var(--transition);
}

h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.2;
}

button {
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition-fast);
}

input, select {
  font-family: var(--font-main);
  outline: none;
  transition: all var(--transition-fast);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ══════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: background var(--transition);
}

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header .logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.sidebar-header .logo-text {
  font-size: 1.15rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--accent-purple-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-header .logo-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  transition: height var(--transition);
}

.nav-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: hsla(220, 90%, 56%, 0.1);
  color: var(--primary-light);
  font-weight: 600;
}

.nav-item.active::before {
  height: 60%;
}

.nav-icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border-subtle);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  width: 100%;
  border: 1px solid var(--border-subtle);
}

.theme-toggle:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
  border-color: var(--border);
}

/* ══════════════════════════════════════
   MAIN LAYOUT
   ══════════════════════════════════════ */
.main-content {
  flex: 1;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Panel Izquierdo ── */
.left-panel {
  width: var(--left-panel-width);
  min-width: var(--left-panel-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition);
}

.panel-section {
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.panel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-section-header h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

/* ── Controles de Simulación ── */
.controls-panel {
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.controls-panel .section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}

.speed-control {
  margin-bottom: 10px;
}

.speed-control label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.speed-control label span {
  color: var(--primary-light);
  font-weight: 600;
  font-family: var(--font-code);
  font-size: 0.75rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 6px var(--primary-glow);
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.control-buttons {
  display: flex;
  gap: 6px;
}

.ctrl-btn {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  font-size: 1rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
  border-color: var(--border);
}

.ctrl-btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.ctrl-btn.primary:hover {
  background: var(--primary-light);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Visor de Pseudocódigo ── */
.pseudocode-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.code-viewer {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  background: var(--code-bg);
  font-family: var(--font-code);
  font-size: 0.76rem;
  line-height: 1.7;
  counter-reset: line-number;
}

.code-line {
  display: flex;
  padding: 1px 12px 1px 0;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.code-line:hover {
  background: hsla(220, 20%, 50%, 0.06);
}

.code-line.active {
  background: var(--code-line-active);
  border-left-color: var(--code-line-active-border);
}

.code-line-number {
  width: 36px;
  text-align: right;
  padding-right: 12px;
  color: var(--text-muted);
  user-select: none;
  flex-shrink: 0;
  font-size: 0.7rem;
}

.code-line-content {
  flex: 1;
  white-space: pre;
  color: var(--text-secondary);
}

.code-line.active .code-line-content {
  color: var(--text-main);
  font-weight: 500;
}

/* Keywords highlight */
.kw { color: hsl(210, 80%, 65%); font-weight: 600; }
.str { color: hsl(120, 50%, 60%); }
.op { color: hsl(30, 90%, 65%); }
.cm { color: var(--text-muted); font-style: italic; }
.fn { color: hsl(50, 80%, 60%); }
.var { color: hsl(340, 65%, 70%); }

/* ── Consola de Eventos ── */
.console-panel {
  height: 180px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.console-output {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  background: var(--code-bg);
  font-family: var(--font-code);
  font-size: 0.72rem;
  line-height: 1.65;
}

.console-line {
  padding: 2px 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.console-line::before {
  content: '›';
  color: var(--text-muted);
  flex-shrink: 0;
  font-weight: 700;
}

.console-line.info { color: var(--accent-cyan); }
.console-line.info::before { content: 'ℹ'; color: var(--accent-cyan); }

.console-line.success { color: var(--accent-green-light); }
.console-line.success::before { content: '✓'; color: var(--accent-green); }

.console-line.warn { color: var(--accent-yellow); }
.console-line.warn::before { content: '⚠'; color: var(--accent-yellow); }

.console-line.error { color: var(--accent-red); }
.console-line.error::before { content: '✗'; color: var(--accent-red); }

.console-line.step { color: var(--text-secondary); }
.console-line.step::before { content: '→'; color: var(--primary-light); }

/* ══════════════════════════════════════
   PANEL DERECHO — VISUALIZACIÓN
   ══════════════════════════════════════ */
.right-panel {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg-app);
  transition: background var(--transition);
}

.module-view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.module-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.module-header {
  margin-bottom: 24px;
}

.module-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--text-main), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.module-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Tarjeta de Controles ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

.card + .card {
  margin-top: 16px;
}

.card-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .badge {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: hsla(220, 90%, 56%, 0.15);
  color: var(--primary-light);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Form Controls ── */
.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

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

.form-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: var(--font-code);
  width: 100%;
  min-width: 0;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* ── Botones de Acción ── */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.btn-push {
  background: linear-gradient(135deg, var(--accent-green), hsl(160, 70%, 34%));
  color: white;
  box-shadow: 0 2px 8px hsla(160, 84%, 39%, 0.3);
}
.btn-push:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px hsla(160, 84%, 39%, 0.45);
}

.btn-pop {
  background: linear-gradient(135deg, var(--accent-red), hsl(0, 70%, 45%));
  color: white;
  box-shadow: 0 2px 8px hsla(0, 78%, 55%, 0.3);
}
.btn-pop:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px hsla(0, 78%, 55%, 0.45);
}

.btn-secondary {
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

.btn-copy {
  padding: 5px 10px;
  font-size: 0.72rem;
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-code);
}
.btn-copy:hover {
  color: var(--primary-light);
  border-color: var(--primary);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ══════════════════════════════════════
   PILA VISUAL (VERTICAL)
   ══════════════════════════════════════ */
.stack-container {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  padding: 30px 20px;
  min-height: 380px;
  position: relative;
}

.stack-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  position: relative;
}

.stack-visual {
  display: flex;
  flex-direction: column-reverse;
  gap: 0;
  position: relative;
}

.stack-cell {
  width: 80px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--cell-border);
  background: var(--cell-empty);
  font-family: var(--font-code);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  position: relative;
  transition: all var(--transition);
}

.stack-cell:first-child {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.stack-cell:last-child {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.stack-cell + .stack-cell {
  border-top: none;
}

.stack-cell.filled {
  background: linear-gradient(135deg, var(--cell-filled-a), var(--cell-filled-a-light));
  color: white;
  border-color: hsl(210, 70%, 42%);
  box-shadow: inset 0 1px 0 hsla(0,0%,100%,0.15);
}

.stack-cell.filled-b {
  background: linear-gradient(135deg, var(--cell-filled-b), var(--cell-filled-b-light));
  border-color: hsl(275, 55%, 44%);
}

/* Index labels */
.stack-indices {
  display: flex;
  flex-direction: column-reverse;
  gap: 0;
}

.stack-index {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-code);
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 24px;
}

/* Pointer arrows */
.stack-pointers {
  display: flex;
  flex-direction: column-reverse;
  gap: 0;
  position: relative;
}

.pointer-indicator {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: bottom var(--transition-slow);
  white-space: nowrap;
}

.pointer-indicator .arrow {
  font-size: 1.1rem;
  color: var(--accent-orange);
}

.pointer-indicator .label {
  font-family: var(--font-code);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--accent-orange);
  color: var(--text-inverse);
  box-shadow: var(--shadow-xs);
}

.pointer-indicator.tope .label {
  background: var(--accent-orange);
}

.pointer-indicator.fondo .label {
  background: var(--text-muted);
}

.pointer-indicator.tope-a .label {
  background: var(--cell-filled-a);
}

.pointer-indicator.tope-b .label {
  background: var(--cell-filled-b);
}

/* ══════════════════════════════════════
   PILA DOBLE (HORIZONTAL)
   ══════════════════════════════════════ */
.double-stack-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 30px 10px;
}

.double-stack-array {
  display: flex;
  gap: 0;
  position: relative;
}

.ds-cell {
  width: 56px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--cell-border);
  background: var(--cell-empty);
  font-family: var(--font-code);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  position: relative;
  transition: all var(--transition);
}

.ds-cell + .ds-cell {
  border-left: none;
}

.ds-cell:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.ds-cell:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.ds-cell.filled-a {
  background: linear-gradient(180deg, var(--cell-filled-a), var(--cell-filled-a-light));
  color: white;
  border-color: hsl(210, 70%, 42%);
}

.ds-cell.filled-b {
  background: linear-gradient(180deg, var(--cell-filled-b), var(--cell-filled-b-light));
  color: white;
  border-color: hsl(275, 55%, 44%);
}

.ds-indices {
  display: flex;
  gap: 0;
}

.ds-index {
  width: 56px;
  text-align: center;
  font-family: var(--font-code);
  font-size: 0.68rem;
  color: var(--text-muted);
  padding-top: 4px;
}

.ds-pointers {
  display: flex;
  gap: 0;
  position: relative;
  height: 30px;
}

.ds-pointer {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: left var(--transition-slow);
}

.ds-pointer .arrow {
  font-size: 1rem;
}

.ds-pointer .label {
  font-family: var(--font-code);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  color: white;
}

.ds-pointer.ptr-a .arrow { color: var(--cell-filled-a); }
.ds-pointer.ptr-a .label { background: var(--cell-filled-a); }
.ds-pointer.ptr-b .arrow { color: var(--cell-filled-b); }
.ds-pointer.ptr-b .label { background: var(--cell-filled-b); }

.ds-controls-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  width: 100%;
}

.ds-control-panel {
  flex: 1;
  max-width: 260px;
}

.ds-control-panel .panel-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  text-align: center;
}

.ds-control-panel.panel-a .panel-label { color: var(--cell-filled-a-light); }
.ds-control-panel.panel-b .panel-label { color: var(--cell-filled-b-light); }

/* ══════════════════════════════════════
   NOTACIÓN POLACA
   ══════════════════════════════════════ */
.polish-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.triple-display {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: stretch;
}

.tape {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.tape-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
}

.tape-cells {
  display: flex;
  gap: 0;
  justify-content: center;
  flex-wrap: wrap;
}

.tape-cell {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--cell-border);
  background: var(--cell-empty);
  font-family: var(--font-code);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.tape-cell + .tape-cell {
  border-left: none;
}

.tape-cell:first-child {
  border-radius: var(--radius-xs) 0 0 var(--radius-xs);
}

.tape-cell:last-child {
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.tape-cell.cursor {
  background: var(--primary);
  color: white;
  border-color: var(--primary-dark);
  box-shadow: 0 0 12px var(--primary-glow);
  transform: scale(1.08);
  z-index: 2;
}

.tape-cell.processed {
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  opacity: 0.5;
}

.tape-cell.output-filled {
  background: var(--accent-green);
  color: white;
  border-color: hsl(160, 70%, 32%);
}

.operator-stack-panel {
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Expresiones Predefinidas ── */
.preset-expressions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ── Panel Flotante de Operación ── */
.operation-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 24px 32px;
  box-shadow: var(--shadow-lg), 0 0 40px var(--primary-glow);
  z-index: 1000;
  text-align: center;
  animation: popupIn 0.3s ease;
}

.operation-popup .op-expression {
  font-family: var(--font-code);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.operation-popup .op-result {
  font-family: var(--font-code);
  font-size: 1.1rem;
  color: var(--accent-green-light);
}

.operation-popup-overlay {
  position: fixed;
  inset: 0;
  background: hsla(0,0%,0%,0.4);
  z-index: 999;
}

@keyframes popupIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ══════════════════════════════════════
   CASOS DE ESTUDIO
   ══════════════════════════════════════ */
.case-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.case-structure {
  flex: 1;
}

.queue-visual {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
}

.queue-cell {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--cell-border);
  background: var(--cell-empty);
  font-family: var(--font-code);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.queue-cell.filled {
  background: linear-gradient(135deg, hsl(160, 70%, 40%), hsl(160, 60%, 55%));
  color: white;
  border-color: hsl(160, 60%, 32%);
}

.counter-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--primary), var(--accent-purple));
  color: white;
  font-family: var(--font-code);
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.counter-badge .count-value {
  font-size: 1.2rem;
}

/* ── Tabla de Reportes ── */
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 16px;
}

.report-table th {
  background: var(--bg-surface-alt);
  padding: 10px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.report-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-code);
  color: var(--text-secondary);
}

.report-table tr:hover td {
  background: var(--bg-surface-hover);
}

.report-table .highlight-row td {
  background: hsla(220, 90%, 56%, 0.12);
  color: var(--primary-light);
  font-weight: 700;
  border-color: var(--primary);
}

.report-table .highlight-row {
  box-shadow: inset 3px 0 0 var(--primary);
}

/* ── Conditional Panel ── */
.condition-panel {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-family: var(--font-code);
  font-size: 0.78rem;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-top: 12px;
}

.condition-panel .cond-active {
  background: var(--code-line-active);
  border-left: 3px solid var(--code-line-active-border);
  padding-left: 8px;
  color: var(--text-main);
  font-weight: 600;
}

/* ── Sub-module Tabs ── */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-surface-alt);
  padding: 4px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.sub-tab {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.sub-tab:hover {
  color: var(--text-main);
}

.sub-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-xs);
}

.sub-view {
  display: none;
}

.sub-view.active {
  display: block;
}

/* Case tabs */
.case-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-surface-alt);
  padding: 4px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.case-tab {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.case-tab:hover {
  color: var(--text-main);
}

.case-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-xs);
}

.case-view {
  display: none;
}

.case-view.active {
  display: block;
}

/* ══════════════════════════════════════
   ANIMACIONES
   ══════════════════════════════════════ */

/* Push: entrada con rebote */
@keyframes pushIn {
  0% { opacity: 0; transform: translateY(-30px) scale(0.8); }
  60% { opacity: 1; transform: translateY(4px) scale(1.05); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.stack-cell.push-anim {
  animation: pushIn 0.45s ease forwards;
}

/* Pop: parpadeo y salida */
@keyframes popOut {
  0% { opacity: 1; transform: scale(1); }
  25% { opacity: 0.3; background: var(--cell-pop); }
  50% { opacity: 1; background: var(--cell-pop); }
  75% { opacity: 0.3; }
  100% { opacity: 0; transform: translateY(-20px) scale(0.7); }
}

.stack-cell.pop-anim {
  animation: popOut 0.55s ease forwards;
}

/* Highlight */
@keyframes cellHighlight {
  0% { box-shadow: 0 0 0 0 var(--accent-yellow-glow); }
  50% { box-shadow: 0 0 16px 4px var(--accent-yellow-glow); }
  100% { box-shadow: 0 0 0 0 var(--accent-yellow-glow); }
}

.stack-cell.highlight,
.ds-cell.highlight,
.tape-cell.highlight {
  animation: cellHighlight 0.6s ease;
}

/* Error shake */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
}

.shake {
  animation: shake 0.5s ease;
}

/* Overflow blink */
@keyframes overflowBlink {
  0%, 100% { border-color: var(--accent-red); box-shadow: 0 0 0 0 var(--accent-red-glow); }
  50% { border-color: var(--accent-red); box-shadow: 0 0 20px 4px var(--accent-red-glow); }
}

.overflow-alert {
  animation: overflowBlink 0.6s ease 3;
}

/* Underflow blink */
@keyframes underflowBlink {
  0%, 100% { border-color: var(--accent-yellow); box-shadow: 0 0 0 0 var(--accent-yellow-glow); }
  50% { border-color: var(--accent-yellow); box-shadow: 0 0 20px 4px var(--accent-yellow-glow); }
}

.underflow-alert {
  animation: underflowBlink 0.6s ease 3;
}

/* Float up (for pop extraction in polish) */
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}

.float-up {
  animation: floatUp 0.4s ease forwards;
}

/* Float down (for push result in polish) */
@keyframes floatDown {
  0% { opacity: 0; transform: translateY(-30px); }
  100% { opacity: 1; transform: translateY(0); }
}

.float-down {
  animation: floatDown 0.4s ease forwards;
}

/* Pulse for counters and highlights */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.pulse {
  animation: pulse 0.5s ease;
}

/* ── Alert Toast ── */
.alert-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: toastIn 0.4s ease, toastOut 0.4s ease 2.5s forwards;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-toast.error {
  background: linear-gradient(135deg, hsl(0, 70%, 48%), hsl(0, 65%, 40%));
  border: 1px solid hsl(0, 70%, 55%);
}

.alert-toast.warning {
  background: linear-gradient(135deg, hsl(45, 85%, 45%), hsl(35, 80%, 40%));
  border: 1px solid hsl(45, 85%, 52%);
}

.alert-toast.success {
  background: linear-gradient(135deg, hsl(160, 70%, 36%), hsl(160, 65%, 30%));
  border: 1px solid hsl(160, 70%, 44%);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ── Variable Display ── */
.var-display {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.var-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-xl);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  font-family: var(--font-code);
  font-size: 0.76rem;
}

.var-chip .var-name {
  color: var(--text-muted);
  font-weight: 600;
}

.var-chip .var-value {
  color: var(--accent-cyan);
  font-weight: 700;
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 1200px) {
  :root {
    --sidebar-width: 200px;
    --left-panel-width: 280px;
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-width: 60px;
    --left-panel-width: 260px;
  }
  .nav-item span:not(.nav-icon) {
    display: none;
  }
  .sidebar-header .logo-text,
  .sidebar-header .logo-sub {
    display: none;
  }
  .theme-toggle span {
    display: none;
  }
}
