/* ============================================================
 * 妖梦与星辉设计原稿编辑器 v3 —— 样式表
 * 中性灰 + 低饱和靛蓝；浅色 / 低眩光深色双主题（CSS 变量）。
 * 规范：SVG 线性图标；无 emoji 图标；无 AI 渐变；无重硬阴影；
 *   焦点清晰可见；prefers-reduced-motion；动画 150–250ms；
 *   悬停不引发布局位移；手机端点击区域 ≥ 44px。
 * ============================================================ */

/* ---------------- 主题变量 ---------------- */
:root,
:root[data-theme='light'] {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --card: #ffffff;
  --paper: #f7f8fa;
  --ink: #22262e;
  --muted: #5d6470;
  --faint: #8a919d;
  --line: #dde1e8;
  --line-strong: #c6ccd7;
  --primary: #4658b4;
  --primary-hover: #3a49a0;
  --primary-ink: #ffffff;
  --primary-soft: #e9ebf9;
  --danger: #b8402f;
  --danger-soft: #f9e9e6;
  --ok: #2e7a4d;
  --ok-soft: #e4f2e9;
  --warn: #946214;
  --warn-soft: #f6eeda;
  --youmu: #2f7e79;
  --youmu-soft: #e2f0ef;
  --star: #9a6a1c;
  --star-soft: #f6eeda;
  --shadow: 0 1px 2px rgba(18, 24, 40, .07);
  --shadow-pop: 0 6px 24px rgba(18, 24, 40, .14);
  --focus: #4658b4;
}

:root[data-theme='dark'] {
  --bg: #171a20;
  --panel: #1e222b;
  --card: #232833;
  --paper: #1a1e26;
  --ink: #d3d8e1;
  --muted: #99a2b1;
  --faint: #6f7889;
  --line: #333a48;
  --line-strong: #444c5e;
  --primary: #93a0ea;
  --primary-hover: #aab6f2;
  --primary-ink: #141827;
  --primary-soft: #2a3050;
  --danger: #d17a6a;
  --danger-soft: #3a2724;
  --ok: #7bbd92;
  --ok-soft: #22352a;
  --warn: #cfa657;
  --warn-soft: #37301f;
  --youmu: #6ab3ad;
  --youmu-soft: #21383a;
  --star: #d6a44f;
  --star-soft: #37301f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, .5);
  --focus: #aab6f2;
}

/* ---------------- 基础 ---------------- */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Yu Gothic UI', 'Hiragino Kaku Gothic ProN', 'Hiragino Maru Gothic ProN',
    'Meiryo', 'Microsoft YaHei', 'PingFang SC', 'Noto Sans CJK SC', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button { font-family: inherit; color: inherit; }

input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }

h1, h2, h3, h4 { line-height: 1.35; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

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

/* ---------------- 图标 ---------------- */
.ic {
  width: 17px; height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--paper); border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--panel); border-color: var(--line-strong); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); filter: brightness(1.08); }

.btn-icon { padding: 7px 9px; }
.btn-icon .ic { vertical-align: middle; }

.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

.btn-dashed {
  width: 100%;
  justify-content: center;
  border-style: dashed;
  color: var(--muted);
  background: transparent;
}
.btn-dashed:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

/* ---------------- 徽章 / 状态 ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-youmu { color: var(--youmu); background: var(--youmu-soft); border-color: var(--youmu); }
.badge-star { color: var(--star); background: var(--star-soft); border-color: var(--star); }
.badge-mark { color: var(--muted); background: var(--paper); border-color: var(--line-strong); }
.badge-status { color: var(--primary); background: var(--primary-soft); border-color: var(--primary); }
.badge-cur { color: var(--ok); background: var(--ok-soft); border-color: var(--ok); }

.store-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: var(--panel);
  white-space: nowrap;
}
.store-badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--faint);
}
.store-badge.local::before { background: var(--youmu); }
.store-badge.server::before { background: var(--ok); }
.store-badge.offline { color: var(--warn); border-color: var(--warn); }
.store-badge.offline::before { background: var(--warn); }
.store-badge.error { color: var(--danger); border-color: var(--danger); }
.store-badge.error::before { background: var(--danger); }

/* ---------------- 项目库 ---------------- */
.view { min-height: 100%; display: flex; flex-direction: column; }

.lib-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-right: auto;
}
.brand .ic { width: 20px; height: 20px; color: var(--primary); }
.lib-head-ops { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.storage-warn {
  padding: 8px 18px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.lib-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px 4px;
}
.lib-search {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 240px;
  max-width: 380px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}
.lib-search input {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 0;
  outline: none;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.is-on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

#libSort {
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
}

.lib-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
  padding: 14px 18px 26px;
}

.lib-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}
.lib-empty p { margin: 8px 0 16px; }

.lib-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color .16s ease;
}
.lib-card:hover { border-color: var(--line-strong); }

.lib-card-top { display: flex; align-items: center; gap: 8px; }
.lib-card-kind { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; }
.lib-card-kind .ic { width: 14px; height: 14px; }
.lib-card-kind.youmu { color: var(--youmu); }
.lib-card-kind.star { color: var(--star); }
.lib-card-status { margin-left: auto; }

.lib-card-name {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  word-break: break-all;
}
.lib-card-name:hover { color: var(--primary); }

.lib-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
}
.lib-card-ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ---------------- 编辑器骨架 ---------------- */
.ed-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.ed-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-right: auto;
}
.ed-doc-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34vw;
}
.ed-head-ops { display: flex; align-items: center; gap: 7px; }

.save-chip {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .16s ease, color .16s ease;
}
.save-chip.ok { color: var(--ok); border-color: var(--ok); }
.save-chip.dirty { color: var(--warn); border-color: var(--warn); }
.save-chip.err { color: var(--danger); border-color: var(--danger); }

.ed-body {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) minmax(360px, 42%);
  gap: 14px;
  padding: 14px;
  align-items: start;
  flex: 1;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
}

.sec-nav {
  position: sticky;
  top: 66px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sec-nav button {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}
.sec-nav button:hover { background: var(--panel); color: var(--ink); }
.sec-nav button .cnt { margin-left: auto; font-size: 11px; color: var(--faint); }

.ed-form { min-width: 0; padding-bottom: 40px; }

.ed-preview {
  position: sticky;
  top: 66px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 84px);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.preview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.preview-title { font-weight: 700; font-size: 13px; }
.stat-info { margin-left: auto; font-size: 11px; color: var(--faint); }
.preview-scroll { overflow-y: auto; padding: 12px 16px 20px; }
.pv-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pv-badge {
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--faint);
}
/* ---------------- 预览排版 ---------------- */
.preview-content .pv-sec { margin-bottom: 18px; }
.preview-content h2 { font-size: 19px; margin: 4px 0 8px; }
.preview-content h3 { font-size: 15px; margin: 12px 0 6px; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
.preview-content h4 { font-size: 13px; margin: 10px 0 4px; color: var(--muted); }
.pv-meta {
  margin: 6px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--primary);
  background: var(--paper);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
}
.pv-meta div { margin: 2px 0; }
.pv-k { color: var(--muted); margin-right: 6px; }
.pv-list { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.pv-list li { margin: 2px 0; }
.pv-label { font-weight: 700; font-size: 13px; margin: 10px 0 2px; }
.pv-text { margin: 2px 0 8px; font-size: 13px; white-space: normal; }
.pv-stats { margin: 8px 0; }
.pv-stat-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 12px; }
.pv-stat-name { width: 34px; color: var(--muted); flex: none; }
.pv-stat-val { width: 34px; text-align: right; font-weight: 700; flex: none; }
.pv-stat-track { flex: 1; height: 8px; background: var(--paper); border-radius: 4px; overflow: hidden; }
.pv-stat-bar { display: block; height: 100%; border-radius: 4px; transition: width .2s ease; }
.pv-stat-total { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------------- 表单通用 ---------------- */
.form-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.form-section > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary::before {
  content: '';
  width: 7px; height: 7px;
  border-right: 2px solid var(--faint);
  border-bottom: 2px solid var(--faint);
  transform: rotate(45deg);
  transition: transform .18s ease;
  flex: none;
}
.form-section[open] > summary::before { transform: rotate(225deg); }
.form-section > summary .summary-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--faint);
}
.form-section > summary .count-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 0 8px;
}
.form-section > summary .stat-total-chip {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.section-body { padding: 4px 14px 14px; }

.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field-label .req { color: var(--danger); }
.field input[type='text'], .field input[type='number'], .field select, .field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  transition: border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: none; }
.field textarea { resize: vertical; min-height: 34px; }
.field input:disabled, .field select:disabled { opacity: .5; background: var(--paper); }
.field-hint { font-size: 11px; color: var(--faint); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
}
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.check.wide { grid-column: 1 / -1; }

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.radio-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}
.radio-chip input { display: none; }
.radio-chip.is-on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.sub-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  background: var(--paper);
}
.sub-block > legend, .sub-block-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
}
.sub-block.replace { border-color: var(--danger); background: var(--danger-soft); }
.sub-block.replace .sub-block-title { color: var(--danger); }
.sub-block.append { border-color: var(--youmu); background: var(--youmu-soft); }
.sub-block.append .sub-block-title { color: var(--youmu); }

.notice {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--muted);
  background: var(--paper);
  margin: 8px 0;
}
.notice .ic { width: 15px; height: 15px; margin-top: 2px; }
.notice.warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.notice.error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

/* ---------------- 种族值 ---------------- */
.stats-grid { display: flex; flex-direction: column; gap: 6px; }
.stat-row {
  display: grid;
  grid-template-columns: 42px 84px 1fr;
  align-items: center;
  gap: 10px;
}
.stat-name { font-size: 13px; color: var(--muted); }
.stat-row input {
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  text-align: right;
}
.stat-row input:focus { border-color: var(--primary); outline: none; }
.stat-track { height: 8px; background: var(--paper); border-radius: 4px; overflow: hidden; }
.stat-bar { display: block; height: 100%; border-radius: 4px; transition: width .18s ease; }
.stats-overview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.ov-chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 2px 10px;
}
.ov-chip b { color: var(--ink); }

/* ---------------- 技能卡 / 适配条目卡 ---------------- */
.skill-sub {
  margin-top: 12px;
}
.skill-sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.skill-sub-title { font-size: 13px; font-weight: 700; color: var(--muted); }
.skill-sub-head .btn { margin-left: auto; }
.card-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.empty-tip { color: var(--faint); font-size: 12px; margin: 6px 0; }

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  transition: border-color .15s ease;
}
.card.dragging { opacity: .45; }
.card.drop-before { border-top: 2px solid var(--primary); }
.card.drop-after { border-bottom: 2px solid var(--primary); }

.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  min-height: 44px;
}
.card-grip {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: grab;
  padding: 6px 4px;
  touch-action: none;
}
.card-grip:active { cursor: grabbing; }
.card-head-main {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 4px 2px;
}
.card-title { font-weight: 700; font-size: 13px; display: block; }
.card-summary {
  display: block;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card:not(.is-collapsed) .card-summary { display: none; }
.card-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.tool {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 6px 7px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background-color .15s ease, color .15s ease;
}
.tool:hover { background: var(--paper); color: var(--ink); }
.tool.danger:hover { color: var(--danger); background: var(--danger-soft); }
.tool .ic { width: 15px; height: 15px; }
.card-body { padding: 4px 12px 12px; border-top: 1px solid var(--line); }
.card.is-collapsed .card-body { display: none; }

/* ---------------- chips（种族多选 / 本系属系） ---------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  font-size: 12px;
  background: var(--panel);
}
.chip-x {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  border-radius: 50%;
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chip-x:hover { color: var(--danger); background: var(--danger-soft); }
.chip-add { display: flex; gap: 6px; margin-top: 6px; }
.chip-add input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
}
.stab-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.stab-chip {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s ease;
}
.stab-chip.is-on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 600; }

/* ---------------- 弹窗 / 菜单 / 气泡 ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 24, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.modal-wide { max-width: 640px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.modal-msg { margin: 4px 0; font-size: 13px; }
.modal-tip { font-size: 12px; color: var(--muted); margin: 8px 0; }
.modal-list { margin: 8px 0; padding-left: 18px; font-size: 13px; }
.modal-list li { margin: 3px 0; }

.menu {
  position: fixed;
  z-index: 120;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 5px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--paper); }
.menu-item.danger { color: var(--danger); }
.menu-item.primary { color: var(--primary); font-weight: 600; }

.toast-root {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  max-width: 86vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.warn { background: var(--warn); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }

/* 新建项目类型选择 */
.tpl-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.tpl-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.tpl-item:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.tpl-item input { display: none; }
.tpl-name { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 14px; }
.tpl-name .ic { color: var(--primary); }
.tpl-desc { font-size: 12px; color: var(--muted); }

/* 历史版本 */
.hist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}
.hist-row:last-child { border-bottom: 0; }
.hist-info { flex: 1; min-width: 0; }
.hist-time { font-weight: 700; font-size: 13px; }
.hist-label { font-size: 12px; color: var(--muted); }

/* ---------------- 手机底部导航 ---------------- */
.mobile-nav { display: none; }

/* ---------------- 响应式：≤1023px 单栏 + 底部导航 ---------------- */
@media (max-width: 1023px) {
  .desktop-only { display: none !important; }

  /* 点击区域 ≥ 44px */
  .btn, .tool, .seg button, .chip-x, .stab-chip,
  .form-section > summary, .sec-nav button, .menu-item {
    min-height: 44px;
  }
  .field input, .field select, .field textarea, .chip-add input, #libSort {
    min-height: 44px;
  }
  .tool { min-width: 44px; justify-content: center; }

  /* 项目库 */
  .lib-head { padding: 10px 12px; }
  .lib-controls { padding: 10px 12px 2px; }
  .lib-search { max-width: none; }
  .lib-list { grid-template-columns: 1fr; padding: 12px 12px 26px; }

  /* 编辑器顶栏：只留 名称 + 保存状态 */
  .ed-head { padding: 8px 12px; gap: 8px; }
  .ed-doc-name { max-width: 46vw; font-size: 14px; }

  /* 单栏：编辑 / 预览 一次只显示一个 */
  .ed-body {
    display: block;
    padding: 10px 12px calc(76px + env(safe-area-inset-bottom));
  }
  .sec-nav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 8px;
    margin-bottom: 4px;
    scrollbar-width: none;
  }
  .sec-nav::-webkit-scrollbar { display: none; }
  .sec-nav button { white-space: nowrap; border: 1px solid var(--line); background: var(--panel); }
  .ed-preview {
    position: static;
    max-height: none;
    margin-top: 10px;
  }
  #viewEditor[data-mview='edit'] .ed-preview { display: none; }
  #viewEditor[data-mview='preview'] .ed-form,
  #viewEditor[data-mview='preview'] .sec-nav { display: none; }

  /* 底部导航 */
  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
  }
  .mobile-nav button .ic { width: 20px; height: 20px; }
  .mobile-nav button.is-on { color: var(--primary); font-weight: 700; }

  /* 弹窗改底部弹板 */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none;
    border-radius: 14px 14px 0 0;
    max-height: 88vh;
    border-bottom: 0;
  }
  .tpl-list { grid-template-columns: 1fr; }

  /* 预览字号略增，便于睡前阅读 */
  .preview-content { font-size: 14px; }
}

/* ---------------- 窄屏补充 ---------------- */
@media (max-width: 480px) {
  .fields-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 38px 76px 1fr; gap: 8px; }
  .lib-head-ops .btn span { display: none; }
  .lib-head-ops .btn .ic { vertical-align: middle; }
}

/* ---------------- 规则参考抽屉 ---------------- */
.rb-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 70;
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
  transform: translateX(103%);
  transition: transform .22s ease;
}
.rb-drawer.open { transform: translateX(0); }
.rb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.rb-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.rb-title .ic { color: var(--primary); }
.rb-search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 14px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.rb-search .ic { color: var(--faint); flex: none; }
.rb-search input { flex: 1; border: 0; background: transparent; min-height: 38px; outline: none; }
.rb-body { flex: 1; overflow-y: auto; padding: 0 14px 14px; }
.rb-sec {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--card);
  overflow: hidden;
}
.rb-sec summary { cursor: pointer; padding: 9px 12px; font-weight: 600; font-size: 13px; }
.rb-sec-body { padding: 0 12px 10px; font-size: 12.5px; }
.rb-sec-body p { margin: 6px 0; }
.rb-sec-body ul { margin: 4px 0 8px; padding-left: 18px; }
.rb-sec-body li { margin: 3px 0; }
.rb-sec-body mark { background: var(--warn-soft); color: inherit; border-radius: 2px; padding: 0 1px; }
.rb-empty { color: var(--muted); text-align: center; padding: 20px 0; }
.rb-foot { padding: 8px 14px; font-size: 11px; color: var(--faint); border-top: 1px solid var(--line); }

@media (max-width: 1023px) {
  .rb-drawer { width: 100vw; border-left: 0; }
  .rb-search input { min-height: 44px; }
  .rb-sec summary { min-height: 44px; display: flex; align-items: center; }
}

/* ---------------- 访问令牌锁屏页 ---------------- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(128, 134, 148, .28);
  backdrop-filter: blur(14px) saturate(.9);
  -webkit-backdrop-filter: blur(14px) saturate(.9);
}
:root[data-theme='dark'] .auth-gate { background: rgba(10, 12, 18, .45); }
.auth-card {
  width: min(340px, calc(100vw - 48px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
  padding: 28px 24px 22px;
  text-align: center;
}
.auth-logo {
  width: 46px;
  height: 46px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
}
.auth-logo .ic { width: 22px; height: 22px; }
.auth-title { font-weight: 700; font-size: 15px; }
.auth-tip { color: var(--muted); font-size: 12.5px; margin: 8px 0 14px; }
.auth-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--paper);
  padding: 0 12px;
  font-size: 14px;
  text-align: center;
  letter-spacing: 1px;
}
.auth-input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.auth-error { color: var(--danger); font-size: 12.5px; margin: 8px 0 0; }
.auth-btn { width: 100%; min-height: 44px; margin-top: 14px; }

/* ---------------- 打印：只输出预览 ---------------- */
@media print {
  body { background: #fff; }
  .ed-head, .sec-nav, .ed-form, .mobile-nav, .lib-head, .lib-controls, .lib-list,
  #viewLibrary, .toast-root, .modal-overlay, .menu { display: none !important; }
  .ed-body { display: block; padding: 0; }
  .ed-preview { position: static; max-height: none; border: 0; box-shadow: none; display: block !important; }
  .preview-scroll { overflow: visible; }
  #viewEditor[data-mview='edit'] .ed-preview { display: block !important; }
}


