:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-2: #e11d48;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 20px 28px 6px;
}
header h1 { margin: 0; font-size: 22px; }
header .sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 14px 28px 28px;
  align-items: start;
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 420px;
}

/* 左侧 */
#dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
#dropzone.over { border-color: var(--accent); background: #eef4ff; }
.dz-main { font-size: 16px; color: var(--text); margin: 0; }
.dz-sub { font-size: 13px; margin: 8px 0 0; }

.img-stage { position: relative; }
.img-stage img { display: block; max-width: 100%; border-radius: 8px; }
.img-stage canvas { position: absolute; left: 0; top: 0; cursor: crosshair; }
#hint {
  margin: 8px 0 0; font-size: 13px; color: var(--accent-2);
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 6px 10px;
}

#toolbar { margin-top: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
button {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
button:hover { border-color: #cbd5e1; background: #f8fafc; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #1d4ed8; }

#status {
  margin-top: 12px; font-size: 14px; color: var(--muted);
  background: #f8fafc; border-radius: 8px; padding: 8px 12px;
}

#regionResult {
  margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 12px;
}
#regionResult h3 { margin: 0 0 8px; font-size: 14px; }
.region-text { font-size: 15px; }
#btnInsert { margin-top: 10px; }

/* 右侧 */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs button { border: none; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--accent); font-weight: 600; border-bottom: 2px solid var(--accent); }

.result {
  font-size: 16px; line-height: 1.75;
  max-height: 72vh; overflow: auto; padding-right: 4px;
}
.result .placeholder { color: var(--muted); }
.result mjx-container[display="true"] { margin: 10px 0; }

#editor {
  width: 100%; min-height: 420px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px; line-height: 1.6; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; resize: vertical;
}

#rightActions { margin-top: 12px; display: flex; gap: 10px; }

.hidden { display: none !important; }

/* 顶栏按钮 */
.header-actions { position: absolute; right: 28px; top: 18px; display: flex; gap: 10px; }

/* 历史记录 */
#historyPanel { position: fixed; inset: 0; z-index: 50; }
.history-mask { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.history-box {
  position: absolute; right: 0; top: 0; bottom: 0; width: 440px; max-width: 92vw;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
}
.history-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.history-head h2 { margin: 0; font-size: 17px; }
#historyList { overflow: auto; padding: 10px; flex: 1; }
.hist-row {
  display: flex; gap: 12px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; align-items: center;
}
.hist-thumb { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; background: #f1f5f9; flex: none; }
.hist-info { flex: 1; min-width: 0; }
.hist-time { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.hist-preview { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.hist-actions button { padding: 4px 10px; font-size: 12px; }

/* 第二阶段 */
#phase2Actions { margin-top: 12px; display: flex; gap: 10px; }
#phase2Result { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.phase2-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.phase2-head span { font-weight: 600; }
#phase2Body { font-size: 15px; line-height: 1.75; max-height: 55vh; overflow: auto; }
.ref-summary { margin-bottom: 12px; }
.ref-sec { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.ref-sec-head { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ref-sec-body { font-size: 14px; }

/* 上传课本 */
.textbook-body { padding: 16px 18px; overflow: auto; flex: 1; }
.textbook-body label { display: block; font-size: 14px; margin-bottom: 6px; }
.textbook-body input[type=text], .textbook-body textarea {
  width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; margin-bottom: 10px; box-sizing: border-box;
}
.textbook-body textarea { min-height: 140px; resize: vertical; }
.tb-label { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.tb-thumb { width: 60px; height: 44px; object-fit: cover; border-radius: 4px; margin: 4px; border: 1px solid var(--border); vertical-align: middle; }
#tbImgList { margin: 6px 0; }
#tbInfo { font-size: 13px; color: var(--muted); margin: 10px 0; }
#btnTbImport { margin-top: 8px; }
#tbPdfName { font-size: 13px; color: var(--muted); margin-left: 8px; }
.tb-range { margin: 8px 0; font-size: 13px; color: var(--muted); }
.tb-range input { width: 70px; margin: 0 4px; }

/* 登录弹窗 */
#authPanel { position: fixed; inset: 0; z-index: 60; }
.auth-box {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: #fff; padding: 24px 28px; border-radius: 12px; width: 320px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2); text-align: center;
}
.auth-box h2 { margin: 0 0 14px; font-size: 16px; }
.auth-box input {
  width: 100%; padding: 9px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 10px; box-sizing: border-box; font-size: 14px;
}
.auth-box button { width: 100%; }
#authErr { color: var(--accent-2); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* 顶栏额度/退出 */
#quota { font-size: 13px; color: var(--muted); align-self: center; }

/* 课本上传 */
.tb-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#tbStatus { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 18px; }
