/* 基础样式 - 扁平化+折叠功能 */
code[class*=language-], pre[class*=language-] {
    color: #e0e0e0;
    background: #282c34;
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace, sans-serif;
    font-size: 14px;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    word-wrap: normal;
    line-height: 1.6;
    tab-size: 4;
    hyphens: none;
    border-radius: 4px;
}

/* 代码块容器样式 - 核心折叠功能 */
pre[class*=language-] {
    padding: 1.5em; /* 移除行号后，左右内边距一致 */
    margin: 1em 0;
    overflow: auto;
    position: relative;
    border: 1px solid #3b4048;
    transition: border-color 0.3s ease, max-height 0.5s ease;
    
    /* 初始最大高度限制（约15行） */
    max-height: 360px;
}

/* 代码过长时显示滚动条，未过长时正常显示 */
pre[class*=language-].code-collapsed {
    max-height: 360px; /* 保持折叠高度 */
}

pre[class*=language-].code-expanded {
    max-height: none; /* 展开后取消高度限制 */
}

pre[class*=language-]:hover {
    border-color: #4f5663;
}

:not(pre) > code[class*=language-], pre[class*=language-] {
    background: #282c34;
}

/* 行内代码样式 */
:not(pre) > code[class*=language-] {
    padding: 0.2em 0.4em;
    border-radius: 3px;
    white-space: normal;
    background: #3b4048;
    border: 1px solid #4f5663;
}

/* 语法高亮颜色（保持扁平化配色） */
.token.block-comment, .token.cdata, .token.comment, .token.doctype, .token.prolog {
    color: #9aa3b2;
}

.token.punctuation {
    color: #d4d4d4;
}

.token.attr-name, .token.deleted, .token.namespace, .token.tag {
    color: #61aeee;
}

.token.function-name {
    color: #e6c07b;
}

.token.boolean, .token.function, .token.number {
    color: #c17e70;
}

.token.class-name, .token.constant, .token.property, .token.symbol {
    color: #56b6c2;
}

.token.atrule, .token.builtin, .token.important, .token.keyword, .token.selector {
    color: #c678dd;
}

.token.attr-value, .token.char, .token.regex, .token.string, .token.variable {
    color: #98c379;
}

.token.entity, .token.operator, .token.url {
    color: #61aeee;
}

.token.bold, .token.important {
    font-weight: 700;
    color: #61aeee;
}

.token.italic {
    font-style: italic;
}

.token.entity {
    cursor: help;
}

.token.inserted {
    color: #98c379;
}

/* 行高亮样式（移除行号后，调整左侧内边距，避免空白） */
pre[data-line] {
    position: relative;
    padding: 1em !important; /* 左右内边距统一为1em，删除行号预留空间 */
}

.line-highlight {
    position: absolute;
    left: 0;
    right: 0;
    padding: inherit 0;
    margin-top: 1em;
    background: rgba(102, 128, 153, 0.15);
    pointer-events: none;
    line-height: inherit;
    white-space: pre;
    border-left: 3px solid #61aeee;
}

.line-highlight:before, .line-highlight[data-end]:after {
    content: attr(data-start);
    position: absolute;
    top: .4em;
    left: .6em;
    min-width: 1em;
    padding: 0 .5em;
    background-color: #3b4048;
    color: #ccc;
    font: bold 65%/1.5 sans-serif;
    text-align: center;
    vertical-align: .3em;
    border-radius: 2px;
    text-shadow: none;
    box-shadow: none;
}

.line-highlight[data-end]:after {
    content: attr(data-end);
    top: auto;
    bottom: .4em;
}

/* 工具栏与折叠按钮样式 */
div.code-toolbar {
    position: relative;
}

div.code-toolbar > .toolbar {
    position: absolute;
    z-index: 10;
    top: .6em;
    right: .6em;
    transition: opacity .3s ease-in-out;
    opacity: 0;
}

div.code-toolbar:hover > .toolbar {
    opacity: 1;
}

div.code-toolbar:focus-within > .toolbar {
    opacity: 1;
}

/* 折叠/展开按钮样式 */
div.code-toolbar .toolbar-item .toggle-collapse {
    margin-left: 6px;
    padding: 0.2em 0.6em;
    background: #3b4048;
    border: 1px solid transparent;
    border-radius: 2px;
    color: #bbb;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
}

div.code-toolbar .toolbar-item .toggle-collapse:hover {
    color: #fff;
    background: #4f5663;
    border-color: #616875;
}

/* 工具栏其他按钮样式 */
div.code-toolbar > .toolbar > .toolbar-item {
    display: inline-block;
    margin-left: 4px;
}

div.code-toolbar > .toolbar > .toolbar-item > a,
div.code-toolbar > .toolbar > .toolbar-item > button:not(.toggle-collapse),
div.code-toolbar > .toolbar > .toolbar-item > span {
    color: #bbb;
    font-size: .85em;
    padding: 0.2em 0.6em;
    background: #3b4048;
    border-radius: 2px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

div.code-toolbar > .toolbar > .toolbar-item > a:focus,
div.code-toolbar > .toolbar > .toolbar-item > a:hover,
div.code-toolbar > .toolbar > .toolbar-item > button:not(.toggle-collapse):focus,
div.code-toolbar > .toolbar > .toolbar-item > button:not(.toggle-collapse):hover,
div.code-toolbar > .toolbar > .toolbar-item > span:focus,
div.code-toolbar > .toolbar > .toolbar-item > span:hover {
    color: #fff;
    background: #4f5663;
    border-color: #616875;
    text-decoration: none;
}

/* 底部渐变遮罩 - 提示用户内容可展开 */
pre[class*=language-].code-collapsed:after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;
    background: linear-gradient(to top, #282c34 0%, rgba(40, 44, 52, 0) 100%);
    pointer-events: none;
}

/* 响应式调整 - 优化移动端显示（移除行号相关适配） */
@media (max-width: 768px) {
    pre[class*=language-] {
        padding: 1em;
        font-size: 13px;
        max-height: 300px; /* 移动端折叠高度减小 */
    }
}