/* ==========================================================================
   Animales Prehistóricos 3D - Hoja de Estilos de Alta Fidelidad
   Estándares canónicos Fijate Tools (Outfit, Inter, JetBrains Mono)
   ========================================================================== */

/* 1. Reset Global y Blindaje Estricto contra [hidden] (Lección 152) */
[hidden] {
  display: none !important;
}

.app-modal-backdrop[hidden],
.excavation-overlay-card[hidden],
.hotspot-detail-card[hidden] {
  display: none !important;
}

/* 2. Variables de Tema y Diseño Anatómico */
:root {
  --paleo-bg-dark: #080c14;
  --paleo-surface: #0f172a;
  --paleo-surface-elevated: #1e293b;
  --paleo-border: rgba(255, 255, 255, 0.08);
  --paleo-border-glow: rgba(0, 229, 255, 0.25);
  --paleo-text-primary: #f8fafc;
  --paleo-text-secondary: #94a3b8;
  --paleo-text-muted: #64748b;
  --paleo-cyan: #00e5ff;
  --paleo-cyan-glow: rgba(0, 229, 255, 0.35);
  --paleo-amber: #f59e0b;
  --paleo-amber-glow: rgba(245, 158, 11, 0.3);
  --paleo-bone: #dfd7c2;
  --paleo-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --paleo-font-title: 'Outfit', sans-serif;
  --paleo-font-mono: 'JetBrains Mono', monospace;
  --paleo-radius-lg: 16px;
  --paleo-radius-md: 10px;
  --paleo-radius-sm: 6px;
  --paleo-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --paleo-bg-dark: #f1f5f9;
  --paleo-surface: #ffffff;
  --paleo-surface-elevated: #f8fafc;
  --paleo-border: rgba(0, 0, 0, 0.08);
  --paleo-border-glow: rgba(0, 168, 204, 0.3);
  --paleo-text-primary: #0f172a;
  --paleo-text-secondary: #475569;
  --paleo-text-muted: #64748b;
  --paleo-cyan: #0284c7;
  --paleo-cyan-glow: rgba(2, 132, 199, 0.25);
}

/* 3. Tipografía y Contención */
body {
  margin: 0;
  padding: 0;
  font-family: var(--paleo-font-sans);
  background-color: var(--paleo-bg-dark);
  color: var(--paleo-text-primary);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, .brand-title, .card-section-title {
  font-family: var(--paleo-font-title);
  letter-spacing: -0.015em;
  margin: 0;
}

.code-font {
  font-family: var(--paleo-font-mono);
}

/* 4. Layout Canónico */
.tool-layout {
  max-width: 1240px;
  margin: 1.25rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.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.25rem;
}

/* Tarjetas con Efecto Glassmorphism */
.card-glass {
  background: var(--paleo-surface);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-lg);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  position: relative;
}

/* 5. Barra Superior de Selección y Períodos */
.species-nav-bar {
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.selector-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 280px;
  min-width: 0;
}

.selector-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--paleo-text-secondary);
  white-space: nowrap;
}

.paleo-select {
  flex: 1 1 0%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 42px;
  padding: 0 1rem;
  background: var(--paleo-surface-elevated);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-md);
  color: var(--paleo-text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: var(--paleo-transition);
}

.paleo-select:focus {
  border-color: var(--paleo-cyan);
  box-shadow: 0 0 0 3px var(--paleo-cyan-glow);
}

.period-quick-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.period-badge-btn {
  border: none;
  background: var(--paleo-surface-elevated);
  color: var(--paleo-text-secondary);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--paleo-transition);
  border: 1px solid transparent;
}

.period-badge-btn:hover {
  color: var(--paleo-text-primary);
  border-color: var(--paleo-border-glow);
}

.period-badge-btn.active {
  background: var(--paleo-cyan-glow);
  color: var(--paleo-cyan);
  border-color: var(--paleo-cyan);
}

/* 6. Escenario 3D Principal */
.stage-3d-card {
  position: relative;
  width: 100%;
  height: 600px;
  border-radius: var(--paleo-radius-lg);
  overflow: hidden;
  background: radial-gradient(circle at center, #111a2e 0%, #080c14 100%);
  display: flex;
  flex-direction: column;
}

[data-theme="light"] .stage-3d-card {
  background: radial-gradient(circle at center, #e2e8f0 0%, #cbd5e1 100%);
}

.model-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(8, 12, 20, 0.88);
  backdrop-filter: blur(8px);
  z-index: 50;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  pointer-events: none;
}

.model-loader.hidden {
  opacity: 0;
  visibility: hidden;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(0, 229, 255, 0.15);
  border-top-color: var(--paleo-cyan);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--paleo-cyan);
  letter-spacing: 0.02em;
}

.webgl-canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  outline: none;
}

.webgl-canvas-wrapper:active {
  cursor: grabbing;
}

/* 7. Barra de Herramientas Flotante Superior */
.viewer-toolbar-top {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  pointer-events: none;
  z-index: 10;
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-md);
  padding: 0.2rem;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

.btn-tool, .btn-tool-toggle {
  background: transparent;
  border: none;
  color: var(--paleo-text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: var(--paleo-radius-sm);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--paleo-transition);
  height: 36px;
  pointer-events: auto;
}

.btn-tool:hover, .btn-tool-toggle:hover {
  color: var(--paleo-text-primary);
}

.btn-tool.active, .btn-tool-toggle.active {
  background: var(--paleo-cyan-glow);
  color: var(--paleo-cyan);
}

.btn-tool-toggle {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-md);
  backdrop-filter: blur(8px);
}

.btn-tool-icon {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-md);
  color: var(--paleo-text-secondary);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: var(--paleo-transition);
  backdrop-filter: blur(8px);
}

.btn-tool-icon:hover {
  color: var(--paleo-cyan);
  border-color: var(--paleo-cyan);
}

/* 8. Barra de Presets de Cámara Rápidos */
.camera-presets-bar {
  position: absolute;
  top: 4.2rem;
  left: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  z-index: 10;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-md);
  padding: 0.25rem 0.5rem;
  backdrop-filter: blur(8px);
}

.preset-label {
  font-size: 0.72rem;
  color: var(--paleo-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  margin-right: 0.2rem;
}

.btn-cam-preset {
  background: transparent;
  border: none;
  color: var(--paleo-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: var(--paleo-radius-sm);
  cursor: pointer;
  transition: var(--paleo-transition);
}

.btn-cam-preset:hover {
  color: var(--paleo-text-primary);
}

.btn-cam-preset.active {
  background: var(--paleo-surface-elevated);
  color: var(--paleo-cyan);
}

/* 11. Hotspots 3D Proyectados en Pantalla */
.paleo-hotspot-pin {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
  pointer-events: auto;
  user-select: none;
}

.hotspot-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--paleo-cyan);
  border: 2px solid #ffffff;
  box-shadow: 0 0 8px var(--paleo-cyan);
  z-index: 2;
  transition: var(--paleo-transition);
}

.hotspot-pulse {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--paleo-cyan);
  animation: hotspot-pulse-anim 1.8s infinite ease-out;
  opacity: 0.8;
}

@keyframes hotspot-pulse-anim {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

.paleo-hotspot-pin:hover .hotspot-dot,
.paleo-hotspot-pin.active .hotspot-dot {
  transform: scale(1.35);
  background: var(--paleo-amber);
  border-color: #ffffff;
}

.hotspot-tooltip {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  border: 1px solid var(--paleo-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.paleo-hotspot-pin:hover .hotspot-tooltip {
  opacity: 1;
}

/* 12. Ficha de Detalle Anatómico Flotante */
.hotspot-detail-card {
  padding: 1.25rem;
  border-left: 4px solid var(--paleo-cyan);
}

.hotspot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.6rem;
}

.hotspot-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--paleo-cyan);
  margin-bottom: 0.2rem;
}

.hotspot-title {
  font-size: 1.15rem;
  color: var(--paleo-text-primary);
}

.btn-close-hotspot {
  background: transparent;
  border: none;
  color: var(--paleo-text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  transition: var(--paleo-transition);
}

.btn-close-hotspot:hover {
  color: var(--paleo-text-primary);
}

.hotspot-body {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--paleo-text-secondary);
  margin: 0;
}

/* 13. Grilla Científica y Biomecánica */
.species-scientific-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.scientific-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.card-section-title {
  font-size: 1.1rem;
  color: var(--paleo-text-primary);
}

.badge-ics {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 12px;
  border: 1px solid currentColor;
}

.taxonomy-table-wrap {
  overflow-x: auto;
}

.taxonomy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.taxonomy-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  color: var(--paleo-text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--paleo-border);
  width: 38%;
}

.taxonomy-table td {
  padding: 0.5rem 0.6rem;
  color: var(--paleo-text-primary);
  border-bottom: 1px solid var(--paleo-border);
}

.kpi-biomechanics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.kpi-box {
  background: var(--paleo-surface-elevated);
  padding: 0.75rem 0.6rem;
  border-radius: var(--paleo-radius-md);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--paleo-border);
}

.kpi-label {
  font-size: 0.72rem;
  color: var(--paleo-text-muted);
  font-weight: 600;
}

.kpi-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--paleo-text-primary);
  margin: 0.2rem 0;
}

.kpi-sub {
  font-size: 0.68rem;
  color: var(--paleo-text-muted);
}

.biomechanics-notes {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--paleo-radius-md);
  padding: 0.75rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--paleo-text-secondary);
}

.biomechanics-notes p {
  margin: 0.3rem 0;
}

/* 14. Registro Fósil y Yacimientos */
.fossil-sites-card {
  padding: 1.25rem;
}

.fossil-site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 0.8rem;
}

.fossil-info-block {
  background: var(--paleo-surface-elevated);
  padding: 0.85rem;
  border-radius: var(--paleo-radius-md);
  border: 1px solid var(--paleo-border);
}

.fossil-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--paleo-text-muted);
  text-transform: uppercase;
}

.fossil-val {
  font-size: 0.88rem;
  color: var(--paleo-text-primary);
  margin: 0.35rem 0 0;
  line-height: 1.45;
}

/* 16. Modal Accesible Genérico */
.app-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  box-sizing: border-box;
}

.app-modal-card {
  background: var(--paleo-surface);
  border: 1px solid var(--paleo-border);
  border-radius: var(--paleo-radius-lg);
  max-width: 580px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

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

.app-modal-title {
  font-size: 1.15rem;
  color: var(--paleo-text-primary);
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--paleo-text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.app-modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--paleo-text-secondary);
}

.glossary-item {
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--paleo-border);
}

.glossary-term {
  font-weight: 700;
  color: var(--paleo-cyan);
  margin-bottom: 0.2rem;
}

.app-modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--paleo-border);
  display: flex;
  justify-content: flex-end;
}

.btn-modal-action {
  background: var(--paleo-surface-elevated);
  border: 1px solid var(--paleo-border);
  color: var(--paleo-text-primary);
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  border-radius: var(--paleo-radius-md);
  cursor: pointer;
  transition: var(--paleo-transition);
  height: 40px;
}

.btn-modal-action:hover {
  border-color: var(--paleo-cyan);
  color: var(--paleo-cyan);
}

/* 17. Adaptaciones Responsivas para Móviles */
@media (max-width: 1024px) {
  .stage-3d-card {
    height: 520px;
  }
  .kpi-biomechanics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .tool-layout {
    padding: 0 0.6rem;
    margin: 0.8rem auto 2rem;
  }

  .stage-3d-card {
    height: 440px;
  }

  .viewer-toolbar-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .camera-presets-bar {
    top: auto;
    bottom: 0.8rem;
    left: 0.6rem;
    right: 0.6rem;
    overflow-x: auto;
  }

  .kpi-biomechanics-grid {
    grid-template-columns: 1fr;
  }
}
