/**
 * Fijate Tools - Simulador de Evolución Biológica y Criaturas Artificiales
 * Hoja de estilos canónica (Midnight Slate, Bio-Glow y UI de Laboratorio)
 */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta Bio-Emerald y Midnight Slate */
  --primary-color: #10b981;
  --primary-light: rgba(16, 185, 129, 0.14);
  --primary-hover: #059669;
  --accent-cyan: #38bdf8;
  --accent-danger: #ef4444;
  --accent-warn: #f59e0b;
  --accent-purple: #a855f7;

  --bg-body: #070b13;
  --bg-card: #0d1424;
  --bg-card-sub: #131b2e;
  --bg-panel: #17223b;
  --bg-input: #090e1a;
  --border-color: #1e293b;
  --border-highlight: #334155;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="light"], body.light-theme {
  --primary-color: #059669;
  --primary-light: rgba(5, 150, 105, 0.12);
  --primary-hover: #047857;
  --accent-cyan: #0284c7;

  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-sub: #f1f5f9;
  --bg-panel: #e2e8f0;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-highlight: #cbd5e1;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-body);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title {
  font-family: var(--font-heading);
}

.mono, code, .stat-value, .badge-gen {
  font-family: var(--font-mono);
}

/* Tarjeta principal contenedora */
.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  margin-bottom: 2rem;
}

/* Barra superior de métricas vivas (Telemetry Ribbon) */
.telemetry-ribbon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}

.telemetry-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.telemetry-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.telemetry-val-box {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.telemetry-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.telemetry-val.highlight-emerald { color: var(--primary-color); }
.telemetry-val.highlight-cyan { color: var(--accent-cyan); }
.telemetry-val.highlight-amber { color: var(--accent-warn); }
.telemetry-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Barra de control de simulación */
.sim-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  margin-bottom: 1.25rem;
}

.sim-btn-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-sim {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-main);
  transition: all 0.18s ease;
}

.btn-sim:hover {
  background: var(--border-highlight);
  border-color: var(--text-muted);
}

.btn-sim-primary {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #ffffff;
}

.btn-sim-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-sim-primary.paused {
  background: var(--accent-warn);
  border-color: var(--accent-warn);
}

.btn-speed {
  min-width: 42px;
  padding: 0 0.6rem;
}

.btn-speed.active {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Layout del Workspace en 2 Columnas (Lienzo Sandbox + Inspector Cerebral) */
.sandbox-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
  .sandbox-workspace {
    grid-template-columns: 1fr;
  }
}

/* Contenedor del Lienzo */
.canvas-panel {
  display: flex;
  flex-direction: column;
  background: #000000;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

.canvas-viewport-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #070b13;
  cursor: crosshair;
}

#ecosystem-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Barra flotante de herramientas divinas y cataclismos */
.canvas-floating-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: rgba(13, 20, 36, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem;
  z-index: 10;
}

.btn-tool-mode {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 34px;
  padding: 0 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-tool-mode:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.btn-tool-mode.active {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.btn-tool-mode.tool-meteor.active {
  background: rgba(239, 68, 68, 0.18);
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}

.btn-tool-mode.tool-virus.active {
  background: rgba(217, 70, 239, 0.18);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

/* Botonera de cataclismos globales al pie del canvas */
.canvas-bottom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg-card-sub);
  border-top: 1px solid var(--border-color);
  padding: 0.5rem 0.85rem;
}

.cataclysm-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn-cataclysm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 32px;
  padding: 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-main);
  transition: all 0.15s ease;
}

.btn-cataclysm:hover {
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

.btn-cataclysm.btn-meteor:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}

.btn-cataclysm.btn-virus:hover {
  background: rgba(217, 70, 239, 0.2);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

.btn-cataclysm.btn-bloom:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Panel Lateral: Inspector Cerebral en Vivo */
.inspector-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.85rem;
}

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

.inspector-title svg {
  color: var(--accent-cyan);
}

.inspector-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  gap: 0.5rem;
}

.inspector-empty svg {
  color: var(--text-dim);
  opacity: 0.5;
}

.specimen-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.specimen-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.badge-diet {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-diet.herbivore {
  background: rgba(16, 185, 129, 0.18);
  color: var(--primary-color);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-diet.carnivore {
  background: rgba(239, 68, 68, 0.18);
  color: var(--accent-danger);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.energy-progress-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.energy-progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.energy-progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.energy-progress-bar {
  height: 100%;
  width: 50%;
  background: var(--primary-color);
  transition: width 0.15s ease, background-color 0.2s ease;
}

.specimen-grid-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  text-align: center;
}

.stat-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-cell-title {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.stat-cell-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Lienzo de la red neuronal en vivo */
.brain-graph-box {
  display: flex;
  flex-direction: column;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 0.25rem;
}

.brain-graph-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
}

#brain-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #080d17;
}

/* Botones de acción del espécimen */
.specimen-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.btn-specimen-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.5rem;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-specimen-act:hover {
  background: var(--border-highlight);
}

.btn-specimen-act.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}

/* Fila de controles y sliders ecológicos */
.ecosystem-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.setting-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.setting-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
}

.setting-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-color);
}

.setting-slider {
  width: 100%;
  accent-color: var(--primary-color);
  cursor: pointer;
}

.setting-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 40px;
  padding: 0 2.5rem 0 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  appearance: none;
}

.setting-select option {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Panel Sparkline histórico */
.sparkline-box {
  display: flex;
  flex-direction: column;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 2rem;
}

.sparkline-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.sparkline-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.sparkline-legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.food { background: #10b981; }
.legend-dot.herbi { background: #38bdf8; }
.legend-dot.carni { background: #ef4444; }

#sparkline-canvas {
  width: 100%;
  height: 90px;
  display: block;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

/* Sección Educativa y Divulgativa */
.educational-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.edu-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.edu-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.edu-title svg {
  color: var(--primary-color);
}

.edu-desc {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
}

/* Modales canónicos HTML/CSS/JS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.modal-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  padding: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
  max-height: 70vh;
  overflow-y: auto;
}

.modal-textarea {
  width: 100%;
  box-sizing: border-box;
  height: 160px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  resize: vertical;
  margin-top: 0.75rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card-sub);
}

.btn-modal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-width: 90px;
  padding: 0 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-main);
  transition: all 0.15s ease;
}

.btn-modal:hover {
  background: var(--border-highlight);
}

.btn-modal.btn-modal-primary {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #ffffff;
}

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

.btn-modal.btn-modal-danger {
  background: var(--accent-danger);
  border-color: var(--accent-danger);
  color: #ffffff;
}

.btn-modal.btn-modal-danger:hover {
  background: #dc2626;
}

/* Toast flotante de avisos */
.toast-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-highlight);
  color: #f8fafc;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  transform: translateY(60px);
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
  pointer-events: none;
}

.toast-notification.show {
  transform: translateY(0);
  opacity: 1;
}

/* Checkbox con switch táctil */
.switch-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  user-select: none;
}

.switch-container input[type="checkbox"] {
  appearance: none;
  width: 36px;
  height: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.switch-container input[type="checkbox"]:checked {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.switch-container input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch-container input[type="checkbox"]:checked::after {
  transform: translateX(16px);
}
