:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e8f0;
  --border-strong: #d5dbe8;
  --text: #1d2537;
  --text-2: #5d6980;
  --text-3: #8b96a9;
  --accent: #2f5fe0;
  --accent-soft: #edf2ff;
  --accent-2: #1b47bd;
  --green: #14805a;
  --green-soft: #e8f6ef;
  --danger: #d3453b;
  --shadow-sm: 0 1px 2px rgba(24, 39, 75, .05), 0 4px 14px rgba(24, 39, 75, .04);
  --shadow-md: 0 12px 40px rgba(24, 39, 75, .12);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* clip 不建立滚动容器，比 hidden 更彻底：整页永远不会被滚走 */
html, body {
  height: 100%;
  overflow: hidden;
  overflow: clip;
  overscroll-behavior: none;
}
body {
  margin: 0;
  position: fixed;          /* 页面钉在视口内，杜绝整页滚动 / 橡皮筋空白 */
  inset: 0;
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 230px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #3b6ce8, #2246bf);
  color: #fff; box-shadow: 0 4px 12px rgba(47, 95, 224, .28);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.brand-text p { margin: 2px 0 0; font-size: 11px; color: var(--text-3); }
.topbar-center { flex: 1; display: flex; justify-content: center; }
.privacy-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--green-soft); color: var(--green);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.privacy-chip svg { width: 14px; height: 14px; stroke-width: 2; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.lang-box select { width: 96px; height: 34px; font-size: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid transparent; background: transparent;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(47, 95, 224, .22); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { color: var(--text-2); border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-outline { border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.btn-outline:hover { background: var(--accent-soft); border-color: #b9c9f5; color: var(--accent-2); }
.btn-text { color: var(--accent); background: transparent; height: 30px; }
.btn-text:hover { text-decoration: underline; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- layout ---------- */
.layout {
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
  overflow: hidden;
}
.sidebar {
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 30px;
}
.sidebar::-webkit-scrollbar, .stage::-webkit-scrollbar { width: 9px; height: 9px; }
.sidebar::-webkit-scrollbar-thumb, .stage::-webkit-scrollbar-thumb { background: #d7dce7; border: 2px solid transparent; background-clip: content-box; border-radius: 8px; }
.panel { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-quiet { border-bottom: 0; padding-top: 14px; }
.panel-title { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.panel-title h2 { margin: 0; font-size: 13px; font-weight: 700; }
.idx {
  font-size: 10px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 5px; padding: 3px 6px; letter-spacing: .5px;
}
.hint { margin-left: auto; font-size: 11px; color: var(--text-3); }
.note { margin: 10px 0 0; font-size: 11px; line-height: 1.6; color: var(--text-3); }

/* ---------- upload ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px; background: var(--surface-2);
  padding: 18px 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .15s, background .15s;
  outline: none; cursor: pointer;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--accent); background: var(--accent-soft);
}
.dz-icon { width: 32px; height: 32px; border-radius: 9px; background: #fff; display: grid; place-items: center; color: var(--accent); box-shadow: var(--shadow-sm); }
.dz-icon svg { width: 18px; height: 18px; }
.dropzone strong { font-size: 12.5px; }
.dropzone small { color: var(--text-3); font-size: 10.5px; line-height: 1.5; }
.thumbs { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.thumbs:empty { display: none; }
.thumb {
  position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden;
  border: 2px solid var(--border); background: var(--surface-2); padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumb .thumb-del {
  position: absolute; top: 1px; right: 1px; width: 17px; height: 17px;
  border: 0; border-radius: 5px; background: rgba(20, 28, 45, .7); color: #fff;
  display: grid; place-items: center; padding: 0; opacity: 0; transition: opacity .15s;
}
.thumb:hover .thumb-del { opacity: 1; }
.thumb .thumb-del svg { width: 11px; height: 11px; stroke-width: 2.4; }

/* ---------- form controls ---------- */
textarea {
  width: 100%; resize: vertical; min-height: 58px; padding: 9px 11px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
  line-height: 1.5; outline: none; font-size: 12.5px;
}
textarea:focus, select:focus, .num input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 9px 0 12px; }
.chips button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  border-radius: 999px; padding: 5px 10px; font-size: 11px;
}
.chips button:hover { border-color: #b9c9f5; color: var(--accent-2); background: var(--accent-soft); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 11px; }
.field-row > label { font-size: 12px; color: var(--text-2); white-space: nowrap; }
select {
  height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); outline: none; font-size: 12px; max-width: 190px; flex: 1;
}
.color-line { display: flex; align-items: center; gap: 8px; }
input[type="color"] {
  width: 34px; height: 30px; padding: 2px; border: 1px solid var(--border-strong);
  border-radius: 7px; background: #fff; cursor: pointer;
}
.swatches { display: flex; gap: 5px; }
.swatches button {
  width: 19px; height: 19px; border-radius: 50%; padding: 0;
  background: var(--c); border: 1px solid rgba(0, 0, 0, .12); box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}
.swatches button:hover { transform: scale(1.15); }
.swatches button.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 11px; font-size: 12px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { appearance: none; width: 15px; height: 15px; border: 1.5px solid var(--border-strong); border-radius: 4px; margin: 0; flex: none; cursor: pointer; position: relative; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(42deg); }

.control { margin-top: 14px; }
.control-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.control-head label { font-size: 12px; color: var(--text-2); }
.num { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; height: 25px; }
.num input { width: 44px; border: 0; background: transparent; outline: none; text-align: right; font-size: 11.5px; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.num input::-webkit-inner-spin-button, .num input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num em { font-style: normal; font-size: 10.5px; color: var(--text-3); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; margin: 0;
  border-radius: 4px; background: #e6eaf2; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(30, 50, 100, .25);
}
input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }

.segmented { display: flex; gap: 6px; }
.segmented label { flex: 1; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px; height: 34px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 12px; color: var(--text-2);
  background: var(--surface-2);
}
.segmented span svg { width: 14px; height: 14px; }
.segmented span span.t { display: inline; height: auto; border: 0; border-radius: 0; background: none; padding: 0; gap: 0; }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--text-2); padding: 0; font-size: 12px; }
.link-btn:hover { color: var(--accent); }
.link-btn svg { width: 14px; height: 14px; }

/* ---------- workspace ---------- */
.workspace {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0; height: 100%;
  overflow: hidden; background: var(--bg);
}
.workspace-bar {
  height: 58px; padding: 0 20px; flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: rgba(255, 255, 255, .72); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.file-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-badge { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.file-info strong { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.file-info small { display: block; font-size: 10.5px; color: var(--text-3); margin-top: 2px; }
.bar-tools { display: flex; align-items: center; gap: 14px; }
.btn-hold { touch-action: none; }
.btn-hold.holding { background: var(--accent-soft); border-color: #b9c9f5; color: var(--accent-2); }
.zoom { display: flex; align-items: center; gap: 8px; }
.zoom label { font-size: 11px; color: var(--text-3); }
.zoom input { width: 100px; }
.zoom span { font-size: 11px; color: var(--text-2); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.fit-btn {
  height: 24px; padding: 0 8px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--text-2); font-size: 11px;
}
.fit-btn:hover { border-color: #b9c9f5; color: var(--accent-2); background: var(--accent-soft); }

.stage {
  flex: 1 1 0; min-height: 0;
  overflow: auto; position: relative;
  overscroll-behavior: contain;   /* 滚到边界不把滚动传给整页 */
}
.stage.dragover::after {
  content: "松开即可添加图片"; position: absolute; inset: 12px; z-index: 3;
  border: 2px dashed var(--accent); border-radius: 14px; background: rgba(237, 242, 255, .9);
  display: grid; place-items: center; font-size: 16px; font-weight: 700; color: var(--accent-2);
  pointer-events: none;
}
.canvas-wrap {
  min-height: 100%; padding: 28px; display: flex; align-items: flex-start; justify-content: center;
}
#preview {
  display: block; max-width: none;
  background: #fff;
  box-shadow: 0 6px 24px rgba(26, 38, 66, .14), 0 0 0 1px rgba(26, 38, 66, .07);
  border-radius: 2px;
}
.workspace-foot {
  height: 34px; flex: none; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-top: 1px solid var(--border); background: var(--surface);
  font-size: 10.5px; color: var(--text-3);
}
.workspace-foot span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.workspace-foot svg { width: 13px; height: 13px; color: var(--green); stroke-width: 2.2; }

/* ---------- empty state ---------- */
.empty {
  min-height: 100%; padding: 40px 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 36px;
}
.empty-card {
  width: min(460px, 100%); padding: 36px 32px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; align-items: center;
}
.empty-icon { width: 54px; height: 54px; border-radius: 15px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 18px; }
.empty-icon svg { width: 26px; height: 26px; }
.empty-card h2 { margin: 0 0 10px; font-size: 18px; }
.empty-card p { margin: 0 0 22px; font-size: 12.5px; line-height: 1.8; color: var(--text-2); }
.empty-card .btn-primary { height: 38px; padding: 0 20px; }
.empty-card .btn-text { margin-top: 6px; }
.empty-features { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.empty-features > div {
  width: 190px; padding: 14px; background: rgba(255,255,255,.7); border: 1px solid var(--border);
  border-radius: 11px; display: flex; flex-direction: column; gap: 4px;
}
.empty-features svg { width: 17px; height: 17px; color: var(--accent); margin-bottom: 4px; }
.empty-features strong { font-size: 12px; }
.empty-features span { font-size: 10.5px; color: var(--text-3); line-height: 1.5; }

/* ---------- toast / busy ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: #202b40; color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 12.5px; box-shadow: var(--shadow-md); opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s; z-index: 30; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.busy {
  position: fixed; inset: 0; z-index: 25; background: rgba(244, 246, 250, .55);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 13px; color: var(--text); font-weight: 600;
}
.spinner { width: 18px; height: 18px; border: 2px solid #c8d3ee; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .topbar-center { display: none; }
  .brand { min-width: 0; }
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .empty-features > div { width: 160px; }
}
@media (max-width: 780px) {
  /* 窄屏改为整页上下滚动，恢复文档滚动能力 */
  html, body { height: auto; overflow: visible; overscroll-behavior: auto; }
  body { position: static; }
  .layout { display: flex; flex-direction: column; height: auto; min-height: calc(100dvh - 64px); overflow: visible; }
  .sidebar { order: 2; height: auto; border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  .workspace { order: 1; height: auto; min-height: 60vh; overflow: visible; }
  .stage { min-height: 50vh; }
  .topbar { padding: 0 12px; }
  .brand-text p { display: none; }
  .topbar-actions .btn-ghost { display: none; }
  .file-info strong { max-width: 130px; }
  .zoom { display: none; }
}
