/**
 * Fijate Tools - Laboratorio de Ferrofluido y Electromagnetismo 3D
 * css/style.css
 */

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

  /* Paleta base Midnight Slate (Tema oscuro por defecto) */
  --bg-page: #07090e;
  --bg-card: #0d121c;
  --bg-card-subtle: #121824;
  --border-card: rgba(255, 255, 255, 0.08);
  --border-focus: #00f0ff;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Acentos electromagnéticos y cobre */
  --accent-cyan: #00f0ff;
  --accent-cyan-glow: rgba(0, 240, 255, 0.28);
  --accent-copper: #f59e0b;
  --accent-copper-glow: rgba(245, 158, 11, 0.32);
  --accent-blue: #3b82f6;
  --accent-red: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Modo claro institucional */
[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --border-card: rgba(15, 23, 42, 0.09);
  --border-focus: #0284c7;

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

  --accent-cyan: #0284c7;
  --accent-cyan-glow: rgba(2, 132, 199, 0.2);
  --accent-copper: #d97706;
  --accent-copper-glow: rgba(217, 119, 6, 0.25);
}

/* 1. Reset y contención canónica */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Layout institucional */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

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

/* Migas de pan */
.tool-breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tool-breadcrumbs li:not(:last-child)::after {
  content: '/';
  margin-left: 0.5rem;
  color: var(--text-dim);
}

.tool-breadcrumbs a {
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
}

.tool-breadcrumbs a:hover {
  color: var(--accent-cyan);
}

/* Hero de presentación */
.hero-card {
  background: linear-gradient(135deg, rgba(13, 18, 28, 0.95), rgba(18, 24, 36, 0.85));
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.hero-card::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, var(--accent-cyan-glow) 0%, transparent 70%);
  pointer-events: none;
}

.hero-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: rgba(0, 240, 255, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 240, 255, 0.25);
}

.badge-tag.badge-copper {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-copper);
  border-color: rgba(245, 158, 11, 0.25);
}

.hero-title {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-main);
  margin-bottom: 0.6rem;
}

.hero-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 860px;
  line-height: 1.55;
}

/* Conmutador de pestañas de modo */
.mode-tabs-wrapper {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.mode-tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  background: var(--bg-card);
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.mode-tab-btn:hover {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border-color: rgba(0, 240, 255, 0.35);
}

.mode-tab-btn.active {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.18), rgba(59, 130, 246, 0.15));
  border-color: var(--accent-cyan);
  color: var(--text-main);
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.mode-tab-btn svg {
  flex-shrink: 0;
}

/* Escenario interactivo 3D */
.stage-card {
  background: #05080e;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

/* Barra superior de herramientas del escenario */
.stage-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  background: rgba(13, 18, 28, 0.9);
  border-bottom: 1px solid var(--border-card);
  flex-wrap: wrap;
  gap: 0.5rem;
  z-index: 5;
}

.stage-title-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulseLive 2s infinite;
}

@keyframes pulseLive {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

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

.btn-stage-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-card);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-stage-action:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-stage-action.active {
  background: rgba(0, 240, 255, 0.18);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Área de visualización 3D */
.stage-viewport-area {
  position: relative;
  width: 100%;
  height: 520px;
  background: #04060a;
  overflow: hidden;
  touch-action: none;
}

#ferrofluid-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#ferrofluid-canvas:active {
  cursor: grabbing;
}

#faraday-container {
  width: 100%;
  height: 100%;
  display: none;
}

#faraday-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Indicación de interacción sobre el lienzo */
.stage-hint-overlay {
  position: absolute;
  bottom: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 18, 28, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-full);
  padding: 0.35rem 0.95rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Cockpit de instrumentación en tiempo real */
.instrumentation-rack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.65rem;
  padding: 0.85rem;
  background: rgba(13, 18, 28, 0.95);
  border-top: 1px solid var(--border-card);
}

.kpi-meter-card {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kpi-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-value.cyan { color: var(--accent-cyan); }
.kpi-value.copper { color: var(--accent-copper); }

/* Fila de presets en 1 clic */
.presets-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.section-subtitle {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.5rem;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  outline: none;
  min-height: 44px;
}

.preset-btn:hover {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border-color: rgba(0, 240, 255, 0.3);
}

.preset-btn.active {
  background: rgba(0, 240, 255, 0.12);
  border-color: var(--accent-cyan);
  color: var(--text-main);
}

.preset-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

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

/* Panel de controles táctiles ergonómicos */
.controls-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.controls-card-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}

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

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.control-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-cyan);
}

/* Sliders estilizados de alta altura táctil */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px; /* Cumplimiento de regla táctil >= 40px */
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: var(--bg-card-subtle);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-card);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 22px;
  width: 22px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
  margin-top: -8px;
  border: 2px solid #ffffff;
  transition: transform 0.15s ease;
}

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

input[type="range"]::-moz-range-track {
  width: 100%;
  height: 6px;
  background: var(--bg-card-subtle);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-card);
}

input[type="range"]::-moz-range-thumb {
  height: 22px;
  width: 22px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
  border: 2px solid #ffffff;
}

/* Botones interactivos de acción */
.btn-action-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  width: 100%;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent-cyan);
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.15), rgba(59, 130, 246, 0.15));
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-action-primary:hover {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.28), rgba(59, 130, 246, 0.28));
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.btn-action-primary.active {
  background: var(--accent-cyan);
  color: #05080e;
  border-color: #ffffff;
  box-shadow: 0 0 20px var(--accent-cyan-glow);
}

/* Guía didáctica y fundamentos */
.edu-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

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

.edu-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.edu-card h3 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.edu-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.formula-box {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-card);
  border-left: 3px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-main);
  overflow-x: auto;
  white-space: nowrap;
}

/* Modal accesible institucional */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

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

.modal-body {
  padding: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  line-height: 1.55;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-card);
  display: flex;
  justify-content: flex-end;
}

/* Adaptación responsive en móvil */
@media (max-width: 768px) {
  .stage-viewport-area {
    height: 380px;
  }

  .hero-title {
    font-size: 1.45rem;
  }

  .stage-actions-group .btn-stage-action span {
    display: none;
  }

  .stage-actions-group .btn-stage-action {
    padding: 0 0.5rem;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .mode-tabs-wrapper {
    grid-template-columns: 1fr;
  }
}
