@property --clear {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

:root {
  --fog-dense: #b9c6d3;
  --fog-clear: #e3e9ef;
  --fog-mid: #dfe6ec;
  --paper: #ffffff;
  --ink: #2a3c4e;
  --ink-2: #566a7d;
  --line: rgba(42, 60, 78, 0.16);
  --wash: rgba(42, 60, 78, 0.06);
  --gold: #b8955e;
  --danger: #8a4b3c;
  --kai: "LXGW WenKai", "Kaiti SC", "STKaiti", serif;
  --sans: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", sans-serif;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  --slide: cubic-bezier(0.22, 0.9, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* 登录页到晨课是两张页面：用浏览器原生的跨页过渡交叉显影，底色先铺雾色，不经过一拍白屏 */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 260ms var(--ease-in) both fade-out; }
::view-transition-new(root) { animation: 420ms var(--ease-out) both condense; }
@keyframes fade-out { to { opacity: 0; filter: blur(6px); } }
html { background: linear-gradient(180deg, #b9c6d3 0%, #dfe6ec 50%, #ffffff 100%) fixed; }
body {
  background: transparent; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased;
  overflow: hidden; line-break: strict; text-autospace: normal; text-spacing-trim: normal; caret-color: var(--ink);
}
::selection { background: rgba(184, 149, 94, 0.28); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[x-cloak] { display: none !important; }
.nb, .clause { white-space: nowrap; }

/* 页面与雾：--clear 从 0 到 1，读得越多雾越薄 */
.app {
  --fog-top: color-mix(in oklab, var(--fog-dense) calc((1 - var(--clear)) * 100%), var(--fog-clear));
  position: relative; height: 100dvh; max-width: 560px; margin: 0 auto; overflow: hidden;
  background: linear-gradient(180deg, var(--fog-top) 0%, color-mix(in oklab, var(--fog-top) 55%, var(--fog-mid)) 24%, var(--fog-mid) 50%, #f1f4f7 74%, var(--paper) 100%);
  transition: --clear 900ms var(--ease-out);
}
.app.on-qa { --clear: 1; }
.page { height: 100%; display: flex; flex-direction: column; transform-origin: 50% 0; transition: transform 300ms var(--slide), filter 300ms var(--slide); }
.app.sheet-open .page { transform: scale(0.97); filter: brightness(0.94); }

/* 顶栏：品牌 + 晨课 / 问答 */
.top { height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 20px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--kai); font-size: 18px; letter-spacing: 0.14em; }
.seal {
  width: 22px; height: 22px; border: 1.25px solid var(--gold); border-radius: 2px;
  display: grid; place-items: center; font-family: var(--kai); font-size: 9px; line-height: 1; color: var(--gold);
  writing-mode: vertical-rl; letter-spacing: 0;
}
.tabs { position: relative; display: flex; }
.tab { min-height: 44px; padding: 0 8px; font-size: 15px; color: var(--ink-2); transition: color 200ms; }
.tab[aria-selected="true"] { color: var(--ink); }
.tab-bar { position: absolute; bottom: 8px; height: 1.5px; background: var(--gold); transition: transform 260ms var(--slide), width 260ms var(--slide); }

/* 进度：整行是打开“今日五句”的按钮 */
.progress { flex: none; display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 20px; width: 100%; position: relative; z-index: 3; }
.progress b { flex: 1; height: 2px; border-radius: 1px; background: rgba(255, 255, 255, 0.75); transition: background-color 300ms var(--ease-out); }
.progress b.read { background: var(--ink); }
.progress b.now { background: var(--gold); }
.count { margin-left: 8px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.count svg { transition: transform 240ms var(--ease-out); }
.app.toc-open .count svg { transform: rotate(180deg); }

/* 课页 */
.leaf {
  flex: 1; min-height: 0; overflow-y: auto; padding: clamp(20px, 8vh, 84px) 28px 20px; display: flex; flex-direction: column; align-items: center;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 28px, #000 calc(100% - 16px), transparent 100%);
}
.verse { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 22px; }
.col { writing-mode: vertical-rl; font-family: var(--kai); font-size: 38px; line-height: 1; letter-spacing: 0.22em; color: var(--ink); }
.kuan { writing-mode: vertical-rl; align-self: flex-end; font-family: var(--kai); font-size: 15px; letter-spacing: 0.18em; color: var(--ink-2); margin-left: 4px; }
.kuan small { font-size: 13px; }
.verse, .below { transition: opacity 180ms var(--ease-in), filter 180ms var(--ease-in); }
.leaf.leaving .verse, .leaf.leaving .below { opacity: 0; filter: blur(6px); }
.leaf.entering .verse { animation: condense 420ms var(--ease-out) both; }
.leaf.entering .below { animation: condense 420ms var(--ease-out) 60ms both; }
@keyframes condense { from { opacity: 0; filter: blur(8px); } to { opacity: 1; filter: blur(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.app.intro .col { animation: condense 460ms var(--ease-out) both; animation-delay: calc(var(--i) * 70ms); }
.app.intro .kuan { animation: condense 460ms var(--ease-out) 180ms both; }
.app.intro .below, .app.intro .acts { animation: rise 420ms var(--ease-out) 240ms both; }

.below { width: 100%; margin-top: 44px; padding-top: 16px; border-top: 1px solid var(--line); }
.gloss { font-size: 16px; line-height: 1.75; color: var(--ink); text-wrap: pretty; }
.notes-toggle { margin-top: 6px; min-height: 44px; display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ink-2); }
.notes-toggle svg { transition: transform 240ms var(--ease-out); }
.notes-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.notes-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 260ms var(--ease-out); }
.notes-wrap.open { grid-template-rows: 1fr; }
.notes-wrap > div { overflow: hidden; }
.note { width: 100%; text-align: left; padding: 12px 0 14px; border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; padding-top: 4px; }
.note-meta { font-size: 13px; color: var(--ink-2); }
.note-meta b { font-weight: 500; color: var(--ink); font-size: 15px; margin-right: 8px; }
.note p { margin-top: 4px; font-size: 15px; line-height: 1.7; color: var(--ink); text-wrap: pretty; }
.note.fresh { animation: rise 360ms var(--ease-out) both; }

/* 底部动作 */
.acts { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 20px max(24px, env(safe-area-inset-bottom)); }
.link { min-height: 44px; display: inline-flex; align-items: center; font-size: 15px; color: var(--ink); }
.link span { border-bottom: 1px solid currentColor; padding-bottom: 2px; }
.primary {
  margin-left: auto; height: 48px; padding: 0 24px; border-radius: 24px; background: var(--ink); color: #fff; font-size: 15px; letter-spacing: 0.04em;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform 120ms var(--ease-out), background-color 200ms;
}
.primary:active { transform: scale(0.97); }
@media (hover: hover) { .primary:hover { background: #34495e; } .link:hover span { border-bottom-width: 2px; } .row:hover { background: var(--wash); } }

/* 遮罩与今日五句 */
.scrim { position: absolute; inset: 0; background: rgba(42, 60, 78, 0.3); opacity: 0; pointer-events: none; transition: opacity 260ms var(--ease-out); z-index: 2; }
.scrim.show { opacity: 1; pointer-events: auto; }
.toc {
  position: absolute; left: 0; right: 0; top: 96px; z-index: 3; background: var(--paper); border-radius: 0 0 16px 16px; padding: 4px 20px 12px;
  transform: translateY(-12px); opacity: 0; pointer-events: none; transition: transform 260ms var(--slide), opacity 200ms var(--ease-out);
}
.toc.show { transform: none; opacity: 1; pointer-events: auto; }
.toc-date { font-size: 13px; line-height: 1.6; color: var(--ink-2); padding: 6px 0 8px; }
.toc li { list-style: none; }
.toc button { width: 100%; min-height: 56px; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; text-align: left; border-top: 1px solid var(--line); }
.toc .n { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.toc .t { font-family: var(--kai); font-size: 18px; letter-spacing: 0.06em; }
.toc .t small { display: block; font-family: var(--sans); font-size: 13px; letter-spacing: 0; color: var(--ink-2); margin-top: 2px; }
.toc .s { font-size: 13px; color: var(--ink-2); }
.toc .s.now { color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.toc .s.now::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }

/* 问答：历史与自由发问 */
.qa { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.qa-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 20px 12px; }
.qa-label { font-size: 13px; color: var(--ink-2); padding: 12px 0 6px; }
.row { width: 100%; text-align: left; padding: 14px 0; border-top: 1px solid var(--line); display: block; }
.qa-label + .row, .qa-empty + .row { border-top: 0; }
.qa-list .row { border-bottom: 1px solid var(--line); border-top: 0; }
.row .q2 { font-size: 16px; line-height: 1.55; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .meta { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.row.hist { display: flex; align-items: center; gap: 12px; }
.row.hist > svg, .row.suggest > svg { flex: none; color: var(--ink-2); }
.hist-main { flex: 1; min-width: 0; display: block; }
.row .quote { display: block; margin-top: 4px; font-family: var(--kai); font-size: 14px; letter-spacing: 0.04em; color: var(--ink-2); }
.row .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.refs-n { display: inline-flex; align-items: center; gap: 3px; }
.refs-n i, .refs-n-chip { font-style: normal; display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; border: 1px solid var(--gold); border-radius: 9px; font-size: 11px; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.row.suggest { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 0; }
.qa-empty { font-size: 15px; line-height: 1.7; color: var(--ink); padding: 18px 0 6px; }
.qa-day { font-family: var(--kai); font-size: 15px; color: var(--ink-2); letter-spacing: 0.08em; padding-top: 6px; }

/* 发问面板 */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; height: calc(100% - 44px); background: var(--paper); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; transform: translateY(102%); transition: transform 300ms var(--slide);
}
.sheet.show { transform: none; }
.sheet.compact { height: auto; max-height: calc(100% - 44px); }
.sheet.compact .sheet-body { flex: none; }
.grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-head { flex: none; display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px 14px 20px; border-bottom: 1px solid var(--line); }
.context { flex: 1; min-width: 0; }
.context q { quotes: none; display: block; font-family: var(--kai); font-size: 18px; line-height: 1.5; letter-spacing: 0.04em; color: var(--ink); }
.context small { display: block; margin-top: 2px; font-size: 13px; color: var(--ink-2); }
.context .free { font-size: 17px; font-weight: 500; line-height: 44px; }
.text-btn { min-height: 44px; padding: 0 8px; font-size: 15px; color: var(--ink); }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 20px 24px; scroll-behavior: smooth; }
.hint { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.suggest-list .row { border-top: 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.suggest-list svg { flex: none; color: var(--ink-2); }

.turn + .turn { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.q { font-size: 19px; font-weight: 500; line-height: 1.45; text-wrap: pretty; }
.stage { margin-top: 10px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stage i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--line); border-top-color: var(--ink); animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.refs { margin-top: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.refs-head { width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0; font-size: 14px; color: var(--ink); }
.refs-head > span { display: inline-flex; align-items: center; gap: 4px; }
.refs-head small { margin-left: 8px; font-size: 13px; color: var(--ink-2); }
.refs-head svg { transition: transform 240ms var(--ease-out); color: var(--ink-2); }
.refs-head[aria-expanded="true"] svg { transform: rotate(180deg); }
.refs ol { list-style: none; padding: 0 0 6px; }
.ref { padding: 10px 0; border-top: 1px solid var(--line); scroll-margin-top: 16px; transition: background-color 600ms; }
.ref.flash { background: rgba(184, 149, 94, 0.14); }
.ref b { font-family: var(--kai); font-weight: 400; font-size: 15px; letter-spacing: 0.04em; }
.page-body { display: contents; }
.ref b em { font-style: normal; }
.ref b span { font-family: var(--sans); font-size: 12px; color: var(--ink-2); margin-right: 6px; font-variant-numeric: tabular-nums; }
.ref p { margin-top: 4px; font-size: 14px; line-height: 1.65; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ref.open p { -webkit-line-clamp: unset; }

.answer { margin-top: 16px; font-size: 16px; line-height: 1.8; color: var(--ink); }
.answer p { margin-bottom: 12px; text-wrap: pretty; }
.answer strong { font-weight: 600; }
.answer blockquote { margin: 4px 0 12px; padding: 2px 0 2px 12px; border-left: 2px solid var(--line); font-family: var(--kai); font-size: 17px; letter-spacing: 0.02em; }
.answer ol, .answer ul { margin: 0 0 12px 1.4em; }
.answer li { margin-bottom: 6px; }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.answer h4 { font-size: 16px; font-weight: 600; margin: 14px 0 6px; }
.cite {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 2px; vertical-align: 3px;
  border: 1px solid var(--gold); border-radius: 9px; font-family: var(--sans); font-size: 11px; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums;
}
.cite::after { content: ""; position: absolute; inset: -13px -12px; }
.cite { position: relative; }
.caret::after { content: ""; display: inline-block; width: 7px; height: 16px; margin-left: 2px; vertical-align: -2px; background: var(--ink); opacity: 0.5; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.after { display: flex; align-items: center; gap: 16px; padding-top: 6px; flex-wrap: wrap; }
.after .primary { margin-left: 0; min-width: 132px; }
.saved-tag { display: inline-flex; align-items: center; gap: 6px; height: 48px; padding: 0 20px; border-radius: 24px; border: 1px solid var(--ink); font-size: 15px; }
.saved-tag svg path { stroke-dasharray: 16; stroke-dashoffset: 16; animation: draw 320ms var(--ease-out) 60ms forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.inline-error { margin-top: 12px; font-size: 14px; line-height: 1.6; color: var(--danger); }
.problem { margin-top: 18px; padding: 16px 0; border-top: 1px solid var(--line); }
.problem p { font-size: 16px; line-height: 1.75; }
.problem p + p { font-size: 14px; color: var(--ink-2); margin-top: 4px; }
.problem .primary { margin: 14px 0 0; }

.composer { flex: none; padding: 10px 16px max(18px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.field { display: flex; align-items: center; gap: 8px; min-height: 50px; padding: 5px 5px 5px 14px; border-radius: 8px; background: #eef2f5; }
.field textarea { flex: 1; min-width: 0; max-height: 120px; border: 0; background: none; font: inherit; font-size: 16px; line-height: 1.5; color: var(--ink); outline: none; resize: none; field-sizing: content; }
.field textarea::placeholder { color: var(--ink-2); }
.send { flex: none; align-self: flex-end; width: 40px; height: 40px; border-radius: 6px; background: var(--ink); color: #fff; display: grid; place-items: center; transition: transform 120ms var(--ease-out); }
.send:active { transform: scale(0.94); }
.send[disabled] { background: #a7b4c1; cursor: default; }
.scope { margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.qa .composer { background: transparent; border-top: 0; }
.qa .field { background: var(--paper); box-shadow: 0 0 0 1px var(--line); }

/* 读毕页 */
.finish { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: clamp(16px, 6vh, 64px) 24px 12px; }
.scroll-page { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 18px; }
.scroll-page .line { writing-mode: vertical-rl; font-family: var(--kai); font-size: 26px; letter-spacing: 0.16em; line-height: 1; color: var(--ink); animation: condense 460ms var(--ease-out) both; animation-delay: calc(var(--i) * 80ms); }
.scroll-page .sign { align-self: flex-end; display: flex; flex-direction: column; align-items: center; gap: 10px; margin-left: 6px; }
.scroll-page .sign span { writing-mode: vertical-rl; font-family: var(--kai); font-size: 15px; letter-spacing: 0.16em; color: var(--ink-2); animation: condense 460ms var(--ease-out) 420ms both; }
.stamp {
  width: 44px; height: 44px; border-radius: 3px; background: var(--gold); display: grid; place-items: center; font-family: var(--kai); font-size: 17px; line-height: 1.05; color: #fff;
  writing-mode: vertical-rl; letter-spacing: 0.02em; animation: stamp 520ms cubic-bezier(0.2, 0.9, 0.3, 1) 1050ms both;
}
@keyframes stamp { 0% { opacity: 0; transform: scale(1.7) rotate(-6deg); } 55% { opacity: 1; transform: scale(0.92) rotate(-2deg); } 72% { transform: scale(1.03) rotate(-2deg); } 100% { opacity: 1; transform: scale(1) rotate(-2deg); } }
.scroll-page .sign { animation: settle 160ms ease-out 1340ms both; }
@keyframes settle { 50% { transform: translateY(1.5px); } }
.done-note { margin-top: 36px; width: 100%; padding-top: 16px; border-top: 1px solid var(--line); font-size: 16px; line-height: 1.75; animation: rise 420ms var(--ease-out) 1500ms both; }
.done-note small { display: block; font-size: 14px; color: var(--ink-2); }

.toast { position: absolute; left: 50%; bottom: 96px; z-index: 6; transform: translate(-50%, 8px); opacity: 0; pointer-events: none; padding: 10px 16px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 14px; transition: opacity 200ms, transform 200ms var(--ease-out); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { flex: 1; display: grid; place-items: center; font-size: 14px; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .saved-tag svg path { stroke-dashoffset: 0; }
}

/* 登录 */
.gate { --clear: 0.2; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: clamp(48px, 14vh, 140px) 28px max(40px, env(safe-area-inset-bottom)); }
.gate-mark { display: flex; flex-direction: column; align-items: center; gap: 28px; }
.gate-cols { display: flex; flex-direction: row-reverse; gap: 18px; }
.gate-cols span { writing-mode: vertical-rl; font-family: var(--kai); font-size: 30px; letter-spacing: 0.24em; color: var(--ink); animation: condense 520ms var(--ease-out) both; }
.gate-cols span + span { animation-delay: 90ms; }
.gate-name { display: flex; align-items: center; gap: 8px; font-family: var(--kai); font-size: 20px; letter-spacing: 0.16em; color: var(--ink-2); }
.gate-form { width: 100%; max-width: 360px; }
.gate-form label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 8px; }
.gate-form .field { background: var(--paper); box-shadow: 0 0 0 1px var(--line); }
.gate-form input { flex: 1; min-width: 0; height: 40px; border: 0; background: none; font: inherit; font-size: 16px; color: var(--ink); outline: none; }
