    (function() {
        const goTopBtn = document.getElementById('goTopBtn');
        if (!goTopBtn) return;

        const BREAKPOINT = 1024;
        const RIGHT_OFFSET = -70;  // 大屏时距离 .wrap 右侧 -70px

        function updatePosition() {
            const wrap = document.querySelector('.wrap');
            const winWidth = window.innerWidth;

            if (winWidth > BREAKPOINT && wrap) {
                const wrapRect = wrap.getBoundingClientRect();
                const rightValue = winWidth - wrapRect.right + RIGHT_OFFSET;
                goTopBtn.style.right = rightValue + 'px';
                if (rightValue < 10) goTopBtn.style.right = '10px'; // 防止溢出左侧
            } else {
                goTopBtn.style.right = '20px';
            }
        }

        function toggleVisibility() {
            const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
            if (scrollTop > 200) {
                goTopBtn.classList.add('show');
            } else {
                goTopBtn.classList.remove('show');
            }
        }

        goTopBtn.addEventListener('click', (e) => {
            e.preventDefault();
            window.scrollTo({ top: 0, behavior: 'smooth' });
        });

        window.addEventListener('scroll', toggleVisibility);
        window.addEventListener('resize', () => {
            updatePosition();
            toggleVisibility();
        });
        window.addEventListener('load', updatePosition);
        setTimeout(updatePosition, 100);

        updatePosition();
        toggleVisibility();
    })();