:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-2: #FAFAF8;
  --surface-3: #F1F0EB;
  --border: #E4E2DA;
  --border-2: #D2CFC4;
  --text: #232323;
  --text-2: #6E6C65;
  --text-3: #A5A39B;
  --accent: #185FA5;
  --accent-hover: #14507F;
  --accent-soft: #E6F1FB;
  --accent-line: #85B7EB;
  --ok: #3B6D11;
  --ok-soft: #EAF3DE;
  --warn: #854F0B;
  --warn-soft: #FAEEDA;
  --danger: #A32D2D;
  --danger-soft: #FCEBEB;
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; }

.logo {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--accent);
  position: relative;
}
.logo::after {
  content: "";
  position: absolute;
  inset: 7px 7px 7px 7px;
  border: 1.5px dashed rgba(255,255,255,.85);
  border-radius: 2px;
}

.brand-text h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.2px;
  line-height: 1.2;
}
.brand-text p {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.3;
}

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  padding: 0 12px;
  height: 26px;
  background: var(--surface-3);
  border-radius: 20px;
}
.stat-div { width: 1px; height: 10px; background: var(--border-2); }

/* ---------- 按钮 ---------- */
.btn {
  height: 30px;
  padding: 0 13px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  transition: background .14s, border-color .14s, opacity .14s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: #BEBAAE; }
.btn:active:not(:disabled) { background: #EAE8E1; }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: #10406A; }

.btn-ghost { background: transparent; border-color: var(--border); }
.btn-mini { height: 25px; padding: 0 9px; font-size: 11.5px; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 2px 0;
}
.link:hover { text-decoration: underline; }

.icon-btn {
  background: none; border: none; color: var(--text-3);
  font-size: 13px; width: 20px; height: 20px; border-radius: 4px;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- 工作区 ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 262px minmax(0, 1fr) 232px;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  position: relative;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px 9px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .2px;
  color: var(--text);
}
.panel-head .count {
  font-weight: 400;
  color: var(--text-3);
  margin-left: 3px;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 4px 14px 14px;
}

.panel-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.panel-foot .btn { flex: 1; }
.panel-foot.column { flex-direction: column; }

/* ---------- 参数组 ---------- */
.scope-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.scope-label {
  font-size: 11px;
  color: var(--text-3);
  flex: 0 0 auto;
}
.seg {
  display: flex;
  flex: 1;
  background: var(--surface-3);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.seg button {
  flex: 1;
  height: 22px;
  font-size: 11.5px;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: 4px;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.seg button:hover:not(:disabled):not(.on) { color: var(--text); }
.seg button.on {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(35,35,35,.07);
}
.seg button:disabled { opacity: .4; cursor: not-allowed; }

.group {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.group:last-child { border-bottom: none; }

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 9px;
  letter-spacing: .2px;
}
.group-title .unit {
  font-weight: 400;
  font-size: 10.5px;
  color: var(--text-3);
}

.tip {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.5;
  margin-top: 7px;
}
.tip.warn { color: var(--warn); background: var(--warn-soft); padding: 6px 8px; border-radius: var(--r-sm); }

/* 输入框 */
input[type="number"], input[type="text"], select {
  width: 100%;
  height: 28px;
  padding: 0 7px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color .14s, box-shadow .14s;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-3); }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #8B887F 50%), linear-gradient(135deg, #8B887F 50%, transparent 50%);
  background-position: calc(100% - 13px) 12px, calc(100% - 9px) 12px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  padding-right: 24px;
}

.inset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.inset-grid label {
  display: flex;
  align-items: center;
  gap: 5px;
  position: relative;
}
.inset-grid label span {
  position: absolute;
  left: 7px;
  font-size: 10.5px;
  color: var(--text-3);
  pointer-events: none;
}
.inset-grid input { padding-left: 20px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.check.mini { margin-top: 0; }
.check input {
  appearance: none;
  width: 14px; height: 14px;
  border: 1px solid var(--border-2);
  border-radius: 3px;
  background: var(--surface);
  position: relative;
  cursor: pointer;
  margin: 0;
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 7px;
  border: solid #fff;
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(42deg);
}

/* chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chips button {
  height: 25px;
  padding: 0 9px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  transition: all .12s;
}
.chips button:hover { border-color: #BEBAAE; color: var(--text); }
.chips button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chips.small button { height: 23px; padding: 0 7px; font-size: 11px; }

.ratio-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
}
.ratio-custom input { width: 100%; }
.ratio-custom span { color: var(--text-3); font-size: 12px; }

.anchor-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}
.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 15px);
  grid-template-rows: repeat(3, 15px);
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  flex: 0 0 auto;
}
.anchor-grid button {
  padding: 0;
  border: none;
  border-radius: 2px;
  background: var(--surface-3);
  transition: background .12s;
}
.anchor-grid button:hover { background: var(--accent-line); }
.anchor-grid button.on { background: var(--accent); }
.anchor-row .tip { margin-top: 0; }

.size-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.size-row .mul { color: var(--text-3); font-size: 12px; flex: 0 0 auto; }

.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}
.select-row span {
  font-size: 11.5px;
  color: var(--text-2);
  flex: 0 0 auto;
  width: 28px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}
.slider-row input[type="range"] { min-width: 0; }
.slider-row span, .slider-row b {
  font-size: 11.5px;
  color: var(--text-2);
  font-weight: 400;
  flex: 0 0 auto;
}
.slider-row b { color: var(--text); font-variant-numeric: tabular-nums; width: 20px; text-align: right; }

input[type="range"] {
  flex: 1;
  min-width: 0;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
}

/* ---------- 舞台 ---------- */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface-2);
}

.stage-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.file-name {
  font-size: 12px;
  font-weight: 500;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.override-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 20px;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.drop-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  transition: background .15s, opacity .15s;
}
.drop-hint.dragging { background: var(--accent-soft); }
.drop-box { text-align: center; }
.drop-icon {
  width: 46px; height: 46px;
  margin: 0 auto 14px;
  border: 1.5px dashed var(--border-2);
  border-radius: 10px;
  position: relative;
}
.drop-icon::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 16px; height: 16px;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(var(--text-3), var(--text-3)) center/1.5px 16px no-repeat,
    linear-gradient(var(--text-3), var(--text-3)) center/16px 1.5px no-repeat;
}
.drop-title { font-size: 14px; font-weight: 500; margin-bottom: 5px; }
.drop-sub { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }

.stage-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.zoom-label {
  font-size: 11.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  width: 40px;
}
.stage-foot input[type="range"] { max-width: 130px; flex: 0 1 130px; }
.stage-foot .check { margin: 0; margin-left: 4px; }

/* ---------- 队列 ---------- */
.queue {
  flex: 1;
  overflow-y: auto;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.queue-empty {
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  padding: 24px 0;
}

.qitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  position: relative;
}
.qitem:hover { background: var(--surface-3); }
.qitem.active { background: var(--accent-soft); border-color: var(--accent-line); }
.qitem.override::before {
  content: "";
  position: absolute;
  left: -1px; top: 8px; bottom: 8px;
  width: 2.5px;
  border-radius: 2px;
  background: var(--accent);
}

.qcheck {
  width: 13px; height: 13px;
  border: 1px solid var(--border-2);
  border-radius: 3px;
  background: var(--surface);
  flex: 0 0 auto;
  position: relative;
  padding: 0;
}
.qcheck.on { background: var(--accent); border-color: var(--accent); }
.qcheck.on::after {
  content: "";
  position: absolute;
  left: 3.5px; top: 0.5px;
  width: 3.5px; height: 6.5px;
  border: solid #fff;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(42deg);
}

.qthumb {
  width: 30px; height: 30px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--surface-3);
  flex: 0 0 auto;
  border: 1px solid var(--border);
}

.qinfo { flex: 1; min-width: 0; }
.qname {
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.qsub {
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 5px;
}
.qsub.ok { color: var(--ok); }
.qsub.err { color: var(--danger); }
.qsub.run { color: var(--accent); }
.qbadge {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.qstatus-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--border-2);
}
.qstatus-dot.done { background: var(--ok); }
.qstatus-dot.run { background: var(--accent); animation: pulse 1s infinite; }
.qstatus-dot.err { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ---------- 状态栏 ---------- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 30px;
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-2);
}
.progress {
  width: 80px;
  flex: 0 0 auto;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
#progressText { min-width: 108px; }
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width .2s;
}
.saving { color: var(--ok); font-variant-numeric: tabular-nums; }
.privacy { color: var(--text-3); font-size: 11px; }

/* ---------- 预设弹层 ---------- */
.popover {
  position: absolute;
  left: 10px;
  top: 44px;
  width: 268px;
  max-height: 66vh;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 28px rgba(35, 35, 35, .13);
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.popover-body { overflow-y: auto; padding: 6px; }
.preset-group-title {
  font-size: 10.5px;
  color: var(--text-3);
  padding: 8px 8px 4px;
  letter-spacing: .3px;
}
.preset-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: none;
  border-radius: var(--r-sm);
  text-align: left;
}
.preset-item:hover { background: var(--accent-soft); }
.preset-item .pname { font-size: 12px; color: var(--text); }
.preset-item .pdesc { font-size: 10.5px; color: var(--text-3); }
.preset-item .pdel {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 3px;
  border: none;
  background: none;
}
.preset-item .pdel:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- toast ---------- */
.toast-wrap {
  position: absolute;
  right: 22px;
  bottom: 44px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  align-items: flex-end;
  z-index: 60;
  pointer-events: none;
}
.toast {
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 20px;
  background: #2C2C2A;
  color: #F5F4F0;
  animation: toastIn .18s ease-out;
  max-width: 420px;
  text-align: center;
}
.toast.err { background: var(--danger); }
.toast.ok { background: #2F5D0E; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #D6D3C9;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #BAB6AA; background-clip: content-box; }

/* ---------- 响应式 ---------- */
@media (max-width: 1320px) {
  .workspace { grid-template-columns: 240px minmax(0, 1fr) 208px; }
  .brand-text p { display: none; }
  .group { padding: 10px 0; }
  .group-title { margin-bottom: 7px; }
  .panel-head { padding: 9px 12px 7px; }
  .panel-scroll { padding: 2px 12px 12px; }
}

@media (max-width: 1080px) {
  /* 手机 / 平板：三块改为底部 Tab 切换，避免画布与参数上下堆叠互相挤占 */
  body { overflow: hidden; }
  .app { height: 100vh; height: 100dvh; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    overflow: hidden;
    position: relative;
  }
  .panel, .stage {
    position: absolute;
    inset: 0;
    display: none;
    border: none;
    min-height: 0;
  }
  body:not([data-tab]) .stage,
  body[data-tab="stage"] .stage { display: flex; }
  body[data-tab="params"] .panel-left { display: flex; }
  body[data-tab="queue"] .panel-right { display: flex; }

  .panel-scroll, .queue { max-height: none; }
  .popover { position: fixed; left: 12px; right: 12px; width: auto; top: 60px; }
  .stat { display: none; }
  .statusbar { padding: 0 10px; font-size: 10px; height: 24px; }
  .statusbar .progress,
  .statusbar .saving,
  .statusbar .privacy { display: none; }
}

/* ---------- 移动端分组切换 ---------- */
.mobile-tabs { display: none; }

@media (max-width: 1080px) {
  .mobile-tabs {
    display: flex;
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    gap: 4px;
  }
  .mobile-tabs button {
    flex: 1;
    position: relative;
    padding: 9px 4px;
    border: none;
    border-radius: var(--r-sm);
    background: none;
    font-size: 12.5px;
    color: var(--text-2);
    transition: background .12s, color .12s;
  }
  .mobile-tabs button.on {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
  }
  .mobile-tabs .m-badge {
    font-style: normal;
    display: inline-block;
    min-width: 15px;
    margin-left: 3px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--border);
    color: var(--text-2);
    font-size: 10px;
    line-height: 15px;
    text-align: center;
  }
  .mobile-tabs button.on .m-badge {
    background: var(--accent);
    color: #fff;
  }
}

/* ---------- 画布适配 ---------- */
#fitModeSeg { margin-top: 2px; }

.color-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  flex-wrap: wrap;
}
.color-label {
  font-size: 11px;
  color: var(--text-2);
  flex: 0 0 auto;
}
input[type="color"] {
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  flex: 0 0 auto;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

.swatches {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}
.swatches button {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid var(--border-2);
  transition: transform .12s, border-color .12s;
}
.swatches button:hover { transform: scale(1.12); border-color: var(--text-3); }
.swatches button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- 折叠子项 ---------- */
details.sub {
  margin-top: 9px;
  border-top: 1px dashed var(--border);
  padding-top: 7px;
}
details.sub > summary {
  font-size: 11px;
  color: var(--text-2);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  user-select: none;
}
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > summary::before {
  content: "›";
  display: inline-block;
  margin-right: 5px;
  color: var(--text-3);
  transition: transform .15s;
  font-size: 12px;
}
details.sub[open] > summary::before { transform: rotate(90deg); }
details.sub > summary > span:first-of-type { flex: 1; }
details.sub[open] > summary { margin-bottom: 7px; }

/* ---------- 折叠大分组 ---------- */
details.group { padding: 13px 0; border-bottom: 1px solid var(--border); }
details.group:last-child { border-bottom: none; }
details.group > summary.group-title {
  cursor: pointer;
  list-style: none;
  user-select: none;
  margin-bottom: 0;
}
details.group > summary.group-title::-webkit-details-marker { display: none; }
details.group > summary.group-title > span:first-child::before {
  content: "›";
  display: inline-block;
  margin-right: 5px;
  color: var(--text-3);
  transition: transform .15s;
}
details.group[open] > summary.group-title > span:first-child::before { transform: rotate(90deg); }
details.group[open] > summary.group-title { margin-bottom: 9px; }
.fold-info {
  font-weight: 400;
  font-size: 10.5px;
  color: var(--text-3);
}

/* ---------- 图层 ---------- */
.layer-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.layer-actions .btn { flex: 1; }

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.layer-list:empty { display: none; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 5px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.layer-row:hover { background: var(--surface-3); }
.layer-row.on { background: var(--accent-soft); border-color: var(--accent-line); }
.layer-row .lname {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-row .ltag {
  font-size: 9.5px;
  color: var(--text-3);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  padding: 0 3px;
  flex: 0 0 auto;
}
.layer-thumb {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 3px;
  background: var(--surface-3);
  flex: 0 0 auto;
}
.layer-btn {
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  background: none;
  border-radius: 3px;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1;
  flex: 0 0 auto;
}
.layer-btn:hover { background: var(--border); color: var(--text); }
.layer-btn[data-act="vis"]:not(.off) { color: var(--accent); }
.layer-btn.off { opacity: .38; }
.layer-btn.del:hover { color: var(--danger); background: var(--danger-soft); }

.layer-editor {
  margin-top: 8px;
  padding: 9px 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.layer-editor textarea {
  width: 100%;
  min-height: 44px;
  resize: vertical;
  padding: 6px 7px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  outline: none;
}
.layer-editor textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.field {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
}
.field > span {
  font-size: 11px;
  color: var(--text-2);
  flex: 0 0 38px;
  white-space: nowrap;
}
.field .mini {
  font-size: 10px;
  font-style: normal;
  color: var(--text-3);
  flex: 0 0 auto;
}
.field > input[type="number"],
.field > input[type="text"],
.field > select { flex: 1; min-width: 0; }
.field .suffix { font-size: 10.5px; color: var(--text-3); flex: 0 0 auto; }
.field .val {
  font-size: 11px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  width: 30px;
  text-align: right;
  flex: 0 0 auto;
}
.field input[type="range"] { flex: 1; min-width: 0; }
.field input[type="color"] { width: 26px; height: 24px; }
.field .check { margin: 0; }

.editor-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 8px;
}
.editor-toggles .check { margin: 0; }

.swatch-row {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.swatch-row button {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 3px;
  border: 1px solid var(--border-2);
}
.swatch-row button:hover { border-color: var(--text-3); }

/* ---------- 分组清空按钮 ---------- */
details.group > summary.group-title {
  align-items: center;
  gap: 6px;
}
details.group > summary.group-title > .gt-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clear-btn {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-3);
  transition: color .12s, border-color .12s, background .12s;
}
.clear-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* ---------- 画布上选中图层的操作条 ---------- */
.layer-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 28px);
  padding: 6px 7px 6px 11px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(28, 26, 22, .16), 0 1px 2px rgba(28, 26, 22, .08);
  z-index: 30;
}
.layer-bar.hidden { display: none; }

.layer-bar .lb-kind {
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.layer-bar .lb-kind.image {
  background: var(--ok-soft);
  color: var(--ok);
}
.layer-bar .lb-name {
  flex: 0 1 auto;
  max-width: 130px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-bar .lb-pos {
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.layer-bar .lb-gap {
  flex: 0 0 auto;
  width: 1px;
  height: 16px;
  background: var(--border);
}
.lb-btn {
  flex: 0 0 auto;
  font-size: 11.5px;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  transition: background .12s, color .12s, border-color .12s;
}
.lb-btn:hover { background: var(--surface-3); }
.lb-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.lb-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.lb-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

@media (max-width: 1180px) {
  .layer-bar { gap: 5px; padding: 5px 6px 5px 9px; bottom: 12px; }
  .layer-bar .lb-pos { display: none; }
  .lb-btn { font-size: 11px; padding: 4px 8px; }
}

.lb-btn:disabled {
  opacity: .42;
  cursor: not-allowed;
  background: var(--surface);
}
.lb-btn.primary:disabled {
  background: var(--text-3);
  border-color: var(--text-3);
  color: #fff;
}

/* ---------- 浏览器能力提示 ---------- */
.compat-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 8px 14px;
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid #E8D9B8;
  font-size: 11.5px;
  line-height: 1.45;
}
.compat-bar strong { font-weight: 600; }
.compat-bar span { opacity: .85; }
.compat-bar.hidden { display: none !important; }
