:root {
  --primary: #4f6bff;
  --primary-dark: #3d56e0;
  --grad: linear-gradient(135deg, #5b7cff, #8a5bff);
  --green: #12b76a;
  --red: #f04438;
  --amber: #f79009;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2433;
  --sub: #8a94a8;
  --border: #e7ebf3;
  --radius: 18px;
  --shadow: 0 6px 22px rgba(40, 60, 130, .08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* 顶部栏（小程序原生导航栏风格：纯色蓝底 + 标题居中） */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: #4f6bff; color: #fff;
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(79, 107, 255, .25);
}
.top-title-wrap { flex: 1; min-width: 0; text-align: center; line-height: 1.25; padding: 10px 44px; }
#topTitle { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-sub { font-size: 11px; opacity: .85; }
.back {
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%); z-index: 21;
  background: transparent; color: #fff; border: 0;
  padding: 8px 12px; font-size: 24px; line-height: 1; cursor: pointer;
}
.back.hidden { display: none !important; }

/* 屏幕 */
.screen { display: none; padding: 16px; padding-bottom: 46px; animation: fadeIn .28s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Hero */
.hero { background: var(--grad); color: #fff; border-radius: 22px; padding: 24px 22px; margin-bottom: 14px; box-shadow: var(--shadow); }
.hero-title { font-size: 20px; font-weight: 800; }
.hero-sub { font-size: 13px; opacity: .92; margin-top: 6px; }

/* 搜索框 */
.search-box { display: flex; align-items: center; background: #fff; border-radius: 14px; padding: 0 14px; margin-bottom: 14px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.search-icon { font-size: 16px; }
.search-box input { flex: 1; border: 0; outline: 0; padding: 13px 10px; font-size: 15px; background: transparent; }

/* 题库头部 + mini 按钮 */
.bank-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.bank-head-title { font-size: 15px; font-weight: 700; }
.mini-btn { background: #eef2ff; color: var(--primary); border: 0; border-radius: 20px; padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer; }
.mini-btn:active { background: #dfe6ff; }

/* 题库列表 */
.bank-list { display: grid; gap: 14px; }
.bank-item { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); cursor: pointer; border: 1px solid var(--border); transition: transform .12s ease; }
.bank-item:active { transform: scale(.98); }
.load-more { display: block; margin: 4px auto 8px; }
.bi-name { font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bi-count { font-size: 12px; color: var(--primary); background: #eef2ff; padding: 2px 10px; border-radius: 12px; font-weight: 700; }
.bi-tag { font-size: 11px; color: #fff; background: var(--amber); padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.bi-tag.judge { background: var(--green); }
.bi-desc { font-size: 13px; color: var(--sub); margin-top: 8px; }
.loading { text-align: center; color: var(--sub); padding: 40px 0; font-size: 14px; }

/* 卡片 */
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* 设置页 */
.setup-name { font-size: 20px; font-weight: 800; text-align: center; }
.setup-desc { font-size: 13px; color: var(--sub); text-align: center; margin: 8px 0 18px; }
.field { margin: 18px 0; }
.field-label { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.mode-group { display: flex; gap: 12px; }
.mode-btn { flex: 1; border: 2px solid var(--border); background: #fff; border-radius: 15px; padding: 14px 10px; cursor: pointer; text-align: left; transition: all .14s ease; }
.mode-btn.active { border-color: var(--primary); background: #f3f6ff; box-shadow: 0 4px 12px rgba(79,107,255,.15); }
.mode-t { font-weight: 800; font-size: 15px; }
.mode-d { font-size: 12px; color: var(--sub); margin-top: 4px; }
.count-row { display: flex; align-items: center; gap: 10px; }
.step { width: 44px; height: 44px; border-radius: 13px; border: 1px solid var(--border); background: #fff; font-size: 22px; cursor: pointer; color: var(--primary); font-weight: 700; }
#countInput { width: 74px; height: 44px; text-align: center; font-size: 18px; border: 1px solid var(--border); border-radius: 13px; font-weight: 700; }
.count-hint { font-size: 12px; color: var(--sub); }
.primary-btn { width: 100%; padding: 15px; border: 0; border-radius: 15px; background: var(--grad); color: #fff; font-size: 16px; font-weight: 800; cursor: pointer; margin-top: 8px; box-shadow: 0 6px 16px rgba(79,107,255,.3); }
.primary-btn:active { opacity: .9; }
.ghost-btn { width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 15px; background: #fff; color: var(--text); font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 12px; }

/* 答题页 */
.quiz-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-text { font-size: 13px; font-weight: 800; color: var(--primary); white-space: nowrap; }
.progress-bar { flex: 1; height: 9px; background: #e4e9f5; border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--grad); transition: width .3s ease; }
.quiz-card { padding: 20px; min-height: 200px; }
.q-index { font-size: 13px; color: var(--sub); margin-bottom: 8px; }
.q-text { font-size: 17px; font-weight: 800; line-height: 1.6; margin-bottom: 18px; }
.options { display: grid; gap: 12px; }
.option { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 2px solid var(--border); border-radius: 13px; cursor: pointer; background: #fff; transition: all .12s ease; }
.option:active { transform: scale(.99); }
.option .tag { width: 30px; height: 30px; border-radius: 50%; background: #eef2ff; color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }
.option .otext { font-size: 15px; flex: 1; }
.option.correct { border-color: var(--green); background: #eafaf1; }
.option.correct .tag { background: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: #fdecea; }
.option.wrong .tag { background: var(--red); color: #fff; }
.option.selected { border-color: var(--primary); background: #f3f6ff; }
.option.selected .tag { background: var(--primary); color: #fff; }
.option.disabled { pointer-events: none; }
.explain { margin-top: 16px; padding: 14px; border-radius: 13px; background: #fff8ec; border: 1px solid #ffe3b0; font-size: 14px; color: #6b5526; display: none; }
.explain.show { display: block; }
.explain .ex-title { font-weight: 800; color: #c07813; margin-bottom: 4px; }

.quiz-nav { display: flex; gap: 12px; margin-top: 18px; }
.nav-btn { flex: 1; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: #fff; font-size: 15px; font-weight: 700; cursor: pointer; color: var(--text); }
.nav-btn.primary { background: var(--grad); color: #fff; border: 0; }
.nav-btn.disabled { opacity: .4; pointer-events: none; }
.swipe-hint { text-align: center; color: #b4bdcd; font-size: 12px; margin-top: 12px; }

/* 结果页 */
.score-box { text-align: center; padding: 8px 0 16px; }
.score-num { font-size: 46px; font-weight: 800; color: var(--primary); }
.score-num .small { font-size: 18px; color: var(--sub); font-weight: 700; }
.score-sub { font-size: 14px; color: var(--sub); margin-top: 4px; }
.result-list { display: grid; gap: 12px; margin-top: 16px; }
.result-item { background: var(--card); border-radius: 15px; padding: 16px; border-left: 5px solid var(--border); box-shadow: var(--shadow); }
.result-item.right { border-left-color: var(--green); }
.result-item.wrong { border-left-color: var(--red); }
.ri-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ri-q { font-size: 15px; font-weight: 700; line-height: 1.5; flex: 1; padding-right: 10px; }
.ri-badge { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 12px; flex-shrink: 0; }
.ri-badge.right { background: #eafaf1; color: var(--green); }
.ri-badge.wrong { background: #fdecea; color: var(--red); }
.ri-line { font-size: 13px; margin-top: 6px; }
.ri-line .lab { color: var(--sub); }
.ri-ans.green { color: var(--green); font-weight: 700; }
.ri-ans.red { color: var(--red); font-weight: 700; }
.ri-explain { font-size: 13px; color: #6b5526; background: #fff8ec; border: 1px solid #ffe3b0; border-radius: 11px; padding: 10px; margin-top: 8px; }
.result-actions { margin-top: 22px; }

/* 表单输入 */
.text-input { width: 100%; padding: 13px 14px; border: 1px solid var(--border); border-radius: 13px; font-size: 15px; background: #fafbfe; }
.text-input:focus { border-color: var(--primary); background: #fff; outline: none; }
.code-row { display: flex; gap: 10px; }
.code-row .text-input { flex: 1; }
.code-btn { background: #eef2ff; color: var(--primary); border: 0; border-radius: 13px; padding: 0 16px; font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.code-btn:disabled { opacity: .5; }
.tip-hint { font-size: 12px; color: var(--amber); margin-top: 8px; }
.auth-link { margin-top: 16px; text-align: center; color: var(--primary); font-size: 14px; font-weight: 700; cursor: pointer; }
.auth-link:active { opacity: .6; }

/* 我的 */
.user-card { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--grad); color: #fff; font-size: 28px; display: flex; align-items: center; justify-content: center; }
.user-phone { font-size: 18px; font-weight: 800; }
.user-status { font-size: 13px; color: var(--sub); margin-top: 3px; }
.menu-list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; justify-content: space-between; padding: 17px 18px; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--border); cursor: pointer; }
.menu-item:last-child { border-bottom: 0; }
.menu-item:active { background: #f7f9ff; }
.chev { color: #c3cbd9; font-size: 20px; }

/* 历史记录 */
.history-list { display: grid; gap: 12px; }
.history-item { background: #fff; border-radius: 15px; padding: 16px; box-shadow: var(--shadow); }
.hi-top { display: flex; align-items: center; justify-content: space-between; }
.hi-name { font-weight: 800; font-size: 15px; }
.hi-mode { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 10px; }
.hi-mode.exam { background: #eef2ff; color: var(--primary); }
.hi-mode.practice { background: #eafaf1; color: var(--green); }
.hi-mid { font-size: 13px; color: #556; margin-top: 6px; }
.hi-mid b { color: var(--primary); font-size: 16px; }
.hi-time { font-size: 12px; color: var(--sub); margin-top: 4px; }

/* 我的题库状态 */
.st-badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 10px; }
.st-badge.pending { background: #fff3e0; color: var(--amber); }
.st-badge.ok { background: #eafaf1; color: var(--green); }
.st-badge.off { background: #eef0f4; color: #8893a7; }

/* 文件上传 */
.tpl-link { display: inline-block; color: var(--primary); font-size: 13px; font-weight: 700; text-decoration: none; margin-bottom: 10px; }
.file-drop { display: block; border: 2px dashed #c8d2ea; border-radius: 14px; padding: 26px; text-align: center; color: var(--sub); font-size: 14px; cursor: pointer; background: #fafbfe; transition: all .12s ease; }
.file-drop:active { background: #f0f4ff; border-color: var(--primary); }

/* PWA 安装提示 */
.install-tip { position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto; background: #1f2433; color: #fff; padding: 12px 16px; display: flex; gap: 10px; align-items: center; font-size: 13px; z-index: 50; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.install-tip button { background: var(--primary); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.install-tip .close { background: transparent; color: #aaa; }

/* ===== v3 新增组件 ===== */

/* 标签 */
.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { border: 1px solid var(--border); background: #fff; color: #556; border-radius: 18px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.bi-tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.bi-tag-mini { font-size: 11px; color: var(--primary); background: #eef2ff; padding: 1px 8px; border-radius: 9px; }
.rank-entry { text-align: center; color: var(--amber); font-size: 13px; font-weight: 700; padding: 6px 0 10px; cursor: pointer; }

/* 头像 */
.avatar-img { width: 56px; height: 56px; border-radius: 50%; background: #eef2ff; }
.avatar-big { width: 76px; height: 76px; border-radius: 50%; background: #eef2ff; }
.profile-avatar-row { display: flex; align-items: center; gap: 18px; margin: 14px 0; }
.sys-avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.sys-avatar { width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.sys-avatar:active { border-color: var(--primary); }
.points-pill { background: #fff4d6; color: var(--amber); font-weight: 800; padding: 6px 12px; border-radius: 16px; font-size: 13px; }

/* 分段切换（seg） */
.seg { display: flex; background: #fff; border-radius: 16px; padding: 4px; margin-bottom: 14px; box-shadow: var(--shadow); }
.seg-item { flex: 1; text-align: center; padding: 10px 0; font-size: 14px; color: var(--sub); border-radius: 12px; cursor: pointer; border: 0; background: transparent; }
.seg-item.active { background: var(--grad); color: #fff; font-weight: 700; }

/* 排行榜 */
.rank-list { display: grid; gap: 10px; }
.rank-item { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.rank-item.top { background: #fffdf5; border: 1px solid #ffe2a8; }
.rank-no { width: 30px; font-weight: 800; text-align: center; font-size: 15px; color: var(--sub); }
.rank-avatar { width: 40px; height: 40px; border-radius: 50%; background: #eef2ff; }
.rank-name { flex: 1; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-pts { font-weight: 800; color: var(--primary); }

/* 留言 */
.cmt-box { display: none; margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 10px; }
.cmt-title { font-size: 13px; font-weight: 700; color: var(--sub); margin-bottom: 10px; }
.cmt-empty { font-size: 13px; color: var(--sub); padding: 10px 0; }
.cmt { display: flex; gap: 10px; margin-bottom: 14px; }
.cmt-avatar { width: 34px; height: 34px; border-radius: 50%; background: #eef2ff; flex-shrink: 0; }
.cmt-main { flex: 1; min-width: 0; }
.cmt-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.cmt-nick { font-weight: 700; font-size: 13px; color: var(--primary); }
.cmt-replyto { font-size: 12px; color: var(--sub); }
.cmt-time { font-size: 11px; color: #b4bdcd; }
.cmt-content { font-size: 14px; margin-top: 4px; word-break: break-word; }
.cmt-reply-btn { font-size: 12px; color: var(--sub); margin-top: 4px; cursor: pointer; }
.cmt.reply { margin-top: 10px; margin-left: 24px; padding-left: 10px; border-left: 2px solid var(--border); }
.cmt-input { display: flex; gap: 10px; margin-top: 8px; }
.cmt-input .text-input { flex: 1; }
.cmt-input .mini-btn { flex-shrink: 0; }

/* 结果内操作 */
.ri-actions { display: flex; gap: 8px; margin-top: 10px; }
.mini-btn.warn { background: #fdecea; color: var(--red); }
.ex-actions { margin-top: 10px; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(20,26,46,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-mask.hidden { display: none; }
.modal { background: #fff; border-radius: 18px; padding: 20px; width: 100%; max-width: 420px; }
.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 14px; text-align: center; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .ghost-btn, .modal-actions .primary-btn { margin-top: 0; }
.textarea { width: 100%; min-height: 160px; border: 1px solid var(--border); border-radius: 13px; padding: 12px 14px; font-size: 15px; font-family: inherit; resize: vertical; background: #fafbfe; }

/* 文章 */
.article-item { background: #fff; border-radius: 16px; padding: 16px; box-shadow: var(--shadow); cursor: pointer; margin-bottom: 12px; }
.art-title { font-size: 16px; font-weight: 800; }
.art-excerpt { font-size: 13px; color: var(--sub); margin: 6px 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.art-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--sub); }
.art-avatar { width: 20px; height: 20px; border-radius: 50%; background: #eef2ff; }
.dot { color: #c3cbd9; }
.art-detail-title { margin: 0 0 10px; font-size: 20px; }
.art-content { font-size: 15px; line-height: 1.8; margin-top: 14px; white-space: pre-wrap; word-break: break-word; }
.bank-link { color: var(--primary); font-weight: 700; text-decoration: underline; cursor: pointer; }

/* 底部导航栏 */
#tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto; background: #fff; border-top: 1px solid var(--border); display: flex; z-index: 60; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(40,60,130,.06); }
#tabbar.hidden { display: none; }
.tab-item { flex: 1; background: transparent; border: 0; padding: 8px 0 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #9aa4b8; }
.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 600; }
.tab-item.active { color: var(--primary); }
.tab-item.active .tab-label { font-weight: 800; }

/* 底部导航占位，避免内容被遮挡 */
.screen { padding-bottom: 90px; }

/* 答题页留言板 */
.quiz-cmt { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }

/* ===== 分页提示 ===== */
.page-info { font-size: 12px; color: var(--sub); padding: 2px 2px 8px; }
.load-end { text-align: center; color: #b3bccd; font-size: 12px; padding: 10px 0 4px; }

/* ===== 题目配图 ===== */
.q-image { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 0 auto 14px; background: #f4f6fb; }
.q-image.small { max-height: 160px; margin: 8px 0; }

/* ===== 多选题 ===== */
.option .tick { width: 30px; height: 30px; border-radius: 8px; background: #eef2ff; color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; flex-shrink: 0; }
.option.selected .tick { background: var(--primary); color: #fff; }
.option.correct .tick { background: var(--green); color: #fff; }
.option.wrong .tick { background: var(--red); color: #fff; }
.multi-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding: 10px 14px; background: #f3f6ff; border-radius: 12px; font-size: 13px; color: var(--sub); font-weight: 700; }
.multi-bar .mini-btn[disabled] { opacity: .5; }
.bi-tag.multi { background: #8b5cf6; }

/* ===== 我的题库操作按钮 ===== */
.bi-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ===== 题库编辑页 ===== */
.mode-group.three .mode-btn { flex: 1; padding: 10px 6px; text-align: center; }
.mode-group.three .mode-t { font-size: 14px; }
.opt-in { margin-bottom: 8px; }
.ans-chip { border: 1px solid var(--border); background: #fff; color: #556; border-radius: 12px; padding: 8px 16px; font-size: 14px; cursor: pointer; font-weight: 700; min-width: 56px; }
.ans-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.img-preview { margin-top: 10px; }
.img-preview img { max-width: 100%; max-height: 180px; border-radius: 10px; display: block; margin-bottom: 6px; }
.q-edit-item { border-bottom: 1px solid #f0f2f7; padding: 12px 0; }
.qe-q { font-size: 15px; font-weight: 700; line-height: 1.5; }
.qe-opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.opt-mini { font-size: 12px; color: var(--sub); background: #f4f6fb; padding: 2px 8px; border-radius: 8px; }
.opt-mini.right { color: var(--green); background: #eafaf1; font-weight: 700; }
.qe-ans { font-size: 12px; color: var(--green); font-weight: 700; margin-bottom: 4px; }
