:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dde3ec;
  --border-strong: #c7d0de;
  --text: #1f2937;
  --text-soft: #5b6675;
  --text-faint: #8a94a3;
  --brand: #1d5fd1;
  --brand-dark: #174aa3;
  --brand-soft: #e8f0ff;
  --green: #0f7b55;
  --green-soft: #e5f6ef;
  --amber: #9a5b00;
  --amber-soft: #fff4dc;
  --red: #b42318;
  --red-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 32px;
  height: 60px;
  background: #10213d;
  color: #e9eef7;
  box-shadow: 0 2px 10px rgba(16, 33, 61, 0.22);
}

.brand {
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.nav a {
  color: #c6d2e6;
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  white-space: nowrap;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  text-decoration: none;
}

.nav a.active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-weight: 600;
}

.nav .spacer {
  flex: 1;
}

/* 顶栏账号级操作：邀请老师 / 兑换邀请码 */
.nav .topbar-action {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.28);
  color: #eef3fb;
  white-space: nowrap;
}

.nav .topbar-action:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c6d2e6;
  font-size: 13px;
  white-space: nowrap;
}

.user-chip .role {
  color: #8fa6c9;
}

.btn.logout {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  color: #dbe5f5;
  padding: 5px 10px;
}

.btn.logout:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- 布局 ---------- */

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 28px 72px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 24px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.page-head .sub {
  margin-top: 4px;
  color: var(--text-soft);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 16px;
  font-weight: 650;
}

.card-head .hint {
  color: var(--text-faint);
  font-size: 12px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.muted {
  color: var(--text-soft);
}

.faint {
  color: var(--text-faint);
  font-size: 12px;
}

.mt-8 {
  margin-top: 8px;
}

.mt-12 {
  margin-top: 12px;
}

.mt-16 {
  margin-top: 16px;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: var(--surface-soft);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--brand);
  padding-left: 6px;
  padding-right: 6px;
}

.btn.ghost:hover {
  background: var(--brand-soft);
}

.btn.danger {
  border-color: #e6b5b0;
  color: var(--red);
  background: #fffafa;
}

.btn.danger:hover {
  background: var(--red-soft);
}

.btn.small {
  padding: 4px 9px;
  font-size: 12px;
}

.btn.block {
  width: 100%;
}

/* ---------- 表格 ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px;
  border-bottom: 1px solid #edf1f6;
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: #fafbfd;
}

.table .nowrap {
  white-space: nowrap;
}

.table .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- 标签 ---------- */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.7;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.draft,
.badge.pending,
.badge.waiting {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: #f2d9a8;
}

.badge.finalized,
.badge.approved,
.badge.active,
.badge.official {
  background: var(--green-soft);
  color: var(--green);
  border-color: #bfe8d7;
}

.badge.rejected,
.badge.mastered {
  background: #eef1f5;
  color: #5b6675;
  border-color: #d9e0e9;
}

.badge.private {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-color: #c7d9fb;
}

.badge.teacher {
  background: #f1ecff;
  color: #5b3cbb;
  border-color: #ddd2fb;
}

.badge.ai {
  background: #edf7ff;
  color: #1b6aa8;
  border-color: #c9e5fb;
}

.badge.basic {
  background: var(--green-soft);
  color: var(--green);
}

.badge.intermediate {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.badge.advanced {
  background: var(--red-soft);
  color: var(--red);
}

.badge.unknown {
  background: var(--surface-soft);
  color: var(--text-faint);
}

.difficulty-summary {
  color: var(--text-soft);
  font-size: 13px;
  margin-top: 10px;
}

.strength-note {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-left: 3px solid var(--brand);
  background: var(--brand-soft);
  color: var(--text-soft);
  font-size: 13px;
  border-radius: 0 6px 6px 0;
}

.badge.view {
  background: var(--surface-soft);
  color: var(--text-soft);
  border-color: var(--border);
}

.badge.out-of-scope {
  background: #fff4e6;
  color: #a35a00;
  border-color: #f0d3aa;
  margin-left: 6px;
}

.scope-out {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.scope-out > summary {
  cursor: pointer;
  color: var(--text-soft);
  font-size: 13px;
}

.change-details > summary {
  cursor: pointer;
  color: var(--text-soft);
}

.change-json {
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 11px;
  background: var(--surface-soft);
  padding: 8px;
  border-radius: 6px;
  margin: 6px 0 0;
}

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

.alert-slot {
  margin-bottom: 16px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.alert.error {
  background: var(--red-soft);
  border-color: #f2c2bd;
  color: #7f1d1d;
}

.alert.success {
  background: var(--green-soft);
  border-color: #bfe8d7;
  color: #0b5d42;
}

.alert.info {
  background: var(--brand-soft);
  border-color: #c7d9fb;
  color: #123f8f;
}

.alert .close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  opacity: 0.65;
}

.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--text-faint);
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.section-error {
  margin-top: 10px;
}

/* ---------- 表单 ---------- */

.form-grid {
  display: grid;
  gap: 14px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-row.inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.form-row label,
.label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.12);
}

.textarea {
  min-height: 78px;
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.form-message {
  font-size: 12px;
  color: var(--red);
  min-height: 18px;
}

.required::after {
  content: " *";
  color: var(--red);
}

/* ---------- 登录 ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 18% 8%, #e8f0ff 0%, transparent 62%),
    radial-gradient(700px 380px at 90% 92%, #e5f6ef 0%, transparent 58%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(16, 33, 61, 0.12);
  padding: 34px 32px 30px;
}

.login-card h1 {
  font-size: 22px;
  letter-spacing: -0.01em;
}

.login-card .sub {
  color: var(--text-soft);
  margin-top: 5px;
  margin-bottom: 24px;
}

.login-card .form-grid {
  gap: 16px;
}

.login-card .input {
  padding: 10px 12px;
}

.login-foot {
  margin-top: 20px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

/* ---------- 错题 / 知识点 ---------- */

.mistake-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mistake-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.mistake-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.mistake-group-head h3 {
  font-size: 14px;
  font-weight: 650;
}

.mistake-group-head .count {
  color: var(--text-faint);
  font-size: 12px;
}

.mistake-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border-bottom: 1px solid #edf1f6;
}

.mistake-row:last-child {
  border-bottom: none;
}

.mistake-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 600;
}

.mistake-meta {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 4px;
}

.mistake-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.ai-original {
  margin-top: 6px;
  padding: 5px 9px;
  border-left: 3px solid #7eb6e8;
  background: #f3f9ff;
  color: #36556f;
  font-size: 12px;
  border-radius: 0 6px 6px 0;
}

.ai-original strong {
  color: #1b6aa8;
}

/* ---------- 练习卷列表 / 详情 ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.stat .stat-label {
  color: var(--text-faint);
  font-size: 12px;
}

.stat .stat-value {
  font-size: 19px;
  font-weight: 650;
  margin-top: 2px;
}

.practice-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.practice-title-row h1 {
  font-size: 22px;
}

.seq-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.seq-actions .btn {
  padding: 3px 7px;
  min-width: 30px;
}

.ai-original-mark {
  display: block;
  margin-top: 4px;
  color: #7a5b12;
  font-size: 12px;
}

/* ---------- 候选题目 ---------- */

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.candidate {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: #ffffff;
}

.candidate:hover {
  border-color: var(--border-strong);
  background: var(--surface-soft);
}

.candidate.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.candidate input {
  margin-top: 3px;
}

.candidate .cand-title {
  font-weight: 600;
  font-size: 13px;
}

.candidate .cand-stem {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 3px;
}

.candidate .cand-stem img,
.stem-preview-body img {
  max-width: 100%;
  max-height: 120px;
  vertical-align: middle;
}

.stem-previews {
  display: grid;
  gap: 12px;
}

.stem-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
}

.stem-preview-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.stem-preview-body {
  font-size: 14px;
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.stem-preview-body img {
  max-height: 160px;
}

/* 独立图形（builder 按 image_sizes 判定的 .block-img）：独占一行、居中。
   详情页给到 320px；换题候选列表矮一些，避免一张图占满弹窗。 */
.stem-preview-body img.block-img {
  display: block;
  max-height: 320px;
  height: auto;
  margin: 8px auto;
  vertical-align: baseline;
}

.candidate .cand-stem img.block-img {
  display: block;
  max-height: 200px;
  height: auto;
  margin: 6px auto;
  vertical-align: baseline;
}

/* ---------- 勾选知识点 ---------- */

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 13px;
}

.check-item input {
  margin-top: 4px;
}

.chapter-label {
  grid-column: 1 / -1;
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- 邀请码 ---------- */

.invite-code {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid #f2d9a8;
  background: var(--amber-soft);
  border-radius: var(--radius-sm);
}

.invite-code .label {
  color: var(--amber);
}

.invite-code code {
  display: block;
  margin-top: 6px;
  padding: 9px 10px;
  background: #ffffff;
  border: 1px dashed #d9b56a;
  border-radius: 6px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  word-break: break-all;
}

/* ---------- 学生选择 ---------- */

.student-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.student-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 170px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #ffffff;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.student-item:hover {
  border-color: var(--brand);
  background: var(--surface-soft);
}

.student-item.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.student-item .name {
  font-weight: 650;
  font-size: 14px;
}

.student-item .meta {
  color: var(--text-soft);
  font-size: 12px;
}

/* ---------- 弹窗 / 提示条 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 20px 32px;
  background: rgba(15, 23, 42, 0.45);
  overflow-y: auto;
}

.modal {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

.modal.wide {
  max-width: 820px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-size: 16px;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 18px 20px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  max-width: 360px;
  padding: 11px 16px;
  border-radius: 9px;
  background: #10213d;
  color: #ffffff;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.24);
}

/* ---------- 错误页 ---------- */

.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.error-card {
  max-width: 460px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 34px;
}

.error-code {
  font-size: 42px;
  font-weight: 750;
  color: var(--brand);
  line-height: 1;
  margin-bottom: 12px;
}

.error-card h1 {
  font-size: 20px;
  margin-bottom: 8px;
}

.error-card p {
  color: var(--text-soft);
  margin-bottom: 20px;
}

/* ---------- 响应式（仅宽屏优先，不做移动端专门适配） ---------- */

@media (max-width: 980px) {
  .grid.two,
  .grid.three,
  .stats {
    grid-template-columns: minmax(0, 1fr);
  }

  .mistake-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    padding: 0 18px;
  }

  .container {
    padding: 22px 18px 60px;
  }
}
