/* 调整 Markdown 转换后的图片样式 */
.prose img {
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* 代码块圆角与行号对齐优化 */
pre[class*="language-"] {
    border-radius: 0.5rem !important;
    margin: 1.5em 0 !important;
}

/* Prism.js 行号样式修复 - 最高优先级 */
pre[class*="language-"],
pre.line-numbers {
    position: relative !important;
    padding-left: 3.8em !important;
    counter-reset: linenumber !important;
}

pre[class*="language-"] > code,
pre.line-numbers > code {
    padding-left: 0 !important;
    position: relative !important;
    z-index: 1 !important;
    line-height: 1.5 !important; /* 确保行高一致 */
    display: block !important;
}

/* 强制行号显示 - 使用!important确保覆盖 */
.line-numbers-rows {
    position: absolute !important;
    pointer-events: none !important;
    top: 0 !important;
    font-size: 100% !important;
    left: -3.8em !important;
    width: 3em !important;
    letter-spacing: -1px !important;
    border-right: 1px solid #999 !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    background: transparent !important;
    height: auto !important; /* 改为auto，让其自然适应内容高度 */
    min-height: 100% !important;
    line-height: 1.5 !important; /* 与代码行高保持一致 */
}

.line-numbers-rows > span {
    pointer-events: none !important;
    display: block !important;
    counter-increment: linenumber !important;
    line-height: 1.5 !important; /* 与代码行高保持一致 */
    min-height: 1.5em !important; /* 确保最小高度 */
}

.line-numbers-rows > span:before {
    content: counter(linenumber) !important;
    color: #999 !important;
    display: block !important;
    padding-right: 0.8em !important;
    text-align: right !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
    font-size: 0.875em !important;
    line-height: 1.5 !important; /* 与父元素行高一致 */
}

/* 调试行号显示 */
pre.line-numbers {
    position: relative !important;
    padding-left: 3.8em !important;
    counter-reset: linenumber !important;
    border-left: 3px solid #4f46e5 !important; /* 调试用边框 */
}

pre.line-numbers > code {
    position: relative !important;
    z-index: 1 !important;
}

/* 代码块水平滚动条美化 */
pre[class*="language-"]::-webkit-scrollbar {
    height: 8px;
}
pre[class*="language-"]::-webkit-scrollbar-track {
    background: #1e1e1e;
    border-radius: 0 0 0.5rem 0.5rem;
}
pre[class*="language-"]::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 10px;
    border: 2px solid #1e1e1e;
}
pre[class*="language-"]::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* 针对 Firefox 的滚动条样式 */
pre[class*="language-"] {
    scrollbar-width: thin;
    scrollbar-color: #4b5563 #1e1e1e;
}

/* 性能补丁：移除实验性属性，回归稳定方案 */

/* CSDN 风格代码块深度模仿 - 恢复整体感 */
.code-wrapper {
    position: relative;
    margin: 2rem 0;
    border-radius: 8px;
    background: #2d2d2d;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    contain: layout paint;
    overflow: visible; /* 改为visible，让行号可以正常显示 */
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #3d3d3d;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
    position: relative;
    z-index: 20;
}

.code-lang {
    color: #999;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* 顶栏按钮组 */
.code-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-btn-csdn {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #999;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: transparent;
    padding: 2px 4px;
    border-radius: 4px;
}
.action-btn-csdn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* 底部蒙层仅保留视觉提示，移除按钮点击逻辑 */
.code-expand-mask {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to top, #2d2d2d 50%, transparent);
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.3s;
}
.code-wrapper.expanded .code-expand-mask {
    opacity: 0;
}

/* 代码块整体容器 - 移除高度限制 */
.code-wrapper {
    display: flex;
    flex-direction: column;
    overflow: visible; /* 改为visible确保行号完整显示 */
}

/* 代码头部固定 */
.code-header {
    flex-shrink: 0;
    background: #3d3d3d;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 20;
}

/* 代码内容区域可滚动 - 单独控制滚动 */
.code-wrapper pre {
    overflow-y: auto;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    max-height: 400px; /* 将高度限制移到pre元素上 */
    line-height: 1.5 !important; /* 确保行高一致 */
}

/* 行号显示样式 */
pre[class*="language-"] {
    position: relative;
    padding-left: 3.8em !important;
    counter-reset: linenumber;
}

pre[class*="language-"] > code[class*="language-"] {
    position: relative;
    white-space: pre;
    word-wrap: normal;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 100%;
    left: -3.8em;
    width: 3em; /* 固定宽度确保对齐 */
    letter-spacing: -1px;
    border-right: 1px solid #999;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: #999;
    display: block;
    padding-right: 0.8em;
    text-align: right;
}

/* Prism.js 行号样式兼容 */
pre.line-numbers {
    position: relative;
    padding-left: 3.8em;
    counter-reset: linenumber;
}

pre.line-numbers > code {
    position: relative;
    white-space: inherit;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 100%;
    left: -3.8em;
    width: 3em;
    letter-spacing: -1px;
    border-right: 1px solid #999;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: #999;
    display: block;
    padding-right: 0.8em;
    text-align: right;
}

/* 隐藏展开/收起相关元素 */
.code-expand-mask {
    display: none;
}

.toggle-btn {
    display: none;
}

/* 调整 pre 的默认样式以适应容器 */
.code-wrapper pre {
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
}

/* 精准控制：仅针对"行内代码"进行样式优化（排除 pre 内部的代码） */
.prose :not(pre) > code {
    background-color: #f3f4f6;
    color: #4f46e5;
    padding: 0.2rem 0.4rem;
    border-radius: 0.375rem;
    font-weight: 500;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* 去除 Tailwind 默认在行内代码前后添加的引号 */
.prose :not(pre) > code::before,
.prose :not(pre) > code::after {
    content: "" !important;
}

/* 目录 (TOC) 外层容器样式 */
.toc-container {
    background-color: #ffffff;
    border-radius: 1rem;
    padding: 1.25rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 10rem);
}
.toc-container .toctitle {
    flex-shrink: 0;
    font-weight: 800;
    font-size: 0.75rem;
    color: #374151;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed #e5e7eb;
}

/* 目录列表滚动区域 */
.toc-container ul {
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

/* 彻底消除 Markdown 插件生成的内层 .toc 容器样式 */
.toc-container .toc {
    display: contents !important;
}

.toc-container ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.toc-container ul ul {

    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    margin-left: 1rem;
    border-left: 1px solid #f3f4f6;
}
.toc-container li {
    margin-bottom: 0.25rem;
}
.toc-container li:last-child {
    margin-bottom: 0;
}
.toc-container a {
    color: #6b7280;
    font-size: 0.875rem;
    text-decoration: none;
    display: block;
    line-height: 1.6;
    padding: 0.5rem 1rem 0.5rem 1.5rem;
    border-radius: 0.375rem;
    position: relative;
    border-left: 2px solid transparent;
}
.toc-container a:hover {
    color: #4338ca;
    background-color: #f5f3ff;
    padding-left: 1.5rem;
    border-left: 2px solid #c7d2fe;
}
.toc-container a.active {
    color: #3730a3;
    background-color: #e0e7ff;
    font-weight: 600;
    border-left: 4px solid #4f46e5;
    padding-left: 1.25rem;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.1);
}
/* 已移除激活状态的箭头标记 */

/* 脉冲动画 */
@keyframes pulse {
    0% { opacity: 1; transform: translateY(-50%) scale(1); }
    50% { opacity: 0.7; transform: translateY(-50%) scale(1.1); }
    100% { opacity: 1; transform: translateY(-50%) scale(1); }
}

/* 侧边栏吸顶 */
.sticky-sidebar {
    position: sticky;
    top: 6rem;
}

/* 隐藏滚动条但保留功能 */
.toc-container ul::-webkit-scrollbar {
    width: 3px;
}
.toc-container ul::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 10px;
}
.toc-container ul::-webkit-scrollbar-track {
    background: transparent;
}

/* 平滑滚动 */
html {
    scroll-behavior: smooth;
}

/* 隐藏没有内容的目录 */
.toc-container:has(ul:empty) {
    display: none;
}
.toc-container ul:empty {
    display: none;
}

/* 动画效果 */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in-down {
    animation: fadeInDown 0.4s ease-out;
}

/* 彻底移除原生输入框聚焦黑框 */
textarea:focus, input:focus {
    outline: none !important;
    box-shadow: none !important;
}
