:root {
    --font-sans: 'Roboto', sans-serif;
    --font-mono: 'Monaco', 'Consolas', monospace;
    --content-width: 70ch;

    --color-bg: #ffffff;
    --color-text: #080808;
    --color-muted: #5f5f5f;
    --color-border: #e0e0e0;
    --color-surface: #f5f5f5;
    --color-link: #111111;
    --color-link-hover: #555555;
    --pointcloud-point-color: #111111;
    --pointcloud-scene-bg: transparent;
    --body-dot-1: rgba(0, 0, 0, 0.35);
    --body-dot-4: rgba(0, 0, 0, 0.15);

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --color-bg: #020202;
        --color-text: #f4f4f0;
        --color-muted: #bdbdbd;
        --color-border: #2a2a2a;
        --color-surface: #101010;
        --color-link: #fefefe;
        --color-link-hover: #d0d0d0;
        --pointcloud-point-color: #e5e5e5;
        --body-dot-1: rgba(255, 255, 255, 0.25);
        --body-dot-4: rgba(255, 255, 255, 0.12);
    }
}

:root[data-theme="light"] {
    --color-bg: #ffffff;
    --color-text: #080808;
    --color-muted: #5f5f5f;
    --color-border: #e0e0e0;
    --color-surface: #f5f5f5;
    --color-link: #111111;
    --color-link-hover: #555555;
    --pointcloud-point-color: #111111;
    --body-dot-1: rgba(0, 0, 0, 0.35);
    --body-dot-2: rgba(0, 0, 0, 0.25);
    --body-dot-3: rgba(0, 0, 0, 0.20);
    --body-dot-4: rgba(0, 0, 0, 0.15);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --color-bg: #020202;
    --color-text: #f4f4f0;
    --color-muted: #bdbdbd;
    --color-border: #2a2a2a;
    --color-surface: #101010;
    --color-link: #fefefe;
    --color-link-hover: #d0d0d0;
    --pointcloud-point-color: #e5e5e5;
    --pointcloud-scene-bg: #020202;
    --pointcloud-bg: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.08), transparent 60%);
    --body-dot-1: rgba(255, 255, 255, 0.25);
    --body-dot-2: rgba(255, 255, 255, 0.18);
    --body-dot-3: rgba(255, 255, 255, 0.15);
    --body-dot-4: rgba(255, 255, 255, 0.12);
    color-scheme: dark;
}

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

html {
    font-size: 16px;
    line-height: 1.5;
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    left: 0;
    top: 0;
    width: 5rem;
    height: 100%;
    background-color: var(--color-bg);
    background-image:
        radial-gradient(circle, var(--body-dot-1) 0.8px, transparent 0.8px),
        radial-gradient(circle, var(--body-dot-4) 0.8px, transparent 0.8px);
    background-size:
        4px 4px,
        4px 4px;
    background-position:
        0px 0px,
        3px 3px;
    pointer-events: none;
    z-index: -1;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: var(--color-text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

a {
    color: var(--color-link);
    text-decoration: underline;
}

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

hr {
    margin: 2rem 0;
}

/* Layout */
.site-header {
    padding: 1rem 0;
    margin-left: 10rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.site-nav {
    max-width: var(--content-width);
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.home-link {
    font-family: var(--font-sans);
    font-weight: normal;
    font-size: 1rem;
}

.nav-link {
    font-family: var(--font-sans);
    font-weight: normal;
    font-size: 1rem;
 }

.theme-toggle {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: 999px;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    border-color: var(--color-link);
    color: var(--color-link);
    outline: none;
}

.theme-toggle__icon {
    width: 1.15rem;
    height: 1.15rem;
    display: none;
}

.theme-toggle__icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.theme-toggle[data-theme-state="light"] .theme-toggle__icon--sun,
.theme-toggle[data-theme-state="dark"] .theme-toggle__icon--moon {
    display: block;
}

.main-content {
    margin-left: 10rem;
    padding: 2rem 2rem 2rem 0;
    /* max-width: var(--content-width); */
    min-height: calc(100vh - 200px);
}

.site-footer {
    margin-left: 10rem;
    padding: 2rem 0;
    color: var(--color-muted);
    font-size: 0.85rem;
}

/* Blog Post Styles */
.blog-post {
    max-width: var(--content-width); 
}

.post-header {
    margin-bottom: 2rem;
}

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

.post-date {
    color: var(--color-muted);
    font-family: var(--font-sans);
    font-size: 0.75rem;
}

.post-content {
    line-height: 1.6;
    max-width: var(--content-width);
}

.post-content h2 {
    margin-top: 2rem;
    margin-bottom: 1rem;
}

.post-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

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

.post-content li {
    margin-bottom: 0.5rem;
}

.post-content li > ul,
.post-content li > ol {
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.post-content blockquote {
    margin: 1.5rem 0;
    padding-left: 1.5rem;
    border-left: 3px solid var(--color-border);
    font-style: italic;
    color: var(--color-text);
}

.post-content img {
    max-width: 100%;
    height: auto;
    margin: 2rem 0;
}

/* Code Styles */
code {
    font-family: var(--font-mono);
    background: var(--color-surface);
    padding: 0.15rem 0.3rem;
    font-size: 0.9em;
    color: var(--color-text);
}

pre {
    background: var(--color-surface);
    padding: 1rem;
    overflow-x: auto;
    border: 1px solid var(--color-border);
}

pre code {
    background: none;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Pygments Syntax Highlighting */
.highlight {
    margin: 1rem 0;
    background: var(--color-surface);
}

.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #000080; font-weight: bold } /* Keyword */
.highlight .l { color: #008080 } /* Literal */
.highlight .n { color: #000000 } /* Name */
.highlight .o { color: #000000 } /* Operator */
.highlight .p { color: #000000 } /* Punctuation */
.highlight .ch { color: #888888; font-style: italic } /* Comment.Hashbang */
.highlight .cm { color: #888888; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #888888; font-style: italic } /* Comment.Preproc */
.highlight .cpf { color: #888888; font-style: italic } /* Comment.PreprocFile */
.highlight .c1 { color: #888888; font-style: italic } /* Comment.Single */
.highlight .cs { color: #888888; font-style: italic } /* Comment.Special */
.highlight .kc { color: #000080; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #000080; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #000080; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #000080 } /* Keyword.Pseudo */
.highlight .kr { color: #000080; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #000080; font-weight: bold } /* Keyword.Type */
.highlight .ld { color: #008000 } /* Literal.Date */
.highlight .m { color: #008080 } /* Literal.Number */
.highlight .s { color: #008000 } /* Literal.String */
.highlight .na { color: #000080 } /* Name.Attribute */
.highlight .nb { color: #000080 } /* Name.Builtin */
.highlight .nc { color: #000080; font-weight: bold } /* Name.Class */
.highlight .no { color: #000080 } /* Name.Constant */
.highlight .nd { color: #000080 } /* Name.Decorator */
.highlight .ni { color: #000080 } /* Name.Entity */
.highlight .ne { color: #000080; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #000080 } /* Name.Function */
.highlight .nl { color: #000080 } /* Name.Label */
.highlight .nn { color: #000080 } /* Name.Namespace */
.highlight .nx { color: #000080 } /* Name.Other */
.highlight .py { color: #000080 } /* Name.Property */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #000080 } /* Name.Variable */
.highlight .ow { color: #000080 } /* Operator.Word */
.highlight .w { color: #000000 } /* Text.Whitespace */
.highlight .mb { color: #008080 } /* Literal.Number.Bin */
.highlight .mf { color: #008080 } /* Literal.Number.Float */
.highlight .mh { color: #008080 } /* Literal.Number.Hex */
.highlight .mi { color: #008080 } /* Literal.Number.Integer */
.highlight .mo { color: #008080 } /* Literal.Number.Oct */
.highlight .sa { color: #008000 } /* Literal.String.Affix */
.highlight .sb { color: #008000 } /* Literal.String.Backtick */
.highlight .sc { color: #008000 } /* Literal.String.Char */
.highlight .dl { color: #008000 } /* Literal.String.Delimiter */
.highlight .sd { color: #008000 } /* Literal.String.Doc */
.highlight .s2 { color: #008000 } /* Literal.String.Double */
.highlight .se { color: #000080 } /* Literal.String.Escape */
.highlight .sh { color: #008000 } /* Literal.String.Heredoc */
.highlight .si { color: #008000 } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #008000 } /* Literal.String.Regex */
.highlight .s1 { color: #008000 } /* Literal.String.Single */
.highlight .ss { color: #008000 } /* Literal.String.Symbol */
.highlight .bp { color: #000080 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #000080 } /* Name.Function.Magic */
.highlight .vc { color: #000080 } /* Name.Variable.Class */
.highlight .vg { color: #000080 } /* Name.Variable.Global */
.highlight .vi { color: #000080 } /* Name.Variable.Instance */
.highlight .vm { color: #000080 } /* Name.Variable.Magic */
.highlight .il { color: #008080 } /* Literal.Number.Integer.Long */

/* Line numbers */
.highlight .linenos { 
    user-select: none;
}

/* Home Page Styles */
.home-page {
    max-width: 100%;
}

.home-pointcloud {
    position: fixed;
    right: 0;
    top: 0;
    width: 50vw;
    height: 100vh;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
    background: var(--pointcloud-bg);
}

.home-pointcloud canvas {
    width: 100%;
    height: 100%;
}

.home-pointcloud.is-hidden {
    display: none;
}

.home-pointcloud--fallback {
    display: none;
    background: none;
}

.home-pointcloud--fallback img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: right center;
}

.home-pointcloud--fallback.is-visible {
    display: block;
}

.intro {
    margin-bottom: 3rem;
}

.intro h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    margin-top: 0;
}

.intro p {
    font-size: 1rem;
    color: var(--color-muted);
}

.posts-list h2 {
    margin-bottom: 1.5rem;
    margin-top: 2rem;
}

.posts-grid {
    display: grid;
    gap: 1.5rem;
}

.post-preview {
    padding: 0;
}

.post-preview a {
    color: var(--color-link);
    display: block;
}

.post-preview a:hover {
    color: var(--color-link-hover);
}

.post-type {
    display: inline-block;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    color: var(--color-muted);
    margin: 0.25rem 0;
}

.post-excerpt {
    color: var(--color-muted);
    margin-top: 0.5rem;
    margin-bottom: 0;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

th, td {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

th {
    font-weight: 600;
    color: var(--color-text);
}

/* Footnotes / Sidenotes */
.post-content .footnote {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.post-content .sidenotes {
    display: none;
}

.post-content .aside-anchor {
    display: block;
    height: 0;
    line-height: 0;
    font-size: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.post-content aside:not(.sidenotes):not(.sidenote-aside) {
    margin: 1rem 0;
    padding: 0.25rem 0 0.25rem 1rem;
    border-left: 3px solid var(--color-border);
    border-left-color: color-mix(in srgb, var(--color-muted) 55%, transparent);
}

.post-content .footnote hr {
    display: none;
}

.post-content .footnote ol {
    padding-left: 1.25rem;
    list-style-position: outside;
}

.post-content .footnote li {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--color-muted);
    margin-bottom: 0.75rem;
}

.post-content .footnote li p {
    margin: 0;
}

.post-content .footnote-ref {
    text-decoration: none;
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}

.post-content .footnote-ref a {
    color: var(--color-muted);
    text-decoration: none;
}

.post-content .footnote-ref a:hover {
    color: var(--color-link);
}

.post-content .footnote-backref {
    text-decoration: none;
    margin-left: 0.25rem;
    color: var(--color-muted);
}

.post-content .footnote li .footnote-backref {
    display: none;
}

.post-content .footnote li .footnote-backref:last-child {
    display: inline;
}

.post-content .footnote-backref:hover {
    color: var(--color-link);
}

/* Mobile/tablet footnotes (below desktop breakpoint) */
@media (max-width: 1199px) {
    .post-content .footnote {
        position: static !important;
    }

    .post-content .footnote li {
        position: static !important;
        margin-bottom: 0.75rem;
    }
}

/* Margin notes styling for larger screens */
@media (min-width: 1200px) {
    /* Ensure post-content can accommodate margin notes */
    .blog-post {
        max-width: 50rem;
        margin-right: 22rem;
    }

    .post-content {
        position: relative;
    }

    /* Position sidenotes container in the right margin */
    .post-content .sidenotes {
        display: block;
        position: absolute;
        right: -22rem;
        top: 0;
        width: 20rem;
        font-size: 0.8rem;
        pointer-events: auto;
    }

    .post-content .sidenotes ol.sidenotes-footnotes {
        list-style: none;
        padding: 0;
        margin: 0;
        counter-reset: sidenote-counter;
        position: static;
    }

    .post-content .sidenotes ol.sidenotes-footnotes li {
        /* JavaScript will set position: absolute and top */
        padding-left: 0;
        margin-bottom: 0;
        line-height: 1.5;
    }

    .post-content .sidenotes ol.sidenotes-footnotes li::before {
        content: counter(sidenote-counter) ". ";
        counter-increment: sidenote-counter;
        font-size: 0.75rem;
        color: var(--color-muted);
        margin-right: 0.25rem;
    }

    .post-content .sidenotes ol.sidenotes-footnotes li p {
        display: inline;
        margin: 0;
    }

    .post-content .sidenotes .footnote-backref {
        display: none;
    }

    .post-content .sidenotes aside.sidenote-aside {
        margin: 0;
        padding: 0.25rem 0 0.25rem 1rem;
        border-left: 3px solid var(--color-border);
        border-left-color: color-mix(in srgb, var(--color-muted) 55%, transparent);
        font-size: 0.85rem;
        line-height: 1.5;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    body::before {
        width: 1rem;
    }

    .site-header {
        margin-left: 2rem;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .theme-toggle {
        margin-left: auto;
    }

    .main-content {
        margin-left: 2rem;
        padding: 1.5rem 1.5rem 1.5rem 0;
    }

    .site-footer {
        margin-left: 2rem;
    }

    .intro h1 {
        font-size: 1.75rem;
    }

    .home-pointcloud {
        width: 60vw;
    }

    /* Ensure footnotes render normally on mobile */
    .post-content .footnote {
        position: static !important;
        margin-top: 2rem;
        padding-top: 1rem;
        border-top: 1px solid var(--color-border);
    }

    .post-content .footnote ol {
        list-style-position: inside;
    }

    .post-content .footnote li {
        position: static !important;
        margin-bottom: 0.75rem;
    }
}

.divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2rem 0;
}

/* Print Styles */
@media print {
    .site-header,
    .site-footer {
        display: none;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }
}
