:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e5e8ee;
  --line-strong: #d5dae3;
  --text: #1f2937;
  --muted: #6b7280;
  --muted-2: #9aa1ad;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef4ff;
  --accent-line: #bfd4ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 13px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }

.app { display: flex; flex-direction: column; height: 100vh; min-height: 620px; }
.topbar {
  height: 64px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .2px; }
.brand-text p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px;
  padding: 5px 10px; border-radius: 999px; background: #f3f4f6; color: var(--muted);
}
.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.status-loading { background: #fff7ed; color: #c2410c; }
.status-pill.status-loading i { animation: pulse 1.2s infinite; }
.status-pill.status-ready { background: #ecfdf5; color: var(--ok); }
.status-pill.status-error { background: #fef2f2; color: var(--danger); }
@keyframes pulse { 50% { opacity: .25; } }
:root { --ok: #16a34a; --danger: #dc2626; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 292px minmax(320px, 1fr) 252px; }
.panel { background: var(--panel); overflow-y: auto; }
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }
.block { padding: 16px 16px 18px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.block-head h2 { margin: 0; font-size: 13px; font-weight: 650; }
.block-head.simple { margin-bottom: 10px; }
.step {
  width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700;
}
.subhead { margin: 16px 0 8px; font-size: 12px; font-weight: 600; color: #374151; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 12px;
  font-size: 12px; font-weight: 600; transition: .15s;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: #374151; border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: #f8fafc; border-color: #b9c1cf; }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.mini-select {
  height: 32px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 7px;
  background: #fff; color: #374151; font-size: 11px; outline: none;
}
.icon-btn {
  width: 28px; height: 28px; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 6px; color: #374151; font-size: 15px; line-height: 1; display: grid; place-items: center;
}
.icon-btn:hover { background: #f8fafc; }
.icon-btn.wide { width: auto; padding: 0 8px; font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

.dropzone {
  border: 1.5px dashed var(--accent-line); background: var(--accent-soft);
  border-radius: var(--radius); padding: 18px 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--accent); transition: .15s; outline: none;
}
.dropzone:hover, .dropzone:focus, .dropzone.dragover { background: #e3edff; border-color: var(--accent); }
.dropzone svg { width: 24px; height: 24px; }
.dropzone strong { font-size: 12px; color: #1e40af; }
.dropzone span { font-size: 10px; color: #6b7f9e; }
.file-meta {
  margin-top: 9px; font-size: 11px; color: var(--muted);
  display: flex; justify-content: space-between; gap: 8px;
}
.file-meta b { color: #374151; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

.eraser-badge {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 9px;
  background: #fff7ed; border: 1px solid #fed7aa; color: #ea580c;
}
.eraser-badge svg { width: 22px; height: 22px; }
.eraser-badge span { display: flex; flex-direction: column; gap: 2px; }
.eraser-badge strong { font-size: 12px; color: #9a3412; }
.eraser-badge small { font-size: 10px; color: #c2410c; }
.field-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.field-row.compact { margin-top: 7px; }
.field-row label { width: 42px; flex: none; font-size: 11px; color: var(--muted); }
.field-row input[type=range] { flex: 1; min-width: 0; }
.field-row output { width: 46px; flex: none; text-align: right; font-size: 11px; color: #374151; font-variant-numeric: tabular-nums; }
input[type=range] { accent-color: var(--accent); height: 4px; }
.hint { margin: 8px 0 0; font-size: 10px; line-height: 1.55; color: var(--muted-2); }
.method-list { display: flex; flex-direction: column; gap: 6px; }
.method-option {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 9px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer;
  transition: .15s;
}
.method-option:hover { border-color: #a9c4ff; background: #f8faff; }
.method-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.method-option input { margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.method-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.method-body strong { font-size: 11px; font-weight: 650; color: #374151; }
.method-body strong em {
  font-style: normal; font-size: 9px; font-weight: 600; color: var(--accent);
  background: #fff; border: 1px solid var(--accent-line); border-radius: 4px; padding: 1px 4px; margin-left: 4px;
}
.method-body small { font-size: 10px; line-height: 1.4; color: var(--muted); }

.workspace { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.canvas-toolbar {
  height: 44px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.zoom-group { display: flex; align-items: center; gap: 5px; }
.zoom-label { margin-left: 6px; font-size: 11px; color: var(--muted); width: 42px; font-variant-numeric: tabular-nums; }
.toolbar-hint { font-size: 10px; color: var(--muted-2); }
.stage {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  background-color: #eceff3;
  background-image:
    linear-gradient(45deg, #e2e6eb 25%, transparent 25%),
    linear-gradient(-45deg, #e2e6eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e6eb 75%),
    linear-gradient(-45deg, transparent 75%, #e2e6eb 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  cursor: none;
}
.stage.panning { cursor: grabbing !important; }
.canvas-wrap { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.canvas-wrap canvas { position: absolute; top: 0; left: 0; display: block; }
#maskCanvas { pointer-events: none; }
.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 9px; color: var(--muted); pointer-events: none;
}
.empty-icon {
  width: 52px; height: 52px; border-radius: 14px; background: #fff; color: var(--accent);
  display: grid; place-items: center; box-shadow: var(--shadow); margin-bottom: 3px;
}
.empty-icon svg { width: 27px; height: 27px; }
.empty-state strong { color: #374151; font-size: 14px; }
.empty-state span { font-size: 11px; }
.empty-state .btn { pointer-events: auto; margin-top: 5px; }

/* 橡皮擦光标：固定在画布坐标系中，跟随鼠标 */
.brush-cursor {
  position: absolute; z-index: 5; border-radius: 50%; pointer-events: none;
  border: 2px solid #ea580c; background: rgba(249, 115, 22, .12);
  box-shadow: 0 0 0 1.5px #fff, 0 1px 6px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
}
.brush-cursor i {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; border-radius: 50%;
  background: #ea580c; border: 1px solid #fff; transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,.25);
}
.stage.panning .brush-cursor { display: none !important; }
.drop-hint {
  position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 12px;
  background: rgba(239, 244, 255, .82); display: grid; place-items: center;
  color: var(--accent); font-weight: 600; font-size: 14px; pointer-events: none; z-index: 8;
}
.statusbar {
  height: 32px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--panel); border-top: 1px solid var(--line);
  font-size: 10px; color: var(--muted);
}

.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preview-item { min-width: 0; }
.preview-item span { display: block; font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.preview-item canvas {
  width: 100%; height: 90px; object-fit: contain; display: block;
  background: #eceff3; border: 1px solid var(--line); border-radius: 7px;
}
.tips { margin: 0; padding-left: 17px; font-size: 11px; line-height: 1.65; color: var(--muted); }
.tips li { margin-bottom: 7px; }
.tips b { color: #374151; font-weight: 600; }
.notice { background: #fffbeb; }
.notice-title { font-size: 12px; font-weight: 650; color: #92400e; margin-bottom: 6px; }
.notice p { margin: 0; font-size: 11px; line-height: 1.65; color: #a16207; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 276px minmax(300px, 1fr); }
  .panel-right { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 1fr); }
  .panel-left { border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .statusbar-right, .toolbar-hint { display: none; }
}
