/* ============================================================
   Loading screen (VOT-738): index.html's .signin-splash, the frosted screen in the member's theme with the
   moving (unchanged) Votenir mark. A static file linked in <head>, not part of the app's CSS, so it styles
   the very first frame before any JS has run, also where the app's CSS only arrives with the JS (the Vite
   dev server). public/theme-init.js shows it by putting a class on <html>:
   - signing-in: a sign-in may be finishing ("Signing you in…");
   - restoring-session: the signed-in hint, Clerk restores the session ("Loading…").
   It also shows while #root is still empty (a page without the prerendered homepage, before React renders),
   so such a load is never a blank white page. src/signInSplash.ts fades it out.
   The --splash-* colours are the theme tokens of src/index.css (pinned by src/signInSplash.test.ts).
   ============================================================ */

:root,
[data-theme="dark"] {
  --splash-bg: hsl(224, 25%, 12%);
  --splash-gradient: linear-gradient(135deg, hsl(224, 25%, 12%) 0%, hsl(224, 30%, 8%) 100%);
  --splash-text: hsl(215, 20%, 65%);
  --splash-track: hsla(217, 30%, 60%, 0.12);
  --splash-accent: hsl(250, 85%, 65%);
  --splash-glow: hsla(250, 85%, 65%, 0.3);
}

[data-theme="light"] {
  --splash-bg: hsl(220, 30%, 97%);
  --splash-gradient: linear-gradient(135deg, hsl(220, 32%, 98%) 0%, hsl(225, 28%, 93%) 100%);
  --splash-text: hsl(220, 14%, 38%);
  --splash-track: hsla(220, 25%, 35%, 0.16);
  --splash-accent: hsl(250, 80%, 60%);
  --splash-glow: hsla(250, 80%, 60%, 0.2);
}

[data-theme="sunset"] {
  --splash-bg: hsl(262, 38%, 17%);
  --splash-gradient: linear-gradient(160deg, hsl(258, 45%, 20%) 0%, hsl(312, 42%, 22%) 48%, hsl(20, 60%, 26%) 100%);
  --splash-text: hsl(28, 28%, 76%);
  --splash-track: hsla(20, 50%, 70%, 0.16);
  --splash-accent: hsl(14, 88%, 60%);
  --splash-glow: hsla(14, 88%, 60%, 0.32);
}

[data-theme="ocean"] {
  --splash-bg: hsl(200, 45%, 12%);
  --splash-gradient: linear-gradient(135deg, hsl(205, 52%, 13%) 0%, hsl(190, 55%, 8%) 100%);
  --splash-text: hsl(190, 18%, 66%);
  --splash-track: hsla(185, 40%, 60%, 0.14);
  --splash-accent: hsl(178, 80%, 42%);
  --splash-glow: hsla(178, 80%, 42%, 0.3);
}

[data-theme="sky"] {
  --splash-bg: hsl(210, 67%, 99%);
  --splash-gradient: linear-gradient(180deg, hsl(210, 67%, 99%) 0%, hsl(204, 70%, 96%) 100%);
  --splash-text: hsl(207, 25%, 32%);
  --splash-track: hsl(205, 56%, 91%);
  --splash-accent: hsl(199, 92%, 60%);
  --splash-glow: hsla(201, 96%, 32%, 0.1);
}

/* The page behind the screen is in the theme too, so no overscroll or hop shows white. */
html.signing-in,
html.restoring-session {
  background: var(--splash-bg);
}
/* The homepage under it is always the light landing: once the screen has gone (the failsafe below, also when the app's
   script never runs), the page behind it takes the landing's background, so no dark strip stays in the scrollbar gutter
   or past the end of the page (VOT-798). With JS the app removes these classes, which does the same. */
html.signing-in:has(> body.lp-home),
html.restoring-session:has(> body.lp-home) {
  animation: signin-splash-landing-bg 1ms 8000ms forwards;
}
@keyframes signin-splash-landing-bg {
  /* --lp-bg of public/sky-tokens.css (pinned by src/signInSplash.test.ts). */
  to { background: #fafcfe; }
}
.signing-in body,
.restoring-session body {
  overflow-y: hidden;
  /* The same failsafe as the screen's own (below): the page scrolls again after 8000 ms, even without JS. */
  animation: signin-splash-unlock 1ms 8000ms forwards;
}
@keyframes signin-splash-unlock {
  to { overflow-y: visible; }
}
/* The homepage's body follows the landing as well (VOT-798, see html above). */
.signing-in body.lp-home,
.restoring-session body.lp-home {
  animation: signin-splash-unlock 1ms 8000ms forwards, signin-splash-landing-bg 1ms 8000ms forwards;
}

.signing-in .signin-splash,
.restoring-session .signin-splash,
body:has(> #root:empty) > .signin-splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  overflow: hidden;
  background: var(--splash-bg);
  background-image: var(--splash-gradient);
  color: var(--splash-text);
  font-family: var(--font-sans, system-ui, sans-serif);
  /* SPLASH_FADE_MS in src/signInSplash.ts */
  transition: opacity 180ms ease-out;
  /* Failsafe without JS (VOT-791): never longer than CLERK_LOAD_TIMEOUT_MS (src/clerkLoadFailsafe.ts), even
     when the app's script never runs; with JS the app gives up on Clerk at the same time. */
  animation: signin-splash-failsafe 1ms 8000ms forwards;
}
@keyframes signin-splash-failsafe {
  /* Also off the screen, so it never catches a click once it has gone. */
  to { visibility: hidden; opacity: 0; transform: translateY(-100%); }
}
/* The frosted glow: two soft blobs of the theme's primary colour behind the mark. */
.signin-splash::before {
  content: '';
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 35% 40%, var(--splash-glow), transparent 40%),
    radial-gradient(circle at 65% 60%, var(--splash-glow), transparent 45%);
  filter: blur(48px);
}
.signing-in-leaving .signin-splash {
  opacity: 0;
  pointer-events: none;
}
.signin-splash-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
}
/* The moving ring around the (unchanged) Votenir mark. */
.signin-splash-mark::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--splash-track);
  border-top-color: var(--splash-accent);
  animation: signin-splash-spin 1s linear infinite;
}
.signin-splash-mark img {
  animation: signin-splash-pulse 1.6s ease-in-out infinite;
}
@keyframes signin-splash-spin {
  to { transform: rotate(360deg); }
}
@keyframes signin-splash-pulse {
  50% { transform: scale(0.88); opacity: 0.75; }
}
.signin-splash-text {
  position: relative;
  margin: 0;
  font-size: 1rem;
}
/* "Signing you in…" while a sign-in may be finishing, "Loading…" otherwise. */
.signin-splash-signing-in,
.signing-in .signin-splash-loading {
  display: none;
}
.signing-in .signin-splash-signing-in {
  display: inline;
}

@media (prefers-reduced-motion: reduce) {
  .signing-in .signin-splash,
  .restoring-session .signin-splash,
  body:has(> #root:empty) > .signin-splash {
    transition: none;
  }
  .signin-splash-mark::before,
  .signin-splash-mark img {
    animation: none;
  }
}
