/* === 设计 token: 与主 viewer (style.css) 同源 === */
:root {
  --primary: #c8553d; --primary-light: #fdeae5;
  --accent: #2d6a7e; --accent-light: #e7f0f3;
  --green: #5b8c5a; --green-light: #e8f3e8;
  --orange: #d4863a; --orange-light: #fdf2e2;
  --bg: #f7f6f3; --card-bg: #ffffff;
  --text: #2c2620; --text-light: #6b5d50; --text-muted: #a09385;
  --border: #e8e2d8; --radius: 10px;
  --shadow: 0 1px 3px rgba(44,38,32,0.08);
  --shadow-lg: 0 4px 16px rgba(44,38,32,0.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
button { font-family: inherit; }

/* === 顶栏 === */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card-bg); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--text); }
.brand h1 { font-size: 17px; font-weight: 600; }
.brand .sub { font-size: 11px; color: var(--text-muted); letter-spacing: .5px; }
.topbar-spacer { flex: 1; }
.ub-profile { font-size: 12px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.ub-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--card-bg); color: var(--text-light); cursor: pointer; transition: all .15s; white-space: nowrap; }
.ub-btn:hover { border-color: var(--accent); color: var(--accent); }
.ub-btn.danger:hover { border-color: var(--primary); color: var(--primary); }
/* tabs */
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab-btn { font-size: 13px; padding: 7px 14px; border: none; border-radius: 8px; background: transparent; color: var(--text-light); cursor: pointer; transition: all .15s; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
/* 图谱子页: 顶栏(56px)以下全部给 iframe */
#graph-pane { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--bg); transition: left .2s; }
#graph-pane[hidden] { display: none; }
#graph-frame { width: 100%; height: 100%; border: none; display: block; }

/* === 共享侧边栏(可收起,两个 tab 通用;样式对齐主 viewer) === */
#sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 290px; background: var(--card-bg); border-right: 1px solid var(--border); z-index: 15; display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .2s; }
body.sb-open #sidebar { transform: none; }
body.sb-open .main { margin-left: 290px; }
body.sb-open #graph-pane { left: 290px; }
.sb-search { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); position: relative; }
.sb-search input { width: 100%; font-size: 13px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); transition: border-color .15s; }
.sb-search input:focus { outline: none; border-color: var(--accent); background: #fff; }
.sb-dims { display: flex; gap: 5px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sb-dim { flex: 1; min-width: 56px; font-size: 11.5px; padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); color: var(--text-light); cursor: pointer; transition: all .15s; white-space: nowrap; }
.sb-dim:hover { border-color: var(--text-muted); }
.sb-dim.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 500; }
.sb-age-filter { display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }
.sb-age-filter select { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text-light); font: inherit; cursor: pointer; }
.sb-age-filter select:focus { outline: none; border-color: var(--accent); }
.sb-tree { flex: 1; overflow-y: auto; padding: 8px 0 16px; }
.sb-loading { color: var(--text-muted); font-size: 13px; padding: 16px 20px; }
.sb-subject-h { display: flex; align-items: center; gap: 6px; padding: 8px 16px; cursor: pointer; font-size: 13.5px; transition: background .15s; user-select: none; }
.sb-subject-h:hover { background: var(--bg); }
.sb-subject-h .arrow { font-size: 10px; color: var(--text-muted); width: 10px; transition: transform .15s; }
.sb-subject.open > .sb-subject-h .arrow { transform: rotate(90deg); }
.sb-subject-h .cnt { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.sb-domains { display: none; padding-bottom: 4px; }
.sb-subject.open > .sb-domains { display: block; }
.sb-domain-h { display: flex; align-items: center; padding: 5px 16px 5px 34px; font-size: 12.5px; color: var(--text-light); cursor: pointer; transition: background .15s; user-select: none; }
.sb-domain-h:hover { background: var(--bg); color: var(--text); }
.sb-domain-h .cnt { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.sb-topics { display: none; }
.sb-domain.open > .sb-topics { display: block; }
.sb-topic { display: block; padding: 4px 16px 4px 48px; font-size: 12px; color: var(--text-light); cursor: pointer; line-height: 1.5; transition: background .15s; }
.sb-topic:hover { background: var(--accent-light); color: var(--accent); }
.sb-topic .age { color: var(--text-muted); font-size: 10.5px; margin-left: 4px; }
.sb-toggle { font-size: 16px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--card-bg); color: var(--text-light); cursor: pointer; transition: all .15s; }
.sb-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* === 主容器 === */
.main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.section-title .n { font-size: 12px; font-weight: 400; color: var(--text-muted); }

/* === 学习面板(标记 + 已掌握 + 推荐) === */
.panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px; }
.mark-row { display: flex; gap: 10px; }
#mark-input { flex: 1; font-size: 14px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; resize: vertical; min-height: 44px; max-height: 160px; background: var(--bg); transition: border-color .15s; }
#mark-input:focus { outline: none; border-color: var(--accent); background: #fff; }
#mark-btn { font-size: 14px; font-weight: 500; padding: 0 20px; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; transition: opacity .15s; flex-shrink: 0; }
#mark-btn:hover { opacity: .9; }
#mark-btn:disabled { opacity: .5; cursor: wait; }
.mark-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.mark-hint kbd { font-size: 10.5px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }

/* AI 确认区 */
#confirm-area { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 4px; }
#confirm-area[hidden] { display: none; }
.parsing { display: flex; align-items: center; gap: 10px; padding: 14px 4px; font-size: 13px; color: var(--text-light); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.claim-block { padding: 12px 0 6px; border-bottom: 1px dashed var(--border); }
.claim-block:last-of-type { border-bottom: none; }
.claim-txt { font-size: 13px; margin-bottom: 8px; color: var(--text-light); }
.claim-txt b { color: var(--text); font-weight: 600; }
.cand { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; border: 1.5px solid var(--border); border-radius: 18px; padding: 6px 13px; margin: 0 8px 8px 0; cursor: pointer; background: var(--card-bg); user-select: none; transition: all .15s; }
.cand:hover { border-color: var(--green); }
.cand.on { border-color: var(--green); background: var(--green-light); }
.cand .ck { width: 15px; height: 15px; border: 1.5px solid var(--text-muted); border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; flex-shrink: 0; transition: all .15s; }
.cand.on .ck { background: var(--green); border-color: var(--green); }
.cand .s { font-size: 11px; color: var(--text-muted); }
.cand .cf { font-size: 10.5px; color: var(--text-muted); }
.cand-note { font-size: 11.5px; color: var(--text-muted); margin: -4px 0 8px 6px; }
.cand-none { font-size: 12.5px; color: var(--text-muted); padding: 10px 4px; }
.mem-note { font-size: 12.5px; color: var(--green); padding: 10px 4px 0; }
.mem-note a { cursor: pointer; text-decoration: underline; color: inherit; }
.confirm-actions { margin: 12px 0 6px; display: flex; gap: 10px; align-items: center; }
.btn { font-size: 13px; padding: 8px 18px; border-radius: 7px; cursor: pointer; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); transition: all .15s; }
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { opacity: .9; }

/* 已掌握: 学科聚合 + 抽屉 */
#mastered-wrap { margin-top: 16px; }
#mastered-wrap[hidden] { display: none; }
.mb-head { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; font-size: 12.5px; }
.mb-head .lbl { color: var(--text-light); font-weight: 500; }
.schip { display: inline-flex; align-items: center; gap: 5px; background: var(--green-light); border: 1px solid #cfe3ce; color: #3d6b3c; border-radius: 14px; padding: 4px 12px; cursor: pointer; user-select: none; transition: all .15s; }
.schip:hover { border-color: var(--green); }
.schip.open { background: var(--green); color: #fff; border-color: var(--green); }
.schip .cnt { font-weight: 700; }
.schip .caret { font-size: 9px; opacity: .6; }
.mb-clear { font-size: 11.5px; color: var(--text-muted); cursor: pointer; margin-left: 2px; }
.mb-clear:hover { color: var(--primary); }
.mb-drawer { margin-top: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; max-height: 240px; overflow-y: auto; }
.mb-drawer[hidden] { display: none; }
.mb-age-lbl { font-size: 11px; color: var(--text-muted); margin: 6px 0 4px; }
.mb-age-grp:first-child .mb-age-lbl { margin-top: 0; }
.mchip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 3px 10px; cursor: pointer; margin: 0 6px 6px 0; transition: all .15s; }
.mchip:hover { border-color: var(--green); }
.mchip .rm { font-weight: 700; opacity: .4; padding: 0 2px; }
.mchip .rm:hover { opacity: 1; color: var(--primary); }

/* 推荐区 */
#next-panel[hidden] { display: none; }
.next-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.next-grid[hidden] { display: none; }
.next-grid .tcard.row-clamped { display: none; }
.next-toggle { margin-left: auto; font-size: 12px; color: var(--text-muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; user-select: none; }
.next-toggle:hover { color: var(--accent); background: var(--bg); }

/* === 图谱探索 === */
.explorer-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.preset-lbl { font-size: 12px; color: var(--text-muted); }
.preset { font-size: 12px; padding: 6px 12px; border-radius: 15px; border: 1px solid var(--border); background: var(--card-bg); cursor: pointer; color: var(--text-light); transition: all .15s; }
.preset:hover { border-color: var(--accent); color: var(--accent); }
.preset-empty { font-size: 12px; color: var(--text-muted); }
#sugg { position: absolute; top: 52px; left: 12px; right: 12px; z-index: 30; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; max-height: 320px; overflow-y: auto; box-shadow: var(--shadow-lg); }
#sugg:empty { display: none; }
.sg { padding: 8px 14px; font-size: 13px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.sg:hover { background: var(--accent-light); }
.sg .s { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
#trail { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; min-height: 18px; }
#trail a { color: var(--text-light); cursor: pointer; text-decoration: none; }
#trail a:hover { color: var(--accent); }
#trail .sep { margin: 0 5px; color: var(--text-muted); }

.cols { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 18px; align-items: start; }
.col-h { font-size: 13px; color: var(--text-light); font-weight: 600; margin-bottom: 10px; }
.col-h .n { font-weight: 400; font-size: 12px; color: var(--text-muted); }

/* 卡片 */
.tcard { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 14px; margin-bottom: 9px; cursor: pointer; transition: all .15s; box-shadow: var(--shadow); }
.tcard:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.tcard .top { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.tcard .nm { font-size: 14px; font-weight: 500; }
.tag { font-size: 10.5px; padding: 1px 8px; border-radius: 9px; background: var(--bg); color: var(--text-muted); white-space: nowrap; }
.tag.x { background: var(--primary); color: #fff; }
.tag.provenance.upstream { background: var(--accent-light); color: var(--accent); }
.tag.provenance.rule { background: var(--bg); color: var(--text-light); border: 1px solid var(--border); }
.tag.provenance.ai-consensus { background: var(--orange-light); color: var(--orange); }
.tag.provenance.human { background: var(--green-light); color: var(--green); }
.tag.ok { background: var(--green); color: #fff; }
.tcard .rsn { font-size: 12px; color: var(--text-light); margin-top: 5px; line-height: 1.5; }
.tcard.xcard { background: var(--orange-light); border-color: #ecd9bc; }
.tcard.xcard:hover { border-color: var(--orange); }
.tcard.mastered { background: var(--green-light); border-color: #cfe3ce; }

/* 中央当前卡 */
.me { background: var(--card-bg); border: 2px solid var(--accent); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow-lg); }
.me .nm { font-size: 18px; font-weight: 700; line-height: 1.4; }
.me .meta { margin: 8px 0 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.me .me-action { min-height: 38px; margin: 0 0 12px; display: flex; align-items: center; gap: 16px; }
.mastery-action { flex: 0 0 138px; min-height: 36px; border: 1px solid var(--green); border-radius: 8px; background: var(--green); color: #fff; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.mastery-action:hover { opacity: .9; }
.mastery-action.mastered { background: var(--green-light); color: var(--green); }
.me-sec { margin-top: 12px; }
.me-sec:first-child { margin-top: 4px; }
.me-sec h4 { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; }
.me-desc { color: var(--text-light); line-height: 1.7; }
.me-evi { list-style: none; }
.me-evi li { color: var(--text-light); line-height: 1.6; padding-left: 16px; position: relative; margin-bottom: 3px; }
.me-evi li::before { content: '✓'; position: absolute; left: 0; color: var(--green); }
.me-assess { background: var(--primary-light); border-radius: 8px; padding: 10px 12px; color: var(--text); line-height: 1.6; }
.me-ph { background: var(--primary); color: #fff; border-radius: 4px; padding: 0 5px; font-size: 12px; }
.assessment-form { margin-top: 12px; }
.assessment-label { display: block; font-size: 12px; color: var(--text-light); }
.assessment-answer { width: 100%; min-height: 88px; margin-top: 5px; padding: 9px 10px; resize: vertical; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); font: inherit; line-height: 1.55; }
.assessment-answer:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.assessment-actions { display: flex; align-items: center; gap: 9px; margin-top: 8px; flex-wrap: wrap; }
.assessment-submit { min-height: 36px; padding: 0 13px; border: 0; border-radius: 7px; background: var(--accent); color: #fff; font: inherit; font-size: 12px; cursor: pointer; }
.assessment-submit:disabled { opacity: .55; cursor: wait; }
.assessment-note { font-size: 10.5px; color: var(--text-muted); }
.assessment-result { margin-top: 10px; font-size: 12px; line-height: 1.55; }
.assessment-result:empty { display: none; }
.assessment-result.pending { color: var(--text-light); }
.assessment-result.error { color: var(--primary); background: var(--primary-light); border-radius: 7px; padding: 8px 10px; }
.assessment-result.success { background: var(--accent-light); border-radius: 8px; padding: 10px 12px; }
.assessment-score { display: flex; align-items: baseline; gap: 4px; color: var(--accent); margin-bottom: 4px; }
.assessment-score strong { font-size: 24px; line-height: 1; }
.assessment-result h5 { margin-top: 7px; font-size: 11.5px; }
.assessment-result ul { padding-left: 18px; }
.me-std { background: var(--bg); border-radius: 7px; padding: 8px 10px; margin-bottom: 6px; }
.me-std-k { font-family: ui-monospace, "SF Mono", monospace; font-size: 11.5px; color: var(--accent); display: block; }
.me-std-s { font-size: 11.5px; color: var(--text-muted); display: block; margin-top: 2px; }
.me-std-n { font-size: 11.5px; color: var(--text-light); display: block; margin-top: 2px; }
.me-empty { font-size: 12.5px; color: var(--text-muted); padding: 8px 0; }
.me .me-action a { font-size: 12.5px; color: var(--accent); cursor: pointer; text-decoration: none; }
.me .me-action a:hover { text-decoration: underline; }
.me .mastery-action { flex-basis: 138px; }

.grp { margin-bottom: 16px; }
.grp-title { font-size: 11.5px; color: var(--text-muted); margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.grp-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.grp-title.xg { color: var(--primary); font-weight: 600; }
.empty { font-size: 12.5px; color: var(--text-muted); padding: 10px 2px; }

/* 骨架屏 */
.skel { border-radius: var(--radius); background: linear-gradient(90deg, var(--border) 25%, #f0ece5 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-card { height: 56px; margin-bottom: 9px; }
.skel-me { height: 180px; }

/* === 弹层 === */
.modal-mask { position: fixed; inset: 0; background: rgba(44,38,32,.45); z-index: 50; display: flex; align-items: center; justify-content: center; animation: fadein .15s; }
@keyframes fadein { from { opacity: 0; } }
.modal-mask[hidden] { display: none; }
.modal { background: var(--card-bg); border-radius: 14px; padding: 22px 24px; width: min(580px, 92vw); max-height: 84vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal h3 { font-size: 16px; margin-bottom: 12px; }
.modal-body { font-size: 13px; line-height: 1.75; color: var(--text-light); }
.modal-body p { margin-bottom: 8px; }
.modal-body b { color: var(--text); }
.modal-actions { margin-top: 16px; display: flex; gap: 10px; }
.profile-list { margin-top: 12px; }
.profile-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; transition: all .15s; background: var(--card-bg); }
.profile-row:hover { border-color: var(--accent); }
.profile-row.active { border-color: var(--accent); background: var(--accent-light); }
.profile-row .pname { font-size: 14px; font-weight: 600; }
.profile-row .pmeta { font-size: 11.5px; color: var(--text-muted); }
.profile-row .pspacer { flex: 1; }
.profile-row .pdel { color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 2px 6px; }
.profile-row .pdel:hover { color: var(--primary); }
.profile-add { display: flex; gap: 8px; margin-top: 10px; }
.profile-add input { flex: 1; font-size: 13px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
.profile-add input:focus { outline: none; border-color: var(--accent); background: #fff; }
.mem-sec { margin-bottom: 14px; }
.mem-sec h4 { font-size: 12.5px; margin-bottom: 5px; color: var(--text); }
.mem-kv { font-size: 12.5px; color: var(--text-light); display: flex; gap: 8px; padding: 2px 0; align-items: baseline; }
.mem-kv .k { color: var(--text-muted); min-width: 64px; flex-shrink: 0; }
.mem-kv .del { cursor: pointer; color: var(--text-muted); }
.mem-kv .del:hover { color: var(--primary); }
.mem-empty { font-size: 12.5px; color: var(--text-muted); }
.mem-raw { font-size: 11px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; white-space: pre-wrap; word-break: break-all; max-height: 140px; overflow-y: auto; color: var(--text-muted); font-family: ui-monospace, "SF Mono", monospace; }

/* === toast === */
#toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--text); color: #fff; font-size: 13px; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* === 响应式 === */
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .me { order: -1; }
  .topbar-inner { padding: 6px 14px; gap: 6px; height: auto; flex-wrap: wrap; }
  .brand h1 { font-size: 15px; white-space: nowrap; }
  .brand .sub, .ub-profile { display: none; }
  .tab-btn { font-size: 12px; padding: 6px 10px; }
  #graph-pane { top: 88px; }
  .ub-btn { font-size: 11px; padding: 5px 8px; }
  .main { padding: 18px 14px 48px; }
  /* 移动端: 侧栏浮层覆盖,不推挤内容 */
  #sidebar { top: 88px; width: min(290px, 82vw); box-shadow: var(--shadow-lg); }
  body.sb-open .main { margin-left: 0; }
  body.sb-open #graph-pane { left: 0; }
}

/* === 移动端知识脉络壳层(320-767px) === */
.mobile-shell { display: none; }
.mobile-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.mobile-sidebar-close { display: none; }

@media (max-width: 767px) {
  .topbar, #path-pane .panel, .explorer-head, #trail, .cols, #next-panel { display: none !important; }
  body.graph-active .mobile-shell { display: none; }
  body.graph-active #graph-pane { display: block !important; top: 0; padding-bottom: 72px; }

  .mobile-shell {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    background: var(--bg);
    padding-top: env(safe-area-inset-top);
    overflow: hidden;
  }

  .mobile-header { position: sticky; top: 0; z-index: 20; background: var(--card-bg); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
  /* --- 头部: 筛选 + 登录/AI 入口 --- */
  .mobile-field { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-light); }
  .mobile-header-row { display: flex; gap: 8px; align-items: center; }
  .mobile-field-label { padding-left: 2px; }
  .mobile-select { -webkit-appearance: none; appearance: none; font: inherit; font-size: 13px; height: 44px; min-height: 44px; padding: 0 30px 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); }
  .mobile-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .mobile-btn { min-height: 44px; min-width: 44px; padding: 0 14px; font-size: 13px; font-weight: 500; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); cursor: pointer; flex: 1; }
  .mobile-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .mobile-btn:focus-visible, .mobile-entry-btn:focus-visible, .mobile-decision-btn:focus-visible, .mobile-stepper-btn:focus-visible, .mobile-nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .mobile-entry-actions { justify-content: space-between; }
  .mobile-entry-btn { min-height: 44px; padding: 0 14px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text-light); cursor: pointer; }

  /* --- 主区: 单张知识卡 + 判定 + 步进器 --- */
  .mobile-main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom) + 64px); overflow: hidden; }
  .mobile-path-card { flex: 1; min-height: 0; position: relative; background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; display: flex; transition: transform .2s ease, opacity .2s ease, border-color .15s, background-color .15s; touch-action: pan-y; will-change: transform; }
  .mobile-path-card.swiping-mastered { border-color: var(--green); background: var(--green-light); }
  .mobile-path-card.swiping-review { border-color: var(--accent); background: var(--accent-light); }
  .mobile-path-card.swipe-cancel { transform: none !important; }
  .mobile-path-card.swipe-commit-left { transform: translateX(-110%) rotate(-3deg) !important; opacity: 0; }
  .mobile-path-card.swipe-commit-right { transform: translateX(110%) rotate(3deg) !important; opacity: 0; }
  .mobile-swipe-cue { position: absolute; top: 18px; z-index: 2; padding: 7px 10px; border: 2px solid currentColor; border-radius: 8px; background: var(--card-bg); font-size: 13px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; }
  .mobile-swipe-cue-mastered { right: 18px; color: var(--green); transform: rotate(5deg) scale(.94); }
  .mobile-swipe-cue-review { left: 18px; color: var(--accent); transform: rotate(-5deg) scale(.94); }
  .mobile-path-card.swiping-mastered .mobile-swipe-cue-mastered, .mobile-path-card.swiping-review .mobile-swipe-cue-review { opacity: 1; transform: rotate(0) scale(1); }
  .mobile-card-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; }
  .mobile-card-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .mobile-decision-mastered[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--card-bg), 0 0 0 2px var(--green); }
  .mobile-decision-review[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
  .mobile-card-title { font-size: 22px; font-weight: 600; line-height: 1.4; margin-bottom: 8px; }
  .mobile-card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
  .mobile-card-detail { font-size: 15px; color: var(--text-light); line-height: 1.6; }
  .mobile-card-status { margin-top: 14px; font-size: 13px; color: var(--text-light); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
  .mobile-path-card[data-state="needs-review"] { border-style: dashed; }
  .mobile-path-card[data-state="mastered"] { border-color: #cfe3ce; background: var(--green-light); }
  .mobile-path-card[data-state="needs-review"] { border-color: var(--border); }

  .mobile-decision-bar { display: flex; gap: 10px; flex-wrap: wrap; }
  .mobile-decision-btn { flex: 1; min-height: 44px; min-width: 44px; font-size: 14px; font-weight: 600; border-radius: 10px; cursor: pointer; }
  .mobile-decision-mastered { border: 1px solid var(--green); background: var(--green); color: #fff; }
  .mobile-decision-review { border: 1px solid var(--border); background: var(--card-bg); color: var(--text); }
  .mobile-undo-btn { flex-basis: 100%; border: 1px solid var(--border); background: var(--card-bg); color: var(--text-light); }
  .mobile-undo-btn[hidden] { display: none; }

  .mobile-stepper { display: flex; align-items: center; gap: 8px; }
  .mobile-stepper-btn { min-height: 44px; min-width: 44px; padding: 0 12px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); cursor: pointer; }
  .mobile-position-wrap { flex: 1; min-width: 0; text-align: center; font-size: 12px; color: var(--text-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-position { display: block; font-weight: 600; color: var(--text); }
  .mobile-context { display: block; }

  /* --- AI 弹窗: 移动端变为底部抽屉 --- */
  .mobile-ai-mask { align-items: flex-end; }
  .mobile-ai-sheet { width: 100%; max-width: none; border-radius: 16px 16px 0 0; max-height: 80vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .mobile-ai-note { margin-top: 8px; color: var(--text-light); font-size: 12px; }

  .mobile-ai-context { margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--accent); }
  .mobile-chat-log { min-height: 120px; max-height: 36vh; margin-top: 12px; padding: 10px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
  .mobile-chat-empty { color: var(--text-light); font-size: 13px; }
  .mobile-chat-message { max-width: 88%; margin-bottom: 9px; padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.6; }
  .mobile-chat-message.user { margin-left: auto; background: var(--accent); color: #fff; }
  .mobile-chat-message.assistant { background: var(--card-bg); border: 1px solid var(--border); color: var(--text); }
  .mobile-chat-error { margin-top: 8px; color: var(--primary); font-size: 12px; }
  .mobile-chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
  #mobile-chat-input { flex: 1; min-height: 54px; max-height: 120px; padding: 9px 10px; resize: vertical; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); font: inherit; font-size: 14px; }
  #mobile-chat-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  #mobile-chat-send { min-height: 44px; flex-shrink: 0; }
  .mobile-chat-message.pending { color: var(--text-light); }
  .mobile-chat-message.pending::after { content: '…'; animation: chat-pulse 1s steps(3,end) infinite; }
  @keyframes chat-pulse { 50% { opacity: .35; } }
  /* --- 底部导航 --- */
  .mobile-bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; background: var(--card-bg); border-top: 1px solid var(--border); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav-btn { flex: 1; min-height: 44px; border: none; background: transparent; color: var(--text-light); font-size: 12px; cursor: pointer; border-radius: 8px; }
  .mobile-nav-btn[aria-current="page"] { color: var(--accent); font-weight: 600; background: var(--accent-light); }
  .mobile-btn:disabled, .mobile-entry-btn:disabled, .mobile-decision-btn:disabled, .mobile-stepper-btn:disabled, .mobile-select:disabled { opacity: .5; cursor: not-allowed; background: var(--bg); color: var(--text-muted); border-color: var(--border); }
  #toast { bottom: calc(28px + 56px + env(safe-area-inset-bottom)); }

  /* --- 目录侧栏(由底部导航"目录"触发,复用现有 #sidebar 而非新建) --- */
  body:not(.sb-open) #sidebar { display: none; }
  body.sb-open #sidebar { display: flex; top: 0; bottom: 0; width: 100%; max-width: none; z-index: 40; transform: none; }
  .mobile-sidebar-close { display: block; min-height: 44px; margin: 10px 14px 0; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); font: inherit; }
  body.sb-open #sidebar .sb-tree { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  #sidebar .sb-search input { min-height: 44px; }
  body.sb-open .mobile-shell { display: none; }
  body.sb-open .main, body.sb-open #graph-pane { margin-left: 0; left: 0; }

  @media (prefers-reduced-motion: reduce) {
    .mobile-path-card, .mobile-decision-btn, .mobile-nav-btn, .mobile-swipe-cue { transition: none !important; animation: none !important; }
    .mobile-path-card.swipe-commit-left, .mobile-path-card.swipe-commit-right { transform: none !important; opacity: 1; }
  }
}

/* Material 3 single-document workspace */
:root {
  --md-primary: #4f5fba;
  --md-on-primary: #fff;
  --md-surface: #f8f7f2;
  --md-surface-container: #efeee8;
  --md-surface-container-high: #e8e7e1;
  --md-outline: #777680;
  --md-error: #ba5b4f;
  --md-mastered: #397655;
}
body { background: var(--md-surface); }
.topbar { background: color-mix(in srgb, var(--md-surface-container) 94%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--md-outline) 28%, transparent); box-shadow: 0 1px 2px rgba(32,31,36,.08); }
.tab-btn, .ub-btn, .sb-toggle, button, input, textarea, select { border-radius: 12px; }
.tab-btn.active { color: var(--md-primary); background: color-mix(in srgb, var(--md-primary) 14%, transparent); }
.tab-btn:hover, button:hover { background-image: linear-gradient(rgba(79,95,186,.08), rgba(79,95,186,.08)); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--md-primary) 70%, transparent); outline-offset: 2px; }
.panel, .me, .tcard, .mobile-path-card, .modal { border-radius: 16px; box-shadow: 0 1px 2px rgba(32,31,36,.08); }
.surface-container { background: var(--md-surface-container); }
.surface-container-high { background: var(--md-surface-container-high); border-radius: 16px; }
.graph-workspace { margin-left: 0; padding: 20px clamp(16px, 3vw, 40px) 40px; }
.graph-toolbar { position: sticky; top: 64px; z-index: 8; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 16px; border: 1px solid rgba(119,118,128,.2); }
.graph-toolbar .search-box { flex: 1 1 240px; margin: 0; }
.graph-toolbar .sidebar-stats { border: 0; padding: 0; }
.graph-toolbar .dimension-bar, .graph-toolbar .filter-bar { border: 0; padding: 0; }
.graph-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; margin-top: 20px; }
.graph-tree { padding: 12px 0; border-radius: 16px; align-self: start; max-height: calc(100vh - 170px); overflow: auto; }
.graph-content { padding: 0; max-width: 1100px; }
.graph-content .overview-hero, .graph-content .detail-body { padding: 24px; }
.eyebrow { color: var(--md-primary); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.mastery-action, .bulk-mastery-apply { background: var(--md-mastered); }
.assessment-result.error, .mobile-error-state { color: var(--md-error); }
body.graph-active #sidebar { display: none; }
@media (min-width: 901px) {
  .topbar-inner { padding-left: 88px; }
  .tabs { position: fixed; left: 12px; top: 84px; width: 64px; z-index: 20; flex-direction: column; background: var(--md-surface-container); padding: 8px; border-radius: 16px; }
  .tab-btn { min-height: 56px; font-size: 11px; white-space: normal; padding: 8px 4px; }
  .main, .graph-workspace { margin-left: 80px; }
}
@media (max-width: 767px) {
  .tabs { display: none; }
  .graph-workspace { padding: 12px 12px 88px; }
  .graph-toolbar { position: static; flex-wrap: wrap; }
  .graph-toolbar .sidebar-stats { display: none; }
  .graph-layout { display: block; }
  .graph-tree { display: none; }
  .graph-content { padding: 0; }
  .overview-stats { grid-template-columns: repeat(2, 1fr); }
  .topic-grid { grid-template-columns: 1fr; }
  .mobile-bottom-nav { grid-template-columns: repeat(4, 1fr); }
}
