/* Intro loading screen */
.site-loader {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  background: radial-gradient(circle at center, rgba(30, 90, 180, 0.1), transparent 55%), #02040a;
  font-family: "Courier New", monospace;
  animation: site-loader-bg-flicker 0.15s infinite steps(2);
}

/* Hide main page content until CRT effect completes */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 999998;
  background: #000;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

body.crt-started::before {
  opacity: 0;
}

body.crt-complete::before {
  display: none;
}

/* Freeze all animations and transitions until ready */
body:not(.crt-complete) * {
  animation-play-state: paused !important;
  transition: none !important;
}

/* Allow only loading screen animations */
body:not(.crt-complete) .site-loader,
body:not(.crt-complete) .site-loader *,
body:not(.crt-complete) .crt-tv-effect,
body:not(.crt-complete) .crt-tv-effect * {
  animation-play-state: running !important;
}

/* Prevent pointer events on main content during loading */
body:not(.crt-complete) .perspective,
body:not(.crt-complete) .container,
body:not(.crt-complete) .l-viewport {
  pointer-events: none !important;
  user-select: none !important;
}

.site-loader::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.35;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 4px);
  animation: site-loader-scanlines 8s linear infinite;
}

.site-loader::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.08;
  background: linear-gradient(to bottom, transparent 0%, rgba(255, 255, 255, 0.15) 50%, transparent 100%);
  animation: site-loader-vertical-glitch 0.3s infinite steps(3);
}

.site-loader__content {
  position: relative;
  z-index: 1;
  width: min(760px, 85vw);
  text-align: center;
}

/* Terminal console in top-left */
.site-loader__terminal {
  position: fixed;
  top: 25px;
  left: 25px;
  z-index: 2;
  max-width: 450px;
  color: #00d4ff;
  font-family: "Courier New", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.6;
  text-align: left;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.8), 0 0 15px rgba(0, 150, 255, 0.5);
}

.site-loader__terminal-line {
  opacity: 0;
  animation: terminal-line-appear 0.3s ease forwards;
  white-space: nowrap;
  overflow: hidden;
}

.site-loader__terminal-line--typing {
  animation: terminal-typing 0.05s steps(1) infinite;
}

.site-loader__terminal-line .terminal-cursor {
  display: inline-block;
  width: 8px;
  height: 12px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: #00d4ff;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.8);
  animation: terminal-cursor-blink 0.8s infinite;
}

.site-loader__terminal-line .terminal-prompt {
  color: #00d4ff;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.9), 0 0 15px rgba(0, 150, 255, 0.6);
}

.site-loader__terminal-line .terminal-success {
  color: #5cc8ff;
  text-shadow: 0 0 8px rgba(92, 200, 255, 0.8), 0 0 15px rgba(0, 150, 255, 0.5);
}

.site-loader__terminal-line .terminal-warning {
  color: #00b8ff;
  text-shadow: 0 0 8px rgba(0, 184, 255, 0.8), 0 0 15px rgba(0, 150, 255, 0.5);
}

.site-loader__terminal-line .terminal-info {
  color: #00e4ff;
  text-shadow: 0 0 8px rgba(0, 228, 255, 0.8), 0 0 15px rgba(0, 180, 255, 0.5);
}

.site-loader__terminal-line .terminal-error {
  color: #0099ff;
  text-shadow: 0 0 8px rgba(0, 153, 255, 0.8), 0 0 15px rgba(0, 120, 255, 0.5);
}

.site-loader__label {
  margin-bottom: 20px;
  color: #a8d8ff;
  font-size: 12px;
  letter-spacing: 0.35em;
  text-shadow: 0 0 8px rgba(110, 190, 255, 0.65);
}

.site-loader__word {
  position: relative;
  display: inline-block;
  min-width: 350px;
  color: #fff;
  font-size: clamp(48px, 8vw, 100px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.06em;
  text-shadow: 0 0 5px #fff, 0 0 15px rgba(120, 190, 255, 0.95), 0 0 35px rgba(50, 140, 255, 0.6);
  will-change: transform, filter, opacity;
}

.site-loader__word::before,
.site-loader__word::after {
  position: absolute;
  inset: 0;
  content: attr(data-text);
  pointer-events: none;
  opacity: 0;
}

.site-loader__word::before {
  color: #3c9dff;
  transform: translateX(-4px);
  clip-path: inset(0 0 60% 0);
}

.site-loader__word::after {
  color: #d7f0ff;
  transform: translateX(4px);
  clip-path: inset(60% 0 0 0);
}

.site-loader__word.is-glitching {
  animation: site-loader-glitch-main 360ms steps(2, end);
}

.site-loader__word.is-glitching::before {
  opacity: 0.9;
  animation: site-loader-glitch-top 360ms steps(2, end);
}

.site-loader__word.is-glitching::after {
  opacity: 0.8;
  animation: site-loader-glitch-bottom 360ms steps(2, end);
}

.site-loader__glitch-bars {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to bottom, transparent 0 44%, rgba(110, 190, 255, 0.18) 44.3% 45%, transparent 45% 61%, rgba(255, 255, 255, 0.12) 61.3% 62%, transparent 62% 78%, rgba(70, 150, 255, 0.15) 78.4% 79%, transparent 79%);
}

.site-loader__word.is-glitching .site-loader__glitch-bars {
  opacity: 1;
  animation: site-loader-bar-glitch 360ms steps(2, end);
}

.site-loader__cursor {
  display: inline-block;
  width: 7px;
  height: 0.8em;
  margin-left: 8px;
  vertical-align: 0.02em;
  background: #fff;
  box-shadow: 0 0 8px #a8d8ff, 0 0 18px #4f9cff;
  animation: site-loader-cursor-blink 0.7s infinite;
}

.site-loader__progress-area { margin-top: 42px; }

.site-loader__progress-value {
  margin-bottom: 10px;
  color: #d4ecff;
  font-size: 14px;
  letter-spacing: 0.15em;
  text-shadow: 0 0 10px rgba(100, 190, 255, 0.75);
}

.site-loader__progress-track {
  position: relative;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(150, 210, 255, 0.55);
  background: rgba(255, 255, 255, 0.035);
  box-shadow: 0 0 10px rgba(70, 150, 255, 0.2);
}

.site-loader__progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(to right, #fff, #a8dcff, #368fff);
  box-shadow: 0 0 8px #fff, 0 0 18px #4ca1ff;
  transition: width 0.15s linear;
}

.site-loader__progress-scan {
  position: absolute;
  top: 0;
  left: -60px;
  width: 55px;
  height: 100%;
  filter: blur(2px);
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.9), transparent);
  animation: site-loader-progress-scan 1.2s linear infinite;
}

.site-loader__status {
  margin-top: 13px;
  color: rgba(190, 220, 250, 0.65);
  font-size: 10px;
  letter-spacing: 0.22em;
}

.site-loader__corner {
  position: absolute;
  width: 110px;
  height: 110px;
  opacity: 0.65;
  border-color: rgba(100, 180, 255, 0.35);
}

.site-loader__corner--top-left {
  top: 25px;
  left: 25px;
  border-top: 1px solid;
  border-left: 1px solid;
}

.site-loader__corner--bottom-right {
  right: 25px;
  bottom: 25px;
  border-right: 1px solid;
  border-bottom: 1px solid;
}

.site-loader__line {
  position: absolute;
  height: 1px;
  opacity: 0.25;
  background: linear-gradient(to right, transparent, rgba(100, 180, 255, 0.9), #fff, rgba(100, 180, 255, 0.9), transparent);
  animation: site-loader-line-glitch 2.2s linear infinite;
  filter: blur(0.5px);
}

.site-loader__line--one { 
  top: 24%; 
  left: 5%; 
  width: 30%;
  animation: site-loader-line-glitch 1.8s linear infinite, site-loader-line-flicker 0.25s infinite steps(4);
}

.site-loader__line--two { 
  top: 72%; 
  right: 8%; 
  width: 18%; 
  animation: site-loader-line-glitch 1.8s linear infinite 0.8s, site-loader-line-flicker 0.3s infinite steps(3) 0.1s;
}

.site-loader__line--three { 
  top: 81%; 
  left: 15%; 
  width: 22%; 
  animation: site-loader-line-glitch 1.8s linear infinite 1.3s, site-loader-line-flicker 0.35s infinite steps(5) 0.2s;
}

.site-loader.is-finished { animation: site-loader-fade-out 650ms ease forwards; }

/* CRT TV Turn On Effect */
.crt-tv-effect {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
  opacity: 0;
}

.crt-tv-effect.is-active {
  opacity: 1;
}

.crt-tv-effect__screen {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.95) 0%, rgba(224, 224, 224, 0.85) 15%, rgba(136, 136, 136, 0.6) 40%, rgba(0, 0, 0, 0.3) 70%);
  opacity: 0;
  mix-blend-mode: screen;
}

.crt-tv-effect.is-flashing .crt-tv-effect__screen {
  animation: crt-flash-blend 900ms ease-out forwards;
}

.crt-tv-effect__line {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 100vh;
  transform: translateY(-50%) scaleY(0);
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.9) 0%, rgba(200, 230, 255, 0.7) 30%, rgba(100, 180, 255, 0.4) 60%, transparent 100%);
  box-shadow: 0 0 60px 30px rgba(255, 255, 255, 0.6);
  mix-blend-mode: screen;
}

.crt-tv-effect.is-collapsing .crt-tv-effect__line {
  animation: crt-line-collapse-blend 700ms ease-in forwards 350ms;
}

.crt-tv-effect__scanline {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 2px,
    transparent 4px
  );
  opacity: 0;
  mix-blend-mode: multiply;
}

.crt-tv-effect.is-active .crt-tv-effect__scanline {
  opacity: 0.7;
  animation: crt-scanline-fade 1200ms ease-out forwards;
}

.crt-tv-effect__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 0%, transparent 50%, rgba(0, 0, 0, 0.6) 100%);
  opacity: 0;
  mix-blend-mode: multiply;
}

.crt-tv-effect.is-active .crt-tv-effect__vignette {
  animation: crt-vignette-fade 1200ms ease-out forwards;
}

.crt-tv-effect.is-complete {
  animation: crt-fade-out 400ms ease forwards;
}

@keyframes site-loader-line-glitch {
  0% { opacity: 0; transform: translateX(-60px); }
  20%, 80% { opacity: 0.4; }
  100% { opacity: 0; transform: translateX(120px); }
}

@keyframes site-loader-glitch-main {
  0%, 100% { filter: brightness(1); transform: translate(0); }
  12% { filter: brightness(1.8); transform: translate(-7px, 1px); }
  25% { transform: translate(6px, -2px); }
  38% { filter: brightness(1.2); transform: translate(-3px, 2px); }
  52% { transform: translate(8px); }
  68% { filter: brightness(1.6); transform: translate(-5px, -1px); }
  82% { transform: translate(2px, 1px); }
}

@keyframes site-loader-glitch-top {
  0% { clip-path: inset(0 0 75% 0); transform: translateX(-3px); }
  20% { clip-path: inset(5% 0 60% 0); transform: translateX(-15px); }
  40% { clip-path: inset(18% 0 50% 0); transform: translateX(10px); }
  60% { clip-path: inset(0 0 65% 0); transform: translateX(-8px); }
  80% { clip-path: inset(12% 0 52% 0); transform: translateX(12px); }
  100% { opacity: 0; }
}

@keyframes site-loader-glitch-bottom {
  0% { clip-path: inset(70% 0 0 0); transform: translateX(4px); }
  20% { clip-path: inset(55% 0 8% 0); transform: translateX(15px); }
  40% { clip-path: inset(65% 0 2% 0); transform: translateX(-12px); }
  60% { clip-path: inset(48% 0 15% 0); transform: translateX(7px); }
  80% { clip-path: inset(72% 0 0 0); transform: translateX(-13px); }
  100% { opacity: 0; }
}

@keyframes site-loader-bar-glitch {
  0%, 100% { transform: translateX(0) scaleY(1); }
  25% { transform: translateX(-18px) scaleY(1.2); }
  50% { transform: translateX(22px) scaleY(0.8); }
  75% { transform: translateX(-8px) scaleY(1.4); }
}

@keyframes site-loader-cursor-blink {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: 0; }
}

@keyframes site-loader-progress-scan {
  from { transform: translateX(0); }
  to { transform: translateX(850px); }
}

@keyframes site-loader-fade-out {
  from { opacity: 1; visibility: visible; }
  to { visibility: hidden; pointer-events: none; opacity: 0; }
}

@keyframes site-loader-bg-flicker {
  0%, 40%, 60%, 100% { filter: brightness(1) contrast(1); }
  10%, 50% { filter: brightness(0.92) contrast(1.1); }
  30%, 70% { filter: brightness(1.05) contrast(0.95); }
}

@keyframes site-loader-scanlines {
  0% { transform: translateY(0); }
  100% { transform: translateY(10px); }
}

@keyframes site-loader-vertical-glitch {
  0% { transform: translateY(0) scaleY(1); opacity: 0.08; }
  33% { transform: translateY(-100vh) scaleY(1.5); opacity: 0.15; }
  66% { transform: translateY(50vh) scaleY(0.8); opacity: 0.05; }
  100% { transform: translateY(100vh) scaleY(1.2); opacity: 0.1; }
}

@keyframes site-loader-line-flicker {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.05; }
  75% { opacity: 0.4; }
}

@keyframes crt-flash-blend {
  0% { opacity: 0; transform: scale(0.01, 1); }
  8% { opacity: 1; transform: scale(1, 1); }
  15% { opacity: 0.8; }
  22% { opacity: 0.95; }
  30% { opacity: 0.75; }
  40%, 100% { opacity: 0.5; }
}

@keyframes crt-line-collapse-blend {
  0% { transform: translateY(-50%) scaleY(0.002); height: 100vh; opacity: 1; }
  15% { transform: translateY(-50%) scaleY(0.6); height: 70vh; opacity: 0.95; }
  50% { transform: translateY(-50%) scaleY(0.15); height: 30vh; opacity: 0.7; }
  80% { transform: translateY(-50%) scaleY(0.02); height: 8vh; opacity: 0.4; }
  100% { transform: translateY(-50%) scaleY(0); height: 1px; opacity: 0; }
}

@keyframes crt-scanline-fade {
  0% { opacity: 0.7; }
  50% { opacity: 0.5; }
  100% { opacity: 0; }
}

@keyframes crt-vignette-fade {
  0% { opacity: 0; }
  30% { opacity: 0.8; }
  100% { opacity: 0; }
}

@keyframes crt-fade-out {
  from { opacity: 1; }
  to { opacity: 0; visibility: hidden; }
}

@keyframes terminal-line-appear {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes terminal-cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@media (max-width: 600px) {
  .site-loader__content { width: 82vw; }
  .site-loader__word { min-width: 0; font-size: clamp(40px, 13vw, 72px); }
  .site-loader__progress-area { margin-top: 30px; }
  
  /* Hide terminal on mobile */
  .site-loader__terminal {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-loader *,
  .site-loader *::before,
  .site-loader *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
