:root {
  --bg: #1a211d;
  --bg2: #242c27;
  --bg3: #2e3832;
  --line: #4a574e;
  --gold: #e2c48a;
  --gold-dim: #c4a062;
  --ink: #f6f1e6;
  --muted: #b7c0b8;
  --paper: #f4eedf;
  --paper2: #ebe3d0;
  --read: #221c14;
  --red: #e07060;
  --ok: #4cba88;
  --warn: #d4a24a;
  --know: #8eabc0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --ui: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--ui); }
button, input, textarea, select { font-family: inherit; }
select {
  background: var(--bg3);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
img { max-width: 100%; }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
}
.app.collapse { grid-template-columns: 0 1fr; }
.app.collapse .sidebar { overflow: hidden; border: 0; padding: 0; }

.sidebar {
  background: linear-gradient(180deg, #141a17, #101412);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
}
.brand { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.seal {
  width: 42px; height: 42px; border: 1.5px solid var(--gold);
  color: var(--gold); display: grid; place-items: center;
  font-family: var(--serif); font-size: 22px; border-radius: 4px;
  box-shadow: inset 0 0 0 3px rgba(212, 180, 131, 0.18);
}
.brand-name { font-weight: 600; letter-spacing: 0.18em; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 11px; margin-top: 2px; letter-spacing: 0.04em; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  padding: 9px 12px; border-radius: 8px; color: #e4ebe6; font-size: 14px;
}
.nav a:hover { background: var(--bg3); }
.nav a.active { background: var(--bg3); color: var(--gold); }

.side-stat { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.7; }
.side-stat b { color: var(--gold); font-weight: 600; }
.bar { height: 6px; background: #2a332e; border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.side-foot { font-size: 11px; color: #5d6660; letter-spacing: 0.08em; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: rgba(16,20,18,.9);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5;
}
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  width: 34px; height: 34px; border-radius: 8px;
}
.crumb { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.search-mini {
  width: 240px; background: var(--bg2); border: 1px solid var(--line); color: var(--ink);
  padding: 8px 10px; border-radius: 8px; outline: none;
}
.search-mini:focus { border-color: var(--gold-dim); }
.pill {
  font-size: 12px; color: var(--gold); border: 1px solid var(--gold-dim);
  padding: 4px 8px; border-radius: 99px;
}

.view { flex: 1; overflow: auto; padding: 22px 28px 60px; }
.boot { color: var(--muted); padding: 80px; text-align: center; }

h1.page { font-size: 28px; margin: 0 0 6px; font-weight: 600; letter-spacing: 0.08em; }
.lead { color: var(--muted); margin: 0 0 22px; font-size: 13px; }

.grid { display: grid; gap: 14px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; }
.stat, .card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 28px; margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--gold); }
.card h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; color: var(--ink); }
.card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
h3 { color: var(--gold); font-weight: 600; }
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted);
}
.chip.master, .lv-master { color: #f0c9b0; border-color: #8a4a3a; background: #3a241f; }
.chip.familiar, .lv-familiar { color: #e6d3a4; border-color: #8a6d42; background: #2e2618; }
.chip.know, .lv-know { color: #c5d4de; border-color: #4a5d6a; background: #1d272e; }
.card:hover { border-color: var(--gold-dim); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--gold); color: #1a140c; border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; font-size: 13px;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.read-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; align-items: start; }
.toc {
  position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.toc a {
  display: block; padding: 6px 8px; border-radius: 6px; color: #b9c2bb; font-size: 12px; line-height: 1.45;
}
.toc a.l3 { padding-left: 8px; color: var(--gold); font-weight: 600; margin-top: 8px; }
.toc a.l4 { padding-left: 16px; }
.toc a.active { background: var(--bg3); color: var(--paper); }
.toc .ch-pick { width: 100%; margin-bottom: 8px; background: var(--bg3); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }

.paper {
  background: var(--paper); color: var(--read); border-radius: 16px; padding: 36px 48px 64px;
  font-family: var(--serif); line-height: 1.95; font-size: 17.5px; box-shadow: var(--shadow);
  min-height: 70vh;
}
.paper h3 { font-size: 22px; margin: 1.4em 0 0.6em; letter-spacing: 0.04em; }
.paper h4 { font-size: 18px; margin: 1.3em 0 0.5em; }
.paper p { margin: 0.7em 0; text-align: justify; }
.paper .imgnote { text-align: center; color: #6b6254; font-size: 13px; font-family: var(--ui); }
.paper figure { margin: 18px auto; text-align: center; }
.paper figure img { cursor: zoom-in; border-radius: 6px; box-shadow: 0 8px 24px rgba(40,30,10,.15); }
.paper .lv { font-family: var(--ui); font-size: 12px; padding: 1px 6px; border-radius: 99px; margin-left: 4px; border: 1px solid; }
.paper .lv-master { color: #9a3b2c; border-color: #c9a39b; background: #f3e4de; }
.paper .lv-familiar { color: #8a6420; border-color: #d8c49a; background: #f4ead3; }
.paper .lv-know { color: #3d5a70; border-color: #b7c6d2; background: #e7eef3; }
.paper .btn { font-family: var(--ui); }
.paper .btn.ghost,
.q-widget .btn.ghost { color: var(--read); border-color: #d0c4aa; background: #fffdf6; }
.paper .row { color: #6b6254; }

.q-widget {
  background: #fffaf0; color: var(--read); border: 1px solid #e2d6bc; border-radius: 12px; padding: 14px 16px; margin: 16px 0;
  font-family: var(--ui); font-size: 14px; line-height: 1.7;
}
.q-widget .q-hd { color: #8a6d42; font-size: 12px; letter-spacing: 0.08em; margin-bottom: 6px; }
.q-opt { display: grid; gap: 6px; margin: 8px 0; }
.q-opt button, .opt {
  text-align: left; background: #fff; border: 1px solid #e5dcc8; border-radius: 8px; padding: 8px 10px; color: var(--read);
}
.q-opt button:hover, .opt:hover { border-color: var(--gold-dim); }
.opt.on { border-color: var(--gold); background: #f7efdc; }
.opt.right { border-color: var(--ok); background: #e7f5ee; }
.opt.wrong { border-color: var(--red); background: #fbecea; }
.explain { background: #f3eee2; border-left: 3px solid var(--gold); padding: 10px 12px; margin-top: 10px; color: #4a4336; font-size: 13px; }
.items { margin: 6px 0 10px; color: #4a4336; }

.practice, .exam-wrap { max-width: 860px; }
.q-stem { font-size: 18px; line-height: 1.7; margin: 8px 0 14px; }
.q-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.sheet {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin: 16px 0;
}
.sheet button {
  height: 32px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg3); color: var(--ink); font-size: 12px;
}
.sheet button.done { background: #31463c; border-color: #4c6d5c; }
.sheet button.cur { outline: 2px solid var(--gold); }
.sheet button.bad { background: #4a2a26; }
.sheet button.good { background: #244336; }

.timer { font-variant-numeric: tabular-nums; color: var(--gold); font-size: 20px; }
.timer.warn { color: var(--red); }

.result { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 24px; text-align: center; }
.result .score { font-size: 64px; color: var(--gold); margin: 8px 0; }

.flash {
  max-width: 720px; margin: 20px auto; min-height: 280px;
  background: var(--paper); color: var(--read); border-radius: 18px; padding: 36px;
  display: flex; flex-direction: column; justify-content: center; gap: 16px;
  box-shadow: var(--shadow); cursor: pointer;
}
.flash .lv-tag { font-family: var(--ui); font-size: 12px; }
.flash h2 { margin: 0; font-size: 26px; font-family: var(--serif); }
.flash .back { font-size: 16px; line-height: 1.8; color: #3c3528; white-space: pre-wrap; }

.search-list { display: grid; gap: 8px; }
.search-item {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer;
}
.search-item b { color: var(--gold); font-weight: 600; }
.search-item p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.notes { width: 100%; min-height: 120px; background: #fffdf6; border: 1px solid #e2d6bc; border-radius: 10px; padding: 10px; color: var(--read); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.space { height: 16px; }
.hidden, [hidden] { display: none !important; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); display: none; place-items: center; z-index: 50; padding: 24px;
}
.lightbox.is-open { display: grid; }
.lightbox img { max-width: 96vw; max-height: 94vh; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.show-side { grid-template-columns: 1fr; }
  .app.show-side .sidebar { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 20; }
  .read-layout { grid-template-columns: 1fr; }
  .toc { position: static; max-height: 240px; }
  .paper { padding: 22px 18px 40px; font-size: 16px; }
  .grid.stats { grid-template-columns: 1fr 1fr; }
  .search-mini { width: 140px; }
}
