@font-face {
    font-family: "Maple Mono";
    font-style: normal;
    font-display: swap;
    font-weight: 400;
    /* Kev, I hope you don't mind me piggybacking off your CDN to serve Maple Mono 😬 */
    src: url("https://cdn.kevquirk.com/maple/MapleMono-Regular.woff2") format("woff2"),
        url("https://cdn.kevquirk.com/maple/MapleMono-Regular.woff") format("woff");
}

@font-face {
    font-family: "Maple Mono";
    font-style: normal;
    font-display: swap;
    font-weight: 700;
    src: url("https://cdn.kevquirk.com/maple/MapleMono-Bold.woff2") format("woff2"),
        url("https://cdn.kevquirk.com/maple/MapleMono-Bold.woff") format("woff");
}

@font-face {
    font-family: "Maple Mono";
    font-style: italic;
    font-display: swap;
    font-weight: 400;
    src: url("https://cdn.kevquirk.com/maple/MapleMono-Italic.woff2") format("woff2"),
        url("https://cdn.kevquirk.com/maple/MapleMono-Italic.woff") format("woff");
}

@font-face {
    font-family: "Maple Mono";
    font-style: italic;
    font-display: swap;
    font-weight: 700;
    src: url("https://cdn.kevquirk.com/maple/MapleMono-BoldItalic.woff2") format("woff2"),
        url("https://cdn.kevquirk.com/maple/MapleMono-BoldItalic.woff") format("woff");
}

:root {
    --measure: 42rem;
    --bg: #ffffff;
    --fg: #1a1a1a;
    --muted: #666666;
    --accent: #0a58ca;
    --border: #dddddd;
    --surface: #f5f5f5;
    --surface-2: #eaeaea;
    --code-bg: #f6f8fa;
    --mark-bg: #fff2a8;
    --mark-fg: #000000;
    --danger: #b00020;

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121212;
        --fg: #e8e8e8;
        --muted: #9aa0a6;
        --accent: #7aa2f7;
        --border: #333333;
        --surface: #1c1c1c;
        --surface-2: #262626;
        --code-bg: #1a1a1a;
        --mark-bg: #5c4d00;
        --mark-fg: #ffffff;
        --danger: #ff6b6b;
    }
}

* {
    box-sizing: border-box;
    font-family: "Maple Mono", ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

body {
    font-family: system-ui, sans-serif;
    line-height: 1.6;
    color: var(--fg);
    background-color: var(--bg);
    margin: 0;
    padding: 0 1rem;
}

.site-header,
main,
.comments,
#townsquare-root,
.site-footer {
    max-width: var(--measure);
    margin-inline: auto;
}

.site-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.site-title { font-weight: 700; text-decoration: none; color: inherit; }
.site-header nav a { /* margin-left: 1rem; */ margin: .2rem; }

main { padding: 2rem 0; }

main {
    overflow-wrap: break-word;
    word-break: break-word;
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 0;
    color: var(--muted);
    font-size: 0.9rem;
}

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

.external-favicon {
    width: 1em;
    height: 1em;
    margin-right: 0.3em;
    vertical-align: -0.15em;
    border-radius: 2px;
}
.external-link::after {
    content: "↗";
    margin-left: 0.15em;
    font-size: 0.8em;
    line-height: 0;
    color: var(--muted);
    text-decoration: none;
}

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

pre {
    overflow-x: auto;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--code-bg);
}
code { font-family: ui-monospace, monospace; }
:not(pre) > code {
    background-color: var(--surface);
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-size: 0.9em;
}

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

.meta { color: var(--muted); font-size: 0.9rem; }
.meta .tag { margin-right: 0.5rem; }

.post-list { list-style: none; padding: 0; }
.post-list li { margin-bottom: 1rem; }
.post-list time { color: var(--muted); font-size: 0.85rem; margin-left: 0.5rem; }
.post-list .preview { color: var(--muted); margin: 0.25rem 0 0; }

/* ---- {{ recent }} / <recent> recent-posts blocks ---- */
ul.recent { list-style: none; padding: 0; }
ul.recent li { margin-bottom: 0.4rem; }
ul.recent time { color: var(--muted); font-size: 0.85rem; margin-left: 0.5rem; }

.recent-posts {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0;
}
.recent-post time { color: var(--muted); font-size: 0.85rem; margin-left: 0.5rem; }
.recent-post .excerpt {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.broken-link { color: var(--danger); border-bottom: 1px dashed var(--danger); }

.callout {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background-color: var(--surface);
}
.callout-title { font-weight: 700; }
.callout-note, .callout-info { border-left-color: #0a58ca; }
.callout-tip { border-left-color: #198754; }
.callout-important { border-left-color: #8250df; }
.callout-warning { border-left-color: #ffc107; }
.callout-caution, .callout-danger { border-left-color: #d1242f; }

/* ---- content tabs (=== "Tab" syntax) ---- */
.tabbed-set {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.tabbed-set > input[type="radio"] { display: none; }
.tabbed-set > label {
    order: -1;
    flex: 1 1 0;
    min-width: 0;
    padding: 0.5rem 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    background: var(--surface);
    border-bottom: 2px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}
.tabbed-set > label:hover { background: var(--surface-2); }
.tabbed-set > .tabbed-content {
    order: 0;
    display: none;
    width: 100%;
    padding: 1rem;
    overflow-x: auto;
}
.tabbed-set > input[type="radio"]:checked + label {
    background: var(--bg);
    border-bottom-color: var(--accent);
}
.tabbed-set > input[type="radio"]:checked + label + .tabbed-content {
    display: block;
}
.tabbed-set .tabbed-content pre { margin: 0; }
.tabbed-set .tabbed-content pre code { background: none; padding: 0; }

#folium-q {
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--surface);
    color: var(--fg);
}
mark { background: var(--mark-bg); color: var(--mark-fg); }

/* ---- GFM task lists ---- */
.contains-task-list { list-style: none; padding-left: 1.2rem; }
.contains-task-list .contains-task-list { padding-left: 1.4rem; }
.task-list-item { list-style: none; }
.task-list-item-checkbox {
    margin: 0 0.45rem 0 -1.4rem;
    vertical-align: middle;
}

/* ---- footnotes: bottom section (fallback), sidenotes, and popup ---- */
sup.footnote-ref { line-height: 0; }
sup.footnote-ref a { text-decoration: none; }
.footnotes { font-size: 0.9rem; color: var(--muted); }
.sidenote-num { color: var(--accent); font-weight: 700; margin-right: 0.35em; }

/* Hidden by default (narrow screens use the popup instead). */
.sidenote { display: none; }

.footnote-popup {
    position: absolute;
    z-index: 1100;
    max-width: min(22rem, calc(100vw - 1rem));
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
    font-size: 0.9rem;
    line-height: 1.5;
}
.footnote-popup-body { padding-right: 1rem; }
.footnote-popup-body p { margin: 0.25rem 0; }
.footnote-popup-body :last-child { margin-bottom: 0; }
.footnote-popup-close {
    position: absolute;
    top: 0;
    right: 4px;
    background: none;
    border: none;
    font-size: 1.2rem;
    line-height: 1.4;
    cursor: pointer;
    color: var(--muted);
}

@media (min-width: 78rem) {
    .sidenote {
        display: block;
        position: absolute;
        left: 100%;
        width: 14rem;
        margin-left: 1.5rem;
        font-size: 0.8rem;
        line-height: 1.45;
        color: var(--muted);
    }
    .sidenote p { margin: 0 0 0.4rem; }
    .sidenote :last-child { margin-bottom: 0; }
    .sidenote-flash {
        outline: 2px solid var(--accent);
        outline-offset: 3px;
        border-radius: 2px;
    }
    /* When sidenotes are shown, drop the duplicated bottom section. */
    .footnotes-enhanced .footnotes,
    .footnotes-enhanced .footnotes-sep { display: none; }
}

/* ---- search popup overlay ---- */
.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10vh 1rem 2rem;
    background: rgba(0, 0, 0, 0.5);
    overflow-y: auto;
}
.search-overlay[hidden] { display: none; }

.search-modal {
    width: 100%;
    max-width: var(--measure);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.search-modal-q {
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--surface);
    color: var(--fg);
}

.search-modal-results {
    margin-top: 1rem;
    max-height: 60vh;
    overflow-y: auto;
}

body.search-open { overflow: hidden; }

table { border-collapse: collapse; }
th, td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; }
th { background-color: var(--surface); }

/* ==========================================================================
   SCROLL PROGRESS INDICATOR (LessWrong Design Layout)
   ========================================================================== */
#scroll-container {
    display: none; /* Blocked in JS, shown only when DOM is ready */
    position: fixed;
    left: 2rem; /* Floating elegantly on the left side of the screen */
    top: 4rem;
    height: calc(100vh - 8rem);
    width: 30px; /* Generous transparent interactive hover hitbox target */
    background-color: transparent;
    z-index: 1000;
    cursor: pointer;
}

/* Central vertical track line */
#scroll-container::before {
    content: "";
    position: absolute;
    left: 14px; /* Centered perfectly inside the 30px target space */
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: light-dark(var(--surface-2), var(--border));
    z-index: 1001;
}

/* Growing Progress Bar Thumb [xxxxxx  ] */
#scroll-container #indicator {
    position: absolute;
    left: 13.5px; /* Aligned over central track line */
    width: 3px;
    background-color: var(--accent);
    z-index: 1002;
    transition: height 0.1s ease-out; /* Keeps transitions silky when scrolling */
}

/* Gap containers for heading markers */
#scroll-container .heading-marker-container {
    position: absolute;
    left: 0;
    right: 0;
    text-decoration: none;
    z-index: 1003; /* High layering so gaps slice through both track and progress bar */
}

/* Tick line breaks */
#scroll-container .heading-indicator {
    display: block;
    margin-left: 13.5px; /* Aligned over track line */
    width: 3px;
    height: 4px;
    background-color: var(--bg); /* Set to body background to clip line visual */
}

/* Hover-expanded heading labels */
#scroll-container .heading-label {
    display: block;
    opacity: 0;
    visibility: hidden;
    width: 12rem;
    margin-left: 2.5rem; /* Safely pushed to the right of the indicator line */
    line-height: 1.1;
    font-size: 0.8rem;
    transform: translateY(-50%);
    transition: opacity 0.25s ease, visibility 0.25s;
    color: var(--muted);
    pointer-events: none;
}

/* Expanding label list on wide tracker hover */
#scroll-container:hover .heading-label {
    opacity: 1;
    visibility: visible;
}

/* Horizontal progress bar for smaller viewport layouts */
@media (max-width: 45rem) {
    #scroll-container {
        position: fixed;
        inset: 0 0 auto;
        height: 4px;
        width: 100%;
        left: 0;
        top: 0;
    }

    #scroll-container::before {
        display: none; /* Hide vertical track backgrounds on narrow layouts */
    }

    #scroll-container #indicator {
        left: 0;
        top: 0;
        height: 100% !important;
    }
}


#townsquare-root#townsquare-root {
    --scene: #e4e2dd;
    --ground-fill: #efede9;
    --page: #efede9;
    --action-zone-fill: #efede9;
    --surface: #fdf8f4;
    --ink: #2a2926;
    --you: #c8641f;
    --tree-trunk: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
    --tree-canopy: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
    --other: #26241f;
    --ground-line: rgba(42, 41, 38, 0.16);
    --ground: rgba(42, 41, 38, 0.16);
    --you-deep: var(--you);
    --text: var(--ink);
    --muted: var(--ink);
}

#townsquare-root#townsquare-root[data-townsquare-theme="dark"] {
    --scene: #242521;
    --ground-fill: #181917;
    --page: #181917;
    --action-zone-fill: #181917;
    --surface: #24231f;
    --ink: #f2eee6;
    --you: #df8a43;
    --tree-trunk: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
    --tree-canopy: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
    --other: #ddd7cc;
    --ground-line: rgba(242, 238, 230, 0.18);
    --ground: rgba(242, 238, 230, 0.18);
    --you-deep: var(--you);
    --text: var(--ink);
    --muted: var(--ink);
}

@media (prefers-color-scheme: dark) {
    #townsquare-root#townsquare-root,
    #townsquare-root#townsquare-root[data-townsquare-theme="auto"] {
        --scene: #242521;
        --ground-fill: #181917;
        --page: #181917;
        --action-zone-fill: #181917;
        --surface: #24231f;
        --ink: #f2eee6;
        --you: #df8a43;
        --tree-trunk: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
        --tree-canopy: color-mix(in oklab, var(--text) 58%, var(--muted) 42%);
        --other: #ddd7cc;
        --ground-line: rgba(242, 238, 230, 0.18);
        --ground: rgba(242, 238, 230, 0.18);
        --you-deep: var(--you);
        --text: var(--ink);
        --muted: var(--ink);
    }
}

