/* 问知学伴 · iPad 优先样式 */
:root {
  --bg: light-dark(#eef1f6, #14161c);
  --surface: light-dark(#ffffff, #20242d);
  --surface2: light-dark(#f5f7fb, #272c37);
  --ink: light-dark(#1c2531, #e9ecf2);
  --sub: light-dark(#5d6776, #a3acb9);
  --line: light-dark(#e2e6ee, #343b48);
  --blue: light-dark(#2e62dc, #82a5ff);
  --blue-soft: light-dark(#e9efff, #2b3a5e);
  --orange: light-dark(#c96f0a, #f0a35c);
  --orange-soft: light-dark(#fdf1e2, #3d3120);
  --green: light-dark(#1d8a55, #5ec99b);
  --green-soft: light-dark(#e4f5ec, #1e3a2c);
  --red: light-dark(#d24848, #ff8080);
  --red-soft: light-dark(#fce9e9, #42252a);
  color-scheme: light dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  padding: 0 0 calc(74px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 860px; margin: 0 auto; padding: 14px 16px 20px; display: grid; gap: 12px; }

/* ---------- 通用 ---------- */
h1 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 500; }
p { margin: 0 0 8px; }
a { color: var(--blue); text-decoration: none; }
.muted { color: var(--sub); }
.small { font-size: 12px; }
.center { text-align: center; }
.hide { display: none; }
.pre { white-space: pre-wrap; margin: 0; line-height: 1.8; }
.error { color: var(--red); }
.loading { text-align: center; color: var(--sub); padding: 40px 0; }

.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
.tilecol { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-content: start; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1.2fr 1fr; } }

.chiprow { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: var(--surface2); color: var(--sub); border: 1px solid var(--line);
  white-space: nowrap;
}
button.chip { cursor: pointer; font-family: inherit; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.orange { background: var(--orange-soft); color: var(--orange); border-color: transparent; }
.chip.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.chip.sel { outline: 2px solid currentColor; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-size: 14px; padding: 9px 16px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--ink); cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--blue); border-color: transparent; color: light-dark(#fff, #10151f); }
.btn.big { padding: 13px 18px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--red); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.input, textarea.input {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px;
}
textarea.input { resize: vertical; }
.frow { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center; margin: 8px 0; }
.frow label { font-size: 13px; color: var(--sub); }

/* ---------- 首页 ---------- */
.weak { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 4px 0; }
.weak .wbar { flex: 1; max-width: 200px; height: 6px; border-radius: 999px; background: var(--surface2); overflow: hidden; }
.weak .wbar i { display: block; height: 100%; border-radius: 999px; background: var(--blue); }
.weak .pct { font-size: 12px; color: var(--sub); }

.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 15px; font-weight: 500; text-align: left; cursor: pointer;
}
.tile small { font-size: 12px; color: var(--sub); font-weight: 400; }
.tile.orange { color: var(--orange); }
.tile.orange small { color: var(--sub); }

/* ---------- 题图 / 遮挡 ---------- */
.qprev { position: relative; margin: 8px 0; }
.qprev img.fit, .qprev canvas.fit { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); }
.qprev .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 10px; }
.qprev canvas.overlay { touch-action: none; cursor: crosshair; }
.cropwrap { position: relative; width: 100%; max-width: 720px; margin: 0 auto; }
.cropwrap canvas { display: block; width: 100%; height: auto; border-radius: 10px; touch-action: none; cursor: crosshair; }
.qtext { font-size: 16px; margin: 8px 0; line-height: 1.8; }
.masknote { position: absolute; top: 8px; right: 8px; font-size: 11px; background: var(--orange-soft); color: var(--orange); padding: 2px 8px; border-radius: 999px; }

/* ---------- 错题本 ---------- */
.wqitem { display: flex; gap: 10px; align-items: center; color: inherit; }
.wqitem img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); flex: none; }
.wqitem .t { flex: 1; min-width: 0; }
.wqitem .t .line1 { font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.filterrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filterrow .input { width: auto; flex: 1; min-width: 120px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 70vh; display: grid; place-items: center; }
.login-card { width: min(360px, 90vw); text-align: center; display: grid; gap: 12px; padding: 28px 24px; }

/* ---------- 底部导航 / 提示 ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: none; border: 0; padding: 7px 0 6px;
  font: inherit; font-size: 11px; color: var(--sub); cursor: pointer;
}
#tabbar button:first-child { font-size: 17px; }
#tabbar button.on { color: var(--blue); }
#tabbar.hidden { display: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: light-dark(#253044, #3a4456); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .25s; z-index: 50; max-width: 80vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }

/* 复习自评三键 */
.grade-no { color: var(--red); }
.grade-mid { color: var(--orange); }
.grade-ok { color: var(--green); }

/* 追问讨论 */
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .b { max-width: 85%; padding: 9px 13px; border-radius: 13px; font-size: 14px; }
.msg.user .b { background: var(--blue-soft); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant .b { background: var(--surface2); border: 1px solid var(--line); border-bottom-left-radius: 4px; width: 100%; max-width: 100%; }
.concl { border: 1.5px solid var(--blue); }
.warnline { color: var(--orange); }
.threaditem { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); color: inherit; }
.threaditem:first-of-type { border-top: 0; }
.threaditem .t1 { font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.weak { color: inherit; }
