/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --line: #dde2ea;
  --paper: #f4f5f7;
  --card: #ffffff;
  --accent: #16a34a;
  --accent-soft: #e9f7ee;
  --warn: #d97706;
  --danger: #dc2626;
  --board: #2b5b4c;
  --radius: 10px;
}

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }

/* ========== 顶栏 ========== */
#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand-logo { width: 30px; height: 30px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 1px; }

#fileSelect {
  flex: 1;
  max-width: 460px;
  height: 36px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.source-tag {
  flex: none;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: default;
}

#switchServerBtn {
  flex: none;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: underline;
  padding: 4px 2px;
}
#switchServerBtn:hover { color: var(--ink); }

/* ZIP 上传入口 */
.upload-panel {
  margin: 44px auto;
  max-width: 470px;
  text-align: center;
  padding: 46px 26px;
  background: #fafbfc;
  border: 2px dashed #c6cdd8;
  border-radius: 16px;
  transition: border-color .2s, background .2s;
}
.upload-panel.dragover { border-color: var(--accent); background: var(--accent-soft); }
.upload-panel > svg { width: 46px; height: 46px; stroke: #8a94a3; margin-bottom: 14px; }
.up-title { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.up-desc { font-size: 13.5px; color: var(--ink-soft); line-height: 1.9; margin-bottom: 20px; }
.up-note { margin-top: 16px; font-size: 12.5px; color: var(--ink-soft); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.progress-text { font-size: 13px; color: var(--ink-soft); min-width: 72px; text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  flex: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f6; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #343b4a; }
.btn.icon-only { padding: 0 9px; }

/* ========== 题号条 ========== */
#chips {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex: none;
}
#chips:empty { display: none; }

.chip {
  position: relative;
  flex: none;
  width: 34px;
  height: 32px;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: #b6bfcc; color: var(--ink); }
.chip.group-start { margin-left: 16px; }
.chip.group-start:first-child { margin-left: 0; }
.chip.group-start::before {
  content: "";
  position: absolute;
  left: -11px; top: 6px; bottom: 6px;
  width: 1px;
  background: var(--line);
}
.chip.current { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.chip.done { color: var(--accent); border-color: #b5dfc5; background: var(--accent-soft); }
.chip.current.done { color: #fff; background: var(--accent); border-color: var(--accent); }

/* ========== 主区域布局 ========== */
#stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(430px, 47%) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

/* ========== 题目面板 ========== */
#qpanel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#qscroll { overflow-y: auto; padding: 22px 26px 30px; flex: 1; }

#qmeta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.meta-tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.meta-tag.type { color: var(--ink); font-weight: 500; }

#qbody { font-size: 21px; line-height: 2; color: var(--ink); }
#qbody img { max-width: 100%; height: auto; display: block; margin: 10px 0; border-radius: 6px; }
#qbody img.img-broken { display: none; }
.img-error {
  display: inline-block;
  margin: 8px 0;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

/* 填空位 */
.blank {
  display: inline-block;
  min-width: 3em;
  margin: 0 2px;
  text-align: center;
  border-bottom: 2px solid #aab4c2;
  line-height: 1.4;
  vertical-align: baseline;
}
.blank i { font-style: normal; color: #9aa4b2; font-size: .85em; letter-spacing: 1px; }
.blank.filled { border-bottom-color: var(--accent); font-weight: 600; }
.blank.filled i { color: var(--accent); font-size: 1em; letter-spacing: 0; }

/* 内嵌选项(====位置, 混合题) */
.slot { display: inline-flex; gap: 8px; margin: 0 4px; vertical-align: middle; }
.opt {
  padding: 1px 16px;
  font-size: 18px;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid #c9d1dc;
  border-radius: 8px;
  transition: all .15s;
}
.opt:hover { border-color: #8f9bab; }
.opt.selected { border-color: var(--warn); background: #fdf3e3; color: #92580a; }
.opt.correct { border-color: var(--accent); background: var(--accent-soft); color: #0b6b36; font-weight: 600; }
.opt.wrong { border-color: var(--danger); background: #fdecec; color: #a11717; }

/* 单选题选项 */
.options { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  font-size: 19px;
  text-align: left;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  transition: all .15s;
}
.option:hover { border-color: #8f9bab; background: #fafbfc; }
.option .letter {
  flex: none;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
}
.option.selected { border-color: var(--warn); background: #fdf6ea; }
.option.selected .letter { border-color: var(--warn); color: var(--warn); }
.option.correct { border-color: var(--accent); background: var(--accent-soft); }
.option.correct .letter { background: var(--accent); border-color: var(--accent); color: #fff; }
.option.wrong { border-color: var(--danger); background: #fdecec; }
.option.wrong .letter { background: var(--danger); border-color: var(--danger); color: #fff; }

/* 操作条 */
#actionbar {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
}

/* 答案区 */
#ansArea {
  margin-top: 16px;
  padding: 16px 18px;
  background: var(--accent-soft);
  border: 1px solid #c4e5d0;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  font-size: 18px;
  line-height: 1.9;
}
.ans-label { font-size: 13px; font-weight: 700; color: #0b6b36; letter-spacing: 2px; margin-bottom: 6px; }
.ans-line b { color: #0b6b36; }

/* 解析区 */
#expArea {
  margin-top: 14px;
  padding: 16px 18px;
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 18px;
  line-height: 1.95;
}
.exp-label { font-size: 13px; font-weight: 700; color: var(--ink-soft); letter-spacing: 2px; margin-bottom: 8px; }
.exp-title { font-weight: 700; margin: 8px 0 4px; }
.explain + .explain { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
#expArea img, #ansArea img { max-width: 100%; height: auto; display: block; margin: 8px 0; border-radius: 6px; }

/* 章节索引视图 */
.index-head { margin-bottom: 16px; }
.index-head h1 { font-size: 24px; margin-bottom: 6px; }
.index-head p { color: var(--ink-soft); font-size: 14px; }
.topic-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.topic-card .t-info { flex: 1; min-width: 0; }
.topic-card .t-name { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.topic-card .t-meta { font-size: 13px; color: var(--ink-soft); display: flex; gap: 8px; flex-wrap: wrap; }

.empty-tip { color: var(--ink-soft); font-size: 15px; line-height: 2; padding: 20px 4px; }

/* ========== 白板 ========== */
#boardCol {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
}

#boardBar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.board-title { font-size: 14px; font-weight: 700; letter-spacing: 2px; color: var(--ink-soft); flex: none; }

.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tool-group { display: flex; align-items: center; gap: 5px; padding-right: 10px; border-right: 1px solid var(--line); }
.tool-group:last-child { border-right: none; }

.swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid rgba(0,0,0,.18);
  outline: 2px solid transparent;
  outline-offset: 2px;
}
.swatch.is-on { outline-color: var(--ink); }

.size-dot {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.size-dot i { display: block; background: var(--ink); border-radius: 50%; }
.size-dot.is-on { border-color: var(--ink); }

.tool-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tool-btn:hover { color: var(--ink); }
.tool-btn.is-on { color: #fff; background: var(--ink); border-color: var(--ink); }
.tool-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.autoclear { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.autoclear input { accent-color: var(--ink); width: 15px; height: 15px; cursor: pointer; }

#boardWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--board);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0,0,0,.25);
}
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#board.eraser-mode { cursor: pointer; }
#boardHint {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,.35);
  font-size: 17px;
  letter-spacing: 2px;
  pointer-events: none;
  transition: opacity .3s;
}
#boardHint.faded { opacity: 0; }

/* ========== 窄屏 ========== */
@media (max-width: 980px) {
  html, body { height: auto; overflow: auto; }
  #stage { flex: none; grid-template-columns: 1fr; overflow: visible; }
  #qpanel { overflow: visible; }
  #qscroll { overflow: visible; }
  #boardWrap { flex: none; height: 48vh; }
  .progress-text { display: none; }
  #fileSelect { max-width: none; }
}
