/* 常见问题页：章节式阅读。左侧目录随滚动指示当前问题，每个问题是一个独立章节。 */
:root {
  --qa-ease: cubic-bezier(.16, 1, .3, 1);
  --qa-head: 64px;
}
/* 全站的 scroll-padding 是给固定页头留的 84px；这一页的页头是 sticky 的
   .qa-top，章节自己已经用 scroll-margin-top 把页头让开了。两层叠在一起，
   原生锚点会多顶 84px，标题挂在页头下面一大片空白里。这里归零，
   让原生跳转和脚本算出的落点重合。 */
html { scroll-padding-top: 0; }
.qa-page { min-height: 100vh; background: var(--bg); }

/* ---------- 顶部：阅读进度 + 页头 ---------- */
.qa-progress { position: fixed; inset: 0 0 auto; z-index: 30; height: 2px; pointer-events: none; }
.qa-progress > span {
  display: block; height: 100%; transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, color-mix(in oklch, var(--gold) 26%, transparent), var(--gold));
  box-shadow: 0 0 12px color-mix(in oklch, var(--gold) 52%, transparent);
  transition: transform .14s linear;
}
.qa-top {
  position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in oklch, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.qa-top-row { display: flex; align-items: center; gap: 24px; min-height: var(--qa-head); padding: 12px var(--gutter); }
.qa-back, .qa-join { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; text-decoration: none; }
.qa-back { gap: 6px; color: var(--muted); transition: color .3s var(--qa-ease); }
.qa-back:hover { color: var(--text); }
.qa-back-arrow { display: inline-block; transition: transform .45s var(--qa-ease); }
.qa-back:hover .qa-back-arrow { transform: translateX(-4px); }
.qa-join {
  padding: 7px 18px; border: 1px solid var(--gold-soft); border-radius: 999px; color: var(--gold); font-weight: 700;
  transition: background-color .3s var(--qa-ease), color .3s var(--qa-ease), border-color .3s var(--qa-ease), transform .45s var(--qa-ease);
}
.qa-join:hover { background: var(--gold); color: var(--bg); border-color: var(--gold); transform: translateY(-1px); }

/* 窄屏的「正在读哪一条」：滚过标题后从页头下方展开。 */
.qa-running { display: none; }

/* ---------- 版面 ---------- */
.qa-main { width: min(100%, 1160px); margin-inline: auto; padding: clamp(48px, 9vw, 104px) var(--gutter) clamp(96px, 14vw, 160px); }
.qa-hero { max-width: 880px; margin-bottom: clamp(44px, 7vw, 88px); }
.qa-hero h1 { margin: 0 0 18px; font-size: clamp(36px, 6vw, 64px); font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.qa-hero-line { display: block; overflow: hidden; padding-block: .05em .1em; margin-block: -.05em -.1em; }
.qa-hero-word { display: block; }
.qa-lede { max-width: 58ch; margin: 0; color: var(--muted); font-size: clamp(15px, 1.4vw, 17px); line-height: 1.9; }

.qa-layout { display: grid; grid-template-columns: minmax(210px, 270px) minmax(0, 1fr); gap: clamp(40px, 6vw, 96px); align-items: start; }

/* ---------- 左侧目录 ---------- */
.qa-rail { position: sticky; top: calc(var(--qa-head) + 32px); }
.qa-rail-scroll {
  max-height: calc(100vh - var(--qa-head) - 72px); overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none;
}
.qa-rail-scroll::-webkit-scrollbar { display: none; }
.qa-rail-track { position: relative; padding-left: 20px; }
.qa-rail-track::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 1px; background: var(--line-soft); }
.qa-index { margin: 0; padding: 0; list-style: none; }
.qa-index a, .qa-toc a {
  display: block; padding: 11px 0; color: var(--faint); font-size: 14px; line-height: 1.55; text-decoration: none;
  transition: color .4s var(--qa-ease), transform .55s var(--qa-ease);
}
.qa-index a:hover, .qa-toc a:hover { color: var(--text); }
.qa-index a[aria-current] { color: var(--text); transform: translateX(5px); }
/* 一条金线在目录里滑动，拉伸着从上一条走到下一条。 */
.qa-marker {
  position: absolute; left: 0; top: 0; width: 2px; height: 1px;
  background: var(--gold); box-shadow: 0 0 10px color-mix(in oklch, var(--gold) 55%, transparent);
  transform-origin: 0 0; transform: translateY(0) scaleY(0); opacity: 0;
  transition: transform .7s var(--qa-ease), opacity .4s var(--qa-ease);
  pointer-events: none;
}
.qa-marker.is-on { opacity: 1; }

/* 窄屏的目录：原生折叠。 */
.qa-toc { display: none; border-block: 1px solid var(--line-soft); margin-bottom: 8px; }
.qa-toc summary {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; font-size: 15px; font-weight: 500; cursor: pointer; list-style: none;
}
.qa-toc summary::-webkit-details-marker { display: none; }
.qa-toc summary::after {
  content: ''; width: 9px; height: 9px; margin-right: 4px;
  border-right: 1.5px solid var(--gold); border-bottom: 1.5px solid var(--gold);
  transform: translateY(-2px) rotate(45deg); transition: transform .5s var(--qa-ease);
}
.qa-toc[open] summary::after { transform: translateY(2px) rotate(-135deg); }
.qa-toc ul { margin: 0; padding: 0 0 12px; list-style: none; }
.qa-toc a { padding: 12px 0; min-height: 44px; color: var(--muted); }
.qa-toc[open] li { animation: qa-fade-up .6s var(--qa-ease) calc(var(--k, 0) * 40ms) both; }

/* ---------- 章节 ---------- */
.qa-chapters { min-width: 0; }
.qa-chapter { position: relative; padding: clamp(40px, 8vh, 80px) 0 clamp(44px, 8vh, 84px); scroll-margin-top: calc(var(--qa-head) + 12px); }
.qa-chapter:first-child { padding-top: 0; }
/* 章节之间不画分隔线，靠留白分开。 */

.qa-question {
  position: relative;
  margin: 0 0 clamp(18px, 2.4vw, 28px); padding-bottom: 8px; max-width: 22em;
  font-size: clamp(24px, 3.2vw, 38px); font-weight: 700; line-height: 1.3; letter-spacing: -.015em; text-wrap: balance;
  transition: opacity .7s var(--qa-ease);
}
/* 金线是一条独立的伪元素，不是标题身上的背景图：背景图会被对比度检查当成
   标题压在一块金色底上，读出 1.3:1 的假问题；伪元素也更容易用 transform 动。 */
.qa-question::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--gold); transform: scaleX(0); transform-origin: 0 50%; pointer-events: none;
}
/* 读到哪一章，哪一章的标题亮起；其余稍退后，目录与正文的指向才一致。 */
.qa-live .qa-chapter:not(.is-current) .qa-question { opacity: .58; }
.qa-answer { max-width: 62ch; color: var(--muted); font-size: 16px; line-height: 1.95; overflow-wrap: anywhere; }
.qa-answer > p { margin: 0 0 20px; }
.qa-answer > :last-child { margin-bottom: 0; }

/* 补充说明：小字号、更浅，和正文拉开层级。 */
.qa-answer .faq-note { margin: 4px 0 28px; padding: 4px 0 4px clamp(14px, 2vw, 20px); border-left: 1px solid var(--line); }
.qa-answer .faq-note p { margin: 0; max-width: 60ch; padding-bottom: 10px; color: var(--faint); font-size: 13.5px; line-height: 1.85; }
.qa-answer .faq-note p:last-child { padding-bottom: 0; }
.qa-answer .faq-note .faq-note-title { padding-bottom: 2px; font-size: 14px; font-weight: 700; line-height: 1.7; color: var(--muted); }

/* 从目录跳进来：标题下划一条金线，画到头再从右侧擦掉。
   两段共用同一根线：前半段从左展开，后半段改从右端收起。 */
.qa-chapter.is-target .qa-question::after { animation: qa-target 2.2s var(--qa-ease) .15s both; }
@keyframes qa-target {
  0% { transform: scaleX(0); transform-origin: 0 50%; }
  38% { transform: scaleX(1); transform-origin: 0 50%; }
  72% { transform: scaleX(1); transform-origin: 100% 50%; }
  100% { transform: scaleX(0); transform-origin: 100% 50%; }
}

/* ---------- 页尾 ---------- */
.qa-close { padding: clamp(56px, 10vh, 96px) 0 0; }
.qa-close h2 { margin: 0 0 14px; font-size: clamp(22px, 2.6vw, 30px); font-weight: 700; line-height: 1.35; letter-spacing: -.01em; }
.qa-close p { max-width: 52ch; margin: 0 0 28px; color: var(--muted); font-size: 15.5px; line-height: 1.9; text-wrap: pretty; }
.qa-cta {
  display: inline-flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 26px;
  border-radius: 999px; background: var(--gold); color: var(--bg); font-weight: 700; text-decoration: none;
  transition: transform .5s var(--qa-ease), box-shadow .5s var(--qa-ease), background-color .3s var(--qa-ease);
}
.qa-cta:hover { color: var(--bg); background: color-mix(in oklch, var(--gold) 88%, white); transform: translateY(-2px); box-shadow: 0 12px 30px -12px color-mix(in oklch, var(--gold) 60%, transparent); }
.qa-cta:active { transform: scale(.97); }
.qa-cta-arrow { display: inline-block; transition: transform .5s var(--qa-ease); }
.qa-cta:hover .qa-cta-arrow { transform: translateX(5px); }

/* ---------- 入场编排 ---------- */
/* 只有内联脚本给 html 加了 anim，才会把初值藏起来；
   每一处都配了一个 3 秒后无条件放行的兜底动画，脚本失败时内容也不会一直不可见。 */
@keyframes qa-unhide { to { opacity: 1; transform: none; clip-path: none; } }
@keyframes qa-rise { from { clip-path: inset(-6% 0 108% 0); transform: translateY(6px); } to { clip-path: inset(-6% 0 -8% 0); transform: none; } }
@keyframes qa-fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes qa-slide-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes qa-bar-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes qa-word-in { to { transform: translateY(0); } }

html.anim .qa-top-row { opacity: 0; transform: translateY(-8px); animation: qa-unhide 0s 3s forwards; }
html.anim .qa-lede { opacity: 0; animation: qa-unhide 0s 3s forwards; }
html.anim .qa-hero-word { transform: translateY(112%); animation: qa-unhide 0s 3s forwards; }
html.anim .qa-index li { opacity: 0; transform: translateX(-10px); animation: qa-unhide 0s 3s forwards; }
html.anim .qa-chapter:not(.qa-in) .qa-question { clip-path: inset(-6% 0 108% 0); transform: translateY(6px); animation: qa-unhide 0s 3s forwards; }
html.anim .qa-chapter:not(.qa-in) .qa-answer > *, html.anim .qa-close:not(.qa-in) > * { opacity: 0; transform: translateY(14px); animation: qa-unhide 0s 3s forwards; }

html.page-ready .qa-top-row { animation: qa-bar-in .75s var(--qa-ease) .02s both; }
html.page-ready .qa-hero-word { animation: qa-word-in 1.05s var(--qa-ease) .06s forwards; }
html.page-ready .qa-lede { animation: qa-fade-up .95s var(--qa-ease) .2s both; }
html.page-ready .qa-index li { animation: qa-slide-in .85s var(--qa-ease) calc(min(var(--k, 0), 10) * 45ms + 280ms) both; }

.qa-chapter.qa-in .qa-question { animation: qa-rise 1s var(--qa-ease) calc(var(--i, 0) * 70ms) both; }
.qa-chapter.qa-in .qa-answer > * { animation: qa-fade-up .9s var(--qa-ease) calc(var(--i, 0) * 70ms + 150ms + var(--p, 0) * 80ms) both; }
.qa-close.qa-in > * { animation: qa-fade-up .9s var(--qa-ease) calc(var(--p, 0) * 90ms) both; }
.qa-chapter.is-target.qa-in .qa-question { animation: qa-rise 1s var(--qa-ease) both; }
.qa-answer > :nth-child(2), .qa-close > :nth-child(2) { --p: 1; }
.qa-answer > :nth-child(3), .qa-close > :nth-child(3) { --p: 2; }
.qa-answer > :nth-child(4) { --p: 3; }
.qa-answer > :nth-child(5) { --p: 4; }
.qa-answer > :nth-child(n+6) { --p: 5; }

@media (max-width: 900px) {
  .qa-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .qa-rail { display: none; }
  .qa-toc { display: block; }
  .qa-running { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .55s var(--qa-ease); }
  .qa-top.has-current .qa-running { grid-template-rows: 1fr; }
  .qa-running-inner { min-height: 0; overflow: hidden; }
  .qa-running-text {
    display: block; padding: 2px var(--gutter) 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-size: 13px; line-height: 1.5;
  }
  .qa-running-text.is-swap { animation: qa-fade-up .5s var(--qa-ease) both; }
  .qa-chapter { scroll-margin-top: calc(var(--qa-head) + 44px); }
  /* 手机上章节间距按视口收一点：8vh 叠起来是一百三十多像素的空档，
     读起来像断了一页；5.5vh 仍比桌面松，但不再断气。 */
  .qa-chapter { padding-block: clamp(40px, 5.5svh, 72px) clamp(44px, 5.5svh, 76px); }
  .qa-chapter:first-child { padding-top: 0; }
}
@media (max-width: 560px) {
  .qa-top-row { gap: 16px; }
  .qa-back-arrow { display: none; }
  .qa-answer { font-size: 15.5px; }
}

@media (prefers-reduced-motion: reduce) {
  html.anim .qa-top-row, html.anim .qa-lede, html.anim .qa-index li,
  html.anim .qa-chapter:not(.qa-in) .qa-answer > *, html.anim .qa-close:not(.qa-in) > * { opacity: 1; transform: none; }
  html.anim .qa-hero-word, html.anim .qa-chapter:not(.qa-in) .qa-question { transform: none; clip-path: none; }
  .qa-live .qa-chapter:not(.is-current) .qa-question { opacity: 1; }
  .qa-progress > span, .qa-marker { transition: none; }
}
