/**
 * 局部修改页面动画效果
 * 提供流畅的交互体验和视觉反馈
 */

/* ==================== 全局动画 ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 141, 148, 0.3);
    }
    50% {
        box-shadow: 0 0 30px rgba(0, 141, 148, 0.6);
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ==================== 页面加载动画 ==================== */
.sidebar {
    animation: slideInLeft 0.6s ease-out;
}

.main-content {
    animation: slideInRight 0.6s ease-out;
}

.section-title {
    animation: fadeIn 0.8s ease-out;
}

/* ==================== 上传区域动画 ==================== */
.upload-area {
    position: relative;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.upload-area::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(0, 141, 148, 0.1) 50%,
        transparent 70%
    );
    transform: rotate(45deg);
    transition: all 0.6s;
    opacity: 0;
}

.upload-area:hover::before {
    opacity: 1;
    animation: shimmer 2s infinite;
}

.upload-area.dragover {
    transform: scale(1.02);
    border-color: #008d94 !important;
    background: rgba(0, 141, 148, 0.1) !important;
    box-shadow: 0 0 30px rgba(0, 141, 148, 0.3);
}

.upload-icon {
    transition: all 0.3s;
}

.upload-area:hover .upload-icon {
    animation: float 2s ease-in-out infinite;
}

/* ==================== 工具选项动画 ==================== */
.tool-option {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tool-option::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(0, 141, 148, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.tool-option:hover::before {
    width: 300px;
    height: 300px;
}

.tool-option:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 141, 148, 0.3);
}

.tool-option.active {
    animation: pulse 2s ease-in-out infinite;
}

.tool-icon {
    transition: all 0.3s;
    display: inline-block;
}

.tool-option:hover .tool-icon {
    transform: scale(1.2) rotate(10deg);
}

.tool-option.active .tool-icon {
    animation: float 3s ease-in-out infinite;
}

/* ==================== 画布工具按钮动画 ==================== */
.canvas-tool-btn {
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.canvas-tool-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #008d94 0%, #FFC145 100%);
    transform: translateX(-50%);
    transition: width 0.3s;
}

.canvas-tool-btn:hover::after {
    width: 80%;
}

.canvas-tool-btn.active::after {
    width: 100%;
}

.canvas-tool-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 141, 148, 0.2);
}

/* ==================== 画布容器动画 ==================== */
.canvas-container {
    transition: all 0.3s;
}

.canvas-wrapper {
    animation: scaleIn 0.5s ease-out;
}

#image-canvas, #mask-canvas {
    transition: all 0.3s;
}

/* ==================== 按钮动画 ==================== */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 141, 148, 0.4);
}

.btn-primary:not(:disabled):active {
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(0, 141, 148, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 141, 148, 0.3);
}

/* ==================== 进度条动画 ==================== */
.progress-bar {
    position: relative;
    overflow: hidden;
    background: #2A2D30;
    height: 8px;
    border-radius: 4px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-fill {
    position: relative;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(90deg, #008d94 0%, #FFC145 100%);
    box-shadow: 0 0 10px rgba(0, 141, 148, 0.5);
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 2s infinite;
}

.progress-text {
    color: #008d94;
    font-weight: 600;
    margin-top: 10px;
    display: none;
}

/* ==================== 画笔光标动画 ==================== */
#mask-canvas {
    cursor: crosshair;
}

#mask-canvas.drawing {
    cursor: none;
}

/* 自定义画笔光标 */
.brush-cursor {
    position: fixed;
    border: 2px solid #008d94;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
    transform: translate(-50%, -50%);
    transition: width 0.1s, height 0.1s;
    box-shadow: 0 0 10px rgba(0, 141, 148, 0.5);
}

/* ==================== 信息框动画 ==================== */
.info-box {
    animation: fadeIn 0.8s ease-out;
    position: relative;
    overflow: hidden;
}

.info-box::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 4px;
    background: linear-gradient(180deg, #008d94 0%, #FFC145 100%);
    animation: glow 2s ease-in-out infinite;
}

/* ==================== 文件信息动画 ==================== */
.file-info {
    animation: slideInLeft 0.4s ease-out;
    transition: all 0.3s;
}

.file-info:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* ==================== 滑块动画 ==================== */
.slider {
    transition: all 0.3s;
}

.slider::-webkit-slider-thumb {
    transition: all 0.3s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(0, 141, 148, 0.6);
}

.slider::-moz-range-thumb {
    transition: all 0.3s;
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(0, 141, 148, 0.6);
}

/* ==================== 加载动画 ==================== */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 141, 148, 0.3);
    border-top-color: #008d94;
    border-radius: 50%;
    animation: rotate 1s linear infinite;
}

/* ==================== 返回顶部按钮 ==================== */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #008d94 0%, #006b70 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0, 141, 148, 0.3);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 141, 148, 0.5);
}

/* ==================== 通知动画 ==================== */
.notification {
    animation: slideInRight 0.3s ease-out;
    transition: all 0.3s;
}

.notification.hiding {
    animation: slideInRight 0.3s ease-out reverse;
}

/* ==================== 响应式动画调整 ==================== */
@media (max-width: 768px) {
    .sidebar,
    .main-content {
        animation-duration: 0.4s;
    }
    
    .tool-option:hover,
    .canvas-tool-btn:hover {
        transform: none;
    }
    
    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
}

/* ==================== 性能优化 ==================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== 画布绘制效果 ==================== */
@keyframes drawPulse {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

.drawing-indicator {
    animation: drawPulse 1s ease-in-out infinite;
}

/* ==================== 结果对比动画 ==================== */
.comparison-slider {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.comparison-slider:hover {
    transform: scale(1.05);
}

/* ==================== 工具提示动画 ==================== */
.tooltip {
    position: relative;
}

.tooltip .tooltiptext {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
