/*
 * Fundo vivo do painel (entrada e dashboard): a imagem fun3.jpg fixa atrás de tudo, mais escura, com
 * a morte "respirando" (recorte fundo-morte.png por cima da própria imagem), luz pulsando atrás da árvore,
 * névoa passando rente ao chão e partículas (canvas, js/fundo-vivo.js).
 * Fica em z-index -1 direto no <body>: abaixo do conteúdo e sem criar camada nova (modais continuam por cima).
 * Quem pediu menos movimento no sistema (prefers-reduced-motion) vê só a imagem parada.
 */
body { background: #000; }
.main-wrapper .page-wrapper { background: transparent; }

.fundo-vivo {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: #000;
}

/* quadro = a imagem inteira (1661x751), no mesmo lugar de antes: largura da área de conteúdo, logo abaixo do topo */
.fundo-vivo__quadro {
  position: absolute;
  top: 60px;
  left: 240px;
  right: 0;
  aspect-ratio: 1661 / 751;
  /* fundo-vivo.jpg = fun3.jpg sem a árvore (céu estimado no lugar); a árvore vem por cima em .fundo-vivo__arvore */
  background: url('/images/fundo-vivo.jpg') 0 0 / 100% 100% no-repeat;
}

/* a árvore: silhueta preta. Com JS, vira um canvas onde os galhos mexem com a brisa e o tronco fica parado
   (js/fundo-vivo.js); sem JS ou com menos movimento, fica esta imagem parada */
.fundo-vivo__arvore {
  position: absolute;
  left: 39.735%;
  top: 19.973%;
  width: 59.603%;
  height: 74.567%;
  background: url('/images/fundo-arvore.png') 0 0 / 100% 100% no-repeat;
}
.fundo-vivo__arvore--viva { background: none; }
.fundo-vivo__arvore-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sidebar-folded .fundo-vivo__quadro { left: 70px; }
@media (max-width: 991px) { .fundo-vivo__quadro { left: 0; } }

/* entrada (login/registro/recuperação): cobre a tela toda, centralizada no alto */
.fundo-vivo--entrada .fundo-vivo__quadro {
  top: 0;
  left: 50%;
  right: auto;
  width: max(100vw, calc(100vh * 1661 / 751));
  transform: translateX(-50%);
}

/* a morte: recorte exato da silhueta por cima dela mesma; só cresce (>= 1), então nunca aparece a original por baixo */
.fundo-vivo__morte {
  position: absolute;
  left: 18.664%;
  top: 60.586%;
  width: 21.674%;
  height: 34.62%;
  background: url('/images/fundo-morte.png') 0 0 / 100% 100% no-repeat;
  transform-origin: 61% 94%;
  animation: fv-respira 6s ease-in-out infinite;
  will-change: transform;
}
@keyframes fv-respira {
  0%, 100% { transform: scale(1, 1) skewX(0deg); }
  42% { transform: scale(1.012, 1.03) skewX(-0.9deg); }
  60% { transform: scale(1.01, 1.025) skewX(-0.7deg); }
}

/* brilho vermelho fraco sob o capuz, acompanhando a respiração */
.fundo-vivo__olhar {
  position: absolute;
  left: 55.2%;
  top: 15.4%;
  width: 2.2%;
  height: 1.4%;
  border-radius: 50%;
  background: #ff2a2a;
  box-shadow: 0 0 6px 2px rgba(255, 30, 30, 0.75), 0 0 18px 6px rgba(200, 0, 0, 0.35);
  opacity: 0.25;
  animation: fv-olhar 6s ease-in-out infinite;
}
@keyframes fv-olhar {
  0%, 100% { opacity: 0.2; }
  45% { opacity: 0.85; }
}

/* brilho rápido na lâmina da foice de vez em quando (dentro da morte: acompanha a respiração) */
.fundo-vivo__foice {
  position: absolute;
  left: 20.8%;
  top: 12.3%;
  width: 7%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 6%, rgba(200, 235, 255, 0.4) 14%, transparent 34%),
    linear-gradient(90deg, transparent 0 46%, rgba(220, 240, 255, 0.85) 50%, transparent 54% 100%),
    linear-gradient(0deg, transparent 0 47%, rgba(220, 240, 255, 0.7) 50%, transparent 53% 100%);
  opacity: 0;
  animation: fv-foice 9s ease-in-out infinite 3s;
}
@keyframes fv-foice {
  0%, 82%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(0deg); }
  87% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(25deg); }
  93% { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotate(45deg); }
}

/* raios de luz saindo da luz atrás da árvore para o céu (só para cima), girando bem devagar.
   A caixa é a metade de cima de um círculo com o centro (base) na luz. */
.fundo-vivo__raios {
  position: absolute;
  left: 69%;
  top: 74%;
  width: 70%;
  aspect-ratio: 2 / 1;
  transform: translate(-50%, -100%);
  transform-origin: 50% 100%;
  background: repeating-conic-gradient(from 0deg at 50% 100%, rgba(255, 238, 200, 0.09) 0deg 2.5deg, transparent 2.5deg 11deg);
  -webkit-mask-image: radial-gradient(circle farthest-side at 50% 100%, #000 8%, rgba(0, 0, 0, 0.5) 45%, transparent 100%);
  mask-image: radial-gradient(circle farthest-side at 50% 100%, #000 8%, rgba(0, 0, 0, 0.5) 45%, transparent 100%);
  mix-blend-mode: screen;
  animation: fv-raios 40s ease-in-out infinite alternate, fv-luz 9s ease-in-out infinite;
}
@keyframes fv-raios {
  from { transform: translate(-50%, -100%) rotate(-6deg); }
  to { transform: translate(-50%, -100%) rotate(6deg); }
}

/* luz atrás do tronco da árvore pulsando devagar */
.fundo-vivo__luz {
  position: absolute;
  left: 69%;
  top: 74%;
  width: 30%;
  height: 46%;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(255, 236, 190, 0.32), rgba(160, 220, 200, 0.1) 55%, transparent 100%);
  mix-blend-mode: screen;
  animation: fv-luz 9s ease-in-out infinite;
}
@keyframes fv-luz {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.85; }
}

/* escurece tudo um pouco + bordas mais escuras */
.fundo-vivo__escuro {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(0, 0, 0, 0.55) 100%),
    rgba(0, 0, 0, 0.38);
}

/* névoa: duas faixas largas passando rente ao chão em velocidades diferentes */
.fundo-vivo__nevoa {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 200%;
  height: 55%;
  background:
    radial-gradient(ellipse 18% 32% at 16% 78%, rgba(170, 205, 200, 0.10), transparent 70%),
    radial-gradient(ellipse 22% 28% at 32% 86%, rgba(150, 190, 190, 0.08), transparent 70%),
    radial-gradient(ellipse 16% 30% at 55% 80%, rgba(170, 205, 200, 0.09), transparent 70%),
    radial-gradient(ellipse 24% 26% at 80% 88%, rgba(150, 190, 190, 0.08), transparent 70%);
  background-size: 50% 100%;
  background-repeat: repeat-x;
  animation: fv-nevoa 70s linear infinite;
  will-change: transform;
}
.fundo-vivo__nevoa--2 {
  height: 40%;
  opacity: 0.8;
  animation-duration: 110s;
  animation-direction: reverse;
  background:
    radial-gradient(ellipse 20% 30% at 18% 85%, rgba(190, 215, 210, 0.08), transparent 70%),
    radial-gradient(ellipse 18% 26% at 45% 90%, rgba(160, 200, 195, 0.07), transparent 70%),
    radial-gradient(ellipse 22% 32% at 70% 84%, rgba(190, 215, 210, 0.08), transparent 70%),
    radial-gradient(ellipse 16% 24% at 86% 90%, rgba(160, 200, 195, 0.07), transparent 70%);
  background-size: 50% 100%;
}
/* a faixa tem 2 telas de largura com o desenho repetido a cada tela e anda uma tela: o loop não dá pulo */
@keyframes fv-nevoa {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.fundo-vivo__particulas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

@media (prefers-reduced-motion: reduce) {
  .fundo-vivo__morte, .fundo-vivo__olhar, .fundo-vivo__luz, .fundo-vivo__raios, .fundo-vivo__nevoa { animation: none; }
  .fundo-vivo__foice { display: none; }
  .fundo-vivo__particulas { display: none; }
}
