:root {
  --paper: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #efe9dd;
  --ink: #211e1a;
  --ink-soft: #5b554c;
  --muted: #9a9384;
  --line: #e4ddcf;
  --accent: #b23a2e;       /* 朱 */
  --accent-ink: #fff;
  --accent-soft: #f3e2dd;
  --ok: #4f7a5b;
  --warn: #c08a2e;
  --shadow-sm: 0 1px 2px rgba(40,34,26,.06);
  --shadow: 0 1px 2px rgba(40,34,26,.06), 0 10px 30px rgba(40,34,26,.07);
  --radius: 14px;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

[data-theme="dark"] {
  --paper: #14120e;
  --surface: #1e1b16;
  --surface-2: #272320;
  --ink: #f1ece1;
  --ink-soft: #b8b0a0;
  --muted: #7c7466;
  --line: #322e26;
  --accent: #d2604f;
  --accent-soft: #3a241f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.seal {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-family: var(--serif); font-size: 20px; font-weight: 700;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.brand-text h1 { margin: 0; font-size: 19px; }
.brand-text p { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .14em; }
.theme-btn { margin-left: 8px; }

.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); padding: 8px 16px; border-radius: 999px;
  font-size: 14px; transition: .18s;
}
.nav-btn:hover { border-color: var(--accent); color: var(--ink); }
.nav-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 64px; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 通用控件 ---------- */
.inp {
  width: 100%; padding: 10px 12px; font-size: 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
  transition: border-color .15s;
}
.inp:focus { border-color: var(--accent); }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.btn.danger { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn.ghost { background: transparent; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 9px; font-size: 16px; line-height: 1;
  display: grid; place-items: center; transition: .15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--ink); }

/* ---------- 速记 / 拍照 ---------- */
.capture-wrap { max-width: 560px; margin: 0 auto; }
.viewfinder {
  position: relative; aspect-ratio: 4 / 3; background: #000;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
#cam { width: 100%; height: 100%; object-fit: cover; display: block; }
.vf-corners i {
  position: absolute; width: 22px; height: 22px; border: 2px solid rgba(255,255,255,.85);
}
.vf-corners i:nth-child(1) { top: 14px; left: 14px; border-right: 0; border-bottom: 0; }
.vf-corners i:nth-child(2) { top: 14px; right: 14px; border-left: 0; border-bottom: 0; }
.vf-corners i:nth-child(3) { bottom: 14px; left: 14px; border-right: 0; border-top: 0; }
.vf-corners i:nth-child(4) { bottom: 14px; right: 14px; border-left: 0; border-top: 0; }
.vf-hint {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px; text-align: center; font-size: 13px;
  color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55));
}
.capture-actions { display: flex; align-items: center; gap: 16px; margin-top: 22px; justify-content: center; }
.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  border: 5px solid var(--surface); background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: var(--shadow);
  transition: transform .12s;
}
.shutter:active { transform: scale(.92); }
.file-btn { margin-left: 4px; }

/* ---------- 错题墙 ---------- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); transition: .18s; cursor: pointer;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.card .thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-2); display: block; }
.card .card-body { padding: 10px 12px 12px; }
.card .card-subj { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.card .card-chap { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 16px; }
.card .card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.noimg {
  width: 100%; aspect-ratio: 4/3; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 13px;
}

.pill { font-size: 11px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft); }
.pill.pending { color: var(--muted); }
.pill.reviewing { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.pill.mastered { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.tag-chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

/* ---------- 复习 ---------- */
.review-card { max-width: 560px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.review-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.review-img { width: 100%; border-radius: 10px; background: var(--surface-2); display: block; }
.review-answer { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.ans-block h4 { margin: 0 0 4px; font-size: 13px; color: var(--accent); }
.ans-block p { margin: 0 0 10px; white-space: pre-wrap; font-size: 14px; color: var(--ink-soft); }
.review-actions { display: flex; gap: 10px; margin-top: 16px; }
.review-actions .btn { flex: 1; }
.review-progress { text-align: center; color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ---------- 统计 ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; box-shadow: var(--shadow-sm); }
.stat-card .num { font-family: var(--serif); font-size: 30px; font-weight: 700; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
.sect { margin: 28px 0 14px; font-size: 16px; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }

/* ---------- 抽屉 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,18,14,.45); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw); z-index: 50;
  background: var(--paper); border-left: 1px solid var(--line);
  box-shadow: -10px 0 40px rgba(0,0,0,.18);
  display: flex; flex-direction: column; animation: slidein .25s ease;
}
@keyframes slidein { from { transform: translateX(100%); } to { transform: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer-img { width: 100%; border-radius: 10px; margin-bottom: 14px; background: var(--surface-2); }
.no-photo { padding: 24px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 10px; margin-bottom: 14px; }
.fld { display: block; margin-bottom: 14px; }
.fld > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; letter-spacing: .04em; }
.fld textarea { resize: vertical; }
.stars { display: flex; gap: 6px; }
.star { font-size: 22px; color: var(--line); background: none; border: none; padding: 0; line-height: 1; transition: color .12s; }
.star.on { color: var(--warn); }
.drawer-foot { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.drawer-foot .btn.primary { margin-left: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 80; box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 12px 14px; }
  main { padding: 18px 14px 56px; }
}
