/* ============ 名著典故通 · 新中式设计 ============ */
:root {
  --paper: #f6f1e5;
  --paper-2: #efe8d6;
  --card: #fffdf6;
  --ink: #2b2520;
  --ink-2: #6b6157;
  --ink-3: #9a8f80;
  --line: #e3d9c2;
  --sg: #a8322d;   /* 三国 · 朱砂 */
  --sh: #2d5f5a;   /* 水浒 · 黛青 */
  --xy: #b06f1e;   /* 西游 · 鎏金 */
  --hl: #8d4a68;   /* 红楼 · 绛紫 */
  --ok: #3e7d46;
  --ok-bg: #e8f2e6;
  --bad: #b03a2e;
  --bad-bg: #f8e9e4;
  --serif: "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --shadow: 0 2px 10px rgba(60, 45, 20, .08);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background: var(--paper);
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(176, 111, 30, .06), transparent);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.65;
}

/* ---------- 顶栏 ---------- */
.topbar {
  background: linear-gradient(180deg, #332c24 0%, #3d342a 100%);
  color: #f3ead6;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
}
.topbar-in { max-width: 760px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand h1 { font-family: var(--serif); font-size: 1.35rem; letter-spacing: .12em; font-weight: 700; }
.brand p { font-size: .72rem; opacity: .62; letter-spacing: .08em; margin-top: 2px; }
.progress-pill {
  background: rgba(243, 234, 214, .12);
  border: 1px solid rgba(243, 234, 214, .25);
  border-radius: 999px;
  padding: 6px 14px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.25;
  min-width: 92px;
}
.pp-num { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: #f0c95c; }
.pp-label { font-size: .66rem; opacity: .65; }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 40;
  display: flex;
  background: rgba(51, 44, 36, .96);
  backdrop-filter: blur(8px);
  padding: 0 8px calc(0px + env(safe-area-inset-bottom) / 4);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.tabs button {
  flex: 1;
  background: none; border: none; cursor: pointer;
  color: rgba(243, 234, 214, .55);
  font-family: var(--sans);
  font-size: .95rem;
  padding: 13px 4px;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.tabs button.active { color: #f0c95c; border-bottom-color: #f0c95c; font-weight: 600; }

/* ---------- 主区 ---------- */
main { max-width: 760px; margin: 0 auto; padding: 16px 14px 60px; }
.view-title { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; margin: 6px 0 14px; letter-spacing: .05em; }

/* ---------- 首页 · 书卡 ---------- */
.novel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.novel-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--c, var(--ink-3));
  border-radius: 12px;
  padding: 14px 14px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s;
}
.novel-card:active { transform: scale(.98); }
.nc-name { font-family: var(--serif); font-size: 1.12rem; font-weight: 700; color: var(--c); letter-spacing: .06em; }
.nc-meta { font-size: .72rem; color: var(--ink-3); margin: 2px 0 8px; }
.nc-count { font-size: .78rem; color: var(--ink-2); margin-bottom: 4px; }
.nc-count b { color: var(--c); font-size: .9rem; }
.bar { height: 7px; background: var(--paper-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c); border-radius: 99px; transition: width .4s; }

.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 6px; }
.recent { margin-top: 18px; }
.recent h3 { font-family: var(--serif); font-size: .95rem; color: var(--ink-2); margin-bottom: 8px; letter-spacing: .05em; }
.score-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 99px;
  font-size: .78rem; padding: 5px 12px; color: var(--ink-2);
}
.chip b { color: var(--ink); }
.chip.good b { color: var(--ok); }
.chip.mid b { color: #b06f1e; }
.chip.low b { color: var(--bad); }

/* ---------- 列表页 ---------- */
.list-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.list-head .view-title { margin: 0; flex: 1; color: var(--c, var(--ink)); }
.back-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: .85rem; color: var(--ink-2); cursor: pointer;
}
.entries { display: flex; flex-direction: column; gap: 8px; }
.entry-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 12px; cursor: pointer;
}
.entry-row:active { background: var(--paper-2); }
.er-main { flex: 1; min-width: 0; }
.er-name { font-family: var(--serif); font-size: 1.02rem; font-weight: 700; }
.er-sub { font-size: .74rem; color: var(--ink-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.er-stars { font-size: .68rem; color: #d9a441; letter-spacing: .05em; white-space: nowrap; }
.er-status {
  font-size: .68rem; border-radius: 6px; padding: 3px 7px; white-space: nowrap;
  background: var(--paper-2); color: var(--ink-3); border: 1px solid var(--line);
}
.er-status.st1 { background: #f5ecd8; color: #8a6d1f; border-color: #e8d9ab; }
.er-status.st2 {
  background: #f9efec; color: var(--bad); border-color: #e5b8ae;
  font-family: var(--serif); font-weight: 700;
}

/* ---------- 详情弹层 ---------- */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(30, 24, 16, .45);
  z-index: 90; opacity: 1; transition: opacity .2s;
}
.sheet-bg.hidden { display: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  max-height: 84vh; overflow-y: auto;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  animation: sheetUp .22s ease-out;
  -webkit-overflow-scrolling: touch;
}
@keyframes sheetUp { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet.hidden { display: none; }
.sh-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.sh-main { flex: 1; }
.sh-novel {
  display: inline-block; font-size: .7rem; color: #fff; background: var(--c);
  border-radius: 5px; padding: 2px 9px; letter-spacing: .1em; margin-bottom: 6px;
}
.sh-name { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; line-height: 1.3; }
.sh-close {
  background: var(--paper-2); border: none; width: 34px; height: 34px; border-radius: 50%;
  font-size: 1rem; color: var(--ink-2); cursor: pointer; flex-shrink: 0;
}
.sh-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.chip2 {
  background: var(--paper-2); border-radius: 99px; font-size: .76rem;
  padding: 3px 11px; color: var(--ink-2);
}
.sh-sec { margin-top: 14px; }
.sh-sec h4 {
  font-family: var(--serif); font-size: .88rem; color: var(--ink-3);
  letter-spacing: .18em; margin-bottom: 5px;
}
.sh-sec p { font-size: .96rem; line-height: 1.85; text-align: justify; }
.meaning-box {
  background: linear-gradient(180deg, #f8f1de, #f5ecd6);
  border-left: 4px solid var(--c);
  border-radius: 8px; padding: 10px 14px; font-size: .92rem; line-height: 1.75;
}
.points { list-style: none; }
.points li {
  font-size: .88rem; line-height: 1.7; color: var(--ink-2);
  padding: 6px 0 6px 22px; position: relative; border-bottom: 1px dashed var(--line);
}
.points li:last-child { border-bottom: none; }
.points li::before { content: "◆"; position: absolute; left: 2px; top: 7px; font-size: .62rem; color: var(--c); }
.sh-actions {
  display: flex; gap: 10px; margin-top: 18px;
  position: sticky; bottom: 0;
  background: var(--card);
  padding: 12px 0 4px;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 12px rgba(60, 45, 20, .06);
}

/* ---------- 按钮 ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-family: var(--sans); font-size: .98rem; font-weight: 500;
  border-radius: 11px; padding: 13px 16px; cursor: pointer; min-height: 46px;
  transition: transform .1s, background .15s;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: #3d342a; color: #f3ead6; border-color: #3d342a; font-weight: 600; }
.btn.accent { background: var(--c, #3d342a); color: #fff; border-color: var(--c, #3d342a); font-weight: 600; }
.btn.good { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 600; }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: .88rem; border-radius: 9px; }

/* ---------- 测验 ---------- */
.quiz-setup { display: flex; flex-direction: column; gap: 14px; }
.scope-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scope-opt {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 11px 6px; text-align: center; font-size: .88rem; cursor: pointer;
  color: var(--ink-2); min-height: 46px; display: flex; align-items: center; justify-content: center;
}
.scope-opt.sel { border-color: var(--c); color: var(--c); background: color-mix(in srgb, var(--c) 7%, var(--card)); font-weight: 700; }
.scope-opt.wide { grid-column: span 3; }

.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.qh-count { font-family: var(--serif); font-size: 1rem; font-weight: 700; }
.qh-count b { color: var(--c); font-size: 1.2rem; }
.qh-tag { font-size: .72rem; color: var(--ink-3); background: var(--paper-2); border-radius: 99px; padding: 3px 10px; }
.q-text {
  font-family: var(--serif); font-size: 1.18rem; font-weight: 700; line-height: 1.65;
  margin-bottom: 16px; min-height: 58px;
}
.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  text-align: left; font-family: var(--sans); font-size: .98rem;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 11px;
  padding: 13px 15px; cursor: pointer; min-height: 48px; color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.opt .ol {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--paper-2); color: var(--ink-2);
  font-size: .8rem; display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
}
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.correct .ol { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .ol { background: var(--bad); color: #fff; }
.opt.dim { opacity: .5; }
.opt:disabled { cursor: default; }
.explain-box {
  margin-top: 14px; border-radius: 10px; padding: 12px 14px; font-size: .88rem; line-height: 1.7;
  background: var(--paper-2); border: 1px dashed var(--line);
}
.explain-box b { color: var(--ok); }
.explain-box.bad b { color: var(--bad); }
.quiz-actions { display: flex; gap: 10px; margin-top: 16px; }

/* 成绩页 */
.quiz-result { text-align: center; padding-top: 8px; }
.score-ring { width: 130px; height: 130px; margin: 8px auto 6px; position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-val {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-val b { font-family: var(--serif); font-size: 2rem; }
.score-val span { font-size: .72rem; color: var(--ink-3); }
.res-comment { font-family: var(--serif); font-size: 1.05rem; color: var(--ink-2); margin-bottom: 16px; }
.res-list { text-align: left; display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.res-item {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: 10px; padding: 10px 13px; font-size: .86rem;
}
.res-item.bad { border-left-color: var(--bad); }
.res-item .rq { font-weight: 600; margin-bottom: 3px; line-height: 1.5; }
.res-item .ra { color: var(--ink-2); line-height: 1.6; }
.res-item .ra b { color: var(--ok); }
.res-item.bad .ra b { color: var(--bad); }

/* ---------- 翻卡 ---------- */
.fc-progress { text-align: center; font-size: .8rem; color: var(--ink-3); margin-bottom: 10px; }
.fc-stage { perspective: 1200px; margin-bottom: 14px; }
.card3d {
  position: relative; width: 100%; min-height: 300px;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.4, .1, .2, 1);
  cursor: pointer;
}
.card3d.flipped { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 22px; text-align: center;
}
.face.front { background: linear-gradient(160deg, var(--card), #f7efdb); box-shadow: var(--shadow); }
.face.back { background: linear-gradient(160deg, #fbf7ec, #f3ead4); transform: rotateY(180deg); box-shadow: var(--shadow); overflow-y: auto; justify-content: flex-start; }
.face .f-novel { font-size: .74rem; color: #fff; background: var(--c); border-radius: 99px; padding: 3px 13px; letter-spacing: .15em; margin-bottom: 14px; }
.face .f-name { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; letter-spacing: .08em; }
.face .f-hint { margin-top: 18px; font-size: .74rem; color: var(--ink-3); letter-spacing: .1em; }
.face.back .f-name { font-size: 1.25rem; margin-bottom: 8px; }
.face.back .f-story { font-size: .9rem; line-height: 1.85; color: var(--ink); text-align: justify; margin-top: 6px; }
.face.back .f-mean { font-size: .84rem; color: var(--ink-2); margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.fc-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 错题本 ---------- */
.wrong-item {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--bad);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 9px; font-size: .9rem;
}
.wrong-item .wq { font-weight: 600; line-height: 1.55; margin-bottom: 5px; }
.wrong-item .wa { color: var(--ink-2); font-size: .84rem; line-height: 1.65; }
.wrong-item .wa b { color: var(--ok); }
.wrong-item .wc { margin-top: 5px; font-size: .74rem; color: var(--ink-3); }
.empty {
  text-align: center; color: var(--ink-3); padding: 46px 20px; font-size: .9rem;
}
.empty .big { font-size: 2.2rem; margin-bottom: 10px; }

/* ---------- 页脚 ---------- */
.foot { text-align: center; font-size: .7rem; color: var(--ink-3); padding: 18px 16px 30px; letter-spacing: .05em; }

/* ---------- 桌面端 ---------- */
@media (min-width: 720px) {
  .novel-grid { grid-template-columns: repeat(4, 1fr); }
  .home-actions { grid-template-columns: repeat(2, 1fr); }
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: 640px; max-width: 92vw; max-height: 82vh;
    border-radius: 16px;
    animation: sheetPop .18s ease-out;
  }
  @keyframes sheetPop { from { transform: translate(-50%, -46%) scale(.97); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
  .q-text { font-size: 1.28rem; }
  main { padding-top: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
