:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7a;
  --line: #dde3ea;
  --brand: #1f5f8b;
  --brand-ink: #ffffff;
  --brand-soft: #e6f0f7;
  --ok: #1e7a46;
  --ok-soft: #e5f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --todo: #e9edf1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --card: #1b2128;
    --text: #e6ebf0;
    --muted: #9aa7b4;
    --line: #2c353f;
    --brand: #5aa6d6;
    --brand-ink: #0d1a24;
    --brand-soft: #1d3140;
    --ok: #5fcf8d;
    --ok-soft: #173325;
    --bad: #f08a80;
    --bad-soft: #3a1d1b;
    --todo: #2a323b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
button, input { font: inherit; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark {
  flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); white-space: nowrap; }

.container { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }

/* 卡片和按钮 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.card h1 { font-size: 22px; line-height: 1.35; margin: 0 0 8px; }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 180px; }
.linkish { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font-size: 14px; }

/* 首页 */
.points { margin: 12px 0 18px; padding: 0; list-style: none; }
.points li { padding: 6px 0 6px 26px; position: relative; }
.points li::before { content: "✓"; position: absolute; left: 2px; color: var(--ok); font-weight: 700; }
.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); letter-spacing: .5px;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.error { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 8px 0; }
.notice { color: var(--text); background: var(--brand-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 0 0 14px; }

/* 进度总览 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 16px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 13px; color: var(--muted); }
.area { margin-top: 14px; }
.area h3 { font-size: 15px; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 52px; height: 40px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--todo); color: var(--text); cursor: pointer; font-size: 14px; font-variant-numeric: tabular-nums;
}
.chip.right { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.chip.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 1px solid var(--line); background: var(--todo); }
.legend i.right { background: var(--ok-soft); border-color: var(--ok); }
.legend i.wrong { background: var(--bad-soft); border-color: var(--bad); }

/* 做题 */
.qhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.tag { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); margin-right: 6px; }
.bar { height: 6px; background: var(--todo); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.stem { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; margin: 6px 0 14px; }
.figure { margin: 0 0 16px; text-align: center; }
.figure img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; }
.figure figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.figure .loading { padding: 40px 0; color: var(--muted); }

/* 选项：每个选项是一个框，提交后这个选项的解析就显示在框里、选项文字正下方 */
.options { display: grid; gap: 10px; }
.opt-item { border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 12px 14px; border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.opt .key {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line); font-weight: 700; font-size: 14px;
}
.opt .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.opt:disabled { cursor: default; }
.opt-item.selected { border-color: var(--brand); background: var(--brand-soft); }
.opt-item.selected .key { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.opt-item.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt-item.correct .key { background: var(--ok); border-color: var(--ok); color: var(--card); }
.opt-item.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt-item.wrong .key { background: var(--bad); border-color: var(--bad); color: var(--card); }
.opt-expl { margin: 0 14px; padding: 10px 0 12px; border-top: 1px dashed var(--line); font-size: 15px; line-height: 1.6; }
/* 解析原文里的换行和空行要保留，否则分段的解析会挤成一段 */
.opt-expl .zh, .opt-expl .en, .pane-expl p { white-space: pre-wrap; overflow-wrap: anywhere; }
.kbd-hint { display: none; margin: 12px 0 0; font-size: 13px; color: var(--muted); }

/* 英文解析：默认收起，点"显示英文解析"后所有英文一起出现；没有中文时直接显示英文 */
.qpage .en { display: none; color: var(--muted); font-size: 14.5px; margin-top: 6px; }
.qpage.show-en .en, .qpage .en.always { display: block; }
.opt-expl .en { padding-left: 10px; border-left: 2px solid var(--line); }

.result { border-radius: 10px; padding: 12px 14px; font-weight: 600; margin-bottom: 14px; }
.result.ok { background: var(--ok-soft); color: var(--ok); }
.result.bad { background: var(--bad-soft); color: var(--bad); }

.pane-expl h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pane-expl p { margin: 0 0 12px; }
.ref { font-size: 13px; color: var(--muted); margin-top: 8px; }
.cta { margin-top: 16px; padding-top: 14px; border-top: 1.5px solid var(--brand); }
.cta h3 { font-size: 16px; margin: 0 0 6px; }
.sticky-actions { position: sticky; bottom: 0; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }

/* 做题页：手机上从上往下排；提交前不显示空的"总体解析"卡片 */
.pane-expl.pending { display: none; }

/* 中等宽度：两栏（左题目，右"选项 + 总体解析"），各自滚动，整页不滚 */
@media (min-width: 900px) {
  .container.qmode {
    max-width: 1680px; display: flex; flex-direction: column;
    height: calc(100vh - 56px); height: calc(100dvh - 56px);
    padding-top: 14px; padding-bottom: 0;
  }
  .qmode .qpage {
    flex: 1; min-height: 0; display: grid; gap: 14px;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  }
  .qmode .pane-q, .qmode .side { overflow: auto; min-height: 0; }
  .qmode .pane { padding: 18px; margin: 0; }
  .qmode .side .pane + .pane { margin-top: 14px; }
  .qmode .figure img { max-height: 70vh; width: auto; }
  .qmode .sticky-actions { position: static; background: none; padding: 12px 0 14px; display: flex; justify-content: center; }
  .qmode .sticky-actions .btn { max-width: 480px; }
}
@media (min-width: 900px) and (pointer: fine) { .kbd-hint { display: block; } }

/* 宽屏：三栏（题目 | 选项 | 总体解析），提交前右栏显示提示文字 */
@media (min-width: 1200px) {
  .qmode .qpage { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, .9fr); }
  .qmode .side { display: contents; }
  .qmode .side .pane { overflow: auto; min-height: 0; }
  .qmode .side .pane + .pane { margin-top: 0; }
  .qmode .pane-expl.pending { display: block; }
}

/* 模考：计时、题号导航、交卷、成绩 */
a.chip { display: inline-grid; place-items: center; text-decoration: none; }
.chip.answered { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.chip.marked { box-shadow: inset 0 -3px 0 #d98e04; }
.chip.current { outline: 2px solid var(--text); outline-offset: 1px; }
.chip.skip { background: var(--todo); color: var(--muted); border-style: dashed; }
.legend i.answered { background: var(--brand-soft); border-color: var(--brand); }
.legend i.marked { box-shadow: inset 0 -3px 0 #d98e04; }
.legend i.skip { border-style: dashed; }
.exam-clock { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; color: var(--brand); }
.exam-clock.urgent { color: var(--bad); }
.exam-nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin: 10px 0 4px; }
.exam-nav .chip { min-width: 0; width: 100%; height: 34px; padding: 0; font-size: 13px; }
.exam-mark { margin-top: 12px; }
.exam-submit { margin-top: 14px; }
.exam-submit p { margin: 0 0 10px; }
.radios { display: grid; gap: 8px; }
.radio { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.score { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 6px; }
.score b { font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; }
.score.ok b { color: var(--ok); }
.score.bad b { color: var(--bad); }
.area-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.area-table td { padding: 7px 6px; border-top: 1px solid var(--line); }
.area-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.area-table .meter-cell { width: 40%; }
.meter { height: 6px; background: var(--todo); border-radius: 999px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--brand); }
.sticky-actions .btn-row .btn { flex: 1 1 120px; }
.exam-mini { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.exam-mini.urgent { color: var(--bad); font-weight: 600; }
@media (min-width: 900px) { .exam-mini { display: none; } }

/* 放大看图：点任意位置返回 */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 18, .92); display: flex; flex-direction: column; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox-bar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); color: #dfe6ec; font-size: 13px; text-align: center; }
.lightbox-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; display: flex; }
.lightbox-body img { margin: auto; max-width: none; max-height: none; height: auto; background: #fff; }  /* 宽度由 app.js 按屏幕算 */

@media (min-width: 720px) {
  .container { padding-top: 24px; }
  .card { padding: 24px; }
  .card h1 { font-size: 26px; }
}
