:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --text: #1f2937;
  --muted: #64748b;
  --line: #d8e0ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #f97316;
  --success: #16a34a;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

/* 兜底：作者样式里的 `display` 会盖过浏览器默认的 `[hidden] { display: none }`，
   于是设了 display 的组件（如 .ai-panel）加上 hidden 属性也藏不住。
   站点里 rating-widget / ai-panel / exercise-result 等都靠 hidden 控制显隐，
   这条规则保证 hidden 始终生效。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 34rem), var(--bg);
}

a {
  color: inherit;
}

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 64px;
}

.hero {
  margin-bottom: 28px;
}

.eyebrow,
.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
  background: #dbeafe;
}

h1 {
  margin: 14px 0 12px;
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.08;
}

h2 {
  margin: 0 0 12px;
  font-size: 24px;
}

h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

p {
  line-height: 1.75;
}

.hero-text {
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
}

.card-grid {
  display: grid;
  /* auto-fill 而非 auto-fit：条目少于轨道数时（书本小节常常只有 1 个单元）
     auto-fit 会把空轨道折叠、把卡片拉伸到满宽，显得空荡 */
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.lesson-card,
.panel,
.info-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.lesson-card {
  display: block;
  padding: 24px;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.lesson-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.14);
}

.lesson-card h2 {
  margin-top: 16px;
}

.lesson-card p,
.info-card p,
.panel p {
  color: var(--muted);
}

.top-nav {
  margin-bottom: 20px;
}

.top-nav a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.lesson-layout,
.lesson-explanation {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(310px, 0.8fr);
  gap: 22px;
  align-items: start;
}

.lesson-explanation {
  margin-top: 22px;
}

.panel {
  padding: 18px;
}

.board-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

/* 画板统一形状：所有单元的画布同一个宽高比。
   配合运行时的统一取景框（sketch-runtime.js 的 canonicalFrame），
   让每页"每单位多少像素"一致 —— 网格大小不因单元而异。
   窄屏改成 4:3（画板高一点更好操作），取景框会跟着容器比例走，仍然一致。 */
.jxgbox {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  min-height: 300px;
}

/* 画板缩放按钮（内容超出画布时的兜底）。
   做得显眼一些：白底 + 实边 + 投影 —— 早先浅底细边只有 30px，
   实测有人"没看到"，所以宁可醒目。 */
.sketch-host { position: relative; }
.sketch-zoom {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.sketch-zoom-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}
.sketch-zoom-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--panel-soft);
}
.sketch-zoom-btn:active:not(:disabled) { transform: translateY(1px); }
.sketch-zoom-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.side-stack {
  display: grid;
  gap: 16px;
}

.info-card {
  padding: 20px;
}

.info-card strong {
  color: var(--text);
}

.metric-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 9px;
}

.metric-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.metric-row dt {
  color: var(--muted);
}

.metric-row dd {
  margin: 0;
  font-weight: 800;
}

.hint {
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff7ed;
  color: #9a3412;
}

.steps {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.8;
}

.formula {
  border-radius: 16px;
  padding: 14px;
  background: var(--panel-soft);
  font-weight: 800;
  text-align: center;
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

.slider-row input {
  width: 100%;
}

@media (max-width: 860px) {
  .lesson-layout,
  .lesson-explanation {
    grid-template-columns: 1fr;
  }

  /* 窄屏画板高一点更好操作；取景框按容器实际比例算，仍与同屏其它画板一致 */
  .jxgbox {
    aspect-ratio: 4 / 3;
  }
}

/* ============ 认证表单页 (login/register/profile) ============ */
.form-card {
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 28px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}
.form-card label {
  display: block;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
}
.form-card input[type="text"],
.form-card input[type="email"],
.form-card input[type="password"],
.form-card input[type="tel"],
.form-card input[type="number"],
.form-card input[type="date"],
.form-card textarea,
.form-card select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.form-card textarea { resize: vertical; line-height: 1.5; }
.form-card input:focus,
.form-card textarea:focus,
.form-card select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-card input:disabled {
  background: var(--panel-soft);
  color: var(--muted);
}
.btn-primary {
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.form-error {
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 14px;
}
.form-notice {
  color: var(--success);
  background: #dcfce7;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 14px;
}
.form-hint {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.form-hint a { color: var(--primary); }
.logout-form { margin-top: 18px; }
.logout-form button.btn-link,
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 15px;
  text-decoration: none;
  padding: 0;
}

/* ============ 顶栏登录态 (account.js 动态注入) ============ */
.account-nav {
  position: fixed;
  top: 10px;
  right: 14px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(6px);
}
.account-greet {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}
.account-link {
  font-size: 14px;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}
.account-link:hover { text-decoration: underline; }
.account-register {
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
}
.account-register:hover { background: var(--panel-soft); text-decoration: none; }
.account-logout { display: inline; margin: 0; }
.account-logout-btn {
  font-size: 14px;
  color: var(--muted);
}
.account-logout-btn:hover { color: #b91c1c; }

/* ============ 课程评分/评论组件 (lesson-rating.js) ============ */
.rating-widget {
  max-width: 1120px;
  margin: 8px auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 24px 24px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}
.rating-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.rating-score { display: flex; align-items: center; gap: 10px; }
.rating-num { font-size: 30px; font-weight: 800; line-height: 1; color: var(--text); }
.rating-stars-big { color: #f59e0b; font-size: 18px; letter-spacing: 2px; }
.rating-meta { color: var(--muted); font-size: 14px; }
.rating-login-tip {
  margin: 14px 0 4px;
  padding: 12px 14px;
  background: var(--panel-soft);
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 15px;
  color: var(--muted);
}
.rating-form-wrap { margin-top: 14px; }
.rating-form-title { font-weight: 700; margin: 0 0 8px; }
.rating-picker { display: flex; gap: 4px; }
.rating-picker .star {
  border: none;
  background: none;
  font-size: 26px;
  line-height: 1;
  color: #cbd5e1;
  cursor: pointer;
  padding: 0 2px;
}
.rating-picker .star.on { color: #f59e0b; }
.rating-picker-hint { margin: 4px 0 10px; font-size: 13px; color: var(--muted); }
.rating-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
}
.rating-form textarea:focus { outline: none; border-color: var(--primary); }
.rating-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 12px 0 0;
}
.rating-submit { width: auto; padding: 9px 22px; }
.rating-del { color: var(--muted); }
.rating-msg { margin: 8px 0 0; font-size: 14px; color: var(--success); }
.rating-msg.err { color: #b91c1c; }
.ratings-list { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 6px; }
.ratings-empty { color: var(--muted); font-size: 15px; }
.rating-item { padding: 12px 0; border-bottom: 1px solid #eef2f8; }
.rating-item:last-child { border-bottom: none; }
.rating-item-top { display: flex; align-items: center; gap: 10px; }
.rating-item-stars { color: #f59e0b; letter-spacing: 1px; }
.rating-item-author { font-weight: 600; font-size: 14px; }
.rating-item-date { color: var(--muted); font-size: 13px; }
.rating-item-comment { margin: 6px 0 0; font-size: 15px; }

/* 列表页卡片平均分 chip */
.lesson-card { display: flex; flex-direction: column; }
.rating-chip {
  margin-top: auto;
  padding-top: 10px;
  color: #b45309;
  font-size: 13px;
  font-weight: 700;
}

/* ============ 反馈 & 管理后台 ============ */
.input-select {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
}
.new-feedback-btn { display: inline-block; width: auto; padding: 9px 20px; text-decoration: none; }
.feedback-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 14px;
}
.feedback-item-head { display: flex; align-items: center; gap: 12px; }
.feedback-item h3 { margin: 10px 0 6px; }
.feedback-item-content { color: var(--text); }
.feedback-item-date { color: var(--muted); font-size: 13px; }
.feedback-reply { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 15px; }
.feedback-reply-label { font-weight: 700; margin: 0 0 4px; }
.feedback-reply-none { color: var(--muted); }

/* 消息中心：反馈列表项、来源页面上下文、回复线程气泡 */
.msg-item { display: block; text-decoration: none; color: inherit; }
.msg-item:hover { border-color: var(--primary); }
.msg-item h3 { color: var(--text); }
.msg-item-page { color: var(--muted); font-size: 13px; margin: 2px 0; }
.msg-item-url { margin-left: 8px; color: var(--primary); }
.msg-item-reply { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.msg-page-ctx {
  margin-bottom: 14px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 14px;
}
.msg-page-ctx-label { margin: 0 0 4px; font-weight: 700; color: var(--text); }
.msg-page-ctx-title { margin: 0 0 2px; font-weight: 700; }
.msg-page-ctx-url { margin: 0; color: var(--muted); word-break: break-all; }
.msg-page-ctx-url a { color: var(--primary); text-decoration: underline; }
.msg-page-ctx-intro { margin: 4px 0 0; color: var(--muted); }

.msg-thread { margin-bottom: 16px; }
.msg-bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
}
.msg-bubble-meta { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.msg-bubble-author { font-weight: 700; color: var(--text); }
.msg-bubble-content { margin: 0; white-space: pre-wrap; }
.msg-bubble-admin { border-left: 3px solid var(--primary); }
.msg-bubble-mine { border-left: 3px solid var(--muted); }

.msg-page-feedback { margin: 10px 0 0; font-size: 14px; }
.msg-page-feedback a { color: var(--primary); }

/* 状态徽标 */
.feedback-status {
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 10px;
}
.st-open      { color: #b45309; background: #fef3c7; }
.st-reviewing { color: #1d4ed8; background: #dbeafe; }
.st-resolved  { color: #15803d; background: #dcfce7; }
.st-closed    { color: #475569; background: #e2e8f0; }
/* 题库上传状态（审核流水线） */
.st-pending   { color: #b45309; background: #fef3c7; }
.st-approved  { color: #1d4ed8; background: #dbeafe; }
.st-rejected  { color: #b91c1c; background: #fee2e2; }
.st-published { color: #15803d; background: #dcfce7; }

/* 题库练习：选项按钮与选中态 */
.q-option {
  display: block;
  width: 100%;
  margin: 4px 0;
  padding: 9px 14px;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.q-option:hover { border-color: var(--primary); }
.q-option.selected { border-color: var(--primary); background: var(--primary); color: #fff; }

/* 管理后台 */
.admin-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.stat-card {
  flex: 1 1 180px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
}
.stat-num { font-size: 30px; font-weight: 800; margin: 0 0 4px; }
.stat-label { color: var(--muted); margin: 0; }
.admin-actions { margin-top: 8px; }
.admin-actions a { text-decoration: none; }
.admin-toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px;
}
.admin-search { flex: 1 1 200px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.admin-filter-btn { width: auto; padding: 9px 18px; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid #eef2f8;
  font-size: 14px;
  vertical-align: middle;
}
.admin-table th { background: var(--panel-soft); color: var(--muted); font-size: 13px; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table a { color: var(--primary); text-decoration: none; }
.admin-dim { color: var(--muted); font-size: 13px; white-space: nowrap; }
.pagination { display: flex; align-items: center; gap: 16px; justify-content: center; margin-top: 18px; color: var(--muted); }
.pagination a { color: var(--primary); text-decoration: none; }
.feedback-detail-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 18px;
  white-space: pre-wrap;
}
.status-form-title { margin-top: 22px; }
.status-form-title + form select { margin-right: 10px; }

/* Phase 6 补充 */
.admin-section-title { font-weight: 800; margin: 6px 0 10px; color: var(--muted); font-size: 14px; }
.admin-link-btn { margin-left: 12px; }
.inline-form { display: inline; margin: 0; }
.danger-link { color: #b91c1c; }
.st-active { color: #15803d; background: #dcfce7; }
.st-banned { color: #b91c1c; background: #fee2e2; }

/* ---- Phase 7：书本式站点 ---- */

/* 交互块：**画板独占整行**，侧栏卡片排到画板下方。
   原先"左板右栏"的排法，画板会被侧栏占掉约三分之一；在书本页里还要再减去
   目录列，实测 1120px 的正文列里画板只剩 743px（侧栏 357px）。
   画板是本页的主角、且宽度直接决定图能画多大（JSXGraph 的 keepaspectratio
   按容器宽高比缩放），所以改成独占宽度，侧栏卡片在下方横向铺开。 */
.sketch-block { margin: 22px 0; container-type: inline-size; }
.sketch-block.has-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.sketch-block > .sketch-title {
  margin: 0 0 10px;
  font-weight: 800;
  color: var(--muted);
  font-size: 14px;
}
.sketch-block.has-side > .sketch-title { grid-column: 1 / -1; }
/* 侧栏卡片在画板下方铺开：宽度够就并排，不够自动换行（移动端自然变一列）。 */
.sketch-side {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  align-items: start;
}
.sketch-side .info-card { padding: 16px 18px; }
.sketch-side .info-card h2 { font-size: 15px; margin: 0 0 10px; }
.sketch-metrics { margin: 0; }
.sketch-failed {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}
.constraint-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; color: var(--muted); }
.constraint-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* 正文排版 */
.unit-body { margin-top: 8px; }
.unit-body h2 {
  margin: 30px 0 12px;
  font-size: 21px;
  scroll-margin-top: 18px;
}
.unit-body h3 { margin: 22px 0 10px; font-size: 17px; }
.unit-body p { line-height: 1.85; color: #334155; }
.unit-body ul, .unit-body ol { line-height: 1.85; color: #334155; }
.unit-body table { border-collapse: collapse; width: 100%; margin: 14px 0; }
.unit-body th, .unit-body td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.unit-body th { background: var(--panel-soft); }
.unit-body code {
  background: var(--panel-soft);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.92em;
}
.unit-body pre {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
}
.unit-body blockquote {
  margin: 14px 0;
  padding: 6px 16px;
  border-left: 4px solid var(--line);
  color: var(--muted);
}

/* 练习与答案 */
.exercise {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 20px;
  margin: 18px 0;
}
.exercise-question { font-weight: 600; }
.exercise-options { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.exercise-options li {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  color: #334155;
}
.option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--panel-soft);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.answer-fold {
  background: var(--panel-soft);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 10px 16px;
  margin: 12px 0 18px;
}
.answer-fold > summary { cursor: pointer; font-weight: 700; color: var(--primary); }
.answer-body { padding-top: 8px; color: #334155; line-height: 1.8; }

/* 提示块 */
.callout { border-left: 4px solid var(--line); }
.callout-title { margin: 0 0 6px; font-weight: 800; }
.callout-warning { border-left-color: var(--accent); background: #fff7ed; }
.callout-warning .callout-title { color: #9a3412; }
.callout-tip { border-left-color: var(--success); background: #f0fdf4; }
.callout-tip .callout-title { color: #15803d; }
.callout-note { border-left-color: var(--primary); }

/* 书本页 */
.book-layout { display: grid; grid-template-columns: minmax(230px, 0.62fr) minmax(0, 2fr); gap: 28px; align-items: start; }
/* 无书本上下文时（/u/{id}）只渲染正文一列。
   少了这条，空着的第一列会把正文挤成 258px 宽。 */
.book-layout.no-toc { grid-template-columns: minmax(0, 1fr); }
.toc-tree { display: grid; gap: 6px; }
.toc-chapter { font-weight: 800; margin: 14px 0 6px; color: var(--text); font-size: 15px; }
.toc-section { margin: 4px 0 4px 2px; color: var(--muted); font-size: 13px; font-weight: 700; }
.toc-list { list-style: none; margin: 0; padding: 0 0 0 12px; display: grid; gap: 2px; }
.toc-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.toc-item a {
  display: block;
  padding: 6px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: #334155;
  font-size: 14px;
  line-height: 1.5;
  flex: 1;
}
.toc-item a:hover { background: var(--panel-soft); color: var(--primary); }
.toc-item.current a { background: #eff6ff; color: var(--primary); font-weight: 700; }
.progress-badge {
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--panel-soft);
  color: var(--muted);
  white-space: nowrap;
}
.book-progress { color: var(--muted); font-size: 14px; margin-top: 6px; }
.unit-nav { display: flex; justify-content: space-between; gap: 16px; margin: 26px 0 8px; }
.unit-nav a {
  text-decoration: none;
  color: var(--primary);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  background: var(--panel);
}
.unit-nav a:hover { border-color: var(--primary); }
.unit-nav .spacer { flex: 1; }
.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.breadcrumb a { color: var(--primary); text-decoration: none; }

/* 容器自己变窄时就改上下堆叠——只按视口宽度判断不够：
   容器可能因为外层栅格而变窄（这正是 no-toc 缺失时发生的事，
   画板曾被压成 0 宽）。 */
@media (max-width: 860px) {
  .book-layout { grid-template-columns: 1fr; }
}

/* ---- Phase 8：练习交互与学习结果 ---- */

.exercise-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.exercise-hint { font-size: 13px; color: var(--muted); }
.exercise-input {
  margin-top: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
}
.exercise-options li { cursor: pointer; }
.exercise-options li:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.exercise-options li.selected {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary-dark);
  font-weight: 600;
}
.exercise-options li.selected .option-letter { background: var(--primary); color: #fff; }

.exercise-result {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}
.exercise-verdict { margin: 0 0 6px; font-weight: 800; }
.exercise-verdict.ok { color: #15803d; }
.exercise-verdict.bad { color: #b91c1c; }
.exercise-answer { margin: 4px 0 8px; color: #334155; }
.exercise-explanation { color: #334155; line-height: 1.8; }
.exercise-explanation > p:first-child { margin-top: 0; }
.exercise-explanation > p:last-child { margin-bottom: 0; }

/* 学习进度徽标（书页目录树） */
.progress-badge.done { background: #dcfce7; color: #15803d; }
.progress-badge.doing { background: #eff6ff; color: var(--primary-dark); }

/* ---- Phase 9：AI 助手浮动面板 ---- */

.ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  padding: 12px 20px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.ai-fab:hover { background: var(--primary-dark); }

.ai-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 61;
  width: min(420px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 44px));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}
.ai-panel-title { font-weight: 800; }
.ai-panel-actions { display: flex; align-items: center; gap: 8px; }
.ai-panel-new,
.ai-panel-close {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 8px;
}
.ai-panel-new:hover,
.ai-panel-close:hover { background: var(--panel); color: var(--primary); }
.ai-panel-close { font-size: 20px; line-height: 1; }

.ai-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 15px;
}
.ai-msg { line-height: 1.75; }
.ai-msg-user {
  align-self: flex-end;
  max-width: 88%;
  background: #eff6ff;
  color: var(--primary-dark);
  border-radius: 14px 14px 4px 14px;
  padding: 8px 12px;
  white-space: pre-wrap;
}
.ai-msg-assistant { color: #334155; }
.ai-msg-assistant p { margin: 0 0 8px; }
.ai-msg-assistant p:last-child { margin-bottom: 0; }
.ai-msg-assistant ul { margin: 6px 0; padding-left: 20px; }
.ai-msg-assistant li { margin: 3px 0; }
.ai-msg-assistant .ai-h { font-weight: 800; color: var(--text); }
.ai-pending { color: var(--muted); font-style: italic; }

.ai-sources {
  font-size: 13px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.ai-sources a { color: var(--primary); text-decoration: none; margin-right: 2px; }
.ai-sources a:hover { text-decoration: underline; }

.ai-note {
  font-size: 13px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.ai-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}
.ai-input {
  /* min-width:0 很关键：flex 项默认 min-width:auto，会被内容撑住不肯收缩 */
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
}
.ai-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
/* .btn-primary 是给认证表单设计的（width:100%），在 flex 行里会把输入框挤没，
   这里按内容宽度收回来 */
.ai-send {
  flex: 0 0 auto;
  width: auto;
  align-self: flex-end;
  padding: 9px 18px;
  font-size: 15px;
  border-radius: 12px;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .ai-panel { right: 8px; bottom: 8px; width: calc(100vw - 16px); height: min(70vh, 560px); }
  .ai-fab { right: 12px; bottom: 12px; }
}

/* Konva 舞台自带像素尺寸，容器不需要 JSXGraph 那套固定高度 */
.konva-host { min-height: 0; height: auto; }
.konva-host canvas { display: block; }

/* 绑定手机：图形验证码一行（输入框 + 可点击换一张的图） */
.captcha-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.captcha-row input { flex: 1 1 9em; }
.captcha-box {
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  line-height: 0;
  cursor: pointer;
}
.captcha-box:hover { border-color: var(--primary); }
.captcha-box:disabled { opacity: 0.6; cursor: default; }
#phone-msg { margin: 12px 0 0; }

/* 成长卡片（个人资料页） */
.growth-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.growth-icon { font-size: 22px; letter-spacing: 2px; color: var(--accent); }
.growth-value { color: var(--muted); font-size: 14px; }
.growth-badge {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.growth-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin: 0 0 12px;
}
.growth-bar > span { display: block; height: 100%; background: var(--primary); }

/* 账号栏里的等级图标 */
.account-level { color: var(--accent); letter-spacing: 1px; margin-right: 4px; }

/* 积分卡片（个人资料页） */
.points-line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 0 0 8px; }
.points-balance { font-size: 28px; color: var(--primary); }
.points-unit { color: var(--muted); font-size: 14px; }
.points-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.points-table th,
.points-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.points-table th { color: var(--muted); font-weight: 500; }
.points-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.points-table .earn { color: var(--success); }
.points-table .spend { color: #b91c1c; }
.points-table .muted { color: var(--muted); white-space: nowrap; }

/* AI 面板里的额度条 */
.ai-quota {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.ai-quota.is-low { color: #b91c1c; background: #fef2f2; }
.ai-quota-exchange {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: var(--panel);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ai-quota-exchange:hover { background: var(--panel-soft); }
.ai-quota-exchange:disabled { opacity: 0.6; cursor: default; }

/* 管理后台：用户表的操作列与积分输入 */
.admin-actions { white-space: nowrap; }
.admin-points-input { width: 4.5em; padding: 2px 4px; font-size: 13px; }

/* 邀请卡片 */
.invite-line { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; }
.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  letter-spacing: 3px;
  color: var(--primary);
  background: var(--panel-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  user-select: all;
}
