/* Shared public control, independent of the theme's legacy scroll button. */
.public-back-to-top {
    --back-top-accent: #14815d;
    --back-top-track: rgba(20, 129, 93, .14);
    --back-top-progress: 100;
    position: fixed;
    right: calc(24px + env(safe-area-inset-right, 0px));
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    z-index: 1025;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    max-width: calc(100vw - 32px);
    padding: 4px 18px 4px 4px;
    border: 1px solid rgba(20, 129, 93, .2);
    border-radius: 999px;
    color: #205440;
    background: linear-gradient(135deg, rgba(255, 255, 255, .96), rgba(226, 248, 237, .94));
    box-shadow: 0 8px 28px rgba(14, 46, 32, .12), inset 0 1px 0 rgba(255, 255, 255, .8);
    -webkit-backdrop-filter: saturate(150%) blur(16px);
    backdrop-filter: saturate(150%) blur(16px);
    font: 600 13px/1.2 var(--fireball-font-sans, system-ui, sans-serif);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(12px) scale(.96);
    transition: opacity .3s ease, transform .4s cubic-bezier(.22, 1, .36, 1),
        visibility .3s, border-color .3s ease, box-shadow .3s ease;
}

.public-back-to-top[hidden] {
    display: none;
}

.public-back-to-top.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.public-back-to-top__icon {
    display: block;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    color: var(--back-top-accent);
}

.public-back-to-top__track {
    stroke: var(--back-top-track);
}

.public-back-to-top__progress {
    stroke: currentColor;
    stroke-dasharray: 100;
    stroke-dashoffset: var(--back-top-progress);
    transform: rotate(-90deg);
    transform-origin: 22px 22px;
    transition: stroke-dashoffset .12s linear;
}

.public-back-to-top__arrow {
    transition: transform .3s cubic-bezier(.22, 1, .36, 1);
}

.public-back-to-top__label {
    white-space: nowrap;
}

.public-back-to-top:focus-visible {
    outline: 3px solid var(--back-top-accent);
    outline-offset: 4px;
}

@media (hover: hover) and (pointer: fine) {
    .public-back-to-top.is-visible:hover {
        transform: translateY(-3px);
        border-color: var(--back-top-accent);
        box-shadow: 0 12px 32px rgba(14, 95, 65, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
    }

    .public-back-to-top:hover .public-back-to-top__arrow {
        transform: translateY(-2px);
    }
}

.public-back-to-top.is-visible:active {
    transform: translateY(0) scale(.94);
}

[data-bs-theme="dark"] .public-back-to-top {
    --back-top-accent: #78e5b6;
    --back-top-track: rgba(120, 229, 182, .17);
    color: #d1f7e5;
    border-color: rgba(120, 229, 182, .24);
    background: linear-gradient(135deg, rgba(32, 43, 38, .95), rgba(21, 31, 27, .93));
    box-shadow: 0 8px 28px rgba(0, 0, 0, .24), inset 0 1px 0 rgba(255, 255, 255, .06);
}

body.is-site-fullscreen .public-back-to-top,
html.chat-viewport-fullscreen .public-back-to-top {
    display: none;
}

body.has-open-offcanvas .public-back-to-top,
body.modal-open .public-back-to-top {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

@media (max-width: 575.98px) {
    .public-back-to-top {
        right: calc(16px + env(safe-area-inset-right, 0px));
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        padding: 4px;
    }

    .public-back-to-top__label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .public-back-to-top,
    .public-back-to-top__progress,
    .public-back-to-top__arrow {
        transition: none;
    }
}
