:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #e5e9f2;
  --brand: #2563eb;
  --brand-soft: #eef3ff;
  --good: #16a34a;
  --good-soft: #e9f8ef;
  --bad: #dc2626;
  --bad-soft: #fdeceb;
  --warn: #b45309;
  --r: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 8px 24px rgba(17, 24, 39, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
[hidden] { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { display: flex; align-items: center; gap: 8px; min-height: 58px; flex-wrap: wrap; row-gap: 6px; }
.logo { font-size: 16px; font-weight: 600; letter-spacing: .2px; white-space: nowrap; }
.topbar-in button { white-space: nowrap; }
.logo span { color: var(--brand); }
.spacer { flex: 1; }
.who { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

/* ---------- 通用 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.pad { padding: 18px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 12px; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }

button {
  font: inherit; cursor: pointer; border: 0; border-radius: 12px;
  padding: 12px 18px; background: var(--brand); color: #fff;
  transition: transform .06s ease, filter .15s ease;
}
button:active { transform: scale(.985); }
button:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }

input, select {
  font: inherit; width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--ink); outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
label { font-size: 13px; color: var(--ink-2); display: block; margin-bottom: 6px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: var(--brand-soft); color: var(--brand);
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.plain { background: #f3f4f6; color: var(--ink-2); }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.login-card .mark {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 20px; margin-bottom: 14px;
}

/* ---------- 首页 ---------- */
.sec-title { font-size: 13px; font-weight: 500; color: var(--ink-3); margin: 18px 0 8px; letter-spacing: .3px; }
.hero { padding: 22px 0 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 4px; }
.stat { padding: 14px; text-align: center; }
.stat b { display: block; font-size: 22px; font-weight: 600; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--ink-3); }

/* 三种方式 */
.modes { display: grid; gap: 10px; }
.mode {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: #fff; color: var(--ink); border: 1.5px solid var(--line);
  border-radius: var(--r); padding: 14px 16px;
}
.mode.on { border-color: var(--brand); background: var(--brand-soft); }
.mode .mi {
  flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: #f2f4f8; color: var(--ink-2); font-size: 15px; font-weight: 600;
}
.mode.on .mi { background: var(--brand); color: #fff; }
.mode .mt { display: grid; gap: 2px; }
.mode .mt b { font-size: 15px; font-weight: 600; }
.mode .mt i { font-style: normal; font-size: 12px; color: var(--ink-2); line-height: 1.45; }
.cfg { margin-top: 10px; }

.seg { display: flex; background: #eceff5; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; background: transparent; color: var(--ink-2); padding: 9px 10px;
  border-radius: 9px; font-size: 14px;
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(17, 24, 39, .12); }
.seg button { white-space: nowrap; }

.chapters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chapter {
  text-align: left; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px;
  display: grid; gap: 6px; position: relative;
}
.chapter.on { border-color: var(--brand); background: var(--brand-soft); }
.chapter .no { font-size: 12px; color: var(--ink-3); }
.chapter .nm { font-size: 14px; font-weight: 500; line-height: 1.35; min-height: 38px; }
.chapter .cnt { font-size: 12px; color: var(--ink-3); }

.bar { height: 6px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

.start-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}

/* ---------- 答题 ---------- */
.quiz-top { position: sticky; top: 0; z-index: 15; background: var(--bg); padding: 10px 0 8px; }
.progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); }

.qcard { margin-top: 8px; padding: 20px; position: relative; }
.qmeta { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; padding-right: 34px; }

/* 收藏星标 */
.star {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--ink-3); font-size: 19px; line-height: 1;
  display: grid; place-items: center;
}
.star:hover { background: #f2f4f8; }
.star.on { color: #f59e0b; }

.tag {
  padding: 2px 8px; border-radius: 6px; background: var(--brand-soft);
  color: var(--brand); font-size: 11px; font-weight: 500;
}
.tag.rec { background: #eefaf3; color: var(--good); }
.tag.exam { background: #fff4e5; color: var(--warn); }

.opt .otext { flex: 1; }
.opt .mark {
  flex: none; align-self: center; font-size: 11px; color: var(--good);
  background: #fff; border: 1px solid #b7ebc9; border-radius: 999px; padding: 1px 7px;
}
.ansline {
  margin-top: 16px; padding: 12px 14px; border-radius: 12px;
  background: var(--good-soft); color: #14532d; font-size: 14px;
}
.ansline b { font-size: 16px; }
.stem { font-size: 17px; line-height: 1.72; font-weight: 500; }
.stem img, .opt img { max-width: 100%; max-height: 260px; display: block; margin: 8px 0; border-radius: 6px; }
.stem .katex, .opt .katex { font-size: 1.05em; }

.options { display: grid; gap: 10px; margin-top: 18px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
  text-align: left; padding: 14px 16px; border-radius: 12px;
  background: #fff; color: var(--ink); border: 1.5px solid var(--line);
  font-size: 15px; line-height: 1.6;
}
.opt .key {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: #f2f4f8; color: var(--ink-2); border: 1px solid var(--line);
}
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .key { background: var(--brand); color: #fff; border-color: var(--brand); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .key { background: var(--good); color: #fff; border-color: var(--good); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); color: #fff; border-color: var(--bad); }
.opt:disabled { opacity: 1; cursor: default; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 12px; font-size: 14px; }
.feedback.ok { background: var(--good-soft); color: #14532d; }
.feedback.no { background: var(--bad-soft); color: #7f1d1d; }
.feedback b { font-weight: 600; }

.quiz-actions { display: flex; gap: 10px; margin-top: 16px; }
.quiz-actions button { flex: 1; padding: 12px 10px; white-space: nowrap; }

/* 答题卡 */
.badge {
  display: inline-block; margin-left: 4px; padding: 0 6px;
  border-radius: 999px; background: #eef1f6; color: var(--ink-2);
  font-size: 11px; font-weight: 500; line-height: 17px; vertical-align: 1px;
}
.sheet-mask {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .35);
  display: grid; place-items: end center; z-index: 50;
}
.sheet {
  width: 100%; max-width: 560px; background: #fff; border-radius: 20px 20px 0 0;
  padding: 20px; max-height: 82vh; overflow: auto;
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 4px; background: #f3f4f6; border: 1px solid var(--line); display: inline-block; }
.dot.done { background: var(--brand-soft); border-color: #c7d7fe; }
.dot.ok { background: var(--good-soft); border-color: #b7ebc9; }
.dot.no { background: var(--bad-soft); border-color: #f6c9c5; }
.dot.cur { background: #fff; border: 2px solid var(--brand); }
.sheet-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 14px 0 16px; }
.sheet-grid button {
  aspect-ratio: 1; padding: 0; background: #f3f4f6; color: var(--ink-2);
  border-radius: 10px; font-size: 13px; border: 1.5px solid transparent;
}
.sheet-grid button.done { background: var(--brand-soft); color: var(--brand); border-color: #dbe6ff; }
.sheet-grid button.ok { background: var(--good-soft); color: var(--good); border-color: #c9efd6; }
.sheet-grid button.no { background: var(--bad-soft); color: var(--bad); border-color: #f7ccc8; }
.sheet-grid button.cur { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37, 99, 235, .18); }
.sheet-foot { gap: 10px; }
.sheet-foot button { flex: 1; }
@media (min-width: 760px) {
  .sheet-mask { place-items: center; }
  .sheet { border-radius: 18px; box-shadow: 0 20px 60px rgba(17, 24, 39, .22); }
  .sheet-grid { grid-template-columns: repeat(8, 1fr); }
}

/* ---------- 成绩 ---------- */
.score-hero { text-align: center; padding: 28px 20px; }
.score-num { font-size: 46px; font-weight: 600; line-height: 1; }
.score-num small { font-size: 16px; color: var(--ink-3); font-weight: 400; }
.review { display: grid; gap: 8px; }
.review-item { padding: 12px 14px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.review-item .ans { font-size: 13px; margin-top: 4px; }

.seg-sm { padding: 3px; }
.seg-sm button { padding: 6px 12px; font-size: 12px; }

/* 题目条目：成绩页 / 错题本 / 收藏 */
.qitem {
  position: relative; padding: 12px 14px; border-radius: 12px;
  background: #fff; border: 1px solid var(--line); border-left-width: 3px;
}
.qitem.ok { border-left-color: var(--good); }
.qitem.no { border-left-color: var(--bad); }
.qitem-head { display: flex; align-items: center; gap: 8px; }
.qitem-head .ord {
  width: 20px; height: 20px; border-radius: 6px; background: #f2f4f8;
  display: inline-grid; place-items: center; font-size: 11px; color: var(--ink-2); flex: none;
}
.qitem-head .star { position: static; width: 26px; height: 26px; font-size: 15px; }
.qitem-stem { font-size: 14px; line-height: 1.6; margin-top: 6px; }
.qitem-ans { font-size: 12px; margin-top: 6px; color: var(--ink-2); }
.qitem-ans b { font-weight: 600; }
.qitem-ans .good, .qitem-ans b.good { color: var(--good); }
.qitem-ans .bad { color: var(--bad); }

/* ---------- 错题本 ---------- */
.wsum {
  margin-top: 16px; padding: 18px;
  background: linear-gradient(160deg, #f5f8ff 0%, #eef3ff 100%);
  border-color: #dfe8ff;
}
.wsum-row { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.wsum-row > div { display: grid; gap: 2px; }
.wsum-row b { font-size: 26px; font-weight: 600; line-height: 1.15; }
.wsum-row span { font-size: 12px; color: var(--ink-2); }
.wsum-row b small { font-size: 12px; font-weight: 400; color: var(--ink-2); margin-left: 2px; }
.wsum-tip { margin: 14px 0 0; font-size: 12px; color: var(--ink-2); line-height: 1.55; }

.wcat {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
}
.wcat-no { font-size: 12px; color: var(--ink-3); width: 22px; flex: none; }
.wcat-nm { flex: 1; font-size: 14px; font-weight: 500; }
.wcat-n { font-size: 12px; color: var(--ink-2); }
.chev { color: var(--ink-3); font-size: 18px; line-height: 1; }

/* ---------- 教师端 ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.kpi { padding: 16px; }
.kpi b { display: block; font-size: 26px; font-weight: 600; line-height: 1.2; }
.kpi span { font-size: 12px; color: var(--ink-3); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

.tbl-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 500; color: var(--ink-2); font-size: 12px; background: #fafbfd; position: sticky; top: 0; }
tr.warn td { background: #fff7ed; }
.mini-bar { width: 64px; height: 6px; background: #eef1f6; border-radius: 999px; overflow: hidden; display: inline-block; vertical-align: middle; }
.mini-bar > i { display: block; height: 100%; background: var(--good); }
.mini-bar.low > i { background: var(--bad); }
.chap-row { display: grid; grid-template-columns: 140px 1fr 50px; gap: 10px; align-items: center; padding: 7px 0; font-size: 13px; }
.hard-item { padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.hard-item:last-child { border-bottom: 0; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; color: var(--ink-2); padding: 10px 12px; border-radius: 0; border-bottom: 2px solid transparent; font-size: 14px; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 99; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.on { opacity: 1; }

@media (max-width: 720px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .chapters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .chapter { padding: 11px; }
  .chapter .nm { min-height: 0; font-size: 13px; }
  .chapter .cnt { font-size: 11px; }
  .stem { font-size: 16px; }
  .wrap-wide { padding: 0 14px; }
  .chap-row { grid-template-columns: 104px 1fr 42px; }
  #two-col { grid-template-columns: 1fr !important; }
  .score-num { font-size: 40px; }
  .topbar-in { min-height: 52px; }
  .who { max-width: 96px; font-size: 12px; }
  .topbar .pill { display: none; }
  .topbar-in .btn-sm { padding: 7px 10px; }
  .tbl-wrap { -webkit-overflow-scrolling: touch; }
}

/* 窄屏（360px 级别的安卓机） */
@media (max-width: 380px) {
  .wrap { padding: 0 12px; }
  .topbar-in { gap: 6px; }
  .topbar-in .btn-sm { padding: 7px 8px; font-size: 12px; }
  .logo { font-size: 15px; }
  .quiz-actions { gap: 8px; }
  .quiz-actions button { padding: 11px 6px; font-size: 13px; }
  .quiz-actions .badge { margin-left: 2px; padding: 0 4px; font-size: 10px; }
  .progress { gap: 6px; }
  .progress .bar { width: 64px !important; }
  .stem { font-size: 15px; }
  .qcard { padding: 16px 14px; }
  .qitem-stem { font-size: 13px; }
  .sheet { padding: 16px; }
  .sheet-grid { gap: 8px; }
  .wsum-row b { font-size: 23px; }
  .mode { padding: 12px; }
  .mode .mt i { font-size: 11px; }
}

/* 文本按钮（登录页切换等） */
.linkish {
  background: none; border: 0; padding: 4px 0; color: var(--ink-3);
  font-size: 12px; text-decoration: underline; text-underline-offset: 3px;
  text-align: center; width: 100%; cursor: pointer;
}
.linkish:active { color: var(--brand); }

/* ---------- 名单管理 ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px dashed #d5dbe6; border-radius: 14px; padding: 24px 16px; cursor: pointer;
  background: #fbfcfe; transition: .15s;
}
.drop.hover, .drop:active { border-color: var(--brand); background: var(--brand-soft); }
.drop b { font-size: 14px; color: var(--brand); }
.row-actions { display: flex; gap: 10px; margin-top: 12px; }
.row-actions button { flex: 1; }
.mini-input {
  width: 100%; min-width: 96px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px; background: #fff;
}
.mini-input:focus { outline: 2px solid rgba(37, 99, 235, .18); border-color: var(--brand); }
.mini-btn {
  padding: 5px 9px; font-size: 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink-2); margin-right: 6px; cursor: pointer; white-space: nowrap;
}
.mini-btn:active { background: #f3f5f9; }
.mini-btn.del { color: #c0392b; border-color: #f0d5d2; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: #eef1f6; color: var(--ink-2); white-space: nowrap; }
.tag.good { background: #e7f6ee; color: #1a7f4b; }
.tag.warn { background: #fdecea; color: #c0392b; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.pwd-cell { white-space: nowrap; }

/* ========== 手机端细化 ========== */
@media (max-width: 720px) {
  /* 顶栏：单行横向滚动，不再把“退出”挤到第二行 */
  .topbar-in { flex-wrap: nowrap; overflow-x: auto; gap: 6px; }
  .topbar-in::-webkit-scrollbar { display: none; }
  .topbar-in { scrollbar-width: none; }
  .topbar-in .spacer { flex: 0 0 6px; }
  .topbar-in .btn-sm { flex: 0 0 auto; }
  .logo { flex: 0 0 auto; }

  /* 首页给底部固定条让位，最后一行章节不再被遮 */
  #v-home { padding-bottom: 96px; }

  /* 答题页顶栏：退出与进度条对齐 */
  .quiz-top .btn-ghost { padding: 8px 12px; font-size: 13px; }

  /* 表格 → 卡片（教师端在手机上也能看完每列） */
  .stu-tbl thead { display: none; }
  .stu-tbl, .stu-tbl tbody, .stu-tbl tr, .stu-tbl td { display: block; width: 100%; }
  .stu-tbl tr {
    border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
    margin-bottom: 10px; background: #fff;
  }
  .stu-tbl td {
    border: 0; padding: 3px 0; white-space: normal; display: flex;
    align-items: baseline; gap: 10px; font-size: 13px;
  }
  .stu-tbl td::before {
    content: attr(data-l); color: var(--ink-3); font-size: 12px;
    min-width: 58px; flex: 0 0 58px;
  }
  .stu-tbl td[data-l=""]::before { display: none; }
  .stu-tbl td.mini-input-cell { display: block; }
  .stu-tbl .mini-input { min-width: 0; }
  .tbl-wrap { overflow: visible; }

  /* 名单页标题与按钮不再挤压 */
  #v-roster .card.pad > .between { flex-wrap: wrap; gap: 8px; }
  #v-roster .between h2 { font-size: 16px; }
}

@media (max-width: 380px) {
  .stat b { font-size: 20px; }
  .mode .mt i { font-size: 11.5px; }
  .sheet-grid { grid-template-columns: repeat(5, 1fr); }
}

.td-sub { margin-left: 6px; }
@media (max-width: 720px) { .td-sub { margin-left: 0; } }

/* 登录页居中，贴近老师之前那套界面 */
.login-card .mark { margin-left: auto; margin-right: auto; }
.login-card > h1, .login-card > p { text-align: center; }
.login-card > h1 { margin-bottom: 6px; }
