/* AITutor 学生端样式 —— 移动优先，浅色主题，字大、按钮大（给初中生用） */
:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1b2233;
  --ink-2: #5a6478;
  --line: #e3e8f0;
  --brand: #2f6df6;
  --brand-ink: #ffffff;
  --ok: #17a673;
  --warn: #e8890c;
  --danger: #d94a4a;
  --shadow: 0 2px 10px rgba(24, 39, 75, .06);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

body { padding-bottom: env(safe-area-inset-bottom); }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand .sub { margin-left: 8px; font-weight: 400; font-size: 12px; color: var(--ink-2); }
.quota {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: 4px 12px; font-size: 12px;
}

/* ---------- Tab ---------- */
main { padding: 14px 14px calc(78px + env(safe-area-inset-bottom)); }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 12px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfe;
}
.card-head .tag { font-size: 13px; font-weight: 600; color: var(--brand); }
.card-body { padding: 14px; }
.card-body > :first-child { margin-top: 0; }
.card-body > :last-child { margin-bottom: 0; }

/* ---------- 按钮 ---------- */
button, .cap-btn {
  font: inherit; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; transition: transform .06s, background .15s;
}
button:active, .cap-btn:active { transform: scale(.985); }
button.primary, .cap-btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.ok { background: #e8f8f1; border-color: #b9e7d3; color: #0f7a53; font-weight: 600; }
button.warn { background: #fff4e5; border-color: #ffd9a8; color: #a35d00; font-weight: 600; }
button.ghost { background: #fff; color: var(--ink-2); }
button.mini { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

/* ---------- 拍题区 ---------- */
.capture { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cap-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 18px 10px; text-align: center; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.cap-btn .ico { font-size: 24px; line-height: 1; }
.cap-btn:last-child { grid-column: 1 / -1; }
.cap-btn.primary { color: var(--brand-ink); }

.hint { color: var(--ink-2); font-size: 13px; }
.hint.center { text-align: center; }

.text-fallback { margin-top: 14px; }
.text-fallback textarea, #fixTextArea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; resize: vertical; background: #fff; color: var(--ink);
}
.text-fallback button { margin-top: 8px; width: 100%; }

/* ---------- 复习横幅 ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #eef4ff; border: 1px solid #cfe0ff; color: #1b4fbf;
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}
.banner-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- 讲解 ---------- */
.lesson { margin-top: 16px; }
.read-card .card-body { font-size: 17px; }
.read-card .stem { white-space: pre-wrap; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: #eef4ff; color: #1b4fbf; border: 1px solid #d8e5ff;
}
.chip.tag-chip { background: #f0fbf6; color: #0f7a53; border-color: #c9ecd9; }

.pick-list { padding: 8px; }
.pick-item {
  width: 100%; text-align: left; margin-bottom: 8px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; line-height: 1.5;
}
.pick-item .idx { color: var(--brand); font-weight: 700; margin-right: 6px; }

.refuse { padding: 16px; text-align: center; }
.refuse button { margin-top: 12px; }

/* 提示层 */
.hints { counter-reset: hint; }
.hint-item {
  display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.hint-item:last-child { border-bottom: 0; }
.hint-item .no {
  flex: 0 0 26px; height: 26px; border-radius: 50%; background: #eef4ff; color: #1b4fbf;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}

/* 步骤 */
.step { padding: 14px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.step-title { font-weight: 700; margin-bottom: 4px; }
.step-why { color: #a35d00; background: #fff8ec; border-left: 3px solid #f0b45a; padding: 6px 10px; border-radius: 6px; font-size: 14px; margin: 8px 0; }
.step-detail { margin-top: 8px; }
.step-ask-btn { margin-top: 8px; font-size: 13px; padding: 4px 10px; }

/* 折叠区 */
.fold { border-top: 1px solid var(--line); }
.fold > summary {
  cursor: pointer; padding: 12px 14px; font-weight: 600; font-size: 15px;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: "▾"; color: var(--ink-2); font-size: 12px; }
.fold[open] > summary::after { content: "▴"; }
.fold .fold-body { padding: 0 14px 14px; }
.k-card { background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.k-card .k-title { font-weight: 600; color: var(--brand); margin-bottom: 4px; }
.pitfall-item { padding-left: 20px; position: relative; margin-bottom: 6px; }
.pitfall-item::before { content: "⚠️"; position: absolute; left: 0; }
.variant-item { border-left: 3px solid var(--brand); padding-left: 10px; margin-bottom: 10px; }

/* 操作条 */
.lesson-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.lesson-actions button { width: 100%; padding: 12px; }

.step-ask { display: flex; gap: 8px; margin-top: 12px; }
.step-ask input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; }

/* 图 */
.visual-box { margin-top: 10px; background: #fbfcfe; border: 1px dashed var(--line); border-radius: 10px; padding: 10px; }
.visual-box svg { width: 100%; height: auto; display: block; }
.visual-cap { font-size: 12px; color: var(--ink-2); text-align: center; margin-top: 6px; }
.visual-controls { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

/* ---------- 错题本 ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters select { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; }
.book-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.book-item .bi-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.book-item .bi-subject { font-size: 12px; font-weight: 700; color: var(--brand); }
.book-item .bi-stem { font-size: 15px; margin-bottom: 8px; white-space: pre-wrap; }
.book-item .bi-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mastery-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; width: 70px; }
.mastery-bar > i { display: block; height: 100%; background: var(--ok); }
.book-item .actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- 我的 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stats .num { font-size: 22px; font-weight: 700; color: var(--brand); }
.stats .lbl { font-size: 12px; color: var(--ink-2); }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.switch-row select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
#quotaBox .bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
#quotaBox .bar > i { display: block; height: 100%; background: var(--brand); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: transparent; border-radius: 0;
  padding: 8px 0 10px; color: var(--ink-2); font-size: 12px; line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button.active { color: var(--brand); font-weight: 600; }
.tabbar .ti {
  width: 21px; height: 21px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tabbar .tl { display: block; }

/* ---------- 抽屉 ---------- */
.drawer {
  position: fixed; inset: 0; z-index: 60; background: var(--card);
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
  overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.drawer-body { padding: 16px; }
.drawer-body label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--ink-2); }
.drawer-body input, .drawer-body select {
  width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; background: #fff; color: var(--ink);
}
.drawer-body > button { width: 100%; }
.byok-steps { margin: 12px 0; }
.byok-step { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; font-size: 14px; }
.byok-step .mark { flex: 0 0 20px; }
.byok-step.ok .mark { color: var(--ok); }
.byok-step.bad .mark { color: var(--danger); }
.byok-step .fix { color: var(--ink-2); font-size: 13px; }
.tutorial { font-size: 13px; color: var(--ink-2); background: #f7f9fc; border-radius: 10px; padding: 12px; }
.tutorial ol { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Gate ---------- */
.gate { padding: 40px 20px; max-width: 480px; margin: 0 auto; }
.gate h2 { margin: 0 0 8px; }
.gate .row { display: flex; gap: 8px; margin: 16px 0 8px; }
.gate input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; }

/* ---------- Toast / Loading ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 90;
  background: rgba(27, 34, 51, .94); color: #fff; padding: 10px 16px;
  border-radius: 999px; font-size: 14px; max-width: 86vw; text-align: center;
}
.loading {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(245, 247, 251, .82); backdrop-filter: blur(2px);
  color: var(--ink-2); font-size: 14px;
}
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--line);
  border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* KaTeX 行内公式不要撑破行 */
.katex { font-size: 1.02em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* 宽屏 */
@media (min-width: 720px) {
  main { max-width: 760px; margin: 0 auto; }
  .capture { grid-template-columns: repeat(3, 1fr); }
  .cap-btn:last-child { grid-column: auto; }
  .lesson-actions { flex-direction: row; }
  .lesson-actions button { width: auto; flex: 1; }
}
