:root {
    --sp-radius: 12px;
    --sp-pill: 999px;
    --sp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  }
  /* ---------- 主题变量：accent 为界面主色，ok/bad 为对错语义色 ---------- */
  html:root[data-theme="dark"] {
    --sp-bg: #121212;
    --sp-surface: #181818;
    --sp-surface-2: #232323;
    --sp-surface-hover: #2a2a2a;
    --sp-border: #2e2e2e;
    --sp-text: #ffffff;
    --sp-muted: #b3b3b3;

    --sp-accent: #1db954;
    --sp-accent-hover: #1ed760;
    --sp-accent-tint: rgba(29, 185, 84, .14);
    --sp-on-accent: #000;

    --sp-ok: #1db954;
    --sp-ok-text: #1ed760;
    --sp-ok-tint: rgba(29, 185, 84, .14);
    --sp-on-ok: #000;

    --sp-bad: #e91429;
    --sp-bad-soft: #ff5c6e;
    --sp-bad-tint: rgba(233, 20, 41, .14);

    --sp-amber: #ffd66b;
    --sp-amber-tint: rgba(255, 214, 107, .14);
    --sp-mid: #f0a441;

    --sp-elev: #3d3d3d;
    --sp-badge-border: #3d3d3d;
    --sp-track: #3d3d3d;
    --sp-ring-track: #2f2f2f;
    --sp-hair: #333;
    --sp-soft-text: #d9d9d9;
    --sp-faint: #6a6a6a;
    --sp-ghost-border: #535353;
    --sp-ghost-hover: #fff;
    --sp-danger-border: #5a2a30;
    --sp-seg-on-bg: #fff;
    --sp-seg-on-text: #000;
    --sp-modal-bg: #282828;
    --sp-modal-border: #3d3d3d;
    --sp-modal-shadow: none;
    --sp-input-bg: #1d1d1d;
    --sp-input-border: #3f3f3f;
    --sp-backdrop: rgba(0, 0, 0, .68);
    --sp-toast-bg: #fff;
    --sp-toast-text: #000;
    --sp-toast-shadow: 0 8px 28px rgba(0, 0, 0, .5);

    /* Pico 变量覆盖 */
    --pico-background-color: var(--sp-bg);
    --pico-color: var(--sp-text);
    --pico-muted-color: var(--sp-muted);
    --pico-border-color: var(--sp-border);
    --pico-border-radius: 10px;
    --pico-font-family: var(--sp-font);
    --pico-form-element-background-color: var(--sp-surface-2);
    --pico-form-element-border-color: #3f3f3f;
    --pico-form-element-color: var(--sp-text);
    --pico-form-element-placeholder-color: #8f8f8f;
    --pico-form-element-active-border-color: #fff;
    --pico-form-element-focus-color: rgba(29, 185, 84, .25);
    --pico-primary: var(--sp-accent-hover);
    --pico-primary-background: var(--sp-accent);
    --pico-primary-inverse: #000;
    --pico-primary-hover: var(--sp-accent-hover);
    --pico-primary-hover-background: var(--sp-accent-hover);
    --pico-primary-focus: rgba(29, 185, 84, .3);
  }

  /* ---------- Outlook / Fluent 风格浅色主题（办公环境） ---------- */
  html:root[data-theme="light"] {
    --sp-bg: #f3f2f1;
    --sp-surface: #ffffff;
    --sp-surface-2: #f3f2f1;
    --sp-surface-hover: #edebe9;
    --sp-border: #e1dfdd;
    --sp-text: #201f1e;
    --sp-muted: #605e5c;

    --sp-accent: #0f6cbd;
    --sp-accent-hover: #115ea3;
    --sp-accent-tint: rgba(15, 108, 189, .1);
    --sp-on-accent: #fff;

    --sp-ok: #107c10;
    --sp-ok-text: #107c10;
    --sp-ok-tint: rgba(16, 124, 16, .09);
    --sp-on-ok: #fff;

    --sp-bad: #d13438;
    --sp-bad-soft: #a4262c;
    --sp-bad-tint: rgba(209, 52, 56, .09);

    --sp-amber: #986f0b;
    --sp-amber-tint: rgba(152, 111, 11, .12);
    --sp-mid: #986f0b;

    --sp-elev: #edebe9;
    --sp-badge-border: #c8c6c4;
    --sp-track: #d2d0ce;
    --sp-ring-track: #e1dfdd;
    --sp-hair: #e1dfdd;
    --sp-soft-text: #323130;
    --sp-faint: #8a8886;
    --sp-ghost-border: #c8c6c4;
    --sp-ghost-hover: #201f1e;
    --sp-danger-border: #e3b6b8;
    --sp-seg-on-bg: #201f1e;
    --sp-seg-on-text: #fff;
    --sp-modal-bg: #ffffff;
    --sp-modal-border: #e1dfdd;
    --sp-modal-shadow: 0 12px 40px rgba(0, 0, 0, .16);
    --sp-input-bg: #ffffff;
    --sp-input-border: #c8c6c4;
    --sp-backdrop: rgba(0, 0, 0, .32);
    --sp-toast-bg: #201f1e;
    --sp-toast-text: #fff;
    --sp-toast-shadow: 0 8px 24px rgba(0, 0, 0, .22);

    /* Pico 变量覆盖 */
    --pico-background-color: var(--sp-bg);
    --pico-color: var(--sp-text);
    --pico-muted-color: var(--sp-muted);
    --pico-border-color: var(--sp-border);
    --pico-border-radius: 10px;
    --pico-font-family: var(--sp-font);
    --pico-form-element-background-color: #fff;
    --pico-form-element-border-color: #c8c6c4;
    --pico-form-element-color: var(--sp-text);
    --pico-form-element-placeholder-color: #8a8886;
    --pico-form-element-active-border-color: #201f1e;
    --pico-form-element-focus-color: rgba(15, 108, 189, .25);
    --pico-primary: #fff;
    --pico-primary-background: var(--sp-accent);
    --pico-primary-inverse: #fff;
    --pico-primary-hover: #fff;
    --pico-primary-hover-background: var(--sp-accent-hover);
    --pico-primary-focus: rgba(15, 108, 189, .3);
  }

  html[data-theme="dark"] { color-scheme: dark; }
  html[data-theme="light"] { color-scheme: light; }

  body { background: var(--sp-bg); font-family: var(--sp-font); padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
  .container { max-width: 760px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
  main.container { padding-top: max(.8rem, env(safe-area-inset-top)); }
  h1, h2, h3, h4, h5, h6 { letter-spacing: -.01em; }
  .hidden { display: none !important; }

  /* ---------- 图标 ---------- */
  .icon { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.22em; flex: none; }

  /* ---------- 视图切换 ---------- */
  .view { display: none; }
  .view.active { display: block; }

  /* ---------- 按钮 ---------- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    border: 1px solid transparent; border-radius: var(--sp-pill);
    padding: .55rem 1.4rem; font-size: .95rem; font-weight: 700; line-height: 1.3;
    cursor: pointer; background: var(--sp-surface-2); color: var(--sp-text);
    transition: transform .06s ease, background .15s ease, border-color .15s ease, color .15s ease;
    user-select: none; text-decoration: none;
  }
  .btn:active { transform: scale(.97); }
  .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
  .btn-primary { background: var(--sp-accent); color: var(--sp-on-accent); }
  .btn-primary:hover:not(:disabled) { background: var(--sp-accent-hover); color: var(--sp-on-accent); }
  .btn-ghost { background: transparent; border-color: var(--sp-ghost-border); color: var(--sp-text); }
  .btn-ghost:hover:not(:disabled) { border-color: var(--sp-ghost-hover); }
  .btn-ghost-danger { background: transparent; border-color: var(--sp-danger-border); color: var(--sp-bad-soft); }
  .btn-ghost-danger:hover:not(:disabled) { border-color: var(--sp-bad-soft); }
  .btn-icon { padding: .38rem .55rem; }
  .btn-icon .icon { width: 1.1em; height: 1.1em; }
  .btn-lg { padding: .8rem 1.6rem; font-size: 1.05rem; }
  .btn-sm { padding: .35rem 1rem; font-size: .85rem; }
  .btn-block { width: 100%; }

  /* ---------- 卡片 ---------- */
  .card { background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius); padding: 1.25rem; }
  .card-title { display: flex; align-items: center; gap: .55rem; font-size: 1.05rem; font-weight: 800; margin-bottom: 1rem; }
  .card-title .icon { color: var(--sp-accent-hover); }

  .seg-group { display: flex; flex-wrap: wrap; gap: .5rem; }
  .seg {
    display: inline-flex; align-items: center; justify-content: center; height: 2.45rem;
    border: none; border-radius: var(--sp-pill); cursor: pointer;
    background: var(--sp-surface-2); color: var(--sp-text); font-weight: 700; font-size: .9rem;
    padding: 0 1.15rem; transition: background .15s, color .15s, transform .06s;
  }
  .seg:active { transform: scale(.96); }
  .seg.active { background: var(--sp-seg-on-bg); color: var(--sp-seg-on-text); }
  .count-input-wrap {
    display: inline-flex; align-items: center; gap: .3rem; height: 2.45rem;
    background: var(--sp-surface-2); border-radius: var(--sp-pill);
    padding: 0 .85rem 0 1rem; transition: box-shadow .15s;
  }
  .count-input-wrap:focus-within { box-shadow: inset 0 0 0 2px var(--sp-accent); }
  .count-input-wrap.on { background: var(--sp-seg-on-bg); }
  .count-input-wrap.on input[type="number"], .count-input-wrap.on span { color: var(--sp-seg-on-text); }
  .count-input-wrap input[type="number"] {
    width: 3.2rem; margin: 0; border: none; background: transparent; color: var(--sp-text);
    font-weight: 700; font-size: .9rem; text-align: center; padding: .3rem 0;
    appearance: textfield; -moz-appearance: textfield;
    --pico-form-element-background-color: transparent; --pico-form-element-border-color: transparent;
  }
  .count-input-wrap input[type="number"]::-webkit-outer-spin-button,
  .count-input-wrap input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .count-input-wrap input[type="number"]:focus { box-shadow: none; }
  .count-input-wrap span { color: var(--sp-muted); font-size: .85rem; }

  /* ---------- 统计页 ---------- */
  .page-head { display: flex; align-items: center; gap: .55rem; margin-bottom: 1rem; }
  .page-head .page-title { font-size: 1.12rem; font-weight: 800; }
  .back-btn {
    flex: none; width: 1.9rem; height: 1.9rem; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--sp-ghost-border); border-radius: 50%;
    background: transparent; color: var(--sp-muted); cursor: pointer; line-height: 0;
    transition: color .15s, border-color .15s;
  }
  .back-btn:hover { color: var(--sp-text); border-color: var(--sp-ghost-hover); }
  .back-btn .icon { width: .95em; height: .95em; }
  .stats-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-bottom: 1rem; }
  .stat-tile { background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius); padding: .8rem .9rem; }
  .stat-value { font-size: 1.22rem; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
  .stat-label { color: var(--sp-muted); font-size: .74rem; margin-top: .15rem; }
  .s-row { margin-bottom: .95rem; }
  .s-row:last-child { margin-bottom: 0; }
  .s-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; margin-bottom: .3rem; }
  .s-row-name { font-weight: 700; font-size: .88rem; }
  .s-row-meta { color: var(--sp-muted); font-size: .78rem; font-variant-numeric: tabular-nums; flex: none; }
  .s-row-bar { height: 6px; border-radius: 3px; background: var(--sp-track); overflow: hidden; }
  .s-row-bar i { display: block; height: 100%; width: 0; border-radius: 3px; }
  .s-row-sub { margin-top: .28rem; text-align: right; color: var(--sp-faint); font-size: .74rem; font-variant-numeric: tabular-nums; }
  .stats-note { margin-top: .95rem; padding-top: .85rem; border-top: 1px solid var(--sp-hair); color: var(--sp-faint); font-size: .78rem; line-height: 1.6; }
  .stats-empty { color: var(--sp-muted); font-size: .86rem; text-align: center; padding: .6rem 0; }

  /* ---------- 章节选择 ---------- */
  .chapter-list { max-height: min(58vh, 500px); overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; }
  .chapter-item {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    width: 100%; text-align: left; cursor: pointer;
    background: var(--sp-surface-2); border: 1px solid transparent; border-radius: var(--sp-radius);
    padding: .68rem .95rem; color: var(--sp-text); font-family: inherit;
    transition: background .15s, border-color .15s, transform .06s;
  }
  .chapter-item:hover { background: var(--sp-surface-hover); }
  .chapter-item:active { transform: scale(.99); }
  .chapter-name { font-weight: 700; font-size: .92rem; }
  .chapter-sub { color: var(--sp-muted); font-size: .75rem; margin-top: .12rem; }
  .chapter-count { flex: none; color: var(--sp-muted); font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }

  .sync-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
  .sync-row .sync-sub { color: var(--sp-muted); font-size: .82rem; margin-top: .2rem; }
  .sync-btns { display: flex; gap: .5rem; }

  /* ---------- 搜索 ---------- */
  /* 弹窗整体限高（dvh 优先，兼容旧浏览器回落 vh），内部只有结果列表滚动，
     小屏或软键盘弹出时高度稳定，头部的输入框和底部按钮始终可见 */
  #modal-search[open] { display: flex; max-height: 86vh; max-height: 86dvh; }
  #modal-search .modal-inner { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
  #modal-search .modal-head, #modal-search .modal-desc, #modal-search .search-meta { flex: none; }
  #search-input { flex: none; margin: 0 0 .8rem; font-size: 1rem; } /* 1rem 防止 iOS 聚焦缩放 */
  .search-meta { color: var(--sp-muted); font-size: .78rem; margin-bottom: .7rem; }
  .search-results {
    flex: 0 1 auto; min-height: 0;
    max-height: min(44vh, 420px); max-height: min(44dvh, 420px); /* 显式限高，不依赖 flex 收缩链 */
    overflow-y: auto; overscroll-behavior: contain; /* 列表滚动不穿透到页面 */
    display: flex; flex-direction: column; gap: .5rem; padding-right: .15rem;
  }
  #modal-search .modal-actions { flex: none; flex-wrap: wrap; }
  #modal-search .modal-actions .btn { flex: 1; }
  .search-item {
    display: block; width: 100%; text-align: left; cursor: pointer;
    background: var(--sp-surface-2); border: 1px solid transparent; border-radius: var(--sp-radius);
    padding: .68rem .95rem; color: var(--sp-text); font-family: inherit;
    transition: background .15s, border-color .15s;
  }
  .search-item:hover { background: var(--sp-surface-hover); }
  .search-item-text {
    font-size: .88rem; line-height: 1.6; color: var(--sp-soft-text);
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  .search-item-text mark { background: var(--sp-accent-tint); color: var(--sp-accent-hover); border-radius: 3px; padding: 0 .1em; font-weight: 800; }
  .search-item-sub { color: var(--sp-muted); font-size: .75rem; margin-top: .3rem; }
  .search-more { text-align: center; color: var(--sp-faint); font-size: .78rem; padding: .45rem 0 .2rem; }

  /* ---------- 答题页 ---------- */
  /* 顶部只保留：进度（题号 + 进度条）、用时（本题/考试倒计时）、收藏与标记 */
  .quiz-head { margin-bottom: .8rem; }
  .quiz-head-row { display: flex; align-items: center; gap: .6rem; }
  .quiz-counter { flex: none; color: var(--sp-text); font-size: .95rem; font-weight: 800; font-variant-numeric: tabular-nums; }
  .quiz-progress-line { flex: 1 1 4.5rem; min-width: 3.5rem; height: 5px; border-radius: 3px; background: var(--sp-track); overflow: hidden; }
  .quiz-progress-line i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--sp-accent); transition: width .35s cubic-bezier(.2, .8, .2, 1); }
  /* 本题用时：药丸样式；超过真实考试节奏（80 秒/题）转琥珀提示 */
  .q-timer {
    flex: none; display: inline-flex; align-items: center; gap: .4rem;
    background: var(--sp-elev); color: var(--sp-text);
    border-radius: var(--sp-pill); padding: .3rem .8rem;
    font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums;
    transition: background .25s, color .25s;
  }
  .q-timer .icon { width: 1.05em; height: 1.05em; }
  .q-timer.over { background: var(--sp-amber-tint); color: var(--sp-amber); }
  .star-btn, .flag-btn { flex: none; background: none; border: none; cursor: pointer; color: var(--sp-faint); padding: .3rem; border-radius: 50%; line-height: 0; transition: color .15s; }
  .star-btn:hover, .flag-btn:hover { color: var(--sp-amber); }
  .star-btn.on, .flag-btn.on { color: var(--sp-amber); }
  .star-btn.on .icon, .flag-btn.on .icon { fill: currentColor; }
  .star-btn .icon, .flag-btn .icon { width: 1.45em; height: 1.45em; }

  .q-head { display: flex; align-items: center; margin-bottom: .9rem; }
  .q-head:empty { display: none; }
  .type-badge { background: var(--sp-elev); color: var(--sp-text); border-radius: var(--sp-pill); font-size: .78rem; font-weight: 700; padding: .25rem .8rem; }
  .type-badge.sub { background: transparent; border: 1px solid var(--sp-badge-border); color: var(--sp-muted); }

  .q-text { font-size: 1.06rem; font-weight: 650; line-height: 1.75; color: var(--sp-text); white-space: pre-wrap; margin-bottom: 1.1rem; }
  .q-text-en { margin-top: .55rem; color: var(--sp-muted); font-size: .92rem; font-weight: 500; line-height: 1.65; white-space: pre-wrap; }

  .opt {
    display: flex; align-items: flex-start; gap: .75rem; width: 100%;
    background: var(--sp-surface-2); border: 1.5px solid transparent; border-radius: 10px;
    padding: .8rem .95rem; margin-bottom: .6rem; cursor: pointer; color: var(--sp-text); text-align: left;
    font-family: inherit; font-size: .95rem; line-height: 1.55;
    transition: background .15s, border-color .15s, transform .06s;
  }
  .opt:hover { background: var(--sp-surface-hover); }
  .opt:active { transform: scale(.99); }
  .opt .opt-letter {
    flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 800; background: var(--sp-elev); color: var(--sp-text); transition: background .15s, color .15s;
  }
  .opt .opt-text { padding-top: .12rem; }
  .opt .opt-text .opt-en { display: block; margin-top: .3rem; color: var(--sp-muted); font-size: .86rem; font-weight: 500; line-height: 1.5; }
  .opt .opt-state { margin-left: auto; align-self: center; }
  .opt.selected { border-color: var(--sp-accent); background: var(--sp-accent-tint); }
  .opt.selected .opt-letter { background: var(--sp-accent); color: var(--sp-on-accent); }
  .opt.locked { cursor: default; }
  .opt.locked:hover { background: var(--sp-surface-2); }
  .opt.correct { border-color: var(--sp-ok); background: var(--sp-ok-tint); }
  .opt.correct .opt-letter { background: var(--sp-ok); color: var(--sp-on-ok); }
  .opt.correct .opt-state { color: var(--sp-ok-text); }
  .opt.wrongpick { border-color: var(--sp-bad); background: var(--sp-bad-tint); }
  .opt.wrongpick .opt-letter { background: var(--sp-bad); color: #fff; }
  .opt.wrongpick .opt-state { color: var(--sp-bad-soft); }
  .opt .opt-state .icon { width: 1.35em; height: 1.35em; }

  .analysis {
    background: var(--sp-surface-2); border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius); margin-top: 1rem; overflow: hidden;
  }
  /* 判定横幅：答对/答错/未作答，配色与选项的对错样式同源 */
  .ana-verdict {
    display: flex; align-items: center; gap: .7rem;
    padding: .85rem 1.05rem; background: var(--sp-ok-tint);
  }
  .ana-verdict.bad { background: var(--sp-bad-tint); }
  .ana-verdict.skip { background: var(--sp-elev); }
  .ana-verdict-icon {
    flex: none; width: 2.1rem; height: 2.1rem; border-radius: 50%; line-height: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--sp-ok); color: var(--sp-on-ok);
  }
  .ana-verdict.bad .ana-verdict-icon { background: var(--sp-bad); color: #fff; }
  .ana-verdict.skip .ana-verdict-icon { background: var(--sp-mid); color: var(--sp-on-accent); }
  .ana-verdict-icon .icon { width: 1.25em; height: 1.25em; }
  .ana-verdict-title { font-size: .95rem; font-weight: 800; color: var(--sp-text); }
  .ana-verdict-sub { margin-top: .12rem; color: var(--sp-muted); font-size: .8rem; }
  .ana-verdict-sub b.ok { color: var(--sp-ok-text); font-weight: 800; }
  .ana-verdict-sub b.bad { color: var(--sp-bad-soft); font-weight: 800; }
  .ana-main { padding: .9rem 1.05rem 1.05rem; }
  .analysis-title { display: flex; align-items: center; gap: .45rem; font-weight: 800; font-size: .88rem; margin: .8rem 0 .55rem; }
  .analysis-title .icon { color: var(--sp-accent-hover); }
  .analysis-meta {
    display: inline-block; background: var(--sp-accent-tint); color: var(--sp-accent-hover);
    font-size: .76rem; font-weight: 700; line-height: 1.6;
    padding: .22rem .75rem; border-radius: var(--sp-pill);
  }
  .analysis-meta::before { content: '考点 · '; opacity: .68; font-weight: 800; }
  .analysis-meta:empty { display: none; }
  .analysis-body { color: var(--sp-soft-text); font-size: .88rem; line-height: 1.8; }
  .ana-line + .ana-line { margin-top: .7rem; }
  .ana-head { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
  .ana-name { font-weight: 650; color: var(--sp-text); font-size: .88rem; line-height: 1.5; }
  .ana-verdict {
    flex: none; font-size: .7rem; font-weight: 800; padding: .12rem .55rem;
    border-radius: var(--sp-pill); background: var(--sp-elev); color: var(--sp-muted);
  }
  .ana-line.ok .ana-verdict { background: var(--sp-ok-tint); color: var(--sp-ok-text); }
  .ana-line.bad .ana-verdict { background: var(--sp-bad-tint); color: var(--sp-bad-soft); }
  .ana-desc { margin: .3rem 0 0 2rem; color: var(--sp-soft-text); font-size: .86rem; line-height: 1.75; }
  .ana-line.plain { font-size: .88rem; line-height: 1.75; }
  .ana-letter {
    flex: none; width: 1.45rem; height: 1.45rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 800; background: var(--sp-elev); color: var(--sp-text);
  }
  .ana-line.ok .ana-letter { background: var(--sp-ok); color: var(--sp-on-ok); }
  .ana-line.bad .ana-letter { background: var(--sp-bad); color: #fff; }

  /* 浅色主题：判定图标与解析字母改用淡彩底 + 彩色图形，避免大面积饱和红绿 */
  html[data-theme="light"] .ana-verdict-icon { background: var(--sp-ok-tint); color: var(--sp-ok-text); }
  html[data-theme="light"] .ana-verdict.bad .ana-verdict-icon { background: var(--sp-bad-tint); color: var(--sp-bad-soft); }
  html[data-theme="light"] .ana-verdict.skip .ana-verdict-icon { background: var(--sp-badge-border); color: var(--sp-muted); }
  html[data-theme="light"] .ana-line.ok .ana-letter { background: var(--sp-ok-tint); color: var(--sp-ok-text); }
  html[data-theme="light"] .ana-line.bad .ana-letter { background: var(--sp-bad-tint); color: var(--sp-bad-soft); }

  /* 上一题/下一题常驻视口底部（sticky），长题干不用滚到最底下才能切题 */
  .quiz-nav {
    position: sticky; bottom: 0; z-index: 50;
    display: flex; gap: .6rem; margin-top: 1rem;
    padding: .7rem 0 calc(.7rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--sp-bg) 72%, transparent);
  }
  .quiz-nav .btn:not(.sheet-btn) { flex: 1; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }

  /* ---------- 结果页 ---------- */
  .result-head { text-align: center; padding: 1.75rem 1.25rem 1.5rem; }
  .ring { --pct: 0; width: 9.2rem; height: 9.2rem; border-radius: 50%; margin: 0 auto 1.1rem; background: conic-gradient(var(--ring-color, var(--sp-ok)) calc(var(--pct) * 1%), var(--sp-ring-track) 0); display: grid; place-items: center; }
  .ring-inner { width: 7.4rem; height: 7.4rem; border-radius: 50%; background: var(--sp-surface); display: grid; place-items: center; }
  .ring-pct { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
  .ring-label { color: var(--sp-muted); font-size: .75rem; }
  .result-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 1.1rem; }
  .result-stats { display: flex; justify-content: center; gap: 2.2rem; }
  .result-stat .num { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
  .result-stat .lbl { color: var(--sp-muted); font-size: .78rem; }
  .result-stat.ok .num { color: var(--sp-ok-text); }
  .result-stat.bad .num { color: var(--sp-bad-soft); }
  .result-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }
  .result-actions .btn { flex: 1; }

  /* ---------- 考试模式 ---------- */
  .exam-timer {
    flex: none; display: inline-flex; align-items: center; gap: .32rem;
    color: var(--sp-muted); font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums;
  }
  .exam-timer .icon { width: 1em; height: 1em; }
  .exam-timer.warn { color: var(--sp-amber); }
  .exam-timer.danger { color: var(--sp-bad-soft); }
  .q-multi-hint {
    display: inline-block; margin-top: .6rem; font-size: .78rem; font-weight: 700;
    color: var(--sp-muted); background: var(--sp-elev); border-radius: var(--sp-pill); padding: .16rem .75rem;
  }
  .res-exam-meta { color: var(--sp-muted); font-size: .85rem; margin: -.45rem 0 1.05rem; }
  .domain-row { margin-bottom: .85rem; }
  .domain-row:last-child { margin-bottom: 0; }
  .domain-head { display: flex; justify-content: space-between; gap: .75rem; font-size: .86rem; margin-bottom: .32rem; }
  .domain-name { font-weight: 700; }
  .domain-pct { color: var(--sp-muted); font-variant-numeric: tabular-nums; }
  .domain-bar { height: 6px; border-radius: 3px; background: var(--sp-track); overflow: hidden; }
  .domain-bar i { display: block; height: 100%; border-radius: 3px; }

  .exam-field-label { color: var(--sp-muted); font-size: .82rem; margin: 1rem 0 .6rem; }
  .exam-time-hint { color: var(--sp-faint); font-size: .78rem; margin-top: .6rem; }
  #exam-min-wrap { margin-top: .6rem; }
  .exam-hist { margin-top: 1.15rem; border-top: 1px solid var(--sp-hair); padding-top: .9rem; }
  .exam-hist-title { display: flex; align-items: center; justify-content: space-between; font-size: .82rem; font-weight: 800; color: var(--sp-muted); margin-bottom: .55rem; }
  .exam-hist-item {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    font-size: .82rem; padding: .45rem .7rem; border-radius: 8px;
    background: var(--sp-surface-2); margin-bottom: .4rem; font-variant-numeric: tabular-nums;
  }
  .exam-hist-item:last-child { margin-bottom: 0; }
  .exam-hist-item .pass { color: var(--sp-ok-text); font-weight: 800; flex: none; }
  .exam-hist-item .fail { color: var(--sp-bad-soft); font-weight: 800; flex: none; }
  .link-btn { background: none; border: none; padding: 0; color: var(--sp-muted); font-size: .78rem; cursor: pointer; text-decoration: underline; font-family: inherit; }
  .link-btn:hover { color: var(--sp-text); }

  /* ---------- 答题卡抽屉（题号按钮唤起，兼作交卷确认） ---------- */
  /* 底部抽屉：dialog 全量显式覆盖几何属性（同 .modal 的说明） */
  dialog.drawer {
    background: var(--sp-modal-bg); color: var(--sp-text);
    border: 1px solid var(--sp-modal-border); border-bottom: none;
    border-radius: 16px 16px 0 0; padding: 0; box-shadow: var(--sp-modal-shadow);
    position: fixed; top: auto; left: 0; right: 0; bottom: 0;
    margin: 0 auto; min-width: 0; min-height: 0;
    width: 100%; max-width: 520px;
    height: fit-content; max-height: calc(100vh - 2.5rem); max-height: calc(100dvh - 2.5rem);
  }
  dialog.drawer::backdrop { background: var(--sp-backdrop); }
  dialog.drawer[open] { animation: drawer-up .3s cubic-bezier(.2, .8, .2, 1); }
  @keyframes drawer-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .drawer-inner {
    width: 100%; min-height: 0; display: flex; flex-direction: column;
    padding: .6rem 1.2rem calc(.95rem + env(safe-area-inset-bottom));
  }
  .drawer-grabber { flex: none; width: 2.6rem; height: 4px; border-radius: 2px; background: var(--sp-track); margin: 0 auto .85rem; }
  .drawer-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; margin-bottom: .85rem; }
  .drawer-head h5 { margin: 0; font-size: 1.02rem; font-weight: 800; }
  .drawer-head .modal-close { flex: none; }
  .drawer-actions { flex: none; display: flex; gap: .6rem; margin-top: 1rem; }
  .drawer-actions .btn { flex: 1; padding-left: .5rem; padding-right: .5rem; }

  /* 设置抽屉内容 */
  .settings-group { padding: .85rem 0; border-top: 1px solid var(--sp-hair); }
  .drawer-inner .settings-group:first-of-type { border-top: none; padding-top: 0; }
  .settings-label { color: var(--sp-muted); font-size: .76rem; font-weight: 700; margin-bottom: .55rem; }
  .settings-group .sync-row { align-items: center; }

  /* 桌面端（≥700px）：答题卡/设置改为居中面板；手机保持底部抽屉 */
  @media (min-width: 700px) {
    dialog.drawer {
      top: 0; bottom: 0;
      margin: auto;                    /* 覆盖基础规则的 margin:0 auto，实现垂直居中 */
      width: min(600px, 92vw); max-width: 600px;
      max-height: calc(100vh - 4rem); max-height: calc(100dvh - 4rem);
      border-radius: 16px; border-bottom: 1px solid var(--sp-modal-border);
    }
    dialog.drawer[open] { animation: drawer-pop .25s cubic-bezier(.2, .8, .2, 1); }
    .drawer-grabber { display: none; }
    .drawer-grid { max-height: min(56dvh, 480px); }
  }
  @keyframes drawer-pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

  .sheet-meta { color: var(--sp-muted); font-size: .84rem; margin-top: .3rem; line-height: 1.5; }
  .sheet-meta b.ok { color: var(--sp-ok-text); }
  .sheet-meta b.bad { color: var(--sp-bad-soft); }
  .sheet-meta b.amber { color: var(--sp-amber); }
  .sheet-tip { display: block; margin-top: .2rem; font-size: .75rem; color: var(--sp-faint); }
  .sheet-grid {
    flex: 0 1 auto; min-height: 0;
    max-height: min(44vh, 420px); max-height: min(44dvh, 420px);
    overflow-y: auto; overscroll-behavior: contain;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr)); gap: .45rem; padding: .1rem;
  }
  .sheet-cell {
    height: 2.3rem; padding: 0; border: 1.5px solid transparent; border-radius: 8px; cursor: pointer;
    background: var(--sp-surface-2); color: var(--sp-muted); font-weight: 700; font-size: .85rem;
    font-variant-numeric: tabular-nums; transition: background .15s, color .15s, border-color .15s;
  }
  .sheet-cell.current { border-color: var(--sp-accent); color: var(--sp-text); }
  .sheet-cell.answered { background: var(--sp-elev); color: var(--sp-text); }
  .sheet-cell.flagged { border-color: var(--sp-amber); color: var(--sp-amber); }
  .sheet-cell.marked { background: var(--sp-elev); color: var(--sp-text); }
  .sheet-cell.correct { background: var(--sp-ok-tint); color: var(--sp-ok-text); }
  .sheet-cell.wrong { background: var(--sp-bad-tint); color: var(--sp-bad-soft); }

  /* 底部导航中央的题号按钮：唤起答题卡抽屉 */
  .sheet-btn { flex: 0 0 auto; gap: .4rem; padding-left: .95rem; padding-right: .95rem; background: var(--sp-elev); }
  .sheet-btn:hover:not(:disabled) { background: var(--sp-surface-hover); }
  .sheet-btn .icon { width: 1.05em; height: 1.05em; color: var(--sp-muted); }
  .sheet-btn .sheet-btn-num { font-weight: 800; font-size: .9rem; font-variant-numeric: tabular-nums; }

  /* ---------- 弹窗 ---------- */
  /* Pico 把 dialog 当全屏遮罩容器（position:fixed; inset:0; min-width/height:100%），
     本应用 dialog 自身是居中小盒、遮罩用 ::backdrop。几何属性必须逐项显式覆盖，
     否则部分移动端内核（Safari/微信）会按 Pico 把弹窗拉成全屏滚动容器 */
  dialog.modal {
    background: var(--sp-modal-bg); color: var(--sp-text); border: 1px solid var(--sp-modal-border); border-radius: 14px;
    padding: 0; box-shadow: var(--sp-modal-shadow);
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; margin: auto;
    min-width: 0; min-height: 0; width: 100%; max-width: min(92vw, 480px);
    height: fit-content; max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
  }
  dialog.modal::backdrop { background: var(--sp-backdrop); }
  .modal-inner { padding: 1.35rem; width: 100%; }
  .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
  .modal-head h5 { margin: 0; font-size: 1.05rem; font-weight: 800; }
  .modal-close { background: none; border: none; color: var(--sp-muted); cursor: pointer; padding: .3rem; border-radius: 50%; line-height: 0; }
  .modal-close:hover { color: var(--sp-text); }
  .modal-desc { color: var(--sp-muted); font-size: .82rem; line-height: 1.6; margin-bottom: .8rem; }
  .modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

  /* ---------- Toast（外层固定居中，内层做动画避免 transform 冲突） ---------- */
  .toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(1.6rem + env(safe-area-inset-bottom)); display: flex; justify-content: center; pointer-events: none; z-index: 300; }
  .toast { display: none; background: var(--sp-toast-bg); color: var(--sp-toast-text); font-size: .88rem; font-weight: 700; border-radius: var(--sp-pill); padding: .6rem 1.3rem; box-shadow: var(--sp-toast-shadow); max-width: 86vw; }
  .toast.show { display: block; }
  .toast.error { background: var(--sp-bad); color: #fff; }

  @media (max-width: 575.98px) {
    .container { padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
    .card { padding: 1.05rem; }
    .stats-overview { grid-template-columns: 1fr 1fr; }
    .result-stats { gap: 1.4rem; }
    .quiz-nav { gap: .55rem; }
    .result-actions { flex-direction: column; }
    .result-actions .btn { width: 100%; }
    .ana-desc { margin-left: 1.9rem; }
    #modal-search .modal-inner { padding: 1.05rem; }
    #modal-search .modal-desc { font-size: .76rem; }
  }

  /* 窄屏答题顶栏：压缩计时药丸，保证一行放得下 */
  @media (max-width: 419.98px) {
    .quiz-counter { font-size: .88rem; }
    .q-timer { padding: .26rem .6rem; font-size: .82rem; gap: .28rem; }
    .q-timer .icon, .exam-timer .icon { display: none; }
    .quiz-head-row { gap: .42rem; }
  }

  @media (max-width: 359.98px) {
    /* 极窄屏答题顶栏：双计时器（考试模式）也保证一行放下不溢出 */
    .quiz-head-row { gap: .32rem; }
    .quiz-counter { font-size: .8rem; }
    .quiz-progress-line { min-width: 2.6rem; }
    .q-timer, .exam-timer { font-size: .78rem; padding: .22rem .5rem; gap: .22rem; }
    .sheet-btn { padding-left: .65rem; padding-right: .65rem; }
  }

  .drawer-head-tools { display: flex; gap: .35rem; flex: none; }
  .modal-close { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
  .drawer-inner { max-height: inherit; overflow-y: auto; overscroll-behavior: contain; }
  #drawer-settings .drawer-head { position: sticky; top: 0; z-index: 1; background: var(--sp-modal-bg); }
  dialog.modal { overflow-y: auto; }
  button, input, select { touch-action: manipulation; }
  @media (max-width: 575.98px) {
    .btn, .seg, .sheet-cell, .back-btn, .hero-more, .scope-select { min-height: 44px; }
    .back-btn, .star-btn, .flag-btn { min-width: 44px; min-height: 44px; }
    .quiz-head-row { flex-wrap: wrap; }
    input, select { font-size: 16px !important; }
    .quiz-nav .btn { padding-left: .65rem; padding-right: .65rem; font-size: .88rem; white-space: nowrap; }
    .drawer-actions { flex-wrap: wrap; }
    .drawer-actions .btn { min-width: 6rem; }
    .modal-actions .btn { min-width: 0; padding-left: .7rem; padding-right: .7rem; }
    .sync-btns { flex-wrap: wrap; }
    .card-title { flex-wrap: wrap; }
  }
  @media (pointer: coarse) {
    .btn, .seg, .sheet-cell, .back-btn, .hero-more, .scope-select { min-height: 44px; }
    .back-btn, .star-btn, .flag-btn { min-width: 44px; min-height: 44px; }
    input, select { font-size: 16px !important; }
  }
  @media (max-height: 500px) and (orientation: landscape) {
    .drawer-inner { padding-top: .5rem; }
    .drawer-grabber { display: none; }
    .drawer-head { margin-bottom: .4rem; }
    .settings-group { padding: .5rem 0; }
    .sheet-grid { max-height: 35dvh; }
  }

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