:root {
  --bg: #faf8f3; --panel: #ffffff; --ink: #2b2620; --muted: #7a7064; --line: #e6e0d4;
  --accent: #8a5a2b; --lun: #3b342c; --pixun: #2f6b5b; --jiang: #4a5a8a;
  --ok: #2f6b3a; --warn: #a06a00; --bad: #7a5238; --hl: #fff1c9;
  --aiv: #6b5bb5; --aiv-bg: #f4f2fb; --kepan: #8a7a4a;
  /* 字体方案 E：回答用思源宋体，典籍原文（论文、披尋記、筆錄、科判）与标题用霞鹜文楷，控件用系统黑体 */
  --font-answer: "Noto Serif TC", "Noto Serif SC", "Source Han Serif TC", "Songti TC", serif;
  --font-scripture: "LXGW WenKai", "Noto Serif TC", "Noto Serif SC", serif;
  --font-ui: system-ui, -apple-system, "Microsoft JhengHei", "PingFang SC", sans-serif;
  --serif: var(--font-answer);
}
/* 简体模式优先用简体字形（同一套思源宋体设计） */
:root:lang(zh-Hans) {
  --font-answer: "Noto Serif SC", "Noto Serif TC", "Source Han Serif SC", "Songti SC", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916; --panel: #24211d; --ink: #ece6da; --muted: #a39a8c; --line: #3a352e;
    --accent: #d39a5f; --lun: #d9d0c0; --pixun: #6fbfa7; --jiang: #92a3dc;
    --ok: #7cc48a; --warn: #e0b04a; --bad: #c9a27a; --hl: #4a3f22;
    --aiv: #a99bef; --aiv-bg: #26233a; --kepan: #c9b577;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.85 var(--font-answer); }
/* 控件、标签、说明性小字用黑体，与正文区分 */
button, textarea, .row, .sub, #status, #rewrite-note, .issue, .aiv-head, .legend, .tag,
#evidence-col h2, .ev .meta, .ev .actions, .ctx-head, .ctx-foot, .cp-meta, #removed-box summary,
#loading, .loading-meta, #aiview-related, #insufficient { font-family: var(--font-ui); }
header, form, main { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 28px; }
h1 { font-family: var(--font-scripture); font-weight: 700; margin: 0; font-size: 28px; color: var(--accent); }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#script-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  background: var(--panel); flex-shrink: 0; }
#script-toggle button { border: 0; background: none; color: var(--muted); padding: 4px 14px; font-size: 14px; }
#script-toggle button:hover { color: var(--accent); }
#script-toggle button.active { background: var(--accent); color: #fff; }
.sub { color: var(--muted); margin: 4px 0 16px; font-size: 14px; }
form textarea { width: 100%; font: inherit; padding: 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink); resize: vertical; }
.row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 20px;
  gap: 12px; font-size: 14px; color: var(--muted); }
button { font: inherit; cursor: pointer; }
#btn { background: var(--accent); color: #fff; border: 0; padding: 8px 22px; border-radius: 6px; }
#btn:disabled { opacity: .5; cursor: wait; }

#loading { max-width: 1168px; margin: 8px auto 32px; padding: 18px 16px; display: flex; gap: 16px;
  align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
@media (max-width: 1200px) { #loading { margin-left: 16px; margin-right: 16px; } }
#loading[hidden] { display: none; }
#loading-stage { font-size: 16px; }
.loading-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.spinner { width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
/* 实际进度：每一步一行，进行中的转圈，完成的打勾 */
#loading { align-items: flex-start; }
.steps { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; line-height: 1.7; color: var(--muted); }
.steps li { position: relative; padding-left: 20px; }
.steps li::before { position: absolute; left: 0; top: 0; width: 14px; text-align: center; }
.steps li.done::before { content: "✓"; color: var(--ok); }
.steps li.doing { color: var(--ink); }
.steps li.doing::before { content: "◌"; color: var(--accent); animation: spin 1.2s linear infinite; display: inline-block; }
#status.st-streaming { color: var(--accent); }
/* 回答还在写：末尾一个淡淡闪动的光标 */
.typing { display: inline-block; width: .5em; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--accent); opacity: .5;
  animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#answer .sent.new { animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing, #answer .sent.new, .steps li.doing::before { animation: none; } }

main { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; padding-bottom: 48px; }
main[hidden] { display: none; }   /* display:grid 会盖过 hidden 属性 */
@media (max-width: 820px) { main { grid-template-columns: 1fr; } }

#status { font-size: 14px; margin-bottom: 10px; }
.st-ok { color: var(--ok); } .st-warning { color: var(--warn); } .st-refused, .st-error { color: var(--bad); }
#answer p { margin: 0 0 16px; }
.sent { border-radius: 3px; }
.sent.partial, .sent.misattributed { text-decoration: underline wavy var(--warn); text-underline-offset: 4px; }
.issue { display: block; font-size: 13px; color: var(--warn); }
.q-verified { font-family: inherit; }
.q-unverified { color: var(--bad); text-decoration: line-through; }
.q-wrong_cite { color: var(--warn); }
sup.cite { cursor: pointer; color: var(--accent); font-size: 12px; margin-left: 1px; }
sup.cite:hover { text-decoration: underline; }
#insufficient:not(:empty) { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--muted);
  color: var(--muted); font-size: 14px; background: var(--panel); }
#removed-box { margin-top: 14px; font-size: 14px; color: var(--muted); }
#removed .r { margin: 6px 0; text-decoration: line-through; }
.opts { display: flex; gap: 16px; }
#aiview-box { margin-top: 18px; padding: 12px 14px; border: 1.5px dashed var(--aiv); border-radius: 8px;
  background: var(--aiv-bg); }
.aiv-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12px;
  color: var(--muted); margin-bottom: 6px; }
#rewrite-note:not(:empty) { font-size: 13px; color: var(--muted); margin: -4px 0 10px; }
#aiview-box.fallback { border-color: var(--warn); background: var(--panel); }
#aiview-box.fallback .aiv-badge { background: var(--warn); }
.aiv-badge { background: var(--aiv); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 10px; }
#aiview-text p { margin: 0 0 8px; }
#aiview-related { font-size: 13px; color: var(--muted); }
.legend { margin-top: 24px; font-size: 13px; color: var(--muted); }

.tag { display: inline-block; font-size: 12px; padding: 0 6px; border-radius: 4px; color: #fff; margin: 0 4px 0 10px; }
.tag.lun { background: var(--lun); } .tag.kepan { background: var(--kepan); } .tag.pixun { background: var(--pixun); } .tag.jiang { background: var(--jiang); }
.legend .tag:first-child { margin-left: 0; }

#evidence-col h2 { font-size: 16px; margin: 0 0 10px; color: var(--muted); font-weight: 500; }
.ev { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; transition: background .3s; }
.ev.lun { border-left-color: var(--lun); } .ev.kepan { border-left-color: var(--kepan); } .ev.pixun { border-left-color: var(--pixun); } .ev.jiang { border-left-color: var(--jiang); }
.ev.flash { background: var(--hl); }
.ev .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.ev .meta b { color: var(--ink); }
.ev .meta .tag { margin: 0; }
.ev .kepan { font-family: var(--font-scripture); font-size: 12.5px; color: var(--muted); margin: 2px 0 4px; }
.ev .text { font-family: var(--font-scripture); font-size: 16.5px; white-space: pre-wrap; max-height: 12em; overflow: hidden; position: relative; }
.ev .text.clipped::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3em;
  background: linear-gradient(to bottom, transparent, var(--panel)); pointer-events: none; }
.ev .text.expanded { max-height: none; }
.ev .text.expanded::after { display: none; }
.ev .actions { font-size: 13px; margin-top: 4px; }
.ev .actions a { color: var(--accent); cursor: pointer; margin-right: 12px; }

.ev .meta .parallel { color: var(--accent); font-weight: 600; }

/* 底部云烟：淡墨晕染，呼应顶部宋画的雾气；固定在视口底部，只作衬底，不挡交互 */
.ink-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.ink-clouds { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 34vh; min-height: 200px; opacity: .55; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ink-clouds { filter: invert(1); opacity: .35; } }
header, form, #loading, main { position: relative; z-index: 1; }

/* 顶部古画横幅（公有领域 CC0：克利夫兰美术馆藏《溪山無盡圖》，北宋，1953.126），下缘淡入纸色 */
.banner { position: relative; z-index: 1; height: 210px; margin-bottom: -40px;
  background: url("/static/banner-xishan.jpg") center 30% / cover no-repeat;
  -webkit-mask-image: linear-gradient(to bottom, #000 45%, transparent 100%);
          mask-image: linear-gradient(to bottom, #000 45%, transparent 100%);
  opacity: .9; }
@media (max-width: 820px) { .banner { height: 130px; margin-bottom: -24px; } }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .banner { filter: invert(1) hue-rotate(180deg); mix-blend-mode: screen; opacity: .45; }
}

/* ── 书卷风格：按语、朱文印、传统颜料色，替换偏“科技感”的紫色虚线框、实心胶囊标签等 ── */
:root {
  --mo: #3b342c;         /* 墨：論文（第一依据，用最沉稳的墨色；全站不用红色） */
  --shilv: #3d6b5c;      /* 石绿：披尋記 */
  --huaqing: #3e5578;    /* 花青：筆錄 */
  --zheshi: #8a5a2b;     /* 赭石：强调、按钮 */
  --paper-2: #fffdf8;    /* 卡片用的暖白纸 */
  --paper-3: #f3eee3;    /* 按语底色 */
  --lun: var(--mo); --pixun: var(--shilv); --jiang: var(--huaqing); --aiv: var(--zheshi); --warn: #9a6a1c;
  --bad: #7a5238;        /* 深褐：引文不符、未检得依据等提示，醒目但不刺眼 */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mo: #d9d0c0; --shilv: #8cc4b0; --huaqing: #9db0d6; --zheshi: #d39a5f;
    --lun: var(--mo); --bad: #c9a27a;
    --paper-2: #26221e; --paper-3: #2c2823; --warn: #e0b04a;
  }
}
/* 控件：赭石色、方角 */
input[type="checkbox"] { accent-color: var(--zheshi); }
#btn { border-radius: 3px; letter-spacing: .15em; padding: 8px 22px 8px 25px; }
form textarea { background: var(--paper-2); border-radius: 3px; }
#script-toggle { border-radius: 3px; }
#loading { border-radius: 3px; background: var(--paper-2); }
/* 证据卡片：暖白纸、细边、近直角 */
.ev { background: var(--paper-2); border-radius: 3px; border-left-width: 3px; }
.ev.flash { background: var(--hl); }
#insufficient:not(:empty) { background: var(--paper-2); }
/* 標籤：朱文印式——细框同色字，方角 */
.tag { background: none; color: var(--c, var(--ink)); border: 1px solid var(--c, var(--line));
  border-radius: 2px; padding: 0 5px; line-height: 1.5; font-weight: 500; }
.tag.lun { --c: var(--mo); } .tag.pixun { --c: var(--shilv); } .tag.jiang { --c: var(--huaqing); } .tag.kepan { --c: var(--kepan); }
.tag.lun, .tag.pixun, .tag.jiang, .tag.kepan { background: none; }
/* AI 判断：按语——上下细线、略深的纸色，标签为朱文小印 */
#aiview-box { border: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  border-radius: 0; background: var(--paper-3); padding: 14px 16px 10px; }
#aiview-box .aiv-badge { background: none; color: var(--zheshi); border: 1px solid var(--zheshi); border-radius: 2px;
  padding: 0 6px; letter-spacing: .1em; font-family: var(--font-scripture); font-size: 13px; }
#aiview-box.fallback { border-color: var(--line); background: var(--paper-3); }
#aiview-box.fallback .aiv-badge { color: var(--muted); border-color: var(--muted); background: none; }
/* “部分有据”：赭石虚线，不用刺眼的黄色波浪线 */
.sent.partial, .sent.misattributed { text-decoration: underline dotted var(--warn); text-decoration-thickness: 1.5px; }
sup.cite { color: var(--zheshi); }

/* 加载动画：墨滴在宣纸上晕开——两滴交错，由浓化淡、边缘略不规则，替代旋转圆圈 */
.spinner { position: relative; width: 46px; height: 46px; border: 0; border-radius: 0; animation: none; }
.spinner::before, .spinner::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 48% 52% 55% 45% / 50% 46% 54% 50%;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--mo) 85%, transparent) 0%,
    color-mix(in srgb, var(--mo) 45%, transparent) 38%,
    color-mix(in srgb, var(--mo) 12%, transparent) 62%,
    transparent 72%);
  filter: blur(.6px);
  animation: ink-spread 2.6s cubic-bezier(.2, .6, .3, 1) infinite;
}
.spinner::after { animation-delay: 1.3s; border-radius: 55% 45% 48% 52% / 46% 55% 45% 54%; }
@keyframes ink-spread {
  0%   { transform: scale(.12) rotate(0deg);  opacity: .95; }
  60%  { opacity: .4; }
  100% { transform: scale(1.55) rotate(25deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .spinner::before, .spinner::after { animation-duration: 6s; } }

/* ── 账号：右上角登录按钮与登录框 ── */
.top-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
#account { font-family: var(--font-ui); font-size: 14px; display: flex; align-items: center; }
#login-btn, #logout-btn { border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: 3px; padding: 3px 12px; font-size: 14px; }
#login-btn:hover, #logout-btn:hover { border-color: var(--zheshi); color: var(--zheshi); }
#user-box { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
#user-box[hidden] { display: none; }
#user-avatar { width: 24px; height: 24px; border-radius: 3px; object-fit: cover; }
#user-name { max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logout-btn { padding: 1px 8px; font-size: 13px; }
/* 等待时的「取消」与回答上方的「分享此回答」：与登录按钮同一套淡色描边样式 */
#cancel-btn, #share-btn { font-family: var(--font-ui); border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: 3px; padding: 3px 12px; font-size: 13px; flex-shrink: 0; }
#cancel-btn:hover, #share-btn:hover { border-color: var(--zheshi); color: var(--zheshi); }
#cancel-btn { margin-left: auto; }
.status-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#share-btn[hidden] { display: none; }

dialog#auth { width: min(400px, 92vw); border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper-2); color: var(--ink); padding: 0; }
.auth-box { position: relative; padding: 22px 26px 18px; font-family: var(--font-ui); }
.auth-box h2 { margin: 0 0 4px; font-family: var(--font-scripture); font-weight: 700; font-size: 22px; color: var(--zheshi); }
.auth-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.auth-close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 22px; color: var(--muted); }
.google-btn { display: block; text-align: center; padding: 8px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--ink); text-decoration: none; background: var(--bg); }
.google-btn:hover { border-color: var(--zheshi); }
/* 邮箱验证码登录 */
.auth-or { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; font-size: 12px; color: var(--muted); }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.auth-or[hidden] { display: none; }
#auth .auth-row { display: flex; gap: 8px; margin: 0 0 8px; padding: 0; max-width: none; }
.auth-row[hidden], #email-login[hidden], .google-btn[hidden] { display: none; }
.auth-row input { flex: 1; min-width: 0; font: 14px var(--font-ui); padding: 7px 10px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--panel); color: var(--ink); }
.auth-row input:focus { outline: none; border-color: var(--zheshi); }
#code-in { letter-spacing: .35em; font-variant-numeric: tabular-nums; }
.auth-row button { flex-shrink: 0; font: 14px var(--font-ui); padding: 7px 12px; border: 1px solid var(--zheshi); border-radius: 3px;
  background: var(--zheshi); color: #fff; cursor: pointer; white-space: nowrap; }
.auth-row button:disabled { opacity: .55; cursor: default; }
.auth-hint { margin: 2px 0 6px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.auth-msg { min-height: 1.2em; margin: 4px 0 8px; font-size: 13px; color: var(--bad); }
.auth-msg.ok { color: var(--ok); }
@media (max-width: 520px) { #user-name { max-width: 6em; } }
.auth-privacy { margin: 10px 0 0; font-size: 12px; color: var(--muted); } .auth-privacy a { color: var(--zheshi); }

/* ── 个人问答历史侧边栏（登录后显示；宽屏固定在左侧，窄屏为抽屉） ── */
#history { position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 5;
  background: var(--paper-2); border-right: 1px solid var(--line); overflow-y: auto;
  padding: 18px 12px 24px; font-family: var(--font-ui); }
#history[hidden] { display: none; }
body.has-history { padding-left: 250px; }
.hist-head { display: flex; justify-content: space-between; align-items: center; padding: 0 6px;
  font-family: var(--font-scripture); font-size: 17px; color: var(--zheshi); }
.hist-note { margin: 2px 6px 10px; font-size: 12px; color: var(--muted); }
#hist-list { list-style: none; margin: 0; padding: 0; }
#hist-list li { position: relative; padding: 8px 26px 8px 8px; border-radius: 3px; cursor: pointer; border-left: 2px solid transparent; }
#hist-list li:hover { background: var(--paper-3); }
#hist-list li.active { background: var(--paper-3); border-left-color: var(--zheshi); }
#hist-list .hq { font-family: var(--font-answer); font-size: 14px; line-height: 1.5; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#hist-list .hd { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
#hist-list .hdel { position: absolute; top: 6px; right: 4px; border: 0; background: none; color: var(--muted);
  font-size: 16px; line-height: 1; padding: 2px 4px; opacity: 0; }
#hist-list li:hover .hdel, #hist-list li.active .hdel { opacity: 1; }
#hist-list .hdel:hover { color: var(--bad); }
#hist-backdrop { position: fixed; inset: 0; z-index: 4; background: rgba(0,0,0,.25); }
#hist-backdrop[hidden] { display: none; }
@media (max-width: 1100px) {
  body.has-history { padding-left: 0; }
  #history { transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  #history.open { transform: none; }
}

/* 侧边栏可收起（宽屏）；收起后正文占满，右上角“历史”按钮可再展开 */
.hist-actions { display: inline-flex; align-items: center; gap: 4px; }
#hist-collapse { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
#hist-collapse:hover { color: var(--zheshi); }
@media (min-width: 1101px) {
  #history { transition: transform .2s ease; }
  body.has-history.hist-collapsed { padding-left: 0; }
  body.hist-collapsed #history { transform: translateX(-100%); }
}

/* 收起后的入口：左边缘竖排书签“我的问答”（与侧边栏同在左侧） */
#hist-tab { position: fixed; left: 0; top: 120px; z-index: 5; display: none;
  writing-mode: vertical-rl; letter-spacing: .25em; padding: 12px 6px;
  font-family: var(--font-scripture); font-size: 14px; color: var(--zheshi);
  background: var(--paper-2); border: 1px solid var(--line); border-left: 0; border-radius: 0 4px 4px 0; cursor: pointer; }
#hist-tab:hover { background: var(--paper-3); }
@media (min-width: 1101px) { body.hist-collapsed #hist-tab:not([hidden]) { display: block; } }
@media (max-width: 1100px) { #hist-tab:not([hidden]) { display: block; } #history.open ~ #hist-tab { display: none; } }

/* 顶部“論典”入口；上下文弹窗里跳到論典页 */
.nav-link { color: var(--muted); text-decoration: none; font-size: 14px; font-family: var(--font-ui); }
.nav-link:hover { color: var(--accent); }

/* 标题链接回主页 */
h1 a { color: inherit; text-decoration: none; }
@media (max-width: 600px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  h1 { font-size: 22px; white-space: nowrap; }
}

/* 页头（问答、心得、論典三页一致）：站名居中题在山水画下缘的雾里；下一行导航居中，登录与繁简在右 */
.site-title { text-align: center; position: relative; z-index: 2; }
.site-title, header .top:has(.site-nav) h1 {
  font-size: 34px; font-weight: 600; letter-spacing: .32em; margin-left: .32em;
  text-shadow: 0 0 10px var(--bg), 0 0 22px var(--bg), 0 0 36px var(--bg); }
header:has(.site-nav) { margin-top: -56px; padding-top: 0; }
header .top:has(.site-nav) { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; row-gap: 14px; }
header .top:has(.site-nav) h1 { grid-column: 1 / -1; justify-self: center; text-align: center; }
header .top:has(.site-nav) .site-nav { grid-column: 2; }
header .top:has(.site-nav) .top-right { grid-column: 3; justify-self: end; }
header:has(.site-nav) .sub { text-align: center; }
.site-nav { display: flex; gap: 6px; font-family: var(--font-answer); }
.site-nav a { position: relative; padding: 4px 14px; font-size: 16px; letter-spacing: .12em; color: var(--ink);
  text-decoration: none; border-radius: 6px; transition: color .15s, background .15s; }
.site-nav a:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.site-nav a.on { color: var(--accent); font-weight: 600; }
.site-nav a.on::after { content: ""; position: absolute; left: 14px; right: calc(14px + .12em); bottom: -2px; height: 2px;
  background: var(--accent); border-radius: 1px; }
@media (max-width: 820px) {
  header:has(.site-nav) { margin-top: -38px; }
  .site-title, header .top:has(.site-nav) h1 { font-size: 23px; letter-spacing: .2em; margin-left: .2em; white-space: nowrap; }
}
@media (max-width: 700px) {
  /* 窄屏：导航靠左、登录与繁简靠右，同一行 */
  header .top:has(.site-nav) { grid-template-columns: auto 1fr; column-gap: 8px; row-gap: 10px; }
  header .top:has(.site-nav) .site-nav { grid-column: 1; gap: 0; }
  header .top:has(.site-nav) .top-right { grid-column: 2; gap: 6px; }
  .site-nav a { font-size: 15px; padding: 2px 9px; letter-spacing: .06em; }
  .site-nav a.on::after { left: 9px; right: calc(9px + .06em); }
  #account { font-size: 13px; }
  #login-btn { padding: 2px 9px; font-size: 13px; }
  #script-toggle button { padding: 2px 9px; font-size: 13px; }
  #user-box .user-hi { display: none; }   /* 窄屏只显示名字 */
  #user-box { gap: 6px; }
  #user-name { max-width: 4.5em; }
  #logout-btn { padding: 1px 6px; }
}
.site-nav a, #login-btn, #logout-btn, #script-toggle button { white-space: nowrap; }
@media (max-width: 700px) { #hist-tab { top: 230px; } }   /* 「我的問答」抽屉把手让开导航行 */
@media (max-width: 400px) {
  #user-name { display: none; }   /* 极窄屏：登录后只留「退出」，导航一行放得下 */
  .site-nav a { padding: 2px 6px; font-size: 14.5px; }
  .site-nav a.on::after { left: 6px; right: calc(6px + .06em); }
  #script-toggle button { padding: 2px 7px; }
}

/* 手机浏览器（如微信）会自动放大文字，导致固定版式溢出；统一关闭 */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* 登录后名字前的问候：歡迎，名字 */
#user-box .user-hi { color: var(--muted); margin-right: -6px; }
#user-box .user-hi::after { content: "，"; }
#user-name { color: var(--ink); }

/* ── 上下文弹窗：标题 + 科判面包屑 / 按类型着色的段落 / 底部主按钮「在論典中打开」 ── */
dialog#ctx { width: min(860px, 94vw); max-height: 88vh; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: var(--paper-2); color: var(--ink);
  box-shadow: 0 24px 60px rgba(30, 24, 16, .28); overflow: hidden; }
dialog#ctx[open] { display: flex; flex-direction: column; animation: ctx-in .18s ease-out; }
@keyframes ctx-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
dialog#ctx::backdrop { background: rgba(28, 22, 14, .45); backdrop-filter: blur(2px); }

.ctx-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line); background: var(--paper-3); }
.ctx-head-main { flex: 1; min-width: 0; }
.ctx-eyebrow { font-size: 12px; letter-spacing: .3em; color: var(--zheshi); }
.ctx-title { font-family: var(--font-scripture); font-size: 22px; line-height: 1.35; color: var(--ink); margin: 2px 0 6px; }
.ctx-kepan { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.ctx-kepan .crumb { font-family: var(--font-scripture); }
.ctx-kepan .crumb.last { color: var(--kepan); font-weight: 600; }
.ctx-kepan .sep { opacity: .5; }
/* 默认折叠：中间各层隐藏，点「…」展开；展开后「…」换成末尾的「收起」 */
.ctx-kepan:not(.expanded) .mid, .ctx-kepan.expanded .kp-more, .ctx-kepan.expanded .more-sep,
.ctx-kepan:not(.expanded) .kp-less { display: none; }
.ctx-kepan button { font: inherit; font-family: var(--font-ui); cursor: pointer; border-radius: 3px; }
.kp-more { padding: 0 7px; line-height: 1.4; border: 1px solid var(--line); background: var(--paper-2);
  color: var(--zheshi); font-weight: 700; letter-spacing: .1em; }
.kp-more:hover { border-color: var(--zheshi); background: var(--paper-2); }
.kp-less { padding: 0 4px; border: 0; background: none; color: var(--zheshi); font-size: 12px; }
.kp-less:hover { text-decoration: underline; }
.kp-copy { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 1px 8px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--muted); font-size: 12px; }
.kp-copy:hover { color: var(--zheshi); border-color: var(--zheshi); }
.kp-copy.done { color: var(--ok); border-color: var(--ok); }
.kp-more:focus-visible, .kp-less:focus-visible, .kp-copy:focus-visible { outline: 2px solid var(--zheshi); outline-offset: 2px; }
.ctx-close { flex-shrink: 0; width: 34px; height: 34px; border: 1px solid transparent; border-radius: 50%;
  background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.ctx-close:hover { background: var(--paper-2); border-color: var(--line); color: var(--ink); }
.ctx-close:focus-visible { outline: 2px solid var(--zheshi); outline-offset: 2px; }

#ctx-body { flex: 1; overflow-y: auto; padding: 10px 20px 18px; overscroll-behavior: contain; outline: none; }
.cp { position: relative; padding: 8px 12px 8px 14px; margin: 6px 0; border-left: 3px solid var(--c, var(--line));
  border-radius: 0 3px 3px 0; }
.cp.lun { --c: var(--mo); } .cp.pixun { --c: var(--shilv); } .cp.jiang { --c: var(--huaqing); }
.cp.kepan, .cp.title { --c: transparent; padding-left: 0; }
.cp-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.cp-type { color: var(--c, var(--muted)); font-weight: 600; letter-spacing: .1em; }
.cp.kepan .cp-type, .cp.title .cp-type { color: var(--kepan); }
.cp-no { font-variant-numeric: tabular-nums; opacity: .8; }
.cp-text { font-family: var(--font-scripture); font-size: 16.5px; line-height: 1.85; white-space: pre-wrap; }
.cp.lun .cp-text { font-weight: 700; }
.cp.kepan .cp-text, .cp.title .cp-text { font-size: 14px; color: var(--muted); }
.cp.hit { background: var(--hl); border-left-width: 4px; }
.cp-hit { margin-left: auto; padding: 0 6px; border: 1px solid var(--zheshi); border-radius: 2px;
  color: var(--zheshi); font-size: 11px; letter-spacing: .1em; }

.ctx-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-top: 1px solid var(--line); background: var(--paper-3); }
.ctx-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.ctx-legend .sw { width: 14px; height: 14px; border-radius: 2px; background: var(--hl); border-left: 3px solid var(--zheshi); }
.ctx-read-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px 10px 18px;
  background: var(--zheshi); color: #fffaf2; border-radius: 3px; text-decoration: none;
  font-family: var(--font-scripture); font-size: 16px; letter-spacing: .12em;
  box-shadow: 0 2px 0 rgba(0,0,0,.12), 0 6px 16px rgba(138, 90, 43, .28);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.ctx-read-btn:hover { filter: brightness(1.08); transform: translateY(-1px);
  box-shadow: 0 3px 0 rgba(0,0,0,.12), 0 10px 22px rgba(138, 90, 43, .34); }
.ctx-read-btn:active { transform: translateY(0); }
.ctx-read-btn:focus-visible { outline: 2px solid var(--zheshi); outline-offset: 3px; }
.ctx-read-btn .arr { transition: transform .12s ease; }
.ctx-read-btn:hover .arr { transform: translateX(3px); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ctx-read-btn { color: #1b1916; }
  :root:not([data-theme="light"]) dialog#ctx { box-shadow: 0 24px 60px rgba(0,0,0,.6); }
}

/* 手机：弹窗贴底成整页卡片，按钮占满一行 */
@media (max-width: 600px) {
  dialog#ctx { width: 100vw; max-width: 100vw; height: 92vh; max-height: 92vh; margin: auto 0 0;
    border-radius: 12px 12px 0 0; border-bottom: 0; }
  .ctx-head { padding: 14px 16px 12px; }
  .ctx-title { font-size: 19px; }
  #ctx-body { padding: 8px 14px 14px; }
  .ctx-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .ctx-legend { display: none; }
  .ctx-read-btn { flex: 1; justify-content: center; padding: 12px; }
}
