:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1b2026;
  --ink-2: #5c6672;
  --ink-3: #8a939e;
  --line: #e5e7eb;
  --accent: #245e8f;
  --accent-2: #3b82c4;
  --accent-soft: #e9f1f8;
  --warn: #b45309;
  --warn-soft: #fdf3e6;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --ok: #227a52;
  --ok-soft: #e7f4ee;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(20, 40, 70, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  line-height: 1.65; font-size: 16px;
}
body { padding-bottom: 78px; }
#app { max-width: 820px; margin: 0 auto; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: rgba(246,247,249,.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 700;
}
.brand-text { font-weight: 650; font-size: 15px; letter-spacing: .3px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #eceff3;
  color: var(--ink-2); cursor: pointer; border: 1px solid var(--line); white-space: nowrap;
}
.chip.on { background: var(--ok-soft); color: var(--ok); border-color: #cfe7da; }

main { padding: 16px; }
h1,h2,h3,h4 { line-height: 1.35; }
h2 { font-size: 19px; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 0 0 8px; }
h4 { font-size: 15px; margin: 16px 0 6px; color: var(--accent); }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.sub { color: var(--ink-2); font-size: 13px; margin: 0 0 14px; }
.muted { color: var(--ink-2); font-size: 13px; }
.tiny { font-size: 12px; color: var(--ink-3); }
.hidden { display: none !important; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 550;
  cursor: pointer; transition: .15s; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.soft { background: var(--accent-soft); border-color: #d5e4f0; color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f1c9c9; background: #fff; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  border: 0; background: none; font: inherit; font-size: 12px; color: var(--ink-2);
  padding: 10px 0 9px; cursor: pointer;
}
.tab.active { color: var(--accent); font-weight: 650; }

/* 首页 */
.hero {
  background: linear-gradient(135deg, #245e8f, #3b82c4);
  color: #fff; border-radius: 18px; padding: 20px 18px; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(36,94,143,.22);
}
.hero h2 { color: #fff; font-size: 21px; margin: 0 0 4px; }
.hero p { color: rgba(255,255,255,.85); font-size: 13px; margin: 0 0 14px; }
.hero .btn { background: #fff; color: var(--accent); border-color: #fff; font-weight: 650; }
.hero .btn.ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.4); }
.hero-stats { display: flex; gap: 18px; margin-top: 14px; }
.hero-stats b { font-size: 20px; display: block; line-height: 1.2; }
.hero-stats span { font-size: 11px; color: rgba(255,255,255,.75); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 0 8px; }
.section-head h3 { margin: 0; }
.section-head a, .section-head button { font-size: 13px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }

.layers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.layer {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px;
}
.layer .name { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; }
.layer .val { font-size: 18px; font-weight: 700; margin-top: 2px; }
.layer .bar { margin-top: 8px; }

.topic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 520px) { .topic-grid { grid-template-columns: 1fr; } }
.topic-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; cursor: pointer; transition: .18s;
}
.topic-card:hover { border-color: #cbd8e4; box-shadow: var(--shadow); }
.topic-card .tname { font-weight: 600; font-size: 14.5px; }
.topic-card .tdesc { font-size: 12px; color: var(--ink-2); margin-top: 2px; min-height: 32px; }
.topic-card .tmeta { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }

.bar { height: 5px; background: #edeff2; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: .35s; }
.bar.ok > i { background: var(--ok); }

/* 列表 */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2); cursor: pointer;
}
.fchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input, .searchbar select {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font: inherit; font-size: 14px;
}
.searchbar select { flex: none; width: 128px; }

.qlist { display: flex; flex-direction: column; gap: 8px; }
.qitem {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; transition: .15s;
}
.qitem:hover { border-color: #cbd8e4; }
.qitem .qno {
  flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.qitem .qmain { flex: 1; min-width: 0; }
.qitem .qt { font-size: 14.5px; font-weight: 550; }
.qitem .qm { font-size: 12px; color: var(--ink-2); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.qitem .qright { flex: none; font-size: 11.5px; color: var(--ink-3); text-align: right; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.part { background: #d97706; }
.dot.no { background: var(--danger); }

/* 练习页 */
.qhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.qcount { font-size: 13px; color: var(--ink-2); }
.qsrc { display: inline-block; font-size: 12px; color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 6px; }
.qtitle { font-size: 18px; font-weight: 650; margin: 4px 0 10px; }
.qprompt {
  white-space: pre-wrap; font-size: 15.5px; line-height: 1.9;
  background: #fbfcfd; border-left: 3px solid #cddbe7;
  padding: 14px 15px; border-radius: 8px;
}
.qprompt .blank {
  display: inline-block; min-width: 3.2em; height: 1.05em; border-bottom: 1.5px solid #9aa7b4;
  vertical-align: baseline; margin: 0 .15em;
}
.media { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.media figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.media img { width: 100%; height: auto; display: block; border-radius: 6px; cursor: zoom-in; }
.media figcaption { font-size: 11.5px; color: var(--ink-3); text-align: center; margin-top: 4px; }

.answer {
  margin-top: 16px; border: 1px solid #d9e6f1; background: var(--accent-soft);
  border-radius: 12px; padding: 14px;
}
.answer h4 { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.answer .ans { white-space: pre-wrap; font-size: 15px; line-height: 1.8; }
.answer .ana { white-space: pre-wrap; font-size: 14px; line-height: 1.8; color: #33414d; margin-top: 10px; }
.answer .ana-label { font-size: 12px; color: var(--ink-2); margin-top: 12px; }
.ana-wrap { margin-top: 12px; border-top: 1px dashed #c9dbe9; padding-top: 10px; }
.ana-wrap summary { font-size: 13px; color: var(--accent); cursor: pointer; user-select: none; }
.ana-wrap[open] summary { margin-bottom: 8px; }
.ana-note { font-size: 11.5px; color: var(--ink-3); margin-top: 10px; }

.grade-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.grade {
  padding: 12px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: 13.5px; cursor: pointer; text-align: center;
}
.grade small { display: block; font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.grade.g2 { border-color: #bfe3d2; }
.grade.g1 { border-color: #f0d3a8; }
.grade.g0 { border-color: #f1c4c4; }
.grade:hover { background: #fafbfc; }
.grade:active { transform: scale(.98); }

/* 方法课 */
.lesson-card {
  display: flex; gap: 13px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; cursor: pointer; margin-bottom: 10px;
}
.lesson-card:hover { border-color: #cbd8e4; }
.lesson-icon {
  flex: none; width: 40px; height: 40px; border-radius: 11px; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.lesson-main { flex: 1; min-width: 0; }
.lesson-title { font-weight: 600; font-size: 15px; }
.lesson-desc { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.lesson-body { font-size: 15px; line-height: 1.85; }
.lesson-body .lead { color: var(--ink-2); font-size: 14.5px; }
.lesson-body ul, .lesson-body ol { padding-left: 20px; margin: 6px 0 12px; }
.lesson-body li { margin: 4px 0; }
.lesson-body pre {
  background: #f5f7fa; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; font-size: 13.5px; line-height: 1.7;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.lesson-body table.mini { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 6px 0 12px; }
.lesson-body table.mini th, .lesson-body table.mini td {
  border: 1px solid var(--line); padding: 6px 8px; text-align: left;
}
.lesson-body table.mini th { background: #f5f7fa; font-weight: 600; }
.pitfall {
  background: var(--warn-soft); color: #7c3f06; border-radius: 8px;
  padding: 10px 12px; font-size: 13.5px; margin: 12px 0;
}
.drill {
  display: inline-block; background: var(--accent); color: #fff !important;
  padding: 8px 14px; border-radius: 9px; font-size: 13.5px; cursor: pointer; text-decoration: none;
}

/* 统计 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-align: center;
}
.stat b { font-size: 21px; display: block; }
.stat span { font-size: 11.5px; color: var(--ink-2); }
.topicstat { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f1f3; }
.topicstat:last-child { border-bottom: 0; }
.topicstat .tn { width: 132px; flex: none; font-size: 13.5px; }
.topicstat .tb { flex: 1; }
.topicstat .tv { width: 44px; text-align: right; font-size: 12.5px; color: var(--ink-2); flex: none; }

/* 空状态 */
.empty { text-align: center; color: var(--ink-2); padding: 48px 16px; font-size: 14px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,32,.5); z-index: 60;
  display: grid; place-items: center; padding: 18px;
}
.modal {
  background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2); max-height: 82vh; overflow: auto;
}
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-actions .btn { flex: 1; }
.modal .codebox {
  font-family: ui-monospace, Consolas, monospace; font-size: 26px; letter-spacing: 6px;
  text-align: center; background: #f5f7fa; border: 1px dashed #c7d3df; border-radius: 10px;
  padding: 14px; margin: 10px 0; color: var(--accent); font-weight: 700;
}
.modal input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font: inherit; letter-spacing: 3px; text-align: center; text-transform: uppercase;
}
.lightbox { position: fixed; inset: 0; background: rgba(10,15,20,.92); z-index: 80;
  display: grid; place-items: center; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 92vh; background: #fff; border-radius: 6px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --card: #161c23; --ink: #e7edf3; --ink-2: #a3b0bd; --ink-3: #74808c;
    --line: #26303a; --accent: #6aa9dc; --accent-soft: #17293a; --ok: #5fc394; --ok-soft: #163024;
  }
  .tabbar { background: rgba(18,24,30,.95); }
  .topbar { background: rgba(15,20,25,.92); }
  .qprompt { background: #131920; border-left-color: #33506a; }
  .media figure, .searchbar input, .searchbar select, .btn, .grade { background: var(--card); color: var(--ink); }
  .answer { background: #14232f; border-color: #244055; }
  .answer .ana { color: #c2ced9; }
  .lesson-body pre { background: #111820; }
  .lesson-body table.mini th { background: #111820; }
  .modal { background: var(--card); color: var(--ink); }
  .modal input { background: #111820; color: var(--ink); }
  .modal .codebox { background: #111820; border-color: #33506a; }
  .pitfall { background: #2b1d0c; color: #f0c48a; }
  .empty, .sub, .muted { color: var(--ink-2); }
}
