:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e4e6eb;
  --text: #1b1f24;
  --muted: #6b7280;
  --brand: #1f6feb;
  --brand-dark: #1a5fd0;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 12px;
}

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

/* hidden 属性优先于任何 display 规则，否则 .modal{display:flex} 会盖掉它 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.view { display: none; min-height: 100vh; }
.view.active { display: block; }

/* ── 登录 ───────────────────────────── */
.login-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 56px 24px 40px;
  text-align: center;
}

.login-wrap h1 {
  font-size: 24px;
  margin: 0 0 8px;
  letter-spacing: .5px;
}

.sub { color: var(--muted); font-size: 13px; margin: 0 0 28px; line-height: 1.6; }

.qr-box {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-box img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }

.qr-mask {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.qr-status { font-size: 13px; color: var(--muted); margin: 0 0 12px; min-height: 20px; }
.qr-status.ok { color: var(--ok); }
.qr-status.err { color: var(--bad); }

.account-list { margin-top: 32px; text-align: left; }
.account-list h3 { font-size: 13px; color: var(--muted); font-weight: 500; margin: 0 0 10px; }

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}

.account-item:active { background: #f0f2f5; }
.account-item .name { font-weight: 600; font-size: 14px; }
.account-item .meta { font-size: 12px; color: var(--muted); }
.account-item .grow { flex: 1; min-width: 0; }
.account-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }

/* ── 通用 ───────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s;
}

.btn:active { background: #eef0f3; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 0; font-size: 14px; }

/* ── 顶栏 ───────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; flex-direction: column; min-width: 0; }
.topbar-left.grow { flex: 1; }
.topbar-left strong { font-size: 15px; }
.topbar-left .muted { font-size: 12px; }
.topbar-right { margin-left: auto; }

/* ── 工具栏 ─────────────────────────── */
.toolbar {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
}

.toolbar input[type="search"] {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
}

.toolbar input:focus { outline: 2px solid rgba(31, 111, 235, .25); border-color: var(--brand); }

/* ── 课程列表 ───────────────────────── */
.course-list { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 10px; }

.course-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform .1s;
}

.course-card:active { transform: scale(.985); }
.course-card .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.course-card .title { font-weight: 600; font-size: 15px; flex: 1; min-width: 0; }
.course-card .cls { font-size: 12px; color: var(--muted); }
.course-card .meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  background: #eef2f8;
  color: #42526b;
  flex: none;
}
.badge.audit { background: #fff4e5; color: #b45309; }

/* ── 详情 ───────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.stat { background: var(--card); padding: 12px 8px; text-align: center; }
.stat .v { font-size: 18px; font-weight: 600; }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 2px; }

.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 57px;
  z-index: 9;
}

.tab {
  flex: 1;
  padding: 12px 8px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.tab-panel { padding: 16px; }

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

.num {
  width: 62px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
}

/* ── 进度 ───────────────────────────── */
.progress-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.bar { height: 6px; background: #eef0f3; border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.bar-fill { height: 100%; width: 0; background: var(--brand); border-radius: 3px; transition: width .3s; }
.bar-fill.ok { background: var(--ok); }
.bar-fill.bad { background: var(--bad); }

.progress-meta { font-size: 13px; color: var(--muted); }

.log {
  margin: 10px 0 0;
  padding: 10px;
  background: #0f1115;
  color: #c9d1d9;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── 叶子列表 ───────────────────────── */
.leaf-list { display: flex; flex-direction: column; gap: 8px; }

.leaf {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.leaf .grow { flex: 1; min-width: 0; }
.leaf .t { font-size: 14px; margin-bottom: 3px; }
.leaf .s { font-size: 12px; color: var(--muted); }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; flex: none; }
.pill.done { background: #e7f6ec; color: var(--ok); }
.pill.todo { background: #fdeaea; color: var(--bad); }
.pill.watching { background: #fff4e5; color: var(--warn); }
.pill.na { background: #eef0f3; color: var(--muted); }
.pill.partial { background: #fff4e5; color: var(--warn); }

.mini-bar { height: 4px; background: #eef0f3; border-radius: 2px; margin-top: 6px; overflow: hidden; }
.mini-bar > i { display: block; height: 100%; background: var(--ok); }

/* ── 弹层 ───────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--card);
  width: 100%;
  max-width: 680px;
  max-height: 86vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
}

@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}

.modal-body { padding: 16px; overflow: auto; }

.problem {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.problem:last-child { border-bottom: 0; }
.problem .q { font-size: 14px; margin-bottom: 10px; line-height: 1.6; }
.problem .q .idx { color: var(--muted); margin-right: 6px; }
.problem .opt { font-size: 13px; padding: 6px 10px; border-radius: 7px; background: #f7f8fa; margin-bottom: 6px; }
.problem .opt.right { background: #e7f6ec; color: var(--ok); font-weight: 600; }
.problem .opt.mine { background: #fdeaea; color: var(--bad); }
.problem .tag { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Toast ──────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(20, 22, 26, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
  max-width: 84vw;
  text-align: center;
}

@media (min-width: 720px) {
  .course-list { display: grid; grid-template-columns: 1fr 1fr; }
  .modal { align-items: center; }
  .modal-card { border-radius: 16px; max-height: 80vh; }
}
