/* 图片工具 — 清爽重组版
   品牌色已统一为工具箱蓝（原珊瑚橘改色，仅换 CSS 变量值，不动类名）：
   - tab 改底部下划线
   - 工具栏内部分组卡片（参数组 / 操作组分开）
   - canvas 自适应高度（去掉过大 min-height）
   - 精简提示文字
   所有效果用 CSS 实现，不动 DOM ID */

* { box-sizing: border-box; }

:root {
  /* 背景层级 */
  --bg:          #FAFBFC;
  --bg-subtle:   #F3F4F6;
  --bg-hover:    #E8EAED;
  --bg-group:    #F7F8FA;
  --panel:       #FFFFFF;

  /* 边框 */
  --border:        #E8EAED;
  --border-strong: #D1D5DB;

  /* 文字 */
  --text:      #1F2329;
  --text-sub:  #6B7280;
  --text-hint: #9CA3AF;

  /* 强调色 — 工具箱蓝 */
  --accent:        #2563eb;
  --accent-hover:  #1d4ed8;
  --accent-active: #1e40af;
  --accent-soft:   #eff6ff;
  --accent-line:   #bfdbfe;
  --accent-bg:     #dbeafe;

  /* 状态 */
  --ok:   #16A34A;
  --err:  #DC2626;
  --warn: #F59E0B;

  /* 字体 */
  --font-body: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;

  /* 圆角 */
  --radius-sm:   6px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-pill: 999px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.08);
  --shadow-cta: 0 4px 12px rgba(37, 99, 235, .24);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ============ HEADER ============ */
.app-header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 0;
}
.app-header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header h1::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 20px;
  background: var(--accent);
  border-radius: 3px;
  flex: 0 0 auto;
}
.app-header .ver {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  margin-left: 2px;
  letter-spacing: 0.02em;
}
.app-header .sub {
  color: var(--text-sub);
  font-size: 13px;
  margin: 0;
  padding-left: 16px;
}

/* ============ TABS — 底部下划线 ============ */
.tabs {
  max-width: 1100px;
  margin: 20px auto 0;
  padding: 0 24px;
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 20px;
  text-decoration: none;
  color: var(--text-sub);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: color .15s ease, border-color .15s ease;
  position: relative;
  top: 1px;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ============ MAIN ============ */
.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 80px;
}

.panel {
  display: none;
}
.panel.active { display: block; }

/* ============ ROW 通用 ============ */
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.row.upload-row {
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
}
.row.actions {
  margin: 28px 0 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
.row .grow { flex: 1 1 320px; }

/* 上传按钮 */
.row.upload-row .btn-upload {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-cta);
  transition: background .15s ease, transform .1s ease;
  pointer-events: auto;
}
.row.upload-row .btn-upload:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.row.upload-row .btn-upload:active {
  background: var(--accent-active);
  transform: translateY(1px);
}
.row.upload-row .btn-upload::before {
  content: '↑';
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
}
.row.upload-row .hint {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 400;
}

/* ============ TOOLBAR + 分组卡片 ============ */
.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: stretch;
  margin: 0 0 16px;
}
/* toolbar-group：参数/操作分组卡片 */
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--bg-group);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex: 0 1 auto;
}
/* 操作按钮组 — 不撑满，靠右 */
.toolbar-group.toolbar-actions {
  margin-left: auto;
  background: transparent;
  border: none;
  padding: 12px 0;
}
/* 第一个 toolbar-group 之后加间距 */
.toolbar-group + .toolbar-group {
  margin-left: 0;
}

/* ============ BUTTONS ============ */
.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: var(--panel);
  color: var(--accent);
  border: 1.5px dashed var(--accent-line);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  transition: all .18s ease;
}
.btn-upload::before {
  content: '↑';
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
}

.btn-primary {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-cta);
  transition: background .15s ease, transform .1s ease;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
  transform: translateY(1px);
}
.btn-primary:disabled {
  background: var(--bg-hover);
  border-color: var(--bg-hover);
  color: var(--text-hint);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-ghost {
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  transition: all .15s ease;
}
.btn-ghost:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text);
}

/* ============ FIELDS ============ */
.field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sub);
}
.field > span:first-child,
.field > textarea,
.field > select {
  display: block;
}
.field.grow { flex: 1 1 320px; }

.field textarea,
.field select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  line-height: 1.5;
}
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea::placeholder { color: var(--text-hint); }
.field select { padding: 7px 12px; }

/* number */
.field input[type=number] {
  width: 76px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input[type=number].range-num { width: 56px; padding: 5px 6px; }
.field input[type=number]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[type=number]::-webkit-inner-spin-button,
.field input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* range */
.field input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-pill);
  cursor: pointer;
  vertical-align: middle;
}
.field input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.field input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.1); }
.field input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.field input[type=range]:disabled::-webkit-slider-thumb {
  border-color: var(--text-hint);
  background: var(--bg-subtle);
}
.field input[type=range]:disabled::-moz-range-thumb {
  border-color: var(--text-hint);
  background: var(--bg-subtle);
}

.field input[type=color] {
  width: 38px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  cursor: pointer;
}
.field input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
.field input[type=color]::-webkit-color-swatch { border: none; border-radius: 4px; }

.field input[type=checkbox] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.field-divider {
  color: var(--text-hint);
  padding: 0 4px;
}

/* 文字列表 */
.text-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 220px;
  max-width: 320px;
  max-height: 140px;
  overflow-y: auto;
  font-size: 13px;
  display: block;
}
.text-list-empty {
  padding: 14px;
  color: var(--text-hint);
  font-size: 12px;
  text-align: center;
}
.text-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--bg);
}
.text-list-item:last-child { border-bottom: none; }
.text-list-item:hover { background: var(--bg-subtle); }
.text-list-item.is-anchor {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.text-list-item input[type=checkbox] { margin: 0; accent-color: var(--accent); }
.text-list-item-label {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* segmented control */
.seg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sub);
}
.seg-btn {
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-sub);
  transition: all .15s ease;
}
.seg-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.seg-btn.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
  font-weight: 500;
}

.hint {
  color: var(--text-sub);
  font-size: 12px;
  line-height: 1.7;
}
.hint strong {
  color: var(--text);
  font-weight: 600;
}

/* ============ CANVAS STAGE ============ */
.canvas-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 16px 0 20px;
  padding: 20px;
  background: var(--bg-group);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.canvas-wrap {
  position: relative;
  flex: 0 0 auto;
  width: fit-content;
  height: fit-content;
  max-width: 100%;
  min-width: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(#F0F1F3 0% 25%, #FAFAFB 0% 50%) 0 0 / 16px 16px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: var(--shadow-md);
  min-height: 200px;
}
.canvas-wrap[hidden] { display: none !important; }
.canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  background: transparent;
}
.canvas-wrap canvas#erase-mask,
.canvas-wrap canvas#erase-restore {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  margin: auto;
}
.canvas-wrap .placeholder {
  position: absolute;
  color: var(--text-hint);
  font-size: 13px;
  pointer-events: none;
  padding: 0 24px;
  text-align: center;
}
.canvas-wrap .caption {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(255,255,255,.95);
  color: var(--text);
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
  z-index: 2;
}

/* ============ STATUS ============ */
.status {
  font-size: 13px;
  color: var(--text-sub);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.status.error { color: var(--err); }
.status.ok    { color: var(--ok); }
.status.loading { color: var(--accent); }

.size-summary {
  font-size: 13px;
  color: var(--text-sub);
  flex: 1;
  font-variant-numeric: tabular-nums;
}

/* ============ RESTORE BLOCK ============ */
.restore-block {
  margin-top: 20px;
  padding: 16px 20px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(31, 35, 41, .95);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  max-width: 80vw;
}

/* ============ 滚动条 ============ */
.text-list::-webkit-scrollbar { width: 6px; }
.text-list::-webkit-scrollbar-track { background: transparent; }
.text-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: var(--radius-pill); }
.text-list::-webkit-scrollbar-thumb:hover { background: var(--text-hint); }

/* ============ 响应式 ============ */
@media (max-width: 720px) {
  .app-header { padding: 20px 16px 0; }
  .app-header h1 { font-size: 18px; gap: 8px; }
  .app-header h1::before { width: 5px; height: 18px; }
  .app-header .sub { padding-left: 13px; font-size: 12px; }
  .tabs { padding: 0 16px; overflow-x: auto; gap: 0; }
  .tab { padding: 10px 14px; font-size: 13px; white-space: nowrap; }
  .app-main { padding: 16px 16px 48px; }
  .toolbar-group { padding: 10px 12px; }
  .toolbar-group.toolbar-actions { width: 100%; }
  .canvas-wrap { flex: 1 1 100%; }
  .canvas-stage { padding: 12px; gap: 12px; }
  .field.grow { flex: 1 1 100%; }
  .row.actions { justify-content: stretch; }
  .row.actions .btn-primary { flex: 1; }
}

/* ============ 可访问性 ============ */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
