/* ========== Tokens ========== */
:root {
  --font-ui: "Noto Serif SC", "Source Serif 4", "Songti SC", Georgia, serif;
  --font-body: "Noto Serif SC", "Source Serif 4", "Songti SC", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  /* 学术论文分角色字体（可由左右栏覆盖） */
  --font-paper-title: "Source Serif 4", "Noto Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
  --font-paper-heading: "Source Serif 4", "Noto Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
  --font-paper-body: "Source Serif 4", "Noto Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
  --font-paper-meta: "Source Serif 4", "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-paper-caption: "Noto Serif SC", "Source Serif 4", "Songti SC", Georgia, serif;

  --fs: 18px;
  --lh: 1.85;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
  --transition: 160ms ease;

  --bg: #f4f0e8;
  --bg-elevated: #fbf8f2;
  --bg-pane: #fffdf8;
  --bg-soft: #efe9dc;
  --border: #e2d8c4;
  --border-strong: #cfc1a6;
  --text: #1f1a14;
  --text-muted: #6b6256;
  --text-faint: #9a8f7e;
  --accent: #8b4513;
  --accent-soft: rgba(139, 69, 19, 0.1);
  --accent-strong: #6b3410;
  --pair: #c45c26;
  --pair-bg: rgba(196, 92, 38, 0.1);
  --pair-border: rgba(196, 92, 38, 0.35);
  --match-bg: #ffe8a3;
  --match-active: #ffd24a;
  --danger: #a33;
  --topbar-h: 52px;
  --status-h: 28px;
  --source-ratio: 1fr;
  --target-ratio: 1fr;
}

html[data-theme="dark"] {
  --bg: #161411;
  --bg-elevated: #1e1a16;
  --bg-pane: #221e19;
  --bg-soft: #2a241d;
  --border: #3a3228;
  --border-strong: #4d4336;
  --text: #f3ebe0;
  --text-muted: #b0a494;
  --text-faint: #7d7366;
  --accent: #e0a56b;
  --accent-soft: rgba(224, 165, 107, 0.12);
  --accent-strong: #f0c090;
  --pair: #f0a060;
  --pair-bg: rgba(240, 160, 96, 0.14);
  --pair-border: rgba(240, 160, 96, 0.4);
  --match-bg: #5a4a18;
  --match-active: #8a7020;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

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

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

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(196, 92, 38, 0.08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(139, 69, 19, 0.06), transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ========== App shell ========== */
.app {
  display: grid;
  /* 去掉独立搜索行：顶栏 + 对照区 + 底栏，最大化阅读面积 */
  grid-template-rows: var(--topbar-h) 1fr var(--status-h);
  height: 100vh;
  min-height: 560px;
}

/* ========== Top bar ========== */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #a35a28);
  color: #fffaf3;
  font-family: "Noto Serif SC", serif;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(139, 69, 19, 0.25);
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-pane);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:hover {
  color: var(--text);
  background: var(--bg-soft);
}

.btn:focus-visible,
.btn-ghost:focus-visible,
.paragraph:focus-visible,
.gutter-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.icon-only {
  width: 32px;
  padding: 0;
  justify-content: center;
}

.btn-toggle.is-active {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

/* 处理控件：范围 + 翻译 + 排版 合一 */
.translate-cluster,
.work-cluster {
  display: inline-flex;
  align-items: stretch;
  height: 32px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--bg-pane);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 8%, transparent);
}

.tr-scope {
  display: inline-flex;
  align-items: stretch;
  background: transparent;
}

.tr-scope-opt {
  appearance: none;
  border: none;
  margin: 0;
  padding: 0 8px;
  min-width: 0;
  height: 100%;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.tr-scope-opt + .tr-scope-opt {
  border-left: 1px solid var(--border);
}

.tr-scope-opt:hover {
  color: var(--text);
  background: var(--bg-soft);
}

.tr-scope-opt.is-active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 600;
}

.tr-scope-opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.translate-cluster .tr-go {
  height: 100%;
  border-radius: 0;
  padding: 0 12px 0 10px;
  gap: 5px;
  border-left: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  box-shadow: none;
}

.translate-cluster .tr-go .tr-go-label,
.translate-cluster .tr-layout .tr-layout-label {
  font-size: 13px;
}

.translate-cluster .tr-layout {
  height: 100%;
  border-radius: 0;
  padding: 0 11px 0 9px;
  gap: 4px;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  box-shadow: none;
}
.translate-cluster .tr-layout:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.translate-cluster .tr-layout:disabled {
  opacity: 0.55;
}
.translate-cluster .tr-layout.is-busy {
  opacity: 1;
  pointer-events: none;
  animation: tr-pulse 1.4s ease-in-out infinite;
}

/* 设置面板内同款分段，略放宽点击区 */
.settings-tr-scope {
  display: inline-flex;
  align-items: stretch;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-pane);
}

.settings-tr-scope .tr-scope-opt {
  padding: 0 14px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  color: #fffaf3 !important;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-primary:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.is-busy {
  position: relative;
}

/* 翻译进行中：中断态（可点） */
.translate-cluster .tr-go.is-busy {
  cursor: pointer;
  opacity: 1;
  pointer-events: auto;
  animation: tr-pulse 1.4s ease-in-out infinite;
}

/* 已中断：强调「继续」 */
.translate-cluster .tr-go.is-paused {
  background: color-mix(in srgb, var(--pair) 88%, #000);
  animation: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--pair) 35%, transparent);
}

@keyframes tr-pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.08);
  }
}

.translate-banner {
  margin: 24px 16px;
  padding: 20px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  text-align: center;
}

.translate-banner p {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.translate-banner .btn {
  margin: 0 4px;
  border: 1px solid var(--border);
  background: var(--bg-pane);
}

.progress-bar {
  display: none;
  height: 2px;
  background: transparent;
  overflow: hidden;
}

.progress-bar.is-on {
  display: block;
}

.progress-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--pair));
  transition: width 200ms ease;
}

.font-tools .font-label {
  min-width: 28px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

html[data-theme="dark"] .icon-sun { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: none; }

/* ========== Search（收进顶栏，默认收起） ========== */
.search-group {
  position: relative;
}

.search-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  min-width: 280px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.search-popover[hidden] {
  display: none !important;
}

.search-field,
.search-field-top {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-pane);
}

.search-field-top {
  width: 100%;
  min-width: 260px;
}

.search-field input,
.search-field-top input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
}

.search-field input::placeholder,
.search-field-top input::placeholder {
  color: var(--text-faint);
}

.search-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-ghost {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* 进度条贴在顶栏底部，不占独立行 */
.topbar .progress-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  margin: 0;
  border: none;
  background: transparent;
  z-index: 21;
}

.statusbar .status-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar .status-keys {
  flex-shrink: 0;
  color: var(--text-faint);
  font-size: 11px;
}

.statusbar .dot {
  color: var(--text-faint);
}

/* ========== Workspace ========== */
.workspace {
  position: relative;
  display: grid;
  /* 始终：原文 | 分隔条 | 译文 —— 目录用浮层，不改变栅格 */
  grid-template-columns: var(--source-ratio) 12px var(--target-ratio);
  min-height: 0;
  overflow: hidden;
}

/* 目录打开时的半透明遮罩（点击关闭） */
.outline-backdrop {
  position: absolute;
  inset: 0;
  z-index: 24;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(20, 16, 12, 0.22);
  cursor: pointer;
}

.outline-backdrop[hidden] {
  display: none !important;
}

html[data-theme="dark"] .outline-backdrop {
  background: rgba(0, 0, 0, 0.45);
}

/* ========== 学术论文目录（左侧浮层抽屉，不挤占对照栅格） ========== */
.outline-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  width: min(280px, 86vw);
  max-width: 320px;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: 8px 0 28px rgba(15, 23, 42, 0.12);
  overflow: hidden;
  animation: outline-slide-in 160ms ease-out;
}

@keyframes outline-slide-in {
  from {
    transform: translateX(-12px);
    opacity: 0.6;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.outline-panel[hidden] {
  display: none !important;
  animation: none;
}

.outline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  padding: 12px 12px 8px 14px;
  border-bottom: 1px solid var(--border);
}

.outline-head strong {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.outline-head .btn-ghost {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
}

.outline-hint {
  margin: 0;
  flex-shrink: 0;
  padding: 8px 14px 6px;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
}

.outline-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 28px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.outline-empty {
  padding: 16px 10px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

.outline-item {
  margin: 0;
}

.outline-item.level-0 {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}

.outline-item.level-0 .outline-link {
  font-weight: 700;
  font-size: 12px;
  color: var(--accent-strong);
}

.outline-item.level-1 .outline-link {
  font-weight: 600;
  font-size: 12.5px;
}

.outline-item.level-2 .outline-link {
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.outline-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  color: var(--text);
  line-height: 1.35;
  border: 1px solid transparent;
}

.outline-link:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 18%, transparent);
}

.outline-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.outline-item.is-current .outline-link {
  background: var(--pair-bg);
  border-color: var(--pair-border);
}

.outline-en {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.outline-zh {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-pane);
}

.pane-source {
  border-right: 1px solid transparent;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 6px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-pane));
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pane-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.pane-title h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.pane-lang {
  color: var(--text-faint);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.pane-body {
  flex: 1;
  overflow: auto;
  scroll-behavior: auto;
  outline: none;
}

.pane-body:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent-soft);
}

.paragraphs {
  padding: 6px 14px 40px;
  max-width: 52rem;
  margin: 0 auto;
}

/* ========== Paragraphs ========== */
/* 左侧固定序号栏：正文/标题都不得压进该区域 */
.paragraph {
  --para-gutter: 44px;
  position: relative;
  margin: 0;
  padding: 14px 16px 14px calc(var(--para-gutter) + 12px);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--text);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
  cursor: pointer;
}

/* 正文行内数学变量：斜体 + 与上下标协调 */
.paragraph .math-var {
  font-style: italic;
  font-family: "Source Serif 4", "Times New Roman", Times, "Noto Serif SC", serif;
  font-synthesis: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.paragraph sub,
.paragraph sup {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
.paragraph sub {
  bottom: -0.2em;
}
.paragraph sup {
  top: -0.4em;
}

.paragraph + .paragraph {
  margin-top: 6px;
}

.paragraph::before {
  content: attr(data-index);
  position: absolute;
  left: 0;
  top: 14px;
  width: var(--para-gutter);
  padding-right: 8px;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
  text-align: right;
  pointer-events: none;
  z-index: 1;
}

.paragraph:hover {
  background: var(--bg-soft);
}

.paragraph.is-active {
  background: var(--pair-bg);
  border-color: var(--pair-border);
  box-shadow: 0 0 0 1px var(--pair-border);
}

.paragraph.is-active::before {
  color: var(--pair);
  font-weight: 500;
}

.paragraph.is-missing {
  opacity: 0.55;
  font-style: italic;
  color: var(--text-muted);
}

.paragraph.is-empty-trans {
  opacity: 0.72;
}

.paragraph.is-empty-trans .empty-trans-hint {
  font-family: var(--font-ui);
  font-size: 13px;
  font-style: italic;
  color: var(--text-faint);
  text-indent: 0;
  user-select: none;
}

/* ========== 学术论文阅读版式 ========== */
.paragraphs.academic-paper {
  max-width: 48rem;
  padding-top: 12px;
}

/* 左栏英文优先；右栏中文优先 —— 翻译后版式仍同结构 */
.pane-source .paragraphs.academic-paper {
  --font-paper-title: "Source Serif 4", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-paper-heading: "Source Serif 4", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-paper-body: "Source Serif 4", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-paper-meta: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  --font-paper-caption: "Source Serif 4", "Noto Serif SC", Georgia, serif;
}

.pane-target .paragraphs.academic-paper {
  --font-paper-title: "Noto Serif SC", "Source Serif 4", "Songti SC", "STSong", serif;
  --font-paper-heading: "Noto Serif SC", "Source Serif 4", "Songti SC", "STSong", serif;
  --font-paper-body: "Noto Serif SC", "Source Serif 4", "Songti SC", "STSong", serif;
  --font-paper-meta: "Noto Serif SC", "Source Serif 4", "Songti SC", serif;
  --font-paper-caption: "Noto Serif SC", "Source Serif 4", "Songti SC", serif;
}

/* ========== 固定文首：题名 / 作者 / 摘要 ========== */
.front-slot-label {
  display: block;
  margin: 0 0 8px;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  text-indent: 0;
}

.front-slot-body {
  text-indent: 0;
  font-family: inherit;
}

.front-slot-body.abstract-body {
  text-indent: 2em;
  text-align: justify;
  line-height: 1.95;
  font-family: var(--font-paper-body);
  font-size: calc(var(--fs) * 0.98);
}

/* 论文题名：最大字号、加粗衬线、居中 */
.paragraph.is-title {
  font-family: var(--font-paper-title);
  font-weight: 700;
  font-size: calc(var(--fs) * 1.22);
  line-height: 1.4;
  color: var(--text);
  text-align: center;
  padding-top: 18px;
  padding-bottom: 12px;
  letter-spacing: 0.015em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  border-radius: 0;
}

.paragraph.is-title .front-slot-body {
  font-family: var(--font-paper-title);
  font-size: inherit;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: inherit;
}

/* 作者：略小于正文、居中 */
.paragraph.is-authors {
  font-family: var(--font-paper-meta);
  text-align: center;
  font-size: calc(var(--fs) * 0.95);
  font-weight: 500;
  color: var(--text);
  padding-top: 10px;
  padding-bottom: 6px;
  letter-spacing: 0.01em;
}

/* 单位：更小、灰调 */
.paragraph.is-affiliation {
  font-family: var(--font-paper-meta);
  text-align: center;
  font-size: calc(var(--fs) * 0.8);
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.55;
  padding-top: 2px;
  padding-bottom: 2px;
  font-style: normal;
}

/* 作者名后 / 单位行首的上标标记（对应 a,b,* 等） */
sup.aff-mark {
  font-size: 0.72em;
  font-weight: 600;
  line-height: 0;
  vertical-align: super;
  color: var(--accent, #3b6ef5);
  margin-left: 1px;
  letter-spacing: 0.02em;
}

.authors-body {
  line-height: 1.65;
}

.affiliation-body {
  display: inline-block;
  text-align: center;
  line-height: 1.65;
  max-width: 100%;
}

.affiliation-body .aff-mark {
  margin-right: 2px;
}

.paragraph.is-corresponding {
  font-family: var(--font-paper-meta);
  text-align: center;
  font-size: calc(var(--fs) * 0.78);
  font-weight: 400;
  color: var(--text-faint);
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 6px;
  border-radius: 0;
  font-style: italic;
}

.meta-label {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  vertical-align: middle;
}

/* 大节标题：1. Introduction / 1. 引言 — 衬线加粗 */
.paragraph.is-heading {
  font-family: var(--font-paper-heading);
  font-weight: 700;
  font-size: calc(var(--fs) * 1.1);
  color: var(--accent-strong);
  letter-spacing: 0.02em;
  margin-top: 18px;
  padding-top: 16px;
  padding-bottom: 6px;
  border-top: 1px solid var(--border);
  border-left: none;
  line-height: 1.4;
  text-align: left;
}

.paragraph.is-heading:first-child,
.paragraph.is-title + .paragraph.is-heading,
.paragraph.is-keywords + .paragraph.is-heading,
.paragraph.is-abstract + .paragraph.is-heading {
  border-top: none;
  margin-top: 8px;
}

/* 小节标题：2.1 Study site — 略小于大节 */
.paragraph.is-heading2 {
  font-family: var(--font-paper-heading);
  font-weight: 600;
  font-size: calc(var(--fs) * 1.02);
  color: var(--accent);
  margin-top: 10px;
  padding-top: 10px;
  padding-bottom: 4px;
  letter-spacing: 0.01em;
  line-height: 1.45;
  text-align: left;
}

.paragraph.is-heading.is-active,
.paragraph.is-heading2.is-active {
  box-shadow: 0 0 0 1px var(--pair-border);
}

/* 英文侧中文节名提示 */
.sec-zh-hint {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  color: var(--accent);
  background: var(--accent-soft);
  vertical-align: middle;
  letter-spacing: 0;
}

/* 摘要正文（固定槽，自带 Abstract·摘要 标签） */
.paragraph.is-abstract {
  font-family: var(--font-paper-body);
  background: color-mix(in srgb, var(--accent) 5%, var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-indent: 0;
  line-height: 1.95;
  padding-top: 14px;
  padding-bottom: 14px;
  margin-top: 8px;
  margin-bottom: 8px;
  font-size: calc(var(--fs) * 0.98);
}

.paragraph.is-abstract .front-slot-label {
  text-align: left;
  margin-bottom: 10px;
}

/* 正文：衬线阅读体 + 首行缩进 */
.paragraph.is-body {
  font-family: var(--font-paper-body);
  font-weight: 400;
  font-size: var(--fs);
  text-indent: 2em;
  text-align: justify;
  hyphens: auto;
  line-height: var(--lh);
  letter-spacing: 0.01em;
}

/* 图题/表题/结构块不缩进 */
.paragraph.is-figure,
.paragraph.is-table,
.paragraph.is-formula,
.paragraph.is-note,
.paragraph.is-keywords,
.paragraph.is-title,
.paragraph.is-authors,
.paragraph.is-affiliation,
.paragraph.is-corresponding,
.paragraph.is-heading,
.paragraph.is-heading2 {
  text-indent: 0;
}

.paragraph.is-title,
.paragraph.is-authors,
.paragraph.is-affiliation,
.paragraph.is-corresponding,
.paragraph.is-figure,
.paragraph.is-table,
.paragraph.is-formula {
  text-align: center;
}

.paragraph.is-heading,
.paragraph.is-heading2,
.paragraph.is-keywords,
.paragraph.is-note {
  text-align: left;
}

/* 公式：独占成段、居中；默认无底色装饰，但 hover/选中与其它段一致 */
.paragraph.is-formula {
  font-family: inherit;
  font-size: calc(var(--fs) * 0.95);
  font-weight: 400;
  background: transparent;
  /* 保留透明边框占位，选中时才能显示 pair 边框 */
  border: 1px solid transparent;
  box-shadow: none;
  text-align: center;
  line-height: 1.5;
  padding: 10px 16px 14px calc(var(--para-gutter) + 12px);
  margin: 16px 0 !important;
  display: block !important;
  width: 100%;
  clear: both;
  text-indent: 0 !important;
  cursor: pointer;
}

.paragraph.is-formula:hover {
  background: var(--bg-soft);
}

.paragraph.is-formula.is-active {
  background: var(--pair-bg);
  border-color: var(--pair-border);
  box-shadow: 0 0 0 1px var(--pair-border);
}

.paragraph.is-formula.is-active::before {
  color: var(--pair);
  font-weight: 500;
}

.paragraph.is-formula + .paragraph.is-formula {
  margin-top: 10px !important;
}

.paragraph.is-formula .formula-editor,
.paragraph.is-formula .formula-stack {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.formula-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.formula-stack > .formula-editor {
  display: block;
  width: 100%;
}

.paragraph.is-figure,
.paragraph.is-table {
  font-family: var(--font-paper-caption);
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  font-size: calc(var(--fs) * 0.9);
  font-weight: 400;
  text-align: center;
  line-height: 1.55;
  color: var(--text-muted);
  font-style: normal;
}

.paragraph.is-keywords {
  font-family: var(--font-paper-meta);
  font-style: normal;
  font-size: calc(var(--fs) * 0.9);
  color: var(--text-muted);
  padding-top: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  line-height: 1.7;
}

.kw-label {
  display: inline-block;
  margin-right: 8px;
  font-weight: 600;
  font-family: var(--font-paper-heading);
  color: var(--accent-strong);
  font-style: normal;
}

.kw-chip {
  display: inline-block;
  margin: 3px 6px 3px 0;
  padding: 2px 10px;
  border-radius: 999px;
  font-family: var(--font-paper-meta);
  font-size: calc(var(--fs) * 0.82);
  font-style: normal;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  text-indent: 0;
}

.paragraph.is-note {
  font-family: var(--font-paper-caption);
  font-size: calc(var(--fs) * 0.85);
  color: var(--text-faint);
  font-style: italic;
  line-height: 1.55;
}

.tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  font-style: normal;
  vertical-align: 1px;
}

.tag-formula {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent-strong);
}

.tag-figure {
  background: color-mix(in srgb, #2a6 18%, transparent);
  color: #1a6b45;
}

.tag-table {
  background: color-mix(in srgb, #36a 18%, transparent);
  color: #1a4a8a;
}

html[data-theme="dark"] .tag-figure {
  color: #7dcea0;
}
html[data-theme="dark"] .tag-table {
  color: #85c1e9;
}

/* ---- 学术表格重建 ---- */
.yixu-table-wrap {
  margin: 0.35em 0 0.6em;
  max-width: 100%;
}
.yixu-table-caption {
  font-size: 0.92em;
  font-weight: 600;
  margin: 0 0 0.35em;
  line-height: 1.45;
  color: var(--text);
}
.yixu-table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-pane, var(--bg-elevated, #fff));
}
.yixu-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.82em;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.yixu-table th,
.yixu-table td {
  border: 1px solid var(--border);
  padding: 0.28em 0.55em;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.yixu-table th {
  background: color-mix(in srgb, var(--accent, #36a) 10%, transparent);
  font-weight: 600;
  text-align: center;
}
.yixu-table td:not(:first-child) {
  text-align: right;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.95em;
}
.yixu-table-empty {
  margin: 0.25em 0;
  font-size: 0.88em;
  color: var(--text-muted);
}
html[data-theme="dark"] .yixu-table-scroll {
  background: color-mix(in srgb, var(--bg-pane) 90%, #000);
}

/* ---- 公式编辑器：单独一行 | 公式居中 | 编号右侧 ---- */
.paragraph.is-formula {
  /* 覆盖上文 is-formula，段落本身不抢样式 */
  display: block;
}

.formula-block,
.formula-editor {
  display: block !important;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  /* 无边框、无底色：像正文中的独立公式行 */
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  outline: none;
  overflow: visible;
  text-indent: 0 !important;
}

/* 三栏舞台：左平衡 | 中公式 | 右编号 */
.formula-editor-stage {
  display: grid;
  grid-template-columns: 3.6em 1fr 3.6em;
  align-items: center;
  min-height: 48px;
  width: 100%;
  padding: 6px 4px;
  gap: 0;
  background: transparent;
  background-image: none;
  text-indent: 0;
}

.formula-editor-side {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  text-indent: 0;
}

.formula-editor-side-left {
  /* 与右侧编号列同宽，保证中间公式视觉居中 */
  width: 100%;
}

.formula-editor-side-right {
  justify-content: flex-end;
  padding-right: 6px;
}

.formula-editor-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 4px 8px;
  text-indent: 0;
}

/* 公式本体：居中，无底色边框 */
.formula-math {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 4px 8px;
  overflow-x: auto;
  text-align: center;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  text-indent: 0;
}

.formula-math .katex-display {
  margin: 0.2em 0;
  text-align: center;
}

.formula-math .katex-display > .katex {
  text-align: center;
}

.formula-math .katex {
  font-size: 1.28em;
  line-height: 1.35;
}

.formula-math-fallback {
  border: none;
  background: transparent;
}

.formula-fallback-text {
  display: inline-block;
  font-family: "Cambria Math", "Times New Roman", STIX Two Math, serif;
  font-size: 1.1em;
  font-style: italic;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  text-align: center;
}

/* 公式双轨 P0：PDF 截图保真显示 */
.formula-math-image {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border: none !important;
  background: transparent;
}

.formula-shot {
  display: block;
  max-width: min(100%, 820px);
  width: auto;
  height: auto;
  max-height: 220px;
  object-fit: contain;
  background: #fff;
  border-radius: 2px;
  image-rendering: auto;
}

.formula-editor-image .formula-editor-center {
  padding: 4px 8px;
}

html[data-theme="dark"] .formula-shot {
  background: #141414;
  filter: invert(0.92) hue-rotate(180deg);
}

/* 右侧编号 (1) */
.formula-eqno {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4em;
  min-height: 1.6em;
  padding: 2px 4px;
  font-family: "Times New Roman", "Songti SC", serif;
  font-size: 15px;
  font-weight: 400;
  font-style: normal;
  color: var(--text);
  letter-spacing: 0.02em;
  user-select: none;
  text-indent: 0;
}

.formula-eqno[data-empty="1"] {
  /* 占位，保持栏宽 */
  visibility: hidden;
  min-width: 2.4em;
}

.formula-eqno[data-empty="1"]::after {
  content: "( )";
  visibility: hidden;
}

/* 同一段内多式：上下叠放，各自一行 */
.formula-editor + .formula-editor {
  margin-top: 10px;
}

html[data-theme="dark"] .formula-editor,
html[data-theme="dark"] .formula-math {
  box-shadow: none;
  background: transparent;
  border: none;
}

/* ---- PDF figure screenshots ---- */
.pdf-shot {
  margin: 0 0 10px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.pdf-shot img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(70vh, 720px);
  object-fit: contain;
  background: #fff;
}

.pdf-shot-missing {
  margin-bottom: 10px;
  padding: 20px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
}

.paragraph.is-figure {
  cursor: default;
}

.paragraph.is-formula {
  cursor: default;
}

/* 结构审查：不完整 / 碎片 / 存疑 */
.paragraph.is-review-incomplete,
.paragraph.is-review-fragment {
  box-shadow: inset 3px 0 0 0 color-mix(in srgb, #e67e22 75%, transparent);
  background: color-mix(in srgb, #e67e22 6%, var(--bg-elevated));
}

.paragraph.is-review-suspicious {
  box-shadow: inset 3px 0 0 0 color-mix(in srgb, #3498db 70%, transparent);
  background: color-mix(in srgb, #3498db 5%, var(--bg-elevated));
}

/* ========== 结构审查面板 ========== */
.structure-panel {
  position: absolute;
  top: 8px;
  left: 8px;
  bottom: 8px;
  width: min(360px, calc(100vw - 24px));
  z-index: 24;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-pane);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.structure-panel[hidden] {
  display: none !important;
}
.structure-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  padding: 10px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.structure-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}
.structure-head-top strong {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.structure-head-top .structure-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
}
/* 第二行：三等分工具条，文字完整显示 */
.structure-head-actions {
  display: grid;
  grid-template-columns: 1.15fr 0.75fr 1fr;
  gap: 6px;
  width: 100%;
}
.structure-tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 30px;
  margin: 0;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-elevated, var(--bg-soft));
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.structure-tool:hover {
  background: var(--bg-soft);
  border-color: color-mix(in srgb, var(--text-muted) 35%, var(--border));
  color: var(--text);
}
.structure-tool:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.structure-tool:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.structure-tool-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.structure-tool.structure-fixall {
  color: var(--accent-strong, var(--accent));
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-pane));
}
.structure-tool.structure-fixall:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 20%, var(--bg-pane));
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}
.structure-tool.structure-recheck,
.structure-tool.structure-export-fb {
  font-weight: 500;
  color: var(--text-muted);
}
.structure-tool.structure-recheck:hover:not(:disabled),
.structure-tool.structure-export-fb:hover:not(:disabled) {
  color: var(--text);
}
.structure-item-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-elevated);
}
.structure-item-wrap .structure-item {
  border: none;
  border-radius: 0;
  background: transparent;
}
.structure-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 8px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-soft) 80%, transparent);
}
.structure-item-actions select {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  padding: 3px 4px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-pane);
  color: var(--text);
}
.structure-item-actions .si-fix {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.structure-item-actions .si-fix:hover {
  background: color-mix(in srgb, var(--accent) 22%, var(--bg-pane));
}
.structure-item-actions .si-fix:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.structure-summary {
  margin: 0;
  padding: 10px 12px 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}
.structure-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.structure-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.structure-chip.is-warn {
  background: color-mix(in srgb, #e67e22 14%, var(--bg-pane));
  color: #b35c00;
  border-color: color-mix(in srgb, #e67e22 35%, var(--border));
}
.structure-chip.is-ok {
  background: color-mix(in srgb, #27ae60 12%, var(--bg-pane));
  color: #1e7a45;
  border-color: color-mix(in srgb, #27ae60 30%, var(--border));
}
.structure-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 12px;
  overflow: auto;
  flex: 1;
}
.structure-list li {
  margin: 0 0 6px;
}
.structure-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color var(--transition), background var(--transition);
}
.structure-item:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}
.structure-item .si-level {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}
.structure-item .si-level.is-suspicious {
  background: color-mix(in srgb, #3498db 20%, transparent);
  color: #1a6fa0;
}
.structure-item .si-level.is-incomplete,
.structure-item .si-level.is-fragment {
  background: color-mix(in srgb, #e67e22 22%, transparent);
  color: #a85a00;
}
.structure-item .si-level.is-info {
  background: var(--bg-soft);
  color: var(--text-muted);
}
.structure-item .si-msg {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
}
.structure-item .si-preview {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.structure-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
.structure-hint {
  margin: 0;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
}
.struct-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 2px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: color-mix(in srgb, #e67e22 85%, #000);
  color: #fff;
  line-height: 1;
}
.struct-badge[hidden] {
  display: none !important;
}

.paragraph mark {
  background: var(--match-bg);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.paragraph mark.is-current {
  background: var(--match-active);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--pair) 40%, transparent);
}

.paragraph.empty-hint {
  cursor: default;
  text-align: center;
  color: var(--text-faint);
  font-size: 15px;
  padding: 48px 24px;
  border: 1px dashed var(--border-strong);
  background: var(--bg-elevated);
}

.paragraph.empty-hint::before {
  display: none;
}

/* ========== Gutter ========== */
.gutter {
  position: relative;
  display: flex;
  justify-content: center;
  background: var(--bg);
  cursor: col-resize;
  user-select: none;
  touch-action: none;
}

.gutter-line {
  width: 1px;
  height: 100%;
  background: var(--border);
}

.gutter-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-pane);
  box-shadow: var(--shadow);
}

.gutter-handle::before,
.gutter-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 2px;
  height: 12px;
  border-radius: 1px;
  background: var(--text-faint);
  transform: translateX(-50%);
}

.gutter-handle::before { top: 11px; }
.gutter-handle::after { bottom: 11px; left: calc(50% + 3px); width: 2px; }

.gutter:hover .gutter-line,
.gutter.is-dragging .gutter-line {
  background: var(--accent);
}

/* ========== Editor layer ========== */
.editor-layer {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  gap: 0;
  background: var(--bg-elevated);
}

.editor-layer[hidden] {
  display: none !important;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-pane);
}

.editor-pane:last-of-type {
  border-right: none;
}

.editor-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 8px;
  font-weight: 600;
  font-size: 14px;
}

.editor-label .hint {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-faint);
}

.editor-pane textarea {
  flex: 1;
  min-height: 0;
  margin: 0 12px 12px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  resize: none;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  outline: none;
}

.editor-pane textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.editor-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

/* ========== Modal ========== */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 32px);
}

.modal::backdrop {
  background: rgba(20, 14, 8, 0.45);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(520px, 100%);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-pane);
  box-shadow: var(--shadow);
  color: var(--text);
}

.modal-card header h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.modal-card header p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.import-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 110px;
  padding: 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), opacity var(--transition);
}

.file-drop-wide {
  min-height: 88px;
  margin-top: 4px;
  border-style: solid;
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.file-drop:hover,
.file-drop.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop.is-loading {
  opacity: 0.7;
  pointer-events: none;
}

.file-drop strong {
  font-size: 14px;
}

.file-drop span {
  font-size: 12px;
  color: var(--text-faint);
  word-break: break-all;
  line-height: 1.45;
}

.import-hint {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
}

.modal-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

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

.settings-card {
  max-width: min(640px, calc(100vw - 32px));
  max-height: min(90vh, 820px);
  display: flex;
  flex-direction: column;
}

.settings-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 8px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.settings-section-title {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}

.settings-switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  line-height: 1.45;
}

.settings-switch input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.settings-label {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.settings-font {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.settings-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-pane);
}

.settings-seg .btn {
  border: none;
  border-radius: 0;
  min-width: 56px;
  height: 32px;
  font-size: 12px;
  box-shadow: none;
}

.settings-seg .btn + .btn {
  border-left: 1px solid var(--border);
}

.settings-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.45;
}

.settings-footer {
  flex-shrink: 0;
}

/* ========== AI 对话面板 ========== */
.ai-chat-panel {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  right: 12px;
  bottom: calc(var(--status-h) + 8px);
  width: min(400px, calc(100vw - 24px));
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ai-chat-panel[hidden] {
  display: none !important;
}

.ai-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.ai-chat-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ai-chat-title strong {
  font-size: 14px;
}

.ai-chat-ctx {
  font-size: 11px;
  color: var(--text-faint);
}

.ai-chat-head-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ai-chat-context-box {
  margin: 10px 12px 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  background: var(--bg-pane);
  max-height: 96px;
  overflow: auto;
}

.ai-chat-context-label {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.ai-chat-context-text {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 6px;
}

.ai-chip {
  border: 1px solid var(--border);
  background: var(--bg-pane);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.ai-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ai-chat-messages {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-chat-msg {
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
}

.ai-chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-pane);
  border: 1px solid var(--border);
  color: var(--text);
}

.ai-chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-faint);
  font-size: 12px;
  padding: 2px 6px;
}

.ai-chat-msg.busy {
  opacity: 0.75;
  font-style: italic;
}

.ai-chat-compose {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-chat-compose textarea {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  background: var(--bg-pane);
  color: var(--text);
  outline: none;
}

.ai-chat-compose textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.ai-chat-compose-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ai-chat-compose-bar .btn {
  height: 32px;
  min-width: auto;
  padding: 0 12px;
  font-size: 12px;
}

/* ========== 文档库 ========== */
.library-card {
  max-width: min(640px, calc(100vw - 32px));
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}

.library-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  max-height: 48vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.library-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.library-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.library-item:last-child {
  border-bottom: none;
}

.library-item.is-current {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.library-item-main {
  flex: 1;
  min-width: 0;
}

.library-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
  word-break: break-all;
}

.library-item-meta {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.45;
}

.library-item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.library-item-actions .btn {
  min-width: 64px;
  height: 30px;
  font-size: 12px;
  padding: 0 10px;
}

/* ========== AI 设置表单 ========== */
.ai-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.ai-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.ai-switch input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.ai-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.ai-field span {
  font-weight: 500;
  color: var(--text);
  font-size: 12px;
}

.ai-field input,
.ai-field select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-pane);
  color: var(--text);
  outline: none;
  font-size: 13px;
}

.ai-field input:focus,
.ai-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.ai-detected {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg-elevated));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-detected-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  line-height: 1.4;
}

.ai-detected-label {
  color: var(--text-faint);
}

.ai-detected code {
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
  color: var(--text-muted);
}

.ai-status {
  min-height: 1.4em;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.ai-status.is-ok {
  color: #2a7a3a;
}

.ai-status.is-err {
  color: var(--danger);
}

.ai-status.is-busy {
  color: var(--accent);
}

html[data-theme="dark"] .ai-status.is-ok {
  color: #7dcea0;
}

.ai-advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px 12px;
  background: var(--bg-soft);
}

.ai-advanced summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}

.ai-advanced[open] summary {
  margin-bottom: 10px;
  color: var(--text);
}

.ai-advanced .ai-field {
  margin-top: 10px;
}

.ai-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.ai-footer-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.ai-footer .btn {
  min-width: 88px;
  pointer-events: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-pane);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.toast.is-error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--bg-pane));
  color: var(--danger);
}

/* ========== Status bar ========== */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.02em;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .app {
    grid-template-rows: auto 1fr var(--status-h);
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 8px;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .btn span {
    display: none;
  }

  .btn {
    padding: 0 10px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 8px 1fr;
    height: calc(100vh - 100px);
    min-height: 480px;
  }

  .outline-panel {
    width: min(300px, 90vw);
  }

  .gutter {
    cursor: row-resize;
  }

  .gutter-line {
    width: 100%;
    height: 1px;
  }

  .gutter-handle {
    width: 42px;
    height: 18px;
  }

  .editor-layer {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr auto;
    overflow: auto;
  }

  .editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 220px;
  }

  .import-grid {
    grid-template-columns: 1fr;
  }

  .search-popover {
    right: auto;
    left: 0;
    min-width: min(320px, calc(100vw - 32px));
  }

  .statusbar .status-keys {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
