/* ============ 基础 ============ */
:root {
  color-scheme: light;
  --bg: #eef0f3;
  --surface: #ffffff;
  --text: #1f2329;
  --text-2: #4b525d;
  --muted: #8a919c;
  --line: #e3e6ea;
  --soft: #f6f7f9;
  --accent: #2f62d1;
  --accent-soft: #edf2fd;
  --focus: rgba(47, 98, 209, .35);
  --danger: #d1453b;
  --warn-bg: #fff5e3;
  --warn: #8f5a00;
  --ok: #2e7d32;

  /* 仿图文平台帖子 */
  --xhs-text: #333333;
  --xhs-muted: #999999;
  --xhs-tag: #13386c;
  --xhs-red: #ff2442;

  --app-w: 430px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
#app {
  max-width: var(--app-w);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
}
@media (min-width: 600px) {
  #app { box-shadow: 0 0 0 1px var(--line), 0 12px 40px rgba(0, 0, 0, .06); }
}
button, input, textarea, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.6; }
.small { font-size: 12px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;
  border-radius: 10px; border: 1px solid transparent;
  background: none; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #b8c5e4; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn-ghost:disabled { color: var(--muted); cursor: not-allowed; }
.btn-danger { background: var(--danger); color: #fff; }
.danger-text { color: var(--danger); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; font-weight: 500; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }
.col { display: flex; flex-direction: column; gap: 8px; }

/* ============ 研究页面框架 ============ */
.pg {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
}
.pg-progress { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; margin: -6px 0 16px; }
.pg-progress i { display: block; height: 100%; background: var(--accent); }
.pg-eyebrow { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.pg-title { font-size: 22px; line-height: 1.35; margin: 0 0 14px; }
.pg-h2 { font-size: 15px; color: var(--text-2); margin: 28px 0 10px; }
.pg-body { flex: 1; }
.pg-foot { padding-top: 20px; }
.prose p { font-size: 16px; line-height: 1.75; color: var(--text-2); margin: 0 0 12px; }
.prose b { color: var(--text); }

/* ============ 题目 ============ */
.q {
  border: 0; min-width: 0;
  margin: 0 0 14px; padding: 14px 12px 12px;
  border-radius: 12px; background: var(--soft);
}
.q--missing { background: #fff5f4; box-shadow: inset 0 0 0 1.5px var(--danger); }
.q-text {
  float: left; width: 100%; padding: 0;
  font-size: 16px; line-height: 1.55; font-weight: 500;
  margin-bottom: 12px;
}
.q-num { display: inline-block; min-width: 1.6em; color: var(--accent); font-weight: 700; }

.scale { clear: both; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.pt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.pt input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.pt-dot {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.5px solid #c4cad3; background: #fff;
  font-size: 15px; font-weight: 600; color: var(--text-2);
  transition: background .12s, border-color .12s, color .12s;
}
.pt-lab { font-size: 11px; line-height: 1.3; color: var(--muted); text-align: center; padding: 0 1px; }
.pt input:checked + .pt-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.pt input:checked ~ .pt-lab { color: var(--accent); font-weight: 600; }
.pt input:focus-visible + .pt-dot { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (max-width: 360px) {
  .pt-dot { width: 32px; height: 32px; font-size: 14px; }
  .pt-lab { font-size: 10px; }
}

.choices { clear: both; display: flex; flex-direction: column; gap: 8px; }
.choices--row { flex-direction: row; flex-wrap: wrap; }
.choices--row .choice { flex: 1 1 140px; }
.choice {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 15px; line-height: 1.45; cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-box { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid #c4cad3; background: #fff; }
.choice input:checked + .choice-box { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px #fff; }
.choice input:focus-visible + .choice-box { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.num { clear: both; display: flex; align-items: center; gap: 8px; font-size: 16px; }
.num input { width: 110px; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 17px; }

.check {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 14px 0; padding: 12px; border-radius: 10px; background: var(--soft);
  font-size: 15px; line-height: 1.55; cursor: pointer;
}
.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }

/* 评分页 */
.rate-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 8px 8px 12px; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: 10px;
}
.rate-ref { min-width: 0; font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rate-head .btn { flex: none; }
.rate-intro { font-size: 15px; line-height: 1.6; color: var(--text-2); margin: 0 0 12px; }
.reminder {
  margin-bottom: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--warn-bg); color: #6b4a12; font-size: 15px; line-height: 1.65;
}

/* ============ 仿图文平台帖子 ============ */
.xhs { background: #fff; color: var(--xhs-text); min-height: 100vh; min-height: 100dvh; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
.xhs-top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 12px 0 4px;
  background: rgba(255, 255, 255, .97);
}
.xhs-ico { flex: none; width: 36px; height: 36px; display: grid; place-items: center; color: #333; }
.xhs-author { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.xhs-avatar { flex: none; width: 32px; height: 32px; }
.xhs-avatar svg { display: block; width: 100%; height: 100%; }
.xhs-name { font-size: 15px; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xhs-follow {
  flex: none; height: 28px; padding: 0 14px; border-radius: 14px;
  display: grid; place-items: center;
  border: 1px solid var(--xhs-red); color: var(--xhs-red); font-size: 14px; font-weight: 500;
}

.xhs-media { position: relative; width: 100%; background: #f3f3f3; overflow: hidden; }
.xhs-track {
  display: flex; width: 100%; height: 100%;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.xhs-track::-webkit-scrollbar { display: none; }
.xhs-slide { position: relative; flex: 0 0 100%; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; }
.xhs-slide img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.img-missing img { visibility: hidden; }
.img-missing::after {
  content: "图片未找到：" attr(data-src);
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  font-size: 13px; color: var(--muted); text-align: center;
}
.xhs-count {
  position: absolute; top: 10px; right: 10px; pointer-events: none;
  padding: 0 9px; border-radius: 11px; line-height: 22px;
  background: rgba(0, 0, 0, .42); color: #fff; font-size: 12px;
}
.xhs-arrow { display: none; }
@media (hover: hover) and (pointer: fine) {
  .xhs-arrow {
    display: grid; place-items: center;
    position: absolute; top: 50%; width: 34px; height: 34px; margin-top: -17px;
    border: 0; border-radius: 50%; background: rgba(255, 255, 255, .88); color: #333;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .18); cursor: pointer;
    opacity: 0; transition: opacity .15s;
  }
  .xhs-media:hover .xhs-arrow { opacity: 1; }
  .xhs-arrow.prev { left: 8px; }
  .xhs-arrow.next { right: 8px; }
  .xhs-arrow.next svg { transform: rotate(180deg); }
  .xhs-arrow.is-off { visibility: hidden; }
}
.xhs-arrow svg { width: 20px; height: 20px; }
.xhs-dots { display: flex; justify-content: center; align-items: center; gap: 5px; height: 22px; }
.xhs-dots i { width: 5px; height: 5px; border-radius: 50%; background: #d8d8d8; }
.xhs-dots i.on { background: #555; }

.xhs-note { padding: 2px 16px 8px; }
.xhs-title { margin: 2px 0 10px; font-size: 18px; font-weight: 600; line-height: 1.45; color: #333; }
.xhs-desc { font-size: 16px; line-height: 1.7; color: #333; white-space: pre-wrap; word-break: break-word; }
.xhs-sticker { width: 1.5em; height: 1.5em; vertical-align: -.4em; }
.xhs-tags { margin-top: 6px; font-size: 16px; line-height: 1.7; color: var(--xhs-tag); word-break: break-word; }
.xhs-date { margin-top: 12px; font-size: 13px; color: var(--xhs-muted); }

/* AI 标签（两组样式完全相同，只有文字不同） */
.ai-label {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 12px; padding: 5px 10px; border-radius: 6px;
  background: #f4f4f4; color: #666; font-size: 13px; line-height: 1.4;
}
.ai-label svg { flex: none; }
.ai-label--onImage { position: absolute; left: 10px; bottom: 10px; margin: 0; background: rgba(0, 0, 0, .5); color: #fff; }
.xhs-labelrow { padding: 0 16px 4px; }
.xhs-labelrow .ai-label { margin: 0; }

/* 研究用“开始评分”区：放在帖子末尾，需要滑到底才会看到 */
.study-next {
  margin: 22px 16px 14px; padding: 16px;
  border-radius: 12px; background: var(--accent-soft); border: 1px dashed #b7c7ee;
}
.study-next p { margin: 0 0 12px; font-size: 14px; line-height: 1.6; color: var(--text-2); text-align: center; }

.xhs-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 5;
  width: 100%; max-width: var(--app-w);
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid #f0f0f0;
}
.xhs-input {
  flex: 1; min-width: 0; height: 36px; padding: 0 12px; border-radius: 18px;
  display: flex; align-items: center; gap: 6px;
  background: #f5f5f5; color: #999; font-size: 14px; white-space: nowrap;
}
.xhs-input svg { flex: none; width: 16px; height: 16px; }
.xhs-stat { flex: none; display: flex; align-items: center; gap: 3px; font-size: 13px; color: #333; }
.xhs-stat svg { width: 22px; height: 22px; }

/* 回看 / 预览浮层 */
.overlay {
  position: fixed; inset: 0; z-index: 500;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: rgba(0, 0, 0, .35);
}
.overlay .xhs { max-width: var(--app-w); margin: 0 auto; }
.study-strip {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: 48px; padding: 0 10px 0 16px;
  background: #1f2937; color: #fff; font-size: 14px;
}
.overlay .xhs-top { top: 48px; }
.strip-btn {
  flex: none; height: 32px; padding: 0 12px; border: 0; border-radius: 8px;
  background: #fff; color: #1f2937; font-size: 14px; font-weight: 600; cursor: pointer;
}

/* ============ 研究人员页面 ============ */
.field { margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.field-label small { display: block; margin-top: 2px; font-weight: 400; color: var(--muted); }
.field input[type="text"] {
  width: 100%; height: 46px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 17px;
}
.field input[type="text"]:focus, .ta:focus, .num input:focus { outline: 3px solid var(--focus); outline-offset: 1px; }
.field-hint { margin-top: 6px; min-height: 1.3em; font-size: 13px; line-height: 1.5; color: var(--muted); }
.field-hint.warn { color: var(--warn); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; flex-direction: column; gap: 3px; height: 100%;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px;
}
.seg small { font-size: 12px; line-height: 1.45; color: var(--muted); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.assign { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.assign-cell {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 12px; color: var(--text-2); cursor: pointer;
}
.assign-cell b { font-size: 14px; color: var(--text); }
.assign-cell em { min-height: 1.3em; font-size: 11px; font-style: normal; }
.assign-cell.done { background: #eef7ef; border-color: #bcdcc1; }
.assign-cell.done em { color: var(--ok); }
.assign-cell.prog em { color: var(--warn); }
.assign-cell.wd em { color: var(--danger); }

.resume {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 16px; padding: 12px; border-radius: 10px;
  background: var(--warn-bg); color: #6b4a12; font-size: 14px; line-height: 1.5;
}
.warn { margin-bottom: 16px; padding: 12px; border-radius: 10px; background: #fdecea; color: #8c2a22; font-size: 14px; line-height: 1.5; }
.summary { margin-bottom: 16px; padding: 12px; border-radius: 10px; background: var(--soft); font-size: 14px; line-height: 1.75; color: var(--text-2); }
.ta {
  width: 100%; min-height: 76px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 15px; line-height: 1.5; resize: vertical;
}
.ta-dump { min-height: 160px; margin-top: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.sess { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sess-main { flex: 1; min-width: 0; }
.sess-main b { font-size: 15px; }
.sess-meta { margin-top: 2px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 9px; background: #eef0f3; color: var(--text-2); font-size: 12px; vertical-align: 1px; }
.badge.done { background: #e6f4e8; color: var(--ok); }
.badge.prog { background: var(--warn-bg); color: var(--warn); }
.badge.wd { background: #fdecea; color: var(--danger); }

.ver { margin: -6px 0 16px; font-size: 12px; color: var(--muted); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.paste { margin-top: 10px; font-size: 14px; color: var(--text-2); }
.paste summary { cursor: pointer; padding: 6px 0; }
.paste .btn { margin-top: 8px; }

.pv { margin-bottom: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.pv-meta { font-size: 12px; color: var(--muted); }
.pv-title { margin: 4px 0 10px; font-size: 15px; font-weight: 600; }
.tag-warn { color: var(--warn); }

/* ============ 弹窗 / 提示 ============ */
.dlg-wrap { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: rgba(15, 20, 30, .45); }
.dlg { width: 100%; max-width: 360px; padding: 20px 18px 16px; border-radius: 14px; background: #fff; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dlg-title { margin-bottom: 8px; font-size: 17px; font-weight: 600; }
.dlg-text { margin-bottom: 16px; font-size: 15px; line-height: 1.6; color: var(--text-2); }
.dlg-actions { display: flex; gap: 10px; }
.dlg-actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 1100;
  max-width: 90vw; padding: 10px 16px; border-radius: 10px;
  background: rgba(20, 24, 31, .9); color: #fff; font-size: 14px; transition: opacity .3s;
}
.toast.out { opacity: 0; }

#rs-hotspot { position: fixed; top: 0; left: 0; z-index: 900; width: 56px; height: 56px; display: none; }
body.in-session #rs-hotspot { display: block; }
