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

:root {
    --font-base: 1.0rem;
    --font-small: 0.85rem;
    --line-height: 1.65;

    /* Colors - light mode */
    --color-bg: #fafafa;
    --color-bg-header: rgba(235, 235, 235, 0.85);
    --color-bg-post-header: rgba(245, 245, 245, 1.0);
    --color-bg-footer: rgba(230, 230, 230, 0.85);
    --color-text: #222;
    --color-text-muted: #666;
    --color-border: #e5e7eb;
    --color-accent: #0066cc;
    --color-code-bg: #f6f6f6;

    /* Layout */
    --content-width: 54rem;
    --max-content-width: 1800px;
    --nav-height: 4rem;
    --gutter: 2rem;

    /* Transitions */
    --transition-duration: 0.07s;

    /* Fonts */
    --font-serif: "Noto Serif", "Georgia", serif;
    --font-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

html {
    /* offset for anchor links: compensate for sticky header */
    scroll-padding-top: 3.75rem;
    /* smooth scrolling to anchors */
    scroll-behavior: smooth;
}

body {
    background-color: var(--color-bg);

    color: var(--color-text);

    font-family: var(--font-serif);
    font-size: var(--font-base);
    line-height: var(--line-height);
}

/* Typography */

@font-face {
  font-family: 'Noto Serif';
  src: url('/static/fonts/NotoSerif-VariableFont_wdth,wght.ttf');
  font-style: normal;
}
@font-face {
  font-family: 'Noto Serif';
  src: url('/static/fonts/NotoSerif-Italic-VariableFont_wdth,wght.ttf');
  font-style: italic;
}

h1, h2, h3, h4, h5, h6, header, footer {
    font-family: var(--font-sans-serif);
}

a {
    color: initial;
    transition: color var(--transition-duration);
}

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

/* Suffix for external links */

a[target="_blank"]::after {
    content: "↗";
    /* vertical-align: super; */
    display: inline-block;
    text-decoration: none;
    margin-left: 0.1rem;
    font-size: 85%;
    font-family: var(--font-sans-serif);
}

a[target="_blank"]:hover::after {
    opacity: 1;
}

/* Header and Navigation */
.site-header {
    position: absolute;
    width: 100%;
}

.site-header.animated {
    position: fixed;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #d5d7db;
    transition: background 0.5s;
    top: 0;
    z-index: 100;
    background: var(--color-bg-header);
}

.site-header.animated.at-top {
    background: none;
    backdrop-filter: none;
    border-bottom: none;
}

.navbar {
    padding: 0.35rem 0;
}

.nav-container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.logo {
    text-decoration: none;
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--color-text);
    margin-right: auto;
}

.nav-links {
    display: flex;
    gap: 2rem;
    list-style: none;
}

.nav-links {
    margin: initial;
    padding: initial;
}

.nav-links li {
    margin: initial;
    padding: initial;
}

.nav-link {
    text-decoration: none;
    color: var(--color-text-muted);
    transition: color var(--transition-duration);
    position: relative;
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-text);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    padding: 0.375rem 0.625rem;
    cursor: pointer;
    font-size: 1.125rem;
    transition: border-color var(--transition-duration);
}

.theme-toggle:hover {
    border-color: var(--color-text-muted);
}

/* Main content */
main {
    min-height: calc(100vh - var(--nav-height) - 5rem);
}

.post, .page, .home {
    margin: 0 auto;
}

/* Post and Page styles */
.post-header, .page-header, .home-header {
    width: 100%;
    margin-bottom: 2.5rem;
    padding-top: 7rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.post-header {
    background: var(--color-bg-post-header);
}

.post-header-content, .page-header-content, .home-header-content {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.post-title, .page-title, .home-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.post-meta, .post-summary-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    font-size: var(--font-small);
}

.meta-separator {
    color: var(--color-text-muted);
}

.tag {
    margin: 0 0.35rem;
}

.tag:first-of-type {
    margin-left: initial;
}

.tag:last-of-type {
    margin-left: initial;
}

.post-content, .page-content, .home-content {
    font-size: var(--font-base);
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.post-content figure, .page-content figure {
    width: fit-content;
    margin: 0 auto;
}

.post-content figure img, .page-content figure img {
    width: 100%;
}

/* Content anchors */

h1 a.anchor,
h2 a.anchor,
h3 a.anchor,
h4 a.anchor,
h5 a.anchor,
h6 a.anchor {
    color: var(--color-text-muted);
    text-decoration: none;
    opacity: 0.0;
    transition: opacity var(--transition-duration);
}

h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
    opacity: 0.5;
}

/* Post body with TOC and content side-by-side */
.post-body {
    display: flex;
    /* gap: var(--gutter); */
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: 0 0;
    align-items: flex-start;
}

/* Table of Contents - left sidebar */
.toc {
    flex: 0 1 15rem;
    position: sticky;
    top: calc(var(--nav-height) + 0.1rem);
    max-height: calc(100vh - var(--nav-height) - 4rem);
    overflow-y: auto;
    padding: 0.3rem 0 0 var(--gutter);
}

/* Post content - main column */
.post-content {
    flex: 1 0 var(--content-width);
    max-width: min(var(--content-width), 100%);
    min-width: 0;
    margin: 0 auto;
}

/* Spacer on the right to balance TOC */
.post-body::after {
    content: '';
    flex: 0 1 15rem;
}

/* TOC styling */
.toc-nav {
    font-size: var(--font-small);
}

.toc-title {
    font-size: var(--font-base);
    font-weight: 600;
    color: var(--color-text);
    margin-top: 0;
}

.toc-nav summary {
    cursor: pointer;
    font-family: var(--font-sans-serif);
    font-weight: 500;
    margin-bottom: 0.35rem;
    transition: color var(--transition-duration);
}

.toc-nav summary:hover {
    color: var(--color-accent);
}

.toc-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-nav ul ul {
    list-style: none;
    padding-left: 1rem;
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.toc-nav a {
    color: var(--color-text-muted);
    text-decoration: none;
    transition: all var(--transition-duration);
}

.toc-nav a:hover {
    color: var(--color-accent);
    border-left-color: var(--color-accent);
}

.toc-nav a.active {
    color: var(--color-text);
    border-left-color: var(--color-text);
    font-weight: 500;
}

/* Content typography */
h1, h2, h3 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: 600;
    line-height: 1.3;
}

:is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) {
    margin-top: initial;
}

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

.post-content p, .home-content p {
    margin-bottom: 0.7rem;
}

code {
    background: var(--color-code-bg);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

pre {
    background: var(--color-code-bg);
    padding: 1.25rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

li pre {
    margin-bottom: initial;
}

pre code {
    background: none;
    padding: 0;
    font-size: 0.8rem;
}

blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    color: var(--color-text-muted);
}

blockquote p {
    margin-bottom: 0;
}

ul, ol {
    margin-bottom: 1.5rem;
    padding-left: 1.75rem;
}

ul ul, ol ol, ul ol, ol ul {
    margin-bottom: initial;
}

li {
    margin-bottom: 0.35rem;
}

ul li ul li, ol li ol li {
    margin-bottom: initial;
}

p img {
    max-width: 100%;
}

/* Hack: Prevent Superscripts and Subscripts from Affecting Line-Height */
sup, sub {
    vertical-align: baseline;
    position: relative;
    top: -0.4em;
}

sub {
    top: 0.4em;
}

.footnotes {
    margin-top: 2.5rem;
    color: var(--color-text-muted);
    font-size: var(--font-small);
}

.footnotes > hr {
    margin-bottom: 1.5rem;
    height: 1px;
    color: var(--color-border);
    background: var(--color-border);
    border: 0;
}

.footnotes p {
    margin-bottom: 0.5rem;
}

hr {
    background-color: var(--color-border);
    margin-bottom: 1.5rem;
    margin-top: 1.5rem;
    height: 1px;
    border: 0;
}

/* Home page styles */
.home-header {
    margin-bottom: 2.5rem;
}

.home-title {
    font-size: 2.5rem;
    font-weight: 700;
}

.post-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.post-summary {
    border-bottom: 1px solid var(--color-border);
}

.post-summary-title {
    margin-top: 0;
    margin-bottom: 0.3rem;
}

.post-summary-title a {
    color: var(--color-text);
    text-decoration: none;
    transition: color var(--transition-duration);
}

.post-summary-title a:hover {
    color: var(--color-accent);
}

.post-summary-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    font-family: var(--font-sans-serif);
    font-size: var(--font-small);
}

.post-summary-excerpt {
    color: var(--color-text-muted);
    margin-top: 0.25rem;
    margin-bottom: 0.75rem;
}

/* Footer */
.site-footer {
    background: var(--color-bg-footer);
    border-top: 1px solid var(--color-border);
    margin-top: 4rem;
    padding: 2rem 0;
}

.footer-container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 var(--gutter);
    display: flex;
    gap: var(--gutter);
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.footer-text {
    color: var(--color-text-muted);
    font-size: var(--font-small);
    flex-shrink: 0;
}

.footer-text code {
    font-size: 0.7rem;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
    flex-shrink: 0;
}

.footer-link {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: var(--font-small);
    transition: color var(--transition-duration);
}

.footer-link:hover {
    color: var(--color-text);
}

/* Responsive */
@media (max-width: 1280px) {
    /* Switch to column layout */
    
    .post-body {
        flex-direction: column;
        max-width: var(--content-width);
        gap: 0;
    }

    .post-body::after {
        display: none;
    }

    .toc {
        position: static;
        flex: 0 0 0;
        max-height: none;
        width: calc(100% - 2 * var(--gutter));
        overflow-y: initial;
        border-bottom: 1px solid var(--color-border);
        margin: 0 var(--gutter) 2rem var(--gutter);
        padding: 0;
        padding-bottom: 1.5rem;
        padding-right: var(--gutter);
    }

    .toc:empty {
        display: none;
    }

    .toc h2 {
        display: none;
    }

}

@media (max-width: 640px) {
    :root {
        font-size: 90%;
        --gutter: 1.5rem;
    }

    .site-header {
        position: relative;
    }

    .footer-container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .nav-container {
        gap: 1rem;
    }

    .nav-links {
        gap: 1rem;
    }
}
