:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2f6feb;
  --accent-soft: #eaf1fe;
  --danger: #cf3f3f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

/* .modal/.viewer 自己设了 display，必须压过它们，hidden 属性才生效 */
[hidden] { display: none !important; }

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

button, input, textarea { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .2px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, #2f6feb, #6ea2ff);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.off { background: #eef0f3; color: var(--muted); }

/* ---------- 按钮 ---------- */

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:hover { background: #f8fafc; border-color: #d3d8e0; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: default; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #2761d4; }

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.danger:hover { background: #b83636; }

.btn.ghost { background: transparent; }
.btn.small { padding: 5px 12px; font-size: 13px; }

/* ---------- 布局 ---------- */

.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.hint { color: var(--muted); font-size: 13px; margin: 0; }

.panel-tools { display: flex; align-items: center; gap: 10px; }

#autoBtn.on {
  color: #b42318;
  border-color: #f3c7c3;
  background: #fef3f2;
}

.ack {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 14px 0 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  font-size: 13.5px;
  line-height: 1.5;
  cursor: pointer;
}
.ack input { margin-top: 3px; flex: none; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 22px 4px; text-align: center; }

code {
  background: #eef1f5;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12.5px;
}

.inline-form { display: flex; gap: 8px; }

.inline-form input {
  width: 200px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 11px;
  background: #fbfcfd;
  outline: none;
}
.inline-form input:focus { border-color: var(--accent); background: #fff; }

/* ---------- 课堂卡片 ---------- */

.class-list { display: flex; flex-direction: column; gap: 10px; }

.class-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #fbfcfe);
}

.class-card .live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e5484d;
  box-shadow: 0 0 0 4px rgba(229, 72, 77, .14);
  animation: pulse 1.8s infinite;
  flex: none;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(229, 72, 77, .14); }
  50% { box-shadow: 0 0 0 7px rgba(229, 72, 77, .05); }
}

.class-body { flex: 1; min-width: 0; }
.class-name { font-weight: 600; margin-bottom: 2px; }
.class-meta { color: var(--muted); font-size: 12.5px; }

/* ---------- 课件卡片 ---------- */

.pres-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.pres-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.pres-card:hover { border-color: #c9d4e8; box-shadow: 0 6px 18px rgba(16, 24, 40, .06); }

.pres-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pres-meta { color: var(--muted); font-size: 12.5px; }

.pres-card .btn { margin-top: 10px; align-self: flex-start; }

/* ---------- 随堂习题 ---------- */

.problem-list { display: flex; flex-direction: column; gap: 12px; }

.problem-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px 17px;
  background: linear-gradient(180deg, #fff, #fbfcfe);
}

.problem-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.problem-type {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 10px;
}

.problem-status {
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 10px;
  background: #eef0f3;
  color: var(--muted);
  flex: none;
}
.problem-status.open { background: #ecfdf3; color: #067647; }
.problem-status.done { background: #eaf1fe; color: var(--accent); }
.problem-status.closed { background: #f2f4f7; color: #667085; }

.problem-title { font-weight: 600; line-height: 1.5; }
.problem-body {
  margin-top: 6px;
  color: #344054;
  font-size: 14px;
  white-space: pre-wrap;
}
.problem-cover {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.problem-options {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.problem-options li {
  display: flex;
  gap: 9px;
  align-items: baseline;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 13.5px;
}
.problem-opt-key {
  flex: none;
  min-width: 20px;
  font-weight: 600;
  color: var(--accent);
}

.problem-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

/* 作答 / 补交编辑器 */

.problem-editor { margin-top: 12px; }

.problem-editor-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.option-row:hover { background: #fbfcff; border-color: #c9d4e8; }
.option-row.selected { background: var(--accent-soft); border-color: var(--accent); }

.option-badge {
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  background: #eef0f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  line-height: 22px;
}
.option-row.selected .option-badge { background: var(--accent); color: #fff; }
.option-text { flex: 1; font-size: 13.5px; }

.problem-editor-tip { margin-top: 6px; color: var(--muted); font-size: 12px; }

.blank-list { display: flex; flex-direction: column; gap: 8px; }
.blank-row { display: flex; align-items: center; gap: 10px; }
.blank-key { flex: none; width: 58px; color: var(--muted); font-size: 12.5px; }
.blank-row input,
.answer-textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  background: #fff;
  outline: none;
  font: inherit;
}
.blank-row input:focus,
.answer-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.answer-textarea { margin-top: 12px; resize: vertical; }

.problem-submit { margin-top: 12px; }
.problem-warn { margin-top: 8px; color: #b54708; font-size: 12.5px; }

.answer-summary {
  margin: 10px 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 20, 28, .42);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: min(430px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 26px 26px 24px;
  box-shadow: 0 24px 60px rgba(15, 20, 28, .25);
}
.modal-card.narrow { width: min(400px, 100%); }

.modal-card h3 { margin: 0 0 14px; font-size: 18px; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
}
.modal-close:hover { background: #f1f3f6; }

.qr-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 6px auto 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.qr-wrap img { width: 100%; height: 100%; object-fit: contain; }

.qr-mask {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .92);
  font-weight: 600;
  color: var(--accent);
}

#loginMsg { text-align: center; margin: 0 0 12px; min-height: 22px; }

#qrReload { display: block; margin: 0 auto 6px; }

.cookie-box {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.cookie-box summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.cookie-box textarea {
  width: 100%;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  resize: vertical;
  background: #fbfcfd;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- 查看器 ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #0e1116;
  color: #e8eaed;
}

.viewer-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.viewer-title {
  font-weight: 600;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-top .hint { color: #9aa3af; }
.viewer-top .btn {
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .14);
  color: #e8eaed;
}
.viewer-top .btn:hover { background: rgba(255, 255, 255, .13); }

.spacer { flex: 1; }

.viewer-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #cfd4dc;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.viewer-close:hover { background: rgba(255, 255, 255, .1); }

.viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.stage {
  flex: 1;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
}

.nav {
  flex: none;
  width: 46px;
  height: 74px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  color: #dfe3e9;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
}
.nav:hover { background: rgba(255, 255, 255, .12); }
.nav[disabled] { opacity: .25; cursor: default; }

.thumbs {
  display: flex;
  gap: 8px;
  padding: 10px 16px 16px;
  overflow-x: auto;
}
.thumbs button {
  flex: none;
  width: 104px;
  height: 68px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #1a1e25;
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s, border-color .15s;
}
.thumbs button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs button:hover { opacity: .85; }
.thumbs button.active { opacity: 1; border-color: var(--accent); }

.text-panel {
  max-height: 32vh;
  overflow: auto;
  margin: 0 16px 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: #171b22;
  color: #d7dbe1;
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.7;
}
.text-panel h4 { margin: 14px 0 4px; color: #8fb4ff; font-size: 12.5px; }
.text-panel h4:first-child { margin-top: 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(560px, 90vw);
  padding: 11px 18px;
  border-radius: 11px;
  background: #1f242c;
  color: #f1f3f6;
  font-size: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .layout { padding: 18px 14px 60px; }
  .panel { padding: 16px; }
  .inline-form input { width: 130px; }
  .viewer-title { max-width: 30vw; }
}
