/* ═══════════════════════════════════════════════════════════
   ZMD PRESS — 终末地视觉语言 · 公众号自由排版编辑器
   烟灰操作面 + 系统黄行动色 · 与 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;

  --action: #f8d34d;
  --action-deep: #e3bc2f;
  --selected: #fffa00;
  --notify: #ff7d1a;
  --gain: #d8f21d;
  --data: #4db5e8;
  --region: #06a2a2;
  --special: #8a5cf6;
  --danger: #e5484d;
  --success: #13cf70;

  --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;
  --source-w: 300px;
  --rail-w: 296px;
}

* { 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; }
a { color: inherit; text-decoration: none; }

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

/* ── 滚动条（操作面语言） ───────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #3a3d42;
  border: 3px solid var(--surface-smoke);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: var(--action-deep); }
.source-input::-webkit-scrollbar-thumb { border-color: var(--surface-panel); }
.stage::-webkit-scrollbar-thumb { border-color: #101113; }
* { scrollbar-width: thin; scrollbar-color: #3a3d42 transparent; }

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

.main {
  display: grid;
  grid-template-columns: var(--source-w) 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;
}

/* 协议工作台切换轨（与 ZMD COVER LAB 同构） */
.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-chip {
  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-dim { color: var(--text-muted); background: transparent; border-color: var(--line); }

.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; }

/* 主行动：纸白胶囊 + 圆形图标章（与 COVER LAB 一致；黄色留给选中与进度） */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 4px 20px;
  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;
  margin-left: -15px;
  flex: none;
  border-radius: 50%;
  background: var(--text-on-action);
  color: var(--action);
  transition: background .15s, color .15s;
}
.btn-primary:hover:not(:disabled) { background: #fff; }
.btn-primary:hover:not(:disabled) svg { background: var(--action); color: var(--text-on-action); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.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:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary svg { width: 15px; height: 15px; color: var(--text-secondary); }
.btn-secondary.btn-block { width: 100%; }
.btn-secondary.btn-block + .btn-block { margin-top: 8px; }
.btn-quiet-danger:hover { border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.btn-quiet-danger:hover svg { color: var(--danger); }
.btn-link { white-space: nowrap; }

.btn-pair { display: flex; gap: 8px; }
.btn-pair > * { flex: 1; }

/* ── 区段（左右轨通用） ─────────────────────── */
.sec { border-bottom: 1px solid var(--line-soft); }
.sec-head, .sec > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  list-style: none;
  user-select: none;
}
.sec > summary { cursor: pointer; }
.sec > summary:hover { background: var(--surface-raised); }
.sec > summary::-webkit-details-marker { display: none; }
.sec-bar { width: 3px; height: 14px; background: var(--action); flex: none; }
.sec-title { font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.sec-code { font-family: var(--font-micro); font-size: 10px; color: var(--text-muted); letter-spacing: .05em; }
.sec-count {
  margin-left: auto;
  font-family: var(--font-micro);
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.sec-chevron { margin-left: auto; display: inline-flex; color: var(--text-muted); transition: transform .18s; }
.sec-chevron svg { width: 14px; height: 14px; }
.sec[open] > summary .sec-chevron { transform: rotate(180deg); }
.sec-count + .sec-chevron { margin-left: 0; }
.sec-body { padding: 4px 14px 16px; }

/* ── 左轨：组件库 + 导入 ────────────────────── */
.source-rail {
  background: var(--surface-panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.lib-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.lib-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  transition: border-color .15s, background .15s, transform .12s;
}
.lib-btn svg { width: 15px; height: 15px; color: var(--text-secondary); flex: none; transition: color .15s; }
.lib-btn:hover { border-color: var(--action-deep); background: var(--surface-overlay); }
.lib-btn:hover svg { color: var(--action); }
.lib-btn:active { transform: translateY(1px); }
.lib-hint { margin-top: 10px; line-height: 1.6; }

.source-input {
  width: 100%;
  resize: vertical;
  background: var(--surface-smoke);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-family: var(--font-micro);
  font-size: 12px;
  line-height: 1.7;
  padding: 10px 12px;
  tab-size: 2;
}
.import-input { min-height: 120px; margin-bottom: 10px; }
.source-input::placeholder { color: var(--text-muted); font-family: var(--font-ui); }
.source-input:focus { border-color: var(--action-deep); outline: none; }
.inline-code {
  font-family: var(--font-micro);
  font-size: 10.5px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--action);
}
.sec-body > .micro-note { line-height: 1.7; }
.sec-body .btn-pair + .micro-note { margin-top: 10px; }

/* 预制文稿模板网格 */
.doc-tpl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 10px;
}
.doc-tpl-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 9px 8px 11px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--tpl-accent, var(--action));
  border-radius: 2px;
  text-align: left;
  color: var(--text-primary);
  position: relative;
  transition: background .15s, border-color .15s, transform .12s;
}
.doc-tpl-btn:hover {
  background: var(--surface-overlay);
  border-color: #4b4f56;
  border-left-color: var(--tpl-accent, var(--action));
}
.doc-tpl-btn:active { transform: translateY(1px); }
.doc-tpl-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}
.doc-tpl-name { font-size: 12px; font-weight: 800; letter-spacing: .03em; }
.doc-tpl-idx { font-family: var(--font-micro); font-size: 9.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.doc-tpl-desc { font-size: 10.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-actions { margin-top: 2px; }

/* ── 预览 / 编辑工作区 ──────────────────────── */
.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}
.stage-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-smoke);
}
.stage-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.stage-bar .seg-group { margin-left: auto; }

.seg-group {
  display: inline-flex;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 3px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text-primary); }
.seg-btn[aria-pressed="true"] { background: var(--action); color: var(--text-on-action); }

.stage {
  position: relative;
  overflow: auto;
  background: #101113;
  padding: 40px 28px 52px;
}
.stage-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(237, 236, 230, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(237, 236, 230, .035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse 90% 80% at 50% 40%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 90% 80% at 50% 40%, #000 30%, transparent 100%);
}
.article-holder {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}
.crop-marks { position: absolute; inset: -14px; pointer-events: none; }
.cm { position: absolute; width: 14px; height: 14px; border-color: #4a4d52; border-style: solid; border-width: 0; }
.cm-tl { top: 0; left: 0; border-top-width: 1.5px; border-left-width: 1.5px; }
.cm-tr { top: 0; right: 0; border-top-width: 1.5px; border-right-width: 1.5px; }
.cm-bl { bottom: 0; left: 0; border-bottom-width: 1.5px; border-left-width: 1.5px; }
.cm-br { bottom: 0; right: 0; border-bottom-width: 1.5px; border-right-width: 1.5px; }

.article-frame {
  position: relative;
  width: 375px;
  max-width: calc(100vw - 80px);
  background: #ffffff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5), 0 2px 10px rgba(0, 0, 0, .4);
  transition: width .2s ease;
}
.preview { min-height: 120px; }

/* ── 块编辑器（仅工具层，不进导出） ───────────── */
.blk { position: relative; }
/* 悬停桥：块上方的隐形命中区，让鼠标能移到块外工具条而不丢 hover */
.blk::before {
  content: "";
  position: absolute;
  top: -17px;
  left: -10px;
  right: -10px;
  height: 17px;
}
.blk-body { position: relative; }
.blk-tag {
  position: absolute;
  top: -8px;
  left: -8px;
  z-index: 6;
  font-family: var(--font-micro);
  font-size: 9px;
  letter-spacing: .05em;
  background: var(--surface-overlay);
  color: var(--text-secondary);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 1px 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  white-space: nowrap;
}
.blk-tools {
  position: absolute;
  top: -13px;
  right: -8px;
  z-index: 6;
  display: flex;
  gap: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.blk:hover .blk-tools, .blk:focus-within .blk-tools, .blk.is-selected .blk-tools { pointer-events: auto; }
.blk-tools button {
  width: 25px;
  height: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-overlay);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text-secondary);
  transition: color .15s, border-color .15s, background .15s;
}
.blk-tools button svg { width: 13px; height: 13px; }
.blk-tools button:hover { color: var(--action); border-color: var(--action-deep); background: var(--surface-raised); }
.blk-tools button[data-act="del"]:hover { color: var(--danger); border-color: var(--danger); }
.blk-tools button[data-act="drag"] { cursor: grab; }
.blk-tools button[data-act="drag"]:active { cursor: grabbing; }
.blk:hover .blk-tag, .blk:hover .blk-tools,
.blk:focus-within .blk-tag, .blk:focus-within .blk-tools,
.blk.is-selected .blk-tag, .blk.is-selected .blk-tools { opacity: 1; }

.blk.is-selected::after {
  content: "";
  position: absolute;
  inset: -3px;
  pointer-events: none;
  --b: 2px; --len: 9px; --c: var(--action);
  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;
}
.blk.drop-before { box-shadow: 0 -2px 0 var(--action); }
.blk.drop-after { box-shadow: 0 2px 0 var(--action); }
.blk.dragging { opacity: .45; }

#preview [data-field] {
  outline: none;
  border-radius: 2px;
  min-width: 1em;
  transition: background .15s;
}
#preview [data-field]:hover { background: rgba(248, 211, 77, .10); }
#preview [data-field]:focus { background: rgba(248, 211, 77, .16); }
#preview [data-field]:empty::before {
  content: attr(data-ph);
  opacity: .38;
  pointer-events: none;
}
#preview [data-field][contenteditable="false"] { cursor: pointer; }
#preview [data-sem] { cursor: pointer; user-select: none; }
#preview [data-sem]:hover { filter: brightness(1.12); }
#preview [data-div-cycle] { cursor: pointer; user-select: none; }

.preview-empty {
  padding: 72px 24px;
  text-align: center;
  color: #8a8d88;
  font-size: 13px;
  line-height: 2;
  background: #ffffff;
}
.empty-cross {
  display: block;
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  border: 1.5px solid #c9cac3;
  border-radius: 50%;
  position: relative;
}
.empty-cross::before, .empty-cross::after {
  content: "";
  position: absolute;
  background: #c9cac3;
}
.empty-cross::before { left: 50%; top: -7px; bottom: -7px; width: 1.5px; transform: translateX(-50%); }
.empty-cross::after { top: 50%; left: -7px; right: -7px; height: 1.5px; transform: translateY(-50%); }

.hint-bar {
  padding: 9px 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--line-soft);
  background: var(--surface-smoke);
  text-align: center;
}
kbd {
  font-family: var(--font-micro);
  font-size: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-secondary);
}

/* ── 右轨：样式控件 ────────────────────────── */
.rail {
  background: var(--surface-panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
/* 版式预设：缩略图是用真实排版函数渲染的迷你文稿 */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; padding: 4px 3px 0; }
.preset-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding: 0;
  text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--card-accent, var(--line));
  border-radius: 0;
  color: var(--text-primary);
  position: relative;
  transition: border-color .15s, transform .12s, background .15s;
}
.preset-thumb { display: block; height: 86px; overflow: hidden; background: #fff; }
.preset-sample {
  display: block;
  width: 375px;
  padding: 16px 16px 0;
  transform: scale(.34);
  transform-origin: 0 0;
  pointer-events: none;
  text-align: left;
}
.preset-name { padding: 6px 8px 0; font-size: 12.5px; font-weight: 800; letter-spacing: .04em; }
.preset-tag { padding: 0 8px 7px; font-size: 10.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset-card:hover { border-color: #4d5157; border-bottom-color: var(--card-accent, var(--action)); background: var(--surface-overlay); }
.preset-card:active { transform: translateY(1px); }
/* 当前版式：说明区明暗反转 + 四角括号 */
.preset-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); }
.preset-card[aria-pressed="true"] .preset-tag { color: #5a5c57; }
.preset-card[aria-pressed="true"] .preset-thumb { border-bottom: 1px solid #d5d4cd; }
.preset-card[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: -4px;
  pointer-events: none;
  --b: 2px; --len: 9px; --c: var(--action);
  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;
}
.preset-note { margin-top: 12px; line-height: 1.7; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: flex; gap: 10px; }
.field.grow { flex: 1; min-width: 0; }
.field-label {
  display: block;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: .03em;
}
.micro-note { font-size: 11px; color: var(--text-muted); }

.color-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.color-input {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-raised);
  cursor: pointer;
  flex: none;
}
.color-input::-webkit-color-swatch-wrapper { padding: 3px; }
.color-input::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-input::-moz-color-swatch { border: none; border-radius: 2px; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .35);
  background: var(--sw);
  cursor: pointer;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.is-active { outline: 2px solid var(--action); outline-offset: 2px; }

.range-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.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;
}
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: 1px solid var(--line);
  border-radius: 2px;
}
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.14); 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: 1px solid var(--line);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  background: var(--surface-paper);
  border: 2px solid var(--text-on-action);
  border-radius: 2px;
}

.select {
  width: 100%;
  appearance: none;
  background: var(--surface-raised);
  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;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-size: 12.5px;
  padding: 8px 28px 8px 10px;
  min-height: 36px;
  cursor: pointer;
}
.select option { background: var(--surface-overlay); color: var(--text-primary); }
.select:hover { border-color: #45494f; }
.select:focus { border-color: var(--action); outline: none; box-shadow: 0 0 0 1px var(--action); }

.sub-block { padding: 6px 0; }
.sub-block + .sub-block { border-top: 1px dashed var(--line-soft); }
.check-line {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  padding: 3px 0;
}
.check-line input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-box {
  width: 16px;
  height: 16px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-raised);
  position: relative;
  transition: background .15s, border-color .15s;
}
.check-line:hover .check-box { border-color: #45494f; }
.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(45deg);
}
.check-line input:focus-visible + .check-box { outline: 2px solid var(--action); outline-offset: 2px; }
.check-hint { margin-left: auto; font-size: 10.5px; color: var(--text-muted); }
.sub-block + .micro-note { margin-top: 8px; line-height: 1.7; }

.export-readout {
  margin-top: 10px;
  font-family: var(--font-micro);
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: center;
}

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

/* ── Toast ────────────────────────────────── */
.toasts {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-overlay);
  border: 1px solid var(--line);
  border-left: 3px solid var(--data);
  border-radius: var(--radius-control);
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--text-primary);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  pointer-events: auto;
  animation: toast-in .22s ease;
  max-width: min(90vw, 480px);
}
.toast.success { border-left-color: var(--success); }
.toast.success svg { color: var(--success); }
.toast.error, .toast.warn { border-left-color: var(--danger); }
.toast.error svg, .toast.warn svg { color: var(--danger); }
.toast.info svg { color: var(--data); }
.toast svg { width: 16px; height: 16px; flex: none; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
.toast-action {
  border: none;
  background: transparent;
  color: var(--action);
  font-size: 12.5px;
  font-weight: 700;
  padding: 2px 4px;
  white-space: nowrap;
}
.toast-action:hover { text-decoration: underline; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── 草稿与账号 ────────────────────────────── */
.save-indicator { font-size: 11px; color: var(--success); white-space: nowrap; }
.save-indicator[data-state="error"] { color: var(--danger); }
.cloud-account { color: var(--text-secondary); font-size: 12px; overflow-wrap: anywhere; }
.cloud-status { color: var(--text-muted); font-size: 11px; margin: 6px 0 12px; line-height: 1.7; }
.cloud-status[data-state="error"] { color: #ff9298; }
.cloud-status[data-state="saved"] { color: var(--success); }
.cloud-section .btn-secondary { padding-inline: 10px; font-size: 11.5px; }
.cloud-auto { display: flex; align-items: center; gap: 7px; margin: 12px 0; font-size: 11px; color: var(--text-secondary); }
.cloud-auto input { accent-color: var(--action); }
.draft-details { margin-top: 14px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.draft-details > summary { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-secondary); font-size: 12px; }
.draft-details > summary::before { content: '›'; color: var(--action); }
.draft-details[open] > summary::before { transform: rotate(90deg); }
.draft-details > .micro-note { margin-top: 7px; }
.draft-list { margin-top: 9px; display: grid; gap: 7px; max-height: 300px; overflow-y: auto; }
.draft-card { border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 3px; padding: 9px 10px; background: var(--surface-raised); min-width: 0; transition: border-color .15s, background .15s; }
.draft-card:hover { border-left-color: var(--action); background: var(--surface-overlay); }
.draft-card-title { display: block; font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-card-meta { font-size: 10px; color: var(--text-muted); margin-top: 4px; overflow-wrap: anywhere; }
.draft-card-actions { display: flex; align-items: center; gap: 9px; margin-top: 7px; }
.text-btn { border: none; background: transparent; color: var(--action); font-size: 11px; font-weight: 700; padding: 3px 0; }
.text-btn:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 3px; }
.text-btn:disabled { color: var(--text-muted); cursor: not-allowed; }
.draft-details > summary .text-btn { margin-left: auto; padding: 2px 4px; }
.draft-versions { margin-top: 6px; font-size: 11px; color: var(--text-secondary); }
.draft-versions .text-btn { display: block; text-align: left; }
.account-dialog {
  margin: auto;
  width: min(440px, calc(100vw - 28px));
  padding: 24px;
  color: var(--text-primary);
  background: var(--surface-panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--action);
  border-radius: 4px;
  box-shadow: 0 25px 90px #000a;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.account-dialog::backdrop { background: rgba(10, 11, 13, .72); backdrop-filter: blur(4px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); }
.dialog-title-wrap { display: flex; align-items: center; gap: 10px; }
.dialog-head h2 { font-size: 16px; font-weight: 800; letter-spacing: .04em; }
.dialog-sub { display: block; font-family: var(--font-micro); font-size: 10px; color: var(--text-muted); letter-spacing: .06em; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tabs .btn-secondary { flex: 1; }
.auth-tabs [aria-pressed="true"] { background: var(--surface-paper); color: var(--text-on-action); border-color: var(--surface-paper); font-weight: 800; }
.cloud-input { display: block; width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-smoke); color: var(--text-primary); font-size: 13px; transition: border-color .15s; }
.cloud-input:focus { border-color: var(--action); outline: none; box-shadow: 0 0 0 1px var(--action); }
.account-dialog .field { margin-top: 14px; }
.account-dialog .field-label { display: block; margin-bottom: 6px; }
.auth-error { color: #ff9298; font-size: 12px; min-height: 18px; margin: 12px 0; }
#signed-in > .field-label { margin-top: 16px; }
.account-welcome { color: var(--success); font-size: 12px; margin: 12px 0; }
#btn-account span { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 响应式 ────────────────────────────────── */
@media (max-width: 1280px) {
  .main {
    grid-template-columns: 316px minmax(0, 1fr);
    grid-template-rows: minmax(0, .55fr) minmax(0, .45fr);
  }
  .source-rail { grid-column: 1; grid-row: 1; overflow: auto; min-height: 0; }
  .rail { grid-column: 1; grid-row: 2; border-left: none; border-right: 1px solid var(--line); }
  .workspace { grid-column: 2; grid-row: 1 / 3; }
  .topbar-meta .meta-dim { display: none; }
  .save-indicator { 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; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { position: sticky; top: 0; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar-meta { display: none; }
  .topbar-actions { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .main { display: flex; flex-direction: column; }
  .source-rail { border-right: none; border-bottom: 1px solid var(--line); }
  .lib-grid { grid-template-columns: repeat(3, 1fr); }
  .doc-tpl-grid { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-rows: auto minmax(420px, 62vh) auto; }
  .stage { padding: 28px 14px 36px; }
  .article-frame { max-width: calc(100vw - 52px); }
  .rail { border-right: none; border-left: none; overflow: visible; }
  .hint-bar { font-size: 10.5px; }
  .blk-tools { opacity: 1; pointer-events: auto; }
  .blk-tag { opacity: 1; }
}

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