:root {
  --brand: #2b6cf6;
  --brand-soft: #eaf1ff;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1a1f2b;
  --sub: #5b6478;
  --muted: #98a1b3;
  --line: #e9edf3;
  --green: #12b76a;
  --green-soft: #e8faf1;
  --red: #f04438;
  --red-soft: #fdecea;
  --orange: #f79009;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 40, 90, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: var(--text); }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }

.app { min-height: 100vh; padding: 0 0 calc(64px + var(--safe-bottom)); max-width: 760px; margin: 0 auto; }
.app.no-tab { padding-bottom: calc(20px + var(--safe-bottom)); }

/* ------------------------------- 顶部导航 ------------------------------- */
.navbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: rgba(242, 244, 247, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}
.navbar.solid { background: var(--brand); color: #fff; }
.navbar .nav-title { font-size: 17px; font-weight: 600; flex: 1; text-align: center; }
.navbar .nav-btn { font-size: 14px; color: var(--brand); min-width: 46px; }
.navbar.solid .nav-btn { color: #fff; }
.navbar .nav-btn.right { text-align: right; }

/* -------------------------------- 卡片 --------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin: 0 12px 12px;
}
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 18px 16px 8px; }
.section-title h3 { margin: 0; font-size: 15px; font-weight: 600; }
.section-title .more { font-size: 12px; color: var(--muted); }

/* -------------------------------- 登录 --------------------------------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 0 24px 60px; }
.brand-logo {
  width: 62px; height: 62px; border-radius: 18px; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
  margin: 0 auto 14px; letter-spacing: 1px; box-shadow: 0 8px 20px rgba(43,108,246,.32);
}
.login-title { text-align: center; font-size: 21px; font-weight: 700; letter-spacing: .5px; }
.login-sub { text-align: center; color: var(--muted); font-size: 12.5px; margin: 6px 0 22px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fbfcfe; outline: none; transition: border-color .15s, background .15s;
}
.input:focus { border-color: var(--brand); background: #fff; }
textarea.input { min-height: 90px; resize: vertical; line-height: 1.6; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 13px; border-radius: 10px; font-size: 15px; font-weight: 600;
  background: var(--brand); color: #fff; transition: opacity .15s, transform .06s;
}
.btn:active { transform: scale(.995); opacity: .92; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.line { background: #fff; border: 1px solid var(--line); color: var(--text); font-weight: 500; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 10px; }

.login-tips { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.8; }

/* ------------------------------- 首页 ---------------------------------- */
.hero {
  margin: 4px 12px 12px; padding: 18px; border-radius: 18px; color: #fff;
  background: linear-gradient(135deg, #2b6cf6, #5b8cff 60%, #7c5cf5);
  box-shadow: 0 10px 24px rgba(43,108,246,.26);
}
.hero h2 { margin: 0 0 2px; font-size: 19px; }
.hero .hero-sub { font-size: 12.5px; opacity: .88; }
.hero-stats { display: flex; gap: 8px; margin-top: 16px; }
.hero-stat { flex: 1; background: rgba(255,255,255,.16); border-radius: 12px; padding: 10px; text-align: center; }
.hero-stat b { display: block; font-size: 19px; line-height: 1.2; }
.hero-stat span { font-size: 11.5px; opacity: .9; }

.notice {
  margin: 0 12px 12px; padding: 11px 14px; border-radius: 12px; background: #fff7e8;
  color: #8a5a00; font-size: 12.5px; display: flex; gap: 8px; align-items: flex-start;
}
.notice .tag { flex: none; font-weight: 700; color: var(--orange); }

.grid-subjects { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 0 12px; }
.subject-card {
  background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.subject-card .subj-name { font-size: 15px; font-weight: 600; }
.subject-card .subj-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.subject-card .subj-bar { height: 5px; border-radius: 3px; background: #eef1f6; margin-top: 12px; overflow: hidden; }
.subject-card .subj-bar i { display: block; height: 100%; border-radius: 3px; }
.subject-card .subj-dot { position: absolute; right: -18px; top: -18px; width: 66px; height: 66px; border-radius: 50%; opacity: .1; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 12px; }
.quick-item { background: var(--card); border-radius: var(--radius); padding: 14px 8px; text-align: center; box-shadow: var(--shadow); }
.quick-item .q-ico { font-size: 21px; }
.quick-item .q-label { font-size: 12.5px; margin-top: 4px; color: var(--sub); }

/* ------------------------------- 科目页 -------------------------------- */
.chapter-item {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
  border-bottom: 1px solid var(--line); background: #fff;
}
.chapter-item:last-child { border-bottom: none; }
.chapter-item .ch-name { flex: 1; font-size: 14px; }
.chapter-item .ch-count { font-size: 12px; color: var(--muted); }
.chapter-list { background: #fff; border-radius: var(--radius); margin: 0 12px 12px; overflow: hidden; box-shadow: var(--shadow); }

/* ------------------------------- 练习页 -------------------------------- */
.practice-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px 6px; font-size: 12.5px; color: var(--muted); }
.pill { padding: 2px 9px; border-radius: 20px; background: var(--brand-soft); color: var(--brand); font-size: 11.5px; }
.pill.gray { background: #eef1f6; color: var(--sub); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: var(--green-soft); color: var(--green); }

.q-stem { font-size: 16px; line-height: 1.7; margin: 6px 0 14px; white-space: pre-wrap; }
.option {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #fbfcfe; margin-bottom: 10px; transition: all .15s; align-items: flex-start;
}
.option .opt-key {
  flex: none; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 600; color: var(--sub);
}
.option .opt-text { flex: 1; font-size: 14.5px; line-height: 1.55; }
.option.selected { border-color: var(--brand); background: var(--brand-soft); }
.option.selected .opt-key { background: var(--brand); border-color: var(--brand); color: #fff; }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.correct .opt-key { background: var(--green); border-color: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .opt-key { background: var(--red); border-color: var(--red); color: #fff; }
.option.disabled { opacity: .95; }

.analysis { margin-top: 4px; padding: 12px 14px; border-radius: 12px; background: #f7f9fc; border: 1px solid var(--line); font-size: 13.5px; line-height: 1.7; white-space: normal; }
.analysis .ans-line { font-weight: 600; margin-bottom: 6px; }
.analysis .ans-line.ok { color: var(--green); }
.analysis .ans-line.no { color: var(--red); }

.practice-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; gap: 10px; padding: 10px 14px calc(10px + var(--safe-bottom));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line); backdrop-filter: blur(6px);
  max-width: 760px; margin: 0 auto;
}
.practice-footer .btn { flex: 1; }

/* ------------------------------- 考试页 -------------------------------- */
.exam-timer {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); font-size: 13px;
}
.exam-timer .clock { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }
.exam-timer .clock.warn { color: var(--red); }
.sheet-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.sheet-cell { padding: 8px 0; text-align: center; border-radius: 8px; background: #f2f4f7; font-size: 13px; }
.sheet-cell.done { background: var(--brand-soft); color: var(--brand); }
.sheet-cell.wrong { background: var(--red-soft); color: var(--red); }
.sheet-cell.right { background: var(--green-soft); color: var(--green); }

.score-ring { width: 120px; height: 120px; border-radius: 50%; margin: 6px auto 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
.score-ring b { font-size: 30px; line-height: 1; }
.score-ring span { font-size: 12px; opacity: .9; margin-top: 4px; }
.result-stats { display: flex; justify-content: space-around; text-align: center; margin-top: 10px; }
.result-stats b { display: block; font-size: 17px; }
.result-stats span { font-size: 11.5px; color: var(--muted); }

/* -------------------------------- 我的 --------------------------------- */
.me-header { display: flex; align-items: center; gap: 14px; padding: 18px 16px; }
.avatar {
  width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg,#2b6cf6,#7c5cf5);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700;
}
.me-name { font-size: 17px; font-weight: 600; }
.me-sub { font-size: 12.5px; color: var(--muted); }
.menu-list { background: #fff; border-radius: var(--radius); margin: 0 12px 12px; overflow: hidden; box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.menu-item:last-child { border-bottom: none; }
.menu-item .m-arrow { margin-left: auto; color: var(--muted); font-size: 13px; }
.menu-item .m-val { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ------------------------------- 管理端 -------------------------------- */
.admin-tabs { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; }
.admin-tab { padding: 8px 14px; border-radius: 20px; background: #fff; font-size: 13px; color: var(--sub); white-space: nowrap; }
.admin-tab.active { background: var(--brand); color: #fff; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 0 12px; }
.stat-box { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat-box b { display: block; font-size: 21px; }
.stat-box span { font-size: 12px; color: var(--muted); }
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 12px 12px; overflow-x: auto; }
table.tb { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 340px; }
table.tb.tb-wide { min-width: 620px; }
table.tb td.stem-cell { max-width: 340px; white-space: normal; word-break: break-word; }
.meta-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.meta-text { font-size: 11.5px; color: var(--muted); }
table.tb th, table.tb td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tb th { background: #f8fafc; color: var(--sub); font-weight: 600; white-space: nowrap; }
table.tb tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn { color: var(--brand); font-size: 12.5px; }
.link-btn.danger { color: var(--red); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; font-size: 13px; color: var(--sub); }

/* ------------------------------- 底部标签 ------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom); backdrop-filter: blur(8px);
  max-width: 760px; margin: 0 auto;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--muted); }
.tab .tab-ico { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--brand); font-weight: 600; }
.tab.active .tab-ico { filter: none; opacity: 1; }

/* ------------------------------- 通用提示 ------------------------------ */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(10px);
  background: rgba(24,30,45,.92); color: #fff; font-size: 13.5px; padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: all .22s; z-index: 100; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal { position: fixed; inset: 0; background: rgba(15,20,35,.45); z-index: 90; display: flex; align-items: flex-end; justify-content: center; }
.modal-box { background: #fff; width: 100%; max-width: 760px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + var(--safe-bottom)); max-height: 86vh; overflow-y: auto; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

.empty { text-align: center; color: var(--muted); font-size: 13.5px; padding: 40px 20px; }
.loading { text-align: center; color: var(--muted); padding: 30px; font-size: 13px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -4px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (min-width: 761px) {
  body { background: #e9edf4; }
  .app { background: var(--bg); box-shadow: 0 0 40px rgba(20,40,90,.08); min-height: 100vh; }
  .grid-subjects { grid-template-columns: repeat(3, 1fr); }
}
