/* ============================================ */
/* 图片去背景工具 — yicool.com.cn /tools/remove-bg */
/* 纯前端 AI 抠图，复刻 iloveimg remove-background 交互 */
/* ============================================ */

.rb-page {
    max-width: none;
    margin: 0;
    padding: 28px 16px 60px;
    box-sizing: border-box;
}

/* ===================== 标题区 ===================== */
.rb-hero {
    text-align: center;
    margin-bottom: 22px;
}
.rb-title {
    font-size: 30px;
    font-weight: 800;
    color: var(--text-primary, #1a1a1a);
    margin: 0 0 10px;
    letter-spacing: .5px;
}
.rb-sub {
    font-size: 14px;
    color: var(--text-secondary, #666);
    max-width: 720px;
    margin: 0 auto 14px;
    line-height: 1.7;
}
.rb-hero-tags {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}
.rb-tag {
    font-size: 12px;
    color: var(--accent, #136ce9);
    background: color-mix(in srgb, var(--accent, #136ce9) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent, #136ce9) 22%, transparent);
    padding: 4px 12px;
    border-radius: 999px;
}

/* ===================== 工具容器 ===================== */
.rb-tool {
    background: var(--bg-card, #fff);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,.06);
    padding: 24px;
}

/* ===================== 上传区 ===================== */
.rb-upload {
    border: 2px dashed var(--border, #e2e2e2);
    border-radius: 24px;
    background: var(--bg-secondary, #fafbfc);
    padding-top: 40%;
    position: relative;
    transition: border-color .2s, background .2s;
    margin-bottom: 18px;
}
.rb-upload.dragover {
    border-color: var(--accent, #136ce9);
    background: color-mix(in srgb, var(--accent, #136ce9) 6%, transparent);
}
.rb-upload-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    padding: 16px;
}
.rb-upload-icon {
    width: 56px;
    height: 56px;
    color: var(--accent, #136ce9);
    margin-bottom: 12px;
}
.rb-upload-icon svg { width: 100%; height: 100%; }
.rb-upload-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #1a1a1a);
    margin: 0 0 6px;
}
.rb-upload-sub {
    font-size: 13px;
    color: var(--text-secondary, #888);
    margin: 0 0 14px;
}
.rb-upload-btn {
    pointer-events: none;
}
.rb-upload-tip {
    font-size: 12px;
    color: var(--text-muted, #aaa);
    margin: 12px 0 0;
}

/* ===================== 设置区 ===================== */
.rb-settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 18px;
}
.rb-setting {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.rb-setting-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
}
.rb-setting-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #555);
}
.rb-seg {
    display: flex;
    background: var(--bg-secondary, #f1f3f5);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}
.rb-seg button {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #555);
    font-size: 13px;
    padding: 8px 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.rb-seg button.active {
    background: var(--bg-card, #fff);
    color: var(--accent, #136ce9);
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.rb-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.rb-color-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border, #ddd);
    cursor: pointer;
    padding: 0;
    transition: transform .15s;
}
.rb-color-dot.active {
    border-color: var(--accent, #136ce9);
    transform: scale(1.12);
}
.rb-color-pick {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    background: none;
    cursor: pointer;
    padding: 2px;
}
.rb-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary, #555);
}
.rb-check input { width: 16px; height: 16px; accent-color: var(--accent, #136ce9); }
.rb-opt-hint { font-size: 11px; color: var(--text-tertiary, #999); margin-left: 2px; }

/* ===================== 操作栏 ===================== */
.rb-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.rb-btn {
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    padding: 10px 22px;
    cursor: pointer;
    transition: all .15s;
    font-weight: 600;
}
.rb-btn-primary {
    background: var(--accent, #136ce9);
    color: #fff;
}
.rb-btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent, #136ce9) 88%, #000); }
.rb-btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.rb-btn-ghost {
    background: transparent;
    color: var(--text-secondary, #555);
    border: 1px solid var(--border, #ddd);
}
.rb-btn-ghost:hover:not(:disabled) { border-color: var(--accent, #136ce9); color: var(--accent, #136ce9); }
.rb-btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
.rb-progress-text {
    font-size: 13px;
    color: var(--accent, #136ce9);
}

/* ===================== 列表 ===================== */
.rb-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.rb-item {
    border: 1px solid var(--border, #eee);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-card, #fff);
    display: flex;
    flex-direction: column;
}
.rb-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border, #f0f0f0);
    gap: 8px;
}
.rb-item-name {
    font-size: 12px;
    color: var(--text-secondary, #555);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.rb-item-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.rb-item-status.wait { background: #fff4e5; color: #d97706; }
.rb-item-status.run { background: #e6f0ff; color: #136ce9; }
.rb-item-status.done { background: #e7f7ec; color: #1a9c4b; }
.rb-item-status.fail { background: #fdeaea; color: #d33; }
.rb-canvas-wrap {
    position: relative;
    background:
        linear-gradient(45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(-45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e9ecef 75%),
        linear-gradient(-45deg, transparent 75%, #e9ecef 75%);
    background-size: 18px 18px;
    background-position: 0 0, 0 9px, 9px -9px, -9px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: 10px;
}
.rb-canvas-wrap img,
.rb-canvas-wrap canvas {
    max-width: 100%;
    max-height: 220px;
    border-radius: 4px;
}
.rb-orig {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    background: rgba(0,0,0,.55);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
}
.rb-progress {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    color: var(--accent, #136ce9);
}
.rb-spinner {
    width: 26px; height: 26px;
    border: 3px solid color-mix(in srgb, var(--accent, #136ce9) 30%, transparent);
    border-top-color: var(--accent, #136ce9);
    border-radius: 50%;
    animation: rbspin .8s linear infinite;
}
@keyframes rbspin { to { transform: rotate(360deg); } }
.rb-item-ops {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--border, #f0f0f0);
}
.rb-item-ops button {
    flex: 1;
    border: 1px solid var(--border, #ddd);
    background: var(--bg-card, #fff);
    color: var(--text-secondary, #555);
    border-radius: 6px;
    font-size: 12px;
    padding: 7px 4px;
    cursor: pointer;
    transition: all .15s;
}
.rb-item-ops button:hover { border-color: var(--accent, #136ce9); color: var(--accent, #136ce9); }
.rb-item-ops button.dl { background: var(--accent, #136ce9); color: #fff; border-color: var(--accent, #136ce9); }

/* 对比滑块 */
.rb-compare {
    position: relative;
    width: 100%;
    max-height: 220px;
    overflow: hidden;
}
.rb-compare img { display: block; width: 100%; }
/* 原图：按容器宽度等比显示；超过最大高度时由 object-fit 等比缩放（留白而非拉伸），
   这样图片始终不变形，且与右侧结果图保持像素级对齐 */
.rb-compare > img {
    height: auto;
    max-height: 220px;
    object-fit: contain;
}
.rb-compare .rb-cmp-after {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 50%;
    overflow: hidden;
    border-right: 2px solid #fff;
    /* 关键：结果图是透明 PNG，透明区域必须显示棋盘格，
       否则会透出下层 before 原图，导致左右两侧看起来都是原图、无法对比 */
    background:
        linear-gradient(45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(-45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e9ecef 75%),
        linear-gradient(-45deg, transparent 75%, #e9ecef 75%);
    background-size: 18px 18px;
    background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.rb-compare .rb-cmp-after img {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: auto;
    max-width: none;
    /* 与左侧原图规则一致：宽度由 JS 对齐到容器宽、高度撑满，
       内容按 object-fit 等比缩放 —— 避免竖图/长图被拉伸变形 */
    object-fit: contain;
}
.rb-cmp-handle {
    position: absolute;
    top: 0; bottom: 0;
    left: 50%;
    width: 2px;
    background: #fff;
    cursor: ew-resize;
    z-index: 2;
}
.rb-cmp-handle::after {
    content: "⇄";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--accent, #136ce9);
    color: #fff;
    width: 26px; height: 26px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
}

/* ===================== 使用说明 ===================== */
.rb-help {
    margin-top: 22px;
    border: 1px solid var(--border, #eee);
    border-radius: 10px;
    background: var(--bg-secondary, #fafbfc);
    padding: 4px 16px;
}
.rb-help summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary, #1a1a1a);
    padding: 10px 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.rb-help-toggle { transition: transform .2s; display: inline-block; }
.rb-help[open] .rb-help-toggle { transform: rotate(180deg); }
.rb-help-body { padding: 4px 0 14px; font-size: 13px; color: var(--text-secondary, #555); line-height: 1.8; }
.rb-help-body ol { margin: 0 0 10px; padding-left: 20px; }
.rb-help-note { color: var(--accent, #136ce9); margin: 0; }

/* ===================== Toast 提示 ===================== */
.rb-toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30,34,42,.92);
    color: #fff;
    font-size: 13px;
    padding: 10px 18px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 100000;
    max-width: 86vw;
    text-align: center;
}
.rb-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.rb-toast.err { background: #d33; }

/* ===================== 响应式 ===================== */
@media (max-width: 991px) {
    .rb-list { grid-template-columns: repeat(2, 1fr); }
    .rb-settings { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
    .rb-page { padding: 16px 12px 40px; }
    .rb-tool { padding: 16px; }
    .rb-title { font-size: 24px; }
    .rb-upload { padding-top: 56%; }
    .rb-list { grid-template-columns: 1fr; }
    .rb-actions { flex-direction: column; align-items: stretch; }
    .rb-actions .rb-btn { width: 100%; }
    .rb-settings { gap: 12px; }
}
@media (max-width: 400px) {
    .rb-upload-icon { width: 44px; height: 44px; }
    .rb-upload-text { font-size: 16px; }
}
