:root {
  --accent: #0e7c66;
  --accent-soft: #e6f4f1;
  --zh-color: #1a5fb4;
  --bg: #f3f5f7;
  --card: #ffffff;
  --line: #e3e7ea;
  --text: #1f2933;
  --muted: #6b7680;
  --danger: #c0392b;
  --radius: 14px;
}
* { box-sizing: border-box; }
.katex, .katex *, .katex-display, .katex-display * { box-sizing: content-box; }
/* body must not be height:100% — that box would clip the sticky .topbar */
html, body { margin: 0; }
body {
  font-family: Georgia, "Times New Roman", "Songti SC", "STSong", serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
}
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 22px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #0a5c4d);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, sans-serif; letter-spacing: .5px; font-size: 15px;
}
.title { font-weight: 700; font-size: 17px; font-family: -apple-system, "PingFang SC", sans-serif; }
.subtitle { font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.teacher-badge {
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  padding: 4px 12px; border-radius: 999px; font-size: 13px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: all .15s ease;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0a5c4d; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; width: 100%; justify-content: center; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.mini { padding: 3px 9px; font-size: 12.5px; border-radius: 8px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: calc(100vh - 65px); }
.sidebar {
  width: 360px; flex: 0 0 360px;
  background: #fff; border-right: 1px solid var(--line);
  overflow-y: auto; height: calc(100vh - 65px);
  position: sticky; top: 65px; padding: 14px 12px 30px;
}
.sidebar-head {
  font-family: -apple-system, "PingFang SC", sans-serif;
  font-size: 12px; letter-spacing: 2px; color: var(--muted);
  padding: 4px 10px 10px; text-transform: uppercase;
}
.chapter-tree { font-family: -apple-system, "PingFang SC", sans-serif; font-size: 14px; }
.ch-item { border-radius: 10px; margin-bottom: 2px; }
.ch-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; cursor: pointer; border-radius: 10px; font-weight: 600;
}
.ch-head:hover { background: var(--accent-soft); }
.ch-head .arrow { transition: transform .15s; color: var(--muted); font-size: 11px; }
.ch-item.open .arrow { transform: rotate(90deg); }
.ch-head.active { color: var(--accent); }
.ch-count {
  margin-left: auto; background: var(--bg); color: var(--muted);
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.ch-read {
  margin-left: auto; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  font-family: -apple-system, "PingFang SC", sans-serif; white-space: nowrap;
}
.ch-count + .ch-read { margin-left: 0; }
.sec-list { display: none; padding: 2px 0 6px 14px; }
.ch-item.open .sec-list { display: block; }
.sec-item {
  padding: 5px 10px; border-radius: 8px; cursor: pointer; color: #46525c;
  font-size: 13.5px; line-height: 1.45;
}
.sec-item:hover { background: var(--accent-soft); }
.sec-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sec-item.lvl2 { padding-left: 22px; font-size: 13px; }
.sec-item.lvl3 { padding-left: 34px; font-size: 12.5px; color: var(--muted); }
.teacher-tools { margin-top: 16px; padding: 12px; border-top: 1px dashed var(--line); display: grid; gap: 8px; }
.teacher-tools-title { font-size: 12px; color: var(--muted); letter-spacing: 1px; text-align: center; }

/* ---------- content ---------- */
.content { flex: 1; padding: 26px 34px 90px; max-width: 940px; margin: 0 auto; }
.loading { color: var(--muted); text-align: center; padding: 60px; }

.block { margin: 14px 0; }
h2.block-h { font-size: 26px; border-bottom: 2px solid var(--accent); padding-bottom: 8px; margin: 34px 0 16px; }
h3.block-h { font-size: 20px; margin: 28px 0 10px; color: #12433a; }
h4.block-h { font-size: 16.5px; margin: 20px 0 8px; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: 0 1px 2px rgba(16,24,32,.04);
}
.env-box { border-left: 4px solid var(--accent); }
.env-title { font-weight: 700; color: var(--accent); margin-bottom: 6px;
  font-family: -apple-system, "PingFang SC", sans-serif; font-size: 14.5px; }
.env-remark, .env-note { border-left-color: #b7791f; }
.env-remark .env-title, .env-note .env-title { color: #b7791f; }

.zh-block {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed #cfe0ec;
  color: var(--zh-color);
}

/* problem cards */
.problem-card { border: 1px solid var(--line); }
.problem-card.resume-flash { animation: resume-flash 2.6s ease-out; }
@keyframes resume-flash {
  0%, 55% { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
  100% { border-color: var(--line); box-shadow: 0 1px 2px rgba(16,24,32,.04); }
}
.prob-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  font-family: -apple-system, "PingFang SC", sans-serif; }
.prob-label {
  background: var(--accent); color: #fff; padding: 2px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.prob-label.example { background: #7c5cd6; }
.prob-label.handout { background: #64748b; }
.prob-type { font-size: 12px; color: var(--muted); }
.prob-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* ---------- reader colour tags ---------- */
.tag-wrap { position: relative; display: inline-flex; }
.tag-btn { border: 1px solid var(--line); background: #fff; color: var(--muted); }
.tag-btn:hover { color: var(--text); border-color: var(--muted); }
.tag-btn.tag-red { background: #fdeeec; border-color: #e08b86; color: #a5302b; }
.tag-btn.tag-yellow { background: #fdf5dd; border-color: #dcc166; color: #8a6a06; }
.tag-btn.tag-blue { background: #eef4fd; border-color: #8fb2e6; color: #22539c; }
.tag-btn.tag-green { background: #eafaf2; border-color: #7ecfa7; color: #14724b; }
.tag-palette {
  position: absolute; top: calc(100% + 7px); right: 0; z-index: 60;
  display: flex; align-items: center; gap: 9px; padding: 7px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 8px 20px rgba(16,24,32,.16); white-space: nowrap;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.tag-swatch {
  width: 19px; height: 19px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.14);
}
.tag-swatch:hover { transform: scale(1.12); }
.tag-swatch.active { box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--text); }
.tag-swatch.tag-red { background: #d6453f; }
.tag-swatch.tag-yellow { background: #e8b422; }
.tag-swatch.tag-blue { background: #2f6fd0; }
.tag-swatch.tag-green { background: #22a06b; }
.tag-clear { border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 12px; font-family: inherit; padding: 0 2px; }
.tag-clear:hover { color: var(--danger); }
.problem-card { position: relative; }
.problem-card[data-tag] { box-shadow: inset 5px 0 0 var(--tagc); }
.problem-card[data-tag="red"] { --tagc: #d6453f; background: #fffaf9; }
.problem-card[data-tag="yellow"] { --tagc: #e8b422; background: #fffcf2; }
.problem-card[data-tag="blue"] { --tagc: #2f6fd0; background: #f8fbff; }
.problem-card[data-tag="green"] { --tagc: #22a06b; background: #f7fdfa; }

/* ---------- filter by tag ---------- */
.tag-filter {
  display: flex; align-items: center; gap: 6px; padding: 4px 9px;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.tf-label { font-size: 12px; color: var(--muted); }
.tf-btn {
  display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: none; cursor: pointer; padding: 2px 4px;
  font-family: inherit; color: var(--muted); font-size: 12px;
}
.tf-btn.all { border-radius: 999px; padding: 2px 9px; }
.tf-btn.all.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tf-dot { width: 15px; height: 15px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.16); }
.tf-n { font-size: 11px; min-width: 8px; }
.tf-btn:hover .tf-dot { transform: scale(1.12); }
.tf-btn.active .tf-dot { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--text); }
.tf-btn.active .tf-n { color: var(--text); font-weight: 700; }
/* para/guide blocks overwrite their className, so match on data-idx rather than .block */
#content [data-idx].filtered-out { display: none; }
#filter-bar {
  position: sticky; top: 74px; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px; padding: 9px 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  font-family: -apple-system, "PingFang SC", sans-serif; font-size: 13.5px;
  box-shadow: 0 2px 6px rgba(16,24,32,.06);
}
.fb-dot { width: 14px; height: 14px; border-radius: 50%; }
.fb-red { background: #d6453f; } .fb-yellow { background: #e8b422; }
.fb-blue { background: #2f6fd0; } .fb-green { background: #22a06b; }
.fb-stat { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.filter-empty {
  margin: 0 0 14px; padding: 26px; text-align: center; color: var(--muted);
  background: #fff; border: 1px dashed var(--line); border-radius: var(--radius);
  font-family: -apple-system, "PingFang SC", sans-serif; font-size: 14px;
}
.ch-tags { display: inline-flex; gap: 3px; margin-left: 6px; }
.ct-dot {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  color: #fff; font-size: 10.5px; font-weight: 700; font-style: normal;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.ct-red { background: #d6453f; } .ct-yellow { background: #e8b422; color: #5c4708; }
.ct-blue { background: #2f6fd0; } .ct-green { background: #22a06b; }

.answer-zone { margin-top: 12px; }
.answer-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px dashed var(--accent); color: var(--accent);
  background: var(--accent-soft); border-radius: 999px;
  padding: 4px 14px; cursor: pointer; font-size: 13px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.answer-body {
  margin-top: 10px; padding: 12px 16px; border-radius: 10px;
  background: #f0fdf7; border: 1px solid #bbe5d3;
}
.answer-body.hidden-answer { display: none; }
.sol-body { background: #f6f2fd; border-color: #ddd2f5; }
.answer-label, .sol-label { font-weight: 700; font-size: 13px; margin-bottom: 4px;
  font-family: -apple-system, "PingFang SC", sans-serif; }
.answer-label { color: #0a5c4d; }
.sol-label { color: #6d4fc4; }
.answer-in-sol {
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed #ddd2f5;
  color: #6d4fc4; font-size: 15px;
}

.fig-img { max-width: 68%; display: block; margin: 14px auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; background: #fff; }
.centered { text-align: center; }
.guide-line { font-weight: 700; color: var(--accent); margin: 14px 0 8px;
  font-family: -apple-system, "PingFang SC", sans-serif; font-size: 14.5px; }
.answer-divider {
  display: flex; align-items: center; gap: 14px; margin: 30px 0 12px;
  color: var(--muted); font-family: -apple-system, "PingFang SC", sans-serif; font-size: 13px;
}
.answer-divider::before, .answer-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.para-block p { margin: 10px 0; }
.latex-fbox { border: 1.5px solid #94a3b8; border-radius: 6px; padding: 10px 14px; display: inline-block; background:#f8fafc; }
.llist { margin: 8px 0 8px 4px; padding-left: 26px; }
.llist li { margin: 4px 0; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,32,.45); z-index: 300;
  display: flex; align-items: center; justify-content: center; }
.modal.hidden, .hidden { display: none; }
.modal-card { background: #fff; border-radius: 16px; padding: 22px 24px;
  width: min(680px, 92vw); max-height: 88vh; overflow: auto;
  font-family: -apple-system, "PingFang SC", sans-serif; }
.modal-card.narrow { width: min(400px, 92vw); }
.modal-card.wide { width: min(940px, 95vw); }
.modal-card h3 { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; margin-top: 8px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 2px 10px;
  border-radius: 999px; font-size: 12px; }
.tex-editor { width: 100%; height: 55vh; font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; resize: vertical; margin-top: 8px; }
.edit-area { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; font-size: 14px; font-family: inherit; margin-top: 6px; }

/* figure manager */
.figs-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-top: 12px; }
.fig-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-size: 11.5px; }
.fig-card img { width: 100%; height: 110px; object-fit: contain; background: #fafafa;
  border-radius: 8px; border: 1px solid var(--line); }
.fig-path { color: var(--muted); word-break: break-all; margin: 6px 0; line-height: 1.35; }
.fig-card input[type=file] { width: 100%; font-size: 11px; }

/* toast */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1f2933; color: #fff; padding: 10px 20px; border-radius: 10px; z-index: 200;
  font-family: -apple-system, "PingFang SC", sans-serif; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.hidden { display: none; }

/* katex sizing */
.katex { font-size: 1.06em; }
.katex-display { margin: 10px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -360px; transition: left .2s; z-index: 40; }
  .sidebar.open { left: 0; }
}

/* ---------- 登录门(学生/教师登录前全屏覆盖) ---------- */
.gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef3f2 0%, var(--bg) 55%, #e9efee 100%);
}
.gate-card {
  width: min(380px, 92vw);
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 18px 50px rgba(15, 60, 50, .12);
  padding: 38px 34px 26px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.gate-logo {
  width: 58px; height: 58px; border-radius: 15px; margin: 0 auto;
  background: linear-gradient(135deg, var(--accent), #0a5c4d);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px; font-size: 18px;
}
.gate-title { font-size: 21px; font-weight: 700; color: var(--text); }
.gate-sub { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.gate-btn { justify-content: center; padding: 11px; font-size: 15px; }
.gate-foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.gate .input { text-align: center; font-size: 15px; }

/* ---------- 学生徽标 ---------- */
.student-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid #cde8e2; padding: 4px 12px; border-radius: 999px; font-size: 13px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.student-badge button {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 0; text-decoration: underline; font-family: inherit;
}
.student-badge button:hover { color: var(--danger); }

/* ---------- 教师工具:章节锁 ---------- */
.lock-btn {
  border: none; background: none; cursor: pointer; font-size: 13px;
  margin-left: 4px; opacity: .55; padding: 2px;
}
.lock-btn:hover { opacity: 1; }
.lock-btn.on { opacity: 1; }
.ch-head.locked-ch { opacity: .55; }

/* ---------- 学生账号管理 ---------- */
.student-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.student-add .input { width: auto; min-width: 120px; padding: 8px 10px; font-size: 13px; }
.students-list { margin-top: 10px; max-height: 46vh; overflow: auto; }
.stu-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px;
  font-family: -apple-system, "PingFang SC", sans-serif;
}
.stu-row b { min-width: 110px; }
.stu-row .stu-note { color: var(--muted); flex: 1; font-size: 13px; }
.stu-row .stu-del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 12px; }

/* ---------- 学生章节权限 ---------- */
.stu-chapters-line { display: flex; align-items: flex-start; gap: 10px; margin: 8px 0 2px; }
.stu-ch-label { font-size: 13px; color: var(--muted); padding-top: 5px; white-space: nowrap;
  font-family: -apple-system, "PingFang SC", sans-serif; }
.stu-chapter-checks { display: flex; flex-wrap: wrap; gap: 6px 10px; flex: 1; }
.stu-chapter-checks label {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer;
  font-family: -apple-system, "PingFang SC", sans-serif; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
}
.stu-chapter-checks label:has(input:checked) { background: var(--accent-soft); border-color: #bfe0d8; }
.stu-ch-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px;
  font-size: 12px; padding: 3px 8px; cursor: pointer; font-family: inherit; }
.stu-ch-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 节/小节编号 & TikZ 图片 ---------- */
.sec-no {
  font-family: -apple-system, "PingFang SC", sans-serif;
  color: var(--accent); font-weight: 700; margin-right: 10px;
}
.sec-item .sec-no { font-weight: 600; margin-right: 6px; opacity: .85; }
img.tikz-img { display: block; margin: 10px auto; max-width: 100%; height: auto; }

/* ---------- 侧栏中英文标题 ---------- */
.sidebar .title-zh, .sec-item .title-zh {
  display: inline-block; color: var(--zh-color); opacity: .78;
  font-size: .86em; margin-left: 6px; font-weight: 400;
}
.ch-head > span:nth-child(2) { flex: 1; min-width: 120px; }
