/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 60px;
    right: 49%;
    background-color: var(--white);
    color: var(--black);
    border: 2px solid var(--black);
    width: 6.5vw;
    height: 6.5vw;
    max-width: 60px;
    max-height: 60px;
    min-width: 30px;
    min-height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 999;
    /* Default state: hidden */
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s, visibility 0s 0.3s;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    pointer-events: none; /* Prevent clicks when hidden visually */
    box-shadow: 4px 4px 0px rgba(0,0,0,1);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    /* Transition when appearing: no delay on visibility */
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s, visibility 0s 0s;
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top,
    .back-to-top.visible {
        transition: none !important;
        transform: none !important;
    }
}

.back-to-top:hover {
    background-color: var(--yellow);
    transform: translateY(-5px);
    box-shadow: 6px 6px 0px rgba(0,0,0,1);
}

.back-to-top:focus-visible {
    outline: 2px solid var(--black);
    outline-offset: 4px;
    background-color: var(--yellow);
}

/* Ensure SVG inherits color */
.back-to-top svg {
    display: block;
}

/* Tooltip for Back to Top */
.back-to-top .tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background-color: var(--black);
    color: var(--yellow);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    font-family: 'Instrument Sans', sans-serif;
    font-weight: 500;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.back-to-top:hover .tooltip,
.back-to-top:focus-visible .tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-12px);
}

@media (max-width: 768px) {
    .back-to-top {
        left: 20px;
    }
}
