/* Writing: article pages. Loaded after index.css, which supplies the base type,
   link style and colours. Everything here is for /writing/<slug>/ pages. */

:root {
    --measure: 35rem;
    --wide: 45rem;
    --ink: #111;
    --muted: #999;
    --rule: #eee;
    --duration-quick: 150ms;
    --duration-fast: 250ms;
    --ease-smooth-out: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

::selection {
    background: #ededed;
}

/* Text scrolls away under a soft fade instead of hitting the viewport edge */
.page-fade {
    position: fixed;
    inset: 0 0 auto;
    z-index: 2;
    height: 2.5rem;
    pointer-events: none;
    background: linear-gradient(180deg, #fff, rgba(255, 255, 255, 0));
}

main.article {
    max-width: var(--measure);
}

/* Back link, then the contents rail on wide screens */
.aside {
    padding-bottom: 32px;
}

.back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    margin: -10px 0;
    font-size: 14px;
    color: var(--muted);
    text-decoration: none;
    transition: color var(--duration-quick) var(--ease-smooth-out);
}

.back svg {
    transition: transform var(--duration-quick) var(--ease-smooth-out);
}

.toc {
    display: none;
}

/* Header */
.article-head {
    margin-bottom: 32px;
}

.article-head h1 {
    margin: 0 0 4px;
    font-size: 24px;
    line-height: 1.25;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

.article-date {
    display: block;
    font-size: 13px;
    color: var(--muted);
}

/* Body */
.prose {
    font-size: 16px;
    line-height: 1.7;
}

.prose > p,
.prose > ul,
.prose > ol,
.prose > blockquote,
.prose > pre {
    margin: 0 0 20px;
}

.prose p {
    text-wrap: pretty;
}

.prose .lede {
    font-size: 18px;
    line-height: 1.55;
    letter-spacing: -0.01em;
}

.prose h2 {
    margin: 0 0 10px;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--ink);
    scroll-margin-top: 64px;
}

.prose h3 {
    margin: 28px 0 8px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.prose hr {
    width: 100%;
    height: 1px;
    margin: 44px 0;
    border: 0;
    background: var(--rule);
}

.prose ul,
.prose ol {
    padding-left: 1.4em;
}

.prose li {
    margin-bottom: 6px;
    padding-left: 2px;
}

.prose li::marker {
    color: var(--muted);
}

.prose blockquote {
    padding-left: 16px;
    border-left: 2px solid var(--ink);
}

.prose blockquote p {
    margin: 0;
}

.prose code {
    padding: 1px 4px;
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
    background: #f5f5f4;
    border-radius: 5px;
}

.prose pre {
    padding: 14px 16px;
    overflow-x: auto;
    line-height: 1.6;
    background: #f7f7f6;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
}

.prose pre code {
    padding: 0;
    font-size: 13px;
    background: none;
}

/* Figures */
.prose figure {
    margin: 28px 0;
}

.prose figure img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
    outline: 1px solid rgba(0, 0, 0, 0.08);
    outline-offset: -1px;
}

.prose figcaption {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--muted);
}

/* Breaks out of the reading column, centred on it, when there is room */
.prose .is-wide {
    margin-inline: calc((100% - min(var(--wide), 100vw - 64px)) / 2);
}

/* Footnotes */
.fn-ref {
    margin-left: 1px;
    font-size: 0.72em;
    line-height: 0;
    vertical-align: super;
}

.fn-ref a {
    padding: 4px 3px;
    color: var(--muted);
    text-decoration: none;
    scroll-margin-top: 96px;
}

.footnotes {
    margin-top: 44px;
    padding-top: 20px;
    border-top: 1px solid var(--rule);
    font-size: 13px;
    line-height: 1.6;
    color: #777;
}

.footnotes ol {
    margin: 0;
    padding-left: 1.4em;
}

.footnotes li {
    padding: 2px 6px;
    margin-left: -6px;
    scroll-margin-top: 96px;
    border-radius: 6px;
    transition: background-color var(--duration-fast) var(--ease-smooth-out);
}

.footnotes li:target {
    background: #f5f5f4;
}

.fn-back {
    margin-left: 4px;
    color: var(--muted);
    text-decoration: none;
}

/* Source credits stay readable but quieter than the point they back up */
.src {
    font-size: 0.82em;
    color: var(--muted);
}

@media (hover: hover) and (pointer: fine) {
    .back:hover {
        color: var(--ink);
        text-decoration: none;
    }

    .back:hover svg {
        transform: translateX(-2px);
    }

    .fn-ref a:hover,
    .fn-back:hover {
        color: var(--ink);
    }
}

@media (hover: none) {
    .back:active {
        color: var(--ink);
    }
}

/* Wide screens: the back link and contents sit in the left margin, out of the
   reading column, and stay put while the article scrolls */
@media (min-width: 1081px) {
    .aside {
        position: fixed;
        top: 72px;
        left: 48px;
        width: 168px;
        padding: 0;
    }

    .toc {
        display: block;
        padding-top: 24px;
    }

    .toc-title {
        display: block;
        padding-bottom: 12px;
        font-size: 13px;
        font-weight: 500;
        line-height: 1.25;
        color: var(--ink);
        text-decoration: none;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--duration-fast) var(--ease-smooth-out);
    }

    .toc.is-scrolled .toc-title {
        opacity: 1;
        pointer-events: auto;
    }

    .toc ul {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin: 0;
        padding: 0 0 0 12px;
        list-style: none;
    }

    /* Rail, and the one marker that travels along it */
    .toc ul::before,
    .toc-marker {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 1px;
    }

    .toc ul::before {
        bottom: 0;
        background: #e4e4e2;
    }

    .toc-marker {
        height: 1px;
        background: var(--ink);
        opacity: 0;
        transform-origin: top;
        transition: opacity var(--duration-quick) var(--ease-smooth-out);
    }

    .toc-marker.is-live {
        opacity: 1;
        transition: opacity var(--duration-quick) var(--ease-smooth-out),
            transform var(--duration-fast) var(--ease-smooth-out);
    }

    .toc li a {
        display: block;
        font-size: 13px;
        line-height: 1.25;
        color: var(--muted);
        text-decoration: none;
        transition: color var(--duration-quick) var(--ease-smooth-out);
    }

    .toc li a:hover,
    .toc li a[aria-current="true"] {
        color: var(--ink);
    }
}

@media (max-width: 640px) {
    .prose hr {
        margin: 32px 0;
    }

    .prose .is-wide {
        margin-inline: 0;
    }

}

@media (prefers-reduced-motion: reduce) {
    .toc-marker.is-live {
        transition: opacity var(--duration-quick) var(--ease-smooth-out);
    }

    .back svg {
        transition: none;
    }
}
