<template>
    <!-- wrapper controls opacity so animation on the inner element is unaffected -->
    <div class="scroll-indicator-fade" :style="{ opacity: indicatorOpacity }">
        <div class="scroll-indicator">
            <div class="scroll-mouse">
                <div class="scroll-dot"></div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const indicatorOpacity = ref(1)

function handleScroll() {
    const maxScroll = 200
    const scrolled = window.scrollY
    indicatorOpacity.value = Math.max(0, 1 - scrolled / maxScroll)
}

onMounted(() => {
    window.addEventListener('scroll', handleScroll, { passive: true })
})

onUnmounted(() => {
    window.removeEventListener('scroll', handleScroll)
})
</script>

<style scoped>
/* wrapper: centering + fade transition */
.scroll-indicator-fade {
    position: fixed;
    bottom: 2dvh;
    left: 50%;
    transform: translateX(-50%); /* keep horizontal centering here */
    transition: opacity 0.3s ease;
    pointer-events: none; /* prevents accidental clicks while visible */
}

/* inner element has the bounce animation — animate translateY only */
.scroll-indicator {
    animation: bounce 2s infinite;
    /* no translateX here; wrapper handles the horizontal offset */
}

.scroll-mouse {
    width: 24px;
    height: 40px;
    border: 2px solid var(--foreground);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    padding-top: 8px;
}

.scroll-dot {
    width: 4px;
    height: 12px;
    background: var(--foreground);
    border-radius: 2px;
    animation: pulse 2s infinite;
}

/* bounce now only moves Y — no translateX so it won't conflict */
@keyframes bounce {
    0%, 20%, 53%, 80%, 100% { transform: translateY(0); }
    40%, 43% { transform: translateY(-15px); }
    70% { transform: translateY(-7px); }
    90% { transform: translateY(-2px); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
</style>
