/* =========================================================================
   SCSLAI — LOADING ANIMATION  (styles)
   -------------------------------------------------------------------------
   One loading animation for every wait on the site:
     • building the fill-out form PDF        (FORMS/engine.js)
     • loading the fill-out form artwork     (FORMS/engine.js)
     • opening a SCSLAICares yearbook        (script.js)
     • swapping an announcement photo        (script.js)
     • opening an event album photo          (script.js)
     • downloading the welcome-popup banner  (welcome-popup.js)

   Markup is built by loading/coin-loader.js:
     <div class="scslai-loader scslai-loader--overlay">
       <span class="scslai-loader__coin">
         <svg class="scslai-loader__ghost">…</svg>
       </span>
       <span class="scslai-loader__label">Loading…</span>
     </div>

   Ghost animation from Uiverse.io by fanishah, re-coloured green for SCSLAI.
   ========================================================================= */

.scslai-loader {
    --scslai-loader-size: 96px;
    --scslai-loader-ink: #f4dfae;

    position: absolute;
    inset: 0;
    z-index: 1;                 /* stays under close buttons / arrows (z-index 2) */

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;

    box-sizing: border-box;
    padding: 18px;
    border-radius: inherit;

    background: rgba(6, 24, 16, 0.62);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;       /* never eat a click while the page settles */
    transition: opacity 200ms ease, visibility 0s linear 200ms;
}

.scslai-loader.is-visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 200ms ease, visibility 0s linear 0s;
}

/* Full-screen variant — SCSLAILoader.show() */
.scslai-loader--overlay {
    position: fixed;
    z-index: var(--scslai-loader-z, 120000);
    pointer-events: auto;       /* the page is busy: hold the clicks */
}

/* Loader that had to fall back to a fixed box because its host is static —
   see inline() in coin-loader.js. */
.scslai-loader--floating {
    position: fixed;
    inset: auto;
    border-radius: 12px;
}

/* Scrim switched off (SCSLAILoader.show({ scrim: false })): the loader rides
   on top of whatever is already on screen. */
.scslai-loader--bare {
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

/* Variant for light panels (the white form preview) */
.scslai-loader--light {
    --scslai-loader-ink: #10362a;

    background: rgba(244, 246, 245, 0.8);
}

/* Sizes */
.scslai-loader--xs { --scslai-loader-size: 34px; }
.scslai-loader--sm { --scslai-loader-size: 58px; }
.scslai-loader--md { --scslai-loader-size: 96px; }
.scslai-loader--lg { --scslai-loader-size: 128px; }

/* =========================================================================
   THE LOADER — the ghost "still working" face
   -------------------------------------------------------------------------
   The wrapper (.scslai-loader__coin) is only the size box; the SVG inside
   fills it, so one set of rules covers every size (xs … lg, plus the tiny
   one used inside a busy button).

   Ghost animation from Uiverse.io by fanishah, re-coloured green for SCSLAI:
   the original cyan/blue pair becomes the two greens below.
   ========================================================================= */

.scslai-loader__coin {
    position: relative;
    display: block;
    flex: 0 0 auto;
    width: var(--scslai-loader-size, 96px);
    height: var(--scslai-loader-size, 96px);
    line-height: 0;                 /* no inline-SVG baseline gap */
}

.scslai-loader__ghost {
    display: block;
    width: 100%;
    height: 100%;
}

/* One tint per layer. The vertical mask blends layer A (top) into layer B
   (bottom), which is what gives the loader its shaded, solid look. */
.scslai-loader__ghost-front-fill   { fill: hsl(135, 90%, 45%); }
.scslai-loader__ghost-front-stroke { stroke: hsl(135, 90%, 45%); }
.scslai-loader__ghost-back-fill    { fill: hsl(160, 90%, 38%); }
.scslai-loader__ghost-back-stroke  { stroke: hsl(160, 90%, 38%); }

/* The two eyes and the two mouths share one timing; each overrides the
   keyframes it needs below. */
.scslai-loader__ghost-eye1,
.scslai-loader__ghost-eye2,
.scslai-loader__ghost-mouth1,
.scslai-loader__ghost-mouth2 {
    animation: scslaiLoaderEye1 3s ease-in-out infinite;
}

.scslai-loader__ghost-eye1,
.scslai-loader__ghost-eye2 {
    transform-origin: 64px 64px;
}

.scslai-loader__ghost-eye2 {
    animation-name: scslaiLoaderEye2;
}

.scslai-loader__ghost-mouth1 {
    animation-name: scslaiLoaderMouth1;
}

.scslai-loader__ghost-mouth2 {
    animation-name: scslaiLoaderMouth2;
    visibility: hidden;
}

@keyframes scslaiLoaderEye1 {
    from {
        transform: rotate(-260deg) translate(0, -56px);
    }

    50%,
    60% {
        animation-timing-function: cubic-bezier(0.17, 0, 0.58, 1);
        transform: rotate(-40deg) translate(0, -56px) scale(1);
    }

    to {
        transform: rotate(225deg) translate(0, -56px) scale(0.35);
    }
}

@keyframes scslaiLoaderEye2 {
    from {
        transform: rotate(-260deg) translate(0, -56px);
    }

    50% {
        transform: rotate(40deg) translate(0, -56px) rotate(-40deg) scale(1);
    }

    52.5% {
        transform: rotate(40deg) translate(0, -56px) rotate(-40deg) scale(1, 0);
    }

    55%,
    70% {
        animation-timing-function: cubic-bezier(0, 0, 0.28, 1);
        transform: rotate(40deg) translate(0, -56px) rotate(-40deg) scale(1);
    }

    to {
        transform: rotate(150deg) translate(0, -56px) scale(0.4);
    }
}

@keyframes scslaiLoaderMouth1 {
    from {
        animation-timing-function: ease-in;
        stroke-dasharray: 0 351.86;
        stroke-dashoffset: 0;
    }

    25% {
        animation-timing-function: ease-out;
        stroke-dasharray: 175.93 351.86;
        stroke-dashoffset: 0;
    }

    50% {
        animation-timing-function: steps(1, start);
        stroke-dasharray: 175.93 351.86;
        stroke-dashoffset: -175.93;
        visibility: visible;
    }

    75%,
    to {
        visibility: hidden;
    }
}

@keyframes scslaiLoaderMouth2 {
    from {
        animation-timing-function: steps(1, end);
        visibility: hidden;
    }

    50% {
        animation-timing-function: ease-in-out;
        visibility: visible;
        stroke-dashoffset: 0;
    }

    to {
        stroke-dashoffset: -351.86;
    }
}

/* Tiny loader — used inside a button that is busy (SCSLAILoader.busy) */
.scslai-loader__coin--tiny {
    --scslai-loader-size: 18px;
}

/* =========================================================================
   LABEL
   ========================================================================= */

.scslai-loader__label {
    max-width: 32ch;
    color: var(--scslai-loader-ink, #f4dfae);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.4;
    text-align: center;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.scslai-loader__label:empty {
    display: none;
}

/* =========================================================================
   BUSY CONTROL — SCSLAILoader.busy(button)
   ========================================================================= */

.scslai-loader-busy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: progress;
}

.scslai-loader-busy[disabled] {
    opacity: 0.85;
    cursor: progress;
}

.scslai-loader__busy-label {
    font: inherit;
    letter-spacing: inherit;
}

/* -------------------------------------------------------------------------
   PAGE-LOAD LOADER — shown while the page itself is still coming down the
   wire (bootPageLoader() in coin-loader.js). The page behind it is only half
   painted, so this one is opaque instead of a scrim over it.
   ------------------------------------------------------------------------- */

.scslai-loader--boot {
    --scslai-loader-ink: #f4dfae;

    background: #04150f;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.scslai-loader--boot .scslai-loader__label {
    font-size: 16px;
}

/* =========================================================================
   REDUCED MOTION — the ghost holds still but the wait stays visible
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
    .scslai-loader__ghost-eye1,
    .scslai-loader__ghost-eye2,
    .scslai-loader__ghost-mouth1,
    .scslai-loader__ghost-mouth2 {
        animation: none;
    }

    .scslai-loader {
        transition: none;
    }
}
