:root {
    --spuf-blue: #0057b8;
    --spuf-yellow: #ffd700;
}

.spuf-wrap {
    --spuf-width: 140px;
    --spuf-offset-x: 20px;
    --spuf-offset-y: 20px;
    --spuf-speed: 4.5s;
    position: fixed;
    z-index: 2147482000;
    width: var(--spuf-width);
    max-width: calc(100vw - 20px);
    pointer-events: none;
    perspective: 700px;
    line-height: 1;
    box-sizing: border-box;
}

.spuf-wrap *,
.spuf-wrap *::before,
.spuf-wrap *::after {
    box-sizing: border-box;
}

.spuf-flag {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 3 / 2;
    overflow: hidden;
    transform-origin: 0 50%;
    transform-style: preserve-3d;
    background: linear-gradient(to bottom, var(--spuf-blue) 0 50%, var(--spuf-yellow) 50% 100%);
    box-shadow: 0 12px 28px rgba(0, 0, 0, .2), 0 3px 8px rgba(0, 0, 0, .14);
    will-change: transform;
}

.spuf-flag::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    background:
        linear-gradient(100deg, transparent 0%, rgba(255,255,255,.12) 24%, transparent 43%, rgba(0,0,0,.08) 62%, transparent 78%),
        repeating-linear-gradient(90deg, rgba(255,255,255,.025) 0 1px, rgba(0,0,0,.018) 1px 3px);
    background-size: 170% 100%, 7px 100%;
    mix-blend-mode: soft-light;
    pointer-events: none;
}

.spuf-flag::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    border: 1px solid rgba(255,255,255,.2);
    pointer-events: none;
}

.spuf-no-shadow .spuf-flag {
    box-shadow: none;
}

/* Positioning */
.spuf-position-top-left { top: var(--spuf-offset-y); left: var(--spuf-offset-x); }
.spuf-position-top-center { top: var(--spuf-offset-y); left: 50%; transform: translateX(-50%); }
.spuf-position-top-right { top: var(--spuf-offset-y); right: var(--spuf-offset-x); }
.spuf-position-middle-left { top: 50%; left: var(--spuf-offset-x); transform: translateY(-50%); }
.spuf-position-middle-right { top: 50%; right: var(--spuf-offset-x); transform: translateY(-50%); }
.spuf-position-bottom-left { bottom: var(--spuf-offset-y); left: var(--spuf-offset-x); }
.spuf-position-bottom-center { bottom: var(--spuf-offset-y); left: 50%; transform: translateX(-50%); }
.spuf-position-bottom-right { bottom: var(--spuf-offset-y); right: var(--spuf-offset-x); }

/* Visual variants */
.spuf-style-classic .spuf-flag {
    border-radius: 2px;
}

.spuf-style-soft-wave .spuf-flag {
    clip-path: polygon(0 3%, 12% 1%, 25% 4%, 39% 1%, 53% 4%, 67% 1%, 81% 4%, 100% 1%, 97% 24%, 100% 50%, 96% 76%, 100% 99%, 82% 96%, 67% 99%, 52% 96%, 38% 99%, 24% 96%, 10% 99%, 0 96%);
    border-radius: 3px 12px 12px 3px;
}

.spuf-style-ribbon .spuf-flag {
    clip-path: polygon(0 0, 100% 0, 92% 50%, 100% 100%, 0 100%);
}

.spuf-style-rounded .spuf-flag {
    border-radius: max(8px, calc(var(--spuf-width) * .07));
    box-shadow: 0 14px 32px rgba(0, 87, 184, .18), 0 8px 20px rgba(0, 0, 0, .16);
}

.spuf-style-pole {
    width: calc(var(--spuf-width) + 8px);
    padding-left: 8px;
}

.spuf-style-pole::before {
    content: "";
    position: absolute;
    left: 2px;
    top: -8px;
    bottom: -14px;
    width: 5px;
    border-radius: 4px;
    background: linear-gradient(to right, #8e8e8e, #f0f0f0 45%, #8b8b8b);
    box-shadow: 0 1px 5px rgba(0,0,0,.25);
}

.spuf-style-pole::after {
    content: "";
    position: absolute;
    left: 0;
    top: -13px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f6d764, #9f7112);
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.spuf-style-pole .spuf-flag {
    border-radius: 0 7px 7px 0;
}

/* Motion */
.spuf-animation-breeze .spuf-flag {
    animation: spuf-breeze var(--spuf-speed) ease-in-out infinite;
}
.spuf-animation-breeze .spuf-flag::before {
    animation: spuf-light calc(var(--spuf-speed) * .8) linear infinite;
}

.spuf-animation-wave .spuf-flag {
    animation: spuf-wave var(--spuf-speed) cubic-bezier(.45,.05,.55,.95) infinite;
}
.spuf-animation-wave .spuf-flag::before {
    animation: spuf-light calc(var(--spuf-speed) * .65) linear infinite;
}

.spuf-animation-none .spuf-flag,
.spuf-animation-none .spuf-flag::before {
    animation: none;
}

@keyframes spuf-breeze {
    0%, 100% { transform: rotateY(0deg) skewY(0deg) translateZ(0); }
    25% { transform: rotateY(-7deg) skewY(.7deg) translateZ(0); }
    50% { transform: rotateY(5deg) skewY(-.55deg) translateZ(0); }
    75% { transform: rotateY(-4deg) skewY(.35deg) translateZ(0); }
}

@keyframes spuf-wave {
    0%, 100% { transform: rotateY(0deg) rotateZ(0deg) skewY(0deg); }
    20% { transform: rotateY(-12deg) rotateZ(.7deg) skewY(1deg); }
    42% { transform: rotateY(8deg) rotateZ(-.5deg) skewY(-1.1deg); }
    67% { transform: rotateY(-10deg) rotateZ(.45deg) skewY(.75deg); }
    84% { transform: rotateY(5deg) rotateZ(-.25deg) skewY(-.4deg); }
}

@keyframes spuf-light {
    0% { background-position: 130% 0, 0 0; }
    100% { background-position: -70% 0, 14px 0; }
}

@media (max-width: 782px) {
    .spuf-wrap {
        max-width: 150px;
    }
    .spuf-hide-mobile {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .spuf-flag,
    .spuf-flag::before {
        animation: none !important;
    }
}
