/* ========================================
   万能抠图工具 - 精致样式表 v2.0
   现代化设计语言、微交互动效、高质感视觉
   ======================================== */

/* ===== CSS 变量 ===== */
:root {
    --brand: #f97316;
    --brand-dark: #ea580c;
    --brand-light: #fff7ed;
    --brand-glow: rgba(249, 115, 22, 0.15);
    --surface: #ffffff;
    --surface-hover: #fafafa;
    --border: #f0f0f0;
    --border-hover: #e5e5e5;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== 工具卡片 - 玻璃质感 ===== */
.tool-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm), 0 0 0 0 rgba(249,115,22,0);
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}
.tool-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, transparent 60%, rgba(249,115,22,0.02) 100%);
    pointer-events: none;
}
.tool-card:hover {
    box-shadow: var(--shadow-md), 0 0 0 0 rgba(249,115,22,0);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

/* ===== Section 标题 ===== */
.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    letter-spacing: -0.01em;
}

/* ===== 上传覆盖层（嵌入画布内，填满原图区） ===== */
.upload-overlay {
    position: absolute;
    inset: 0;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #e2e8f0;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #fafbfc 0%, #f8fafc 100%);
    transition: all var(--transition-smooth);
    margin: 0;
}
.upload-overlay:hover {
    border-color: #fbbf24;
    background: linear-gradient(135deg, #fff7ed 0%, #fffbeb 100%);
    box-shadow: inset 0 0 0 6px rgba(251,191,36,0.06);
}
.upload-overlay.dragover {
    border-color: var(--brand);
    border-style: solid;
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    box-shadow: inset 0 0 0 12px rgba(249,115,22,0.08);
    animation: uploadPulse 0.6s ease-in-out infinite;
}
/* 已加载图片 → 隐藏上传覆盖层 */
.upload-overlay[data-loaded="true"] {
    display: none;
}

/* 旧上传区（兼容） */
.upload-area {
    border: 2px dashed #e2e8f0;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #fafbfc 0%, #f8fafc 100%);
    transition: all var(--transition-smooth);
    position: relative;
}
.upload-area::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    border: 2px solid transparent;
    pointer-events: none;
    transition: border-color var(--transition-smooth);
}
.upload-area:hover {
    border-color: #fbbf24;
    background: linear-gradient(135deg, #fff7ed 0%, #fffbeb 100%);
    box-shadow: 0 0 0 6px rgba(251,191,36,0.06);
    transform: scale(1.005);
}
.upload-area:hover::after {
    border-color: rgba(249,115,22,0.15);
}
.upload-area.dragover {
    border-color: var(--brand);
    border-style: solid;
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    box-shadow: 0 0 0 12px rgba(249,115,22,0.08);
    transform: scale(1.01);
    animation: uploadPulse 0.6s ease-in-out infinite;
}

/* 已加载图片状态 */
.upload-area[data-loaded="true"] {
    border-color: #22c55e;
    border-style: solid;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
}
.upload-area[data-loaded="true"]:hover {
    border-color: var(--brand);
    background: linear-gradient(135deg, #fff7ed 0%, #fffbeb 100%);
}

@keyframes uploadPulse {
    0%, 100% { box-shadow: 0 0 0 12px rgba(249,115,22,0.08); }
    50% { box-shadow: 0 0 0 18px rgba(249,115,22,0.04); }
}

.upload-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    border: 2px solid #fed7aa;
    box-shadow: 0 4px 16px rgba(249,115,22,0.12);
    transition: all var(--transition-bounce);
}
.upload-area:hover .upload-icon-wrap {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(249,115,22,0.2);
}

/* ===== 参数值标签 ===== */
.param-badge {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand);
    background: var(--brand-light);
    padding: 3px 10px;
    border-radius: 9999px;
    border: 1.5px solid #fed7aa;
    min-width: 38px;
    text-align: center;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    transition: all var(--transition-fast);
}

/* ===== 自定义滑动条 - 填充轨道 ===== */
.styled-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 9999px;
    background: #f1f5f9;
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.styled-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 9999px;
}
.styled-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--brand);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(249,115,22,0.3);
    transition: all var(--transition-bounce);
    margin-top: -8px;
    position: relative;
}
.styled-range::-webkit-slider-thumb:hover {
    transform: scale(1.25);
    box-shadow: 0 4px 16px rgba(249,115,22,0.4);
    border-color: var(--brand-dark);
}
.styled-range::-webkit-slider-thumb:active {
    transform: scale(1.15);
    box-shadow: 0 2px 6px rgba(249,115,22,0.35);
}
.styled-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--brand);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(249,115,22,0.3);
    transition: all var(--transition-bounce);
}
.styled-range::-moz-range-thumb:hover {
    transform: scale(1.25);
    box-shadow: 0 4px 16px rgba(249,115,22,0.4);
    border-color: var(--brand-dark);
}

/* ===== 滑块填充进度 - 使用 JS 动态设置 ===== */
.range-with-fill {
    position: relative;
}
.range-fill {
    position: absolute;
    top: 50%;
    left: 0;
    height: 6px;
    border-radius: 9999px;
    background: linear-gradient(90deg, #fed7aa, var(--brand));
    pointer-events: none;
    transform: translateY(-50%);
    transition: width 0.1s linear;
}

/* ===== 颜色输入框 ===== */
.color-input-wrap {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 2.5px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    transition: all var(--transition-bounce);
    flex-shrink: 0;
    cursor: pointer;
}
.color-input-wrap:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 14px rgba(249,115,22,0.2);
    transform: scale(1.08);
}
.color-input-wrap input[type="color"] {
    width: 130%;
    height: 130%;
    margin: -15%;
    border: 0;
    padding: 0;
    cursor: pointer;
    background: transparent;
}

/* ===== 颜色芯片按钮 ===== */
.color-chip {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    background: #f8fafc;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-bounce);
    outline: none;
    position: relative;
}
.color-chip:hover {
    background: #f1f5f9;
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.color-chip:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 3px;
}
.color-chip.active {
    border-color: var(--brand);
    background: var(--brand-light);
    box-shadow: 0 0 0 4px var(--brand-glow);
    transform: scale(1.1);
}
.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: block;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.1);
    transition: transform var(--transition-bounce);
}
.color-chip:hover .color-dot {
    transform: scale(1.1);
}

/* ===== 主按钮 ===== */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 0;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    letter-spacing: 0.03em;
    box-shadow: 0 2px 10px rgba(249,115,22,0.35), 0 1px 3px rgba(249,115,22,0.25);
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}
.btn-primary::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.1) 50%, transparent 100%);
    pointer-events: none;
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
    box-shadow: 0 6px 20px rgba(249,115,22,0.45), 0 2px 6px rgba(249,115,22,0.3);
    transform: translateY(-2px);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 6px rgba(249,115,22,0.3);
    transition: all 0.1s ease;
}
.btn-primary:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.btn-primary:disabled::after {
    display: none;
}

/* ===== 次要按钮 ===== */
.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 0;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    cursor: pointer;
    transition: all var(--transition-smooth);
}
.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
    box-shadow: var(--shadow-sm);
}
.btn-secondary:active {
    background: #e2e8f0;
    transition: all 0.1s ease;
}

/* ===== 成功/导出按钮 ===== */
.btn-success {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 0;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    letter-spacing: 0.03em;
    box-shadow: 0 2px 10px rgba(34,197,94,0.35), 0 1px 3px rgba(34,197,94,0.25);
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}
.btn-success::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
    pointer-events: none;
}
.btn-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    box-shadow: 0 6px 20px rgba(34,197,94,0.45), 0 2px 6px rgba(34,197,94,0.3);
    transform: translateY(-2px);
}
.btn-success:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 6px rgba(34,197,94,0.3);
    transition: all 0.1s ease;
}
.btn-success:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.btn-success:disabled::after {
    display: none;
}

/* ===== 提示卡片 - 渐变背景 ===== */
.tips-card {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 50%, #fef9c3 100%);
    border: 1px solid #fde68a;
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: 0 2px 8px rgba(251,191,36,0.08);
    position: relative;
    overflow: hidden;
}
.tips-card::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, rgba(251,191,36,0.15) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

/* ===== 画布容器 ===== */
.canvas-wrapper {
    cursor: crosshair;
    flex: 1;
    background-color: #fafbfc;
    background-image: 
        linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
        linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    min-height: 260px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
}
@media (min-width: 1024px) {
    .canvas-wrapper {
        min-height: 480px;
    }
}
@media (max-width: 639px) {
    .canvas-wrapper {
        min-height: 220px;
        background-size: 14px 14px;
        background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
    }
}

/* ===== 缩放控制栏 ===== */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 3px;
    box-shadow: var(--shadow-sm);
}
.zoom-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    color: #64748b;
    transition: all var(--transition-fast);
    font-size: 16px;
    font-weight: 600;
}
.zoom-btn:hover {
    background: #fff;
    color: var(--brand);
    box-shadow: var(--shadow-sm);
}
.zoom-btn:active {
    background: var(--brand-light);
}
.zoom-level {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: center;
    user-select: none;
}

/* ===== 实时预览开关 ===== */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 9999px;
    transition: all var(--transition-smooth);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: all var(--transition-bounce);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--brand);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ===== 蒙版画布层 ===== */
.mask-canvas {
    pointer-events: none;
}

/* ===== 空状态图标 ===== */
.empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1.5px solid #e2e8f0;
    transition: all var(--transition-smooth);
}

/* ===== 选区指示器 ===== */
.selection-indicator {
    display: inline-block;
    width: 20px;
    height: 3px;
    background: repeating-linear-gradient(90deg, var(--brand) 0, var(--brand) 4px, transparent 4px, transparent 8px);
    border-radius: 2px;
    vertical-align: middle;
}

/* ===== 选区缩放手柄 ===== */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid var(--brand);
    border-radius: 3px;
    pointer-events: auto;
    z-index: 5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    transition: all var(--transition-fast);
}
.resize-handle:hover {
    background: var(--brand);
    transform: scale(1.5);
    box-shadow: 0 2px 8px rgba(249,115,22,0.3);
}
.resize-handle.nw { cursor: nw-resize; top: -5px; left: -5px; }
.resize-handle.n  { cursor: n-resize;  top: -5px; left: 50%; margin-left: -5px; }
.resize-handle.ne { cursor: ne-resize; top: -5px; right: -5px; }
.resize-handle.e  { cursor: e-resize;  top: 50%; right: -5px; margin-top: -5px; }
.resize-handle.se { cursor: se-resize; bottom: -5px; right: -5px; }
.resize-handle.s  { cursor: s-resize;  bottom: -5px; left: 50%; margin-left: -5px; }
.resize-handle.sw { cursor: sw-resize; bottom: -5px; left: -5px; }
.resize-handle.w  { cursor: w-resize;  top: 50%; left: -5px; margin-top: -5px; }

/* 选区高亮框 */
.selection-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 3;
}
.selection-overlay .fill {
    position: absolute;
    inset: 0;
    background: rgba(249, 115, 22, 0.12);
    border-radius: 2px;
}
.selection-overlay .border {
    position: absolute;
    inset: 0;
    border: 2px dashed var(--brand);
    border-radius: 2px;
}

/* ===== 结果预览区 ===== */
.result-preview {
    background-color: #fafbfc;
    background-image: 
        linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
        linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
}

/* 预览图淡入动画 */
@keyframes sealReveal {
    from { opacity: 0; transform: scale(0.9); filter: blur(4px); }
    to   { opacity: 1; transform: scale(1); filter: blur(0); }
}
#sealPreview {
    animation: sealReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-radius: 4px;
    image-rendering: auto;
    -ms-interpolation-mode: bicubic;
}

/* ===== 提取统计面板 ===== */
.stats-panel {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.stat-item {
    flex: 1;
    min-width: 80px;
    text-align: center;
    padding: 10px 8px;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border-radius: 12px;
    border: 1px solid var(--border);
}
.stat-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--brand);
    line-height: 1;
}
.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* 预览区内嵌统计（紧凑） */
.compare-preview .stats-panel .stat-item {
    padding: 6px 10px;
    min-width: 60px;
}
.compare-preview .stats-panel .stat-value {
    font-size: 15px;
}


/* ===== 加载动画 ===== */
.loader-ring {
    width: 40px;
    height: 40px;
    border: 3px solid #fed7aa;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto;
}

.loader-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
}
.loader-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
    animation: dotBounce 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== 处理中遮罩层 ===== */
.processing-overlay {
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* ===== 动画关键帧 ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.animate-fade-in-up {
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-slide-in {
    animation: slideInRight 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-pop-in {
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== 键盘快捷键提示 ===== */
.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    color: #64748b;
    line-height: 1;
    font-family: inherit;
    box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

/* ===== 并排对比布局 ===== */
.compare-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: stretch;
}
.compare-pane {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    min-height: 260px;
    display: flex;
    flex-direction: column;
}
@media (min-width: 1024px) {
    .compare-pane { min-height: 480px; }
}
@media (max-width: 639px) {
    .compare-pane { min-height: 220px; }
}
.compare-original {
    background: #fafbfc;
}
.compare-preview {
    background-color: #fafbfc;
    background-image: 
        linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
        linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
        linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}
.compare-label {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 9999px;
    z-index: 10;
    letter-spacing: 0.04em;
    pointer-events: none;
}

/* 预览包裹器 */
.preview-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    position: relative;
    transition: background var(--transition-fast);
}
@media (min-width: 1024px) {
    .preview-wrapper { min-height: 480px; }
}
@media (max-width: 639px) {
    .preview-wrapper { min-height: 220px; }
}
@media (max-width: 767px) {
    .preview-wrapper { min-height: 220px; }
}
.preview-wrapper:hover {
    background: rgba(249, 115, 22, 0.03);
}
.preview-processing {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.7);
    z-index: 5;
}

/* 预览画布 */
#previewCanvas {
    border-radius: 6px;
    max-width: 100%;
    max-height: 100%;
}

/* ===== 比较视图（旧版兼容） ===== */
.compare-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.compare-pane.legacy {
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* ===== 响应式微调 ===== */
@media (max-width: 639px) {
    .tool-card {
        border-radius: var(--radius-md);
    }
    .upload-area {
        padding: 20px 12px;
    }
    .upload-icon-wrap {
        width: 44px;
        height: 44px;
    }
    .compare-view,
    .compare-split {
        grid-template-columns: 1fr;
    }
    .compare-pane {
        min-height: 180px;
    }
    .preview-wrapper {
        min-height: 180px;
    }
    .stats-panel {
        flex-direction: column;
    }
}

/* ===== 焦点可见性 ===== */
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ===== 侧边栏细节组（保持） ===== */
details.group summary::-webkit-details-marker {
    display: none;
}

/* ===== 按钮禁用通用 ===== */
button:disabled {
    opacity: 1;
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== 选择文本 ===== */
::selection {
    background: rgba(249, 115, 22, 0.2);
    color: inherit;
}

/* ===== 颜色处理 - 色板芯片 ===== */
.palette-chip {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 2.5px solid transparent;
    cursor: pointer;
    position: relative;
    transition: all var(--transition-bounce);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1), inset 0 2px 4px rgba(255,255,255,0.3);
    padding: 0;
    outline: none;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: hidden;
}
.palette-chip:hover {
    transform: scale(1.18);
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    z-index: 2;
}
.palette-chip.active {
    border-color: #f97316;
    transform: scale(1.15);
    box-shadow: 0 0 0 4px rgba(249,115,22,0.25), 0 4px 12px rgba(0,0,0,0.15);
}
.chip-pct {
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: rgba(0,0,0,0.45);
    padding: 1px 5px;
    border-radius: 4px 4px 6px 6px;
    line-height: 1;
    margin-bottom: 2px;
    text-shadow: 0 1px 1px rgba(0,0,0,0.3);
}

/* ===== 颜色处理操作按钮悬浮效果 ===== */
#selectByColorBtn:hover:not(:disabled) {
    background: #dbeafe !important;
    border-color: #93c5fd !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37,99,235,0.15);
}
#deleteByColorBtn:hover:not(:disabled) {
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(220,38,38,0.15);
}
#recolorBtn:hover:not(:disabled) {
    background: #ede9fe !important;
    border-color: #c4b5fd !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(124,58,237,0.15);
}

/* 保留上色按钮悬浮 */
#cropToRecolorBtn:hover:not(:disabled) {
    background: #d1fae5 !important;
    border-color: #6ee7b7 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(5,150,105,0.15);
}

/* 框选删除按钮悬浮 */
#boxDeleteBtn:hover:not(:disabled) {
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(220,38,38,0.15);
}

/* 撤销按钮悬浮 */
#undoColorOpBtn:hover:not(:disabled) {
    background: #e2e8f0 !important;
    border-color: #cbd5e1 !important;
    transform: translateY(-1px);
}

/* ===== 吸管按钮激活态 ===== */
#eyedropperBtn:active,
#eyedropperBtn.active-mode {
    background: #fed7aa !important;
    box-shadow: 0 0 0 3px rgba(249,115,22,0.2);
}

/* ===== 模式选择器 ===== */
.mode-selector {
    display: flex;
    gap: 4px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 4px;
}
.mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 6px 7px;
    background: transparent;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    transition: all var(--transition-smooth);
    outline: none;
    position: relative;
    color: #94a3b8;
}
.mode-btn:hover:not(.active) {
    background: #f1f5f9;
    color: #64748b;
}
.mode-btn.active {
    background: #fff;
    color: var(--brand);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 0 0 1px rgba(249,115,22,0.15);
    transform: translateY(-1px);
}
.mode-btn:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}
.mode-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f1f5f9;
    transition: all var(--transition-smooth);
}
.mode-btn.active .mode-icon {
    background: var(--brand-light);
    box-shadow: 0 2px 6px var(--brand-glow);
}
.mode-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

/* 模式切换动画 */
@keyframes modeSwitchIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
#modeDescription {
    animation: modeSwitchIn 0.25s ease-out;
}
#colorPickSection,
#thresholdSection,
#minAreaSection {
    transition: opacity 0.2s ease, max-height 0.3s ease;
}

@media (max-width: 639px) {
    .mode-selector {
        gap: 2px;
        border-radius: 12px;
        padding: 3px;
    }
    .mode-btn {
        padding: 7px 3px 5px;
        border-radius: 10px;
        gap: 2px;
    }
    .mode-icon {
        width: 24px;
        height: 24px;
    }
    .mode-label {
        font-size: 9px;
    }
}

/* ===================================================
   集成工具栏 - Figma/Canva 风格，紧随预览区
   =================================================== */

/* 工具栏容器 */
.inline-toolbar {
    background: #fafbfc;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* 工具栏主行 - flex-wrap 自然换行，移动端友好 */
.toolbar-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

/* ---------- 工具栏按钮基础 ---------- */
.tb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    background: #fff;
    color: #475569;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: all 0.15s ease;
    flex-shrink: 0;
    letter-spacing: 0.01em;
}
.tb-btn:hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.tb-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: none;
}
.tb-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.tb-btn svg {
    flex-shrink: 0;
}
.tb-label {
    line-height: 1;
}

/* 主打按钮 - 抠出 */
.tb-btn-pri {
    background: linear-gradient(135deg, #f97316, #ea580c);
    border-color: #ea580c;
    color: #fff;
    font-weight: 700;
    padding: 0 10px;
    box-shadow: 0 1px 4px rgba(249,115,22,0.25);
}
.tb-btn-pri:hover:not(:disabled) {
    background: linear-gradient(135deg, #fb923c, #f97316);
    border-color: #f97316;
    color: #fff;
    box-shadow: 0 3px 10px rgba(249,115,22,0.35);
}
.tb-btn-pri:disabled {
    background: #e2e8f0;
    border-color: #e2e8f0;
    color: #94a3b8;
    box-shadow: none;
}

/* 次要按钮 - 检测 */
.tb-btn-sec {
    background: #fff;
    border-color: #f97316;
    color: #f97316;
    font-weight: 600;
}
.tb-btn-sec:hover:not(:disabled) {
    background: #fff7ed;
    border-color: #fb923c;
    color: #ea580c;
}

/* 颜色操作按钮 */
.tb-btn-blue  { background: #eff6ff; border-color: #bfdbfe; color: #2563eb; }
.tb-btn-blue:hover:not(:disabled)  { background: #dbeafe; border-color: #93c5fd; box-shadow: 0 2px 8px rgba(37,99,235,0.12); }
.tb-btn-red   { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
.tb-btn-red:hover:not(:disabled)   { background: #fee2e2; border-color: #fca5a5; box-shadow: 0 2px 8px rgba(220,38,38,0.12); }
.tb-btn-purple { background: #f5f3ff; border-color: #ddd6fe; color: #7c3aed; }
.tb-btn-purple:hover:not(:disabled) { background: #ede9fe; border-color: #c4b5fd; box-shadow: 0 2px 8px rgba(124,58,237,0.12); }
.tb-btn-green { background: #ecfdf5; border-color: #a7f3d0; color: #059669; }
.tb-btn-green:hover:not(:disabled) { background: #d1fae5; border-color: #6ee7b7; box-shadow: 0 2px 8px rgba(5,150,105,0.12); }
.tb-btn-gray  { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }
.tb-btn-gray:hover:not(:disabled)  { background: #f1f5f9; border-color: #cbd5e1; }

/* 框选删除激活态 */
.tb-boxdel-active {
    background: #fecaca !important;
    border-color: #f87171 !important;
    color: #dc2626 !important;
    box-shadow: 0 0 0 2px rgba(220,38,38,0.15);
}

/* 下载按钮 */
.tb-btn-dl {
    height: 26px;
    padding: 0 7px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    border-radius: 6px;
    min-width: 36px;
}
.tb-btn-dl[data-fmt="png"] { border-color: #059669; color: #059669; background: #ecfdf5; }
.tb-btn-dl[data-fmt="png"]:hover:not(:disabled) { background: #d1fae5; }
.tb-btn-dl[data-fmt="pdf"] { border-color: #dc2626; color: #dc2626; background: #fef2f2; }
.tb-btn-dl[data-fmt="pdf"]:hover:not(:disabled) { background: #fee2e2; }
.tb-btn-dl[data-fmt="eps"] { border-color: #7c3aed; color: #7c3aed; background: #f5f3ff; }
.tb-btn-dl[data-fmt="eps"]:hover:not(:disabled) { background: #ede9fe; }
.tb-btn-dl[data-fmt="svg"] { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.tb-btn-dl[data-fmt="svg"]:hover:not(:disabled) { background: #dbeafe; }

/* ---------- 分隔线 ---------- */
.tb-sep {
    width: 1px;
    height: 20px;
    background: #e2e8f0;
    flex-shrink: 0;
    margin: 0 3px;
    border-radius: 1px;
}

/* ---------- 颜色栏（内联） ---------- */
.tb-color-bar {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    height: 28px;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    background: #fff;
    flex-shrink: 0;
}
.tb-cdot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px #d4d4d8, 0 1px 3px rgba(0,0,0,0.15);
    flex-shrink: 0;
}
.tb-chex {
    font-size: 10px;
    font-weight: 700;
    color: #334155;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    min-width: 44px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

/* 内联 range 滑块 */
.tb-range {
    -webkit-appearance: none;
    appearance: none;
    width: 52px;
    height: 4px;
    border-radius: 2px;
    background: #e2e8f0;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
}
.tb-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #f97316;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    margin-top: -5px;
}
.tb-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #f97316;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
}

/* 容差值标签 */
.tb-badge {
    font-size: 10px;
    font-weight: 700;
    color: #f97316;
    min-width: 18px;
    text-align: right;
    flex-shrink: 0;
}

/* 吸管按钮 */
.tb-icn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    color: #64748b;
    flex-shrink: 0;
    transition: all 0.15s ease;
}
.tb-icn:hover {
    background: #f1f5f9;
    color: #f97316;
}
.tb-icn:active,
.tb-icn.active-mode {
    background: #fed7aa;
    box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}

/* 颜色选择器 */
.tb-clr {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    overflow: hidden;
    border: 1.5px solid #d4d4d8;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.15s ease;
}
.tb-clr:hover {
    border-color: #f97316;
    box-shadow: 0 0 0 2px rgba(249,115,22,0.15);
}
.tb-clr input[type="color"] {
    width: 140%;
    height: 140%;
    margin: -20%;
    border: 0;
    padding: 0;
    cursor: pointer;
    background: transparent;
}

/* 按钮组 */
.tb-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

/* 管道步数标签 */
.tb-pipe {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 9px;
    font-weight: 600;
    color: #f97316;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 6px;
    padding: 2px 6px;
    height: 22px;
    flex-shrink: 0;
}
.tb-pipe span {
    font-weight: 800;
}

/* 提示文本 */
.tb-hint {
    font-size: 9px;
    color: #94a3b8;
    text-align: center;
    line-height: 1.4;
}

/* ===== 移动端工具栏适配 ===== */
@media (max-width: 767px) {
    .inline-toolbar {
        background: #f8fafc;
        border-radius: 8px;
    }
    .toolbar-row {
        gap: 3px;
    }
    .tb-btn {
        height: 26px;
        padding: 0 6px;
        font-size: 10px;
        border-radius: 6px;
        gap: 2px;
    }
    .tb-btn svg {
        width: 10px;
        height: 10px;
    }
    .tb-label {
        font-size: 10px;
    }
    .tb-sep {
        height: 16px;
        margin: 0 2px;
    }
    .tb-color-bar {
        height: 26px;
        padding: 0 4px;
        gap: 2px;
        border-radius: 6px;
    }
    .tb-cdot {
        width: 10px;
        height: 10px;
    }
    .tb-chex {
        font-size: 9px;
        min-width: 36px;
    }
    .tb-range {
        width: 36px;
    }
    .tb-badge {
        font-size: 9px;
    }
    .tb-clr {
        width: 20px;
        height: 20px;
    }
    .tb-btn-dl {
        height: 24px;
        padding: 0 5px;
        font-size: 9px;
        min-width: 28px;
    }
    .tb-hint {
        font-size: 8px;
    }
    .tb-pipe {
        font-size: 8px;
        height: 20px;
    }
}

@media (max-width: 639px) {
    /* 手机端工具栏分两行：主操作一行，精修一行 */
    .toolbar-row {
        --tb-row-gap: 4px;
        row-gap: var(--tb-row-gap);
    }
    .toolbar-row .tb-sep {
        margin: 0 1px;
    }
}

/* ===================================================
   管线式工作流 - 步骤头部
   =================================================== */

/* 步骤头部行 */
.step-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 步骤编号圆圈 */
.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(249,115,22,0.3);
    flex-shrink: 0;
}

/* 步骤标题 */
.step-title {
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.01em;
}

/* 管线式工作流卡片悬浮微效 */
#colorRefineCard, #touchupCard {
    transition: all 0.3s ease;
}

/* 上传覆盖层内的图标适配 */
.upload-overlay .upload-icon-wrap {
    width: 48px;
    height: 48px;
}
.upload-overlay .upload-icon-wrap svg {
    width: 24px;
    height: 24px;
}

/* 合并卡片更紧凑的间距 */
.tool-card.p-4 {
    padding: 14px;
}
.tool-card .section-title {
    font-size: 13px;
}

/* 下载区在工作流卡片中 */
#touchupCard .dl-fmt-row {
    margin-top: 2px;
}

/* ===== 手机端响应式工作流 ===== */
@media (max-width: 767px) {
    .step-num {
        width: 20px;
        height: 20px;
        font-size: 11px;
    }
    .step-title {
        font-size: 12px;
    }
    .upload-overlay .upload-icon-wrap {
        width: 40px;
        height: 40px;
    }
    .upload-overlay .upload-icon-wrap svg {
        width: 20px;
        height: 20px;
    }
}"
