/* ==========================================================================
   SCROLL TO TOP
   css only: the link points to "#top", smooth scrolling comes from scroll-behavior,
   showing the button after 100px of scrolling from a scroll-driven animation.
   markup: footer.php
   ========================================================================== */

/* note: this also smooths all other in-page links (e.g. the menu anchors). */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

.scroll-to-top {
    position: fixed;
    right: 80px;
    bottom: 0;
    z-index: 998;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: var(--color-grey-100);
    color: var(--color-grey-400);
    font-size: 25px;
    text-decoration: none;
    transition: background-color .25s ease-in-out, color .25s ease-in-out;
}

.scroll-to-top:is(:hover, :focus-visible) {
    background: var(--color-blue);
    color: var(--color-white);
}

.scroll-to-top:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

/* progressive enhancement: hidden at the top of the page, fades in while scrolling from 100px to 200px.
   without support the button is always visible. */
@supports (animation-timeline: scroll()) {
    .scroll-to-top {
        animation: scroll-to-top-show linear both;
        animation-timeline: scroll(root);
        animation-range: 100px 200px;
    }
}

/* visibility: hidden at the start, so the invisible button can't be clicked or focused. */
@keyframes scroll-to-top-show {
    from {
        opacity: 0;
        visibility: hidden;
    }

    to {
        opacity: 1;
        visibility: visible;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scroll-to-top {
        transition: none;
    }
}
