/* ================================================
   拉绳式主题切换器 - 创意样式
   ================================================ */

/* CSS变量 */
:root {
    --pull-switch-rope-color: #8b7355;
    --pull-switch-handle-dark: #667eea;
    --pull-switch-handle-light: #ffd93d;
    --pull-switch-mount-color: #34495e;
    --pull-switch-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 主容器 */
.pull-switch {
    position: fixed !important;
    top: 0 !important;
    right: 40px !important;
    z-index: 99999 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

/* 固定装置 */
.pull-switch-mount {
    position: relative;
    width: 60px;
    height: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pull-switch-mount-plate {
    width: 50px;
    height: 8px;
    background: linear-gradient(180deg, #506175 0%, #34495e 50%, #2c3e50 100%);
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3),
                inset 0 1px 1px rgba(255, 255, 255, 0.1),
                inset 0 -1px 1px rgba(0, 0, 0, 0.3);
}

.pull-switch-mount-screw {
    position: absolute;
    width: 6px;
    height: 6px;
    background: radial-gradient(circle at 30% 30%, #7f8c8d 0%, #2c3e50 100%);
    border-radius: 50%;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.pull-switch-mount-screw::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 0.5px;
    background: rgba(0, 0, 0, 0.6);
}

.pull-switch-mount-screw.screw-1 {
    left: 8px;
}

.pull-switch-mount-screw.screw-2 {
    right: 8px;
}

/* 绳子 */
.pull-switch-rope {
    width: 6px;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform-origin: top center;
    transition: var(--pull-switch-transition);
}

.rope-segment {
    width: 100%;
    height: 16px;
    background: repeating-linear-gradient(
        0deg,
        var(--pull-switch-rope-color) 0px,
        #a0826d 2px,
        var(--pull-switch-rope-color) 4px
    );
    position: relative;
}

.rope-segment::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
}

.rope-segment::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
}

.pull-switch-rope.stretched {
    transform: scaleY(1.3);
    transition: transform 0.2s ease-out;
}

/* 拉手 */
.pull-switch-handle {
    position: relative;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    cursor: grab;
    padding: 0;
    outline: none;
    transition: var(--pull-switch-transition);
    transform-origin: top center;
}

.pull-switch-handle:active,
.pull-switch-handle.touching {
    cursor: grabbing;
}

.handle-body {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--pull-switch-handle-dark) 0%, #764ba2 100%);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4),
                0 2px 4px rgba(0, 0, 0, 0.2),
                inset 0 -2px 4px rgba(0, 0, 0, 0.2),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
    transition: var(--pull-switch-transition);
    overflow: hidden;
}

body[data-theme="light"] .handle-body {
    background: linear-gradient(135deg, var(--pull-switch-handle-light) 0%, #f5576c 100%);
    box-shadow: 0 4px 12px rgba(255, 217, 61, 0.5),
                0 2px 4px rgba(0, 0, 0, 0.1),
                inset 0 -2px 4px rgba(0, 0, 0, 0.1),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* 高光效果 */
.handle-shine {
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    height: 50%;
    background: linear-gradient(180deg,
                                rgba(255, 255, 255, 0.4) 0%,
                                transparent 100%);
    border-radius: 50% 50% 100% 100%;
    z-index: 5; /* 确保高光在背景之上，但在图标之下 */
    pointer-events: none; /* 确保不影响点击事件 */
}

/* 图标 */
.handle-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translate(-50%, -50%);
    z-index: 10; /* 确保图标在高光效果之上 */
}

.handle-icon svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    display: block;
    margin: auto;
}

/* 阴影 */
.handle-shadow {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 8px;
    background: radial-gradient(ellipse at center,
                                rgba(0, 0, 0, 0.3) 0%,
                                transparent 70%);
    transition: var(--pull-switch-transition);
}

/* 拉动动画 */
.pull-switch.pulling .pull-switch-handle {
    animation: pullDown 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pullDown {
    0% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(30px);
    }
    60% {
        transform: translateY(-5px);
    }
    80% {
        transform: translateY(2px);
    }
    100% {
        transform: translateY(0);
    }
}

.pull-switch-handle.pulled {
    transform: translateY(30px);
}

/* 悬停效果 */
.pull-switch:hover .handle-body {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6),
                0 2px 4px rgba(0, 0, 0, 0.2),
                inset 0 -2px 4px rgba(0, 0, 0, 0.2),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

body[data-theme="light"] .pull-switch:hover .handle-body {
    box-shadow: 0 6px 20px rgba(255, 217, 61, 0.7),
                0 2px 4px rgba(0, 0, 0, 0.1),
                inset 0 -2px 4px rgba(0, 0, 0, 0.1),
                inset 0 2px 4px rgba(255, 255, 255, 0.4);
}

.pull-switch:hover .handle-shadow {
    transform: translateX(-50%) scale(1.1);
    opacity: 0.7;
}

/* 粒子效果 */
.pull-switch-particles {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.particle {
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 4px;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.8) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0;
    transform: translate(-50%, -50%);
}

body[data-theme="light"] .particle {
    background: radial-gradient(circle, rgba(255, 217, 61, 0.8) 0%, transparent 70%);
}

.pull-switch-particles.active .particle {
    animation: particleBurst 0.8s ease-out forwards;
}

@keyframes particleBurst {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) translateX(0) translateY(0) scale(0);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%)
                   translateX(calc(cos(var(--angle)) * 50px))
                   translateY(calc(sin(var(--angle)) * 50px))
                   scale(1.5);
    }
}

/* 焦点样式 */
.pull-switch-handle:focus-visible {
    outline: none;
}

.pull-switch-handle:focus-visible .handle-body {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.5),
                0 4px 12px rgba(102, 126, 234, 0.4),
                0 2px 4px rgba(0, 0, 0, 0.2),
                inset 0 -2px 4px rgba(0, 0, 0, 0.2),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

/* 浅色主题下的焦点 */
body[data-theme="light"] .pull-switch-handle:focus-visible .handle-body {
    box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.5),
                0 4px 12px rgba(255, 217, 61, 0.5),
                0 2px 4px rgba(0, 0, 0, 0.1),
                inset 0 -2px 4px rgba(0, 0, 0, 0.1),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* 响应式 - 平板 */
@media (max-width: 1024px) {
    .pull-switch {
        right: 30px !important;
    }

    .pull-switch-mount {
        width: 50px;
    }

    .pull-switch-mount-plate {
        width: 40px;
    }

    .pull-switch-rope {
        height: 70px;
    }

    .pull-switch-handle {
        width: 36px;
        height: 36px;
    }

    .handle-icon {
        width: 18px;
        height: 18px;
    }
}

/* 响应式 - 移动端 */
@media (max-width: 768px) {
    .pull-switch {
        right: 20px !important;
    }

    .pull-switch-mount {
        width: 45px;
        height: 10px;
    }

    .pull-switch-mount-plate {
        width: 36px;
        height: 6px;
    }

    .pull-switch-mount-screw {
        width: 5px;
        height: 5px;
    }

    .pull-switch-rope {
        width: 5px;
        height: 60px;
    }

    .rope-segment {
        height: 12px;
    }

    .pull-switch-handle {
        width: 32px;
        height: 32px;
    }

    .handle-icon {
        width: 16px;
        height: 16px;
    }
}

/* 超小屏幕 */
@media (max-width: 480px) {
    .pull-switch {
        right: 15px !important;
    }

    .pull-switch-mount {
        width: 40px;
    }

    .pull-switch-mount-plate {
        width: 32px;
    }

    .pull-switch-rope {
        height: 50px;
    }

    .pull-switch-handle {
        width: 28px;
        height: 28px;
    }

    .handle-icon {
        width: 14px;
        height: 14px;
    }
}

/* 摇摆动画（闲置时） */
@keyframes gentleSwing {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(2deg);
    }
    75% {
        transform: rotate(-2deg);
    }
}

.pull-switch:not(.pulling) .pull-switch-rope {
    animation: gentleSwing 4s ease-in-out infinite;
}

.pull-switch:not(.pulling) .pull-switch-handle {
    animation: gentleSwing 4s ease-in-out infinite;
}

/* 打印时隐藏 */
@media print {
    .pull-switch {
        display: none !important;
    }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    .pull-switch-rope,
    .pull-switch-handle,
    .handle-body,
    .particle {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .pull-switch-mount-plate {
        border: 2px solid currentColor;
    }

    .handle-body {
        border: 2px solid currentColor;
    }
}
