/* ==========================================================================
   Ubuntu Chemicals — loading curtain
   Runs on every page. The <html> class is set by an inline script in <head>
   so there is never a flash of page before the curtain appears, and a hard
   failsafe in that same script clears it even if app.js never runs.

   States, all set on <html>:
     is-loading   curtain covering the viewport
       + is-first   full sequence  — first page of the session
       + is-quick   instant lockup — every page after that
     loaded       curtain parked above the viewport
     is-leaving   curtain sweeping back down, ahead of a navigation

   The curtain stays in the DOM once parked so it can be brought back down
   for the exit. Page to page it reads as one continuous wipe: down over the
   page you are leaving, up off the page you are arriving at.
   ========================================================================== */

/* Without JS the curtain is never in play. */
#loader { display: none; }

.js.is-loading,
.js.is-loading body { overflow: hidden; }

.js #loader {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--u-navy-700);   /* the navy the logo is locked up on */
  color: var(--on-dark);
  border-bottom: 2px solid var(--u-green-500);
}

/* The curtain lifts, and the green edge sweeps up the viewport with it. */
.js.loaded #loader {
  transform: translateY(-101%);
  transition: transform 700ms cubic-bezier(0.76, 0, 0.24, 1);
  pointer-events: none;
}

/* On the way out it comes back down over the page, faster than it left. */
.js.loaded.is-leaving #loader {
  transform: translateY(0);
  transition: transform 380ms cubic-bezier(0.76, 0, 0.24, 1);
  pointer-events: auto;
}

/* Note: the page underneath is deliberately NOT faded out while the curtain
   is up. The curtain is opaque and covers the viewport, so there is nothing
   to hide — and making the whole page depend on a transition running to
   completion is one dropped frame away from a blank site. */

/* --------------------------------------------------------- quick variant -- */

/* Second page onward: the lockup is simply there. No stagger to sit through
   on every single click. */
.js.is-quick .loader__mark,
.js.is-quick .loader__word span,
.js.is-quick .loader__tag,
.js.is-quick .loader__foot {
  animation: none;
  opacity: 1;
  transform: none;
}

/* ------------------------------------------------------------- the stage -- */

.loader__stage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -54%);
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(92vw, 520px);
  text-align: center;
}

.loader__mark {
  width: 118px;
  height: 118px;
  opacity: 0;
  transform: scale(0.88);
  animation: loaderMark 680ms var(--ease-out) 40ms forwards;
}
.loader__mark svg { width: 100%; height: 100%; }

@keyframes loaderMark {
  to { opacity: 1; transform: none; }
}

/* Letters rise out of a mask, one after the next. */
.loader__word {
  display: flex;
  gap: 0.01em;
  overflow: hidden;
  padding-block: 0.1em;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  letter-spacing: -0.03em;
  line-height: 0.92;
}
/* Timed so the last letter lands just before the curtain lifts. */
.loader__word span {
  display: block;
  transform: translateY(110%);
  animation: loaderLetter 600ms var(--ease-out) forwards;
  animation-delay: calc(130ms + var(--i) * 46ms);
}

@keyframes loaderLetter {
  to { transform: none; }
}

.loader__tag {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--on-dark-3);
  opacity: 0;
  animation: loaderFade 520ms var(--ease-out) 430ms forwards;
}

@keyframes loaderFade {
  to { opacity: 1; }
}

/* --------------------------------------------------------------- the bar -- */

.loader__foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 var(--gutter) 26px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--on-dark-3);
  opacity: 0;
  animation: loaderFade 520ms var(--ease-out) 340ms forwards;
}

.loader__num {
  color: var(--on-dark);
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.loader__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(244, 244, 240, 0.12);
  overflow: hidden;
}
.loader__bar i {
  display: block;
  height: 100%;
  background: var(--u-green-500);
  transform: scaleX(var(--p, 0));
  transform-origin: left center;
  transition: transform 220ms var(--ease-out);
}

@media (max-width: 620px) {
  .loader__mark { width: 90px; height: 90px; }
  .loader__stage { gap: 14px; }
  .loader__foot { padding-bottom: 22px; }
  .loader__label { display: none; }
  .loader__foot { justify-content: flex-end; }
}

/* ----------------------------------------------------------------- calm --- */

@media (prefers-reduced-motion: reduce) {
  /* No sliding curtain at all — it is simply not there. (app.js also removes
     the element outright in this mode; this covers the window before it runs.) */
  .js.loaded #loader { transform: none; opacity: 0; visibility: hidden; transition: none; }
  .js.loaded.is-leaving #loader { transform: none; opacity: 0; visibility: hidden; }
  .loader__mark,
  .loader__word span,
  .loader__tag,
  .loader__foot { animation: none; opacity: 1; transform: none; }
}

/* The exit is the curtain coming back down (see .is-leaving above), not a
   fade on the page content — so there is no state in which the page is
   half-visible waiting on an animation to finish. */
