document.addEventListener('DOMContentLoaded', function () {

    const backToTop = document.querySelector('.modern-back-to-top');

    if (!backToTop) {
        return;
    }

    const toggleBackToTop = function () {

        if (window.scrollY > 400) {
            backToTop.classList.add('show');
        } else {
            backToTop.classList.remove('show');
        }

    };

    window.addEventListener('scroll', toggleBackToTop, {
        passive: true
    });

    backToTop.addEventListener('click', function () {

        window.scrollTo({
            top: 0,
            behavior: 'smooth'
        });

    });

    toggleBackToTop();

});