/**
 * Tovio Loader Animations
 * 4 types: ball-morph, jersey-fill, shoe-bounce, flag-circle
 */

/* ========== BASE OVERLAY ========== */
.tovio-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--tovio-dark, #1A1A1A);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.tovio-loader.loaded {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tovio-loader-label {
    font-family: 'Oswald', 'Bebas Neue', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2rem;
}

/* ========== TYPE 1: BALLON MORPHING ========== */
.loader-ball-morph {
    width: 80px;
    height: 80px;
    position: relative;
}

.loader-ball-morph svg {
    width: 80px;
    height: 80px;
    filter: drop-shadow(0 0 20px rgba(206, 17, 38, 0.3));
}

.loader-ball-morph .ball-shape {
    fill: var(--tovio-primary, #D42027);
    animation: ballMorph 8s ease-in-out infinite;
}

.loader-ball-morph .ball-lines {
    fill: none;
    stroke: rgba(255, 255, 255, 0.4);
    stroke-width: 1.5;
    animation: ballLinesMorph 8s ease-in-out infinite;
}

.loader-ball-morph .ball-label {
    font-family: 'Oswald', sans-serif;
    font-size: 9px;
    fill: rgba(255, 255, 255, 0.7);
    text-anchor: middle;
    letter-spacing: 2px;
    animation: ballTextFade 8s ease-in-out infinite;
}

/* Football (round) → Basketball (round+lines) → Tennis (round+curve) → Volleyball (round+panels) → Rugby (oval) */
@keyframes ballMorph {
    0%, 100% {
        d: path("M40 8 C57 8 72 23 72 40 C72 57 57 72 40 72 C23 72 8 57 8 40 C8 23 23 8 40 8 Z");
        fill: var(--tovio-primary, #D42027);
    }
    20% {
        d: path("M40 8 C57 8 72 23 72 40 C72 57 57 72 40 72 C23 72 8 57 8 40 C8 23 23 8 40 8 Z");
        fill: #E87722;
    }
    40% {
        d: path("M40 10 C56 10 70 24 70 40 C70 56 56 70 40 70 C24 70 10 56 10 40 C10 24 24 10 40 10 Z");
        fill: #C5D942;
    }
    60% {
        d: path("M40 8 C57 8 72 23 72 40 C72 57 57 72 40 72 C23 72 8 57 8 40 C8 23 23 8 40 8 Z");
        fill: var(--tovio-accent, #FCD116);
    }
    80% {
        d: path("M40 12 C60 12 68 24 68 40 C68 56 60 68 40 68 C20 68 12 56 12 40 C12 24 20 12 40 12 Z");
        fill: var(--tovio-secondary, #009E49);
    }
}

@keyframes ballLinesMorph {
    0%, 100% {
        /* Football pentagon pattern */
        d: path("M40 20 L32 28 L35 38 L45 38 L48 28 Z M25 40 L15 40 M55 40 L65 40 M40 55 L40 65");
        opacity: 1;
    }
    20% {
        /* Basketball lines */
        d: path("M40 8 L40 72 M8 40 L72 40 M15 18 C28 30 52 30 65 18 M15 62 C28 50 52 50 65 62");
        opacity: 1;
    }
    40% {
        /* Tennis curve */
        d: path("M20 15 C30 35 50 45 60 65 M15 50 C35 45 45 35 65 30");
        opacity: 0.6;
    }
    60% {
        /* Volleyball panels */
        d: path("M40 8 L40 72 M12 25 L68 55 M68 25 L12 55");
        opacity: 1;
    }
    80% {
        /* Rugby laces */
        d: path("M40 22 L40 58 M34 28 L46 28 M34 52 L46 52 M36 40 L44 40");
        opacity: 0.8;
    }
}

@keyframes ballTextFade {
    0%, 15%   { opacity: 1; }
    18%, 35%  { opacity: 0; }
    20%, 33%  { opacity: 1; }
    38%, 55%  { opacity: 0; }
    40%, 53%  { opacity: 1; }
    58%, 75%  { opacity: 0; }
    60%, 73%  { opacity: 1; }
    78%, 95%  { opacity: 0; }
    80%, 93%  { opacity: 1; }
    98%       { opacity: 0; }
}

/* Bounce effect */
.loader-ball-morph svg {
    animation: ballBounce 1s ease-in-out infinite;
}

@keyframes ballBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

/* ========== TYPE 2: MAILLOT QUI SE COLORIE ========== */
.loader-jersey-fill {
    width: 100px;
    height: 110px;
    position: relative;
}

.loader-jersey-fill svg {
    width: 100px;
    height: 110px;
    filter: drop-shadow(0 0 20px rgba(206, 17, 38, 0.2));
}

.loader-jersey-fill .jersey-outline {
    fill: none;
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 2;
}

.loader-jersey-fill .jersey-fill-color {
    fill: var(--tovio-primary, #D42027);
    clip-path: inset(100% 0 0 0);
    animation: jerseyFillUp 2.5s ease-in-out infinite;
}

@keyframes jerseyFillUp {
    0% {
        clip-path: inset(100% 0 0 0);
        fill: var(--tovio-secondary, #009E49);
    }
    40% {
        fill: var(--tovio-accent, #FCD116);
    }
    70% {
        clip-path: inset(0% 0 0 0);
        fill: var(--tovio-primary, #D42027);
    }
    85% {
        clip-path: inset(0% 0 0 0);
        fill: var(--tovio-primary, #D42027);
    }
    100% {
        clip-path: inset(100% 0 0 0);
        fill: var(--tovio-secondary, #009E49);
    }
}

/* Number pulse on jersey */
.loader-jersey-fill .jersey-number {
    font-family: 'Oswald', 'Bebas Neue', sans-serif;
    font-size: 28px;
    font-weight: 700;
    fill: white;
    text-anchor: middle;
    opacity: 0.9;
    animation: numberPulse 2.5s ease-in-out infinite;
}

@keyframes numberPulse {
    0%, 100% { opacity: 0.2; }
    70%, 85% { opacity: 0.9; }
}

/* ========== TYPE 3: CHAUSSURE REBOND ========== */
.loader-shoe-bounce {
    width: 100px;
    height: 80px;
    position: relative;
}

.loader-shoe-bounce svg {
    width: 100px;
    height: 80px;
    animation: shoeRun 0.8s ease-in-out infinite;
    filter: drop-shadow(0 0 15px rgba(206, 17, 38, 0.3));
}

.loader-shoe-bounce .shoe-body {
    fill: var(--tovio-primary, #D42027);
}

.loader-shoe-bounce .shoe-sole {
    fill: var(--tovio-dark, #1A1A1A);
}

.loader-shoe-bounce .shoe-accent {
    fill: var(--tovio-accent, #FCD116);
}

.loader-shoe-bounce .shoe-laces {
    fill: none;
    stroke: white;
    stroke-width: 1.5;
    stroke-linecap: round;
}

@keyframes shoeRun {
    0% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-15px) rotate(-5deg); }
    50% { transform: translateY(0) rotate(0deg); }
    75% { transform: translateY(-8px) rotate(3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

/* Speed lines */
.loader-shoe-bounce::before,
.loader-shoe-bounce::after {
    content: '';
    position: absolute;
    left: -20px;
    height: 2px;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.4), transparent);
    animation: speedLines 0.8s ease-in-out infinite;
}

.loader-shoe-bounce::before {
    top: 30%;
    width: 25px;
    animation-delay: 0.1s;
}

.loader-shoe-bounce::after {
    top: 55%;
    width: 18px;
    animation-delay: 0.3s;
}

@keyframes speedLines {
    0% { opacity: 0; transform: translateX(10px); }
    50% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(-10px); }
}

/* ========== TYPE 4: CERCLE DRAPEAU BURKINA ========== */
.loader-flag-circle {
    width: 90px;
    height: 90px;
    position: relative;
}

.loader-flag-circle svg {
    width: 90px;
    height: 90px;
    animation: flagSpin 3s linear infinite;
}

.loader-flag-circle .flag-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 6;
}

.loader-flag-circle .flag-red {
    fill: none;
    stroke: var(--tovio-primary, #D42027);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 75.4;
    stroke-dashoffset: 75.4;
    animation: flagSegment 2s ease-in-out infinite;
    animation-delay: 0s;
}

.loader-flag-circle .flag-green {
    fill: none;
    stroke: var(--tovio-secondary, #009E49);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 75.4;
    stroke-dashoffset: 75.4;
    animation: flagSegment 2s ease-in-out infinite;
    animation-delay: 0.3s;
}

.loader-flag-circle .flag-yellow {
    fill: none;
    stroke: var(--tovio-accent, #FCD116);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 75.4;
    stroke-dashoffset: 75.4;
    animation: flagSegment 2s ease-in-out infinite;
    animation-delay: 0.6s;
}

@keyframes flagSegment {
    0% { stroke-dashoffset: 75.4; }
    40% { stroke-dashoffset: 0; }
    60% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -75.4; }
}

@keyframes flagSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Star in center */
.loader-flag-circle .flag-star {
    fill: var(--tovio-accent, #FCD116);
    animation: starPulse 1s ease-in-out infinite;
}

@keyframes starPulse {
    0%, 100% { opacity: 0.5; transform-origin: center; transform: scale(1); }
    50% { opacity: 1; transform-origin: center; transform: scale(1.15); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 767px) {
    .tovio-loader-label {
        font-size: 0.75rem;
        letter-spacing: 3px;
    }
}
