:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --ink: #2b2a26;
  --muted: #8a877d;
  --line: #e5e2d8;
  --accent: #4a6fa5;
  --accent-soft: #e8eef7;
  --danger: #c0564f;
  --danger-soft: #faeceb;
  --warn: #b8860b;
  --warn-soft: #faf3e3;
  --ok: #4f8f5f;
  --ok-soft: #e9f3ec;
  --soft-bg: #f3f1ec;
  --soft-ink: #555;
  --analysis-bg: #fbfaf6;
  --seg-bg: #eae8e0;
  --input-bg: #ffffff;
  --badge-bg: #f0eee6;
  --card-border: #222;
  --radius: 10px;
}

/* ---------- 黑夜模式 ---------- */
body.dark {
  color-scheme: dark;
  --bg: #1b1b1d;
  --card: #2a2a2d;
  --ink: #e8e6e0;
  --muted: #98958c;
  --line: #434346;
  --accent: #7fa8d9;
  --accent-soft: #283747;
  --danger: #e07a72;
  --danger-soft: #3a2524;
  --warn: #d8a84a;
  --warn-soft: #3a3120;
  --ok: #7fb58a;
  --ok-soft: #22372a;
  --soft-bg: #333336;
  --soft-ink: #cfccc4;
  --analysis-bg: #242427;
  --seg-bg: #3a3a3e;
  --input-bg: #222225;
  --badge-bg: #3d3d41;
  --card-border: #ffffff;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.6;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 20px;
}
.brand { font-size: 20px; font-weight: 700; color: var(--accent); }
.brand .sub { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.subject-bar { display: flex; align-items: center; gap: 6px; }
.subject-bar select { width: auto; min-width: 130px; padding: 5px 8px; }
.subject-bar .btn { padding: 5px 8px; }
.sort-meta { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  border: none; background: none; cursor: pointer; font-size: 14px;
  padding: 6px 14px; border-radius: 8px; color: var(--muted);
}
.tab:hover { background: var(--accent-soft); color: var(--accent); }
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.ai-status { font-size: 12px; color: var(--muted); }
.ai-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot.on { background: var(--ok); } .dot.off { background: #ccc; }

main { max-width: 1080px; margin: 20px auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

.card { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.hidden { display: none !important; }

.seg { display: inline-flex; background: var(--seg-bg); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.seg-btn { border: none; background: none; padding: 6px 16px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field.row { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.check { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }
.field label.check { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: var(--input-bg); color: var(--ink);
}
input[type="checkbox"], input[type="radio"] {
  width: auto; padding: 0; border: none; border-radius: 0; background: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--input-bg); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--danger); border-color: #e8c9c6; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.filterbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filterbar select, .filterbar input { width: auto; }
#f-q { flex: 1; min-width: 160px; }

.qcard { cursor: pointer; }
.qcard:hover { border-color: var(--accent); }
.qhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 20px;
  background: var(--badge-bg); color: var(--muted); white-space: nowrap;
}
.badge.subject { background: var(--accent-soft); color: var(--accent); }
.badge.pending { background: var(--danger-soft); color: var(--danger); }
.badge.cat { background: var(--ok-soft); color: var(--ok); }
.badge.ai-rec { background: #e6e0f7; color: #6a4fa3; }
.qstem { white-space: pre-wrap; }
.qmeta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

.cat-layout { display: block; }
.cat-right { display: none !important; }
.cat-tree { list-style: none; margin: 0; padding: 0; }
.cat-tree ul { list-style: none; margin: 0; padding-left: 18px; }
.cat-node { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.cat-node:hover { background: var(--accent-soft); }
.cat-node.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-node .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-node .cnt { font-size: 11px; color: var(--muted); }

.kv-editor .kv-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.kv-editor .kv-row input.key { width: 140px; flex-shrink: 0; }
.kv-editor .kv-row input.val { flex: 1; }
.kv-editor .kv-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.kv-editor .kv-del:hover { color: var(--danger); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--ok-soft); color: var(--ok); border-radius: 20px;
  padding: 2px 10px; font-size: 12px; margin: 0 6px 6px 0;
}
.chip button { border: none; background: none; color: inherit; cursor: pointer; opacity: .7; }
.chip button:hover { opacity: 1; }
.chip.pending { background: var(--warn-soft); color: var(--warn); }

.suggest-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.suggest-item .reason { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.tag { display: inline-block; font-size: 11px; border-radius: 4px; padding: 1px 6px; margin-right: 6px; }
.tag.high { background: var(--danger-soft); color: var(--danger); }
.tag.medium { background: var(--warn-soft); color: var(--warn); }
.tag.low { background: var(--badge-bg); color: var(--muted); }

.ver-item { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.ver-item .v { color: var(--accent); font-weight: 600; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(30,30,25,.45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow: auto;
}
.modal { background: var(--card); border: 2px dashed var(--card-border); border-radius: 12px; width: 100%; max-width: 860px; padding: 18px; }
.modal .modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal .close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.detail-tab { border: none; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; }
.detail-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.detail-panel { display: none; }
.detail-panel.active { display: block; }

.analysis-box { background: var(--analysis-bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 10px; }
.md-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 6px;
  background: var(--analysis-bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.7;
  cursor: text;
}
.md-preview::before {
  content: 'Markdown 预览';
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.md-preview h1, .md-preview h2, .md-preview h3, .md-preview h4 { margin: 6px 0 4px; }
.md-preview p { margin: 4px 0; }
.md-preview ul { margin: 4px 0; padding-left: 20px; }
.md-preview code { background: var(--badge-bg); padding: 0 4px; border-radius: 4px; }
.md-preview blockquote { border-left: 3px solid var(--line); margin: 4px 0; padding-left: 10px; color: var(--muted); }
.md-preview table { border-collapse: collapse; width: 100%; margin: 6px 0; border: 1px solid var(--line); }
.md-preview th, .md-preview td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.md-preview th { background: var(--badge-bg); }

.md-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 6px;
}
.md-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--badge-bg);
}
.md-tab {
  flex: 1;
  border: none;
  background: none;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.md-tab.active {
  background: var(--card);
  color: var(--accent);
  font-weight: 600;
}
.md-editor textarea {
  border: none;
  border-radius: 0;
  margin: 0;
}
/* 无论 JS 是否初始化，默认都显示预览；只有 .edit-mode 才显示文本编辑框 */
.md-editor textarea { display: none; }
.md-editor .md-preview { display: block; }
.md-editor.edit-mode textarea { display: block; }
.md-editor.edit-mode .md-preview { display: none; }

.md-editor .md-preview {
  border: none;
  border-radius: 0;
  margin: 0;
  min-height: 80px;
}
.md-editor img.md-image {
  max-width: min(100%, 480px);  /* 默认不占满整个心得框 */
  height: auto;
  display: block;
  margin: 8px auto;             /* 始终居中 */
  border-radius: 8px;
}
.md-img-btn {
  flex: 0 0 auto;
  margin-left: auto;
}


.analysis-box h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); }

#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #333; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2); animation: fadein .2s; }
.toast.error { background: var(--danger); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.inbox-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.inbox-row .info { flex: 1; min-width: 0; }
.inbox-row .info .t { font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.inbox-row .info .r { font-size: 12px; color: var(--muted); }
.ai-line { font-size: 12px; margin-top: 4px; }
.ai-line.ok { color: var(--ok); }
.ai-line.warn { color: var(--warn); }
.ai-line.error { color: var(--danger); }
.inbox-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- v2 标签体系 ---------- */
.q-display { background: var(--soft-bg); color: var(--soft-ink); padding: 12px 14px; border-radius: 8px; user-select: text; }
.q-display .prep-stem { white-space: pre-wrap; margin-bottom: 6px; }
.q-display .prep-opt { margin: 2px 0; }
.q-display .prep-line { margin-top: 8px; font-size: 13px; }

.tag-block {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 9px; font-size: 12px; margin: 0 6px 6px 0; cursor: pointer;
  background: var(--card); color: var(--ink);
}
.tag-block.fixed { border-color: #c9d6ea; background: var(--accent-soft); color: var(--accent); }
.tag-block.free { border-color: #e3cfa8; background: var(--warn-soft); color: #8a6508; }
.tag-block.pending { border-style: dashed; opacity: .85; }
.tag-block .tag-x { border: none; background: none; cursor: pointer; color: inherit; font-size: 13px; padding: 0 2px; }
.tag-block .tag-x:hover { color: var(--danger); }
.tag-block.editing { padding: 0; border-style: solid; }
.tag-block.editing input { border: none; outline: 1px solid var(--accent); padding: 4px 8px; width: 160px; border-radius: 5px; font-size: 12px; }
.tag-block.remove-mode { border-style: dashed; border-color: var(--danger); color: var(--danger); }
.tag-block.remove-mode .tag-x { color: var(--danger); }

.add-tag-bar { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.type-toggle {
  border: 1px solid var(--line); background: var(--input-bg); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.type-toggle.fixed { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.type-toggle.free { background: var(--warn-soft); color: #8a6508; border-color: #e3cfa8; }
body.dark .type-toggle.free { color: var(--warn); }
.add-tag-bar .type-toggle, .add-tag-bar .btn { height: 32px; padding: 3px 12px; }

.chip.fixed { background: var(--accent-soft); color: var(--accent); }
.chip.free { background: var(--warn-soft); color: #8a6508; }

.tag-row { display: block; background: var(--card); border: 1px solid var(--card-border); border-radius: 10px; padding: 12px; margin-bottom: 10px; cursor: pointer; }
.tag-row .tag-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag-row .name { font-weight: 600; }
.tag-relations { font-size: 12px; color: var(--muted); }
.tag-first { font-size: 13px; color: var(--ink); margin-top: 6px; line-height: 1.6; white-space: pre-wrap; }
.tag-details { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 6px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.tag-details .md-preview { border: none; margin: 0; font-size: 12px; line-height: 1.5; }
.tag-row:hover { background: var(--accent-soft); }
.tag-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-row .cnt { font-size: 11px; color: var(--muted); }

.type-badge { display: inline-block; font-size: 11px; border-radius: 4px; padding: 1px 6px; margin-right: 6px; }
.type-badge.fixed { background: var(--accent-soft); color: var(--accent); }
.type-badge.free { background: var(--warn-soft); color: #8a6508; }

/* 标签「新增题目」选题弹窗 */
.aq-count { font-size: 13px; color: var(--muted); padding: 4px 2px; font-weight: 600; }
.aq-meta { font-size: 12px; color: var(--muted); padding: 0 2px 4px; }
.aq-body { max-height: 55vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
.aq-row { display: flex; gap: 8px; align-items: flex-start; padding: 8px 2px; border-bottom: 1px dashed var(--line); cursor: pointer; }
.aq-row:last-child { border-bottom: none; }
.aq-row input { margin-top: 4px; }
.aq-stem, .tp-name {
  font-size: 13px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 织题 v3：发现页 ---------- */
.badge.ai-rec { background: #fef3c7; color: #92400e; }

.feeling-text {
  font-size: 14px; line-height: 1.7; margin-top: 4px;
  white-space: pre-wrap; word-break: break-word;
  background: var(--analysis-bg); border-left: 3px solid #e8e2d0;
  padding: 8px 10px; border-radius: 6px;
}

#view-discover details { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--card); }
#view-discover details summary { cursor: pointer; font-weight: 600; color: var(--accent); }
#view-discover details[open] summary { margin-bottom: 8px; }

#vec-status { font-size: 13px; }

.link { color: var(--accent); text-decoration: underline; cursor: pointer; }
.link:hover { opacity: .85; }

/* ---------- 织题 v3：数据导出 / 标签关系 ---------- */
.check-grid { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check-grid .check { display: flex; align-items: center; gap: 5px; }
#td-relations .inbox-row { border-bottom: 1px dashed var(--line); padding: 6px 0; }
#td-relations .inbox-row:last-child { border-bottom: none; }

/* ---------- 织题 v3：标签自动补全 + 固定标签体系设置 ---------- */
.tag-ac-list {
  position: fixed;
  z-index: 1000;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  max-height: 200px;
  overflow: auto;
}
.tag-ac-item { padding: 8px 10px; cursor: pointer; font-size: 13px; }
.tag-ac-item:hover { background: var(--accent-soft); }
.tag-ac-item.active { background: var(--accent-soft); color: var(--accent); }

.ftd-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.ftd-row input, .ftd-row select {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}

/* AI 建议统一板块样式（题目编辑页 / 导入页 / 分析页共用） */
.ai-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0;
  background: var(--card);
}
.ai-section > h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.ai-section-title {
  margin: 14px 0 4px;
  font-size: 14px;
  color: var(--accent);
}

/* ---------- 快捷键系统 ---------- */
.keyboard-focus {
  outline: 3px solid var(--accent) !important;
  outline-offset: -1px;
  border-radius: 14px;
  position: relative;
  z-index: 30;
  /* 更粗蓝框 + 左侧养眼绿色竖色条 */
  box-shadow: inset 5px 0 0 #6fbf8f !important;
}
[data-focusable="region"], .modal, .detail-panel, .analysis-box, .card {
  position: relative;
}
/* 区域视觉分区：保留白框，只留普通边界（焦点蓝框/左侧色条由 .keyboard-focus 提供） */
.kbd-region {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  background: var(--card);
}
.kbd-region > h3, .kbd-region > h4 {
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* 区域标题旁的小提示（仅快捷键模式生成） */
.kbd-title-hint {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 400;
  color: var(--accent);
  background: rgba(74, 111, 165, .10);
  border-radius: 10px;
  padding: 1px 7px;
  pointer-events: none;
  white-space: nowrap;
}
.kbd-action-hint {
  position: relative;
}
/* 悬浮按键角标：用真实 DOM 元素实现，确保 input/textarea/select 也能显示 */
.kbd-action-badge {
  position: fixed;
  z-index: 90;
  background: rgba(30, 30, 25, .62);
  color: #fff;
  font-size: 10px;
  line-height: 1.5;
  min-width: 16px;
  text-align: center;
  padding: 0 4px;
  border-radius: 10px;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}
/* 焦点外极淡遮罩：四块覆盖当前区域之外的视口区域 */
#kbd-dim {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}
.kbd-dim-piece {
  position: fixed;
  background: rgba(30, 30, 25, .05);
  pointer-events: none;
}
body.dark .kbd-dim-piece {
  background: rgba(0, 0, 0, .18);
}
.kbd-action-focus {
  outline: 2px solid var(--accent) !important;
  outline-offset: 1px;
  border-radius: 6px;
  position: relative;
  box-shadow: inset 3px 0 0 #6fbf8f !important;
}
#kbd-bar {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 120;
  background: rgba(30, 30, 25, .78);
  color: #fff;
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 20px;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
body.kbd-edit #kbd-bar {
  background: rgba(30, 30, 25, .55);
}

/* 命令面板 */
.kbd-palette {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.kbd-palette-mask {
  position: absolute;
  inset: 0;
  background: rgba(30, 30, 25, .35);
}
.kbd-palette-box {
  position: relative;
  width: min(640px, 92vw);
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.kbd-palette-box input {
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 14px 16px;
  font-size: 15px;
}
.kbd-palette-box input:focus {
  border-color: var(--accent);
}
#kbd-palette-results {
  max-height: 50vh;
  overflow: auto;
  padding: 6px;
}
.kbd-palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.kbd-palette-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.kbd-palette-kind {
  font-size: 11px;
  border-radius: 10px;
  padding: 1px 7px;
  background: var(--badge-bg);
  color: var(--muted);
  flex-shrink: 0;
}
.kbd-palette-item.active .kbd-palette-kind {
  background: var(--accent);
  color: #fff;
}
.kbd-palette-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* 到达边界时的轻微回弹 */
@keyframes kbd-bounce {
  0% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
  60% { transform: translateY(4px); }
  100% { transform: translateY(0); }
}
.kbd-bounce {
  animation: kbd-bounce 0.3s ease;
}

/* 背诵导出指示灯 */
.recite-light { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.recite-light.red { background: #e07a72; }
.recite-light.yellow { background: #d8a84a; }
.recite-light.green { background: #7fb58a; }
.recite-item { display: flex; align-items: center; gap: 8px; }

/* ---------- 设备识别类（JS 写入 body：is-touch / is-mobile / is-tablet） ---------- */
body.is-touch .kbd-action-badge,
body.is-touch #kbd-bar,
body.is-touch #kbd-dim,
body.is-touch .kbd-region-hint {
  display: none !important;
}

/* ---------- 平板（769–1080） ---------- */
@media (min-width: 769px) and (max-width: 1080px) {
  main { max-width: 940px; }
  .tabs { gap: 6px; }
  .tab { padding: 8px 16px; }
  .modal { max-width: 760px; }
}

/* ---------- 手机（≤768px）高水准适配 ---------- */
@media (max-width: 768px) {
  body { font-size: 15px; }
  main { padding: 0 12px 72px; margin: 8px auto 0; }

  /* 顶部栏紧凑 */
  .topbar {
    gap: 6px;
    padding: 8px 10px;
    position: sticky;
    flex-wrap: wrap;
  }
  .brand { font-size: 17px; }
  .brand .sub { display: none; }
  .subject-bar select { min-width: 110px; padding: 6px 8px; flex: 1 1 auto; }
  .ai-status { display: none; }   /* 手机端去掉「AI：模型名」，顶部太挤 */
  #btn-dark-mode { padding: 6px 8px; }

  /* 底部标签导航 */
  .tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    display: flex;
    width: auto;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: auto;
    box-shadow: 0 -2px 10px rgba(0,0,0,.04);
  }
  .tab {
    flex: 1 0 0;
    min-width: 0;
    min-height: 56px;
    padding: 8px 4px;
    border-radius: 0;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }
  .tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
  }
  .tab:active { background: var(--accent-soft); }

  /* 弹窗：全屏化，便于触摸 */
  .modal-mask {
    padding: 0;
    align-items: stretch;
  }
  .modal {
    max-width: none;
    width: 100%;
    border: none;
    border-radius: 0;
    padding: 14px 14px max(14px, env(safe-area-inset-bottom));
    min-height: 100dvh;
    overflow-y: auto;
  }
  .modal-head {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 5;
    padding: 4px 0 8px;
  }
  .modal .close { font-size: 26px; padding: 4px; }

  /* 触控目标 */
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; padding: 6px 12px; }
  input, textarea, select { font-size: 16px; padding: 10px 12px; border-radius: 10px; }
  .card { padding: 14px; border-radius: 14px; }
  .qcard, .tag-row { padding: 14px; }
  .inbox-row { padding: 14px 0; }
  .inbox-actions { gap: 8px; }
  .link { padding: 4px 2px; }

  /* 筛选区纵向 */
  .filterbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .filterbar select,
  .filterbar input,
  .filterbar button {
    width: 100%;
  }
  .field.row { flex-wrap: wrap; gap: 10px; }
  .add-tag-bar { flex-wrap: wrap; }

  /* 详情页签横向滚动 */
  .detail-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .detail-tab { flex: 0 0 auto; padding: 12px 16px; }

  /* 标签区 */
  .cat-left, .cat-right { width: 100%; }

  /* Markdown 工具条换行 */
  .md-tabs { flex-wrap: wrap; }
  .md-img-btn { margin-left: auto; }

  /* 去掉不必要的 hover，改用 active 反馈 */
  .tab:hover, .btn:hover, .qcard:hover, .tag-row:hover { background: inherit; border-color: var(--line); }
  .btn:active, .qcard:active, .tag-row:active { opacity: .8; }
}

/* ---------- 双主机单写者：状态徽章 + 下拉状态栏 ---------- */
.remote-badge {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.rb-cell { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.rb-sep { color: var(--muted); margin: 0 2px; }
.rb-writer { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.rb-sync { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.rb-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.rb-dot.green { background: var(--ok); }
.rb-dot.yellow { background: #d8a84a; }
.rb-dot.red { background: var(--danger); }
.remote-panel {
  position: fixed;
  top: 56px;
  right: 12px;
  z-index: 90;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
}
.remote-panel .remote-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 8px;
}
.remote-panel .remote-head .close { font-size: 20px; }
.remote-rows { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin-bottom: 12px; }
.remote-progress .rp-steps { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; }
.rp-step { color: var(--muted); }
.rp-step.done { color: var(--ok); }
.rp-step.active { color: var(--accent); font-weight: 600; }
.rp-bar { height: 6px; background: var(--seg-bg); border-radius: 3px; overflow: hidden; }
#rp-bar-inner { height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* ---------- 手机端 UI 修复（编辑框溢出 / 底部导航 / 导入列表挤压） ---------- */
@media (max-width: 768px) {
  main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* 编辑框不再撑破屏幕 */
  input, textarea, select, button {
    max-width: 100%;
    box-sizing: border-box;
  }
  input[type="file"] {
    max-width: 100%;
    width: 100%;
  }
  .field { max-width: 100%; }
  .find-bar, .pr-bar, .add-tag-bar { max-width: 100%; }

  /* 底部导航更稳，不消失 */
  .tabs {
    z-index: 60;
    will-change: transform;
    -webkit-transform: translateZ(0);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* 刷题导入预览行：题干独占一行按钮换行，不再互相挤压 */
  .pr-item { flex-wrap: wrap; }
  .pr-item .info { flex: 1 1 100%; min-width: 0; }
  .pr-item .inbox-actions {
    width: 100%;
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
  }
  .pr-item .inbox-actions .btn { min-height: 38px; padding: 6px 14px; }

  /* 状态栏：手机上变成顶部下拉面板 */
  .remote-badge { font-size: 11px; padding: 6px 8px; }
  .remote-panel {
    top: 50px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    border-radius: 14px;
  }
}

/* 心得图片编辑器 */
.img-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.img-edit-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.img-edit-size { width: 76px; flex-shrink: 0; }
/* ===================================================================
   织题 v3.8 · 视觉优化层（紧致 / 按钮统一 / 留白规整）
   后置覆盖，保持既有选择器与结构不变。
   =================================================================== */
:root {
  --bg: #f6f5f1;
  --card-border: #e7e4db;
  --shadow-sm: 0 1px 2px rgba(40, 38, 32, .05);
  --shadow-md: 0 6px 20px rgba(40, 38, 32, .07);
  --shadow-lg: 0 18px 48px rgba(30, 29, 25, .18);
  --radius: 12px;
}
body.dark {
  --bg: #17171a;
  --card-border: #3b3b40;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, .4);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

body { line-height: 1.55; -webkit-font-smoothing: antialiased; }

/* ---------- 顶栏 ---------- */
.topbar { gap: 14px; padding: 8px 18px; box-shadow: var(--shadow-sm); }
.brand { font-size: 19px; letter-spacing: .5px; }
.tabs { gap: 2px; }
.tab { padding: 6px 13px; border-radius: 9px; font-size: 13.5px; }
.tab.active { box-shadow: var(--shadow-sm); }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-right .ai-status { white-space: nowrap; }
.tabs + .topbar-right { margin-left: 0; }

/* ---------- 主区域 / 卡片 ---------- */
main { max-width: 1180px; margin: 18px auto 44px; padding: 0 18px; }
.card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
}
h3 { font-size: 15px; margin: 0 0 10px; letter-spacing: .2px; }
.kbd-region {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  background: var(--card);
}
.kbd-region > h4 { font-size: 12.5px; color: var(--muted); letter-spacing: .3px; }

/* ---------- 表单 / 按钮统一 ---------- */
.field > label { display: flex; align-items: center; gap: 6px; }
.field.row { align-items: center; gap: 10px; }
.btn {
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.2;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { box-shadow: 0 1px 2px rgba(74, 111, 165, .28); }
.btn.ok { color: var(--ok); border-color: #cfe3d4; }
.btn.ok:hover { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn-row { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.filterbar { gap: 8px; }
.filterbar select, .filterbar input { padding: 7px 10px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* 小复制按钮（普通输入框旁） */
.mini-copy {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--muted);
  border-radius: 6px;
  font-size: 11px;
  padding: 1px 7px;
  cursor: pointer;
  line-height: 1.4;
}
.mini-copy:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Markdown 工具条：编辑/预览靠左，复制/图片两个动作统一靠右（与下方「保存心得」对齐） */
.md-tabs { align-items: stretch; }
.md-editor .md-tabs .md-tab { flex: 0 0 auto; }
.md-editor .md-tabs [data-mode="preview"] { margin-right: auto; }
.md-copy-btn, .md-img-btn { margin-left: 0; }
.md-copy-btn:hover { color: var(--accent); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  padding: 46px 16px;
  background: rgba(30, 30, 25, .34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.modal {
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 18px 20px;
}
.modal .modal-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 3;
}

/* ---------- 内置刷题 ---------- */
.quiz-card { padding: 16px 18px; }
.quiz-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.quiz-bar h3 { margin: 0; }
.quiz-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.quiz-controls select { width: auto; padding: 6px 9px; }
.quiz-qhead { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.quiz-spacer { flex: 1; }
.quiz-stem { font-size: 15.5px; line-height: 1.7; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.quiz-option {
  text-align: left;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  transition: background .15s, border-color .15s, color .15s;
}
.quiz-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.quiz-option.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.quiz-option.wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.quiz-answer { margin-top: 12px; border-left: 3px solid var(--accent); }
.quiz-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.quiz-insight { margin-top: 14px; }
.quiz-insight label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.quiz-nav { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.quiz-nav .qmeta { margin-left: auto; }
body.dark .quiz-option:hover { background: #2e3a49; }

/* 刷题：模式切换 + 题概览 */
.quiz-mode-switch { margin: 0; }
.quiz-mode-switch .seg-btn { padding: 5px 12px; font-size: 13px; }
.quiz-bar #qz-progress { margin-left: auto; white-space: nowrap; }

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 4px 2px 10px;
}
.ov-cell {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 8px;
  min-height: 36px;
  cursor: pointer;
  font-size: 13px;
}
.ov-cell:hover { border-color: var(--accent); }
.ov-cell.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.ov-cell.bad { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); font-weight: 600; }
.ov-cell.cur { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 移动端补充 ---------- */
@media (max-width: 768px) {
  .topbar-right { margin-left: auto; gap: 4px; }
  .topbar-right .ai-status { display: none; }
  .quiz-controls { width: 100%; margin-left: 0; }
  .quiz-controls select { flex: 1 1 30%; }
  .quiz-actions .btn { flex: 1 1 auto; }
  .quiz-nav .btn { flex: 1 1 auto; }
}


/* ===================================================================
   织题 v3.9 · 移动端重构（图标底栏 + 更多面板 + 去噪）
   最后追加，覆盖以上所有桌面/移动规则。
   =================================================================== */
.tab-ico, .tab-short, .tab-more { display: none; }

/* 「更多」底部面板（桌面端靠 .hidden 保持不显示） */
.more-sheet { position: fixed; inset: 0; z-index: 95; display: flex; align-items: flex-end; }
.more-sheet-mask { position: absolute; inset: 0; background: rgba(20, 20, 18, .38); }
.more-sheet-body {
  position: relative; width: 100%; background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 8px;
}
.more-sheet-title { font-size: 12px; color: var(--muted); padding: 4px 4px 2px; }
.more-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--soft-bg); color: var(--ink);
  font-size: 15px; text-align: left; cursor: pointer;
}
.more-item .more-ico { font-size: 18px; }
.more-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

@media (max-width: 768px) {
  /* 触屏：去掉高亮闪一下、避免双击缩放延迟 */
  * { -webkit-tap-highlight-color: transparent; }
  button, .tab, .tab-more, .more-item, .quiz-option, .qcard, .tag-row { touch-action: manipulation; }

  /* 顶栏收成一行 */
  .topbar { flex-wrap: nowrap; gap: 6px; align-items: center; }
  .topbar .brand { font-size: 16px; flex: 0 0 auto; }
  .subject-bar { flex: 1 1 auto; min-width: 0; gap: 4px; }
  .subject-bar select { min-width: 0; width: 100%; }
  .topbar-right { flex: 0 0 auto; margin-left: 0; }

  /* 底栏：5 个主入口 + 更多 */
  .tabs { padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); gap: 0; }
  .tab {
    flex-direction: column; gap: 3px; min-height: 54px;
    padding: 6px 2px; font-size: 11px; line-height: 1.1;
  }
  .tab.tab-secondary { display: none; }
  .tab .tab-full { display: none; }
  .tab .tab-ico { display: block; font-size: 17px; line-height: 1; }
  .tab .tab-short { display: block; font-size: 11px; }
  .tab-more {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; flex: 0 0 auto; min-width: 58px; min-height: 54px; padding: 6px;
    border: none; background: transparent; color: var(--muted);
    font-size: 11px; line-height: 1.1; cursor: pointer;
  }
  .tab-more .tab-ico { display: block; font-size: 17px; line-height: 1; }
  .tab-more .tab-short { display: block; }
  .tab-more.active { color: var(--accent); font-weight: 700; }

  /* 快捷键的区域边框在触屏上纯属噪音（快捷键已固定关闭） */
  .kbd-region { border: none; background: transparent; padding: 0; margin: 6px 0; }
  .kbd-region > h4 { margin-top: 10px; }

  /* 主操作更容易点 */
  .field.row .btn.primary { flex: 1 1 100%; }
  .btn-row { width: 100%; }
  .btn-row .btn { flex: 1 1 auto; }
  .quiz-option { padding: 13px 15px; font-size: 15px; }
  .ov-cell { min-height: 42px; }
  .overview-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }

  /* 卡片更轻，留白更稳 */
  .card { box-shadow: none; margin-bottom: 10px; }
  body.dark .card { box-shadow: none; }
}

