:root {
  color-scheme: dark;
  /* 沉浸浮动工作室（草图 C）：画布井是唯一的"房间"，全部 chrome 是悬浮的
     液态玻璃层。一条石墨-靛蓝中性色阶 + 单一靛蓝 accent。
     --accent-strong 是文字级（够亮，可读于深色玻璃上）；--accent-deep 是填充级。 */
  --bg: #0f1116;            /* 画布井基调 —— 全屏最暗处 */
  --surface: #1d212a;       /* 实心 chrome（输入框、下拉、次级容器） */
  --surface-2: #262c38;
  --surface-3: #2d3442;
  --panel: #181c24;
  --check: #1b1f27;
  --ink: #e9ecf3;
  --ink-soft: #aab3c520;
  --muted: #9ba4b5;
  --muted-2: #6d7689;
  --line: #2b313d;
  --line-strong: #3a4150;
  --accent: #4a72f5;
  --accent-hover: #5d82f8;
  --accent-strong: #a7bbff;
  --accent-deep: #3a5ede;
  --accent-tint: rgba(88, 124, 246, 0.16);
  --accent-tint-2: rgba(88, 124, 246, 0.32);
  --danger: #f28b80;
  --danger-deep: #e2574a;
  --danger-tint: rgba(226, 87, 74, 0.14);
  --success: #4cc38a;
  --warn: #e0a34e;
  --warn-tint: rgba(224, 163, 78, 0.14);
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);
  /* 液态玻璃配方（Apple 式）：半透明底 + 高饱和 blur + 顶部镜面高光边。 */
  --glass: rgba(24, 28, 37, 0.66);
  --glass-strong: rgba(20, 24, 32, 0.82);
  --glass-sheen: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.015) 38%, rgba(255, 255, 255, 0) 62%, rgba(255, 255, 255, 0.03));
  --glass-edge:
    inset 0 1px 0 rgba(255, 255, 255, 0.11),
    inset 0 0 0 1px rgba(255, 255, 255, 0.055),
    inset 0 -1px 0 rgba(0, 0, 0, 0.22);
  --glass-shadow: 0 14px 36px rgba(0, 0, 0, 0.42), 0 2px 8px rgba(0, 0, 0, 0.28);
  --well:
    radial-gradient(120% 90% at 50% 38%, #14171f 0%, #0d0f14 62%, #090a0e 100%);
  --hover-wash: rgba(255, 255, 255, 0.06);
  --hover-wash-2: rgba(255, 255, 255, 0.1);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs-base: 13.5px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

/* 浅色主题 token 覆盖：暗色是精修基准，浅色保证可用（001 口径）。 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e8ebf1;
  --surface: #fbfcfd;
  --surface-2: #f1f4f8;
  --surface-3: #e7ebf2;
  --panel: #f0f3f7;
  --check: #dde2ea;
  --ink: #1a2230;
  --ink-soft: #34405220;
  --muted: #5c6677;
  --muted-2: #8a93a3;
  --line: #dde3ec;
  --line-strong: #cbd3df;
  --accent: #3b5bdb;
  --accent-hover: #2f49b2;
  --accent-strong: #2f49b2;
  --accent-deep: #2f49b2;
  --accent-tint: rgba(59, 91, 219, 0.1);
  --accent-tint-2: rgba(59, 91, 219, 0.2);
  --danger: #d6453a;
  --danger-deep: #d6453a;
  --danger-tint: #fbeae8;
  --success: #2f9e6f;
  --warn: #c8801e;
  --warn-tint: #fbf3e6;
  --shadow-sm: 0 1px 2px rgba(26, 34, 48, 0.05), 0 1px 3px rgba(26, 34, 48, 0.06);
  --shadow-md: 0 6px 18px rgba(26, 34, 48, 0.09);
  --shadow-lg: 0 14px 38px rgba(26, 34, 48, 0.14);
  /* 002 浅色精修：提高玻璃底不透明度 + 描边对比 + 投影层次，浮层在浅底上
     不再"糊"在画布里；镜面高光保留但收敛。 */
  --glass: rgba(252, 253, 255, 0.78);
  --glass-strong: rgba(250, 251, 254, 0.9);
  --glass-sheen: linear-gradient(160deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.2) 38%, rgba(255, 255, 255, 0) 62%, rgba(255, 255, 255, 0.28));
  --glass-edge:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    inset 0 -1px 0 rgba(26, 34, 48, 0.07),
    0 0 0 1px rgba(26, 34, 48, 0.09);
  --glass-shadow: 0 16px 40px rgba(26, 34, 48, 0.16), 0 3px 10px rgba(26, 34, 48, 0.09);
  --well:
    radial-gradient(120% 90% at 50% 38%, #eef1f6 0%, #e3e7ee 62%, #d9dee7 100%);
  --hover-wash: rgba(26, 34, 48, 0.05);
  --hover-wash-2: rgba(26, 34, 48, 0.08);
}

/* 少数无法共用一条 rgba 的地方。 */
:root[data-theme="light"] .working-overlay { background: rgba(26, 34, 48, 0.12); }
:root[data-theme="light"] .project-transition { background: rgba(248, 250, 252, 0.74); }
:root[data-theme="light"] .frame-pending { background: rgba(140, 152, 170, 0.1); }
:root[data-theme="light"] .frame-pending::after {
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.5) 50%, transparent 80%);
}
:root[data-theme="light"] .error-box { border-color: rgba(214, 69, 58, 0.4); }
:root[data-theme="light"] .error-box span { color: #8d2d25; }
:root[data-theme="light"] .mention-highlight .mention-token {
  background: rgba(59, 91, 219, 0.18);
  box-shadow: 0 0 0 1px rgba(59, 91, 219, 0.55);
}
:root[data-theme="light"] .toast {
  background: var(--ink);
  border-color: transparent;
  color: white;
}
:root[data-theme="light"] .status-dot.ready { box-shadow: 0 0 0 3px rgba(47, 158, 111, 0.16); }
:root[data-theme="light"] .gen-pop {
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.16), 0 2px 8px rgba(15, 23, 42, 0.07);
}
:root[data-theme="light"] .error-box span { color: #8d2d25; }

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

::selection {
  background: rgba(88, 124, 246, 0.4);
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* 统一细滚动条：玻璃浮层里原生粗轨道过于抢眼 */
*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
  border: 2.5px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--muted-2);
}
*::-webkit-scrollbar-track,
*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ============ 液态玻璃基元 ============ */
.glass {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-edge), var(--glass-shadow);
}

/* 顶部镜面高光（液态玻璃的"流光"层）：叠加一层不可交互的渐变。 */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--glass-sheen);
  pointer-events: none;
}

/* 玻璃内的内容必须浮在流光层之上。 */
.glass > * {
  position: relative;
}

/* ============ 外壳：全幅画布 + 悬浮层 ============ */
.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

.float {
  position: absolute;
  z-index: 40;
}

/* ============ 画布井 ============ */
.canvas-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--well);
}

/* ---- 左上：品牌 + 项目 ---- */
.cluster-tl {
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.wordmark {
  font-size: var(--fs-base);
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--danger-deep);
  box-shadow: 0 0 0 3px var(--danger-tint);
  flex: 0 0 auto;
}

.status-dot.ready {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(76, 195, 138, 0.18);
}

.proj-wrap {
  position: relative;
}

.proj-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 30vw;
  padding: 9px 14px;
  border: 0;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 650;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 150ms ease;
}

.proj-pill::after {
  content: "";
  width: 8px;
  height: 5px;
  flex: none;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  opacity: 0.55;
}

.proj-pill:hover {
  background-color: var(--hover-wash);
}

/* 项目菜单：position:fixed，projects.js 打开时锚到 pill 下方。 */
.proj-menu {
  position: fixed;
  min-width: 216px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  z-index: 900; /* 语义层级：popover 60 < transition 800 < dropdown 900 < toast 1000 */
}

.proj-menu[hidden] {
  display: none;
}

.proj-menu-items {
  display: grid;
  gap: 1px;
}

.proj-item,
.proj-mi {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-sm);
  text-align: left;
  list-style: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 140ms ease;
}

.proj-item:hover,
.proj-mi:hover {
  background: var(--hover-wash);
}

.proj-item.active {
  color: var(--accent-strong);
  font-weight: 700;
  background: var(--accent-tint);
}

.proj-mi svg {
  color: var(--muted);
  flex: none;
}

.proj-mi.danger:hover {
  background: var(--danger-tint);
  color: var(--danger);
}

.proj-mi.danger svg {
  color: var(--danger);
}

.proj-menu-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--line);
}

/* ---- 右上：全局图标操作 ---- */
.cluster-tr {
  top: 16px;
  right: 16px;
}

.icon-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
}

.iconbtn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 120ms ease;
}

.iconbtn:hover:not(:disabled) {
  background: var(--hover-wash);
  color: var(--ink);
  transform: translateY(-1px);
}

.iconbtn:active:not(:disabled) {
  transform: translateY(0);
}

.iconbtn:disabled {
  color: var(--muted-2);
  opacity: 0.5;
  cursor: not-allowed;
}

.iconbtn.active {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.iconbtn.danger:hover:not(:disabled) {
  background: var(--danger-tint);
  color: var(--danger);
}

.icon-div {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--line);
}

/* ---- 左侧：竖向工具 dock ---- */
.tool-dock {
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  padding: 7px;
}

.tool-dock .tools {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dock-tool {
  position: relative;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.dock-tool:hover:not(:disabled) {
  background: var(--hover-wash);
  color: var(--ink);
}

.dock-tool.active {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.dock-tool.active::after {
  content: "";
  position: absolute;
  left: -7px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.dock-tool:disabled {
  color: var(--muted-2);
  opacity: 0.38;
  cursor: not-allowed;
}

.tool-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}

/* dock tooltip */
.dock-tool[data-tip]::before {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-xs);
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
  z-index: 60;
}

.dock-tool:hover[data-tip]::before {
  opacity: 1;
}

/* ---- 拆层参数浮层（所有拆层入口先经过这里） ---- */
.split-pop {
  left: 72px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  display: grid;
  gap: 11px;
  width: 244px;
  padding: 15px 16px 16px;
}

.split-pop[hidden] {
  display: none;
}

.split-pop h4 {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 650;
}

.split-pop p {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.45;
}

/* 拆层参数 segmented（替代原生 select）：等分按钮 + seg-glider 滑块动效。 */
.split-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* ---- 右侧：浮动图层面板 ---- */
.layer-panel {
  top: 72px;
  right: 16px;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-height: calc(100% - 150px);
  overflow: hidden;
}

.layer-panel[hidden] {
  display: none;
}

body.layers-collapsed .layer-panel {
  display: none;
}

.layer-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 15px 11px;
  border-bottom: 1px solid var(--line);
}

.layer-panel-head > div {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.layer-panel-head strong {
  font-size: var(--fs-base);
  font-weight: 650;
}

.layer-panel-head span {
  color: var(--muted);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lp-collapse {
  width: 28px;
  height: 28px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.lp-collapse:hover {
  background: var(--hover-wash);
  color: var(--ink);
}

.layer-list {
  display: grid;
  gap: 3px;
  align-content: start;
  padding: 8px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

/* 折叠态标签 */
.layer-tab {
  top: 72px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 0;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 650;
  cursor: pointer;
}

.layer-tab[hidden] {
  display: none;
}

.layer-tab:hover {
  background-color: var(--hover-wash);
}

.layer-tab svg {
  color: var(--muted);
}

/* ---- 生成设置（挂图层面板下方，dock.js 定位 top） ---- */
.gen-panel {
  right: 16px;
  top: 72px;
  display: grid;
  gap: 12px;
  width: 300px;
  padding: 13px 15px 15px;
}

.gen-panel[hidden] {
  display: none;
}

.drawer-head {
  display: grid;
  gap: 2px;
}

.drawer-head strong {
  font-size: var(--fs-base);
  font-weight: 650;
}

.drawer-head span {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.result-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.result-strip:empty {
  display: none;
}

/* ---- 通用小按钮（图层面板底部等） ---- */
.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.seg-btn:hover:not(:disabled) {
  background: var(--surface-3);
}

.seg-btn:disabled {
  color: var(--muted-2);
  cursor: not-allowed;
  opacity: 0.6;
}

.seg-btn.primary {
  background: var(--accent-tint);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent-deep);
}

.seg-btn.primary:hover:not(:disabled) {
  background: var(--accent-tint-2);
}

.seg-btn.busy {
  position: relative;
  overflow: hidden;
}

.seg-btn.busy::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: progress-sweep 1100ms linear infinite;
}

/* ============ 底部命令 dock ============ */
.command-bar {
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 11px;
  /* 与右下缩放控件互不叠压：中等宽度下按视口收窄，宽屏保持 760px。 */
  width: min(760px, max(400px, calc(100vw - 520px)));
  padding: 12px 14px;
}

.cmd-row {
  /* 三件套（上传 / 输入框 / 生成）统一由输入框撑高、其余拉伸对齐 */
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.prompt-stack {
  display: grid;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.prompt-stack textarea {
  min-height: 48px;
  max-height: 140px;
  padding: 13px 14px;
  border-radius: var(--radius);
  /* 高度由 entry.js 自动增长驱动；手动拖拽角标只会破坏三件套对齐 */
  resize: none;
}

.btn-gen {
  flex: none;
  align-self: stretch;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--accent-hover), var(--accent-deep));
  color: #fff;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 2px 10px rgba(74, 114, 245, 0.35);
  transition: filter 140ms ease, box-shadow 140ms ease, transform 120ms ease;
}

.btn-gen:hover {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent-deep));
  filter: brightness(1.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 4px 16px rgba(74, 114, 245, 0.45);
}

.btn-gen:active {
  background: linear-gradient(180deg, var(--accent-deep), var(--accent-deep));
  transform: translateY(1px);
}

.btn-gen svg {
  flex: none;
}

.upload-icon-button {
  /* 随输入框高度拉伸的"迷你拖放区"：虚线框 + 居中图标，与 prompt 框读作一组 */
  align-self: stretch;
  width: 48px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.upload-icon-button:hover {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.upload-icon-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ===== 生成选项 chips + 上浮 popover（gensize.js 构建） ===== */
.gen-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  min-height: 26px;
}

.gen-options:empty {
  display: none;
}

.gen-chip-wrap {
  position: relative;
}

.gen-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 10px 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.gen-chip:hover,
.gen-chip-wrap.open .gen-chip {
  background: var(--surface-3);
  border-color: var(--line-strong);
  color: var(--ink);
}

.gen-chip-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.gen-chip-value {
  font-size: 12px;
  font-weight: 750;
  color: var(--accent-strong);
}

.gen-chip-caret {
  display: inline-flex;
  color: var(--muted-2);
  will-change: transform;
}

.gen-pop {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 60;
  min-width: 158px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--surface-2);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  will-change: transform, opacity;
}

.gen-pop[hidden] { display: none; }

.gen-pop-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background 130ms ease;
}

.gen-pop-row:hover { background: var(--surface-3); }
.gen-pop-row.active { background: var(--accent-tint); }
.gen-pop-row.active .gen-pop-row-title { color: var(--accent-strong); }

.gen-pop-row-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
}

.gen-pop-row-hint {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

.gen-pop-counts {
  display: flex;
  gap: 5px;
  padding: 2px;
}

.gen-pop-count {
  width: 36px;
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease, border-color 130ms ease;
}

.gen-pop-count:hover:not(.active) { background: var(--surface-3); color: var(--ink); }

.gen-pop-count.active {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-weight: 700;
}

.gen-pop-wide { width: 312px; }

.gen-pop-ratios {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.gen-ratio-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 40px;
  padding: 5px 2px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease, border-color 130ms ease;
}

.gen-ratio-cell:hover:not(.active) {
  background: var(--surface-3);
  color: var(--ink);
}

.gen-ratio-cell.active {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.gen-ratio-thumb {
  display: block;
  border: 1.5px solid currentColor;
  border-radius: 2.5px;
  opacity: 0.7;
  transition: opacity 130ms ease, background 130ms ease;
}

.gen-ratio-cell.active .gen-ratio-thumb {
  opacity: 1;
  background: currentColor;
}

.gen-ratio-text {
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}

/* ============ 表单控件 ============ */
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.field.compact {
  gap: 8px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: var(--fs-xs);
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

textarea {
  resize: vertical;
  min-height: 80px;
  padding: 10px 12px;
  line-height: 1.5;
}

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

input[type="range"] {
  padding: 0;
  min-height: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--muted-2);
  cursor: not-allowed;
}

/* ============ 按钮 ============ */
.button {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 0 16px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.button:hover {
  background: var(--surface-3);
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button.busy {
  position: relative;
  overflow: hidden;
}

.button.busy::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  animation: progress-sweep 1100ms linear infinite;
}

.button.primary {
  border-color: transparent;
  background: var(--accent);
  color: white;
  font-weight: 650;
  box-shadow: 0 2px 10px rgba(74, 114, 245, 0.32);
}

.button.primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 3px 14px rgba(74, 114, 245, 0.42);
}

.button.primary:active {
  background: var(--accent-deep);
}

.button.secondary {
  flex: 1;
}

.compact-button {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* ============ 画布状态（左下） / 缩放控件（右下） ============ */
.canvas-status {
  position: absolute;
  left: 16px;
  bottom: 20px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0;
  max-width: calc(50% - 400px);
  min-width: 0;
  padding: 8px 4px;
}

.status-pill {
  min-width: 0;
  max-width: 32vw;
  padding: 0 12px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill + .status-pill {
  border-left: 1px solid var(--line);
}

.selection-label {
  min-width: 0;
  max-width: 30vw;
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 3px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-label[hidden] { display: none; }
.selection-label[data-mode="busy"] { color: var(--accent-strong); }
.selection-label[data-mode="warn"] {
  border-color: var(--warn);
  background: var(--warn-tint);
  color: var(--warn);
}

.canvas-tools {
  position: absolute;
  right: 16px;
  bottom: 20px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
}

.canvas-tools[hidden] {
  display: none;
}

.canvas-tool-button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease;
}

.canvas-tool-button:hover {
  background: var(--hover-wash);
  color: var(--ink);
}

.canvas-tool-button.zoom-fit {
  padding: 0 10px;
  font-size: var(--fs-xs);
}

.canvas-tool-button.zoom-step {
  width: 30px;
  padding: 0;
  font-size: 14px;
}

.zoom-label {
  min-width: 48px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ============ 画布坐标契约（2.8，勿放松） ============ */
canvas {
  display: none;
  max-width: 100%;
  max-height: calc(100vh - 190px);
}

#imageCanvas,
#maskCanvas,
.layer-stage {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

#maskCanvas {
  cursor: crosshair;
  touch-action: none;
  pointer-events: none;
}

.has-image canvas {
  display: block;
}

.selection-mode #maskCanvas {
  pointer-events: auto;
}

.layer-stage {
  display: none;
  overflow: hidden;
  background: transparent;
  touch-action: none;
  cursor: default;
}

.layer-mode #imageCanvas {
  display: none;
}

.layer-mode #maskCanvas {
  display: none;
}

.layer-mode.selection-mode #maskCanvas {
  display: block;
  z-index: 4;
  max-width: none;
  max-height: none;
  /* In layer mode the red selection is drawn by the in-stage Konva mask node,
     which shares the layers' transform and cannot drift. This DOM canvas stays
     only as the offscreen pixel buffer and the pointer-input surface, so it must
     capture clicks but never be seen (otherwise a drifting copy shows on top). */
  opacity: 0;
}

.layer-mode .layer-stage {
  display: block;
  inset: 0;
  transform: none;
  max-width: none;
  max-height: none;
}

/* Never clamp the Konva canvas: it must render 1:1 with the stage so every
   coordinate system below (world -> stage -> overlay) lines up. */
.layer-mode .layer-stage canvas {
  display: block;
  max-width: none;
  max-height: none;
}

/* 抓手/选择模式下的画布光标（dock.js 切 body class） */
.layer-mode .layer-stage {
  cursor: grab;
}

body.board-select .layer-mode .layer-stage {
  cursor: default;
}

/* ---- crop overlay ---- */
.layer-crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.layer-crop-overlay[hidden] {
  display: none;
}

.layer-crop-box {
  position: absolute;
  border: 2px dashed var(--warn);
  background: rgba(224, 163, 78, 0.16);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.dom-crop-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--warn);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.dom-crop-handle.nw, .dom-crop-handle.ne,
.dom-crop-handle.sw, .dom-crop-handle.se { border-radius: 3px; }
.dom-crop-handle.nw { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.dom-crop-handle.n { left: 50%; top: 0; transform: translate(-50%, -50%); cursor: ns-resize; }
.dom-crop-handle.ne { right: 0; top: 0; transform: translate(50%, -50%); cursor: nesw-resize; }
.dom-crop-handle.e { right: 0; top: 50%; transform: translate(50%, -50%); cursor: ew-resize; }
.dom-crop-handle.se { right: 0; bottom: 0; transform: translate(50%, 50%); cursor: nwse-resize; }
.dom-crop-handle.s { left: 50%; bottom: 0; transform: translate(-50%, 50%); cursor: ns-resize; }
.dom-crop-handle.sw { left: 0; bottom: 0; transform: translate(-50%, 50%); cursor: nesw-resize; }
.dom-crop-handle.w { left: 0; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }

/* ---- pending (placeholder) frames ---- */
.frame-pending-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: none;
}

.layer-mode .frame-pending-layer {
  display: block;
}

.frame-pending {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(160, 175, 200, 0.06);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame-pending::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(233, 236, 243, 0.09) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: framePendingSweep 1.25s ease-in-out infinite;
}

.frame-pending-label {
  position: relative;
  z-index: 1;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-align: center;
  padding: 0 8px;
}

.frame-pending.failed {
  border-color: rgba(226, 87, 74, 0.7);
  background: var(--danger-tint);
}

.frame-pending.failed::after { display: none; }
.frame-pending.failed .frame-pending-label { color: var(--danger); }

@keyframes framePendingSweep {
  to { transform: translateX(100%); }
}

/* ---- 矩形框选（选择模式下空白处拖动） ---- */
.marquee-box {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  border: 1.5px dashed var(--accent);
  border-radius: 2px;
  background: var(--accent-tint);
}

.marquee-box[hidden] { display: none; }

/* ---- 上下文物体工具条（浮在选中图片上方） ---- */.layer-selection-menu {
  position: absolute;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  transform: translate(-50%, -100%);
  border-radius: var(--radius);
}

.layer-selection-menu[hidden] { display: none; }

/* 上方空间不足时翻到选框下方：去掉 -100% 的上移。 */
.layer-selection-menu.below { transform: translate(-50%, 0); }

.layer-selection-menu button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease;
}

.layer-selection-menu button:hover {
  background: var(--hover-wash);
}

.layer-selection-menu button.primary {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.layer-selection-menu button.primary:hover {
  background: var(--accent-tint-2);
}

.layer-selection-menu button.danger { color: var(--danger); }
.layer-selection-menu button.danger:hover { background: var(--danger-tint); }

.layer-selection-menu .menu-div {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: var(--line);
}

/* ---- 图层编辑面板（签名交互） ---- */
.layer-edit-panel {
  position: absolute;
  z-index: 55;
  display: grid;
  gap: 12px;
  width: 320px;
  max-width: calc(100vw - 32px);
  /* Never taller than the canvas it floats in — #canvasWrap has overflow:hidden,
     so an oversized panel would get its bottom border + buttons clipped. Cap the
     height and scroll internally instead. overflow-x MUST be explicit: with only
     overflow-y set, CSS computes overflow-x to `auto`, so a long title would trip
     a spurious horizontal scrollbar. */
  max-height: calc(100% - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 15px 16px;
}

.layer-edit-panel[hidden] { display: none; }

/* 编辑面板会内部滚动：sheen 伪元素随内容滚走没关系，但要保证不挡交互（已 pointer-events:none）。 */

.layer-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.layer-edit-head strong {
  min-width: 0;
  font-size: var(--fs-base);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-edit-head button {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.layer-edit-head button:hover {
  background: var(--hover-wash);
  color: var(--ink);
}

.layer-edit-head[data-drag-handle] {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.layer-edit-panel textarea {
  min-height: 72px;
  max-height: 150px;
  resize: vertical;
  font-size: 13px;
}

/* 分段控件（编辑范围 / 尺寸策略） */
.layer-edit-scope {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.layer-edit-sizemode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.layer-edit-sizemode .layer-edit-size {
  grid-column: 1 / -1;
  min-height: 30px;
  border-radius: 6px;
}

.scope-button {
  min-height: 28px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 130ms ease, color 130ms ease;
}

.scope-button:hover:not(:disabled) {
  color: var(--ink);
}

.scope-button.active {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.scope-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.concept-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.layer-concept-row { display: none; }
.layer-edit-panel.scope-concept .layer-concept-row { display: grid; }

.layer-brush-control { display: none; }
.layer-edit-panel.scope-paint .layer-brush-control,
.layer-edit-panel.scope-erase .layer-brush-control { display: grid; }

.layer-brush-control span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.layer-brush-control b { color: var(--accent-strong); font-family: var(--mono); }

.layer-edit-meta {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.layer-edit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 7px;
}

/* ---- 选区膨胀（仅 SAM 有效，.show-dilate 控制显隐） ---- */
.layer-edit-dilate {
  display: none;
  flex-direction: column;
  gap: 7px;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.layer-edit-panel.show-dilate .layer-edit-dilate { display: flex; }

.dilate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layer-edit-dilate-label {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.dilate-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  background: var(--accent-tint);
  padding: 2px 8px;
  border-radius: 999px;
}

.dilate-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--dilate-pct, 0%),
    var(--line-strong) var(--dilate-pct, 0%),
    var(--line-strong) 100%
  );
  outline: none;
  cursor: pointer;
}
.dilate-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.dilate-range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.dilate-range::-webkit-slider-thumb:active { transform: scale(1.04); box-shadow: 0 0 0 4px var(--accent-tint-2); }
.dilate-range::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
}

.dilate-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding: 0 1px;
}

/* ---- SAM candidates (A–E groups) ---- */
.mask-candidates {
  display: grid;
  gap: 7px;
  max-height: 188px;
  overflow-y: auto;
}

.mask-candidates:empty { display: none; }

.candidate {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.candidate.loading {
  border-color: var(--accent);
  color: var(--accent-strong);
  animation: soft-pulse 950ms ease-in-out infinite;
}

.candidate.active {
  border-color: var(--danger);
  background: var(--danger-tint);
  color: var(--danger);
}

.candidate-group {
  display: grid;
  grid-template-columns: 20px auto minmax(0, 1fr) 22px;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.candidate-group-name {
  display: grid;
  place-items: center;
  width: 20px;
  height: 24px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
}

.candidate-group.active .candidate-group-name {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.candidate-options { display: flex; gap: 5px; }

.candidate-label {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-label[data-mode="busy"] { color: var(--accent-strong); }
.candidate-label[data-mode="warn"] { color: var(--danger); }

/* 分组条删除入口：ghost 小按钮，线性描边 ×，hover 转 danger */
.candidate-delete {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.candidate-delete:hover {
  background: var(--danger-tint);
  color: var(--danger);
}
.candidate-delete svg { width: 12px; height: 12px; display: block; }

.sam-status {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sam-status[data-mode="ready"] { color: var(--success); }
.sam-status[data-mode="busy"] { color: var(--accent-strong); }

/* ---- error box ---- */
.error-box {
  display: grid;
  gap: 6px;
  padding: 11px 12px;
  border: 1px solid rgba(226, 87, 74, 0.45);
  border-radius: var(--radius-sm);
  background: var(--danger-tint);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.45;
}

.error-box[hidden] { display: none; }
.error-box strong { font-size: 12px; }
.error-box span { overflow-wrap: anywhere; color: #f2aaa1; }

/* ---- empty state ---- */
.empty {
  display: grid;
  gap: 10px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.empty strong { color: var(--ink); font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.empty > span { font-size: 13px; max-width: 34ch; }
.has-image .empty { display: none; }

.empty-mark {
  position: relative;
  width: 88px;
  height: 72px;
  margin-bottom: 6px;
}
.empty-mark span {
  position: absolute;
  width: 56px;
  height: 42px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}
.empty-mark span:nth-child(1) { left: 0; top: 0; }
.empty-mark span:nth-child(2) { left: 14px; top: 13px; border-color: var(--muted-2); }
.empty-mark span:nth-child(3) {
  left: 28px; top: 26px;
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: var(--shadow-sm);
}

/* ---- overlays ---- */
.working-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 60;
  background: rgba(10, 12, 16, 0.5);
  pointer-events: none;
}
.working-overlay[hidden] { display: none; }

.working-box {
  width: min(280px, calc(100% - 40px));
  display: grid;
  gap: 9px;
  padding: 14px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.working-bar {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}
.working-bar::before {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: progress-slide 1150ms ease-in-out infinite;
}

/* SAM 点选即时反馈：点击处水波纹（纯 CSS，不依赖 GSAP）。
   JS（core.js showClickPing）750ms 后移除节点，动画只负责观感。 */
.click-ping {
  position: absolute;
  z-index: 70; /* 压在 working-overlay(60) 的暗化之上，点击点始终可见 */
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 2px var(--accent-tint-2);
  pointer-events: none;
  animation: ping-dot 700ms ease-out forwards;
}
.click-ping::before {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  animation: ping-ring 700ms ease-out forwards;
}
@keyframes ping-dot {
  0% { transform: scale(0.5); opacity: 0.95; }
  55% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}
@keyframes ping-ring {
  from { transform: scale(1); opacity: 0.85; }
  to { transform: scale(3.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  /* 降级为静态圆点：仍然有"点到了"的即时确认，但不做扩散动画 */
  .click-ping { animation: none; opacity: 0.8; }
  .click-ping::before { animation: none; opacity: 0; }
}

.project-transition {
  position: absolute;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 18, 24, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: all;
}
.project-transition[hidden] { display: none; }
.project-transition.visible { opacity: 1; }
.project-transition.fade-out { opacity: 0; }
.project-transition-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  transform: translateY(6px);
  transition: transform 0.28s ease;
}
.project-transition.visible .project-transition-inner { transform: translateY(0); }
.project-transition-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--accent-tint-2);
  border-top-color: var(--accent);
  animation: project-spin 0.8s linear infinite;
}
.project-transition-text {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.project-transition-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 220px;
}
.project-transition-progress[hidden] { display: none; }
.project-transition-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--accent-tint-2);
  overflow: hidden;
}
.project-transition-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.18s ease;
}
.project-transition-progress.indeterminate .project-transition-bar-fill {
  width: 40% !important;
  animation: project-progress-sweep 1.1s ease-in-out infinite;
}
@keyframes project-progress-sweep {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
.project-transition-bytes {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
@keyframes project-spin { to { transform: rotate(360deg); } }

/* ============ 图层列表行 ============ */
.layer-item {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) repeat(3, 24px);
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: grab;
  transition: background 140ms ease, opacity 140ms ease;
}
/* transform 过渡只在拖动进行中生效（整行让位平移）；平时关掉，避免与
   FLIP 回放（GSAP 逐帧写 transform）互相拉扯。 */
#layerList.drag-active .layer-item {
  transition: background 140ms ease, opacity 140ms ease,
    transform 220ms cubic-bezier(0.25, 0.8, 0.3, 1);
}
.layer-item:hover { background: var(--hover-wash); }
.layer-item.selected { background: var(--accent-tint); }
.layer-item.selected .layer-main strong { color: var(--accent-strong); }
.layer-item.muted { opacity: 0.55; }

/* ---- 拖动排序反馈 ---- */
/* 拖起的源行：明显降透明 + 虚线描边占位（原生拖影仍是完整快照）。
   落点反馈是 iOS 式整行让位：JS 给源行与插入点之间的行写内联
   translateY（一行高），插入处腾出整行空隙，无需指示条。 */
.layer-item.dragging {
  opacity: 0.3;
  cursor: grabbing;
  box-shadow: inset 0 0 0 1.5px var(--accent-tint-2);
}

@media (prefers-reduced-motion: reduce) {
  .layer-item { transition: none; }
}

.layer-item img {
  width: 38px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  object-fit: contain;
  background:
    linear-gradient(45deg, var(--check) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check) 75%);
  background-color: var(--bg);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.layer-main { display: grid; gap: 1px; min-width: 0; padding-right: 2px; }
.layer-main strong { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-main span { color: var(--muted-2); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layer-icon-button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease;
}
.layer-icon-button svg { display: block; }
.layer-icon-button:disabled { cursor: not-allowed; opacity: 0.38; }
.layer-icon-button:hover:not(:disabled) { background: var(--hover-wash-2); color: var(--ink); }
.layer-icon-button.active { color: var(--ink); }
.layer-icon-button.danger { color: var(--muted-2); }
.layer-icon-button.danger:hover:not(:disabled) { background: var(--danger-tint); color: var(--danger); }

.thumb {
  width: 64px;
  height: 50px;
  flex: 0 0 auto;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
}
.thumb.active { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  right: 20px;
  bottom: 80px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  transition: opacity 200ms cubic-bezier(0.22, 1, 0.36, 1), transform 200ms cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }

@keyframes progress-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}
@keyframes progress-slide {
  0% { transform: translateX(-110%); }
  50% { transform: translateX(82%); }
  100% { transform: translateX(250%); }
}
@keyframes soft-pulse {
  0%, 100% { opacity: 0.62; }
  50% { opacity: 1; }
}

/* ============ 响应式 ============ */
@media (max-width: 1100px) {
  .canvas-status { display: none; }
}

@media (max-width: 900px) {
  .layer-panel, .gen-panel { width: 264px; }
  /* 窄屏：命令栏可以放宽，缩放控件改为抬到命令栏上方，互不叠压。 */
  .command-bar { width: calc(100vw - 24px); bottom: 12px; }
  .canvas-tools { bottom: 118px; right: 8px; }
  .tool-dock { left: 8px; }
  .cluster-tl { left: 8px; top: 8px; }
  .cluster-tr { right: 8px; top: 8px; }
  .layer-panel, .layer-tab { right: 8px; top: 64px; }
  .gen-panel { right: 8px; }
  /* 窄屏下右侧图层面板压缩最大高度，避免和底部命令栏叠压。 */
  .layer-panel { max-height: calc(100% - 220px); }
}

@media (max-width: 640px) {
  .command-bar { width: calc(100vw - 16px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ── @图片引用 — layer-reference picker + chips ─────────────────────────── */
.mention-pop {
  position: fixed;
  z-index: 900;
  width: 280px;
  max-width: calc(100vw - 16px);
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.mention-pop-head {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 4px 6px;
}
.mention-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.mention-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
}
.mention-item:hover { border-color: var(--line-strong); }
.mention-item.selected {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.mention-item img {
  width: 100%;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
}
.mention-item-name {
  font-size: 11px;
  color: var(--ink);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mention-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* 空 chips 容器不占 prompt-stack 的 grid 轨道，否则命令行三件套高度差 14px */
.mention-chips:empty {
  display: none;
}
.mention-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 4px;
  font-size: 12px;
  color: var(--accent-strong);
  background: var(--accent-tint);
  border: 1px solid var(--accent-tint-2);
  border-radius: 999px;
}
.mention-chip-thumb {
  width: 18px;
  height: 18px;
  object-fit: cover;
  border-radius: 50%;
  background: #fff;
}
.mention-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.mention-chip-x:hover { color: var(--danger); background: var(--danger-tint); }

.mention-input-wrap {
  position: relative;
  display: grid;
  min-width: 0;
}
.mention-input-wrap > textarea {
  position: relative;
  z-index: 1;
  width: 100%;
}
.mention-highlight {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  overflow: hidden;
  pointer-events: none;
  color: transparent;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.mention-highlight .mention-token {
  border-radius: 4px;
  background: rgba(116, 148, 255, 0.24);
  box-shadow: 0 0 0 1px rgba(116, 148, 255, 0.55);
}

/* ============ 自定义弹窗（modal.js，替代原生 prompt/confirm） ============ */
/* 语义层级：popover 60 < transition 800 < dropdown 900 < modal 950 < toast 1000 */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(9, 11, 15, 0.48);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

/* display:flex 会盖掉 UA 的 [hidden]{display:none}，必须显式补回。 */
.modal-overlay[hidden] {
  display: none;
}

:root[data-theme="light"] .modal-overlay {
  background: rgba(26, 34, 48, 0.2);
}

.modal-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 20px;
  border-radius: var(--radius-lg);
}

.modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.modal-message {
  margin: 0;
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.modal-actions .button {
  min-height: 34px;
  padding: 0 18px;
  font-size: var(--fs-base);
}

.button.danger {
  border-color: transparent;
  background: var(--danger-deep);
  color: #fff;
  box-shadow: 0 2px 10px rgba(226, 87, 74, 0.3);
}

.button.danger:hover {
  background: var(--danger-deep);
  filter: brightness(1.08);
}

/* ============ segmented 滑块（motion.js attachSegmentedGlider） ============ */
/* 有动效时 active 背景由 .seg-glider 承载，从旧位置滑到新位置；无 gsap /
   reduced-motion 下不注入 glider，.scope-button.active 的背景规则原样兜底。 */
.segmented {
  position: relative;
}

.seg-glider {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  border-radius: 5px;
  background: var(--accent-tint);
  pointer-events: none;
}

.segmented .scope-button {
  position: relative;
  z-index: 1;
}

.segmented.has-glider .scope-button.active {
  background: transparent;
}
