:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --accent: #10b981;
  --accent-soft: #d1fae5;
  --wrong: #ef4444;
  --wrong-soft: #fee2e2;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; }
.hdr-right { display: flex; gap: 8px; align-items: center; }
select, .ghost {
  font: inherit; font-size: 13px; color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); padding: 6px 8px;
}
.ghost { cursor: pointer; }

main {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 12px;
}
.empty {
  margin: auto; text-align: center; color: var(--muted);
  font-size: 14px; padding: 30px; line-height: 2;
}
.empty-emoji { font-size: 48px; }

.msg { max-width: 92%; display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }
.bubble {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
  overflow-x: auto; word-break: break-word;
}
.msg.user .bubble { background: var(--accent-soft); border-color: transparent; }
.msg.user .bubble.plain { background: var(--accent); color: #fff; }
.bubble img.photo { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; }
.bubble .photo-thumb { font-size: 13px; color: var(--muted); }
.msg-mode-tag {
  font-size: 11px; color: var(--muted);
  background: var(--bg); border-radius: 6px; padding: 1px 7px;
}
.msg-mode-tag.grade { color: #92400e; background: var(--warn-soft); }
.msg-mode-tag.list { color: #1d4ed8; background: #dbeafe; }

.picker { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.picker-title { font-weight: 600; font-size: 14px; }
.picker-canvas { width: 100%; border-radius: 10px; cursor: pointer; background: #000; display: block; }
.problem-card {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; background: var(--card); cursor: pointer;
}
.problem-card:active { background: var(--accent-soft); }
.pc-head { font-weight: 700; font-size: 14px; }
.pc-kind {
  font-size: 11px; font-weight: 600; color: #1d4ed8; background: #dbeafe;
  border-radius: 99px; padding: 1px 8px; margin-left: 6px;
}
.pc-excerpt { font-size: 13px; color: var(--muted); margin-top: 2px; }

#pickBar {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(112px + env(safe-area-inset-bottom));
  background: #0b1220; color: #e2e8f0; border-radius: 12px; padding: 10px;
  display: flex; gap: 8px; align-items: center; z-index: 40; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}
#pickBar .pb-label { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#pickBar button {
  font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid #334155; background: #1e293b; color: #e2e8f0;
  border-radius: 8px; padding: 7px 10px;
}
#pickBar button[data-a="teach"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .4em; font-size: 15px; }
.md p { margin: .5em 0; }
.md ol, .md ul { padding-left: 1.4em; margin: .5em 0; }
.md code { background: #f1f5f9; border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.md mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

details.reasoning { max-width: 100%; }
details.reasoning summary {
  cursor: pointer; font-size: 12px; color: var(--muted);
  background: var(--bg); border-radius: 8px; padding: 4px 10px;
}
details.reasoning .body {
  font-size: 12px; color: var(--muted); white-space: pre-wrap;
  padding: 8px 4px 0; max-height: 200px; overflow-y: auto;
}

.grade { display: flex; flex-direction: column; gap: 8px; min-width: min(320px, 80vw); }
.grade .overall { font-weight: 600; }
.grade .verdict { font-size: 13px; font-weight: 600; border-radius: 8px; padding: 4px 10px; width: fit-content; }
.grade .verdict.ok { color: #065f46; background: var(--accent-soft); }
.grade .verdict.bad { color: #991b1b; background: var(--wrong-soft); }
.grade .verdict.unk { color: var(--muted); background: var(--bg); }
.step {
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px; padding: 8px 10px; background: var(--card);
}
.step.ok { border-left-color: var(--accent); }
.step.wrong { border-left-color: var(--wrong); background: #fff7f7; }
.step.missing { border-left-color: var(--warn); background: #fffdf5; }
.step .head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.step .chip { font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 8px; }
.step.ok .chip { color: #065f46; background: var(--accent-soft); }
.step.wrong .chip { color: #991b1b; background: var(--wrong-soft); }
.step.missing .chip { color: #92400e; background: var(--warn-soft); }
.step .student { margin: 4px 0; }
.step .note { font-size: 13px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 4px; margin-top: 4px; }
.grade .hint { font-size: 13px; background: var(--accent-soft); border-radius: 8px; padding: 6px 10px; }

.typing { display: inline-block; }
.typing::after { content: "▋"; animation: blink 1s step-end infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

footer {
  background: var(--card); border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  position: sticky; bottom: 0;
}
.attach-preview { position: relative; width: fit-content; margin-bottom: 6px; }
.attach-preview img { max-height: 64px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.attach-preview .rm {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: #334155; color: #fff;
  font-size: 12px; line-height: 20px; cursor: pointer;
}
.composer { display: flex; flex-direction: column; gap: 8px; }
.modes { display: flex; gap: 8px; }
.mode {
  font: inherit; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 99px; padding: 5px 14px; color: var(--muted);
}
.mode.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
#textInput {
  flex: 1; font: inherit; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; background: var(--bg); outline: none; min-width: 0;
}
#textInput:focus { border-color: var(--accent); }
.att {
  font-size: 20px; border: 1px solid var(--border); background: var(--bg);
  border-radius: 10px; width: 42px; height: 40px; cursor: pointer; flex: none;
}
.send {
  font-size: 17px; border: none; background: var(--accent); color: #fff;
  border-radius: 10px; width: 48px; height: 40px; cursor: pointer; flex: none;
}
.send:disabled { opacity: .45; }

/* 拍后裁剪 */
.crop-modal {
  position: fixed; inset: 0; z-index: 50;
  background: #0b1220; display: flex; flex-direction: column;
}
.crop-head {
  color: #cbd5e1; font-size: 13px; text-align: center;
  padding: calc(12px + env(safe-area-inset-top)) 12px 8px;
}
.crop-canvas { flex: 1; width: 100%; touch-action: none; }
.crop-bar {
  display: flex; gap: 10px; justify-content: space-between; align-items: center;
  padding: 12px calc(12px + env(safe-area-inset-right))
           calc(12px + env(safe-area-inset-bottom))
           calc(12px + env(safe-area-inset-left));
}
.crop-bar button {
  font: inherit; font-size: 14px; cursor: pointer;
  border: 1px solid #334155; background: #1e293b; color: #e2e8f0;
  border-radius: 10px; padding: 10px 14px;
}
.crop-bar .primary {
  flex: 1; background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600;
}

#toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: #334155; color: #fff; font-size: 13px;
  border-radius: 10px; padding: 8px 14px; z-index: 60; max-width: 86vw;
}
.hidden { display: none !important; }

/* 使用须知弹层 */
#infoBtn { color: var(--muted); font-size: 13px; cursor: pointer; margin-left: 2px; }
.dc-card { max-height: 82vh; }
.dc-body { overflow-y: auto; font-size: 13.5px; line-height: 1.7; color: var(--ink); }
.dc-body p { margin: 0 0 10px; }
.dc-ok {
  border: none; background: var(--accent); color: #fff; font: inherit;
  font-size: 15px; font-weight: 600; border-radius: 10px; padding: 11px; cursor: pointer;
}
.ai-note { font-size: 11px; color: var(--muted); opacity: .8; border-top: 1px dashed var(--border); padding-top: 5px; }

/* 批改卡片:知识点与历史错题横幅 */
.cat-chip {
  display: inline-block; font-size: 12px; font-weight: 600;
  color: #1d4ed8; background: #dbeafe; border-radius: 99px; padding: 2px 10px;
}
.wb-banner {
  font-size: 13px; font-weight: 600; border-radius: 8px; padding: 6px 10px;
}
.wb-banner.again { color: #991b1b; background: var(--wrong-soft); }
.wb-banner.now_fixed { color: #065f46; background: var(--accent-soft); }
.wb-banner.confirmed { color: var(--muted); background: var(--bg); }

/* 用户管理弹层 */
.modal {
  position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.um-card {
  background: var(--card); border-radius: 16px; padding: 16px;
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px;
}
.um-title { font-weight: 700; }
.um-row {
  display: flex; justify-content: space-between; align-items: center;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 14px;
}
.um-del {
  border: none; background: var(--bg); color: var(--muted);
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
}
.um-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.um-hint { font-size: 12px; color: var(--muted); }
.um-add { display: flex; gap: 8px; }
.um-add input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.um-add select { font-size: 13px; }
.um-add button {
  border: none; background: var(--accent); color: #fff;
  border-radius: 8px; padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer;
}

/* 错题本 */
#bookView { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.book-tabs {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.bt {
  font: inherit; font-size: 14px; border: 1px solid var(--border);
  background: var(--bg); border-radius: 99px; padding: 6px 14px; cursor: pointer; color: var(--muted);
}
.bt.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.spacer { flex: 1; }
.book-filters { display: flex; gap: 8px; padding: 10px 12px 0; }
.fchip {
  font: inherit; font-size: 13px; border: 1px solid var(--border);
  background: var(--card); border-radius: 99px; padding: 4px 14px; cursor: pointer; color: var(--muted);
}
.fchip.on { color: #065f46; background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.book-body { padding: 10px 12px 24px; display: flex; flex-direction: column; gap: 8px; }
.book-empty { color: var(--muted); text-align: center; padding: 40px 16px; font-size: 14px; }
.cat-head { font-weight: 700; font-size: 14px; margin-top: 10px; }
.cat-n { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.wcard {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.wcard.is-fixed { opacity: .62; }
.wcard img { max-height: 150px; align-self: flex-start; border-radius: 8px; border: 1px solid var(--border); }
.wc-text { font-size: 14px; }
.wc-meta { font-size: 12px; color: var(--muted); }
.wc-note { font-size: 13px; color: #92400e; background: var(--warn-soft); border-radius: 8px; padding: 5px 9px; }
.wc-acts { display: flex; gap: 8px; }
.wc-acts button {
  font: inherit; font-size: 12px; border: 1px solid var(--border);
  background: var(--bg); border-radius: 8px; padding: 5px 10px; cursor: pointer;
}
.wc-acts button.del { color: var(--wrong); }
.stat-row { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.stat-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.stat-top span:first-child { font-weight: 600; }
.stat-top span:last-child { color: var(--muted); }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-in { height: 100%; background: linear-gradient(90deg, #fbbf24, #ef4444); border-radius: 99px; }
