/* ==========================================================================
   1. 全局变量与基础重置
   ========================================================================== */
:root {
    --primary: #1f2937;
    --accent: #c81d25;
    --accent-strong: #a31217;
    --bg: #fdf7f2;
    --surface: #fffaf5;
    --border: #f2e6db;
    --muted: #8b6f5a;
    --shadow-sm: 0 1px 2px rgba(31, 41, 55, 0.06);
    --shadow-md: 0 8px 24px rgba(31, 41, 55, 0.1);
}

* { box-sizing: border-box; }

body {
    font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    margin: 0;
    color: var(--primary);
    letter-spacing: 0.2px;
}

a { text-decoration: none; color: inherit; transition: 0.2s; }

/* ==========================================================================
   2. 头部、导航与公共组件 (Hero Header)
   ========================================================================== */
.top-bar {
    background: #f4f4f5;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--muted);
}

.top-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-user {
    color: var(--primary);
    font-weight: 600;
}

.top-bar-link {
    color: var(--primary);
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
}

.top-bar-link:hover {
    border-color: var(--border);
    color: var(--accent);
    background: #fff;
}

.top-bar-link--accent {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.top-bar-icon-link {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    background: #fff;
    transition: 0.2s;
}

.top-bar-icon-link svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.top-bar-icon-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.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;
}
.hero-header {
    background: var(--surface);
    color: var(--primary);
    padding: 28px 0 20px;
    border-bottom: 1px solid var(--border);
}

/* ==========================================================================
   3. 登录注册页
   ========================================================================== */
.auth-page {
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.auth-card {
    width: min(460px, 100%);
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    padding: 32px;
    border: 1px solid var(--border);
}

.auth-tabs {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.auth-tab {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: 0.2s;
    position: relative;
}

.auth-tab svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.auth-tab.is-active {
    color: var(--accent);
    border-color: rgba(200, 29, 37, 0.4);
    box-shadow: var(--shadow-sm);
    background: #fff5f5;
}

.auth-panel {
    display: none;
}

.auth-panel.is-active {
    display: block;
}

.auth-field {
    margin-bottom: 16px;
}

.auth-field input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 0.95rem;
    background: #fff;
}

.auth-field input:focus {
    outline: none;
    border-color: rgba(200, 29, 37, 0.5);
    box-shadow: 0 0 0 3px rgba(200, 29, 37, 0.12);
}

.auth-submit {
    width: 100%;
    padding: 12px 16px;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.auth-submit:hover {
    background: var(--accent-strong);
}

.auth-message {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.auth-message--error {
    background: #fff1f1;
    color: #b91c1c;
    border: 1px solid rgba(185, 28, 28, 0.2);
}

.auth-message--success {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid rgba(21, 128, 61, 0.2);
}

.hero-inner, .container-wrapper {
    max-width: 1200px; margin: 0 auto; padding: 0 20px;
}

.hero-inner { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 16px;
}
.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: block;
    object-fit: contain;
}

.brand-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.badge {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    color: var(--primary);
    background: var(--surface);
}

.badge-accent {
    border-color: rgba(37, 99, 235, 0.3);
    color: var(--accent);
    background: rgba(37, 99, 235, 0.12);
}

.nav-container {
    position: sticky;
    top: 0;
    z-index: 99;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 22px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.nav-links { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: center; }
.user-menu { justify-self: end; grid-column: 3; }
.nav-link { padding: 10px 12px; font-weight: 600; border-radius: 8px; color: var(--primary); }
.nav-link:hover { background: #f3f4f6; color: var(--accent); }
.nav-link.is-active {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.12);
    border: 1px solid rgba(37, 99, 235, 0.3);
}
.nav-more {
    display: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
}

.btn-solid {
    background: var(--accent);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.btn-ghost {
    color: var(--primary);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
}

/* ==========================================================================
   3. 首页/分类页网格布局 (修复变窄核心)
   ========================================================================== */
.container {
    max-width: 1200px;
    margin: 36px auto 48px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 28px;
}

.container.portal {
    display: block;
}

.portal-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 32px;
    align-items: start;
}

.portal-main {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.portal-sidebar {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.portal-section {
    margin-bottom: 40px;
}

.section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.section-header h2 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: 0.4px;
}

.section-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

.portal-grid {
    display: grid;
    gap: 24px;
}

.portal-top-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.portal-top-grid .portal-card--hero {
    grid-column: span 2;
}

.portal-secondary-grid,
.portal-hot-grid,
.portal-latest-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.portal-latest-grid {
    grid-template-columns: 1fr;
    gap: 18px;
}

.portal-card--hero .card-content h3 {
    font-size: 1.5rem;
}

.portal-card--compact .card-content {
    padding: 16px;
}

.portal-card--compact .card-content h3 {
    font-size: 1rem;
}

.portal-card--compact .meta {
    padding: 10px 16px;
}

.portal .pagination {
    grid-column: auto;
    margin-top: 10px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 28px;
    color: #94a3b8;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 12px;
}

.card {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card-image img { width: 100%; height: 200px; object-fit: cover; display: block; }
.card-content { padding: 20px; flex-grow: 1; }
.card-content h3 {
    margin: 0 0 10px;
    font-size: 1.2rem;
    line-height: 1.55;
}
.card-content p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.7;
}
.meta { font-size: 0.85rem; color: var(--muted); padding: 12px 20px; border-top: 1px solid var(--border); }

.latest-item {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.latest-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.latest-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.latest-body {
    flex: 1;
    min-width: 0;
}

.latest-body h3 {
    margin: 0 0 12px;
    font-size: 1.2rem;
    line-height: 1.6;
}

.latest-summary {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.7;
}

.latest-body h3 a {
    color: var(--primary);
    text-decoration: none;
}

.latest-body h3 a:hover {
    color: var(--accent);
}

.latest-meta {
    display: flex;
    gap: 16px;
    font-size: 0.85rem;
    color: var(--muted);
}

.latest-meta span {
    padding: 4px 10px;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid var(--border);
}

.latest-thumb {
    width: 160px;
    height: 100px;
    border-radius: 10px;
    overflow: hidden;
    background: #f3f4f6;
    flex-shrink: 0;
}

.latest-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.latest-thumb--empty {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
}

/* ==========================================================================
   4. tag.php 列表美化
   ========================================================================== */
.tag-container { max-width: 1000px; margin: 30px auto; padding: 0 20px; }
.tag-header { border-bottom: 2px solid var(--accent); padding-bottom: 15px; margin-bottom: 30px; }
.news-item { display: flex; gap: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.news-item .thumb { width: 200px; height: 130px; overflow: hidden; border-radius: 8px; flex-shrink: 0; }
.news-item .thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ==========================================================================
   5. 通用分页组件 (最关键：解决所有冲突)
   ========================================================================== */
.pagination {
    grid-column: 1 / -1; /* 👈 强制在首页 Grid 布局中占满整行，解决变窄问题 */
    display: flex; 
    justify-content: center; 
    align-items: center;
    padding: 40px 0; 
    gap: 8px; 
    width: 100%; 
    margin-top: 20px;
    clear: both;
    flex-wrap: wrap;
}

.pagination a, .pagination span, .pagination button {
    padding: 8px 16px; border: 1px solid var(--border);
    text-decoration: none; color: var(--muted); border-radius: 6px;
    transition: all 0.2s; background: var(--surface);
    font-size: 0.95rem;
    line-height: 1.2;
}

/* 统一前台选中状态颜色（红色） */
.pagination a.active, .pagination span.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}

.pagination a:hover:not(.active) { background-color: #f3f4f6; color: var(--accent); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.pagination .disabled {
    color: #9ca3af;
    border-color: var(--border);
    background: #f3f4f6;
    cursor: not-allowed;
}

.pagination .pagination__ellipsis {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    padding: 8px 6px;
}

.pagination__meta {
    color: var(--muted);
    padding: 8px 12px;
}

.pagination__jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pagination__jump input {
    width: 70px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.pagination__jump button {
    cursor: pointer;
}

.pagination a:focus-visible,
.pagination button:focus-visible,
.pagination__jump input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   6. 文章详情、点赞与评论
   ========================================================================== */
.article-container { max-width: 800px; margin: 40px auto; padding: 24px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.article-body { line-height: 1.9; font-size: 1.05rem; }
.article-body img { max-width: 100% !important; height: auto !important; border-radius: 5px; margin-bottom: 20px; }

.like-section { text-align: center; margin: 40px 0; border-top: 1px dashed var(--border); padding-top: 30px; }
.like-btn { padding: 12px 30px; background: var(--accent); color: white; border: none; border-radius: 999px; cursor: pointer; box-shadow: var(--shadow-sm); }

.comment-section { max-width: 800px; margin: 40px auto; padding: 20px; border-top: 1px solid var(--border); }
.comment-form textarea { width: 100%; height: 100px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; }

/* ==========================================================================
   8. 底部与响应式
   ========================================================================== */
.footer {
    text-align: center !important;
    padding: 40px 20px !important;
    color: var(--muted) !important;
    font-size: 0.9rem !important;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
    .container { grid-template-columns: 1fr; }
    .top-bar-inner {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap;
        gap: 8px;
    }
    .top-bar-date {
        white-space: nowrap;
    }
    .top-bar-actions {
        width: auto;
        justify-content: flex-end;
        flex-wrap: nowrap;
        white-space: nowrap;
    }
    .hero-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
    .nav-container { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
    .nav-links {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 6px;
        justify-items: center;
    }
    .nav-link {
        width: 100%;
        padding: 6px 4px;
        font-size: 0.85rem;
        text-align: center;
        white-space: nowrap;
    }
    .news-item { flex-direction: column; }
    .news-item .thumb { width: 100%; }
    .portal-top-grid { grid-template-columns: 1fr; }
    .portal-top-grid .portal-card--hero { grid-column: span 1; }
    .portal-layout { grid-template-columns: 1fr; }
    .nav-links .nav-category { display: inline-flex; }
    .pagination {
        padding: 24px 0;
        gap: 6px;
    }
    .pagination .pagination__first,
    .pagination .pagination__last,
    .pagination .pagination__ellipsis {
        display: none;
    }
    .card-content h3,
    .news-item h3 {
        font-size: 1rem;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}

@media (min-width: 769px) {
    .nav-links .nav-category { display: inline-flex; }
}
/* 追加到 CSS 第 4 部分末尾 */
.news-item .info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center; /* 使文字垂直居中对齐图片 */
}

.news-item h3 {
    margin: 0;
    font-size: 1.2rem;
    line-height: 1.4;
}

.news-item h3 a {
    color: var(--primary);
    text-decoration: none;
}

.news-item h3 a:hover {
    color: var(--accent);
}

/* 响应式：手机端图片变小或切换为上下布局 */
@media (max-width: 600px) {
    .news-item {
        flex-direction: column;
    }
    .news-item .thumb {
        width: 100%;
        height: auto;
    }
}
/* --- 文章导航优化 (修复重叠) --- */
.article-nav {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin: 40px 0;
    padding: 20px 0;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    gap: 20px; /* 增加间距防止挤压 */
}

.nav-item {
    flex: 1; /* 平分空间 */
    min-width: 0; /* 允许文字截断 */
}

.nav-item small {
    display: block;
    color: #999;
    margin-bottom: 5px;
    font-size: 12px;
}

.nav-item a {
    color: #333;
    text-decoration: none;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* 超出显示省略号 */
    transition: color 0.2s;
}

.nav-item a:hover {
    color: var(--accent);
}
/* --- 文章导航：左对齐与右对齐，防止重叠 --- */
.article-nav {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin: 40px 0;
    padding: 25px 0;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    gap: 20px;
}

.nav-item {
    flex: 1; /* 平分宽度 */
    min-width: 0; /* 允许截断 */
}

.nav-item.next {
    text-align: right; /* 下一篇文字右对齐 */
}

.nav-item a {
    display: block;
    color: #333;
    font-weight: bold;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* 标题太长自动变... */
    font-size: 15px;
}

/* --- 点赞按钮：精美大气的居中样式 --- */
.action-bar {
    display: flex;
    justify-content: center; /* 确保真正居中 */
    margin: 50px 0;
}

.like-btn {
    padding: 12px 35px;
    border-radius: 50px; /* 圆角胶囊形状 */
    border: 2px solid var(--accent);
    background: #fff;
    color: var(--accent);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.like-btn:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.3);
}

.like-btn:disabled {
    background: #f1f2f6;
    border-color: #dfe4ea;
    color: #a4b0be;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* --- 评论表单：对齐与间距 --- */
.comment-form-container {
    margin-top: 30px;
    padding: 25px;
    background: #f8f9fa;
    border-radius: 12px;
}

#commentForm textarea {
    width: 100%;
    min-height: 100px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box; /* 关键：防止撑破容器 */
    font-size: 14px;
    margin-bottom: 15px;
    display: block;
}

.btn-submit {
    padding: 10px 30px;
    background: #2f3542;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}
/* --- 点赞按钮区域居中 --- */
.action-bar {
    display: flex;
    justify-content: center; /* 强制水平居中 */
    margin: 40px 0;
    width: 100%;
}

.like-btn {
    padding: 10px 25px;
    background-color: var(--accent);
    color: #fff;
    border: none;
    border-radius: 30px; /* 圆角胶囊形状 */
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(249, 115, 22, 0.2);
}

.like-btn:hover {
    background-color: var(--accent-strong);
    transform: translateY(-2px);
}

.like-btn:disabled, .like-btn.voted {
    background-color: #f1f2f6 !important; /* 变成淡灰色 */
    color: #a4b0be !important;
    cursor: default;
    box-shadow: none;
    transform: none;
}

/* 导航样式（上一篇/下一篇） */
.article-nav { 
    display: flex; 
    justify-content: space-between; 
    margin: 40px 0; 
    padding: 20px 0; 
    border-top: 1px solid #eee; 
    border-bottom: 1px solid #eee; 
}

.nav-item { flex: 1; min-width: 0; }
.nav-item.next { text-align: right; }
.nav-item small { color: #999; display: block; margin-bottom: 5px; }
.nav-item a { 
    color: #2c3e50; 
    font-weight: bold; 
    text-decoration: none; 
    display: block; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
}
.nav-item a:hover { color: var(--accent); }

/* 点赞及分享操作栏 */
.action-bar { 
    text-align: center; 
    margin: 40px 0; 
    display: flex; 
    justify-content: center; 
    gap: 15px; 
    align-items: center; 
}

.like-btn, .share-btn { 
    padding: 12px 30px; 
    border-radius: 25px; 
    border: none; 
    cursor: pointer; 
    font-weight: bold; 
    text-decoration: none; 
    font-size: 14px; 
    transition: transform 0.2s;
}

.like-btn:active, .share-btn:active { transform: scale(0.95); }

.like-btn { background: var(--accent); color: #fff; }
.like-btn:disabled { background: #dfe4ea; color: #a4b0be; cursor: default; }
.share-btn { background: #2f3542; color: #fff; 
 }

/* =========================
   ✅ 全站：灭横向溢出兜底（加到 style.css 最底部）
   ========================= */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* 常见元凶：100vw 会导致手机出现横向滚动 */
body, header, main, footer,
.top-bar, .hero-header, .nav-container {
  max-width: 100%;
}

/* 所有 img/iframe 等媒体元素不要撑破 */
img, video, iframe, embed, object {
  max-width: 100%;
  height: auto;
}
