/* ============================================================================
 * markdown.css — 予你 3.0 · 聊天富文本样式（Markdown / KaTeX / 代码高亮）
 * 只作用于 .bubble.md-rendered 内部；375 / 390 / 430 三档都要不横向溢出。
 * 颜色尽量取 tokens.css 变量，取不到时用兜底值。
 * ========================================================================== */

/* ---------- 气泡容器 ---------- */
.bubble.md-rendered {
  display: inline-block;
  max-width: 100%;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble.md-rendered > :first-child { margin-top: 0 !important; }
.bubble.md-rendered > :last-child { margin-bottom: 0 !important; }
/* 含代码 / 公式 / 表格的消息略放宽一点（仍受气泡 max-width 与容器限制） */
.bubble.md-wide { max-width: 100%; }

/* ---------- 段落 / 标题 ---------- */
.md-p { margin: 0 0 8px; }
.md-p:last-child { margin-bottom: 0; }
.md-h { font-weight: 800; line-height: 1.38; margin: 12px 0 6px; color: inherit; }
.md-h1 { font-size: 18px; }
.md-h2 { font-size: 17px; }
.md-h3 { font-size: 16px; }
.md-h4 { font-size: 15.5px; }
.md-h5 { font-size: 15px; }
.md-h6 { font-size: 14.5px; color: inherit; opacity: .9; }

/* ---------- 列表 ---------- */
.md-ul, .md-ol { margin: 6px 0 8px; padding-left: 20px; }
.md-ul:last-child, .md-ol:last-child { margin-bottom: 0; }
.md-ul { list-style: disc; }
.md-ol { list-style: decimal; }
.md-li { margin: 3px 0; }
.md-li > .md-ul, .md-li > .md-ol { margin: 3px 0 1px; }
.md-ul.md-sub, .md-ol.md-sub { padding-left: 18px; }
.md-ul.md-sub { list-style: circle; }

/* ---------- 引用 ---------- */
.md-quote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid rgba(94, 124, 255, .55);
  background: rgba(94, 124, 255, .08);
  border-radius: 0 8px 8px 0;
  color: inherit;
  opacity: .96;
}
.md-quote .md-p { margin-bottom: 4px; }

/* ---------- 分割线 ---------- */
.md-hr { border: 0; border-top: 1px solid rgba(20, 30, 60, .14); margin: 10px 0; }

/* ---------- 行内代码 ---------- */
.md-icode {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .9em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(20, 28, 50, .08);
  color: inherit;
  overflow-wrap: anywhere;
}

/* ---------- 代码块 ---------- */
.md-code {
  position: relative;
  margin: 8px 0;
  border-radius: 12px;
  background: #1E2430;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
}
.md-pre {
  margin: 0;
  padding: 11px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.md-code.has-lang .md-pre { padding-top: 25px; }
.md-code-body {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.62;
  color: #E6EDF3;
  white-space: pre;
  tab-size: 4;
  -moz-tab-size: 4;
}
.md-code-lang {
  position: absolute;
  top: 6px;
  left: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #7E8CA0;
  pointer-events: none;
}
.md-copy {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 2;
  height: 22px;
  padding: 0 8px;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 7px;
  background: rgba(255, 255, 255, .10);
  color: #C9D4E3;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, color .15s ease;
}
.md-copy:hover, .md-copy:focus-visible { background: rgba(255, 255, 255, .2); color: #fff; outline: none; }
.md-copy:active { transform: scale(.96); }
.md-copy.ok { color: #9BE7B0; border-color: rgba(155, 231, 176, .45); }
/* 小屏点按区域补足（视觉不变） */
.md-copy::after { content: ""; position: absolute; inset: -6px -4px; }

/* highlight.js 配色（深色底，尽量少用色、保证对比度） */
.md-code-body .hljs-keyword,
.md-code-body .hljs-selector-tag,
.md-code-body .hljs-literal,
.md-code-body .hljs-section { color: #C792EA; }
.md-code-body .hljs-string,
.md-code-body .hljs-attr,
.md-code-body .hljs-template-tag,
.md-code-body .hljs-addition { color: #A5E3A0; }
.md-code-body .hljs-number,
.md-code-body .hljs-symbol,
.md-code-body .hljs-bullet { color: #F2C37B; }
.md-code-body .hljs-title,
.md-code-body .hljs-title.function_,
.md-code-body .hljs-function .hljs-title { color: #82AAFF; }
.md-code-body .hljs-comment,
.md-code-body .hljs-quote { color: #7C8AA0; font-style: italic; }
.md-code-body .hljs-variable,
.md-code-body .hljs-params,
.md-code-body .hljs-property { color: #D7DEE8; }
.md-code-body .hljs-type,
.md-code-body .hljs-built_in,
.md-code-body .hljs-class .hljs-title { color: #7FDBCA; }
.md-code-body .hljs-meta,
.md-code-body .hljs-meta .hljs-keyword { color: #F78C6C; }
.md-code-body .hljs-tag,
.md-code-body .hljs-name { color: #FF8FA3; }
.md-code-body .hljs-attribute { color: #A5E3A0; }
.md-code-body .hljs-regexp,
.md-code-body .hljs-link { color: #89DDFF; }
.md-code-body .hljs-deletion { color: #FF8FA3; }
.md-code-body .hljs-emphasis { font-style: italic; }
.md-code-body .hljs-strong { font-weight: 800; }

/* ---------- 数学公式 ---------- */
.md-math {
  margin: 8px 0;
  padding: 2px 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  text-align: center;
}
.md-math .katex-display { margin: .25em 0; }
.md-math .katex-display > .katex { display: inline-block; max-width: none; }
.md-math-inline { white-space: normal; }
.md-math-inline .katex { font-size: 1.04em; }
/* 一句话中间的 $$...$$：按块级公式展示，可横向滚动 */
.md-math-inline-display {
  display: block;
  max-width: 100%;
  margin: 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}
.md-math-inline-display .katex-display { margin: .2em 0; }
.md-math-inline-display .katex-display > .katex { display: inline-block; max-width: none; }
.md-math-pending {
  display: block;
  margin: 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted, #6B7590);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* KaTeX 渲染失败 / 未加载：原样显示 $...$ 源码，不吞内容 */
.md-rawmath {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(20, 28, 50, .07);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------- 表格 ---------- */
.md-table-wrap {
  margin: 8px 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(20, 30, 60, .12);
  border-radius: 10px;
}
.md-table { border-collapse: collapse; width: 100%; font-size: 13px; line-height: 1.5; }
.md-table th, .md-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(20, 30, 60, .10);
  text-align: left;
  white-space: nowrap;
}
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-table thead th { background: rgba(94, 124, 255, .10); font-weight: 800; }
.md-table tbody tr:nth-child(even) { background: rgba(20, 30, 60, .035); }

/* ---------- 链接 / 强调 / 删除线 ---------- */
.md-link { color: #2F63F6; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.md-link:hover { color: #1E4BD8; }
.md-imglink { color: #2F63F6; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.md-link-blocked { color: inherit; opacity: .8; word-break: break-all; }
.md-strong { font-weight: 800; }
.md-em { font-style: italic; }
.md-del { text-decoration: line-through; opacity: .75; }

/* ---------- 用户气泡（蓝紫渐变底）上的配色修正 ---------- */
.me-row .md-icode { background: rgba(255, 255, 255, .22); color: #fff; }
.me-row .md-link, .me-row .md-imglink { color: #fff; text-decoration-color: rgba(255, 255, 255, .75); }
.me-row .md-link-blocked { color: rgba(255, 255, 255, .85); }
.me-row .md-quote {
  border-left-color: rgba(255, 255, 255, .8);
  background: rgba(255, 255, 255, .16);
}
.me-row .md-hr { border-top-color: rgba(255, 255, 255, .35); }
.me-row .md-rawmath { background: rgba(255, 255, 255, .2); }

/* ---------- 深色主题（站点切 dark 时跟着走） ---------- */
html.dark .md-icode, body.dark .md-icode, [data-theme="dark"] .md-icode { background: rgba(255, 255, 255, .12); }
html.dark .md-quote, body.dark .md-quote, [data-theme="dark"] .md-quote { background: rgba(120, 150, 255, .14); }
html.dark .md-hr, body.dark .md-hr, [data-theme="dark"] .md-hr { border-top-color: rgba(255, 255, 255, .18); }
html.dark .md-table-wrap, body.dark .md-table-wrap, [data-theme="dark"] .md-table-wrap { border-color: rgba(255, 255, 255, .16); }
html.dark .md-table th, html.dark .md-table td,
body.dark .md-table th, body.dark .md-table td,
[data-theme="dark"] .md-table th, [data-theme="dark"] .md-table td { border-bottom-color: rgba(255, 255, 255, .12); }
html.dark .md-table thead th, body.dark .md-table thead th, [data-theme="dark"] .md-table thead th { background: rgba(120, 150, 255, .16); }
html.dark .md-table tbody tr:nth-child(even),
body.dark .md-table tbody tr:nth-child(even),
[data-theme="dark"] .md-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .05); }
html.dark .md-rawmath, body.dark .md-rawmath, [data-theme="dark"] .md-rawmath { background: rgba(255, 255, 255, .1); }
html.dark .md-math-pending, body.dark .md-math-pending, [data-theme="dark"] .md-math-pending { color: rgba(255, 255, 255, .55); }

/* ---------- 小屏 ---------- */
@media (max-width: 380px) {
  .md-code-body { font-size: 12px; }
  .md-table { font-size: 12.5px; }
  .md-h1 { font-size: 17px; }
  .md-h2 { font-size: 16px; }
}
/* 很窄的屏（<=340）缩小代码行高，保证不溢出 */
@media (max-width: 340px) {
  .md-code-body { font-size: 11.5px; }
  .md-pre { padding-left: 10px; padding-right: 10px; }
}
/* 动画/无障碍：尊重减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  .md-copy, .md-copy:active { transition: none; transform: none; }
}