@font-face {
  font-family: "ZZ Serif";
  src: url("fonts/NotoSerifSC-subset.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --fs: 18px;
  --serif: "ZZ Serif", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "Songti SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --paper: #f5f1e8;
  --page: #fffdf8;
  --ink: #1d1b18;
  --ink2: #4a4640;
  --muted: #8a847a;
  --rule: #e4ddcf;
  --rule2: #d6cdbb;
  --accent: #9e2a2b;
  --accent-soft: #f4e6e2;
  --ok: #2d6a4f;
  --ok-soft: #e5efe8;
  --bad: #b23a30;
  --bad-soft: #f8e4df;
  --pick: #2f4f8a;
  --pick-soft: #e6ebf5;
  --bar-h: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15140f; --page: #1d1c17; --ink: #e8e3d8; --ink2: #c9c3b6; --muted: #8f897d;
    --rule: #34312a; --rule2: #48443a; --accent: #e58a7d; --accent-soft: #3a2722;
    --ok: #7cc49b; --ok-soft: #1f3128; --bad: #f08a7c; --bad-soft: #3d241f;
    --pick: #9bb4e6; --pick-soft: #232d40; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #15140f; --page: #1d1c17; --ink: #e8e3d8; --ink2: #c9c3b6; --muted: #8f897d;
  --rule: #34312a; --rule2: #48443a; --accent: #e58a7d; --accent-soft: #3a2722;
  --ok: #7cc49b; --ok-soft: #1f3128; --bad: #f08a7c; --bad-soft: #3d241f;
  --pick: #9bb4e6; --pick-soft: #232d40; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: var(--fs); line-height: 1.85;
  --track: 0;
  font-kerning: normal;
  text-autospace: normal;          /* 中文与数字、字母之间自动留 1/8 字空 */
  text-spacing-trim: trim-start;   /* 相邻标点挤压、行首标点半宽 */
  hanging-punctuation: allow-end;  /* 行尾标点悬挂（Safari） */
  line-break: normal;              /* 避头尾（标准强度，避免整行被拉散） */
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* ---------- 顶栏（界面元素用黑体） ---------- */
.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--page) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
.brand { font-family: var(--serif); font-weight: 700; color: var(--ink); white-space: nowrap; font-size: 1.02rem; letter-spacing: .04em; }
.topnav { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.topnav a, .topnav .icon {
  min-height: 36px; display: inline-flex; align-items: center;
  padding: 0 11px; border-radius: 8px; color: var(--ink2); font-size: .9rem;
  border: 0; background: none;
}
.topnav a.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.topnav .icon { font-family: var(--serif); font-weight: 700; }
.badge[hidden] { display: none; }
.badge { display: inline-block; min-width: 1.5em; padding: 0 .4em; margin-left: 4px; border-radius: 99px;
  background: var(--accent); color: #fff; font-size: .7rem; line-height: 1.55; text-align: center; font-weight: 600; }

.settings {
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 29;
  background: var(--page); border-bottom: 1px solid var(--rule);
  padding: 10px max(16px, env(safe-area-inset-left)); font-family: var(--sans); font-size: .88rem;
  box-shadow: 0 8px 20px rgba(0,0,0,.06);
}
.settings .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.settings .row > span:first-child { width: 3em; color: var(--muted); }
.settings button { min-height: 34px; padding: 0 12px; border: 1px solid var(--rule2); background: var(--paper); border-radius: 8px; }
.settings button.on { border-color: var(--accent); color: var(--accent); }
.settings .danger { color: var(--bad); }
.hint { color: var(--muted); font-size: .8rem; margin: 6px 0 0; line-height: 1.6; }

main { max-width: 760px; margin: 0 auto; padding: 22px 18px 48px; }
.foot { max-width: 760px; margin: 0 auto; padding: 0 18px 40px; color: var(--muted); font-size: .75rem; font-family: var(--sans); line-height: 1.6; }

h1 { font-size: 1.5em; font-weight: 700; margin: .1em 0 .5em; letter-spacing: .08em; line-height: 1.4; }
.sub { color: var(--muted); font-size: .82rem; font-family: var(--sans); margin: -.3em 0 1.1em; line-height: 1.7; }

/* ---------- 首页 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 22px; }
.stat { background: var(--page); border-radius: 10px; padding: 12px 14px; border: 1px solid var(--rule); }
.stat b { display: block; font-size: 1.5em; line-height: 1.25; font-weight: 700; }
.stat span { color: var(--muted); font-size: .76rem; font-family: var(--sans); }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.year {
  display: block; background: var(--page); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px;
  color: var(--ink); transition: border-color .15s;
}
.year .y { font-weight: 700; font-size: 1.25em; letter-spacing: .04em; }
.year .meta { color: var(--muted); font-size: .74rem; font-family: var(--sans); }
.bar { height: 4px; background: var(--rule); border-radius: 99px; overflow: hidden; margin-top: 10px; display: flex; }
.bar i { display: block; height: 100%; }
.bar .g { background: var(--ok); } .bar .r { background: var(--bad); }

/* ---------- 工具条 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 16px; font-family: var(--sans); }
.seg { display: inline-flex; border: 1px solid var(--rule2); border-radius: 9px; overflow: hidden; background: var(--page); }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 14px; font-size: .85rem; color: var(--ink2); }
.seg button.on { background: var(--ink); color: var(--page); }
.btn { min-height: 34px; border: 1px solid var(--rule2); background: var(--page); border-radius: 9px; padding: 0 14px; font-size: .85rem; font-family: var(--sans); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .4; cursor: default; }
.spacer { flex: 1; }
.score { font-size: .8rem; color: var(--muted); font-family: var(--sans); }
.score b { color: var(--ink); }

.secttl {
  margin: 30px 0 14px; font-size: 1.02em; font-weight: 700; letter-spacing: .08em; color: var(--ink);
  display: flex; align-items: center; gap: 12px;
}
.secttl::after { content: ""; flex: 1; height: 1px; background: var(--rule2); }

/* ---------- 题卡：像试卷一样的版面 ---------- */
.q {
  background: var(--page); border: 1px solid var(--rule); border-radius: 12px;
  padding: 18px 20px 14px; margin-bottom: 16px; scroll-margin-top: 70px;
}
.qhead { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .74rem; font-family: var(--sans); margin-bottom: 6px; min-height: 22px; }
.tag { padding: 0 7px; border-radius: 4px; border: 1px solid var(--rule2); line-height: 1.7; }
.tag.multi { color: var(--pick); border-color: color-mix(in srgb, var(--pick) 40%, transparent); }
.qhead .res { margin-left: auto; font-weight: 600; }
.qhead .res.ok { color: var(--ok); } .qhead .res.bad { color: var(--bad); }

.stem { text-align: justify; text-justify: inter-ideograph; letter-spacing: var(--track); line-height: 1.85; text-wrap: pretty; }
.stem p { margin: 0 0 .35em; }
.stem p:last-child { margin-bottom: 0; }
.stem .qn { font-weight: 700; margin-right: .3em; letter-spacing: 0; font-variant-numeric: tabular-nums; }

.opts { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; min-height: 48px;
  padding: 10px 14px; border: 1px solid var(--rule2); border-radius: 10px;
  background: transparent; text-align: left; line-height: 1.65; font-family: var(--serif);
  transition: background-color .12s, border-color .12s;
}
.opt > span:last-child { flex: 1; text-align: left; letter-spacing: var(--track); padding-top: .06em; text-wrap: pretty; }
.opt .L {
  flex: none; width: 1.75em; height: 1.75em; margin-top: .12em; border-radius: 50%;
  display: grid; place-items: center; border: 1px solid var(--rule2);
  font-family: var(--sans); font-size: .8em; font-weight: 600; color: var(--ink2);
}
.opt:active { background: var(--pick-soft); }
.opt.pick { border-color: var(--pick); background: var(--pick-soft); }
.opt.pick .L { background: var(--pick); color: #fff; border-color: var(--pick); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .L { background: var(--ok); color: #fff; border-color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .L { background: var(--bad); color: #fff; border-color: var(--bad); }
.opt.miss { border-style: dashed; background: transparent; }
.locked .opt { cursor: default; }
.locked .opt:active { background: inherit; }
@media (hover: hover) {
  .opt:hover { border-color: var(--pick); }
  .locked .opt:hover:not(.right):not(.wrong):not(.pick) { border-color: var(--rule2); }
  .year:hover { border-color: var(--accent); }
}

.qfoot { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 12px; font-family: var(--sans); }
.ansline { font-size: .86rem; color: var(--ink2); }
.ansline b { color: var(--ok); letter-spacing: .12em; font-size: 1.05em; }
.link, .star { border: 0; background: none; min-height: 34px; padding: 0 2px; font-size: .84rem; }
.link { color: var(--accent); }
.star { color: var(--muted); }
.star.on { color: #b8860b; }

.ana {
  margin-top: 12px; padding: 14px 16px; border-radius: 10px; background: var(--paper);
  border-left: 3px solid var(--accent);
  font-size: .94em; line-height: 1.85; text-align: justify; text-justify: inter-ideograph; letter-spacing: 0; text-wrap: pretty; color: var(--ink2);
}
.ana p { margin: 0 0 .6em; text-indent: 2em; }
.ana p:last-child { margin-bottom: 0; }
.ana p:has(> .lbl) { text-indent: 0; }
.ana .lbl {
  display: inline-block; margin-right: .45em; padding: 0 .5em; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent); font-family: var(--sans); font-size: .78em; font-weight: 700;
  line-height: 1.8; vertical-align: .08em;
}
.note { color: var(--muted); font-size: .76rem; margin-top: 8px; font-family: var(--sans); text-indent: 0; }
.q img { max-width: 100%; height: auto; border-radius: 6px; }
.q div[style*="text-align"] { margin: 8px 0; text-align: center; }
.q table { border-collapse: collapse; font-size: .85em; margin: 8px 0; max-width: 100%; display: block; overflow-x: auto; }
.q td, .q th { border: 1px solid var(--rule2); padding: 2px 8px; }

/* ---------- 逐题模式 ---------- */
.dots { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; font-family: var(--sans); }
.dots a { width: 2.3em; height: 2.3em; display: grid; place-items: center; border-radius: 8px; font-size: .74rem;
  border: 1px solid var(--rule2); background: var(--page); color: var(--ink2); }
.dots a.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.dots a.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.dots a.cur { outline: 2px solid var(--ink); outline-offset: 1px; color: var(--ink); font-weight: 700; }
.dots .gap { width: 100%; height: 0; }
.dots.fold { max-height: calc(2.3em * 2 + 6px); overflow: hidden; position: relative; }
.dotsbtn { margin: -8px 0 14px; }

.pager { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-top: 6px; font-family: var(--sans); }
.pager .btn { min-height: 42px; padding: 0 18px; }

/* 手机：底部固定操作栏 */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: none;
  gap: 10px; align-items: center; justify-content: space-between;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--page) 94%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--rule); font-family: var(--sans);
}
.dock .btn { min-height: 44px; flex: 1; font-size: .92rem; border-radius: 11px; }
.dock .btn.mid { flex: 1.3; }
.dock .pos { font-size: .78rem; color: var(--muted); min-width: 3.6em; text-align: center; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; font-family: var(--sans); }
.form { background: var(--page); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; display: grid; gap: 12px; font-size: .88rem; font-family: var(--sans); }
.form label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form select, .form input { min-height: 36px; padding: 0 8px; border: 1px solid var(--rule2); border-radius: 8px; background: var(--paper); color: var(--ink); }
.form .btn { min-height: 42px; }

.swipe-l { animation: inL .18s ease-out; } .swipe-r { animation: inR .18s ease-out; }
@keyframes inL { from { opacity: .3; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes inR { from { opacity: .3; transform: translateX(-24px); } to { opacity: 1; transform: none; } }

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  :root { --fs: 17px; }
  .top { gap: 6px; }
  .brand { font-size: .95rem; letter-spacing: .02em; }
  .brand .long { display: none; }
  .topnav a, .topnav .icon { padding: 0 9px; min-height: 38px; }
  main { padding: 14px 8px 32px; }
  h1 { font-size: 1.3em; }
  .q { padding: 14px 12px 10px; border-radius: 10px; margin-bottom: 10px; }
  .opt { padding: 9px 10px; gap: 9px; }
  .ana { padding: 11px 10px 11px 11px; margin-left: -4px; margin-right: -4px; }
  .stats { gap: 8px; }
  .stat { padding: 10px; }
  .stat b { font-size: 1.3em; }
  .years { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .year { padding: 8px 10px; }
  .year .meta { line-height: 1.4; }
  .bar { margin-top: 6px; }
  .year .y { font-size: 1.1em; }
  .toolbar { gap: 6px; }
  .toolbar .score { width: 100%; order: 9; }
  body.has-dock { --bar-h: 62px; }
  body.has-dock .dock { display: flex; }
  body.has-dock .pager { display: none; }
  .foot { padding-bottom: 24px; }
}
@media (max-width: 360px) {
  :root { --fs: 16px; }
  .years { grid-template-columns: repeat(2, 1fr); }
}
.stem img { width: auto !important; max-width: min(100%, 340px); max-height: 360px; display: block; margin: 8px auto; }
@media (max-width: 640px) {
  .stem { line-height: 1.8; }
  .ana { line-height: 1.8; }
}

/* ---------- 搜索 ---------- */
.searchbox { position: relative; margin: 0 0 12px; }
.searchbox input {
  width: 100%; min-height: 46px; padding: 0 44px 0 14px; font-size: 16px; font-family: var(--sans);
  border: 1px solid var(--rule2); border-radius: 12px; background: var(--page); color: var(--ink);
  -webkit-appearance: none; appearance: none; outline: none;
}
.searchbox input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.searchbox input::-webkit-search-cancel-button { display: none; }
.sclear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 22px; line-height: 1; }
.sfilter { margin-bottom: 6px; }
#sres .sub b { color: var(--ink); }
mark { background: #f6e3a1; color: inherit; border-radius: 2px; padding: 0 .05em; }
:root[data-theme="dark"] mark { background: #6b5517; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark { background: #6b5517; } }
.more { text-align: center; margin: 6px 0 20px; }
.more .btn { min-height: 42px; }
@media (max-width: 640px) {
  .topnav a, .topnav .icon { padding: 0 7px; }
}
@media (max-width: 360px) {
  .brand { font-size: .88rem; }
  .topnav a, .topnav .icon { padding: 0 5px; font-size: .84rem; }
}
