* { box-sizing: border-box; }
:root {
  --primary: #4f7cff;
  --primary-soft: #e7eeff;
  --primary-dark: #3658d8;
  --bg: #f5f7fb;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --card: #ffffff;
  --shadow: 0 4px 20px rgba(0,0,0,0.05);
  --radius: 14px;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
}

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.hero {
  background: linear-gradient(135deg, #6c8cff 0%, #4f7cff 100%);
  color: #fff;
  padding: 26px 0;
  box-shadow: 0 4px 20px rgba(79, 124, 255, 0.18);
}
.hero-inner {
  max-width: 960px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 16px;
}
.logo { font-size: 38px; }
.hero h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; }
.sub { margin: 4px 0 0; opacity: 0.92; font-size: 14px; }
.badge {
  margin-left: auto;
  background: rgba(255,255,255,0.25);
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
}

.container {
  max-width: 960px;
  margin: 22px auto 80px;
  padding: 0 24px;
  display: flex; flex-direction: column; gap: 18px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border: 1px solid #eef0f5;
}
.card.soft { background: #fafbff; }
.card h3 { margin: 0 0 12px; font-size: 16px; }

.lbl { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }

.dropzone {
  border: 2px dashed #c7d0e8;
  border-radius: var(--radius);
  padding: 50px 20px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  background: #fbfcff;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 48px; margin-bottom: 8px; }
.dz-inner p { margin: 4px 0; color: var(--text); }
.muted { color: var(--muted); font-size: 13px; }
.muted.small { font-size: 12px; }

.hidden { display: none !important; }

/* 工具条 */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px 12px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-left { flex: 1; min-width: 220px; }
.toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.select-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.select-wrap select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  outline: none;
}

/* 画布 */
.canvas-wrap {
  display: flex; justify-content: center;
  background: #f4f6fb;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}
.canvas-stage {
  position: relative;
  user-select: none;
  display: inline-block;
  max-width: 100%;
  max-height: 62vh;
  line-height: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  border-radius: 8px;
  overflow: hidden;
}
.canvas-stage img {
  display: block;
  max-width: 100%;
  max-height: 62vh;
  height: auto;
  width: auto;
  border-radius: 6px;
  user-select: none;
  -webkit-user-drag: none;
}
.overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
.drawing-rect {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(79, 124, 255, 0.18);
  pointer-events: none;
  display: none;
  border-radius: 3px;
}

/* 已有选区 */
.region-rect {
  position: absolute;
  border: 2px solid var(--primary);
  background: rgba(79, 124, 255, 0.18);
  pointer-events: auto;
  cursor: move;
  border-radius: 3px;
  box-sizing: border-box;
}
.region-rect .handle {
  position: absolute;
  width: 10px; height: 10px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 2px;
  display: none;
}
.region-rect.selected {
  border-color: #ff8a3d;
  background: rgba(255, 138, 61, 0.20);
}
.region-rect.selected .handle { display: block; }
.region-rect .handle.br {
  right: -6px; bottom: -6px; cursor: nwse-resize;
}
.region-rect .label {
  position: absolute;
  top: -22px; left: -2px;
  background: var(--primary);
  color: #fff;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 3px;
  white-space: nowrap;
}
.region-rect.selected .label { background: #ff8a3d; }

/* 选区列表 */
.region-list {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 12px;
}
.region-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.region-chip.active { background: #ffd9bd; color: #c2410c; }
.region-chip .x { font-size: 14px; opacity: 0.6; }
.region-chip .x:hover { opacity: 1; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px;
  border: 0; cursor: pointer;
  font-size: 14px; font-weight: 500;
  text-decoration: none;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
  color: var(--text);
}
.btn.primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 12px rgba(79, 124, 255, 0.25);
}
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79, 124, 255, 0.32); }
.btn.primary:disabled { background: #b8c2e3; box-shadow: none; cursor: not-allowed; transform: none; }
.btn.ghost {
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--text);
}
.btn.ghost:hover { background: #f3f5fb; }
.btn.ghost.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.ghost.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 6px 12px; font-size: 12px; }

/* 底部操作 */
.actions {
  display: flex; align-items: center; gap: 12px;
  margin-top: 16px; flex-wrap: wrap;
}
.actions.center { justify-content: center; }
.param { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.param input[type="range"] { accent-color: var(--primary); width: 120px; }
.param b { color: var(--text); }
.quality-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  outline: none;
  color: var(--text);
  cursor: pointer;
}
.hint {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: #f6f8fc;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

/* 进度 */
.progress {
  height: 8px;
  background: var(--primary-soft);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}
.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6c8cff, #4f7cff);
  transition: width 0.3s;
}

/* 对比 */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 8px 0 12px;
}
.compare figure {
  margin: 0;
  text-align: center;
}
.compare figcaption {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.compare img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.info {
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #555;
  margin: 8px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.tips {
  margin: 6px 0 0;
  padding-left: 22px;
  color: #555;
  font-size: 14px;
  line-height: 1.85;
}
.tips li::marker { color: var(--primary); font-weight: 600; }

footer { text-align: center; padding: 18px; }

/* ===== 模式切换 ===== */
.mode-switch {
  display: inline-flex;
  background: #eef1f8;
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  margin: 0 auto;
  align-self: center;
}
.mode-btn {
  border: 0; background: transparent;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(79, 124, 255, 0.18);
}

/* ===== 批量模式 ===== */
.batch-summary {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 14px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 14px;
  flex-wrap: wrap; gap: 8px;
}
.batch-actions-inline { display: flex; gap: 8px; }

.batch-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  margin-bottom: 12px;
}
@media (max-width: 720px) {
  .batch-layout { grid-template-columns: 1fr; }
}

.batch-filelist {
  background: #f8fafd;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  max-height: 480px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.file-item {
  display: flex; flex-direction: column;
  padding: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.file-item.template {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.file-item .thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  background: #e5e7eb;
}
.file-item .info {
  padding: 8px 10px 6px;
  min-width: 0;
}
.file-item .name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-item .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-item .x {
  position: absolute;
  top: 6px; right: 6px;
  border: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 16px; line-height: 1;
  width: 24px; height: 24px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.file-item .x:hover { background: var(--danger); color: #fff; }

.batch-template {
  background: #f4f6fb;
  border-radius: 10px;
  padding: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.batch-template .muted { align-self: flex-start; }

/* 图像居中显示 */
.batch-template .canvas-stage {
  align-self: center;
  max-width: 100%;
}

.batch-count-inline {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
}

/* 统计 */
.batch-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 8px 0 16px;
}
@media (max-width: 640px) {
  .batch-stats { grid-template-columns: repeat(2, 1fr); }
}
.stat {
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 22px;
  color: var(--text);
  line-height: 1.1;
}
.stat span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.stat.ok b { color: #16a34a; }
.stat.fail b { color: var(--danger); }
.btn.big { padding: 12px 26px; font-size: 15px; }

@media (max-width: 640px) {
  .compare { grid-template-columns: 1fr; }
  .hero h1 { font-size: 18px; }
}

/* ===== 批量预览网格 ===== */
.batch-preview-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 2px 10px;
}
.batch-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.pv-tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.pv-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  border-color: var(--primary);
}
.pv-tile.failed { cursor: default; opacity: 0.85; }
.pv-tile.failed:hover { transform: none; box-shadow: none; border-color: var(--line); }
.pv-thumb {
  position: relative;
  background: #f3f5fb;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}
.pv-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.pv-mask {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45);
  color: #fff; font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s;
}
.pv-tile:hover .pv-mask { opacity: 1; }
.pv-meta {
  padding: 8px 10px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
}
.pv-name {
  flex: 1; min-width: 0;
  font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pv-size {
  font-size: 11px; color: var(--muted); flex-shrink: 0;
}
.pv-fail {
  padding: 18px 10px;
  text-align: center;
  color: var(--danger);
}
.pv-fail-icon { font-size: 30px; margin-bottom: 6px; }
.pv-fail-name { font-size: 12px; color: var(--text); margin-bottom: 4px; }
.pv-fail-msg { font-size: 11px; color: var(--muted); word-break: break-all; }

/* ===== 预览弹窗 + 对比滑块 ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  width: min(960px, 100%);
  max-height: 92vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-right: 12px;
}
.modal-close {
  border: 0; background: transparent;
  font-size: 24px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  width: 30px; height: 30px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }
.modal-body {
  flex: 1;
  padding: 14px;
  overflow: auto;
  background: #1f2937;
  display: flex; align-items: center; justify-content: center;
}
.modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #fafbff;
  flex-wrap: wrap; gap: 8px;
}
.modal-foot > div { display: flex; gap: 8px; }

.compare-slider {
  position: relative;
  display: inline-block;
  user-select: none;
  max-width: 100%;
  max-height: 70vh;
  line-height: 0;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  border-radius: 6px;
  overflow: hidden;
}
.cs-img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
}
.cs-after { display: block; }
.cs-before-wrap {
  position: absolute; left: 0; top: 0;
  height: 100%;
  width: 50%;
  overflow: hidden;
  border-right: 2px solid #fff;
  box-sizing: border-box;
}
.cs-before-wrap .cs-img {
  /* 让原图保持与处理后图同样的绝对像素尺寸 */
  position: absolute;
  top: 0; left: 0;
  width: var(--cs-w, auto);
  height: var(--cs-h, auto);
  max-width: none;
  max-height: none;
}
.cs-handle {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 36px;
  transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center;
  cursor: ew-resize;
  z-index: 2;
}
.cs-arrow {
  color: #fff; font-size: 18px; font-weight: bold;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  z-index: 2;
}
.cs-line {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 3px;
  background: #fff;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
}
.cs-tag {
  position: absolute;
  top: 10px;
  padding: 3px 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 12px;
  border-radius: 4px;
  pointer-events: none;
}
.cs-tag-l { left: 10px; }
.cs-tag-r { right: 10px; }
