/* ============================================================
 * 新能源课程系统 · 自建前端
 * 主题：浅色为默认（课程正文多为白底图片），可切深色
 * 所有颜色走变量，便于「外观」面板实时调整
 * ============================================================ */

:root {
  /* 浅色（默认） */
  --bg: #f4f6fa;
  --bg-grad: radial-gradient(1200px 600px at 12% -10%, #ffffff 0%, #f4f6fa 55%);
  --panel: #ffffff;
  --panel-2: #f8fafd;
  --field: #f2f5fa;
  --line: #e2e7f0;
  --line-strong: #cfd7e5;
  --text: #17202e;
  --sub: #5f6b80;
  --muted: #8b96a8;
  --accent: #3b5bdb;
  --accent-2: #5872e8;
  --accent-soft: rgba(59, 91, 219, .08);
  --accent-line: rgba(59, 91, 219, .35);
  --ok: #0f9d58;
  --warn: #b7791f;
  --bad: #d64545;
  --shadow: 0 1px 2px rgba(23, 32, 46, .05), 0 10px 28px rgba(23, 32, 46, .07);
  --shadow-s: 0 1px 2px rgba(23, 32, 46, .06);
  --read-w: 1120px;
  --fs-body: 13.5px;
  --fs-text: 14px;

  /* 控制台（固定深色，两套主题通用） */
  --con-bg: #0f1420;
  --con-panel: #131926;
  --con-line: #252d3d;
  --con-text: #dfe5f3;
  --con-sub: #8b95a9;
  --con-code: #0a0d14;
}

[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-grad: radial-gradient(1200px 600px at 12% -10%, #16202e 0%, #0b0f16 55%);
  --panel: #141b25;
  --panel-2: #18202b;
  --field: #101822;
  --line: #232c3a;
  --line-strong: #2f3b4d;
  --text: #e6ebf3;
  --sub: #8d97a8;
  --muted: #6d7789;
  --accent: #6b7dff;
  --accent-2: #8697ff;
  --accent-soft: rgba(107, 125, 255, .12);
  --accent-line: rgba(107, 125, 255, .4);
  --ok: #43c97d;
  --warn: #e0a33c;
  --bad: #e5544b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
  --shadow-s: 0 1px 2px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#shell { display: flex; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

/* ---------------- 侧栏 ---------------- */

#nav {
  width: 188px;
  flex: 0 0 188px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 0 4px 18px;
  font-size: 14.5px; font-weight: 700; letter-spacing: .2px;
  color: var(--text);
}
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#nav-items { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--sub);
  text-decoration: none;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.nav-item:hover { background: var(--field); color: var(--text); }
.nav-item.on {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav-foot {
  margin-top: auto;
  padding: 10px 4px 2px;
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted);
}
.build { font-variant-numeric: tabular-nums; }

/* ---------------- 主区 ---------------- */

#stage {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 20px 22px 100px;
}
#stage > * { max-width: var(--read-w); margin-left: auto; margin-right: auto; }

/* ---------------- 卡片 ---------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-s);
}
.card-h { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .1px; color: var(--text); }
.card-h .btn { margin-left: auto; flex: none; }
.meta { color: var(--sub); font-size: 12px; line-height: 1.7; }

.btn {
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  font: 600 13px/1 inherit;
  cursor: pointer;
  transition: .16s;
}
.btn:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--sub); }
.btn.ghost:hover { border-color: var(--line-strong); color: var(--text); }
.btn.tiny { padding: 5px 11px; font-size: 11.5px; border-radius: 7px; }
.btn.tiny.ghost { background: transparent; border: 1px solid var(--line); color: var(--sub); }
.btn.tiny.ghost:hover { color: var(--text); border-color: var(--line-strong); }

.loading { color: var(--sub); font-size: 13px; padding: 18px 4px; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); padding: 46px 0; font-size: 13px;
}
.empty-mark { width: 30px; height: 30px; border: 1.5px solid var(--line-strong); border-radius: 8px; opacity: .8; }
.empty-sub { color: var(--muted); font-size: 12px; margin-top: -2px; }
.hint {
  margin: 8px 0; padding: 9px 11px; border-radius: 9px; font-size: 11.5px; line-height: 1.65;
  color: var(--warn);
  background: rgba(183, 121, 31, .1);
  border: 1px solid rgba(183, 121, 31, .3);
}

.raw { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.raw > summary, .raw-h { padding: 9px 12px; font-size: 12px; color: var(--sub); cursor: pointer; background: var(--panel-2); }

/* ---------------- 课程页 ---------------- */

.course-wrap { display: flex; gap: 16px; align-items: flex-start; min-height: 0; }

.tree {
  width: 208px;
  flex: 0 0 208px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-s);
  position: sticky;
  top: 0;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
}
.tree-h {
  padding: 12px 14px;
  font-size: 12px; letter-spacing: 1.5px; color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  flex: none;
}
.tree-body { padding: 8px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }

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

.tree-item {
  padding: 9px 11px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: .14s;
}
.tree-item:hover { background: var(--field); }
.tree-item.on { background: var(--accent-soft); border-color: var(--accent-line); }
.ti-name { font-size: 13px; color: var(--text); }
.ti-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.ti-count {
  font-size: 10.5px; color: var(--muted);
  background: var(--field); border-radius: 5px; padding: 1px 5px;
  margin-left: auto;
}

.teacher { margin-bottom: 3px; }
.teacher > .tree-item { padding: 9px 10px; border: 1px solid var(--line); background: var(--panel-2); }
.teacher > .tree-item.on { border-color: var(--accent-line); }
.teacher.open > .tree-item { background: var(--accent-soft); }
.tree-child { display: none; padding-left: 10px; margin: 4px 0 8px 8px; border-left: 1px solid var(--line); }
.teacher.open .tree-child { display: block; }

.catalog-node { margin-bottom: 1px; }
.catalog-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--sub);
  padding: 6px 9px; border-radius: 7px; cursor: pointer;
  border: 0;
  background: transparent;
}
.catalog-item:hover { background: var(--field); color: var(--text); }
.catalog-item.on { background: var(--accent-soft); color: var(--accent); }
.catalog-item .caret { width: 12px; flex: none; color: var(--accent); font-size: 11px; transition: transform .15s; }
.catalog-item .caret.dot { color: var(--line-strong); }
.catalog-item .ti-name { font-size: 12.5px; color: inherit; }
.catalog-item.expanded .caret { transform: rotate(90deg); }
.catalog-item.leaf::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--line-strong); flex: none; margin: 0 4px 0 2px; }
.cat-kids { display: none; padding-left: 12px; border-left: 1px solid var(--line); margin-left: 6px; }
.cat-kids.open { display: block; }

/* ---------------- 课程/试卷 tab ---------------- */

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tab {
  padding: 7px 13px; border-radius: 9px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line); color: var(--sub);
  cursor: pointer; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: .14s;
}
.tab:hover { color: var(--text); border-color: var(--line-strong); }
.tab.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }

/* ---------------- 内容流 ---------------- */

.content-list { display: flex; flex-direction: column; gap: 14px; }

.sec {
  font-size: var(--fs-text);
  font-weight: 650;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 9px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-line);
}
.sec[data-lvl="2"] { font-weight: 600; font-size: calc(var(--fs-text) - 1px); margin-left: 10px; }

.para { font-size: var(--fs-text); line-height: 1.9; color: var(--text); }
.para.html { color: var(--text); }

/* 正文里的富文本（含表格） */
.html { line-height: 1.9; }
.html img { max-width: 100%; height: auto; border-radius: 6px; }
.html table { border-collapse: collapse; max-width: 100%; background: var(--panel); }
.html td, .html th { border: 1px solid var(--line-strong); padding: 7px 10px; font-size: 13px; color: var(--text); }
.html p { margin: 0 0 .7em; }

/* 附件卡 */

.atta {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.atta-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.atta-name { font-size: 13px; color: var(--text); font-weight: 500; word-break: break-all; }
.atta-btns { display: flex; gap: 6px; flex: none; }
.atta-meta { font-size: 11.5px; color: var(--muted); }

/* ---------------- 题目 ---------------- */

.q { padding: 16px 0; border-top: 1px solid var(--line); }
.q.inline {
  margin: 4px 0;
  padding: 16px 16px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-line);
  border-radius: 12px;
  background: var(--panel-2);
}
.q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; flex-wrap: wrap; }
.q-n {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
}
.q-meta { font-size: 11.5px; color: var(--muted); }
.q-saved { margin-left: auto; font-size: 11.5px; color: var(--accent); font-weight: 600; }
.q-stem.html { font-size: var(--fs-text); color: var(--text); }
.q-stem.html img { display: block; margin: 8px 0; border: 1px solid var(--line); background: #fff; }

.q-opts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.opt {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 9px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  cursor: pointer;
}
.opt:hover { border-color: var(--line-strong); }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.opt input { accent-color: var(--accent); margin: 0; }

.q-input {
  width: 100%; min-height: 84px; resize: vertical;
  padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: 13.5px/1.7 inherit; outline: none;
}
.q-input:focus { border-color: var(--accent-line); }

.q-act { display: flex; gap: 8px; margin-top: 10px; }

.q-ans {
  display: none; margin-top: 12px; padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
}
.q-ans.show { display: block; }
.ans-line { font-size: 13px; color: var(--text); line-height: 1.85; margin: 4px 0; }
.ans-line b { color: var(--ok); font-weight: 600; margin-right: 6px; }
.ans-html img { max-width: 100%; border-radius: 6px; }

/* 已提交的作答图片 */

.q-atts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 2px; }
.q-att {
  position: relative; width: 104px; border-radius: 9px; overflow: hidden;
  background: var(--field); border: 1px solid var(--line);
}
.q-att img { display: block; width: 100%; height: 104px; object-fit: cover; cursor: zoom-in; }
.q-att-file { padding: 16px 8px; font-size: 11px; color: var(--sub); text-align: center; }
.q-att-del {
  position: absolute; top: 5px; right: 5px;
  width: 21px; height: 21px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(15, 20, 30, .62); color: #fff; font-size: 11px; line-height: 21px;
}
.q-att-del:hover { background: var(--bad); }

/* ---------------- AI ---------------- */

.ai-wrap { display: flex; gap: 16px; height: calc(100vh - 124px); height: calc(100dvh - 124px); min-height: 420px; }
.ai-side {
  width: 220px; flex: 0 0 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-s);
}
.ai-side .tree-body { overflow-y: auto; }
.ai-main {
  flex: 1 1 auto; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-s);
}
.chat { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 76%; padding: 11px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.75; }
.msg.ai { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; }
.composer {
  flex: none; display: flex; gap: 10px; align-items: flex-end;
  padding: 12px; border-top: 1px solid var(--line); background: var(--panel-2);
}
.composer textarea {
  flex: 1; min-height: 44px; max-height: 120px; resize: none;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  color: var(--text); padding: 11px 12px; font: 13.5px/1.6 inherit; outline: none;
}

/* ---------------- 收藏 / 设置 ---------------- */

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag {
  padding: 5px 11px; border-radius: 999px; font-size: 12px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--sub);
}
.tag.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 2px; border-top: 1px solid var(--line);
}
.row-t { font-size: 13px; color: var(--text); line-height: 1.6; }
.row-s { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.kv { display: flex; flex-direction: column; }
.kv-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 2px; border-top: 1px solid var(--line); font-size: 13px;
}
.kv-row span { color: var(--sub); }
.kv-row b { color: var(--text); font-weight: 600; }
.note { margin-top: 12px; font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---------------- 轻提示 ---------------- */

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  max-width: 82vw; padding: 11px 18px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  font-size: 12.5px; line-height: 1.6; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .22s; z-index: 999999;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { border-color: rgba(15, 157, 88, .45); color: var(--ok); }
#toast.warn { border-color: rgba(183, 121, 31, .45); color: var(--warn); }
#toast.bad { border-color: rgba(214, 69, 69, .45); color: var(--bad); }

/* ---------------- token 接入 ---------------- */

#rb-access {
  position: fixed; inset: 0; z-index: 999997;
  background: rgba(12, 18, 28, .5);
  backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
}
#rb-access.show { display: flex; }
.rb-card {
  width: min(440px, 92vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow);
}
.rb-t { font-size: 17px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.rb-s { font-size: 12.5px; color: var(--sub); line-height: 1.8; margin-bottom: 16px; }
.rb-card label { display: block; font-size: 12px; color: var(--sub); margin: 12px 0 6px; }
.rb-card input {
  width: 100%; background: var(--field); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); padding: 11px 12px; font: 13px/1.5 ui-monospace, monospace; outline: none;
}
.rb-card input:focus { border-color: var(--accent-line); }
#rb-save {
  width: 100%; margin-top: 20px; border: 0; border-radius: 10px; padding: 12px 0;
  background: var(--accent); color: #fff; font: 600 14px/1 inherit; cursor: pointer;
}

/* ---------------- 确认弹窗 ---------------- */

#cf-mask {
  position: fixed; inset: 0; z-index: 999998;
  background: rgba(12, 18, 28, .5); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
}
#cf-mask.show { display: flex; }
.cf-card {
  width: min(480px, 92vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow);
}
.cf-t { font-size: 15px; font-weight: 650; margin-bottom: 12px; color: var(--text); }
.cf-line { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
#cf-method { font: 700 11px/1 ui-monospace, monospace; padding: 5px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
#cf-path { font: 12px/1.5 ui-monospace, monospace; color: var(--sub); word-break: break-all; }
.cf-body {
  max-height: 150px; overflow: auto; margin-bottom: 14px;
  background: var(--field); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; color: var(--sub); font: 11.5px/1.6 ui-monospace, monospace;
  white-space: pre-wrap; word-break: break-all;
}
.cf-body:empty { display: none; }
.cf-auto { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--sub); cursor: pointer; }
.cf-auto input { accent-color: var(--accent); }
.cf-actions { display: flex; gap: 10px; margin-top: 16px; }
.cf-actions button { flex: 1; padding: 11px 0; border-radius: 10px; border: 0; font: 600 14px/1 inherit; cursor: pointer; }
#cf-cancel { background: var(--field); color: var(--sub); }
#cf-ok { background: var(--accent); color: #fff; }

/* ---------------- 控制台（固定深色） ---------------- */

#dbg { position: fixed; right: 16px; bottom: 16px; z-index: 999996; font-family: inherit; }
.dbg-fabs { display: flex; gap: 8px; justify-content: flex-end; }
#dbg-token, #dbg-fab {
  height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid #2a3140; background: #1a2130; color: #cdd3ff;
  font: 600 13px/1 inherit; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
}
#dbg-token:hover, #dbg-fab:hover { background: #212a3b; }
#dbg-n {
  display: inline-block; min-width: 17px; height: 17px; margin-left: 6px; padding: 0 4px;
  border-radius: 9px; background: rgba(255, 255, 255, .18);
  font-size: 11px; line-height: 17px; text-align: center;
}
#dbg-panel, #tok-panel {
  display: none; position: absolute; right: 0; bottom: 48px;
  width: 480px; max-width: 92vw; height: 70vh;
  flex-direction: column;
  background: var(--con-bg); border: 1px solid var(--con-line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
#dbg-panel.show { display: flex; }
#tok-panel { height: auto; width: 380px; }
#tok-panel.show { display: block; }

.dbg-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 10px 12px; border-bottom: 1px solid var(--con-line); background: var(--con-panel);
  font-size: 13px; font-weight: 600; color: var(--con-text);
}
#dbg-clear, #dbg-close, #tok-close { margin-left: 10px; color: var(--con-sub); font-size: 12px; cursor: pointer; font-weight: 400; }
#dbg-clear { margin-left: auto; }

.dbg-list { max-height: 36%; overflow: auto; border-bottom: 1px solid var(--con-line); flex: none; }
.dbg-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid rgba(37, 45, 61, .6); }
.dbg-row.sel { background: rgba(107, 125, 255, .16); }
.dbg-st {
  min-width: 38px; text-align: center; padding: 2px 5px; border-radius: 5px;
  background: #1a2130; color: var(--con-sub); font: 700 11px/1.6 ui-monospace, monospace;
}
.dbg-st.ok { background: rgba(67, 201, 125, .16); color: #5ade8e; }
.dbg-st.warn { background: rgba(224, 163, 60, .16); color: #f0bd63; }
.dbg-st.bad { background: rgba(229, 84, 75, .16); color: #ff8b83; }
.dbg-st.gray { background: rgba(255, 255, 255, .06); color: var(--con-sub); }
.dbg-url {
  flex: 1; min-width: 0; color: #cfd6e6;
  font: 11.5px/1.4 ui-monospace, Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dbg-dur { color: #6a7488; font: 11px/1 ui-monospace, monospace; flex: none; }
.dbg-empty { padding: 24px 0; text-align: center; color: #6a7488; font-size: 12px; }

.dbg-detail { flex: 1; overflow: auto; padding: 10px 12px 16px; }
.kv-block {
  white-space: pre-wrap; word-break: break-all; margin-bottom: 9px;
  padding: 9px 11px; background: var(--con-code); border: 1px solid #1d2534; border-radius: 8px;
  color: #b9c2d4; font: 11.5px/1.65 ui-monospace, Menlo, monospace;
}
.kv-block b { display: block; color: #7fd4ff; font-weight: 600; margin-bottom: 4px; }

.tok-body { padding: 12px; }
.tok-body label { display: block; color: var(--con-sub); font-size: 11.5px; margin: 10px 0 5px; }
.tok-body input {
  width: 100%; background: var(--con-code); border: 1px solid #1d2534; border-radius: 8px;
  color: var(--con-text); padding: 9px 10px; font: 12px/1.6 ui-monospace, monospace; outline: none;
}
#tok-save {
  width: 100%; margin-top: 14px; border: 0; border-radius: 9px; padding: 11px 0;
  background: #5b6cff; color: #fff; font: 600 14px/1 inherit; cursor: pointer;
}

/* ---------------- 外观面板 ---------------- */

#theme-fab {
  margin-top: 10px; padding: 10px 12px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; color: var(--sub); background: transparent;
  border: 1px dashed var(--line); text-align: left;
}
#theme-fab:hover { color: var(--text); border-color: var(--line-strong); background: var(--field); }

#theme-panel {
  position: fixed; z-index: 999995; top: 0; right: 0; bottom: 0;
  width: min(340px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(23, 32, 46, .12);
  transform: translateX(102%); transition: transform .24s ease;
  display: flex; flex-direction: column;
}
#theme-panel.show { transform: none; }

.th-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  font-size: 14px; font-weight: 650; color: var(--text);
}
#th-close { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; cursor: pointer; }
.th-body { padding: 16px; overflow-y: auto; }

.th-group { margin-bottom: 22px; }
.th-label { font-size: 12px; color: var(--muted); margin-bottom: 9px; letter-spacing: .5px; }

.th-seg { display: flex; gap: 6px; }
.th-seg button {
  flex: 1; padding: 9px 0; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--sub);
  font: 600 12.5px/1 inherit;
}
.th-seg button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.th-colors { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.th-sw {
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--line);
}
.th-sw.on { border-color: var(--text); }
.th-pick {
  width: 30px; height: 30px; padding: 0; border: 1px solid var(--line);
  border-radius: 9px; background: var(--panel-2); cursor: pointer;
}

.th-note { font-size: 11.5px; color: var(--muted); line-height: 1.7; margin-top: 10px; }
#th-reset {
  width: 100%; padding: 11px 0; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--sub);
  font: 600 13px/1 inherit;
}
#th-reset:hover { color: var(--text); border-color: var(--line-strong); }

/* ---------------- 窄屏 ---------------- */

@media (max-width: 860px) {
  #shell { flex-direction: column; }
  #nav {
    width: 100%; flex: none; height: auto; max-height: none;
    flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 12px; overflow: visible;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; font-size: 13px; white-space: nowrap; }
  #nav-items { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { padding: 8px 11px; white-space: nowrap; box-shadow: none!important; }
  .nav-item.on { box-shadow: none; }
  .nav-foot, #theme-fab { display: none; }
  #theme-panel { width: 100%; top: auto; height: 72vh; border-left: 0; border-top: 1px solid var(--line); transform: translateY(102%); }
  #theme-panel.show { transform: none; }

  #stage { padding: 16px 14px 96px; }
  .course-wrap { flex-direction: column; }
  .tree { width: 100%; flex: none; position: static; max-height: 46vh; }
  .ai-wrap { flex-direction: column; height: auto; }
  .ai-side { width: 100%; flex: none; max-height: 200px; }
  .ai-main { height: 62vh; }
  #dbg { right: 10px; bottom: 10px; }
}


/* ---------------- 目录抽屉：默认收起，把宽度让给正文 ---------------- */

.tree-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums;
  margin: 2px 0 6px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  border: 1px dashed var(--line); background: transparent; color: var(--sub);
  font: 600 12.5px/1 inherit;
}
.tree-toggle:hover { color: var(--text); border-color: var(--line-strong); }

.tree {
  position: fixed; z-index: 99999;
  top: 70px; bottom: 16px; left: 12px;
  width: min(360px, 86vw);
  max-height: none;
  display: none;
  box-shadow: 0 18px 50px rgba(20, 28, 40, .22);
}
.tree.open { display: flex; }
.tree > .tree-body { max-height: none; }

.tree-mask {
  display: none;
  position: fixed; inset: 0; z-index: 99998;
  background: rgba(16, 22, 32, .3);
  backdrop-filter: blur(2px);
}
.tree-mask.show { display: block; }

.course-wrap { flex-direction: column; align-items: stretch; }
.course-wrap .main { width: 100%; }

@media (max-width: 1200px) {
  #stage { padding: 16px 16px 96px; }
  #stage > * { max-width: none; }
}

@media (max-width: 1200px) {
  #shell { flex-direction: column; }
  #nav {
    width: 100%; flex: none; height: auto; max-height: none;
    flex-direction: row; align-items: center; gap: 10px;
    padding: 9px 12px; overflow: visible;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; font-size: 13px; white-space: nowrap; }
  #nav-items { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { padding: 8px 11px; white-space: nowrap; box-shadow: none!important; }
  .nav-item.on { box-shadow: none; background: var(--accent-soft); }
  .nav-foot { display: none; }
  #theme-fab { margin: 0; padding: 8px 11px; border-style: solid; white-space: nowrap; }

  .ai-wrap { flex-direction: column; height: auto; }
  .ai-side { width: 100%; flex: none; max-height: 170px; }
  .ai-main { height: 64vh; }
}


 /* 抽屉里的目录更紧凑 */
.tree .tree-item { padding: 8px 10px; }
.tree .ti-name { font-size: 13px; }
.tree .ti-sub { font-size: 10.5px; }
.tree .catalog-item { padding: 5px 8px; }
.tree.open .tree-h { letter-spacing: 1px; }

/* ---------------- 全班成绩 ---------------- */

.st-sum { display: flex; align-items: baseline; gap: 8px; margin-left: auto; margin-right: 14px; }
.st-sum b { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.st-sum span { font-size: 11.5px; color: var(--muted); }
.st-n { flex: none; }

.st-list { max-height: 300px; overflow-y: auto; margin-top: 6px; border-top: 1px solid var(--line); }
.st-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 2px; border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.st-row.me { background: var(--accent-soft); border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.st-rank { width: 26px; flex: none; text-align: right; color: var(--muted); font: 600 11.5px/1 ui-monospace, monospace; }
.st-name { width: 88px; flex: none; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-name em { font-style: normal; margin-left: 5px; font-size: 10px; color: var(--accent); }
.st-bar { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; }
.st-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; opacity: .55; }
.st-score { width: 46px; flex: none; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text); }


/* ---------------- 作答图片上传 ---------------- */

.q-photo { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; flex-wrap: wrap; }
.q-photo-note { font-size: 11px; color: var(--muted); }
.btn.tiny[disabled] { opacity: .55; cursor: default; }
.q-atts { margin-top: 10px; }
.q-att img:active { transform: scale(.98); }


/* 目录按钮放进侧栏/顶栏，避免浮在正文上挡字 */
#nav .tree-toggle { width: 100%; justify-content: flex-start; margin: 6px 0 0; }
#nav .tree-toggle.open { border-style: solid; border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }
@media (max-width: 1200px) {
  #nav .tree-toggle { width: auto; margin: 0; white-space: nowrap; }
}

/* ---------------- 增强选项 & 预览 ---------------- */

.q-enh {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--sub); cursor: pointer;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--field); user-select: none;
}
.q-enh input { accent-color: var(--accent); margin: 0; }

#enh-mask {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); padding: 24px;
}
.enh-card {
  background: var(--panel); color: var(--text);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: min(860px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.enh-h { padding: 14px 18px; font-weight: 650; font-size: 14px; border-bottom: 1px solid var(--line); }
.enh-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 18px; overflow: auto; }
.enh-body figure { margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.enh-body figcaption { font-size: 11.5px; color: var(--muted); }
.enh-body img { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.enh-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); }

@media (max-width: 700px) {
  .enh-body { grid-template-columns: 1fr; }
}

/* ---------------- 模组（一题干多小题） ---------------- */

.q-module { padding-left: 4px; }
.q-sub {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
}
.q-sub-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.q-sub-n { font-weight: 650; font-size: 12.5px; color: var(--accent); }
.q-sub .q-opts { margin-top: 4px; }

/* ---------------- 单题全班作答 ---------------- */

.q-stat { display: none; margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); }
.q-stat.open { display: block; }
.qstat-h { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.qstat-h b { color: var(--accent); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.qstat-row { padding: 6px 0; border-top: 1px dashed var(--line); }
.qstat-k { font-size: 12.5px; color: var(--text); font-weight: 600; }
.qstat-k em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 11.5px; }
.qstat-n { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-top: 2px; }
.qstat-empty { font-size: 12px; color: var(--muted); }
.qstat-score { color: var(--accent); font-weight: 650; font-size: 12px; }

/* ---------------- 自评打分 ---------------- */

.q-self { margin-top: 8px; padding: 9px 11px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; background: var(--field); }
.qs-h { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 650; margin-bottom: 7px; }
.qs-cur { color: var(--accent); font-weight: 650; }
.qs-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qs-chip { min-width: 42px; padding: 4px 8px; font-size: 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums; }
.qs-chip:hover { border-color: var(--accent); }
.qs-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }
.q-self .q-act { margin-top: 8px; }

/* 账号密码登录段 */
.tok-sec { font-size: 12px; font-weight: 650; color: var(--con-text); margin-bottom: 8px; }
.tok-body input#tok-pwd { font-family: inherit; }
#tok-login {
  width: 100%; margin-top: 10px; border: 0; border-radius: 9px; padding: 10px 0;
  background: #2f9e63; color: #fff; font: 600 13.5px/1 inherit; cursor: pointer;
}
.tok-divider { margin: 16px 0 4px; padding-top: 12px; border-top: 1px dashed #26303f; font-size: 11.5px; color: var(--con-sub); }

/* ---------------- 批量下载清单 ---------------- */

#dl-n.on { color: #7fd4ff; margin-left: 2px; }
#dl-panel {
  position: fixed; z-index: 999996; right: 16px; bottom: 108px; width: 400px; max-height: 62vh;
  display: none; flex-direction: column; border-radius: 12px; overflow: hidden;
  background: var(--con-bg); border: 1px solid #26303f; box-shadow: 0 14px 40px rgba(0,0,0,.4);
  color: var(--con-text);
}
#dl-panel.show { display: flex; }
.dl-body { padding: 10px 12px 12px; overflow: auto; }
.dl-list { max-height: 30vh; overflow: auto; }
.dl-row { position: relative; padding: 7px 40px 7px 0; border-bottom: 1px dashed #26303f; }
.dl-name { font-size: 12.5px; font-weight: 600; }
.dl-url { font: 11px/1.5 ui-monospace, Menlo, monospace; color: #8b96a8; word-break: break-all; margin-top: 2px; }
.dl-del { position: absolute; right: 0; top: 8px; background: transparent; border: 1px solid #3a4556; color: #9aa6b8; border-radius: 6px; font-size: 11px; padding: 3px 6px; cursor: pointer; }
.dl-empty { font-size: 12px; color: #8b96a8; padding: 14px 0; }
.dl-tip { font-size: 11px; color: #8b96a8; margin: 8px 0 6px; }
#dl-text { width: 100%; height: 120px; resize: vertical; background: var(--con-code); border: 1px solid #1d2534; border-radius: 8px; color: #cfd8e6; font: 11.5px/1.6 ui-monospace, Menlo, monospace; padding: 8px; }
.dl-btns { display: flex; gap: 8px; margin-top: 8px; }
.dl-btns button { flex: 1; border: 0; border-radius: 8px; padding: 9px 0; font: 600 12.5px/1 inherit; color: #fff; cursor: pointer; }
#dl-copy { background: #16a34a; }
#dl-export { background: #0891b2; }

/* 悬浮按钮区分：批量下载用主色实心 */
#dl-fab {
  height: 38px; padding: 0 14px 0 11px; border-radius: 999px; border: 1px solid var(--accent-line);
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: #fff; font: 600 13px/1 inherit; cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .22);
}
#dl-fab:hover { filter: brightness(1.08); }
#dl-fab:active { transform: translateY(1px); }
#dl-fab .dl-ico {
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .22); font-size: 12px; line-height: 1;
}
#dl-fab #dl-n { min-width: 0; margin: 0; padding: 0; background: transparent; color: #fff; font-weight: 700; }
#dl-fab #dl-n.on { margin-left: 1px; padding: 0 6px; height: 18px; border-radius: 9px; background: rgba(255, 255, 255, .26); }

.nav-foot { justify-content: flex-end; }

/* 登录/调试按钮跟随主题，避免浅色页面上糊一块深色 */
#dbg-token, #dbg-fab {
  background: var(--panel); border-color: var(--line); color: var(--sub);
  box-shadow: var(--shadow-s); font-weight: 600;
}
#dbg-token:hover, #dbg-fab:hover { background: var(--field); color: var(--text); border-color: var(--line-strong); }
#dbg-n { background: var(--accent-soft); color: var(--accent); }
