/* ============================================================
   代码块移动端修复：
   问题：移动端 .hljs 被强制 white-space: pre-wrap 自动换行，
         长代码被外层 overflow:hidden 裁掉，且无法横向滚动。
   修复：移动端改为不换行，整个代码容器横向可滚动。
   ============================================================ */
@media (max-width: 768px) {
  /* 整个代码块容器作为横向滚动容器 */
  .code-pre-wrapper {
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  /* 行号列保持内容宽度，不参与缩放 */
  .code-pre-wrapper .line-numbers-pre {
    flex: 0 0 auto !important;
    white-space: nowrap;
  }

  /* 代码内容：不换行、宽度跟随内容，让横向滚动真正生效 */
  .code-pre-wrapper .code-content {
    overflow: visible !important;
    width: max-content !important;
    min-width: 0 !important;
    max-width: none !important;
    flex: 0 0 auto !important;
    white-space: pre !important;
    word-break: normal !important;
    word-wrap: normal !important;
  }
  .code-pre-wrapper .code-content code,
  .code-pre-wrapper .code-content .line {
    white-space: pre !important;
    word-break: normal !important;
    word-wrap: normal !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  /* 细滚动条，减少对内容遮挡 */
  .code-pre-wrapper::-webkit-scrollbar {
    height: 4px;
  }
  .code-pre-wrapper::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.5);
    border-radius: 2px;
  }
}

/* ============================================================
   流程图 / 结构图（```text 语言）水平居中：
   - 内容宽度 < 可用宽度：整体居中，隐藏行号，作为"图"展示
   - 内容宽度 > 可用宽度：自动回到左对齐 + 横向滚动，
     避免 flex 居中时左侧内容被裁掉
   普通代码块（c/cpp 等）不受影响。
   ============================================================ */
.code-pre-wrapper:has(> .code-content.text) {
  overflow-x: auto;
}

.code-pre-wrapper:has(> .code-content.text) > .line-numbers-pre {
  display: none;
}

.code-pre-wrapper:has(> .code-content.text) > .code-content {
  flex: 0 0 auto !important;
  width: fit-content !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin-inline: auto !important;
}

/* 统一 text 图代码区背景色，避免缩小居中后容器露出灰色形成两层颜色 */
.code-pre-wrapper:has(> .code-content.text) {
  background: #1e1e1e !important;
}
