:root {
  --bg: #0f1117;
  --bg-soft: #171a23;
  --bg-card: #1d2130;
  --border: #2a3040;
  --text: #e6e9f0;
  --text-dim: #9aa3b8;
  --text-faint: #6b7488;
  --primary: #4f8cff;
  --primary-soft: rgba(79, 140, 255, .12);
  --green: #2ecc71;
  --green-soft: rgba(46, 204, 113, .14);
  --red: #ff5c5c;
  --red-soft: rgba(255, 92, 92, .14);
  --amber: #ffb020;
  --amber-soft: rgba(255, 176, 32, .14);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
  gap: 12px;
}

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

.logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #4f8cff, #8b5cf6);
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.5px;
}

.brand h1 { font-size: 17px; font-weight: 600; }
.brand .sub { font-size: 12px; color: var(--text-faint); }

.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }

.tab {
  background: none; border: 0; color: var(--text-dim);
  padding: 8px 18px; border-radius: 8px;
  font-size: 14px; cursor: pointer; transition: .15s;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: #fff; font-weight: 500; }

/* ---------- 全局进度 ---------- */
.global-progress {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.gp-bar { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.gp-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, #4f8cff, #2ecc71);
  transition: width .4s ease;
}
.gp-text { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

/* ---------- 主区域 ---------- */
main { flex: 1; display: flex; overflow: hidden; }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }

/* ---------- 学习视图 ---------- */
.sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.search-box { padding: 14px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; padding: 9px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px;
  font-family: inherit; outline: none;
}
.search-box input:focus { border-color: var(--primary); }

.chapter-list { flex: 1; overflow-y: auto; padding: 8px; }

.chapter-item {
  margin-bottom: 2px;
}
.chapter-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13.5px;
  transition: .12s; user-select: none;
}
.chapter-head:hover { background: var(--bg-card); }
.chapter-head.open { background: var(--bg-card); }

.ch-arrow { font-size: 10px; color: var(--text-faint); transition: transform .2s; }
.chapter-head.open .ch-arrow { transform: rotate(90deg); }

.ch-title { flex: 1; font-weight: 500; }
.ch-badge {
  font-size: 11px; color: var(--text-faint);
  background: var(--bg); padding: 1px 7px; border-radius: 10px;
}

.section-list { display: none; padding-left: 12px; }
.section-list.open { display: block; }

.section-item {
  padding: 7px 12px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--text-dim);
  transition: .12s; display: flex; align-items: center; gap: 6px;
}
.section-item:hover { background: var(--bg-card); color: var(--text); }
.section-item.active { background: var(--primary-soft); color: var(--primary); }

.s-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.section-item.done .s-dot { background: var(--green); }
.section-item.done { color: var(--green); }

/* ---------- 内容区 ---------- */
.content {
  flex: 1; overflow-y: auto; padding: 32px 44px;
  max-width: 940px;
}

.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; min-height: 340px;
  color: var(--text-faint); text-align: center;
}
.empty-icon { font-size: 44px; margin-bottom: 16px; opacity: .5; }
.empty-state h2 { font-size: 17px; color: var(--text-dim); font-weight: 500; margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 400px; }

.content-header {
  margin-bottom: 28px; padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.content-chapter {
  font-size: 12px; color: var(--primary);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 8px; font-weight: 500;
}
.content-header h2 { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.content-meta { font-size: 12.5px; color: var(--text-faint); }

.point-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  transition: .15s;
}
.point-card:hover { border-color: #38405a; }

.point-card.mastered {
  border-color: rgba(46, 204, 113, .35);
  background: linear-gradient(90deg, var(--green-soft), var(--bg-card) 40%);
}

.point-text {
  display: flex; gap: 12px; align-items: flex-start;
  cursor: pointer;
}
.point-check {
  width: 20px; height: 20px; flex-shrink: 0; margin-top: 2px;
  border: 2px solid var(--border); border-radius: 6px;
  display: grid; place-items: center;
  transition: .15s; font-size: 12px; color: transparent;
}
.point-card.mastered .point-check {
  background: var(--green); border-color: var(--green); color: #fff;
}
.point-body { flex: 1; font-size: 14.5px; line-height: 1.75; }

.point-body strong { color: #93b8ff; font-weight: 600; }
.point-body em { color: var(--amber); font-style: normal; font-weight: 500; }
.point-body code {
  background: var(--bg); padding: 2px 6px; border-radius: 4px;
  font-size: 13px; color: #ffb86c; font-family: ui-monospace, monospace;
}

.sub-block {
  margin: 22px 0 14px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
}
.sub-block h4 {
  font-size: 15px; color: var(--primary);
  margin-bottom: 12px; font-weight: 600;
}

/* 章节底部操作 */
.chapter-actions {
  margin-top: 28px; padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; flex-wrap: wrap;
}

/* ---------- 按钮 ---------- */
.btn {
  padding: 9px 18px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text);
  font-size: 13.5px; cursor: pointer;
  font-family: inherit; transition: .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: #3a4358; background: #222738; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.btn.primary:hover { background: #3d7ae8; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.link-btn {
  background: none; border: 0; color: var(--text-faint);
  font-size: 12px; cursor: pointer; text-decoration: underline;
  font-family: inherit;
}
.link-btn:hover { color: var(--red); }

/* ---------- 刷题视图 ---------- */
#view-quiz { flex-direction: column; overflow-y: auto; padding: 24px 32px; }

.quiz-toolbar {
  display: flex; align-items: flex-end; gap: 14px;
  padding: 16px 20px; background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 22px; flex-wrap: wrap;
}

.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label { font-size: 11.5px; color: var(--text-faint); }
.filter-group select {
  padding: 8px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; cursor: pointer; min-width: 150px;
}
.filter-group select:focus { border-color: var(--primary); }

.quiz-counter { margin-left: auto; font-size: 13px; color: var(--text-dim); }

.quiz-stage { max-width: 820px; margin: 0 auto; width: 100%; }

.quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 30px;
}

.quiz-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px; font-size: 12px; color: var(--text-faint);
}
.quiz-tag {
  background: var(--primary-soft); color: var(--primary);
  padding: 3px 10px; border-radius: 10px; font-weight: 500;
}

.quiz-question {
  font-size: 18px; font-weight: 600; line-height: 1.6;
  margin-bottom: 22px; color: #fff;
}

.quiz-hint {
  font-size: 13px; color: var(--text-faint);
  margin-bottom: 16px; font-style: italic;
}

.quiz-answer {
  margin-top: 22px; padding-top: 20px;
  border-top: 1px dashed var(--border);
  display: none;
}
.quiz-answer.show { display: block; }

.answer-label {
  font-size: 12px; color: var(--green);
  font-weight: 600; margin-bottom: 12px;
  letter-spacing: .5px;
}

.answer-list { list-style: none; }
.answer-list li {
  position: relative; padding-left: 20px;
  margin-bottom: 10px; font-size: 14.5px;
  color: var(--text); line-height: 1.75;
}
.answer-list li::before {
  content: "▸"; position: absolute; left: 4px;
  color: var(--primary);
}

.quiz-actions {
  margin-top: 22px; display: flex; gap: 10px;
  flex-wrap: wrap; align-items: center;
}

.mark-btns { display: flex; gap: 8px; margin-left: auto; }
.btn.mark {
  padding: 8px 16px; font-size: 13px;
}
.btn.mark.good:hover, .btn.mark.good.active {
  background: var(--green-soft); border-color: var(--green); color: var(--green);
}
.btn.mark.bad:hover, .btn.mark.bad.active {
  background: var(--red-soft); border-color: var(--red); color: var(--red);
}

/* ---------- 统计视图 ---------- */
#view-stats {
  display: none; flex-direction: column;
  padding: 28px 32px; overflow-y: auto;
}
#view-stats.active { display: flex; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; max-width: 1100px; margin: 0 auto; width: 100%;
}

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.stat-label { font-size: 12px; color: var(--text-faint); margin-bottom: 10px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-value.small { font-size: 20px; }
.stat-sub { font-size: 12px; color: var(--text-faint); margin-top: 8px; }

.stat-card.full { grid-column: 1 / -1; }

.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar-name { width: 150px; font-size: 13px; color: var(--text-dim); flex-shrink: 0; }
.bar-track { flex: 1; height: 20px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar-inner {
  height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, #4f8cff, #2ecc71);
  transition: width .5s; min-width: 2px;
}
.bar-num { font-size: 12px; color: var(--text-dim); width: 70px; text-align: right; flex-shrink: 0; }

/* ---------- 页脚 ---------- */
.footer {
  padding: 10px 24px; background: var(--bg-soft);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--text-faint);
  flex-wrap: wrap; gap: 8px;
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2f3648; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3d465c; }

/* ---------- 响应式 ---------- */
@media (max-width: 820px) {
  .sidebar { width: 100%; max-height: 260px; border-right: 0; border-bottom: 1px solid var(--border); }
  main { flex-direction: column; }
  .content { padding: 20px; }
  #view-quiz, #view-stats { padding: 16px; }
  .quiz-card { padding: 20px; }
  .brand h1 { font-size: 15px; }
}
