/* Loading screen (loading.js): the baked float loop with a progress line (--progress 0-1).
   When ready, a foam-ringed hole opens from the float (--float-x/y, --opened set by loading.js). */

/* Registered so it can be transitioned. */
@property --opening {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
}

.loading {
    position: fixed;
    inset: 0;
    z-index: var(--z-loading);
    overflow: hidden;
    background: linear-gradient(to bottom, #78b8ec, #cfe8fa 28%, #3f97e0 30%, #2a7fcf 70%, #1f6fbd);
    --float-x: 50%;
    --float-y: 44%;
    --opened: 150vmax;
    /* Matches openSeconds in loading.js. */
    transition:
        --opening 1.2s cubic-bezier(0.6, 0, 0.25, 1),
        transform 1.2s cubic-bezier(0.5, 0, 0.3, 1),
        visibility 0s linear 1.2s;
}

.loading.is-done {
    --opening: var(--opened);
    -webkit-mask-image: radial-gradient(circle at var(--float-x) var(--float-y), transparent calc(var(--opening) - 1px), #000 var(--opening));
    mask-image: radial-gradient(circle at var(--float-x) var(--float-y), transparent calc(var(--opening) - 1px), #000 var(--opening));
    transform: scale(1.08);
    transform-origin: var(--float-x) var(--float-y);
    visibility: hidden;
    pointer-events: none;
}

/* Foam round the hole. Own layer, or the video can paint over it. */
.loading.is-done::after {
    content: "";
    position: absolute;
    z-index: 1;
    will-change: transform;
    left: var(--float-x);
    top: var(--float-y);
    width: calc(var(--opening) * 2);
    height: calc(var(--opening) * 2);
    border-radius: 50%;
    translate: -50% -50%;
    box-shadow:
        0 0 0 3px rgba(22, 38, 61, 0.55),
        0 0 0 14px rgba(255, 255, 255, 0.85),
        0 0 24px 22px rgba(220, 240, 255, 0.55);
    animation: loading-foam 1.2s ease-in both;
    pointer-events: none;
}

@keyframes loading-foam {
    60% {
        opacity: 0.9;
    }
    to {
        opacity: 0;
    }
}

/* Covers the window, keeping the float in view. A touch soft, so the upscaled video's blocky
   edges don't show. */
.loading-loop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 40%;
    filter: blur(0.4px) saturate(1.06);
}

/* Film grain and a soft vignette over the video, hiding its compression and banding. The grain
   tile jitters a few times a second; it's oversized so the jumps never show an edge. */
.loading-grain {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: radial-gradient(ellipse 80% 75% at 50% 42%, transparent 45%, rgba(8, 30, 60, 0.5) 100%);
    pointer-events: none;
}

.loading-grain::before {
    position: absolute;
    inset: -100px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 180px 180px;
    opacity: 0.34;
    mix-blend-mode: overlay;
    content: "";
    animation: loading-grain 0.5s steps(1) infinite;
}

@keyframes loading-grain {
    0% { transform: translate(0, 0); }
    20% { transform: translate(-37px, 22px); }
    40% { transform: translate(51px, -44px); }
    60% { transform: translate(-18px, -61px); }
    80% { transform: translate(64px, 29px); }
}

.loading-words {
    position: absolute;
    left: 0;
    right: 0;
    top: 66%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition:
        opacity 0.3s ease,
        transform 0.4s cubic-bezier(0.3, 0, 0.6, 1);
}

.loading.is-done .loading-words {
    opacity: 0;
    transform: translateY(-28px);
}

.loading-text {
    margin: 0 0 16px;
    font-size: clamp(22px, 3vw, 34px);
}

.loading-line {
    width: min(280px, 70vw);
    height: 12px;
    box-sizing: border-box;
    border: 3px solid #16263d;
    border-radius: 999px;
    background: rgba(7, 26, 51, 0.4);
    box-shadow: 0 3px 0 rgba(10, 20, 35, 0.35);
    overflow: hidden;
}

.loading-reeled {
    width: calc(var(--progress, 0) * 100%);
    height: 100%;
    border-radius: inherit;
    background: #ffd54a;
    transition: width 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
    .loading,
    .loading-words,
    .loading-reeled {
        transition: none;
    }

    .loading.is-done {
        -webkit-mask-image: none;
        mask-image: none;
        transform: none;
    }

    .loading.is-done::after {
        content: none;
    }

    .loading-grain::before {
        animation: none;
    }
}
