:root {
  --primary: #3b6ef6;
  --primary-dark: #2c56c8;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7484;
  --line: #e4e8f0;
  --green: #1fa971;
  --red: #e5533d;
  --orange: #f08c1f;
  --radius: 14px;
  --nav-h: 62px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6;
  padding-bottom: calc(var(--nav-h) + 16px);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 16px; }
.top-left { display: flex; gap: 8px; align-items: center; }
.back-btn {
  border: 1px solid var(--line); background: #f6f8fc; color: var(--text);
  width: 32px; height: 32px; border-radius: 10px; font-size: 17px; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.back-btn:active { transform: scale(.95); }
.top-right { display: flex; gap: 8px; align-items: center; }
.due-badge {
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 12px; padding: 2px 9px; font-weight: 600;
}
.ai-status { font-size: 12px; color: var(--muted); }
.ai-status.ok { color: var(--green); }
.ai-status.no { color: var(--orange); }

/* 布局 */
#main { max-width: 860px; margin: 0 auto; padding: 14px 14px 0; }
.view { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(20,30,60,.06);
}
.card-title { font-weight: 700; margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hello h2 { font-size: 20px; margin-bottom: 4px; }

/* 统计 */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { text-align: center; padding: 14px 6px; margin-bottom: 0; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat.accent .stat-num { color: var(--red); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 9px 16px; font-size: 14px; cursor: pointer;
  transition: background .15s, transform .05s; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:hover { background: #f6f8fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--red); border-color: #f3c4bc; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.file-btn { position: relative; overflow: hidden; }

/* 表单 */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; min-width: 140px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(59,110,246,.25); border-color: var(--primary); }
.row { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }

/* 标签页 */
.tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 16px; font-size: 13.5px; cursor: pointer; color: var(--muted);
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* 图片预览 */
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.preview-item { position: relative; width: 92px; height: 92px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-item .del {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.55); color: #fff;
  border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 11px; line-height: 1;
}
.status-line { margin-top: 10px; font-size: 13px; color: var(--muted); min-height: 18px; }
.status-line.err { color: var(--red); }
.status-line.ok { color: var(--green); }

/* 识别结果 */
.rec-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.rec-item .rec-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.rec-item textarea { margin-top: 6px; }
.rec-check { width: 18px; height: 18px; accent-color: var(--primary); }

/* 错题列表 */
.m-card { cursor: pointer; transition: box-shadow .15s; }
.m-card:hover { box-shadow: 0 3px 10px rgba(20,30,60,.10); }
.m-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.m-text { font-size: 14px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.m-foot { display: flex; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chip {
  display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 11.5px; font-weight: 600;
  background: #eef2fb; color: var(--primary);
}
.chip.gray { background: #f0f1f4; color: var(--muted); }
.chip.green { background: #e5f6ee; color: var(--green); }
.chip.red { background: #fdeae7; color: var(--red); }
.chip.orange { background: #fef2e2; color: var(--orange); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.filter-card .row { margin-top: 0; }
.filter-card input[type=search] { flex: 2; min-width: 160px; }

/* 复习 */
.due-list { margin-bottom: 6px; }
.due-item { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.due-item:last-child { border-bottom: none; }
.review-q { font-size: 15px; margin: 10px 0; }
.review-actions { display: flex; gap: 10px; margin-top: 12px; }
.review-actions .btn { flex: 1; padding: 12px; }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
.btn.fail { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.answer-box { background: #f7f9fd; border-radius: 10px; padding: 12px; margin-top: 10px; }

/* 计划 */
.plan-day { margin-bottom: 12px; }
.plan-day-head { font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.block-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.block-item:last-child { border-bottom: none; }
.block-item input[type=checkbox] { margin-top: 4px; width: 17px; height: 17px; accent-color: var(--green); }
.block-item.done .block-task { text-decoration: line-through; color: var(--muted); }
.block-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.block-task { font-size: 13.5px; flex: 1; }

/* 弹层 */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(15,20,35,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-body {
  background: var(--bg); width: 100%; max-width: 860px; max-height: 92vh;
  border-radius: 18px 18px 0 0; overflow-y: auto; padding: 14px 14px 30px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; position: sticky; top: 0; background: var(--bg); padding: 4px 0; z-index: 2; }
#detail-title { font-weight: 700; font-size: 16px; }

/* 详情内部 */
.detail-section { margin-bottom: 12px; }
.detail-section h4 { font-size: 14px; margin-bottom: 6px; }
.detail-text { font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.detail-imgs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.detail-imgs img { max-width: 160px; max-height: 160px; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.cause-box { border-left: 3px solid var(--orange); background: #fff8ef; border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.tutor-chat { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.msg { max-width: 92%; border-radius: 12px; padding: 10px 12px; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.msg.ai { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg.ai .md p { margin: 4px 0; }
.mode-switch { display: flex; gap: 8px; margin-bottom: 8px; }
.similar-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13.5px; }
.verify-note { font-size: 12px; color: var(--orange); margin-top: 6px; }

/* Markdown 内容 */
.md { font-size: 14px; line-height: 1.75; word-break: break-word; }
.md p { margin: 6px 0; }
.md ol, .md ul { padding-left: 22px; margin: 6px 0; }
.md code { background: #f0f2f7; border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.md pre { background: #f6f8fb; border-radius: 8px; padding: 10px; overflow-x: auto; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); margin: 6px 0; }
.md table { border-collapse: collapse; margin: 8px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; font-size: 13px; }
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* 底部导航 */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; max-width: 100%;
}
.nav-item {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 15px; color: var(--muted); min-width: 0;
}
.nav-item span { font-size: 10px; white-space: nowrap; }
.nav-item.active { color: var(--primary); font-weight: 700; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translateX(-50%);
  background: rgba(25,32,50,.92); color: #fff; border-radius: 10px;
  padding: 10px 18px; font-size: 13.5px; z-index: 99; max-width: 86vw; text-align: center;
}
.tip { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fff8ef; font-size: 13px; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick {
  border: 1px solid var(--line); background: #f8fafd; border-radius: 12px;
  padding: 14px 10px; font-size: 14px; cursor: pointer;
}
.quick:hover { background: #eef3fc; }

/* 桌面适配 */
@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .modal { align-items: center; padding: 20px; }
  .modal-body { border-radius: 18px; max-height: 88vh; }
  .bottom-nav { max-width: 860px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (max-width: 420px) {
  .stat-num { font-size: 21px; }
  .row { flex-wrap: wrap; }
}

/* 考试记录 */
.trend-svg { width: 100%; height: auto; display: block; margin: 6px 0; }
.exam-total { font-size: 15px; margin: 8px 0; }
.exam-total b { color: var(--primary); font-size: 18px; }
.exam-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.exam-table th, .exam-table td { border: 1px solid var(--line); padding: 6px 8px; font-size: 13px; text-align: center; }
.exam-table th { background: #f6f8fc; color: var(--muted); font-weight: 600; }
.exam-table .rate-low { color: var(--red); font-weight: 700; }
.exam-table .rate-high { color: var(--green); font-weight: 700; }
.exam-row { align-items: flex-end; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.exam-row .field { min-width: 70px; }
.exam-row .er-del { margin-bottom: 1px; }
