/* --- Variables & Themes --- */
:root {
    /* Light Theme (Default) */
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-secondary: #7f8c8d;
    --primary-color: #3498db;
    --primary-hover: #2980b9;
    --border-color: #ecf0f1;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 8px 16px rgba(0,0,0,0.08);
    --header-height: 64px;
    --watermark-color: rgba(180, 180, 180, 0.45);
    --modal-overlay: rgba(44, 62, 80, 0.6);
}

[data-theme="dark"] {
    --bg-body: #1a1a1a;
    --bg-card: #252525;
    --text-main: #ecf0f1;
    --text-secondary: #95a5a6;
    --primary-color: #3498db;
    --primary-hover: #5dade2;
    --border-color: #333;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 16px rgba(0,0,0,0.5);
    --watermark-color: rgba(150, 150, 150, 0.25);
    --modal-overlay: rgba(0, 0, 0, 0.8);
}

[data-theme="sepia"] {
    --bg-body: #f5e6d3;
    --bg-card: #fdf6e3;
    --text-main: #5b4636;
    --text-secondary: #8f7e6b;
    --primary-color: #d35400;
    --primary-hover: #e67e22;
    --border-color: #eaddcf;
    --shadow-sm: 0 2px 4px rgba(91, 70, 54, 0.1);
    --shadow-md: 0 8px 16px rgba(91, 70, 54, 0.2);
    --watermark-color: rgba(91, 70, 54, 0.15);
    --modal-overlay: rgba(91, 70, 54, 0.4);
}

/* --- Reset & Base --- */
body {
    font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.7;
    transition: background 0.3s ease, color 0.3s ease;
    
    /* Sticky Footer Layout */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; transition: color 0.2s; }
a:hover { color: var(--primary-color); }
ul { list-style: none; padding: 0; margin: 0; }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3, h4, h5, h6 { margin-top: 0; font-weight: 600; line-height: 1.3; }

/* --- Markdown Body --- */
.markdown-body {
    color: var(--text-main);
    line-height: 1.8;
    word-wrap: break-word;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, 
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}

.markdown-body h1 { font-size: 2em; padding-bottom: .3em; border-bottom: 1px solid var(--border-color); }
.markdown-body h2 { font-size: 1.5em; padding-bottom: .3em; border-bottom: 1px solid var(--border-color); }
.markdown-body h3 { font-size: 1.25em; }

.markdown-body p { margin-top: 0; margin-bottom: 16px; }

.markdown-body blockquote {
    padding: 0 1em;
    color: var(--text-secondary);
    border-left: .25em solid var(--border-color);
    margin: 0 0 16px 0;
}

.markdown-body ul, .markdown-body ol {
    padding-left: 2em;
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body ul { list-style-type: disc; }
.markdown-body ol { list-style-type: decimal; }

.markdown-body code {
    padding: .2em .4em;
    margin: 0;
    font-size: 85%;
    background-color: var(--bg-body);
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--bg-body);
    border-radius: 6px;
    margin-bottom: 16px;
}

.markdown-body pre code {
    padding: 0;
    margin: 0;
    background-color: transparent;
    font-size: 100%;
    word-break: normal;
    white-space: pre;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: var(--bg-card);
    border-radius: 8px;
    margin: 10px auto;
    box-shadow: var(--shadow-sm);
}

.markdown-body hr {
    height: .25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--border-color);
    border: 0;
}

.markdown-body table {
    display: block;
    width: 100%;
    width: max-content;
    max-width: 100%;
    overflow: auto;
    margin-top: 0;
    margin-bottom: 16px;
    border-spacing: 0;
    border-collapse: collapse;
}

.markdown-body table th, .markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--border-color);
}

.markdown-body table tr {
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--bg-body);
}

/* --- Layout --- */
.site-header {
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    height: var(--header-height);
    position: sticky; top: 0; z-index: 100;
    flex-shrink: 0;
    /* Glassmorphism support */
    backdrop-filter: blur(10px);
    background-color: rgba(var(--bg-card), 0.95);
}

.header-inner {
    max-width: 1100px; margin: 0 auto; padding: 0 20px;
    height: 100%; display: flex; align-items: center; justify-content: space-between;
}

.logo { font-size: 1.4rem; font-weight: 700; color: var(--text-main); letter-spacing: -0.5px; }
.nav-menu { display: flex; gap: 25px; align-items: center; }
.nav-item { font-size: 0.95rem; font-weight: 500; color: var(--text-secondary); position: relative; }
.nav-item:hover { color: var(--primary-color); }

.theme-select {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    outline: none;
    font-family: inherit;
    transition: all 0.2s;
}
.theme-select:hover { border-color: var(--primary-color); color: var(--primary-color); background: rgba(0,0,0,0.02); }
.theme-select option { background: var(--bg-card); color: var(--text-main); }

.main-container {
    max-width: 1100px; margin: 40px auto; padding: 0 20px;
    display: grid; grid-template-columns: 1fr 320px; gap: 40px;
    width: 100%; box-sizing: border-box;
    flex: 1;
}

@media (max-width: 850px) {
    .main-container { grid-template-columns: 1fr; }
    .sidebar-column { display: none; } /* Optional: Hide sidebar on mobile */
}

/* --- Article List (Home) --- */
.article-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative; overflow: hidden;
}
.article-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: transparent;
}
/* Decoration line on hover */
.article-card::before {
    content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%;
    background: var(--primary-color);
    opacity: 0; transition: opacity 0.3s;
}
.article-card:hover::before { opacity: 1; }

.article-title { font-size: 1.4rem; margin-bottom: 10px; }
.article-title a { color: var(--text-main); background-image: linear-gradient(var(--primary-color), var(--primary-color)); background-position: 0% 100%; background-repeat: no-repeat; background-size: 0% 2px; transition: background-size .3s; }
.article-title a:hover { color: var(--primary-color); background-size: 100% 2px; }

.article-meta { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; display: flex; align-items: center; gap: 15px; }
.article-meta i { margin-right: 5px; }

.article-summary { color: var(--text-secondary); font-size: 1rem; line-height: 1.6; margin-bottom: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.read-more { 
    display: inline-block; padding: 8px 20px; 
    background: transparent; color: var(--primary-color);
    border: 1px solid var(--primary-color); border-radius: 20px;
    font-size: 0.9rem; font-weight: 500; transition: all 0.2s;
}
.read-more:hover { background: var(--primary-color); color: white; }

/* --- Sidebar --- */
.sidebar-widget {
    background: var(--bg-card);
    padding: 15px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
.widget-title { font-size: 1rem; margin-bottom: 15px; padding-bottom: 8px; border-bottom: 2px solid var(--border-color); position: relative; }
.widget-title::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 50px; height: 2px; background: var(--primary-color); }

/* --- Article Detail --- */
.article-container {
    background: var(--bg-card);
    padding: 50px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}
.article-header { margin-bottom: 40px; text-align: center; }
.article-h1 { font-size: 2.4rem; margin-bottom: 15px; color: var(--text-main); }
.article-header .article-meta { justify-content: center; }

/* Markdown Content Styles */
.markdown-body { font-size: 1.1rem; color: var(--text-main); }
.markdown-body h2 { font-size: 1.8rem; margin-top: 1.5em; margin-bottom: 0.8em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border-color); }
.markdown-body h3 { font-size: 1.4rem; margin-top: 1.5em; margin-bottom: 0.8em; }
.markdown-body p { margin-bottom: 1.5em; line-height: 1.8; text-align: justify; }
.markdown-body blockquote { border-left: 4px solid var(--primary-color); background: rgba(0,0,0,0.02); padding: 15px 20px; margin: 20px 0; border-radius: 0 4px 4px 0; color: var(--text-secondary); font-style: italic; }
.markdown-body code { background: rgba(0,0,0,0.06); color: #c7254e; padding: 2px 6px; border-radius: 4px; font-family: "Fira Code", Consolas, monospace; font-size: 0.9em; }
[data-theme="dark"] .markdown-body code { color: #ff6b6b; background: rgba(255,255,255,0.1); }
.markdown-body pre { background: #282c34; color: #abb2bf; padding: 20px; border-radius: 8px; overflow-x: auto; margin: 20px 0; }
.markdown-body pre code { background: none; color: inherit; padding: 0; }
.markdown-body ul, .markdown-body ol { padding-left: 2em; margin-bottom: 1.5em; }
.markdown-body li { margin-bottom: 0.5em; }

/* Locked Content Overlay */
.locked-placeholder {
    padding: 80px 20px; text-align: center;
    background: repeating-linear-gradient(45deg, var(--bg-body), var(--bg-body) 10px, var(--bg-card) 10px, var(--bg-card) 20px);
    border: 2px dashed var(--border-color);
    border-radius: 12px; margin-top: 40px;
    color: var(--text-secondary);
}

/* Footer */
.site-footer {
    text-align: center; padding: 50px 0; color: var(--text-secondary); font-size: 0.9rem;
    margin-top: 60px; border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    flex-shrink: 0;
}
.footer-links {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}
.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s;
}
.footer-links a:hover {
    color: var(--primary-color);
}

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--modal-overlay);
    backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}
.modal {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    transform: translateY(0);
    animation: slideUp 0.3s ease;
    position: relative; /* For absolute positioning of close button */
}
.modal .modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
    width: auto; /* Ensure width is not 100% */
    height: auto;
    line-height: 1;
}
.modal .modal-close:hover { color: var(--text-main); background: transparent; }

.modal h3 { margin-bottom: 15px; font-size: 1.5rem; }
.modal p { color: var(--text-secondary); margin-bottom: 20px; }
.modal img { 
    max-width: 200px; 
    margin: 15px auto; /* auto margin for horizontal centering */
    border-radius: 8px; 
    display: block; /* Ensure block display for margin auto to work */
}
.modal input { 
    background: var(--bg-body); color: var(--text-main); 
    border: 2px solid var(--border-color); 
    padding: 12px; width: 100%; box-sizing: border-box; 
    border-radius: 8px; font-size: 1rem; text-align: center; letter-spacing: 2px;
    margin-bottom: 20px; transition: border-color 0.2s;
}
.modal input:focus { border-color: var(--primary-color); outline: none; }
.modal button {
    background: var(--primary-color); color: white;
    border: none; padding: 12px 0; width: 100%;
    border-radius: 8px; font-size: 1rem; font-weight: 600;
    cursor: pointer; transition: background 0.2s;
}
.modal button:hover { background: var(--primary-hover); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Hot Articles Widget */
.hot-articles-list { list-style: none; padding: 0; }
.hot-articles-list li {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border-color);
}
.hot-articles-list li:last-child { border-bottom: none; }

.hot-articles-list .rank {
    width: 24px; height: 24px;
    background: #eee; color: #666;
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: bold;
    flex-shrink: 0;
}
.hot-articles-list .top-rank {
    background: var(--primary-color);
    color: white;
}

.hot-articles-list a {
    flex: 1;
    font-size: 0.95rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--text-main);
}
.hot-articles-list a:hover { color: var(--primary-color); }

.hot-articles-list .views {
    font-size: 0.8rem; color: var(--text-secondary);
    display: flex; align-items: center; gap: 4px;
}

/* Pagination */
.pagination {
    display: flex; align-items: center; justify-content: center; gap: 15px;
    margin-top: 20px;
    padding: 10px 0;
}
.page-link {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-main);
    font-size: 0.9rem;
    transition: all 0.2s;
}
.page-link:hover:not(.disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-body);
}
.page-link.disabled {
    opacity: 0.5; cursor: not-allowed;
    color: var(--text-secondary);
}
.page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.limit-select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.9rem;
    cursor: pointer;
}
