:root { 
    --primary: #6366f1; 
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --bg: #f8fafc; 
    --card-bg: #ffffff; 
    --text: #0f172a; 
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #f1f5f9;
    --border-hover: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.08);
    --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; 
    background-color: var(--bg); 
    color: var(--text); 
    margin: 0; 
    padding: 0; 
    line-height: 1.7; 
    -webkit-tap-highlight-color: transparent;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 扩展整体容器宽度，缩小侧边栏，增大主体文章区 */
.layout-container { 
    max-width: 1200px; 
    margin: 25px auto 0 auto; 
    padding: 0 20px; 
    display: grid; 
    grid-template-columns: 1fr 280px; 
    gap: 25px; 
    width: 100%;
}

main { min-width: 0; }

.post-card { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 24px; 
    margin-bottom: 20px; 
    box-shadow: var(--shadow-sm); 
    border: 1px solid var(--border); 
    overflow: visible; 
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.post-card:hover {
    box-shadow: var(--shadow-lg);
}

.post-card-inner {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.post-thumbnail {
    flex-shrink: 0;
    width: 160px;
    height: 100px;
    overflow: hidden;
    border-radius: 8px;
    background: #f1f5f9;
}
.post-thumbnail a {
    display: block;
    width: 100%;
    height: 100%;
}
.post-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
}
.post-thumbnail img:hover {
    transform: scale(1.08);
}

.post-content-wrap {
    flex: 1;
    min-width: 0;
}

.post-card .post-title { 
    margin: 0 0 6px 0; 
    font-size: 1.25rem; 
    font-weight: 700; 
    line-height: 1.4; 
    word-break: break-word; 
}
.post-card .post-title a { color: var(--text); text-decoration: none; transition: color 0.2s; }
.post-card .post-title a:hover { color: var(--primary); }

.post-card .post-excerpt {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 6px;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-card .meta {
    margin-top: auto;
    margin-bottom: 0;
    padding-top: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.post-detail-content { 
    font-size: 1.05rem; 
    line-height: 1.85; 
    color: #334155; 
    margin: 20px 0; 
    word-break: break-word; 
    overflow-wrap: break-word; 
    max-width: 100%;
}
.post-detail-content::after { content: ""; display: table; clear: both; }

.post-detail-content p { 
    margin-top: 0; 
    margin-bottom: 1.6em; 
    line-height: 1.85; 
    letter-spacing: 0.2px; 
    word-break: break-word;
}
.post-detail-content h1, 
.post-detail-content h2, 
.post-detail-content h3, 
.post-detail-content h4 { 
    margin-top: 1.8em; 
    margin-bottom: 0.8em; 
    line-height: 1.4; 
    color: var(--text); 
    font-weight: 700; 
    word-break: break-word;
}
.post-detail-content ul, 
.post-detail-content ol { 
    margin-top: 0; 
    margin-bottom: 1.6em; 
    padding-left: 1.5em; 
    line-height: 1.85; 
}
.post-detail-content li { 
    margin-bottom: 0.5em; 
    word-break: break-word;
}
.post-detail-content blockquote { 
    margin: 1.6em 0; 
    padding: 14px 20px; 
    background: var(--bg); 
    border-left: 4px solid var(--primary); 
    border-radius: 0 8px 8px 0; 
    color: var(--text-secondary); 
    overflow-x: auto;
}
.post-detail-content img { 
    max-width: 100% !important; 
    height: auto !important; 
    border-radius: 8px; 
    margin: 16px 0; 
    display: block; 
    cursor: zoom-in;
}
.post-detail-content pre, 
.post-detail-content table { 
    max-width: 100%; 
    overflow-x: auto; 
    display: block; 
    margin-bottom: 1.6em; 
}

.code-block-wrapper {
    position: relative;
    margin: 1.6em 0;
    border-radius: 8px;
    background: #1e293b;
    overflow: hidden;
}
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0f172a;
    padding: 6px 14px;
    font-size: 0.8rem;
    color: #94a3b8;
    border-bottom: 1px solid #334155;
}
.code-block-header .code-lang {
    font-weight: 600;
    text-transform: uppercase;
}
.code-copy-btn {
    background: #334155;
    color: #f8fafc;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.code-copy-btn:hover {
    background: var(--primary);
    color: #ffffff;
}
.code-copy-btn.copied {
    background: #10b981;
    color: #ffffff;
}
.code-block-wrapper pre {
    margin: 0 !important;
    padding: 14px 16px;
    background: transparent !important;
    color: #f8fafc;
    font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    overflow-x: auto;
}
.code-block-wrapper pre code {
    background: transparent !important;
    padding: 0 !important;
    color: inherit;
    font-family: inherit;
}

.article-right-ad {
    float: right; margin: 10px 0 15px 20px; max-width: 260px; width: 100%;
    background: #ffffff; border: 1px solid var(--border-hover); border-radius: 10px;
    padding: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); text-align: center; position: relative;
}
.article-right-ad .ad-tag { position: absolute; top: 4px; right: 6px; font-size: 0.65rem; color: var(--text-muted); background: rgba(241, 245, 249, 0.9); padding: 1px 5px; border-radius: 4px; line-height: 1; border: 1px solid #e2e8f0; }
.article-right-ad img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 0 auto; }
.article-right-ad .ad-text-box { padding: 16px 10px 8px 10px; font-size: 0.95rem; color: var(--primary); font-weight: 600; line-height: 1.4; word-break: break-all; }
.article-right-ad a { text-decoration: none; display: block; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; font-size: 0.75rem; border-radius: 6px; font-weight: 600; margin-right: 6px; }
.badge-top { background: #fef2f2; color: #ef4444; border: 1px solid #fee2e2; }
.badge-hot { background: #fff7ed; color: #f97316; border: 1px solid #ffedd5; }

.meta { font-size: 0.85rem; color: var(--text-muted); display: flex; gap: 18px; align-items: center; margin-bottom: 15px; flex-wrap: wrap; }

.sidebar { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.widget { background: var(--card-bg); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; }
.widget-title { font-size: 1rem; font-weight: 700; margin: 0 0 12px 0; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.widget-list { list-style: none; padding: 0; margin: 0; }
.widget-list li { margin-bottom: 10px; font-size: 0.88rem; width: 100%; overflow: hidden; }
.widget-list li:last-child { margin-bottom: 0; }

.widget-list a { 
    color: var(--text-secondary); 
    text-decoration: none; 
    display: block; 
    width: 100%;
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
    line-height: 1.6;
    padding: 3px 0;
    transition: color 0.2s;
}
.widget-list a:hover { color: var(--primary); }

.like-section { 
    text-align: center; 
    margin: 40px 0 20px 0; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    gap: 16px; 
    flex-wrap: nowrap; 
    width: 100%;
}
.btn-like {
    background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary);
    padding: 10px 24px; border-radius: 30px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
    transition: all 0.3s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 46px; touch-action: manipulation; white-space: nowrap;
    max-width: 180px; flex: 1;
}
.btn-like:hover, .btn-like:active { background: var(--primary); color: #fff; }
.btn-like:disabled { background: var(--border); color: var(--text-muted); border-color: var(--border); cursor: not-allowed; }

.btn-dislike {
    background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1;
    padding: 10px 24px; border-radius: 30px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
    transition: all 0.3s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 46px; touch-action: manipulation; white-space: nowrap;
    max-width: 180px; flex: 1;
}
.btn-dislike:hover, .btn-dislike:active { background: #64748b; color: #fff; }
.btn-dislike:disabled { background: var(--border); color: var(--text-muted); border-color: var(--border); cursor: not-allowed; }

.read-more-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    background: var(--primary-light);
    padding: 4px 12px;
    min-height: 28px;
    border-radius: 20px;
    transition: all 0.2s;
    touch-action: manipulation;
}
.read-more-link:hover, .read-more-link:active {
    background: var(--primary);
    color: #fff;
}

.btn-load-more {
    background: #ffffff;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 12px 35px;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}
.btn-load-more:hover {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}
.btn-load-more:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    border-color: #cbd5e1;
    cursor: not-allowed;
    box-shadow: none;
}

.comments-section { margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border); overflow: visible; }
.comments-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 20px; }
.comment-item { display: flex; gap: 15px; padding: 18px 0; border-bottom: 1px dashed var(--border); }
.comment-item:last-child { border-bottom: none; }

.comment-avatar img { width: 45px; height: 45px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); background: #f1f5f9; flex-shrink: 0; }
.comment-content-wrap { flex: 1; min-width: 0; }

.comment-meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.comment-user { font-weight: 600; color: var(--text); margin-right: 10px; font-size: 0.95rem; }
.comment-body { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.65; word-break: break-word; }

.comment-form-box { background: var(--bg); padding: 20px; border-radius: 12px; margin-top: 30px; overflow: visible; }
.form-group { margin-bottom: 15px; }
.position-relative { position: relative !important; }

.form-control { width: 100%; padding: 12px; border: 1px solid var(--border-hover); border-radius: 8px; font-family: inherit; font-size: 0.95rem; transition: border-color 0.2s; min-height: 44px; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea.form-control { resize: vertical; min-height: 110px; }

.editor-toolbar { margin-bottom: 8px; position: relative; z-index: 10; }
.btn-emoji { 
    background: transparent; border: 1px solid var(--border-hover); border-radius: 8px; 
    cursor: pointer; font-size: 0.92rem; padding: 8px 14px; min-height: 40px; 
    color: var(--text-secondary); transition: all 0.2s; display: inline-flex; align-items: center; 
    touch-action: manipulation;
}
.btn-emoji:hover, .btn-emoji:active { background: var(--border); color: var(--text); }

/* 表情面板样式 */
.emoji-panel { 
    display: none;
    position: absolute; 
    top: 45px; 
    left: 0; 
    background: #ffffff; 
    border: 1px solid var(--border-hover, #e2e8f0); 
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1); 
    padding: 10px; 
    border-radius: 10px; 
    z-index: 1000 !important; 
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); 
    gap: 6px; 
    width: 320px; 
    max-width: 100%; 
    max-height: 200px; 
    overflow-y: auto; 
    box-sizing: border-box;
}

.emoji-panel.show {
    display: grid !important;
}

.emoji-item { 
    cursor: pointer; 
    font-size: 1.25rem; 
    text-align: center; 
    padding: 6px; 
    border-radius: 6px; 
    transition: background 0.15s ease, transform 0.15s ease; 
    min-height: 36px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    user-select: none;
}
.emoji-item:hover, .emoji-item:active { 
    background: var(--primary-light, #eef2ff); 
    transform: scale(1.15); 
}

.btn-submit { 
    background: var(--primary); color: #fff; border: none; padding: 12px 28px; 
    min-height: 46px; border-radius: 8px; font-weight: 600; font-size: 1rem; 
    cursor: pointer; transition: background 0.3s; touch-action: manipulation; 
    width: auto;
}
.btn-submit:hover, .btn-submit:active { background: var(--primary-hover); }

.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.88);
    z-index: 1000;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(5px);
    padding: 20px 0;
}
.image-modal.active { display: flex; opacity: 1; }

.modal-body-wrap {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.modal-main-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0 60px;
}
.modal-main-stage img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 25px;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    font-weight: bold;
    z-index: 1010;
    line-height: 1;
    user-select: none;
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1010;
    transition: background 0.2s ease;
    padding: 0;
}
.modal-nav:hover { background: rgba(255, 255, 255, 0.35); }
.modal-prev { left: 15px; }
.modal-next { right: 15px; }

.modal-thumbs-bar {
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    max-width: 90%;
    overflow-x: auto;
    scrollbar-width: thin;
}
.modal-thumb-item {
    width: 60px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, border-color 0.2s;
    border: 2px solid transparent;
    flex-shrink: 0;
}
.modal-thumb-item:hover { opacity: 0.8; }
.modal-thumb-item.active {
    opacity: 1;
    border-color: var(--primary);
}

@media (max-width: 768px) {
    .layout-container { grid-template-columns: 1fr; padding: 0 12px; margin-top: 12px; }
    
    .post-card-inner { 
        display: block; 
        overflow: hidden;
    }
    .post-thumbnail {
        float: left;
        width: 105px;
        height: 75px;
        margin-right: 10px;
        margin-bottom: 4px;
    }

    .post-card .post-title { 
        font-size: 0.98rem; 
        margin-bottom: 4px;
        line-height: 1.35;
    }

    .post-card .post-excerpt {
        font-size: 0.82rem;
        line-height: 1.4;
        margin-bottom: 6px;
        -webkit-line-clamp: 2;
    }

    .post-card .meta {
        clear: both;
        margin-top: 6px;
        padding-top: 4px;
        border-top: 1px dashed var(--border);
    }

    .read-more-link {
        font-size: 0.75rem;
        padding: 2px 8px;
        min-height: 24px;
    }

    .article-right-ad { float: none; clear: both; margin: 20px auto; max-width: 100%; width: 100%; }
    .btn-submit { width: 100%; }
    .comment-item { flex-direction: column; gap: 10px; }
    .comment-avatar img { width: 36px; height: 36px; }
    
    .like-section {
        gap: 12px;
        margin: 25px 0 15px 0;
    }
    .btn-like, .btn-dislike {
        padding: 8px 12px;
        font-size: 0.9rem;
        min-height: 42px;
    }

    .modal-main-stage { padding: 0 40px; }
    .modal-nav { width: 36px; height: 36px; }
    .modal-prev { left: 5px; }
    .modal-next { right: 5px; }
    .modal-thumb-item { width: 48px; height: 36px; }
}
/* ====================================================================
   完美的暗黑模式配合代码 (追加到底部)
   原理：重写 :root 变量 + 强制覆盖硬编码颜色 + 强杀富文本内联背景
==================================================================== */

/* 1. 在暗黑模式下，重写所有的 CSS 变量 */
html.dark-mode {
    --bg: #0f172a;           /* 最底层的深黑蓝色背景 */
    --card-bg: #1e293b;      /* 卡片背景，稍微提亮以突出层级 */
    --text: #f8fafc;         /* 主标题及正文亮白色 */
    --text-secondary: #cbd5e1; /* 次要文本浅灰色 */
    --text-muted: #64748b;   /* 辅助性弱化文本 */
    --border: #334155;       /* 边框颜色 */
    --border-hover: #475569; /* hover 状态边框 */
    
    /* 核心：暗黑模式下的主色透明度背景，防止纯色在黑底上过于刺眼 */
    --primary-light: rgba(99, 102, 241, 0.15); 
    
    /* 加深阴影 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.5);
}

/* 2. 强杀富文本编辑器自带的内联样式（解决穿透不完美的核心） */
html.dark-mode .post-detail-content {
    color: var(--text) !important; /* 覆盖你原代码写的 #334155 */
}
html.dark-mode .post-detail-content p,
html.dark-mode .post-detail-content div,
html.dark-mode .post-detail-content span,
html.dark-mode .post-detail-content section,
html.dark-mode .post-detail-content font {
    background-color: transparent !important; /* 强制抹除富文本自带的白底 */
    color: var(--text) !important;            /* 强制抹除富文本自带的黑字 */
}

/* 3. 覆盖你原代码中“硬编码(写死)”的亮色 */
/* 广告位 */
html.dark-mode .article-right-ad {
    background: var(--card-bg);
    border-color: var(--border);
}
html.dark-mode .article-right-ad .ad-tag {
    background: rgba(30, 41, 59, 0.9);
    border-color: var(--border);
}

/* 标签 Badge */
html.dark-mode .badge-top {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
}
html.dark-mode .badge-hot {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
}

/* 按钮状态 (踩、加载更多) */
html.dark-mode .btn-dislike {
    background: var(--border);
    color: var(--text-secondary);
    border-color: var(--border-hover);
}
html.dark-mode .btn-dislike:hover {
    background: var(--border-hover);
    color: var(--text);
}
html.dark-mode .btn-load-more {
    background: var(--card-bg);
}
html.dark-mode .btn-load-more:disabled,
html.dark-mode .btn-like:disabled,
html.dark-mode .btn-dislike:disabled {
    background: #0f172a; /* disabled 状态更暗 */
    border-color: var(--border);
    color: var(--text-muted);
}

/* 评论区与表情面板 */
html.dark-mode .comment-avatar img,
html.dark-mode .post-thumbnail {
    background: var(--border);
}
html.dark-mode .emoji-panel {
    background: var(--card-bg);
    border-color: var(--border);
}

/* 4. 代码块在暗黑模式下的层级区分 */
/* 因为你原来的代码块就是黑色的，如果在黑色的卡片里会混为一体，这里稍微加深它的背景 */
html.dark-mode .code-block-wrapper {
    background: #020617; /* 极夜黑 */
    border: 1px solid var(--border);
}
html.dark-mode .code-block-header {
    background: #0f172a;
    border-bottom-color: var(--border);
}
html.dark-mode .code-copy-btn {
    background: var(--border);
}

/* 5. 护眼细节：图片和封面在暗黑模式下降低亮度防刺眼 */
html.dark-mode img,
html.dark-mode .post-thumbnail img {
    filter: brightness(0.85) contrast(1.1);
}
/* 图片放大模态框中恢复原本亮度 */
html.dark-mode .modal-main-stage img {
    filter: brightness(1) contrast(1);
}