/* ═══════════════════════════════════════════════════════════
   ZMD COVER LAB — 终末地视觉语言
   烟灰操作面 + 系统黄行动色 · 语义色角色化 · 切角/角括号/技术微标
   ═══════════════════════════════════════════════════════════ */

:root {
  /* 中性材质层级 */
  --surface-smoke: #141517;
  --surface-panel: #1c1e20;
  --surface-raised: #24262a;
  --surface-overlay: #2c2f33;
  --surface-paper: #f2f1ec;
  --line: #34373c;
  --line-soft: #292c30;

  /* 文字 */
  --text-primary: #edece6;
  --text-secondary: #a9aba5;
  --text-muted: #71746f;
  --text-on-action: #1a1a14;

  /* 语义角色（遵循 Endfield Design 权威角色表） */
  --action: #f8d34d;        /* 黄：行动 / 选中 / 导航 / 进度填充 */
  --action-deep: #e3bc2f;
  --selected: #fffa00;
  --notify: #ff7d1a;        /* 橙：数量 / 第二强调 */
  --gain: #d8f21d;          /* 荧光黄绿：增益 / 新数值 */
  --data: #4db5e8;          /* 蓝：尺寸 / 坐标等量值读数 */
  --region: #06a2a2;        /* 青：地区 / 机构主题 */
  --special: #8a5cf6;       /* 紫：特殊 / 角色主题 */
  --danger: #e5484d;        /* 红：删除 / 错误 / 警示 */
  --success: #13cf70;       /* 绿：确认 / 成功 */
  --info: #4db5e8;

  /* 控件 */
  --radius-control: 4px;
  --radius-chip: 999px;
  --font-ui: "Noto Sans SC", -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-micro: "Cascadia Code", Consolas, "Noto Sans SC", -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;

  --topbar-h: 58px;
  --rail-w: 344px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-smoke);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

/* ── 应用骨架 ─────────────────────────────── */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
}

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  min-height: 0;
}

/* ── 顶栏 ─────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--surface-panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--action) 0 96px, transparent 96px);
  pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; color: var(--action); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong {
  font-size: 14px;
  letter-spacing: .06em;
  font-weight: 800;
  white-space: nowrap;
}
.brand-text span {
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .04em;
  white-space: nowrap;
}

/* 协议工作台切换轨（角形导航 + 明暗反转） */
.suite-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-smoke);
  border: 1px solid var(--line);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%);
}
.suite-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.suite-tab .suite-idx {
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.suite-tab:hover:not(.is-active) { color: var(--text-primary); background: var(--surface-raised); }
.suite-tab.is-active {
  background: var(--surface-paper);
  color: var(--text-on-action);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%);
}
.suite-tab.is-active .suite-idx {
  color: var(--text-on-action);
  background: var(--action);
  padding: 0 4px;
  font-weight: 800;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}
.meta-size {
  font-family: var(--font-micro);
  font-size: 12px;
  color: var(--data);
  background: color-mix(in srgb, var(--data) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--data) 28%, transparent);
  padding: 3px 9px;
  border-radius: var(--radius-chip);
  white-space: nowrap;
}
.meta-ratio {
  font-family: var(--font-micro);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 图标按钮 */
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--text-secondary);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-overlay); color: var(--text-primary); border-color: #41454b; }
.icon-btn:active:not(:disabled) { transform: translateY(1px); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn svg { width: 17px; height: 17px; }

/* 主行动：纸白胶囊 + 圆形图标章（工作室面的主行动形；黄色留给选中与进度） */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 4px 20px 4px 5px;
  border: none;
  border-radius: var(--radius-chip);
  background: var(--surface-paper);
  color: var(--text-on-action);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
  min-height: 38px;
  transition: background .15s, transform .12s;
}
.btn-primary svg {
  width: 30px; height: 30px;
  padding: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--text-on-action);
  color: var(--action);
  transition: background .15s, color .15s;
}
.btn-primary:hover { background: #fff; }
.btn-primary:hover svg { background: var(--action); color: var(--text-on-action); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary.btn-block { width: 100%; }

/* 次行动：深色胶囊 */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  min-height: 36px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-chip);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--surface-overlay); border-color: #45494f; }
.btn-secondary svg { width: 15px; height: 15px; color: var(--text-secondary); }
.btn-secondary.btn-block { width: 100%; }

/* 危险行动 */
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  min-height: 36px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: var(--radius-chip);
  color: #ff8b8f;
  font-size: 12.5px;
  font-weight: 600;
  transition: background .15s;
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.btn-danger svg { width: 15px; height: 15px; }

/* 整宽块状按钮（添加文字 / 上传） */
.btn-block {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 40px;
  background: var(--surface-raised);
  border: 1px dashed #45494f;
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .03em;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-block:hover { background: var(--surface-overlay); border-color: var(--action); color: var(--action); }
.btn-block svg { width: 16px; height: 16px; }
.btn-block.btn-primary {
  border: none;
  border-radius: var(--radius-chip);
  background: var(--surface-paper);
  color: var(--text-on-action);
  padding: 4px 20px 4px 5px;
}
.btn-block.btn-primary:hover { background: #fff; color: var(--text-on-action); }
.btn-block.btn-primary svg { width: 30px; height: 30px; }

.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--data);
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 2px 4px;
}
.text-btn:hover { color: #86cbf0; }
.text-btn svg { width: 13px; height: 13px; }

.mini-btn {
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  color: var(--text-muted);
  transition: color .15s, background .15s;
  flex: none;
}
.mini-btn:hover:not(:disabled) { color: var(--text-primary); background: var(--surface-overlay); }
.mini-btn.danger:hover:not(:disabled) { color: #ff8b8f; background: color-mix(in srgb, var(--danger) 15%, transparent); }
.mini-btn:disabled { opacity: .3; cursor: not-allowed; }
.mini-btn svg { width: 13px; height: 13px; }

/* ── 工作区 ───────────────────────────────── */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 14px 18px 10px;
  gap: 10px;
  position: relative;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background:
    radial-gradient(ellipse 90% 80% at 50% 40%, transparent 40%, rgba(0,0,0,.35) 100%),
    var(--surface-smoke);
  overflow: hidden;
}

/* 工作区低对比网格纹理（唯一背景纹理系统） */
.stage-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.028) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(ellipse 75% 75% at 50% 50%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 75% 75% at 50% 50%, #000 30%, transparent 100%);
}

/* 舞台左上的面包屑：当前文稿基于哪套模板 */
.stage-tag {
  position: absolute;
  top: 10px; left: 12px;
  z-index: 3;
  pointer-events: none;
  font-family: var(--font-micro);
  font-size: 10.5px;
  letter-spacing: .05em;
  color: var(--text-muted);
}

/* 舞台右上的参考辅助开关（胶囊形紧凑状态控件） */
.stage-hud {
  position: absolute;
  top: 8px; right: 10px;
  z-index: 4;
  display: flex;
  gap: 6px;
}
.hud-pill {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  padding: 3px 10px;
  border-radius: var(--radius-chip);
  background: rgba(28, 30, 32, .82);
  border: 1px solid var(--line);
  color: var(--text-secondary);
  backdrop-filter: blur(4px);
  transition: background .15s, color .15s, border-color .15s;
}
.hud-pill:hover { color: var(--text-primary); border-color: #4d5157; }
.hud-pill[aria-pressed="true"] {
  background: var(--action);
  border-color: var(--action);
  color: var(--text-on-action);
  font-weight: 800;
}

.canvas-holder { position: relative; padding: 22px; max-width: 100%; max-height: 100%; }

/* 裁切标记 */
.crop-marks { position: absolute; inset: 8px; pointer-events: none; }
.cm { position: absolute; width: 14px; height: 14px; }
.cm::before, .cm::after { content: ""; position: absolute; background: var(--text-muted); opacity: .55; }
.cm::before { width: 14px; height: 1px; }
.cm::after { width: 1px; height: 14px; }
.cm-tl { top: 0; left: 0; }
.cm-tr { top: 0; right: 0; transform: scaleX(-1); }
.cm-bl { bottom: 0; left: 0; transform: scaleY(-1); }
.cm-br { bottom: 0; right: 0; transform: scale(-1); }

.canvas-frame {
  position: relative;
  box-shadow: 0 12px 44px rgba(0,0,0,.55), 0 0 0 1px var(--line);
  background: #000;
  line-height: 0;
}
.canvas-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#art { z-index: 1; }
#overlay { z-index: 2; touch-action: none; cursor: default; }
#overlay:focus-visible { outline: 2px solid var(--action); outline-offset: 3px; }

/* 拖入遮罩 */
.drop-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20,21,23,.82);
  backdrop-filter: blur(2px);
}
.stage.drag-over .drop-veil { display: flex; }
.drop-veil-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 30px;
  border: 2px dashed var(--action);
  color: var(--action);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .05em;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%);
  background: color-mix(in srgb, var(--action) 8%, transparent);
}
.drop-veil-box svg { width: 22px; height: 22px; }

/* ── 预制模板停靠带 ───────────────────────── */
.tpl-dock { flex: none; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tpl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 30px; }
.tpl-head .sec-title { font-size: 13px; }
.tpl-cats {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}
.cat-pill {
  padding: 3px 10px;
  border-radius: var(--radius-chip);
  border: 1px solid var(--line);
  background: var(--surface-panel);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.cat-pill:hover { color: var(--text-primary); border-color: #4a4e54; }
.cat-pill[aria-pressed="true"] {
  background: var(--surface-paper);
  border-color: var(--surface-paper);
  color: var(--text-on-action);
  font-weight: 800;
}
.tpl-note { font-size: 11px; color: var(--text-muted); margin-left: 2px; }
.theme-line { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.theme-line .field-label { margin-bottom: 0; white-space: nowrap; }
.theme-line .swatches { flex-wrap: nowrap; }
.theme-line .color-input { width: 32px; height: 24px; }
.tpl-pager { display: inline-flex; gap: 3px; margin-left: 2px; }
.pager-btn {
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #101113;
  border: 1px solid var(--line);
  color: var(--text-secondary);
  font-family: var(--font-micro);
  font-size: 14px;
  line-height: 1;
  transition: color .15s, border-color .15s, background .15s;
}
.pager-btn:hover { color: var(--action); border-color: var(--action); background: var(--surface-raised); }

.tpl-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 4px 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: #3d4147 transparent;
}
.tpl-card {
  flex: none;
  width: 172px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding: 0;
  text-align: left;
  background: var(--surface-panel);
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--card-accent, var(--line));
  border-radius: 0;
  color: var(--text-primary);
  position: relative;
  scroll-snap-align: start;
  transition: border-color .15s, transform .12s, background .15s;
}
.tpl-card canvas { display: block; width: 100%; aspect-ratio: 900 / 383; background: var(--surface-smoke); }
.tpl-meta { display: flex; align-items: baseline; gap: 7px; padding: 6px 8px 0; min-width: 0; }
.tpl-idx { font-family: var(--font-micro); font-size: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tpl-name { font-size: 12.5px; font-weight: 800; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-tag { padding: 0 8px 7px; font-size: 10.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-card:hover { border-color: #4d5157; border-bottom-color: var(--card-accent, var(--action)); background: var(--surface-raised); }
.tpl-card:active { transform: translateY(1px); }
/* 当前模板：说明区明暗反转 + 四角括号 */
.tpl-card[aria-pressed="true"] { background: var(--surface-paper); border-color: var(--surface-paper); border-bottom-color: var(--card-accent, var(--action)); color: var(--text-on-action); }
.tpl-card[aria-pressed="true"] .tpl-idx,
.tpl-card[aria-pressed="true"] .tpl-tag { color: #5a5c57; }
.tpl-card[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: -4px;
  pointer-events: none;
  --b: 2px; --len: 10px; --c: var(--selected);
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 0 0 / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--b) var(--len);
  background-repeat: no-repeat;
}

.canvas-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
  min-height: 24px;
}
.canvas-meta .meta-item {
  font-family: var(--font-micro);
  font-size: 11.5px;
  color: var(--text-secondary);
}
.canvas-meta .meta-size { color: var(--data); background: none; border: none; padding: 0; font-size: 11.5px; }
.meta-sep { color: var(--text-muted); font-size: 11px; }
.demo-chip {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--notify);
  background: color-mix(in srgb, var(--notify) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--notify) 35%, transparent);
  padding: 2px 9px;
  border-radius: var(--radius-chip);
  white-space: nowrap;
}
.demo-chip[hidden] { display: none; }

.hint-bar {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: .01em;
}
.hint-bar kbd {
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 5px;
  margin: 0 1px;
}

/* ── 属性轨 ───────────────────────────────── */
.rail {
  background: var(--surface-panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #3d4147 var(--surface-panel);
}
.rail::-webkit-scrollbar { width: 10px; }
.rail::-webkit-scrollbar-track { background: var(--surface-panel); border-left: 1px solid var(--line-soft); }
.rail::-webkit-scrollbar-thumb {
  background: #3d4147;
  border: 2px solid var(--surface-panel);
  border-radius: 5px;
}
.rail::-webkit-scrollbar-thumb:hover { background: var(--action-deep); }

/* 区段 */
.sec { border-bottom: 1px solid var(--line-soft); }
.sec summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--surface-panel);
  z-index: 3;
  transition: background .15s;
}
.sec summary::-webkit-details-marker { display: none; }
.sec summary:hover { background: var(--surface-raised); }
.sec summary:focus-visible { outline: 2px solid var(--action); outline-offset: -2px; }
.sec-bar { width: 3px; height: 14px; background: var(--action); flex: none; }
.sec-title { font-size: 13px; font-weight: 800; letter-spacing: .06em; }
.sec-code {
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .05em;
}
.sec-count {
  font-family: var(--font-micro);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--notify);
  background: color-mix(in srgb, var(--notify) 14%, transparent);
  border-radius: var(--radius-chip);
  padding: 1px 8px;
  font-variant-numeric: tabular-nums;
}
.sec-chevron { margin-left: auto; color: var(--text-muted); display: inline-flex; transition: transform .18s; }
.sec-chevron svg { width: 14px; height: 14px; }
.sec[open] > summary .sec-chevron { transform: rotate(180deg); }
.sec-body { padding: 4px 14px 16px; }

/* 字段 */
.field { margin-top: 12px; min-width: 0; }
.field-row { display: flex; gap: 10px; margin-top: 12px; }
.field-row .field { margin-top: 0; }
.field.grow { flex: 1; }
.field.field-narrow { width: 108px; flex: none; }
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  margin-bottom: 5px;
}

.select, .text-input, .num-input, .textarea {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-size: 12.5px;
  padding: 8px 10px;
  min-height: 36px;
  transition: border-color .15s;
}
.select:hover, .text-input:hover, .num-input:hover, .textarea:hover { border-color: #45494f; }
.select:focus, .text-input:focus, .num-input:focus, .textarea:focus {
  border-color: var(--action);
  outline: none;
  box-shadow: 0 0 0 1px var(--action);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a9aba5' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
.select option { background: var(--surface-overlay); color: var(--text-primary); }
.textarea { resize: vertical; min-height: 56px; line-height: 1.55; }
.num-input { font-variant-numeric: tabular-nums; font-family: var(--font-micro); }

/* 滑杆：灰轨 + 黄填充进度条（遵循 SKILL.md 进度完成度填充规范） */
.range-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 5px; }
.range-head .field-label { margin-bottom: 0; }
.range-val {
  font-family: var(--font-micro);
  font-size: 11px;
  color: var(--data);
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  display: block;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  background: linear-gradient(90deg, var(--action) 0 var(--pct, 50%), var(--surface-overlay) var(--pct, 50%) 100%);
  border-radius: 2px;
  border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5.5px;
  background: var(--surface-paper);
  border: 2px solid var(--text-on-action);
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,.55);
  transition: transform .12s, background .12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); background: var(--action); }
input[type="range"]::-moz-range-track {
  height: 5px;
  background: linear-gradient(90deg, var(--action) 0 var(--pct, 50%), var(--surface-overlay) var(--pct, 50%) 100%);
  border-radius: 2px;
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  background: var(--surface-paper);
  border: 2px solid var(--text-on-action);
  border-radius: 2px;
}
input[type="range"]:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; border-radius: 4px; }

.range-inline { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.range-inline input[type="range"] { flex: 1; }
.range-inline .range-val { flex: none; min-width: 42px; text-align: right; }

/* 颜色 */
.color-line { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.color-input {
  -webkit-appearance: none;
  appearance: none;
  width: 38px; height: 30px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-raised);
  padding: 3px;
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-input::-moz-color-swatch { border: none; border-radius: 2px; }
.micro-note { font-size: 11px; color: var(--text-muted); min-width: 0; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 22px; height: 22px;
  border-radius: var(--radius-control);
  border: 1px solid rgba(255,255,255,.18);
  background: var(--sw);
  transition: transform .12s;
  position: relative;
}
.swatch:hover { transform: scale(1.14); }
.swatch.active::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1.5px solid var(--action);
  border-radius: 6px;
}

/* 对齐分段控件与画布快捷定位 */
.align-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip-action {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-chip);
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chip-action:hover { background: var(--surface-overlay); color: var(--action); border-color: var(--action-deep); }
.chip-action:active { transform: translateY(1px); }

/* 内置程序底图快选胶囊 */
.builtin-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.builtin-pill {
  padding: 6px 6px;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .15s, color .15s, border-color .15s;
}
.builtin-pill:hover { background: var(--surface-overlay); color: var(--text-primary); border-color: #494d53; }
.builtin-pill.is-active {
  background: color-mix(in srgb, var(--action) 14%, var(--surface-raised));
  border-color: var(--action);
  color: var(--action);
  font-weight: 800;
}

.seg-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  overflow: hidden;
  background: var(--surface-raised);
}
.seg-btn {
  width: 44px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-right: 1px solid var(--line);
  color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--surface-overlay); color: var(--text-primary); }
.seg-btn[aria-pressed="true"] { background: var(--action); color: var(--text-on-action); }
.seg-btn svg { width: 15px; height: 15px; }
.seg-wide { width: auto; padding: 0 14px; font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.seg-typeface { margin-left: 2px; }
.seg-group:focus-within { outline: 2px solid var(--action); outline-offset: 2px; }
.seg-btn:focus-visible { outline: none; }

/* 复选开关：方形机械感 */
.sub-block { margin-top: 12px; }
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 4px 0;
  min-height: 30px;
  user-select: none;
}
.check-line input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-box {
  width: 16px; height: 16px;
  flex: none;
  border: 1.5px solid #4d5157;
  border-radius: 3px;
  background: var(--surface-raised);
  position: relative;
  transition: background .15s, border-color .15s;
}
.check-line:hover .check-box { border-color: var(--action); }
.check-line input:checked + .check-box {
  background: var(--action);
  border-color: var(--action);
}
.check-line input:checked + .check-box::after {
  content: "";
  position: absolute;
  left: 4.5px; top: 1.5px;
  width: 4px; height: 8px;
  border: solid var(--text-on-action);
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}
.check-line input:focus-visible + .check-box { outline: 2px solid var(--action); outline-offset: 2px; }
.check-hint { font-size: 10.5px; font-weight: 400; color: var(--text-muted); margin-left: 2px; }
.sub-controls {
  margin: 6px 0 2px 24px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}
.sub-controls[hidden] { display: none; }
.sub-controls .field:first-child { margin-top: 2px; }

/* 图层列表 */
.layer-list { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  min-height: 40px;
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-control);
  cursor: pointer;
  position: relative;
  transition: background .15s, border-color .15s;
}
.layer-row:hover { background: var(--surface-overlay); }
.layer-row.selected {
  background: color-mix(in srgb, var(--action) 9%, var(--surface-raised));
  border-color: color-mix(in srgb, var(--action) 35%, transparent);
}
/* 选中态：左侧脊条 + 角括号（黄） */
.layer-row.selected::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--action);
  border-radius: 2px 0 0 2px;
}
.layer-row.selected::after {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  --b: 1.5px; --len: 8px; --c: var(--selected);
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 0 0 / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--b) var(--len),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--len) var(--b),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--b) var(--len);
  background-repeat: no-repeat;
}
.layer-row.hidden-layer { opacity: .5; }
.layer-type {
  font-family: var(--font-micro);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-on-action);
  background: var(--text-secondary);
  border-radius: 3px;
  padding: 1px 5px;
  flex: none;
}
.layer-row.selected .layer-type { background: var(--action); }
.layer-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layer-tools { display: flex; gap: 1px; flex: none; }
.layer-tools .mini-btn { width: 22px; height: 22px; }

.empty-note {
  margin-top: 10px;
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius-control);
  line-height: 1.6;
}

.img-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  min-height: 26px;
}
.img-name {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.export-readout {
  margin-top: 12px;
  font-family: var(--font-micro);
  font-size: 11.5px;
  color: var(--data);
  font-variant-numeric: tabular-nums;
}
#btn-export { margin-top: 10px; }
#btn-copy { margin-top: 8px; }

.rail-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .04em;
}

/* ── Toast ────────────────────────────────── */
.toasts {
  position: fixed;
  left: 30px;
  top: calc(var(--topbar-h) + 48px);   /* 舞台左上：不遮挡底部的模板停靠带 */
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  background: var(--surface-overlay);
  border: 1px solid var(--line);
  border-left: 3px solid var(--info);
  border-radius: var(--radius-control);
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  font-size: 12.5px;
  color: var(--text-primary);
  animation: toast-in .22s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--notify); }
.toast svg { width: 15px; height: 15px; flex: none; }
.toast.success svg { color: var(--success); }
.toast.error svg { color: var(--danger); }
.toast.warn svg { color: var(--notify); }
.toast.info svg { color: var(--info); }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-action {
  flex: none;
  background: none;
  border: none;
  color: var(--action);
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 2px 4px;
}
.toast.leaving { animation: toast-out .18s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ── 响应式 ───────────────────────────────── */
@media (max-width: 1260px) {
  :root { --rail-w: 312px; }
  .topbar-meta { display: none; }
  .tpl-note { display: none; }
}

@media (max-width: 960px) {
  .suite-tab .suite-idx { display: none; }
  .suite-tab { padding: 5px 9px; font-size: 11.5px; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; grid-template-rows: auto auto; }
  .main { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
    position: sticky;
    top: 0;
  }
  .topbar-actions { margin-left: auto; }
  .brand-text strong { font-size: 13px; }
  .workspace { padding: 12px 12px 8px; }
  .stage { min-height: 240px; height: 44vh; flex: none; }
  .rail { border-left: none; border-top: 1px solid var(--line); overflow: visible; }
  .sec summary { position: static; }
  .hint-bar { font-size: 10.5px; }
  .tpl-cats { width: 100%; overflow-x: auto; padding-bottom: 2px; margin-left: 0; }
  .theme-line { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .theme-line .swatch { width: 26px; height: 26px; }
  .tpl-pager { margin-left: auto; }
  .tpl-card { width: 156px; }
  .toasts { left: 12px; top: auto; bottom: 12px; }
  /* 触屏目标放大 */
  .mini-btn { width: 30px; height: 30px; }
  .layer-tools .mini-btn { width: 28px; height: 28px; }
  .seg-btn { width: 52px; height: 38px; }
  .seg-wide { width: auto; height: 38px; padding: 0 10px; font-size: 11.5px; }
  .icon-btn { width: 40px; height: 40px; }
}

@media (max-width: 480px) {
  .topbar-actions { width: 100%; }
  .btn-primary { flex: 1; }
  .brand-text span { display: none; }
  .canvas-meta { gap: 6px; }
  .field.field-narrow { width: 92px; }
  .btn-pair { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}