/* ============================================
   qfire.cn 代码块美化 - 子比主题兼容版
   配合 Prism.js 语法高亮使用
   ============================================ */

/* --- 文章内容区代码块容器 --- */
.wp-posts-content pre[class*="language-"],
.wp-posts-content pre.wp-block-code,
.wp-posts-content pre:not(.wp-block-code) {
    position: relative;
    margin: 1.5em 0;
    border-radius: 10px;
    overflow: hidden;
    background: #1e1e2e !important;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 0 !important;
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 14px;
    line-height: 1.7;
}

/* 代码内容区 padding */
.wp-posts-content pre[class*="language-"] code,
.wp-posts-content pre.wp-block-code code,
.wp-posts-content pre code {
    display: block;
    padding: 18px 20px !important;
    overflow-x: auto;
    background: transparent !important;
    color: #cdd6f4 !important;
    margin: 0 !important;
    border: none !important;
    font-size: inherit;
    line-height: inherit;
    tab-size: 4;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* 滚动条美化 */
.wp-posts-content pre code::-webkit-scrollbar {
    height: 6px;
}
.wp-posts-content pre code::-webkit-scrollbar-track {
    background: transparent;
}
.wp-posts-content pre code::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}
.wp-posts-content pre code::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --- 语言标签（自动显示在右上角） --- */
.wp-posts-content pre[class*="language-"]::before {
    content: attr(data-language);
    position: absolute;
    top: 0;
    right: 0;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #89b4fa;
    background: rgba(255, 255, 255, 0.04);
    border-bottom-left-radius: 8px;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 2;
    pointer-events: none;
}

/* --- 复制按钮 --- */
.code-copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    background: rgba(30, 30, 46, 0.8);
    color: #a6adc8;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 3;
    opacity: 0;
    backdrop-filter: blur(4px);
}

.wp-posts-content pre:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #cdd6f4;
    border-color: rgba(255, 255, 255, 0.2);
}

.code-copy-btn.copied {
    color: #a6e3a1;
    border-color: rgba(166, 227, 161, 0.3);
}

/* 有语言标签时，复制按钮左移避免重叠 */
.wp-posts-content pre[class*="language-"] .code-copy-btn {
    right: auto;
    left: 8px;
}

/* --- Prism.js 语法高亮颜色（Catppuccin Mocha） --- */
.wp-posts-content .token.keyword    { color: #cba6f7; }
.wp-posts-content .token.function   { color: #89b4fa; }
.wp-posts-content .token.string     { color: #a6e3a1; }
.wp-posts-content .token.number     { color: #fab387; }
.wp-posts-content .token.comment    { color: #6c7086; font-style: italic; }
.wp-posts-content .token.operator   { color: #89dceb; }
.wp-posts-content .token.class-name { color: #f9e2af; }
.wp-posts-content .token.tag        { color: #f38ba8; }
.wp-posts-content .token.attr-name  { color: #f9e2af; }
.wp-posts-content .token.attr-value { color: #a6e3a1; }
.wp-posts-content .token.builtin    { color: #fab387; }
.wp-posts-content .token.variable   { color: #f5c2e7; }
.wp-posts-content .token.regex      { color: #f38ba8; }
.wp-posts-content .token.punctuation { color: #bac2de; }
.wp-posts-content .token.selector   { color: #f38ba8; }
.wp-posts-content .token.property   { color: #89b4fa; }
.wp-posts-content .token.boolean    { color: #fab387; }
.wp-posts-content .token.constant   { color: #fab387; }
.wp-posts-content .token.important  { color: #cba6f7; font-weight: bold; }
.wp-posts-content .token.deleted    { color: #f38ba8; background: rgba(243, 139, 168, 0.1); }
.wp-posts-content .token.inserted   { color: #a6e3a1; background: rgba(166, 227, 161, 0.1); }

/* --- 行号样式（Prism Line Numbers 插件） --- */
.wp-posts-content pre[class*="language-"].line-numbers {
    padding-left: 3.5em !important;
}

.wp-posts-content .line-numbers-rows {
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding-right: 8px;
    margin-right: 12px;
}

.wp-posts-content .line-numbers-rows > span::before {
    color: rgba(255, 255, 255, 0.2);
    font-size: 12px;
}

/* --- 高亮行（Prism Line Highlight 插件） --- */
.wp-posts-content .line-highlight {
    background: rgba(249, 226, 175, 0.08) !important;
}

/* --- 内联代码（文章中的小代码片段） --- */
.wp-posts-content code:not([class*="language-"]):not(pre code) {
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(253, 153, 153, 0.15) !important;
    border: 1px solid rgba(253, 153, 153, 0.15);
    color: #ff3c98 !important;
    font-size: 0.9em;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    word-break: break-word;
}

/* --- 响应式 --- */
@media (max-width: 768px) {
    .wp-posts-content pre[class*="language-"],
    .wp-posts-content pre.wp-block-code,
    .wp-posts-content pre:not(.wp-block-code) {
        border-radius: 8px;
        font-size: 12px;
    }
    .wp-posts-content pre[class*="language-"] code,
    .wp-posts-content pre.wp-block-code code,
    .wp-posts-content pre code {
        padding: 14px 14px !important;
    }
    .code-copy-btn {
        opacity: 1; /* 移动端始终显示 */
        font-size: 11px;
        padding: 3px 8px;
    }
}

/* --- 深色模式兼容（子比主题暗色模式） --- */
body.dark .wp-posts-content pre[class*="language-"],
body.dark .wp-posts-content pre.wp-block-code,
body.dark .wp-posts-content pre:not(.wp-block-code) {
    background: #11111b !important;
    border-color: rgba(255, 255, 255, 0.04);
}

body.dark .code-copy-btn {
    background: rgba(17, 17, 27, 0.8);
}

/* --- 加载动画 --- */
@keyframes codeFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wp-posts-content pre[class*="language-"],
.wp-posts-content pre.wp-block-code {
    animation: codeFadeIn 0.3s ease-out;
}
