:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #5f6672;
  --primary: #2563eb;
  --primary-press: #1d4ed8;
  --primary-soft: #e8efff;
  --on-primary: #ffffff;
  --ok-text: #15803d;
  --ok-bg: #dcfce7;
  --ok-border: #22c55e;
  --bad-text: #b91c1c;
  --bad-bg: #fee2e2;
  --bad-border: #ef4444;
  --warn-bg: #fff7d6;
  --warn-text: #7a5300;
  --c-network: #2563eb;
  --c-os: #7c3aed;
  --c-web: #db2777;
  --c-crypto: #0d9488;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --border: #2c313a;
    --text: #e8eaee;
    --muted: #9aa2ae;
    --primary: #4f8cff;
    --primary-press: #3b78f0;
    --primary-soft: #1b2740;
    --on-primary: #ffffff;
    --ok-text: #86efac;
    --ok-bg: #0f2e1c;
    --ok-border: #22a355;
    --bad-text: #fca5a5;
    --bad-bg: #3a1414;
    --bad-border: #d64545;
    --warn-bg: #3a300f;
    --warn-text: #f5d77a;
    --c-network: #6ea0ff;
    --c-os: #a78bfa;
    --c-web: #f472b6;
    --c-crypto: #2dd4bf;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hidden { display: none; }
.muted { color: var(--muted); }
code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 .3em;
  overflow-wrap: anywhere;
}
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 8px 16px;
  font-size: 14px;
  text-align: center;
}

/* ---------- 布局 ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(32px + var(--safe-b));
}
.page.has-bottom, .quiz-page { padding-bottom: calc(100px + var(--safe-b)); }
.loading { text-align: center; color: var(--muted); padding: 30vh 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  max-width: 640px; margin: 0 auto;
  padding: 8px 12px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
}
body[data-view="home"] .topbar { grid-template-columns: 1fr 44px; padding: 12px 16px 4px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; justify-content: flex-start; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar:not(:first-child) .brand, body:not([data-view="home"]) .brand { justify-content: center; font-size: 17px; }
.logo { font-size: 22px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

.section-title { font-size: 15px; font-weight: 600; color: var(--muted); margin: 24px 4px 10px; }
.foot { font-size: 13px; text-align: center; margin-top: 28px; }

/* ---------- 首页 ---------- */
.overview {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-top: 8px; padding: 14px 4px;
}
.ov-item { text-align: center; display: flex; flex-direction: column; }
.ov-item + .ov-item { border-left: 1px solid var(--border); }
.ov-item b { font-size: 22px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.ov-item span { font-size: 13px; color: var(--muted); }

.wrong-entry, .mix-card {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 14px 16px; margin-top: 12px; min-height: 64px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.wrong-entry { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.wrong-entry .we-text b { color: var(--text); }
.we-text { flex: 1; display: flex; flex-direction: column; line-height: 1.35; }
.we-text small { color: var(--muted); font-size: 13px; }
.badge {
  min-width: 26px; height: 26px; padding: 0 8px; border-radius: 13px;
  background: var(--bad-border); color: #fff; font-size: 14px; font-weight: 700;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.wrong-entry:hover, .mix-card:hover, .cat-card:hover { filter: brightness(.98); }
.wrong-entry:active, .mix-card:active, .cat-card:active { transform: scale(.99); }

.cat-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 520px) { .cat-grid { grid-template-columns: 1fr 1fr; } }
.cat-card {
  --c: var(--primary);
  text-align: left; padding: 16px; min-height: 112px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 4px solid var(--c);
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .1s;
}
.cat-network { --c: var(--c-network); }
.cat-os { --c: var(--c-os); }
.cat-web { --c: var(--c-web); }
.cat-crypto { --c: var(--c-crypto); }
.cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cat-head b { font-size: 17px; }
.cat-head .muted { font-size: 13px; }
.mini-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--c); border-radius: 3px; width: 0; }
.cat-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.cat-meta .pend { color: var(--bad-text); font-weight: 600; }
.mix-card .icon:first-child { color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  min-height: 48px; padding: 10px 20px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-press); }
.btn-primary:disabled { opacity: .45; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--bad-border); color: #fff; }
.btn-small { min-height: 38px; padding: 6px 14px; font-size: 14px; }

/* ---------- 答题页 ---------- */
.quizbar { grid-template-columns: 44px 1fr auto; }
.qprog { display: flex; align-items: center; gap: 10px; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 3px; transition: width .25s; }
.score { color: var(--ok-text); font-weight: 700; font-size: 15px; padding-right: 6px; font-variant-numeric: tabular-nums; }

.qcard { padding-top: 4px; }
.qmeta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; font-size: 12px; line-height: 1; padding: 6px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.chip.cat-network, .chip.cat-os, .chip.cat-web, .chip.cat-crypto { color: var(--c); border-color: color-mix(in srgb, var(--c) 35%, transparent); background: color-mix(in srgb, var(--c) 10%, transparent); }
.chip-bad { color: var(--bad-text); background: var(--bad-bg); border-color: transparent; }
.star-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px;
}
.star-btn .icon { width: 16px; height: 16px; }
.star-btn.on { color: #d97706; border-color: color-mix(in srgb, #f59e0b 45%, transparent); }
.star-btn.on .icon { fill: #f59e0b; stroke: #f59e0b; }

.stem { font-size: 18px; line-height: 1.6; font-weight: 600; margin: 14px 0 12px; word-break: break-word; }
.stem strong { color: var(--bad-text); text-decoration: underline; text-underline-offset: 3px; }
.codeblock {
  margin: 0 0 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  overflow-x: auto; max-width: 100%; font-size: 14px; line-height: 1.5;
}
.codeblock code { background: none; border: 0; padding: 0; white-space: pre; word-break: normal; font-size: inherit; }

.options { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.opt {
  width: 100%; min-height: 52px; display: flex; align-items: flex-start; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow); line-height: 1.5; transition: border-color .12s, background .12s, opacity .2s;
}
.opt:hover:not(:disabled) { border-color: var(--primary); }
.opt:active:not(:disabled) { background: var(--primary-soft); }
.opt-letter {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; background: var(--surface-2); color: var(--muted);
}
.opt-text { flex: 1; padding-top: 2px; word-break: break-word; }
.opt-mark { flex: none; font-weight: 800; font-size: 18px; line-height: 28px; }
.opt.correct { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.opt.correct .opt-letter { background: var(--ok-border); color: #fff; }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad-text); }
.opt.wrong .opt-letter { background: var(--bad-border); color: #fff; }
.opt.dim { opacity: .5; }
.opt:disabled { color: inherit; }
.opt.correct:disabled { color: var(--ok-text); }
.opt.wrong:disabled { color: var(--bad-text); }

.explain {
  margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--ok-border); box-shadow: var(--shadow);
  animation: rise .2s ease-out;
  scroll-margin-bottom: calc(96px + var(--safe-b));
}
.explain.bad { border-left-color: var(--bad-border); }
.exp-head { font-weight: 700; }
.explain.ok .exp-head { color: var(--ok-text); }
.explain.bad .exp-head { color: var(--bad-text); }
.exp-note { margin-top: 6px; font-size: 14px; padding: 6px 10px; border-radius: 8px; background: var(--ok-bg); color: var(--ok-text); }
.explain p { margin: 8px 0 10px; font-size: 15px; line-height: 1.7; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag-hl { background: var(--warn-bg); color: var(--warn-text); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  transform: translateY(110%); transition: transform .2s ease-out;
}
.bottom-bar.show { transform: none; }
.bottom-bar .btn { max-width: 608px; margin: 0 auto; display: flex; }

/* ---------- 结果页 ---------- */
.res-top { display: flex; align-items: center; gap: 24px; justify-content: center; padding: 20px 0 8px; }
.ring {
  --p: 0;
  width: 128px; height: 128px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0);
  display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative;
}
.ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--bg); }
.ring b, .ring span { position: relative; }
.ring b { font-size: 28px; line-height: 1.1; }
.ring span { font-size: 13px; color: var(--muted); }
.res-stats { display: flex; flex-direction: column; gap: 12px; }
.res-stats div { display: flex; flex-direction: column; line-height: 1.3; }
.res-stats b { font-size: 20px; font-variant-numeric: tabular-nums; }
.res-stats span { font-size: 13px; color: var(--muted); }
.res-actions { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 4px; }
.notice { padding: 12px 14px; border-radius: 12px; text-align: center; font-weight: 600; margin-top: 8px; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }

/* ---------- 错题集 ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-top: 4px; }
.tab { min-height: 42px; border: 0; background: transparent; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 12px; }
@media (min-width: 560px) { .toolbar { flex-direction: row; align-items: center; justify-content: space-between; } }
.filters { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
@media (min-width: 560px) { .filters { margin: 0; padding: 2px 0; } }
.filters::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 14px;
}
.fchip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.fcount { font-size: 12px; opacity: .7; font-variant-numeric: tabular-nums; }
.sort {
  min-height: 38px; padding: 4px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; align-self: flex-start;
}
@media (min-width: 560px) { .sort { font-size: 14px; align-self: auto; } }

.weak { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); }
.weak-title { font-weight: 700; font-size: 14px; }
.weak ol { margin: 6px 0 0; padding-left: 22px; font-size: 14px; }
.weak li em { font-style: normal; opacity: .75; margin-left: 8px; font-size: 13px; }

.wlist { display: flex; flex-direction: column; gap: 10px; }
.witem { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.witem summary {
  list-style: none; cursor: pointer; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.witem summary::-webkit-details-marker { display: none; }
.wi-title { font-weight: 600; line-height: 1.5; word-break: break-word; }
.wi-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.witem[open] summary { border-bottom: 1px solid var(--border); }
.wi-body { padding: 12px 14px 14px; }
.wi-stem { margin: 0 0 10px; font-weight: 600; word-break: break-word; }
.wi-opts { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wi-opts li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 15px; word-break: break-word; }
.wi-opts li > span:nth-child(2) { flex: 1; }
.wi-opts li em { font-style: normal; font-size: 12px; white-space: nowrap; font-weight: 600; padding-top: 2px; }
.wi-opts li.correct { background: var(--ok-bg); color: var(--ok-text); }
.wi-opts li.wrong { background: var(--bad-bg); color: var(--bad-text); }
.wi-mark { font-weight: 800; width: 14px; flex: none; }
.wi-exp { margin: 0; font-size: 15px; line-height: 1.7; color: var(--muted); }
.wi-actions { margin-top: 12px; display: flex; justify-content: flex-end; }

.empty { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty-emoji { font-size: 44px; }
.empty p { color: var(--muted); margin: 4px 0 14px; }

/* ---------- 设置 ---------- */
.settings { display: flex; flex-direction: column; gap: 16px; margin-top: 4px; }
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; min-height: 64px; }
.row + .row { border-top: 1px solid var(--border); }
.row.col { flex-direction: column; align-items: stretch; }
.row > div:first-child { display: flex; flex-direction: column; line-height: 1.4; }
.row small { color: var(--muted); font-size: 13px; }
.row .btn { flex: none; }
.note { padding: 14px 16px; font-size: 14px; }
.note ul { margin: 6px 0 0; padding-left: 20px; color: var(--muted); }
.note p { margin: 6px 0 0; }
.switch { flex: none; width: 52px; height: 32px; border-radius: 16px; border: 0; background: var(--border); position: relative; transition: background .2s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch.on { background: var(--primary); }
.switch.on i { transform: translateX(20px); }

/* ---------- 分段控件 ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg-btn { min-height: 42px; border: 0; background: transparent; border-radius: 9px; font-size: 15px; color: var(--muted); padding: 4px 6px; }
.seg-btn.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- 弹窗 / 抽屉 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.modal p { margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { flex: 1; }

.sheet-overlay { align-items: flex-end; padding: 0; animation: none; background: rgba(0,0,0,0); transition: background .2s; }
.sheet-overlay.show { background: rgba(0,0,0,.45); }
.sheet {
  width: 100%; max-width: 640px; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(100%); transition: transform .22s ease-out;
}
.sheet-overlay.show .sheet { transform: none; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 19px; }
.sheet-body { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.sheet-body p { margin: 0; font-size: 14px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
@media (min-width: 720px) {
  .sheet-overlay { align-items: center; padding: 16px; }
  .sheet { border-radius: 20px; max-width: 440px; transform: translateY(16px); opacity: 0; transition: transform .2s, opacity .2s; }
  .sheet-overlay.show .sheet { opacity: 1; }
  .sheet-handle { display: none; }
}

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