@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
    --bg: #f8f3ed;
    --text: #1a1510;
    --text-mid: #4a4539;
    --text-light: #8a7f6f;
    --accent: #c7402a;
    --border: #d4c9ba;
    --code-bg: #ebe5db;
    --sidenote-bg: #f0ebe2;
    --highlight-bg: #fff5b8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-size: 19px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 32px;
}

/* Header */
header {
    padding: 100px 0 70px;
}

.site-title {
    font-size: 52px;
    font-weight: 600;
    margin: 0 0 20px 0;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.site-title a {
    color: var(--text);
    text-decoration: none;
}

.site-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 18px;
    color: var(--text-mid);
    margin-bottom: 60px;
    max-width: 540px;
}

nav {
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    font-weight: 500;
    display: flex;
    gap: 28px;
}

nav a {
    color: var(--text-mid);
    text-decoration: none;
    transition: color 0.2s;
}

nav a:hover {
    color: var(--accent);
}

/* Main Content */
main {
    padding: 0 0 100px;
}

/* Year Groups */
.year-group {
    margin-bottom: 56px;
}

.year-heading {
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-light);
    margin: 0 0 20px 0;
    padding: 0;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

/* Ensure first year group doesn't have extra top margin */
.year-group:first-child {
    margin-top: 0;
}

.year-group:first-child .year-heading {
    margin-top: 0;
}

/* Feed Items */
.feed-item {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 20px;
    margin: 0 0 20px 0;
    align-items: baseline;
}

.item-date {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: var(--text-light);
}

.feed-item h2 {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.feed-item h2 a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s;
}

.feed-item h2 a:hover {
    color: var(--accent);
}

/* Footer */
footer {
    padding: 60px 0 80px;
    border-top: 1px solid var(--border);
}

.footer-links {
    font-family: 'Inter', sans-serif;
    display: flex;
    gap: 28px;
    margin-bottom: 16px;
}

.footer-links a {
    color: var(--text-mid);
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent);
}

.footer-note {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: var(--text-light);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        font-size: 18px;
    }

    .container {
        padding: 0 20px;
    }

    header {
        padding: 70px 0 50px;
    }
    
    .site-title {
        font-size: 40px;
    }
    
    .feed-item {
        grid-template-columns: 1fr;
        gap: 4px;
        margin-bottom: 24px;
    }

    .feed-item h2 {
        font-size: 22px;
    }

    nav {
        gap: 20px;
        flex-wrap: wrap;
    }

    .footer-links {
        flex-wrap: wrap;
        gap: 20px;
    }
}

/* ============================================
   POST PAGE STYLES
   ============================================ */

/* Reading Progress Bar */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: var(--accent);
    z-index: 1000;
    transition: width 0.1s ease-out;
}

/* Post Container - Wider for sidenotes */
.post-container {
    max-width: 1400px;
    padding: 0 40px;
    overflow: visible;
}

/* On larger screens, make container wide enough for article + sidenotes */
@media (min-width: 1200px) {
    .post-container {
        max-width: 100%;
        padding: 0;
    }
    
    .post-container header,
    .post-container footer {
        max-width: 1400px;
        margin-left: auto;
        margin-right: auto;
        padding-left: 40px;
        padding-right: 40px;
    }
    
    /* Ensure article can be full 1600px width */
    .post-container article {
        width: 100%;
        max-width: 1600px;
        margin-left: auto;
        margin-right: auto;
    }
}

.post-container header {
    max-width: 820px;
    margin: 0 auto;
}

.post-container footer {
    max-width: 820px;
    margin: 0 auto;
    border-top: 1px solid var(--border);
    padding: 40px 0;
}

.post-container .footer-links {
    font-family: 'Inter', sans-serif;
    display: flex;
    gap: 28px;
}

.post-container .footer-links a {
    color: var(--text-light);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: color 0.2s;
}

.post-container .footer-links a:hover {
    color: var(--accent);
}

/* Article Layout - Centred with side margins for notes */
article {
    max-width: 1600px;
    margin: 0 auto;
    padding: 60px 0 80px;
    position: relative;
}

/* On large screens, allow sidenotes to overflow article bounds */
@media (min-width: 1200px) {
    article {
        overflow: visible;
    }
}

.article-main {
    max-width: 820px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* Article Header */
.article-meta {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 16px;
}

article h1 {
    font-size: 44px;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 40px;
    letter-spacing: -0.03em;
}

/* Article Content - Typography */
.article-content p {
    margin-bottom: 24px;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInUp 0.6s ease-out forwards;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Stagger paragraph animations */
.article-content p:nth-child(1) { animation-delay: 0.05s; }
.article-content p:nth-child(2) { animation-delay: 0.1s; }
.article-content p:nth-child(3) { animation-delay: 0.15s; }
.article-content p:nth-child(4) { animation-delay: 0.2s; }
.article-content p:nth-child(5) { animation-delay: 0.25s; }
.article-content p:nth-child(6) { animation-delay: 0.3s; }
.article-content p:nth-child(7) { animation-delay: 0.35s; }
.article-content p:nth-child(8) { animation-delay: 0.4s; }
.article-content p:nth-child(9) { animation-delay: 0.45s; }
.article-content p:nth-child(10) { animation-delay: 0.5s; }

.article-content h2 {
    font-size: 32px;
    font-weight: 600;
    margin-top: 56px;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}

.article-content h3 {
    font-size: 26px;
    font-weight: 600;
    margin-top: 40px;
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

.article-content h4 {
    font-size: 22px;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 16px;
}

/* Links - Animated underline */
.article-content a {
    color: var(--accent);
    text-decoration: none;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-size: 0% 1px;
    background-repeat: no-repeat;
    background-position: left bottom;
    transition: background-size 0.3s ease-out;
}

.article-content a:hover {
    background-size: 100% 1px;
}

/* Highlighting */
.article-content mark {
    background: var(--highlight-bg);
    padding: 2px 4px;
    border-radius: 2px;
}

/* Emphasis */
.article-content em {
    font-style: italic;
}

.article-content strong {
    font-weight: 600;
}

/* Lists */
.article-content ul,
.article-content ol {
    margin-bottom: 24px;
    padding-left: 28px;
}

.article-content li {
    margin-bottom: 8px;
}

/* Blockquotes */
.article-content blockquote {
    margin: 32px 0;
    padding-left: 24px;
    border-left: 3px solid var(--accent);
    color: var(--text-mid);
    font-style: italic;
}

.article-content blockquote p {
    margin-bottom: 0;
}

/* Code */
.article-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
}

.article-content pre {
    margin: 32px 0;
    padding: 20px;
    background: var(--code-bg);
    border-radius: 6px;
    overflow-x: auto;
}

.article-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.5;
}

/* Images */
.article-content img {
    max-width: 100%;
    height: auto;
    margin: 40px 0;
    border-radius: 4px;
    transition: transform 0.3s ease-out, filter 0.3s ease-out;
}

.article-content img:hover {
    transform: scale(1.02);
    filter: brightness(1.05);
}

.article-content figure {
    margin: 40px 0;
}

.article-content figure img {
    margin: 0 0 12px 0;
}

.article-content figcaption {
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    color: var(--text-light);
    text-align: center;
}

/* Horizontal Rule */
.article-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 48px 0;
}

/* Sidenotes - Alternating Left and Right */
.sidenote-ref {
    color: var(--accent);
    font-family: 'Inter', sans-serif;
    font-size: 0.75em;
    vertical-align: super;
    text-decoration: none;
    margin-left: 2px;
    font-weight: 500;
    transition: background-color 0.2s ease-out, color 0.2s ease-out;
    padding: 2px 4px;
    border-radius: 3px;
}

.sidenote-ref:hover {
    text-decoration: underline;
}

.sidenote-ref.highlighted {
    background-color: var(--accent);
    color: var(--bg);
    text-decoration: none;
}

.sidenote {
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-mid);
    background: var(--sidenote-bg);
    padding: 16px;
    border-radius: 4px;
    position: absolute;
    width: 260px;
    max-width: 260px;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out, border-color 0.2s ease-out, box-shadow 0.2s ease-out;
    border: 2px solid transparent;
    z-index: 0;
}

.sidenote.highlighted {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidenote.highlighted a {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.sidenote.highlighted a:hover {
    border-bottom-color: transparent;
}


.sidenote.visible {
    opacity: 1;
    transform: translateX(0);
}

.sidenote a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
}

.sidenote a:hover {
    border-bottom-color: transparent;
}

/* Left side sidenotes */
.sidenote.left {
    left: 60px;
    transform: translateX(20px);
}

.sidenote.left.visible {
    transform: translateX(0);
}

/* Right side sidenotes */
.sidenote.right {
    right: 60px;
}

/* On large screens, position sidenotes in margins outside article content */
@media (min-width: 1200px) {
    /* Calculate available space: viewport width minus article-main (820px) divided by 2, minus gap and margin */
    /* This ensures sidenotes stay within bounds and can grow taller if window is narrow */
    .sidenote {
        /* Available space per side = (100vw - 820px) / 2, minus 60px gap, minus 60px viewport margin */
        /* Use min() to cap at 260px but allow smaller if viewport is narrow */
        max-width: min(260px, calc((100vw - 820px) / 2 - 120px));
        width: min(260px, calc((100vw - 820px) / 2 - 120px));
    }
    
    /* Position sidenotes relative to article center (where article-main is centered) */
    /* Article-main is 820px, so half is 410px */
    /* Left sidenotes: center - 410px (to article-main left) - 60px gap - sidenote width */
    .sidenote.left {
        left: 50%;
        margin-left: calc(-410px - 60px);
        transform: translateX(-100%) translateX(20px);
    }
    
    .sidenote.left.visible {
        transform: translateX(-100%);
    }
    
    /* Right sidenotes: center + 410px (to article-main right) + 60px gap */
    .sidenote.right {
        left: 50%;
        margin-left: calc(410px + 60px);
        right: auto;
    }
}

/* Mobile: sidenotes inline */
@media (max-width: 1199px) {
    .sidenote {
        display: none;
    }

    .sidenote-inline {
        display: block;
        margin: 32px 0;
        background: var(--sidenote-bg);
        padding: 16px;
        border-radius: 4px;
        font-family: 'Inter', sans-serif;
        font-size: 15px;
        line-height: 1.5;
        color: var(--text-mid);
    }

    .sidenote-inline a {
        color: var(--accent);
        text-decoration: none;
        border-bottom: 1px solid var(--accent);
    }

    .sidenote-inline a:hover {
        border-bottom-color: transparent;
    }
}

@media (min-width: 1200px) {
    .sidenote-inline {
        display: none;
    }
}

/* Post Page Responsive */
@media (max-width: 768px) {
    article {
        padding: 40px 0 60px;
    }

    article h1 {
        font-size: 34px;
    }

    .article-content h2 {
        font-size: 28px;
        margin-top: 40px;
    }

    .article-content h3 {
        font-size: 23px;
        margin-top: 32px;
    }

    .article-content h4 {
        font-size: 20px;
    }
}
