/* 知序 · 练习 / 批改 / 错题 / 诊断 / 讲题。依赖 ui.css token。 */

/* ---------- Shared ---------- */
.study-head { margin-bottom: 16px; }
.study-head h1 { font-size: clamp(22px, 2.4vw, 28px); font-weight: 700; line-height: 1.3; }
.study-head h2 { font-size: 18px; font-weight: 700; line-height: 1.35; }
.study-head p { margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.study-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: clamp(18px, 2.2vw, 24px); }
.study-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.study-muted { color: var(--ink-3); font-size: 14px; }
.study-error:empty { display: none; }
.study-error { margin: 12px 0; padding: 10px 14px; border-radius: var(--r-md); background: var(--bad-soft); color: var(--bad); font-size: 14px; font-weight: 500; }
.study-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--sunken); color: var(--ink-2); }
.study-badge.good { background: var(--ok-soft); color: var(--ok); }
.study-badge.bad { background: var(--bad-soft); color: var(--bad); }
.study-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--ink-3); }
.review-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; min-height: 44px; }
.review-toolbar p { font-size: 14px; color: var(--ink-2); }
.review-toolbar b { color: var(--ink); font-size: 16px; }

/* AI panel */
.study-ai { margin-top: 20px; display: grid; gap: 12px; }
.study-ai-head { display: flex; align-items: flex-start; gap: 12px; }
.study-ai-head > div { flex: 1; }
.study-ai-head strong { display: block; font-size: 15px; font-weight: 700; }
.study-ai-head p { margin-top: 2px; font-size: 13px; color: var(--ink-3); }
.study-ai-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); color: var(--brand-ink); flex: none; }
.study-ai .study-actions { margin-top: 0; }
.study-ai-result:empty { display: none; }
.study-ai-result { padding: 16px 18px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: 15px; line-height: 1.8; overflow-x: auto; }
.study-ai-result details { margin-top: 12px; font-size: 12px; color: var(--ink-4); white-space: normal; }

/* ---------- Unified AI Markdown + KaTeX Typography ---------- */
.md-math { display: grid; gap: 10px; color: var(--ink); font-size: 15px; line-height: 1.8; }
.md-math > :first-child { margin-top: 0; }
.md-math > :last-child { margin-bottom: 0; }
.md-p { margin: 0; }
.md-h { margin: 6px 0 0; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; line-height: 1.45; }
.md-h1 { font-size: 17px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.md-h2 { font-size: 16px; color: var(--brand-ink); }
.md-h3 { font-size: 15px; color: var(--ink); font-weight: 700; display: flex; align-items: center; gap: 7px; }
.md-h3::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--brand); flex: none; }
.md-h4 { font-size: 14.5px; color: var(--ink-2); }
.md-hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.md-ul, .md-ol { margin: 0; padding-left: 1.35em; display: grid; gap: 6px; }
.md-ul li::marker { color: var(--brand); }
.md-ol li::marker { color: var(--ink-3); font-weight: 700; }
.md-quote { margin: 2px 0; padding: 11px 14px; border-left: 3px solid var(--brand); border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--brand-soft); display: grid; gap: 6px; font-size: 14.5px; }
.md-quote .md-ul, .md-quote .md-ol { gap: 4px; }
.md-tag { display: inline-flex; align-items: center; padding: 1px 7px; margin-right: 4px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-ink); font-size: 12.5px; font-weight: 700; vertical-align: 1px; }
.md-code { padding: 1px 6px; border-radius: 5px; background: var(--sunken); font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.9em; }
.md-pre { margin: 0; padding: 12px 14px; border-radius: var(--r-sm); background: var(--sunken); overflow-x: auto; font-size: 13.5px; line-height: 1.6; }
.md-math-block { margin: 4px 0; padding: 6px 10px; overflow-x: auto; text-align: center; }
.md-table-wrap { overflow-x: auto; }
.md-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md-table th, .md-table td { padding: 7px 10px; border: 1px solid var(--line); text-align: left; }
.md-table th { background: var(--surface-2); font-weight: 700; }
.katex .cjk_fallback, .katex .mord.text { font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif; }

/* ---------- Practice (focus mode) ---------- */
.study-practice-shell { max-width: 1240px; margin: 0 auto; padding: 20px var(--gutter) 0; }
.study-masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 32px; flex-wrap: wrap; margin-bottom: 16px; }
.study-masthead .study-head { margin: 0; min-width: 0; flex: 1 1 360px; }
.study-masthead .study-head h1 { font-size: clamp(20px, 2.2vw, 24px); }
.study-full-goal { margin-top: 4px; font-size: 13px; color: var(--ink-3); }
.study-full-goal summary { color: var(--brand-ink); font-weight: 600; }
.study-full-goal p { margin-top: 6px; max-width: 70ch; }
.study-assignment-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 6px; font-size: 13px; color: var(--ink-3); }
.study-assignment-meta code { font-size: 12px; }
.study-meta-sep { color: var(--ink-4); }
.study-mode-tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 600; }
.study-print-btn { min-height: 32px; padding: 0 8px; font-size: 13px; margin-left: 4px; }
.study-head-desc { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.study-progress-card { flex: none; }
.study-progress-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.study-progress-summary { display: grid; gap: 0; text-align: right; }
.study-progress-step { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.study-progress-count { font-size: 15px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.study-progress-uncertain { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--unsure); }
.study-progress-uncertain i { width: 6px; height: 6px; border-radius: 50%; background: var(--unsure); }
.study-nav { display: flex; flex-wrap: wrap; gap: 6px; }
.study-number { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; transition: all 0.15s var(--ease); }
.study-number:hover { border-color: var(--ink-4); }
.study-number.answered { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-ink); }
.study-number.current { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); color: var(--brand-ink); }
.study-number.answered.current { background: var(--brand); color: #fff; border-color: var(--brand); }
.study-number i { position: absolute; top: -2px; right: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--unsure); border: 2px solid var(--bg); font-size: 0; }

.study-workspace { display: block; }
.notebook-document { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-md); }
.notebook-page { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: min(62vh, 640px); }
.notebook-page > .study-question { padding: clamp(20px, 2.6vw, 32px); border: 0; border-right: 1px solid var(--line); border-radius: var(--r-xl) 0 0 0; background: transparent; }
.notebook-page > .study-scratch { padding: 16px clamp(16px, 2vw, 24px) 18px; background: var(--surface-2); border-radius: 0 var(--r-xl) 0 0; display: flex; flex-direction: column; min-width: 0; }

.problem-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.problem-number { display: grid; place-items: center; min-width: 36px; height: 36px; padding: 0 6px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.study-question-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 16px; font-weight: 700; line-height: 1.4; padding-top: 6px; outline: none; }
.study-type { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--sunken); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.study-verification { display: inline-flex; margin-top: 6px; height: 22px; align-items: center; padding: 0 8px; border-radius: 999px; background: var(--seal-soft); color: var(--seal); font-size: 12px; font-weight: 600; }
.study-previous { margin: 0 0 12px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.study-stem { font-size: 17px; line-height: 1.85; color: var(--ink); overflow-x: auto; overflow-y: hidden; white-space: pre-wrap; }
.study-stem .katex-display { margin: 0.6em 0; }
.study-options { display: grid; gap: 10px; margin-top: 22px; }
.study-option { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 10px 16px 10px 12px; text-align: left; border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--surface); font-size: 16px; line-height: 1.6; transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), box-shadow 0.15s var(--ease); }
.study-option:hover:not(:disabled) { border-color: var(--brand-line); background: var(--surface-2); }
.study-option-letter { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--line-strong); color: var(--ink-2); font-size: 14px; font-weight: 700; flex: none; transition: all 0.15s var(--ease); }
.study-option-content { min-width: 0; overflow-x: auto; }
.study-option.is-selected { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(47, 85, 196, 0.12); }
.study-option.is-selected .study-option-letter { background: var(--brand); border-color: var(--brand); color: #fff; }
.study-option:disabled { opacity: 1; cursor: default; }
.study-written { display: grid; gap: 8px; margin-top: 20px; }
.study-written label { font-size: 14px; font-weight: 600; }
.study-written textarea { width: 100%; font-size: 16px; }
.study-written small { font-size: 12.5px; color: var(--ink-3); }
.problem-colophon { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 22px; padding-top: 14px; border-top: 1px dashed var(--line); }
.study-meta-source { font-size: 12.5px; color: var(--ink-3); min-width: 0; }
.study-meta-source a { color: var(--ink-3); text-decoration: none; }
.study-meta-source a:hover { color: var(--brand-ink); text-decoration: underline; }
.study-unsure { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 600; }
.study-unsure:hover { border-color: var(--unsure-line); color: var(--unsure); }
.study-unsure.on { background: var(--unsure-soft); border-color: var(--unsure-line); color: var(--unsure); }

/* Scratch / handwriting */
.scratch-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.scratch-head h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.notebook-tools { display: flex; gap: 4px; }
.notebook-tools > div { display: flex; gap: 2px; padding: 3px; border-radius: var(--r-sm); background: var(--sunken); }
.notebook-tools button { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 10px; border-radius: 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.notebook-tools button:hover { color: var(--ink); }
.notebook-tools button[aria-pressed="true"] { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow-sm); }
.notebook-tools button svg { width: 17px; height: 17px; }
.scratch-leaf { flex: 1; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.scratch-canvas { display: block; width: 100%; flex: 1; min-height: 320px; aspect-ratio: auto; touch-action: pan-y; cursor: crosshair;
  background-color: #fff; background-image: radial-gradient(circle, #cfd3dc 0.9px, transparent 1px); background-size: 20px 20px; background-position: 10px 10px; }
.scratch-canvas.touch-ink { touch-action: none; }
.scratch-text-group { flex: 1; display: flex; }
.scratch-text-group textarea { flex: 1; width: 100%; min-height: 320px; border: 0; border-radius: 0; padding: 14px 16px; background: repeating-linear-gradient(transparent, transparent 31px, var(--line) 31px, var(--line) 32px); background-attachment: local; line-height: 32px; font-size: 16px; resize: none; box-shadow: none; }
.scratch-text-group textarea:focus { box-shadow: none; }
.study-scratch-inner[data-scratch-mode="ink"] .scratch-text-group, .study-scratch-inner[data-scratch-mode="text"] .scratch-canvas { display: none; }
.scratch-status { display: block; margin-top: 8px; font-size: 12.5px; color: var(--ink-3); }
.study-scratch.is-answer .scratch-leaf { border-color: var(--brand-line); box-shadow: 0 0 0 3px var(--brand-soft); }

/* Bottom action bar */
.study-action-bar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px clamp(16px, 2.2vw, 24px) calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.study-action-bar .study-error { flex: 1 1 100%; order: -1; margin: 0; }
.study-action-group { display: flex; gap: 10px; align-items: center; }
.study-action-bar .study-btn { min-height: 48px; padding: 0 20px; }
.study-action-bar .study-primary { min-width: 140px; }

/* Paper re-entry mode */
.study-practice-paper .study-paper-list { display: grid; gap: 16px; }
.study-practice-paper .study-question { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: clamp(18px, 2.4vw, 28px); scroll-margin-top: 80px; }
.study-practice-paper .study-options { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.study-submit { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px calc(-1 * var(--gutter)) 0; padding: 14px var(--gutter) calc(14px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.study-submit-info { display: grid; gap: 2px; font-size: 14px; color: var(--ink-2); }
.study-submit-info strong { color: var(--ink); }
.study-submit-hint { font-size: 13px; color: var(--warn); }
.study-submit-hint.is-ready { color: var(--ok); }
.study-submit .study-primary { min-height: 48px; padding: 0 24px; }

@media (max-width: 900px) {
  .notebook-page { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .notebook-page > .study-question { border-right: 0; border-bottom: 1px solid var(--line); }
  .notebook-page > .study-scratch { border-radius: 0; }
  .scratch-canvas, .scratch-text-group textarea { min-height: 260px; }
}
@media (max-width: 700px) {
  .study-practice-shell { padding: 12px 12px 0; }
  .study-masthead { gap: 12px; }
  .study-progress-card { width: 100%; }
  .study-progress-row { justify-content: space-between; }
  .study-progress-summary { text-align: left; order: -1; }
  .notebook-document { border-radius: var(--r-lg); }
  .study-action-bar { border-radius: 0 0 var(--r-lg) var(--r-lg); }
  .study-action-bar .study-btn { padding: 0 14px; }
  .study-action-bar .study-primary { min-width: 0; }
  .notebook-tools button span { display: none; }
  .study-stem { font-size: 16px; }
  .study-option { font-size: 15px; }
}

/* ---------- Grade ---------- */
.grade-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.grade-view > * { min-width: 0; }
.grade-view > .study-head { margin: 0; order: -1; }
.grade-history { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grade-history label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.grade-history label span { font-weight: 400; color: var(--ink-3); }
.grade-history select { flex: 1 1 320px; min-width: 0; width: 100%; max-width: 560px; text-overflow: ellipsis; }
.grade-history p { flex-basis: 100%; font-size: 13px; color: var(--warn); }
.grade-ledger { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: clamp(18px, 2.4vw, 26px); box-shadow: var(--shadow-sm); }
.grade-ledger-top { display: flex; align-items: center; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.grade-score-main { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.grade-score-num { font-size: 40px; line-height: 1; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.grade-score-unit { display: grid; font-size: 14px; color: var(--ink-2); }
.grade-score-unit small { font-size: 12.5px; color: var(--warn); }
.grade-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.grade-stat { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.grade-stat.is-wrong { background: var(--bad-soft); color: var(--bad); }
.grade-stat.is-unsure { background: var(--unsure-soft); color: var(--unsure); }
.grade-stat.is-solid { background: var(--ok-soft); color: var(--ok); }
.grade-stat.is-zero { background: var(--sunken); color: var(--ink-3); }
.grade-stat-val { font-size: 15px; }
.grade-priority { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.grade-priority-head { font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 10px; }
.grade-priority-list { display: flex; flex-wrap: wrap; gap: 8px; }
.grade-jump { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; }
.grade-jump:hover { border-color: var(--line-strong); }
.grade-jump-num { font-weight: 700; }
.grade-jump.is-wrong .grade-jump-tag { color: var(--bad); }
.grade-jump.is-unsure .grade-jump-tag { color: var(--unsure); }
.grade-list-bar { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-top: 8px; }
.grade-list-title { font-size: 16px; font-weight: 700; }
.grade-list-note { font-size: 13px; color: var(--ink-3); }
.grade-list { display: grid; gap: 10px; }
.grade-item { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; scroll-margin-top: 16px; }
.grade-item.is-wrong .grade-q-index { background: var(--bad-soft); color: var(--bad); }
.grade-item.is-unsure .grade-q-index { background: var(--unsure-soft); color: var(--unsure); }
.grade-item.is-pending .grade-q-index { background: var(--warn-soft); color: var(--warn); }
.grade-summary { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 68px; padding: 12px 16px 12px 18px; list-style: none; }
.grade-summary:hover { background: var(--surface-2); }
.grade-q-index { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--sunken); font-size: 13px; font-weight: 700; color: var(--ink-2); }
.grade-summary-main { min-width: 0; display: grid; gap: 4px; }
.grade-summary-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.grade-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--ok-soft); color: var(--ok); }
.grade-badge.is-wrong { background: var(--bad-soft); color: var(--bad); }
.grade-badge.is-unsure { background: var(--unsure-soft); color: var(--unsure); }
.grade-badge.is-pending { background: var(--warn-soft); color: var(--warn); }
.grade-topic { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.grade-source { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.grade-summary-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grade-summary-title.is-stem-only { font-weight: 500; color: var(--ink-2); }
.grade-summary-side { display: flex; align-items: center; gap: 10px; }
.grade-ans-pair { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.grade-ans-chip { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 600; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.grade-ans-chip.is-good { background: var(--ok-soft); color: var(--ok); }
.grade-ans-chip.is-bad { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.grade-ans-chip.is-unsure { background: var(--unsure-soft); color: var(--unsure); }
.grade-ans-chip.is-key { background: var(--ok-soft); color: var(--ok); }
.grade-chevron { width: 10px; height: 10px; border-right: 2px solid var(--ink-4); border-bottom: 2px solid var(--ink-4); transform: rotate(45deg); margin: -4px 4px 0; transition: transform 0.2s var(--ease); }
.grade-item[open] .grade-chevron { transform: rotate(-135deg); margin-top: 4px; }
.grade-detail-body { padding: 4px 20px 20px 62px; display: grid; gap: 14px; }
.grade-stem { font-size: 16px; line-height: 1.85; overflow-x: auto; white-space: pre-wrap; }
.grade-unanswered { font-size: 14px; color: var(--warn); }
.grade-options { display: grid; gap: 8px; }
.grade-opt { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 14px 8px 10px; border: 1.5px solid var(--line); border-radius: var(--r-md); font-size: 15px; }
.grade-opt-code { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--line-strong); font-size: 13px; font-weight: 700; color: var(--ink-2); flex: none; }
.grade-opt-text { flex: 1; min-width: 0; overflow-x: auto; }
.grade-opt-flag { font-size: 12px; font-weight: 700; white-space: nowrap; }
.grade-opt-flag.is-good { color: var(--ok); }
.grade-opt-flag.is-bad { color: var(--bad); }
.grade-opt-flag.is-unsure { color: var(--unsure); }
.grade-opt.is-correct-key, .grade-opt.is-right-pick { border-color: var(--ok-line); background: var(--ok-soft); }
.grade-opt.is-correct-key .grade-opt-code, .grade-opt.is-right-pick .grade-opt-code { background: var(--ok); border-color: var(--ok); color: #fff; }
.grade-opt.is-wrong-pick { border-color: var(--bad-line); background: var(--bad-soft); }
.grade-opt.is-wrong-pick .grade-opt-code { background: var(--bad); border-color: var(--bad); color: #fff; }
.grade-opt.is-unsure-pick { border-color: var(--unsure-line); background: var(--unsure-soft); }
.grade-opt.is-unsure-pick .grade-opt-code { background: var(--unsure); border-color: var(--unsure); color: #fff; }
.grade-ans-fallback { font-size: 14px; color: var(--ink-2); }
.study-written-review { display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.study-written-review h3, .study-submitted-ink h3 { font-size: 13px; font-weight: 700; color: var(--ink-2); margin-top: 6px; }
.study-written-review h3:first-child { margin-top: 0; }
.study-written-review p { font-size: 15px; line-height: 1.75; white-space: pre-wrap; overflow-x: auto; }
.study-written-review ul { font-size: 14px; color: var(--ink-2); line-height: 1.7; }
.study-submitted-ink { display: grid; gap: 6px; }
.ink-svg { display: block; width: 100%; max-height: 500px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; color: var(--ink); }
.grade-explain { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.grade-explain-summary { display: flex; align-items: center; justify-content: space-between; min-height: 46px; padding: 0 14px; list-style: none; font-size: 14px; font-weight: 600; color: var(--brand-ink); }
.grade-explain-count { font-size: 12.5px; font-weight: 500; color: var(--ink-3); }
.grade-steps { margin: 0; padding: 0 16px 14px 36px; display: grid; gap: 8px; font-size: 15px; line-height: 1.8; }
.grade-step { padding-left: 4px; overflow-x: auto; }
.grade-item-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px dashed var(--line); }
.grade-reason { display: inline-flex; align-items: center; gap: 8px; }
.grade-reason-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.grade-reason-select { min-height: 36px; padding: 4px 30px 4px 10px; font-size: 14px; }
.grade-foot-note { font-size: 13px; color: var(--ink-3); }
.grade-item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grade-item-actions .study-btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.grade-bottom-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 8px 0; }
@media (max-width: 700px) {
  .grade-summary { grid-template-columns: 28px minmax(0, 1fr); padding-left: 14px; }
  .grade-summary-side { grid-column: 2; justify-content: flex-start; }
  .grade-chevron { display: none; }
  .grade-detail-body { padding: 4px 14px 16px 18px; }
  .grade-score-num { font-size: 34px; }
}

/* ---------- Mistakes (Linear-style grouped issue ledger — kills floating card stack) ---------- */
.mistake-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.mistake-filters .chip { min-block-size: 32px; padding: 0 11px; }
@media (pointer: coarse) {
  .mistake-filters .chip { min-block-size: 42px; }
}
.study-empty-inline { padding: 32px 16px; text-align: center; color: var(--ink-3); background: var(--surface); border-radius: var(--r-lg); border: 1px dashed var(--line-strong); font-size: var(--t-base); }
.mistake-list {
  display: grid;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.mistake-list:has(> .study-empty-inline) {
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}
.mistake-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px 20px;
  padding: 15px 18px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 0;
  box-shadow: none;
  transition: background-color 0.13s var(--ease);
}
.mistake-card:last-child { border-bottom: 0; }
.mistake-card:hover { background: #f8f9fb; }
.mistake-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}
.mistake-card header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.mistake-meta-line { font-size: var(--t-xs); color: var(--ink-3); line-height: 1.45; }
.mistake-card h3 { font-size: var(--t-md); font-weight: 600; letter-spacing: -0.012em; color: var(--ink); line-height: 1.35; }
.mistake-stem { font-size: var(--t-base); line-height: 1.7; color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; white-space: pre-wrap; }
.mistake-note { margin-top: 2px; padding: 8px 11px; border-radius: var(--r-sm); background: var(--seal-soft); border: 1px solid var(--seal-line); font-size: var(--t-xs); line-height: 1.55; color: var(--ink); }
.mistake-note b { color: var(--seal); }
.mistake-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding-top: 2px;
  flex: none;
}
.mistake-actions-sub {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  opacity: 0.62;
  transition: opacity 0.14s var(--ease);
}
.mistake-card:hover .mistake-actions-sub,
.mistake-card:focus-within .mistake-actions-sub {
  opacity: 1;
}
.mistake-actions .study-btn-ghost.btn-sm {
  min-height: 28px;
  padding: 0 7px;
  font-size: var(--t-xs);
  color: var(--ink-3);
}
.mistake-actions .study-btn-ghost.btn-sm:hover { color: var(--ink); }
@media (hover: none) {
  .mistake-actions-sub { opacity: 1; }
}
@media (max-width: 720px) {
  .mistake-card { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 14px 14px; }
  .mistake-actions { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
  .mistake-actions-sub { opacity: 1; }
}
.mistake-list + .study-ai, .mistake-card + .study-ai { margin-top: 0; }

/* ---------- Diagnosis ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.topic-card { display: grid; gap: 10px; align-content: start; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.topic-card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topic-card h3 { font-size: 16px; font-weight: 700; }
.topic-meter { display: flex; align-items: center; gap: 10px; }
.topic-meter .progress { flex: 1; height: 8px; }
.topic-meter b { font-size: 15px; min-width: 42px; text-align: right; }
.topic-card.is-bad .topic-meter .progress > i { background: var(--bad); }
.topic-card.is-warn .topic-meter .progress > i { background: var(--warn); }
.topic-facts { font-size: 13px; color: var(--ink-3); }
.topic-advice { font-size: 14px; color: var(--ink-2); }
.topic-reasons { font-size: 13px; color: var(--ink-3); }
.topic-actions { margin-top: 2px; }

/* ---------- Tutor ---------- */
.study-tutor-layout { display: grid; gap: 16px; max-width: 860px; }
.study-tutor-layout > .study-card > h2 { font-size: 18px; font-weight: 700; margin: 8px 0 12px; }
.study-tutor-layout .study-btn { margin: 12px 8px 0 0; }
.study-tutor-layout .study-actions .study-btn { margin: 0; }
.study-tutor-prompt { margin-top: 18px; padding: 14px 16px; border-radius: var(--r-md); background: var(--brand-soft); }
.study-tutor-prompt strong { font-size: 14px; color: var(--brand-ink); }
.study-tutor-prompt p { margin-top: 4px; font-size: 15px; line-height: 1.7; }
.study-explain { margin-top: 16px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: 15px; line-height: 1.8; }
.study-explain ol { margin-top: 10px; display: grid; gap: 6px; }
.study-followup { margin-top: 14px; padding: 14px 16px; border-radius: var(--r-md); background: var(--warn-soft); }
.study-followup strong { color: var(--warn); font-size: 14px; }
.study-topic { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; }
.study-result-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); }

@media print {
  .study-action-bar, .study-submit, .notebook-tools, .study-ai { display: none !important; }
}
