@import url('https://fonts.googleapis.com/css2?family=League+Spartan:wght@400;700;900&display=swap');

:root {
    --primary-bg: #0C001F; /* Nu Disco very dark purple */
    --secondary-bg: #180D2A; /* slightly lighter purple from Nu Disco */
    --primary-text: #d6b4fc; /* light purple for body text */
    --secondary-text: #d6b4fc;
    --heading: #5ACC75; /* Nu Disco green for headings */
    --accent: #5ACC75;
    --accent-hover: #d6b4fc;
    --icon-color: #5ACC75;
    --icon-hover: #d6b4fc;
    --max-width: 800px;
}

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

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: 'League Spartan', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--primary-bg);
    color: var(--primary-text);
    line-height: 1.6;
    font-size: 1.25rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--primary-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 0;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 2rem 4vw 1rem 4vw;
    box-sizing: border-box;
}

.site-title {
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--heading);
    margin-right: auto;
    padding-left: 0;
}

nav {
    margin-left: auto;
    display: flex;
    margin-right: 0;
    padding-right: 0;
}

nav a {
    color: #5ACC75 !important;
    text-decoration: none !important;
    transition: color 0.2s;
    padding-left: 2rem;
    font-weight: 600;
    font-size: 1.5rem;
}

nav a:first-child {
    padding-left: 0;
}

nav a:hover {
    color: #d6b4fc !important;
    text-decoration: none !important;
}

a:not(nav a) {
    text-decoration: underline;
    font-size: 1.15rem;
}

@media (max-width: 700px) {
    .header-container {
        padding: 1rem 5vw 1rem 5vw;
    }
    .site-title {
        font-size: 1.3rem;
    }
    nav a {
        padding-left: 1rem;
        font-size: 1rem;
    }
}

/* Page-specific main-content widths and display */
.landing-page .main-content {
    max-width: 700px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70vh;
    margin: 0 auto;
    flex: 1;
}
.articles-page .main-content {
    width: 33%;
    max-width: none;
    display: block;
    margin-left: auto;
    margin-right: auto;
}
.articles-page .main-content > * {
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}
.notes-page .main-content {
    width: 50%;
    max-width: none;
    display: block;
}

.main-content {
    flex: 1 1 0%;
    min-width: 0;
    margin: 4rem 0 0 0;
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
}

.intro {
    flex: 2;
}

.intro h1 {
    font-size: 2.8rem;
    margin-bottom: 1.5rem;
    color: var(--heading);
}

.intro p {
    margin-bottom: 1.2rem;
    font-size: 1.25rem;
    color: var(--primary-text);
}

a, nav a {
    color: #5ACC75 !important;
    text-decoration: underline;
    transition: color 0.2s;
    font-weight: 600;
}

a:hover, nav a:hover {
    color: #d6b4fc !important;
}

footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--primary-text);
    background: var(--secondary-bg);
    margin-top: auto;
}

/* Blog post styling */
.blog-post {
    margin-bottom: 3rem;
}

.blog-post h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--heading);
}

.blog-post .date {
    color: var(--primary-text);
    margin-bottom: 1rem;
}

/* Markdown content styling */
.markdown-content {
    max-width: 100vw;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}

/* Responsive images to prevent horizontal overflow */
.markdown-content img {
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    display: block;
    margin: 1rem auto;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    margin: 2rem 0 1rem;
    color: var(--heading);
}

.markdown-content p {
    margin-bottom: 1.5rem;
    color: var(--primary-text);
    font-size: 1.25rem;
}

.markdown-content ul,
.markdown-content ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.markdown-content code {
    background-color: var(--secondary-bg);
    color: var(--primary-text);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: monospace;
}

.markdown-content pre {
    background-color: var(--secondary-bg);
    color: var(--primary-text);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.social-icons {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.social-icons a {
    color: var(--icon-color);
    font-size: 7rem;
    transition: color 0.2s;
}

.social-icons a:hover {
    color: var(--icon-hover);
}

.intro h1,
.markdown-content h1 {
    color: var(--heading);
}

.intro p,
.markdown-content p {
    color: var(--primary-text);
}

/* Three-column header for articles page */
.articles-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 2rem 4vw 1rem 4vw;
    box-sizing: border-box;
}
.articles-header .header-left {
    flex: 1;
    text-align: left;
}
.articles-header .header-center {
    flex: 2;
    text-align: center;
}
.articles-header .header-right {
    flex: 1;
    text-align: right;
}
@media (max-width: 700px) {
    .articles-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem 5vw 1rem 5vw;
    }
    .articles-header .header-center h1 {
        font-size: 2rem;
    }
    /* Make articles page use full width on mobile */
    .articles-page .main-content {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        padding: 0 5vw;
    }
    /* Ensure article links take full width */
    .articles-page .main-content ul {
        width: 100%;
    }
    .articles-page .main-content li {
        width: 100%;
    }
    .articles-page .main-content a:not(.intro a) {
        display: block;
        width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* Articles page top bar and title */
.articles-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 1.2rem 4vw 1.2rem 4vw;
    background: var(--primary-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.articles-topbar .site-title {
    font-size: 1.3rem;
    color: var(--heading);
    text-decoration: none;
    font-weight: bold;
}
.articles-nav a {
    color: var(--heading);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.35rem;
    margin-left: 2rem;
    transition: color 0.2s;
}
.articles-nav a:first-child {
    margin-left: 0;
}
.articles-nav a:hover {
    color: var(--accent-hover);
}
.articles-title {
    text-align: center;
    margin-top: 2.5rem;
    margin-bottom: 2.5rem;
}
.articles-title h1 {
    font-size: 2.8rem;
    color: var(--heading);
    margin: 0;
}
@media (max-width: 700px) {
    .articles-topbar {
        flex-direction: column;
        gap: 0.7rem;
        padding: 1rem 5vw 1rem 5vw;
    }
    .articles-title h1 {
        font-size: 2rem;
    }
}

.generated-page .main-content {
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    display: block;
    position: relative;
    min-height: 100vh;
}
.generated-page .main-content > * {
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}

/* Remove .site-title special styling for generated pages */
.generated-page .site-title {
    font-size: inherit;
    font-weight: 600;
    color: #5ACC75 !important;
    margin-right: 0;
    padding-left: 2rem;
    text-decoration: none !important;
}

/* Ensure articles-page has the same header styling as generated pages */
.articles-page .site-title {
    font-size: inherit;
    font-weight: 600;
    color: #5ACC75 !important;
    margin-right: 0;
    padding-left: 2rem;
    text-decoration: none !important;
}

.generated-page .header-container a {
    color: #5ACC75 !important;
    font-size: 1.35rem;
    font-weight: 600;
    text-decoration: none !important;
    transition: color 0.2s;
}

.articles-page .header-container a {
    color: #5ACC75 !important;
    font-size: 1.35rem;
    font-weight: 600;
    text-decoration: none !important;
    transition: color 0.2s;
}

.generated-page .header-container a:first-child {
    padding-left: 0;
}

.articles-page .header-container a:first-child {
    padding-left: 0;
}

.generated-page .header-container a:hover {
    color: #d6b4fc !important;
    text-decoration: none !important;
}

.articles-page .header-container a:hover {
    color: #d6b4fc !important;
    text-decoration: none !important;
}

.generated-page .markdown-content {
    /* margin-top removed for better h1 centering */
}
.generated-page .markdown-content > :not(h1:first-of-type) {
    opacity: 0.2;
    transition: opacity 0.6s;
}
.generated-page .markdown-content.faded-in > :not(h1:first-of-type) {
    opacity: 1;
}
.generated-page .markdown-content h1:first-of-type {
    font-size: clamp(1.5rem, 8vw, 3.5rem);
    font-weight: 900;
    color: var(--heading);
    margin-top: 35vh;
    margin-bottom: 3.5rem;
    width: auto;
    max-width: 100vw;
    text-align: center;
    display: block;
    opacity: 1;
    position: static;
    transform: translateY(-50%);
    pointer-events: auto;
    background: none;
    z-index: auto;
    line-height: 1.1;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.generated-page .markdown-content h1:not(:first-of-type) {
    font-size: 2.1rem;
    font-weight: 700;
    color: var(--heading);
    margin: 2.5rem 0 1.5rem 0;
    text-align: left;
    max-width: 100%;
    background: none;
    position: static;
    transform: none;
}
.generated-page .markdown-content h1:first-of-type + * {
    margin-top: 6rem;
}

.footnote-popup {
    position: absolute;
    z-index: 9999;
    max-width: 350px;
    background: var(--secondary-bg, #180D2A);
    color: var(--primary-text, #d6b4fc);
    border: 1px solid var(--accent, #5ACC75);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    padding: 0.75em 1em;
    font-size: 0.98em;
    line-height: 1.5;
    pointer-events: none;
    opacity: 0.97;
    transition: opacity 0.15s;
    word-break: break-word;
}

/* --- Generated Page Layout --- */

.layout-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

.toc-sidebar {
    height: max-content;
    overflow-y: auto;
    background: var(--secondary-bg, #180D2A);
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
    padding: 1.2rem 1rem;
    font-size: 1rem;
    z-index: 100;
    max-height: 100vh; /* Limit height to viewport height */
}

.main-content {
    flex: 1 1 0%;
    min-width: 0;
}

/* For wide screens, fix the TOC to the side */
@media (min-width: 901px) {
    .toc-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 350px;
        margin: 0;
        border-radius: 0;
        height: 100vh; /* Set explicit height for fixed positioning */
        overflow-y: auto; /* Enable vertical scrolling */
        overflow-x: hidden; /* Prevent horizontal scrolling */
    }

    .main-content {
        margin-left: 370px; /* 350px width + 20px gap */
    }

    .generated-page .main-content {
        margin-left: 370px;
        width: calc(100% - 410px); /* 370px for left margin, 40px for right padding */
        padding-right: 40px;
        margin-right: 0;
        max-width: none;
    }
}

/* For narrow screens, stack the layout vertically */
@media (max-width: 900px) {
    .layout-container {
        flex-direction: column;
    }

    .toc-sidebar {
        position: static;
        width: auto;
        margin: 1rem;
        max-height: none; /* Remove height constraint on mobile */
        overflow-y: visible; /* Allow full content to be visible */
    }
}

.toc-sidebar nav, .toc-sidebar ul, .toc-sidebar ol {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc-sidebar a {
    color: var(--accent, #5ACC75);
    text-decoration: none;
    display: block;
    padding: 0.2em 0.1em;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    font-size: 1.15rem;
}

.toc-sidebar a:hover, .toc-sidebar a:focus {
    background: var(--accent, #5ACC75);
    color: var(--primary-bg, #0C001F);
}

.toc-sidebar a.active {
    background: rgba(90,204,117,0.18);
    color: var(--accent, #5ACC75);
    font-weight: bold;
    box-shadow: none;
}

.toc-sidebar ul ul {
    margin-left: 1.2em;
    border-left: 2px solid var(--accent, #5ACC75);
    padding-left: 0.8em;
    overflow-wrap: break-word;
}
.toc-sidebar ul ul ul {
    margin-left: 1.2em;
    border-left: 2px solid var(--accent, #5ACC75);
    padding-left: 0.8em;
    opacity: 0.95;
}
.toc-sidebar ul ul ul ul {
    margin-left: 1.2em;
    border-left: 2px solid var(--accent, #5ACC75);
    padding-left: 0.8em;
    opacity: 0.90;
}

main {
    flex: 1;
}

/* Prevent horizontal overflow on all content */
.main-content,
.markdown-content,
.layout-container,
.toc-sidebar {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Ensure text content doesn't overflow */
.markdown-content p,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6,
.markdown-content li,
.markdown-content blockquote {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.markdown-content blockquote {
    border-left: 4px solid var(--accent);
    padding-left: 1rem;
    margin-left: 0;
    font-style: italic;
}

h1 {
    font-size: 4rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.no-wrap {
    white-space: nowrap;
}

p {
    line-height: 1.6;
    font-size: 1.1em;
}

.intro p a {
    display: inline;
    margin: 0;
    padding: 0;
    border: none;
    text-align: inherit;
    font-weight: inherit;
}