:root {
  --accent: #0a6ef0;
  --accent-deep: #0a4fb0;
  --ink: #141821;
  --muted: #6b7280;
  --line: rgba(16, 19, 26, 0.09);
  --card: #fff;
  --bg: #f5f6f8;
  --ok: #17a673;
  --warn: #d98413;
  --danger: #d33b3b;
  --shadow: 0 1px 2px rgba(16, 19, 26, 0.06), 0 10px 30px -18px rgba(16, 19, 26, 0.35);
  --radius: 16px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 8% -10%, #ffe6cf 0%, rgba(255, 230, 207, 0) 60%),
    radial-gradient(900px 520px at 100% 0%, #e6ddff 0%, rgba(230, 221, 255, 0) 55%),
    radial-gradient(900px 600px at 50% 120%, #dff1ff 0%, rgba(223, 241, 255, 0) 60%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- 登录 ---------- */
.login-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 340px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 28px 26px 24px;
  box-shadow: 0 1px 2px rgba(16, 19, 26, 0.06), 0 24px 60px -30px rgba(16, 19, 26, 0.55);
  backdrop-filter: blur(18px);
}
.login-brand {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 600;
}
.login-card h1 { font-size: 24px; margin: 8px 0 4px; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 10px 0 0; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  outline: none;
}
.field input:focus { border-color: rgba(10, 110, 240, 0.5); box-shadow: 0 0 0 3px rgba(10, 110, 240, 0.12); }

/* ---------- 通用按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 9px;
  height: 32px;
  padding: 0 14px;
  cursor: pointer;
  background: #fff;
  border-color: var(--line);
  transition: 0.14s ease;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn:active { transform: translateY(0.5px); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover { background: #0a63d6; }
.btn-plain { background: rgba(255, 255, 255, 0.7); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; height: 38px; }
.btn kbd {
  font: inherit;
  font-size: 11px;
  opacity: 0.7;
  margin-left: 4px;
}
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid rgba(16, 19, 26, 0.07);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 190px; }
.brand-mark { font-weight: 700; letter-spacing: 0.16em; font-size: 12.5px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: rgba(16, 19, 26, 0.05); padding: 3px; border-radius: 10px; }
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 5px 14px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
}
.tab.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16, 19, 26, 0.12); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sync { font-size: 12px; color: var(--muted); }
.sync.ok { color: var(--ok); }
.ghost-link { font-size: 12.5px; }

/* ---------- 三栏 ---------- */
.view {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 356px;
  gap: 14px;
  padding: 14px 14px 18px;
  height: calc(100vh - 54px);
  min-height: 560px;
}
.rail, .stage, .preview, .note-stage, .note-preview {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rail-head { padding: 12px; border-bottom: 1px solid var(--line); }
.search {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #f8f9fb;
  outline: none;
}
.search:focus { border-color: rgba(10, 110, 240, 0.45); background: #fff; }
.rail-scroll { overflow: auto; flex: 1; padding: 8px; }
.rail-foot { padding: 10px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.paper-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.paper-item:hover { background: #f5f8fd; }
.paper-item.on { background: rgba(10, 110, 240, 0.08); border-color: rgba(10, 110, 240, 0.28); }
.paper-item b { font-weight: 550; font-size: 12.8px; letter-spacing: 0.01em; }
.paper-item .p-meta { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.paper-item .dot { width: 7px; height: 7px; border-radius: 99px; background: #d6dae2; flex: none; }
.paper-item .dot.part { background: #f0b04a; }
.paper-item .dot.done { background: var(--ok); }

/* 题目 */
.stage-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 6px;
  flex-wrap: wrap;
}
.paper-title { display: flex; align-items: baseline; gap: 10px; }
.paper-title b { font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }
.filters { margin-left: auto; display: flex; gap: 6px; }
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 99px;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.chip.on { background: rgba(10, 110, 240, 0.1); border-color: rgba(10, 110, 240, 0.35); color: var(--accent-deep); }

.qchips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 14px 12px;
  border-bottom: 1px solid var(--line);
  max-height: 132px;
  overflow: auto;
}
.qchip {
  position: relative;
  width: 34px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  color: #454b56;
}
.qchip:hover { border-color: rgba(10, 110, 240, 0.4); }
.qchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.qchip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 99px;
  background: #cfd4dc;
}
.qchip.has-fig::after { background: var(--ok); }
.qchip.auto-fig::after { background: #f0b04a; }
.qchip.no-fig::after { background: var(--danger); }
.qchip.has-table::after { background: #7b6bd6; }
.qchip.on::after { background: rgba(255, 255, 255, 0.85); }

/* 编辑器 */
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  flex-wrap: wrap;
}
.seg { display: flex; background: rgba(16, 19, 26, 0.06); border-radius: 9px; padding: 2px; }
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16, 19, 26, 0.12); }
.editor-actions { margin-left: auto; display: flex; gap: 8px; }

.stage-crop {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 14px 14px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background:
    linear-gradient(90deg, rgba(16, 19, 26, 0.03) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(rgba(16, 19, 26, 0.03) 1px, transparent 1px) 0 0 / 22px 22px,
    #fbfbfc;
  border-top: 1px solid var(--line);
}
.crop-canvas {
  position: relative;
  user-select: none;
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(16, 19, 26, 0.1), 0 10px 24px -16px rgba(16, 19, 26, 0.5);
  background: #fff;
}
.crop-canvas img { display: block; width: 100%; height: 100%; pointer-events: none; }
.shade {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 32, 0.34);
  pointer-events: none;
}
.cbox {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(10, 110, 240, 0.9), 0 0 0 9999px rgba(12, 18, 32, 0.0);
  cursor: move;
  border-radius: 2px;
}
.cbox .tag {
  position: absolute;
  left: 0;
  top: -20px;
  font-size: 11px;
  background: rgba(10, 110, 240, 0.92);
  color: #fff;
  padding: 1px 6px;
  border-radius: 5px;
  white-space: nowrap;
}
.hd {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 3px;
}
.hd.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.hd.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.hd.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.hd.se { right: -7px; bottom: -7px; cursor: nwse-resize; }

.objs { position: absolute; inset: 0; pointer-events: none; }
.obox {
  position: absolute;
  border: 2px dashed rgba(255, 255, 255, 0.95);
  outline: 1px solid rgba(217, 132, 19, 0.9);
  border-radius: 3px;
  cursor: move;
  pointer-events: auto;
}
.obox .tag {
  position: absolute;
  left: 0;
  top: -18px;
  font-size: 10.5px;
  background: rgba(217, 132, 19, 0.95);
  color: #fff;
  padding: 0 5px;
  border-radius: 4px;
}
.obox .hd { border-color: var(--warn); width: 10px; height: 10px; }

.fields {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  background: #fff;
}
.fields label { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.fields input {
  width: 74px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
  outline: none;
  background: #fbfcfd;
}
.fields input:focus { border-color: rgba(10, 110, 240, 0.5); background: #fff; }
.hint { font-size: 11.5px; color: var(--muted); margin-left: auto; }

.empty { padding: 60px 20px; color: var(--muted); text-align: center; font-size: 13px; }

/* 预览 */
.preview-head, .note-preview .preview-head {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.preview-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background:
    linear-gradient(180deg, #f8fafc 0%, #fff 60%);
}
.preview-foot { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* 注意：这里不能有 border/padding 改变 padding-box，
   因为 img 的 left/top 百分比是按它算的，差 1px 就会把边缘切掉 */
.crop-view {
  position: relative;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(16, 19, 26, 0.08);
  border-radius: 6px;
  max-width: 100%;
  flex: none;
}
.crop-view img {
  position: absolute;
  display: block;
  max-width: none;
  max-height: none;
}
.stem-prev { display: block; margin: 0 0 12px; }
.opt-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.opt-row .opt-cell { flex: 0 0 auto; }
/* 用 box-shadow 画描边、padding 交给 <b>，保证 .crop-view 的宽度就是格宽，
   否则内宽 w-10 会让 max-width:100% 把视图压窄，而高度还按 w 算，比例就崩了 */
.opt-cell { border: 0; padding: 0; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.opt-cell .crop-view { border: 0; border-radius: 0; box-shadow: none; }
.opt-cell > b { display: block; font-size: 10.5px; color: var(--muted); font-weight: 500; padding: 4px 6px 2px; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: rgba(10, 110, 240, 0.1);
  color: var(--accent-deep);
  margin-right: 6px;
}
.badge.warn { background: rgba(217, 132, 19, 0.14); color: #8a5304; }
.badge.danger { background: rgba(211, 59, 59, 0.12); color: #a52626; }
.badge.ok { background: rgba(23, 166, 115, 0.13); color: #0f7a55; }
.warnbar {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(232, 163, 61, 0.12);
  border: 1px solid rgba(232, 163, 61, 0.45);
  color: #8a5304;
  font-size: 12px;
  line-height: 1.6;
}
.preview-note { font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 讲义 */
.note-stage { min-width: 0; }
.note-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.note-bar b { font-size: 13.5px; flex: 1 1 auto; min-width: 60px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-actions { margin-left: 6px; display: flex; gap: 7px; flex: none; }
.note-bar #noteState { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-bar { gap: 10px; }
.note-src {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  padding: 16px 18px;
  background: #fcfcfd;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, "PingFang SC", monospace;
  font-size: 12.5px;
  line-height: 1.72;
  tab-size: 2;
}
.note-preview-scroll { flex: 1; overflow: auto; padding: 20px 24px 40px; }
.note-list-item {
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12.8px;
  border: 1px solid transparent;
  display: flex;
  gap: 6px;
  align-items: center;
}
.note-list-item:hover { background: #f5f8fd; }
.note-list-item.on { background: rgba(10, 110, 240, 0.08); border-color: rgba(10, 110, 240, 0.28); }
.note-list-item .n-meta { margin-left: auto; font-size: 11px; color: var(--muted); }

/* Markdown 预览：直接对齐主站讲义排版 */
.md-body {
  font-family: Arial, "Helvetica Neue", Helvetica, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14.5px;
  line-height: 1.75;
  color: #1c1f24;
}
.md-body h1 { font-size: 23px; line-height: 1.32; margin: 0 0 16px; font-weight: 700; }
.md-body h2 { font-size: 18.5px; margin: 26px 0 11px; padding-bottom: 6px; border-bottom: 1px solid rgba(16, 19, 26, 0.1); }
.md-body h3 { font-size: 15.5px; margin: 20px 0 8px; }
.md-body p { margin: 0 0 12px; }
.md-body ul, .md-body ol { margin: 0 0 14px; padding-left: 22px; }
.md-body li { margin-bottom: 6px; }
.md-body ul { list-style: disc; }
.md-body ol { list-style: decimal; }
.md-body li::marker { color: rgba(28, 31, 36, 0.45); }
.md-body li > p { margin: 0 0 4px; }
.md-body hr { border: 0; border-top: 1px dashed rgba(16, 19, 26, 0.12); margin: 24px 0; }
.md-body blockquote {
  margin: 0 0 14px; padding: 8px 14px;
  border-left: 3px solid rgba(10, 110, 240, 0.35);
  background: rgba(10, 110, 240, 0.05);
  border-radius: 0 10px 10px 0; color: #2a2f37;
}
.md-body blockquote p { margin: 0; }
.md-body table { border-collapse: collapse; margin: 6px 0 16px; font-size: 13.5px; }
.md-body th, .md-body td { border: 1px solid rgba(16, 19, 26, 0.12); padding: 7px 12px; text-align: left; }
.md-body th { background: rgba(16, 19, 26, 0.03); font-weight: 600; }
.md-body em { color: #4a505a; }
.md-body .katex { font-size: 1em; }
.md-body .katex, .md-body .katex *:not(svg):not(svg *) { font-family: inherit; font-weight: 400; }
.md-body .md-total { display: block; text-align: right; font-weight: 600; margin-top: 4px; }
.md-body img { display: block; max-width: min(100%, 560px); height: auto; max-height: 620px; object-fit: contain; margin: 4px auto 6px; border-radius: 10px; }
.md-body p:has(img) { margin-bottom: 8px; }

/* ::: 区块（类名和主站一致：md-box md-learning …） */
.md-box {
  margin: 16px 0 18px; padding: 14px 18px; border-radius: 12px;
  border: 1px solid rgba(16, 19, 26, 0.08); border-left-width: 3px;
  background: rgba(16, 19, 26, 0.02);
}
.md-box > p:last-child, .md-box > ul:last-child { margin-bottom: 0; }
.md-learning { border-left-color: #0a84ff; background: rgba(10, 132, 255, 0.055); }
.md-before { border-left-color: #8a94a6; background: rgba(138, 148, 166, 0.07); }
.md-note { border-left-color: #e8a33d; background: rgba(232, 163, 61, 0.07); }
.md-key { border-left-color: #2eb872; background: rgba(46, 184, 114, 0.07); }
.md-example { border-left-color: #2aa5a0; background: rgba(42, 165, 160, 0.07); }
.md-activity { border-left-color: #e8890c; background: rgba(232, 137, 12, 0.07); }
.md-exam { border-left-color: #e05a5a; background: rgba(224, 90, 90, 0.07); }
.md-checklist { border-left-color: #5c7cfa; background: rgba(92, 124, 250, 0.07); }
.md-reflection { border-left-color: #8e6cd8; background: rgba(142, 108, 216, 0.07); }
.md-summary { border-left-color: #2eb872; background: rgba(46, 184, 114, 0.09); }
.md-equation { border-left-color: #6d5ae0; background: rgba(109, 90, 224, 0.06); text-align: center; }
.md-equation p { margin: 4px 0; }
.md-equation strong { display: block; font-size: 12.5px; letter-spacing: 0.04em; color: #5a4bd0; margin-bottom: 6px; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: rgba(20, 24, 33, 0.9);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 16px;
  border-radius: 99px;
  z-index: 60;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
}

@media (max-width: 1180px) {
  .view { grid-template-columns: 220px minmax(0, 1fr) 300px; }
}
@media (max-width: 980px) {
  .view { grid-template-columns: 1fr; height: auto; }
  .rail { max-height: 260px; }
  .preview, .note-preview { max-height: 420px; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
}

.sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }

/* hidden 属性优先于 display 规则 */
[hidden] { display: none !important; }

/* 没有框时不要把整页图压黑 */
.crop-canvas.no-box .shade { background: rgba(12, 18, 32, 0.06); }

/* 讲义视图：预览栏更宽一点，长文更好读 */
#view-notes { grid-template-columns: 240px minmax(0, 1fr) minmax(360px, 46%); }
@media (max-width: 1180px) {
  #view-notes { grid-template-columns: 210px minmax(0, 1fr) minmax(320px, 44%); }
}
