/**
 * Back to Top Button
 * Floating Action Button (FAB) for scrolling back to top
 */

.back-to-top {
    position: fixed;
    bottom: 80px; /* Above mobile bottom nav */
    right: 16px;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #FFB81C 0%, #f0a800 100%);
    color: #041E42;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255, 184, 28, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.back-to-top:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 20px rgba(255, 184, 28, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.back-to-top:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 2px 8px rgba(255, 184, 28, 0.4);
}

.back-to-top svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    transform: rotate(-90deg);
}

/* Add subtle pulse animation when first appearing */
@keyframes pulseBackToTop {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-4px) scale(1.05);
    }
}

.back-to-top.visible.pulse {
    animation: pulseBackToTop 1s ease-in-out 2;
}

/* Adjust position on desktop */
@media (min-width: 1025px) {
    .back-to-top {
        bottom: 24px;
        right: 24px;
        width: 56px;
        height: 56px;
    }

    .back-to-top svg {
        width: 28px;
        height: 28px;
    }
}

/* Adjust for very small mobile screens */
@media (max-width: 360px) {
    .back-to-top {
        width: 44px;
        height: 44px;
        bottom: 76px;
        right: 12px;
    }

    .back-to-top svg {
        width: 20px;
        height: 20px;
    }
}

/* Safe area support for iPhone notch */
.back-to-top {
    bottom: calc(80px + env(safe-area-inset-bottom));
    right: calc(16px + env(safe-area-inset-right));
}

@media (min-width: 1025px) {
    .back-to-top {
        bottom: calc(24px + env(safe-area-inset-bottom));
        right: calc(24px + env(safe-area-inset-right));
    }
}

/* Add number badge showing scroll position */
.back-to-top .scroll-progress {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
}

.back-to-top .scroll-progress-ring {
    transform: rotate(-90deg);
}

.back-to-top .scroll-progress-circle {
    stroke: rgba(4, 30, 66, 0.3);
    stroke-width: 2;
    fill: none;
    transition: stroke-dashoffset 0.1s linear;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .back-to-top {
        background: linear-gradient(135deg, #FFB81C 0%, #f0a800 100%);
        color: #041E42;
    }

    .back-to-top .scroll-progress-circle {
        stroke: rgba(255, 255, 255, 0.3);
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .back-to-top {
        border: 2px solid #041E42;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .back-to-top {
        transition: opacity 0.2s ease, visibility 0.2s ease;
        transform: none !important;
    }

    .back-to-top:hover,
    .back-to-top:active {
        transform: none !important;
    }

    .back-to-top.visible.pulse {
        animation: none;
    }
}

/* Accessibility - keyboard focus */
.back-to-top:focus {
    outline: 3px solid #FFB81C;
    outline-offset: 2px;
}

.back-to-top:focus:not(:focus-visible) {
    outline: none;
}

.back-to-top:focus-visible {
    outline: 3px solid #FFB81C;
    outline-offset: 2px;
}

/* Add ripple effect */
.back-to-top::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(4, 30, 66, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.back-to-top:active::before {
    width: 100%;
    height: 100%;
}

/* Label for accessibility (visually hidden but screen reader accessible) */
.back-to-top .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
