:root {
  --bg: #f4f2ec;
  --card: #fffefb;
  --ink: #1d1c19;
  --ink-2: #4a463d;
  --muted: #918b7c;
  --line: #e5e0d3;
  --accent: #2f6f52;
  --accent-soft: #e6efe8;
  --star: #c9902a;
  --danger: #b8463c;
  --shadow: 0 1px 2px rgba(40, 35, 20, .05), 0 8px 24px rgba(40, 35, 20, .06);
  --r: 16px;
  --fs: 1;
  --tab-h: 58px;
}
html[data-theme="dark"] {
  --bg: #15161a;
  --card: #1e2026;
  --ink: #edeae2;
  --ink-2: #bdb8ac;
  --muted: #837e73;
  --line: #2e3038;
  --accent: #6fbf95;
  --accent-soft: #22322b;
  --star: #e0b054;
  --danger: #e0776c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: calc(16px * var(--fs));
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; font-size: calc(16px * var(--fs)); border: 0; background: none; color: inherit; cursor: pointer; }
b, i { font-style: normal; }
[hidden] { display: none !important; }

/* ---------- 视图容器 ---------- */
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  min-height: 100dvh;
}
.view.review-mode { padding: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 2px 10px;
  gap: 10px;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand .dot { color: var(--muted); margin: 0 3px; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: .82em; }
.count { color: var(--muted); font-size: .85em; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px; color: var(--ink-2);
  background: var(--card); box-shadow: var(--shadow);
}
.icon-btn:disabled { opacity: .35; }
.section-title { margin: 22px 2px 10px; font-size: .82em; color: var(--muted); letter-spacing: .5px; }
.tip { color: var(--muted); font-size: .82em; line-height: 1.7; padding: 0 2px; }
.tip.foot { margin-top: 18px; font-size: .74em; opacity: .8; text-align: center; }

/* ---------- 今日 ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.hero {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px; margin-top: 6px; position: relative; overflow: hidden;
}
.days-left { font-size: 46px; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.days-left i { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.hero-cap { color: var(--muted); font-size: .82em; margin-top: 8px; }
.ring { width: 84px; height: 84px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 8; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: 276.5; stroke-dashoffset: 276.5;
  transition: stroke-dashoffset .5s ease;
}

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px 8px; text-align: center;
}
.stat b { display: block; font-size: 24px; font-weight: 750; line-height: 1.1; }
.stat span { font-size: .72em; color: var(--muted); }
.mastery-line { margin: 12px 2px 0; font-size: .8em; color: var(--muted); }

.primary {
  width: 100%; background: var(--accent); color: #fff; font-weight: 700;
  border-radius: 14px; padding: 16px; margin-top: 18px;
  box-shadow: 0 6px 16px rgba(47, 111, 82, .25);
}
.primary:active { transform: translateY(1px); }
.primary.big { font-size: 1.08em; }
.primary[disabled] { opacity: .45; box-shadow: none; }

.chip-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.chip-row.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip-row.scroll::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--card);
  color: var(--ink-2); font-size: .84em; box-shadow: var(--shadow); white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; box-shadow: none; }

/* ---------- 背记 ---------- */
.review-bar { padding: calc(env(safe-area-inset-top) + 12px) 12px 8px; }
.progress-wrap { flex: 1; }
.progress { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s; }
.progress-label { display: flex; justify-content: space-between; font-size: .72em; color: var(--muted); margin-top: 5px; }

.card-stage {
  padding: 12px 14px 0; min-height: 46dvh;
  display: flex;
}
.qa-card {
  flex: 1; background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  padding: 18px 18px 20px; max-height: calc(100dvh - 250px); overflow-y: auto;
  overscroll-behavior: contain;
}
.qa-meta { display: flex; align-items: center; gap: 8px; font-size: .72em; color: var(--muted); flex-wrap: wrap; }
.badge-doc, .badge-type {
  padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  font-size: .95em; font-weight: 600;
}
.badge-type { background: var(--line); color: var(--ink-2); }
.badge-type.uncertain { background: #f6ecd4; color: #a4761c; }
html[data-theme="dark"] .badge-type.uncertain { background: #3a2f14; color: #e0b054; }
.qa-chapter { font-size: .76em; color: var(--muted); margin-top: 10px; }
.qa-q { font-size: 1.24em; font-weight: 650; line-height: 1.55; margin-top: 12px; letter-spacing: .2px; }
.qa-q .blank { color: var(--muted); }
.qa-answer {
  margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line);
  font-size: 1.04em; line-height: 1.8; color: var(--ink); word-break: break-word;
}
.qa-answer .hl { background: linear-gradient(transparent 62%, var(--star) 62%); background-size: 100% 60%; font-weight: 600; }
.qa-note { margin-top: 12px; font-size: .82em; color: var(--muted); line-height: 1.7; border-left: 3px solid var(--line); padding-left: 10px; }
.tap-hint { text-align: center; color: var(--muted); font-size: .78em; margin-top: 18px; opacity: .8; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 3px; line-height: 1.15; font-size: 0.95em; }
.frac > span { white-space: nowrap; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 4px; }
.frac > span:last-child { padding: 0 4px; }
.qa-answer { overflow-x: auto; }

.review-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--bg) 72%, transparent);
  display: flex; gap: 10px; align-items: stretch;
  max-width: 560px; margin: 0 auto;
}
.review-actions .primary { margin-top: 0; flex: 1; }
.ghost-btn {
  padding: 10px 16px; border-radius: 12px; background: var(--card); color: var(--ink-2);
  box-shadow: var(--shadow); font-size: .9em; white-space: nowrap;
}
.ghost-btn:active { opacity: .7; }
.ghost-btn.danger { color: var(--danger); width: 100%; margin-top: 8px; }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grade {
  border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; gap: 2px;
  align-items: center; font-weight: 700; box-shadow: var(--shadow); background: var(--card);
  border: 1.5px solid transparent;
}
.grade span { font-size: .68em; font-weight: 400; opacity: .75; }
.grade.g1 { color: var(--danger); border-color: rgba(184, 70, 60, .22); }
.grade.g2 { color: #a4761c; border-color: rgba(164, 118, 28, .22); }
.grade.g3 { color: var(--accent); border-color: rgba(47, 111, 82, .25); }
.grade:active { transform: scale(.97); }

/* ---------- 浏览 ---------- */
.search-wrap { margin: 2px 0 10px; }
#search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: .95em; outline: none;
}
#search:focus { border-color: var(--accent); }
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.item {
  background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.item .q { font-weight: 600; font-size: .95em; line-height: 1.45; }
.item .m { font-size: .72em; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.item .star { color: var(--star); }
.list.compact .item { padding: 10px 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: .9em; }

/* ---------- 统计 ---------- */
.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.stat.big-stat { padding: 16px 12px; text-align: left; }
.stat.big-stat b { font-size: 26px; }
.bars { display: flex; gap: 8px; align-items: flex-end; height: 120px; padding: 0 2px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-col .bar { width: 100%; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; opacity: .85; }
.bar-col .lbl { font-size: .64em; color: var(--muted); }
.chapter-list { display: flex; flex-direction: column; gap: 8px; }
.chapter-row { background: var(--card); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.chapter-row .t { display: flex; justify-content: space-between; font-size: .84em; gap: 10px; }
.chapter-row .t span:last-child { color: var(--muted); font-size: .9em; }
.chapter-row .track { height: 5px; border-radius: 999px; background: var(--line); margin-top: 8px; overflow: hidden; }
.chapter-row .track i { display: block; height: 100%; background: var(--accent); }

/* ---------- 设置 ---------- */
.form-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.form-row label { font-size: .92em; color: var(--ink-2); }
.form-row input[type="date"], .form-row select {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 8px; padding: 7px 8px; font-size: .9em; font-family: inherit;
}
.form-row input[type="range"] { width: 45%; accent-color: var(--accent); }
.btn-row { display: flex; gap: 10px; }
.btn-row .ghost-btn { flex: 1; text-align: center; }
.switch { position: relative; width: 46px; height: 27px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s;
}
.switch i::after {
  content: ""; position: absolute; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: .2s;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(19px); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px; margin: 0 auto;
}
.tabbar button {
  height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .68em; color: var(--muted);
}
.tabbar button i { font-size: 17px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* ---------- 浮层 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column;
}
.overlay-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; font-size: .9em; color: var(--ink-2);
}
.page-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pinch-zoom; text-align: center; }
.page-scroll img { width: 100%; max-width: 900px; display: block; margin: 0 auto; transform-origin: top center; transition: transform .2s; }
.page-scroll img.zoomed { transform: scale(2); }
.overlay-foot { padding: 8px 14px calc(env(safe-area-inset-bottom) + 10px); text-align: center; }
.overlay.sheet { background: var(--bg); }
/* 原页浮层可以盖在题库详情之上，z-index 必须高于其它浮层 */
#page-overlay { z-index: 60; }
.chapter-picker, .detail-body { flex: 1; overflow: auto; padding: 4px 14px calc(env(safe-area-inset-bottom) + 20px); }
.chapter-group { margin-bottom: 14px; }
.chapter-group .g-title { font-size: .78em; color: var(--muted); margin: 10px 2px 6px; }
.chapter-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--card); border-radius: 10px; padding: 12px 14px; margin-bottom: 6px;
  box-shadow: var(--shadow); font-size: .9em; text-align: left; width: 100%;
}
.chapter-item span:last-child { color: var(--muted); font-size: .84em; }
.detail-body .qa-q { font-size: 1.1em; }
.detail-body .qa-answer { border-top: 1px dashed var(--line); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 30px); transform: translateX(-50%) translateY(10px);
  background: rgba(28, 26, 22, .92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: .84em; opacity: 0; pointer-events: none; transition: .22s; z-index: 99; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 700px) {
  .view { padding-left: 24px; padding-right: 24px; }
  .days-left { font-size: 54px; }
}
