/**
 * Laboratorio de Ilusiones Ópticas - Perception Studio
 * Estilos y Sistema Visual Dark Premium
 * @version 1.0.0
 */

:root {
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta Dark Premium */
  --bg-page: #0b0f17;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-hover: rgba(30, 41, 59, 0.85);
  --bg-input: #1e293b;
  --border-card: rgba(255, 255, 255, 0.08);
  --border-focus: #38bdf8;
  
  /* Acentos */
  --accent-cyan: #38bdf8;
  --accent-orange: #ff8507;
  --accent-purple: #a855f7;
  --accent-green: #22c55e;
  --accent-rose: #f43f5e;

  /* Texto */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.25);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: clip; /* Previene anulación de sticky en ads (Lección 79) */
  -webkit-font-smoothing: antialiased;
}

/* Layout General y Centrado */
.app-main {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 auto !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  padding: 0 1rem 3rem 1rem;
}

.main-wrapper {
  width: 100% !important;
  max-width: 1440px !important;
  margin: 0 auto !important;
}

@media (min-width: 1536px) {
  .main-wrapper {
    max-width: 1720px !important;
  }
}

@media (min-width: 1920px) {
  .main-wrapper {
    max-width: 1880px !important;
  }
}

.tool-with-sidebar {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* =========================================================================
   CABECERA DE LA HERRAMIENTA
   ========================================================================= */
.perception-hero-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-card);
}

.hero-info {
  flex: 1 1 280px;
  min-width: 0;
}

.hero-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.category-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.hero-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.hero-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-word;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Botones de Cabecera y Herramientas */
.btn-icon-action {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon-action:hover {
  background: rgba(51, 65, 85, 0.9);
  color: #ffffff;
  border-color: var(--accent-cyan);
}

/* =========================================================================
   STAGE DE VISUALIZACIÓN INTERACTIVA (CANVAS)
   ========================================================================= */
.stage-container {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
  align-items: stretch;
}

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

.illusion-stage {
  position: relative;
  background: #020617;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  flex: 1 1 0%;
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#illusion-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Barra Flotante de Revelado en el Canvas */
.stage-floating-bar {
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.btn-reveal-main {
  flex: 1 1 0%;
  min-width: 0;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-reveal-main:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-glow);
}

.btn-reveal-main.is-active {
  background: var(--accent-cyan);
  color: #0b0f17;
  border-color: var(--accent-cyan);
}

/* =========================================================================
   PANEL LATERAL DE CONTROLES PARAMÉTRICOS
   ========================================================================= */
.controls-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-card);
}

.panel-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-card);
  padding-bottom: 0.75rem;
}

.controls-fields-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.control-val-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--accent-cyan);
  border: 1px solid var(--border-card);
}

/* Sliders personalizados */
.control-slider, .challenge-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #334155;
  outline: none;
  cursor: pointer;
}

.control-slider::-webkit-slider-thumb, .challenge-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
  border: 2px solid #ffffff;
}

.control-slider::-moz-range-thumb, .challenge-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
  border: 2px solid #ffffff;
}

/* Toggles estilo Switch */
.control-toggle-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
}

.switch-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: 0.3s;
  border-radius: 24px;
}

.slider-toggle::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider-toggle {
  background-color: var(--accent-cyan);
}

input:checked + .slider-toggle::before {
  transform: translateX(20px);
}

/* Selects */
.control-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 40px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0 0.75rem;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.control-select:focus {
  border-color: var(--border-focus);
}

/* =========================================================================
   MODO DESAFÍO Y TEMPORIZADOR
   ========================================================================= */
.challenge-card {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.challenge-header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.challenge-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.challenge-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffffff;
}

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

.btn-primary-action {
  width: 100%;
  min-height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-cyan), #0284c7);
  color: #0b0f17;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary-action:hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-glow);
}

/* Temporizador */
.timer-widget {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.timer-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.btn-timer-toggle {
  height: 38px;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

/* =========================================================================
   PANEL NEUROCIENTÍFICO EXPLICATIVO
   ========================================================================= */
.neuro-panel-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.neuro-panel-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.neuro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.neuro-box {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.neuro-box-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-cyan);
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.neuro-box-val {
  font-size: 0.95rem;
  font-weight: 600;
  color: #ffffff;
}

.neuro-deep-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--border-card);
  padding-top: 1rem;
}

/* =========================================================================
   BENTO GRID DE EXPLORACIÓN DE ILUSIONES
   ========================================================================= */
.explorer-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.explorer-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.explorer-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffffff;
}

.explorer-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Pestañas de categoría */
.category-tab-btn {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.category-tab-btn:hover {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.category-tab-btn.is-active {
  background: var(--accent-cyan);
  color: #0b0f17;
  font-weight: 700;
  border-color: var(--accent-cyan);
}

.search-input-box {
  position: relative;
  min-width: 220px;
}

.search-input {
  width: 100%;
  height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: 9999px;
  color: var(--text-main);
  padding: 0 1rem 0 2.2rem;
  font-size: 0.85rem;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent-cyan);
}

.search-icon-svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

/* Rejilla Bento */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.bento-illusion-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bento-illusion-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.bento-illusion-card.is-active {
  border-color: var(--accent-cyan);
  background: rgba(30, 41, 59, 0.95);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

.bento-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bento-category-tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-cyan);
}

.bento-live-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.bento-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
}

.bento-card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1 1 0%;
}

.bento-card-footer {
  border-top: 1px solid var(--border-card);
  padding-top: 0.6rem;
}

.bento-action-hint {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

/* =========================================================================
   MODAL NATIVO ACCESIBLE
   ========================================================================= */
.app-modal-backdrop {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  padding: 1rem;
}

.app-modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.app-modal-card {
  background: #0f172a;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.app-modal-backdrop.is-open .app-modal-card {
  transform: scale(1);
}

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

.app-modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
}

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

.test-result-summary {
  text-align: center;
  padding: 1rem;
  background: rgba(30, 41, 59, 0.5);
  border-radius: var(--radius-md);
}

.metric-score-big {
  font-size: 2.75rem;
  font-weight: 900;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

.metric-score-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.test-result-details {
  font-size: 0.9rem;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.test-result-diag {
  color: var(--accent-orange);
  font-weight: 600;
  padding: 0.5rem;
  background: rgba(249, 115, 22, 0.1);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-orange);
}

.modal-neuro-quote {
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-card);
  padding-top: 0.75rem;
}
