/* Loading screen + page cross-fades (Step 36)
   - Shown on the first page of a visit only, and only if that page is slow: the white screen is there at once,
     the logo and the colour strip appear after 0.25 s, so a fast page simply fades in.
   - Gone when the fonts and the images on screen are ready, after 2.5 s at the latest (preloader.js),
     and after 3.2 s even without JavaScript (pl-failsafe below).
   - The seven colours of the SDG banner fill the strip one after another (right to left in Arabic).
   - "Reduce motion": logo fades in, strip still. The widget's "Stop animations": no loading screen, no cross-fades.
   - The page-to-page cross-fade is in assets/css/page-transitions.css (Step 38). */

#overlay {
  /* banner colours (same values as assets/css/sdg-theme.css; repeated so the page works without it) */
  --pl-orange: #F89E24; --pl-cyan: #00ADD8; --pl-teal: #0090B4; --pl-green: #3EAD49;
  --pl-forest: #41804B; --pl-pink: #DF1A82; --pl-magenta: #B90E6E;
  --pl-ease: cubic-bezier(.2, .7, .2, 1);

  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background: #ffffff;
  animation: pl-failsafe 0s 3.2s forwards;   /* safety net: never covers the page longer (no animation, just the end state) */
}
@keyframes pl-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }

#overlay.is-leaving { opacity: 0; visibility: hidden; transition: opacity .45s cubic-bezier(.4, 0, .2, 1), visibility 0s .45s; }
#overlay.is-leaving.is-quick { transition-duration: .25s, 0s; transition-delay: 0s, .25s; }

.preloader-stage {
  width: min(56vw, 480px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 3vh, 26px);
  opacity: 0;
  transform: translateY(8px) scale(.985);
  animation: pl-in .6s var(--pl-ease) .25s forwards;
  transition: translate .45s cubic-bezier(.4, 0, .2, 1);
}
@keyframes pl-in { to { opacity: 1; transform: none; } }
#overlay.is-leaving .preloader-stage { translate: 0 -12px; }   /* lifts while the screen fades */

#preloader-image { display: block; width: 100%; height: auto; }

/* the strip: seven segments in the banner colours, filling and emptying in a wave */
.preloader-strip { display: flex; width: 72%; height: 4px; gap: 4px; }
.preloader-strip i {
  --from: left; --to: right;
  flex: 1;
  border-radius: 2px;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: var(--from);
  animation: pl-wave 1.8s cubic-bezier(.65, 0, .35, 1) calc(.4s + var(--n) * .09s) infinite;
}
.preloader-strip i:nth-child(1) { --c: var(--pl-orange);  --n: 0; }
.preloader-strip i:nth-child(2) { --c: var(--pl-cyan);    --n: 1; }
.preloader-strip i:nth-child(3) { --c: var(--pl-teal);    --n: 2; }
.preloader-strip i:nth-child(4) { --c: var(--pl-green);   --n: 3; }
.preloader-strip i:nth-child(5) { --c: var(--pl-forest);  --n: 4; }
.preloader-strip i:nth-child(6) { --c: var(--pl-pink);    --n: 5; }
.preloader-strip i:nth-child(7) { --c: var(--pl-magenta); --n: 6; }
@keyframes pl-wave {
  0%   { transform: scaleX(0); transform-origin: var(--from); }
  38%  { transform: scaleX(1); transform-origin: var(--from); }
  62%  { transform: scaleX(1); transform-origin: var(--to); }
  100% { transform: scaleX(0); transform-origin: var(--to); }
}
:lang(ar) .preloader-strip { flex-direction: row-reverse; }
:lang(ar) .preloader-strip i { --from: right; --to: left; }

@media (max-width: 640px) {
  .preloader-stage { width: 74vw; }
  .preloader-strip { height: 3px; gap: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  .preloader-stage { transform: none; animation-name: pl-fade; transition: none; }
  #overlay.is-leaving .preloader-stage { translate: none; }
  .preloader-strip i { animation: none; transform: none; }
}
@keyframes pl-fade { to { opacity: 1; } }

html.a11y-still #overlay { display: none; }

/* the page-to-page cross-fade is in assets/css/page-transitions.css, linked in each page's <head> (Step 38) */
