/* 命书页「细问」：桌面贴右侧栏、窄屏底部上滑浮层。纸色与细线沿用阅读页，不另起视觉。 */
.qa-panel[hidden], .qa-scrim[hidden], .qa-launcher[hidden], .qa-quote[hidden] { display: none; }
:root { --qa-w: clamp(360px, 30vw, 420px); }

.qa-panel {
  position: fixed; z-index: 140; display: flex; flex-direction: column; min-height: 0;
  background: var(--ivory); color: var(--near-black); font-family: var(--sans);
  border: 1px solid var(--border-soft); box-shadow: 0 12px 40px rgba(24,24,26,.12);
  transition: transform .22s cubic-bezier(.2,.8,.2,1), opacity .22s ease, height .22s ease;
}
.qa-panel.is-dragging { transition: none; }
.qa-scrim { position: fixed; inset: 0; z-index: 139; background: rgba(24,24,26,.32); }

.qa-grab { display: none; }
.qa-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 20px; border-bottom: 1px solid var(--border-soft); }
.qa-titles { flex: 1; min-width: 0; }
.qa-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .04em; }
.qa-sub { margin: 2px 0 0; font-size: 12px; color: var(--stone); }
.qa-desk { font-size: 13px; color: var(--stone); text-decoration: none; padding: 12px 6px; white-space: nowrap; }
.qa-desk:hover { color: var(--near-black); text-decoration: underline; text-underline-offset: 3px; }
.qa-close {
  display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: var(--near-black); cursor: pointer;
}
.qa-close:hover { background: rgba(24,24,26,.05); }

.qa-thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px; }
.qa-empty, .qa-more { margin: 8px 0 16px; font-size: 13px; line-height: 1.6; color: var(--stone); }
.qa-bubble { margin: 0 0 16px; font-size: 15px; line-height: 1.75; overflow-wrap: anywhere; }
.qa-bubble.is-ask {
  margin-left: 24px; padding: 10px 14px; border: 1px solid var(--border-soft); border-radius: 12px;
  background: var(--warm-sand); background: color-mix(in srgb, var(--ivory) 70%, var(--warm-sand));
}
.qa-bubble.is-ask > p { margin: 0; }
.qa-bubble.is-ask .reading-quote-card + p { margin-top: 10px; }
.qa-bubble.is-reply p { margin: 0 0 10px; }
.qa-bubble.is-reply ul { margin: 0 0 10px; padding-left: 20px; }
.qa-bubble.is-error { color: var(--stone); }
.qa-followups { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: -4px 0 16px; }
.qa-followups button {
  min-height: 36px; padding: 6px 12px; border: 1px solid var(--border-soft); border-radius: 18px;
  background: transparent; color: var(--near-black); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.qa-followups button:hover { border-color: var(--stone); }

.qa-composer { border-top: 1px solid var(--border-soft); padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.qa-quote { padding: 0 4px 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.qa-quote .reading-quote-prompts { gap: 6px; margin: 4px 0 6px; }
.qa-quote .reading-quote-prompts button { min-height: 32px; padding: 4px 12px; border: 1px solid var(--border-soft); border-radius: 16px; }
.qa-quote .reading-quote-prompts button:hover { border-color: var(--stone); }
.qa-row { display: flex; align-items: flex-end; gap: 8px; }
.qa-input {
  flex: 1; min-width: 0; min-height: 44px; max-height: 160px; resize: none; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--near-black);
  font: inherit; font-size: 16px; line-height: 1.5;
  overflow-y: hidden; scrollbar-width: none;
}
.qa-input::-webkit-scrollbar { display: none; }
.qa-input:focus { outline: none; border-color: var(--near-black); }
.qa-send {
  min-width: 64px; min-height: 44px; border: 0; border-radius: 12px; background: var(--near-black);
  color: var(--ivory); font: inherit; font-size: 15px; cursor: pointer;
}
.qa-send:disabled { opacity: .35; cursor: default; }
.qa-status { margin: 6px 2px 0; min-height: 0; font-size: 12px; line-height: 1.5; color: var(--stone); }
.qa-status:empty { display: none; }
.qa-status a { color: var(--near-black); text-decoration: underline; text-underline-offset: 3px; }

/* 右下角「细问」：与划线续问同一副小胶囊（图标＋字），但用纸色，常驻不抢正文。 */
.qa-launcher {
  position: fixed; z-index: 130; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 17px 0 16px; border: 1px solid var(--border-soft); border-radius: 999px;
  background: var(--ivory); color: var(--near-black); font: inherit; font-size: 14px; font-weight: 500; letter-spacing: .04em;
  box-shadow: 0 6px 18px rgba(24,24,26,.10), 0 1px 2px rgba(24,24,26,.06); cursor: pointer;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.qa-launcher::before {
  content: ""; display: block; width: 14px; height: 14px; flex: none; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='2 2 12 12' fill='none' stroke='black' stroke-width='1.35' stroke-linejoin='round' stroke-linecap='round'%3E%3Cpath d='M2.75 3.25h10.5v7.25H8.5l-3.25 2.5v-2.5h-2.5z'/%3E%3Cpath d='M5.5 6.25h5M5.5 8.25h3'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='2 2 12 12' fill='none' stroke='black' stroke-width='1.35' stroke-linejoin='round' stroke-linecap='round'%3E%3Cpath d='M2.75 3.25h10.5v7.25H8.5l-3.25 2.5v-2.5h-2.5z'/%3E%3Cpath d='M5.5 6.25h5M5.5 8.25h3'/%3E%3C/svg%3E") center / contain no-repeat;
}
/* 宽屏页面两侧有版心外框（--frame-w，居中）：固定贴视口右缘会骑在框边上，改为落在框内 16px。 */
@media (min-width: 681px) {
  .qa-launcher { right: calc(max(20px, (100vw - var(--frame-w, 100vw)) / 2) + 16px); }
}
.qa-launcher:hover { border-color: var(--border); box-shadow: 0 8px 22px rgba(24,24,26,.14), 0 1px 2px rgba(24,24,26,.08); }
/* 窄屏时右下角「细问」常驻，会压住正文最后两三行：给页面底部让出它的高度。 */
@media (max-width: 1100px) {
  html.qa-launcher-on body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
}
/* 「放到桌面」提示卡在屏时让位：浮钮层级更高，会正好压住卡片右下角的「知道了」。 */
html.a2hs-open .qa-launcher { display: none; }
.qa-launcher.is-busy::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; vertical-align: middle;
  border-radius: 50%; background: var(--stone);
}

/* 桌面：右侧浮层，正文整体左让，不压字；顶栏不跟着让（负右外边距抵回全宽），浮层在它下面。 */
@media (min-width: 1101px) {
  .qa-panel {
    top: 72px; right: 16px; bottom: 16px; width: var(--qa-w); border-radius: 16px;
    transform: translateX(24px); opacity: 0;
  }
  .qa-panel.is-open { transform: none; opacity: 1; }
  html.qa-docked body { padding-right: calc(var(--qa-w) + 32px); }
  html.qa-docked .topbar { margin-right: calc(-1 * (var(--qa-w) + 32px)); }
}

/* 窄屏：底部上滑浮层；半屏时去掉遮罩，上半屏命书仍可读可划。 */
@media (max-width: 1100px) {
  .qa-panel {
    left: 0; right: 0; bottom: 0; height: min(86dvh, 760px); border-radius: 16px 16px 0 0;
    border-bottom: 0; transform: translateY(100%);
  }
  .qa-panel.is-open { transform: none; }
  .qa-panel.is-half { height: 48dvh; }
  /* 半屏是边读边等：引用只留一行出处与原文，把高度让给回答。 */
  .qa-panel.is-half .reading-quote-prompts, .qa-panel.is-half .reading-quote-budget,
  .qa-panel.is-half .qa-quote .reading-quote-card > button, .qa-panel.is-half .qa-sub { display: none; }
  .qa-panel.is-half .qa-quote .reading-quote-card blockquote { -webkit-line-clamp: 1; }
  .qa-grab { display: flex; justify-content: center; padding: 8px 0 0; touch-action: none; cursor: grab; }
  .qa-grab i { width: 36px; height: 5px; border-radius: 3px; background: var(--border); }
  .qa-head { touch-action: none; padding-top: 4px; }
  .qa-thread { padding: 12px 16px; }
  html.qa-sheet-open body { overflow: hidden; }
}
@media (max-width: 1100px) and (min-width: 701px) {
  .qa-panel { left: 50%; right: auto; width: min(720px, 100%); margin-left: calc(min(720px, 100%) / -2); }
}

@media (prefers-reduced-motion: reduce) { .qa-panel { transition: none; } }
/* 可接回的失败超时后给「重试这一问」（月册／年册 transport 线，2026-09-25）。 */
.qa-status-action {
  min-height: 32px; margin-left: 4px; padding: 2px 12px; border: 1px solid var(--border-soft); border-radius: 16px;
  background: transparent; color: var(--near-black); font: inherit; font-size: 12px; cursor: pointer;
}
.qa-status-action:hover { border-color: var(--stone); }
