/* ── Lyra Shell Protocol ──────────────────────────────────────────
   取用设计系统语义 token，不写死颜色。
   ──────────────────────────────────────────────────────────────── */
@import url("/ds/tokens/colors.css");
@import url("/ds/tokens/themes.css");
@import url("/ds/tokens/typography.css");
@import url("/ds/tokens/spacing.css");
@import url("/ds/tokens/motion.css");

/* 整块可点的元素，hover 不能给所有子元素加下划线 */
.lyra-header a, .lyra-header a:hover,
.lyra-footer a, .lyra-footer a:hover,
.lyra-toc-rail a, .lyra-toc-rail a:hover,
.lyra-toc-panel a, .lyra-toc-panel a:hover,
.ds-card, .ds-card:hover, .ds-card *,
.kit a, .kit a:hover, .spec .open, .spec .open:hover,
.jump a, .jump a:hover { text-decoration: none; }

/* ══ Header ══ 固定不动，进度条始终可见 */
.lyra-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: var(--header-h-desktop);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--gutter-desktop);
  background: color-mix(in srgb, var(--surface-page) 90%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-hairline);
}
body { padding-top: var(--header-h-desktop); }

.lyra-mark {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-mono-display); font-size: 16px;
  font-weight: var(--weight-medium); letter-spacing: .18em;
  text-transform: uppercase; color: var(--text-heading);
  white-space: nowrap;
}
.lyra-mark img { width: 22px; height: 22px; display: block; border-radius: 5px; }
.lyra-mark:hover { color: var(--accent); }

.lyra-header nav { display: flex; align-items: center; gap: var(--sp-5); min-width: 0; }
.lyra-header nav a, .lyra-header nav span {
  font-size: var(--fs-small); color: var(--text-muted); white-space: nowrap;
}
.lyra-header nav a:hover { color: var(--accent); }
.lyra-kind { display: inline-flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; }
.lyra-kind::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); flex: 0 0 auto;
}

.lyra-header::after {
  content: ""; position: absolute; left: 0; bottom: -1px; height: 2px;
  width: var(--lyra-progress, 0%); background: var(--accent);
  transition: width 80ms linear;
}

/* ══ Footer ══ */
.lyra-footer {
  min-height: var(--footer-min-h);
  display: flex; align-items: center;
  padding: var(--sp-5) var(--gutter-desktop);
  margin-top: var(--sp-8);
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-page-alt);
  font-family: var(--font-code); font-size: var(--fs-micro); color: var(--text-muted);
}
.lyra-footer-in {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-5); flex-wrap: wrap;
}
.lyra-footer a { color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.lyra-footer a:hover { color: var(--accent); }

/* ══ TocRail ══ 右侧边缘，横线直接可点，悬停时本条与邻近撑开成标题 */
.lyra-toc-rail {
  position: fixed; right: var(--rail-left-offset); top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 7px; padding: var(--sp-3) var(--sp-2);
  z-index: 20; max-height: 78vh;
  transition: gap var(--dur-fast) var(--ease-out);
}
.lyra-toc-rail:hover { gap: 3px; }

.lyra-toc-rail .row {
  position: relative;
  display: flex; align-items: center; justify-content: flex-end;
  gap: 10px; min-height: 3px; cursor: pointer;
  background: none; border: 0; padding: 0;
  color: var(--text-muted);
  transition: min-height var(--dur-fast) var(--ease-out), padding var(--dur-fast) var(--ease-out);
}
.lyra-toc-rail .row .label {
  max-width: 0; opacity: 0; overflow: hidden; white-space: nowrap;
  font-family: var(--font-code); font-size: var(--fs-micro);
  line-height: 1.3; text-align: right;
  transition: max-width var(--dur-panel) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.lyra-toc-rail .row .dash {
  height: 2px; border-radius: 1px; background: var(--toc-line);
  opacity: .55; flex: 0 0 auto;
  transition: all var(--dur-fast) var(--ease-standard);
}
.lyra-toc-rail .row[data-active="1"] .dash { height: 3px; background: var(--accent); opacity: 1; }
.lyra-toc-rail .row[data-active="1"] { color: var(--text-heading); }

/* 悬停撑开：near 0 = 本条，1 = 上下各一条，2 = 再外一层 */
.lyra-toc-rail .row[data-near] { min-height: 20px; padding: 2px 0; }
.lyra-toc-rail .row[data-near="0"] .label { max-width: 280px; opacity: 1; color: var(--accent); font-weight: var(--weight-medium); }
.lyra-toc-rail .row[data-near="1"] .label { max-width: 230px; opacity: .8; }
.lyra-toc-rail .row[data-near="2"] .label { max-width: 190px; opacity: .45; }
.lyra-toc-rail .row[data-near="0"] .dash { background: var(--accent); opacity: 1; height: 3px; }
.lyra-toc-rail .row:hover .dash { opacity: 1; }

/* ══ 移动端目录 ══ */
.lyra-toc-fab {
  display: none;
  position: fixed; right: var(--gutter-mobile);
  bottom: calc(var(--fab-offset) + env(safe-area-inset-bottom));
  height: var(--hit-min); padding: 0 16px;
  align-items: center; gap: 8px; z-index: 24; cursor: pointer;
  border-radius: var(--radius-pill);
  background: var(--surface-raised); color: var(--text-body);
  border: 1px solid var(--border-strong);
  box-shadow: 0 6px 20px rgba(0,0,0,.24);
  font-family: var(--font-code); font-size: var(--fs-micro);
}
.lyra-toc-scrim { position: fixed; inset: 0; z-index: 34; background: transparent; border: 0; padding: 0; }
.lyra-toc-panel {
  position: fixed; z-index: 35; left: 0; right: 0; bottom: 0;
  max-height: 56vh; display: flex; flex-direction: column;
  border-radius: var(--radius-4) var(--radius-4) 0 0;
  padding: var(--sp-4) var(--gutter-mobile) calc(var(--sp-6) + env(safe-area-inset-bottom));
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  color: var(--text-body);
  animation: lyra-sheet-up var(--dur-panel) var(--ease-out);
}
.lyra-toc-panel::before {
  content: ""; width: 36px; height: 4px; border-radius: 2px;
  background: var(--border-strong); margin: 0 auto var(--sp-4); flex: 0 0 auto;
}
.lyra-toc-head { display: flex; align-items: center; justify-content: space-between; }
.lyra-toc-head span {
  font-family: var(--font-code); font-size: var(--fs-micro);
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-muted);
}
.lyra-toc-head button {
  width: var(--hit-min); height: var(--hit-min); margin-right: -10px;
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 15px;
}
.lyra-toc-panel hr { height: 1px; border: 0; background: var(--border-hairline); margin: var(--sp-3) 0 var(--sp-2); }
.lyra-toc-panel nav { display: grid; gap: 2px; overflow-y: auto; }
.lyra-toc-panel nav a {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--hit-min);
  font-size: var(--fs-small); color: var(--text-muted); line-height: 1.45;
}
.lyra-toc-panel nav a[data-lvl="3"] { padding-left: var(--sp-5); font-size: var(--fs-micro); }
.lyra-toc-panel nav a[data-lvl="4"] { padding-left: var(--sp-6); font-size: var(--fs-micro); }
.lyra-toc-panel nav a .bullet {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: transparent; border: 1px solid var(--border-strong);
}
.lyra-toc-panel nav a[data-active="1"] { color: var(--text-heading); font-weight: var(--weight-medium); }
.lyra-toc-panel nav a[data-active="1"] .bullet { background: var(--accent); border: 0; }

@keyframes lyra-sheet-up { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: none; } }

/* ══ 响应式 ══ */
@media (max-width: 1180px) {
  .lyra-toc-rail { display: none; }
  .lyra-toc-fab { display: inline-flex; }
}
@media (max-width: 640px) {
  body { padding-top: var(--header-h-mobile); }
  .lyra-header { height: var(--header-h-mobile); padding: 0 var(--gutter-mobile); }
  .lyra-mark { font-size: 14px; }
  .lyra-mark img { width: 19px; height: 19px; }
  .lyra-header nav { gap: var(--sp-4); }
  .lyra-kind { display: none; }
  .lyra-footer { padding: var(--sp-5) var(--gutter-mobile); margin-top: var(--sp-7); }
  .lyra-footer-in { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
}
@media (prefers-reduced-motion: reduce) {
  .lyra-toc-rail, .lyra-toc-rail .row, .lyra-toc-rail .row .label, .lyra-toc-panel {
    transition: none; animation: none;
  }
}

/* ══ 表格窄屏堆叠 ══ */
@media (max-width: 720px) {
  .lyra-stack table { min-width: 0 !important; width: 100%; font-size: 14px; }
  .lyra-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .lyra-stack tbody tr { display: block; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-hairline); }
  .lyra-stack tbody tr:last-child { border-bottom: 0; }
  .lyra-stack tbody td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: var(--sp-4); padding: 5px 0; border: 0; text-align: right;
  }
  .lyra-stack tbody td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 48%; text-align: left;
    font-family: var(--font-code); font-size: 11px; letter-spacing: .05em; line-height: 1.5; opacity: .62;
  }
  .lyra-stack tbody td:first-child {
    display: block; text-align: left; font-weight: var(--weight-bold);
    font-size: var(--fs-small); padding-bottom: var(--sp-2);
  }
  .lyra-stack tbody td:first-child::before { display: none; }
}

/* ── 登录态槽位：头像与登出之间要有间距 ── */
[data-lyra-auth] {
  display: inline-flex; align-items: center; gap: var(--sp-3);
}
[data-lyra-auth]:empty { display: none; }

/* ── 回顶部 & 管理员头像 ── */
.lyra-footer .f-right { display: inline-flex; align-items: center; gap: var(--sp-5); }
.lyra-top { cursor: pointer; }
.lyra-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.lyra-avatar {
  width: 26px; height: 26px; border-radius: 50%; overflow: hidden;
  display: inline-grid; place-items: center; flex: 0 0 auto;
  background: var(--accent); color: var(--on-accent);
  font-family: var(--font-mono-display); font-size: 12px; line-height: 1;
  font-weight: var(--weight-medium); text-transform: uppercase;
  user-select: none;
}

/* ══ GrokLauncher ══ 右下角，48px 圆钮，3s 呼吸 */
.lyra-ai-fab {
  position: fixed; right: var(--fab-offset);
  bottom: calc(var(--fab-offset) + 32px + env(safe-area-inset-bottom));
  height: var(--fab-size); min-width: var(--fab-size);
  padding: 0 18px 0 15px; gap: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 25; cursor: pointer;
  border-radius: var(--radius-pill);
  background: var(--accent); color: var(--on-accent);
  border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
  font-family: var(--font-code); font-size: var(--fs-micro); letter-spacing: .04em;
  animation: lyra-breathe var(--pulse-cycle) var(--ease-standard) infinite;
}
.lyra-ai-fab:hover { animation-play-state: paused; filter: brightness(1.06); }
.lyra-ai-fab .sp { font-size: 15px; line-height: 1; }
@keyframes lyra-breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(var(--pulse-scale)); } }

/* ══ GrokPanel ══ 桌面右侧 400px 滑入，移动端底部 85% */
/* 遮罩只负责点空白关闭，不能挡住正文选词——否则开着面板就没法再引用第二段 */
.lyra-ai-scrim { display: none; }
.lyra-ai-panel {
  position: fixed; z-index: 40; right: 0; top: 0; bottom: 0;
  width: var(--panel-w-grok); max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-left: 1px solid var(--border-hairline);
  color: var(--text-body);
  animation: lyra-slide-right var(--dur-panel) var(--ease-out);
}
@keyframes lyra-slide-right { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: none; } }

.lyra-ai-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-4); border-bottom: 1px solid var(--border-hairline); flex: 0 0 auto;
}
.lyra-ai-head .sp { color: var(--accent); font-size: 15px; }
.lyra-ai-head b {
  flex: 1; font-size: var(--fs-small); color: var(--text-heading);
  font-weight: var(--weight-medium); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lyra-ai-head button {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 15px;
}
.lyra-ai-head button:hover { color: var(--accent); }

.lyra-ai-log {
  flex: 1; overflow-y: auto; padding: var(--sp-4);
  display: grid; gap: var(--sp-4); align-content: start;
}
.lyra-ai-msg { max-width: 88%; }
.lyra-ai-msg.me { justify-self: end; }
.lyra-ai-msg .who {
  font-family: var(--font-code); font-size: 10px; letter-spacing: var(--tracking-label);
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px;
}
.lyra-ai-msg.me .who { text-align: right; }
.lyra-ai-msg .bubble {
  padding: 10px 13px; border-radius: var(--radius-3);
  font-size: var(--fs-small); line-height: var(--lh-body);
  background: var(--surface-raised); border: 1px solid var(--border-hairline);
  white-space: pre-wrap; word-break: break-word;
}
.lyra-ai-msg.me .bubble { background: var(--accent); color: var(--on-accent); border: 0; }
.lyra-ai-msg .bubble code {
  font-family: var(--font-code); font-size: .92em;
  background: var(--inline-code-bg); color: var(--inline-code-fg);
  padding: 1px 5px; border-radius: var(--radius-1);
}
.lyra-ai-empty {
  color: var(--text-muted); font-size: var(--fs-small); line-height: var(--lh-body);
  padding: var(--sp-5) var(--sp-2);
}
.lyra-ai-empty b { display: block; color: var(--text-heading); margin-bottom: 6px; font-weight: var(--weight-medium); }
.lyra-ai-dots span {
  display: inline-block; width: 5px; height: 5px; margin-right: 4px; border-radius: 50%;
  background: var(--text-muted); animation: lyra-dot 1.1s infinite;
}
.lyra-ai-dots span:nth-child(2) { animation-delay: .18s; }
.lyra-ai-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes lyra-dot { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

.lyra-ai-form {
  display: flex; gap: var(--sp-2); padding: var(--sp-3);
  border-top: 1px solid var(--border-hairline); flex: 0 0 auto;
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
}
.lyra-ai-form textarea {
  flex: 1; min-width: 0; min-height: 40px; max-height: 120px; resize: none;
  padding: 9px 12px; border-radius: var(--radius-2);
  background: var(--surface-page); border: 1px solid var(--border-hairline);
  color: var(--text-body); font-family: var(--font-body); font-size: var(--fs-small);
  line-height: 1.5; outline: none;
}
.lyra-ai-form textarea:focus { border-color: var(--accent); }
.lyra-ai-form button {
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-2); cursor: pointer;
  background: var(--accent); color: var(--on-accent); border: 0;
  font-family: var(--font-body); font-size: var(--fs-small); font-weight: var(--weight-medium);
}
.lyra-ai-form button[disabled] { opacity: .45; cursor: default; }

@media (max-width: 640px) {
  .lyra-ai-fab { padding: 0; min-width: var(--fab-size); }
  .lyra-ai-fab .txt { display: none; }
  .lyra-ai-panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 85%;
    border-left: 0; border-top: 1px solid var(--border-hairline);
    border-radius: var(--radius-4) var(--radius-4) 0 0;
    animation: lyra-sheet-up var(--dur-panel) var(--ease-out);
  }
  .lyra-ai-panel::before {
    content: ""; width: 36px; height: 4px; border-radius: 2px;
    background: var(--border-strong); margin: var(--sp-3) auto 0; flex: 0 0 auto;
  }
  .lyra-ai-head button { width: var(--hit-min); height: var(--hit-min); }
  /* 目录按钮让位，别和 AI 钮叠在一起 */
  .lyra-toc-fab { right: calc(var(--fab-offset) + var(--fab-size) + 12px); }
}
@media (prefers-reduced-motion: reduce) {
  .lyra-ai-fab { animation: none; }
  .lyra-ai-panel { animation: none; }
}

/* ══ 划词工具条 ══ 选中正文文字后浮出 */
.lyra-sel-bar {
  position: absolute; z-index: 36;
  display: inline-flex; align-items: stretch; overflow: hidden;
  border-radius: var(--radius-3);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
  animation: lyra-sel-in 140ms var(--ease-out);
}
@keyframes lyra-sel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.lyra-sel-bar button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; cursor: pointer;
  background: none; border: 0; color: var(--text-body);
  font-family: var(--font-body); font-size: var(--fs-small); white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-standard);
}
.lyra-sel-bar button + button { border-left: 1px solid var(--border-hairline); }
.lyra-sel-bar button:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.lyra-sel-bar button .g { font-size: 13px; line-height: 1; opacity: .85; }

/* 注释高亮 */
mark.lyra-note {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit; border-bottom: 1px solid var(--accent);
  border-radius: 2px; padding: 0 1px; cursor: pointer;
}
mark.lyra-note:hover { background: color-mix(in srgb, var(--accent) 32%, transparent); }

/* 批注气泡：两个去向标签 + 输入 + 操作 */
.lyra-note-pop .tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  border-radius: var(--radius-3); background: var(--surface-inset);
  margin-bottom: var(--sp-3);
}
.lyra-note-pop .tabs button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: var(--radius-2); cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  font-family: var(--font-body); font-size: var(--fs-small); white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-standard);
}
.lyra-note-pop .tabs button[aria-pressed="true"] {
  background: var(--surface-raised); color: var(--text-heading);
  border-color: var(--border-hairline); font-weight: var(--weight-medium);
  box-shadow: var(--shadow-card);
}
.lyra-note-pop .tabs button .g { font-size: 13px; line-height: 1; }

/* 注释气泡 */
.lyra-note-pop {
  position: absolute; z-index: 37; width: min(380px, 92vw);
  padding: var(--sp-4);
  border-radius: var(--radius-3);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  box-shadow: 0 12px 34px rgba(0,0,0,.3);
  animation: lyra-sel-in 140ms var(--ease-out);
}
.lyra-note-pop .quote {
  font-size: var(--fs-micro); color: var(--text-muted); line-height: 1.6;
  padding-left: 10px; border-left: 2px solid var(--accent);
  margin-bottom: var(--sp-3);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.lyra-note-pop textarea {
  width: 100%; min-height: 76px; resize: vertical;
  padding: 9px 11px; border-radius: var(--radius-2);
  background: var(--surface-page); border: 1px solid var(--border-hairline);
  color: var(--text-body); font-family: var(--font-body); font-size: var(--fs-small);
  line-height: 1.6; outline: none;
}
.lyra-note-pop textarea:focus { border-color: var(--accent); }
.lyra-note-pop .row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); margin-top: var(--sp-3);
}
.lyra-note-pop .row button {
  padding: 7px 14px; border-radius: var(--radius-2); cursor: pointer;
  font-family: var(--font-body); font-size: var(--fs-small); border: 0;
  background: var(--accent); color: var(--on-accent); font-weight: var(--weight-medium);
}
.lyra-note-pop .row button.ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border-hairline); font-weight: var(--weight-regular);
}
.lyra-note-pop .row button.ghost:hover { color: var(--accent); border-color: var(--accent); }

/* AI 输入框里的引用暂存块 */
.lyra-ai-quote {
  margin: 0 var(--sp-3) var(--sp-2); padding: 9px 11px;
  border-radius: var(--radius-2);
  background: var(--surface-raised); border: 1px solid var(--border-hairline);
  border-left: 2px solid var(--accent);
  font-size: var(--fs-micro); color: var(--text-muted); line-height: 1.6;
  display: flex; align-items: flex-start; gap: 8px;
}
.lyra-ai-quote span {
  flex: 1; display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}
.lyra-ai-quote button {
  flex: 0 0 auto; background: none; border: 0; cursor: pointer;
  color: var(--text-muted); font-size: 13px; line-height: 1; padding: 0;
}
.lyra-ai-quote button:hover { color: var(--accent); }

@media (max-width: 640px) {
  .lyra-sel-bar button { padding: 11px 15px; min-height: var(--hit-min); }
}

/* ══ AI 侧栏停靠态 ══ 像浏览器插件侧边栏：挤开正文，不盖页头页尾 */
:root { --dock-w: 400px; }

html[data-lyra-dock="1"] body { padding-right: var(--dock-w); }
html[data-lyra-dock="1"] .lyra-header { right: var(--dock-w); }
html[data-lyra-dock="1"] .lyra-toc-rail { right: calc(var(--dock-w) + var(--rail-left-offset)); }
html[data-lyra-dock="1"] .lyra-ai-fab { display: none; }
html[data-lyra-dock="1"] .lyra-toc-fab { right: calc(var(--dock-w) + var(--gutter-mobile)); }

.lyra-ai-panel[data-dock="1"] {
  top: 0; bottom: 0; right: 0; width: var(--dock-w);
  border-left: 1px solid var(--border-hairline);
  background: var(--surface-page);
  -webkit-backdrop-filter: none; backdrop-filter: none;
  animation: none;
  box-shadow: -1px 0 0 var(--border-hairline);
}
/* 停靠时不要遮罩，页面要能继续操作 */
.lyra-ai-scrim[data-dock="1"] { display: none; }

/* 左边缘拖拽改宽度 */
.lyra-ai-grip {
  position: absolute; left: -3px; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 2; background: transparent;
}
.lyra-ai-grip:hover, .lyra-ai-grip[data-drag="1"] { background: var(--accent); opacity: .55; }
.lyra-ai-panel:not([data-dock="1"]) .lyra-ai-grip { display: none; }

/* 头部的模式切换 */
.lyra-ai-head .close { color: var(--text-muted); }
.lyra-ai-head .close:hover { color: var(--accent); }
.lyra-ai-head .mode {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: none; border: 0; color: var(--text-muted); cursor: pointer;
  font-size: 13px; line-height: 1; border-radius: var(--radius-2);
}
.lyra-ai-head .mode:hover { color: var(--accent); background: var(--surface-raised); }

/* ══ 图片附件 ══ */
.lyra-ai-shots {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 var(--sp-3) var(--sp-2);
}
.lyra-ai-shot {
  position: relative; width: 62px; height: 62px; flex: 0 0 auto;
  border-radius: var(--radius-2); overflow: hidden;
  border: 1px solid var(--border-hairline); background: var(--surface-raised);
}
.lyra-ai-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lyra-ai-shot button {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(0,0,0,.62); color: #fff; border: 0; font-size: 11px; line-height: 1;
}
.lyra-ai-tools {
  display: inline-flex; align-items: flex-end; gap: 2px; flex: 0 0 auto;
}
.lyra-ai-form .tool {
  width: 34px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center; cursor: pointer;
  border-radius: var(--radius-2);
  background: transparent; border: 0;
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease-standard),
              background var(--dur-fast) var(--ease-standard);
}
.lyra-ai-form .tool:hover:not([disabled]) {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.lyra-ai-form .tool[disabled] { opacity: .35; cursor: default; }
.lyra-ai-form .send { flex: 0 0 auto; }
.lyra-ai-msg .bubble img.shot {
  max-width: 100%; border-radius: var(--radius-2); margin-top: 6px; display: block;
}
.lyra-ai-panel[data-drop="1"]::after {
  content: "松手上传图片"; position: absolute; inset: 0; z-index: 5;
  pointer-events: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 2px dashed var(--accent); border-radius: inherit;
  font-family: var(--font-code); font-size: var(--fs-small); color: var(--accent);
}

/* 窄屏不支持停靠，退回底部弹出 */
@media (max-width: 1024px) {
  html[data-lyra-dock="1"] body { padding-right: 0; }
  html[data-lyra-dock="1"] .lyra-header { right: 0; }
  html[data-lyra-dock="1"] .lyra-toc-rail { right: var(--rail-left-offset); }
  html[data-lyra-dock="1"] .lyra-ai-fab { display: inline-flex; }
  html[data-lyra-dock="1"] .lyra-toc-fab { right: calc(var(--fab-offset) + var(--fab-size) + 12px); }
  .lyra-ai-panel[data-dock="1"] {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 85%;
    border-left: 0; border-top: 1px solid var(--border-hairline);
    border-radius: var(--radius-4) var(--radius-4) 0 0;
    animation: lyra-sheet-up var(--dur-panel) var(--ease-out);
  }
  .lyra-ai-scrim[data-dock="1"] { display: block; }
  .lyra-ai-head .close { color: var(--text-muted); }
.lyra-ai-head .close:hover { color: var(--accent); }
.lyra-ai-head .mode { display: none; }
}

/* ══ 手机端底部操作簇：目录 + 问 AI 并排 ══ */
.lyra-dock-cluster {
  display: none;
  position: fixed; right: var(--gutter-mobile);
  bottom: calc(var(--fab-offset) + env(safe-area-inset-bottom));
  z-index: 25;
  align-items: stretch; overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.lyra-dock-cluster button {
  display: inline-flex; align-items: center; gap: 7px;
  height: var(--hit-min); padding: 0 16px; cursor: pointer;
  background: none; border: 0; color: var(--text-body);
  font-family: var(--font-code); font-size: var(--fs-micro); white-space: nowrap;
}
.lyra-dock-cluster button + button { border-left: 1px solid var(--border-hairline); }
.lyra-dock-cluster button.ai { background: var(--accent); color: var(--on-accent); }
.lyra-dock-cluster button.ai .sp { font-size: 14px; line-height: 1; }
.lyra-dock-cluster button:active { filter: brightness(.94); }

@media (max-width: 1024px) {
  .lyra-dock-cluster { display: inline-flex; }
  /* 合并后原来两个独立按钮退场 */
  .lyra-toc-fab, .lyra-ai-fab { display: none !important; }
  html[data-lyra-dock="1"] .lyra-ai-fab { display: none !important; }
}

/* 手机端不要箭头 */
@media (max-width: 640px) {
  .lyra-footer .ar { display: none; }
  .lyra-footer .f-right { gap: var(--sp-4); flex-wrap: wrap; }
}


/* ══ 多条引用暂存 ══ */
.lyra-ai-quotes { display: grid; gap: 6px; padding: 0 var(--sp-3) var(--sp-2); }
.lyra-ai-quotes .q-head {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-code); font-size: 11px; color: var(--text-muted);
}
.lyra-ai-quotes .q-head button {
  background: none; border: 0; cursor: pointer; padding: 0;
  color: var(--text-muted); font-family: inherit; font-size: 11px;
}
.lyra-ai-quotes .q-head button:hover { color: var(--accent); }
.lyra-ai-quotes .lyra-ai-quote {
  margin: 0; display: block; padding: 9px 10px;
}
.lyra-ai-quote .q-body {
  display: flex; align-items: flex-start; gap: 8px;
}
.lyra-ai-quote .q-no {
  flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  font-style: normal; font-size: 10px; font-family: var(--font-code);
  margin-top: 1px;
}
.lyra-ai-quote .q-ask {
  width: 100%; margin-top: 7px; padding: 6px 9px;
  border-radius: var(--radius-2);
  background: var(--surface-page);
  border: 1px solid var(--border-hairline);
  color: var(--text-body);
  font-family: var(--font-body); font-size: var(--fs-micro);
  line-height: 1.5; outline: none;
}
.lyra-ai-quote .q-ask:focus { border-color: var(--accent); }
.lyra-ai-quote .q-ask::placeholder { color: var(--text-muted); opacity: .8; }

/* ══ 批注侧栏 ══ */
.lyra-notes-fab {
  position: fixed; right: var(--fab-offset);
  bottom: calc(var(--fab-offset) + 32px + var(--fab-size) + 12px + env(safe-area-inset-bottom));
  height: 40px; padding: 0 15px; gap: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 25; cursor: pointer;
  border-radius: var(--radius-pill);
  background: var(--surface-raised); color: var(--text-body);
  border: 1px solid var(--border-strong);
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  font-family: var(--font-code); font-size: var(--fs-micro);
}
.lyra-notes-fab:hover { color: var(--accent); border-color: var(--accent); }
.lyra-notes-fab b {
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  display: inline-grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  font-size: 10px; font-weight: var(--weight-medium);
}

.lyra-notes-panel {
  position: fixed; z-index: 40; right: 0; top: 0; bottom: 0;
  width: var(--panel-w-grok); max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--surface-page);
  border-left: 1px solid var(--border-hairline);
  color: var(--text-body);
  animation: lyra-slide-right var(--dur-panel) var(--ease-out);
}
html[data-lyra-notes="1"] body { padding-right: var(--dock-w); }
html[data-lyra-notes="1"] .lyra-header { right: var(--dock-w); }
html[data-lyra-notes="1"] .lyra-toc-rail { right: calc(var(--dock-w) + var(--rail-left-offset)); }
html[data-lyra-notes="1"] .lyra-notes-fab,
html[data-lyra-notes="1"] .lyra-ai-fab { display: none; }
.lyra-notes-panel { width: var(--dock-w); }

.lyra-notes-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-4); border-bottom: 1px solid var(--border-hairline); flex: 0 0 auto;
}
.lyra-notes-head b {
  flex: 1; font-size: var(--fs-small); color: var(--text-heading);
  font-weight: var(--weight-medium);
}
.lyra-notes-head .g { color: var(--accent); font-size: 14px; }
.lyra-notes-head button {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 15px;
}
.lyra-notes-head button:hover { color: var(--accent); }

.lyra-notes-list { flex: 1; overflow-y: auto; padding: var(--sp-3); display: grid; gap: var(--sp-3); align-content: start; }
.lyra-note-card {
  padding: var(--sp-4); border-radius: var(--radius-3);
  background: var(--surface-raised); border: 1px solid var(--border-hairline);
  cursor: pointer; transition: all var(--dur-fast) var(--ease-standard);
}
.lyra-note-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lyra-note-card .q {
  font-size: var(--fs-micro); color: var(--text-muted); line-height: 1.6;
  padding-left: 9px; border-left: 2px solid var(--accent);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lyra-note-card .n {
  margin-top: var(--sp-3); font-size: var(--fs-small);
  line-height: var(--lh-body); color: var(--text-body); white-space: pre-wrap;
}
.lyra-note-card .n.empty { color: var(--text-muted); font-style: italic; }
.lyra-note-card .meta {
  margin-top: var(--sp-3); display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-code); font-size: 10px; color: var(--text-muted);
}
.lyra-note-card .meta button {
  background: none; border: 0; cursor: pointer; padding: 0;
  color: var(--text-muted); font-family: inherit; font-size: 10px;
}
.lyra-note-card .meta button:hover { color: var(--accent); }
.lyra-notes-empty { padding: var(--sp-7) var(--sp-4); text-align: center;
  color: var(--text-muted); font-size: var(--fs-small); line-height: var(--lh-body); }

mark.lyra-note.flash { animation: lyra-flash 1.2s var(--ease-standard); }
@keyframes lyra-flash {
  0%, 100% { background: color-mix(in srgb, var(--accent) 22%, transparent); }
  35% { background: var(--accent); }
}

@media (max-width: 1024px) {
  html[data-lyra-notes="1"] body { padding-right: 0; }
  html[data-lyra-notes="1"] .lyra-header { right: 0; }
  html[data-lyra-notes="1"] .lyra-toc-rail { right: var(--rail-left-offset); }
  .lyra-notes-fab { display: none; }
  .lyra-notes-panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 82%;
    border-left: 0; border-top: 1px solid var(--border-hairline);
    border-radius: var(--radius-4) var(--radius-4) 0 0;
    animation: lyra-sheet-up var(--dur-panel) var(--ease-out);
  }
}
