/* Variables */
:root {
    --fg: #090C9B;
    --bg: #FFFDF7;
    --fg2:  #090C9B;
    --fg3:  #7E818B;
    --highlight-color: rgba(55, 84, 237, 0.3);
    --font-mono: 'IBM Plex Mono', 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
    --font-sans: 'Pilcrow', 'Arial', 'Helvetica', sans-serif;
    --font-serif: 'Sentient', 'Times New Roman', 'Georgia', serif;
    --container-width: 1320px;
    --base-font-size: 16px;
}
 
/* Dark mode variables */
[data-theme="dark"] {
    --fg: #FFFDF7;
    --bg: #03053A;
    --fg2: #FFFDF7;
    --fg3: #8FB3F5;
    --highlight-color: rgba(55, 84, 237, 0.5);
}

/* Toggle button styles */
.theme-toggle {
    position: fixed;
    top: 0;
    right: 0;
    width: 28px;
    height: 28px;
    background-color: var(--fg2);
    border: none;
    cursor: pointer;
    z-index: 1000;
    transition: background-color 0.2s;
}

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

@font-face {
    font-family: 'Pilcrow';
    src: url('/fonts/PilcrowRounded-subset.woff2') format('woff2-variations');
    font-display: swap;
    font-weight: 400 600 800;
}

@font-face {
    font-family: 'Sentient';
    src: url('/fonts/SentientVariable-subset.woff2') format('woff2-variations');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

body {
    background-color: var(--bg);
    color: var(--fg);
    overflow-x: hidden; /* Prevent horizontal scrolling */
    transition: background-color 0.3s, color 0.3s;
    font-size: var(--base-font-size);
}

/* Container positioning */
.post-container {
    position: relative;
    width: 100%;
    max-width: var(--container-width);
    margin: 20px auto 100px;
    padding-left: 40px;
    padding-right: 40px;
}

main {
    position: relative;
    margin: 0 auto;
    max-width: 100%;
}

/* Navigation */
.main-nav {
    position: relative;
    top: 4rem;
    width: 100%;
    max-width: var(--container-width);
    z-index: 100;
    margin: 0 auto 20px;
    padding-left: 40px;
    padding-right: 40px;
}

.main-nav ul {
    list-style: none;
    display: flex;
    gap: 40px;
}

.main-nav a {
    font-family: var(--font-sans);
    font-size: 1.2rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--fg);
    display: inline-block;
    padding: 3px 8px;
    text-transform: uppercase;
}

/* Top row: Header and Image */
.top-row {
    display: flex;
    gap: 60px;
    margin-bottom: 40px;
    margin-top: 80px;
    align-items: flex-end;
}

/* Post header */
.post-header {
    flex: 4;
    position: relative;
    z-index: 5;
    text-align: left;
}

.post-image img {
    width: 100%;
    height: auto;
    display: block;
}

.post-image {
    flex: 3;
    min-width: 100px;
}

.bottom-row {
    display: flex;
    gap: 60px;
    align-items: flex-start;
}

/* Section labels */
.section-label {
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--fg3);
    font-size: 0.9rem;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--fg3);
    margin-bottom: 20px;
}

.section-label::before {
    content: "/ ";
}

/* Left column with metadata */
.left-column {
    position: sticky;
    top: 0;
    width: 400px;
    flex-shrink: 0;
    align-self: flex-start;
    z-index: 2;
    background-color: var(--bg);
    padding-top: 15px;
    transition: background-color 0.3s;
}

.left-column::before {
    content: '';
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 460px;
    height: 15px;
    background-color: var(--bg);
    z-index: 0;
    transition: background-color 0.3s;
}

/* Mini header that appears after scrolling */
.post-header-mini {
    display: none;
    font-family: var(--font-sans);
    font-weight: 600;
    width: 100%;
    background-color: var(--bg);
    z-index: 3;
    margin-bottom: 2rem;
    transition: opacity 0.2s ease, background-color 0.3s;
}

.post-header-mini.visible {
    display: block;
    opacity: 1;
}

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

/* Ensure home page uses the same styles */
body.home .post-header-mini {
    display: none;
}

body.home .post-header-mini.visible {
    display: block;
}

/* Metadata section */
.metadata-section {
    background-color: var(--bg);
    transition: background-color 0.3s;
}

.metadata-section.sticky .section-label {
    position: sticky;
    top: 75px; /* Space for mini header */
    background-color: var(--bg);
    z-index: 2;
    padding-top: 5px;
    transition: background-color 0.3s;
}

/* Make sure sticky header elements update color correctly when theme changes */
[data-theme="dark"] .post-header-mini,
[data-theme="dark"] .left-column,
[data-theme="dark"] .metadata-section,
[data-theme="dark"] .metadata-section.sticky .section-label,
[data-theme="dark"] .left-column::before {
    background-color: var(--bg);
}

.post-metadata {
    font-family: var(--font-sans);
    color: var(--fg3);
    font-size: 0.9rem;
    margin-bottom: 40px;
    background-color: var(--bg);
    position: relative;
    z-index: 1;
    transition: background-color 0.3s, color 0.3s;
}

.meta-table {
    width: 100%;
    border-collapse: collapse;
}

.meta-table td {
    padding: 6px 0;
    border-bottom: none;
}

.meta-table tr {
    border-bottom: 1px dashed var(--fg3);
    transition: border-color 0.3s;
}

.meta-table td:first-child {
    width: 150px;
    font-weight: 500;
    padding-right: 20px;
}

.metadata-section .section-label {
    margin-bottom: 10px; /* Less space after METADATA label */
}

.tag {
    text-transform: uppercase;
    display: inline-block;
    padding: 2px 6px;
    border: 1px dashed var(--fg3);
    margin: 4px 5px 4px 0;
    transition: border-color 0.3s;
}

/* Content area */
.post-content-wrapper {
    flex-grow: 1;
    max-width: 720px !important;
}

/* Archive page special styling */
.archive-content {
    max-width: 100% !important;
    width: 100%;
}

.archive-content .section-label {
    width: 100%;
}

.archive-content .posts-list {
    width: 100%;
    max-width: 100% !important;
}

.archive-content .post-item {
    width: 100%;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed var(--fg3);
}

.post-content{
    font-family: var(--font-serif);
    line-height: 1.6;
    position: relative;
    margin-bottom: 40px;
    text-align: left;
}

/* Unified Typography */
h1 {
    font-family: var(--font-sans);
    color: var(--fg);
    font-size: 3.5rem;
    line-height: 1.1;
    margin-top: 2rem;
    margin-bottom: 1.25rem;
    font-weight: 800;
    text-align: left;
    transition: color 0.3s;
}

body:not(.single-post) h1 {
    font-size: 6rem;
    color: var(--fg);
    margin-top: 0px;
    font-weight: 700;
    text-transform: uppercase;
    font-family: var(--font-sans);
}

h2 {
    font-family: var(--font-sans);
    color: var(--fg);
    font-size: 2.5rem;
    line-height: 1.3;
    margin: 1rem 0 1rem;
    font-weight: 700;
    text-align: left;
    padding-top: 1.2rem;
    padding-bottom: 0.6rem;
}

h3 {
    font-family: var(--font-sans);
    color: var(--fg);
    font-size: 2rem;
    line-height: 1.3;
    margin: 1rem 0 1rem;
    font-weight: 700;
    transition: color 0.3s;
    padding-top: 0.8rem;
    padding-bottom: 0.2rem;
}

h4 {
    font-family: var(--font-sans);
    color: var(--fg);
    font-size: 1.5rem;
    line-height: 1.3;
    margin: 1.2em 0 0.5em;
    font-weight: 700;
    transition: color 0.3s;
}

p {
    font-family: var(--font-serif);
    line-height: 1.6;
    margin-bottom: 1em;
    font-size: 1rem;
    font-weight: 400;
}

/* Text highlight */
.highlight {
    background-color: var(--highlight-color);
    padding: 0 0.2em;
    transition: background-color 0.3s;
}

/* LaTeX equations styling */
.MathJax {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

/* Footnotes CSS-only solution */
.footnote-number {
    font-family: var(--font-sans);
    color: var(--fg3);
    font-weight: 600;
    font-size: 0.8rem;
    display: inline-block;
    transform: translate(-0.3em, -0.5em); /* Move slightly to the left and up */
    transition: color 0.3s;
    padding-left: 0.5rem;
}

.footnote-inline {
    display: none;
    color: var(--fg3);
    transition: color 0.3s;
}

.footnote-sidebar {
    font-family: var(--font-serif);
    font-size: 0.85rem;
    line-height: 1.4;
    display: block;
    margin-bottom: 1em;
    position: absolute;
    left: -460px; /* Positions in left column */
    width: 350px;
    max-width: 350px;
    text-align: left;
    padding-right: 20px;
    transform: translateY(-1.5em); /* Adjust vertical alignment */
    color: var(--fg);
    background-color: var(--bg);
    transition: color 0.3s, background-color 0.3s;
    overflow-wrap: break-word; /* Ensure text wrapping */
    word-wrap: break-word; /* Fallback for older browsers */
    word-break: break-word; /* Allow words to break if needed */
    hyphens: auto; /* Enable hyphenation for better wrapping */
}

.post-footnotes {
    position: relative;
    z-index: 1; /* Lower than metadata */
}

/* Use hidden elements in the content to position the footnotes */
.footnote-marker:target + .footnote-inline + .footnote-sidebar {
    background-color: rgba(255, 255, 0, 0.1); /* Subtle highlight */
    transition: background-color 0.5s;
}

/* Posts list style (for archive and home) */
.posts-list {
    font-family: var(--font-serif);
    max-width: 1100px !important;
    width: 100%;
}

.post-item {
    display: flex;
    border-bottom: 1px dashed var(--fg3);
    padding: 15px 0;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.3s;
}

.post-item:first-child {
    padding-top: 0;
}

.post-title {
    font-family: var(--font-serif);
    font-size: 1rem;
    padding-top: 0.5rem;
    padding-top: 0.5rem;
}

.post-title a {
    color: var(--fg);
    text-decoration: none;
    transition: color 0.3s;
}

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

.post-date {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    color: var(--fg3);
    flex-shrink: 0;
    margin-left: 20px;
    transition: color 0.3s;
    padding-bottom: 0.5rem;
}

.subscribe-form-wrapper {
    position: relative;
    width: 100%;
    background-color: var(--bg);
    border: 1px dashed var(--fg3);
    padding: 20px;
    margin-bottom: 60px;
    transition: background-color 0.3s, border-color 0.3s;
}

.substack-iframe {
    width: 100%;
    height: 150px;
    background: transparent;
    border: none;
    background-color: var(--bg);
    color: var(--fg);
    transition: background-color 0.3s, color 0.3s;
}

/* Blockquote styles */
.post-content blockquote {
    font-family: var(--font-sans);
    font-style: normal;
    margin: 2rem 1rem;
    padding: 0.5rem 1.5rem;
    position: relative;
    color: var(--fg);
    font-size: 1.2rem !important;
    line-height: 1.6;
    transition: color 0.3s;
}
  
.post-content blockquote p {
    font-family: var(--font-sans);
    text-align: left;
    margin: 0;
    padding: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--fg3);
    transition: color 0.3s;
}
  
/* Citation styles */
.post-content blockquote em {
    font-family: var(--font-sans);
    font-style: normal;
    font-size: 1rem;
    text-transform: uppercase;
    display: block;
    margin-top: 0.5rem;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
    .post-container {
        max-width: 95%;
    }
    
    .main-nav {
        padding-left: calc(2.5% + 10px);
        padding-right: calc(2.5% + 10px);
    }
    
    .top-row {
        gap: 40px;
    }
    
    .bottom-row {
        gap: 40px;
    }
    
    .left-column {
        width: 300px;
    }
    
    .left-column::before {
        width: 360px;
    }
    
    .footnote-sidebar {
        left: -340px;
        width: 260px;
        max-width: 260px;
    }
}

@media (max-width: 900px) {
    :root {
        --base-font-size: 15px;
    }

    .post-container {
        padding-left: 10px;
        padding-right: 10px;
    }

    .post-content {
        text-align: left;
    }
    
    .main-nav {
        position: relative;
        padding-left: 10px;
        padding-right: 10px;
        display: flex;
        width: 100%;
        margin-bottom: 20px;
        margin-top: 50px;
        justify-content: center; /* Center the flex items */
    }

    .main-nav ul {
        justify-content: center; /* Center the list items */
    }

    h1, 
    .post-header h1,
    body:not(.single-post) h1,
    body.home h1, 
    body.archive h1,
    #main-header h1 {
        text-align: center !important;
    }
    
    /* Ensure the post header itself is centered */
    .post-header, 
    #main-header {
        text-align: center;
        width: 100%;
    }
    
    body:not(.single-post) h1 {
        font-size: 5rem;
        text-transform: uppercase;
    }

    h1 {
        font-size: 3rem;
    }

    h2 {
        font-size: 2rem;
    }
    
    h3 {
        font-size: 1.5rem;
    }

    h4 {
        font-size: 1.2rem;
    }

    .top-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 30px;
    }
    
    .post-image {
        width: 100%;
    }
    
    .bottom-row {
        flex-direction: column;
    }
    
    .left-column, .post-content-wrapper {
        width: 100%;
    }
    
    .left-column {
        position: relative;
        top: 0;
    }
    
    .left-column::before {
        display: none;
    }
    
    .post-header-mini {
        display: none !important; /* Hide mini header on small screens */
    }
    
    .metadata-section.sticky .section-label {
        position: relative;
        top: auto;
    }
    
    /* Mobile footnote handling */
    .footnote-number {
        display: none;
    }
    
    .footnote-inline {
        display: inline;
        color: var(--fg);
    }
    
    .footnote-sidebar {
        display: none;
    }
    
    .post-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .post-date {
        margin-left: 0;
        margin-top: 5px;
        font-size: 0.8rem;
    }
    
    .post-content blockquote {
        font-family: var(--font-sans);
        padding: 0.5rem 0.5rem;
    }

    .post-content blockquote p {
        font-size: 1.1rem;
    }

    .home-intro {
        font-size: 1rem;
    }

    .section-label {
        margin-top: 10px; /* Increased top margin on mobile */
        margin-bottom: 10px; /* Increased bottom margin on mobile */
    }
    
    /* First section label should have consistent top spacing */
    .bottom-row .section-label:first-of-type {
        margin-top: 10px;
    }
    
    /* Last section label should have consistent bottom spacing */
    .section-label:last-of-type {
        margin-bottom: 10px;
    }
    
    /* Adjust spacing after metadata table */
    .post-metadata {
        margin-bottom: 0px; /* Increased space after metadata */
    }
    
    /* Ensure even spacing between sections */
    .post-content-wrapper {
        padding-top: 0;
        margin-top: 0;
    }
}

/* Ordered List Styling */
.post-content ol {
    counter-reset: item;
    list-style-type: none;
    padding-left: 0;
    margin: 1.5em 0;
}

.post-content ol > li {
    position: relative;
    padding-left: 2.625rem;
    margin-bottom: 1.2em;
}

.post-content ol > li:before {
    counter-increment: item;
    content: counter(item);
    background-color: var(--fg3);
    color: var(--bg);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    border-radius: 50%;
    width: 1.75rem;
    height: 1.75rem;
    line-height: 1.75rem;
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s, color 0.3s;
}

/* Unordered List Styling */
.post-content ul {
    list-style-type: none;
    padding-left: 1.2em;
    margin: 1.5em 0;
}

.post-content ul > li {
    position: relative;
    padding-left: 1.5em;
    margin-bottom: 0.8em;
}

.post-content ul > li:before {
    content: "✦";
    position: absolute;
    left: 0;
    color: var(--fg3);
    transition: color 0.3s;
}

/* Nested unordered lists (subbullets) */
.post-content ul ul {
    margin: 0.8em 0 0.8em 0.5em;
}

.post-content ul ul > li:before {
    content: "✧";
}

/* Bold text styling */
.post-content strong {
    font-weight: 800;
}

/* Link styling - UPDATED to match the requested style */
.post-content a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 2px solid var(--fg);
    font-weight: bold;
    transition: color 0.3s, border-bottom 0.3s;
}

.post-content a:hover {
    color: var(--fg3);
    border-bottom: 2px solid var(--fg3);
}

/* Apply the same styling to links in footnotes */
.footnote-sidebar a,
.footnote-inline a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 2px solid var(--fg);
    font-weight: bold;
    transition: color 0.3s, border-bottom 0.3s;
    display: inline; /* Keep links inline */
    word-break: break-word; /* Allow URLs to break */
    overflow-wrap: break-word;
}

.footnote-sidebar a:hover,
.footnote-inline a:hover {
    color: var(--fg3);
    border-bottom: 2px solid var(--fg3);
}

/* Prevent image overflow in post content */
.post-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.5em 0;
}

/* For figures with captions */
.post-content figure {
    max-width: 100%;
    margin: 1.5em 0;
}

.post-content figure img {
    margin: 0 0 0.5em 0;
}

.post-content figcaption {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--fg2);
    text-align: center;
    transition: color 0.3s;
}

/* If you use Hugo's built-in image processing and figure shortcode */
.post-content .figure {
    max-width: 100%;
    margin: 1.5em 0;
}

.post-content .figure img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 0 0.5em 0;
}

.post-content .figure figcaption {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--fg2);
    text-align: center;
    transition: color 0.3s;
}

/* Target home page specifically */
body.home .bottom-row {
    display: flex;
    flex-direction: row; /* Default row direction for desktop */
}

/* Reorder columns on small screens for home page only */
@media (max-width: 900px) {
    body.home .bottom-row {
        display: flex;
        flex-direction: column; /* Stack vertically on mobile */
    }
    
    body.home .post-content-wrapper {
        order: 1; /* Display right column content first */
    }
    
    body.home .left-column {
        order: 2; /* Display left column content last */
        margin-top: 40px; /* Add some spacing between columns */
    }
}

/* Glossary Term Styling */
.glossary-term {
    border-bottom: 1px dashed var(--fg3);
}

/* Glossary Sidebar - simplified */
.glossary-sidebar {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1.4;
    display: block;
    margin-bottom: 1em;
    position: absolute;
    left: -460px;
    max-width: 256px;
    width: 256px;
    padding-right: 20px;
    text-align: left;
    transform: translateY(-3em);
    color: var(--fg3);
    background-color: var(--bg);
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.glossary-term-label {
    font-family: var(--font-sans);
    color: var(--fg3);
    font-size: 1rem;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 5px;
    transition: color 0.3s;
}

.glossary-content {
    font-family: var(--font-sans);
    color: var(--fg3);
    font-weight: 500;
    font-size: 0.9rem;
    transition: color 0.3s;
}

/* Glossary content links */
.glossary-content a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 2px solid var(--fg);
    font-weight: bold;
    transition: color 0.3s, border-bottom 0.3s;
    display: inline;
    word-break: break-word;
    overflow-wrap: break-word;
}

.glossary-content a:hover {
    color: var(--fg3);
    border-bottom: 2px solid var(--fg3);
}

/* Glossary Popup (for mobile) */
.glossary-popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 40px);
    max-width: 320px;
    background-color: var(--bg);
    border: 2px solid var(--fg3);
    border-radius: 8px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease, background-color 0.3s, border-color 0.3s;
    padding: 15px;
}

.glossary-popup.active {
    display: block;
    opacity: 1;
}

.glossary-close {
    background: none;
    border: none;
    color: var(--fg);
    font-size: 0.875rem;
    cursor: pointer;
    font-weight: bold;
    padding: 0;
    position: absolute;
    right: 15px;
    top: 15px;
    transition: color 0.3s;
}

.glossary-popup-content {
    margin-top: 30px;
}

/* Responsive adjustments for the sidebar glossary */
@media (max-width: 1200px) {
    .glossary-sidebar {
        left: -340px;
        width: 260px;
        max-width: 260px;
    }
}

/* Hide sidebar glossary on mobile */
@media (max-width: 900px) {
    .glossary-sidebar {
        display: none;
    }

    .glossary-content {
        font-size: 1rem;
    }

    .glossary-term-label {
        font-size: 1rem;
    }
}

/* Fix for unwanted rectangle on home page */
body.home .left-column::before {
    display: none;
}

.load-newsletter-btn {
    padding: 0.75rem 1.5rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    background-color: var(--fg3);
    border-radius: 4px;
    color: var(--bg);
    border: none;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
    display: block; /* Change to block instead of inline-block */
    margin: 0 auto; /* This will work with display: block */
    width: fit-content; /* This ensures the button is only as wide as its content */
  }
  
  .load-newsletter-btn:hover {
    background-color: var(--fg3);
  }