/* ==========================================================================
   ESP32 Lab - Estilos Profesionales en Modo Oscuro (Dark Theme)
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Fondos oscuros de alta fidelidad */
  --bg-app: #0c1017;
  --bg-surface: #141b28;
  --bg-surface-elevated: #1a2336;
  --bg-surface-hover: #222d45;
  --bg-canvas: #090d14;

  /* Bordes sutiles */
  --border-color: #212c40;
  --border-subtle: #192233;
  --border-focus: #7c3aed;

  /* Tipografía */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Acentos Púrpura / Índigo */
  --accent-purple: #7c3aed;
  --accent-purple-light: #8b5cf6;
  --accent-purple-glow: rgba(124, 58, 237, 0.4);
  --accent-purple-bg: rgba(124, 58, 237, 0.16);

  /* Colores de estado */
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --cyan: #06b6d4;

  /* Tamaño ajustable del panel de código */
  --editor-width: 440px;

  /* Scrollbars */
  scrollbar-color: #27344d transparent;
  scrollbar-width: thin;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-app: #f4f6fa;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --bg-canvas: #f8fafc;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-purple: #6366f1;
  --accent-purple-light: #818cf8;
  --accent-purple-bg: rgba(99, 102, 241, 0.12);
  scrollbar-color: #cbd5e1 transparent;
}

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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   1. BARRA SUPERIOR (HEADER)
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.navbar {
  height: 54px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.25rem;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-mark {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-svg {
  width: 100%;
  height: 100%;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.brand-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Pestañas Centrales */
.nav-center-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background-color: var(--bg-app);
  padding: 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background-color: var(--accent-purple-bg);
  color: var(--accent-purple-light);
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.nav-tab.nav-btn-action {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-tab.nav-btn-action:hover {
  background-color: var(--accent-purple-bg);
  border-color: var(--accent-purple);
  color: var(--accent-purple-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.nav-tab.nav-btn-action:active {
  transform: translateY(0);
}

.tab-icon {
  font-size: 0.9rem;
}

/* Acciones Superiores */
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-run {
  background-color: var(--accent-purple);
  color: #ffffff;
  box-shadow: 0 0 12px var(--accent-purple-glow);
}

.btn-run:hover:not(:disabled) {
  background-color: #6d28d9;
  box-shadow: 0 0 18px rgba(124, 58, 237, 0.6);
  transform: translateY(-1px);
}

.btn-stop {
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-stop:hover:not(:disabled) {
  background-color: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
}

.btn-restart {
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border-color: var(--border-color);
  padding: 0.45rem 0.8rem;
}

.btn-restart:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

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

.btn-icon-nav {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}

.btn-icon-nav:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   2. WORKSPACE LAYOUT (3 COLUMNAS)
   -------------------------------------------------------------------------- */
.workspace-layout {
  display: grid;
  grid-template-columns: 240px 1fr 6px var(--editor-width, 440px);
  flex: 1;
  height: calc(100vh - 54px - 34px);
  overflow: hidden;
  position: relative;
}

/* Divisor interactivo para redimensionar el panel de código */
.panel-resizer {
  width: 6px;
  background-color: var(--border-color);
  cursor: col-resize;
  position: relative;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  z-index: 55;
  user-select: none;
}

.panel-resizer:hover,
.panel-resizer.is-resizing {
  background-color: var(--accent-purple);
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

.panel-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 36px;
  border-radius: 2px;
  background-color: rgba(255, 255, 255, 0.45);
}

/* --------------------------------------------------------------------------
   COLUMNA IZQUIERDA: MENÚ DE COMPONENTES
   -------------------------------------------------------------------------- */
.sidebar-components {
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 0.75rem 1rem 0.4rem;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.search-box {
  margin: 0.5rem 0.75rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0.35rem 0.6rem;
  gap: 0.4rem;
}

.search-icon {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.78rem;
  width: 100%;
}

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

/* Menú de Categorías */
.category-menu {
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0.5rem;
  gap: 0.2rem;
}

.cat-item {
  display: flex;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}

.cat-item:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.cat-item.active {
  background-color: var(--accent-purple-bg);
  color: var(--accent-purple-light);
  font-weight: 600;
}

.cat-icon {
  margin-right: 0.6rem;
  font-size: 0.95rem;
}

.cat-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-count-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.cat-item.active .cat-count-badge {
  background-color: var(--accent-purple);
  color: #ffffff;
  border-color: var(--accent-purple-light);
}

.cat-chevron {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Sub-panel de Componentes para Spawnear */
.component-items-drawer {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.65rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-app);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.spawn-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.spawn-chip-number {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent-purple-light);
  background: var(--accent-purple-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  border: 1px solid rgba(139, 92, 246, 0.3);
  font-family: monospace;
}

.spawn-chip:hover {
  border-color: var(--accent-purple);
  background-color: var(--bg-surface-elevated);
  transform: translateX(2px);
}

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   COLUMNA CENTRAL: LIENZO LIBRE DE HARDWARE
   -------------------------------------------------------------------------- */
.canvas-workspace {
  position: relative;
  background-color: var(--bg-canvas);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Barra de herramientas flotante */
.floating-toolbar {
  position: absolute;
  top: 12px;
  z-index: 50;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.toolbar-left { left: 14px; }
.toolbar-right { right: 14px; }

.tool-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 0.35rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.tool-btn.active {
  background-color: var(--accent-purple-bg);
  color: var(--accent-purple-light);
}

.toolbar-sep {
  width: 1px;
  height: 16px;
  background-color: var(--border-color);
  margin: 0 0.15rem;
}

.quick-wire-colors {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.25rem;
}

.wire-c-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.wire-c-dot:hover {
  transform: scale(1.15);
}

.wire-c-dot.active {
  border-color: #ffffff;
  transform: scale(1.25);
  box-shadow: 0 0 6px var(--accent-purple);
}

/* Escenario / Lienzo */
.canvas-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  user-select: none;
  background-image: radial-gradient(#202b3d 1.3px, transparent 1.3px);
  background-size: 24px 24px;
  cursor: grab;
  width: 100%;
  height: 100%;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 5000px;
  transform-origin: 0 0;
  pointer-events: auto;
}

.canvas-stage.is-panning {
  cursor: grabbing !important;
  user-select: none !important;
}

/* Espaciador para permitir desplazamiento libre y amplio por todo el lienzo */
.canvas-bounds-spacer {
  position: absolute;
  top: 0;
  left: 0;
  width: 5000px;
  height: 4000px;
  pointer-events: none;
  z-index: 1;
}

/* Capa SVG para Cables */
.wires-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 5000px;
  height: 4000px;
  pointer-events: none;
  z-index: 10;
}

.circuit-wire {
  fill: none;
  stroke-width: 4.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
  cursor: pointer;
  filter: url(#cableGlow);
  transition: stroke-width 0.15s ease, filter 0.15s ease;
}

.circuit-wire:hover {
  stroke-width: 7.5px;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.9));
}

.circuit-wire.selected {
  stroke-dasharray: 6, 6;
  stroke-width: 6.5px;
  animation: wireFlow 0.8s linear infinite;
  filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.9));
}

@keyframes wireFlow {
  to { stroke-dashoffset: -12; }
}

/* Manivelas de ajuste y codos ordenados de cables */
.wire-handle {
  fill: #0c1017;
  stroke: #38bdf8;
  stroke-width: 2.5px;
  cursor: grab;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
  transition: transform 0.1s ease, fill 0.15s ease;
  pointer-events: all;
}

.wire-handle:hover {
  fill: #38bdf8;
  stroke: #ffffff;
  transform: scale(1.4);
  cursor: grab;
}

.wire-handle.is-dragging {
  fill: #f59e0b;
  stroke: #ffffff;
  stroke-width: 3px;
  transform: scale(1.6);
  cursor: grabbing;
}

.wire-handle-dot {
  fill: #ffffff;
  pointer-events: none;
}

.temp-wire-live {
  fill: none;
  stroke-width: 3.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 5, 5;
  animation: wireFlow 0.4s linear infinite;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   COMPONENTES DIRECTOS EN EL LIENZO
   -------------------------------------------------------------------------- */
.canvas-item {
  position: absolute;
  z-index: 20;
  cursor: grab;
  transition: filter 0.2s ease, transform 0.1s ease;
}

.canvas-item:active {
  cursor: grabbing;
}

.canvas-item.is-dragging {
  z-index: 40;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.6));
}

/* --------------------------------------------------------------------------
   CHASIS Y REGLAS DE PINES ESP32 DE ALTA PRECISIÓN
   -------------------------------------------------------------------------- */
.esp32-board-carrier {
  display: flex;
  align-items: center;
  background: #0b0f19;
  border: 1.5px solid #1e293b;
  border-radius: 12px;
  padding: 6px 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75), 0 0 1px rgba(255, 255, 255, 0.12);
  user-select: none;
  cursor: grab;
  z-index: 30;
}

.esp32-board-carrier.is-dragging {
  cursor: grabbing;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.9), 0 0 0 2px var(--accent-purple);
}

.esp32-visual-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.6));
  pointer-events: none;
}

.esp32-visual-wrapper wokwi-esp32-devkit-v1 {
  display: block;
}

/* Rieles de Pines Izquierda y Derecha */
.esp-header-rail {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  min-height: 360px;
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 6px 3px;
  box-sizing: border-box;
}

.rail-left {
  margin-right: 6px;
}

.rail-right {
  margin-left: 6px;
}

/* Fila de cada Pin: 100% fija y estable */
.pin-pad {
  display: flex;
  align-items: center;
  height: 22px;
  padding: 0 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.12s ease;
  position: relative;
  box-sizing: border-box;
}

.rail-left .pin-pad {
  justify-content: flex-end;
  gap: 7px;
}

.rail-right .pin-pad {
  justify-content: flex-start;
  gap: 7px;
}

/* Etiquetas de Texto Monospace de Ancho Fijo */
.pin-lbl {
  font-family: 'Fira Code', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  color: #64748b;
  width: 28px;
  letter-spacing: -0.2px;
  transition: color 0.12s ease;
  pointer-events: none;
}

.rail-left .pin-lbl {
  text-align: right;
}

.rail-right .pin-lbl {
  text-align: left;
}

/* Sockets de Pines Metálicos - Cero Jitter, Cero Transform Scale */
.pad-ring {
  width: 12px;
  height: 12px;
  min-width: 12px;
  min-height: 12px;
  max-width: 12px;
  max-height: 12px;
  border-radius: 50%;
  background: #f59e0b;
  border: 2px solid #b45309;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

/* Agujero central del socket */
.pad-ring::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #030712;
}

/* Categorías de Pines por Color */
.pad-ring.gnd { background: #475569; border-color: #1e293b; }
.pad-ring.vcc { background: #ef4444; border-color: #991b1b; }
.pad-ring.adc { background: #06b6d4; border-color: #0e7490; }
.pad-ring.dac { background: #8b5cf6; border-color: #6d28d9; }
.pad-ring.uart { background: #f97316; border-color: #c2410c; }

.pin-vcc .pin-lbl { color: #f87171; }
.pin-gnd .pin-lbl { color: #94a3b8; }
.pin-adc .pin-lbl { color: #38bdf8; }
.pin-dac .pin-lbl { color: #c084fc; }
.pin-uart .pin-lbl { color: #fb923c; }

/* Hover Estable: NO modifica dimensiones, solo emite resplandor nítido */
.pin-pad:hover {
  background-color: #1e293b;
}

.pin-pad:hover .pin-lbl {
  color: #ffffff;
}

.pin-pad:hover .pad-ring {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.4), 0 0 10px #38bdf8 !important;
}

/* Pin con cable activo conectado o en trazado */
.pin-pad.wire-active {
  background-color: rgba(168, 85, 247, 0.25) !important;
}

.pin-pad.wire-active .pad-ring {
  background: #a855f7 !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.5), 0 0 14px #a855f7 !important;
}

.pin-pad.wire-active .pin-lbl {
  color: #d8b4fe !important;
  font-weight: 700;
}

/* Rieles de Pines en Componentes Libres (LED, Botón, etc.) */
.component-pads-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  background-color: #090d16;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #1e293b;
}

.component-pads-row .pin-pad {
  height: 24px;
  padding: 2px 6px;
  gap: 6px;
  border-radius: 4px;
  background-color: transparent;
}

.component-pads-row .pin-pad span {
  font-family: 'Fira Code', monospace;
  font-size: 0.66rem;
  font-weight: 600;
  color: #94a3b8;
}

.component-pads-row .pin-pad:hover {
  background-color: #1e293b;
}

.component-pads-row .pin-pad:hover span {
  color: #ffffff;
}

/* Componente LED Libre */
.canvas-led-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.led-visual-glow {
  transition: filter 0.2s ease;
}

.led-visual-glow.active {
  filter: drop-shadow(0 0 18px #3b82f6) drop-shadow(0 0 35px #2563eb);
}

.led-visual-glow.active-red {
  filter: drop-shadow(0 0 18px #ef4444) drop-shadow(0 0 35px #dc2626);
}

.led-visual-glow.active-green {
  filter: drop-shadow(0 0 18px #10b981) drop-shadow(0 0 35px #059669);
}

.led-visual-glow.active-yellow {
  filter: drop-shadow(0 0 18px #f59e0b) drop-shadow(0 0 35px #d97706);
}

.component-pads-row {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.2rem;
}

/* Pulsador Libre */
.canvas-button-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(20, 27, 40, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.4rem;
}

/* Resistencia Libre */
.canvas-resistor-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Módulo Display / Sensores */
.canvas-display-item,
.canvas-sensor-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(18, 24, 38, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.sensor-control-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  width: 100%;
}

.sensor-slider {
  flex: 1;
  accent-color: var(--accent-purple);
  cursor: pointer;
}

/* Botón flotante para borrar componente */
.btn-delete-node {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  border: none;
  font-size: 0.65rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  transition: transform 0.15s ease;
}

.btn-delete-node:hover {
  transform: scale(1.2);
}

/* Botón flotante para configurar componente */
.btn-config-node {
  position: absolute;
  top: -8px;
  right: 14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  border: none;
  font-size: 0.65rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn-config-node:hover {
  background: #2563eb;
  transform: scale(1.2);
}

.canvas-item:hover .btn-delete-node,
.canvas-item:hover .btn-config-node {
  display: flex;
}

/* Wrapper de pulsador con respuesta activa física */
.button-wrapper {
  position: relative;
  border-radius: 50%;
  transition: all 0.15s ease;
}

.button-wrapper.btn-pressed-active {
  box-shadow: 0 0 0 3px #ef4444, 0 0 16px rgba(239, 68, 68, 0.7);
  transform: scale(0.95);
}

/* Pin pad activo cuando un GPIO está en HIGH (3.3V) */
.pin-pad.pin-pad-active-high .pad-ring {
  box-shadow: 0 0 10px #38bdf8, 0 0 18px #0284c7;
  border-color: #38bdf8;
  background-color: #0284c7;
}

/* Modal de Configuración y Propiedades de Componentes */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeInModal 0.15s ease-out;
}

@keyframes fadeInModal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.config-modal-card {
  width: 90%;
  max-width: 480px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 14px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  animation: scaleInModal 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleInModal {
  from { transform: scale(0.95); opacity: 0.5; }
  to { transform: scale(1); opacity: 1; }
}

.config-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: #162032;
  border-bottom: 1px solid #1f293d;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.modal-icon {
  font-size: 1.5rem;
  background: rgba(59, 130, 246, 0.15);
  padding: 0.35rem;
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f1f5f9;
  margin: 0;
}

.modal-subtitle {
  font-size: 0.75rem;
  color: #94a3b8;
  margin: 0.15rem 0 0 0;
  font-family: 'Fira Code', monospace;
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.btn-modal-close:hover {
  background: #1f293d;
  color: #ffffff;
}

.config-modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 65vh;
  overflow-y: auto;
}

.config-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.config-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.config-input,
.config-select {
  background: #0b0f19;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f8fafc;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.config-input:focus,
.config-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.config-presets-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.preset-chip {
  background: #1e293b;
  border: 1px solid #334155;
  color: #94a3b8;
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.preset-chip:hover,
.preset-chip.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}

.color-swatches {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.color-swatch-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch-btn:hover {
  transform: scale(1.15);
}

.color-swatch-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px #3b82f6;
}

.config-modal-footer {
  padding: 0.85rem 1.25rem;
  background: #162032;
  border-top: 1px solid #1f293d;
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

/* Popover rápido de cables */
.wire-quick-popover {
  position: absolute;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  z-index: 999;
  animation: fadeInModal 0.12s ease-out;
}

.popover-label {
  font-size: 0.72rem;
  color: #94a3b8;
}

.popover-colors {
  display: flex;
  gap: 0.35rem;
}

.wire-pop-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
}

.wire-pop-dot:hover {
  transform: scale(1.25);
}

.btn-pop-delete {
  background: transparent;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0 0.2rem;
}

/* --------------------------------------------------------------------------
   COLUMNA DERECHA: CÓDIGO + INSPECTOR CPU XTENSA + MONITOR SERIAL
   -------------------------------------------------------------------------- */
.sidebar-editor {
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-card,
.terminal-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-card {
  flex: 1.25;
  border-bottom: 1px solid var(--border-color);
}

.card-bar {
  height: 38px;
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.85rem;
}

.card-tab-switch {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background-color: var(--bg-app);
  padding: 0.15rem;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

.sub-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.sub-tab-btn.active {
  background-color: var(--accent-purple-bg);
  color: var(--accent-purple-light);
  font-weight: 700;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.lang-selector select,
.baud-select {
  background-color: var(--bg-app);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 0.76rem;
  outline: none;
  cursor: pointer;
}

.lang-selector select:focus,
.baud-select:focus {
  border-color: var(--accent-purple);
}

/* =============================================================================
   Barra de Pestañas y Explorador Multi-archivo de Proyectos (sketch.ino, .h, .cpp)
   ============================================================================= */
.project-files-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #0d121f;
  border-bottom: 1px solid var(--border-color);
  padding: 0.25rem 0.6rem 0 0.6rem;
  overflow-x: auto;
  min-height: 34px;
}

.project-tabs-list {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.project-tabs-list::-webkit-scrollbar {
  display: none;
}

.project-file-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.74rem;
  color: #94a3b8;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.project-file-tab:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

.project-file-tab.active {
  background-color: #0b0f17;
  color: #38bdf8;
  border-color: var(--border-color);
  border-bottom: 1px solid #0b0f17;
  font-weight: 600;
  box-shadow: 0 -2px 0 0 #38bdf8 inset;
}

.tab-file-icon {
  font-size: 0.8rem;
  opacity: 0.85;
}

.tab-file-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-file-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 0.25rem;
  font-size: 0.85rem;
  line-height: 1;
  color: #64748b;
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.tab-file-close:hover {
  background-color: rgba(239, 68, 68, 0.25);
  color: #ef4444;
}

.project-file-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

.btn-new-file {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #c084fc;
  background-color: rgba(168, 85, 247, 0.14);
  border: 1px solid rgba(168, 85, 247, 0.28);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-new-file:hover {
  background-color: rgba(168, 85, 247, 0.25);
  border-color: rgba(168, 85, 247, 0.5);
  color: #e9d5ff;
}

/* Editor con Números de Línea */
.code-view-container {
  flex: 1;
  display: flex;
  background-color: #0b0f17;
  overflow: hidden;
}

.line-numbers {
  width: 38px;
  padding: 0.75rem 0.5rem 0.75rem 0;
  text-align: right;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #475569;
  user-select: none;
  border-right: 1px solid var(--border-subtle);
  background-color: #0a0d14;
}

#codeEditor {
  flex: 1;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: #38bdf8;
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.5;
  padding: 0.75rem 0.85rem;
  resize: none;
  tab-size: 2;
  white-space: pre;
}

/* Inspector del Procesador Xtensa LX6 */
.cpu-inspector-view {
  flex: 1;
  background-color: #080c14;
  padding: 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-family: 'Fira Code', monospace;
}

.cpu-status-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
}

.cpu-stat .lbl {
  color: var(--text-muted);
}

.cpu-stat .val {
  color: var(--text-primary);
}

.val-hex {
  color: var(--accent-purple-light);
}

.cpu-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cpu-inst-box {
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #38bdf8;
  border-left: 3px solid var(--accent-purple);
}

.registers-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.reg-cell {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.25rem 0.35rem;
  font-size: 0.68rem;
  display: flex;
  flex-direction: column;
}

.reg-name {
  color: #f59e0b;
  font-weight: bold;
}

.reg-val {
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bus-traffic-box {
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.65rem;
  border-radius: 5px;
  font-size: 0.74rem;
  color: #a855f7;
}

/* Monitor Serial */
.terminal-card {
  flex: 0.95;
}

.terminal-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon-subtle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.btn-icon-subtle:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.terminal-body {
  flex: 1;
  background-color: #080c14;
  padding: 0.65rem 0.85rem;
  overflow-y: auto;
  font-family: 'Fira Code', monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #4ade80;
  word-break: break-all;
}

.log-entry.log-sys { color: #94a3b8; font-style: italic; }
.log-entry.log-boot { color: #a855f7; font-family: monospace; }
.log-entry.log-err { color: #f87171; font-weight: 600; }
.log-entry.log-in { color: #38bdf8; font-weight: 600; }

.terminal-send-row {
  height: 38px;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-color);
  display: flex;
  padding: 0.35rem 0.65rem;
  gap: 0.4rem;
  align-items: center;
}

#terminalInput {
  flex: 1;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-primary);
  outline: none;
}

#terminalInput:focus {
  border-color: var(--accent-purple);
}

.btn-send {
  background-color: var(--accent-purple);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s ease;
}

.btn-send:hover {
  background-color: #6d28d9;
}

/* --------------------------------------------------------------------------
   3. BARRA INFERIOR DE ESTADO
   -------------------------------------------------------------------------- */
.bottom-bar {
  height: 34px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.25rem;
  font-size: 0.74rem;
  color: var(--text-secondary);
  z-index: 60;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.live-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #64748b;
  transition: all 0.3s ease;
}

.live-status-dot.active {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 1.5s infinite;
}

.cpu-freq-badge {
  font-family: 'Fira Code', monospace;
  font-size: 0.68rem;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.status-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.status-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.status-btn:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
}

.zoom-pill {
  display: flex;
  align-items: center;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
  gap: 0.35rem;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.2rem;
}

.zoom-value {
  font-size: 0.72rem;
  font-weight: 600;
  min-width: 34px;
  text-align: center;
}

/* ==========================================================================
   VISTA DE SERVIDOR WEB ESP32 (NAVEGADOR IOT SIMULADO)
   ========================================================================== */
.web-preview-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: #090d16;
  overflow: hidden;
}

.browser-address-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #131b2e;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.browser-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  flex-shrink: 0;
}

.browser-status-dot.online {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.browser-address-bar input {
  flex: 1;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: #38bdf8;
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  outline: none;
}

.btn-browser-tool {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.25rem;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.btn-browser-tool:hover {
  background: #1e293b;
  color: #ffffff;
}

.browser-quick-links {
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  background: #0d1322;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.web-link-chip {
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-size: 0.68rem;
  font-family: 'Fira Code', monospace;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.web-link-chip:hover {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}

.browser-page-viewport {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  background: #ffffff;
  color: #0f172a;
  min-height: 200px;
}

.web-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #64748b;
  padding: 1.5rem;
}

.web-empty-state h4 {
  margin: 0.5rem 0 0.25rem 0;
  color: #1e293b;
}

.web-empty-state p {
  font-size: 0.8rem;
  max-width: 320px;
  line-height: 1.4;
}

/* Botón disparador de sensor PIR */
.btn-pir-trigger {
  background: #1e293b;
  border: 1px solid #334155;
  color: #38bdf8;
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  margin-top: 0.25rem;
  transition: all 0.15s ease;
}

.btn-pir-trigger:hover,
.btn-pir-trigger.active {
  background: #10b981;
  border-color: #10b981;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.slide-switch-wrapper {
  padding: 0.25rem;
  cursor: pointer;
}

/* ==========================================================================
   CATÁLOGO COMPLETO DE 100 COMPONENTES - TARJETAS Y MÓDULOS DE HARDWARE
   ========================================================================== */
.hw-module-card {
  background: linear-gradient(145deg, #0d1322, #070a12);
  border: 1.5px solid #1e293b;
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 150px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  user-select: none;
  cursor: grab;
  transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-sizing: border-box;
}

.hw-module-card:hover {
  border-color: #38bdf8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.85), 0 0 14px rgba(56, 189, 248, 0.25);
}

.hw-module-card.is-dragging {
  cursor: grabbing;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.95), 0 0 0 2px var(--accent-purple);
}

.hw-module-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px solid #1e293b;
  padding-bottom: 4px;
}

.hw-module-title-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
}

.hw-module-icon {
  font-size: 0.95rem;
}

.hw-module-num {
  font-size: 0.62rem;
  font-weight: 700;
  color: #a855f7;
  background: rgba(168, 85, 247, 0.15);
  padding: 1px 4px;
  border-radius: 4px;
  font-family: monospace;
}

.hw-module-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.hw-module-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-code-node {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: #38bdf8;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-code-node:hover {
  background: #0284c7;
  color: #ffffff;
}

.hw-module-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6rem;
  font-family: 'Fira Code', monospace;
  margin-top: 1px;
}

.badge-volt {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 700;
}

.badge-proto {
  background: rgba(14, 165, 233, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(14, 165, 233, 0.3);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 700;
}

.hw-module-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  gap: 4px;
  min-height: 40px;
}

.hw-module-chip {
  background: #030712;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: #94a3b8;
  font-family: monospace;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
  width: 100%;
  box-sizing: border-box;
}

.hw-module-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  flex-shrink: 0;
}

.hw-module-screen {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 4px;
  padding: 6px;
  font-family: monospace;
  font-size: 0.68rem;
  color: #38bdf8;
  text-align: center;
  min-width: 110px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
  width: 100%;
  box-sizing: border-box;
}

/* ==========================================================================
   PANTALLAS Y DISPLAYS ELECTRÓNICOS REALISTAS (11-21)
   ========================================================================== */
.hw-screen-frame {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.screen-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.62rem;
  font-family: 'Fira Code', monospace;
  padding: 2px 4px;
  box-sizing: border-box;
}

.screen-chip-tag {
  color: #38bdf8;
  font-weight: 700;
}

.screen-res-tag {
  color: #94a3b8;
}

/* Wokwi Element Display Styles */
wokwi-lcd1602, wokwi-lcd2004 {
  display: block;
  max-width: 100%;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

wokwi-ssd1306 {
  display: block;
  max-width: 100%;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

wokwi-ili9341 {
  display: block;
  max-width: 100%;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

wokwi-7segment {
  display: block;
  max-width: 100%;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

/* OLED SSD1306 (13) & SH1106 (14) */
.oled-frame {
  min-width: 175px;
}

.oled-bezel {
  background: #020617;
  border: 2px solid #0f172a;
  border-radius: 6px;
  padding: 6px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.95), 0 2px 6px rgba(0, 0, 0, 0.6);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

.oled-glass {
  background: #000000;
  border: 1px solid #1e293b;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
}

.oled-canvas {
  display: block;
  width: 160px;
  height: 80px;
  background: #000000;
  image-rendering: pixelated;
}

/* LCD 1602 (15) & LCD 2004 (16) */
.lcd-frame {
  min-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lcd-bezel {
  background: #0b1329;
  border: 3px solid #1e293b;
  border-radius: 8px;
  padding: 8px;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.9), 0 4px 10px rgba(0, 0, 0, 0.5);
  width: 100%;
  box-sizing: border-box;
}

.lcd-screen-inner {
  border-radius: 4px;
  padding: 6px 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.74rem;
  letter-spacing: 1.2px;
  line-height: 1.45;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.85);
  user-select: none;
}

.lcd-blue {
  background: #002e8a;
  color: #e0f2fe;
  text-shadow: 0 0 6px rgba(56, 189, 248, 0.85), 0 0 2px #ffffff;
}

.lcd-line {
  white-space: pre;
  font-weight: 700;
  overflow: hidden;
}

/* TFT ILI9341 (11) & ST7789 (12) */
.tft-frame {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tft-bezel {
  background: #881337;
  border: 2px solid #9f1239;
  border-radius: 8px;
  padding: 8px 8px 6px 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

.tft-canvas {
  background: #000000;
  border: 1.5px solid #000000;
  border-radius: 4px;
  display: block;
  width: 200px;
  height: 150px;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.9);
}

.st7789-frame {
  min-width: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.st7789-bezel {
  background: #0f172a;
  border: 2.5px solid #334155;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(0, 0, 0, 0.95);
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

.st7789-canvas {
  background: #000000;
  border-radius: 6px;
  display: block;
  width: 170px;
  height: 170px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
}

/* Display 7 Segmentos (17) & TM1637 (18) */
.sevenseg-frame, .tm1637-frame {
  min-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sevenseg-bezel, .tm1637-bezel {
  background: #050811;
  border: 2px solid #1e293b;
  border-radius: 6px;
  padding: 8px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.95);
  display: flex;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
}

.sevenseg-digits-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.seg-digit-svg {
  width: 30px;
  height: 50px;
}

.seg-colon-svg {
  width: 10px;
  height: 50px;
}

/* MAX7219 Matriz LED 8x8 (19) */
.matrix-frame {
  min-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.matrix-bezel {
  background: #090d16;
  border: 2.5px solid #1e293b;
  border-radius: 8px;
  padding: 8px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.95), 0 4px 12px rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
}

.matrix-grid-8x8 {
  display: grid;
  grid-template-columns: repeat(8, 14px);
  grid-template-rows: repeat(8, 14px);
  gap: 4px;
}

.matrix-led-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #18181b;
  border: 1px solid #27272a;
  transition: all 0.1s ease;
  cursor: pointer;
}

.matrix-led-dot.active {
  background: #ef4444;
  border-color: #f87171;
  box-shadow: 0 0 10px #ef4444, inset 0 0 4px #ffffff;
}

/* E-Ink / E-Paper (20) */
.eink-frame {
  min-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.eink-bezel {
  background: #cbd5e1;
  border: 2px solid #94a3b8;
  border-radius: 6px;
  padding: 6px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.2), 0 3px 8px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.eink-paper {
  background: #f8fafc;
  color: #0f172a;
  width: 190px;
  min-height: 90px;
  padding: 8px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  border: 1px solid #94a3b8;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.08);
}

.eink-title {
  font-size: 0.7rem;
  font-weight: 700;
  border-bottom: 1px solid #334155;
  padding-bottom: 2px;
}

.eink-temp {
  font-size: 1.25rem;
  font-weight: 900;
  text-align: center;
  margin: 4px 0;
}

.eink-details, .eink-battery {
  font-size: 0.62rem;
  color: #334155;
}

/* TFT Touch XPT2046 (21) */
.xpt-frame {
  min-width: 210px;
}

.xpt-bezel {
  position: relative;
  background: #1e1b4b;
  border: 2px solid #4338ca;
  border-radius: 8px;
  padding: 6px;
  display: flex;
  justify-content: center;
  cursor: crosshair;
}

.xpt-canvas {
  background: #000000;
  border-radius: 4px;
  display: block;
  width: 180px;
  height: 135px;
}

.xpt-touch-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #22c55e;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px #22c55e;
}

.hw-module-slider-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hw-module-slider-lbl {
  font-size: 0.65rem;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
}

.hw-module-slider {
  width: 100%;
  accent-color: #38bdf8;
  cursor: pointer;
}

.hw-module-trigger-btn {
  width: 100%;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hw-module-trigger-btn:hover {
  background: var(--accent-purple);
  color: #ffffff;
  border-color: var(--accent-purple-light);
}

.modal-code-preview-wrap {
  margin-top: 12px;
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: 8px;
  overflow: hidden;
}

.modal-code-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  font-size: 0.72rem;
  color: #94a3b8;
}

.modal-code-pre {
  margin: 0;
  padding: 10px;
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #e2e8f0;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.4;
  background: #070a12;
}

.btn-code-insert {
  background: #059669;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-code-insert:hover {
  background: #10b981;
}

.btn-code-copy {
  background: #334155;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.7rem;
  cursor: pointer;
}

.btn-code-copy:hover {
  background: #475569;
}

/* ==========================================================================
   SIMULACIÓN ELÉCTRICA: COMPONENTES QUEMADOS, HUMO Y CHISPAS
   ========================================================================== */

/* Estado de componente quemado / dañado */
.canvas-item.is-burned, .hw-module-card.is-burned {
  z-index: 50 !important;
  background: radial-gradient(circle at center, #261212 0%, #110505 100%) !important;
  border-color: #ef4444 !important;
  box-shadow: 0 0 18px 2px rgba(239, 68, 68, 0.75), inset 0 0 15px rgba(0, 0, 0, 0.9) !important;
  animation: burnShake 0.45s ease-in-out;
}

.canvas-item.is-burned wokwi-led,
.canvas-item.is-burned wokwi-rgb-led,
.canvas-item.is-burned .hw-module-title-wrap {
  filter: grayscale(0.8) brightness(0.55) sepia(0.4) contrast(1.2);
}

@keyframes burnShake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-3px, 2px) rotate(-1deg); }
  40% { transform: translate(3px, -2px) rotate(1deg); }
  60% { transform: translate(-2px, -1px) rotate(-0.5deg); }
  80% { transform: translate(2px, 1px) rotate(0.5deg); }
}

/* Badge superior indicador de componente quemado */
.burned-badge {
  position: absolute;
  top: -12px;
  right: 6px;
  background: linear-gradient(135deg, #ef4444, #991b1b);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 12px;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.95);
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 100;
  cursor: pointer;
  animation: pulseBurned 1.4s infinite;
  user-select: none;
}

@keyframes pulseBurned {
  0%, 100% { transform: scale(1); box-shadow: 0 0 8px rgba(239, 68, 68, 0.8); }
  50% { transform: scale(1.06); box-shadow: 0 0 18px rgba(239, 68, 68, 1); }
}

/* Botón interactivo para reemplazar / reparar el componente dañado */
.btn-repair-component {
  position: absolute;
  bottom: -13px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1.5px solid #38bdf8;
  color: #38bdf8;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.85);
  cursor: pointer;
  z-index: 101;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-repair-component:hover {
  background: #38bdf8;
  color: #020617;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.8);
}

/* Contenedor flotante de animación de humo y chispas */
.smoke-puff-container {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 70px;
  pointer-events: none;
  z-index: 200;
}

.smoke-puff {
  position: absolute;
  width: 26px;
  height: 26px;
  background: radial-gradient(circle, rgba(180, 180, 180, 0.85) 0%, rgba(90, 90, 90, 0.5) 60%, rgba(30, 30, 30, 0) 100%);
  border-radius: 50%;
  animation: smokeRise 2.4s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}

.smoke-puff:nth-child(1) { left: 18px; animation-delay: 0s; }
.smoke-puff:nth-child(2) { left: 30px; animation-delay: 0.18s; width: 34px; height: 34px; }
.smoke-puff:nth-child(3) { left: 10px; animation-delay: 0.35s; width: 30px; height: 30px; }

@keyframes smokeRise {
  0% {
    transform: translateY(18px) scale(0.3);
    opacity: 0.95;
  }
  50% {
    transform: translateY(-28px) scale(1.4);
    opacity: 0.7;
  }
  100% {
    transform: translateY(-75px) scale(2.4);
    opacity: 0;
  }
}

.spark-particle {
  position: absolute;
  width: 5px;
  height: 5px;
  background: #fbbf24;
  border-radius: 50%;
  box-shadow: 0 0 8px #f59e0b, 0 0 12px #ef4444;
  animation: sparkShoot 0.75s ease-out forwards;
}

@keyframes sparkShoot {
  0% { transform: translate(0, 0) scale(1.2); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
