/* ===================================================
   Alueco Clock — Estilos principales
   Diseño: fantasía onírica, mobile-first
   =================================================== */

/* ---------- Variables ---------- */
:root {
  --bg:           #0d0a1a;
  --bg2:          #12102a;
  --accent:       #c8a96e;
  --accent2:      #7eb8a0;
  --accent-glow:  rgba(200, 169, 110, 0.35);
  --accent2-glow: rgba(126, 184, 160, 0.3);
  --text:         #e8ddd0;
  --text-dim:     #9a8f88;
  --timer-color:  #f0e6d0;
  --firefly:      #aaff88;
  --star:         #fff8e1;
  --fog-color:    rgba(200, 210, 240, 0.05);
  --cloak:        #2a2060;
  --cloak2:       #1a1545;
  --orb:          #ffd88a;
  --progress-from: #7eb8a0;
  --progress-to:  #c8a96e;
  --card-bg:      rgba(13, 10, 26, 0.82);
  --card-border:  rgba(200, 169, 110, 0.22);
  --radius:       1rem;
  --transition:   0.5s ease;
}

/* Mañana */
body.time--morning {
  --bg:           #1a120f;
  --bg2:          #221810;
  --fog-color:    rgba(255, 220, 160, 0.06);
  --accent:       #e0b070;
  --accent2:      #a0c8a0;
}

/* Tarde */
body.time--afternoon {
  --bg:           #0f1520;
  --bg2:          #12192a;
  --fog-color:    rgba(180, 200, 240, 0.06);
}

/* Noche */
body.time--night {
  --bg:           #07051a;
  --bg2:          #0d0a28;
  --fog-color:    rgba(140, 160, 220, 0.07);
  --accent:       #b89adc;
  --accent2:      #7eb8a0;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Georgia', 'Palatino Linotype', serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%; height: 100%;
}

/* ---------- Escena principal ---------- */
.scene {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 60%, var(--bg2) 0%, var(--bg) 75%);
  transition: background var(--transition);
}

/* ---------- Niebla ---------- */
.fog {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.fog-1 {
  background: radial-gradient(ellipse 80% 40% at 30% 60%, var(--fog-color), transparent 70%);
  animation: fogDrift1 18s ease-in-out infinite alternate;
}

.fog-2 {
  background: radial-gradient(ellipse 70% 35% at 70% 40%, var(--fog-color), transparent 70%);
  animation: fogDrift2 24s ease-in-out infinite alternate;
}

@keyframes fogDrift1 {
  from { transform: translateX(-8%) translateY(4%); opacity: 0.6; }
  to   { transform: translateX(8%)  translateY(-4%); opacity: 1; }
}
@keyframes fogDrift2 {
  from { transform: translateX(6%)  translateY(-3%); opacity: 0.8; }
  to   { transform: translateX(-6%) translateY(3%);  opacity: 0.4; }
}

/* ---------- Estrellas (solo noche) ---------- */
.stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: var(--star);
  animation: starTwinkle var(--dur, 3s) ease-in-out infinite alternate;
  opacity: 0;
}

@keyframes starTwinkle {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: var(--max-opacity, 0.8); transform: scale(1.1); }
}

/* ---------- ESCENA VACÍA ---------- */
.empty-scene {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  animation: fadeIn 1.2s ease;
}

.empty-echo {
  font-size: 5rem;
  color: var(--text-dim);
  opacity: 0.3;
  animation: echoFloat 6s ease-in-out infinite;
  letter-spacing: 0.5em;
}

@keyframes echoFloat {
  0%,100% { transform: translateY(0) scale(1);   opacity: 0.25; }
  50%      { transform: translateY(-12px) scale(1.05); opacity: 0.45; }
}

.empty-message {
  font-size: 1.15rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0 2rem;
  font-style: italic;
  letter-spacing: 0.03em;
  opacity: 0.7;
}

/* ---------- ESCENA ACTIVA ---------- */
.active-scene {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 420px;
  padding: 1rem 1.5rem 1.5rem;
  animation: fadeIn 0.8s ease;
}

/* Nombre */
.character-name {
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: -0.5rem;
}

/* Personaje */
.character-container {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 120px;
  animation: characterAppear 1s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes characterAppear {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.character-svg {
  animation: breathe 4s ease-in-out infinite;
  filter: drop-shadow(0 4px 16px rgba(200,169,110,0.15));
  cursor: pointer;
  transition: filter 0.3s;
}
.character-svg:hover,
.character-svg:active {
  filter: drop-shadow(0 4px 24px rgba(200,169,110,0.5));
}

@keyframes breathe {
  0%,100% { transform: scaleY(1)   translateY(0); }
  50%      { transform: scaleY(0.97) translateY(2px); }
}

.orb {
  position: absolute;
  right: -8px;
  bottom: 28px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe9a0 30%, #ffb830 100%);
  box-shadow: 0 0 12px 6px rgba(255,210,80,0.55);
  animation: orbFloat 3s ease-in-out infinite;
}

@keyframes orbFloat {
  0%,100% { transform: translateY(0)   scale(1);    box-shadow: 0 0 12px 6px rgba(255,210,80,0.55); }
  50%      { transform: translateY(-6px) scale(1.08); box-shadow: 0 0 18px 10px rgba(255,210,80,0.35); }
}

/* Temporizador */
.timer-display {
  font-size: clamp(3.5rem, 18vw, 5rem);
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-variant-numeric: tabular-nums;
  color: var(--timer-color);
  letter-spacing: 0.05em;
  line-height: 1;
  text-shadow: 0 0 32px var(--accent-glow), 0 0 8px rgba(255,255,255,0.08);
  transition: color 0.5s, text-shadow 0.5s;
}

.timer-display.urgent {
  color: #ffb87a;
  animation: timerPulse 1s ease-in-out infinite;
  text-shadow: 0 0 32px rgba(255,140,60,0.6), 0 0 8px rgba(255,255,255,0.1);
}

@keyframes timerPulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}

/* Barra de progreso */
.progress-bar-container {
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--progress-from), var(--progress-to));
  width: 0%;
  transition: width 1s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Reloj de arena */
.hourglass-container {
  cursor: pointer;
  transition: transform 0.3s;
  filter: drop-shadow(0 2px 10px rgba(200,169,110,0.2));
}
.hourglass-container:hover,
.hourglass-container:active {
  transform: scale(1.12);
  filter: drop-shadow(0 2px 20px rgba(200,169,110,0.5));
}

/* Caja de mensaje */
.message-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 0.85rem 1.2rem;
  text-align: center;
  width: 100%;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
  font-style: italic;
  letter-spacing: 0.02em;
  transition: opacity 0.4s ease;
}

.message-text.fade-out { opacity: 0; }
.message-text.fade-in  { opacity: 1; }

/* Botón ánimo */
.btn-encourage {
  background: transparent;
  border: 1px solid var(--card-border);
  border-radius: 99px;
  color: var(--accent);
  padding: 0.55rem 1.4rem;
  font-family: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.25s, box-shadow 0.25s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-encourage:hover {
  background: rgba(200,169,110,0.08);
  box-shadow: 0 0 12px var(--accent-glow);
}
.btn-encourage:focus-visible,
.bell-btn:focus-visible,
.sound-toggle:focus-visible,
.character-svg:focus-visible,
.hourglass-container:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.btn-encourage:active {
  transform: scale(0.95);
}

/* Texto discreto */
.hint-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  opacity: 0.5;
  letter-spacing: 0.03em;
}

/* Campana / objeto mágico */
.bell-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.6rem;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
  -webkit-tap-highlight-color: transparent;
  padding: 0.25rem;
}
.bell-btn:hover  { opacity: 0.9; }
.bell-btn:active { transform: scale(0.9) rotate(-15deg); }

/* Fila de acciones */
.action-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ---------- ESCENA COMPLETA ---------- */
.complete-scene {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 2rem 1.5rem;
  animation: fadeIn 1s ease;
  max-width: 420px;
  text-align: center;
}

.celebration {
  font-size: 4rem;
  animation: celebrationSpin 3s linear infinite, celebrationGlow 2s ease-in-out infinite alternate;
  color: var(--accent);
}

@keyframes celebrationSpin {
  from { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(1.15); }
  to   { transform: rotate(360deg) scale(1); }
}
@keyframes celebrationGlow {
  from { text-shadow: 0 0 20px var(--accent-glow); }
  to   { text-shadow: 0 0 50px rgba(200,169,110,0.8), 0 0 80px rgba(200,169,110,0.3); }
}

.complete-stars {
  display: flex;
  gap: 0.5rem;
  font-size: 1.4rem;
  color: var(--accent);
  animation: starsAppear 0.8s ease both;
}
@keyframes starsAppear {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 1; transform: scale(1); }
}

.complete-message {
  font-size: 1.35rem;
  color: var(--text);
  font-style: italic;
  letter-spacing: 0.03em;
  line-height: 1.4;
}

.restart-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
  opacity: 0.65;
  letter-spacing: 0.02em;
  line-height: 1.6;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  background: var(--card-bg);
}

/* ---------- Luciérnagas ---------- */
.fireflies {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.firefly {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--firefly);
  box-shadow: 0 0 8px 3px rgba(170, 255, 136, 0.6);
  animation: fireflyFloat var(--dur, 4s) ease-in-out infinite alternate;
  opacity: 0;
}

@keyframes fireflyFloat {
  0%   { opacity: 0;   transform: translate(0, 0) scale(0.7); }
  20%  { opacity: 0.9; }
  80%  { opacity: 0.7; }
  100% { opacity: 0;   transform: translate(var(--tx, 20px), var(--ty, -20px)) scale(1.2); }
}

/* ---------- Botón de sonido ---------- */
.sound-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  z-index: 100;
  transition: background 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.6;
}
.sound-toggle:hover { opacity: 1; box-shadow: 0 0 10px var(--accent-glow); }

/* ---------- Badge franja horaria ---------- */
.time-slot-badge {
  position: fixed;
  top: 1rem;
  left: 1rem;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.45;
  z-index: 100;
}

/* ---------- Estado de carga ---------- */
.loading-scene {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(200,169,110,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  opacity: 0.6;
}

/* ---------- Error / mensaje ---------- */
.error-message {
  background: var(--card-bg);
  border: 1px solid rgba(200,100,100,0.3);
  border-radius: var(--radius);
  padding: 1rem 1.4rem;
  font-size: 0.9rem;
  color: #d4a0a0;
  text-align: center;
  max-width: 320px;
  z-index: 10;
  position: relative;
  line-height: 1.5;
}

/* ---------- Animación general ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive (escritorio) ---------- */
@media (min-width: 600px) {
  .active-scene,
  .complete-scene {
    max-width: 480px;
    padding: 2rem 2.5rem;
  }
  .timer-display {
    font-size: 5rem;
  }
  .character-container {
    height: 140px;
  }
}

/* ---------- Accesibilidad ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
