:root {
  --fg: #1f2328; --muted: #6b7280; --line: #e5e7eb; --bg: #f6f7f9; --card: #fff;
  --accent: #2563eb; --ok: #16a34a; --ok-bg: #e8f7ec; --bad: #dc2626; --bad-bg: #fdecec; --sel: #eef3ff;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.6 -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--fg); background: var(--bg); }
header { position: sticky; top: 0; z-index: 2; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px 8px; }
h1 { margin: 0 0 6px; font-size: 17px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 14px; }
.toolbar input[type=number] { width: 80px; }
select, input[type=number], button { font: inherit; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--ok); transition: width .2s; }
#stats { font-size: 13px; color: var(--muted); margin-top: 4px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
#card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; }
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.qhead h2 { margin: 0; font-size: 16px; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin-left: 6px; font-weight: normal; }
.star { border: none; font-size: 20px; color: #d1d5db; padding: 0 4px; background: none; }
.star.on { color: #f59e0b; }
.content p { margin: 6px 0; }
.content ul { margin: 6px 0; padding-left: 22px; }
.content img { max-width: 100%; display: block; margin: 8px 0; border: 1px solid var(--line); border-radius: 4px; }

.options { list-style: none; padding: 0; margin: 14px 0; }
.options li { display: flex; gap: 10px; padding: 9px 12px; margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; white-space: pre-line; }
.options li:hover { border-color: var(--accent); }
.options li .lab { font-weight: 600; min-width: 1.4em; }
.options li.sel { background: var(--sel); border-color: var(--accent); }
.options.done li { cursor: default; }
.options.done li.right { background: var(--ok-bg); border-color: var(--ok); }
.options.done li.wrong { background: var(--bad-bg); border-color: var(--bad); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }

.result { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.verdict { font-weight: 600; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.answer { margin: 6px 0; }
.annotation { background: #fff7e0; border: 1px solid #f5d98b; border-radius: 6px; padding: 4px 10px; margin: 8px 0; font-size: 13px; }
.explanation { background: #f8f9fb; border-radius: 8px; padding: 10px 14px; margin-top: 10px; }
.explanation h3 { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 14px 0; }
#pos { color: var(--muted); font-size: 14px; }
details summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 5px; }
#grid button { padding: 3px 0; font-size: 12px; }
#grid .ok { background: var(--ok-bg); border-color: var(--ok); }
#grid .bad { background: var(--bad-bg); border-color: var(--bad); }
#grid .cur { outline: 2px solid var(--accent); }
#grid .noted { border-style: dashed; font-weight: 600; }

/* ---------- 同步码 ---------- */
.sep { width: 1px; height: 18px; background: var(--line); }
#synccode { width: 190px; font-size: 13px; }
.sync { font-size: 12px; color: var(--muted); }
.sync.ok { color: var(--ok); }
.sync.err { color: var(--bad); }

/* ---------- 统计面板 ---------- */
details { margin-top: 14px; }
#stats-panel, #wrongbook { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fbfbfd; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 600; line-height: 1.25; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat-table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; }
.stat-table th, .stat-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stat-table th { color: var(--muted); font-weight: 500; }

/* ---------- 错题本 ---------- */
.wb-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.wb-row:last-child { border-bottom: none; }
.wb-num { flex: none; font-weight: 600; color: var(--accent); background: var(--sel); border-color: var(--accent); }
.wb-body { flex: 1; min-width: 0; }
.wb-stem { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wb-meta { font-size: 12px; color: var(--muted); }
.wb-badges { flex: none; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; }

/* ---------- 卡片内笔记 ---------- */
.notes { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.notes-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.note-tags, .note-content { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; resize: vertical; }
.note-tags:focus, .note-content:focus { outline: none; border-color: var(--accent); }
.notes-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.note-status { font-size: 12px; color: var(--muted); }
.note-status.ok { color: var(--ok); }

/* ---------- AI 讨论抽屉 ---------- */
.hidden { display: none !important; }
.drawer-open { overflow: hidden; }
.cd-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .28); z-index: 30; }
.cd { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--card); border-left: 1px solid var(--line); z-index: 31; display: flex; flex-direction: column; }
.cd.full { width: 100% !important; }
.cd-resize { position: absolute; left: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.cd-resize::after { content: ""; position: absolute; left: 2px; top: 50%; transform: translateY(-50%); width: 3px; height: 40px; border-radius: 2px; background: var(--line); }
.cd-resize:hover::after { background: var(--accent); }
.cd.full .cd-resize { display: none; }
body.cd-resizing { cursor: col-resize; user-select: none; }
.cd-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cd-head-actions { display: flex; gap: 6px; }
.cd-head-actions button { padding: 3px 9px; font-size: 13px; }
.cd-chats { display: flex; gap: 6px; overflow-x: auto; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.cd-chats:empty { display: none; }
.chip { flex: none; font-size: 12px; padding: 3px 10px; border-radius: 12px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.cd-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 92%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.bubble.user { align-self: flex-end; background: var(--sel); border-color: #c7d5ff; }
.bubble.assistant { align-self: flex-start; background: #f8f9fb; }
.bubble-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 3px; }
.bubble-role { font-size: 11px; color: var(--muted); }
.bubble-acts { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.bubble:hover .bubble-acts, .bubble-acts:focus-within { opacity: 1; }
.act { font-size: 11px; line-height: 1.6; padding: 0 6px; border-radius: 5px; color: var(--muted); background: #fff; }
.act:hover { color: var(--accent); }
.bubble-body { word-break: break-word; font-size: 14px; }
.bubble.user .bubble-body { white-space: pre-wrap; }
.bubble-err { color: var(--bad); font-size: 13px; margin-top: 6px; }
.bubble.streaming .bubble-body::after { content: "▋"; color: var(--muted); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cd-summary { margin: 0 14px 10px; border: 1px solid #f5d98b; background: #fffaf0; border-radius: 10px; padding: 10px 12px; max-height: 34vh; overflow-y: auto; }
.cd-summary.err { border-color: var(--bad); background: var(--bad-bg); }
.cd-summary-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cd-summary-body { font-size: 13.5px; }
.cd-compose { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.cd-compose textarea { flex: 1; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: none; }
.cd-compose textarea:focus { outline: none; border-color: var(--accent); }
.cd-compose button { align-self: flex-end; }
.empty.err { color: var(--bad); font-style: normal; }
@media (max-width: 620px) {
  .wb-badges { display: none; }
  #synccode { width: 140px; }
  .cd-resize { display: none; }
  .bubble-acts { opacity: 1; }
}

/* ---------- Markdown 渲染内容（.md）---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 6px 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 13px 0 6px; line-height: 1.4; font-size: 15px; }
.md h1 { font-size: 17px; }
.md h2 { font-size: 16px; }
.md h3, .md h4 { font-size: 14.5px; color: #374151; }
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md strong { font-weight: 600; }
.md code { background: #eceff4; border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.md pre { background: #f1f3f7; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.55; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; width: max-content; max-width: 100%; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.md th { background: #eef1f6; font-weight: 600; white-space: nowrap; }
.md tbody tr:nth-child(even) { background: #fafbfd; }
.md blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md a { color: var(--accent); word-break: break-all; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.md img { max-width: 100%; border-radius: 6px; }
.katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex { font-size: 1.02em; }
