/* PWA splash / loader screen.
 * Linked directly in index.html so it paints as soon as the stylesheet loads.
 * The class `app-loaded` is added to <body> by App.tsx once mounted.
 *
 * Design: a deliberate branded launch moment (deep navy, brand-blue halo,
 * wordmark reveal, indeterminate progress). Identical in light & dark so the
 * cold-start OS paint (manifest background_color) matches exactly — no flash.
 * The whole screen cross-fades out once React mounts, reading as an intro
 * rather than a loading glitch.
 */
:root {
  --splash-navy-0: #0b1120;
  --splash-navy-1: #0f1830;
  --splash-brand: #3b82f6;
  --splash-brand-soft: #60a5fa;
}

.app-loader-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(env(safe-area-inset-top), 24px) 24px max(env(safe-area-inset-bottom), 24px);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(59, 130, 246, 0.16) 0%, transparent 55%),
    radial-gradient(90% 90% at 50% 120%, rgba(37, 99, 235, 0.12) 0%, transparent 50%),
    linear-gradient(160deg, var(--splash-navy-1) 0%, var(--splash-navy-0) 100%);
  overflow: hidden;
}

#app-loader {
  transition: opacity 600ms cubic-bezier(0.16, 1, 0.3, 1), visibility 600ms;
}

/* Slow drifting aurora glow behind the logo. */
.app-loader-screen::before {
  content: '';
  position: absolute;
  inset: -40%;
  z-index: 0;
  background:
    radial-gradient(circle at 32% 34%, rgba(96, 165, 250, 0.18) 0%, transparent 42%),
    radial-gradient(circle at 68% 66%, rgba(37, 99, 235, 0.14) 0%, transparent 42%);
  animation: app-loader-aurora 14s ease-in-out infinite alternate;
  transform-origin: center;
  filter: blur(6px);
}

body.app-loaded #app-loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-loader__content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  /* Optical centre. Margin, not transform: the entrance animation owns
     `transform`, so a static translate would snap back when it ends. */
  margin-top: -6vh;
  animation: app-loader-fade-in 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-loader__logo-wrap {
  position: relative;
  width: clamp(112px, 11vw, 152px);
  aspect-ratio: 600 / 589.4;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 18px 32px rgba(0, 0, 0, 0.32)) drop-shadow(0 0 24px rgba(59, 130, 246, 0.18));
}

.app-loader__logo {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
}

/* Expanding pulse rings in brand blue (radar). */
.app-loader__ring {
  position: absolute;
  inset: 4px;
  z-index: 0;
  border-radius: 28px;
  border: 1.5px solid rgba(96, 165, 250, 0.55);
  animation: app-loader-radar 2.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
  opacity: 0;
}

.app-loader__ring:nth-child(2) { animation-delay: 0.9s; }

/* Rotating conic halo — the premium sweep around the logo. */
.app-loader__logo-border {
  position: absolute;
  inset: -4px;
  z-index: 1;
  border-radius: 28px;
  background: conic-gradient(
    from 0deg,
    transparent 0%,
    var(--splash-brand-soft) 18%,
    var(--splash-brand) 32%,
    transparent 55%,
    transparent 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  padding: 3px;
  animation: app-loader-border-spin 2.2s linear infinite;
}

/* Wordmark reveal. */
.app-loader__wordmark {
  margin: 0;
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif;
  font-size: clamp(18px, 1.8vw, 22px);
  font-weight: 450;
  letter-spacing: 0.025em;
  color: #f8fafc;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  animation: app-loader-word-in 0.4s 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.app-loader__wordmark b { color: #93c5fd; font-weight: 650; }

/* Indeterminate progress line. */
.app-loader__progress {
  position: relative;
  width: 132px;
  height: 3px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.18);
  animation: app-loader-word-in 0.9s 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.app-loader__progress::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--splash-brand-soft), var(--splash-brand), transparent);
  animation: app-loader-progress 1.4s ease-in-out infinite;
}

@keyframes app-loader-fade-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes app-loader-word-in { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } to { opacity: 1; transform: translateY(0); filter: blur(0); } }
@keyframes app-loader-aurora { 0% { transform: rotate(0deg) scale(1); } 100% { transform: rotate(12deg) scale(1.12); } }
@keyframes app-loader-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes app-loader-radar { 0% { transform: scale(0.85); opacity: 0.65; } 70% { opacity: 0.9; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes app-loader-border-spin { to { transform: rotate(360deg); } }
@keyframes app-loader-progress { 0% { left: -40%; } 100% { left: 100%; } }

@media (max-width: 640px) {
  .app-loader-screen {
    padding-inline: max(env(safe-area-inset-left), 20px) max(env(safe-area-inset-right), 20px);
  }

  .app-loader__content { gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-loader-screen::before,
  .app-loader__ring,
  .app-loader__logo-border,
  .app-loader__progress::before { animation: none; }
  .app-loader__ring { display: none; }
  .app-loader__logo { content: url('/logo-line-blue.svg'); filter: brightness(0) invert(1); }
  .app-loader__wordmark,
  .app-loader__progress { animation: none; opacity: 1; }
  .app-loader__progress::before { left: 0; width: 100%; opacity: 0.6; }
}
