/* Functor Academic Blog Styles - "Thinking Machines" Theme */

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

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #111827;
    /* Almost Black */
    --text-primary: #1A1A1A;
    --text-secondary: #4B5563;
    /* Cool Grey */
    --text-muted: #6B7280;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F3F4F6;
    --border-color: #E5E7EB;
    --accent-color: #2563EB;
    /* Muted Blue for links */
    --code-bg: #F9FAFB;

    --font-serif: 'Merriweather', Georgia, serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --max-content-width: 740px;
    --sidebar-width: 280px;
}

body {
    font-family: var(--font-serif);
    font-size: 19px;
    line-height: 1.65;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

/* --- Layout Grid --- */

.container {
    padding: 0 24px;
    max-width: 1600px;
    /* Wide container to accommodate sidebars */
    margin: 0 auto;
}

/* Post Page Grid - The Core Asymmetric Layout */
.post-page-grid {
    display: grid;
    /* Left TOC | Center Content | Right Sidenotes */
    grid-template-columns: minmax(200px, 1fr) minmax(auto, var(--max-content-width)) minmax(250px, 1fr);
    gap: 4rem;
    padding-top: 4rem;
    padding-bottom: 8rem;
    position: relative;
    align-items: start;
}

/* --- Typography Hierarchy --- */

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    margin-top: 2.5em;
    margin-bottom: 0.8em;
    font-weight: 700;
}

/* Article Title */
.post-header h1 {
    font-size: 3.5rem;
    line-height: 1.1;
    font-weight: 700;
    /* Standard weight, size carries it */
    letter-spacing: -0.02em;
    margin-bottom: 1.5rem;
    text-align: center;
}

/* Subheadings - The "Signature" Style */
.post-content h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-style: italic;
    font-weight: 400;
    /* Not bold */
    margin-top: 3rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.post-content h3 {
    font-family: var(--font-sans);
    font-size: 1.15rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2.5rem;
    color: var(--text-secondary);
}

p {
    margin-bottom: 1.5rem;
}

.post-content p,
.post-content li {
    text-align: justify;
}

a {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--text-muted);
    transition: all 0.2s ease;
}

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

/* --- Header / Navbar --- */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0;
    max-width: 1400px;
    margin: 0 auto;
    border-bottom: 1px solid transparent;
    /* Minimalist */
}

.logo {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.logo:hover {
    text-decoration: none;
    color: black;
}

.header nav {
    display: flex;
    gap: 32px;
}

.header nav a {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 400;
}

.header nav a:hover {
    color: var(--text-muted);
}


/* --- Sidebar: Table of Contents (Left) --- */

.toc-sidebar {
    position: sticky;
    top: 120px;
    padding-right: 2rem;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    color: var(--text-muted);
    /* Hidden on smaller screens */
    display: block;
}

.toc-sidebar h3 {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #999;
    margin-top: 0;
    margin-bottom: 1rem;
}

.toc-sidebar ul {
    list-style: none;
    border-left: 1px solid var(--border-color);
}

.toc-sidebar li {
    margin-bottom: 0.75rem;
}

.toc-sidebar a {
    text-decoration: none;
    color: var(--text-muted);
    display: block;
    padding-left: 1.25rem;
    line-height: 1.4;
    border-left: 2px solid transparent;
    margin-left: -1px;
    /* Align with border */
    transition: all 0.2s;
}

.toc-sidebar a:hover {
    color: var(--text-primary);
    border-left-color: var(--text-muted);
}

.toc-sidebar a.active {
    color: var(--text-primary);
    border-left-color: var(--text-primary);
    font-weight: 700;
}

/* --- Main Article Column --- */

.main-content {
    /* No max-width here, grid handles it */
}

.post-meta {
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 3rem;
}

.post-meta .post-author {
    color: var(--text-primary);
    font-weight: 500;
}

.post-subtitle {
    text-align: center;
    font-size: 1.4rem;
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.4;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

/* --- Sidebar: Sidenotes (Right) --- */

.sidenotes-sidebar {
    position: relative;
    /* Not sticky generally, but absolute items inside */
    height: 100%;
}

.sidenote {
    position: absolute;
    /* Positioned by JS relative to container which must match text height */
    width: 100%;
    right: 0;
    font-family: var(--font-serif);
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    transition: opacity 0.3s;
}

.sidenote-number {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    vertical-align: super;
    margin-right: 0.25em;
    color: var(--text-primary);
    font-weight: 600;
}

/* Reference in text */
.sidenote-ref {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    vertical-align: super;
    line-height: 0;
    color: var(--accent-color);
    cursor: pointer;
    margin-left: 2px;
}

/* --- Components --- */

/* Code Blocks */
pre {
    background: var(--code-bg);
    border-radius: 6px;
    padding: 1.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    overflow-x: auto;
    margin: 2rem 0;
}

code {
    font-family: var(--font-mono);
}

/* Tables */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 3rem 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    font-family: var(--font-sans);
}

th {
    text-align: left;
    border-bottom: 2px solid var(--text-primary);
    padding: 0.75rem 0.5rem;
    font-weight: 600;
}

td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 0.5rem;
    color: var(--text-secondary);
}

/* Images */
figure {
    margin: 3rem 0;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

figcaption {
    text-align: center;
    font-family: var(--font-sans);
    /* Tufte usually puts this in margin, but centered italic is good too */
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    font-style: italic;
}

/* Citation Block */
.citation-block {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 2rem;
    margin-top: 4rem;
    margin-bottom: 2rem;
    position: relative;
    font-family: var(--font-sans);
}

.citation-block h3 {
    margin-top: 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.citation-code {
    background: white;
    border: 1px solid var(--border-color);
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 1rem;
}

/* --- Footer --- */

.footer-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: var(--max-content-width);
    margin: 4rem auto 2rem auto;
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

.footer-nav a {
    text-decoration: none;
    color: var(--text-secondary);
}

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

.global-footer {
    text-align: center;
    padding: 3rem 0;
    border-top: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: #999;
}

/* --- Responsiveness --- */

@media (max-width: 1200px) {
    .post-page-grid {
        grid-template-columns: 200px 1fr 0px;
        /* Hide sidenote column */
        gap: 2rem;
        padding-right: 2rem;
    }

    .sidenotes-sidebar {
        display: none;
    }

    /* Make sidenotes behave like inline footnotes or bottom notes if hidden */
    /* For simplicity in this CSS-only fallback, we assume JS will handle mobile layout or CSS below */
}

@media (max-width: 900px) {
    .post-page-grid {
        display: block;
        /* Stack everything */
        max-width: 700px;
        margin: 0 auto;
        padding-top: 2rem;
    }

    .toc-sidebar {
        position: relative;
        top: 0;
        margin-bottom: 3rem;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 1rem;
    }

    .toc-sidebar ul {
        border-left: none;
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .toc-sidebar a {
        border-left: none;
        padding-left: 0;
        font-size: 0.85rem;
    }

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

/* Mobile - Very small screens */
@media (max-width: 600px) {
    body {
        font-size: 17px;
        line-height: 1.6;
    }

    .container {
        padding: 0 16px;
    }

    .header {
        padding: 16px 0;
        flex-direction: column;
        gap: 12px;
    }

    .header nav {
        gap: 20px;
    }

    .header nav a {
        font-size: 0.85rem;
    }

    .post-page-grid {
        padding-top: 1.5rem;
        padding-bottom: 3rem;
    }

    .post-header h1 {
        font-size: 1.75rem;
        line-height: 1.2;
        letter-spacing: -0.01em;
    }

    .post-subtitle {
        font-size: 1.1rem;
        max-width: 100%;
        margin-bottom: 1.5rem;
    }

    .post-meta {
        font-size: 0.8rem;
        margin-bottom: 2rem;
    }

    .post-content h2 {
        font-size: 1.25rem;
        margin-top: 2.5rem;
    }

    .post-content h3 {
        font-size: 1rem;
        margin-top: 2rem;
    }

    /* TOC: Collapsible on mobile */
    .toc-sidebar {
        margin-bottom: 2rem;
        padding-bottom: 0.75rem;
    }

    .toc-sidebar h3 {
        font-size: 0.7rem;
    }

    .toc-sidebar ul {
        gap: 0.5rem 0.75rem;
    }

    .toc-sidebar a {
        font-size: 0.75rem;
    }

    /* Code blocks: Prevent overflow */
    pre {
        padding: 1rem;
        font-size: 0.75rem;
        margin: 1.5rem -16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    code {
        font-size: 0.8rem;
    }

    /* Tables: Horizontal scroll */
    table {
        font-size: 0.85rem;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    th, td {
        padding: 0.5rem 0.4rem;
    }

    /* Images and figures */
    figure {
        margin: 2rem -16px;
    }

    figure img {
        width: calc(100% + 32px);
        max-width: none;
    }

    figcaption {
        padding: 0 16px;
        font-size: 0.8rem;
    }

    /* Footer */
    .footer-nav {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        margin: 2rem auto 1.5rem;
    }

    .global-footer {
        padding: 2rem 0;
        font-size: 0.75rem;
    }

    /* Sidenote refs on mobile - show as tooltip hint */
    .sidenote-ref {
        font-size: 0.7rem;
    }
}