/* ------------------------------------------------------------------
   Fonts (self-hosted, latin subset, variable weight)
------------------------------------------------------------------ */
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter-latin.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin.woff2") format("woff2");
}

/* ------------------------------------------------------------------
   Tokens
------------------------------------------------------------------ */
:root {
    color-scheme: light;

    --bg: #faf9f6;
    --surface: #ffffff;
    --surface-2: #f1eee8;
    --text: #1f1d1a;
    --text-muted: #6c675e;
    --text-faint: #a39d92;
    --border: #e4dfd6;
    --border-strong: #cfc8bc;
    --accent: #b1500b;
    --accent-hover: #8c3f08;
    --accent-soft: rgba(177, 80, 11, 0.10);
    --code-bg: #f4f2ed;
    --code-border: #e4dfd6;
    --selection: rgba(177, 80, 11, 0.18);
    --shadow: 0 1px 2px rgba(20, 15, 5, 0.04), 0 4px 16px rgba(20, 15, 5, 0.05);

    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --measure: 44rem;
    --toc-width: 15rem;
    --toc-gap: 3rem;
    --gutter: 1rem;
    --radius: 8px;
}

html.dark {
    color-scheme: dark;

    --bg: #141311;
    --surface: #1b1917;
    --surface-2: #242120;
    --text: #e8e5de;
    --text-muted: #a09a8f;
    --text-faint: #6a655c;
    --border: #2d2a26;
    --border-strong: #3d3933;
    --accent: #f0a33a;
    --accent-hover: #f6b95f;
    --accent-soft: rgba(240, 163, 58, 0.14);
    --code-bg: #1b1917;
    --code-border: #2d2a26;
    --selection: rgba(240, 163, 58, 0.25);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* ------------------------------------------------------------------
   Base
------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html {
    font-size: 106.25%; /* 17px */
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 1.5rem;
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition: none !important; }
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.65;
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection { background: var(--selection); }

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
a:focus-visible, button:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

img, svg, video { max-width: 100%; height: auto; }

.skip-link {
    position: absolute;
    left: 0.5rem;
    top: -3rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    z-index: 100;
}
.skip-link:focus { top: 0.5rem; }

/* ------------------------------------------------------------------
   Header
------------------------------------------------------------------ */
.site-header {
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.site-header-inner {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto;
    padding: 0.9rem var(--gutter);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 650;
    letter-spacing: -0.01em;
    font-size: 1.05rem;
}
.brand img { border-radius: 6px; }
.brand:hover { color: var(--accent); }

.site-nav {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
    flex-wrap: wrap;
}
.site-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle .icon { width: 1.05rem; height: 1.05rem; fill: currentColor; display: none; }
html[data-theme="auto"] .icon-auto,
html[data-theme="light"] .icon-light,
html[data-theme="dark"] .icon-dark { display: block; }

@media (max-width: 40rem) {
    .site-header-inner { gap: 0.75rem 1rem; }
    .site-nav { order: 3; width: 100%; margin-left: -0.6rem; }
    .theme-toggle { margin-left: auto; }
}

/* ------------------------------------------------------------------
   Layout
------------------------------------------------------------------ */
.container {
    width: 100%;
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto;
    padding: 2.5rem var(--gutter) 4rem;
    flex: 1;
}

/* Posts with a table of contents: on wide screens the ToC hangs in the right
   margin, so the article column stays in the same place as on every other page. */
@media (min-width: 80rem) {
    .with-toc { position: relative; }
    .with-toc .toc-wrap {
        position: absolute;
        top: 2.5rem;
        bottom: 4rem;
        left: calc(100% - var(--gutter) + var(--toc-gap));
        width: var(--toc-width);
        margin: 0;
    }
    .with-toc .toc {
        position: sticky;
        top: 1.5rem;
        max-height: calc(100vh - 3rem);
        overflow-y: auto;
        border: 0;
        border-left: 1px solid var(--border);
        border-radius: 0;
        background: transparent;
        padding: 0.35rem 0 0.35rem 0.9rem;
    }
    .with-toc .toc > summary { display: none; }
    .with-toc .toc::before {
        content: "On this page";
        display: block;
        font-family: var(--font-mono);
        font-size: 0.72rem;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--text-faint);
        margin-bottom: 0.6rem;
    }
    .with-toc .toc li a { padding-left: 0.85rem; margin-left: -0.9rem; border-left-width: 2px; }
    .with-toc .toc li a { margin-left: calc(-0.9rem - 1px); }
    .with-toc .toc li.toc-l2 a { padding-left: 1.75rem; }
}

/* ------------------------------------------------------------------
   Table of contents
------------------------------------------------------------------ */
.toc-wrap { margin: 0 0 2rem; font-size: 0.86rem; }
.toc {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0.6rem 0.9rem;
}
.toc > summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}
.toc > summary::-webkit-details-marker { display: none; }
.toc > summary::before {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}
.toc[open] > summary::before { transform: rotate(45deg); }
.toc[open] > summary { margin-bottom: 0.5rem; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; line-height: 1.4; }
.toc li a {
    display: block;
    padding: 0.28rem 0 0.28rem 0.7rem;
    border-left: 2px solid transparent;
    color: var(--text-muted);
    text-decoration: none;
}
.toc li a:hover { color: var(--text); }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); }
.toc li.toc-l2 a { padding-left: 1.6rem; font-size: 0.95em; }

/* ------------------------------------------------------------------
   Headers of pages and posts
------------------------------------------------------------------ */
.page-header, .post-header { margin-bottom: 2rem; }
.page-header h1, .post-header h1, .hero h1 {
    font-size: clamp(1.75rem, 1.3rem + 2vw, 2.35rem);
    line-height: 1.15;
    letter-spacing: -0.022em;
    font-weight: 700;
    margin: 0 0 0.6rem;
    text-wrap: balance;
}
.meta, .lede { margin: 0; }
.meta {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.meta .sep { color: var(--text-faint); }
.lede { color: var(--text-muted); font-size: 1.02rem; }

/* ------------------------------------------------------------------
   Home
------------------------------------------------------------------ */
.hero { margin-bottom: 1.5rem; }
.hero .tagline {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.recent { margin: 3rem 0 2.5rem; }
.recent h2 {
    font-size: 0.8rem;
    font-family: var(--font-mono);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin: 0 0 1rem;
}
.recent .more { margin: 1.25rem 0 0; font-size: 0.95rem; }

/* ------------------------------------------------------------------
   Post lists
------------------------------------------------------------------ */
.year { margin-bottom: 2.5rem; }
.year-heading {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    margin: 0 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li {
    display: grid;
    grid-template-columns: 6.5rem 1fr;
    gap: 0.25rem 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.post-list li:last-child { border-bottom: 0; }
.post-list-date {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    padding-top: 0.3rem;
    white-space: nowrap;
}
.post-list-title {
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.01em;
    line-height: 1.35;
    display: inline-block;
}
.post-list-title:hover { color: var(--accent); }
.post-list-description {
    margin: 0.3rem 0 0;
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text-muted);
}
@media (max-width: 34rem) {
    .post-list li { grid-template-columns: 1fr; gap: 0.1rem; }
    .post-list-date { padding-top: 0; }
}

/* ------------------------------------------------------------------
   Prose (rendered markdown)
------------------------------------------------------------------ */
.prose { font-size: 1rem; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

.prose p, .prose ul, .prose ol, .prose blockquote, .prose .table-wrapper, .prose .codeblock, .prose figure {
    margin: 0 0 1.3rem;
}
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
    position: relative;
    line-height: 1.25;
    letter-spacing: -0.015em;
    font-weight: 650;
    margin: 2.4rem 0 0.9rem;
    text-wrap: balance;
}
.prose h1 { font-size: 1.6rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.18rem; }
.prose h4 { font-size: 1.04rem; }
.prose h5, .prose h6 { font-size: 0.95rem; color: var(--text-muted); }
.prose hr + h1, .prose hr + h2, .prose hr + h3, .prose hr + h4 { margin-top: 0; }

/* Heading anchors: shown on hover, positioned in the left margin on wide screens. */
.prose .anchor {
    text-decoration: none;
    color: var(--text-faint);
    margin-left: 0.4rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.prose .anchor::after { content: "#"; }
.prose h1:hover .anchor, .prose h2:hover .anchor, .prose h3:hover .anchor,
.prose h4:hover .anchor, .prose .anchor:focus-visible { opacity: 1; }
.prose .anchor:hover { color: var(--accent); }

.prose ul, .prose ol { padding-left: 1.5rem; }
.prose li { margin: 0.3rem 0; }
.prose li > ul, .prose li > ol { margin: 0.3rem 0 0; }
.prose li > p { margin-bottom: 0.5rem; }

.prose strong { font-weight: 650; }
.prose hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 2.5rem 0 2rem;
}
.prose blockquote {
    border-left: 3px solid var(--border-strong);
    padding: 0.1rem 0 0.1rem 1.1rem;
    color: var(--text-muted);
}
.prose blockquote > :last-child { margin-bottom: 0; }

.prose small { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; display: inline-block; }
.prose .prompt { color: var(--accent); font-family: var(--font-mono); }

/* Code */
.prose code, .prose kbd {
    font-family: var(--font-mono);
    font-size: 0.86em;
}
.prose :not(pre) > code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.08em 0.36em;
    border-radius: 5px;
    word-break: break-word;
}
.prose a > code { color: inherit; }
.codeblock {
    position: relative;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius);
}
.codeblock pre {
    margin: 0;
    padding: 0.95rem 1.1rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    tab-size: 4;
}
.codeblock code { font-size: inherit; background: none; border: 0; padding: 0; }
.codeblock .copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.55rem;
    font: 500 0.7rem var(--font-mono);
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.codeblock:hover .copy, .codeblock .copy:focus-visible, .codeblock .copy.copied { opacity: 1; }
.codeblock .copy:hover { color: var(--text); }
.codeblock .copy.copied { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .codeblock .copy { opacity: 1; } }

/* Figures and images */
.prose figure { margin-left: 0; margin-right: 0; }
.prose img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
}
.prose p > img { margin: 0.25rem 0; }
.prose figcaption {
    margin-top: 0.55rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-muted);
}
.prose figcaption em { font-style: normal; }

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.prose table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    line-height: 1.5;
}
.prose th, .prose td {
    padding: 0.55rem 0.85rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}
.prose th {
    background: var(--surface-2);
    font-weight: 600;
    white-space: nowrap;
}
.prose tr:last-child td { border-bottom: 0; }
.prose td code { white-space: nowrap; }

/* Footnotes */
.prose .footnotes { font-size: 0.88rem; color: var(--text-muted); }
.prose .footnotes-sep { margin: 2.5rem 0 1rem; }

/* ------------------------------------------------------------------
   Post navigation and comments
------------------------------------------------------------------ */
.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 3.5rem 0 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.post-nav-link {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.post-nav-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow); color: var(--text); }
.post-nav-link .label { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); }
.post-nav-link .title { font-weight: 600; font-size: 0.92rem; line-height: 1.35; }
.post-nav-link.newer { text-align: right; align-items: flex-end; }
@media (max-width: 34rem) {
    .post-nav { grid-template-columns: 1fr; }
    .post-nav-link.newer { text-align: left; align-items: flex-start; }
}

.comments { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.comments h2 { font-size: 1.25rem; margin: 0 0 1rem; letter-spacing: -0.015em; }

/* ------------------------------------------------------------------
   Footer
------------------------------------------------------------------ */
.site-footer {
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-muted);
}
.site-footer-inner {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto;
    padding: 1.25rem var(--gutter);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    justify-content: space-between;
}
.site-footer nav { display: flex; gap: 1.25rem; }
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

@media print {
    .site-header, .site-footer, .toc-wrap, .post-nav, .comments, .codeblock .copy { display: none !important; }
    .container { padding: 0; }
}

/* Formulas written as MathML in the markdown (e.g. the CS:GO beep pattern post). */
.prose math[display="block"] { font-size: 1.4em; margin: 0.75rem 0 1rem; overflow-x: auto; }
