:root {
    --bg-color: #ffffff;
    --bg-alt: #f4f7f6;
    --text-color: #333333;
    --text-muted: #666666;
    --primary-color: #0056b3;
    --primary-hover: #004494;
    --header-bg: #ffffff;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --footer-bg: #1a1a1a;
    --footer-text: #f1f1f1;
    --tag-bg: #e2e8f0;
    --tag-text: #334155;
    --input-bg: #ffffff;
    --input-border: #cccccc;
    --btn-text: #ffffff;
}

/* --- System Auto Mode (Dark Mode Overrides) --- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #121212;
        --bg-alt: #1e1e1e;
        --text-color: #e0e0e0;
        --text-muted: #aaaaaa;
        --primary-color: #4dabf7;
        --primary-hover: #74c0fc;
        --header-bg: #1f1f1f;
        --card-bg: #2a2a2a;
        --border-color: #333333;
        --footer-bg: #0a0a0a;
        --footer-text: #e0e0e0;
        --tag-bg: #334155;
        --tag-text: #cbd5e1;
        --input-bg: #1e1e1e;
        --input-border: #444444;
        --btn-text: #121212;
    }
}

/* --- Explicit Overrides for JavaScript Toggle --- */
html[data-theme="light"] {
    --bg-color: #ffffff;
    --bg-alt: #f4f7f6;
    --text-color: #333333;
    --text-muted: #666666;
    --primary-color: #0056b3;
    --primary-hover: #004494;
    --header-bg: #ffffff;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --footer-bg: #1a1a1a;
    --footer-text: #f1f1f1;
    --tag-bg: #e2e8f0;
    --tag-text: #334155;
    --input-bg: #ffffff;
    --input-border: #cccccc;
    --btn-text: #ffffff;
}

html[data-theme="dark"] {
    --bg-color: #121212;
    --bg-alt: #1e1e1e;
    --text-color: #e0e0e0;
    --text-muted: #aaaaaa;
    --primary-color: #4dabf7;
    --primary-hover: #74c0fc;
    --header-bg: #1f1f1f;
    --card-bg: #2a2a2a;
    --border-color: #333333;
    --footer-bg: #0a0a0a;
    --footer-text: #e0e0e0;
    --tag-bg: #334155;
    --tag-text: #cbd5e1;
    --input-bg: #1e1e1e;
    --input-border: #444444;
    --btn-text: #121212;
}

/* --- Reset & Global Styles --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
div#viewer-content {
    white-space: unset;
}
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

.post-body {
    overflow-wrap: break-word;
    word-break: break-word;
}
a {
    text-decoration: none;
    color: var(--primary-color);
    transition: opacity 0.2s, color 0.2s;
}

a:hover {
    color: var(--primary-hover);
}

/* --- Header & Navigation (Sticky Removed) --- */
header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

#nav-menu {
    margin-left: auto;
    margin-right: 2rem;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-color);
    font-weight: 500;
}

.header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.theme-btn,
.menu-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-color);
    background-color: var(--card-bg);
    transition: transform 0.2s;
}

.theme-btn:active,
.menu-btn:active {
    transform: scale(0.95);
}

.menu-btn {
    display: none;
}

/* --- Post Layout Wrapper (Main + Sidebar) --- */
.post-layout-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 4rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4rem;
}
/* Modern Unified Search Bar Styling */
.search-input-group {
    display: flex;
    align-items: center;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Blue glow when clicking inside the search box */
.search-input-group:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    padding: 12px 18px;
    color: var(--text-color);
    font-size: 0.95rem;
    width: 100%;
}

.search-input::placeholder {
    color: #888888;
}
/* Search Modal Backdrop */
.search-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease-out;
}

/* Modal Content Card */
.search-modal-content {
    color: var(--text-color);
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    width: 90%;
    max-width: 520px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

/* Modal Close Button (X) */
.modal-close-btn {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    background: transparent;
    border: none;
    color: red;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
}

.modal-close-btn:hover {
    color: #ffffff;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.search-btn {
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 12px 22px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease;
}

.search-btn:hover {
    background-color: #1d4ed8;
}
@media (min-width: 1024px) {
    .post-layout-wrapper {
        grid-template-columns: 2.5fr 1fr;
    }
}
.post-header {
    margin-bottom: 2rem;
    text-align: center;
}

.category {
    display: inline-block;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: var(--tag-bg);
    color: var(--tag-text);
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.post-header h1 {
    font-size: 2.8rem;
    line-height: 1.2;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.post-meta {
    display: flex;
    justify-content: center;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    flex-wrap: wrap;
}

.post-meta .meta-item:not(:last-child)::after {
    content: "|";
    margin-left: 1rem;
    color: var(--border-color);
}

.post-body {
    line-height: 1.8;
}

.post-body p {
    margin-bottom: 1.5rem;
}

.post-body h2 {
    font-size: 1.8rem;
    margin: 2.5rem 0 1rem;
    color: var(--text-color);
}

.post-body ul {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

.post-body ul li {
    margin-bottom: 0.5rem;
}

.post-body blockquote {
    font-size: 1.4rem;
    font-style: italic;
    color: var(--primary-color);
    border-left: 4px solid var(--primary-color);
    padding: 1rem 2rem;
    margin: 2rem 0;
    background-color: var(--bg-alt);
    border-radius: 0 8px 8px 0;
}

.post-tags {
    margin-top: 3rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    background-color: var(--tag-bg);
    color: var(--tag-text);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.section-divider {
    border: 0;
    height: 1px;
    background-color: var(--border-color);
    margin: 4rem 0;
}

/* --- More Posts Section (Sidebar Sidebar Stack) --- */
.section-title {
    font-size: 1.5rem;
    margin-bottom: 2rem;
}

.sidebar-post-stack {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.recent-posts h3,
.best-posts h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.post-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background-color: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.post-content {
    padding: 1.5rem;
}

.post-card h4 {
    font-size: 1.1rem;
    margin: 0.5rem 0;
    line-height: 1.4;
}

.highlight-card {
    border-left: 4px solid var(--primary-color);
}

.date {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Comments Section --- */
.comments-section h2 {
    font-size: 1.8rem;
    margin-bottom: 2rem;
}

.comments-list {
    margin-bottom: 3rem;
}

.comment-box {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.comment-avatar {
    width: 50px;
    height: 50px;
    background-color: var(--primary-color);
    color: var(--btn-text);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.comment-content {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    width: 100%;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.comment-author {
    font-weight: 600;
    font-size: 1.1rem;
}

.comment-date {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.comment-text {
    color: var(--text-color);
    line-height: 1.6;
}

/* --- Comment Form --- */
.comment-form-container {
    background-color: var(--bg-alt);
    padding: 2.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.comment-form-container h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.comment-form-container p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 86, 179, 0.2);
}

.submit-btn {
    background-color: var(--primary-color);
    color: var(--btn-text);
    border: none;
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    align-self: flex-start;
}

.submit-btn:hover {
    background-color: var(--primary-hover);
}

/* --- Footer --- */
footer {
    background-color: var(--footer-bg);
    color: var(--footer-text);
    padding: 4rem 2rem 1rem;
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-info h3 {
    color: var(--footer-text);
    margin-bottom: 0.5rem;
}

.footer-links h4 {
    margin-bottom: 1rem;
    color: #aaaaaa;
}

.footer-links ul {
    list-style: none;
}

.footer-links a {
    color: var(--footer-text);
    font-size: 0.9rem;
}

.footer-links a:hover {
    text-decoration: underline;
}

.footer-bottom {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid #333333;
    font-size: 0.85rem;
    color: #888888;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .header-container {
        flex-wrap: wrap;
        padding: 1rem;
        align-items: center;
        justify-content: space-between;
    }

    .logo {
        flex: 1;
    }

    .menu-btn {
        display: block;
    }

    #nav-menu {
        margin-left: unset;
        margin-right: unset;
    }

    nav {
        order: 3;
        width: 100%;
        margin-top: 1rem;
        display: none;
        margin-left: 0;
        margin-right: 0;
    }

    nav.show-menu {
        display: block;
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        gap: 0;
        background-color: var(--card-bg);
        border-radius: 8px;
        border: 1px solid var(--border-color);
        overflow: hidden;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links a {
        display: block;
        padding: 0.8rem;
        text-align: center;
        border-bottom: 1px solid var(--border-color);
    }

    .nav-links li:last-child a {
        border-bottom: none;
    }

    .post-header h1 {
        font-size: 2.2rem;
    }

    .comment-box {
        flex-direction: column;
        gap: 1rem;
    }

    .comment-avatar {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .submit-btn {
        width: 100%;
    }
    .post-header h1 {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    overflow-wrap: break-word;
    word-break: break-word;
    }
    .post-layout-wrapper {
        padding: 2rem 1rem;
    }
}