/**
 * style.css — Estilos de la aplicación WebAR Eclipse
 * Arquitectura de capas superpuestas con position:fixed
 * Cada capa ocupa el 100% de la pantalla, apiladas por z-index
 */

/* =============================================
   RESET Y BASE
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Paleta de colores del eclipse */
  --color-primary: #F5A623;      /* Naranja/dorado de la corona solar */
  --color-bg-dark: #050914;      /* Azul casi negro — cielo en totalidad */
  --color-bg-mid: #1A233A;       /* Azul oscuro — gradiente del cielo */
  --color-text: #FFFFFF;
  --color-text-muted: rgba(255, 255, 255, 0.55);

  /* Tamaño del slider */
  --slider-thumb-size: 28px;
  --slider-track-height: 6px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;              /* Sin scroll — experiencia inmersiva fullscreen */
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  /* Evitar selección de texto accidental durante la interacción con el slider */
  user-select: none;
  -webkit-user-select: none;
}

/* =============================================
   CAPA 1 — VIDEO (feed crudo cámara trasera)
   z-index: 1 — la capa más trasera
   ============================================= */
#camera-feed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;             /* Rellena pantalla sin deformar */
  z-index: 1;
  /* La cámara trasera puede tener orientación invertida en algunos Android */
  transform: scaleX(1);
}

/* =============================================
   CAPA 2 — CANVAS CIELO (overlay oscuro segmentado)
   z-index: 2 — sobre el video, bajo la luna
   ============================================= */
#sky-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;          /* No intercepta eventos táctiles */
}

/* =============================================
   CAPA 3 — CANVAS THREE.JS (luna 3D + corona)
   z-index: 3 — entre el cielo y el usuario
   IMPORTANTE: el fondo del renderer WebGL debe ser
   transparente (configurado en scene3d.js con alpha:true)
   ============================================= */
#three-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

/* =============================================
   CAPA 4 — CANVAS USUARIO (persona en primer plano)
   z-index: 4 — la capa más al frente antes del HUD
   El usuario NUNCA queda tapado por la luna o el cielo
   ============================================= */
#user-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
}

/* =============================================
   CAPA 5 — HUD / UI OVERLAY
   z-index: 10+ — interfaz de usuario por encima de todo
   ============================================= */
#ui-hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  /* El HUD es un contenedor flex para organizar sus hijos */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  pointer-events: none;          /* El contenedor no bloquea toques */
}

/* Logo en esquina superior izquierda */
#hud-logo {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 72px;
  height: 72px;
  object-fit: contain;
  pointer-events: none;
}

/* Botón volver — esquina superior derecha */
#back-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  pointer-events: all;           /* Este sí debe recibir toques */
  color: var(--color-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 8px 16px;
  transition: background 0.2s, border-color 0.2s;
}

#back-btn:hover,
#back-btn:active {
  background: rgba(245, 166, 35, 0.25);
  border-color: rgba(245, 166, 35, 0.5);
}

/* Botón flip cámara — esquina inferior derecha, encima del slider */
#flip-btn {
  position: absolute;
  bottom: 160px;
  right: 24px;
  pointer-events: all;
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.35s ease;
}

#flip-btn:active {
  background: rgba(245, 166, 35, 0.25);
  border-color: rgba(245, 166, 35, 0.5);
  transform: rotate(180deg);
}

#flip-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* =============================================
   CONTENEDOR DEL SLIDER — anclado en la parte inferior
   ============================================= */
#slider-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 24px 40px;      /* Padding extra inferior por el notch/home indicator */
  background: linear-gradient(
    to top,
    rgba(5, 9, 20, 0.75) 0%,
    transparent 100%
  );
  pointer-events: all;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Etiquetas del slider */
#slider-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
}

#slider-labels span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* =============================================
   SLIDER PERSONALIZADO — el control maestro
   ============================================= */
#eclipse-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 480px;
  height: var(--slider-track-height);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  pointer-events: all;

  /* Gradiente del track: naranja en el centro (totalidad) */
  background: linear-gradient(
    to right,
    rgba(255,255,255,0.12) 0%,
    var(--color-primary) 50%,
    rgba(255,255,255,0.12) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Thumb — WebKit (Chrome, Safari, Android) */
#eclipse-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--slider-thumb-size);
  height: var(--slider-thumb-size);
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 0 0 4px rgba(245, 166, 35, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.5);
  cursor: grab;
  transition: transform 0.1s, box-shadow 0.1s;
}

#eclipse-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
  box-shadow:
    0 0 0 6px rgba(245, 166, 35, 0.35),
    0 4px 16px rgba(0, 0, 0, 0.6);
}

/* Thumb — Firefox */
#eclipse-slider::-moz-range-thumb {
  width: var(--slider-thumb-size);
  height: var(--slider-thumb-size);
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 0 0 4px rgba(245, 166, 35, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.5);
  cursor: grab;
}

/* Track — Firefox */
#eclipse-slider::-moz-range-track {
  height: var(--slider-track-height);
  border-radius: 999px;
  background: linear-gradient(
    to right,
    rgba(255,255,255,0.12) 0%,
    var(--color-primary) 50%,
    rgba(255,255,255,0.12) 100%
  );
}

/* Hint de instrucción encima del slider */
#slider-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
  text-align: center;
  margin-bottom: 4px;
}

/* =============================================
   LOADER OVERLAY — pantalla de carga inicial
   z-index: 20 — por encima de todo
   ============================================= */
#loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  background: var(--color-bg-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;

  /* Transición de fade-out al completarse la carga */
  transition: opacity 0.6s ease, visibility 0.6s ease;
  opacity: 1;
  visibility: visible;
}

/* Estado oculto — se activa desde app.js añadiendo la clase .hidden */
#loader-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Icono de carga SVG */
#loader-icon {
  width: 80px;
  height: 80px;
  animation: spin 1.8s linear infinite;
}

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

/* Texto de estado de carga */
#loader-text {
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Barra de progreso de carga */
#loader-progress-bar {
  width: 200px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

#loader-progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

/* =============================================
   PANTALLA DE INICIO — permiso de cámara
   Se muestra antes de solicitar getUserMedia
   ============================================= */
#start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  background: linear-gradient(160deg, var(--color-bg-dark) 0%, var(--color-bg-mid) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px;
  text-align: center;

  transition: opacity 0.5s ease, visibility 0.5s ease;
  opacity: 1;
  visibility: visible;
}

#start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#start-logo {
  width: 100px;
  height: auto;
  margin-bottom: 8px;
}

#start-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: 0.04em;
  line-height: 1.3;
}

#start-subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: 300px;
}

/* Botón de inicio — debe activar el gesto del usuario para getUserMedia y AudioContext */
#start-btn {
  margin-top: 8px;
  padding: 16px 40px;
  background: var(--color-primary);
  color: #050914;
  border: none;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 0 30px rgba(245, 166, 35, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}

#start-btn:active {
  transform: scale(0.97);
  box-shadow: 0 0 15px rgba(245, 166, 35, 0.2);
}

/* Aviso de permisos */
#start-notice {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.3);
  max-width: 280px;
  line-height: 1.5;
}

/* =============================================
   MENSAJE DE ERROR — cámara denegada / no HTTPS
   ============================================= */
#error-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 25;
  background: var(--color-bg-dark);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
}

#error-screen.visible {
  display: flex;
}

#error-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

#error-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

#error-message {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: 300px;
}

#error-retry-btn {
  margin-top: 8px;
  padding: 12px 32px;
  background: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
  border-radius: 50px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s;
}

#error-retry-btn:active {
  background: rgba(245, 166, 35, 0.15);
}

/* =============================================
   INDICADOR VISUAL DE FASE DEL ECLIPSE
   Pequeña etiqueta dinámica que indica la fase actual
   ============================================= */
#phase-indicator {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  pointer-events: none;
  transition: color 0.5s, border-color 0.5s;
  white-space: nowrap;
}

/* Cuando está en totalidad (slider ~50), resalta en dorado */
#phase-indicator.totality {
  color: var(--color-primary);
  border-color: rgba(245, 166, 35, 0.4);
}

/* =============================================
   RESPONSIVE — ajustes para tablets
   ============================================= */
@media (min-width: 768px) {
  #hud-logo {
    width: 140px;
  }

  #slider-container {
    padding: 24px 60px 48px;
  }

  #eclipse-slider {
    max-width: 600px;
  }
}
