/* CyberForge Arcade — Back to Top button with scroll progress ring
 *
 * A floating action button anchored bottom-right that surfaces once the
 * user has scrolled meaningfully (>= 1.5 viewport heights). The button
 * is wrapped in a circular SVG ring whose `stroke-dashoffset` is updated
 * by backToTop.js to visualize total page scroll progress.
 *
 * Themed entirely through CSS variables (--primary, --background,
 * --glow-color-*), so it adapts automatically to preset and custom
 * themes. Respects prefers-reduced-motion. Sits above the games grid
 * and game cards (z-index 80) but below modals (z-index 1000+).
 */

.back-to-top {
    position: fixed;
    /* Use safe-area insets for modern iOS so the button doesn't sit
       under the home indicator. The bottom offset is chosen to clear
       the .fullscreen-button (anchored at bottom:1rem, ~2.5rem tall)
       with a comfortable gap so the two FABs never overlap. */
    right: calc(1.25rem + env(safe-area-inset-right, 0px));
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
    z-index: 80;
    /* Hidden initial state. .visible flips it in. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.92);
    transition:
        opacity 0.25s ease,
        transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1.1),
        visibility 0s linear 0.25s;
    pointer-events: none;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition:
        opacity 0.25s ease,
        transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1.1),
        visibility 0s linear 0s;
    pointer-events: auto;
}

/* The clickable area sits inside the SVG ring. Use a button so it gets
   default keyboard focus / activation semantics. */
.back-to-top-button {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.78);
    border: 1px solid var(--primary);
    color: var(--text);
    font-size: 1.05rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 0 14px var(--glow-color-40);
    transition:
        background 0.18s ease,
        color 0.18s ease,
        transform 0.18s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease;
}

.back-to-top-button:hover,
.back-to-top-button:focus-visible {
    background: var(--primary);
    color: var(--background);
    border-color: var(--secondary);
    transform: scale(1.06);
    box-shadow: 0 0 20px var(--glow-color-60), 0 0 36px var(--glow-color-40);
    outline: none;
}

.back-to-top-button:active {
    transform: scale(0.96);
}

/* The progress ring is an absolutely-positioned SVG. The track is a
   faint full circle; the indicator is a stroked circle whose dash
   offset is updated in JS to reflect scroll progress (0 = full circle
   visible, circumference = empty). */
.back-to-top-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: rotate(-90deg); /* start the progress at 12 o'clock */
    overflow: visible;
}

.back-to-top-ring circle {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}

.back-to-top-ring .ring-track {
    stroke: rgba(255, 255, 255, 0.12);
}

.back-to-top-ring .ring-progress {
    stroke: var(--primary);
    /* stroke-dasharray + stroke-dashoffset are set by JS for animation. */
    transition: stroke-dashoffset 0.18s linear, stroke 0.2s ease;
    filter: drop-shadow(0 0 6px var(--glow-color-40));
}

.back-to-top.visible .back-to-top-ring .ring-progress {
    stroke: var(--primary);
}

/* Small screens: shrink slightly to leave room for game cards. */
@media (max-width: 480px) {
    .back-to-top {
        width: 48px;
        height: 48px;
        right: calc(0.85rem + env(safe-area-inset-right, 0px));
        /* Keep clear of the fullscreen button on phones too. */
        bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
    }
    .back-to-top-button {
        font-size: 0.95rem;
    }
}

/* Suspend ring drop-shadow / scale animation under prefers-reduced-motion. */
@media (prefers-reduced-motion: reduce) {
    .back-to-top,
    .back-to-top-button,
    .back-to-top-ring .ring-progress {
        transition: none !important;
    }
    .back-to-top-button:hover,
    .back-to-top-button:focus-visible {
        transform: none;
    }
}
