/* ==========================================================================
   ClearCut · 透明背景处理台
   主题变量：默认浅色，html[data-theme="dark"] 覆盖为深色
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --bg-soft: #e2e8f0;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --accent: #0ea5e9;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow: 0 4px 16px rgba(15, 23, 42, .07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --checker-a: #ffffff;
  --checker-b: #e6eaf0;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #111a2e;
  --surface: #131c2e;
  --surface-2: #0f1728;
  --border: #24314b;
  --border-strong: #33415c;
  --text: #e8eefb;
  --text-2: #a6b4cc;
  --text-3: #6b7c99;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: #17233c;
  --accent: #38bdf8;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  --checker-a: #2a3446;
  --checker-b: #222b3b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ============================ 顶栏 ============================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; }
.logo { width: 32px; height: 32px; flex: none; border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: 16px; letter-spacing: .2px; }
.brand-text span { font-size: 11.5px; color: var(--text-3); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.pill.safe { color: var(--success); border-color: color-mix(in srgb, var(--success) 32%, transparent); background: color-mix(in srgb, var(--success) 9%, transparent); }

/* ============================ 布局 ============================ */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 336px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

/* ============================ 侧栏卡片 ============================ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13.5px;
  user-select: none;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after {
  content: "";
  width: 7px; height: 7px;
  margin-left: auto;
  border-right: 1.8px solid var(--text-3);
  border-bottom: 1.8px solid var(--text-3);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .18s ease;
}
.card[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.card > summary:hover { color: var(--primary); }
.card-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 14px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

/* ============================ 表单元素 ============================ */
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label {
  font-size: 12.5px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.field-label .val {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 700;
  font-size: 12.5px;
}
.hint { margin: 0; font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.muted { color: var(--text-3); }
.xs { font-size: 11.5px; }
.sm { font-size: 12.5px; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: var(--bg-soft);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--bg-soft); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }

.input, .select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
.select { cursor: pointer; }

.color-input {
  -webkit-appearance: none;
  appearance: none;
  width: 40px; height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  flex: none;
}
.color-input.sm { width: 32px; height: 26px; }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: none; border-radius: 5px; }

.swatches { display: flex; gap: 6px; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--c);
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, box-shadow .12s ease;
}
.swatch:hover { transform: scale(1.14); box-shadow: var(--shadow-sm); }

.switch { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); cursor: pointer; user-select: none; }
.switch input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; flex: none; }

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.segmented.sm { padding: 2px; }
.seg {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.segmented.sm .seg { padding: 4px 9px; font-size: 12px; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }

.mini-btn {
  font: inherit;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
}
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }
.mini-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============================ 上传区 ============================ */
.dropzone {
  border: 1.6px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-2);
  transition: border-color .18s, background .18s, transform .18s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); transform: scale(1.01); }
.dz-icon { display: block; margin: 0 auto 6px; color: var(--primary); }
.dz-main { margin: 0; font-size: 13px; font-weight: 600; color: inherit; }
.dz-sub { margin: 3px 0 0; font-size: 11.5px; color: var(--text-3); }

/* 队列 */
.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.queue:empty { display: none; }
.q-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.q-item:hover { border-color: var(--border-strong); }
.q-item.active { border-color: var(--primary); background: var(--primary-soft); }
.q-thumb {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 6px;
  object-fit: contain;
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  border: 1px solid var(--border);
}
.q-meta { min-width: 0; flex: 1; }
.q-name { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-dim { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.q-del {
  border: none; background: transparent; color: var(--text-3);
  cursor: pointer; padding: 3px; border-radius: 5px; line-height: 0; flex: none;
}
.q-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* 快捷键表 */
.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.keys li { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.keys li span { margin-left: auto; color: var(--text-3); font-size: 11.5px; }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  color: var(--text-2);
  line-height: 1.3;
}

.foot-note { font-size: 11px; color: var(--text-3); text-align: center; margin: 4px 6px 8px; line-height: 1.6; }
.foot-note b { color: var(--text-2); }

/* ============================ 工作区 ============================ */
.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  position: sticky;
  top: 76px;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.tool-group { display: flex; align-items: center; gap: 7px; }
.tool-group.right { margin-left: auto; }
.tool-label { font-size: 12px; color: var(--text-3); }
.zoom-val { font-size: 12px; color: var(--text-2); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  width: 28px; height: 28px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  font-family: inherit;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn:active { transform: scale(.94); }

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 400px;
  height: calc(100vh - 300px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
.canvas-wrap[data-bg="white"] { background-color: #fff; background-image: none; }
.canvas-wrap[data-bg="black"] { background-color: #000; background-image: none; }
.canvas-wrap[data-bg="custom"] { background-image: none; }

#previewCanvas {
  display: block;
  image-rendering: auto;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 12%, transparent), var(--shadow);
  border-radius: 2px;
  margin: auto;
}
#previewCanvas.picking { cursor: crosshair; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-3);
  text-align: center;
  pointer-events: none;
}
.empty p { margin: 8px 0 0; font-size: 14px; font-weight: 600; color: var(--text-2); }
.empty span { font-size: 12px; }
.empty[hidden] { display: none; }

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}

.actionbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
#actionHint { margin-left: auto; }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn.ghost { background: transparent; font-weight: 500; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; font-weight: 500; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 25%, transparent);
  border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
.btn.primary.loading::after { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.site-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-3);
  padding: 0 4px 8px;
}

/* ============================ 浮层 ============================ */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--primary) 12%, rgba(255,255,255,.7));
  backdrop-filter: blur(3px);
}
html[data-theme="dark"] .drop-overlay { background: color-mix(in srgb, var(--primary) 20%, rgba(0,0,0,.6)); }
.drop-overlay.show { display: flex; }
.drop-overlay span {
  padding: 22px 42px;
  border: 2.4px dashed var(--primary);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--primary);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
}

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  color: var(--text);
  max-width: 340px;
  animation: toastIn .22s ease;
  display: flex;
  align-items: center;
  gap: 7px;
}
.toast.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.toast.ok { border-color: color-mix(in srgb, var(--success) 45%, transparent); color: var(--success); }
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ============================ 响应式 ============================ */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: none; overflow: visible; padding-right: 0; }
  .stage { position: static; }
  .canvas-wrap { height: 62vh; min-height: 320px; }
  .queue { max-height: 200px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .layout { padding: 12px; gap: 12px; }
  .brand-text span { display: none; }
  .tool-label { display: none; }
  .stage-toolbar { gap: 10px; }
  .tool-group.right { margin-left: 0; width: 100%; }
  .actionbar .btn { flex: 1; justify-content: center; }
  #actionHint { display: none; }
  .canvas-wrap { height: 52vh; padding: 10px; }
}

@media print { .sidebar, .topbar, .actionbar, .stage-toolbar { display: none; } }
