/* ============================================================
   TCM Sage Guide — Main Stylesheet
   Colors live in tokens.css (linked before this file).
   响应式布局：宽度随浏览器，最小宽度 900px（侧栏展开再叠加）
   ============================================================ */

:root {
  /* Layout / geometry only — brand colors → static/css/tokens.css */
  --timeline-gutter: 24px;
  --sage-inactive: 0.35;
  --header-height: 50px;
  --input-bar-height: auto;
  --input-bar-offset: 0px;
  /* Horizontal padding of the input panel; the collapsed expand-btn and the
     scope menu anchor to this so they stay aligned when it changes. */
  --input-panel-pad-x: 26px;
  --input-composer-max-height: 300px;
  --input-resize-handle-height: 10px;
  --input-toolbar-height: 44px;
  --input-control-lane-height: 36px;
  /* Home toolbar geometry (layout helpers; site floor is --content-min-width). */
  --home-search-width: 361px;
  --home-tab-width: 88px;
  /* 3 tabs + 2px padding + 1px border on each side */
  --home-tabs-width: calc(var(--home-tab-width) * 3 + 6px);
  --home-toolbar-gap: 10px;
  --home-toolbar-pad-right: 16px;
  /* play toggle lane: 8px offset + 36px button */
  --timeline-play-lane: 44px;
  /* Whole-site floor; open sidebars add --sidebar-width on top (see html:has rules). */
  --content-min-width: 900px;
  --page-gutter: 32px;
  --sidebar-width: 220px;
  --radius: 10px;
  --radius-tag: 6px;
  --radius-pill: 999px;
  /* Global typography: edit these two variables to change site fonts. */
  --font-zh:
    "Noto Serif SC",
    "Source Han Serif SC",
    "Songti SC",
    "STSong",
    "SimSun",
    "HanaMinB",
    "Hanamin B",
    "HanaMinA",
    "Hanamin A",
    serif;
  --font-en:
    "Source Serif 4",
    "Noto Serif",
    "Liberation Serif",
    Georgia,
    "Times New Roman",
    "Noto Serif SC",
    serif;
  --font-current: var(--font-zh);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-width: var(--content-min-width);
}

html:has(.chat-sidebar.open),
html:has(.notes-sidebar.open) {
  min-width: calc(var(--content-min-width) + var(--sidebar-width));
}

html:has(.chat-sidebar.open):has(.notes-sidebar.open) {
  min-width: calc(var(--content-min-width) + var(--sidebar-width) * 2);
}

html:lang(zh),
html:lang(zh-CN) {
  --font-current: var(--font-zh);
}

html:lang(en) {
  --font-current: var(--font-en);
}

html, body {
  width: 100%;
  height: 100%;
  /* Allow horizontal scroll when viewport < --content-min-width (900px). */
  overflow-x: auto;
  overflow-y: hidden;
  font-family: var(--font-current);
  color: var(--text-primary);
  background: var(--bg-neijing-ground);
  display: flex;
  flex-direction: column;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

/* ---- 顶栏以下：sidebar + 主内容 ---- */
.app-shell {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  min-width: var(--content-min-width);
  align-self: stretch;
}

.app-shell:has(> .chat-sidebar.open),
.app-shell:has(> .notes-sidebar.open) {
  min-width: calc(var(--content-min-width) + var(--sidebar-width));
}

.app-shell:has(> .chat-sidebar.open):has(> .notes-sidebar.open) {
  min-width: calc(var(--content-min-width) + var(--sidebar-width) * 2);
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: var(--content-min-width);
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-neijing-ground);
  transition: margin-left 0.25s ease;
}

/* ============================================================
   BACKGROUND LAYERS
   z0 art ground → z1 fixed watermarks → z2 translucent parchment
   ============================================================ */

.bg-art-base {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--bg-neijing-ground);
  pointer-events: none;
}

.bg-parchment {
  position: absolute;
  inset: 0;
  z-index: 2;
  /* 80% opaque parchment so ground + watermarks show through */
  background-color: color-mix(in srgb, var(--bg-parchment) 90%, transparent);
  pointer-events: none;
}

/* 内经图水印：固定宽、原比例、垂直居中略下移；左右各外溢；右边水平镜像 */
.bg-watermark-left,
.bg-watermark-right {
  position: absolute;
  /* 略低于正中：只改 top，不要动 transform（右边还依赖 scaleX(-1)） */
  top: calc(50% + 36px);
  width: var(--bg-watermark-w);
  aspect-ratio: var(--bg-watermark-aspect);
  height: auto;
  z-index: 1;
  pointer-events: none;
  opacity: 0.6;
  background-image: url("/static/images/bg/neijing-tu.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 100% auto; /* width fills box; height follows aspect — no squash */
}

.bg-watermark-left {
  left: calc(-1 * var(--bg-watermark-bleed));
  transform: translateY(-50%);
}

.bg-watermark-right {
  right: calc(-1 * var(--bg-watermark-bleed));
  transform: translateY(-50%) scaleX(-1);
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: relative;
  z-index: 300;
  flex-shrink: 0;
  height: var(--header-height);
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header h1 {
  margin: 0;
  line-height: 0;
}

.header-logo {
  cursor: pointer;
}

.header-logo .app-logo {
  display: block;
  height: 24px;
  width: auto;
  margin-top: 4px;
  cursor: pointer;
}

body.is-guest .header-logo {
  display: none;
}

.app-logo--landing {
  display: block;
  height: 56px;
  width: auto;
  max-width: min(100%, 360px);
  margin: 0 auto 18px;
  object-fit: contain;
  object-position: center;
}

.lang-toggle {
  position: static;
  transform: none;
}

.header-actions {
  position: static;
  transform: none;
  display: flex;
  align-items: center;
  gap: 0;
}

.header-end {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
}

body.is-guest .header-end {
  right: 16px;
}

.header-actions > .lang-capsule,
.header-actions > .lang-toggle {
  margin-left: 10px;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 0;
  outline: none;
}

.user-menu-wrap {
  position: relative;
  line-height: 0;
}

.user-avatar-btn {
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  padding: 0;
  border-radius: var(--radius-circle, 50%);
  cursor: pointer;
  width: 36px;
  height: 36px;
  overflow: hidden;
  outline: none;
  box-shadow: none;
  display: block;
}

.user-avatar-btn:focus,
.user-avatar-btn:focus-visible {
  outline: none;
  box-shadow: none;
}

.auth-link-btn {
  border: none;
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 4px;
}

.auth-outline-btn {
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: transparent;
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 5px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.auth-login-btn {
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: transparent;
  color: #fff;
  border-radius: 10px;
  padding: 5px 16px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  font-family: inherit;
  height: 30px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.auth-btn {
  border: 1px solid rgba(212, 196, 168, 0.85);
  background: rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.auth-btn-primary {
  background: var(--header-bg);
  color: var(--header-text);
  border-color: var(--header-bg);
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-menu-popover {
  position: fixed;
  z-index: 500;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  min-width: 160px;
  padding: 8px;
}

.user-menu-popover[hidden] {
  display: none !important;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius);
}

.user-menu-item:hover {
  background: #f0f0f0;
}

.user-menu-divider {
  border: none;
  border-top: 1px solid #eee;
  margin: 6px 8px;
}

.lang-capsule.segmented-control {
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: transparent;
  border-radius: var(--radius);
  padding: 2px;
  overflow: visible;
}

.lang-capsule .lang-btn {
  color: #fff;
  padding: 5px 12px;
  font-size: 12px;
  min-width: 36px;
  border-radius: calc(var(--radius) - 2px);
  font-weight: 500;
}

.lang-capsule .lang-btn.active {
  background: transparent;
  color: var(--header-bg);
  font-weight: 500;
}

.lang-capsule .segmented-slider {
  background: #fff;
}

.app-trial-banner,
.trial-banner {
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 290;
  position: relative;
}

.trial-banner[hidden],
.app-trial-banner[hidden] {
  display: none !important;
  padding: 0;
  border: none;
}

.trial-banner-blue {
  background: #e3f2fd;
  border-bottom: 1px solid #bbdefb;
  color: #1565c0;
}

.trial-banner-text {
  text-align: center;
  flex: 1;
}

.trial-banner-close {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 4px 8px;
}

.trial-banner a,
.trial-banner-text a {
  color: #1565c0;
  font-weight: 600;
  text-decoration: underline;
}

.auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-modal[hidden] {
  display: none;
}

.confirm-delete-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 24px;
}

.confirm-delete-modal[hidden] {
  display: none;
}

.confirm-delete-panel {
  width: min(360px, 92vw);
  padding: 24px 22px 18px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.confirm-delete-message {
  margin: 0 0 8px;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
  text-align: left;
}

.confirm-delete-name {
  display: inline-block;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.confirm-delete-body {
  margin: 0 0 22px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}

.confirm-delete-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.confirm-delete-btn {
  min-width: 96px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.confirm-delete-btn-cancel {
  background: #e8e4de;
  color: var(--text-primary);
  border-color: #e8e4de;
}

.confirm-delete-btn-cancel:hover {
  background: #ddd7cf;
}

.confirm-delete-btn-danger {
  background: #c0392b;
  color: #fff;
  border-color: #c0392b;
}

.confirm-delete-btn-danger:hover {
  background: #a93226;
}

.auth-modal-panel {
  background: #fff;
  border-radius: 12px;
  padding: 1.75rem 1.5rem 1.5rem;
  width: min(380px, 92vw);
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.auth-modal-panel h2 {
  margin: 0 0 1.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-current);
}

.auth-modal-panel .auth-field {
  display: block;
  margin-bottom: 1rem;
  font-size: 13px;
  font-family: var(--font-current);
}

.auth-modal-panel .auth-field > span {
  display: block;
  margin-bottom: 6px;
}

.auth-modal-panel input {
  width: 100%;
  margin-top: 0;
  padding: 10px 12px;
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
  outline: none;
}

.auth-modal-panel input:focus {
  border-color: #000;
  box-shadow: none;
}

.auth-password-wrap {
  position: relative;
}

.auth-password-wrap input {
  padding-right: 40px;
}

.auth-pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  width: 18px;
  height: 18px;
}

.auth-pw-toggle img {
  position: absolute;
  inset: 0;
  width: 18px;
  height: 18px;
  display: block;
}

.auth-pw-toggle img[hidden] {
  display: none !important;
}

.auth-field--error input {
  border-color: #c0392b;
}

.auth-field-hint {
  margin: -0.35rem 0 0.75rem;
  font-size: 13px;
  text-align: left;
  font-family: var(--font-current);
}

.auth-field-hint--error {
  color: #c0392b;
}

.auth-reset-link {
  color: #8b6914;
  text-decoration: underline;
}

.auth-field-hint[hidden] {
  display: none;
}

.auth-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #333;
}

.auth-error {
  color: #c0392b;
  font-size: 12px;
  min-height: 0;
  margin: 0 0 0.5rem;
}

.auth-modal-panel .auth-btn {
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: var(--font-current);
  font-size: 15px;
  padding: 11px 16px;
  cursor: pointer;
  width: 100%;
}

.auth-modal-panel .auth-btn-secondary {
  margin-top: 4px;
  background: #e8e0d5;
  color: var(--text-primary);
  border-color: #e8e0d5;
}

.auth-modal-panel .auth-btn-primary {
  background: var(--header-bg);
  color: var(--header-text);
  border-color: var(--header-bg);
  margin-top: 8px;
}

.auth-switch-link {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 13px;
  color: #8b6914;
  text-decoration: underline;
  font-family: var(--font-current);
}

.auth-view[hidden] {
  display: none;
}

.header-actions .lang-capsule.segmented-control {
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: transparent;
  border-radius: var(--radius);
  padding: 2px;
  overflow: hidden;
  height: 30px;
  /* border-box: 2×36 buttons + 4 padding + 2 border = 78 (80 left a 2px right gap) */
  width: 78px;
  box-sizing: border-box;
  align-items: center;
  flex-shrink: 0;
  /* Lock metrics so html:lang font swap doesn't nudge 中/EN */
  font-family: var(--font-zh);
}

.header-actions .lang-capsule .lang-btn {
  color: #fff;
  padding: 0;
  font-size: 12px;
  flex: 0 0 36px;
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  background: transparent;
  font-weight: 500; /* same weight active/inactive — bold was shifting width + baseline */
  font-family: inherit;
  border-radius: calc(var(--radius) - 2px);
  border: none !important;
}

.header-actions .lang-capsule.segmented-control > button {
  border-right: none !important;
}

.header-actions .lang-capsule.segmented-control > button:first-child,
.header-actions .lang-capsule.segmented-control > button:last-child {
  border-radius: calc(var(--radius) - 2px);
}

.header-actions .lang-capsule .lang-btn.active {
  background: transparent;
  color: var(--header-bg);
  font-weight: 500;
}

.header-actions .lang-capsule .segmented-slider {
  background: #fff;
  z-index: 1;
  /* Equal button widths — only slide horizontally */
  transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-actions .lang-capsule.segmented-control > .lang-btn {
  position: relative;
  z-index: 2;
}

.segmented-control {
  display: inline-flex;
  position: relative;
  border: 1px solid rgba(212, 196, 168, 0.85);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.55);
}

.segmented-slider {
  position: absolute;
  top: 2px;
  left: 0;
  z-index: 0;
  border-radius: calc(var(--radius) - 2px);
  pointer-events: none;
  box-sizing: border-box;
  transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1), width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: left, width;
}

.segmented-control > button {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  border-radius: 0;
  border-right: 1px solid rgba(212, 196, 168, 0.65);
  transition: color 0.2s;
}

.segmented-control > button:last-child {
  border-right: none;
}

.segmented-control > button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.segmented-control > button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.lang-toggle.lang-toggle {
  border-color: rgba(212, 175, 55, 0.35);
  background: rgba(255, 255, 255, 0.08);
}

.lang-toggle > .lang-btn {
  color: rgba(212, 175, 55, 0.55);
  font-size: 13px;
  padding: 4px 10px;
  font-weight: 500;
}

.lang-toggle > .lang-btn.active {
  color: var(--header-text);
  font-weight: 500;
  background: transparent;
}

.lang-toggle .segmented-slider {
  background: rgba(255, 255, 255, 0.14);
}

.lang-btn {
  border: none;
  background: transparent;
  color: rgba(212, 175, 55, 0.55);
  font-family: inherit;
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 999px;
}

.lang-btn.active {
  color: var(--header-text);
  font-weight: 500;
  background: transparent;
}

.sidebar-toggle {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  box-sizing: border-box;
}

.sidebar-toggle--left {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle svg,
.sidebar-toggle .trigram-icon {
  width: 24px;
  height: 24px;
  display: block;
}

/* ===== 对话记录 Sidebar ===== */
.chat-sidebar {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: #fafaf8;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  transition: width 0.25s ease;
}

.chat-sidebar.open {
  width: var(--sidebar-width);
}

.sidebar-panel {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  flex-shrink: 0;
}

.chat-sidebar-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-sidebar {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: #fafaf8;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  transition: width 0.25s ease;
}

.notes-sidebar.open {
  width: var(--sidebar-width);
}

.notes-sidebar-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-add-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% - 12px);
  margin: 8px 6px 4px;
  padding: 10px;
  border: 1px dashed rgba(0, 0, 0, 0.18);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.notes-add-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
}

.notes-list {
  flex: 1;
}

.notes-sidebar-toggle {
  position: static;
  transform: none;
}

.chat-sidebar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.chat-sidebar-close {
  display: none;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 4px;
}

.chat-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
}

.chat-list-item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
}

.chat-list-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.chat-list-item.active {
  background: rgba(212, 175, 55, 0.15);
}

.chat-list-item-body {
  flex: 1;
  min-width: 0;
}

.chat-list-item-query {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-list-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.chat-list-item-delete {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.chat-list-item-delete:hover {
  color: #c0392b;
}

.chat-list-empty {
  display: none;
  padding: 24px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.chat-list-empty.visible {
  display: block;
}

/* ============================================================
   MAIN CONTENT AREA — 占据 header 与 input 之间的剩余空间
   ============================================================ */
.main-content {
  position: relative;
  z-index: 10;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ============================================================
   VIEW: HOME — 横向时间轴
   ============================================================ */
.view-home {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: transparent;
  opacity: 1;
  transition: opacity 0.45s ease;
}

.view-home.collapsed {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: none;
}

/* 首页胶囊 Tab — 右侧对齐，样式与语言切换一致 */
.home-tabs-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0;
  /* Left padding reserves the absolutely positioned play toggle's lane so the
     flex items can never slide underneath it. */
  padding: 10px var(--home-toolbar-pad-right) 8px var(--timeline-play-lane);
  z-index: 30;
  background: transparent;
  pointer-events: none;
}

/* Collapses to 0 before anything overlaps — this is what sets the page min width. */
.home-toolbar-spacer {
  flex: 0 1 var(--home-toolbar-gap);
  min-width: 0;
  align-self: stretch;
  pointer-events: none;
}

/* Play/pause — same row as search; left: 8px inside content so chats sidebar pushes it out */
.timeline-play-toggle {
  position: absolute;
  left: 8px;
  top: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  pointer-events: auto;
  box-sizing: border-box;
  z-index: 31;
}

.timeline-play-toggle:hover {
  background: rgba(61, 43, 31, 0.06);
  color: var(--text-primary);
}

.timeline-play-toggle[hidden] {
  display: none;
}

.timeline-play-toggle .timeline-play-icon {
  display: block;
  flex-shrink: 0;
}

.timeline-play-toggle .timeline-play-icon[hidden] {
  display: none;
}

.timeline-play-toggle .timeline-play-icon--play {
  width: 20px;
  height: 20px;
}

.home-search-wrap {
  position: relative;
  width: var(--home-search-width);
  flex-shrink: 0;
  pointer-events: auto;
}

.home-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9a8f82;
  pointer-events: none;
  z-index: 1;
}

.home-search-input {
  width: 100%;
  height: 36px;
  flex-shrink: 0;
  padding: 0 36px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  background: rgba(255, 255, 255,0.96);
  outline: none;
  pointer-events: auto;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.home-search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--header-bg);
  cursor: pointer;
  z-index: 1;
}

.home-search-clear[hidden] {
  display: none;
}

.home-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  display: none;
}

.home-search-input::-webkit-search-decoration {
  -webkit-appearance: none;
}

.home-search-input:focus {
  border: none;
  outline: none;
}

.home-search-input::placeholder {
  color: #9a8f82;
}

.home-tabs-wrap .home-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, var(--home-tab-width));
  align-items: stretch;
  position: relative;
  height: 36px;
  box-sizing: border-box;
  pointer-events: auto;
  border: none;
  border-radius: var(--radius);
  padding: 2px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: none;
  overflow: hidden;
}

.home-tabs > .home-tab {
  color: var(--text-secondary);
  font-size: 12px;
  height: 100%;
  min-height: 0;
  line-height: 1;
  width: var(--home-tab-width);
  min-width: var(--home-tab-width);
  max-width: var(--home-tab-width);
  padding: 0 6px;
  border: none;
  border-right: none;
  border-radius: 0;
  background: transparent;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
}

.home-tabs > .home-tab.active {
  background: transparent;
  color: var(--color-avatar-bg);
  font-weight: 600;
}

.home-tabs .segmented-slider-hover {
  position: absolute;
  top: 2px;
  left: 0;
  z-index: 1;
  border-radius: calc(var(--radius) - 2px);
  background: var(--color-avatar-bg);
  pointer-events: none;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.home-tabs .segmented-slider {
  background: var(--header-bg);
  z-index: 2;
  border-radius: calc(var(--radius) - 2px);
}

.home-tabs.segmented-control > button {
  border-right: none !important;
}

.home-panels-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  height: 100%;
  background: transparent;
}

.home-panel-sage,
.home-panel-book,
.home-panel-lineage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: transparent;
}

.home-panel-sage[hidden],
.home-panel-book[hidden],
.home-panel-lineage[hidden] {
  display: none !important;
}

.home-panel-book,
.home-panel-lineage {
  padding: 52px 16px 10px;
}

.timeline-viewport {
  flex: 1;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
  transition: opacity 0.6s ease;
}

.timeline-viewport.timeline-round-fade-out {
  opacity: 0;
}

.timeline-viewport.timeline-round-fade-in {
  opacity: 1;
}

.timeline-viewport.is-scroll-paused .timeline-scroll {
  cursor: default;
}

.timeline-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: scroll;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  background: transparent;
}

.timeline-loop {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 100%;
}

.timeline-loop-gap {
  flex-shrink: 0;
  align-self: stretch;
}

.timeline-track-clone {
  flex-shrink: 0;
}

.timeline-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
  background: transparent;
}

.timeline-scroll::-webkit-scrollbar-track,
.timeline-scroll::-webkit-scrollbar-corner {
  background: transparent;
}

.timeline-scroll::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
}

.timeline-viewport:hover .timeline-scroll,
.timeline-scroll:hover {
  scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
}

.timeline-viewport:hover .timeline-scroll::-webkit-scrollbar-thumb,
.timeline-scroll:hover::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
}

.timeline-loop {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 100%;
  width: max-content;
}

.timeline-loop-gap {
  flex-shrink: 0;
  align-self: stretch;
}

.timeline-track {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 0 var(--timeline-gutter, 24px) 10px;
  flex-shrink: 0;
}

.timeline-rails {
  flex-shrink: 0;
  width: 100%;
  margin-top: -5px;
  position: relative;
  z-index: 1;
}

/* 名医层（时间轴上方） */
.sages-layer {
  position: relative;
  flex: 1;
  min-height: 360px;
  margin-bottom: -5px;
  z-index: 2;
}

.dynasty-lineage-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.dynasty-lineage-svg[hidden] {
  display: none;
}

.dynasty-lineage-svg .dynasty-lineage-hit {
  pointer-events: stroke;
  cursor: pointer;
}

.dynasty-lineage-svg .dynasty-lineage-path {
  pointer-events: none;
  stroke: var(--dynasty-lineage-curve, #A9ABAC);
  stroke-opacity: var(--dynasty-lineage-curve-idle-opacity, 0.4);
  transition: stroke-opacity 0.18s ease, stroke-width 0.18s ease;
}

.dynasty-lineage-svg .dynasty-lineage-edge.is-hover .dynasty-lineage-path,
.dynasty-lineage-svg .dynasty-lineage-edge.is-active .dynasty-lineage-path {
  stroke-opacity: var(--dynasty-lineage-curve-hover-opacity, 0.9);
}

.sage-nodes-h {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.h-sage-node {
  position: absolute;
  bottom: 5px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--sage-slot-width, 140px);
  z-index: 3;
  /* Node shell does not block curve hits in the stem band */
  pointer-events: none;
}

.h-sage-node:hover {
  z-index: 5;
}

.h-sage-node--highlight {
  z-index: 5;
}

.h-sage-node--highlight .h-sage-card {
  animation: none;
  box-shadow: none;
  transform: none;
}

.h-sage-node--highlight .h-sage-avatar {
  border-color: #e8b84a;
  box-shadow:
    0 0 0 4px var(--bg-parchment),
    0 0 10px 3px rgba(255, 210, 90, 0.65),
    0 0 22px 8px rgba(255, 185, 55, 0.4),
    0 0 36px 14px rgba(255, 160, 40, 0.18);
  filter: brightness(1.06);
}

.h-sage-node--dim .h-sage-card {
  opacity: 0.38;
  transition: opacity 0.35s ease;
}

.h-sage-node--dim.h-sage-node--highlight .h-sage-card {
  opacity: 1;
}

.h-sage-stem {
  width: 1.5px;
  flex-shrink: 0;
  z-index: 3;
  align-self: center;
  margin-bottom: 8px;
  position: relative;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  background: var(--element-none);
}

.h-sage-stem[data-element="earth"] { background: var(--element-earth); }
.h-sage-stem[data-element="wood"] { background: var(--element-wood); }
.h-sage-stem[data-element="metal"] { background: var(--element-metal); }
.h-sage-stem[data-element="fire"] { background: var(--element-fire); }
.h-sage-stem[data-element="water"] { background: var(--element-water); }
.h-sage-stem[data-element="none"] { background: var(--element-none); }

.h-sage-node:hover .h-sage-stem {
  opacity: 0.3;
}

/* hide joint 
.h-sage-joint {
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-timeline-joint);
  z-index: 4;
}
--hide joint*/

.dynasty-color {
  height: 5px;
  border-radius: var(--radius);
  opacity: 0.88;
  position: relative;
  z-index: 1;
}

.dynasty-label {
  margin-top: 5px;
  text-align: center;
  padding: 0 4px;
  line-height: 1.3;
}

.h-sage-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 2;
  position: relative;
  padding-bottom: 6px;
  width: 100%;
  max-width: var(--sage-slot-width, 140px);
  pointer-events: auto;
}

.h-sage-card:hover {
  transform: translateY(-2px);
}

.h-sage-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--color-avatar-border);
  object-fit: cover;
  background: var(--color-avatar-bg);
  box-shadow: 0 0 0 4px var(--bg-parchment);
  flex-shrink: 0;
  transition: box-shadow 0.35s ease, border-color 0.35s ease, filter 0.35s ease;
}

.h-sage-card:hover .h-sage-avatar {
  border-color: var(--color-avatar-border-hover);
  box-shadow:
    0 0 0 4px var(--bg-parchment),
    0 0 10px 3px rgba(255, 210, 90, 0.65),
    0 0 22px 8px rgba(255, 185, 55, 0.4),
    0 0 36px 14px rgba(255, 160, 40, 0.18);
  filter: brightness(1.06);
}

.h-sage-text {
  position: relative;
  z-index: 2;
  width: 100%;
  text-align: center;
  margin-top: 4px;
}

.h-sage-name-row {
  line-height: 1.35;
  margin-bottom: 3px;
}

.h-sage-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.h-sage-lifespan {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  line-height: 1.35;
}

.h-sage-bio {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.h-sage-bio .h-sage-tag {
  color: var(--accent-orange);
  font-weight: 600;
}

.h-sage-works {
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}

.work-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.work-title {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
}


/* 朝代色带 + 名称标注（时间轴下方，替代横向轴线） */
.dynasty-strip {
  display: flex;
  flex-shrink: 0;
  margin-top: 0;
  align-items: flex-start;
}

.dynasty-segment {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.dynasty-color {
  height: 5px;
  border-radius: var(--radius);
  opacity: 0.88;
  background: var(--element-none);
}

/* Five-element dynasty bars — colors from tokens.css */
.dynasty-color[data-element="earth"] { background: var(--element-earth); }
.dynasty-color[data-element="wood"] { background: var(--element-wood); }
.dynasty-color[data-element="metal"] { background: var(--element-metal); }
.dynasty-color[data-element="fire"] { background: var(--element-fire); }
.dynasty-color[data-element="water"] { background: var(--element-water); }
.dynasty-color[data-element="none"] { background: var(--element-none); }

.dynasty-label {
  margin-top: 5px;
  text-align: center;
  padding: 0 4px;
  line-height: 1.3;
}

.dynasty-label-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
}

.dynasty-label-range {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.35;
  word-break: break-word;
  white-space: normal;
}

/* Book View 表格 */
.book-table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.85);
}

.col-category-th {
  position: relative;
}

.th-category-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.th-category-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.88;
}

.th-category-filter-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  opacity: 1;
}

.th-category-filter-btn.has-active-filter {
  color: #ffc980;
  opacity: 1;
}

.col-category-th .book-category-dropdown {
  left: 0;
  right: auto;
  min-width: 100%;
  width: max-content;
  max-width: min(360px, 90vw);
}

.book-category-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e0d5c5;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  z-index: 60;
  padding: 8px 0;
  color: var(--text-primary);
}

.book-category-dropdown.open {
  display: block;
}

.category-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}

.category-filter-option:hover {
  background: #f5f5f0;
}

.book-sort-select {
  flex-shrink: 0;
  padding: 8px 12px;
  border: 1px solid #e0d5c5;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.book-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header-bg);
  color: var(--color-avatar-bg);
}

.book-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.book-table td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  vertical-align: top;
  line-height: 1.5;
  color: var(--text-primary);
}

.book-table tbody tr:hover {
  background: rgba(212, 175, 55, 0.08);
}

.book-table .col-seq {
  width: 48px;
  text-align: center;
  color: var(--text-secondary);
}


.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sortable-th .sort-indicator {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  vertical-align: middle;
}

.sort-icon {
  font-size: 12px;
  opacity: 0.45;
  line-height: 1;
}

.sort-icon.active {
  opacity: 1;
  font-weight: 700;
}

.sortable-th:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sort-indicator {
  margin-left: 4px;
  font-size: 12px;
  opacity: 0.85;
}

.book-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.book-link:hover {
  text-decoration: underline;
}

.book-table .col-title-h,
.book-table .col-title {
  white-space: nowrap;
  width: 1%;
}

.book-table .col-edition {
  min-width: 120px;
  max-width: 200px;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.45;
}

.book-table .col-author-h,
.book-table .col-author {
  white-space: nowrap;
  width: 1%;
}

.book-table tbody tr.book-table-row-pending {
  background: var(--color-divider-line);
}

.book-table tbody tr.book-table-row-pending:hover {
  background: color-mix(in srgb, var(--color-divider-line) 85%, rgba(212, 175, 55, 0.12));
}

.book-table .col-desc {
  min-width: 0;
  max-width: 360px;
  width: 28%;
  font-size: 12px;
}

.book-table .col-reference {
  min-width: 160px;
  font-size: 12px;
}

/* Hidden: book table "show in search" column (feature paused)
.book-table .col-search-vis-h,
.book-table .col-search-vis {
  text-align: center;
  white-space: nowrap;
  min-width: 7em;
}

.book-table .book-search-vis-cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--header-text, #5c4033);
}
*/

.book-reference-link {
  display: inline-block;
  margin: 0 8px 4px 0;
  color: inherit;
}


@media (max-width: 640px) {
  :root {
    --page-gutter: 16px;
  }

  /* Timeline sage avatars stay 52px — do not shrink with viewport. */
}

/* ============================================================
   VIEW: COLLECTIVE (群贤毕至 mode)
   ============================================================ */
.view-collective {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease 0.3s, transform 0.5s ease 0.3s;
}

.view-collective.active {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

.view-close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 40;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.view-close-btn:hover {
  background: rgba(61, 43, 31, 0.08);
  color: var(--text-primary);
}

.sage-bar {
  display: none !important;
}

.sage-bar[hidden] {
  display: none !important;
}

.sage-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 56px;
  cursor: pointer;
  transition: opacity 0.3s;
  flex-shrink: 0;
}

.sage-bar-item img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid transparent;
  object-fit: cover;
  background: #e8dcc8;
}

.sage-bar-item.active img {
  border-color: var(--header-text);
}

.sage-bar-item.inactive {
  opacity: var(--sage-inactive);
  filter: grayscale(80%);
}

.sage-bar-item span {
  font-size: 12px;
  color: var(--header-text);
  white-space: nowrap;
}

.collective-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 48px 32px 16px;
}

.chat-turn {
  margin-bottom: 28px;
}

.chat-turn:last-child {
  margin-bottom: 0;
}

.chat-turn:not(:last-child) {
  padding-bottom: 8px;
}

/* Only newly loaded turns (not history re-render) */
.chat-turn.chat-turn-enter {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.chat-turn.chat-turn-enter.is-in {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .chat-turn.chat-turn-enter {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

.user-query-bubble {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin-bottom: 16px;
  width: 100%;
}

.user-query-bubble .bubble {
  background: var(--user-bubble);
  padding: 12px 18px;
  border-radius: var(--radius);
  max-width: 70%;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

.user-query-scope {
  max-width: 70%;
  padding: 0 4px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.ai-summary {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
  margin-bottom: 24px;
  padding: 0 8px;
  max-width: 100%;
  word-break: break-word;
}

.ai-summary-p {
  margin: 0 0 0.4lh;
}

.ai-summary-p:last-child {
  margin-bottom: 0;
}

.ai-summary strong {
  font-weight: 600;
}

.ai-disclaimer {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  color: var(--text-secondary, #6b6560);
  font-size: 0.92em;
  line-height: 1.45;
}

.ai-disclaimer--block {
  display: flex;
  align-items: center;
  gap: 0.35em;
  margin-top: 0.75em;
  text-align: left;
  justify-content: flex-start;
}

.ai-disclaimer-icon {
  flex: 0 0 auto;
  width: 0.95em;
  height: 0.95em;
  min-width: 12px;
  min-height: 12px;
  color: currentColor;
  opacity: 0.9;
  vertical-align: -0.1em;
}

.ai-disclaimer-text {
  flex: 1 1 auto;
}

.chat-corpus-section {
  margin-top: 1lh;
  margin-bottom: 8px;
}

.chat-corpus-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 8px;
  margin: 4px 0 10px;
}

.chat-corpus-section .matched-concepts {
  padding: 0 8px;
  margin-bottom: 10px;
}

.chat-corpus-section--empty .search-no-hit {
  margin: 0 8px 8px;
}

.chat-corpus-section--empty .search-empty-actions {
  padding: 0 8px;
}

.expert-corpus-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px 8px;
}

.result-cards-scroll {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 8px 4px 20px;
  scroll-snap-type: x mandatory;
}

.result-card {
  flex: 0 0 280px;
  align-self: flex-start;
  height: auto;
  max-height: 700px;
  scroll-snap-align: start;
  background: var(--search-card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--search-card-shadow);
  display: flex;
  flex-direction: column;
}

.result-card-header {
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  isolation: isolate;
  background: var(--element-earth-dark);
  color: var(--search-card-header-text);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.result-card-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  opacity: 0.2;
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.result-card:not(.result-card--formula) .result-card-header::before {
  background-image: url("/static/images/bg/book-pattern.png");
  background-size: 280px auto;   /* 越小纹样越密/越小 */
}

.result-card--formula .result-card-header::before,
.expert-result-card--formula .result-card-header::before {
  background-image: url("/static/images/bg/herb-pattern.png");
}

.result-card-header > * {
  position: relative;
  z-index: 1;
}

.result-card-header img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--search-card-avatar-bg);
  border: 1px solid var(--search-formula-avatar-border);
}

.result-card-header .name {
  font-size: 15px;
  font-weight: 700;
  color: inherit;
}

.result-card-book {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 14px 6px;
  color: var(--search-card-book);
  line-height: 1.4;
  border-bottom: 1px solid var(--search-card-book-border);
  background: var(--search-card-bg);
}

.result-card-book .book-ref-link,
.result-card-book .book-title-link,
.expert-result-card .book-ref-link,
.expert-result-card .book-title-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.result-card-book .book-ref-link:hover,
.result-card-book .book-title-link:hover,
.expert-result-card .book-ref-link:hover,
.expert-result-card .book-title-link:hover {
  text-decoration: underline;
}

.result-card-excerpt {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--color-ink);
}

/* —— Formula / bencao result card (wood palette; brown cards remain for classic prose) —— */
.result-card--formula {
  flex: 0 0 320px;
  align-self: flex-start;
  height: auto;
  background: var(--search-formula-body-bg);
  box-shadow: var(--search-formula-shadow);
}

.result-card--formula .result-card-header img,
.expert-result-card--formula .result-card-header img {
  background: var(--search-formula-avatar-bg);
  border: 1.5px solid var(--search-formula-avatar-border);
  box-sizing: border-box;
}

.result-card--formula .result-card-header,
.expert-result-card--formula .result-card-header {
  flex-shrink: 0;
  background: var(--search-formula-header);
  color: var(--search-formula-header-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.expert-result-card--formula .result-card-header {
  border-radius: var(--radius) var(--radius) 0 0;
}

.result-card--formula .result-card-book {
  flex-shrink: 0;
  color: var(--search-formula-book);
  border-bottom: 1px solid var(--color-divider-line);
  background: var(--search-formula-body-bg);
}

.result-card--formula .result-card-book .book-title-link:hover {
  text-decoration: underline;
}

.formula-card-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--search-formula-text);
  background: var(--search-formula-body-bg);
}

.formula-card-name {
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--search-formula-title);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

/* hide herb icon
.formula-card-herb-icon {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  display: inline-flex;
  color: var(--search-formula-title);
  transform: translateY(0.02em);
}

.formula-card-herb-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
/* hide herb icon */

.formula-card-section {
  margin: 0;
}

.formula-card-label {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--search-formula-label);
  padding: 2px 2px;
  margin-bottom: 5px;
}

.formula-card-ingredients {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.formula-card-ingredients li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--search-formula-ingredient-row-bg);
}

.formula-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--formula-role-text);
  background: var(--formula-role-default);
  border-radius: 3px;
  text-align: center;
  padding: 1px 0;
  letter-spacing: 0.08em;
}

.formula-role[data-role="君"] { background: var(--formula-role-jun); }
.formula-role[data-role="臣"] { background: var(--formula-role-chen); }
.formula-role[data-role="佐"] { background: var(--formula-role-zuo); }
.formula-role[data-role="使"] { background: var(--formula-role-shi); }

.formula-herb {
  font-weight: 600;
  color: var(--search-formula-herb);
}

.formula-herb-note {
  font-weight: 400;
  color: var(--search-formula-note);
  font-size: 12px;
}

.formula-dose {
  color: var(--search-formula-note);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.formula-card-prep,
.formula-card-indications {
  margin: 0;
  color: var(--search-formula-text);
}

.formula-card-indications-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.formula-card-indications-list li {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--search-formula-tag-bg);
  color: white;
}

.formula-card-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--search-formula-note);
  border-top: 1px solid var(--color-divider-line);
  padding-top: 8px;
}

.formula-card-quote {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--search-formula-text);
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
}

.expert-result-card--formula {
  background: var(--search-formula-body-bg);
  border: 1px solid var(--search-formula-border);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 700px;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.expert-result-card--formula .book-ref {
  flex-shrink: 0;
  color: var(--search-formula-book);
  border-bottom: 1px solid var(--color-divider-line);
  background: var(--search-formula-body-bg);
  padding: 10px 14px 6px;
  margin-bottom: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.input-chat-thread .result-card--formula {
  flex: 0 0 280px;
}

/* ============================================================
   VIEW: EXPERT (专家号 mode)
   ============================================================ */
.view-expert {
  position: absolute;
  inset: 0;
  display: none;
  opacity: 0;
}

.view-expert.active {
  display: flex;
  opacity: 1;
}

/* ============================================================
   VIEW: NOTES
   ============================================================ */
.view-notes {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  background: transparent;
}

.view-notes.active {
  display: flex;
  opacity: 1;
}

/* Notes page has no chat composer */
#app.notes-view-active .input-bar {
  display: none !important;
}

.notes-editor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 28px 28px;
  overflow: auto;
  position: relative;
}

.notes-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  /* Bleed past the editor padding so the opaque bar spans the full width and
     hides content scrolling underneath it. */
  margin: 0 -28px 12px;
  padding: 10px 16px 10px 20px;
  background: var(--bg-parchment);
  box-shadow: none;
  transition: box-shadow 0.18s ease;
}

/* Only once content has scrolled under it does the bar read as a separate layer. */
.notes-toolbar.is-stuck {
  box-shadow: 0 6px 8px -6px rgba(44, 36, 22, 0.22);
}

.notes-toolbar-close {
  position: static;
  margin-left: auto;
  flex-shrink: 0;
}

/* The floating close only serves the empty state; the toolbar owns it otherwise. */
.view-notes:has(.notes-editor:not([hidden])) > .view-close-btn {
  display: none;
}

.notes-tool-btn {
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
}

.notes-tool-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.notes-delete-btn {
  color: #8a3b2c;
}

.notes-title-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: #000;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 12px;
  font-family: inherit;
  padding: 0;
}

.notes-title-input::placeholder {
  color: rgba(0, 0, 0, 0.28);
  font-weight: 700;
}

.notes-body-input {
  flex: 1;
  min-height: 200px;
  outline: none;
  color: #000;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
}

.notes-body-input:empty::before {
  content: attr(data-placeholder);
  color: rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.notes-body-input a.tsg-source-link {
  color: #8b6914;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.notes-body-input strong,
.notes-body-input b {
  font-weight: 700;
}

.notes-empty-hint {
  margin: auto;
  padding: 48px 24px 24px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.notes-empty-hint[hidden],
.notes-editor[hidden] {
  display: none !important;
}

/* ============================================================
   VIEW: LINEAGE (医脉)
   ============================================================ */
.lineage-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.lineage-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 0 4px 10px;
}

.lineage-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lineage-title-block {
  flex: 1;
  min-width: 0;
}

.lineage-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.lineage-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.lineage-subtitle b {
  color: var;
  font-weight: 600;
}

.lineage-legend-dropdown {
  position: relative;
  flex-shrink: 0;
}

.lineage-legend-toggle,
.lineage-fullscreen-btn {
  flex-shrink: 0;
  border: none;
  background: var(--color-avatar-bg);
  color: #2b2420;
  font-size: 12px;
  line-height: 1.2;
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.lineage-legend-toggle:hover,
.lineage-legend-toggle--open {
  background: var(--color-avatar-bg-hover);
}

.lineage-fullscreen-btn:hover {
  background: var(--color-avatar-bg-hover);
}

.lineage-legend-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 120;
  width: min(360px, 86vw);
  max-height: min(420px, 58vh);
  overflow-y: auto;
  padding: 10px 12px 12px;
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: 0 8px 24px rgba(43, 36, 32, 0.14);
}

.lineage-legend-menu[hidden] {
  display: none;
}

.lineage-legend-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-divider-line);
}

.lineage-legend-actions button {
  font-family: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 10px;
  border: none;
  background: var(--color-avatar-bg);
  color: #2b2420;
  cursor: pointer;
}

.lineage-legend-actions button:hover {
  background: var(--color-avatar-bg-hover);
}

.lineage-legend-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lineage-legend-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 4px 5px;
  border-radius: 6px;
  margin-bottom: 0;
}

.lineage-legend-item:hover {
  background: rgba(184, 146, 74, 0.12);
}

.lineage-legend-check--off .lineage-swatch,
.lineage-legend-check input[type="checkbox"]:not(:checked) ~ .lineage-swatch {
  opacity: 0.35;
}

.lineage-legend-check--off .lineage-legend-text b,
.lineage-legend-check--off .lineage-legend-text i,
.lineage-legend-check input[type="checkbox"]:not(:checked) ~ .lineage-legend-text {
  opacity: 0.4;
}

.lineage-legend-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  max-height: 108px;
  overflow-y: auto;
  padding: 10px 4px 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(61, 43, 31, 0.12);
}

.lineage-legend-bar--collapsed {
  display: none;
}

.lineage-legend-bar .lineage-legend-item {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 180px;
  max-width: 260px;
}

.lineage-swatch {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1.5px solid;
  margin-top: 2px;
}

.lineage-legend-text {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
  gap: 1px;
}

.lineage-legend-text b {
  font-size: 12px;
  color: var(--text-primary);
}

.lineage-legend-text i {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: normal;
}

.lineage-legend-check {
  cursor: pointer;
  user-select: none;
}

.lineage-legend-check input[type="checkbox"] {
  width: 12px;
  height: 12px;
  margin: 2px 0 0;
  cursor: pointer;
}

.lineage-legend-check input[type="checkbox"]:not(:checked) ~ .lineage-swatch {
  opacity: 0.35;
}

.lineage-legend-check input[type="checkbox"]:not(:checked) ~ .lineage-legend-text {
  opacity: 0.45;
}

.lineage-legend-check input[type="checkbox"]:not(:checked) ~ .lineage-legend-text b {
  text-decoration: line-through;
}

.lineage-viewer {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  cursor: grab;
  border-radius: 10px;
  background:#ffffff96;
}

.lineage-viewer--dragging {
  cursor: grabbing;
}

.lineage-svg {
  display: block;
  /* Pixel-sized by JS on fit/zoom only — not 100%, so window resize won't re-scale. */
  width: auto;
  height: auto;
  max-width: none;
  flex-shrink: 0;
  user-select: none;
}

.lineage-link {
  fill: none;
  stroke-linecap: round;
  pointer-events: none;
}

.lineage-link--dashed {
  pointer-events: none;
}

.lineage-link-arrow {
  pointer-events: none;
}

.lineage-link-hit {
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

.lineage-edge--hover .lineage-link {
  stroke-width: 2.4;
}

.lineage-edge--hover .lineage-link-arrow {
  stroke-width: 2;
}

.lineage-layer--links-hover {
  pointer-events: none;
}

.lineage-layer--links-hover .lineage-link-hit {
  pointer-events: stroke;
}

.lineage-root-lines {
  pointer-events: none;
}

.lineage-node-svg {
  pointer-events: auto;
  transition: opacity 0.35s ease;
}

.lineage-node-svg--dim {
  opacity: 0.32;
}

.lineage-node-svg--highlight {
  opacity: 1;
  filter:
    drop-shadow(0 0 3px rgba(255, 210, 90, 0.95))
    drop-shadow(0 0 10px rgba(255, 185, 55, 0.7))
    drop-shadow(0 0 18px rgba(255, 160, 40, 0.35));
}

.lineage-node-svg--highlight .lineage-node-card {
  stroke: var(--color-primary) !important;
  stroke-width: 1.5px !important;
}

.lineage-node-avatar {
  pointer-events: none;
  clip-path: circle(50%);
}

.lineage-floatlabel {
  pointer-events: none;
}

.lineage-hint {
  position: absolute;
  left: 22px;
  bottom: 22px;
  font-size: 12px;
  color: #5c5347;
  background: var(--color-avatar-bg);
  padding: 6px 12px;
  border-radius: 10px;
  border: none;
  pointer-events: none;
  z-index: 5;
}

.lineage-controls {
  position: absolute;
  right: 22px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}

.lineage-controls button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: none;
  background: var(--color-avatar-bg);
  color: #2b2420;
  font-size: 18px;
  cursor: pointer;
}

.lineage-controls button:hover {
  background: var(--color-avatar-bg-hover);
}

.lineage-fit-btn {
  font-size: 12px !important;
}

/* Dim page behind expanded chat input; header stays above (z-index 300). */
.input-backdrop {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 295;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.input-backdrop[hidden] {
  display: none;
}

body.lineage-fullscreen-active .header,
body.lineage-fullscreen-active .trial-banner,
body.lineage-fullscreen-active .input-bar,
body.lineage-fullscreen-active .input-backdrop,
body.lineage-fullscreen-active .chat-sidebar,
body.lineage-fullscreen-active .notes-sidebar,
body.lineage-fullscreen-active .sidebar-toggle,
body.lineage-fullscreen-active .notes-sidebar-toggle {
  display: none !important;
}

body.lineage-fullscreen-active .app-shell {
  display: block;
}

body.lineage-fullscreen-active #app {
  margin-left: 0 !important;
}

body.lineage-fullscreen-active .view-home .home-tabs-wrap {
  display: none;
}

body.lineage-fullscreen-active .home-panel-sage,
body.lineage-fullscreen-active .home-panel-book {
  display: none !important;
}

body.lineage-fullscreen-active #panel-lineage {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  bottom: 0;
  z-index: 600;
  /* Same site floor as html/#app — fixed overlay previously ignored --content-min-width. */
  width: max(100vw, var(--content-min-width));
  min-width: var(--content-min-width);
  padding: 12px 16px 16px !important;
  background: rgba(244, 239, 226, 0.5);
  box-sizing: border-box;
}

body.lineage-fullscreen-active {
  overflow-x: auto;
}

body.lineage-fullscreen-active #panel-lineage .lineage-viewport {
  height: 100%;
}

body.lineage-fullscreen-active #panel-lineage .lineage-viewer {
  flex: 1;
  min-height: 0;
}

body.lineage-fullscreen-active .lineage-title-block,
body.lineage-fullscreen-active .lineage-hint {
  display: none !important;
}

body.lineage-fullscreen-active .lineage-header {
  justify-content: flex-end;
  padding-bottom: 8px;
}

.expert-layout {
  display: flex;
  height: 100%;
  width: 100%;
  min-height: 0;
}

.expert-sidebar {
  /* Content width 200–220 (excludes padding). Starts at 200; grows only as viewport > 900. */
  box-sizing: content-box;
  flex: 0 0 auto;
  width: min(220px, max(200px, calc(200px + (100vw - 900px) * 0.04)));
  min-width: 200px;
  max-width: 220px;
  padding: 16px 12px;
  overflow-y: auto;
  border-right: 1px solid rgba(0,0,0,0.06);
  position: relative;
}

.expert-back-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--header-text, #8b6914);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.expert-back-btn:hover {
  background: rgba(201, 169, 98, 0.18);
  color: var(--accent-orange, #c45c00);
}

.expert-back-btn:active {
  background: rgba(201, 169, 98, 0.28);
}

.expert-avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 10px auto 10px;
}

.expert-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 1.5px solid var(--color-avatar-border);
  object-fit: cover;
  display: block;
  margin: 0;
  background: #e8dcc8;
}

@keyframes expert-avatar-glow {
  0% {
    border-color: #e8b84a;
    box-shadow:
      0 0 0 4px var(--bg-parchment),
      0 0 6px 2px rgba(255, 210, 90, 0.35),
      0 0 12px 4px rgba(255, 185, 55, 0.2),
      0 0 18px 6px rgba(255, 160, 40, 0.1);
    filter: brightness(1.02);
  }
  36% {
    border-color: #e8b84a;
    box-shadow:
      0 0 0 8px var(--bg-parchment),
      0 0 20px 6px rgba(255, 210, 90, 0.65),
      0 0 44px 16px rgba(255, 185, 55, 0.4),
      0 0 72px 28px rgba(255, 160, 40, 0.18);
    filter: brightness(1.06);
  }
  100% {
    border-color: #c9a962;
    box-shadow: none;
    filter: none;
  }
}

.expert-avatar.expert-avatar--glow {
  animation: expert-avatar-glow 2s ease-out forwards;
}

.expert-xinghua {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 10px;
  padding: 5px 10px;
  border: none;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
}

.expert-xinghua:hover,
.expert-xinghua:active {
  background: transparent;
}

.expert-xinghua-icon {
  width: 26px;
  height: 26px;
  display: block;
  pointer-events: none;
  transform-origin: center center;
  transition: transform 0.15s ease;
}

.expert-xinghua:hover .expert-xinghua-icon {
  transform: scale(1.1);
}

.expert-xinghua:active .expert-xinghua-icon {
  transform: scale(0.96);
}

.expert-xinghua-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--accent-orange, #c45c00);
  min-width: 0.6em;
  pointer-events: none;
}

.expert-xinghua-count.is-empty {
  display: none;
}

.expert-name {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.expert-lifespan {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.expert-tag {
  text-align: center;
  font-size: 12px;
  color: var(--accent-orange);
  font-weight: 600;
  margin-bottom: 8px;
}

.expert-contribution-label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
  margin-top: 4px;
}

.expert-contribution {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.expert-works-label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.expert-works-list {
  list-style: none;
  margin-bottom: 16px;
}

.expert-works-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
  cursor: default;
  line-height: 1.4;
  position: relative;
}

.expert-work-select {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.expert-work-select:hover,
.expert-works-list li.active .expert-work-select {
  color: var(--color-avatar-border);
  font-weight: 600;
}

.expert-work-title {
  min-width: 0;
  flex: 1 1 auto;
}

.expert-work-edition {
  position: relative;
  flex: 0 0 auto;
  margin-left: auto;
}

.expert-work-edition-btn {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
}

.expert-work-edition-btn:hover,
.expert-work-edition-btn:focus-visible,
.expert-work-edition-btn[aria-expanded="true"],
.expert-works-list li.active .expert-work-edition-btn,
.expert-works-list li.active .expert-work-edition-btn[aria-expanded="true"] {
  color: var(--text-secondary);
  font-weight: 400;
  outline: none;
}

.expert-work-edition-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 40;
  width: max-content;
  max-width: min(240px, 70vw);
  padding: 10px 28px 10px 10px;
  border-radius: 8px;
  background: #1b2430;
  color: #f5f7fa;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.expert-work-edition-popover[hidden] {
  display: none !important;
}

.expert-work-edition-arrow {
  position: absolute;
  right: 14px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #1b2430;
  transform: rotate(45deg);
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.06);
}

.expert-work-edition-close {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #c5ccd6;
  cursor: pointer;
}

.expert-work-edition-close:hover,
.expert-work-edition-close:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.expert-work-edition-body {
  display: block;
}

.book-covers {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.book-cover {
  width: 72px;
  height: 110px;
  background: linear-gradient(180deg, #1a3a5c 0%, #0d2240 100%);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 6px;
  cursor: pointer;
  position: relative;
  box-shadow: 2px 4px 8px rgba(0,0,0,0.2);
  overflow: hidden;
  box-sizing: border-box;
}

.book-cover-label {
  background: #fff;
  border-radius: 4px;
  padding: 4px 3px;
  width: fit-content;
  height: auto;
  max-height: 100%;
  overflow: hidden;
  display: block;
  box-sizing: border-box;
  flex-shrink: 0;
}

.book-cover-chars {
  writing-mode: vertical-rl;
  text-orientation: upright;
  display: block;
  width: 1em;
  height: auto;
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  box-sizing: border-box;
}

.book-cover-ellipsis {
  display: block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  color: #1a1a1a;
  text-align: center;
  letter-spacing: 0;
}

.book-cover-ellipsis[hidden] {
  display: none !important;
}

.book-cover.active {
  outline: 1.5px solid var(--color-avatar-border);
}

.expert-chapters {
  /* Content width 180–200 (excludes padding). Starts at 180; grows only as viewport > 900. */
  box-sizing: content-box;
  flex: 0 0 auto;
  width: min(200px, max(180px, calc(180px + (100vw - 900px) * 0.04)));
  min-width: 180px;
  max-width: 200px;
  padding: 12px 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255,255,255,0.5);
  border-right: 1px solid rgba(0,0,0,0.06);
}

.expert-toc-search-wrap {
  width: 100%;
  flex-shrink: 0;
  margin-bottom: 10px;
  pointer-events: auto;
}

.expert-toc-search-wrap .expert-toc-search-input,
.expert-toc-search-wrap .home-search-input {
  height: 32px;
  font-size: 12px;
  padding: 0 32px;
}

.expert-toc-search-wrap .home-search-icon {
  left: 10px;
  width: 14px;
  height: 14px;
}

.expert-toc-search-wrap .home-search-clear {
  right: 10px;
}

.expert-toc-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.expert-toc-search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expert-toc-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 252, 245, 0.95);
  padding: 8px 10px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.expert-toc-hit:hover,
.expert-toc-hit.is-active {
  background: rgba(201, 169, 98, 0.14);
  border-color: rgba(139, 105, 20, 0.28);
}

.expert-toc-hit-path {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #8b7355;
  line-height: 1.35;
  margin-bottom: 4px;
}

.expert-toc-hit-excerpt {
  display: block;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-primary, #3d2b1f);
}

.expert-toc-hit-excerpt mark,
.reading-text mark.reading-search-hit {
  background: rgba(255, 214, 102, 0.85);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

.reading-text mark.passage-quote-flash {
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
  background: rgba(255, 230, 80, 0.55);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  animation: passage-quote-flash 1s ease-in-out 3;
}

.reading-text .reading-passage {
  white-space: pre-wrap;
}

.reading-text .reading-passage + .reading-passage {
  margin-top: 1.15em;
}

@keyframes passage-quote-flash {
  0%,
  100% {
    background: rgba(255, 236, 120, 0.35);
  }
  50% {
    background: rgba(255, 214, 40, 0.95);
  }
}

.expert-toc-search-status {
  padding: 16px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary, #888);
}

.chapter-list {
  list-style: none;
}

.chapter-section {
  list-style: none;
  margin: 10px 0 4px;
  padding: 0;
}

.chapter-section:first-child {
  margin-top: 0;
}

.chapter-section-label {
  padding: 4px 10px 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #8b7355;
  text-transform: none;
  user-select: none;
  pointer-events: none;
}

.toc-parent-group {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-section-group {
  margin: 10px 0 4px;
}

.chapter-section-group:first-child {
  margin-top: 0;
}

.chapter-department-group {
  margin: 4px 0 2px;
}

.chapter-subgroup-group {
  margin: 2px 0 1px;
}

.toc-parent-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 4px 8px 4px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius);
  color: #8b7355;
}

.toc-parent-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.toc-parent-toggle .chapter-section-label,
.toc-parent-toggle .chapter-department-label,
.toc-parent-toggle .chapter-subgroup-label {
  pointer-events: none;
  padding: 0;
  flex: 1;
}

.toc-parent-toggle.chapter-department-toggle {
  padding-left: 12px;
  color: #a08b6e;
}

.toc-parent-toggle.chapter-subgroup-toggle {
  padding-left: 18px;
  font-weight: 600;
  color: #8f7a5c;
}

.toc-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  color: inherit;
  transition: transform 0.15s ease;
}

.toc-arrow::before {
  content: "▾";
}

.toc-parent-toggle.is-collapsed .toc-arrow {
  transform: rotate(-90deg);
}

.toc-children {
  list-style: none;
  margin: 0;
  padding: 0 0 0 4px;
}

.toc-parent-group.is-collapsed > .toc-children {
  display: none;
}

.toc-children > .chapter-item {
  padding-left: 18px;
}

.toc-children .toc-children > .chapter-item {
  padding-left: 28px;
}

.toc-children .toc-children .toc-children > .chapter-item {
  padding-left: 36px;
}

.chapter-department-label {
  padding: 2px 10px 2px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #a08b6e;
  user-select: none;
  pointer-events: none;
}

.chapter-subgroup-label {
  padding: 2px 10px 2px 22px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #8f7a5c;
  user-select: none;
  pointer-events: none;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  margin-bottom: 2px;
}

.chapter-item .chapter-title {
  flex: 1;
  min-width: 0;
}

.chapter-item span:first-child {
  flex: none;
  min-width: 0;
}

.chapter-item:hover {
  background: rgba(0,0,0,0.04);
}

.chapter-item.active {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.08);
  font-weight: 600;
}

.chapter-item .page-num {
  font-size: 12px;
  color: #aaa;
  flex-shrink: 0;
  min-width: 1.4em;
  text-align: left;
}


.expert-content {
  flex: 6 1 0;
  min-width: 0;
  /* Match input-bar-panel: fixed pad-x; top 10; bottom 0 (panel has its own top pad).
     scrollbar-gutter keeps width stable; right pad compensates so card aligns with input. */
  padding: 20px var(--input-panel-pad-x) 0;
  padding-right: calc(var(--input-panel-pad-x) - 2px);
  overflow-y: auto;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
}

#app:has(.input-bar-collapsed) .expert-content {
  padding-bottom: 20px;
}

.expert-reading-notice {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.expert-reading-notice .reading-notice {
  margin: 0;
}

.expert-reading-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 20px 16px;
  line-height: 2;
  font-size: 15px;
  flex: 1;
}

.expert-reading-card .chapter-label {
  font-size: inherit;
  font-weight: bolder;
  line-height: inherit;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
  word-break: break-word;
}

.reading-notice {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-left: 1.5px solid var(--color-avatar-border);
  background: #fff9eb;
  color: #5c4a32;
  font-size: 14px;
  line-height: 1.65;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.matched-concepts {
  font-size: 13px;
  color: #666;
  margin: 8px 0 12px;
  padding: 0 4px;
}

.matched-concepts-label {
  font-weight: 600;
  color: var(--element-earth-dark);
}

.matched-concepts--chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.matched-concepts-chip-row {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.matched-concept-chip {
  appearance: none;
  border: 1px solid var(--color-divider-line, rgba(0, 0, 0, 0.08));
  background: var(--color-surface, #fff);
  color: var(--color-ink, #3d3429);
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.matched-concept-chip:hover {
  border-color: var(--element-earth);
  color: var(--element-earth-dark);
}

.chat-clarification {
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: var(--color-avatar-bg, #f3efe6);
  border-radius: 8px;
}

.chat-clarification-prompt {
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-ink, #3d3429);
  margin-bottom: 10px;
}

.chat-clarification-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-clarification-chip {
  appearance: none;
  border: 1px solid var(--color-divider-line, rgba(0, 0, 0, 0.12));
  background: var(--color-surface, #fff);
  color: var(--color-ink, #3d3429);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.chat-clarification-chip:hover {
  border-color: var(--element-earth);
  color: var(--element-earth-dark);
}

.chat-lineage-snippet {
  /*margin: 8px 0 12px;*/
  padding: 0px 12px;
  border-left: 3px solid var(--element-earth, #8a6d3b);
  background: transparent;
  max-width: 100%;
}

.chat-lineage-snippet-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-ink, #3d3429);
}

.chat-lineage-routes {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}

.chat-lineage-route {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary, #6b5d4d);
  word-break: break-word;
}

.chat-lineage-snippet-list {
  margin: 0;
  padding-left: 1.1em;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary, #6b5d4d);
}

.chat-notice-block {
  padding: 0 4px;
  margin: 4px 0 10px;
}

.chat-notice-block .search-no-hit {
  margin: 0;
}

.search-no-hit {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 14px;
  color: var(--text-secondary, #6b5d4d);
  padding: 12px 16px;
  line-height: 1.6;
  background: var(--color-avatar-bg);
  border-radius: 8px;
  margin: 8px 0;
}

.search-empty-actions {
  margin: 4px 0 12px;
  padding: 0 4px;
}

.search-clear-scope-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--element-earth-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.search-clear-scope-btn:hover {
  opacity: 0.85;
}

.search-hints {
  list-style: none;
  margin: 8px 0 12px;
  padding: 0 4px 0 16px;
  font-size: 13px;
  color: var(--text-secondary, #6b5d4d);
  line-height: 1.55;
}

.search-hints-label {
  font-weight: 600;
  color: #8b4513;
  list-style: none;
  margin-left: -12px;
  margin-bottom: 4px;
}

.search-hints li:not(.search-hints-label) {
  margin: 4px 0;
}

.ctext-source,
.book-source {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: var(--text-secondary, #5c5347);
}

.book-source-label {
  font-weight: 500;
}

.book-source-link,
.ctext-source a {
  color: #8b4513;
  text-decoration: none;
  margin-left: 2px;
}

.book-source-link:hover,
.ctext-source a:hover {
  text-decoration: underline;
}

.expert-reading-card .reading-text {
  white-space: pre-line;
  /* Global language font; --font-zh preserves HanaMin fallbacks for rare CJK. */
  font-family: var(--font-current);
}

.expert-reading-card .reading-text.reading-empty {
  color: var(--text-muted, #8a8680);
  font-style: normal;
  white-space: normal;
}

.expert-search-results {
  display: none;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Horizontal inset comes from .expert-content */
  padding: 10px 0 0;
}

.expert-search-results.active {
  display: flex;
}

.expert-result-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  max-height: 700px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.expert-result-card .book-ref {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--card-header-bg);
}

.expert-result-card .excerpt {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.9;
  color: var(--text-secondary);
}

/* ============================================================
   FOOTER INPUT BAR — floating over all views; height drag-resizable
   Collapse: slot animates height; fixed 36px control lane at bottom;
   inner panel keeps intrinsic size (no text/icon squash).
   ============================================================ */
.input-bar {
  position: relative;
  z-index: 200;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.input-bar-slot {
  overflow: hidden;
  transition: height 0.25s ease;
}

.input-bar:not(.input-bar-collapsed) .input-bar-slot {
  overflow: visible;
}

.input-bar-panel {
  position: relative;
  width: 100%;
  padding: 10px var(--input-panel-pad-x) 14px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.input-turn-notice {
  align-self: stretch;
  margin: 0 0 6px;
  padding: 8px 14px;
  background: #f3f0ea;
  border: 1px solid #ddd2c2;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.input-turn-notice[hidden] {
  display: none;
}

.input-turn-notice.is-hard {
  background: #fcecea;
  border-color: #e5b4ad;
  color: #7a2e24;
}

body.is-resizing-input {
  cursor: ns-resize;
  user-select: none;
}

body.is-resizing-input iframe {
  pointer-events: none;
}

.input-bar-control-lane {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--input-control-lane-height);
  overflow: visible;
  pointer-events: none;
  z-index: 1;
  background: transparent;
}

.input-bar:not(.input-bar-collapsed) .input-bar-control-lane {
  height: 0;
  overflow: hidden;
}

.input-quota-notice {
  align-self: stretch;
  margin: 0 0 -1px;
  padding: 8px 14px;
  background: #fff8e6;
  border: 1px solid #e7d3a2;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: #7a4d00;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.input-quota-notice[hidden] {
  display: none;
}

.input-quota-notice:not([hidden]) + .input-composer {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.input-composer {
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--input-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
  overflow: visible;
}

.input-composer:focus-within {
  border-color: var(--header-text);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.12);
}

.input-composer textarea {
  width: 100%;
  flex: 0 0 auto;
  min-height: 44px;
  max-height: 120px;
  border: none;
  resize: none;
  padding: 10px 18px 8px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  background: transparent;
  outline: none;
  overflow-y: auto;
}

.input-composer textarea::placeholder {
  color: var(--input-placeholder);
}

.input-inline-turn {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-inline-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  align-self: flex-end;
  max-width: 70%;
  gap: 4px;
}

.input-inline-user-scope {
  padding: 0 4px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.input-inline-user {
  align-self: flex-end;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px 12px 4px 12px;
  background: var(--user-bubble);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.input-inline-assistant {
  align-self: flex-start;
  max-width: 100%;
  width: 100%;
  padding: 2px 2px 0;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.input-inline-assistant .ai-summary-p {
  margin: 0 0 1.5lh;
}

.input-inline-assistant .ai-summary-p:last-child {
  margin-bottom: 0;
}

.input-inline-assistant strong {
  font-weight: 600;
}

.input-inline-meta {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 12px;
}

.input-inline-cards {
  margin-top: 4px;
  padding-bottom: 6px;
}

.input-chat-thread .result-card {
  flex: 0 0 min(220px, 70vw);
  font-size: 12px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.07);
}

.input-chat-thread .result-card-header {
  padding: 8px 10px;
}

.input-chat-thread .result-card-header img,
.input-chat-thread .expert-result-card--formula .result-card-header img {
  width: 26px;
  height: 26px;
}

.input-chat-thread .result-card-book,
.input-chat-thread .result-card-excerpt {
  font-size: 12px;
  line-height: 1.5;
}

.input-chat-thread .expert-result-card {
  flex: 0 0 min(240px, 75vw);
  padding: 10px 12px;
  background: #faf7f2;
  border: 1px solid #ebe2d4;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.55;
}

.input-chat-thread .expert-result-card--formula {
  padding: 0;
  background: var(--search-formula-body-bg);
  border: 1px solid var(--search-formula-border);
}

.input-inline-pending {
  align-self: stretch;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 2px;
}

/* Selection → explain tip */
.selection-explain-tip {
  position: fixed;
  z-index: 520;
  transform: none;
  padding: 0;
  background: transparent;
  pointer-events: none;
}

.selection-explain-tip[hidden] {
  display: none;
}

.selection-explain-tip button {
  pointer-events: auto;
  border: 1px solid #d8cbb6;
  background: #2c2416;
  color: #f5f0e8;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1.2;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.selection-explain-tip button:hover {
  background: #3d3224;
}

.input-scope-row {
  padding: 9px 14px 0;
}

.input-scope-row[hidden],
.input-scope-menu[hidden] {
  display: none;
}

.input-scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 7px 5px 12px;
  border-radius: 999px;
  background: var(--color-avatar-bg);
  color: var(--text-primary);
  font-size: 12px;
}

.input-scope-kind {
  color: var(--text-secondary);
}

.input-scope-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.input-scope-remove {
  border: 0;
  padding: 0 2px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
}

.input-scope-menu {
  position: absolute;
  left: var(--input-panel-pad-x);
  width: min(360px, calc(100% - var(--input-panel-pad-x) * 2));
  bottom: calc(100% - 10px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  max-height: 320px;
  overflow: hidden;
  padding: 0;
  border: 1px solid #ddd2c2;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

.input-scope-tabs {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  border-bottom: 1px solid #efe6d8;
  background: #faf7f2;
}

.input-scope-tab {
  flex: 1;
  border: 0;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.input-scope-tab.active {
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--header-text);
}

.input-scope-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
}

.input-scope-empty {
  padding: 14px 10px;
  color: var(--text-secondary);
  font-size: 12px;
  text-align: center;
}

.input-scope-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.input-scope-option.active,
.input-scope-option:hover {
  background: #f3ede3;
}

.input-scope-option small {
  color: var(--text-secondary);
}

.input-toolbar {
  flex-shrink: 0;
  height: var(--input-toolbar-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 10px 8px;
}

.input-toolbar-spacer {
  flex: 1;
}

.input-toolbar .mic-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.65;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s, opacity 0.2s;
}

.input-toolbar .mic-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

.input-toolbar .mic-btn:disabled,
.input-toolbar .send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.input-toolbar .mic-btn:disabled:hover {
  background: transparent;
}

.input-toolbar .mic-btn.listening {
  opacity: 1;
  background: rgba(231, 76, 60, 0.12);
  animation: mic-pulse 1.2s ease infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

.input-toolbar .mic-btn.unsupported {
  cursor: not-allowed;
  opacity: 0.3;
}

.input-toolbar .mic-btn img {
  width: 20px;
  height: 20px;
}

.input-toolbar .send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent-orange);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.input-toolbar .send-btn:hover {
  background: #d35400;
}

.input-toolbar .send-btn:disabled:hover {
  background: var(--accent-orange);
}

.input-toolbar .send-btn svg {
  width: 16px;
  height: 16px;
}

.input-toolbar .input-collapse-btn,
.input-expand-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary, #666);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.7;
  transition: background 0.2s, opacity 0.2s;
}

.input-toolbar .input-collapse-btn:hover,
.input-expand-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

.input-expand-btn {
  position: absolute;
  /* Match expanded collapse-btn: panel pad + toolbar pad 10 + send 36 + gap 6 + mic 36 + gap 6 */
  right: calc(var(--input-panel-pad-x) + 10px + 36px + 6px + 36px + 6px);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  transition: background 0.2s;
}

.input-bar.input-bar-collapsed .input-expand-btn:not([hidden]) {
  opacity: 0.7;
  pointer-events: auto;
}

.input-bar.input-bar-collapsed .input-expand-btn:not([hidden]):hover {
  opacity: 0.9;
  background: #4a4a4a;
  color: #fff;
}

.input-expand-btn[hidden] {
  display: none !important;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: var(--radius);
}

.loading {
  text-align: center;
  padding: 24px 40px;
  color: var(--text-secondary);
  font-size: 14px;
  overflow: visible;
}

.chat-pending.loading-animated {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 16px 24px;
  padding-left: 28px;
  text-align: left;
  min-height: 0;
  overflow: visible;
}

.loading-status-row {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  align-self: flex-start;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.4;
  overflow: visible;
  padding: 8px 6px;
}

.loading-text-label {
  white-space: nowrap;
}

.loading-text-dots {
  display: inline-block;
  min-width: 1.25em;
  text-align: left;
  white-space: pre;
}

/* Inline book: one flip cycle = one full ellipsis loop (. → .. → ... → blank) */
.loading-book {
  --lb-surface-1: #faf8f2;
  --lb-surface-2: #faf8f2;
  --lb-border-strong: #b0aea5;
  --lb-border: #b0aea5;
  /* 4 × 420ms — keep in sync with LOADING_ELLIPSIS_CYCLE_MS in app.js */
  --lb-flip-ms: 1680ms;
  position: relative;
  width: 36px;
  height: 30px;
  display: inline-block;
  flex-shrink: 0;
  overflow: visible;
  vertical-align: middle;
}

.loading-book-scale {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 44px;
  /* was 0.32; ×1.5 → 0.48 */
  transform: translate(-50%, -50%) scale(0.48);
  transform-origin: center center;
  pointer-events: none;
  overflow: visible;
}

.loading-book-stage {
  position: relative;
  width: 56px;
  height: 44px;
  perspective: 240px;
  overflow: visible;
}

.lb-cover-left {
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 44px;
  background: var(--lb-surface-1);
  border: 1.25px solid var(--lb-border-strong);
  border-radius: 4px 0 0 4px;
  box-sizing: border-box;
}

.lb-cover-right {
  position: absolute;
  right: 0;
  top: 0;
  width: 28px;
  height: 44px;
  background: var(--lb-surface-1);
  border: 1.25px solid var(--lb-border-strong);
  border-radius: 0 4px 4px 0;
  box-sizing: border-box;
}

.lb-page {
  position: absolute;
  left: 2px;
  top: 0;
  width: 26px;
  height: 44px;
  background: var(--lb-surface-2);
  border: 1.25px solid var(--lb-border);
  border-radius: 4px 0 0 4px;
  transform-origin: right center;
  box-sizing: border-box;
}

/* One flip = one full “...” load; page B delayed by one cycle */
.lb-page--a {
  animation: pageflip var(--lb-flip-ms) infinite;
  backface-visibility: hidden;
}

.lb-page--b {
  animation: pageflip2 var(--lb-flip-ms) infinite;
  animation-delay: var(--lb-flip-ms);
}

/* Fast lift, slow settle — left → right */
@keyframes pageflip {
  0% {
    transform: rotateY(0deg);
  }
  22% {
    transform: rotateY(145deg);
  }
  45% {
    transform: rotateY(165deg);
  }
  100% {
    transform: rotateY(165deg);
  }
}

@keyframes pageflip2 {
  0% {
    transform: rotateY(0deg);
  }
  22% {
    transform: rotateY(145deg);
  }
  45% {
    transform: rotateY(165deg);
  }
  100% {
    transform: rotateY(165deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lb-page--a,
  .lb-page--b {
    animation: none;
  }
}

/* ============================================================
   GUEST LANDING PAGE — parchment + watermarks + centered copy
   ============================================================ */
#landing-page {
  display: none;
  /* Do not flex-grow while hidden — competing with .app-shell if display is ever toggled wrong */
  flex: none;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

body.is-guest #landing-page {
  display: flex;
  flex: 1;
}

body.auth-pending #app-shell {
  display: none !important;
}

body.is-guest #app-shell {
  display: none !important;
}

body.is-guest #sidebar-toggle {
  display: none !important;
}

body.is-guest #notes-sidebar-toggle {
  display: none !important;
}

body.is-guest {
  position: relative;
  background: var(--bg-neijing-ground);
  min-height: 100vh;
  min-width: var(--content-min-width);
  overflow-x: auto;
}

body.is-guest .header {
  background: var(--header-bg);
  z-index: 400;
  min-width: var(--content-min-width);
}

body.is-guest #landing-page {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  min-width: var(--content-min-width);
  width: 100%;
  overflow: hidden;
}

.landing-stage,
.landing-tint {
  position: absolute;
  inset: 0;
  width: 100%;
  min-width: var(--content-min-width);
}

.landing-stage {
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.landing-stage .bg-art-base,
.landing-stage .bg-parchment,
.landing-stage .bg-watermark-left,
.landing-stage .bg-watermark-right {
  position: absolute;
}

.landing-stage .bg-watermark-left,
.landing-stage .bg-watermark-right {
  opacity: 0.88;
}

.landing-stage .bg-parchment {
  background-color: color-mix(in srgb, var(--bg-parchment) 72%, transparent);
}

/* Text/mayfly SVG filter (watermarks are NOT in this tree — avoids global wm glitch). */
.landing-water-svg {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.landing-ripple-root {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: var(--content-min-width);
  width: 100%;
  /* Filter only while rippling — always-on + 60fps mayfly redraw overheats GPU */
  filter: none;
}

.landing-ripple-root.is-rippling {
  filter: url(#landing-water-ripple);
}

/* DOM watermarks hidden on landing; canvas draws them (with local ripple). */
.landing-stage .bg-watermark-left,
.landing-stage .bg-watermark-right {
  opacity: 0;
  /* Layout-only placeholders; mirror is baked into canvas texture */
  transform: translateY(-50%);
}

.landing-wm-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

.landing-tint {
  z-index: 1;
  background: rgba(202, 190, 167, 0.5);
  pointer-events: none;
}

/* Firefly cursor: above filtered content, does not receive events */
.landing-cursor-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  cursor: none;
}

/* Full-bleed mayfly layer: transparent ink over watermarks + copy; captures clicks.
   System cursor hidden — JS draws a warm firefly glow that follows the pointer. */
.landing-mayfly-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  pointer-events: auto;
}

/* Header / auth stay usable with a normal cursor above the landing */
body.is-guest .header,
body.is-guest .auth-modal {
  cursor: auto;
}

body.is-guest .header button,
body.is-guest .header a,
body.is-guest .auth-modal button,
body.is-guest .auth-modal a,
body.is-guest .auth-modal input {
  cursor: pointer;
}

.landing-layout {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin: 0 auto;
  padding: calc(var(--header-height) + 28px) 40px 48px;
  box-sizing: border-box;
  pointer-events: none;
}

.landing-content {
  position: relative;
  z-index: 3;
  width: 620px;
  max-width: 620px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 0;
  margin: 0;
  box-sizing: border-box;
  pointer-events: none;
}

.landing-title {
  margin: 0 0 14px;
  font-size: 42px;
  font-weight: 600;
  color: var(--color-gold-deep);
  letter-spacing: 0.06em;
  line-height: 1.25;
}

.landing-copy {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* ~1.2 × 字高 between the three blocks */
  /*gap: 1.2em;*/
}

.landing-stats {
  margin: 0 0 1.2em;
  font-size: 20px;
  font-weight: 600;
  color: var(--element-fire-dark);
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.landing-stats .landing-dot {
  margin: 0 0.35em;
  opacity: 0.75;
}

.landing-para {
  margin: 0;
  font-size: 15px;
  line-height: 1.95;
  color: var(--color-ink-muted);
  text-align: center;
}

.landing-content { align-items: center; }
.app-logo--landing {
  display: block;
  height: 56px;
  width: auto;
  max-width: min(100%, 720px);
  margin: 0 auto 18px;
  object-fit: contain;
  object-position: center;
}

@media (prefers-reduced-motion: reduce) {
  .landing-mayfly-canvas,
  .landing-cursor-canvas {
    display: none;
  }
}

body.is-guest .auth-modal {
  background: rgba(0, 0, 0, 0.55);
}

.scrape-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 16, 12, 0.55);
}
.scrape-overlay[hidden] { display: none !important; }
.scrape-overlay-panel {
  width: min(440px, 100%);
  background: var(--color-paper, #f7f2e8);
  color: var(--color-ink, #2a2118);
  border-radius: 12px;
  padding: 28px 24px 22px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  text-align: center;
}
.scrape-overlay-panel h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}
.scrape-overlay-body,
.scrape-overlay-hint {
  margin: 0 0 14px;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--color-ink-muted, #5c4f42);
}
.scrape-cooldown-timer {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 8px 0 16px;
  color: var(--color-ink, #2a2118);
}
.scrape-overlay-panel .auth-btn { min-width: 140px; }

