/* Global Variables & Resets */
:root {
    --text-color: #333;
    --background-color: #ffffff;
    --container-bg: #fff;
    --link-color: #365c7c;
    --header-bg: #365c7c;
    --header-text-color: white;
    --search-input-bg: #3a576e;
    --search-input-border: #4a657c;
    --post-card-bg: #fff;
    --post-card-shadow: rgba(0, 0, 0, 0.1);
    --post-category-color: #666;
    --post-description-color: #555;
    --post-meta-color: #777;
    --tag-bg: #f0f0f0;
    --tag-text: #555;
    --footer-color: #777;
    --section-title-color: #333;
    --section-subtitle-color: #555;
    --mobile-menu-bg: #365c7c;
    --mobile-menu-border: rgba(255, 255, 255, 0.2);
    --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
}

body.dark-mode {
    --text-color: #f0f0f0;
    --background-color: #282828;
    --container-bg: #282828;
    --header-text-color: #f0f0f0;
    --search-input-bg: #3a3a3a;
    --search-input-border: #555;
    --post-card-bg: #282828;
    --post-card-shadow: rgba(255, 255, 255, 0.1);
    --post-category-color: #b0b0b0;
    --post-description-color: #ccc;
    --post-meta-color: #b0b0b0;
    --tag-bg: #555;
    --tag-text: #f0f0f0;
    --footer-color: #b0b0b0;
    --section-title-color: #f0f0f0;
    --section-subtitle-color: #f0f0f0;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
    border: none;
    outline: none;
}

body {
    font-family: var(--font-main);
    font-size: 1.1em;
    line-height: 1.5;
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.no-scroll {
    overflow: hidden;
}

/* Layout & Typography */
h1,
h2,
h3 {
    color: var(--text-color);
    font-family: var(--font-main);
    font-weight: 700;
    transition: color 0.3s ease;
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1400px;
    margin: auto;
    padding: 30px;
    box-sizing: border-box;
    background: var(--container-bg);
    transition: background-color 0.3s ease;
}

/* Header */
.main-header {
    background-color: var(--header-bg);
    color: var(--header-text-color);
    width: 100%;
    transition: background-color 0.3s ease;
}

.header-content {
    max-width: 1400px;
    margin: auto;
    padding: 15px 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.logo h1 {
    margin: 0;
    font-size: 1.6em;
    font-weight: bold;
    white-space: nowrap;
}

.logo h1 a,
.main-header .logo h1 a {
    color: var(--header-text-color) !important;
    text-decoration: none !important;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* Search & Buttons */
.search-form {
    display: flex;
    align-items: center;
    background-color: var(--search-input-bg);
    border: 1px solid var(--search-input-border);
    border-radius: 20px;
    padding: 5px 10px;
    transition: background-color 0.3s ease;
}

.search-form input[type="text"] {
    background: transparent;
    border: none;
    color: var(--header-text-color);
    padding: 5px;
    font-size: 0.9em;
    outline: none;
    width: 150px;
    transition: width 0.3s ease;
}

.search-form input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.search-form button,
.dark-mode-toggle,
.mobile-nav-toggle,
.mobile-nav-close {
    background: transparent;
    border: none;
    color: var(--header-text-color);
    cursor: pointer;
}

.dark-mode-toggle {
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 4px;
    transition: 0.3s ease;
}

.dark-mode-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Navigation */
.main-nav {
    margin-top: 15px;
    width: 100%;
}

.main-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

.main-nav li {
    margin: 5px 10px;
}

.main-nav a {
    color: var(--header-text-color);
    font-weight: bold;
    padding: 8px 12px;
    border-radius: 4px;
    transition: 0.3s ease;
}

.main-nav a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Mobile Nav */
.mobile-nav-toggle {
    font-size: 1.5em;
    padding: 5px;
}

.mobile-nav-overlay {
    position: fixed;
    top: 0;
    right: -100%;
    width: 80%;
    height: 100vh;
    background-color: var(--mobile-menu-bg);
    z-index: 1000;
    transition: right 0.3s ease;
    padding: 20px;
    box-sizing: border-box;
    border-left: 1px solid var(--mobile-menu-border);
}

.mobile-nav-overlay.active {
    right: 0;
}

.mobile-nav-close {
    font-size: 2em;
    float: right;
    margin-bottom: 20px;
}

.mobile-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mobile-nav li {
    margin-bottom: 15px;
}

.mobile-nav a {
    color: var(--header-text-color);
    font-size: 1.2em;
    font-weight: bold;
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--mobile-menu-border);
}

/* Post Content */
.post-detail-container {
    max-width: 728px;
    margin: 20px auto;
    padding: 0 15px;
}

.post-title-detail {
    font-size: 2.5em;
    line-height: 1.2;
    margin-bottom: 0.5em;
}

.post-description-detail {
    font-size: 1.3em;
    color: var(--post-description-color);
    margin-bottom: 1em;
}

.post-meta {
    font-size: 0.9em;
    color: var(--post-meta-color);
    margin-bottom: 1.5em;
}

.post-body-content {
    font-size: 1.15em;
    line-height: 1.6;
    color: var(--text-color);
    word-wrap: break-word;
}

.post-body-content p {
    margin-bottom: 1.2em;
}

/* UPDATED: Reduced Heading Margins */
.post-body-content h1 {
    font-size: 2.5em;
    margin: 1em 0 0.5em;
}

.post-body-content h2 {
    font-size: 2em;
    margin: 0.9em 0 0.4em;
}

.post-body-content h3 {
    font-size: 1.7em;
    margin: 0.8em 0 0.3em;
}

.post-body-content h4 {
    font-size: 1.4em;
    margin: 0.7em 0 0.3em;
}

.post-body-content h5 {
    font-size: 1.2em;
    margin: 0.6em 0 0.2em;
}

.post-body-content h6 {
    font-size: 1.1em;
    margin: 0.5em 0 0.2em;
}

.post-body-content img {
    max-width: 100% !important;
    height: auto !important;
    display: block;
    margin: 1.2em auto;
}

/* Figures */
.post-body-content figure {
    margin: 3em auto 3.5em;
    text-align: center;
    max-width: 100%;
}

.post-body-content figure img {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.post-body-content figcaption {
    margin-top: 1.5em;
    font-size: 0.875rem;
    font-style: italic;
    color: #6b7280;
    font-family: Georgia, serif;
}

.post-body-content figcaption a {
    color: #6b7280;
    border-bottom: 1px solid transparent;
    transition: 0.2s;
}

.post-body-content figcaption a:hover {
    color: var(--link-color);
    border-bottom-color: var(--link-color);
}

/* Dark Mode Figures */
body.dark-mode .post-body-content figure img {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

body.dark-mode .post-body-content figcaption,
body.dark-mode .post-body-content figcaption a {
    color: #9ca3af;
}

/* Post Grid */
.post-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-top: 30px;
}

.post-card {
    background: var(--post-card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 5px var(--post-card-shadow);
    overflow: hidden;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
}

.post-card:hover {
    box-shadow: 0 6px 24px var(--post-card-shadow);
    transform: translateY(-2px);
    text-decoration: none;
}

.post-card h3,
.post-card .post-description,
.post-category,
.post-meta-info {
    padding: 6px 12px;
    margin: 0;
}

.post-card h3 {
    font-size: 1.5em;
    color: var(--text-color);
}

.post-card .post-description {
    font-size: 1em;
    color: var(--post-description-color);
}

.post-card .post-image-placeholder {
    width: 100%;
    height: 200px;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

.post-card .post-image-placeholder img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* Code Blocks */
.codehilite,
pre {
    background: #f3f4f6;
    padding: 20px 24px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 2em 0;
    border: 1px solid #e1e4e8;
    font-family: var(--font-mono);
    font-size: 0.95em !important;
    line-height: 1.6;
    color: #24292f;
}

.codehilite pre {
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
}

code {
    background: #f3f4f6;
    color: #e11d48;
    padding: 0.125em 0.375em;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.875em;
    font-weight: 500;
}

/* Syntax Highlighting */
.codehilite .k,
.codehilite .kd,
.codehilite .kn,
.codehilite .kp,
.codehilite .kr,
.codehilite .kt,
.codehilite .o,
.codehilite .ow,
.codehilite .ne {
    color: #d73a49;
}

.codehilite .s,
.codehilite .s1,
.codehilite .s2,
.codehilite .sb,
.codehilite .sc,
.codehilite .sd,
.codehilite .se,
.codehilite .sh,
.codehilite .si,
.codehilite .sx,
.codehilite .sr,
.codehilite .ss,
.codehilite .m,
.codehilite .mi,
.codehilite .mf,
.codehilite .mh,
.codehilite .mo,
.codehilite .nb,
.codehilite .no {
    color: #032f62;
}

.codehilite .c,
.codehilite .c1,
.codehilite .cm,
.codehilite .cp,
.codehilite .cs {
    color: #6a737d;
    font-style: italic;
}

.codehilite .na,
.codehilite .nc,
.codehilite .nd,
.codehilite .nf,
.codehilite .nx {
    color: #6f42c1;
}

.codehilite .nt {
    color: #22863a;
}

.codehilite .nv {
    color: #e36209;
}

/* Dark Mode Code */
body.dark-mode .codehilite,
body.dark-mode pre {
    background: #161b22;
    color: #e6edf3;
    border-color: #30363d;
}

body.dark-mode code {
    background: #262c36;
    color: #f97316;
}

body.dark-mode .codehilite .k,
body.dark-mode .codehilite .kd,
body.dark-mode .codehilite .kn,
body.dark-mode .codehilite .kp,
body.dark-mode .codehilite .kr,
body.dark-mode .codehilite .kt,
body.dark-mode .codehilite .ne,
body.dark-mode .codehilite .o,
body.dark-mode .codehilite .ow {
    color: #ff7b72;
}

body.dark-mode .codehilite .s,
body.dark-mode .codehilite .s1,
body.dark-mode .codehilite .s2,
body.dark-mode .codehilite .sb,
body.dark-mode .codehilite .sc,
body.dark-mode .codehilite .sd,
body.dark-mode .codehilite .se,
body.dark-mode .codehilite .sh,
body.dark-mode .codehilite .si,
body.dark-mode .codehilite .sx,
body.dark-mode .codehilite .sr,
body.dark-mode .codehilite .ss,
body.dark-mode .codehilite .m,
body.dark-mode .codehilite .mi,
body.dark-mode .codehilite .mf,
body.dark-mode .codehilite .mh,
body.dark-mode .codehilite .mo,
body.dark-mode .codehilite .nb,
body.dark-mode .codehilite .no {
    color: #a5d6ff;
}

body.dark-mode .codehilite .c,
body.dark-mode .codehilite .c1,
body.dark-mode .codehilite .cm,
body.dark-mode .codehilite .cp,
body.dark-mode .codehilite .cs {
    color: #8b949e;
}

body.dark-mode .codehilite .na,
body.dark-mode .codehilite .nc,
body.dark-mode .codehilite .nd,
body.dark-mode .codehilite .nf,
body.dark-mode .codehilite .nx {
    color: #d2a8ff;
}

body.dark-mode .codehilite .nt {
    color: #7ee787;
}

body.dark-mode .codehilite .nv {
    color: #ffa657;
}

/* MarkdownX Overrides */
.markdownx .markdownx-preview code,
.markdownx .markdownx-preview pre {
    font-size: 0.95em !important;
}

.markdownx .markdownx-preview img {
    max-width: 100% !important;
    height: auto !important;
}

/* Footer & Extras */
.related-posts-section,
.author-section,
.footer {
    margin-top: 60px;
    padding-top: 30px;
    border-top: 1px solid #eee;
}

.related-posts-section h2,
.author-section h2 {
    font-size: 2.8em;
    font-weight: bold;
    margin-bottom: 30px;
    color: var(--section-title-color);
}

.related-posts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}

.related-post-card {
    background: var(--post-card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 5px var(--post-card-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
}

.related-post-card:hover {
    box-shadow: 0 6px 24px var(--post-card-shadow);
    transform: translateY(-2px);
    text-decoration: none;
}

.related-post-image-placeholder {
    width: 100%;
    height: 200px;
    background: #f5f5f5;
    overflow: hidden;
}

.related-post-image-placeholder img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border: none;
}

.related-post-category,
.related-post-card h3,
.related-post-description,
.related-post-meta-info {
    padding: 0.25em 0.5em;
}

.author-logo {
    width: 32px;
    height: 32px;
    vertical-align: middle;
    margin-right: 5px;
}

.footer {
    text-align: center;
    color: var(--footer-color);
    padding: 30px 0;
}

/* Mobile (max-width: 767px) */
@media (max-width: 767px) {
    body {
        font-size: 1em;
    }

    .container {
        padding: 20px 15px;
    }

    .top-bar .logo h1 {
        font-size: 2.2em;
    }

    .main-nav,
    .mobile-nav-toggle {
        display: block;
    }

    .main-nav {
        display: none;
    }

    .search-form input[type="text"] {
        width: 120px;
        font-size: 0.95em;
    }

    .mobile-nav-overlay.active {
        width: 300px;
    }

    .mobile-nav a {
        font-size: 1.5em;
        padding: 0 10px;
    }

    .post-grid {
        grid-template-columns: 1fr;
        gap: 25px;
    }

    .post-card h3 {
        font-size: 2em;
    }

    .post-card .post-description {
        font-size: 1.3em;
    }

    .post-card .post-image-placeholder {
        height: 180px;
    }

    .post-title-detail {
        font-size: 3.2em;
    }

    .post-description-detail {
        font-size: 1.6em;
    }

    .post-detail-container {
        font-size: 1em !important;
    }

    .post-body-content,
    .post-body-content * {
        font-size: 1.05em !important;
        line-height: 1.6 !important;
    }

    .post-body-content h1 {
        font-size: 2.2em !important;
    }

    .post-body-content h2 {
        font-size: 1.8em !important;
    }

    .post-body-content h3 {
        font-size: 1.5em !important;
    }

    .post-body-content h4 {
        font-size: 1.3em !important;
    }

    .post-body-content h5 {
        font-size: 1.15em !important;
    }

    .post-body-content h6 {
        font-size: 1.05em !important;
    }

    .author-description,
    .author-description * {
        font-size: 1em !important;
    }

    .post-body-content code {
        font-size: 0.75em !important;
        background: rgba(243, 244, 246, 0.5) !important;
        font-weight: 400 !important;
    }

    .codehilite,
    pre,
    .markdownx .markdownx-preview code {
        font-size: 0.75em !important;
    }

    .post-body-content pre code,
    .codehilite code {
        font-size: 1em !important;
        background: none !important;
    }

    .post-body-content figure {
        margin: 2em auto 2.5em;
    }
}

/* Tablet & Desktop (min-width: 768px) */
@media (min-width: 768px) {
    .mobile-nav-toggle {
        display: none;
    }

    .header-content {
        flex-direction: row !important;
        justify-content: space-between;
        flex-wrap: nowrap;
    }

    .logo {
        flex: 0 0 auto;
    }

    .header-right {
        flex: 0 0 auto;
        justify-content: flex-end;
    }

    .main-nav {
        display: flex;
        flex: 1;
        justify-content: center;
        margin: 0 20px;
    }

    .search-form input[type="text"] {
        width: 200px;
    }

    .post-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
        gap: 30px;
    }

    .related-posts-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px;
    }

    .post-title-detail {
        font-size: 3.5em;
    }

    .post-description-detail {
        font-size: 1.4em;
    }
}

/* Large Desktop */
@media (min-width: 1200px) {
    .post-grid {
        grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    }

    .search-form input[type="text"] {
        width: 250px;
    }
}

/* Homepage Sections */
.home-landing {
    max-width: 1000px;
    margin: 0 auto;
}

.section-heading {
    font-size: 1.4em;
    font-weight: 700;
    color: var(--section-title-color);
    margin: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5em;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5em;
}

body.dark-mode .section-header {
    border-color: #444;
}

.view-all-link {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--link-color);
    white-space: nowrap;
}

.view-all-link:hover {
    text-decoration: underline;
}

/* Featured Card */
.featured-section {
    margin-bottom: 3em;
}

.featured-section .section-heading {
    margin-bottom: 1em;
}

.featured-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5em;
}

@media (min-width: 768px) {
    .featured-grid {
        grid-template-columns: 3fr 2fr;
    }

    .featured-hero {
        grid-row: 1 / 2;
        grid-column: 1 / 2;
    }

    .featured-secondary {
        grid-row: 1 / 2;
        grid-column: 2 / 2;
    }
}

.featured-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    background: var(--post-card-bg);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 12px var(--post-card-shadow);
    transition: box-shadow 0.3s ease, transform 0.2s ease;
}

.featured-card:hover {
    box-shadow: 0 6px 24px var(--post-card-shadow);
    transform: translateY(-2px);
    text-decoration: none;
}

/* Hero card */
.featured-hero .featured-image {
    height: 280px;
    overflow: hidden;
}

.featured-hero .featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.featured-hero .featured-content h3 {
    font-size: 1.5em;
    line-height: 1.3;
}

/* Secondary cards */
.featured-secondary {
    display: flex;
    flex-direction: column;
    gap: 1.5em;
}

.featured-small .featured-image {
    height: 140px;
    overflow: hidden;
}

.featured-small .featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.featured-small .featured-content h3 {
    font-size: 1.1em;
    line-height: 1.3;
}

.featured-small .featured-description {
    display: none;
}

/* Shared featured content */
.featured-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1em 1.2em;
}

.featured-tag {
    font-size: 0.75em;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--post-category-color);
    margin-bottom: 0.4em;
}

.featured-content h3 {
    margin: 0 0 0.4em;
    color: var(--text-color);
}

.featured-description {
    font-size: 0.95em;
    color: var(--post-description-color);
    line-height: 1.5;
    margin-bottom: 0.8em;
}

.featured-meta {
    font-size: 0.8em;
    color: var(--post-meta-color);
    display: flex;
    gap: 0.4em;
    margin-top: auto;
}

/* Latest & Portfolio Sections */
.latest-section,
.portfolio-section {
    margin-bottom: 3em;
}

/* Mobile Featured */
@media (max-width: 767px) {
    .featured-hero .featured-image {
        height: 200px;
    }

    .featured-hero .featured-content h3 {
        font-size: 1.3em;
    }
}

/* Tags Page Styles */
.tags-container {
    max-width: 1000px;
    margin: 2em auto 4em;
    padding: 0 1em;
}

.tags-header {
    text-align: center;
    margin-bottom: 3em;
}

.tags-header h1 {
    font-size: 2.5em;
    color: var(--text-color);
    margin-bottom: 0.3em;
}

.tags-subtitle {
    font-size: 1.1em;
    color: var(--post-description-color);
}

.tags-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5em;
}

.tag-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2em 1.5em;
    background: var(--post-card-bg);
    border: 1px solid var(--mobile-menu-border);
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

body.dark-mode .tag-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.tag-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    border-color: var(--link-color);
    text-decoration: none;
}

body.dark-mode .tag-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.tag-name {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5em;
    text-align: center;
}

.tag-count {
    font-size: 0.85em;
    font-weight: 600;
    color: #fff;
    background-color: var(--link-color);
    padding: 0.4em 1em;
    border-radius: 20px;
    letter-spacing: 0.05em;
}