/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

/* 应用容器 */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 上传区域 */
.upload-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.upload-section h1 {
    text-align: center;
    margin-bottom: 24px;
    color: #2c3e50;
    font-size: 1.8rem;
    font-weight: 600;
}

.upload-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.upload-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-btn {
    display: inline-block;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.upload-status {
    font-size: 0.9rem;
    color: #666;
    text-align: center;
}

/* Canvas容器 - 双层重叠效果 */
.canvas-container {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    overflow: hidden;
}

.fullscreen-btn {
    position: absolute;
    top: 25px;
    right: 25px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.fullscreen-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.fullscreen-btn svg {
    width: 20px;
    height: 20px;
    fill: #333;
}

.canvas-container.fullscreen .icon-fullscreen-enter {
    display: none;
}

.canvas-container.fullscreen .icon-fullscreen-exit {
    display: block !important;
}

.canvas-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    border-radius: 0;
    z-index: 999;
}

.canvas-container.fullscreen #background-canvas,
.canvas-container.fullscreen .overlay-canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
}

/* Canvas占位符 */
.canvas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    text-align: center;
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.placeholder-text {
    font-size: 1.1rem;
    font-weight: 500;
}

#background-canvas,
.overlay-canvas {
    position: absolute;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    max-width: calc(100% - 40px);
    max-height: 70vh;
    object-fit: contain;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: none; /* 初始隐藏，直到图片加载完成 */
}

#background-canvas {
    z-index: 1;
}

.overlay-canvas {
    z-index: 2;
    transition: opacity 0.3s ease;
}

.overlay-canvas.hidden {
    opacity: 0;
}

/* 拖拽横线 */
.drag-line {
    position: absolute;
    width: 100%;
    height: 2px;
    background: #ff6b6b;
    cursor: ns-resize;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: none; /* 初始隐藏 */
}

.drag-line::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 18px;
    background: #ff6b6b;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

.drag-line::after {
    content: '⋮⋮⋮';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 12px;
    line-height: 18px;
    pointer-events: none;
}

.canvas-container.images-loaded:hover .drag-line,
.drag-line.dragging {
    opacity: 1;
}

.drag-line.dragging {
    opacity: 1 !important;
}

.drag-line.dragging::before {
    background: #ff5252;
    transform: translateX(-50%) scale(1.1);
}

/* 控制面板 */
.control-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.control-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-weight: 500;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-bottom: 4px;
}

.control-item label:not(.control-label) {
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 4px;
    display: block;
}

.control-item label span {
    color: #667eea;
    font-weight: 600;
}

/* 开关样式 */
input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    transition: background 0.3s ease;
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

input[type="checkbox"]:checked + .toggle-slider {
    background: #667eea;
}

input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(26px);
}

/* 滑动条样式 */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.3s ease;
}

.slider:focus {
    background: #ccc;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
}

.slider::-webkit-slider-thumb:active {
    transform: scale(1.2);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.8);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
}

.slider::-moz-range-thumb:active {
    transform: scale(1.2);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.8);
}

/* 使用说明 */
.instructions {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    margin-bottom: 20px;
}

.instructions h3 {
    color: #2c3e50;
    margin-bottom: 16px;
    font-size: 1.2rem;
    font-weight: 600;
}

.instructions ol {
    margin-bottom: 16px;
    padding-left: 20px;
}

.instructions li {
    margin-bottom: 8px;
    color: #555;
    line-height: 1.5;
}

.instructions .tips {
    background: rgba(102, 126, 234, 0.1);
    border-left: 4px solid #667eea;
    padding: 12px 16px;
    border-radius: 4px;
    color: #2c3e50;
    font-size: 0.9rem;
}

.instructions .tips strong {
    color: #667eea;
}

/* 操作按钮 */
.action-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-btn {
    padding: 12px 32px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.action-btn.primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.action-btn.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.action-btn.primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #666;
    border: 2px solid #ddd;
}

.action-btn.secondary:hover {
    background: white;
    border-color: #667eea;
    color: #667eea;
}

.action-btn.tertiary {
    background: rgba(255, 255, 255, 0.9);
    color: #e74c3c;
    border: 1px solid #e74c3c;
    font-size: 14px;
    transition: all 0.3s ease;
}

.action-btn.tertiary:hover {
    background: #e74c3c;
    border-color: #e74c3c;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
}

/* 错误提示 */
.error-message {
    background: #ff6b6b;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin-top: 16px;
    display: none;
    text-align: center;
    animation: slideIn 0.3s ease;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    max-width: 90%;
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.4);
}

.error-message.show {
    display: block;
}

/* 成功提示 */
.success-message {
    background: #4CAF50;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin-top: 16px;
    display: none;
    text-align: center;
    animation: slideIn 0.3s ease;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    max-width: 90%;
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.4);
}

/* 加载提示 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    color: white;
    font-size: 1.1rem;
}

/* 动画 */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 移动设备支持 */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
        gap: 16px;
    }
    
    .upload-section h1 {
        font-size: 1.5rem;
    }
    
    .upload-controls {
        grid-template-columns: 1fr;
    }
    
    .canvas-container {
        padding: 16px;
        min-height: 300px;
    }
    
    #background-canvas,
    .overlay-canvas {
        max-height: 50vh;
    }
    
    .control-group {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .action-btn {
        width: 100%;
        max-width: 280px;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 12px;
    }
    
    .upload-section,
    .canvas-container,
    .control-panel {
        padding: 16px;
    }
    
    .upload-section h1 {
        font-size: 1.3rem;
        margin-bottom: 16px;
    }
    
    .upload-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

/* 控制面板交互状态 */
.control-item:hover .slider {
    background: #ccc;
}

.control-item:hover label span {
    color: #5a67d8;
}

/* 拖拽状态下的视觉反馈 */
.canvas-container.dragging {
    cursor: ns-resize;
}

.canvas-container.dragging .drag-line {
    opacity: 1 !important;
}

/* 触摸设备交互优化 */
@media (hover: none) and (pointer: coarse) {
    .upload-btn:hover {
        transform: none;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    }
    
    .action-btn.primary:hover:not(:disabled) {
        transform: none;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    }
    
    .slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .slider.touching::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.8);
    }
    
    .drag-line {
        opacity: 0;
    }
    
    .drag-line::before {
        width: 50px;
        height: 24px;
        top: -11px;
    }
    
    .drag-line::after {
        top: -11px;
        line-height: 24px;
    }
}

/* 加载状态优化 */
.loading-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* 按钮禁用状态优化 */
.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* 错误和成功消息的响应式优化 */
@media (max-width: 480px) {
    .error-message,
    .success-message {
        left: 10px;
        right: 10px;
        transform: none;
        max-width: none;
        margin: 0;
    }
}

/* 性能优化：减少重绘 */
.canvas-container,
#background-canvas,
.overlay-canvas {
    will-change: transform;
}

.drag-line {
    will-change: top, opacity;
}

.slider::-webkit-slider-thumb {
    will-change: transform, box-shadow;
}

/* 跨浏览器兼容性 */
.slider {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.toggle-slider {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #background-canvas,
    .overlay-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}