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

  /* Colores temáticos hidrológicos */
  --water-primary: #0284c7;
  --water-accent: #38bdf8;
  --water-deep: #0369a1;
  --water-vapor: #e0f2fe;
  --water-aquifer: #0d9488;
  --water-ice: #bae6fd;
  
  /* Sistema de diseño adaptativo */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --border-card: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-card: #0f172a;
  --bg-card-subtle: #1e293b;
  --border-card: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

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

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

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.hero-title,
.faq-section-title {
  font-family: var(--font-heading);
  letter-spacing: -0.015em;
  font-weight: 700;
}

.mono,
code,
.telemetry-val {
  font-family: var(--font-mono);
}

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

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

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Tarjeta principal */
.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

/* Cabecera del simulador */
.simulator-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.simulator-title-group h2 {
  font-size: 1.5rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.simulator-title-group p {
  font-size: 0.925rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.badge-live-3d {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(14, 165, 233, 0.15);
  color: #0284c7;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  border: 1px solid rgba(14, 165, 233, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

[data-theme="dark"] .badge-live-3d {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.3);
}

.badge-live-3d .pulse-dot {
  width: 7px;
  height: 7px;
  background-color: #0284c7;
  border-radius: 50%;
  animation: pulse-glow 2s infinite;
}

[data-theme="dark"] .badge-live-3d .pulse-dot {
  background-color: #38bdf8;
}

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

/* Barra de modos superiores */
.modes-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: var(--bg-card-subtle);
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid var(--border-card);
}

.btn-mode {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 38px;
}

.btn-mode:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .btn-mode:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-mode.active {
  color: #ffffff;
  background: var(--water-primary);
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
}

/* Contenedor del visor 3D */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: clamp(560px, 64vh, 740px);
  min-height: 540px;
  border-radius: 16px;
  overflow: hidden;
  background: #111a2e;
  box-shadow: 0 12px 30px -5px rgba(0, 0, 0, 0.35), inset 0 0 25px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-card);
}

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

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

/* HUD Overlay sobre el Canvas */
.canvas-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-group-left,
.hud-group-right {
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

.hud-btn {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
}

.hud-btn:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(255, 255, 255, 0.3);
}

.hud-btn.active {
  background: var(--water-primary);
  border-color: var(--water-accent);
}

/* Banner de la cinemática «Viaje de una gota» */
.drop-cinematic-banner {
  position: absolute;
  bottom: 14px;
  left: 14px;
  right: 14px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  color: #f8fafc;
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 15;
  animation: slide-up 0.3s ease-out;
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.drop-cinematic-banner.visible {
  display: flex;
}

.cinematic-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cinematic-stage-badge {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.cinematic-step-counter {
  font-size: 0.8rem;
  color: #94a3b8;
  font-family: var(--font-mono);
}

.cinematic-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.cinematic-desc {
  font-size: 0.875rem;
  color: #cbd5e1;
  line-height: 1.45;
}

.cinematic-nav {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.cinematic-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cinematic-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.cinematic-btn.primary {
  background: var(--water-primary);
  border-color: var(--water-accent);
}

/* Panel de controles ambientales y parámetros */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--bg-card-subtle);
  border-radius: 12px;
  border: 1px solid var(--border-card);
}

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

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.control-value-badge {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--water-primary);
  font-weight: 700;
  background: rgba(2, 132, 199, 0.1);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

[data-theme="dark"] .control-value-badge {
  color: var(--water-accent);
  background: rgba(56, 189, 248, 0.15);
}

.control-range {
  width: 100%;
  accent-color: var(--water-primary);
  height: 6px;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

.control-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Conmutador de urbanización vs naturaleza */
.toggle-switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}

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

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

.slider-switch {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 34px;
}

[data-theme="dark"] .slider-switch {
  background-color: #475569;
}

.slider-switch:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider-switch {
  background-color: var(--water-primary);
}

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

/* Panel de telemetría y balance de masas */
.telemetry-section {
  margin-top: 1.5rem;
}

.telemetry-section-title {
  font-size: 1.15rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

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

.telemetry-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.telemetry-card:hover {
  transform: translateY(-2px);
  border-color: var(--water-accent);
}

.telemetry-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.telemetry-val-group {
  margin: 0.6rem 0 0.3rem;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

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

.telemetry-unit {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.telemetry-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Leyenda del corte transversal */
.cross-section-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card-subtle);
  border-radius: 10px;
  border: 1px solid var(--border-card);
  font-size: 0.8rem;
  color: var(--text-main);
}

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

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Botones de acción general */
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-action-primary {
  background: var(--water-primary);
  color: #ffffff;
}

.btn-action-primary:hover {
  background: var(--water-deep);
}

.btn-action-outline {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-card);
}

.btn-action-outline:hover {
  background: var(--bg-card-subtle);
}

/* Secciones divulgativas y acordeones */
.content-accordion {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.accordion-item {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.accordion-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.15rem 1.25rem;
  background: transparent;
  border: none;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.2s ease;
}

.accordion-header:hover {
  background-color: var(--bg-card-subtle);
}

.accordion-icon {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
  flex-shrink: 0;
  stroke: var(--text-muted);
}

.accordion-item.open .accordion-icon {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 0 1.25rem 1.25rem;
  font-size: 0.925rem;
  color: var(--text-muted);
  line-height: 1.65;
  border-top: 1px solid var(--border-card);
}

.accordion-item.open .accordion-body {
  display: block;
}

.accordion-body p {
  margin-bottom: 0.85rem;
}

.accordion-body p:last-child {
  margin-bottom: 0;
}

.accordion-body ul,
.accordion-body ol {
  padding-left: 1.4rem;
  margin-bottom: 0.85rem;
}

.accordion-body li {
  margin-bottom: 0.4rem;
}

.data-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-card);
}

.data-table th {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  font-weight: 700;
}

/* Modales accesibles (sustituto estricto de window.alert) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  max-width: 500px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  animation: modal-appear 0.25s ease-out;
}

@keyframes modal-appear {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-title {
  font-size: 1.25rem;
  color: var(--text-main);
  margin-bottom: 0.6rem;
}

.modal-desc {
  font-size: 0.925rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Adaptabilidad móvil y pantallas pequeñas */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .card-main {
    padding: 1rem;
    border-radius: 12px;
  }

  .canvas-wrapper {
    height: 380px;
  }

  .modes-bar {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding: 0.25rem;
  }

  .btn-mode {
    flex: 1 0 auto;
    justify-content: center;
    font-size: 0.78rem;
    padding: 0.45rem 0.65rem;
  }

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

  .telemetry-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .telemetry-val {
    font-size: 1.3rem;
  }

  .drop-cinematic-banner {
    padding: 0.85rem 1rem;
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  .cinematic-title {
    font-size: 0.95rem;
  }

  .cinematic-desc {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .telemetry-grid {
    grid-template-columns: 1fr;
  }
}
