:root {
    /* 浅色模式 (默认) */
    --bg-color: #f9f9f9;
    --text-color: #333333;
    --header-bg: #ffffff;
    --header-text: #333333;
    --primary-color: #f5c518; /* 活力黄 */
    --accent-color: #333333; /* 深色辅助 */
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --link-color: #333333;
    --link-hover: #f5c518;
    --meta-color: #777777;
    --input-bg: #ffffff;
    --input-border: #cccccc;
    --table-header-bg: #f0f0f0;
    --table-header-text: #333333;
}

[data-theme="dark"] {
    /* 深色模式 */
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --header-bg: #1e1e1e;
    --header-text: #ffffff;
    --primary-color: #f5c518; /* 保持黄色 */
    --accent-color: #ffffff;
    --card-bg: #1e1e1e;
    --border-color: #333333;
    --link-color: #e0e0e0;
    --link-hover: #f5c518;
    --meta-color: #aaaaaa;
    --input-bg: #2c2c2c;
    --input-border: #444444;
    --table-header-bg: #2c2c2c;
    --table-header-text: #ffffff;
}

body {
    font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 90%; /* 增加整体宽度以容纳三栏 */
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden;
}

/* Header Redesign */
header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 15px 0;
    border-bottom: 2px solid var(--primary-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: background-color 0.3s;
}

header a {
    color: var(--header-text);
    text-decoration: none;
    font-size: 16px;
    transition: color 0.2s;
}

header ul {
    padding: 0;
    margin: 0;
    list-style: none;
    display: flex;
    align-items: center;
}

header li {
    padding: 0 15px;
}

header #branding {
    float: left;
    display: flex;
    align-items: center;
}

header #branding h1 {
    margin: 0;
    font-size: 24px;
}

header nav {
    float: right;
    margin-top: 5px;
}

header .highlight {
    color: var(--primary-color);
    font-weight: bold;
}

header a:hover {
    color: var(--primary-color);
}

/* Toggle Button */
.theme-switch-wrapper {
    display: inline-flex;
    align-items: center;
    margin-left: 20px;
    vertical-align: middle;
}

.theme-switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 48px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    background-color: #fff;
    bottom: 2px;
    content: "";
    height: 20px;
    left: 2px;
    position: absolute;
    transition: .4s;
    width: 20px;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* Layout Container (Three Columns) */
.main-container {
    width: 90%; /* Match container width */
    max-width: 1400px;
    margin: 20px auto;
    overflow: hidden;
    display: flex;
    gap: 30px;
}

.left-sidebar {
    flex: 0 0 15%; /* 15% width, fixed */
}

.main-content {
    flex: 1; /* Takes remaining space (approx 60-65%) */
}

.right-sidebar {
    flex: 0 0 26%; /* 26% width, fixed */
    overflow: hidden; /* Prevent content from expanding sidebar */
}

/* Responsive Layout */
@media (max-width: 992px) {
    .main-container {
        flex-direction: column;
    }
    .left-sidebar, .main-content, .right-sidebar {
        width: 100%;
        flex: none;
    }
}

/* Post Styling */
.post-card {
    background: var(--card-bg);
    padding: 20px;
    margin-bottom: 20px;
    border: 2px solid var(--text-color); /* Stronger border */
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    transition: background-color 0.3s, border-color 0.3s, transform 0.2s, box-shadow 0.2s;
    position: relative; /* For clickable area if needed via JS or CSS */
}

.post-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.1);
}

.post-info h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.4em;
}

.post-info h3 a {
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s;
}

.post-card:hover h3 a {
    color: var(--primary-color);
}

.post-meta {
    color: var(--meta-color);
    font-size: 0.85em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.post-meta .post-views {
    margin-left: auto;
    white-space: nowrap;
}

.post-excerpt {
    color: var(--text-color);
    font-size: 0.95em;
    line-height: 1.5;
    margin: 0;
}

.post-image-thumb {
    max-height: 120px;
    max-width: 200px;  /* Limit width as well */
    width: auto;
    float: left;
    margin-right: 15px; /* Reduced margin */
    border-radius: 4px;
    object-fit: cover; /* Ensure aspect ratio */
}

/* Sidebar Styling */
.sidebar-block {
    background: transparent; /* Transparent for topics */
    padding: 0; /* Remove padding for topics */
    border: none; /* Remove border for topics */
    margin-bottom: 20px;
}

/* Specific style for right sidebar blocks if needed */
.right-sidebar .sidebar-block {
    background: var(--card-bg);
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden; /* Ensure consistent width */
}

.sidebar-block h3 {
    margin-top: 0;
    color: var(--text-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    display: inline-block;
}

/* Topic List in Left Sidebar */
.topic-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.topic-list li {
    margin-bottom: 0; /* Remove bottom margin as we use padding */
    border-bottom: none; /* Remove separator line */
    padding: 10px 0; /* Add vertical padding */
}

.topic-list a {
    color: #333 !important; /* Force black text on white bg (in light mode) */
    background-color: #fff; /* White background */
    text-decoration: none;
    font-weight: 700; /* Bold */
    font-size: 1.2em; /* Larger font size */
    display: block;
    padding: 15px; /* Comfortable padding */
    transition: all 0.2s;
    border-radius: 4px;
}

/* Dark mode override for topic list to ensure visibility but keep style */
[data-theme="dark"] .topic-list a {
    color: #fff !important;
    background-color: #333;
}

.topic-list a:hover {
    background-color: var(--primary-color);
    color: #333 !important;
    transform: translateX(5px);
}

.left-sidebar {
    flex: 0 0 15%;
    margin-right: 30px; /* Increase gap between topics and posts */
}


/* General Post Styling (Keep for single post view) */
.post {
    background: var(--card-bg);
    padding: 25px;
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.post-image {
    max-width: 100%;
    height: auto;
    margin-bottom: 15px;
    border-radius: 4px;
}

/* Search Bar (Restored simple style if needed, though header handles it) */
.search-form {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 20px;
    padding: 5px 15px;
}

.search-form input {
    border: none;
    background: transparent;
    padding: 5px;
    outline: none;
    color: var(--text-color);
    width: 200px;
    margin-bottom: 0;
}

.search-form button {
    background: transparent;
    border: none;
    color: var(--meta-color);
    padding: 5px;
    cursor: pointer;
}

.search-form button:hover {
    color: var(--primary-color);
    background: transparent;
}


/* Form Styling */
input[type="text"], input[type="password"], textarea, select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--input-border);
    margin-bottom: 20px;
    box-sizing: border-box;
    border-radius: 4px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
}

button {
    background: var(--primary-color);
    color: #333;
    border: 0;
    padding: 12px 24px;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
    font-size: 16px;
}

button:hover {
    background: #e0b40e; /* 稍微深一点的黄色 */
}

/* Admin Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background-color: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
}

table, th, td {
    border: 1px solid var(--border-color);
}

th, td {
    padding: 15px;
    text-align: left;
}

th {
    background-color: var(--table-header-bg);
    color: var(--table-header-text);
    font-weight: 600;
}

td {
    color: var(--text-color);
}

/* Topic Badge */
.topic-badge {
    background-color: var(--primary-color);
    color: #333 !important;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85em;
    text-decoration: none;
    font-weight: 600;
    display: inline-block;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    margin-top: 40px;
    color: var(--meta-color);
    border-top: 1px solid var(--border-color);
}

/* Utils */
.page-title {
    color: var(--text-color);
    border-bottom: 2px solid var(--primary-color);
    display: inline-block;
    padding-bottom: 5px;
    margin-bottom: 20px;
}

hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 20px 0;
}

/* Login Form specific override */
.login-form {
    background: var(--card-bg) !important;
    border-color: var(--border-color) !important;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Admin specific */
.admin-nav {
    background: var(--card-bg) !important;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}
.admin-nav a {
    color: var(--text-color) !important;
}

/* Ranking List in Right Sidebar */
.ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: rank;
}

.ranking-list li {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 0.95em;
    position: relative;
    padding-left: 25px; /* Space for number */
    height: 40px; /* Fixed height to prevent layout shift */
    overflow: hidden;
    gap: 8px;
}

.ranking-list li:last-child {
    border-bottom: none;
}

.ranking-list li::before {
    counter-increment: rank;
    content: counter(rank);
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 4px; /* Rounded square */
    background: #eee;
    color: #666;
    font-size: 0.8em;
    font-weight: bold;
}

/* Top 3 Highlighting */
.ranking-list li:nth-child(1)::before {
    background: #e74c3c; 
    color: #fff;
}
.ranking-list li:nth-child(2)::before {
    background: #e67e22; 
    color: #fff;
}
.ranking-list li:nth-child(3)::before {
    background: #f1c40f; 
    color: #fff;
}

.ranking-list .rank-thumb {
    display: block;
    width: 44px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: 4px;
    overflow: hidden;
    background: #f0f0f0;
}

.ranking-list .rank-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ranking-list .rank-title {
    color: var(--text-color);
    text-decoration: none;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 5px;
    display: block;
}

.ranking-list .rank-title:hover {
    color: var(--primary-color);
}

.ranking-list .hits {
    font-size: 0.8em;
    color: var(--meta-color);
    white-space: nowrap;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    margin-left: auto;
}

/* Capsule Tabs Style */
.ranking-tabs {
    display: flex;
    justify-content: space-between;
    background-color: #f0f0f0; /* Light grey background */
    border-radius: 30px; /* Capsule shape */
    padding: 4px;
    margin-bottom: 15px;
    border: none; /* Remove bottom border */
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 6px 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--meta-color);
    border-radius: 20px; /* Inner capsule */
    transition: all 0.3s;
    font-size: 0.9em;
    margin-bottom: 0; /* Reset */
    border-bottom: none;
}

.tab-btn.active {
    background-color: #fff;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Dark mode adjustment for tabs */
[data-theme="dark"] .ranking-tabs {
    background-color: #2c2c2c;
}
[data-theme="dark"] .tab-btn.active {
    background-color: #3e3e3e;
    color: var(--primary-color);
}

.ranking-content {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Adjust list for tabs */
.ranking-list {
    margin-top: 5px;
}
