/* =========================================================
   xue · core layout (共享核心版式)
   学生四问驱动：我在哪 / 下一步 / 我做过什么 / 为什么算数。
   每个视图必须能回答四问；本文件提供其骨架。
   依赖 tokens.css，禁止在此文件出现裸色值。
   ========================================================= */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--xue-bg); color: var(--xue-ink);
  font-family: var(--xue-font-body); font-size: var(--xue-fs-md);
  line-height: var(--xue-lh-ui);
}
:focus-visible { outline: 2px solid var(--xue-focus); outline-offset: 2px; border-radius: 2px; }
a { color: var(--xue-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ---------- 应用壳：顶栏（回答「我在哪」） ---------- */
.xue-topbar {
  position: sticky; top: 0; z-index: var(--xue-z-topbar);
  display: flex; align-items: center; gap: var(--xue-sp-4);
  height: var(--xue-topbar-h); padding: 0 var(--xue-sp-4);
  background: color-mix(in srgb, var(--xue-surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--xue-line);
}
.xue-crumbs { display: flex; align-items: center; gap: var(--xue-sp-2); min-width: 0;
  font-size: var(--xue-fs-sm); color: var(--xue-ink-2); white-space: nowrap; overflow: hidden; }
.xue-crumbs a { color: var(--xue-ink-2); }
.xue-crumbs .sep { color: var(--xue-muted); }
.xue-crumbs .here { color: var(--xue-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.xue-topbar .spacer { flex: 1; }
.xue-session { font-size: var(--xue-fs-xs); color: var(--xue-muted); }

/* ---------- 容器 ---------- */
.xue-main { max-width: var(--xue-measure-wide); margin: 0 auto; padding: var(--xue-sp-5) var(--xue-sp-4) var(--xue-sp-7); }
.xue-reading { max-width: var(--xue-measure-reading); margin: 0 auto; }

/* ---------- 学习单元地图（回答「下一步」） ---------- */
.xue-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--xue-sp-4); }
.xue-unit-card {
  display: flex; flex-direction: column; gap: var(--xue-sp-2);
  padding: var(--xue-sp-4); background: var(--xue-surface);
  border: 1px solid var(--xue-line); border-left: 4px solid var(--xue-st-none);
  border-radius: var(--xue-r-md); box-shadow: var(--xue-shadow);
  color: inherit; text-align: left; cursor: pointer;
  transition: transform var(--xue-t-fast), border-color var(--xue-t-fast);
}
.xue-unit-card:hover { transform: translateY(-2px); text-decoration: none; }
.xue-unit-card[data-status="in_progress"] { border-left-color: var(--xue-st-progress); }
.xue-unit-card[data-status="completed"]  { border-left-color: var(--xue-st-done); }
.xue-unit-card[data-status="mastered"]   { border-left-color: var(--xue-st-mastered); }
.xue-unit-card h3 { margin: 0; font-size: var(--xue-fs-md); }
.xue-unit-card .kicker { font-size: var(--xue-fs-xs); color: var(--xue-muted); }
.xue-unit-card .prereq { font-size: var(--xue-fs-xs); color: var(--xue-ink-2); }
.xue-unit-card .prereq b { color: var(--xue-st-progress); font-weight: 600; }

/* 「继续学习」主行动条：地图页唯一主 CTA */
.xue-continue {
  display: flex; align-items: center; gap: var(--xue-sp-4);
  margin-bottom: var(--xue-sp-5); padding: var(--xue-sp-4);
  background: var(--xue-surface); border: 1px solid var(--xue-line);
  border-radius: var(--xue-r-lg); box-shadow: var(--xue-shadow);
}
.xue-continue .what { flex: 1; min-width: 0; }
.xue-continue .what .kicker { font-size: var(--xue-fs-xs); color: var(--xue-muted); }
.xue-continue .what .title { font-weight: 600; }

/* ---------- 状态徽章（全系统统一词汇） ---------- */
.xue-status { display: inline-flex; align-items: center; gap: .35em;
  font-size: var(--xue-fs-xs); color: var(--xue-ink-2); }
.xue-status::before { content: ""; width: .6em; height: .6em; border-radius: 50%;
  background: var(--xue-st-none); }
.xue-status[data-status="in_progress"]::before { background: var(--xue-st-progress); }
.xue-status[data-status="completed"]::before  { background: var(--xue-st-done); }
.xue-status[data-status="mastered"]::before   { background: var(--xue-st-mastered); }

.xue-vbadge { display: inline-block; padding: 0 .5em; border-radius: var(--xue-r-full);
  font-size: var(--xue-fs-xs); line-height: 1.6; color: var(--xue-bg);
  background: var(--xue-v-unverified); }
.xue-vbadge[data-v="auto"]     { background: var(--xue-v-auto); }
.xue-vbadge[data-v="ai"]       { background: var(--xue-v-ai); }
.xue-vbadge[data-v="human"]    { background: var(--xue-v-human); }
.xue-vbadge[data-v="inferred"] { background: var(--xue-v-inferred); }

/* ---------- 单元学习页：内容列 + 行动栏 ---------- */
.xue-unit-layout { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; gap: var(--xue-sp-6); }
@media (max-width: 56rem) { .xue-unit-layout { grid-template-columns: 1fr; } }
.xue-rail { position: sticky; top: calc(var(--xue-topbar-h) + var(--xue-sp-4)); align-self: start;
  display: flex; flex-direction: column; gap: var(--xue-sp-3); }
@media (max-width: 56rem) { .xue-rail { position: static; } }
.xue-rail .card { padding: var(--xue-sp-4); background: var(--xue-surface);
  border: 1px solid var(--xue-line); border-radius: var(--xue-r-md); }
.xue-rail h4 { margin: 0 0 var(--xue-sp-2); font-size: var(--xue-fs-sm); color: var(--xue-ink-2); }

/* 课文内容块 */
.xue-content { font-size: var(--xue-fs-reading); line-height: var(--xue-lh-reading); }
.xue-content p { margin: 0 0 1em; }
.xue-chunk { position: relative; }
.xue-chunk .page-anchor { position: absolute; right: 100%; margin-right: var(--xue-sp-3);
  font-size: var(--xue-fs-xs); color: var(--xue-muted); font-family: var(--xue-font-mono);
  user-select: none; white-space: nowrap; }
@media (max-width: 72rem) {
  .xue-chunk .page-anchor { position: static; display: inline-flex; margin: 0 0 var(--xue-sp-2); user-select: auto; }
}
.xue-chunk figure { margin: var(--xue-sp-5) 0; padding: var(--xue-sp-4);
  background: var(--xue-surface-2); border-radius: var(--xue-r-md); text-align: center; }
.xue-chunk audio, .xue-chunk video { display: block; width: 100%; max-width: 100%; }
.xue-chunk figcaption { margin-top: var(--xue-sp-2); font-size: var(--xue-fs-sm); color: var(--xue-ink-2); }
.xue-chunk table { border-collapse: collapse; width: 100%; font-size: var(--xue-fs-md); }
.xue-chunk th, .xue-chunk td { border: 1px solid var(--xue-line); padding: var(--xue-sp-2) var(--xue-sp-3); }
.xue-chunk th { background: var(--xue-surface-2); }
.xue-table-scroll { overflow-x: auto; }
.math-fallback { font-family: var(--xue-font-mono); background: var(--xue-warn-bg);
  color: var(--xue-warn-ink); padding: 0 .3em; border-radius: var(--xue-r-sm); }

/* 课标锚 chips（回答「为什么学这个」） */
.xue-std-refs { display: flex; flex-wrap: wrap; gap: var(--xue-sp-2); margin: var(--xue-sp-4) 0; }
.xue-std-chip { font-size: var(--xue-fs-xs); padding: .2em .7em;
  background: var(--xue-surface-2); border: 1px solid var(--xue-line);
  border-radius: var(--xue-r-full); color: var(--xue-ink-2); cursor: pointer; }
.xue-std-chip:hover { border-color: var(--xue-accent); color: var(--xue-accent); }

/* ---------- 练习卡（尝试-反馈-重试，历史不灭） ---------- */
.xue-practice { margin-top: var(--xue-sp-6); padding: var(--xue-sp-5);
  background: var(--xue-surface); border: 1px solid var(--xue-line); border-radius: var(--xue-r-lg); }
.xue-practice .stem { font-size: var(--xue-fs-reading); line-height: var(--xue-lh-reading); }
.xue-choices { display: flex; flex-direction: column; gap: var(--xue-sp-2); margin: var(--xue-sp-4) 0; }
.xue-choice { display: flex; gap: var(--xue-sp-3); align-items: baseline;
  padding: var(--xue-sp-3) var(--xue-sp-4); border: 1px solid var(--xue-line);
  border-radius: var(--xue-r-md); background: var(--xue-surface); cursor: pointer;
  font-size: var(--xue-fs-md); text-align: left; color: inherit; width: 100%;
  transition: border-color var(--xue-t-fast); }
.xue-choice:hover { border-color: var(--xue-accent); }
.xue-choice[aria-pressed="true"] { border-color: var(--xue-accent); box-shadow: inset 0 0 0 1px var(--xue-accent); }
.xue-feedback { margin-top: var(--xue-sp-4); padding: var(--xue-sp-4); border-radius: var(--xue-r-md);
  font-size: var(--xue-fs-md); }
.xue-feedback[data-kind="ok"]   { background: var(--xue-ok-bg); color: var(--xue-ok-ink); }
.xue-feedback[data-kind="err"]  { background: var(--xue-err-bg); color: var(--xue-err-ink); }
.xue-feedback[data-kind="info"] { background: var(--xue-surface-2); color: var(--xue-ink-2); }
.xue-attempts { margin-top: var(--xue-sp-4); border-top: 1px dashed var(--xue-line); padding-top: var(--xue-sp-3); }
.xue-attempts li { font-size: var(--xue-fs-sm); color: var(--xue-ink-2); margin: .3em 0; }

/* ---------- 按钮 ---------- */
.xue-btn { display: inline-flex; align-items: center; gap: .4em;
  padding: .55em 1.2em; border-radius: var(--xue-r-md); border: 1px solid var(--xue-line);
  background: var(--xue-surface); color: var(--xue-ink); font-size: var(--xue-fs-md);
  cursor: pointer; transition: filter var(--xue-t-fast); }
.xue-btn:hover { filter: brightness(.97); }
.xue-btn.primary { background: var(--xue-accent); color: var(--xue-accent-ink); border-color: transparent; }
.xue-btn:disabled { opacity: .5; cursor: not-allowed; }
.xue-btn.ghost { border-color: transparent; background: transparent; color: var(--xue-accent); }

/* ---------- 证据抽屉（回答「为什么算数」） ---------- */
.xue-stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: var(--xue-sp-3); }
.xue-stat { display: flex; flex-direction: column; gap: var(--xue-sp-1); align-items: flex-start;
  padding: var(--xue-sp-4); background: var(--xue-surface); border: 1px solid var(--xue-line);
  border-radius: var(--xue-r-md); cursor: pointer; color: inherit; text-align: left;
  font: inherit; }
.xue-stat:hover { border-color: var(--xue-accent); }
.xue-stat .value { font-size: var(--xue-fs-2xl); font-weight: 650; line-height: 1.1; }
.xue-stat .label { font-size: var(--xue-fs-sm); color: var(--xue-ink-2); }
.xue-stat .why { font-size: var(--xue-fs-xs); color: var(--xue-accent); }

dialog.xue-drawer { position: fixed; inset: 0 0 0 auto; height: 100dvh; max-height: none;
  width: min(28rem, 92vw); margin: 0; padding: 0; border: none; border-left: 1px solid var(--xue-line);
  background: var(--xue-surface); color: var(--xue-ink); box-shadow: var(--xue-shadow);
  z-index: var(--xue-z-drawer); }
dialog.xue-drawer::backdrop { background: rgba(0,0,0,.35); }
.xue-drawer .head { display: flex; align-items: center; gap: var(--xue-sp-3);
  padding: var(--xue-sp-4); border-bottom: 1px solid var(--xue-line); }
.xue-drawer .head h3 { margin: 0; flex: 1; font-size: var(--xue-fs-md); }
.xue-drawer .body { padding: var(--xue-sp-4); overflow-y: auto; height: calc(100dvh - var(--xue-topbar-h)); }
.xue-ev-item { padding: var(--xue-sp-3) 0; border-bottom: 1px dashed var(--xue-line); }
.xue-ev-item .row1 { display: flex; align-items: center; gap: var(--xue-sp-2); font-size: var(--xue-fs-sm); }
.xue-ev-item .row1 .type { font-weight: 600; }
.xue-ev-item time { font-size: var(--xue-fs-xs); color: var(--xue-muted); font-family: var(--xue-font-mono); }
.xue-ev-item .detail { margin-top: var(--xue-sp-1); font-size: var(--xue-fs-sm); color: var(--xue-ink-2); }
.xue-ev-item .superseded { text-decoration: line-through; opacity: .6; }

/* ---------- 引证卡（AI 接地） ---------- */
.xue-cite-answer { font-size: var(--xue-fs-md); line-height: 1.8; }
.xue-cite-mark { display: inline-block; padding: 0 .45em; margin: 0 .1em;
  border-radius: var(--xue-r-full); background: var(--xue-surface-2);
  border: 1px solid var(--xue-line); font-size: var(--xue-fs-xs);
  color: var(--xue-accent); cursor: pointer; vertical-align: super; line-height: 1.5; }
.xue-cite-sources { margin-top: var(--xue-sp-3); display: flex; flex-direction: column; gap: var(--xue-sp-2); }
.xue-cite-src { display: flex; gap: var(--xue-sp-2); align-items: baseline;
  font-size: var(--xue-fs-sm); color: var(--xue-ink-2); padding: var(--xue-sp-2) var(--xue-sp-3);
  background: var(--xue-surface-2); border-radius: var(--xue-r-sm); cursor: pointer; }
.xue-cite-src:hover { color: var(--xue-accent); }
.xue-cite-src .quote { font-family: var(--xue-font-serif); }
.xue-uncited { padding: var(--xue-sp-4); background: var(--xue-warn-bg); color: var(--xue-warn-ink);
  border-radius: var(--xue-r-md); font-size: var(--xue-fs-sm); }
.xue-uncited details { margin-top: var(--xue-sp-2); }

/* ---------- 互动转化引擎（interaction-engine）---------- */
.xue-ix { margin-top: var(--xue-sp-6); padding: var(--xue-sp-5);
  background: var(--xue-surface); border: 1px solid var(--xue-line);
  border-radius: var(--xue-r-lg); box-shadow: var(--xue-shadow); }
.xue-ix-head { display: flex; align-items: flex-start; gap: var(--xue-sp-3); }
.xue-ix-head h3 { margin: var(--xue-sp-1) 0 0; font-size: var(--xue-fs-lg); }
.xue-ix-head > div:first-child { flex: 1; }
.xue-ix-source { margin: var(--xue-sp-3) 0; padding: var(--xue-sp-4);
  background: var(--xue-surface-2); border-radius: var(--xue-r-md);
  font-size: var(--xue-fs-reading); line-height: var(--xue-lh-reading);
  border-inline-start: 3px solid var(--xue-accent); }
.xue-ix-objectives { display: flex; flex-direction: column; gap: var(--xue-sp-2);
  margin: var(--xue-sp-3) 0; font-size: var(--xue-fs-sm); color: var(--xue-ink-2); }
.xue-ix-evidence-req { padding: var(--xue-sp-2) var(--xue-sp-3);
  background: var(--xue-surface-2); border-radius: var(--xue-r-sm); }
.xue-ix-phases { display: flex; gap: var(--xue-sp-2); margin: var(--xue-sp-4) 0; }
.xue-ix-phase { padding: .2em .8em; border-radius: var(--xue-r-full);
  font-size: var(--xue-fs-xs); color: var(--xue-muted);
  border: 1px solid var(--xue-line); }
.xue-ix-phase.current { color: var(--xue-accent-ink); background: var(--xue-accent);
  border-color: transparent; font-weight: 600; }
.xue-ix-phase.done { color: var(--xue-st-done); border-color: var(--xue-st-done); }
.xue-ix-stage { margin: var(--xue-sp-4) 0; }
.xue-ix-current { font-size: var(--xue-fs-lg); text-align: center;
  padding: var(--xue-sp-4); background: var(--xue-surface-2);
  border-radius: var(--xue-r-md); margin-bottom: var(--xue-sp-3); }
.xue-ix-trail { margin: 0 0 var(--xue-sp-3); padding-left: 1.5em;
  font-size: var(--xue-fs-md); color: var(--xue-ink-2); }
.xue-ix-trail li { margin: .35em 0; }
.xue-ix-predict { margin-top: var(--xue-sp-3); }
.xue-ix-balance svg { width: 100%; max-width: 30rem; display: block; margin: 0 auto;
  transition: transform var(--xue-t-med); }
.xue-ix-readout { text-align: center; font-family: var(--xue-font-mono);
  font-size: var(--xue-fs-sm); color: var(--xue-ink-2); margin: var(--xue-sp-2) 0 var(--xue-sp-3); }
.xue-ix-foot { display: flex; align-items: center; justify-content: space-between;
  gap: var(--xue-sp-3); margin-top: var(--xue-sp-3); padding-top: var(--xue-sp-3);
  border-top: 1px dashed var(--xue-line); font-size: var(--xue-fs-xs); color: var(--xue-muted); }

/* ---------- 原页查看器（ADR-006 单页交付） ---------- */
dialog.xue-pageviewer { position: fixed; inset: 0; width: 100vw; height: 100dvh;
  max-width: none; max-height: none; margin: 0; padding: 0; border: none;
  background: color-mix(in srgb, var(--xue-bg) 96%, black); z-index: var(--xue-z-drawer); }
.xue-pageviewer .pv-head { display: flex; align-items: center; gap: var(--xue-sp-3);
  padding: var(--xue-sp-2) var(--xue-sp-4); border-bottom: 1px solid var(--xue-line);
  background: var(--xue-surface); }
.xue-pageviewer .pv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1; }
.xue-pageviewer .pv-pageno { font-family: var(--xue-font-mono); font-size: var(--xue-fs-sm);
  color: var(--xue-ink-2); }
.xue-pageviewer .pv-stage { position: relative; height: calc(100dvh - 3.2rem);
  display: flex; align-items: center; justify-content: center; }
.xue-pageviewer .pv-img { max-height: 100%; max-width: min(92vw, 60rem);
  box-shadow: var(--xue-shadow); background: white; }
.xue-pageviewer .pv-nav { position: absolute; top: 50%; transform: translateY(-50%);
  width: 3rem; height: 6rem; border: none; border-radius: var(--xue-r-md);
  background: color-mix(in srgb, var(--xue-surface) 70%, transparent);
  color: var(--xue-ink); font-size: 2rem; cursor: pointer; }
.xue-pageviewer .pv-prev { left: var(--xue-sp-3); }
.xue-pageviewer .pv-next { right: var(--xue-sp-3); }
button.page-anchor { background: none; border: none; cursor: pointer; padding: 0;
  color: var(--xue-accent); font: inherit; font-size: var(--xue-fs-xs);
  font-family: var(--xue-font-mono); }
button.page-anchor:hover { text-decoration: underline; }

/* ---------- 书架（真书封） ---------- */
.shelf-hero { margin: 0 0 var(--xue-sp-5); }
.shelf-sub { color: var(--xue-ink-2); margin: var(--xue-sp-1) 0 0; font-size: var(--xue-fs-sm); }
.shelf-stage { font-size: var(--xue-fs-lg); margin: var(--xue-sp-6) 0 var(--xue-sp-2);
  padding-bottom: var(--xue-sp-2); border-bottom: 2px solid var(--xue-line); }
.shelf-subject { font-size: var(--xue-fs-sm); color: var(--xue-ink-2); margin: var(--xue-sp-4) 0 var(--xue-sp-2); }
.shelf-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: var(--xue-sp-4); }
.shelf-book { display: flex; flex-direction: column; gap: var(--xue-sp-1);
  color: inherit; text-decoration: none; }
.shelf-book:hover { text-decoration: none; }
.shelf-cover { position: relative; display: block; aspect-ratio: 1 / 1.41;
  border-radius: var(--xue-r-sm); overflow: hidden; background: var(--xue-surface-2);
  box-shadow: var(--xue-shadow); transition: transform var(--xue-t-fast), box-shadow var(--xue-t-fast); }
.shelf-book:hover .shelf-cover { transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.shelf-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shelf-resume { position: absolute; left: 0; bottom: 0; right: 0;
  padding: .15em .5em; font-size: var(--xue-fs-xs);
  background: color-mix(in srgb, var(--xue-ink) 78%, transparent); color: var(--xue-bg); }
.shelf-name { font-size: var(--xue-fs-sm); font-weight: 600; line-height: 1.35; }
.shelf-meta { font-size: var(--xue-fs-xs); color: var(--xue-muted); }

/* ---------- 整册阅读器 ---------- */
body.reading .xue-main { max-width: none; padding: 0; }
.rd-root { min-height: 100dvh; }
.rd-bar { position: sticky; top: var(--xue-topbar-h); z-index: 30;
  display: flex; align-items: center; gap: var(--xue-sp-3);
  padding: var(--xue-sp-2) var(--xue-sp-4);
  background: color-mix(in srgb, var(--xue-surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--xue-line); }
.rd-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.rd-pageno { font-family: var(--xue-font-mono); font-size: var(--xue-fs-sm);
  color: var(--xue-ink-2); }
.rd-progress { position: sticky; top: calc(var(--xue-topbar-h) + 2.6rem); z-index: 30;
  height: 2px; background: var(--xue-line); }
.rd-progress-fill { height: 100%; width: 0; background: var(--xue-accent);
  transition: width var(--xue-t-fast); }
.rd-stream { max-width: 60rem; margin: 0 auto; padding: var(--xue-sp-4);
  display: flex; flex-direction: column; gap: var(--xue-sp-4); }
.rd-stream.full { max-width: none; }
.rd-page { background: var(--xue-surface-2); border-radius: 2px;
  box-shadow: var(--xue-shadow); overflow: hidden; }
.rd-page.ready { background: white; }
.rd-img { width: 100%; height: 100%; display: block; }

/* ---------- 杂项 ---------- */
.xue-empty { padding: var(--xue-sp-6); text-align: center; color: var(--xue-muted); }
.xue-toast { position: fixed; bottom: var(--xue-sp-5); left: 50%; transform: translateX(-50%);
  z-index: var(--xue-z-toast); padding: var(--xue-sp-3) var(--xue-sp-5);
  background: var(--xue-ink); color: var(--xue-bg); border-radius: var(--xue-r-full);
  font-size: var(--xue-fs-sm); box-shadow: var(--xue-shadow); }
.xue-kicker { font-size: var(--xue-fs-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--xue-muted); }
h1.xue-h1 { font-size: var(--xue-fs-xl); margin: 0 0 var(--xue-sp-4); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; }
