/* ==========================================================================
   Site loader — "CHAITANYA" in several languages, then a curved curtain lift.
   Ported from the React/Framer Motion WordsPreloader (Chaitanya-Frontend),
   recoloured to the site's palette (sky gradient + pattern, black Druk type).
   ========================================================================== */

/* Until the loader element exists, keep the page hidden (head script adds
   .ch-preload and always removes it within 3s, so this can never hang). */
html.ch-preload body {
  visibility: hidden;
}

/* The loader is a light brand intro shown before the page styles load, so
   its colours are literal, not theme tokens. */
html.ch-preload,
html.site-loading {
  color-scheme: light;
  background: #f7faff;
}

/* Motion exception (motion audit): the one-time boot loader choreographs the
   logo reveal over ~1.5s, so its durations sit outside the 100–300ms tokens.
   It runs once per load and honours prefers-reduced-motion. */
#site-loader {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: visible;
  background-color: #dbe7fb;
  background-image: url(/images/footerPatern.png), linear-gradient(0deg, #b4cbf5, #f7faff);
  background-repeat: repeat, no-repeat;
  background-size: 80px, 100% 100%;
  color: #000000;
  transform: translate3d(0, 0, 0);
  /* Only transform animates (GPU-composited), so the lift stays smooth even
     while the 3D scene is busy loading on the main thread. */
  transition: transform 1s cubic-bezier(0.22, 1, 0.36, 1) 0.1s;
  will-change: transform;
}

/* Curved bottom edge of the curtain: an ellipse that grows out of the
   loader's bottom edge as it lifts (scaleY, also GPU-only). */
#site-loader::after {
  content: "";
  position: absolute;
  top: 100%;
  left: -25%;
  width: 150%;
  height: 22vh;
  margin-top: -1px;
  background: url(/images/footerPatern.png) repeat 0 0 / 80px, #b4cbf5;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  transform: scaleY(0);
  transform-origin: top center;
  transition: transform 0.8s cubic-bezier(0.33, 1, 0.68, 1) 0.1s;
  will-change: transform;
}

#site-loader.is-leaving {
  transform: translate3d(0, calc(-100% - 22vh), 0);
  pointer-events: none;
}

#site-loader.is-leaving::after {
  transform: scaleY(1);
}

/* All eight words share one grid cell; each is shown for its own slot by a
   CSS opacity animation (compositor-driven, so main-thread work during app
   start-up can't stall it). Slots: first word 0-600ms (fading in), then
   150ms per word; the last word stays until the curtain lifts. */
.site-loader-words {
  display: grid;
  place-items: center;
}

.site-loader-word {
  grid-area: 1 / 1;
  margin: 0;
  padding: 0 16px;
  white-space: nowrap;
  font-family: "DrukMedium", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: clamp(56px, 11vw, 168px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: var(--track-display, 0.02em);
  text-transform: uppercase;
  opacity: 0;
  animation: site-loader-slot 150ms linear calc(450ms + var(--i) * 150ms);
}

.site-loader-word:first-child {
  animation:
    site-loader-in 0.5s ease 0.1s forwards,
    site-loader-hide 0s linear 600ms forwards;
}

.site-loader-word:last-child {
  animation: site-loader-in 0s linear 1500ms forwards;
}

/* Scripts Druk doesn't cover fall back to a bolder system face. */
.site-loader-word[lang]:not([lang="en"]) {
  font-weight: 600;
  letter-spacing: 0;
  font-size: clamp(44px, 8vw, 128px);
}

.site-loader-tag {
  position: absolute;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 4px 12px;
  background-color: #f7faff;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  /* One line down to 320px (it wrapped, leaving "]" alone on line two);
     sized with the 0.08em label tracking included. */
  font-size: clamp(10px, 3.1vw, 12px);
  font-weight: 600;
  letter-spacing: var(--track-label, 0.08em);
  white-space: nowrap;
  text-transform: uppercase;
  color: #005a3c;
  /* Small text: readable at full contrast from the first frame, no fade. */
}

@keyframes site-loader-in {
  to {
    opacity: 1;
  }
}

@keyframes site-loader-hide {
  to {
    opacity: 0;
  }
}

/* Visible only while the animation runs (no fill), i.e. for its 150ms slot. */
@keyframes site-loader-slot {
  from,
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  #site-loader {
    transition: opacity 0.3s ease;
  }

  #site-loader.is-leaving {
    transform: none;
    opacity: 0;
  }

  #site-loader::after {
    display: none;
  }

  .site-loader-word {
    animation: none;
    opacity: 0;
  }

  .site-loader-word:first-child {
    animation: none;
    opacity: 1;
  }
}

/* Small phones: the word never touches the screen edges (nowrap). */
@media (max-width: 379px) {
  .site-loader-word {
    font-size: clamp(44px, 15vw, 56px);
  }
}
