/* ============================================================
   APEX LOADER — cinematic page loader
   3 concentric rotating rings + pulsing logo + glow + progress
   ============================================================ */

.apex-loader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #050308;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  overflow: hidden;
  isolation: isolate;
  transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.8s, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.apex-loader.expand {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.15);
  pointer-events: none;
}

/* Atmospheric background */
.apex-loader__bg {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 60% 50% at 50% 50%, rgba(var(--theme-primary-rgb), 0.22), transparent 65%),
    radial-gradient(ellipse 40% 40% at 30% 70%, rgba(var(--theme-accent-rgb), 0.12), transparent 60%),
    radial-gradient(ellipse 40% 40% at 70% 30%, rgba(124, 58, 237, 0.08), transparent 60%);
  animation: loaderAtmos 6s ease-in-out infinite alternate;
}
@keyframes loaderAtmos {
  from { transform: scale(1)   rotate(0deg); }
  to   { transform: scale(1.1) rotate(2deg); }
}
.apex-loader::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black, transparent 75%);
  z-index: -1;
  animation: loaderGrid 24s linear infinite;
}
@keyframes loaderGrid { to { transform: translate(60px, 60px); } }

/* Core: logo + rings */
.apex-loader__core {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apex-loader__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

.apex-loader__ring--1 {
  border: 2px solid transparent;
  border-top-color: var(--theme-primary);
  border-right-color: rgba(var(--theme-primary-rgb), 0.4);
  animation: ringSpin 2.2s cubic-bezier(0.6, 0.05, 0.4, 0.95) infinite;
  box-shadow: 0 0 30px rgba(var(--theme-primary-rgb), 0.4);
}
.apex-loader__ring--2 {
  inset: 12px;
  border: 1px dashed rgba(var(--theme-accent-rgb), 0.5);
  animation: ringSpin 3.4s linear infinite reverse;
}
.apex-loader__ring--3 {
  inset: 24px;
  border: 1px solid rgba(var(--theme-primary-rgb), 0.15);
  animation: ringPulse 2.4s ease-in-out infinite;
}

@keyframes ringSpin {
  to { transform: rotate(360deg); }
}
@keyframes ringPulse {
  0%, 100% { transform: scale(1);    opacity: 0.6; }
  50%      { transform: scale(1.08); opacity: 1; }
}

.apex-loader__logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  filter: drop-shadow(0 8px 36px rgba(var(--theme-primary-rgb), 0.55));
  animation: logoBeat 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  position: relative;
  z-index: 2;
}
@keyframes logoBeat {
  0%, 100% { transform: scale(1)     rotate(0deg);   filter: drop-shadow(0 8px 36px rgba(var(--theme-primary-rgb), 0.5)); }
  20%      { transform: scale(1.08)  rotate(-3deg);  filter: drop-shadow(0 12px 50px rgba(var(--theme-primary-rgb), 0.8)); }
  40%      { transform: scale(0.98)  rotate(0deg);   filter: drop-shadow(0 8px 36px rgba(var(--theme-primary-rgb), 0.5)); }
  60%      { transform: scale(1.04)  rotate(3deg);   filter: drop-shadow(0 12px 50px rgba(var(--theme-primary-rgb), 0.8)); }
}

.apex-loader__glow {
  position: absolute;
  inset: 30px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--theme-primary-rgb), 0.45), transparent 70%);
  filter: blur(24px);
  z-index: 1;
  animation: glowPulse 1.4s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.95); }
  50%      { opacity: 0.9; transform: scale(1.1); }
}

/* Brand text */
.apex-loader__brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.apex-loader__brand-text {
  font-family: 'Big Shoulders Display', 'Impact', sans-serif;
  font-weight: 900;
  font-size: clamp(2.5rem, 5vw, 4rem);
  letter-spacing: -0.03em;
  line-height: 1;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff 30%, var(--theme-primary) 80%, var(--theme-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 40px rgba(var(--theme-primary-rgb), 0.4));
  animation: brandReveal 0.8s 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.apex-loader__brand-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--theme-primary);
  opacity: 0.8;
  animation: brandReveal 0.8s 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes brandReveal {
  from { opacity: 0; transform: translateY(20px); letter-spacing: 0.5em; }
  to   { opacity: 1; transform: translateY(0); }
}

/* Progress bar */
.apex-loader__progress {
  width: min(320px, 70vw);
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  margin-top: 6px;
}
.apex-loader__progress-bar {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--theme-primary) 30%,
    var(--theme-accent) 50%,
    var(--theme-primary) 70%,
    transparent 100%);
  background-size: 200% 100%;
  animation: progressSweep 1.6s linear infinite;
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(var(--theme-primary-rgb), 0.6);
}
@keyframes progressSweep {
  from { background-position: -200% 0; transform: translateX(-100%); }
  to   { background-position: 200% 0;  transform: translateX(100%); }
}

/* Hint text — typewriter effect */
.apex-loader__hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 0.5rem;
  min-height: 1em;
  animation: hintBlink 1.4s ease-in-out infinite;
}
.apex-loader__hint::after {
  content: "▌";
  display: inline-block;
  margin-left: 4px;
  color: var(--theme-primary);
  animation: cursorBlink 0.8s steps(1) infinite;
}
@keyframes hintBlink {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}
@keyframes cursorBlink {
  50% { opacity: 0; }
}

/* Mobile */
@media (max-width: 640px) {
  .apex-loader__core { width: 160px; height: 160px; }
  .apex-loader__logo { width: 80px; height: 80px; }
  .apex-loader__brand-text { font-size: 2.2rem; }
}
