/* =========================================
   BACK TO TOP BUTTON - PREMIUM VERSION
   ========================================= */

#backToTop {
    position: fixed;
    bottom: 10px;
    right: 25px;
    width: 65px;
    height: 65px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d6efd, #3b82f6);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 8px 25px rgba(13, 110, 253, 0.35);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(30px) scale(0.8);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Show button */
#backToTop.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Arrow */
#backToTop .arrow {
    font-size: 28px;
    color: white;
    position: absolute;
    z-index: 2;
    transition: transform 0.3s ease;
    line-height: 1;
}

/* Hover */
#backToTop:hover {
    transform: scale(1.12);
    box-shadow: 0 12px 35px rgba(13, 110, 253, 0.55);
}

/* Arrow hover movement */
#backToTop:hover .arrow {
    transform: translateY(-5px);
}

/* Progress ring */
.progress-ring {
    position: absolute;
    transform: rotate(-90deg);
    width: 70px;
    height: 70px;
}

.progress-ring circle {
    fill: none;
    stroke: rgba(255, 255, 255, 0.4);
    stroke-width: 4;
    stroke-linecap: round;
    cx: 35;
    cy: 35;
    r: 30;
    stroke-dasharray: 188.5; /* 2 * PI * 30 = 188.5 */
    stroke-dashoffset: 188.5;
    transition: stroke-dashoffset 0.15s linear;
}

/* Floating animation */
@keyframes floating {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-6px); }
    100% { transform: translateY(0px); }
}

#backToTop.show {
    animation: floating 2s infinite ease-in-out;
}

/* Pulse glow */
#backToTop::before {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.3);
    animation: pulse 2s infinite;
    z-index: 1;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    70% {
        transform: scale(1.5);
        opacity: 0;
    }
    100% {
        opacity: 0;
    }
}

/* =========================================
   RESPONSIVE MEDIA QUERIES
   ========================================= */

/* Tablet - 768px to 1024px */
@media (max-width: 1024px) {
    #backToTop {
        bottom: 30px;
        right: 25px;
        width: 58px;
        height: 58px;
        box-shadow: 0 6px 20px rgba(13, 110, 253, 0.30);
    }

    #backToTop .arrow {
        font-size: 24px;
    }

    .progress-ring {
        width: 62px;
        height: 62px;
    }

    .progress-ring circle {
        stroke-width: 3.5;
        cx: 31;
        cy: 31;
        r: 26;
        stroke-dasharray: 163.36; /* 2 * PI * 26 = 163.36 */
        stroke-dashoffset: 163.36;
    }

    @keyframes floating {
        0% { transform: translateY(0px); }
        50% { transform: translateY(-5px); }
        100% { transform: translateY(0px); }
    }

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.6; }
        70% { transform: scale(1.4); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* Mobile Large - 480px to 768px */
@media (max-width: 768px) {
    #backToTop {
        bottom: 25px;
        right: 20px;
        width: 52px;
        height: 52px;
        box-shadow: 0 5px 18px rgba(13, 110, 253, 0.28);
    }

    #backToTop .arrow {
        font-size: 20px;
    }

    .progress-ring {
        width: 56px;
        height: 56px;
    }

    .progress-ring circle {
        stroke-width: 3;
        cx: 28;
        cy: 28;
        r: 23;
        stroke-dasharray: 144.51; /* 2 * PI * 23 = 144.51 */
        stroke-dashoffset: 144.51;
    }

    #backToTop:hover {
        transform: scale(1.08);
    }

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

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.5; }
        70% { transform: scale(1.3); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* Mobile Medium - 380px to 480px */
@media (max-width: 480px) {
    #backToTop {
        bottom: 20px;
        right: 15px;
        width: 46px;
        height: 46px;
        box-shadow: 0 4px 15px rgba(13, 110, 253, 0.25);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #backToTop .arrow {
        font-size: 18px;
    }

    .progress-ring {
        width: 50px;
        height: 50px;
    }

    .progress-ring circle {
        stroke-width: 2.5;
        cx: 25;
        cy: 25;
        r: 20;
        stroke-dasharray: 125.66; /* 2 * PI * 20 = 125.66 */
        stroke-dashoffset: 125.66;
    }

    #backToTop:hover {
        transform: scale(1.05);
        box-shadow: 0 6px 20px rgba(13, 110, 253, 0.35);
    }

    #backToTop.show {
        animation: floating 2s infinite ease-in-out;
    }

    @keyframes floating {
        0% { transform: translateY(0px); }
        50% { transform: translateY(-3px); }
        100% { transform: translateY(0px); }
    }

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.4; }
        70% { transform: scale(1.2); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* Mobile Small - 320px to 380px */
@media (max-width: 380px) {
    #backToTop {
        bottom: 15px;
        right: 12px;
        width: 40px;
        height: 40px;
        box-shadow: 0 3px 12px rgba(13, 110, 253, 0.20);
    }

    #backToTop .arrow {
        font-size: 16px;
    }

    .progress-ring {
        width: 44px;
        height: 44px;
    }

    .progress-ring circle {
        stroke-width: 2;
        cx: 22;
        cy: 22;
        r: 17;
        stroke-dasharray: 106.81; /* 2 * PI * 17 = 106.81 */
        stroke-dashoffset: 106.81;
    }

    #backToTop::before {
        animation: pulse 2s infinite;
    }

    @keyframes floating {
        0% { transform: translateY(0px); }
        50% { transform: translateY(-2px); }
        100% { transform: translateY(0px); }
    }

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.3; }
        70% { transform: scale(1.15); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* Extra Small - 280px to 320px */
@media (max-width: 320px) {
    #backToTop {
        bottom: 12px;
        right: 10px;
        width: 36px;
        height: 36px;
        box-shadow: 0 2px 10px rgba(13, 110, 253, 0.18);
    }

    #backToTop .arrow {
        font-size: 14px;
    }

    .progress-ring {
        width: 40px;
        height: 40px;
    }

    .progress-ring circle {
        stroke-width: 2;
        cx: 20;
        cy: 20;
        r: 15;
        stroke-dasharray: 94.25; /* 2 * PI * 15 = 94.25 */
        stroke-dashoffset: 94.25;
    }

    @keyframes floating {
        0% { transform: translateY(0px); }
        50% { transform: translateY(-2px); }
        100% { transform: translateY(0px); }
    }

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.25; }
        70% { transform: scale(1.1); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* Landscape Mode for Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #backToTop {
        bottom: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
    }

    #backToTop .arrow {
        font-size: 18px;
    }

    .progress-ring {
        width: 48px;
        height: 48px;
    }

    .progress-ring circle {
        stroke-width: 2.5;
        cx: 24;
        cy: 24;
        r: 19;
        stroke-dasharray: 119.38; /* 2 * PI * 19 = 119.38 */
        stroke-dashoffset: 119.38;
    }

    @keyframes floating {
        0% { transform: translateY(0px); }
        50% { transform: translateY(-3px); }
        100% { transform: translateY(0px); }
    }

    @keyframes pulse {
        0% { transform: scale(1); opacity: 0.4; }
        70% { transform: scale(1.2); opacity: 0; }
        100% { opacity: 0; }
    }
}

/* =========================================
   REDUCED MOTION PREFERENCE
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    #backToTop {
        animation: none !important;
        transition: opacity 0.3s ease, visibility 0.3s ease !important;
    }

    #backToTop::before {
        animation: none !important;
    }

    #backToTop .arrow {
        transition: none !important;
    }

    #backToTop:hover {
        transform: scale(1.05) !important;
    }

    #backToTop.show {
        animation: none !important;
    }

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

    @keyframes pulse {
        0%, 100% { opacity: 0.3; transform: scale(1); }
    }
}

/* =========================================
   TOUCH DEVICE OPTIMIZATION
   ========================================= */
@media (hover: none) and (pointer: coarse) {
    #backToTop {
        width: 52px;
        height: 52px;
        bottom: 25px;
        right: 20px;
    }

    #backToTop .arrow {
        font-size: 20px;
    }

    .progress-ring {
        width: 56px;
        height: 56px;
    }

    .progress-ring circle {
        cx: 28;
        cy: 28;
        r: 23;
        stroke-dasharray: 144.51;
        stroke-dashoffset: 144.51;
    }

    /* Disable hover effects on touch devices */
    #backToTop:hover {
        transform: scale(1) !important;
    }

    #backToTop:hover .arrow {
        transform: translateY(0) !important;
    }

    /* Active state for touch feedback */
    #backToTop:active {
        transform: scale(0.92) !important;
        box-shadow: 0 4px 15px rgba(13, 110, 253, 0.2) !important;
    }
}