/* 设计令牌:整套主题一处改。
   右侧栏取值来自 Figma《生成器布局规范原型》Properties Sidebar(228:5269):
   面板底 #fcfcfd、卡片白 + 8% 描边 + 双层柔影、字段底 #eeeff1、主色 #292a2d、
   正文 Inter 12、分段/按钮 Inter Medium。 */
:root {
  --bg: #f1f2f4;                 /* 画布区灰底(Figma 画布 #f1f2f4) */
  --panel-bg: #fcfcfd;           /* 右侧栏底 */
  --surface: #ffffff;            /* 卡片白 */
  --surface-2: #f8f9fa;          /* 卡片内衬 / 色块外圈 */
  --field-bg: #eeeff1;           /* 数字输入底 */
  --field-bg-2: #f1f2f4;         /* 下拉底 */
  --seg-bg: rgba(61, 62, 66, .06); /* 分段控件槽底 */
  --line: rgba(61, 62, 66, .08); /* 卡片描边 / 分隔线 */
  --border: #d9dbde;             /* 实色描边(面板左缘、次级按钮) */
  --text: #171719;               /* 标题 */
  --text-2: #1c1c21;             /* 字段标签 */
  --text-3: #3d3e42;             /* 输入值 / 次级按钮文字 */
  --muted: #929499;              /* 未选中 / 辅助 */
  --muted-2: #85878b;            /* 单位后缀 */
  --icon: #848b96;               /* 箭头图标 */
  --accent: #292a2d;             /* 主按钮 / 选中态 / 开关 */
  --accent-soft: #eef0f4;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow-sm: 0 1px 4px rgba(20, 18, 14, .08);
  --shadow-card: 0 4px 12px rgba(11, 11, 13, .06), 0 0 4px rgba(11, 11, 13, .06);
  --shadow-seg: 0 2px 8px rgba(0, 0, 0, .10);
  --shadow-lg: -8px 8px 32px rgba(20, 18, 14, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* —— 挂载容器:官方壳给的工作区 / 独立模式根,都要有确定高度 —— */
generator-workbench { display: block; height: 100vh; }
#standalone-root { height: 100vh; }
/* runtime 根:填满宿主给的容器(壳工作区或独立根)。
   workbench 的 workspace-host 是 flex 容器,不写 flex/width 会收缩到内容宽,
   右侧空出一大块(实测 bug)。 */
#app { display: flex; flex-direction: column; height: 100%; min-height: 480px; width: 100%; flex: 1 1 auto; min-width: 0; font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; }
/* —— 画布悬浮件(Figma 画布规范:四角留白 16,顶栏/底栏 32 高)——
   顶部:左上 切换 tab(分段控件,与侧栏同款)/ 右上 搜索(白底 #d9dbde 描边胶囊,同 Tips 按钮)
   底部:左下 缩放组(32×32 白底 r8 按钮,间距 4)/ 右下 提示文字(白色柔影胶囊) */
.loc-search, .p2d-legend {
  background: var(--surface); border: 1px solid var(--border);
}
.canvas-pill, #status-bar, .p3d-explode {
  background: var(--surface); box-shadow: var(--shadow-card);
}

main { flex: 1; display: flex; min-height: 0; }
#canvas-area { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
.view { flex: 1; min-height: 0; position: relative; }

/* 视图切换:左上角分段控件(Figma Segmented 的尺寸:32 高 r6 内边距 2;项 28 高 r5 Inter Medium 12)。
   设计稿放顶部居中,本生成器右上要放搜索框,故留在左上,只对齐设计语言。
   槛底不用设计稿的 6% 透明灰:选区视图下面是深色地图,透明槛看不见;改用与右上搜索框同款的
   白底 + #d9dbde 描边,选中项主色反白(与下拉选中、图层筛选选中同一套语言)。 */
#view-tabs {
  position: absolute; top: 16px; left: 16px; z-index: 12;
  display: inline-flex; height: 32px; padding: 2px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--border);
}
#view-tabs button {
  height: 26px; padding: 5px 10px; border: none; background: transparent; border-radius: 4px;
  cursor: pointer; font-size: 12px; font-weight: 500; line-height: 16px; color: var(--text-3);
  transition: background .15s, color .15s; white-space: nowrap;
}
#view-tabs button:hover { color: var(--text); background: var(--seg-bg); }
#view-tabs button.active { background: var(--accent); color: #fff; }

/* 状态提示:右下角白色柔影胶囊(空文本自动隐藏) */
#status-bar {
  position: absolute; right: 16px; bottom: 16px; z-index: 12;
  height: 32px; display: flex; align-items: center; padding: 0 12px;
  font-size: 12px; line-height: 16px; color: var(--text-3);
  border-radius: 999px; max-width: 55%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#status-bar:empty { display: none; }

/* 缩放组(Figma Zoom Controls):左下角,32×32 白底 r8 按钮横排,间距 4,图标 #3d3e42;
   百分比按钮 51 宽 Inter 12。选区视图(.loc-zoom)与 2D 视图(.zoom-ctrl)共用 */
.loc-zoom, .zoom-ctrl {
  position: absolute; left: 16px; bottom: 16px; z-index: 12;
  display: flex; align-items: center; gap: 4px;
}
.loc-zoom button, .zoom-ctrl button {
  min-width: 32px; height: 32px; padding: 0; border: none; border-radius: 8px;
  background: var(--surface); color: var(--text-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 16px; transition: background .12s, color .12s;
}
.loc-zoom button svg, .zoom-ctrl button svg { display: block; }
.loc-zoom button:hover:not(:disabled), .zoom-ctrl button:hover { background: #f8f9fa; color: var(--text); }
.loc-zoom button:disabled { opacity: .4; cursor: not-allowed; }
.loc-zoom .lz-lock.active { background: var(--accent); color: #fff; }
.zoom-ctrl button[data-z="pct"] { width: 51px; padding: 0 10px; color: var(--text-3); }
.loc-zoom .lz-sep { width: 1px; height: 20px; margin: 0 2px; background: var(--border); }

/* 常显坐标:相框左下角外侧的一行半透明白字(无底、无框,落在暗化的框外区域上),
   hover 才显出复制图标 */
.loc-coords {
  position: absolute; z-index: 12;
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0;
  color: rgba(255, 255, 255, .72);
  font-size: 11px; line-height: 14px; font-variant-numeric: tabular-nums; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: color .15s;
}
.loc-coords:hover { color: rgba(255, 255, 255, .95); }
.lc-copy {
  display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
  padding: 0; border: none; border-radius: 4px; background: transparent; color: inherit; cursor: pointer;
  opacity: 0; transition: opacity .12s, background .12s;
}
.loc-coords:hover .lc-copy, .lc-copy:focus-visible, .lc-copy.copied { opacity: 1; }
.lc-copy:hover { background: rgba(255, 255, 255, .18); }
.lc-copy.copied { color: #86efac; }

/* —— 画布文字编辑器(选区叠加层内的文字项)—— */
.loc-overlay .loc-texts .txt { pointer-events: auto; cursor: move; }
.txt-hit { fill: transparent; }
.txt-box { fill: none; stroke: var(--accent); stroke-width: 1px; }
.txt-handle { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5px; pointer-events: auto; cursor: nwse-resize; }
.txt-handle[data-handle="ne"], .txt-handle[data-handle="sw"] { cursor: nesw-resize; }
.txt-handle.txt-rot { cursor: grab; }
.txt-rot-line { stroke: var(--accent); stroke-width: 1px; }
.txt-guide { stroke: #ff6500; stroke-width: 1px; stroke-dasharray: 4 3; pointer-events: none; }
/* 双击面板:内容 + 字体 + 删除,悬浮在文字下方 */
.txt-pop {
  position: absolute; z-index: 20; width: 240px; padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-card);
  animation: fadeIn .12s ease-out;
}
.txt-pop .text-input { max-width: none; }
.txt-pop-row { display: flex; align-items: center; gap: 8px; }
.txt-pop-row .dd-trigger { flex: 1; width: auto; min-width: 0; }
.txt-pop-del, .txt-pop-ul { width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; flex: none; }
.txt-pop-del { color: var(--danger); }
.txt-pop-ul { color: var(--text-3); background: var(--field-bg-2); }
.txt-pop-ul.active { background: var(--accent); color: #fff; }

/* 独立模式的本地导出:主按钮(Figma Primary Button:287×32,#292a2d,r6,Inter Medium 14) */
.export-fab {
  position: absolute; right: 16px; bottom: 16px; z-index: 12;
  height: 32px; padding: 6px 12px; border-radius: 6px; border: none;
  background: var(--accent); color: #fff; cursor: pointer; font-size: 14px; font-weight: 500; line-height: 20px;
  transition: transform .1s, opacity .15s;
}
.export-fab:hover { opacity: .9; }
.export-fab:active { transform: scale(.98); }

/* —— 右侧参数面板(Figma Properties Sidebar:320 宽,表头 56 / 内容滚动 / 底块 108)—— */
#panel-area {
  width: 320px; background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
/* 表头:单位切换居左,语言 + Reset 居右;不随内容滚动 */
#panel-head {
  flex: none; height: 56px; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.head-actions { display: flex; align-items: center; gap: 8px; }
#panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; }
#panel-scroll::-webkit-scrollbar { width: 8px; }
#panel-scroll::-webkit-scrollbar-thumb { background: #d5d2cb; border-radius: 4px; }
/* 底块:Buy Materials(37)+ 8 + Export(37)+ 上下留白,给壳的两颗 fixed 按钮腾位 */
#panel-foot {
  flex: none; height: 108px; background: var(--panel-bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
/* 独立模式的本地导出按钮停靠进底块时:占满、不再悬浮 */
#panel-foot .export-fab { position: static; width: 100%; }
/* 壳(generator-workbench)的导出区原本 fixed 在右下角悬浮压住面板内容;
   钉进底块:右缘对齐面板内边距。壳样式在同一 shadow root,需 !important 压过。
   宽/高由耗材购买规范 v2 统一覆盖成 291×37(src/platform/material-purchase.js),
   这里只管位置。类名为壳内部实现,变更时优雅退化回悬浮态。 */
.sidebar-footer-floating {
  right: 16px !important; bottom: 12px !important; left: auto !important;
}
/* basic 档不做模板发布:兜底隐藏壳导出区里的 Publish as Template 入口
   (结构:第一个子节点是 Export 下拉触发器,其后的 tooltip 触发器即 Publish) */
.sidebar-footer-export > .xt_tooltip_trigger { display: none !important; }

/* 次级按钮(表头 Reset):32 高,#d9dbde 描边,r6,Inter Medium 14 */
.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 6px; background: transparent;
  font-size: 14px; font-weight: 500; line-height: 20px; color: var(--text-3); cursor: pointer;
  white-space: nowrap; transition: background .12s;
}
.ghost-btn:hover { background: var(--seg-bg); }
.ghost-btn:active { transform: translateY(1px); }
.ghost-btn svg { flex: none; }

/* 分区卡片:白底 + 8% 描边 + 双层柔影,r8;卡片间距 12 */
.panel-sec {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-card); margin-bottom: 12px; overflow: hidden;
}
.panel-sec:last-child { margin-bottom: 0; }
/* 分区表头 40 高,标题 Inter Medium 12,右侧折叠箭头 */
.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 40px; padding: 8px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.sec-head h3 { margin: 0; font-size: 12px; font-weight: 500; line-height: 16px; color: var(--text); }
.sec-head .chev { color: var(--icon); display: flex; transition: transform .15s; }
.panel-sec.collapsed .sec-head { border-bottom-color: transparent; }
.panel-sec.collapsed .sec-body { display: none; }
.panel-sec.collapsed .chev { transform: rotate(-90deg); }
.chev svg, .dd-caret svg { display: block; }

/* 字段行:标签左(Inter 12 #1c1c21),控件右对齐;上下 8 + 控件高 = 44 / 40 / 48 */
.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 16px; font-size: 12px; line-height: 16px;
}
.field-label {
  display: flex; align-items: center; gap: 5px; white-space: nowrap;
  color: var(--text-2); flex: 0 1 auto;
}
.field-row > :last-child:not(.field-label) { flex: 0 0 auto; display: flex; justify-content: flex-end; }
.field-col { padding: 8px 16px; font-size: 12px; }
.field-col .field-label { display: block; margin-bottom: 6px; }
/* 二级面板里的字段行不带卡片内边距 */
.cmg-modal-body .field-row, .cmg-modal-body .field-col { padding: 6px 0; }

/* 文本输入:与数字输入同款(灰底、无边框、r4、28 高) */
.text-input {
  width: 100%; max-width: 170px; height: 28px; padding: 6px; font-size: 12px; line-height: 16px;
  border: 1px solid transparent; border-radius: 4px; background: var(--field-bg); color: var(--text-3);
  transition: border-color .15s;
}
.text-input:focus { border-color: var(--text-3); outline: none; }
/* 二级面板里的文本输入:填满标签右侧剩余空间,右缘与其他控件对齐。
   字段行控件槛默认 flex:0 0 auto(按内容定宽),input 的 width:100% 会按其
   固有宽度(约 20 字符)撑开、越出面板右缘(实测 bug:面板出现横向滚动)。 */
.cmg-modal-body .field-row > .text-input { flex: 1 1 0; min-width: 0; width: auto; max-width: none; }

/* —— scrub 数字字段(Figma Input Number:92×28,#eeeff1,r4,值 12 / 单位 10)—— */
.scrub {
  display: flex; align-items: center; gap: 4px; width: 92px; height: 28px;
  border: 1px solid transparent; border-radius: 4px; padding: 6px;
  background: var(--field-bg); cursor: ew-resize; user-select: none;
  transition: border-color .15s, background .15s;
}
.scrub:hover, .scrub.dragging { background: #e6e7ea; }
.scrub:focus-within { border-color: var(--text-3); background: var(--field-bg); }
.scrub input {
  flex: 1; min-width: 0; border: none; background: transparent; font-size: 12px; line-height: 16px;
  text-align: left; cursor: inherit; padding: 0; color: var(--text-3);
}
.scrub input:focus { cursor: text; outline: none; }
.scrub-suffix { font-size: 10px; line-height: 14px; color: var(--muted-2); flex: none; }

/* —— 分段选择器(Figma Segmented:槽 6% 灰底 r6 内边距 2;项 28 高 r5,选中白底 + 柔影)—— */
.seg { display: inline-flex; padding: 2px; border-radius: 6px; background: var(--seg-bg); }
.seg-fill { display: flex; width: 100%; }
.seg button {
  flex: 1; height: 28px; padding: 6px 8px; border: none; border-radius: 5px; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 500; line-height: 16px; color: var(--muted); transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.seg button:hover { color: var(--text-3); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-seg); }
.seg-rich button { display: flex; flex-direction: column; align-items: center; gap: 1px; height: auto; padding: 6px 4px; }
.seg-rich button small { font-size: 10px; font-weight: 400; color: var(--muted); }
.seg-rich button.active small { color: var(--muted-2); }
.field-row .seg { max-width: 190px; }

/* —— 自定义下拉(Figma Dropdown:28 高,#f1f2f4,r6;图标 + 文字 + 箭头)—— */
.dd-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  width: 124px; height: 28px; padding: 6px; font-size: 12px; line-height: 16px; cursor: pointer;
  border: 1px solid transparent; border-radius: 6px; background: var(--field-bg-2);
  color: var(--text-3); transition: background .15s, border-color .15s;
}
.dd-trigger:hover { background: #e9eaed; }
.dd-trigger:focus-visible { border-color: var(--text-3); outline: none; }
.dd-val { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dd-val > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-caret { color: var(--icon); flex: none; display: flex; }
.dd-icon { flex: none; color: var(--text-3); }
.dd-menu {
  position: fixed; z-index: 90; padding: 4px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 10px 32px rgba(20, 18, 14, .16);
  max-height: 320px; overflow-y: auto;
  animation: fadeIn .12s ease-out;
}
.dd-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; font-size: 12px; line-height: 16px; text-align: left; cursor: pointer;
  border: none; background: transparent; border-radius: 5px; color: var(--text-3);
  white-space: nowrap; transition: background .12s;
}
.dd-item:hover { background: var(--seg-bg); }
.dd-item.active { background: var(--accent); color: #fff; }
.dd-item.active .dd-icon { color: #fff; }
/* 字体选项:上排真实字形样例,下排中文说明 */
.font-opt { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.font-opt em { font-style: normal; font-size: 17px; }
.font-opt small { font-size: 11px; color: var(--muted); }
.dd-item.active .font-opt small { color: #cbd5e1; }

/* —— 取色器(Figma Color Swatch:24×24,#f8f9fa 外圈 r4.5,色块 18 r1.5)—— */
.swatch {
  width: 24px; height: 24px; border-radius: 4.5px; border: 3px solid var(--surface-2);
  background-clip: padding-box; box-shadow: 0 0 0 1px var(--line);
  cursor: pointer; padding: 0; transition: transform .1s;
}
.swatch:active { transform: scale(.94); }
.color-pop {
  position: fixed; z-index: 80; width: 216px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  box-shadow: var(--shadow-lg);
}
.cp-sv { position: relative; height: 120px; border-radius: 6px; cursor: crosshair; }
.cp-sv-white { position: absolute; inset: 0; border-radius: 6px; background: linear-gradient(to right, #fff, transparent); }
.cp-sv-black { position: absolute; inset: 0; border-radius: 6px; background: linear-gradient(to top, #000, transparent); }
.cp-sv .cp-knob {
  position: absolute; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3); transform: translate(-6px, -6px);
  pointer-events: none;
}
.cp-hue {
  position: relative; height: 12px; border-radius: 6px; margin-top: 10px; cursor: ew-resize;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-hue .cp-knob {
  position: absolute; top: -2px; width: 14px; height: 16px; border-radius: 5px;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3); transform: translateX(-7px);
  pointer-events: none; background: transparent;
}
.cp-row { display: flex; gap: 8px; margin-top: 10px; }
.cp-hex {
  flex: 1; min-width: 0; height: 28px; padding: 6px; font-size: 12px; font-family: ui-monospace, monospace;
  border: 1px solid transparent; border-radius: 4px; background: var(--field-bg); color: var(--text-3);
}
.cp-hex:focus { border-color: var(--text-3); outline: none; }
.cp-preview { width: 34px; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); }
.cp-presets { display: flex; gap: 5px; margin-top: 10px; }
.cp-presets button {
  flex: 1; aspect-ratio: 1; border-radius: 4px; border: none; box-shadow: 0 0 0 1px var(--line);
  cursor: pointer; padding: 0; transition: transform .1s;
}
.cp-presets button:hover { transform: scale(1.12); }

/* —— "?" 悬浮说明 —— */
.help-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; font-size: 10px;
  border: 1px solid var(--border); color: var(--muted); cursor: help; flex: none;
  transition: background .15s, color .15s;
}
.help-tip:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.help-bubble {
  position: fixed; z-index: 90; width: max-content; max-width: 224px;
  background: #24272e; color: #e8e9ec; font-size: 11.5px; line-height: 1.5;
  padding: 7px 10px; border-radius: 6px; box-shadow: var(--shadow-lg);
  pointer-events: none; animation: fadeIn .12s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; } }

/* —— 表面材质卡片:提示条 + 4 列色块(色块图来自 CDN;选中 = 2px 深描边 + 2px 白色间隙)—— */
.surface-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.surface-hint {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px;
  background: #eef4fe; border-radius: 8px; font-size: 12px; line-height: 1.5; color: var(--text-2);
}
.surface-hint svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
/* minmax(0,1fr) 必须保留:否则内容 min-width 会把列撑爆、网格向右溢出 */
.surface-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.surface-swatch {
  width: 100%; aspect-ratio: 1; padding: 0; border: 1px solid var(--line); border-radius: 8px;
  background-color: var(--field-bg-2); background-size: cover; background-position: center; background-origin: border-box;
  cursor: pointer; transition: border-color .15s;
}
.surface-swatch:hover { border-color: var(--border); }
.surface-swatch.active { border: 2px solid var(--text); padding: 2px; background-origin: content-box; background-clip: content-box; }

/* —— 图层卡片(分区卡片内的次级卡片:灰底表头 + 白底要素区,r6)—— */
.layers-list { position: relative; padding: 8px 16px 12px; }
/* 拖拽换序:把手 / 拖动中的卡片 / 插入线 / 违规提示 */
.layer-grip { display: inline-flex; align-items: center; color: var(--icon); cursor: grab; padding: 4px 2px; margin: -4px 0 -4px -4px; touch-action: none; }
.layer-grip:hover { color: var(--text-3); }
.layer-card.dragging { opacity: .45; }
.layer-card.reject { animation: shake .3s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.layer-drop-line { position: absolute; left: 16px; right: 16px; height: 2px; border-radius: 1px; background: var(--accent); pointer-events: none; z-index: 2; }
.layer-drop-line.invalid { background: var(--danger); }
.layer-hint { font-size: 11px; line-height: 14px; color: var(--danger); margin: 6px 2px 0; }
.layer-card {
  border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px;
  background: var(--field-bg-2); overflow: hidden; transition: box-shadow .15s;
}
.layer-card:hover { box-shadow: var(--shadow-sm); }
.layer-card.layer-hidden { opacity: .55; }
.layer-head { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; cursor: pointer; list-style: none; }
/* 展开时:标题与要素列表之间一条细分隔线,层次更清晰 */
details[open] > .layer-head { border-bottom: 1px solid var(--line); }
details[open] .layer-feats { padding-top: 6px; }
.layer-head::-webkit-details-marker { display: none; }
.layer-head::before {
  content: ''; width: 5px; height: 5px; flex: none; margin-left: 1px;
  border-right: 1.5px solid var(--icon); border-bottom: 1.5px solid var(--icon);
  transform: rotate(-45deg); transition: transform .15s;
}
details[open] > .layer-head::before { transform: rotate(45deg); }
.layer-name { font-size: 12px; font-weight: 500; color: var(--text); }
.mode-badge {
  font-size: 10px; line-height: 14px; padding: 1px 6px; border-radius: 4px;
  background: var(--seg-bg); color: var(--muted-2);
}
.mode-badge.mode-score { box-shadow: inset 0 0 0 1px var(--border); background: transparent; }
.mode-badge.mode-engrave { background: #f4ede2; }
.mode-badge.mode-solid { background: #e8f0f8; }
.layer-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.layer-head:hover .layer-actions { opacity: 1; }
.icon-btn {
  border: none; background: transparent; padding: 3px 5px; border-radius: 4px;
  cursor: pointer; color: var(--text-3); line-height: 0; transition: background .12s;
}
.icon-btn:hover { background: var(--seg-bg); }
/* 要素区:比标题栏更浅的白底,分隔线上下两个区域一眼可辨 */
.layer-feats { padding: 2px 8px 6px 20px; background: var(--surface); }
.feat-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-size: 12px; line-height: 16px;
  color: var(--text-2); border-radius: 4px; transition: background .12s;
}
.feat-row:hover { background: var(--surface-2); }
.feat-swatch { width: 14px; height: 14px; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); flex: none; }
.feat-label { flex: 1; }
.feat-row .feat-edit { opacity: 0; }
.feat-row:hover .feat-edit { opacity: 1; }
.layer-add {
  font-size: 12px; font-weight: 500; line-height: 16px; height: 32px; padding: 6px 12px; border-radius: 6px; width: 100%;
  border: 1px dashed var(--border); background: transparent; cursor: pointer; color: var(--muted);
  transition: border-color .15s, color .15s, background .12s;
}
.layer-add:hover:not(:disabled) { border-color: var(--text-3); color: var(--text-3); background: var(--surface-2); }

/* —— 二级面板(停靠在参数栏左侧)—— */
.cmg-panel {
  position: fixed; width: 300px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); z-index: 60;
  animation: fadeIn .14s ease-out;
}
.cmg-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 500;
}
/* ✕ 是文本字形,不能吃 .icon-btn 的 line-height:0(会被压成一团) */
.cmg-close {
  width: 24px; height: 24px; padding: 0; line-height: 1; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 4px;
}
.cmg-modal-body { padding: 8px 16px; overflow-y: auto; }
.cmg-modal-body::-webkit-scrollbar { width: 8px; }
.cmg-modal-body::-webkit-scrollbar-thumb { background: #d5d2cb; border-radius: 4px; }
.cmg-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
/* 按钮(Figma Button:32 高,r6,Inter Medium 14;主色 #292a2d,次级 #d9dbde 描边) */
.cmg-btn {
  height: 32px; font-size: 14px; font-weight: 500; line-height: 20px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-3); cursor: pointer;
  transition: transform .1s, opacity .15s, background .12s;
}
.cmg-btn:hover:not(:disabled) { background: var(--surface-2); }
.cmg-btn:active:not(:disabled) { transform: translateY(1px); }
.cmg-btn.cmg-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.cmg-btn.cmg-primary:hover:not(:disabled) { background: #3d3e42; }
.cmg-btn.cmg-danger { color: var(--danger); border-color: #e5c3c3; margin-top: 10px; }
.cmg-hint { font-size: 12px; color: var(--muted); margin: 4px 0 8px; line-height: 1.5; }
.cls-title { font-size: 12px; color: var(--text); margin: 12px 0 6px; font-weight: 500; display: flex; align-items: center; justify-content: space-between; }
.cls-toggle { display: flex; align-items: center; gap: 5px; font-weight: 400; color: var(--text-2); cursor: pointer; }
.cls-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.cls-list label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.cls-list input, .cls-toggle input { accent-color: var(--accent); }

/* —— 选区视图 —— */
/* 搜索:画布右上角悬浮胶囊(图标 + 输入,回车提交) */
.loc-search {
  position: absolute; top: 16px; right: 16px; z-index: 12;
  display: flex; align-items: center; gap: 6px;
  width: 232px; height: 32px; padding: 0 12px 0 10px; border-radius: 999px;
  color: var(--text-3); transition: width .18s ease, border-color .15s;
}
.loc-search:focus-within { width: 280px; color: var(--text); border-color: var(--text-3); }
.loc-search svg { flex: none; }
.loc-search input {
  flex: 1; min-width: 0; border: none; background: transparent;
  font-size: 12px; line-height: 16px; color: var(--text); padding: 0;
}
.loc-search input:focus { outline: none; }
.loc-search input::placeholder { color: var(--muted); }
/* 搜索框内右侧的定位按钮:定位中转圈,失败短暂变红 */
.loc-locate {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-right: -4px; padding: 0; border: none; border-radius: 6px;
  background: transparent; color: var(--icon); cursor: pointer; transition: background .12s, color .12s;
}
.loc-locate:hover:not(:disabled) { background: var(--seg-bg); color: var(--text); }
.loc-locate:disabled { opacity: .35; cursor: not-allowed; }
.loc-locate.is-busy svg { animation: spin .9s linear infinite; }
.loc-locate.is-error { color: var(--danger); }
/* 结果下拉:悬浮在搜索胶囊下方,右对齐 */
.loc-results {
  position: absolute; top: 54px; right: 16px; z-index: 12; width: 300px;
  list-style: none; margin: 0; padding: 5px; border: 1px solid var(--line);
  border-radius: 8px; max-height: 240px; overflow-y: auto; background: var(--surface);
  box-shadow: 0 10px 32px rgba(20, 18, 14, .18);
  animation: fadeIn .12s ease-out;
}
.loc-results li { padding: 8px 10px; cursor: pointer; font-size: 13px; border-radius: 6px; }
.loc-results li:hover { background: var(--seg-bg); }
/* 地图加载态:居中卡片(雷达扫描圈 + 跳动的定位针 + 轮换文案),地图轻微蒙灰,不拦截交互 */
.loc-loading {
  position: absolute; inset: 0; z-index: 13; display: flex; align-items: center; justify-content: center;
  background: rgba(241, 242, 244, .35); pointer-events: none; animation: fadeIn .15s ease-out;
}
.loc-loading[hidden] { display: none; }
.loc-loading-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 200px; padding: 18px 22px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-card);
}
.loc-radar { position: relative; width: 64px; height: 64px; border-radius: 50%; border: 1.5px dashed var(--border); margin-bottom: 4px; }
.loc-radar::before { content: ''; position: absolute; inset: 10px; border-radius: 50%; border: 1px solid var(--line); }
.loc-sweep {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(249, 115, 22, 0) 0 62%, rgba(249, 115, 22, .45) 100%);
  animation: spin 1.4s linear infinite;
}
.loc-pin {
  position: absolute; left: 50%; top: 50%; color: #f97316; display: flex; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .18));
  animation: pin-bounce 1s ease-in-out infinite;
}
@keyframes pin-bounce { 0%, 100% { transform: translate(-50%, -64%); } 50% { transform: translate(-50%, -84%); } }
.loc-loading-title { font-size: 13px; font-weight: 600; line-height: 16px; color: var(--text); }
.loc-loading-sub { font-size: 11.5px; line-height: 14px; color: var(--muted); min-height: 14px; }
@media (prefers-reduced-motion: reduce) { .loc-sweep, .loc-pin { animation: none; } }

/* id+类特异性:压过 maptiler-sdk.css 的 .maplibregl-map{position:relative}(它后加载) */
#view-select .loc-map { position: absolute; inset: 0; }
.loc-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 1; width: 100%; height: 100%; }


/* —— 2D / 3D 预览(全幅画布 + 悬浮件)—— */
/* 2D 分层 = 导出排版预览:每件垫白色板材 + 图层名;导出里的 0.1mm 发丝线在屏幕上按恒定像素宽显示
   (CSS 优先级高于 path 上的 stroke-width 表现属性),缩放到任何比例都看得见 */
.p2d-sheet { fill: var(--surface); stroke: var(--border); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.p2d-label { fill: var(--muted-2); font-family: Inter, -apple-system, sans-serif; font-weight: 500; }
.p2d-stage path[stroke] { vector-effect: non-scaling-stroke; stroke-width: 1.25px; }
/* 舞台全幅:留白由视野矩形(fit 8%)负责;拖拽平移时抓手光标 */
.p2d-stage { position: absolute; inset: 0; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
.p2d-stage.panning { cursor: grabbing; }
.p2d-stage svg { width: 100%; height: 100%; display: block; }
.p2d-warn {
  position: absolute; bottom: 56px; right: 16px; left: auto; z-index: 11;
  font-size: 12px; color: #b45309; max-width: 45%; text-align: right;
}
/* 加工模式图例:2D 右上角玻璃胶囊(红=切割 蓝=雕刻) */
.p2d-legend {
  position: absolute; top: 16px; right: 16px; z-index: 11;
  display: flex; align-items: center; gap: 14px; height: 32px;
  padding: 0 14px; border-radius: 999px; font-size: 12px; line-height: 16px; color: var(--text-3);
}
.lg-item { display: flex; align-items: center; gap: 6px; }
.lg-item em { font-style: normal; }
.lg-swatch { width: 16px; border-top: 2.5px solid; border-radius: 2px; }
.lg-cut { border-color: #ff0000; }
.lg-engrave { border-color: #0000ff; }

/* user-select:none:拖拽旋转/平移不能触发文本选中(否则松手弹系统取词工具栏) */
.p3d-stage { position: absolute; inset: 0; user-select: none; -webkit-user-select: none; touch-action: none; }
.p3d-stage canvas { width: 100%; height: 100%; display: block; }
/* 炸开:底部居中悬浮胶囊 */
.p3d-explode {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 12;
  display: flex; align-items: center; gap: 10px; height: 32px;
  padding: 0 14px; border-radius: 999px; font-size: 12px; line-height: 16px; color: var(--text-3);
}
.p3d-explode input[type=range] { width: 140px; accent-color: var(--accent); }

/* —— 计算中加载态(覆盖 2D/3D 视图)—— */
.view-loading {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(241, 242, 244, .55); backdrop-filter: blur(2px);
  font-size: 13px; color: var(--muted);
  animation: fadeIn .15s ease-out;
}
/* display:flex 会盖过 UA 样式表的 [hidden]{display:none},必须显式补回 */
.view-loading[hidden] { display: none; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid #d5d2cb; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
