/* =========================================================================
   墨匣 · 中式古典视觉系统
   --------------------------------------------------------------------------
   - 严格 8pt 栅格(4/8/12/16/20/24/32/40/48/64)
   - 统一面板·卡片·按钮·输入骨架
   - 宣纸 + 墨 + 朱印 + 竹青 + 古铜 配色
   - 衬线宋体(标题) + 黑体(界面元素)
   - 栏线 / 双线 / 印章 等古籍装饰
   ========================================================================= */

/* ---------- 1. 设计 Token(已抽到 src/tokens.css,共享给移动端) -------- */

@import url('src/tokens.css');

/* ---------- 2. 重置与基础 ------------------------------------------------ */

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

body {
  min-width: 320px;
  color: var(--ink-0);
  font-family: var(--font-ui-body);
  font-size: var(--fs-14);
  line-height: 1.6;
  background-color: var(--paper-0);
  background-image:
    /* 宣纸纤维斑点 */
    radial-gradient(var(--grain-a) 1px, transparent 1px),
    radial-gradient(var(--grain-b) 1px, transparent 1px),
    /* 纸张暗角 */
    radial-gradient(ellipse at top left, var(--vignette-a), transparent 60%),
    radial-gradient(ellipse at bottom right, var(--vignette-b), transparent 60%);
  background-size: 6px 6px, 11px 11px, 100% 100%, 100% 100%;
  background-position: 0 0, 3px 5px, 0 0, 0 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- 登录 / 账号与个人 API ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background:
    radial-gradient(circle at 20% 15%, var(--seal-soft), transparent 34%),
    radial-gradient(circle at 82% 78%, var(--jade-soft), transparent 32%),
    var(--paper-0);
}
.auth-card { width: min(430px, 100%); padding: var(--sp-8); border: 1px solid var(--rule-0); border-radius: var(--r-4); background: var(--paper-2); box-shadow: var(--shadow-3); }
.auth-brand { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-6); }
.auth-brand > span { display: grid; place-items: center; width: 58px; height: 58px; flex: 0 0 auto; border-radius: 50%; color: #fff; background: var(--seal); font-family: var(--font-ui-display); font-size: var(--fs-26); box-shadow: inset 0 0 0 5px rgba(255,255,255,.14); }
.auth-brand h1 { font-size: var(--fs-26); }
.auth-brand p { margin-top: 4px; color: var(--ink-3); font-size: var(--fs-12); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: var(--sp-5); padding: 4px; border-radius: var(--r-2); background: var(--paper-1); }
.auth-tabs button { min-height: 36px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-3); }
.auth-tabs button.active { color: var(--ink-0); background: var(--paper-3); box-shadow: var(--shadow-1); }
#authForm { display: grid; gap: var(--sp-4); }
#authForm label { display: grid; gap: 6px; color: var(--ink-2); font-size: var(--fs-12); }
.auth-submit { width: 100%; min-height: 44px; }
.auth-error { min-height: 20px; color: var(--danger); font-size: var(--fs-12); }
.auth-footnote { margin-top: var(--sp-5); text-align: center; color: var(--ink-3); font-size: var(--fs-11); }
.guest-entry { width: 100%; min-height: 42px; margin-top: var(--sp-3); border: 1px solid var(--rule-1); border-radius: var(--r-2); background: transparent; color: var(--ink-2); }
.guest-entry:hover { border-color: var(--seal); color: var(--seal); background: var(--paper-1); }

.account-button { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 4px 10px 4px 5px; border: 1px solid var(--rule-2); border-radius: 999px; background: var(--paper-2); color: var(--ink-2); }
.account-button > span { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; color: #fff; background: var(--seal); font-size: var(--fs-11); }
.account-button b { max-width: 100px; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-12); }
.account-dialog { width: min(720px, calc(100vw - 32px)); }
.account-capacity { display: grid; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--rule-2); }
.account-capacity > div { display: flex; justify-content: space-between; color: var(--ink-2); font-size: var(--fs-12); }
.account-capacity progress { width: 100%; height: 8px; accent-color: var(--seal); }
.account-api-section { display: grid; gap: var(--sp-4); padding: var(--sp-5); }
.account-api-section h3 { margin-bottom: 5px; }
.account-api-section p { color: var(--ink-3); font-size: var(--fs-12); line-height: 1.7; }
.account-api-section code { padding: 2px 5px; border-radius: 4px; background: var(--paper-1); color: var(--ink-1); user-select: all; }
.api-token-create { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-3); }
.api-token-create label { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--ink-2); font-size: var(--fs-12); }
.api-token-create label input { width: auto; min-height: auto; }
.api-token-list { display: grid; gap: var(--sp-2); }
.api-token-list > div { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--rule-2); border-radius: var(--r-2); background: var(--paper-3); }
.api-token-list span { display: grid; min-width: 0; }
.api-token-list small { color: var(--ink-3); font-family: var(--font-mono); font-size: var(--fs-11); }
.api-token-actions { display: flex; align-items: center; gap: var(--sp-2); flex: 0 0 auto; }
.api-key-once { display: grid; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--seal); border-radius: var(--r-2); background: var(--seal-soft); }
.api-key-once code { padding: var(--sp-2); overflow-wrap: anywhere; user-select: all; background: var(--paper-2); }
.openclaw-guide { display: grid; gap: var(--sp-3); padding: var(--sp-4); border: 1px dashed var(--rule-1); border-radius: var(--r-3); background: color-mix(in srgb, var(--paper-1) 55%, transparent); }
.openclaw-guide h4 { margin-top: 2px; font-size: var(--fs-18); }
.openclaw-guide ol { display: grid; gap: var(--sp-2); padding-left: 22px; color: var(--ink-2); font-size: var(--fs-12); line-height: 1.7; }
.openclaw-guide > p { margin: 0; padding-top: var(--sp-2); border-top: 1px solid var(--rule-2); }
.account-footer { display: flex; justify-content: flex-end; padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--rule-2); }

@media screen and (max-width: 640px) {
  .auth-card { padding: var(--sp-5); }
  .api-token-create { grid-template-columns: 1fr; align-items: stretch; }
  .account-button b { display: none; }
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-ui-display);
  font-weight: 600;
  color: var(--ink-0);
  letter-spacing: 0.02em;
  line-height: 1.35;
}

p { margin: 0; }

button {
  cursor: pointer;
  font: inherit;
  color: inherit;
}

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

textarea, input, select {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  color: var(--ink-0);
  font-size: var(--fs-14);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  min-height: 156px;
  padding: var(--sp-3);
  line-height: 1.85;
  resize: vertical;
  font-family: var(--font-serif);
  font-size: var(--fs-15);
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
  background: var(--paper-3);
}

input::placeholder,
textarea::placeholder { color: var(--ink-4); }

mark {
  background: rgba(179, 50, 42, 0.18);
  color: var(--ink-0);
  padding: 0 2px;
  border-radius: 0;
}

/* 滚动条 */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--rule-2);
  border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--rule-1); }

/* ---------- 3. 应用骨架(无侧栏，工作区拉满整个宽度) --------------------- */

/* 整体固定为一屏：页面本身不滚动，滚动都发生在各自的小窗口里 */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.main {
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--sp-7) var(--main-pad) var(--sp-3);
}

/* ---- Dock栏导航 (苹果风格，现在是唯一的导航方式) ---- */

.dock-trigger {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 18px;
  z-index: 998;
  cursor: pointer;
  background: transparent;
  transition: bottom 0.35s cubic-bezier(0.4,0,0.2,1);
}

.dock {
  position: fixed;
  bottom: -120px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 5px;
  padding: 9px 11px;
  background: color-mix(in srgb, var(--paper-2) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid color-mix(in srgb, var(--rule-0) 72%, transparent);
  border-radius: 22px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.1);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: bottom 0.28s cubic-bezier(0.2,0.8,0.2,1), opacity 0.2s ease, visibility 0.28s;
}

.dock.visible {
  bottom: 24px;
  opacity: 1;
  visibility: visible;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 58px;
  gap: 3px;
  border-radius: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  color: var(--ink-2);
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.dock-item-settings {
  margin-left: 6px;
  border-left: 1px solid var(--rule-2);
  border-radius: 16px 16px 16px 16px;
}

.dock-item::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  padding: 6px 12px;
  background: rgba(0,0,0,0.8);
  color: white;
  font-size: 12px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: all 0.2s ease;
}

.dock-item:hover::before {
  opacity: 1;
  transform: translateY(0);
}

.dock-item-icon {
  font-size: 24px;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}

.dock-item:hover {
  transform: translateY(-3px);
  background: rgba(179,50,42,0.08);
}

.dock-item.active {
  background: var(--seal-soft);
  color: var(--seal-deep);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--seal) 18%, transparent);
}

.dock-item-label { font-size: 10px; line-height: 1; white-space: nowrap; }

.dock-handle {
  position: fixed;
  z-index: 999;
  left: 50%;
  bottom: 5px;
  width: 54px;
  height: 16px;
  padding: 0;
  transform: translateX(-50%);
  border: 0;
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper-2) 90%, transparent);
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  cursor: pointer;
  transition: bottom .28s ease, opacity .2s ease;
}
.dock-handle span { display: block; width: 24px; height: 3px; margin: auto; border-radius: 2px; background: var(--ink-3); }
.dock-handle.visible { bottom: 2px; opacity: .55; }
.dock-handle:focus-visible, .dock-item:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }

.dock::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 10%;
  right: 10%;
  height: 8px;
  background: rgba(179,50,42,0.15);
  border-radius: 50%;
  filter: blur(12px);
  opacity: 0.6;
}

/* ---------- 4. 顶栏 ------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-bottom: var(--sp-5);
  margin-bottom: var(--sp-7);
  border-bottom: 1px solid var(--rule-2);
  position: relative;
  flex-shrink: 0;
}

.topbar > div:first-child { min-width: 0; }

.topbar h1 {
  font-family: var(--font-serif);
  font-size: var(--fs-32);
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink-0);
  line-height: 1.1;
}

.eyebrow {
  display: inline-block;
  margin: 0 0 var(--sp-2);
  padding: 0;
  color: var(--ink-3);
  font-family: var(--font-sans);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.36em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

/* ---- 搜索 ---- */

.search-wrapper { position: relative; }

.search-container {
  display: flex;
  align-items: stretch;
  width: min(36vw, 420px);
  height: var(--h-md);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-container:focus-within {
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.search-container input {
  flex: 1;
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 0 var(--sp-3);
  font-size: var(--fs-14);
  box-shadow: none;
}
.search-container input:focus { box-shadow: none; }

.search-container input[type="search"]::-webkit-search-cancel-button { display: none; }

.search-button,
.clear-search-button {
  display: grid;
  place-items: center;
  width: 36px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-15);
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
}

.search-button:hover { color: var(--seal); }

.clear-search-button:hover { background: var(--seal-soft); color: var(--seal); }

.search-suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-2);
  z-index: 30;
}

.suggestion-item {
  padding: var(--sp-3);
  cursor: pointer;
  border-bottom: 1px solid var(--rule-2);
  transition: background 0.15s ease;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--seal-soft); }

.suggestion-item.no-results { color: var(--ink-3); cursor: default; }
.suggestion-item.no-results:hover { background: transparent; }

.suggestion-title {
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--ink-0);
}

.suggestion-meta {
  font-size: var(--fs-12);
  color: var(--ink-3);
}

.search-stats {
  padding: var(--sp-2) 0;
  font-size: var(--fs-12);
  color: var(--ink-3);
  border-bottom: 1px solid var(--rule-2);
  margin-bottom: var(--sp-3);
}

/* ---------- 5. 视图切换 ------------------------------------------------- */

.view { display: none; }

/* 每个视图是独立的滚动小窗口，主区整体不再随内容增高 */
.view.active {
  display: block;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--sp-7);
}

/* 写作视图自身就是满高三栏（编辑器/列表内部各自滚动），不需要外层滚动 */
#writingView.active {
  overflow: hidden;
  padding-bottom: 0;
}

/* ---------- 6. 统一面板 / 卡片 / 标题 ----------------------------------- */

/* 所有 panel 共享同一基础骨架 */
.capture-panel,
.stats-panel,
.review-panel,
.timeline-panel,
.book-grid-panel,
.book-detail-panel,
.split-layout > section,
.detail-panel,
.library-layout > section,
.module-tabs,
.chapter-list-panel,
.editor-panel,
.reference-panel,
.settings-panel {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
}

/* 默认面板内边距 */
.capture-panel,
.review-panel,
.timeline-panel,
.book-grid-panel,
.book-detail-panel,
.split-layout > section,
.detail-panel,
.library-layout > section,
.module-tabs,
.chapter-list-panel,
.reference-panel,
.settings-panel {
  padding: var(--sp-5);
}

/* 统一的面板标题:eyebrow + h2 + 操作按钮,带栏线分割 */
.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
  position: relative;
}

.panel-heading > div:first-child { min-width: 0; }

.panel-heading-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-heading h2 {
  font-family: var(--font-serif);
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-0);
}

.panel-heading.compact {
  margin-bottom: var(--sp-3);
  padding-bottom: var(--sp-2);
}

.panel-heading.compact h2 {
  font-size: var(--fs-16);
  letter-spacing: 0.1em;
}

/* 资料库 / 工作台 各栏标题里的 .eyebrow 已统一定义 */

/* ---------- 7. 按钮 / chip / pill --------------------------------------- */

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--h-md);
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-2);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.12s ease;
  white-space: nowrap;
}

/* 主按钮:朱印感 */
.primary-button {
  background: var(--seal);
  color: var(--paper-2);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 2px 8px var(--seal-soft);
}
.primary-button:hover {
  background: var(--seal-deep);
  transform: translateY(-1px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    0 6px 16px var(--seal-soft);
}
.primary-button:active { transform: translateY(0); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 1px 3px var(--seal-soft); }

/* 次按钮:框线 */
.secondary-button {
  background: var(--paper-3);
  border-color: var(--rule-1);
  color: var(--ink-1);
  box-shadow: var(--shadow-1);
}
.secondary-button:hover {
  border-color: var(--seal);
  color: var(--seal-deep);
  background: var(--paper-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

/* 幽灵按钮:更轻 */
.ghost-button {
  background: transparent;
  border-color: var(--rule-0);
  color: var(--ink-2);
}
.ghost-button:hover {
  background: var(--paper-3);
  border-color: var(--ink-3);
  color: var(--ink-0);
}

/* 纯文字按钮 */
.text-button {
  min-height: auto;
  padding: 6px var(--sp-2);
  border: 0;
  background: transparent;
  color: var(--seal);
  font-size: var(--fs-13);
  letter-spacing: 0.06em;
}
.text-button:hover { color: var(--seal-deep); text-decoration: underline; text-underline-offset: 3px; }
.text-button.danger { color: var(--danger); }
.text-button.danger:hover { color: #8d342c; }

/* 图标按钮 */
.icon-button {
  width: var(--h-sm);
  height: var(--h-sm);
  min-height: var(--h-sm);
  padding: 0;
  border-radius: var(--r-2);
  border: 1px solid var(--rule-0);
  background: var(--paper-3);
  color: var(--ink-2);
  font-size: var(--fs-15);
  letter-spacing: 0;
}
.icon-button:hover { border-color: var(--seal); color: var(--seal); }

/* chip (筛选) */
.filter-chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: 14px;
  background: var(--paper-3);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.18s ease;
}
.filter-chip:hover { border-color: var(--seal); color: var(--seal); }
.filter-chip.active {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--paper-2);
}

/* 状态 pill / 标签 / 模块 pill */
.status-pill,
.tag,
.module-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 11px;
  font-family: var(--font-sans);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.status-pill {
  background: var(--jade-soft);
  color: var(--jade-deep);
  border: 1px solid rgba(63, 93, 75, 0.2);
}

.tag {
  background: var(--bronze-soft);
  color: var(--bronze);
  border: 1px solid rgba(138, 90, 35, 0.2);
}

.tag-protagonist {
  background: linear-gradient(135deg, #e57373 0%, #ef5350 100%);
  color: white;
  border-color: rgba(229, 115, 115, 0.5);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(229, 115, 115, 0.3);
}

.module-pill {
  background: var(--seal-soft);
  color: var(--seal-deep);
  border: 1px solid rgba(179, 50, 42, 0.22);
}

/* ---------- 8. 输入区(随手写入) ---------------------------------------- */

.title-input {
  margin-bottom: var(--sp-3);
  min-height: 44px;
  padding: 0 var(--sp-3);
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--paper-3);
}

.capture-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.helper-text {
  margin: var(--sp-3) 0 0;
  color: var(--ink-3);
  font-size: var(--fs-12);
  line-height: 1.7;
  font-family: var(--font-serif);
  letter-spacing: 0.04em;
}

/* ---------- 9. 工作台栅格 ----------------------------------------------- */

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(0, 7fr);
  gap: var(--sp-5);
  align-items: start;
}

.workspace-rail { grid-column: 1; display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.capture-panel { grid-column: 2; }

/* 工作台主区是一张可持续书写的记事纸 */
#workspaceView .capture-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 188px);
  padding: clamp(24px, 3vw, 48px);
  background:
    linear-gradient(90deg, transparent 0 46px, color-mix(in srgb, var(--seal) 18%, transparent) 46px 47px, transparent 47px),
    var(--paper-2);
}

#workspaceView .capture-panel .panel-heading,
#workspaceView .capture-panel > input,
#workspaceView .capture-panel > textarea,
#workspaceView .capture-panel .capture-actions,
#workspaceView .capture-panel .helper-text { margin-left: 30px; }

#workspaceView .capture-panel .title-input {
  min-height: 54px;
  border-width: 0 0 1px;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: var(--fs-20);
}

#workspaceView .capture-panel > textarea {
  flex: 1;
  min-height: 430px;
  padding: 12px 14px;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule-2) 31px 32px);
  background-attachment: local;
  box-shadow: none;
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  line-height: 32px;
  resize: none;
}

#workspaceView .capture-panel > textarea:focus { box-shadow: none; }

/* 统计卡 — 工整 2×2 */
.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.stats-panel::before { inset: 4px; }

.stat-card {
  display: grid;
  align-content: center;
  gap: var(--sp-2);
  min-height: 76px;
  padding: var(--sp-3);
  background: transparent;
  position: relative;
}

.stat-card + .stat-card { border-left: 1px solid var(--rule-2); }
.stat-card:nth-child(n + 3) { border-top: 1px solid var(--rule-2); }

.stat-card span {
  color: var(--ink-3);
  font-size: var(--fs-12);
  font-family: var(--font-serif);
  letter-spacing: 0.12em;
}

.stat-card strong {
  font-family: var(--font-serif);
  font-size: var(--fs-24);
  font-weight: 600;
  line-height: 1;
  color: var(--ink-0);
  letter-spacing: 0.04em;
}

.review-panel, .timeline-panel { min-height: 0; padding: var(--sp-3); overflow: hidden; }
#workspaceView .review-panel .panel-heading,
#workspaceView .timeline-panel .panel-heading { margin-bottom: var(--sp-3); padding-bottom: var(--sp-2); align-items: center; }
#workspaceView .review-panel .panel-heading h2,
#workspaceView .timeline-panel .panel-heading h2 { font-size: var(--fs-16); letter-spacing: .06em; }
#workspaceView .review-panel .eyebrow,
#workspaceView .timeline-panel .eyebrow { display: none; }
#workspaceView .suggestion-list,
#workspaceView .activity-list { max-height: 230px; overflow-y: auto; gap: var(--sp-2); padding-right: 3px; }
#workspaceView .suggestion-card,
#workspaceView .activity-card { gap: 4px; padding: var(--sp-2) var(--sp-3); }
#workspaceView .activity-card strong { font-size: var(--fs-12); line-height: 1.45; }
#workspaceView .activity-card p { margin: 0; font-size: var(--fs-10); }
#workspaceView .review-panel .empty-state,
#workspaceView .timeline-panel .empty-state { min-height: 100px; padding: var(--sp-3); }

/* ---------- 10. 列表与卡片(收件箱 / 资料库 / 建议 / 活动) ------------- */

.suggestion-list,
.activity-list,
.note-list,
.chapter-list,
.reference-list,
.analyze-button-wrapper {
  display: grid;
  gap: var(--sp-3);
}

.library-list {
  display: grid;
  gap: var(--sp-3);
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  margin: 0;
}

.note-card,
.suggestion-card,
.activity-card,
.library-card,
.chapter-card,
.reference-card {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border: 1px solid var(--rule-0);
  border-left: 3px solid var(--rule-1);
  border-radius: var(--r-2);
  background: var(--paper-3);
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.note-card,
.chapter-card,
.module-tab { cursor: pointer; }

.note-card:hover,
.chapter-card:hover,
.module-tab:hover {
  border-color: var(--rule-1);
  border-left-color: var(--seal);
}

.note-card.selected,
.chapter-card.active,
.module-tab.active {
  border-color: var(--rule-1);
  border-left-color: var(--seal);
  background: var(--paper-2);
  box-shadow: var(--shadow-1);
}

/* 卷章结构 */
.book-part {
  margin-bottom: var(--sp-3);
  background: var(--paper-2);
  border-radius: var(--r-3);
  border: 1px solid var(--rule-0);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.book-part-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: linear-gradient(135deg, var(--paper-3) 0%, var(--paper-2) 100%);
  cursor: pointer;
  transition: all 0.25s ease;
  border-bottom: 1px solid var(--rule-0);
}

.book-part-header:hover {
  background: linear-gradient(135deg, var(--paper-4) 0%, var(--paper-3) 100%);
}

.book-part-header:hover .part-expand-icon {
  color: var(--seal);
  transform: rotate(90deg);
}

.part-expand-icon {
  font-size: var(--fs-11);
  color: var(--ink-3);
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.part-icon {
  font-size: var(--fs-16);
  flex-shrink: 0;
}

.part-title {
  flex: 1;
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--ink-0);
  letter-spacing: 0.02em;
}

.part-word-count {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 500;
  margin-right: var(--sp-2);
  flex-shrink: 0;
}

.part-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  background: none;
  border: none;
  padding: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.book-part-header:hover .part-actions {
  opacity: 1;
}

.part-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--paper-1);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  font-size: var(--fs-13);
  cursor: pointer;
  transition: all 0.2s ease;
}

.part-action-btn:hover {
  background: var(--seal-soft);
  border-color: var(--seal);
  transform: translateY(-1px);
}

.book-part-content {
  padding: 0;
}

.book-part-content.collapsed {
  display: none;
}

.book-part-content .chapter-card {
  padding: var(--sp-3) var(--sp-4) var(--sp-3) calc(var(--sp-4) + 24px);
  border-radius: 0;
  border-left: 3px solid transparent;
  border-right: none;
  border-top: none;
  border-bottom: 1px solid var(--rule-0);
  transition: all 0.2s ease;
}

.book-part-content .chapter-card:hover {
  background: var(--paper-3);
  border-left-color: var(--seal);
}

.book-part-content .chapter-card.active {
  background: var(--seal-soft);
  border-left-color: var(--seal);
  box-shadow: inset 0 0 0 1px var(--seal);
}

.book-part-content .chapter-card:last-child {
  border-bottom: none;
}

/* 未分类章节样式 */
.book-part.orphan-part .book-part-header {
  background: linear-gradient(135deg, var(--paper-2) 0%, var(--paper-1) 100%);
}

.book-part.orphan-part .part-icon {
  opacity: 0.6;
}

/* 卡片头(标题 + 状态) */
.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
}

.card-title-row strong {
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-0);
  letter-spacing: 0.03em;
}

.card-title-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.favorite-btn {
  font-size: var(--fs-16);
  color: var(--ink-4);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--r-1);
  transition: color 0.18s ease, background 0.18s ease;
}

.favorite-btn:hover {
  color: #f59e0b;
  background: var(--paper-4);
}

.favorite-btn.active {
  color: #f59e0b;
}

.card-text {
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  line-height: 1.85;
  color: var(--ink-1);
  white-space: pre-wrap;
  letter-spacing: 0.02em;
}

.muted { color: var(--ink-3); }
.small { font-size: var(--fs-12); }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--rule-2);
}

/* ---------- 11. 收件箱 / 双栏 ------------------------------------------- */

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--sp-5);
  align-items: start;
}

.detail-panel {
  align-self: start;
  position: sticky;
  top: var(--sp-7);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: var(--sp-7);
  border: 1px dashed var(--rule-0);
  border-radius: var(--r-2);
  color: var(--ink-3);
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  letter-spacing: 0.06em;
  text-align: center;
  background: transparent;
}

/* ---------- 12. 资料库 -------------------------------------------------- */

.library-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

.module-tabs {
  display: grid;
  align-content: start;
  gap: 2px;
  padding: var(--sp-4);
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.module-tab-wrapper { position: relative; }

.library-favorite-toggle {
  margin-top: var(--sp-4);
  padding: var(--sp-4);
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
}

/* 资料库二级导航 */
.library-subnav {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--rule-0);
}

.library-tab {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--ink-2);
  transition: all 0.18s ease;
}

.library-tab:hover {
  background: var(--paper-2);
  color: var(--ink-1);
}

.library-tab.active {
  background: var(--paper-3);
  border-color: var(--rule-0);
  color: var(--ink-0);
}

.library-tab-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--seal);
  color: var(--paper-0);
  font-size: var(--fs-12);
  font-weight: 600;
  border-radius: var(--r-1);
}

.library-pane {
  display: none;
}

#libraryView.active #outlinePane {
  display: block;
}

#libraryView.active #cardsPane {
  display: none;
}

.library-tab.active[data-id="outline"] ~ #outlinePane {
  display: block;
}

.library-tab.active[data-id="cards"] ~ #cardsPane {
  display: block;
}

#libraryView.active .library-tab.active[data-id="outline"] ~ #outlinePane,
#libraryView.active .library-tab.active[data-id="cards"] ~ #cardsPane {
  display: block;
}

/* 大纲列表页面 */
.outline-list-page {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.outline-list-page .page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--rule-0);
}

.outline-list-page .page-header h1 {
  font-size: var(--fs-28);
  font-family: var(--font-serif);
}

.outline-list-page .eyebrow {
  font-size: var(--fs-12);
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.outline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-4);
}

.outline-card {
  display: flex;
  flex-direction: column;
  padding: var(--sp-5);
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  cursor: pointer;
  transition: all 0.2s ease;
  height: 100%;
}

.outline-card:hover {
  border-color: var(--seal);
  box-shadow: 0 4px 12px var(--shadow-2);
  transform: translateY(-2px);
}

.outline-card-header {
  margin-bottom: var(--sp-3);
}

.outline-card-header strong {
  display: block;
  font-size: var(--fs-17);
  font-weight: 600;
  color: var(--ink-0);
  font-family: var(--font-serif);
  margin-bottom: 6px;
}

.outline-card-meta {
  display: flex;
  gap: var(--sp-3);
  font-size: var(--fs-12);
  color: var(--ink-4);
}

.outline-card-content {
  flex: 1;
  font-size: var(--fs-14);
  color: var(--ink-2);
  line-height: 1.7;
  margin-bottom: var(--sp-4);
}

.outline-card-footer {
  display: flex;
  justify-content: flex-end;
}

.outline-card-arrow {
  font-size: var(--fs-18);
  color: var(--ink-4);
  transition: color 0.2s ease;
}

.outline-card:hover .outline-card-arrow {
  color: var(--seal);
}

/* 大纲详情页面 */
.outline-detail-page {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.outline-detail-page .page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--rule-0);
}

.back-button {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: transparent;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  font-size: var(--fs-14);
  color: var(--ink-2);
  transition: all 0.18s ease;
}

.back-button:hover {
  background: var(--paper-2);
  border-color: var(--ink-3);
  color: var(--ink-0);
}

.back-arrow {
  font-size: var(--fs-16);
}

.outline-actions {
  display: flex;
  gap: var(--sp-2);
}

.outline-content-area {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.outline-title-input {
  width: 100%;
  font-size: var(--fs-28);
  font-weight: 600;
  font-family: var(--font-serif);
  padding: var(--sp-3) var(--sp-4);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--rule-0);
  border-radius: 0;
  transition: border-color 0.18s ease;
}

.outline-title-input:focus {
  border-color: var(--seal);
  box-shadow: none;
}

.outline-content {
  width: 100%;
  min-height: 180px;
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  line-height: 1.85;
}

.outline-acts-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.outline-acts-section .section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.outline-acts-section h3 {
  font-size: var(--fs-18);
  font-family: var(--font-serif);
}

.outline-acts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.act-section {
  padding: var(--sp-5);
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
}

.act-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-4);
}

.act-title-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.act-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--ink-0);
  color: var(--paper-0);
  font-size: var(--fs-14);
  font-weight: 600;
  border-radius: 50%;
}

.act-title-input {
  flex: 1;
  font-size: var(--fs-18);
  font-weight: 600;
  font-family: var(--font-serif);
  padding: var(--sp-3) var(--sp-4);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule-0);
  border-radius: 0;
}

.act-title-input:focus {
  border-color: var(--seal);
  box-shadow: none;
}

.act-actions {
  display: flex;
  gap: var(--sp-2);
}

.act-description {
  width: 100%;
  min-height: 100px;
  margin-bottom: var(--sp-4);
  font-size: var(--fs-15);
}

.scene-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  padding-left: var(--sp-6);
  border-left: 3px solid var(--rule-0);
}

.scene-item {
  padding: var(--sp-4);
  background: var(--paper-3);
  border-radius: var(--r-2);
}

.scene-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.scene-number {
  font-size: var(--fs-12);
  color: var(--ink-4);
  font-family: var(--font-mono);
  font-weight: 500;
}

.scene-title-input {
  flex: 1;
  font-size: var(--fs-15);
  font-weight: 500;
  padding: var(--sp-2) var(--sp-3);
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--rule-0);
  border-radius: 0;
}

.scene-title-input:focus {
  border-color: var(--seal);
  box-shadow: none;
}

.scene-desc-input,
.scene-keypoint-input {
  width: 100%;
  font-size: var(--fs-14);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.scene-desc-input {
  background: var(--paper-4);
}

.scene-keypoint-input {
  background: var(--seal-soft);
  border-color: var(--seal);
}

.empty-scenes,
.empty-acts {
  padding: var(--sp-8);
  text-align: center;
  color: var(--ink-4);
  font-size: var(--fs-14);
  background: var(--paper-3);
  border-radius: var(--r-2);
}

/* 新建大纲按钮 */
#newOutlineButton {
  white-space: nowrap;
}

.favorite-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
  padding: var(--sp-2);
  border-radius: var(--r-2);
  transition: background 0.18s ease;
}

.favorite-toggle:hover {
  background: var(--paper-3);
}

.favorite-toggle input[type="checkbox"] {
  display: none;
}

.favorite-toggle-icon {
  font-size: var(--fs-18);
  color: var(--ink-4);
  transition: color 0.18s ease;
}

.favorite-toggle input[type="checkbox"]:checked + span.favorite-toggle-icon {
  color: #f59e0b !important;
}

.favorite-toggle-label {
  font-size: var(--fs-14);
  color: var(--ink-2);
  font-weight: 500;
}

.favorite-toggle-count {
  margin-left: auto;
  font-size: var(--fs-12);
  color: var(--ink-4);
  background: var(--paper-4);
  padding: 2px 8px;
  border-radius: var(--r-full);
}

.module-tab {
  display: grid;
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  border-radius: var(--r-2);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.module-tab:hover {
  background: var(--paper-3);
  border-left-color: var(--rule-1);
}

.module-tab.active {
  background: var(--paper-3);
  border-color: var(--rule-1);
  border-left-color: var(--seal);
}

.module-tab strong {
  display: block;
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--ink-0);
  letter-spacing: 0.06em;
}

.module-tab span {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-12);
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

.module-tab-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.module-tab-wrapper:hover .module-tab-actions { opacity: 1; }

.module-tab-actions .icon-button {
  width: 26px; height: 26px; min-height: 26px;
  font-size: var(--fs-12);
  background: var(--paper-2);
}

.module-tab.add-module {
  border: 1px dashed var(--rule-1);
  border-left: 1px dashed var(--rule-1);
  color: var(--ink-3);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.08em;
  min-height: var(--h-md);
  display: grid;
  place-items: center;
  margin-top: var(--sp-2);
}

.module-tab.add-module:hover {
  border-color: var(--seal);
  color: var(--seal);
  background: var(--seal-soft);
}

.reference-filter,
.reference-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: var(--sp-3);
  margin-bottom: var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
}

.analyze-button-wrapper .secondary-button {
  width: 100%;
  justify-content: center;
}

/* ---------- 13. 书库布局 / 书卡 ---------------------------------------- */

.books-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--sp-5);
  align-items: start;
}

.book-detail-panel {
  position: sticky;
  top: var(--sp-7);
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-4);
}

.book-card {
  display: grid;
  grid-template-rows: 140px 1fr;
  overflow: hidden;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.book-card:hover {
  border-color: var(--seal);
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.book-card.active {
  border-color: var(--seal);
  box-shadow: 0 0 0 2px var(--seal-soft), var(--shadow-2);
}

.book-cover {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--paper-2);
  font-family: var(--font-serif);
  font-size: var(--fs-40);
  font-weight: 600;
  overflow: hidden;
  position: relative;
}

.book-cover::after {
  /* 古籍书脊金线 */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(to right, transparent, var(--bronze), transparent);
  opacity: 0.5;
}

.book-cover-image { width: 100%; height: 100%; object-fit: cover; }
.book-cover-color { display: grid; place-items: center; width: 100%; height: 100%; }

.all-books-cover {
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-deep) 100%);
}
.all-books-icon { font-size: var(--fs-32); }
.all-books-detail-cover {
  font-size: var(--fs-40);
  background: linear-gradient(135deg, var(--jade) 0%, var(--jade-deep) 100%);
  color: var(--paper-2);
}

.book-info {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-4);
}

.book-info strong {
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  font-weight: 600;
  color: var(--ink-0);
  letter-spacing: 0.06em;
  line-height: 1.35;
}

.book-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.book-metric {
  display: grid;
  gap: 2px;
  padding: var(--sp-2);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-1);
  background: var(--paper-2);
  text-align: center;
}

.book-metric span {
  color: var(--ink-3);
  font-size: var(--fs-11);
  letter-spacing: 0.06em;
}

.book-metric b {
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  font-weight: 600;
  line-height: 1;
  color: var(--ink-0);
}

/* 书库右侧 — 当前作品详情 */
.book-detail { display: grid; gap: var(--sp-4); }

.book-detail-header {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: var(--sp-4);
  align-items: center;
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--rule-2);
  position: relative;
}

.book-detail-cover-wrapper {
  position: relative;
  width: 84px;
  height: 112px;
  border-radius: var(--r-2);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.book-detail-cover-image { width: 100%; height: 100%; object-fit: cover; }

.book-detail-cover-color {
  display: grid;
  place-items: center;
  width: 100%; height: 100%;
  color: var(--paper-2);
  font-family: var(--font-serif);
  font-size: var(--fs-32);
  font-weight: 600;
}

.cover-upload-button,
.cover-remove-button {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border: 0;
  border-radius: 11px;
  font-size: var(--fs-11);
  letter-spacing: 0.04em;
  color: var(--paper-2);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s ease, background 0.18s ease;
}

.book-detail-cover-wrapper:hover .cover-upload-button,
.book-detail-cover-wrapper:hover .cover-remove-button { opacity: 1; }

.cover-upload-button { bottom: 6px; right: 6px; background: rgba(28, 22, 18, 0.78); }
.cover-upload-button:hover { background: rgba(28, 22, 18, 0.92); }
.cover-upload-button input { display: none; }

.cover-remove-button { bottom: 6px; left: 6px; background: rgba(168, 71, 60, 0.85); }
.cover-remove-button:hover { background: rgba(168, 71, 60, 1); }

.book-detail-title { display: grid; gap: var(--sp-2); min-width: 0; }
.book-detail-title h2 {
  font-family: var(--font-serif);
  font-size: var(--fs-22);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-0);
}

.book-title-input {
  min-height: 34px;
  padding: 0 var(--sp-2);
  border: 1px dashed var(--rule-1);
  background: transparent;
  font-family: var(--font-serif);
  font-size: var(--fs-22);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-0);
}

.book-edit-section,
.book-stats-section,
.book-nav-section,
.book-chapters-section,
.book-actions-section {
  display: grid;
  gap: var(--sp-3);
}

.edit-form { display: grid; gap: var(--sp-3); }

.book-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  overflow: hidden;
  background: var(--paper-2);
}

.stat-item {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
}
.stat-item + .stat-item { border-left: 1px solid var(--rule-2); }

.stat-item strong {
  font-family: var(--font-serif);
  font-size: var(--fs-20);
  font-weight: 600;
  color: var(--ink-0);
  line-height: 1;
}

.stat-item span {
  font-size: var(--fs-11);
  color: var(--ink-3);
  letter-spacing: 0.12em;
}

.book-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  overflow: hidden;
}

.book-metrics-grid .stat-item:nth-child(2n) { border-left: 1px solid var(--rule-2); }
.book-metrics-grid .stat-item:nth-child(n + 3) { border-top: 1px solid var(--rule-2); }

.nav-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
}

.nav-card {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: var(--paper-3);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.nav-card:hover { border-color: var(--seal); background: var(--paper-2); }

.nav-icon { font-family: var(--font-serif); color: var(--bronze); text-align: center; }

.nav-text {
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  color: var(--ink-1);
  letter-spacing: 0.04em;
}

.nav-count {
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  color: var(--ink-3);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--rule-2);
}

.section-header h3,
.section-header > span:first-child {
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink-2);
}

.chapter-list-preview {
  display: grid;
  gap: 2px;
}

.mini-chapter-card {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: var(--sp-2);
  align-items: center;
  padding: 6px var(--sp-2);
  border-radius: var(--r-1);
  font-size: var(--fs-13);
  cursor: pointer;
  transition: background 0.15s ease;
}

.mini-chapter-card:hover { background: var(--seal-soft); }

.mini-chapter-card .chapter-order {
  font-family: var(--font-serif);
  color: var(--bronze);
  text-align: center;
}

.mini-chapter-card .chapter-title {
  font-family: var(--font-serif);
  color: var(--ink-1);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
}

.mini-chapter-card .chapter-words {
  font-size: var(--fs-11);
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

/* ---------- 14. 写作视图 ----------------------------------------------- */

.writing-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  gap: var(--sp-5);
  height: 100%;
  min-height: 0;
  align-items: stretch;
}

.chapter-list-panel,
.reference-panel { overflow: auto; }

.editor-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  padding: 0;
  background: var(--paper-2);
}

.editor-panel::before { inset: 4px; }

/* 编辑器章节标题 — 与 mini-chapter 同名但样式独立 */
.editor-panel .chapter-title,
input.chapter-title {
  position: relative;
  z-index: 1;
  border: 0;
  border-bottom: 1px solid var(--rule-0);
  border-radius: 0;
  min-height: 64px;
  padding: 0 var(--sp-6);
  background: transparent;
  font-family: var(--font-serif);
  font-size: var(--fs-22);
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-0);
}

.editor-panel .chapter-title:focus,
input.chapter-title:focus {
  box-shadow: none;
  border-bottom-color: var(--seal);
}

.editor-wrapper {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.chapter-body {
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: var(--sp-6) var(--sp-7);
  margin: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(2em - 1px),
      var(--rule-2) calc(2em - 1px),
      var(--rule-2) 2em
    ),
    var(--paper-2);
  font-family: var(--font-serif);
  font-size: var(--fs-16);
  line-height: 2;
  color: var(--ink-0);
  letter-spacing: 0.04em;
  box-sizing: border-box;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-ligatures: none;
  tab-size: 4;
  overflow-y: auto;
  outline: none;
  cursor: text;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chapter-body:empty:before {
  content: attr(data-placeholder);
  color: var(--ink-4);
  pointer-events: none;
}

.chapter-body:focus {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(2em - 1px),
      var(--rule-2) calc(2em - 1px),
      var(--rule-2) 2em
    ),
    var(--paper-3);
}

.chapter-body p {
  margin: 0 0 1.5em 0;
  padding: 0;
}

.chapter-body p:last-child {
  margin-bottom: 0;
}

.chapter-body .highlight-term {
  background: rgba(245, 158, 11, 0.35);
  color: inherit;
  border-radius: 3px;
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
  padding: 0 2px;
}

.chapter-body .highlight-term::selection {
  background: var(--seal);
  color: var(--paper-2);
}

.chapter-body:focus {
  box-shadow: none;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(2em - 1px),
      var(--rule-2) calc(2em - 1px),
      var(--rule-2) 2em
    ),
    var(--paper-3);
}

.editor-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-6);
  border-top: 1px solid var(--rule-0);
  background: var(--paper-1);
  color: var(--ink-3);
  font-family: var(--font-serif);
  font-size: var(--fs-12);
  letter-spacing: 0.1em;
}

.reference-card mark {
  background: rgba(138, 90, 35, 0.22);
  color: inherit;
}

.reference-card {
  cursor: pointer;
}

.reference-card:hover {
  border-color: var(--accent);
  background: var(--paper-2);
}

.reference-card.highlighted {
  border-color: #f59e0b;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(245, 158, 11, 0.02) 100%);
  box-shadow: 
    0 0 0 1px rgba(245, 158, 11, 0.3),
    0 0 20px rgba(245, 158, 11, 0.15);
}

.reference-card.highlighted .card-title-row strong {
  color: #f59e0b;
  text-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.highlight-indicator {
  font-size: var(--fs-14);
  color: #f59e0b;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.reference-card.highlighted .highlight-indicator {
  opacity: 1;
}

/* ---------- 15. 弹窗 / 表单 -------------------------------------------- */

.modal {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-4);
  background: var(--paper-2);
  box-shadow: var(--shadow-3);
  color: var(--ink-0);
  position: relative;
}

.modal.wide { width: min(760px, calc(100vw - 32px)); }

.modal::backdrop {
  background: rgba(28, 22, 18, 0.42);
  backdrop-filter: blur(3px);
}

.modal form {
  position: relative;
  z-index: 1;
  display: grid;
  gap: var(--sp-4);
  padding: var(--sp-6);
}

/* 弹窗里直接是 grid 子元素的按钮不应拉满 */
.modal form > .primary-button,
.modal form > .secondary-button,
.modal form > .ghost-button {
  justify-self: end;
  min-width: 96px;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
  position: relative;
  margin-bottom: 0;
}

.modal h2 {
  font-family: var(--font-serif);
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-0);
}

.modal-heading .icon-button {
  border: 1px solid var(--rule-2);
  background: transparent;
  font-size: var(--fs-15);
  color: var(--ink-3);
}

.modal-body { display: grid; gap: var(--sp-4); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--rule-2);
}

.modal label,
.form-group label,
.form-group {
  display: grid;
  gap: 6px;
  color: var(--ink-2);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  font-weight: 600;
  letter-spacing: 0.1em;
}

.modal input,
.modal textarea,
.modal select {
  color: var(--ink-0);
  font-size: var(--fs-15);
  font-weight: 400;
  letter-spacing: 0;
  font-family: var(--font-sans);
}

.modal textarea {
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  letter-spacing: 0.03em;
}

.modal input { min-height: var(--h-md); padding: 0 var(--sp-3); }

.note-edit-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.note-title-input {
  width: 100%;
  min-height: var(--h-lg);
  padding: var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-serif);
  font-size: var(--fs-18);
  font-weight: 600;
  color: var(--ink-0);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.note-title-input:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.note-title-input:read-only {
  background: transparent;
  border: none;
  padding: 0;
}

.note-content-input {
  width: 100%;
  min-height: 120px;
  padding: var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  line-height: 1.7;
  color: var(--ink-1);
  resize: vertical;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.note-content-input:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.note-content-input:read-only {
  background: transparent;
  border: none;
  padding: 0;
  resize: none;
  min-height: auto;
}

.note-book-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.note-book-select {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  color: var(--ink-1);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.note-book-select:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.note-book-select:disabled {
  display: none;
}

.note-module-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.module-label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.note-module-select {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  color: var(--ink-1);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.note-module-select:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.note-module-select:disabled {
  display: none;
}

.note-tags-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tags-label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.note-tags-input {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  color: var(--ink-1);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.note-tags-input:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.note-tags-input:read-only {
  display: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--seal);
  cursor: pointer;
}

.checkbox-label span:first-of-type {
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  color: var(--ink-1);
  letter-spacing: 0.04em;
}

.checkbox-hint {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 400;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: var(--sp-3);
}

.close-button {
  width: 32px; height: 32px;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-15);
  cursor: pointer;
}
.close-button:hover { color: var(--seal); border-color: var(--seal); }

/* 裁剪器 */
.crop-container { padding: var(--sp-5); display: grid; gap: var(--sp-4); }
.crop-area { display: grid; gap: var(--sp-3); }
.crop-frame {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  overflow: hidden;
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-2);
  background: var(--paper-0);
}
.crop-frame img {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  pointer-events: auto;
  cursor: grab;
}
.crop-frame img:active { cursor: grabbing; }
.crop-hint { text-align: center; color: var(--ink-3); font-size: var(--fs-12); }
.crop-controls { display: grid; gap: var(--sp-3); }
.crop-controls input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--rule-0);
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  padding: 0;
}
.crop-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  background: var(--seal);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--paper-2);
}
.crop-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* 自动识别的外部链接 */
.ext-link {
  color: var(--seal);
  text-decoration: underline;
  text-decoration-color: var(--rule-1);
  text-underline-offset: 2px;
  word-break: break-all;
  cursor: pointer;
}
.ext-link:hover { text-decoration-color: var(--seal); }
.ext-link:visited { color: var(--seal); }

/* ---------- 16. Toast --------------------------------------------------- */

.toast {
  position: fixed;
  right: var(--sp-6);
  bottom: var(--sp-6);
  z-index: 50;
  max-width: min(420px, calc(100vw - 48px));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--r-2);
  background: var(--ink-0);
  color: var(--paper-2);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-3);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { transform: translateY(0); opacity: 1; pointer-events: auto; }

.toast .toast-action {
  margin-left: var(--sp-3);
  padding: 2px 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--r-1);
  background: transparent;
  color: var(--paper-0);
  font-family: inherit;
  font-size: var(--fs-12);
  letter-spacing: 0.08em;
  cursor: pointer;
  min-height: 28px;
}

.toast .toast-action:hover {
  background: rgba(255, 255, 255, 0.12);
}

.backup-item .backup-actions {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

/* ---------- 关系图谱：交互升级 ---------- */

.relation-graph {
  touch-action: none;
  cursor: grab;
}

.relation-graph:active {
  cursor: grabbing;
}

.relation-node-group {
  cursor: pointer;
}

.edge-label {
  font-size: 12px;
  fill: var(--ink-1, #44403c);
  paint-order: stroke;
  stroke: var(--paper-0, #f7f3ea);
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}

.relation-edge {
  cursor: pointer;
}

.relation-node-group,
.relation-edge {
  transition: opacity 0.15s ease;
}

.relation-node-group.dimmed {
  opacity: 0.15;
}

.relation-edge.dimmed {
  opacity: 0.12;
}

.relation-module-filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
}

.module-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(120, 90, 50, 0.25);
  background: transparent;
  cursor: pointer;
  font-size: var(--fs-12);
  opacity: 0.45;
}

.module-chip.active {
  opacity: 1;
  background: rgba(120, 90, 50, 0.08);
}

.relation-zoom-controls {
  position: absolute;
  right: var(--sp-3);
  top: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  z-index: 5;
}

.zoom-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-2);
  border: 1px solid rgba(120, 90, 50, 0.25);
  background: var(--paper-0, #f7f3ea);
  font-size: var(--fs-16);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(60, 42, 22, 0.1);
}

.zoom-btn:hover {
  background: rgba(120, 90, 50, 0.08);
}

.connect-mode-banner {
  position: absolute;
  left: 50%;
  top: var(--sp-3);
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-radius: 999px;
  background: var(--ink-0, #292524);
  color: var(--paper-2, #e7e0d2);
  font-size: var(--fs-13);
  z-index: 6;
  box-shadow: var(--shadow-3, 0 4px 16px rgba(0,0,0,0.2));
}

.connect-mode-banner.show {
  display: inline-flex;
}

.connect-mode-banner .text-button {
  color: var(--paper-0, #f7f3ea);
  text-decoration: underline;
}

.tooltip-note-row {
  margin-top: var(--sp-2);
}

.tooltip-note-input {
  width: 100%;
  resize: vertical;
  font-size: var(--fs-12);
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid rgba(120, 90, 50, 0.25);
  border-radius: var(--r-1);
  background: var(--paper-0, #f7f3ea);
}

.tooltip-actions {
  display: flex;
  gap: var(--sp-2);
}

.tooltip-actions-secondary button {
  flex: 1;
  min-height: 32px;
  font-size: var(--fs-12);
  border: 1px solid rgba(120, 90, 50, 0.25);
  border-radius: var(--r-1);
  background: transparent;
  cursor: pointer;
  padding: 4px 8px;
}

.tooltip-actions-secondary button:hover {
  background: rgba(120, 90, 50, 0.08);
}

.ai-extract-results {
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--sp-3);
}

.ai-extract-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-bottom: 1px solid rgba(120, 90, 50, 0.12);
  cursor: pointer;
}

.ai-extract-row:hover {
  background: rgba(120, 90, 50, 0.05);
}

.ai-extract-row input[type="checkbox"] {
  margin-top: 4px;
  width: 18px;
  height: 18px;
}

.ai-extract-text {
  font-size: var(--fs-13);
  line-height: 1.5;
}

.ai-extract-rel {
  color: #b45309;
  margin: 0 4px;
  white-space: nowrap;
}

.ai-extract-evidence {
  display: block;
  color: rgba(68, 64, 60, 0.65);
  font-size: var(--fs-12);
}

/* ---------- AI 对话 ---------- */

.ai-chat-fab {
  position: fixed;
  right: 24px;
  bottom: 88px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(120, 90, 50, 0.3);
  background: var(--ink-0, #292524);
  color: var(--paper-0, #f7f3ea);
  font-size: 22px;
  cursor: pointer;
  z-index: 150;
  box-shadow: 0 4px 16px rgba(60, 42, 22, 0.3);
  transition: transform 0.2s ease;
}

.ai-chat-fab:hover {
  transform: scale(1.08);
}

.ai-chat-fab.hidden {
  display: none;
}

.ai-chat-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(400px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 32px));
  display: none;
  flex-direction: column;
  background: var(--paper-0, #f7f3ea);
  border: 1px solid rgba(120, 90, 50, 0.3);
  border-radius: var(--r-3, 12px);
  box-shadow: 0 12px 48px rgba(60, 42, 22, 0.28);
  z-index: 160;
  overflow: hidden;
}

.ai-chat-panel.open {
  display: flex;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid rgba(120, 90, 50, 0.18);
  background: rgba(120, 90, 50, 0.05);
}

.ai-chat-tabs {
  display: flex;
  gap: var(--sp-1);
}

.ai-chat-tab {
  min-height: 34px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: var(--fs-13);
  color: var(--ink-2, #57534e);
}

.ai-chat-tab.active {
  background: var(--ink-0, #292524);
  color: var(--paper-0, #f7f3ea);
}

.ai-chat-tools {
  display: flex;
  gap: var(--sp-1);
}

.ai-roleplay-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid rgba(120, 90, 50, 0.14);
  font-size: var(--fs-13);
}

.ai-roleplay-bar select {
  flex: 1;
  min-height: 36px;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.ai-chat-empty {
  margin: auto;
  max-width: 80%;
  text-align: center;
  color: rgba(68, 64, 60, 0.55);
  font-size: var(--fs-13);
  line-height: 1.7;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.ai-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.ai-msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.ai-msg-bubble {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-2, 8px);
  font-size: var(--fs-13);
  line-height: 1.7;
  word-break: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--ink-0, #292524);
  color: var(--paper-0, #f7f3ea);
}

.ai-msg-assistant .ai-msg-bubble {
  background: rgba(120, 90, 50, 0.08);
  color: var(--ink-1, #44403c);
}

.ai-typing {
  opacity: 0.6;
  font-style: italic;
}

.ai-msg-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: 2px;
}

.ai-chat-input-row {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid rgba(120, 90, 50, 0.18);
  background: rgba(120, 90, 50, 0.04);
}

.ai-chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid rgba(120, 90, 50, 0.25);
  border-radius: var(--r-2, 8px);
  padding: var(--sp-2);
  font-size: var(--fs-13);
  background: var(--paper-0, #f7f3ea);
}

.ai-chat-input-row .primary-button {
  align-self: flex-end;
  min-height: 40px;
}

/* 写作协作 */

.ai-write-entry {
  min-height: 32px;
  font-size: var(--fs-12);
}

.ai-write-context {
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
  border-left: 3px solid rgba(120, 90, 50, 0.35);
  background: rgba(120, 90, 50, 0.06);
  font-size: var(--fs-12);
  line-height: 1.6;
  color: var(--ink-2, #57534e);
  max-height: 120px;
  overflow-y: auto;
}

.ai-write-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.ai-write-action {
  min-height: 36px;
  padding: 6px 16px;
  cursor: pointer;
}

.ai-write-custom-row {
  display: flex;
  gap: var(--sp-2);
}

.ai-write-custom-row input {
  flex: 1;
}

#aiWriteResult,
#dlgResult {
  width: 100%;
  font-size: var(--fs-13);
  line-height: 1.7;
}

/* 生成对白 */

.dlg-char-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.dlg-char-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid rgba(120, 90, 50, 0.25);
  border-radius: 999px;
  font-size: var(--fs-13);
  cursor: pointer;
}

.dlg-char-item input {
  width: 16px;
  height: 16px;
}

@media screen and (max-width: 768px) {
  .ai-chat-fab {
    bottom: 76px;
    right: 16px;
  }

  .ai-chat-panel {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    height: min(560px, calc(100vh - 80px));
  }
}

/* ---------- 外观与个性化设置 ---------- */

.appearance-group {
  margin-bottom: var(--sp-4);
  min-width: 0;
}

.appearance-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}

.appearance-label {
  font-size: var(--fs-13);
  color: var(--ink-2);
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}

.appearance-label strong {
  color: var(--ink-0);
  font-size: var(--fs-13);
}

.appearance-divider {
  margin: var(--sp-5) 0 var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px dashed var(--rule-2);
  font-size: var(--fs-12);
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

/* 主题卡片 */
.theme-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--sp-3);
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-2);
  border: 1.5px solid var(--rule-2);
  border-radius: var(--r-3);
  background: var(--paper-2);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.theme-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.theme-card.active {
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.theme-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 52px;
  padding: 7px 9px;
  border-radius: var(--r-2);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.theme-preview .tp-bar {
  width: 26px;
  height: 7px;
  border-radius: 2px;
}

.theme-preview .tp-line {
  width: 80%;
  height: 4px;
  border-radius: 2px;
  opacity: 0.5;
}

.theme-preview .tp-line.short { width: 55%; }

.theme-preview-xuan { background: #f7f1e1; }
.theme-preview-xuan .tp-bar { background: #b3322a; }
.theme-preview-xuan .tp-line { background: #5a4b3a; }

.theme-preview-moye { background: #161310; }
.theme-preview-moye .tp-bar { background: #d05a4e; }
.theme-preview-moye .tp-line { background: #a3967d; }

.theme-preview-qingzhu { background: #edf1e4; }
.theme-preview-qingzhu .tp-bar { background: #3f5d4b; }
.theme-preview-qingzhu .tp-line { background: #54624e; }

.theme-preview-yuebai { background: #eef0f3; }
.theme-preview-yuebai .tp-bar { background: #3a5a78; }
.theme-preview-yuebai .tp-line { background: #51606f; }

.theme-name {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink-0);
}

.theme-desc {
  font-size: var(--fs-11);
  color: var(--ink-3);
}

/* 强调色 */
.accent-swatches {
  display: flex;
  gap: var(--sp-3);
}

.accent-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.accent-swatch:hover {
  transform: scale(1.12);
}

.accent-swatch.active {
  box-shadow: 0 0 0 2px var(--paper-0), 0 0 0 4.5px var(--ink-0);
}

/* 界面字体方案 */
.font-preset-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.font-preset-card {
  display: grid;
  gap: var(--sp-3);
  min-height: 106px;
  padding: var(--sp-4);
  text-align: left;
  color: var(--ink-1);
  background: var(--paper-3);
  border: 1.5px solid var(--rule-2);
  border-radius: var(--r-3);
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.font-preset-card:hover { transform: translateY(-2px); border-color: var(--rule-1); box-shadow: var(--shadow-1); }
.font-preset-card.active { border-color: var(--seal); box-shadow: 0 0 0 3px var(--seal-soft); }
.font-preset-sample { font-size: var(--fs-20); line-height: 1.4; color: var(--ink-0); }
.font-preset-literary .font-preset-sample { font-family: "Songti SC", "STSong", "SimSun", serif; }
.font-preset-clear .font-preset-sample { font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif; }
.font-preset-meta { display: grid; gap: 2px; }
.font-preset-meta strong { font-size: var(--fs-13); }
.font-preset-meta small { color: var(--ink-3); font-size: var(--fs-11); }

/* 分段选择器 */
.segmented {
  display: inline-flex;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  overflow: hidden;
  background: var(--paper-2);
}

.segment {
  min-height: 36px;
  padding: 4px 14px;
  border: none;
  background: transparent;
  font-size: var(--fs-13);
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}

.segment + .segment {
  border-left: 1px solid var(--rule-2);
}

.segment.active {
  background: var(--seal);
  color: #fff;
}

/* 滑杆 */
.appearance-group input[type="range"] {
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--seal);
}

/* ---------- 写作排版个性化（应用 --editor-* 变量） ---------- */

.chapter-body,
.focus-chapter-body {
  font-family: var(--editor-font-family, var(--font-serif));
  font-size: var(--editor-font-size, 17px);
  line-height: var(--editor-line-height, 1.9);
}

.chapter-body {
  max-width: var(--editor-max-width, none);
  margin-left: auto;
  margin-right: auto;
}

.focus-chapter-body {
  max-width: var(--editor-max-width, 720px);
  margin-left: auto;
  margin-right: auto;
}

/* ---------- 全局视觉打磨 ---------- */

::selection {
  background: var(--seal);
  color: #fff;
}

dialog.modal::backdrop {
  background: rgba(24, 18, 12, 0.45);
  backdrop-filter: blur(3px);
}

dialog.modal[open] {
  animation: modal-in 0.22s cubic-bezier(0.21, 0.8, 0.4, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.view.active {
  animation: view-in 0.26s ease;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.nav-item {
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease, transform 0.1s ease;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.segment:active,
.theme-card:active {
  transform: translateY(1px) scale(0.99);
}

.stat-card,
.book-card,
.suggestion-list > *,
.note-list > *,
.library-list > * {
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

@media (prefers-reduced-motion: reduce) {
  dialog.modal[open],
  .view.active {
    animation: none;
  }
}

@media screen and (max-width: 900px) {
  .appearance-row {
    grid-template-columns: 1fr;
    gap: 0;
  }
}

/* ---------- 选中浮动工具条（高亮笔 + AI 操作） ---------- */

.editor-bubble {
  position: fixed;
  z-index: 240;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: var(--r-3);
  border: 1px solid var(--rule-0);
  background: var(--paper-2);
  box-shadow: var(--shadow-3);
}

.editor-bubble.show {
  display: inline-flex;
  animation: bubble-in 0.14s ease;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.bubble-color {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.bubble-color:hover {
  transform: scale(1.18);
}

.bubble-color-clear {
  background: transparent;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1;
}

.bubble-sep {
  width: 1px;
  height: 18px;
  background: var(--rule-2);
  margin: 0 3px;
}

.bubble-btn {
  border: none;
  background: transparent;
  padding: 4px 8px;
  border-radius: var(--r-2);
  font-size: var(--fs-12);
  color: var(--ink-1);
  cursor: pointer;
  white-space: nowrap;
}

.bubble-btn:hover {
  background: var(--seal-soft);
  color: var(--seal);
}

/* ---------- AI 幽灵续写 ---------- */

.ai-ghost {
  color: var(--ink-3);
  background: var(--seal-soft);
  border-bottom: 1.5px dashed var(--seal);
  border-radius: 2px;
  padding: 0 2px;
}

.ai-ghost-bar {
  position: fixed;
  z-index: 240;
  display: flex;
  gap: var(--sp-2);
  padding: 6px;
  border-radius: var(--r-3);
  border: 1px solid var(--rule-0);
  background: var(--paper-2);
  box-shadow: var(--shadow-3);
}

.ai-ghost-bar button {
  min-height: 32px;
  font-size: var(--fs-12);
  padding: 2px 12px;
}

.ai-ghost-bar:not(.ready) button[data-ghost="accept"],
.ai-ghost-bar:not(.ready) button[data-ghost="retry"] {
  opacity: 0.4;
  pointer-events: none;
}

.ai-continue-entry {
  font-size: var(--fs-15);
  color: var(--seal);
}

.user-hl {
  border-radius: 2px;
  padding: 0 1px;
}

/* ---------- AI 搜索 ---------- */

.suggestion-ai {
  border-bottom: 1px solid var(--rule-2);
  background: var(--seal-soft);
}

.suggestion-ai .suggestion-title {
  color: var(--seal);
  font-weight: 600;
}

.ai-search-bar {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.ai-search-bar input {
  flex: 1;
}

.ai-search-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}

.ai-search-web {
  margin-left: auto;
  font-size: var(--fs-12);
  color: var(--ink-3);
  display: inline-flex;
  gap: var(--sp-2);
  align-items: center;
}

.ai-search-section-title {
  font-size: var(--fs-12);
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin: var(--sp-3) 0 var(--sp-2);
}

.ai-search-local {
  max-height: 320px;
  overflow-y: auto;
}

.ai-search-result {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-bottom: 1px solid var(--rule-2);
  cursor: pointer;
  min-height: var(--h-touch);
}

.ai-search-result:hover {
  background: var(--seal-soft);
}

.ai-search-badge {
  flex-shrink: 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--jade-soft);
  color: var(--jade);
  font-size: var(--fs-11);
  margin-top: 2px;
  white-space: nowrap;
}

.ai-search-result-main {
  min-width: 0;
  font-size: var(--fs-13);
  line-height: 1.5;
}

.ai-search-result-main em {
  font-style: normal;
  color: var(--ink-3);
  margin-left: var(--sp-2);
  font-size: var(--fs-12);
}

.ai-search-snippet {
  display: block;
  color: var(--ink-2);
  font-size: var(--fs-12);
}

.ai-search-aibox {
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  margin-bottom: var(--sp-2);
  background: var(--paper-3);
}

.ai-search-answer {
  font-size: var(--fs-13);
  line-height: 1.8;
  color: var(--ink-0);
}

.agent-steps {
  margin-bottom: var(--sp-2);
}

.agent-step {
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--ink-2);
  padding: 2px 0;
  border-bottom: 1px dotted var(--rule-2);
  word-break: break-all;
}

/* ---------- 关系图谱：工具行 + 关系卡片（重设计） ---------- */

.relation-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-5);
  padding: var(--sp-2) var(--sp-4);
}

.relation-toolbar .relation-module-filter {
  padding: 0;
}

.relation-depth {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

.relation-depth-label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  margin-right: var(--sp-1);
  letter-spacing: 0.06em;
}

.depth-chip {
  min-height: 30px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule-2);
  background: transparent;
  font-size: var(--fs-12);
  color: var(--ink-2);
  cursor: pointer;
}

.depth-chip.active {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff;
}

/* 关系卡片 */
.relation-tooltip {
  position: fixed;
  z-index: 60;
  display: none;
  width: 288px;
  padding: 0 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-4);
  background: var(--paper-2);
  box-shadow: var(--shadow-3);
  animation: bubble-in 0.16s ease;
  overflow: hidden;
}

.relation-tooltip::before { display: none; }

.rt-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
  background: var(--paper-1);
}

.rt-dot {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.relation-tooltip .tooltip-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: var(--fs-14);
  color: var(--ink-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rt-close {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-12);
  cursor: pointer;
}

.rt-close:hover {
  background: var(--seal-soft);
  color: var(--seal);
}

.relation-tooltip .tooltip-content {
  padding: var(--sp-2) var(--sp-3) 0;
  font-size: var(--fs-12);
  line-height: 1.6;
  color: var(--ink-2);
  max-height: 76px;
  overflow-y: auto;
}

.relation-tooltip .tooltip-tags {
  padding: 2px var(--sp-3) 0;
  font-size: var(--fs-11);
  color: var(--ink-3);
}

.rt-form {
  padding: var(--sp-2) var(--sp-3) 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.rt-field {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
}

.rt-field label {
  flex-shrink: 0;
  width: 34px;
  padding-top: 8px;
  font-size: var(--fs-12);
  color: var(--ink-3);
}

.rt-field select,
.rt-field textarea {
  flex: 1;
  min-height: 34px;
  font-size: var(--fs-13);
}

.rt-field textarea {
  min-height: 48px;
  padding: 6px var(--sp-2);
  line-height: 1.5;
  resize: none;
  font-family: var(--font-sans);
}

.relation-tooltip .tooltip-actions {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) 0;
}

.rt-save {
  flex: 1;
  min-height: 34px;
  border: none;
  border-radius: var(--r-2);
  background: var(--seal);
  color: #fff;
  font-size: var(--fs-13);
  cursor: pointer;
}

.rt-save:hover { background: var(--seal-deep); }

.rt-remove {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(168, 71, 60, 0.4);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--danger);
  font-size: var(--fs-12);
  cursor: pointer;
}

.rt-remove:hover {
  background: rgba(168, 71, 60, 0.08);
}

.relation-tooltip .tooltip-actions-secondary {
  padding-top: var(--sp-2);
}

.relation-tooltip .tooltip-actions-secondary button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-12);
  cursor: pointer;
  padding: 2px 6px;
}

.relation-tooltip .tooltip-actions-secondary button:hover {
  background: var(--seal-soft);
  color: var(--seal);
  border-color: var(--seal);
}

.relation-tooltip .tooltip-actions-secondary button i {
  font-style: normal;
  font-size: var(--fs-13);
}

.relation-tooltip .tooltip-hint { display: none; }

/* ---------- 图谱设置弹窗（⚙） ---------- */

.gs-modal {
  width: min(520px, calc(100vw - 48px));
}

.gs-section {
  padding: var(--sp-3) 0;
}

.gs-section + .gs-section {
  border-top: 1px dashed var(--rule-2);
}

.gs-title {
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--ink-0);
}

.gs-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gs-hint {
  margin: 4px 0 var(--sp-3);
  font-size: var(--fs-12);
  color: var(--ink-3);
  line-height: 1.6;
}

.gs-depth .segment {
  min-width: 56px;
}

.gs-add-btn {
  min-height: 32px;
  padding: 2px 12px;
  font-size: var(--fs-12);
}

.gs-type-list {
  margin-top: var(--sp-2);
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  background: var(--paper-3);
}

.gs-type-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
}

.gs-type-row + .gs-type-row {
  border-top: 1px solid var(--rule-2);
}

.gs-type-row:hover {
  background: var(--seal-soft);
}

.gs-swatch {
  position: relative;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  overflow: hidden;
}

.gs-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  min-height: 0;
  padding: 0;
  border: none;
}

.gs-name {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  border-color: transparent;
  background: transparent;
  font-size: var(--fs-13);
  padding: 0 var(--sp-2);
}

.gs-name:hover:not(:disabled) {
  border-color: var(--rule-2);
  background: var(--paper-2);
}

.gs-name:focus {
  border-color: var(--seal);
  background: var(--paper-2);
}

.gs-name:disabled {
  color: var(--ink-3);
}

.gs-meta {
  flex-shrink: 0;
  display: inline-flex;
  gap: 4px;
}

.gs-badge {
  font-style: normal;
  font-size: var(--fs-11);
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--jade-soft);
  color: var(--jade);
  white-space: nowrap;
}

.gs-badge-lock {
  background: var(--bronze-soft);
  color: var(--bronze);
}

.gs-del {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-12);
  cursor: pointer;
}

.gs-del:hover:not(:disabled) {
  background: rgba(168, 71, 60, 0.1);
  color: var(--danger);
}

.gs-del:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.gs-clean-btn {
  margin-top: var(--sp-3);
  width: 100%;
  min-height: 36px;
  font-size: var(--fs-12);
}

.relation-types-limit {
  font-size: var(--fs-12);
  color: var(--ink-3);
}

/* ---------- 章节版本历史 ---------- */

.version-list {
  max-height: 380px;
  overflow-y: auto;
}

.version-row {
  border-bottom: 1px solid var(--rule-2);
  padding: var(--sp-2) 0;
}

.version-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-13);
}

.version-head strong {
  color: var(--ink-0);
  font-weight: 600;
}

.version-head span {
  color: var(--ink-3);
  font-size: var(--fs-12);
}

.version-head .text-button {
  margin-left: auto;
}

.version-head .text-button + .text-button {
  margin-left: var(--sp-2);
}

.version-preview {
  margin: var(--sp-2) 0 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--rule-1);
  background: var(--paper-3);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  line-height: 1.8;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

/* ---------- 编辑器升级：章节卡片 / 回收站 / 保存状态 ---------- */

.chapter-card {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.chapter-card-main {
  flex: 1;
  min-width: 0;
}

.chapter-drag-handle {
  flex-shrink: 0;
  color: var(--ink-4);
  font-size: var(--fs-12);
  cursor: grab;
  letter-spacing: -2px;
  user-select: none;
}

.chapter-card.dragging {
  opacity: 0.4;
}

.chapter-card.drag-over {
  box-shadow: inset 0 3px 0 var(--seal);
}

.chapter-delete-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-4);
  font-size: var(--fs-11);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.chapter-card:hover .chapter-delete-btn {
  opacity: 1;
}

.chapter-delete-btn:hover {
  color: var(--danger);
  background: rgba(168, 71, 60, 0.1);
}

@media (pointer: coarse) {
  .chapter-delete-btn { opacity: 1; } /* 触屏没有 hover，常显 */
}

.chapter-trash-entry {
  display: block;
  width: 100%;
  margin-top: var(--sp-2);
  min-height: 36px;
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-12);
  cursor: pointer;
}

.chapter-trash-entry:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.save-error {
  color: var(--danger) !important;
  font-weight: 600;
}

.focus-exit-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* ---------- 书库页面重制：竖版书籍造型 ---------- */

.book-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.book-filter-chips {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.book-filter-chips .filter-chip {
  min-height: 32px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--rule-2);
  background: transparent;
  font-size: var(--fs-12);
  color: var(--ink-2);
  cursor: pointer;
}

.book-filter-chips .filter-chip.active {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff;
}

.book-sort-select {
  width: auto;
  min-width: 132px;
  min-height: 34px;
  font-size: var(--fs-12);
}

.book-grid {
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: var(--sp-5) var(--sp-4);
  align-items: start;
}

.book-card {
  grid-template-rows: auto auto;
  border: none;
  background: transparent;
  overflow: visible;
  border-radius: 0;
}

.book-card:hover {
  border: none;
  transform: translateY(-5px);
  box-shadow: none;
}

.book-card.active {
  border: none;
  box-shadow: none;
}

/* 封面 = 一本立着的书：3:4 比例 + 右侧翻口 + 底部书脊金线（原有 ::after 保留） */
.book-cover {
  aspect-ratio: 3 / 4;
  height: auto;
  border-radius: 3px 8px 8px 3px;
  border: 1px solid rgba(60, 42, 22, 0.18);
  box-shadow:
    inset 4px 0 6px -4px rgba(0, 0, 0, 0.35),      /* 书脊阴影 */
    inset -5px 0 0 -3px rgba(255, 255, 255, 0.5),  /* 翻口页边 */
    inset -9px 0 0 -7px rgba(60, 42, 22, 0.25),
    0 2px 6px rgba(60, 42, 22, 0.16);
  transition: box-shadow 0.2s ease;
}

.book-card:hover .book-cover {
  box-shadow:
    inset 4px 0 6px -4px rgba(0, 0, 0, 0.35),
    inset -5px 0 0 -3px rgba(255, 255, 255, 0.5),
    inset -9px 0 0 -7px rgba(60, 42, 22, 0.25),
    0 12px 24px rgba(60, 42, 22, 0.28);
}

.book-card.active .book-cover {
  outline: 2px solid var(--seal);
  outline-offset: 3px;
}

/* 古籍题签：竖排书名条 */
.cover-slip {
  position: absolute;
  top: 8px;
  left: 12px;
  writing-mode: vertical-rl;
  padding: 10px 5px;
  max-height: 72%;
  overflow: hidden;
  background: var(--paper-3, #fff9ea);
  border: 1px solid rgba(60, 42, 22, 0.3);
  border-radius: 2px;
  color: var(--ink-0, #1c1612);
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  letter-spacing: 0.2em;
  line-height: 1.2;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.18);
}

/* 状态印章（右下角） */
.cover-status {
  position: absolute;
  right: 9px;
  bottom: 9px;
  padding: 2px 7px;
  font-size: 10px;
  letter-spacing: 0.1em;
  font-family: var(--font-serif);
  border-radius: 2px;
  border: 1.5px solid currentColor;
  background: rgba(251, 246, 232, 0.88);
  transform: rotate(-3deg);
}

.cover-status-planning { color: #8a5a23; }
.cover-status-active { color: #2c6e49; }
.cover-status-paused { color: #6b665e; }
.cover-status-finished { color: #b3322a; }

.status-pill.cover-status-planning,
.status-pill.cover-status-active,
.status-pill.cover-status-paused,
.status-pill.cover-status-finished {
  position: static;
  transform: none;
  background: transparent;
}

.book-info {
  padding: var(--sp-2) 2px 0;
  background: transparent;
  border: none;
}

.book-info strong {
  display: block;
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-metrics {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 3px;
  font-size: var(--fs-11);
  color: var(--ink-3);
  border: none;
  padding: 0;
  background: transparent;
}

.book-metric-words {
  color: var(--seal);
  font-weight: 600;
  font-size: var(--fs-12);
}

/* 「全部作品」：函套造型 */
.all-books-card .book-cover {
  background:
    repeating-linear-gradient(90deg, rgba(60, 42, 22, 0.05) 0 2px, transparent 2px 14px),
    var(--paper-1);
  border: 1px solid var(--rule-1);
}

.all-books-icon {
  font-family: var(--font-serif);
  font-size: var(--fs-40);
  color: var(--ink-2);
  border: 2px solid var(--rule-1);
  border-radius: 4px;
  padding: 10px 14px;
}

/* 新建作品卡 */
.new-book-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  aspect-ratio: 3 / 4;
  border: 2px dashed var(--rule-1);
  border-radius: 3px 8px 8px 3px;
  background: transparent;
  color: var(--ink-3);
  font-size: var(--fs-13);
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.new-book-card:hover {
  border-color: var(--seal);
  color: var(--seal);
  transform: translateY(-3px);
}

.new-book-plus {
  font-size: var(--fs-32);
  line-height: 1;
}

/* 详情面板：封面同样上书籍质感 */
.book-detail-cover-wrapper .book-detail-cover-color,
.book-detail-cover-wrapper .book-detail-cover-image {
  border-radius: 3px 8px 8px 3px;
  box-shadow:
    inset 4px 0 6px -4px rgba(0, 0, 0, 0.3),
    inset -5px 0 0 -3px rgba(255, 255, 255, 0.5),
    inset -9px 0 0 -7px rgba(60, 42, 22, 0.25),
    0 6px 16px rgba(60, 42, 22, 0.2);
}

.book-metrics-grid .stat-item strong {
  font-family: var(--font-serif);
}

/* ---------- 批次5：触控适配 + 顺手度 ---------- */

/* 收件箱筛选/批量 */
.inbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}

.inbox-batch-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-2);
  background: var(--seal-soft);
}

.inbox-batch-check {
  width: 18px;
  height: 18px;
  min-height: 18px;
  flex-shrink: 0;
  margin-right: var(--sp-2);
  accent-color: var(--seal);
}

/* 资料库排序条 */
.library-sort-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--sp-2);
}

/* 搜索建议键盘选中态 */
.suggestion-item.kb-active {
  background: var(--seal-soft);
  box-shadow: inset 3px 0 0 var(--seal);
}

/* 写作页平板抽屉（≤1200px 三栏改单栏 + 侧滑面板） */
.writing-drawer-toggle {
  display: none;
}

.writing-drawer-backdrop {
  display: none;
}

@media screen and (max-width: 1200px) {
  #writingView .writing-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #writingView .chapter-list-panel,
  #writingView .reference-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(320px, 85vw);
    z-index: 220;
    margin: 0;
    border-radius: 0;
    box-shadow: var(--shadow-3);
    transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
    background: var(--paper-2);
    padding: var(--sp-4);
    overflow-y: auto;
  }

  #writingView .chapter-list-panel {
    left: 0;
    transform: translateX(-105%);
  }

  #writingView .reference-panel {
    right: 0;
    transform: translateX(105%);
  }

  #writingView .chapter-list-panel.drawer-open,
  #writingView .reference-panel.drawer-open {
    transform: none;
  }

  .writing-drawer-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 215;
    background: rgba(28, 22, 18, 0.35);
    backdrop-filter: blur(2px);
  }

  .writing-drawer-toggle {
    display: grid;
    place-items: center;
    position: absolute;
    top: 50%;
    width: 30px;
    height: 64px;
    z-index: 50;
    border: 1px solid var(--rule-0);
    background: var(--paper-2);
    color: var(--ink-2);
    cursor: pointer;
    box-shadow: var(--shadow-2);
  }

  .writing-drawer-toggle-left {
    left: 0;
    border-radius: 0 var(--r-3) var(--r-3) 0;
    border-left: none;
  }

  .writing-drawer-toggle-right {
    right: 0;
    border-radius: var(--r-3) 0 0 var(--r-3);
    border-right: none;
  }

  #writingView.active {
    position: relative;
  }
}

/* 触控目标达标（粗指针设备） */
@media (pointer: coarse) {
  .text-button {
    min-height: 38px;
    padding: 6px 10px;
  }

  .icon-button {
    min-width: 40px;
    min-height: 40px;
  }

  .filter-chip,
  .module-chip,
  .depth-chip {
    min-height: 40px;
  }

  .suggestion-item {
    min-height: 52px;
  }

  .nav-item {
    min-height: var(--h-touch);
  }

  .card-actions .text-button {
    min-height: 42px;
  }

  .zoom-btn {
    width: 46px;
    height: 46px;
  }
}

.ai-continue-floating {
  position: absolute;
  right: var(--sp-5);
  bottom: 72px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  box-shadow: var(--shadow-2);
  z-index: 5;
}

.focus-editor-panel {
  position: relative;
}

/* ---------- 布局排版优化 ---------- */

/* 稿纸栏线间距跟随写作行距设置 */
.chapter-body {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(1em * var(--editor-line-height, 2) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2))
    ),
    var(--paper-2);
}

.chapter-body:focus {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(1em * var(--editor-line-height, 2) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2))
    ),
    var(--paper-3);
}

.focus-chapter-body {
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(1em * var(--editor-line-height, 2.1) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2.1) - 1px),
      var(--rule-2) calc(1em * var(--editor-line-height, 2.1))
    ),
    transparent;
}

/* 超宽屏内容收敛居中，阅读节奏更稳（写作/图谱保持全宽） */
@media screen and (min-width: 1720px) {
  #workspaceView.active,
  #booksView.active,
  #inboxView.active,
  #libraryView.active,
  #settingsView.active {
    max-width: 1620px;
    margin-inline: auto;
    width: 100%;
  }
}

/* 面板标题节奏统一 */
.panel-heading {
  margin-bottom: var(--sp-4);
}

.panel-heading.compact {
  margin-bottom: var(--sp-3);
}

/* ---------- 17. 设置 / 日志 -------------------------------------------- */

#settingsView.active {
  min-height: 100%;
  padding: 0;
}

#settingsContent {
  max-width: 1180px;
  margin: 0 auto;
}

.settings-content { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: var(--sp-5); padding: 0; align-items: start; }
.settings-sections { min-width: 0; }

.settings-nav {
  position: sticky;
  top: 0;
  display: grid;
  gap: 5px;
  padding: var(--sp-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  background: color-mix(in srgb, var(--paper-2) 92%, transparent);
  box-shadow: var(--shadow-1);
}
.settings-nav-title { padding: var(--sp-2) var(--sp-2) var(--sp-3); font-family: var(--font-serif); font-size: var(--fs-20); font-weight: 700; border-bottom: 1px solid var(--rule-2); margin-bottom: 3px; }
.settings-nav-item { display: grid; width: 100%; gap: 2px; padding: 10px 12px; border: 0; border-radius: var(--r-2); background: transparent; color: var(--ink-1); text-align: left; text-decoration: none; }
.settings-nav-item:hover, .settings-nav-item:focus-visible { background: var(--paper-3); }
.settings-nav-item.active { background: var(--seal-soft); color: var(--seal-deep); box-shadow: inset 3px 0 0 var(--seal); }
.settings-nav-item span { font-size: var(--fs-13); font-weight: 600; }
.settings-nav-item small { color: var(--ink-3); font-size: var(--fs-11); }

.settings-panel { display: none; width: 100%; max-width: none; min-height: 560px; margin: 0; animation: settings-panel-in .18s ease-out; }
.settings-panel.active { display: block; }
@keyframes settings-panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.settings-sections > .settings-panel { padding: 0; overflow: hidden; }
.settings-sections > .settings-panel > .appearance-group,
.settings-sections > .settings-panel > .appearance-row,
.settings-sections > .settings-panel > .appearance-divider { margin-left: var(--sp-5); margin-right: var(--sp-5); }
.settings-sections > .settings-panel > .appearance-group:first-of-type { margin-top: var(--sp-5); }
.settings-sections > .settings-panel > .helper-text { padding: 0 var(--sp-5); }
.cloud-settings-body { display: grid; gap: var(--sp-4); padding: var(--sp-5); }
.cloud-user-summary { display: flex; align-items: center; gap: var(--sp-3); }
.cloud-user-avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: #fff; background: var(--seal); font-weight: 700; }
.cloud-user-summary > div { display: grid; }
.cloud-user-summary small { color: var(--ink-3); font-size: var(--fs-12); }
.cloud-settings-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.settings-section-divider { height: var(--sp-5); border-bottom: 1px solid var(--rule-0); background: var(--paper-1); }
.embedded-account-management { border-top: 1px solid var(--rule-0); }
.embedded-account-management .account-capacity { display: none; }
.embedded-account-management .account-api-section { padding: var(--sp-5); }
.account-login-prompt { display: grid; place-items: center; gap: var(--sp-2); min-height: 360px; padding: var(--sp-6); text-align: center; color: var(--ink-2); }
.account-login-prompt strong { font-family: var(--font-serif); font-size: var(--fs-20); }
.account-login-prompt p { color: var(--ink-3); }

.settings-panel .panel-heading {
  padding: var(--sp-5);
  margin: 0;
  border-bottom: 1px solid var(--rule-0);
}
.settings-panel .panel-heading h2 { margin: 0; }
.settings-panel .panel-heading p { margin: 5px 0 0; color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }

@media screen and (max-width: 860px) {
  .settings-content { grid-template-columns: 1fr; }
  .settings-nav { position: sticky; top: 0; z-index: 10; display: flex; overflow-x: auto; padding: 7px; }
  .settings-nav-title, .settings-nav-item small { display: none; }
  .settings-nav-item { flex: 0 0 auto; display: block; padding: 8px 12px; }
  .settings-nav-item.active { box-shadow: inset 0 -2px 0 var(--seal); }
  .appearance-row { grid-template-columns: 1fr; gap: 0; }
}

@media screen and (max-width: 680px) {
  .dock { width: calc(100vw - 20px); overflow-x: auto; justify-content: flex-start; padding: 8px; bottom: -130px; }
  .dock.visible { bottom: 12px; }
  .dock-item { flex: 0 0 56px; width: 56px; }
  .dock-item-settings { margin-left: 2px; padding-left: 2px; }
  .settings-panel .panel-heading { align-items: flex-start; flex-direction: column; }
  .panel-heading-actions { justify-content: flex-start; }
}

.log-filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--rule-2);
}

.log-list {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  max-height: 540px;
  overflow-y: auto;
}

.log-item {
  display: grid;
  gap: 6px;
  padding: var(--sp-3);
  border: 1px solid var(--rule-2);
  border-left: 3px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
}

.log-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.log-time {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  color: var(--ink-3);
}

.log-type {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.log-api    { border-left-color: #4a5b7a; }
.log-error  { border-left-color: var(--seal); }
.log-info   { border-left-color: var(--jade); }

.log-api   .log-type { background: rgba(74, 91, 122, 0.14); color: #3b496a; }
.log-error .log-type { background: var(--seal-soft); color: var(--seal-deep); }
.log-info  .log-type { background: var(--jade-soft); color: var(--jade-deep); }

.log-message {
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  line-height: 1.7;
  color: var(--ink-1);
}

.log-details { margin-top: 4px; }

.expand-details {
  border: 0;
  background: none;
  color: var(--seal);
  font-size: var(--fs-12);
  cursor: pointer;
  padding: 0;
  letter-spacing: 0.04em;
}
.expand-details:hover { text-decoration: underline; }

.log-details-content {
  margin-top: 6px;
  padding: var(--sp-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: var(--paper-0);
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow-y: auto;
}

/* ---------- 18. 响应式 -------------------------------------------------- */

@media screen and (max-width: 1400px) {
  :root {
    --sidebar-w: 240px;
    --main-pad: var(--sp-5);
  }
  
  .main {
    padding-top: var(--sp-5);
    padding-bottom: var(--sp-7);
  }
  
  .search-container {
    width: min(32vw, 360px);
  }
  
  .workspace-grid {
    gap: var(--sp-4);
  }
  
  .writing-layout {
    grid-template-columns: 180px minmax(0, 1fr) 240px;
    gap: var(--sp-4);
  }
  
  .library-layout {
    grid-template-columns: 180px minmax(0, 1fr);
  }
  
  .split-layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
  
  .books-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

@media screen and (max-width: 1200px) {
  :root {
    --sidebar-w: 220px;
  }
  
  body {
    font-size: var(--fs-13);
  }
  
  .writing-layout {
    grid-template-columns: 160px minmax(0, 1fr) 220px;
    gap: var(--sp-3);
  }
  
  .library-layout {
    grid-template-columns: 160px minmax(0, 1fr);
  }
  
  .search-container {
    width: min(280px, 40vw);
  }
  
  .topbar h1 {
    font-size: var(--fs-26);
  }
  
  .panel-heading h2 {
    font-size: var(--fs-18);
  }
}

@media screen and (max-width: 1024px) {
  :root {
    --sidebar-w: 200px;
    --main-pad: var(--sp-4);
  }
  
  body {
    font-size: var(--fs-13);
  }
  
  .main {
    padding-top: var(--sp-4);
    padding-bottom: var(--sp-6);
  }
  
  .writing-layout {
    grid-template-columns: 140px minmax(0, 1fr) 200px;
    gap: var(--sp-3);
  }
  
  .library-layout {
    grid-template-columns: 140px minmax(0, 1fr);
  }
  
  .split-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
  
  .books-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
  
  .search-container {
    width: min(260px, 40vw);
  }
  
  .topbar h1 {
    font-size: var(--fs-24);
  }
  
  .stat-card strong {
    font-size: var(--fs-28);
  }
  
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

@media screen and (max-width: 900px) {
  :root {
    --sidebar-w: 180px;
  }
  
  body {
    font-size: var(--fs-12);
  }
  
  .workspace-grid {
    grid-template-columns: minmax(230px, 1fr) minmax(0, 5fr);
    gap: var(--sp-4);
  }
  
  .writing-layout {
    grid-template-columns: 120px minmax(0, 1fr) 180px;
    gap: var(--sp-2);
  }
  
  .library-layout {
    grid-template-columns: 120px minmax(0, 1fr);
  }
  
  .split-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
  
  .books-layout {
    grid-template-columns: minmax(0, 1fr) 240px;
  }
  
  .search-container {
    width: min(240px, 35vw);
  }
  
  .topbar h1 {
    font-size: var(--fs-22);
  }
  
  .panel-heading h2 {
    font-size: var(--fs-16);
  }
  
  .stat-card strong {
    font-size: var(--fs-24);
  }
  
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  
  .book-card {
    grid-template-rows: 100px 1fr;
  }
  
  .book-cover {
    font-size: var(--fs-32);
  }
}

@media screen and (max-width: 768px) {
  .main {
    padding: var(--sp-3);
    padding-top: 56px;
  }
  
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--paper-0);
    background-image:
      radial-gradient(var(--grain-a) 1px, transparent 1px),
      radial-gradient(var(--grain-b) 1px, transparent 1px);
    background-size: 6px 6px, 11px 11px;
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: 0;
    box-shadow: 0 2px 8px rgba(60, 42, 22, 0.06);
  }
  
  .topbar::after {
    display: none;
  }
  
  .topbar h1 {
    font-size: var(--fs-20);
  }
  
  .topbar-actions {
    gap: var(--sp-2);
  }
  
  .search-container {
    width: min(220px, 45vw);
  }
  
  .search-container input {
    font-size: var(--fs-12);
  }
  
  .workspace-grid {
    grid-template-columns: minmax(220px, 1fr) minmax(0, 3fr);
    gap: var(--sp-3);
  }
  
  .writing-layout {
    grid-template-columns: 100px minmax(0, 1fr) 160px;
    gap: var(--sp-2);
  }
  
  .library-layout {
    grid-template-columns: 120px minmax(0, 1fr);
  }
  
  .split-layout {
    grid-template-columns: minmax(0, 1fr) 240px;
  }
  
  .books-layout {
    grid-template-columns: minmax(0, 1fr) 220px;
  }
}

/* ---------- 19. 沉浸写作模式 (#focusView .focus-mode) ----------------- */

/* 写作编辑器右上角的 ⛶ 入口按钮 */
.chapter-title-wrapper {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--rule-0);
  background: transparent;
  position: relative;
  z-index: 1;
}

.chapter-title-wrapper input.chapter-title,
.chapter-title-wrapper .chapter-title {
  flex: 1;
  border-bottom: 0;
}

.focus-mode-toggle {
  flex-shrink: 0;
  width: 44px;
  margin: 10px var(--sp-4) 10px 0;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  color: var(--ink-2);
  font-size: var(--fs-16);
  cursor: pointer;
  transition: all 0.18s ease;
}

.focus-mode-toggle:hover {
  background: var(--seal-soft);
  border-color: var(--seal);
  color: var(--seal);
}

/* 沉浸模式全屏覆盖 */
.focus-mode {
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: var(--paper-0);
  background-image:
    radial-gradient(var(--grain-a) 1px, transparent 1px),
    radial-gradient(var(--grain-b) 1px, transparent 1px),
    radial-gradient(ellipse at top, var(--vignette-b), transparent 60%);
  background-size: 6px 6px, 11px 11px, 100% 100%;
  background-position: 0 0, 3px 5px, 0 0;
  display: none;
}

.focus-mode.active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* 左右浮动开关按钮 — 极简古籍藏书签样式 */
.focus-toggle-button {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 72px;
  border: 1px solid var(--rule-0);
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: var(--fs-16);
  cursor: pointer;
  z-index: 110;
  box-shadow: var(--shadow-2);
  transition: background 0.18s ease, color 0.18s ease, transform 0.2s ease;
}

.focus-toggle-button:hover {
  background: var(--seal);
  color: var(--paper-2);
  border-color: var(--seal);
}

.focus-toggle-left {
  left: 0;
  border-left: 0;
  border-radius: 0 var(--r-3) var(--r-3) 0;
}

.focus-toggle-right {
  right: 0;
  border-right: 0;
  border-radius: var(--r-3) 0 0 var(--r-3);
}

/* 左右抽屉式滑出面板 */
.focus-slide-panel {
  position: fixed;
  top: 0; bottom: 0;
  width: 320px;
  background: var(--paper-1);
  border-right: 1px solid var(--rule-0);
  box-shadow: 8px 0 32px rgba(60, 42, 22, 0.10);
  z-index: 105;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--sp-5);
  transition: transform 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
  transform: translateX(-100%);
}

.focus-slide-right {
  right: 0;
  left: auto;
  border-right: 0;
  border-left: 1px solid var(--rule-0);
  box-shadow: -8px 0 32px rgba(60, 42, 22, 0.10);
  transform: translateX(100%);
}

.focus-slide-panel.open,
.focus-slide-right.open {
  transform: translateX(0);
}

.focus-slide-panel .panel-heading {
  padding-bottom: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.focus-slide-panel .chapter-list,
.focus-slide-panel .reference-list {
  flex: 1;
  overflow-y: auto;
}

.focus-slide-panel .reference-filter {
  flex-wrap: wrap;
  gap: 4px;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.focus-slide-panel .filter-chip {
  height: 22px;
  padding: 0 8px;
  font-size: var(--fs-11);
  max-width: 100%;
}

.focus-exit-section {
  padding-top: var(--sp-4);
  margin-top: var(--sp-3);
  border-top: 1px solid var(--rule-0);
}

.focus-exit-section .ghost-button {
  width: 100%;
  color: var(--seal);
  border-color: var(--rule-1);
}

.focus-exit-section .ghost-button:hover {
  background: var(--seal-soft);
  border-color: var(--seal);
  color: var(--seal-deep);
}

/* 居中写作主区 — 留白尽可能多 */
.focus-editor-panel {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(var(--sp-7), 6vh, 80px) clamp(var(--sp-4), 4vw, var(--sp-9));
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  min-height: 0;
}

.focus-chapter-title {
  flex-shrink: 0;
  width: 100%;
  padding: var(--sp-3) 0;
  border: 0;
  border-bottom: 1px solid var(--rule-0);
  border-radius: 0;
  min-height: 0;
  background: transparent;
  font-family: var(--font-serif);
  font-size: clamp(var(--fs-26), 3vw, var(--fs-32));
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink-0);
  text-align: center;
}

.focus-chapter-title:focus {
  outline: none;
  box-shadow: none;
  border-bottom-color: var(--seal);
  background: transparent;
}

.focus-chapter-title::placeholder { color: var(--ink-4); }

.focus-chapter-body {
  flex: 1;
  min-height: 400px;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: var(--sp-4) 0;
  margin: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(2.1em - 1px),
      var(--rule-2) calc(2.1em - 1px),
      var(--rule-2) 2.1em
    ),
    transparent;
  font-family: var(--font-serif);
  font-size: clamp(var(--fs-16), 1.3vw, var(--fs-18));
  line-height: 2.1;
  color: var(--ink-0);
  letter-spacing: 0.06em;
  overflow-y: auto;
  outline: none;
  cursor: text;
  box-sizing: border-box;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-ligatures: none;
  tab-size: 4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.focus-chapter-body:empty:before {
  content: attr(data-placeholder);
  color: var(--ink-4);
  pointer-events: none;
}

.focus-chapter-body p {
  margin: 0 0 1.5em 0;
  padding: 0;
}

.focus-chapter-body p:last-child {
  margin-bottom: 0;
}

.focus-chapter-body .highlight-term {
  background: rgba(245, 158, 11, 0.35);
  color: inherit;
  border-radius: 3px;
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
  padding: 0 2px;
}

.focus-chapter-body .highlight-term::selection {
  background: var(--seal);
  color: var(--paper-2);
}

.focus-chapter-body:focus {
  outline: none;
  box-shadow: none;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(2.1em - 1px),
      var(--rule-2) calc(2.1em - 1px),
      var(--rule-2) 2.1em
    ),
    transparent;
}

.focus-chapter-body::placeholder {
  color: var(--ink-4);
  font-style: normal;
}

.focus-editor-footer {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--rule-2);
  color: var(--ink-3);
  font-family: var(--font-serif);
  font-size: var(--fs-12);
  letter-spacing: 0.12em;
}

/* ---------- 20. 关系图谱 (#relationView) -------------------------------- */

#relationView {
  background-color: var(--paper-0);
  background-image:
    radial-gradient(var(--grain-a) 1px, transparent 1px),
    radial-gradient(ellipse at center, var(--vignette-b), transparent 70%);
  background-size: 8px 8px, 100% 100%;
}

#relationView.active {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: calc(100vh - 120px);
}

.relation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
  position: relative;
}

.relation-header::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  pointer-events: none;
}

.relation-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  position: relative;
  z-index: 1;
}

.relation-title h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-0);
}

.relation-favorite-btn {
  font-size: var(--fs-18);
  color: var(--ink-4);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--r-1);
  transition: color 0.18s ease, background 0.18s ease;
}

.relation-favorite-btn:hover {
  color: #f59e0b;
  background: var(--paper-3);
}

.relation-favorite-btn.active {
  color: #f59e0b;
}

.relation-header-actions {
  display: flex;
  gap: var(--sp-2);
  position: relative;
  z-index: 1;
}

/* 模块颜色圆点 — 列表里每一项前面都是这个 */
.module-color-dot {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(60, 42, 22, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  background: var(--ink-3); /* 默认色 — 实际由 JS 注入 inline style 覆盖 */
}

/* 关系图谱颜色图例 */
.relation-legend {
  position: fixed;
  left: calc(var(--sp-6) + 320px);
  bottom: calc(var(--sp-6) + 30px);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  margin: 0;
  z-index: 99;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

.legend-dot {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(60, 42, 22, 0.18);
}

.legend-label { color: var(--ink-2); }

/* 空状态 */
.relation-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  padding: var(--sp-8);
  color: var(--ink-3);
  font-family: var(--font-serif);
  letter-spacing: 0.08em;
}

.empty-icon {
  font-size: var(--fs-40);
  margin-bottom: var(--sp-3);
  color: var(--bronze);
  opacity: 0.55;
  font-family: var(--font-serif);
}

.relation-empty-state p {
  margin: 0;
  font-size: var(--fs-15);
  color: var(--ink-3);
}

/* 图谱容器 */
.relation-graph-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-6) + 180px);
  overflow: visible;
  min-height: 500px;
}

.relation-graph {
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 500px;
}

.relation-node {
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.relation-node:hover {
  transform: scale(1.08);
}

.relation-node-group:hover .relation-node {
  filter: drop-shadow(0 4px 10px rgba(60, 42, 22, 0.25));
}

/* 底部关系详情面板 */
.relation-details {
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  padding: var(--sp-5);
  max-height: 340px;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-1);
}

.relation-details::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  pointer-events: none;
}

.relation-section {
  position: relative;
  z-index: 1;
  margin-bottom: var(--sp-5);
}

.relation-section:last-child { margin-bottom: 0; }

.relation-section h3 {
  margin: 0 0 var(--sp-3) 0;
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--rule-2);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.24em;
}

/* 关系列表 — 每项左侧模块颜色圆点 */
.relation-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.relation-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--paper-3);
  border: 1px solid var(--rule-2);
  border-left: 3px solid var(--rule-1);
  border-radius: var(--r-2);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.relation-item:hover {
  background: var(--paper-2);
  border-color: var(--rule-1);
  border-left-color: var(--seal);
}

.relation-item-title {
  flex: 1;
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--ink-0);
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.relation-type {
  flex-shrink: 0;
  padding: 3px 10px;
  background: var(--seal-soft);
  color: var(--seal-deep);
  border: 1px solid rgba(179, 50, 42, 0.22);
  border-radius: 11px;
  font-family: var(--font-sans);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.06em;
}

/* 添加关系按钮 / 包裹 */
.add-relation-button-wrapper {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.add-relation-label {
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

.add-relation-button {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border: 1px solid var(--seal);
  border-radius: 50%;
  background: var(--paper-3);
  color: var(--seal);
  font-size: var(--fs-16);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.add-relation-button:hover {
  background: var(--seal);
  color: var(--paper-2);
  transform: scale(1.05);
}

.add-relation-button span { line-height: 1; margin-top: -1px; }

.add-relation-button-float {
  position: fixed;
  left: calc(var(--sp-6) + 20px);
  bottom: calc(var(--sp-6) + 80px);
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--seal);
  color: var(--paper-2);
  font-size: var(--fs-24);
  font-weight: 600;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 12px 32px rgba(179, 50, 42, 0.38);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.add-relation-button-float:hover {
  transform: scale(1.08);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 10px 28px rgba(179, 50, 42, 0.42);
}

.add-relation-button-float span { line-height: 1; margin-top: -2px; }

.add-relation-menu-wrapper {
  position: relative;
}

.relation-action-buttons {
  position: fixed !important;
  left: calc(var(--sp-6) + 220px) !important;
  bottom: calc(var(--sp-6) + 85px) !important;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100 !important;
}

.relation-action-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  font-size: var(--fs-20);
  font-weight: 600;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.1),
    0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.relation-action-btn.main-btn {
  background: var(--seal);
  color: var(--paper-2);
  z-index: 10;
  position: relative;
}

.relation-action-btn.main-btn:hover {
  transform: scale(1.08);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 10px 28px rgba(179, 50, 42, 0.42);
}

.relation-action-btn.main-btn span {
  line-height: 1;
  margin-top: -2px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.relation-action-btn.secondary-btn {
  background: var(--paper-2);
  opacity: 0;
  transform: translateX(60px);
  pointer-events: none;
  z-index: 5;
}

.relation-action-btn.secondary-btn.favorite-btn {
  color: #f59e0b;
}

.relation-action-btn.secondary-btn.add-btn {
  color: var(--seal);
}

.relation-action-btn.secondary-btn:hover {
  background: var(--paper-3);
  transform: scale(1.08);
}

.relation-action-buttons.expanded .main-btn {
  opacity: 0.5;
}

.relation-action-buttons.expanded .main-btn span {
  transform: rotate(45deg);
}

.relation-action-buttons.expanded .secondary-btn {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.relation-action-buttons.expanded .secondary-btn.favorite-btn {
  transform: translateX(0);
  transition-delay: 0.05s;
}

.relation-action-buttons.expanded .secondary-btn.add-btn {
  transform: translateX(0);
  transition-delay: 0.1s;
}

.add-relation-menu {
  display: none;
}

.add-relation-menu.hidden {
  display: none;
}

.add-relation { position: relative; }

/* 添加关系的搜索框 */
.relation-search {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  color: var(--ink-0);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.relation-search:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.relation-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-2);
  z-index: 30;
}

.relation-search-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid var(--rule-2);
}

.relation-search-item:last-child { border-bottom: 0; }
.relation-search-item:hover { background: var(--seal-soft); }

.relation-search-item .add-btn {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  background: var(--seal);
  color: var(--paper-2);
  border-radius: 50%;
  font-size: var(--fs-12);
  font-weight: 600;
}

.relation-search-results-modal {
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--sp-3);
}

.relation-search-item-modal {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-2);
  cursor: pointer;
  transition: background 0.18s ease;
}

.relation-search-item-modal:hover { background: var(--seal-soft); }

.relation-search-item-title {
  flex: 1;
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  color: var(--ink-0);
}

.add-relation-btn {
  padding: 4px var(--sp-3);
  background: var(--seal);
  color: var(--paper-2);
  border: 0;
  border-radius: var(--r-1);
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.add-relation-btn:hover { background: var(--seal-deep); }

/* 关系类型管理 */
.relation-type-select,
.relation-type-search-input,
.type-name-input {
  width: 100%;
  min-height: var(--h-md);
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  color: var(--ink-0);
}

.type-name-input:disabled {
  background: var(--paper-1);
  color: var(--ink-3);
  cursor: not-allowed;
}

.relation-types-search { margin-bottom: var(--sp-4); }

.relation-types-list {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: var(--paper-3);
}

.relation-type-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
}

.relation-type-item:last-child { border-bottom: 0; }

.type-color-preview {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(60, 42, 22, 0.18);
  border-radius: var(--r-2);
}

.type-info { flex: 1; min-width: 0; }

.type-id {
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--ink-3);
  margin-left: var(--sp-2);
}

.type-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.type-color-picker {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: transparent;
  cursor: pointer;
}

.type-color-picker:disabled { cursor: not-allowed; opacity: 0.5; }

.type-locked {
  padding: 2px 8px;
  border-radius: var(--r-1);
  background: var(--paper-1);
  font-size: var(--fs-11);
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

.add-new-relation-type-btn,
#addNewRelationTypeBtn.add-new-relation-type-btn,
.add-relation-type-btn {
  width: 100%;
  margin-top: var(--sp-3);
  min-height: var(--h-md);
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--seal);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: all 0.18s ease;
}

.add-new-relation-type-btn:hover,
.add-relation-type-btn:hover {
  background: var(--seal-soft);
  border-color: var(--seal);
  color: var(--seal-deep);
}

/* 关系类型管理 — 删除/已使用/批量清理 */
.type-delete-btn {
  padding: 4px var(--sp-3);
  border: 1px solid var(--rule-1);
  border-radius: var(--r-1);
  background: var(--paper-3);
  color: var(--danger);
  font-family: var(--font-serif);
  font-size: var(--fs-12);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.18s ease;
}

.type-delete-btn:hover:not(:disabled) {
  background: rgba(168, 71, 60, 0.1);
  border-color: var(--danger);
}

.type-delete-btn:disabled {
  color: var(--ink-4);
  cursor: not-allowed;
  opacity: 0.6;
}

.type-in-use {
  display: inline-block;
  margin-left: var(--sp-2);
  padding: 2px 8px;
  border-radius: var(--r-1);
  background: var(--jade-soft);
  color: var(--jade-deep);
  border: 1px solid rgba(63, 93, 75, 0.2);
  font-family: var(--font-sans);
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.remove-unused-btn {
  width: 100%;
  margin-top: var(--sp-2);
  min-height: var(--h-md);
  border: 1px solid var(--rule-1);
  border-radius: var(--r-2);
  background: var(--paper-3);
  color: var(--ink-2);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: all 0.18s ease;
}

.remove-unused-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(168, 71, 60, 0.08);
}

/* 工具类 */
.text-muted { color: var(--ink-3); }
.text-center { text-align: center; }

.relation-types-limit {
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bronze-soft);
  border-radius: var(--r-2);
  color: var(--bronze);
  font-size: var(--fs-12);
  text-align: center;
  letter-spacing: 0.06em;
}

/* 节点详情抽屉 — 右侧卷轴 */
.relation-tooltip {
  position: fixed !important;
  top: 96px !important;
  right: var(--sp-5) !important;
  left: auto !important;
  bottom: var(--sp-5);
  width: 340px;
  max-height: calc(100vh - 120px);
  z-index: 60;
  overflow-y: auto;
  padding: var(--sp-5);
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  box-shadow:
    -10px 0 32px rgba(60, 42, 22, 0.14),
    var(--shadow-2);
  /* 默认隐藏 — 配合 JS 的 display 控制 */
  display: none;
  /* 滑入动画 */
  animation: relationDrawerSlideIn 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.relation-tooltip > * {
  position: relative;
  z-index: 1;
}

@keyframes relationDrawerSlideIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (max-width: 720px) {
  .relation-tooltip {
    top: auto !important;
    bottom: 0;
    right: 0 !important;
    width: 100%;
    max-height: 60vh;
    border-radius: var(--r-3) var(--r-3) 0 0;
    border-bottom: 0;
  }
}

.tooltip-title {
  margin: 0 0 var(--sp-2) 0;
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--rule-2);
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--ink-0);
  letter-spacing: 0.04em;
}

.tooltip-content {
  margin: 0 0 var(--sp-2) 0;
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  line-height: 1.65;
  color: var(--ink-2);
  max-height: 96px;
  overflow-y: auto;
}

.tooltip-tags {
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  color: var(--bronze);
  letter-spacing: 0.04em;
}

.tooltip-relation-select {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--sp-2);
}

.tooltip-relation-select label {
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

.tooltip-relation-type-select {
  width: 100%;
  padding: 6px var(--sp-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-1);
  background: var(--paper-3);
  font-size: var(--fs-12);
  color: var(--ink-0);
}

.tooltip-actions {
  display: flex;
  gap: 6px;
  margin-bottom: var(--sp-2);
}

.tooltip-change-btn,
.tooltip-remove-btn {
  flex: 1;
  padding: 6px var(--sp-3);
  border: 0;
  border-radius: var(--r-1);
  color: var(--paper-2);
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.tooltip-change-btn { background: var(--seal); }
.tooltip-change-btn:hover { background: var(--seal-deep); }

.tooltip-remove-btn { background: var(--danger); }
.tooltip-remove-btn:hover { background: #8d342c; }

.tooltip-hint {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--rule-2);
  font-size: var(--fs-11);
  color: var(--ink-3);
  text-align: center;
  letter-spacing: 0.06em;
}

/* 模态对话框 */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  width: 90%;
  max-width: 480px;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-4);
  box-shadow: var(--shadow-4);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--rule-1);
  background: var(--paper-1);
}

.modal-header h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-18);
  font-weight: 600;
  color: var(--ink-0);
}

.modal-close-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--r-2);
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.modal-close-btn:hover {
  background: var(--paper-4);
  color: var(--ink-0);
}

.modal-body {
  padding: var(--sp-4);
  max-height: 400px;
  overflow-y: auto;
}

.favorite-relation-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-3);
  border-radius: var(--r-2);
  cursor: pointer;
  transition: background 0.18s ease;
}

.favorite-relation-item:hover {
  background: var(--paper-3);
}

.favorite-relation-title {
  font-family: var(--font-serif);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--ink-0);
}

.favorite-relation-date {
  font-size: var(--fs-12);
  color: var(--ink-4);
}

/* ---------- AI 管理：多接口列表（现代化卡片式布局） ---------- */

.modal.ai-manage-modal {
  width: min(880px, calc(100vw - 32px));
}

.ai-manage-modal .modal-heading {
  padding: var(--sp-5) var(--sp-6) var(--sp-4);
}

.ai-manage-body {
  position: relative;
  z-index: 1;
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
  max-height: 78vh;
  overflow-y: auto;
}

.ai-manage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.ai-manage-count {
  font-family: var(--font-sans);
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

.ai-manage-toolbar-actions {
  display: flex;
  gap: var(--sp-2);
}

.secondary-button.small {
  min-height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-12);
}

.ai-provider-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.ai-provider-row {
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  background: var(--paper-3);
  padding: var(--sp-4);
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.ai-provider-row:hover {
  box-shadow: var(--shadow-2);
  border-color: var(--rule-1);
}

.ai-provider-add-row {
  background: var(--seal-soft);
  border-style: dashed;
  border-color: var(--rule-1);
}

.ai-row-top {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.ai-name-input {
  flex: 1 1 180px;
  min-width: 140px;
  font-weight: 600;
  border: none;
  background: transparent;
  padding: 0;
  min-height: auto;
  font-size: var(--fs-15);
  box-shadow: none !important;
}

.ai-name-input:focus {
  box-shadow: none;
  outline: none;
  text-decoration: underline;
  text-decoration-color: var(--seal-soft);
  text-underline-offset: 4px;
}

.ai-status-label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  white-space: nowrap;
  margin-right: -4px;
}

.ai-row-actions {
  display: flex;
  gap: var(--sp-1);
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.ai-row-fields {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1.3fr;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px dashed var(--rule-2);
}

.ai-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ai-field span {
  font-size: var(--fs-11);
  color: var(--ink-3);
  letter-spacing: 0.03em;
}

.ai-field-wide {
  grid-column: span 2;
}

.ai-cell-input,
.ai-cell-select {
  width: 100%;
  min-height: 36px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: var(--paper-2);
  color: var(--ink-0);
  font-size: var(--fs-13);
  font-family: var(--font-sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-cell-input:focus,
.ai-cell-select:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-soft);
}

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--rule-1);
  border-radius: var(--r-2);
  background: var(--paper-2);
  color: var(--ink-1);
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.mini-button:hover {
  border-color: var(--seal);
  color: var(--seal-deep);
  background: var(--paper-3);
  transform: translateY(-1px);
}

.mini-button.primary {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--paper-2);
}

.mini-button.primary:hover {
  background: var(--seal-deep);
  border-color: var(--seal-deep);
}

.mini-button.danger {
  color: var(--danger);
  border-color: rgba(168, 71, 60, 0.35);
}

.mini-button.danger:hover {
  background: rgba(168, 71, 60, 0.1);
  border-color: var(--danger);
}

.ai-status-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: var(--ink-4);
  cursor: pointer;
  flex: none;
  box-shadow: 0 0 0 3px transparent;
  transition: box-shadow 0.15s ease;
}

.ai-status-dot:hover { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06); }

.ai-status-dot.is-ok { background: #3f8f5f; }
.ai-status-dot.is-fail { background: var(--danger); }
.ai-status-dot.is-unknown { background: #c9a13b; }
.ai-status-dot.is-off { background: var(--rule-1); }

.ai-default-tag {
  font-size: var(--fs-11);
  color: var(--seal);
  border: 1px solid var(--seal-soft);
  background: var(--seal-soft);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  font-weight: 600;
}

.ai-new-tag {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--seal-deep);
  letter-spacing: 0.02em;
}

.ai-hint {
  margin-top: var(--sp-4);
  font-size: var(--fs-12);
  line-height: 1.7;
  color: var(--ink-3);
}

@media screen and (max-width: 640px) {
  .ai-row-fields { grid-template-columns: 1fr; }
  .ai-field-wide { grid-column: span 1; }
  .ai-row-actions { width: 100%; justify-content: flex-start; }
}

/* 私聊：单接口直连对话弹窗 */

.ai-provider-chat-modal {
  width: min(560px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  max-height: 82vh;
}

.ai-provider-chat-modal .modal-heading {
  padding: var(--sp-4) var(--sp-5) var(--sp-3);
}

.ai-provider-chat-modal .ai-chat-messages {
  flex: 1;
  min-height: 240px;
  max-height: 50vh;
}

.ai-provider-chat-modal .ai-chat-input-row {
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  background: transparent;
  border-top: 1px solid var(--rule-2);
}

.ai-provider-chat-modal .ai-chat-input-row textarea {
  background: var(--paper-2);
  border-color: var(--rule-2);
  color: var(--ink-0);
}

/* =========================================================================
   关系视图子菜单 + 背景地图
   ========================================================================= */

.relation-subtabs {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) 0;
}

.relation-subtab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--rule-0);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.relation-subtab:hover {
  border-color: var(--seal);
  color: var(--seal-deep);
}

.relation-subtab.active {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--paper-2);
}

.relation-subview-host {
  min-height: 500px;
}

/* ---------- 地图画册 ---------- */

.map-album {
  padding: var(--sp-4);
}

.map-album-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.map-album-head h2 { font-size: var(--fs-26); }
.map-album-subtitle { margin-top: 5px; color: var(--ink-3); font-size: var(--fs-13); }

.map-capability-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: var(--sp-5);
  padding: var(--sp-3);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-3);
  background: color-mix(in srgb, var(--paper-2) 78%, transparent);
}
.map-capability-strip span { padding: 4px var(--sp-3); color: var(--ink-2); font-size: var(--fs-12); border-right: 1px solid var(--rule-2); }
.map-capability-strip span:last-child { border-right: 0; }
.map-capability-strip b { margin-right: 7px; color: var(--seal); font-family: var(--font-mono); font-size: var(--fs-11); }

.map-album-actions {
  display: flex;
  gap: var(--sp-2);
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-4);
}

.map-card {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.map-card:hover {
  border-color: var(--rule-1);
  box-shadow: var(--shadow-2);
}

.map-card-thumb {
  height: 150px;
  background: var(--paper-3);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--rule-2);
}

.map-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.map-card-blank {
  color: var(--ink-4);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.16em;
}

.map-card-body {
  display: grid;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
}

.map-card-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: var(--fs-14);
  color: var(--ink-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-card-meta {
  font-size: var(--fs-11);
  color: var(--ink-3);
}

.map-card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.map-card:hover .map-card-actions {
  opacity: 1;
}

.map-card-actions .icon-button {
  background: rgba(251, 246, 232, 0.92);
  border: 1px solid var(--rule-1);
  border-radius: var(--r-2);
  width: 28px;
  height: 28px;
  font-size: var(--fs-13);
}

.map-empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-5);
  text-align: center;
  border: 1px dashed var(--rule-1);
  border-radius: var(--r-3);
  color: var(--ink-2);
  font-family: var(--font-serif);
}
.map-empty-mark { display: grid; place-items: center; width: 64px; height: 64px; border: 1px solid var(--seal); border-radius: 50%; color: var(--seal); font-family: var(--font-ui-display); font-size: var(--fs-26); box-shadow: inset 0 0 0 5px var(--seal-soft); }
.map-empty h3 { font-size: var(--fs-20); }
.map-empty .helper-text { max-width: 620px; line-height: 1.8; }
.map-empty-hints { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2); }
.map-empty-hints span { padding: 5px 11px; border: 1px solid var(--rule-2); border-radius: 999px; background: var(--paper-3); color: var(--ink-3); font-family: var(--font-ui-body); font-size: var(--fs-11); }

@media screen and (max-width: 780px) {
  .font-preset-cards { grid-template-columns: 1fr; }
  .map-album-head { align-items: flex-start; flex-direction: column; }
  .map-album-actions { flex-wrap: wrap; }
  .map-capability-strip { grid-template-columns: repeat(2, 1fr); }
  .map-capability-strip span:nth-child(2) { border-right: 0; }
  .map-capability-strip span:nth-child(-n+2) { border-bottom: 1px solid var(--rule-2); }
}

/* ---------- 地图编辑器 ---------- */

.map-editor {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: calc(100vh - 190px);
  min-height: 480px;
  margin: var(--sp-3) var(--sp-4) var(--sp-4);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  background: var(--paper-2);
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
  flex-wrap: wrap;
}

.map-back {
  flex-shrink: 0;
}

.map-name-input {
  width: 150px;
  border: 0;
  border-bottom: 1px dashed var(--rule-1);
  background: transparent;
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--ink-0);
  padding: 4px 2px;
  outline: none;
}

.map-name-input:focus {
  border-bottom-color: var(--seal);
}

.map-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.map-tool {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-14);
  cursor: pointer;
}

.map-tool:hover {
  background: var(--paper-3);
}

.map-tool.active {
  background: var(--seal-soft);
  border-color: var(--seal);
  color: var(--seal-deep);
}

.map-tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.map-tool-sep {
  width: 1px;
  height: 20px;
  background: var(--rule-2);
  margin: 0 4px;
}

.map-colors {
  display: flex;
  gap: 4px;
}

.map-color {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.map-color.active {
  border-color: var(--ink-0);
  box-shadow: 0 0 0 2px var(--paper-2);
}

.map-size {
  padding: 4px 10px;
  border: 1px solid var(--rule-0);
  border-radius: 999px;
  background: var(--paper-3);
  color: var(--ink-2);
  font-size: var(--fs-12);
  cursor: pointer;
}

.map-size.active {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--paper-2);
}

.map-toolbar-right {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
}

.map-canvas-wrap {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(rgba(120, 90, 50, 0.05) 1px, transparent 1px);
  background-size: 8px 8px;
}

.map-canvas-wrap canvas {
  display: block;
}

.map-statusbar {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 6px var(--sp-3);
  border-top: 1px solid var(--rule-2);
  font-size: var(--fs-12);
  color: var(--ink-3);
}

/* ---------- 地图标记:编辑弹窗 + 图例面板 ---------- */

.map-marker-pop {
  position: absolute;
  z-index: 30;
  width: 250px;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-3);
  padding: var(--sp-3);
  display: grid;
  gap: var(--sp-2);
}

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

.mmp-name {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--rule-1);
  background: transparent;
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--ink-0);
  padding: 4px 2px;
  outline: none;
}
.mmp-name:focus { border-bottom-color: var(--seal); }

.mmp-desc {
  width: 100%;
  border: 1px solid var(--rule-0);
  border-radius: var(--r-2);
  background: var(--paper-3);
  font-family: var(--font-sans);
  font-size: var(--fs-13);
  line-height: 1.6;
  color: var(--ink-1);
  padding: var(--sp-2);
  resize: vertical;
  outline: none;
}
.mmp-desc:focus { border-color: var(--seal); }

.mmp-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-2);
}

.map-legend-panel {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  z-index: 25;
  width: 260px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(251, 246, 232, 0.96);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

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

.map-legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--rule-2);
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  letter-spacing: 0.08em;
  color: var(--ink-1);
}

.map-legend-list {
  overflow-y: auto;
  padding: var(--sp-2);
}

.map-legend-item {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  padding: var(--sp-2);
  border-radius: var(--r-2);
  cursor: pointer;
}

.map-legend-item:hover { background: var(--seal-soft); }

.map-legend-item .legend-dot {
  margin-top: 4px;
  flex-shrink: 0;
}

.map-legend-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.map-legend-text strong {
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  color: var(--ink-0);
}

.map-legend-text span {
  font-size: var(--fs-12);
  color: var(--ink-2);
  line-height: 1.5;
  word-break: break-word;
}

.map-legend-empty {
  padding: var(--sp-3);
  font-size: var(--fs-12);
  color: var(--ink-3);
  line-height: 1.7;
  margin: 0;
}

/* ---------- 地图贴图库调色板 + 贴图操作浮层 ---------- */

.map-stamp-palette {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 26;
  width: 244px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(251, 246, 232, 0.97);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.map-stamp-palette[hidden] { display: none; }

.map-palette-cats {
  display: flex;
  gap: 4px;
  padding: var(--sp-2);
  border-bottom: 1px solid var(--rule-2);
  flex-wrap: wrap;
}

.map-palette-cat {
  padding: 4px 12px;
  border: 1px solid var(--rule-0);
  border-radius: 999px;
  background: var(--paper-3);
  color: var(--ink-2);
  font-size: var(--fs-12);
  font-family: var(--font-serif);
  cursor: pointer;
}

.map-palette-cat.active {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--paper-2);
}

.map-palette-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  padding: var(--sp-2);
}

.map-palette-item {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: var(--sp-2) 4px 6px;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-2);
  background: var(--paper-2);
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.map-palette-item:hover { border-color: var(--rule-1); }

.map-palette-item.active {
  border-color: var(--seal);
  box-shadow: 0 0 0 2px var(--seal-soft);
}

.map-palette-item svg,
.map-palette-item img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  display: block;
}

.map-palette-name {
  font-size: var(--fs-11);
  color: var(--ink-3);
  font-family: var(--font-serif);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.map-palette-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: var(--r-1);
  background: rgba(251, 246, 232, 0.9);
  color: var(--danger);
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.map-palette-item:hover .map-palette-del { opacity: 1; }

.map-palette-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-top: 1px solid var(--rule-2);
}

.map-palette-foot[hidden] { display: none; }

.map-stamp-pop {
  position: absolute;
  z-index: 30;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--paper-2);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-3);
}

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

.map-stamp-pop button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-2);
  color: var(--ink-1);
  font-size: var(--fs-14);
}

.map-stamp-pop button:hover { background: var(--seal-soft); color: var(--seal-deep); }

/* 线型按钮 */
.map-linestyles { display: flex; gap: 2px; }
.map-linestyle {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  color: var(--ink-2);
  font-size: var(--fs-15);
  cursor: pointer;
}
.map-linestyle:hover { background: var(--paper-3); }
.map-linestyle.active {
  background: var(--seal-soft);
  border-color: var(--seal);
  color: var(--seal-deep);
}

/* 半透明填色按钮:棋盘格衬底看清透明度 */
.map-tints { margin-left: 4px; }
.map-tint {
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%),
    linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
}

/* ---------- 地图图层面板 ---------- */

.map-layers-panel {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  z-index: 27;
  width: 250px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(251, 246, 232, 0.97);
  border: 1px solid var(--rule-0);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

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

.map-layers-list {
  overflow-y: auto;
  padding: var(--sp-2);
  display: grid;
  gap: 3px;
}

.map-layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  cursor: pointer;
}

.map-layer-row:hover { background: var(--paper-3); }

.map-layer-row.active {
  background: var(--seal-soft);
  border-color: var(--seal);
}

.map-layer-row.fixed {
  background: var(--paper-3);
  border: 1px dashed var(--rule-2);
  cursor: default;
}

.map-layer-eye {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: var(--r-1);
  font-size: 13px;
  color: var(--ink-2);
  flex-shrink: 0;
}
.map-layer-eye:hover { background: var(--seal-soft); }

.map-layer-name {
  flex: 1;
  min-width: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-13);
  color: var(--ink-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-layer-count {
  font-style: normal;
  font-size: var(--fs-11);
  color: var(--ink-4);
  margin-left: 6px;
}

.map-layer-ops {
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity 0.12s ease;
  flex-shrink: 0;
}

.map-layer-row:hover .map-layer-ops,
.map-layer-row.active .map-layer-ops { opacity: 1; }

.map-layer-ops button {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: var(--r-1);
  font-size: 11px;
  color: var(--ink-2);
}
.map-layer-ops button:hover { background: var(--seal-soft); color: var(--seal-deep); }

.map-layers-foot {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-top: 1px solid var(--rule-2);
}

.map-layer-opacity {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-12);
  color: var(--ink-2);
}

.map-layer-opacity input[type="range"] { flex: 1; }
