/* lecture-webview/style.css */

:root {
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --border: color-mix(in srgb, var(--vscode-panel-border) 72%, transparent);
  --surface-1: color-mix(in srgb, var(--vscode-editor-background) 88%, transparent);
  --surface-2: color-mix(in srgb, var(--vscode-sideBar-background) 62%, var(--vscode-editor-background));
  --surface-3: color-mix(in srgb, var(--vscode-input-background) 80%, var(--vscode-editor-background));
  --accent: var(--vscode-button-background);
  --accent-soft: color-mix(in srgb, var(--vscode-button-background) 16%, transparent);
  --accent-strong: color-mix(in srgb, var(--vscode-button-background) 92%, white 8%);
  --success: rgba(76, 175, 80, 0.85);
  --success-soft: rgba(76, 175, 80, 0.20);
  --warn: rgba(245, 158, 11, 0.92);
  --danger: rgba(239, 68, 68, 0.92);
  --shadow-popover: 0 18px 38px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--vscode-editor-background);
  color: var(--vscode-editor-foreground);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

/* ===== header ===== */

.lecture-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 36px 14px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--vscode-editor-background) 96%, transparent) 0%,
    color-mix(in srgb, var(--vscode-editor-background) 88%, transparent) 100%);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.lecture-meta {
  flex: 1;
  min-width: 0;
}

.lecture-topic {
  color: color-mix(in srgb, var(--vscode-descriptionForeground, var(--vscode-foreground)) 80%, transparent);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lecture-title {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lecture-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lecture-status {
  font-size: 12px;
  color: color-mix(in srgb, var(--vscode-descriptionForeground, var(--vscode-foreground)) 70%, transparent);
}

.lecture-status[data-level="success"] { color: var(--success); }
.lecture-status[data-level="error"] { color: var(--danger); }

.btn-mini {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  color: var(--vscode-foreground);
  cursor: pointer;
  font-size: 14px;
  transition: 120ms ease;
  /* SVG 子元素居中（也对文字按钮无副作用） */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.btn-mini svg {
  display: block;       /* 消除 inline 行高造成的偏移 */
  stroke: currentColor; /* 跟随主题色 */
}

.btn-mini:hover {
  background: var(--accent-soft);
  transform: rotate(90deg);
}
/* 撤回按钮：rotate 对 undo 语义不自然，改成轻微放大反馈 */
.btn-mini--icon:hover {
  transform: scale(1.1);
}

/* ===== body / markdown ===== */

.lecture-body {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 40px 120px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.4em 0 0.6em;
  letter-spacing: 0.005em;
}

.markdown-body h1 { font-size: 26px; }
.markdown-body h2 {
  font-size: 21px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.markdown-body h3 { font-size: 17px; }
.markdown-body h4 { font-size: 14px; }

.markdown-body p,
.markdown-body li,
.markdown-body blockquote {
  font-size: 14.5px;
  line-height: 1.78;
}

.markdown-body p { margin: 0.7em 0; }

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4em;
  margin: 0.6em 0;
}

.markdown-body blockquote {
  margin: 1em 0;
  padding: 6px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: color-mix(in srgb, var(--vscode-foreground) 92%, transparent);
}

.markdown-body code {
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--vscode-editor-font-family, "Consolas", monospace);
  font-size: 13px;
  background: color-mix(in srgb, var(--vscode-textCodeBlock-background, var(--surface-3)) 90%, transparent);
}

.markdown-body pre {
  margin: 0.8em 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--vscode-textCodeBlock-background, var(--surface-3)) 92%, transparent);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 1em 0;
  width: 100%;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--border);
}

.markdown-body th {
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  font-weight: 600;
}

.markdown-body a {
  color: var(--vscode-textLink-foreground);
  text-decoration: none;
  border-bottom: 1px dashed color-mix(in srgb, var(--vscode-textLink-foreground) 50%, transparent);
}

.markdown-body a:hover { border-bottom-style: solid; }

/* 讲义内嵌图：透明 PNG（如 Wikipedia / Jay Alammar / arxiv 图）在深色主题下，
 * 透明区域被深色背景渗透 → 黑色线条/文字被"吞掉"。给所有讲义图加白底 + 圆角内边距
 * 兜底（GitHub README 同款方案）。浅色主题多包一层白也无视觉副作用。 */
.markdown-body img {
  max-width: 100%;
  height: auto;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  /* 给一个微妙的描边让白底跟讲义深色背景边界更柔和 */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  display: block;
  margin: 0.8em auto;
}

/* ===== 图片删除按钮（hover 浮现的 ✕） =====
 * <span class="lecture-img-wrap"> 包裹 <img>，X 按钮 absolute 浮右上角。
 * 用 span（不是 div）是因为 markdown-it 把图片渲染到 <p> 里，<p> 内只能放
 * inline / phrasing content；span 是合法的。span 设 display:block 仍是有效 HTML5。 */
.lecture-img-wrap {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.8em auto;   /* 移植自 .markdown-body img 原来的居中 margin */
  line-height: 0;        /* 消除 inline 行高造成的 img 下方空隙 */
}
.lecture-img-wrap img {
  display: block;
  max-width: 100%;
  margin: 0;             /* 被 wrap 接管居中，img 自身 margin 归零 */
}

.lecture-img-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: rgba(239, 68, 68, 0.92);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: opacity 120ms ease, transform 120ms ease, background 120ms ease;
  z-index: 2;            /* 浮在 img 白底 padding 之上 */
}
.lecture-img-wrap:hover .lecture-img-delete-btn,
.lecture-img-delete-btn:focus-visible {
  opacity: 1;
}
.lecture-img-delete-btn:hover {
  transform: scale(1.08);
  background: rgb(239, 68, 68);
}
.lecture-img-delete-btn:active {
  transform: scale(0.95);
}

/* 公式溢出滚动而不撑大页面 */
.markdown-body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

/* ===== flash highlight (5s 后渐隐) ===== */

[data-source-line].flash-changed {
  background: rgba(76, 175, 80, 0.20);
  outline: 2px solid rgba(76, 175, 80, 0.45);
  outline-offset: 2px;
  border-radius: 6px;
  transition: background 1.2s ease-out 3.6s, outline-color 1.2s ease-out 3.6s;
  animation: flash-in 240ms ease-out;
}

@keyframes flash-in {
  from { background: rgba(76, 175, 80, 0.55); }
  to { background: rgba(76, 175, 80, 0.20); }
}

/* 让选中状态在自身渲染 markdown 内更柔和 */
::selection {
  background: color-mix(in srgb, var(--vscode-editor-selectionBackground, var(--accent)) 80%, transparent);
}

/* ===== 蓝色按钮：固定在讲义右上角，始终可点 ===== */
/* 旧设计是浮动 chip 跟着选区走，结果代码块 / 跨块选区 / 没选区都召不出来。
   现在改成右上角常驻入口：有选区 → 针对选区提问；无选区 → 自动注入全文。 */
.lecture-chip {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 1000;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--vscode-button-foreground);
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.30);
  transition: transform 120ms ease, box-shadow 120ms ease;
  user-select: none;
}

.lecture-chip:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.36);
}

.lecture-chip:active {
  transform: scale(0.96);
}

/* ===== 可视化建议卡片 (cc-suggest) ===== */
/* AI 生成讲义时插入 <div class="cc-suggest" data-kind="image|widget" data-query="...">
   渲染成"虚线框 + 标题 + 几个按钮"的卡片，让用户一键触发对应操作。 */
div.cc-suggest {
  margin: 18px 0;
}
.cc-suggest-card {
  padding: 14px 16px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--vscode-textLink-foreground, #4dabf7) 8%, var(--vscode-editor-background));
  border: 1.5px dashed color-mix(in srgb, var(--vscode-textLink-foreground, #4dabf7) 55%, transparent);
  position: relative;
  transition: opacity 200ms ease;
}
.cc-suggest-busy .cc-suggest-card {
  opacity: 0.55;
  pointer-events: none;
}
.cc-suggest-header {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.cc-suggest-icon {
  font-size: 16px;
}
.cc-suggest-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: color-mix(in srgb, var(--vscode-textLink-foreground, #4dabf7) 80%, var(--vscode-foreground));
  text-transform: uppercase;
}
.cc-suggest-body {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--vscode-foreground);
  margin-bottom: 12px;
}
.cc-suggest-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cc-suggest-btn {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.12));
  background: transparent;
  color: var(--vscode-foreground);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.cc-suggest-btn:hover {
  background: color-mix(in srgb, var(--vscode-button-background) 18%, transparent);
  border-color: color-mix(in srgb, var(--vscode-foreground) 30%, transparent);
}
.cc-suggest-btn.primary {
  background: var(--vscode-button-background, #0e639c);
  color: var(--vscode-button-foreground, #fff);
  border-color: var(--vscode-button-background, #0e639c);
  font-weight: 500;
}
.cc-suggest-btn.primary:hover {
  background: var(--vscode-button-hoverBackground, #1177bb);
  border-color: var(--vscode-button-hoverBackground, #1177bb);
}
.cc-suggest-btn.ghost {
  opacity: 0.7;
}
.cc-suggest-btn.ghost:hover {
  opacity: 1;
  background: color-mix(in srgb, #ef4444 12%, transparent);
  border-color: color-mix(in srgb, #ef4444 50%, transparent);
  color: #ef4444;
}

/* ===== 视频卡片（粘贴 YouTube / B 站 URL 后嵌入）===== */
.cc-video {
  margin: 18px 0;
}
.cc-video-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--vscode-editor-background) 92%, var(--vscode-foreground) 8%);
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.08));
  color: var(--vscode-foreground);
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.cc-video-card:hover {
  background: color-mix(in srgb, var(--vscode-editor-background) 80%, var(--vscode-foreground) 20%);
  border-color: color-mix(in srgb, var(--vscode-foreground) 35%, transparent);
  transform: translateY(-1px);
}
.cc-video-thumb {
  flex-shrink: 0;
  position: relative;
  width: 168px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a1a center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cc-video-thumb-fallback {
  color: #888;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.05em;
}
.cc-video-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  pointer-events: none;
}
.cc-video-meta {
  flex: 1;
  min-width: 0;
}
.cc-video-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 6px;
}
.cc-video-sub {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: color-mix(in srgb, var(--vscode-descriptionForeground, var(--vscode-foreground)) 80%, transparent);
}
.cc-video-platform, .cc-video-t {
  white-space: nowrap;
}

/* ===== 右键菜单 ===== */
.lecture-context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 180px;
  padding: 4px;
  background: var(--vscode-menu-background, var(--vscode-editor-background, #252526));
  color: var(--vscode-menu-foreground, var(--vscode-foreground));
  border: 1px solid var(--vscode-menu-border, var(--vscode-panel-border, rgba(255,255,255,0.12)));
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  font-family: inherit;
}
.lecture-context-menu[hidden] { display: none !important; }
.lecture-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 7px 12px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.lecture-context-menu button:hover {
  background: var(--vscode-menu-selectionBackground, var(--vscode-list-activeSelectionBackground, #094771));
  color: var(--vscode-menu-selectionForeground, var(--vscode-list-activeSelectionForeground, #fff));
}

/* ===== popover (评论框) ===== */

.lecture-comment-popover {
  /* position: fixed 让 popover 锚在 chip 左侧（顶部与 chip 对齐，紧贴右上角），
     用户滚动讲义不会改变 popover 位置。
     Ctrl+滚轮缩放时 body.zoom≠1，但 popover 高度由内容（mode-bar/quote/textarea/
     actions）决定，本身是 shrink-to-fit，没有写死的 height/max-height，所以不会
     像 bubble 那样被 zoom 撑出视口；位置由 showPopoverFor 按 scale 换算。 */
  position: fixed;
  z-index: 1001;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-popover);
  animation: pop-in 160ms ease-out;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.popover-heading {
  font-size: 12px;
  font-weight: 500;
  color: color-mix(in srgb, var(--vscode-foreground) 70%, transparent);
  margin-bottom: 6px;
}

.popover-mode-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  padding: 3px;
  background: var(--vscode-input-background, rgba(0,0,0,0.2));
  border-radius: 8px;
}

.popover-mode-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--vscode-foreground);
  padding: 6px 8px;
  font-size: 11.5px;
  white-space: nowrap;
  border-radius: 6px;
  cursor: pointer;
  transition: 120ms ease;
  white-space: nowrap;
}

.popover-mode-btn:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.popover-mode-btn.active {
  background: var(--accent);
  color: var(--vscode-button-foreground, #fff);
  font-weight: 600;
}

.popover-quote {
  font-size: 12px;
  color: color-mix(in srgb, var(--vscode-descriptionForeground, var(--vscode-foreground)) 80%, transparent);
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  padding: 6px 10px;
  border-radius: 0 6px 6px 0;
  max-height: 80px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

.popover-textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  background: var(--vscode-input-background);
  color: var(--vscode-input-foreground);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.popover-textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent);
}

.popover-textarea.empty-flash {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 30%, transparent);
}

.popover-actions,
.bubble-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* 气泡的操作按钮（关闭/采纳/丢弃）做成粘性底栏：长答案时整个气泡内滚，按钮始终钉在
   气泡可视底部，不用滚到底才够得着（配合 positionBubble 的动态 max-height，治"按钮被
   视口截断、要缩放才点得到"）。不透明底色遮住滚到下面的内容，顶部细线与正文分隔。 */
.bubble-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  padding-top: 8px;
  background: var(--surface-2);
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.btn-primary,
.btn-ghost {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12.5px;
  cursor: pointer;
  transition: 120ms ease;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-color: color-mix(in srgb, var(--accent) 76%, var(--border));
  color: var(--vscode-button-foreground);
}

.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--vscode-foreground);
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--surface-1) 80%, transparent);
}

/* ===== suggestion bubble ===== */

.lecture-suggestion-bubble {
  /* position: fixed 跟 chip / popover 一致，锚到视口右上角不跟随讲义滚动 */
  position: fixed;
  z-index: 999;
  width: 440px;
  max-width: calc(100vw - 32px);
  /* 视口高度上限 + 自身滚动：widget 内容超长时让整个 bubble 内部滚（header
     + body + actions 一起），而不是 .bubble-body 单独滚 → 用户拖滚动条
     永远能看到 header 跟 actions。
     注意：max-height 会被 JS（positionBubble）动态覆盖成按 scale 换算后的值，
     这里只是兜底（scale=1 时等价）。calc(100vh - 32px) 在 body.zoom≠1 下视觉会
     被 ×scale，但 JS 覆盖后就不走这条了。 */
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  box-shadow: var(--shadow-popover);
  padding: 12px 14px 14px 18px;
  animation: bubble-in 180ms ease-out;
  border-left: 3px solid var(--accent);
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.lecture-suggestion-bubble.failed { border-left-color: var(--danger); }
.lecture-suggestion-bubble.applied { border-left-color: var(--success); }

/* streaming：AI 还在逐字写入时，bubble 显示闪烁光标 */
.lecture-suggestion-bubble.streaming .bubble-body[data-streaming-body]::after {
  content: '▌';
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  opacity: 0.6;
  animation: lecture-stream-blink 0.9s steps(2, start) infinite;
}
@keyframes lecture-stream-blink {
  to { opacity: 0; }
}

.bubble-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.bubble-tag {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  background: var(--accent-soft);
  color: color-mix(in srgb, var(--vscode-foreground) 92%, transparent);
  padding: 2px 8px;
  border-radius: 999px;
}

.lecture-suggestion-bubble.failed .bubble-tag,
.bubble-tag-error {
  background: color-mix(in srgb, var(--danger) 20%, transparent);
  color: color-mix(in srgb, var(--danger) 92%, white 6%);
}

.lecture-suggestion-bubble.applied .bubble-tag {
  background: var(--success-soft);
  color: color-mix(in srgb, var(--success) 92%, white 6%);
}

.bubble-range {
  font-size: 11px;
  color: color-mix(in srgb, var(--vscode-descriptionForeground, var(--vscode-foreground)) 80%, transparent);
  font-variant-numeric: tabular-nums;
}

/* ✕ 取消按钮：仅在 pending/streaming bubble 显示，靠 header 右侧 */
.bubble-cancel-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--vscode-foreground) 20%, transparent);
  color: color-mix(in srgb, var(--vscode-foreground) 75%, transparent);
  font: inherit;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.bubble-cancel-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger, #ef4444) 14%, transparent);
  border-color: color-mix(in srgb, var(--danger, #ef4444) 60%, transparent);
  color: var(--danger, #ef4444);
}
.bubble-cancel-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.bubble-body {
  font-size: 13.5px;
  line-height: 1.7;
  /* 不再 max-height + overflow:auto。bubble 外层已经做了视口高度限制 +
     自身滚动；body 内层再加一层会形成嵌套滚动条，长 widget 切两次 */
  background: color-mix(in srgb, var(--vscode-editor-background) 82%, transparent);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.bubble-body p { margin: 0.4em 0; }
.bubble-body pre { margin: 0.4em 0; }

/* loading dots */

.bubble-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px;
  justify-content: center;
}

.bubble-loading .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
  animation: dot-pulse 1.05s infinite ease-in-out;
}
.bubble-loading .dot:nth-child(2) { animation-delay: 0.18s; }
.bubble-loading .dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== toasts ===== */

.lecture-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.lecture-toast {
  pointer-events: auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--vscode-editor-background) 86%, var(--surface-2));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-popover);
  font-size: 12.5px;
  max-width: 360px;
  animation: toast-in 180ms ease-out;
}

.lecture-toast.success {
  border-color: color-mix(in srgb, var(--success) 60%, var(--border));
  color: color-mix(in srgb, var(--success) 92%, white 6%);
}

.lecture-toast.error {
  border-color: color-mix(in srgb, var(--danger) 60%, var(--border));
  color: color-mix(in srgb, var(--danger) 92%, white 6%);
}

.lecture-toast.warn {
  border-color: color-mix(in srgb, var(--warn) 60%, var(--border));
  color: color-mix(in srgb, var(--warn) 92%, white 6%);
}

/* ===== undo pill ===== */

.lecture-undo-pill {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--vscode-editor-foreground);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-popover);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.lecture-undo-pill.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.lecture-undo-pill:hover {
  background: var(--surface-3);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
}

.lecture-toast.fading {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 280ms ease-out, transform 280ms ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 通用图表外壳：mermaid / dot 都用，提供 toolbar + 源码切换面板 ===== */
.cc-chart-wrap {
  margin: 16px 0;
  border-radius: 10px;
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.08));
  background: var(--vscode-editor-background, transparent);
  overflow: hidden;
}
.cc-chart-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.06));
  background: color-mix(in srgb, var(--vscode-sideBar-background, #252526) 70%, transparent);
}
.cc-chart-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.62;
}
.cc-chart-spacer { flex: 1; }
.cc-chart-btn {
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.1));
  color: var(--vscode-foreground);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 120ms ease, background 120ms ease;
  font-family: inherit;
}
.cc-chart-btn:hover {
  opacity: 1;
  background: color-mix(in srgb, var(--vscode-button-background) 18%, transparent);
}
.cc-chart-source-panel {
  margin: 0;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--vscode-editor-background) 96%, var(--vscode-foreground) 4%);
  border-top: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.06));
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  max-height: 400px;
  /* 关键：可选中文字，user-select: text 让用户拖蓝色按钮的"基于选区"流程能拿到 */
  user-select: text;
  -webkit-user-select: text;
}
.cc-chart-source-panel.hidden { display: none; }
.cc-chart-source-panel code {
  font-family: inherit;
  white-space: pre;
  user-select: text;
}

/* 把 .mermaid-rendered / .graphviz-rendered 的外边距和边框去掉 —— 它们现在
   是 .cc-chart-wrap 的子元素，外壳已经处理了 margin / border */
.cc-chart-wrap .mermaid-rendered,
.cc-chart-wrap .graphviz-rendered {
  margin: 0;
  border: 0;
  border-radius: 0;
}

/* ===== Mermaid 视觉化 ===== */
.mermaid-rendered {
  margin: 16px 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--vscode-editor-background, transparent);
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.08));
  overflow-x: auto;
  text-align: center;
}
.mermaid-rendered svg {
  max-width: 100%;
  height: auto;
}

/* CSS 兜底：即使 themeVariables 漏覆盖某类节点（如自定义 shape），强制把
   svg 内文字 / 描边的"中性色"撞回 VS Code 前景色。注意不要碰用户用 style
   显式上的颜色（如 stroke=#ff0000），所以只覆盖 fill/stroke 包含
   neutral gray (#aaa-#ccc-#888-rgb(170,..)) 的元素。
   实操更保险：只把 mermaid 默认的 stroke / fill 颜色（#333 / #000 / 灰系）
   兜底为 currentColor。但风险高，先用 text fill 兜底。 */
.mermaid-rendered svg .nodeLabel,
.mermaid-rendered svg .edgeLabel,
.mermaid-rendered svg .label,
.mermaid-rendered svg .messageText,
.mermaid-rendered svg .actor-text,
.mermaid-rendered svg .titleText,
.mermaid-rendered svg foreignObject div,
.mermaid-rendered svg foreignObject span {
  color: var(--vscode-foreground) !important;
}
.mermaid-rendered svg text {
  /* 只有 fill 是 none / 接近灰白时才覆盖；其它情况（用户/themeVariables 主动设了色）保留 */
  fill: var(--vscode-foreground);
}
.mermaid-rendered svg text[fill="#333"],
.mermaid-rendered svg text[fill="#333333"],
.mermaid-rendered svg text[fill="black"],
.mermaid-rendered svg text[fill="rgb(51, 51, 51)"] {
  fill: var(--vscode-foreground) !important;
}
.mermaid-fallback {
  margin: 16px 0;
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--vscode-charts-yellow, #d4a017) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--vscode-charts-yellow, #d4a017) 30%, transparent);
}
.mermaid-fallback-banner {
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--vscode-charts-yellow, #d4a017);
}
.mermaid-fallback pre {
  background: var(--vscode-editor-background, #1e1e1e);
  padding: 8px;
  border-radius: 4px;
  margin: 6px 0;
  overflow-x: auto;
}
.mermaid-fallback a {
  font-size: 11px;
  color: var(--vscode-textLink-foreground);
}

/* ===== GraphViz / DOT 视觉化 ===== */
/* DOT 图：固定"白底深字"专业制图风格，不跟随 VS Code 主题色。
   原因：之前用 var(--vscode-foreground)，Dark+ 默认主题下是 #cccccc 浅灰，
   暗背景上对比度只有 4.5:1（WCAG AA 边缘），用户反馈"看不清"。
   现在锁死白底深字，任何主题下文字都清晰可读，DOT 看起来像传统流程图。
   inline fill="black" 由 renderGraphviz 的 SVG 后处理移除（main.js）。 */
.graphviz-rendered {
  margin: 16px 0;
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  overflow-x: auto;
  text-align: center;
}
.graphviz-rendered svg {
  max-width: 100%;
  height: auto;
}
.graphviz-rendered svg text {
  fill: #111827;  /* 深灰黑文字 */
  font-weight: 500;
}
.graphviz-rendered svg .node ellipse,
.graphviz-rendered svg .node polygon,
.graphviz-rendered svg .node path,
.graphviz-rendered svg .node circle {
  fill: #ffffff;    /* 节点白底 */
  stroke: #374151;  /* 深灰节点边框 */
}
/* 边线（贝塞尔 path）：只描边不填充。
   之前 .edge path 和 .edge polygon 合并写了 fill: #374151，
   直边没事，但弯曲 path 的"首尾连线围出区域"被实心填充 → 视觉上像"箭头拖尾"楔形。 */
.graphviz-rendered svg .edge path {
  stroke: #374151;
  fill: none;
}
/* 箭头三角（polygon）：填充 + 描边都用同色，让箭头实心醒目 */
.graphviz-rendered svg .edge polygon {
  stroke: #374151;
  fill: #374151;
}
/* cluster（子图）：浅灰底 + 中灰边框，让节点群"区域感"明显 */
.graphviz-rendered svg .cluster polygon {
  fill: rgba(243, 244, 246, 0.55);
  stroke: #9ca3af;
}
.graphviz-rendered svg .cluster text {
  fill: #111827;
  font-weight: 600;  /* cluster 标题更粗 */
}

.graphviz-fallback {
  margin: 16px 0;
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--vscode-charts-yellow, #d4a017) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--vscode-charts-yellow, #d4a017) 30%, transparent);
}
.graphviz-fallback-banner {
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--vscode-charts-yellow, #d4a017);
}
.graphviz-fallback pre {
  background: var(--vscode-editor-background, #1e1e1e);
  padding: 8px;
  border-radius: 4px;
  margin: 6px 0;
  overflow-x: auto;
}

/* ===== 交互式 Widget（iframe sandbox）===== */
.cc-widget-container {
  margin: 16px 0;
  border-radius: 10px;
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.08));
  background: var(--vscode-editor-background, transparent);
  overflow: hidden;
  position: relative;
}
.cc-widget-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.06));
  background: color-mix(in srgb, var(--vscode-sideBar-background, #252526) 70%, transparent);
}
.cc-widget-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.62;
}
.cc-widget-spacer { flex: 1; }
.cc-widget-btn {
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.1));
  color: var(--vscode-foreground);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 120ms ease, background 120ms ease;
  font-family: inherit;
}
.cc-widget-btn:hover {
  opacity: 1;
  background: color-mix(in srgb, var(--vscode-button-background) 18%, transparent);
}
/* 高度被自动锁定时给 ↻ 按钮加个橙色提示，告诉用户"我已经锁住了，
   如果你想再测一次就点 ↻"。功能没区别（reload 始终能重测），只是视觉提示。 */
.cc-widget-container[data-height-locked] .cc-widget-btn[data-action="reload"] {
  border-color: color-mix(in srgb, #f59e0b 60%, var(--vscode-panel-border));
  color: #f59e0b;
  opacity: 1;
}
.cc-widget-container[data-height-locked] .cc-widget-btn[data-action="reload"]:hover {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
}
.cc-widget-iframe {
  width: 100%;
  border: 0;
  display: block;
  background: transparent;
}
.cc-widget-error {
  padding: 8px 12px;
  font-size: 11.5px;
  border-top: 1px solid color-mix(in srgb, #ef4444 40%, var(--vscode-panel-border));
  background: color-mix(in srgb, #ef4444 10%, transparent);
  color: #ef4444;
  white-space: pre-wrap;
}
.cc-widget-error.hidden { display: none; }
.cc-widget-console {
  padding: 6px 12px;
  max-height: 200px;
  overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  background: color-mix(in srgb, var(--vscode-editor-background) 95%, var(--vscode-foreground) 5%);
  border-top: 1px dashed var(--vscode-panel-border, rgba(255,255,255,0.06));
}
.cc-widget-console.hidden { display: none; }
.cc-widget-console-line {
  padding: 1px 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.cc-widget-console-line.level-log { color: var(--vscode-foreground); opacity: 0.75; }
.cc-widget-console-line.level-warn { color: var(--vscode-charts-yellow, #d4a017); }
.cc-widget-console-line.level-error { color: #ef4444; }

.cc-widget-source-panel {
  margin: 0;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--vscode-editor-background) 96%, var(--vscode-foreground) 4%);
  border-top: 1px solid var(--vscode-panel-border, rgba(255,255,255,0.06));
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  max-height: 400px;
}
.cc-widget-source-panel.hidden { display: none; }
.cc-widget-source-panel code {
  font-family: inherit;
  white-space: pre;
}

/* ===== Q&A 折叠块（wrapAsCallout 写回讲义的格式）===== */
.markdown-body details.cc-qa {
  margin: 1.2em 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--vscode-panel-border) 70%, transparent);
  border-left: 3px solid var(--vscode-textLink-foreground, #4dabf7);
  border-radius: 8px;
  background: color-mix(in srgb, var(--vscode-editor-background) 92%, var(--vscode-textLink-foreground) 8%);
  overflow: hidden;
}

.markdown-body details.cc-qa > summary {
  cursor: pointer;
  padding: 10px 14px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  font-size: 0.95em;
  line-height: 1.5;
  transition: background-color 120ms ease;
}

.markdown-body details.cc-qa > summary::-webkit-details-marker { display: none; }

.markdown-body details.cc-qa > summary::before {
  content: '▸';
  font-size: 0.8em;
  opacity: 0.55;
  transition: transform 160ms ease;
  flex: 0 0 auto;
}

.markdown-body details.cc-qa[open] > summary::before {
  transform: rotate(90deg);
}

.markdown-body details.cc-qa > summary:hover {
  background: color-mix(in srgb, var(--vscode-textLink-foreground) 6%, transparent);
}

.markdown-body details.cc-qa > summary strong {
  flex: 0 0 auto;
  color: var(--vscode-textLink-foreground, #4dabf7);
}

.markdown-body details.cc-qa[open] > summary {
  border-bottom: 1px dashed color-mix(in srgb, var(--vscode-panel-border) 60%, transparent);
}

/* 折叠 body 用 first-child margin 处理：去掉顶部多余空白 */
.markdown-body details.cc-qa > *:not(summary) {
  margin-left: 14px;
  margin-right: 14px;
}
.markdown-body details.cc-qa > *:nth-child(2) { margin-top: 12px; }
.markdown-body details.cc-qa > *:last-child { margin-bottom: 12px; }
