/*
 * Drift King - logo.css
 * The animated game logo (img/logo-master.svg) shown on the start screen and in the main menu.
 *
 * HOW IT WORKS
 *   .gameLogo      sized box (keeps the logo's aspect ratio, never wider/taller than the screen allows)
 *     .gl-float    gentle floating / tilting loop + holds the sparkles
 *       .gl-art    pop-in animation, stacks 3 copies of the same image:
 *         .gl-glow   blurred copy behind = pulsing glow
 *         .gl-img    the visible logo
 *         .gl-shine  bright copy revealed by a moving band = light sweep
 *       .gl-spark  twinkling stars on the crown and letters
 *
 * TO CHANGE THE SIZE: edit --logo-splash-w (start screen) or .gl-menu width (main menu) below. The sizes are limited by the
 * screen WIDTH and HEIGHT at the same time, so the logo can never overlap the car, the top
 * buttons or the menu card, in portrait or in landscape.
 * TO SWAP THE LOGO: replace img/logo-master.svg (keep the same aspect ratio, about 2.6 : 1) and, if you
 * use another file name, change the three <img> tags per screen in index.html.
 */

:root {
    --logo-ratio: 1200 / 462; /* width / height of img/logo-master.svg */
    --H: 100vh; /* visible screen height (dvh = correct on phones with moving address bars) */
}
@supports (height: 100dvh) {
    :root {
        --H: 100dvh;
    }
}

/*
 * START SCREEN: below the logo we need ~270px for subtitle + loading bar + PLAY button.
 */
:root {
    --logo-splash-w: max(200px, min(90vw, 720px, calc((var(--H) - 270px) * 2.597)));
}

/*
 * MAIN MENU: the logo may only use the space ABOVE the car. The tallest vehicle (fire truck,
 * box van) starts at ~28% of the screen height on desktop/tablet and ~33% on phones, so:
 *   landscape (default): logo is in the top bar, between pills and buttons -> height <= 27% of screen
 *   portrait:            logo is on its own row under the pills (~120px from the top)
 * 2.597 = logo width / height. Raise the percentages only if you also move the car lower.
 */
.gameLogo.gl-menu {
    width: min(100%, 560px, max(120px, calc((var(--H) * 0.27 - 26px) * 2.597)));
}
@media (max-aspect-ratio: 1/1) {
    .gameLogo.gl-menu {
        width: min(88vw, 540px, max(120px, calc((var(--H) * 0.275 - 120px) * 2.597)));
    }
}
@media (max-aspect-ratio: 7/10) {
    .gameLogo.gl-menu {
        width: min(88vw, 540px, max(120px, calc((var(--H) * 0.32 - 120px) * 2.597)));
    }
}

.gameLogo {
    position: relative;
    flex: 0 0 auto;
    aspect-ratio: var(--logo-ratio);
    pointer-events: none;
}
.gameLogo.gl-splash {
    width: var(--logo-splash-w);
}
.gameLogo img {
    display: block;
    width: 100%;
    height: 100%;
    -webkit-user-drag: none;
    user-select: none;
}
.gl-float {
    position: absolute;
    inset: 0;
    animation: glFloat 4.2s ease-in-out infinite;
    will-change: transform;
}
.gl-art {
    position: absolute;
    inset: 0;
}
.gl-art img {
    position: absolute;
    inset: 0;
}

/* --- pop-in every time the screen is shown --- */
#splash:not(.hide) .gl-art {
    animation: glIn 1s cubic-bezier(0.2, 1.4, 0.4, 1) 0.15s both;
}
#menu:not(.hide) .gl-art {
    animation: glIn 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) 0.1s both;
}

/* --- pulsing glow --- */
.gl-glow {
    filter: blur(clamp(8px, 1.6vw, 16px)) saturate(1.7) brightness(1.15);
    transform: scale(1.02);
    opacity: 0.45;
    animation: glGlow 2.6s ease-in-out infinite;
}

/* --- light sweep: bright copy of the logo, only visible inside a moving diagonal band --- */
.gl-shine {
    filter: brightness(2.6) saturate(0.2);
    opacity: 0.9;
    -webkit-mask-image: linear-gradient(
        105deg,
        transparent 0 43%,
        rgba(0, 0, 0, 0.35) 47%,
        #000 50%,
        rgba(0, 0, 0, 0.35) 53%,
        transparent 57% 100%
    );
    mask-image: linear-gradient(
        105deg,
        transparent 0 43%,
        rgba(0, 0, 0, 0.35) 47%,
        #000 50%,
        rgba(0, 0, 0, 0.35) 53%,
        transparent 57% 100%
    );
    -webkit-mask-size: 300% 100%;
    mask-size: 300% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: 100% 0;
    mask-position: 100% 0;
    animation: glShine 4.2s ease-in-out 1.2s infinite;
}

/* --- sparkles (positions are % of the logo box) --- */
.gl-spark {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--s);
    aspect-ratio: 1;
    margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
    background:
        radial-gradient(circle, #fff 0 8%, rgba(255, 244, 180, 0.9) 14%, rgba(255, 220, 100, 0) 56%),
        linear-gradient(rgba(255, 255, 255, 0), #fff, rgba(255, 255, 255, 0)) center / 9% 100% no-repeat,
        linear-gradient(90deg, rgba(255, 255, 255, 0), #fff, rgba(255, 255, 255, 0)) center / 100% 9% no-repeat;
    opacity: 0;
    transform: scale(0) rotate(0deg);
    animation: glTwinkle 2.8s ease-in-out infinite;
    animation-delay: var(--d);
}
.gl-spark.s1 {
    --x: 50.3%;
    --y: 8.5%;
    --s: 9%;
    --d: 0.6s;
}
.gl-spark.s2 {
    --x: 38.6%;
    --y: 15.2%;
    --s: 6.5%;
    --d: 1.5s;
}
.gl-spark.s3 {
    --x: 62.3%;
    --y: 15.2%;
    --s: 6.5%;
    --d: 2.2s;
}
.gl-spark.s4 {
    --x: 13%;
    --y: 53%;
    --s: 7%;
    --d: 1s;
}
.gl-spark.s5 {
    --x: 88.5%;
    --y: 57%;
    --s: 7%;
    --d: 1.9s;
}

@keyframes glIn {
    from {
        opacity: 0;
        transform: scale(0.2) rotate(-7deg) translateY(12%);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
@keyframes glFloat {
    0%,
    100% {
        transform: translateY(0) rotate(-0.6deg);
    }
    50% {
        transform: translateY(-3%) rotate(0.6deg);
    }
}
@keyframes glGlow {
    0%,
    100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.8;
    }
}
@keyframes glShine {
    0% {
        -webkit-mask-position: 100% 0;
        mask-position: 100% 0;
    }
    38%,
    100% {
        -webkit-mask-position: 0% 0;
        mask-position: 0% 0;
    }
}
@keyframes glTwinkle {
    0%,
    55%,
    100% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    75% {
        opacity: 1;
        transform: scale(1) rotate(60deg);
    }
}

/* nothing animates on hidden screens (saves battery) */
.scr.hide .gameLogo *,
.scr.hide .gameLogo {
    animation-play-state: paused;
}
@media (prefers-reduced-motion: reduce) {
    .gl-float,
    .gl-glow,
    .gl-shine,
    .gl-spark,
    .gl-art {
        animation: none !important;
    }
    .gl-glow {
        opacity: 0.5;
    }
    .gl-shine,
    .gl-spark {
        display: none;
    }
}
