/* ====================================================
   FASES DE LA LUNA — Hoja de estilos principal
   Estructura: variables → reset → loading → UI base →
               info-panel → controles → responsive
   ==================================================== */

:root {
  --ui-top:    20px;
  --ui-side:   20px;
  --ui-bottom: 28px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --panel-bg:  rgba(10, 10, 22, 0.84);
  --gold:      #ffd966;
  --gold-dim:  #c8a030;
  --purple-dk: #2d2642;
  --purple-md: #5c4f81;
  --blue-hint: #88bbff;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 10px;
  --shadow:    0 8px 28px rgba(0,0,0,0.65);
}

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  overflow: hidden;
  font-family: 'Segoe UI', 'Nunito', 'Comic Sans MS', cursive, sans-serif;
  height: 100dvh;
  width:  100vw;
  background: #08081a;
  touch-action: none;
}

canvas { display: block; }

/* ---------- ETIQUETA DEL PROYECTO ---------- */
#project-badge {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  right: 18px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 10, 22, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255, 215, 150, 0.35);
  border-radius: 40px;
  padding: 7px 14px 7px 10px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.badge-star {
  font-size: 1.1rem;
  line-height: 1;
}

.badge-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.badge-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.badge-grade {
  font-size: 0.72rem;
  color: #aaa;
  line-height: 1.2;
}

@media (max-width: 600px) {
  #project-badge {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    right: 10px;
    padding: 5px 10px 5px 8px;
    gap: 6px;
  }
  .badge-star  { font-size: 0.95rem; }
  .badge-name  { font-size: 0.78rem; }
  .badge-grade { font-size: 0.65rem; }
}

/* ---------- PANTALLA DE CARGA ---------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #14142e 0%, #05050f 100%);
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

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

.loading-content {
  text-align: center;
  color: #f0e6d2;
  padding: 32px 28px;
  max-width: 300px;
  width: 90vw;
}

.loading-moon {
  font-size: 3.8rem;
  animation: moon-float 1.6s ease-in-out infinite;
  display: block;
}

@keyframes moon-float {
  0%, 100% { transform: translateY(0)   rotate(-6deg); }
  50%       { transform: translateY(-12px) rotate(6deg); }
}

.loading-content h2 {
  margin: 16px 0 6px;
  font-size: 1.35rem;
  color: var(--gold);
  font-weight: 700;
}

.loading-content p {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: #aaa;
  min-height: 1.3em;
}

.loading-bar {
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 215, 150, 0.25);
}

#loading-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff9922, var(--gold));
  border-radius: 8px;
  transition: width 0.35s ease;
}

/* ---------- CAPA UI ---------- */
#ui-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    var(--ui-top)
    var(--ui-side)
    calc(var(--ui-bottom) + var(--safe-b))
    var(--ui-side);
  gap: 10px;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#ui-layer.visible { opacity: 1; }

/* ---------- FILA SUPERIOR ---------- */
#top-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  pointer-events: none;
}

/* ---------- PANEL DE INFORMACIÓN ---------- */
#info-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #f0e6d2;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1.5px solid rgba(255, 215, 150, 0.45);
  max-width: 380px;
  flex: 1 1 300px;
  pointer-events: auto;
  overflow: hidden;
}

/* Cabecera siempre visible */
#panel-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px 12px;
  cursor: default;
}

#phase-icon-wrap {
  flex-shrink: 0;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,220,100,0.14) 0%, transparent 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(255,200,80,0.30);
}

#phase-icon {
  display: block;
  width: 60px;
  height: 60px;
}

.phase-text { flex: 1; min-width: 0; }

.phase-label {
  font-size: 0.85rem;
  opacity: 0.75;
  letter-spacing: 0.5px;
}

#phase-name {
  font-size: clamp(1.15rem, 4vw, 1.85rem);
  font-weight: 800;
  margin: 3px 0 4px;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255,170,0,0.7);
  letter-spacing: 0.5px;
  line-height: 1.1;
  transition: opacity 0.2s ease;
}

#phase-short {
  font-size: clamp(0.82rem, 2.2vw, 0.95rem);
  color: #c8c0b0;
  line-height: 1.35;
}

/* Botón toggle (solo móvil) — anula estilos genéricos de button */
#info-toggle {
  display: none;
  background: rgba(255,255,255,0.08) !important;
  border: 1px solid rgba(255,200,80,0.35) !important;
  border-bottom: 1px solid rgba(255,200,80,0.35) !important;
  box-shadow: none !important;
  color: var(--gold) !important;
  border-radius: 50% !important;
  width: 30px !important;
  height: 30px !important;
  min-height: 30px !important;
  font-size: 0.85rem !important;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex: 0 0 30px !important;
  padding: 0 !important;
  transition: transform 0.3s ease, background 0.2s ease;
  letter-spacing: 0;
}

#info-toggle:hover {
  background: rgba(255,200,80,0.18) !important;
  transform: none !important;
  box-shadow: none !important;
}

/* Cuerpo del panel (descripción, funfact, dots) */
#panel-details {
  padding: 0 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#description {
  font-size: clamp(0.88rem, 2.3vw, 1rem);
  line-height: 1.55;
  color: #ddd;
}

/* Dato curioso */
#fun-fact {
  background: rgba(255, 200, 50, 0.09);
  border: 1px solid rgba(255, 200, 50, 0.28);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #f5d878;
}

#fun-fact::before {
  content: '⭐ ';
}

/* Dots de navegación de fase */
#phase-dots {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  align-items: center;
}

.phase-dot {
  background: none;
  border: none;
  border-bottom: none;
  box-shadow: none;
  padding: 1px 2px;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.38;
  transition: opacity 0.25s ease, transform 0.25s ease, filter 0.25s ease;
  line-height: 1;
  letter-spacing: 0;
}

.phase-dot:hover {
  opacity: 0.82;
  transform: scale(1.3);
  background: none;
  border-bottom: none;
  box-shadow: none;
}

.phase-dot.done   { opacity: 0.60; }

.phase-dot.active {
  opacity: 1;
  transform: scale(1.4);
  filter: drop-shadow(0 0 6px rgba(255, 210, 60, 0.95));
}

/* Pista de vista */
#view-hint {
  font-size: 0.80rem;
  color: var(--blue-hint);
  font-style: italic;
  line-height: 1.35;
}

/* Leyenda dentro del panel */
.legend-inline {
  display: flex;
  gap: 14px;
  font-size: 0.80rem;
  color: #aaa;
  flex-wrap: wrap;
  padding-top: 2px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* Sugerencia de interacción */
.hint-text {
  font-size: 0.80rem;
  color: #888;
  padding: 0 18px 14px;
  line-height: 1.35;
}

/* ---------- CONTROLES ---------- */
.controls {
  align-self: center;
  background: rgba(18, 14, 28, 0.90);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 12px 20px;
  border-radius: 50px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 200, 0.22);
  pointer-events: auto;
  max-width: min(96%, 780px);
  width: 100%;
}

button {
  border: none;
  color: white;
  padding: 10px 18px;
  border-radius: 36px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
  background: linear-gradient(135deg, var(--purple-md), var(--purple-dk));
  box-shadow: 0 3px 8px rgba(0,0,0,0.40);
  border-bottom: 2.5px solid #ffb347;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  min-height: 44px;
  white-space: nowrap;
}

button:hover {
  background: linear-gradient(135deg, #7b6aa2, #3e3458);
  border-bottom-color: #ffdd88;
  transform: translateY(-2px);
  box-shadow: 0 7px 14px rgba(0,0,0,0.50);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.50);
}

button.btn-active {
  background: linear-gradient(135deg, #2a6098, #153050);
  border-bottom-color: #66bbff;
}

button.btn-playing {
  background: linear-gradient(135deg, #883322, #4a1a0e);
  border-bottom-color: #ff9966;
}

/* Nav prev/next: tamaño fijo */
#prev-phase, #next-phase {
  flex: 0 0 auto;
  padding: 10px 16px;
}

/* Slider en el centro */
.slider-container {
  flex: 1 1 100px;
  max-width: 200px;    /* evita que se expanda demasiado */
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
}

input[type=range] {
  flex: 1;
  cursor: pointer;
  height: 6px;
  border-radius: 4px;
  accent-color: #ffaa33;
  min-width: 60px;
}

/* Vista y Auto no crecen más allá de su contenido */
#view-mode   { flex: 0 1 auto; }
#auto-rotate { flex: 0 1 auto; }

/* ============================================================
   RESPONSIVE — tablets y móviles
   ============================================================ */

/* Tabletas / móviles landscape anchos */
@media (max-width: 900px) {
  :root {
    --ui-top:    12px;
    --ui-side:   12px;
    --ui-bottom: 14px;
  }

  #info-panel {
    max-width: none;
    flex: 1 1 100%;
    border-radius: var(--radius-md);
  }

  #panel-header { padding: 12px 14px 10px; gap: 11px; }

  #phase-icon-wrap { width: 58px; height: 58px; }
  #phase-icon      { width: 50px; height: 50px; }

  #panel-details { padding: 0 14px 12px; gap: 8px; }

  .controls {
    padding: 10px 14px;
    gap: 8px;
    border-radius: 36px;
  }

  button { padding: 10px 14px; font-size: 0.88rem; }
}

/* Móviles pequeños en portrait */
@media (max-width: 600px) {
  :root {
    --ui-top:    8px;
    --ui-side:   8px;
    --ui-bottom: 10px;
  }

  /* El panel colapsa por defecto */
  #info-toggle { display: flex; }

  /* Icono más pequeño en móvil */
  #phase-icon-wrap { width: 50px !important; height: 50px !important; }
  #phase-icon      { width: 42px !important; height: 42px !important; }

  /* Texto de fase más compacto */
  #phase-name  { font-size: 1.15rem; }
  #phase-short { font-size: 0.78rem; }
  .phase-label { font-size: 0.75rem; }

  #panel-details {
    max-height: 0;
    padding-bottom: 0;
    gap: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, padding 0.35s ease;
  }

  /* Estado expandido */
  #info-panel.expanded #panel-details {
    max-height: 400px;
    padding: 0 14px 12px;
    gap: 8px;
  }

  #info-panel.expanded #info-toggle {
    transform: rotate(180deg);
  }

  .hint-text { display: none; }

  /* Los dots no heredan el flex 50% de los botones generales */
  .phase-dot {
    font-size: 1.1rem;
    flex: 0 0 auto !important;
    padding: 1px 2px !important;
    min-height: auto !important;
  }

  /* Controles en dos filas claras */
  .controls {
    padding: 8px 10px;
    gap: 7px;
    border-radius: 24px;
  }

  button {
    font-size: 0.82rem;
    padding: 9px 12px;
    flex: 1 1 calc(50% - 7px);
  }

  #prev-phase, #next-phase {
    flex: 0 0 calc(28% - 7px);
    padding: 9px 10px;
  }

  .slider-container {
    flex: 1 1 100%;
    order: -1;
  }

  #view-mode, #auto-rotate {
    flex: 1 1 calc(50% - 7px);
  }
}

/* Landscape en pantallas pequeñas (teléfonos girados) */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --ui-top:    6px;
    --ui-side:   10px;
    --ui-bottom: 8px;
  }

  #ui-layer {
    flex-direction: row;
    align-items: flex-end;
    flex-wrap: nowrap;
    gap: 8px;
  }

  #top-row {
    flex: 0 0 250px;
    align-self: flex-start;
    flex-direction: column;
  }

  .controls {
    flex: 1;
    align-self: flex-end;
    padding: 7px 10px;
    border-radius: 18px;
    flex-wrap: wrap;
  }

  #info-panel {
    border-radius: var(--radius-sm);
    max-width: none;
  }

  #panel-header { padding: 8px 10px 6px; }
  #phase-icon-wrap { width: 44px; height: 44px; }
  #phase-icon      { width: 38px; height: 38px; }
  #phase-name      { font-size: 1rem; }

  #panel-details {
    max-height: 0;
    overflow: hidden;
  }

  #info-toggle { display: none; }
  .hint-text   { display: none; }

  button {
    font-size: 0.78rem;
    padding: 7px 10px;
    min-height: 38px;
  }
}
