/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.7;
    color: #333;
    background-color: #fff;
    font-size: 18px;
    margin: 0 auto;
    padding: 2rem;
}

/* Main container for all content */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Homepage content - centered and constrained width */
.post-list {
    max-width: 800px;
    margin: 3rem auto 0 auto;
}

/* Individual post content - use full width */
.post, .post-with-toc {
    max-width: 800px; /* Constrain reading width */
    margin: 3rem auto 0 auto; /* Center the post content */
}

/* Header */
header {
    padding: 2rem 0;
    text-align: center;
    border-bottom: 1px solid #eee;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #000;
}

nav {
    margin-top: 1rem;
}

nav ul {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 0;
    padding: 0;
}

nav a {
    color: #555;
    text-decoration: none;
    font-size: 1rem;
    transition: color 0.2s ease;
}

nav a:hover {
    color: #000;
    text-decoration: underline;
}

/* Main content */
main {
    padding: 0;
}

/* Post list on homepage */
.post-item {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.post-item:last-child {
    border-bottom: none;
}

.post-item .post-thumbnail {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.post-item-content {
    flex: 1;
}

.post-item h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-align: left;
}

.post-item h3 a {
    color: #000;
    text-decoration: none;
}

.post-item h3 a:hover {
    text-decoration: underline;
}

.post-item .post-meta {
    font-size: 0.9rem;
    color: #777;
    margin-bottom: 1rem;
    text-align: left;
}

.post-item .post-excerpt {
    font-size: 1rem;
    line-height: 1.6;
    color: #555;
    text-align: left;
}

/* Individual post pages */
.post header {
    border-bottom: none;
    margin-bottom: 1rem;
    padding: 0;
    text-align: left;
}

.post header h1 {
    font-size: 2.8rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.2;
    text-align: left;
}

.post-meta {
    color: #777;
    font-size: 0.9rem;
    margin-bottom: 3rem;
    text-align: left;
}

.post-content {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #333;
}

.post-content h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 3rem 0 1.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
    text-align: left;
}

.post-content h3 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 2.5rem 0 1rem 0;
    text-align: left;
}

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

.post-content a {
    color: #007bff;
    text-decoration: none;
}

.post-content a:hover {
    text-decoration: underline;
}

/* Media - improved styling */
figure {
    margin: 3rem 0;
    text-align: center;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto; /* Center image within figure */
    border-radius: 8px; /* Softer corners */
}

video {
    max-width: 100%;
    height: auto;
}

figcaption {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #777;
    text-align: center;
    line-height: 1.5;
}

/* Navigation */
.post-navigation {
    margin-top: 3rem;
    text-align: center;
}

.post-navigation a {
    color: #000;
    text-decoration: underline;
    font-size: 14px;
}

.post-navigation a:hover {
    text-decoration: none;
}

/* Footer */
footer {
    text-align: center;
    padding: 3rem 0;
    color: #888;
    font-size: 0.9rem;
    border-top: 1px solid #eee;
    margin-top: 5rem;
}

/* Remove duplicated and unused styles */
/* .img-caption, img + p em can be removed as we now use figure/figcaption */

/* Footnotes */
.footnote {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
    color: #666;
}

.footnote hr {
    display: none; /* Hide the default markdown footnote hr */
}

.footnote ol {
    padding-left: 20px;
    margin: 0;
}

.footnote li {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.footnote p {
    margin: 0;
    display: inline;
}

.footnote a {
    color: #007bff;
    text-decoration: none;
    font-weight: normal;
}

.footnote a:hover {
    text-decoration: underline;
}

/* Footnote references in text */
sup {
    line-height: 0; /* prevent sup from affecting line-height */
}

sup a {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8em;
    vertical-align: super;
}

sup a:hover {
    text-decoration: underline;
}

/* Table of Contents */
.post-with-toc {
    display: grid;
    grid-template-columns: 1fr 300px; /* Give TOC a bit more space */
    gap: 60px;
    margin-bottom: 40px;
    max-width: 1200px; /* Allow wider layout for TOC */
}

.post-content-wrapper {
    min-width: 0; /* Prevents grid overflow */
    max-width: 800px; /* Constrain reading width */
}

.table-of-contents {
    position: sticky;
    top: 40px;
    height: fit-content;
    padding: 25px;
    background: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 8px;
    font-size: 0.9rem;
}

.table-of-contents h3 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #000;
}

.table-of-contents ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.table-of-contents li {
    margin: 0;
    line-height: 1.5;
}

.table-of-contents a {
    display: block;
    padding: 8px 0;
    color: #666;
    text-decoration: none;
    border-left: 3px solid transparent;
    padding-left: 15px;
    transition: all 0.2s ease;
}

.table-of-contents a:hover {
    color: #000;
    border-left-color: #ccc;
}

.table-of-contents a.active {
    color: #000;
    border-left-color: #000;
    font-weight: 600;
}

/* Nested headers in TOC */
.table-of-contents li.h3 a {
    padding-left: 30px;
}

.table-of-contents li.h4 a {
    padding-left: 45px;
}

/* Mobile responsive - hide TOC on small screens */
@media (max-width: 1100px) {
    .post-with-toc {
        grid-template-columns: 1fr;
        gap: 30px;
        max-width: 800px; /* Revert to single column max-width */
    }
    
    .table-of-contents {
        order: -1; /* Show TOC before content on mobile */
        position: static;
        margin-bottom: 2rem;
    }
}

@media (max-width: 900px) {
    .table-of-contents {
        display: none; /* Hide TOC on very small screens */
    }
    
    .post-with-toc {
        grid-template-columns: 1fr;
    }
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Add some space above headers for better anchor positioning */
.post h2, .post h3, .post h4 {
    scroll-margin-top: 40px;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 1rem;
        font-size: 16px;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .post-list {
        max-width: none;
        margin: 2rem 0 0 0;
    }
    
    /* Mobile-friendly post items */
    .post-item {
        flex-direction: column;
        gap: 1rem;
        margin-bottom: 2rem;
        padding-bottom: 2rem;
    }
    
    .post-item .post-thumbnail {
        width: 100%;
        height: auto;
        max-height: 250px;
        object-fit: cover;
    }
    
    .post-item h3 {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }
    
    .post-item .post-meta {
        font-size: 0.85rem;
    }
    
    .post-item .post-excerpt {
        font-size: 0.95rem;
    }
    
    header {
        padding: 1.5rem 0;
        margin-bottom: 1rem;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .post header h1 {
        font-size: 2rem;
    }
    
    nav ul {
        gap: 1rem;
        flex-wrap: wrap;
    }
}
