:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #3b5bdb;
  --accent-soft: #eef1fe;
  --warn: #b45309;
  --ok: #0f766e;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
}

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

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.doc-title {
  font-size: 14px;
  color: var(--muted);
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spacer { flex: 1; }

/* ---------- 工具 ---------- */
.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: #f3f4f6;
  border-radius: 12px;
}

.tool {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 13.5px;
  color: #374151;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.tool:hover { background: #e9ebef; }
.tool.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); font-weight: 550; }
.tool svg { width: 16px; height: 16px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #fafafa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3249b8; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f2f4; color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.color-dot {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #d1d5db;
  cursor: pointer;
  padding: 0;
}
.color-dot.active { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- 阅读区 ---------- */
.viewport {
  position: relative;
  overflow: auto;
  height: calc(100vh - 58px);
  -webkit-overflow-scrolling: touch;
  padding: 20px 0 120px;
  overscroll-behavior: contain;
}
.viewport.no-toolbar { height: 100vh; }

.pages { display: flex; flex-direction: column; align-items: center; gap: 22px; }

.page-wrap {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16,24,40,.08), 0 8px 24px rgba(16,24,40,.08);
  border-radius: 3px;
  overflow: hidden;
  flex: none;
}
.page-wrap canvas { display: block; }
.page-wrap .overlay {
  position: absolute; inset: 0;
  touch-action: pan-y;
  cursor: crosshair;
}
.page-wrap .overlay.draw { touch-action: none; }
.page-wrap .pnum {
  position: absolute; right: 8px; bottom: 6px;
  font-size: 11px; color: #b6bcc6;
  pointer-events: none;
  letter-spacing: .04em;
}
.page-loading {
  padding: 14px;
  color: #9aa0aa;
  font-size: 13px;
}

/* 同步状态 */
.sync {
  font-size: 12.5px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.sync .pip {
  width: 6px; height: 6px; border-radius: 50%; background: #cbd5e1;
  transition: background .2s;
}
.sync.saving .pip { background: var(--warn); }
.sync.ok .pip { background: var(--ok); }
.sync.err .pip { background: var(--danger); }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(15, 23, 42, .38);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.modal.show { display: flex; }

.card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  padding: 26px;
  width: min(420px, 100%);
}
.card h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.card p.hint { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=password] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fafbfc;
  transition: border-color .15s, background .15s;
  font-size: 15px;
}
.field input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }

.card .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* 提示条 */
.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(22, 24, 29, .92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- 首页 ---------- */
.landing {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}
.landing-inner { width: min(760px, 100%); }
.landing h1 {
  font-size: clamp(26px, 4.6vw, 38px);
  letter-spacing: -.025em;
  margin: 0 0 10px;
  line-height: 1.2;
}
.landing .sub { color: var(--muted); margin: 0 0 30px; font-size: 15px; }

.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.role {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.role h3 { margin: 0 0 6px; font-size: 15.5px; }
.role p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.role .row { display: flex; gap: 8px; }
.role input {
  flex: 1; min-width: 0;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: #fafbfc; outline: none;
}
.role input:focus { border-color: var(--accent); background: #fff; }

@media (max-width: 640px) {
  .roles { grid-template-columns: 1fr; }
  .doc-title { max-width: 46vw; }
  .tool { padding: 7px 9px; }
}

/* ---------- 教师后台 ---------- */
.admin-shell { display: flex; flex-direction: column; height: 100vh; }
.admin-body { flex: 1; overflow: auto; padding: 22px; }
.admin-body.with-viewer { padding: 0; display: flex; flex-direction: column; overflow: hidden; }

.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-title h2 { margin: 0; font-size: 16px; font-weight: 600; }
.section-title .count { color: var(--muted); font-size: 13px; }

.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
  cursor: pointer;
  transition: border-color .15s, transform .12s, box-shadow .15s;
}
.doc-row:hover { border-color: #c9d2e3; transform: translateY(-1px); box-shadow: var(--shadow); }
.doc-row .meta { flex: 1; min-width: 0; }
.doc-row .name { font-weight: 550; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; }
.pill {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 550;
}
.pill.gray { background: #f1f2f4; color: #4b5563; }
.pill.green { background: #e7f7f2; color: var(--ok); }

.empty {
  border: 1px dashed #cfd6e2; border-radius: 14px;
  padding: 44px 20px; text-align: center; color: var(--muted); background: #fafbfd;
}
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 15px; }

/* 后台文档视图 */
.viewer-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fff;
}
.students-strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { font-size: 11.5px; opacity: .75; }

.admin-viewport { flex: 1; overflow: auto; background: var(--bg); padding: 18px 0 80px; }
.replay-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; border-top: 1px solid var(--line); background: #fff;
}
progress { -webkit-appearance: none; appearance: none; }

.upload-row { display: flex; gap: 10px; align-items: center; }
.upload-row input[type=file] {
  font-size: 13px; max-width: 220px;
}

.kv-note {
  margin-top: 18px; font-size: 12.5px; color: var(--muted);
  line-height: 1.65;
}
