/* Property order: custom props → display/flex → z-index, position → sizing → spacing → typography → colors/borders → rest */

body {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    align-items: center;
}

/* ======== */
/*  Layout  */
/* ======== */
/* Text keeps to a centre column one measure wide. The cover spans the
   content width; the contents sit in the left margin. */
.article {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, var(--measure)) minmax(0, 1fr);
    grid-template-areas:
        ".      header ."
        "media  media  media"
        "aside  page   .";
    padding-inline: var(--gutter);
}

.article-header {
    grid-area: header;
    padding-top: var(--section-pad);

    > .title {
        text-wrap: balance;
    }

    > .subtitle {
        margin: var(--space-s) 0 0;
        font-size: var(--fs-lead);
        line-height: var(--lh-body);
        text-wrap: pretty;
        color: var(--clr-text-variant);
    }

    > .meta {
        margin: var(--space-s) 0 0;
        font-size: var(--fs-meta);
        color: var(--clr-text-muted);
    }

    > .meta > .author::before {
        margin-inline: 0.5em;
        content: "|";
    }
}

.article-media {
    grid-area: media;
    margin-top: var(--space);

    > .frame {
        overflow: hidden;
        aspect-ratio: 2;
        background: var(--clr-surface);
        border-radius: var(--radius);
    }
}

.article-aside {
    grid-area: aside;
    justify-self: end;
    width: 100%;
    max-width: 14rem;
    padding: var(--space) var(--space) 0 0;

    @media (width <= 1280px) {
        display: none;
    }
}

/* Sticks below the fixed nav. */
.article-toc {
    position: sticky;
    top: calc(var(--nav-height) + var(--space));
    font-size: var(--fs-meta);
    line-height: var(--lh-body);

    > ol {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    > ol > li {
        margin: var(--space-2xs) 0;
    }

    > ol > li > a {
        text-decoration: none;
        color: var(--clr-text-muted);

        &:hover {
            color: var(--clr-text);
        }
    }
}

/* ============= */
/*  CMS content  */
/* ============= */

.article-page {
    grid-area: page;
    padding-block: var(--space) var(--section-pad);
    line-height: var(--lh-body);
    overflow-wrap: break-word;

    > * {
        margin: 0;
    }

    > * + * {
        margin-top: var(--space-l);
    }

    > * + :is(h1, h2, h3, h4, h5, h6) {
        margin-top: 1.5em;
    }

    :is(h1, h2, h3, h4, h5, h6) {
        font-family: var(--font-head);
        line-height: var(--lh-head);
        text-wrap: balance;
        scroll-margin-top: calc(var(--nav-height) + var(--space));
    }

    h1 { font-size: var(--fs-h2); }
    h4 { font-size: var(--fs-lead); }
    :is(h5, h6) { font-size: var(--fs-body); }
    h6 { color: var(--clr-text-muted); }

    p {
        text-wrap: pretty;
    }

    a {
        text-decoration-thickness: var(--border-width);
        text-underline-offset: 0.15em;
        transition: var(--transition);
        transition-property: color, text-decoration-color;

        &:hover {
            text-decoration-color: var(--clr-sec-d);
            color: var(--clr-sec-d);
        }
    }

    :is(strong, b) {
        font-weight: 600;
    }

    :is(code, pre) {
        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    }

    /* Inline, so it is sized against the text around it, at the meta-to-body ratio. */
    code {
        padding: 0 0.25em;
        font-size: 0.875em;
        background: var(--clr-surface);
        border-radius: var(--radius-s);
    }

    pre {
        overflow-x: auto;
        padding: var(--space-s);
        font-size: var(--fs-meta);
        color-scheme: dark;
        color: var(--clr-prm-l);
        background: var(--clr-prm-d);
        border-radius: var(--radius);

        code {
            padding: 0;
            font-size: inherit;
            background: none;
        }
    }

    blockquote {
        padding-left: var(--space-s);
        font-size: var(--fs-lead);
        border-left: var(--border-width) solid var(--clr-accent);
    }

    :is(ul, ol) {
        padding-left: var(--space-l);
    }

    li {
        margin-top: var(--space-2xs);

        > p {
            margin: 0;
        }
    }

    hr {
        border: none;
        border-top: 1px solid var(--hairline);
    }

    mark {
        padding: 0 0.25em;
        color: inherit;
        background: color-mix(in oklab, var(--clr-accent) 45%, transparent);
        border-radius: var(--radius-s);
    }

    img {
        display: block;
        max-width: 100%;
        height: auto;
        border-radius: var(--radius);
    }

    /* Open, like the zone list on the homepage: hairlines instead of boxes. */
    table {
        width: 100%;
        font-size: var(--fs-meta);
        border-collapse: collapse;
    }

    /* Wide enough for a ten-letter word before a column wraps. */
    :is(td, th) {
        min-width: 10ch;
        padding-block: var(--space-2xs);
        padding-right: var(--space-xs);
        text-align: left;
        border-bottom: 1px solid var(--hairline);

        > p {
            margin: 0;
        }
    }

    th {
        font-weight: 500;
    }

    details {
        border-block: 1px solid var(--hairline);

        summary {
            padding-block: var(--space-xs);
            cursor: pointer;
        }
    }
}
