/* Loading page - Canvas painting effect */

/* 
 * SISTEMA DE LOADING ANTI-FOUC
 * 
 * Fluxo:
 * 1. Loading começa INVISÍVEL (opacity: 0, visibility: hidden)
 * 2. JS verifica se é primeira visita da sessão
 * 3. Se primeira visita: adiciona .active (loading aparece)
 * 4. Após animação: adiciona .completed (fade-out 0.25s)
 * 5. Demais visitas: remove loading ANTES do primeiro frame
 */

/* ========== CONTAINER PRINCIPAL ========== */
.loading-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #f5f1e8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 99999;
  
  /* INVISÍVEL POR PADRÃO - Nunca pisca! */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ========== ESTADO ATIVO ========== */
/* Só o JS adiciona esta classe na primeira visita */
.loading-container.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ========== ESTADO COMPLETADO (FADE-OUT) ========== */
/* Animação única de saída - 0.25s */
.loading-container.completed {
  animation: canvasFadeOut 0.25s ease-out forwards;
  pointer-events: none;
}

/* Keyframe única para fade-out */
@keyframes canvasFadeOut {
  0% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

/* Canvas - camada de pintura */
#paintCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 99998;
}

/* Textura de tela */
#paintCanvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,0,0,.02) 2px, rgba(0,0,0,.02) 4px),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.02) 2px, rgba(0,0,0,.02) 4px);
  pointer-events: none;
  z-index: 99999;
}

/* Camadas escondidas (para carregar imagens) */
.painting-layers {
  display: none;
}

.paint-layer {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Info do loading */
.loading-info {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 99999;
  pointer-events: none;
  width: 80%;
  max-width: 400px;
}

.painting-text {
  color: #333;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 20px;
  opacity: 0.9;
}

/* Barra de progresso visual */
.loading-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 15px;
}

.loading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8B7355, #D4AF37, #8B7355);
  background-size: 200% 100%;
  animation: progressShine 2s linear infinite;
  border-radius: 3px;
  transition: width 0.3s ease-out;
}

@keyframes progressShine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-value {
  color: #333;
  font-size: 24px;
  font-weight: 900;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}

/* Fade out dos textos */
.loading-container.completed .loading-info {
  animation: fadeOutInfo 0.2s ease-out forwards;
}

@keyframes fadeOutInfo {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* SVG Filter para textura */
svg {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .painting-text {
    font-size: 14px;
  }

  .progress-value {
    font-size: 20px;
  }

  .loading-info {
    bottom: 40px;
  }
}

@media (max-width: 480px) {
  .painting-text {
    font-size: 12px;
    letter-spacing: 1px;
  }

  .progress-value {
    font-size: 18px;
  }

  .loading-info {
    bottom: 30px;
  }
}
