/* ==================== 1. 基础变量与全局重置 ==================== */
:root { 
    --primary: #2563eb; 
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --bg: #f8fafc; 
    --card-bg: #ffffff; 
    --text: #0f172a; 
    --text-secondary: #4b5563;
    --text-muted: #94a3b8;
    --border: #f1f5f9;
    --border-hover: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px -2px rgba(0,0,0,0.05);
    --radius: 16px;
}

*, *::before, *::after { 
    box-sizing: border-box; 
}

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;
    overflow-wrap: anywhere;
    word-break: break-word;
}

img, svg, video { 
    max-width: 100%; 
    height: auto; 
    display: block; 
}

/* ==================== 2. 布局与主框架 ==================== */
.layout-container { 
    max-width: 1200px; 
    margin: 24px auto 0 auto; 
    padding: 0 16px; 
    display: grid; 
    grid-template-columns: 1fr 300px; 
    gap: 24px; 
    width: 100%;
}

main { 
    min-width: 0; 
}

/* ==================== 3. 分类导航栏 ==================== */
.category-nav-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    -webkit-overflow-scrolling: touch;
}

.category-nav-bar::-webkit-scrollbar {
    height: 3px;
}

.category-nav-bar::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 3px;
}

.category-item {
    white-space: nowrap;
    padding: 6px 14px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 20px;
    transition: all 0.2s ease;
    background: #f3f4f6;
}

.category-item:hover, .category-item.active {
    background: var(--primary);
    color: #ffffff;
}

.badge-category {
    display: inline-block;
    background-color: #f3f4f6;
    color: #4b5563;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    margin-right: 6px;
    vertical-align: middle;
}

/* ==================== 4. 文章卡片样式 ==================== */
.post-card { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 20px; 
    margin-bottom: 18px; 
    box-shadow: var(--shadow-sm); 
    border: 1px solid var(--border); 
    transition: all 0.25s ease; 
    overflow: hidden; 
}

.post-card:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-md); 
    border-color: var(--border-hover);
}

.post-card-inner {
    display: flex;
    gap: 20px;
    align-items: stretch;
    width: 100%;
}

.post-thumbnail {
    flex-shrink: 0;
    width: 220px;
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
    background: #f1f5f9;
    border: 1px solid var(--border);
    display: block;
}

.post-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.post-body {
    flex: 1;
    min-width: 0; 
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.post-title { 
    margin: 0 0 10px 0; 
    font-size: 1.2rem; 
    font-weight: 700; 
    line-height: 1.45; 
}

.post-title a { 
    color: var(--text); 
    text-decoration: none; 
}

.post-title a:hover { 
    color: var(--primary); 
}

.badge { 
    display: inline-flex; 
    align-items: center; 
    padding: 2px 6px; 
    font-size: 0.72rem; 
    border-radius: 5px; 
    font-weight: 600; 
    margin-right: 4px; 
}

.badge-top { 
    background: #fef2f2; 
    color: #ef4444; 
    border: 1px solid #fee2e2; 
}

.badge-hot { 
    background: #fff7ed; 
    color: #f97316; 
    border: 1px solid #ffedd5; 
}

.post-excerpt { 
    font-size: 0.92rem; 
    color: var(--text-secondary); 
    margin-bottom: 14px; 
    line-height: 1.7; 
    display: -webkit-box; 
    -webkit-line-clamp: 2; 
    -webkit-box-orient: vertical; 
    overflow: hidden; 
}

.post-footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px dashed var(--border);
    padding-top: 12px;
    margin-top: 6px;
    gap: 10px;
    flex-wrap: wrap;
}

.meta { 
    font-size: 0.82rem; 
    color: var(--text-muted); 
    display: flex; 
    gap: 10px; 
    align-items: center; 
    flex-wrap: wrap;
}

.read-more-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    background: var(--primary-light);
    padding: 7px 16px;
    border-radius: 18px;
}

/* ==================== 5. 加载更多按钮 ==================== */
.load-more-container { 
    text-align: center; 
    margin: 24px 0 40px 0; 
}

.btn-load-more {
    background: #ffffff;
    color: var(--text);
    border: 1px solid var(--border-hover);
    padding: 10px 32px;
    min-height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 28px;
    cursor: pointer;
}

/* ==================== 6. 侧边栏与小工具 ==================== */
.sidebar { 
    display: flex; 
    flex-direction: column; 
    gap: 16px; 
    min-width: 0; 
}

.widget { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 18px; 
    box-shadow: var(--shadow-sm); 
    border: 1px solid var(--border); 
}

.widget-title { 
    font-size: 0.98rem; 
    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; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    gap: 8px; 
}

.widget-list a { 
    color: var(--text-secondary); 
    text-decoration: none; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
    flex: 1; 
    min-width: 0;
}

.rank-num { 
    display: inline-flex; 
    justify-content: center; 
    align-items: center; 
    width: 20px; 
    height: 20px; 
    border-radius: 5px; 
    background: #f1f5f9; 
    font-size: 0.72rem; 
    flex-shrink: 0;
}

.rank-num.top-1 { background: #ef4444; color: #fff; }
.rank-num.top-2 { background: #f97316; color: #fff; }
.rank-num.top-3 { background: #eab308; color: #fff; }

/* ==================== 7. 搜索高亮 ==================== */
mark.search-highlight {
    background-color: #fef08a; 
    color: #b45309;             
    padding: 0 2px;
    border-radius: 4px;
    font-weight: 600;
}

/* ==================== 8. 响应式适配 ==================== */
@media screen and (max-width: 1024px) {
    .layout-container { 
        grid-template-columns: 1fr 260px; 
        gap: 16px; 
    }
    .post-thumbnail { 
        width: 180px; 
        height: 120px; 
    }
}

@media screen and (max-width: 868px) {
    .layout-container { 
        grid-template-columns: 1fr; 
        gap: 20px; 
    }
}

@media screen and (max-width: 640px) {
    .layout-container { 
        padding: 0 12px; 
        margin-top: 16px; 
    }

    .post-card { 
        padding: 14px; 
    }
    .post-card-inner { 
        flex-direction: column; 
        gap: 12px; 
    }
    .post-thumbnail { 
        width: 100% !important; 
        aspect-ratio: 16 / 9; 
        height: auto; 
    }
    
    .post-title { 
        font-size: 1.08rem; 
    }
    .post-excerpt { 
        font-size: 0.88rem; 
        margin-bottom: 10px; 
    }
    
    .post-footer-row { 
        flex-direction: column; 
        align-items: stretch; 
    }

    .read-more-link { 
        width: 100%; 
        text-align: center; 
        justify-content: center; 
    }
}

@media screen and (max-width: 480px) {
    .meta { 
        font-size: 0.78rem; 
        gap: 6px; 
    }
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
/* ==================== 9. 黑暗模式适配 ==================== */

/* 1. 重新定义黑暗模式下的全局变量 */
html.dark-mode, body.dark-mode, html[data-theme="dark"] {
    /* 主题色在暗色背景下稍微提亮，保证视觉对比度 */
    --primary: #3b82f6;       
    --primary-hover: #60a5fa;
    /* 浅色背景改为透明度方案，使其能完美融合黑色卡片 */
    --primary-light: rgba(59, 130, 246, 0.15); 
    
    --bg: #0f172a;           
    --card-bg: #1e293b;      
    --text: #f8fafc;         
    --text-secondary: #cbd5e1; 
    --text-muted: #64748b;   
    --border: #334155;       
    --border-hover: #475569; 
    
    /* 阴影在暗色下需要加深才会有立体感 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px -2px rgba(0,0,0,0.5);
}

/* 2. 覆盖代码中硬编码（写死）的亮色背景 */

/* 分类导航栏 */
html.dark-mode .category-nav-bar {
    background: var(--card-bg);
}
html.dark-mode .category-nav-bar::-webkit-scrollbar-thumb {
    background: var(--border-hover);
}
html.dark-mode .category-item,
html.dark-mode .badge-category {
    background: var(--border);
    color: var(--text-secondary);
}
html.dark-mode .category-item:hover, 
html.dark-mode .category-item.active {
    background: var(--primary);
    color: #ffffff;
}

/* 文章封面图骨架屏与护眼滤镜 */
html.dark-mode .post-thumbnail {
    background: var(--border);
}
html.dark-mode img {
    filter: brightness(0.85) contrast(1.1); /* 降低亮瞎眼的白色图片亮度 */
}

/* 置顶/热门徽章 (改用半透明背景更契合暗黑风格) */
html.dark-mode .badge-top {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
html.dark-mode .badge-hot {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
    color: #fdba74;
}

/* 底部加载更多按钮 */
html.dark-mode .btn-load-more {
    background: var(--card-bg);
}

/* 侧边栏排名数字 (非前三名的普通数字) */
html.dark-mode .rank-num:not(.top-1):not(.top-2):not(.top-3) {
    background: var(--border);
    color: var(--text-secondary);
}

/* 搜索结果高亮 (暗夜模式下黄色高亮需要降低透明度) */
html.dark-mode mark.search-highlight {
    background-color: rgba(234, 179, 8, 0.25);
    color: #fde047;
}