/* ================= 基础 ================= */
:root {
  --primary: #2f6fed;
  --primary-600: #2558c4;
  --primary-bg: #eaf1fe;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --green-bg: #e9f9ef;
  --red: #dc2626;
  --red-bg: #fdeeee;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --nav-h: 62px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
  min-height: 100vh; padding-bottom: var(--nav-h);
}
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: 1rem; }
input, select { font-family: inherit; font-size: 1rem; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.25em; }
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }

/* ================= 顶栏 ================= */
#topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--card); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; cursor: pointer; white-space: nowrap; }
.brand svg { color: var(--primary); width: 1.5em; height: 1.5em; }
#topnav { display: none; gap: 4px; flex: 1; }
#topnav a { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: .95rem; }
#topnav a.active { color: var(--primary); background: var(--primary-bg); font-weight: 600; }
.user-box { position: relative; margin-left: auto; }
.user-chip { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--bg); font-size: .92rem; cursor: pointer; }
.user-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 140px; overflow: hidden; z-index: 60; }
.user-menu button { display: block; width: 100%; text-align: left; padding: 10px 16px; }
.user-menu button:hover { background: var(--bg); }
.user-menu button.danger { color: var(--red); }

/* ================= 底部导航（移动端） ================= */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
#bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--muted); font-size: .68rem; }
#bottomnav a svg { width: 22px; height: 22px; }
#bottomnav a.active { color: var(--primary); }

/* ================= 通用组件 ================= */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 22px; border-radius: 10px; font-size: 1rem; font-weight: 600; transition: .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:disabled { background: #a8c0f2; cursor: not-allowed; }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-lg { padding: 13px 28px; font-size: 1.05rem; width: 100%; }
.btn-sm { padding: 6px 14px; font-size: .88rem; border-radius: 8px; }
.page-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: .9rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-blue { background: var(--primary-bg); color: var(--primary); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--bg); color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .35; margin-bottom: 12px; }

/* 统计数字块 */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-item .num { font-size: 1.7rem; font-weight: 700; color: var(--primary); }
.stat-item .label { font-size: .85rem; color: var(--muted); }
.stat-item.good .num { color: var(--green); }
.stat-item.warn .num { color: var(--amber); }

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 14px; text-align: left; white-space: nowrap; }
th { background: var(--bg); font-weight: 600; color: var(--muted); font-size: .85rem; }
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: #fafbfd; }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); outline: none;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.form-error { color: var(--red); font-size: .88rem; min-height: 1.4em; margin-bottom: 8px; }

/* 首页入口 */
.home-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.entry { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 16px; display: flex; flex-direction: column; gap: 6px; transition: .15s; box-shadow: var(--shadow); }
.entry:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.entry svg { width: 28px; height: 28px; color: var(--primary); }
.entry .t { font-weight: 700; }
.entry .d { font-size: .8rem; color: var(--muted); }

/* ================= 题目卡片 ================= */
.q-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 20px; }
.q-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.q-stem { font-size: 1.05rem; font-weight: 500; margin-bottom: 18px; word-break: break-word; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; width: 100%;
  padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 12px; background: var(--card);
  font-size: .98rem; line-height: 1.55; transition: .12s;
}
.opt:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-bg); }
.opt:disabled { cursor: default; }
.opt .letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; margin-top: 1px;
}
.opt.selected { border-color: var(--primary); background: var(--primary-bg); }
.opt.selected .letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.opt.correct { border-color: var(--green); background: var(--green-bg); }
.opt.correct .letter { background: var(--green); border-color: var(--green); color: #fff; }
.opt.wrong { border-color: var(--red); background: var(--red-bg); }
.opt.wrong .letter { background: var(--red); border-color: var(--red); color: #fff; }
.opt.judge-opt { justify-content: center; font-size: 1.05rem; font-weight: 600; }

/* 答题反馈条 */
.feedback { margin-top: 16px; padding: 12px 16px; border-radius: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.feedback.ok { background: var(--green-bg); color: var(--green); }
.feedback.no { background: var(--red-bg); color: var(--red); }
.feedback .fa { font-size: 1.05rem; }

/* 进度条 */
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.progress-text { font-size: .88rem; color: var(--muted); white-space: nowrap; }
.progress-bar { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }

/* 答题操作行 */
.q-actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.q-actions .btn { flex: 1; min-width: 120px; }

/* 考试计时器 */
.exam-timer-bar {
  position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.timer { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.timer.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.exam-count { font-size: .9rem; color: var(--muted); white-space: nowrap; }

/* 题号导航网格 */
.qnav { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.qnav button {
  aspect-ratio: 1; border-radius: 8px; border: 1.5px solid var(--border); background: var(--card);
  font-size: .75rem; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.qnav button.answered { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.qnav button.current { outline: 2.5px solid var(--primary); outline-offset: 1px; }

/* 速记 */
.memo-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 12px; }
.memo-item .q { font-size: 1rem; font-weight: 500; line-height: 1.7; word-break: break-word; }
.memo-item .opts-mini { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.memo-item .opts-mini div { padding: 2px 0; }
.memo-item .opts-mini .is-ans { color: var(--green); font-weight: 700; }
.memo-ans { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; color: var(--primary); font-weight: 700; }
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 20px 0; }
.pager button { padding: 8px 18px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); font-weight: 600; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* 标签页切换 */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { padding: 8px 18px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); color: var(--muted); font-size: .92rem; }
.tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* 考试结果 */
.result-hero { text-align: center; padding: 30px 16px; }
.result-hero .score { font-size: 3.4rem; font-weight: 800; line-height: 1.1; }
.result-hero .score.pass { color: var(--green); }
.result-hero .score.fail { color: var(--red); }
.result-hero .sub { color: var(--muted); margin-top: 8px; }

/* 考试记录详情 */
.review-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.review-item.wrong-item { border-color: #f3b0b0; background: #fffafa; }
.review-item .q { font-weight: 500; margin-bottom: 8px; word-break: break-word; }
.review-item .ro { padding: 2px 0; font-size: .92rem; display: flex; gap: 8px; }
.review-item .ro .l { font-weight: 700; flex: none; }
.review-item .ro.user-ans { color: var(--text); }
.review-item .ro.right-ans { color: var(--green); font-weight: 600; }
.review-item .opts-mini { margin-top: 6px; font-size: .92rem; display: flex; flex-direction: column; gap: 2px; }

/* 解析 */
.expl-box { margin-top: 12px; padding: 10px 14px; background: var(--bg); border-left: 3px solid var(--primary); border-radius: 8px; font-size: .92rem; color: #374151; line-height: 1.75; word-break: break-word; }
.expl-box .expl-title { font-weight: 700; color: var(--primary); margin-right: 8px; }
.expl-details { margin-top: 10px; }
.expl-details summary { cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--primary); user-select: none; }
.expl-details summary:hover { text-decoration: underline; }
.expl-details .expl-box { margin-top: 8px; }

/* 开关行 */
.switch-row { display: flex; align-items: center; gap: 10px; margin: 6px 0 18px; font-size: .95rem; cursor: pointer; }
.switch-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; cursor: pointer; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%);
  background: rgba(17, 24, 39, .92); color: #fff; padding: 10px 22px; border-radius: 999px;
  font-size: .92rem; z-index: 200; max-width: 86vw; text-align: center;
}
#toast.err { background: var(--red); }

/* Modal */
#modal-root .mask { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--card); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 24px; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin-bottom: 14px; font-size: 1.1rem; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal .modal-actions .btn { flex: 1; }

/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 34px 28px; }
.login-card .brand { justify-content: center; margin-bottom: 6px; font-size: 1.15rem; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 24px; }

/* ================= 响应式 ================= */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  #bottomnav { display: none; }
  #topnav { display: flex; }
  .home-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .qnav { grid-template-columns: repeat(16, 1fr); }
  .container { padding: 28px 24px 60px; }
  #toast { bottom: 40px; }
}
@media (max-width: 360px) {
  .qnav { grid-template-columns: repeat(8, 1fr); }
}
