/**
 * Global Loader - Spaceship Animation
 * Inspired by Mr. Alien's Redirecting Loader
 */

/* Global Loader Container */
.global-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.3s ease-out;
}

.global-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.global-loader h1 {
  position: absolute;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  left: 50%;
  top: 58%;
  margin-left: -30px;
  color: var(--text-primary);
  letter-spacing: 0.1em;
}

/* Spaceship Container */
.loader-spaceship {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -50px;
  transform: translateY(-50%);
  animation: speeder 0.4s linear infinite;
}

/* Spaceship Body */
.loader-body {
  position: relative;
}

.loader-body > span {
  height: 5px;
  width: 35px;
  background: var(--accent-blue);
  position: absolute;
  top: -19px;
  left: 60px;
  border-radius: 2px 10px 1px 0;
}

/* Base */
.loader-base {
  position: absolute;
  top: 0;
  left: 0;
}

.loader-base span {
  position: absolute;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-right: 100px solid var(--accent-blue);
  border-bottom: 6px solid transparent;
}

.loader-base span::before {
  content: "";
  height: 22px;
  width: 22px;
  border-radius: 50%;
  background: var(--accent-blue);
  position: absolute;
  right: -110px;
  top: -16px;
}

.loader-base span::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-right: 55px solid var(--accent-blue);
  border-bottom: 16px solid transparent;
  top: -16px;
  right: -98px;
}

/* Face */
.loader-face {
  position: absolute;
  height: 12px;
  width: 20px;
  background: var(--accent-blue);
  border-radius: 20px 20px 0 0;
  transform: rotate(-40deg);
  right: -125px;
  top: -15px;
}

.loader-face::after {
  content: "";
  height: 12px;
  width: 12px;
  background: var(--accent-blue);
  right: 4px;
  top: 7px;
  position: absolute;
  transform: rotate(40deg);
  transform-origin: 50% 50%;
  border-radius: 0 0 0 2px;
}

/* Fazers (trail lines) */
.loader-body > span > span:nth-child(1),
.loader-body > span > span:nth-child(2),
.loader-body > span > span:nth-child(3),
.loader-body > span > span:nth-child(4) {
  width: 30px;
  height: 1px;
  background: var(--accent-blue);
  position: absolute;
  animation: fazer1 0.2s linear infinite;
}

.loader-body > span > span:nth-child(2) {
  top: 3px;
  animation: fazer2 0.4s linear infinite;
}

.loader-body > span > span:nth-child(3) {
  top: 1px;
  animation: fazer3 0.4s linear infinite;
  animation-delay: -1s;
}

.loader-body > span > span:nth-child(4) {
  top: 4px;
  animation: fazer4 1s linear infinite;
  animation-delay: -1s;
}

@keyframes fazer1 {
  0% {
    left: 0;
  }
  100% {
    left: -80px;
    opacity: 0;
  }
}

@keyframes fazer2 {
  0% {
    left: 0;
  }
  100% {
    left: -100px;
    opacity: 0;
  }
}

@keyframes fazer3 {
  0% {
    left: 0;
  }
  100% {
    left: -50px;
    opacity: 0;
  }
}

@keyframes fazer4 {
  0% {
    left: 0;
  }
  100% {
    left: -150px;
    opacity: 0;
  }
}

@keyframes speeder {
  0% {
    transform: translate(2px, 1px) rotate(0deg);
  }
  10% {
    transform: translate(-1px, -3px) rotate(-1deg);
  }
  20% {
    transform: translate(-2px, 0px) rotate(1deg);
  }
  30% {
    transform: translate(1px, 2px) rotate(0deg);
  }
  40% {
    transform: translate(1px, -1px) rotate(1deg);
  }
  50% {
    transform: translate(-1px, 3px) rotate(-1deg);
  }
  60% {
    transform: translate(-1px, 1px) rotate(0deg);
  }
  70% {
    transform: translate(3px, 1px) rotate(-1deg);
  }
  80% {
    transform: translate(-2px, -1px) rotate(1deg);
  }
  90% {
    transform: translate(2px, 1px) rotate(0deg);
  }
  100% {
    transform: translate(1px, -2px) rotate(-1deg);
  }
}

/* Long Fazers (background streaks) */
.loader-longfazers {
  position: absolute;
  width: 100%;
  height: 100%;
}

.loader-longfazers span {
  position: absolute;
  height: 2px;
  width: 20%;
  background: var(--accent-blue);
  opacity: 0.6;
}

.loader-longfazers span:nth-child(1) {
  top: 20%;
  animation: lf 0.6s linear infinite;
  animation-delay: -5s;
}

.loader-longfazers span:nth-child(2) {
  top: 40%;
  animation: lf2 0.8s linear infinite;
  animation-delay: -1s;
}

.loader-longfazers span:nth-child(3) {
  top: 60%;
  animation: lf3 0.6s linear infinite;
}

.loader-longfazers span:nth-child(4) {
  top: 80%;
  animation: lf4 0.5s linear infinite;
  animation-delay: -3s;
}

@keyframes lf {
  0% {
    left: 200%;
  }
  100% {
    left: -200%;
    opacity: 0;
  }
}

@keyframes lf2 {
  0% {
    left: 200%;
  }
  100% {
    left: -200%;
    opacity: 0;
  }
}

@keyframes lf3 {
  0% {
    left: 200%;
  }
  100% {
    left: -100%;
    opacity: 0;
  }
}

@keyframes lf4 {
  0% {
    left: 200%;
  }
  100% {
    left: -100%;
    opacity: 0;
  }
}

/* Hide body content while loading */
body.loading {
  overflow: hidden;
}

body.loading > *:not(.global-loader) {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
  transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
}

body.loaded > *:not(.global-loader) {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease-in, visibility 0.3s ease-in;
}

/* Responsive */
@media (max-width: 768px) {
  .global-loader h1 {
    font-size: 10px;
    margin-left: -25px;
  }
  
  .loader-spaceship {
    transform: translateY(-50%) scale(0.8);
  }
}
