/* ============ 设计系统 ============ */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #6b7280;
  --line: #e5e9f2;
  --bg: #f4f6fb;
  --card: #ffffff;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef0ff;
  --ok: #10b981;
  --ok-soft: #e8faf3;
  --warn: #f59e0b;
  --warn-soft: #fff7e6;
  --danger: #ef4444;
  --danger-soft: #feecec;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow: 0 8px 24px rgba(15, 23, 42, .08);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, .16);
  --r: 14px;
  --r-lg: 20px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased; font-size: 15px; line-height: 1.5;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd6e4; border-radius: 8px; border: 2px solid var(--bg); }
::selection { background: #c7d2fe; }

/* ============ 通用组件 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line);
  background: #fff; color: var(--ink-2); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: .18s; white-space: nowrap; user-select: none;
}
.btn:hover { border-color: #cbd5e1; background: #fbfcfe; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(180deg, #5b52f0, #4f46e5); color: #fff; border-color: #4f46e5; box-shadow: 0 4px 14px rgba(79, 70, 229, .3); }
.btn-primary:hover { background: linear-gradient(180deg, #6a61f5, #5550e8); border-color: #5550e8; }
.btn-ok { background: linear-gradient(180deg, #12c48f, #0ea97b); color: #fff; border-color: #0ea97b; box-shadow: 0 4px 14px rgba(16, 185, 129, .28); }
.btn-ok:hover { background: #0ea97b; }
.btn-warn { background: #fff; color: #b45309; border-color: #fcd9a8; }
.btn-warn:hover { background: var(--warn-soft); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #eef2f9; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 15.5px; border-radius: 13px; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn .ic { font-size: 16px; line-height: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.pad { padding: 20px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.center { display: flex; align-items: center; justify-content: center; }
.pill { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 999px; background: #eef2f9; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.pill-ok { background: var(--ok-soft); color: #047857; }
.pill-warn { background: var(--warn-soft); color: #b45309; }
.pill-danger { background: var(--danger-soft); color: #b91c1c; }
.pill-brand { background: var(--brand-soft); color: #4338ca; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; background: #fff;
  padding: 10px 13px; outline: none; transition: .15s; font-size: 14.5px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3.5px rgba(99, 102, 241, .14); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.hint { font-size: 12px; color: var(--muted); }

/* ============ 公式排版 ============ */
.math { font-family: "Times New Roman", "Songti SC", "STSong", serif; font-size: 1.06em; }
.math-block { display: block; text-align: center; margin: 6px 0; }
.mvar { font-style: italic; }
.mtext { font-family: var(--font); font-style: normal; }
.mfrac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 2px; line-height: 1.15; }
.mfrac .mnum { border-bottom: 1.3px solid currentColor; padding: 0 3px; }
.mfrac .mden { padding: 0 3px; }
.msqrt { white-space: nowrap; }
.msqrt-body { border-top: 1.3px solid currentColor; padding: 0 2px; margin-left: -1px; }
.msqrt-idx { font-size: .72em; vertical-align: super; margin-right: 1px; }
.moverline { text-decoration: overline; }
.munderline { text-decoration: underline; }
sup, sub { font-size: .72em; }

/* ============ 登录 ============ */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login-brand {
  background: radial-gradient(1200px 600px at 10% 10%, #6d63f2 0%, #4f46e5 45%, #3730a3 100%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.login-brand::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cg fill='none' stroke='rgba(255,255,255,.09)' stroke-width='1.4'%3E%3Cpath d='M0 60h120M60 0v120'/%3E%3Ccircle cx='60' cy='60' r='28'/%3E%3C/g%3E%3C/svg%3E");
}
.login-brand h1 { font-size: clamp(28px, 3vw, 42px); margin: 0 0 14px; letter-spacing: -.5px; }
.login-brand p { font-size: 15.5px; opacity: .86; max-width: 460px; line-height: 1.9; margin: 0; }
.login-brand .feat { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.login-brand .feat span { background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); padding: 7px 13px; border-radius: 999px; font-size: 13px; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-form { width: 100%; max-width: 372px; }
.login-form h2 { margin: 0 0 6px; font-size: 24px; }
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .3px; }
.brand-mark .dot { width: 30px; height: 30px; border-radius: 9px; background: #fff; color: var(--brand); display: grid; place-items: center; font-size: 17px; }

/* ============ 应用骨架 ============ */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar {
  height: 62px; flex: none; display: flex; align-items: center; gap: 18px; padding: 0 20px;
  background: #fff; border-bottom: 1px solid var(--line); z-index: 20;
}
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.topbar .logo .mark {
  width: 34px; height: 34px; border-radius: 10px; color: #fff; display: grid; place-items: center; font-size: 18px;
  background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 4px 12px rgba(79, 70, 229, .32);
}
.nav { display: flex; gap: 4px; margin-left: 6px; }
.nav a {
  padding: 8px 14px; border-radius: 10px; color: var(--ink-2); font-weight: 600; font-size: 14px; transition: .16s;
}
.nav a:hover { background: #f1f4fa; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.main { flex: 1; overflow: auto; }
.page { max-width: 1240px; margin: 0 auto; padding: 26px 22px 60px; }
.page.wide { max-width: 1500px; }
.page-title { font-size: 22px; font-weight: 800; margin: 0 0 4px; letter-spacing: -.3px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }

/* ============ 首页 ============ */
.hero {
  border-radius: var(--r-lg); padding: 26px 28px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(120deg, #4f46e5, #7c3aed 55%, #2563eb);
  box-shadow: var(--shadow);
}
.hero h2 { margin: 0 0 6px; font-size: 24px; }
.hero p { margin: 0; opacity: .9; font-size: 14px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.lesson-card {
  padding: 18px; border-radius: var(--r); border: 1px solid var(--line); background: #fff;
  display: flex; flex-direction: column; gap: 12px; transition: .18s; cursor: pointer;
}
.lesson-card:hover { border-color: #c7d2fe; box-shadow: var(--shadow); transform: translateY(-2px); }
.lesson-card .code { font-family: ui-monospace, Menlo, monospace; font-size: 20px; font-weight: 800; letter-spacing: 3px; color: var(--brand); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.status-dot.live { background: var(--ok); box-shadow: 0 0 0 4px rgba(16, 185, 129, .16); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); } 50% { box-shadow: 0 0 0 7px rgba(16, 185, 129, .04); } }

/* ============ 大屏课堂 ============ */
body.live-mode .topbar { display: none; }
body.live-mode .main { overflow: hidden; }
.live { height: 100vh; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.live-head {
  height: 66px; flex: none; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
}
.live-head .code-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
  background: var(--brand-soft); color: var(--brand); border-radius: 11px; padding: 6px 13px; font-weight: 800;
}
.live-head .code-badge b { font-family: ui-monospace, Menlo, monospace; font-size: 21px; letter-spacing: 3px; }
.live-head .code-badge span { font-size: 10.5px; font-weight: 600; opacity: .75; letter-spacing: .5px; }
.stat-chip { display: flex; flex-direction: column; padding: 4px 14px; border-left: 1px solid var(--line); }
.stat-chip b { font-size: 21px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-chip span { font-size: 11.5px; color: var(--muted); }
.timer-chip {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 12px;
  background: #f1f5fb; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px;
}
.timer-chip.urgent { background: var(--danger-soft); color: #b91c1c; }

.live-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr); gap: 14px; padding: 14px 18px; min-height: 0; }

.stage {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg); display: flex; flex-direction: column;
  min-height: 0; overflow: hidden; box-shadow: var(--shadow-sm);
}
.stage-head { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-bottom: 1px dashed var(--line); }
.q-index { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; border-radius: 10px; padding: 4px 12px; font-weight: 800; font-size: 15px; }
.stage-body { flex: 1; overflow: auto; padding: 24px 30px 30px; }
.q-stem { font-size: clamp(19px, 1.55vw, 27px); line-height: 1.85; color: var(--ink); word-break: break-word; }
.q-stem img { max-width: 100%; border-radius: 12px; }
.q-options { display: grid; gap: 11px; margin-top: 22px; }
.q-opt {
  display: flex; align-items: flex-start; gap: 13px; padding: 13px 17px; border: 1.5px solid var(--line);
  border-radius: 13px; font-size: clamp(17px, 1.35vw, 22px); background: #fcfdff; transition: .16s;
}
.q-opt .key {
  flex: none; width: 30px; height: 30px; border-radius: 9px; background: #eef2fb; color: var(--ink-2);
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.q-opt.correct { border-color: #a7f3d0; background: var(--ok-soft); }
.q-opt.correct .key { background: var(--ok); color: #fff; }
.answer-note {
  margin-top: 22px; padding: 13px 16px; border-radius: 13px; background: #f8faff; border: 1px dashed #c7d2fe;
  font-size: 14px; color: var(--ink-2); line-height: 1.75;
}
.answer-note b { color: var(--brand); }

.students-panel { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.students-head { display: flex; align-items: center; gap: 8px; }
.sgrid { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 9px; align-content: start; padding: 2px; }
.scard {
  position: relative; background: #fff; border: 1.5px solid var(--line); border-radius: 13px; padding: 9px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 5px; cursor: pointer; transition: .16s; overflow: hidden;
}
.scard:hover { border-color: #c7d2fe; box-shadow: var(--shadow-sm); }
.scard .av {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  background: #eef2fb; color: var(--ink-2);
}
.scard .nm { font-size: 12.5px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard .st { font-size: 10.5px; color: var(--muted); }
.scard .thumb { position: absolute; inset: 0; opacity: 0; transition: .2s; }
.scard .thumb img { width: 100%; height: 100%; object-fit: cover; }
.scard.submitted { border-color: #86efac; background: #f6fffa; }
.scard.submitted .av { background: var(--ok); color: #fff; }
.scard.graded { border-color: #34d399; }
.scard.drafting { border-color: #a5b4fc; background: #f8f9ff; }
.scard.drafting .av { background: #e0e7ff; color: #4338ca; }
.scard.offline { opacity: .45; }
.scard.help { border-color: var(--warn); background: var(--warn-soft); }
.scard .score { position: absolute; top: 4px; right: 5px; font-size: 11px; font-weight: 800; color: var(--ok); }
.scard .live-dot { position: absolute; top: 6px; left: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand-2); }
.scard .live-dot.on { animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.live-foot {
  flex: none; background: #fff; border-top: 1px solid var(--line); padding: 12px 18px;
  display: flex; align-items: center; gap: 10px;
}
.progress-bar { flex: 1; min-width: 80px; height: 10px; border-radius: 999px; background: #eef2f9; overflow: hidden; display: flex; }
.progress-bar i { display: block; height: 100%; background: linear-gradient(90deg, #34d399, #10b981); transition: width .5s cubic-bezier(.22, 1, .36, 1); }

/* ============ 抽屉 / 弹窗 ============ */
.drawer-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .34); opacity: 0; transition: .22s; z-index: 60; }
.drawer-mask.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 96vw); background: #fff; z-index: 61;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transform: translateX(102%); transition: transform .28s cubic-bezier(.22, 1, .36, 1);
}
.drawer.show { transform: none; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.drawer-body { flex: 1; overflow: auto; padding: 18px 20px; }
.drawer-foot { padding: 13px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); padding: 0 20px; }
.tabs .tab { padding: 11px 4px; margin-right: 16px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: min(760px, 96vw); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { padding: 17px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; font-weight: 700; }
.modal-body { padding: 20px 22px; overflow: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ============ 表格 ============ */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 700; background: #fafbfe; position: sticky; top: 0; }
.table tr:hover td { background: #fafcff; }
.table .num { font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 7px; font-size: 11.5px; font-weight: 700; background: #eef2f9; color: var(--ink-2); }
.tag.ok { background: var(--ok-soft); color: #047857; }
.tag.warn { background: var(--warn-soft); color: #b45309; }
.tag.bad { background: var(--danger-soft); color: #b91c1c; }

/* ============ 统计 ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 13px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; }
.kpi .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.bar-row { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.bar-track { flex: 1; height: 8px; background: #eef2f9; border-radius: 999px; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #818cf8, #4f46e5); }
.insight { display: flex; gap: 10px; padding: 11px 14px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--line); font-size: 13.5px; }
.insight.warn { background: var(--warn-soft); border-color: #fde68a; }
.insight.good { background: var(--ok-soft); border-color: #a7f3d0; }

/* ============ 回放播放器 ============ */
.player { position: relative; border-radius: 14px; overflow: hidden; background: #fff; border: 1px solid var(--line); }
.player canvas { display: block; width: 100%; height: auto; background: #fff; }
.player-bar { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-top: 1px solid var(--line); background: #fafbfe; }
.player-bar input[type=range] { flex: 1; accent-color: var(--brand); }

/* ============ 题库 ============ */
.bank-item { display: flex; gap: 14px; padding: 15px 18px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; align-items: flex-start; }
.bank-item:hover { border-color: #c7d2fe; }
.bank-item .idx { width: 30px; height: 30px; flex: none; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.bank-item .body { flex: 1; min-width: 0; }
.bank-item .stem-preview { color: var(--ink-2); font-size: 13.5px; line-height: 1.65; max-height: 46px; overflow: hidden; }

/* ============ 提示 ============ */
#toasts { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(-8px); transition: .28s;
}
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: #047857; }
.toast-warn { background: #b45309; }
.toast-error { background: #b91c1c; }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .5; }

.chk { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13.5px; user-select: none; }
.chk input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ============ 响应式 ============ */
@media (max-width: 1120px) {
  .live-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .students-panel { max-height: 34vh; }
}
@media (max-width: 720px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .topbar .nav { display: none; }
}
