/* --- TECNOLÓGICA: CONSTRUCTIVISMO CIBERNÉTICO --- */
/* Basado en ESTILO MAESTRO_DARK TECH + MONTSERRAT.css */

:root {
  /* 1. PALETA DE COLORES (Deep Space / Quantum Void) */
  --bg-deep: #0f172a;
  /* Fondo principal */
  --bg-panel: #1e293b;
  /* Paneles / Tarjetas */
  --bg-panel-transparent: rgba(30, 41, 59, 0.7);
  /* Glassmorphism */

  /* Acentos Energía */
  --accent-cyan: #00f3ff;
  /* Señal ALTA / Activo */
  --accent-magenta: #d946ef;
  /* Títulos / Especial */
  --accent-gradient: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 50%, #d946ef 100%);

  /* Estados */
  --signal-low: #94a3b8;
  /* Señal BAJA / Inactivo (Slate 400) */
  --signal-high: var(--accent-cyan);

  /* Texto */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;

  /* 2. TIPOGRAFÍA */
  --font-main: 'Montserrat', sans-serif;
  --font-code: 'Consolas', 'Monaco', monospace;

  /* 3. FORMAS Y EFECTOS */
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-glow: 0 0 15px rgba(0, 243, 255, 0.2);
  --shadow-panel: 0 10px 30px rgba(0, 0, 0, 0.5);
  --glass-border: 1px solid rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-main);
  height: 100vh;
  overflow: hidden;
  /* App-like feel */
  font-size: 16px;
}

/* --- INTRO LAYER --- */
#intro-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.8s ease;
}

#intro-video {
  width: 60%;
  max-width: 800px;
  height: auto;
}

#start-btn-container {
  margin-top: 30px;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

#start-btn-container.visible {
  opacity: 1;
  pointer-events: auto;
}

/* --- LAYOUT --- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar (Toolbox) */
.sidebar {
  width: 340px;
  /* Slightly wider to prevent horizontal scroll */
  background: var(--bg-panel);
  border-right: 1px solid #334155;
  display: flex;
  flex-direction: column;
  padding: 24px;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
  z-index: 20;
  /* Higher than canvas elements */
  overflow-x: hidden;
  /* No horizontal scroll */
  overflow-y: auto;
}

.sidebar-header {
  text-align: center;
  margin-bottom: 30px;
}

.sidebar-header img {
  max-width: 180px;
  height: auto;
}


/* Toolbox Sections */
.toolbox-section {
  margin-bottom: 30px;
}

.toolbox-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 1.5px;
  margin-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 5px;
}

.toolbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* Toolbox Item (Draggable) */
.toolbox-item {
  background: rgba(255, 255, 255, 0.03);
  border: var(--glass-border);
  border-radius: var(--radius-md);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: all 0.2s ease;
}

.toolbox-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

.toolbox-item span {
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Toolbox Icons (SVG Backgrounds) */
[class^="icon-gate-"] {
  width: 48px;
  height: 32px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.icon-gate-not {
  background-image: url('../assets/gates/not.svg');
}

.icon-gate-and {
  background-image: url('../assets/gates/and.svg');
}

.icon-gate-or {
  background-image: url('../assets/gates/or.svg');
}

.icon-gate-nand {
  background-image: url('../assets/gates/nand.svg');
}

.icon-gate-nor {
  background-image: url('../assets/gates/nor.svg');
}

.icon-gate-xor {
  background-image: url('../assets/gates/xor.svg');
}

.icon-gate-xnor {
  background-image: url('../assets/gates/xnor.svg');
}

.icon-switch {
  width: 40px;
  height: 20px;
  border: 2px solid #94a3b8;
  border-radius: 10px;
  position: relative;
  margin-bottom: 5px;
}

.icon-switch::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: #94a3b8;
  border-radius: 50%;
  top: 1px;
  left: 2px;
}

.icon-bulb {
  width: 40px;
  height: 40px;
  /* SVG Circle + Filament */
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='20' cy='20' r='12' stroke='%2394a3b8' stroke-width='2' fill='none'/%3E%3Cpath d='M 14 24 L 17 16 L 20 24 L 23 16 L 26 24' stroke='%2394a3b8' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

/* Buttons */
.controls-section {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 10px 0;
}

.btn-primary,
.btn-secondary {
  border: none;
  font-family: var(--font-main);
  font-weight: 700;
  text-transform: uppercase;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: var(--accent-cyan);
  color: var(--bg-deep);
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
}

.btn-primary:hover {
  background: #fff;
  box-shadow: 0 0 25px rgba(0, 243, 255, 0.7);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid #334155;
}

.btn-secondary:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn-danger {
  background: transparent;
  color: #ef4444;
  /* Red 500 */
  border: 1px solid #ef4444;
  margin-top: 5px;
  font-family: var(--font-main);
  font-weight: 700;
  text-transform: uppercase;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.btn-danger:hover {
  background: #ef4444;
  color: #fff;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}


/* Canvas Area */
.canvas-area {
  flex-grow: 1;
  position: relative;
  background-color: var(--bg-deep);
  overflow: auto;
  /* Allow scrolling if circuit gets big */
  /* Grid Pattern (Technical Look) */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

.canvas-header {
  position: fixed !important;
  top: 20px;
  left: 360px;
  /* Sidebar width + 20px */
  z-index: 100;
  pointer-events: none;
  /* Let clicks pass through to canvas if needed */
}

#circuit-container {
  width: 2000px;
  /* Large canvas */
  height: 2000px;
  position: relative;
}

#connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Pass through click events to components */
  z-index: 0;
}

/* Wire Styles (SVG) */
.connection-path {
  fill: none;
  stroke: var(--signal-low);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke 0.1s ease;
  pointer-events: stroke;
  /* Wire detects clicks */
  cursor: pointer;
}

.connection-path:hover {
  stroke-width: 6;
  stroke: #fff;
}

.connection-path.selected {
  stroke: #d946ef !important;
  /* Magenta select */
  filter: drop-shadow(0 0 5px #d946ef);
}

/* Active Wire (High Signal) */
.connection-path[stroke="#00f3ff"],
.connection-path[stroke="#06b6d4"] {
  stroke: var(--accent-cyan) !important;
  filter: drop-shadow(0 0 8px var(--accent-cyan));
}

/* Component Styles on Canvas */
.component {
  position: absolute;
  cursor: move;
  width: 60px;
  height: 40px;
  /* Base box size, though ports extend */
  z-index: 10;
}

.component.selected {
  outline: 2px dashed #d946ef;
  outline-offset: 4px;
  border-radius: 4px;
}

/* Ports - Small circles */
.port {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #1e293b;
  border: 2px solid #64748b;
  border-radius: 50%;
  cursor: crosshair;
  z-index: 20;
  transition: all 0.1s;
}

.port.input-port {
  background: #0f172a;
}

.port.output-port {
  background: #0f172a;
}

.port:hover {
  background: var(--accent-cyan) !important;
  border-color: #fff !important;
  transform: scale(1.4);
}

/* Bulb Styles */
.active circle {
  fill: var(--accent-cyan) !important;
  stroke: var(--accent-cyan) !important;
  filter: drop-shadow(0 0 10px var(--accent-cyan));
}

.component[data-type="bulb"].active path {
  stroke: #000 !important;
  /* Filament dark against bright glow */
}

/* Switch Active State (SVG) */
.component[data-type="switch"] circle {
  transition: all 0.2s ease;
}

.component[data-type="switch"].active circle {
  fill: var(--accent-cyan) !important;
  filter: drop-shadow(0 0 5px var(--accent-cyan));
  transform: translateX(20px);
  /* Slide to right */
}

/* Modal Styles */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.85);
  /* Deep dark overlay */
  backdrop-filter: blur(5px);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active,
.modal-overlay.visible {
  display: flex;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  width: 80%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
  animation: modalSlideIn 0.3s ease-out;
}

#hero-modal .modal-content {
  width: 35% !important;
  /* Specific size for Hero Image */
  background: transparent;
  border: none;
  box-shadow: none;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  color: var(--accent-magenta);
  font-size: 1.5rem;
  text-transform: uppercase;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: #fff;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Truth Table Styles */
.truth-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-family: var(--font-code);
}

.truth-table th,
.truth-table td {
  padding: 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.truth-table th {
  color: var(--accent-cyan);
  font-weight: 700;
  text-transform: uppercase;
  font-family: var(--font-main);
  font-size: 0.85rem;
}

.truth-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.truth-table .output-col {
  color: var(--accent-magenta);
  font-weight: bold;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* Simulation Button */
.btn-simulate-fixed {
  position: fixed;
  top: 20px;
  right: 30px;
  z-index: 1000;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-secondary);
  padding: 12px 24px;
  border-radius: 50px;
  font-family: var(--font-main);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.btn-simulate-fixed:hover {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0, 243, 255, 0.2);
}

.btn-simulate-fixed .icon {
  font-size: 1.2rem;
  filter: grayscale(1);
  transition: all 0.3s;
}

/* Active Simulation State */
.btn-simulate-fixed.simulating {
  background: var(--accent-cyan);
  color: #0f172a;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(0, 243, 255, 0.6);
}

.btn-simulate-fixed.simulating .icon {
  filter: grayscale(0);
  animation: pulse 1.5s infinite;
}


@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}

/* Footer License */
.canvas-footer {
  position: fixed;
  bottom: 15px;
  left: 340px;
  /* Sidebar width */
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  /* Let clicks pass through outside the content */
  z-index: 90;
  /* Below header/modals */
}

.canvas-footer-content {
  background: rgba(15, 23, 42, 0.6);
  /* Semi-transparent background */
  backdrop-filter: blur(4px);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 0.7rem;
  pointer-events: auto;
  /* Enable interaction */
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.canvas-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.canvas-footer a:hover {
  color: var(--accent-cyan);
  text-decoration: underline;
}

.canvas-footer img {
  vertical-align: middle;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.canvas-footer img:hover {
  opacity: 1;
}