/**
 * Back to Top Button Styles
 * Requirements: 3.8
 * 
 * A button that appears for long articles and scrolls smoothly to top
 */

.back-to-top {
    position: fixed;
    bottom: 90px;
    width: 48px;
    height: 48px;
    border: none;
    background: var(--color-primary, #3b82f6);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3), 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 999;
    opacity: 0;
    transform: translateY(20px) scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease;
    pointer-events: none;
}

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

/* Position variants */
.back-to-top--right {
    right: 24px;
}

.back-to-top--left {
    left: 24px;
}

/* Hover state */
.back-to-top:hover {
    background: var(--color-primary-dark, #2563eb);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4), 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Active state */
.back-to-top:active {
    transform: translateY(0) scale(0.95);
}

/* Focus state */
.back-to-top:focus {
    outline: 2px solid var(--color-primary, #3b82f6);
    outline-offset: 4px;
}

/* Icon */
.back-to-top__icon {
    flex-shrink: 0;
    animation: arrowBounce 2s ease-in-out infinite;
}

@keyframes arrowBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

/* Stop animation on hover */
.back-to-top:hover .back-to-top__icon {
    animation: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .back-to-top {
        width: 44px;
        height: 44px;
        bottom: 74px;
    }
    
    .back-to-top--right {
        right: 16px;
    }
    
    .back-to-top--left {
        left: 16px;
    }
    
    .back-to-top__icon {
        width: 20px;
        height: 20px;
    }
}

/* Dark mode support */
[data-theme="dark"] .back-to-top {
    background: var(--color-primary-dark, #2563eb);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .back-to-top:hover {
    background: var(--color-primary, #3b82f6);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5), 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* Accessibility: Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .back-to-top {
        transition: opacity 0.1s ease;
    }
    
    .back-to-top__icon {
        animation: none;
    }
    
    .back-to-top:hover {
        transform: none;
    }
}

/* Print: Hide back to top button */
@media print {
    .back-to-top {
        display: none;
    }
}

/* Adjust position when floating action bar is present */
.floating-action-bar.visible ~ .back-to-top {
    bottom: 160px;
}

@media (max-width: 768px) {
    .floating-action-bar.visible ~ .back-to-top {
        bottom: 140px;
    }
}
