:root {
  --primary: #2f7bff;
  --primary-dark: #1e63e6;
  --green: #34a853;
  --red: #ea4335;
  --orange: #e8830c;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e5e8ef;
  --text: #23272f;
  --text2: #6b7280;
  --radius: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; background: var(--bg); color: var(--text); }
button { font-family: inherit; }

/* ===== 布局 ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 224px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid #f0f2f6; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #2f7bff, #6bc2ff); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 19px; font-weight: 700; }
.brand .btitle { font-size: 15.5px; font-weight: 700; }
.brand .bsub { font-size: 11.5px; color: var(--text2); margin-top: 1px; }
.sidebar nav { padding: 10px 10px; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; font-size: 14.5px; color: #414855; cursor: pointer; margin-bottom: 3px; transition: all .14s; }
.nav-item:hover { background: #f2f5fa; }
.nav-item.active { background: #eef4ff; color: var(--primary); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; font-size: 15px; }
.nav-item .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 9px; font-weight: 600; }
.nav-item .badge.gray { background: #dfe3ea; color: #6b7280; }
.side-foot { padding: 12px 16px 16px; border-top: 1px solid #f0f2f6; }
.side-foot .tip { font-size: 11.5px; color: #98a0ad; line-height: 1.6; }
.sync-badge { display: flex; align-items: center; gap: 6px; font-size: 11.5px; margin-bottom: 8px; padding: 5px 8px; border-radius: 6px; background: #f5f7fa; color: #8a929e; }
.sync-badge .dot { font-size: 11px; line-height: 1; }
.sync-badge.synced { background: #eefaf1; color: #2e9e5b; }
.sync-badge.syncing { background: #fff6e8; color: #c8871f; }
.sync-badge.error { background: #fdeeee; color: #d0453b; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 22px; position: sticky; top: 0; z-index: 20; }
.topbar h2 { font-size: 17px; font-weight: 700; }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 15px; }
.content { padding: 22px; flex: 1; }

/* ===== 通用组件 ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stats-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 20px; flex: 1; min-width: 132px; }
.stat-card .num { font-size: 25px; font-weight: 700; color: var(--primary); }
.stat-card .num.green { color: var(--green); }
.stat-card .num.red { color: var(--red); }
.stat-card .num.orange { color: var(--orange); }
.stat-card .label { font-size: 12.5px; color: var(--text2); margin-top: 2px; }
.section-title { font-size: 15.5px; font-weight: 700; margin: 20px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title .sub { font-size: 12.5px; font-weight: 400; color: var(--text2); }

.btn { padding: 8px 18px; border-radius: 8px; border: none; font-size: 13.5px; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #b9cffa; cursor: not-allowed; }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: var(--text2); }
.btn-ghost:hover { color: var(--primary); border-color: var(--primary); }
.btn-danger { background: #fff; border: 1px solid var(--border); color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: #fef3f2; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }

.pbar { height: 6px; background: #edf0f5; border-radius: 3px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #6bc2ff); border-radius: 3px; transition: width .3s; }
.pbar.green i { background: var(--green); }

.empty { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty .big { font-size: 42px; margin-bottom: 10px; opacity: .5; }

/* ===== 首页科目卡 ===== */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 14px; }
.subject-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: all .18s; }
.subject-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(47,123,255,.12); border-color: #bcd4ff; }
.subject-card .sname { font-size: 16px; font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.subject-card .sname .arrow { color: #c3c9d4; font-size: 15px; }
.subject-card .meta { font-size: 12px; color: var(--text2); display: flex; gap: 8px; margin-bottom: 11px; flex-wrap: wrap; }
.subject-card .meta .tag { background: #eef4ff; color: var(--primary); padding: 2px 8px; border-radius: 6px; }
.subject-card .meta .tag.multi { background: #fff4e8; color: var(--orange); }
.subject-card .meta .tag.err { background: #fdecea; color: var(--red); }
.subject-card .pinfo { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); margin-top: 7px; }

/* ===== 练习页 ===== */
.practice-wrap { display: flex; gap: 18px; align-items: flex-start; }
.prac-side { width: 306px; flex-shrink: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px; position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow-y: auto; }
.prac-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 13px; }
.prog-title { font-size: 14px; color: var(--text2); }
.prog-title b { color: var(--primary); font-size: 22px; }
.prog-legend { display: flex; gap: 12px; font-size: 12.5px; color: var(--text2); margin: 8px 0 13px; flex-wrap: wrap; }
.prog-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.un { background: #fff; border: 1.5px solid #c9cfda; }
.dot.ok { background: var(--green); }
.dot.no { background: var(--red); }
.dot.mid { background: #a9c4f7; }

.qgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 16px; }
.qcell { aspect-ratio: 1; border-radius: 50%; border: 1.5px solid #c9cfda; background: #fff; color: var(--text2); font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; transition: all .12s; user-select: none; }
.qcell:hover { border-color: var(--primary); color: var(--primary); }
.qcell.ok { background: var(--green); border-color: var(--green); color: #fff; }
.qcell.no { background: var(--red); border-color: var(--red); color: #fff; }
.qcell.mid { background: #a9c4f7; border-color: #a9c4f7; color: #fff; }
.qcell.cur { box-shadow: 0 0 0 3px rgba(47,123,255,.35); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.qcell.cur.ok, .qcell.cur.no, .qcell.cur.mid { color: #fff; }
.qcell.bk::after { content: "★"; position: absolute; top: -7px; right: -3px; font-size: 11px; color: #f5a623; text-shadow: 0 0 2px #fff; }

.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 2px; font-size: 13.5px; border-top: 1px solid #f0f2f6; }
.toggle-row:first-of-type { border-top: none; }
.switch { width: 40px; height: 22px; border-radius: 11px; background: #d5dbe5; position: relative; cursor: pointer; transition: background .18s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: left .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--primary); }
.switch.on::after { left: 20px; }

.qcard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; min-height: 400px; display: flex; flex-direction: column; }
.qcard-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.qtype-badge { background: #eef4ff; color: var(--primary); font-size: 12.5px; padding: 3px 11px; border-radius: 6px; font-weight: 600; }
.qtype-badge.multi { background: #fff4e8; color: var(--orange); }
.qsrc { font-size: 12.5px; color: var(--text2); }
.qcard-head .spacer { flex: 1; }
.star-btn { background: none; border: 1px solid var(--border); border-radius: 7px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; color: var(--text2); }
.star-btn.on { color: #f5a623; border-color: #f7d08b; background: #fffaf0; }
.qstem { font-size: 16.5px; line-height: 1.75; white-space: pre-wrap; margin-bottom: 20px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 15px; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; transition: all .13s; font-size: 15px; line-height: 1.6; }
.opt:hover { border-color: #bcd4ff; background: #f7faff; }
.opt .letter { font-weight: 700; color: var(--text2); flex-shrink: 0; width: 20px; }
.opt.selected { border-color: var(--primary); background: #f0f6ff; }
.opt.selected .letter { color: var(--primary); }
.opt.correct { border-color: var(--green); background: #effaf2; }
.opt.correct .letter { color: var(--green); }
.opt.wrong { border-color: var(--red); background: #fef1f0; }
.opt.wrong .letter { color: var(--red); }
.opt.locked { cursor: default; }
.opt.locked:hover { background: inherit; border-color: var(--border); }
.opt.locked.correct:hover { background: #effaf2; border-color: var(--green); }
.opt.locked.wrong:hover { background: #fef1f0; border-color: var(--red); }
.submit-row { margin-top: 15px; }

.exp-box { margin-top: 17px; background: #f8f9fc; border: 1px solid #eceff5; border-radius: 10px; padding: 14px 17px; font-size: 14px; line-height: 1.75; color: #444a55; }
.exp-box .exp-title { font-weight: 700; color: var(--text); margin-bottom: 5px; font-size: 13.5px; }
.verdict { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 6px; margin-left: 6px; }
.verdict.ok { color: var(--green); background: #effaf2; }
.verdict.no { color: var(--red); background: #fef1f0; }

.nav-bar { display: flex; gap: 11px; }
.btn-nav { flex: 1; padding: 12px; border-radius: 10px; font-size: 14.5px; cursor: pointer; border: none; transition: all .15s; }
.btn-prev { background: #e9edf5; color: var(--text); }
.btn-prev:hover { background: #dde3ee; }
.btn-next { background: var(--primary); color: #fff; }
.btn-next:hover { background: var(--primary-dark); }

/* ===== 考试 ===== */
.exam-setup { max-width: 640px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
.chips { display: flex; gap: 9px; flex-wrap: wrap; }
.chip { padding: 7px 16px; border: 1.5px solid var(--border); border-radius: 20px; font-size: 13.5px; cursor: pointer; background: #fff; transition: all .14s; }
.chip:hover { border-color: #bcd4ff; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.exam-timer { font-size: 15px; font-weight: 700; color: var(--red); }
.exam-result { text-align: center; padding: 12px 0 4px; }
.exam-result .score { font-size: 46px; font-weight: 700; color: var(--primary); }
.exam-result .score.pass { color: var(--green); }
.exam-result .score.fail { color: var(--red); }
.exam-result .desc { color: var(--text2); font-size: 14px; margin-top: 6px; }

/* ===== 统计 ===== */
.sub-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.sub-table th, .sub-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #f0f2f6; }
.sub-table th { color: var(--text2); font-weight: 600; font-size: 12.5px; }
.sub-table td.bar-cell { width: 170px; }
.trend-box { height: 170px; }
.record-list .rec { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid #f2f4f8; font-size: 13.5px; }
.record-list .rec:last-child { border-bottom: none; }
.record-list .rec .score { font-weight: 700; width: 62px; }

/* ===== 弹窗 / 提示 ===== */
.toast { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); background: rgba(30,35,45,.9); color: #fff; padding: 9px 20px; border-radius: 8px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 200; }
.toast.show { opacity: 1; }
.modal { position: fixed; inset: 0; background: rgba(20,25,35,.45); display: none; align-items: center; justify-content: center; z-index: 300; }
.modal.show { display: flex; }
.modal-box { background: #fff; border-radius: 14px; width: min(560px, 92vw); max-height: 84vh; display: flex; flex-direction: column; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 15.5px; font-weight: 700; }
.modal-body { padding: 18px 20px; overflow-y: auto; font-size: 14px; line-height: 1.7; }
.modal-foot { padding: 13px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; }

/* ===== 移动端底部标签栏 / 悬浮按钮（桌面隐藏） ===== */
body { -webkit-tap-highlight-color: transparent; }
button, .opt, .qcell, .switch, .chip, .tab { touch-action: manipulation; }
.tabbar { display: none; }
.grid-fab { display: none; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -240px; z-index: 50; transition: left .2s; box-shadow: 0 0 30px rgba(0,0,0,.12); }
  .sidebar.open { left: 0; }
  .menu-btn { display: block; padding: 8px 13px; font-size: 17px; }

  /* ---- 底部标签栏 ---- */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: #fff; border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 16px rgba(20,30,50,.06);
  }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; font-size: 10.5px; color: #8a929e; cursor: pointer; position: relative; }
  .tab .t-ico { font-size: 19px; line-height: 1; }
  .tab.on { color: var(--primary); font-weight: 600; }
  .t-badge { position: absolute; top: 3px; left: calc(50% + 4px); background: var(--red); color: #fff; font-size: 9.5px; min-width: 15px; height: 15px; line-height: 15px; border-radius: 8px; padding: 0 4px; text-align: center; font-weight: 600; }

  /* ---- 题号导航悬浮按钮 ---- */
  .grid-fab {
    display: block; position: fixed; right: 14px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 55;
    width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--primary); color: #fff; font-size: 19px;
    box-shadow: 0 6px 18px rgba(47,123,255,.4);
  }

  /* ---- 主内容让出底部空间 ---- */
  .content { padding: 14px 13px calc(84px + env(safe-area-inset-bottom)); }
  .topbar { height: 52px; padding: 0 14px; }
  .topbar h2 { font-size: 16px; }

  /* ---- 练习页：题目优先，题号面板收起 ---- */
  .practice-wrap { flex-direction: column; }
  .prac-main { order: 1; }
  .prac-side { order: 2; width: 100%; position: static; max-height: 60vh; overflow-y: auto; display: none; }
  .prac-side.open { display: block; }
  .qcard { min-height: auto; padding: 16px 14px; }
  .qstem { font-size: 16px; }

  /* ---- 触控目标加大 ---- */
  .opt { padding: 14px 15px; font-size: 15.5px; }
  .btn-nav { padding: 15px; font-size: 15.5px; }
  .btn { padding: 11px 20px; font-size: 14.5px; }
  .btn-sm { padding: 8px 14px; font-size: 13px; }
  .qgrid { grid-template-columns: repeat(6, 1fr); gap: 10px; }
  .qcell { font-size: 14px; }
  .chip { padding: 10px 18px; font-size: 14.5px; }
  .switch { width: 46px; height: 26px; }
  .switch::after { width: 22px; height: 22px; }
  .switch.on::after { left: 22px; }
  .toggle-row { padding: 13px 2px; font-size: 14.5px; }
  .star-btn { padding: 8px 14px; font-size: 13.5px; }

  /* ---- 统计表格窄屏 ---- */
  .sub-table td.bar-cell { width: 110px; }
  .exam-result .score { font-size: 40px; }
}
