/* MD Reader · shell layout + Theme Lab tokens (injected by themes.js) */

:root {
  /* gruvbox-dark fallback until themes.js injects */
  --bg: #282828;
  --bg-deep: #1d2021;
  --surface: #3c3836;
  --surface-2: #504945;
  --border: #665c54;
  --ink: #ebdbb2;
  --ink-muted: #a89984;
  --ink-dim: #928374;
  --accent: #fe8019;
  --accent-2: #fabd2f;
  --on-accent: #1d2021;
  --red: #fb4934;
  --green: #b8bb26;
  --aqua: #8ec07c;
  --blue: #83a598;
  --purple: #d3869b;
  --link: #8ec07c;
  --code-bg: #1d2021;
  --code-fg: #ebdbb2;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);

  --font-display: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --side-w: 320px;
  --outline-w: auto;
  --topbar-h: 48px;
  --reader-font-size: 15px;
  --splitter-w: 6px;

  /* 分角色字体/字号（typography.js 写入） */
  --md-font-heading: "Noto Serif SC", "Noto Serif", "Source Han Serif SC", "Songti SC", serif;
  --md-font-body: "Noto Sans SC", "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --md-font-quote: "Noto Serif SC", "Noto Serif", "Source Han Serif SC", "Songti SC", serif;
  --md-font-code: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --md-size-heading: 22px;
  --md-size-body: 15px;
  --md-size-quote: 15px;
  --md-size-code: 13px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

/* ── 滚动条：DESIGN 铁律 thin 半透明，禁默认灰 ── */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--ink) 28%, transparent) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--ink) 22%, transparent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--ink) 40%, transparent);
  background-clip: padding-box;
}

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

/* ── Theme Lab 组件 ── */
.tl-btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  line-height: 1.2;
  white-space: nowrap;
}
.tl-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.tl-btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.tl-btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  color: var(--on-accent);
}
.tl-btn-ghost {
  background: transparent;
}
.tl-btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
.tl-btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--red) 12%, transparent);
}
.tl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tl-btn-sm {
  padding: 3px 8px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.tl-input {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  min-width: 0;
  width: 100%;
}
.tl-input:focus {
  border-color: var(--accent);
}
.tl-input::placeholder {
  color: var(--ink-dim);
}

.tl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}
.tl-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.tl-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.tl-seg button {
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink-muted);
  padding: 6px 12px;
  font-size: 12px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-family: var(--font-body);
}
.tl-seg button:last-child {
  border-right: 0;
}
.tl-seg button.active {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 700;
}
.tl-seg button:hover:not(.active) {
  color: var(--accent-2);
}

.tl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-dim);
  display: inline-block;
  flex-shrink: 0;
}
.tl-dot.ok {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.tl-dot.run {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.tl-dot.bad {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

/* ── App shell ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  flex-shrink: 0;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-label {
  display: inline-flex;
  align-items: center;
  margin: 0;
}
.theme-select {
  width: auto;
  min-width: 140px;
  max-width: 180px;
  cursor: pointer;
  padding-right: 24px;
}

/* ── 旧 tabstrip 已废 ── */
.tabstrip {
  display: none !important;
}

/* ── Workspace: 库 | 大纲 | 正文 ── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

/* ── 库栏分割：默认可点窄轨，hover 才亮 ── */
.splitter {
  flex: 0 0 var(--splitter-w);
  width: var(--splitter-w);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 2;
  transition: background 0.12s ease;
  outline: none;
}
.splitter::after {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--border) 55%, transparent);
  pointer-events: none;
  transition: background 0.12s ease, box-shadow 0.12s ease, width 0.12s ease;
}
.splitter:hover,
.splitter:focus-visible,
.splitter.dragging {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.splitter:hover::after,
.splitter:focus-visible::after,
.splitter.dragging::after {
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 50%, transparent);
}
body.is-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.is-resizing * {
  cursor: col-resize !important;
}

/* ── 大纲与正文：两端渐隐细线（不可拖） ── */
.divider-fade {
  flex: 0 0 14px;
  width: 14px;
  position: relative;
  pointer-events: none;
  background: transparent;
  z-index: 1;
}
.divider-fade::before {
  content: "";
  position: absolute;
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: linear-gradient(
    to bottom,
    transparent 0%,
    color-mix(in srgb, var(--border) 35%, transparent) 14%,
    color-mix(in srgb, var(--ink-muted) 42%, transparent) 50%,
    color-mix(in srgb, var(--border) 35%, transparent) 86%,
    transparent 100%
  );
}

/* ── Sidebar 库 ── */
.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--side-w);
  width: var(--side-w);
  min-height: 0;
  min-width: 0;
  background: var(--bg-deep);
  overflow: hidden;
}

.side-open-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 10px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.side-open-bar .tl-btn {
  flex: 1 1 auto;
  min-width: 0;
}
/* 刷新：不抢主按钮视觉 */
.side-open-bar .btn-refresh-lib {
  flex: 0 0 auto;
  opacity: 0.72;
  font-size: 11px;
  padding: 3px 7px;
}
.side-open-bar .btn-refresh-lib:hover {
  opacity: 1;
}

.side-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}
.side-h {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.side-sub {
  font-size: 11px;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

.empty-hint {
  margin: 4px 8px 0;
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.45;
}

.tree-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 8px 12px;
}

/* ── 收藏夹 ── */
.fav-wrap {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  max-height: 28%;
  overflow: auto;
  padding-bottom: 6px;
}
.fav-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 4px;
}
.fav-item {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 1px 0;
}
.fav-link {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12px;
  text-align: left;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fav-link:hover {
  background: var(--surface);
  color: var(--accent);
}

/* ── 目录树 / 多根库包 ── */
.tree-toolbar {
  padding: 2px 4px 8px;
  font-size: 11px;
  color: var(--ink-dim);
}
.tree-show-hidden {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}

.vault-pack {
  margin-bottom: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 35%, transparent);
  overflow: hidden;
  position: relative;
  transition: opacity 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.vault-body {
  cursor: default;
  /* 大文件夹不把侧栏其他库顶出视口：包内滚动 */
  max-height: min(42vh, 360px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}
.vault-pack-loose {
  /* 单文件：无包体、无折叠，一行即可 */
}
.vault-pack-loose .vault-head {
  border-bottom: 0;
  cursor: default;
}
.vault-pack-loose .vault-grip {
  cursor: grab;
}
body.is-vault-dragging {
  cursor: grabbing !important;
  user-select: none !important;
}
body.is-vault-dragging * {
  cursor: grabbing !important;
}
.tree-sort-hint {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  opacity: 0.55;
  user-select: none;
  padding: 1px 4px;
  border-radius: 4px;
}
.tree-sort-hint[hidden] {
  display: none !important;
}
.tree-sort-hint:hover {
  opacity: 0.9;
  color: var(--ink-muted);
}
.vault-pack.active-vault {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.vault-pack.is-hidden {
  opacity: 0.55;
}
.vault-pack.is-dragging {
  opacity: 0.45;
  cursor: grabbing;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--bg-deep) 50%, transparent);
}
.vault-pack.drop-before {
  box-shadow: inset 0 3px 0 0 var(--accent);
}
.vault-pack.drop-after {
  box-shadow: inset 0 -3px 0 0 var(--accent);
}
.vault-head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  cursor: grab;
  user-select: none;
}
.vault-head:active {
  cursor: grabbing;
}
.vault-title.is-active-file {
  color: var(--accent);
  font-weight: 700;
}
.vault-grip {
  flex-shrink: 0;
  width: 22px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-dim);
  opacity: 0.65;
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.vault-grip:hover,
.vault-pack:hover .vault-grip,
.vault-pack.is-dragging .vault-grip {
  opacity: 1;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.vault-grip:active,
.vault-pack.is-dragging .vault-grip {
  cursor: grabbing;
}
/* 四个小点 2×2 */
.vault-grip-dots {
  display: grid;
  grid-template-columns: 3px 3px;
  grid-template-rows: 3px 3px;
  gap: 3px;
  width: 9px;
  height: 9px;
  pointer-events: none;
}
.vault-grip-dots i {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}
.vault-toggle,
.vault-title {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
}
.vault-toggle {
  width: 22px;
  flex-shrink: 0;
  color: var(--ink-dim);
  font-size: 11px;
}
.vault-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}
.vault-title:hover,
.vault-toggle:hover {
  background: var(--surface);
  color: var(--accent);
}
.vault-body {
  padding: 4px 6px 8px;
  /* max-height 见上方合并块；此处补齐 padding */
}
.vault-actions {
  opacity: 0;
  pointer-events: none;
}
.vault-head:hover .vault-actions,
.vault-head:focus-within .vault-actions {
  opacity: 1;
  pointer-events: auto;
}

.tree {
  list-style: none;
  margin: 0;
  padding: 0 0 0 2px;
}
.tree .tree {
  padding-left: 14px;
  margin-top: 2px;
  border-left: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.tree-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
  border-radius: var(--radius-sm);
  min-width: 0;
  position: relative;
  /* 操作钮绝对定位，不占标签宽度 */
}
.tree-row:hover {
  background: var(--surface);
  z-index: 2;
}
.tree-row:hover .tree-actions,
.tree-row:focus-within .tree-actions {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.tree-dir,
.tree-file {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  text-align: left;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.3;
}
.tree-dir:hover,
.tree-file:hover {
  color: var(--accent);
}
.tree-file.active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-weight: 600;
}
.tree-file.selected {
  outline: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
}
.tree-toggle {
  width: 14px;
  flex-shrink: 0;
  color: var(--ink-dim);
  font-size: 10px;
  text-align: center;
  user-select: none;
  margin-top: 2px;
}
.tree-icon {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}
.tree-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
  width: 100%;
  overflow: visible;
  line-height: 1.3;
}
.tree-label-date {
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
  /* 日期永不截断 */
  overflow: visible;
  max-width: none;
}
.tree-label-main {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 13px;
  color: inherit;
  line-height: 1.35;
}
.tree-file.is-html .tree-label-main {
  color: var(--aqua, var(--ink));
}
.tree-row-file {
  min-height: 40px;
}
.tree-row-file .tree-file {
  padding-top: 6px;
  padding-bottom: 6px;
  padding-right: 10px;
}
.tree-li {
  margin: 2px 0;
}
.tree-li.collapsed > .tree {
  display: none;
}
.tree-li.is-hidden > .tree-row {
  opacity: 0.5;
}

/* hover 操作：浮在行上，不挤占文件名宽度 */
.tree-actions {
  position: absolute;
  right: 4px;
  top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 92%, var(--bg-deep));
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--bg-deep) 45%, transparent);
  transition: opacity 0.12s ease;
  z-index: 3;
  max-width: calc(100% - 8px);
}
.tree-act {
  border: 0;
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  color: var(--ink-muted);
  font-size: 10px;
  font-family: var(--font-body);
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.tree-act:hover {
  background: var(--accent);
  color: var(--on-accent);
}
.tree-act[data-action="delete"]:hover {
  background: var(--red);
  color: #fff;
}

/* 确认对话框 */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg-deep) 72%, transparent);
  backdrop-filter: blur(2px);
  padding: 16px;
}
.modal-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
}
.modal-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-family: var(--font-display);
  color: var(--ink);
}
.modal-msg {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.55;
  white-space: pre-wrap;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Reader ── */
.reader {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.edit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  background: color-mix(in srgb, var(--surface) 80%, var(--bg));
  flex-shrink: 0;
  min-height: 36px;
}
.edit-toolbar[hidden] {
  display: none !important;
}
.edit-toolbar.is-editing {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.ed-btn {
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.2;
  min-width: 28px;
}
.ed-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.ed-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ed-btn-primary {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--accent);
}
.ed-btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent, #1d2021);
}
.ed-btn-accent:disabled {
  opacity: 0.4;
}
.ed-sep {
  width: 1px;
  height: 18px;
  background: color-mix(in srgb, var(--border) 80%, transparent);
  margin: 0 4px;
}
.ed-dirty {
  margin-left: auto;
  font-size: 11px;
  color: var(--red, #fb4934);
  font-weight: 600;
}
.md-source {
  display: block;
  width: 100%;
  min-height: 60vh;
  box-sizing: border-box;
  border: 0;
  resize: vertical;
  padding: 20px 28px 40px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--md-font-code, ui-monospace, "JetBrains Mono", Consolas, monospace);
  font-size: calc(var(--md-size-body, 16px) * 0.95);
  line-height: 1.65;
  outline: none;
  tab-size: 2;
}
.md-source[hidden] {
  display: none !important;
}
.reader-inner {
  flex: 1;
  min-height: 0;
  overflow: auto;
  /* 随屏宽自适应：窄屏少留白，宽屏也不死锁 36px+820 双夹 */
  padding: 20px clamp(12px, 2.5vw, 28px) 40px;
}
.reader-inner:has(.markdown-body.is-html-doc) {
  padding: 8px 10px 10px;
  overflow: hidden;
}
.reader-inner:has(.md-source:not([hidden])) {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.reader-inner:has(.md-source:not([hidden])) .md-source {
  flex: 1;
  min-height: 0;
  resize: none;
}

.empty-state {
  max-width: 440px;
  margin: 12vh auto 0;
  text-align: center;
  color: var(--ink-muted);
}
.empty-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  font-family: var(--font-display);
}
.empty-desc {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.6;
}
.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Outline（正文左侧，宽度随文字内容；背景与正文同色融合） ── */
.outline {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  width: max-content;
  min-width: 112px;
  max-width: min(320px, 28vw);
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}
.outline-nav {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 10px 12px 8px;
  /* 大纲滚动条隐藏（用户要求） */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.outline-nav::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
.outline-item {
  display: block;
  width: max-content;
  max-width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 12px;
  text-align: left;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.35;
  white-space: nowrap;
}
.outline-item:hover {
  background: var(--surface);
  color: var(--accent);
}
.outline-item.active {
  color: var(--accent);
  font-weight: 600;
}
.outline-item.depth-1 { padding-left: 6px; }
.outline-item.depth-2 { padding-left: 14px; font-size: 11.5px; }
.outline-item.depth-3 { padding-left: 22px; font-size: 11px; }
.outline-item.depth-4,
.outline-item.depth-5,
.outline-item.depth-6 {
  padding-left: 28px;
  font-size: 11px;
  color: var(--ink-dim);
}

/* ── Markdown body（分角色字体；宽随阅读区走，可读行长封顶） ── */
.markdown-body {
  max-width: min(100%, 1100px);
  width: 100%;
  margin: 0 auto;
  color: var(--ink);
  font-family: var(--md-font-body, var(--font-body));
  font-size: var(--md-size-body, var(--reader-font-size, 15px));
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
}
/* HTML 文档（archify 等）：全宽 iframe */
.markdown-body.is-html-doc {
  max-width: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-h) - 24px);
}
.html-doc-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 70vh;
  height: calc(100vh - var(--topbar-h) - 32px);
  border: 0;
  border-radius: var(--radius-md);
  background: #fff;
}

/* ── 设置面板 ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--bg-deep) 55%, transparent);
  backdrop-filter: blur(1px);
}
.settings-overlay[hidden],
.settings-panel[hidden] {
  display: none !important;
}
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 910;
  width: min(400px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-title {
  margin: 0;
  font-size: 16px;
  font-family: var(--font-display);
  color: var(--ink);
}
.settings-body {
  flex: 1;
  overflow: auto;
  padding: 12px 16px 24px;
}
.settings-block {
  margin-bottom: 18px;
}
.settings-h {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--ink);
}
.settings-row .tl-input {
  width: auto;
  min-width: 140px;
  max-width: 200px;
}
.settings-num {
  width: 72px !important;
  min-width: 72px !important;
  text-align: center;
}
.settings-check {
  justify-content: flex-start;
  cursor: pointer;
  user-select: none;
}
.settings-block .tl-btn {
  width: 100%;
}
.settings-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.45;
}
.typo-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.typo-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 64px;
  gap: 8px;
  align-items: center;
}
.typo-row-wide {
  grid-template-columns: 42px minmax(0, 1fr);
}
.typo-label {
  font-size: 12px;
  color: var(--ink-muted);
}
.typo-font {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
}
.typo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.typo-actions .tl-btn {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
}
#typoStatus:empty {
  display: none;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-family: var(--md-font-heading, var(--font-display));
  color: var(--ink);
  font-weight: 700;
  line-height: 1.3;
  margin: 1.4em 0 0.55em;
  scroll-margin-top: 12px;
}
.markdown-body h1 {
  font-size: calc(var(--md-size-heading, 22px) * 1.18);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}
.markdown-body h2 {
  font-size: var(--md-size-heading, 22px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  padding-bottom: 0.25em;
}
.markdown-body h3 {
  font-size: calc(var(--md-size-heading, 22px) * 0.86);
  color: var(--ink);
}
.markdown-body h4 {
  font-size: calc(var(--md-size-heading, 22px) * 0.72);
}
.markdown-body h5,
.markdown-body h6 {
  font-size: calc(var(--md-size-heading, 22px) * 0.64);
  color: var(--ink-muted);
}

.markdown-body p {
  margin: 0.7em 0;
}

.markdown-body a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.markdown-body a:hover {
  color: var(--accent);
}

.markdown-body strong {
  color: var(--ink);
  font-weight: 700;
}
.markdown-body em {
  color: var(--ink);
  font-style: italic;
  opacity: 0.92;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.6em 0;
  padding-left: 1.5em;
}
.markdown-body li {
  margin: 0.25em 0;
}
.markdown-body li > ul,
.markdown-body li > ol {
  margin: 0.15em 0;
}

.markdown-body blockquote {
  margin: 0.9em 0;
  padding: 0.4em 0 0.4em 1em;
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--md-font-quote, var(--md-font-body, var(--font-body)));
  font-size: var(--md-size-quote, var(--md-size-body, 15px));
}
.markdown-body blockquote p {
  margin: 0.35em 0;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

.markdown-body code {
  font-family: var(--md-font-code, var(--font-mono));
  font-size: calc(var(--md-size-code, 13px) * 0.96);
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.markdown-body pre {
  margin: 1em 0;
  padding: 14px 16px;
  overflow: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.15);
  color: var(--code-fg);
}
.markdown-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--code-fg);
  font-family: var(--md-font-code, var(--font-mono));
  font-size: var(--md-size-code, 13px);
  line-height: 1.55;
  white-space: pre;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.95em;
  display: block;
  overflow-x: auto;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
}
.markdown-body tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface) 35%, transparent);
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.markdown-body input[type="checkbox"] {
  margin-right: 0.4em;
  accent-color: var(--accent);
}

/* 错误条 + 可操作恢复 */
.err-banner {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--red);
  background: color-mix(in srgb, var(--red) 12%, var(--bg));
  color: var(--red);
  font-size: 13px;
}
.err-banner-text {
  margin: 0 0 8px;
  line-height: 1.45;
}
.err-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.err-banner .tl-btn {
  color: var(--ink);
}

/* 侧栏：权限失效恢复面板 */
.reauth-panel {
  padding: 10px 12px 12px;
  border-top: 1px dashed color-mix(in srgb, var(--red) 35%, var(--border));
  background: color-mix(in srgb, var(--red) 8%, var(--panel));
}
.reauth-panel .empty-hint {
  margin: 0 0 10px;
  color: var(--red);
  font-size: 12.5px;
  line-height: 1.45;
}
.reauth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* 大纲列表（outline.js 用 ul） */
.outline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: max-content;
  min-width: 100%;
}
.outline-list .outline-item {
  margin: 0;
  padding: 0;
  width: max-content;
  max-width: 100%;
}
.outline-link {
  display: block;
  width: max-content;
  max-width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 12px;
  text-align: left;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.35;
  white-space: nowrap;
}
.outline-link:hover {
  background: var(--surface);
  color: var(--accent);
}
.outline-l1 .outline-link { padding-left: 6px; font-weight: 600; }
.outline-l2 .outline-link { padding-left: 14px; font-size: 11.5px; }
.outline-l3 .outline-link { padding-left: 22px; font-size: 11px; }
.markdown-body .outline-flash {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

/* wiki / 相对链 */
.markdown-body a.wiki-link,
.markdown-body a.md-rel-link {
  color: var(--aqua);
  text-decoration: underline dotted;
}
.markdown-body a.wiki-miss {
  color: var(--red);
}

/* 文内查找面板 */
.find-panel {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.find-panel[hidden] {
  display: none !important;
}
.reader {
  position: relative;
}
.find-label {
  font-size: 12px;
  color: var(--ink-muted);
}
.find-input {
  width: 160px;
  min-width: 100px;
  padding: 4px 8px;
}
.find-count {
  font-size: 11px;
  color: var(--ink-dim);
  min-width: 4em;
}
mark.find-hit {
  background: color-mix(in srgb, var(--accent-2) 55%, transparent);
  color: var(--ink);
  border-radius: 2px;
  padding: 0 1px;
}
mark.find-hit.current {
  outline: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}

/* tab needs-reopen */
.tab.needs-reopen {
  opacity: 0.75;
  font-style: italic;
}
.tabstrip-empty {
  font-size: 12px;
  color: var(--ink-dim);
  align-self: center;
  padding: 0 8px;
}


/* ── Responsive: collapse outline / sidebar ── */
@media (max-width: 960px) {
  .outline,
  .divider-fade {
    display: none;
  }
}

@media (max-width: 720px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .cap-banner {
    display: none;
  }
  .topbar-title {
    font-size: 14px;
  }
  .theme-select {
    min-width: 110px;
  }
  .reader-inner {
    padding: 20px 16px 40px;
  }
}
