
@layer pages {
    .article-page {
        padding-top: clamp(3rem, 4.5vw, 4.5rem);

        --article-col: 52rem;
    }

    .article-hero {
        max-width: var(--article-col);
        margin-inline: auto;
        margin-bottom: clamp(2rem, 4vw, 3rem);
        display: grid;
        justify-items: center;
        gap: clamp(1.2rem, 2.8vw, 2.2rem);
        text-align: center;
        position: relative;
        isolation: isolate;

        & > * {
            position: relative;
            z-index: 2;
        }

        & .page-title {
            max-width: 16ch;
        }
    }

    .article-visual {
        width: clamp(4rem, 7vw, 6.5rem);
        opacity: 0.9;
        pointer-events: none;

        & .hero-smn {
            --hero-smn-width: 100%;
            margin-inline: auto;
        }

        & .hero-smn-svg {
            & .main {
                stroke-width: 1.56;
            }

            & .main.thick {
                stroke-width: 1.9;
            }

            & .accent {
                stroke-width: 1.56;
            }

            & .muted {
                stroke-width: 1.12;
            }
        }
    }

    .article-shell {
        max-width: var(--layout-content);
        margin: 0 auto;
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
    }

    .article-main {
        width: 100%;
        max-width: none;
        margin: 0;
        min-width: 0;
    }

    .article-content {
        --fs: var(--text-md);
        --lh: 1.72;
        --line: calc(var(--fs) * var(--lh));
        /* One column, not two. The grid used to reserve 52rem for the content
           track while the prose was capped at the measure inside it, flush left,
           so the article sat left of the page with dead space beside it. The
           track is the measure; anything wider breaks out. */
        --col: calc(36 * var(--fs));
        --bleed: clamp(0rem, 4vw, 5rem);

        --text-body: color-mix(in oklch, var(--text-ink) 82%, var(--text-muted-2));
        display: grid;
        grid-template-columns:
            [full-start] minmax(0, 1fr)
            [wide-start] minmax(0, var(--bleed))
            [content-start] minmax(0, var(--col)) [content-end]
            minmax(0, var(--bleed)) [wide-end]
            minmax(0, 1fr) [full-end];
        padding-top: 1rem;
        font-size: var(--fs);
        line-height: var(--lh);
        color: var(--text-body);

        & > * {
            grid-column: content;
        }

        & :is(h2, h3) {
            position: relative;
        }
    }

    @scope (.article-content) to (.lab-embed) {
        /* Code, pictures and tables are read across, not down a measure. */
        :scope :is(img, table, pre) {
            grid-column: wide;
        }

        :scope > h1:first-child {
            display: none;
        }

        :scope > * + * {
            margin-top: var(--line);
        }

        :scope p + :is(ul, ol) {
            margin-top: 0;
        }

        :scope h2 {
            font-size: var(--text-2xl);
            line-height: calc(var(--line) * 2);
            letter-spacing: -0.02em;
            margin-top: calc(var(--line) * 4);
            margin-bottom: var(--line);
            scroll-margin-top: 7rem;
            text-wrap: balance;
            color: var(--text-ink);
        }

        :scope > h2:first-child {
            margin-top: calc(var(--line) * 2);
        }

        :scope h3 {
            font-size: var(--text-xl);
            line-height: var(--line);
            font-weight: 300;
            letter-spacing: -0.01em;
            margin-top: calc(var(--line) * 2);
            margin-bottom: var(--line);
            scroll-margin-top: 7rem;
            text-wrap: balance;
            color: var(--text-ink);
        }

        :scope p {
            font-size: var(--fs);
            line-height: var(--lh);
        }

        /* Prose links only. The anchor beside a heading is a control, not a
           reference, and it draws itself. */
        :scope a:not(.heading-permalink) {
            color: var(--accent-purple);
            text-decoration: none;
            border-bottom: 1px solid color-mix(in oklch, var(--accent-purple) 35%, transparent);
            transition: border-color 0.2s ease;
        }

        :scope a:not(.heading-permalink):hover {
            border-color: var(--accent-purple);
        }

        :scope :is(ul, ol) {
            padding-left: 1.4rem;
            font-size: var(--fs);
            line-height: var(--lh);
        }

        :scope li {
            margin-top: 0;
        }

        :scope :is(ul, ol) :is(ul, ol) {
            padding-left: 1.4rem;
            margin-top: 0.25rem;
            font-size: 1em;
        }

        :scope code {
            font-family: var(--font-mono);
            font-size: 0.84em;
            background: color-mix(in oklch, var(--text-ink) 10%, transparent);
            padding: 0.12em 0.36em;
            border-radius: 0.25rem;
        }

        :scope pre {
            background: color-mix(in oklch, var(--bg-elevated) 75%, transparent);
            border: 1px solid color-mix(in oklch, var(--border-dim) 45%, transparent);
            border-radius: var(--radius-sm);
            padding: 1.45rem;
            overflow-x: auto;
            margin-top: calc(var(--line) * 2);
            margin-bottom: calc(var(--line) * 2);
        }

        :scope pre code {
            background: none;
            padding: 0;
            border: none;
            font-size: var(--text-sm);
            line-height: 1.55;
        }

        :scope blockquote {
            border-left: 2px solid var(--accent-purple);
            padding-left: 1.2rem;
            margin: calc(var(--line) * 2) 0;
            font-size: var(--text-lg);
            line-height: var(--line);
            color: var(--text-muted);
            font-style: italic;
        }

        :scope img {
            width: 100%;
            max-width: none;
            height: auto;
            border-radius: var(--radius-sm);
            margin-top: calc(var(--line) * 2);
            margin-bottom: calc(var(--line) * 2);
        }

        :scope hr {
            border: none;
            border-top: 1px solid color-mix(in oklch, var(--border-dim) 50%, transparent);
            margin: 2.5rem 0;
        }

        :scope strong {
            font-weight: 500;
            color: var(--text-ink);
        }

        :scope em {
            font-style: italic;
        }

        :scope table {
            width: 100%;
            border-collapse: collapse;
            font-size: var(--text-sm);
            margin-block: calc(var(--line) * 3.25);
            overflow-x: auto;
            display: block;
        }

        :scope :is(th, td) {
            padding: 0.7rem 1.6rem 0.7rem 0;
            text-align: left;
            vertical-align: baseline;
            border-bottom: 1px solid color-mix(in oklch, var(--border-dim) 22%, transparent);
        }

        :scope th {
            font-weight: 500;
            color: var(--text-ink);
            border-bottom-color: color-mix(in oklch, var(--border-dim) 55%, transparent);
        }

        :scope :is(th, td) code {
            white-space: nowrap;
        }
    }

    @media (width >= 1440px) {
        .article-shell {
            grid-template-columns: 1fr;
            max-width: 62rem;
            margin-inline: auto;
        }

        .article-main {
            max-width: 62rem;
            margin: 0 auto;
        }
    }

    .article-close {
        max-width: var(--article-col);
        margin: clamp(2.5rem, 6vw, 4rem) auto 0;
        color: var(--text-muted);
        font-size: var(--text-base);
        font-style: italic;
        text-align: center;
    }

    .article-date {
        color: var(--text-muted-2);
        font-size: var(--text-xs);
        font-stretch: semi-condensed;
        letter-spacing: 0.12em;
        text-transform: uppercase;
    }

    .article-meta-rail {
        max-width: var(--article-col);
        margin: clamp(3.5rem, 8vw, 6.5rem) auto 0;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: clamp(2rem, 6vw, 4rem);
    }

    .meta-rail-item {
        padding-block: 1.2rem 1.1rem;
        display: grid;
        gap: 0.2rem;
        justify-items: center;
        text-align: center;
    }

    .meta-rail-label {
        font-size: var(--text-2xs);
        letter-spacing: 0.15em;
        text-transform: uppercase;
        color: var(--text-muted-2);
    }

    .meta-rail-value {
        font-size: var(--text-sm);
        line-height: 1.45;
        color: var(--text-muted);
    }

    .related-section {
        max-width: min(100%, var(--article-col));
        margin: clamp(6rem, 10vw, 10rem) auto 0;
        padding-top: 2.6rem;
        border-top: 1px solid color-mix(in oklch, var(--border-dim) 35%, transparent);
    }

    .related-title {
        text-align: left;
        margin-bottom: clamp(1.6rem, 3vw, 2.4rem);
    }

    .related-list {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
    }

    .related-item {
        position: relative;
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: clamp(1rem, 2.4vw, 2rem);
        padding: clamp(1.4rem, 2.4vw, 2rem) 0;
        border-top: 1px solid color-mix(in oklch, var(--border-dim) 30%, transparent);
        text-decoration: none;
        transition: padding-left 240ms ease, border-color 240ms ease;

        &:first-child {
            border-top: none;
        }

        &:hover {
            padding-left: 0.5rem;
            border-color: color-mix(in oklch, var(--border-dim) 70%, transparent);
        }

        &:hover + .related-item {
            border-color: color-mix(in oklch, var(--border-dim) 70%, transparent);
        }

        & h3 a {
            color: inherit;
            text-decoration: none;
            border: none;
        }

        &:hover .related-icon {
            opacity: 0.95;
            color: var(--text-ink);
            transform: translateY(-1px);
        }

        & h3 {
            font-size: var(--text-lg);
            font-weight: 400;
            letter-spacing: -0.005em;
            line-height: 1.3;
            color: var(--text-ink);
            text-wrap: balance;
        }
    }

    .related-icon {
        width: 1.55rem;
        height: 1.55rem;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: var(--text-muted-2);
        opacity: 0.55;
        transition: opacity 0.3s ease, color 0.3s ease, transform 0.3s ease;

        & svg {
            width: 100%;
            height: 100%;
        }
    }

    .related-item-date {
        font-size: var(--text-xs);
        color: var(--text-muted-2);
        white-space: nowrap;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        font-variant-numeric: tabular-nums;
        opacity: 0.7;
    }

    @media (width <= 768px) {
        .related-section {
            margin-top: clamp(9rem, 22vw, 12rem);
        }

        .related-title {
            margin-bottom: 1.8rem;
        }

        .related-item {
            grid-template-columns: auto 1fr;
            row-gap: 0.45rem;
        }

        .related-item-date {
            grid-column: 2;
            font-size: var(--text-2xs);
        }

        .related-item h3 {
            font-size: var(--text-lg);
        }
    }
}

@layer pages {
    .article-content kbd {
        padding: 0.18em 0.45em;
        border: 1px solid color-mix(in oklch, var(--border-dim) 85%, transparent);
        border-radius: 0.35em;
        background: color-mix(in oklch, var(--bg-elevated) 55%, transparent);
        box-shadow: 0 1.5px 0 color-mix(in oklch, var(--border-dim) 60%, transparent);
        color: var(--text-ink);
        font-family: var(--font-mono);
        font-size: 0.82em;
        line-height: 1;
        white-space: nowrap;
    }

    /* A link inside running prose is told apart by its underline, not by a
       shade of ink: colour alone is not a distinction every reader can make. */
    .article-content :is(p, li) a {
        color: var(--text-ink);
        text-decoration: underline;
        text-decoration-color: color-mix(in oklch, var(--text-ink) 40%, transparent);
        text-decoration-thickness: 1px;
        text-underline-offset: 0.2em;
        background-image: var(--grad-accent);
        background-repeat: no-repeat;
        background-position: 0 100%;
        background-size: 0 1px;
        transition: background-size 300ms var(--ease-elastic), text-decoration-color 250ms ease;

        &:hover {
            background-size: 100% 1px;
            text-decoration-color: transparent;
        }
    }

    .article-content abbr[title] {
        text-decoration: underline dotted color-mix(in oklch, var(--text-muted) 65%, transparent);
        text-decoration-thickness: 1px;
        text-underline-offset: 0.22em;
        cursor: help;
    }
}
