/* ============================================================
   blog.css — Styles for /blog/ index and post pages
   Intentionally minimal; add your own design tokens on top.
   ============================================================ */

/* ── Reset / base ── */
:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --bg-elevated: #fefefe;
    --bg-muted: #fafafa;
    --bg-strong: #f6f6f6;
    --surface: #ffffff;
    --text: #222222;
    --text-strong: #111111;
    --text-soft: #333333;
    --text-muted: #888888;
    --text-faint: #aaaaaa;
    --line: #000000;
    --line-soft: #dddddd;
    --line-softer: #cccccc;
    --line-muted: #e0e0e0;
    --footer-overlay: rgba(255, 255, 255, 0.9);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111315;
        --bg-elevated: #16191c;
        --bg-muted: #1a1d21;
        --bg-strong: #20252a;
        --surface: #181c20;
        --text: #e4e7eb;
        --text-strong: #f7f8fa;
        --text-soft: #d5dae0;
        --text-muted: #a0a8b3;
        --text-faint: #87909b;
        --line: #d7dce2;
        --line-soft: #3b434c;
        --line-softer: #454d57;
        --line-muted: #343b44;
        --footer-overlay: rgba(17, 19, 21, 0.9);
    }
}

*, *::before, *::after {

    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Red Hat Mono", monospace;
    font-size: 13pt;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
    /* Invert article images and PDF raster pages so light PDFs
       remain readable on dark backgrounds */
    .blog-post-body img {
        filter: invert(0.9) hue-rotate(180deg);
    }

    #pdf-link-preview img {
        filter: invert(0.9) hue-rotate(180deg);
    }
}

/* ── Sticky nav bar ── */
.site-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-elevated);
    border-bottom: 1.5pt solid var(--line-soft);
    padding: 8pt 24pt;
    display: flex;
    align-items: center;
    gap: 10pt;
    font-size: 11pt;
}

.site-nav a {
    text-decoration: none;
    color: var(--text-soft);
}

.site-nav a:hover {
    text-decoration: underline;
}

.site-nav .nav-home {
    display: flex;
    align-items: center;
}

.nav-home-logo {
    height: 1em;
    width: auto;
    display: block;
}

.site-nav .nav-sep {
    color: var(--line-softer);
    user-select: none;
}

.site-nav .nav-current {
    color: var(--text-muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 30em;
}


/* ── Shared page wrapper (blog index only) ── */
.page-wrapper {
    max-width: 44em;
    margin: 0 auto;
    padding: 48pt 24pt 80pt;
}


/* ============================================================
   Blog post page — two-column layout
   ============================================================ */

/*
 * .post-columns is the outermost grid on a post page.
 * Left column : sticky sidebar (invisible until header scrolls out)
 * Right column: article header + body + footer
 *
 * The sidebar column has a fixed em width; the article column
 * fills the rest up to its own comfortable reading width.
 */
.post-columns {
    display: grid;
    grid-template-columns: 13em 1fr;
    gap: 0 3.5em;
    max-width: 72em;
    margin: 0 auto;
    padding: 40pt 24pt 80pt;
    align-items: start;
}

/* ── Sidebar ── */
.post-sidebar {
    position: sticky;
    top: 50px;                          /* sits just below .site-nav          */
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 3em;

    /* Hidden until the article header scrolls out of view.
       JS adds .is-visible via IntersectionObserver. */
    opacity: 0;
    pointer-events: none;
    transform: translateX(-8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.post-sidebar.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

/* Thin, unobtrusive scrollbar for the sidebar */
.post-sidebar::-webkit-scrollbar       { width: 3px; }
.post-sidebar::-webkit-scrollbar-track { background: transparent; }
.post-sidebar::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* ── Sidebar meta block ── */
.sidebar-meta {
    padding-bottom: 10pt;
    margin-bottom: 10pt;
    border-bottom: 1px solid var(--line-muted);
}

.sidebar-title {
    font-size: 10pt;
    font-weight: bold;
    line-height: 1.3;
    color: var(--text);
    margin: 0 0 5pt;
}

.sidebar-byline {
    font-size: 9pt;
    color: var(--text-faint);
    margin: 0 0 5pt;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-wrap: auto;
}

.sidebar-summary {
    font-size: 9pt;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.45;
    margin: 0;

    /* Clamp to four lines */
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Sidebar TOC ── */
.sidebar-toc ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-toc li {
    margin: 0;
    line-height: 1;
}

.sidebar-toc a:not(.sidebar-links a) {
    display: block;
    font-size: 9.5pt;
    line-height: 1.35;
    padding: 3pt 0 3pt 8pt;
    color: var(--text-faint);
    text-decoration: none;
    border-left: 2px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease, border-color 0.15s ease;
    text-wrap: auto;
}

.sidebar-toc a:not(.sidebar-links a):hover {
    color: var(--text-soft);
    border-left-color: var(--line-softer);
}

.sidebar-toc a:not(.sidebar-links a).is-active {
    color: var(--text-strong);
    border-left-color: var(--line);
    font-weight: bold;
}

/* h3 — one level of indentation */
.sidebar-toc .toc-h3 a:not(.sidebar-links a) {
    padding-left: 18pt;
    font-size: 9pt;
}

/* h4 — two levels */
.sidebar-toc .toc-h4 a:not(.sidebar-links a) {
    padding-left: 28pt;
    font-size: 8.5pt;
}

/* ── Right column wrapper ── */
.post-main {
    min-width: 0;       /* prevent grid blowout on long content */
    max-width: 44em;
}

/* ── TOC page-number pills (only for PDF articles)── */
.sidebar-toc .toc-page-num {
    font-size: 8pt;
    color: var(--line-softer);
    margin-left: 4pt;
}

.sidebar-toc a.is-active .toc-page-num {
    color: var(--text-muted);
}

/* ── Download link in sidebar (only for PDF articles) ── */
.sidebar-download:hover {
    color: royalblue;
    border-color: royalblue;
}

/* ── External publication links in sidebar (only for PDF articles) ── */
.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 6pt;
    margin-top: 10pt;
}

.sidebar-pub-link {
    display: flex;
    align-items: center;
    gap: 6pt;
    padding: 5pt 8pt;
    font-size: 9pt;
    color: color-mix(in srgb, var(--text) 82%, var(--bg) 18%);
    text-decoration: none;
    border: 1px solid var(--line-soft);
    border-radius: 3px;
    transition: color 0.15s, border-color 0.15s;
}

.sidebar-pub-link:hover {
    color: royalblue;
    border-color: royalblue;
}

.sidebar-pub-link .pub-link-label {
    flex: 1;
}

.sidebar-pub-link .pub-link-icon {
    font-size: 8pt;
    opacity: 0.6;
}

/* ============================================================
   Blog index page
   ============================================================ */

.blog-index-header {
    margin-bottom: 40pt;
    padding-bottom: 20pt;
    border-bottom: 1.5pt solid var(--line);
}

.blog-index-header h1 {
    font-family: "Sixtyfour", sans-serif;
    font-optical-sizing: auto;
    font-weight: 200;
    font-variation-settings: "BLED" 0, "SCAN" -10;
    font-size: 20pt;
    line-height: 1.05;
    margin: 0 0 8pt;
    text-transform: uppercase;
}

.blog-index-header p {
    font-size: 11pt;
    color: color-mix(in srgb, var(--text) 72%, var(--bg) 28%);
    margin: 0;
}

/* Post list */
.post-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.post-list li {
    padding: 20pt 0;
    border-bottom: 1px solid var(--line-soft);
}

.post-list li:first-child {
    border-top: 1px solid var(--line-soft);
}

.post-meta {
    font-size: 10pt;
    color: var(--text-muted);
    margin-bottom: 4pt;
}

.post-title-link {
    display: block;
    font-size: 15pt;
    font-weight: bold;
    line-height: 1.25;
    color: var(--text-strong);
    text-decoration: none;
    margin-bottom: 6pt;
}

.post-title-link:visited {
    color: var(--text-soft);
}

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

.post-summary {
    font-size: 11pt;
    color: color-mix(in srgb, var(--text) 82%, var(--bg) 18%);
    margin: 0 0 8pt;
}

.post-read-more {
    font-size: 10pt;
    color: royalblue;
    text-decoration: none;
    border-bottom: 1pt solid royalblue;
}

.post-read-more:visited {
    color: rebeccapurple;
    border-bottom-color: rebeccapurple;
}

.post-read-more:hover {
    opacity: 0.75;
}

.no-posts {
    color: var(--text-muted);
    font-size: 11pt;
    padding: 24pt 0;
}

.rss-link {
    display: inline-block;
    margin-left: 8pt;
    font-size: 9pt;
    font-weight: bold;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid #ccc;
    border-radius: 2px;
    padding: 1pt 5pt;
    vertical-align: middle;
    letter-spacing: 0.04em;
    transition: color 0.15s, border-color 0.15s;
}

.rss-link:hover {
    color: #e06000;
    border-color: #e06000;
}


/* ============================================================
   Blog post page
   ============================================================ */

/* Offset anchor-jump scrolling so headings aren't hidden behind the sticky nav.
   The value matches the .site-nav height (~37px) plus a small breathing gap. */
.blog-post-body h1,
.blog-post-body h2,
.blog-post-body h3,
.blog-post-body h4,
.blog-post-body h5,
.blog-post-body h6 {
    scroll-margin-top: 58px;
}

/* Post header — lives inside .post-main (the right grid column) */
.blog-post-header {
    margin-bottom: 36pt;
    padding-bottom: 20pt;
    border-bottom: 1.5pt solid var(--line);
}

.blog-post-header h1 {
    font-family: "Sixtyfour", sans-serif;
    font-optical-sizing: auto;
    font-weight: 200;
    font-variation-settings: "BLED" 0, "SCAN" -10;
    font-size: 20pt;
    line-height: 1.1;
    margin: 0 0 10pt;
    text-transform: uppercase;
}

.blog-post-meta {
    font-size: 10pt;
    color: var(--text-muted);
    margin-bottom: 10pt;
}

.blog-post-summary {
    font-size: 12pt;
    color: color-mix(in srgb, var(--text) 82%, var(--bg) 18%);
    font-style: italic;
    margin: 0;
}


/* ── Main header links (PDF download, publication links) ── */
.main-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8pt;
    margin-top: 12pt;
}

.main-pub-link {
    display: inline-flex;
    align-items: center;
    gap: 6pt;
    padding: 6pt 10pt;
    font-size: 10pt;
    color: color-mix(in srgb, var(--text) 82%, var(--bg) 18%);
    text-decoration: none;
    border: 1px solid var(--line-soft);
    border-radius: 3px;
    transition: color 0.15s, border-color 0.15s;
}

.main-pub-link:hover {
    color: royalblue;
    border-color: royalblue;
}

.main-pub-link .pub-link-label {
    flex: 1;
}

.main-pub-link .pub-link-icon {
    font-size: 9pt;
    opacity: 0.6;
}



/* ── Post body typography ── */
.blog-post-body p {
    margin: 0 0 1em;
}

/* Images */
.blog-post-body img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Standalone image in its own paragraph — centre it */
.blog-post-body p > img:only-child {
    margin: 1.5em auto;
}

/* Figures */
.blog-post-body figure {
    margin: 2em 0;
    text-align: center;
}

.blog-post-body figure img {
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    display: block;
}

.blog-post-body figcaption {
    margin-top: 7pt;
    font-size: 9.5pt;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.45;
    text-align: center;

    /* Constrain caption width to match a comfortable reading measure */
    max-width: 34em;
    margin-left: auto;
    margin-right: auto;
}

.blog-post-body h1,
.blog-post-body h2,
.blog-post-body h3,
.blog-post-body h4,
.blog-post-body h5,
.blog-post-body h6 {
    font-family: "Red Hat Mono", monospace;
    font-weight: bold;
    line-height: 1.2;
    margin: 2em 0 0.5em;
}

.blog-post-body h1 { font-size: 20pt; }
.blog-post-body h2 { font-size: 16pt; }
.blog-post-body h3 { font-size: 13pt; }
.blog-post-body h4 { font-size: 12pt; font-style: italic; }

/* Links */
.blog-post-body a {
    color: royalblue;
    text-decoration: underline;
}

.blog-post-body a:visited {
    color: rebeccapurple;
}

/* Blockquotes */
.blog-post-body blockquote {
    margin: 1.5em 0;
    padding: 0.5em 1em;
    border-left: 3pt solid var(--line-softer);
    color: color-mix(in srgb, var(--text) 82%, var(--bg) 18%);
    font-style: italic;
}

.blog-post-body blockquote p {
    margin: 0;
}

/* Code — inline */
.blog-post-body code {
    font-family: "Red Hat Mono", monospace;
    font-size: 0.88em;
    background: var(--bg-strong);
    border: 1px solid var(--line-soft);
    border-radius: 3px;
    padding: 0.1em 0.35em;
}

/* Code — fenced blocks */
.blog-post-body pre {
    margin: 1.5em 0;
    padding: 14pt 16pt;
    background: var(--bg-strong);
    border: 1px solid var(--line-soft);
    border-left: 3pt solid var(--line);
    overflow-x: auto;
    font-size: 0.85em;
    line-height: 1.5;
}

.blog-post-body pre code {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    font-size: inherit;
}

/* Tables */
.blog-post-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: 11pt;
}

.blog-post-body thead tr {
    border-bottom: 2pt solid var(--line);
}

.blog-post-body th {
    text-align: left;
    padding: 6pt 10pt;
    font-weight: bold;
}

.blog-post-body td {
    padding: 6pt 10pt;
    border-bottom: 1px solid var(--line-soft);
}

.blog-post-body tr:last-child td {
    border-bottom: none;
}

/* Horizontal rule */
.blog-post-body hr {
    border: none;
    border-top: 1.5pt solid var(--line);
    margin: 3em 0;
}

/* Lists */
.blog-post-body ul,
.blog-post-body ol {
    margin: 0 0 1em 1.5em;
    padding: 0;
}

.blog-post-body li {
    margin-bottom: 0.3em;
}

/* Math — arithmatex generic mode produces .arithmatex wrappers.
   Display-math divs should be centred with scroll on overflow. */
.blog-post-body .arithmatex {
    overflow-x: auto;
}

div.arithmatex {
    text-align: center;
    margin: 1.5em 0;
    overflow-x: auto;
}


/* ── Post footer ── */
.blog-post-footer {
    margin-top: 48pt;
    padding-top: 16pt;
    border-top: 1px solid var(--line-soft);
    font-size: 10pt;
}

.blog-post-footer a {
    color: royalblue;
    text-decoration: none;
    border-bottom: 1pt solid royalblue;
}

.blog-post-footer a:visited {
    color: rebeccapurple;
    border-bottom-color: rebeccapurple;
}

.blog-post-footer a:hover {
    opacity: 0.75;
}

/* Footer */
footer {
    position: relative;
    color: var(--text-strong);
    text-align: center;
    padding: 0 0;
    font-size: 10pt;
    background: url('square-logo-stylized-background.svg') no-repeat center center / 100% 100%;
}

@media (prefers-color-scheme: dark) {
    footer {
        filter: invert(1) hue-rotate(180deg);
    }
}

footer > * {
    background: var(--footer-overlay);
    padding: 8pt 16pt;
    margin-top: 0;
    margin-bottom: 0;
    display: inline-block;
}


/* ── Responsive ── */

/* Collapse the sidebar below ~900 px — single-column reading view */
@media (max-width: 900px) {
    .post-columns {
        grid-template-columns: 1fr;
        padding: 32pt 18pt 60pt;
    }

    .post-sidebar {
        display: none;
    }

    .post-main {
        max-width: 100%;
    }
}

@media (max-width: 600px) {
    html, body {
        font-size: 12pt;
    }

    .page-wrapper {
        padding: 28pt 16pt 60pt;
    }

    .blog-index-header h1 {
        font-size: 22pt;
    }

    .blog-post-header h1 {
        font-size: 16pt;
        font-variation-settings:
          "BLED" 0,
          "SCAN" 0;
    }

    .site-nav {
        padding: 8pt 14pt;
        gap: 6pt;
    }

    .site-nav .nav-current {
        display: none;   /* breadcrumb title gets too long on small screens */
    }
}