:root {
  --primary: #4f6ef7;
  --primary-dark: #3b55d9;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #7a8299;
  --border: #e6e9f2;
  --success: #2eab5c;
  --danger: #e5534b;
  --warn: #e8a33d;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(31, 41, 72, .07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.7;
}
a { color: var(--primary); text-decoration: none; }
button {
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 9px 18px; background: var(--primary); color: #fff; transition: .15s;
}
button:hover { background: var(--primary-dark); }
button:disabled { background: #b9c2dd; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
button.ghost:hover { background: #eef1fe; }
button.plain { background: #eef1f7; color: var(--text); }
button.plain:hover { background: #e2e7f0; }
input, textarea, select {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; outline: none; background: #fff; transition: border .15s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 110px; resize: vertical; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  background: #fff; padding: 0 22px; height: 58px; box-shadow: var(--shadow);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--primary); }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 14px; border-radius: 10px; color: var(--muted); font-weight: 500;
}
.nav a.active, .nav a:hover { background: #eef1fe; color: var(--primary); }
.nav .badge { margin-left: 4px; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.userbox .role-chip { background: #eef1fe; color: var(--primary); border-radius: 99px; padding: 2px 10px; }
.userbox button { padding: 5px 12px; font-size: 13px; background: #eef1f7; color: var(--text); }

/* ---------- 布局 ---------- */
.container { max-width: 1180px; margin: 20px auto; padding: 0 18px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; background: #eef1f7; color: var(--muted); }
.badge.done { background: #e3f6ea; color: var(--success); }
.badge.doing { background: #fdf3e2; color: var(--warn); }
.badge.lock { background: #f1f2f6; color: #b3b9c9; }
.badge.diff-easy { background: #e3f6ea; color: var(--success); }
.badge.diff-medium { background: #fdf3e2; color: var(--warn); }
.badge.diff-hard { background: #fde9e7; color: var(--danger); }

/* ---------- 登录 ---------- */
.auth-wrap { min-height: calc(100vh - 130px); display: flex; align-items: center; justify-content: center; }
.auth-card { width: 400px; max-width: 92vw; }
.auth-card h1 { text-align: center; margin-bottom: 6px; font-size: 22px; }
.auth-card .sub { text-align: center; margin-bottom: 20px; }
.tabs { display: flex; background: #eef1f7; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; background: transparent; color: var(--muted); padding: 8px; }
.tabs button.on { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.auth-card button[type=submit] { width: 100%; padding: 11px; }
.err-tip { color: var(--danger); font-size: 13px; margin-bottom: 12px; text-align: center; }

/* ---------- 首页 ---------- */
.page-title { font-size: 20px; margin-bottom: 4px; }
.sub-row { margin-bottom: 20px; }
.sub-card { cursor: pointer; transition: .15s; position: relative; }
.sub-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(31,41,72,.12); }
.sub-card h3 { margin-bottom: 6px; }
.progress-track { height: 8px; background: #edf0f7; border-radius: 99px; overflow: hidden; margin: 12px 0 6px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #6c8cff, var(--primary)); border-radius: 99px; transition: width .3s; }
.stat-row { display: flex; gap: 14px; margin: 18px 0; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 150px; text-align: center; padding: 16px; }
.stat-card b { font-size: 26px; color: var(--primary); display: block; }
.stat-card.hot b { color: var(--warn); }

/* ---------- 学习页 ---------- */
.learn-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.tree { position: sticky; top: 74px; max-height: calc(100vh - 96px); overflow: auto; padding: 14px; }
.tree .chapter { margin-bottom: 10px; }
.tree .chapter-title { font-weight: 600; font-size: 14px; padding: 6px 4px; color: var(--text); }
.tree .chapter-title.fold, .tree .sec-title.fold { cursor: pointer; user-select: none; border-radius: 8px; }
.tree .chapter-title.fold:hover { background: #f2f4fb; }
.tree .sec-title.fold:hover { background: #f7f8fc; }
.tree .arrow { display: inline-block; width: 16px; color: var(--muted); font-size: 12px; }
.tree .sec-title { font-size: 13px; color: var(--muted); padding: 4px 4px 2px 10px; }
.tree .kp-item {
  display: flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 9px;
  font-size: 13px; cursor: pointer; color: var(--text);
}
.tree .kp-item:hover { background: #f2f4fb; }
.tree .kp-item.active { background: var(--primary); color: #fff; }
.tree .kp-item.locked { color: #b3b9c9; cursor: not-allowed; }
.tree .kp-item .st { margin-left: auto; font-size: 11px; }
.crumb { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.kp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.kp-head h2 { font-size: 21px; }
.kp-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 6px; }
.video-box { margin: 14px 0; border-radius: 12px; overflow: hidden; background: #000; }
.video-box video { width: 100%; max-height: 420px; display: block; }
.video-miss { padding: 18px; color: #cbd2e1; font-size: 14px; text-align: center; }

/* Markdown 正文 */
.md { font-size: 15px; }
.md h1 { font-size: 20px; margin: 18px 0 10px; }
.md h2 { font-size: 17px; margin: 16px 0 8px; padding-left: 9px; border-left: 3px solid var(--primary); }
.md h3 { font-size: 15px; margin: 12px 0 6px; }
.md p, .md li { margin: 6px 0; }
.md ul, .md ol { padding-left: 22px; }
.md table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: #f5f7fd; }
.md code { background: #eef1f7; border-radius: 5px; padding: 1px 6px; font-size: 13px; }
.md pre { background: #f5f7fd; padding: 12px; border-radius: 10px; overflow-x: auto; }

/* 习题 */
.quiz-panel { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 16px; }
.quiz-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.q-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.q-stem { font-weight: 500; margin-bottom: 8px; }
.q-stem .q-idx { color: var(--muted); font-weight: 400; margin-right: 6px; }
.q-opt { display: flex; align-items: flex-start; gap: 8px; padding: 7px 10px; border-radius: 9px; cursor: pointer; }
.q-opt:hover { background: #f2f4fb; }
.q-opt input { width: auto; margin-top: 4px; }
.q-opt.sel { background: #eef1fe; }
.feedback { border-radius: 10px; padding: 10px 14px; margin-top: 10px; font-size: 14px; }
.feedback.good { background: #e3f6ea; color: #1d7a43; }
.feedback.bad { background: #fde9e7; color: #b03a33; }
.feedback b { display: block; margin-bottom: 3px; }
.judge-btns button { margin-right: 8px; }
.judge-btns .on-pick { outline: 2px solid var(--primary); }
.quiz-result { text-align: center; padding: 14px; background: #f5f7fd; border-radius: 12px; margin-top: 6px; }

/* 笔记 */
.note-panel { margin-top: 12px; }
.note-panel textarea { margin-bottom: 8px; }

/* 错题本 / 复习 */
.item-card { margin-bottom: 12px; }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.empty-tip { text-align: center; color: var(--muted); padding: 40px 0; }

/* 美术评卷对话 */
.art-chat { max-width: 860px; margin: 0 auto; }
.art-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.art-msgs {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; min-height: 320px; max-height: 56vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px;
}
.art-input-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
/* 美术评卷输入区两行布局：拍照/选图一行，文字输入+发送一行（不影响 AI 答疑面板的同名类） */
.art-input-wrap .ai-input { flex-direction: column; gap: 8px; }
.art-input-wrap .ai-actions, .art-input-wrap .ai-textrow { display: flex; gap: 8px; align-items: center; }
.art-input-wrap .ai-textrow input { flex: 1; }
.pending-img { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pending-img img { height: 64px; border-radius: 8px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #2b3040; color: #fff; padding: 10px 22px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 99;
}
#toast.show { opacity: .95; }

/* AI 答疑面板 */
.ai-panel {
  margin-top: 14px; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; background: #fafbff;
}
.ai-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.ai-messages {
  max-height: 320px; overflow-y: auto; display: flex; flex-direction: column;
  gap: 10px; padding: 4px 2px; margin-bottom: 10px;
}
.ai-msg { display: flex; }
.ai-msg.user { justify-content: flex-end; }
.ai-bubble {
  max-width: 85%; padding: 9px 13px; border-radius: 12px; font-size: 14px;
}
.ai-msg.user .ai-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.ai-msg.assistant .ai-bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.ai-msg.assistant .ai-bubble p { margin: 4px 0; }
.ai-input { display: flex; gap: 8px; }
.ai-input input { flex: 1; }

@media (max-width: 860px) {
  .learn-layout { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 300px; }
  .container { margin-top: 12px; padding: 0 12px; }

  /* 顶栏改为两行：上行品牌+用户，下行导航横向滑动，避免挤压 */
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 6px 10px; }
  .brand { font-size: 15px; }
  .brand img { width: 22px; height: 22px; }
  .userbox { margin-left: auto; font-size: 12px; gap: 8px; }
  .userbox button { padding: 4px 10px; }
  .nav {
    flex: 1 1 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 6px; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex-shrink: 0; padding: 7px 12px; font-size: 14px; }
  .art-input-wrap .ai-actions button { flex: 1; }
}
