/* ══════════════════════════════════════════════════
   Loading Screen — 2035 design system
   Selectors (#loadingScreen, .loader-logo, .loader-spinner,
   .loader-text) MUST stay stable — used by inline FOUC
   blocks and JS in every template.
   ══════════════════════════════════════════════════ */

#loadingScreen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background:
    radial-gradient(circle at 20% 20%,
      color-mix(in srgb, var(--primary, #6366f1) 22%, transparent), transparent 55%),
    radial-gradient(circle at 80% 80%,
      color-mix(in srgb, var(--accent,  #22d3ee) 18%, transparent), transparent 55%),
    var(--ds-bg, #06060f);
  color: var(--ds-text, #f4f5fb);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
    /* Immediately visible — prevents FOUC (page content flash before loader covers it).
      Auth-guarded pages that redirect instantly will briefly show this loader, which
      is better UX than flashing the real page content. The delayed animation is a
      CSS-only fallback so late/blocking scripts cannot leave the screen stuck. */
  opacity: 1;
    animation: loaderAutoRelease .22s ease 2.8s forwards;
  transition: opacity .22s var(--ease-standard, ease), visibility .22s var(--ease-standard, ease);
}

#loadingScreen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  animation: none;
}

/* JS-triggered loading screens (created by click handler) should appear
   immediately since the user already committed to the action. */
#loadingScreen.ls-instant {
  opacity: 1;
  animation: none;
}

@keyframes loaderFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes loaderAutoRelease {
  to { opacity: 0; visibility: hidden; pointer-events: none; }
}

.loader-logo {
  font-size: 2.6rem;
  width: 88px;
  height: 88px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 26px;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary, #6366f1) 30%, transparent),
    color-mix(in srgb, var(--accent,  #22d3ee) 22%, transparent));
  border: 1px solid color-mix(in srgb, var(--primary, #6366f1) 40%, transparent);
  box-shadow:
    0 24px 60px -22px color-mix(in srgb, var(--primary, #6366f1) 70%, transparent),
    inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: loaderPulse 2.2s ease-in-out infinite;
}

.loader-spinner {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: conic-gradient(from 90deg,
    transparent 0%,
    color-mix(in srgb, var(--primary, #6366f1) 80%, white) 75%,
    var(--primary, #6366f1) 100%);
  -webkit-mask: radial-gradient(circle 12px at 50% 50%, transparent 98%, #000 100%);
          mask: radial-gradient(circle 12px at 50% 50%, transparent 98%, #000 100%);
  animation: loaderSpin .9s linear infinite;
}

/* keep border-based fallback for engines that ignore conic mask */
@supports not (mask: radial-gradient(circle, #000, transparent)) {
  .loader-spinner {
    background: none;
    border: 3px solid color-mix(in srgb, var(--ds-text, #fff) 12%, transparent);
    border-top-color: var(--primary, #6366f1);
  }
}

.loader-text {
  font-family: var(--font-display, 'Inter', sans-serif);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--ds-text, #fff) 75%, transparent);
}

@keyframes loaderSpin {
  to { transform: rotate(360deg); }
}

@keyframes loaderPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 24px 60px -22px color-mix(in srgb, var(--primary, #6366f1) 70%, transparent), inset 0 1px 0 rgba(255,255,255,0.08); }
  50%      { transform: scale(1.04); box-shadow: 0 28px 70px -22px color-mix(in srgb, var(--primary, #6366f1) 90%, transparent), inset 0 1px 0 rgba(255,255,255,0.12); }
}

/* ── Light theme ── */
[data-theme="light"] #loadingScreen {
  background:
    radial-gradient(circle at 20% 20%,
      color-mix(in srgb, var(--primary, #6366f1) 18%, transparent), transparent 55%),
    radial-gradient(circle at 80% 80%,
      color-mix(in srgb, var(--accent,  #22d3ee) 14%, transparent), transparent 55%),
    var(--ds-bg, #f6f7fb);
  color: var(--ds-text, #1b1d2a);
}
[data-theme="light"] .loader-text {
  color: color-mix(in srgb, var(--ds-text, #1b1d2a) 70%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .loader-logo, .loader-spinner { animation: none !important; }
  .loader-spinner {
    border: 3px solid color-mix(in srgb, var(--ds-text, #fff) 12%, transparent);
    border-top-color: var(--primary, #6366f1);
    background: none;
    -webkit-mask: none;
            mask: none;
  }
}
