:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #1f2733;
  --muted: #7a8694;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --accent: #f97316;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header { text-align: center; padding: 28px 16px 8px; }
.app-header h1 { margin: 0 0 6px; font-size: 26px; }
.app-header p { margin: 0; }

.muted { color: var(--muted); }

main {
  width: min(1180px, 96vw);
  margin: 18px auto 40px;
  flex: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

/* ---------- 上传区 ---------- */
#dropZone {
  border: 2px dashed #c3cbd6;
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
#dropZone:hover, #dropZone.dragover {
  border-color: var(--primary);
  background: #eff5ff;
}
.dz-icon { font-size: 44px; }
.dz-title { font-size: 17px; margin: 10px 0 4px; }

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-label { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-indicator { font-size: 14px; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: #f0f4f9; border-color: #c3cbd6; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.ghost { background: transparent; }

.inline-label { font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

/* ---------- 编辑布局 ---------- */
.editor-layout { display: flex; gap: 16px; align-items: flex-start; }

#thumbList {
  width: 148px;
  flex: 0 0 148px;
  max-height: 640px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.thumb {
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: #fff;
}
.thumb.active { border-color: var(--primary); }
.thumb-box { position: relative; display: flex; justify-content: center; }
.thumb-box canvas { display: block; }
.thumb-no {
  position: absolute;
  top: 4px; left: 4px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
}
.thumb-line { position: absolute; background: var(--accent); pointer-events: none; }
.thumb-line.vertical { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.thumb-line.horizontal { left: 0; right: 0; height: 2px; margin-top: -1px; }

.preview-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }

#canvasBox {
  position: relative;
  width: 100%;
  line-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #eceff3;
  touch-action: none;
  cursor: col-resize;
  display: flex;
  justify-content: center;
}
#previewCanvas { max-width: 100%; display: block; }

#cutLine {
  position: absolute;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(255,255,255,.7);
  pointer-events: none;
  z-index: 5;
}
#cutLine::after {
  content: "";
  position: absolute;
  background: var(--accent);
  border-radius: 4px;
}
#cutLine.vertical { top: 0; bottom: 0; width: 3px; margin-left: -1.5px; cursor: col-resize; }
#cutLine.vertical::after {
  width: 9px; height: 44px;
  left: -3px; top: calc(50% - 22px);
  clip-path: polygon(0 0, 100% 0, 100% 35%, 60% 50%, 100% 65%, 100% 100%, 0 100%, 0 65%, 40% 50%, 0 35%);
}
#cutLine.horizontal { left: 0; right: 0; height: 3px; margin-top: -1.5px; cursor: row-resize; }
#cutLine.horizontal::after {
  height: 9px; width: 44px;
  top: -3px; left: calc(50% - 22px);
  clip-path: polygon(0 0, 35% 0, 50% 40%, 65% 0, 100% 0, 100% 100%, 65% 100%, 50% 60%, 35% 100%, 0 100%);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.mini-previews {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.mini-previews figure { margin: 0; text-align: center; }
.mini-previews canvas {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  display: block;
  margin: 0 auto;
}
.mini-previews figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---------- 状态条 ---------- */
#statusBar {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
#statusBar.info { background: #eff6ff; color: #1d4ed8; }
#statusBar.ok { background: #f0fdf4; color: var(--ok); }
#statusBar.err { background: #fef2f2; color: var(--danger); }

.app-footer { text-align: center; padding: 0 16px 24px; font-size: 13px; }

@media (max-width: 760px) {
  .editor-layout { flex-direction: column; }
  #thumbList {
    width: 100%;
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .thumb { flex: 0 0 auto; }
}
