/*
 * moonlab.org
 *
 * Technical documents.
 *
 * Black/White
 * Generic Font Families
 * No JavaScript
 *
*/

:root {
    color-scheme: light;

    --bg: #FFFFFF;
    --fg: #000000;

    --muted: #555555;

    --rule: #CCCCCC;
    --rule-strong: #000000;

    --code-bg: #F3F3F3;
}

/* base */
* {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;

    /* Reserve the scrollbar's width whether or not the page needs one. The
     * header and every other centred block are laid out against the viewport,
     * so without this a short page and a long one centre a few pixels apart
     * and the identity shifts as you navigate. */
    scrollbar-gutter: stable;
}

body {
    /* A column so that a short page can push its footer to the bottom of the
     * viewport rather than leaving it halfway up. dvh after vh so that a
     * browser understanding both takes the one that accounts for a retracting
     * address bar. */
    display: flex;
    flex-direction: column;

    min-height: 100vh;
    min-height: 100dvh;

    margin: 0;
    padding: 0;

    background: var(--bg);
    color: var(--fg);

    font-family: serif;
    font-size: 1.5rem;
    line-height: 1.5;
}

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

/* accessibility */
.skip-link {
    position: absolute;
    left: -10000px;
    top: auto;

    width: 1px;
    height: 1px;

    overflow: hidden;
}

.skip-link:focus {
    z-index: 1000;

    left: 1rem;
    top: 1rem;

    width: auto;
    height: auto;

    padding: 0.4rem 0.6rem;

}

/* links */
a,
a:visited {
    color: #0000FF;
    text-decoration: underline;
    text-underline-offset: 0.16em;
}

/* system bar */
.site-header {
    width: 100%;

    margin: 0;
    padding: 0;

    border-bottom: 0;

    background-image: url("/assets/zigzag-rule.gif");
    background-repeat: repeat-x;
    background-position: left bottom;

    font-family: monospace;
}

.site-header-inner {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem 4rem;
    align-items: center;

    max-width: 80rem;
    margin: 0 auto;
    padding: 1.15rem 2rem;
}

.site-header a,
.site-header a:visited,
.site-header a:hover,
.site-header a:active {
    color: #000000;
}

/* ASCII header */
.site-title {
    display: block;

    font-family: monospace;
    text-decoration: none;
}

.site-logo {
    margin: 0;
    padding: 0;

    background: transparent;
    color: inherit;

    border: 0;

    font-family: monospace;

    font-size: 0.9rem;
    line-height: 1.02;

    white-space: pre;
    overflow: visible;
}

.site-title-text {
    position: absolute;

    width: 1px;
    height: 1px;

    margin: -1px;
    padding: 0;

    overflow: hidden;

    clip: rect(0 0 0 0);
    clip-path: inset(50%);

    white-space: nowrap;

    border: 0;
}


.site-nav {
    justify-self: end;

    font-size: 0.875rem;
    line-height: 1.4;
}

.site-nav ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.3rem 1.2rem;

    margin: 0;
    padding: 0;

    list-style: none;
}

/* common page shell */
.site-main {
    max-width: 80rem;

    margin: 0 auto;
    padding: 3rem 2rem 6rem;
}


/* homepage intro */
.intro {
    max-width: 62ch;

    margin-bottom: 3.5rem;
}

.intro p {
    margin: 0;

    font-size: 1.5rem;
    line-height: 1.45;
}

/* section labels */

/* A heading rules itself off at the bottom and the first row of a list rules
 * itself off at the top, so a heading sitting directly on a list draws both
 * and reads as a double line. Where prose comes between them, as on the
 * archive, the two are far enough apart to read as one each. */
.section-heading + .featured-posts .featured-post:first-child,
.section-heading + .archive-list .archive-row:first-child {
    border-top: 0;
}

.section-heading {
    margin: 0 0 0.8rem;
    padding-bottom: 0.4rem;

    border-bottom: 1px solid var(--rule);

    font-size: 0.925rem;
    font-weight: normal;
    line-height: 1.4;

    letter-spacing: 0.04em;
    text-transform: uppercase;
}


/* homepage: recent articles */
.featured-posts {
    margin: 0;
    padding: 0;

    list-style: none;
}

.featured-post {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    gap: 0 1.75rem;

    padding: 1.55rem 0;

    border-bottom: 1px solid var(--rule);
}

.featured-post:first-child {
    border-top: 1px solid var(--rule);
}

.post-date {
    padding-top: 0.25rem;

    color: var(--muted);

    font-size: 0.95rem;
    line-height: 1.4;

    white-space: nowrap;
}

.post-body {
    min-width: 0;
}

.post-title {
    max-width: 42ch;

    margin: 0;

    font-size: 1.4rem;
    font-weight: bold;
    line-height: 1.3;
}

/* Titles in a listing read as headings that happen to be clickable, so they
 * take the text colour and drop the underline. Bold italic is what marks
 * them as titles instead. Every other link on the page stays blue. */
.post-title a,
.post-title a:visited,
.archive-title a,
.archive-title a:visited {
    color: var(--fg);

    font-weight: bold;
    font-style: italic;

    text-decoration: none;
}

/* The underline comes back on hover, since colour and underline are both
 * gone at rest and something has to say these are links. */
.post-title a:hover,
.archive-title a:hover {
    text-decoration: underline;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.65rem;

    margin-top: 0.5rem;

    color: var(--muted);

    font-size: 0.95rem;
    line-height: 1.4;
}

.post-meta a,
.post-meta a:visited {
    color: inherit;
}

.post-meta span + span::before {
    content: "·";

    margin-right: 0.65rem;

    color: var(--rule-strong);
}


.post-summary {
    max-width: 68ch;

    margin: 0.75rem 0 0;

    font-size: 1.25rem;
    line-height: 1.5;
}

.post-summary p {
    margin: 0;
}

.post-summary p + p {
    margin-top: 0.6rem;
}

.continue-reading {
    margin: 0.8rem 0 0;

    font-size: 0.975rem;
}


/* archive rows */
.earlier {
    margin-top: 3.5rem;
}

.archive-list {
    margin: 0;
    padding: 0;

    list-style: none;
}

.archive-row {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr) auto;
    gap: 0.5rem 1.75rem;
    align-items: baseline;

    padding: 0.62rem 0;

    border-bottom: 1px solid var(--rule);

    font-size: 1.05rem;
}

.archive-row:first-child {
    border-top: 1px solid var(--rule);
}

.archive-date,
.archive-author {
    color: var(--muted);

    font-size: 0.95rem;
    line-height: 1.4;

    white-space: nowrap;
}

.archive-title {
    min-width: 0;
}

.archive-more {
    margin: 1rem 0 0;

    font-size: 0.975rem;
}


/* article shell */
.document-shell {
    max-width: 90rem;

    margin: 0 auto;
    padding: 4rem 2rem 7rem;
}

.article {
    max-width: 80ch;

    margin: 0 auto;
}


/* article heading */
.article-header {
    margin-bottom: 3.75rem;

    text-align: left;
}

.article-title {
    max-width: 34ch;

    margin: 0 0 1rem;

    font-size: 2.6rem;
    font-weight: normal;
    line-height: 1.15;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.65rem;

    margin: 0;

    color: var(--muted);

    font-size: 0.95rem;
    line-height: 1.4;
}

.article-meta a,
.article-meta a:visited {
    color: inherit;
}

.article-meta span + span::before {
    content: "·";

    margin-right: 0.65rem;

    color: var(--rule-strong);
}



.article-deck {
    max-width: 68ch;

    margin: 1.8rem 0 0;

    font-size: 1.3rem;
    line-height: 1.5;
}


/* article body */
.article-body {
    max-width: 80ch;
}

.article-body h2 {
    margin: 3.2rem 0 0.95rem;

    font-size: 1.45rem;
    font-weight: bold;
    line-height: 1.3;
}

.article-body h3 {
    margin: 2.4rem 0 0.8rem;

    font-size: 1.1rem;
    font-weight: bold;
    line-height: 1.35;
}

.article-body h4 {
    margin: 2rem 0 0.7rem;

    font-size: 1rem;
    font-style: italic;
    font-weight: normal;
}

.article-body p {
    margin: 0 0 1.05rem;
}


/* lists */

.article-body ul,
.article-body ol {
    margin: 1rem 0 1.5rem;
    padding-left: 2rem;
}

.article-body li {
    margin: 0.35rem 0;
}

.article-body li > ul,
.article-body li > ol {
    margin-top: 0.3rem;
    margin-bottom: 0.4rem;
}

.article-body dl {
    margin: 1.25rem 0 1.5rem;
}

.article-body dt {
    margin-top: 0.8rem;

    font-weight: bold;
}

.article-body dd {
    margin: 0.15rem 0 0.65rem 1.75rem;
}


/* quotations */

blockquote {
    margin: 1.8rem 2.5rem;
    padding-left: 1rem;

    border-left: 1px solid var(--rule-strong);
}

blockquote p {
    font-size: 1.05rem;
}


/* admonitions */
.admonition {
    margin: 1.8rem 0;
    padding: 0.9rem 1.1rem;

    border: 1px solid var(--rule);
    border-left: 2px solid var(--fg);
}

.admonition-label {
    margin: 0 0 0.4rem;

    font-family: monospace;
    font-size: 0.85rem;
    font-weight: bold;

    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.admonition p:last-child {
    margin-bottom: 0;
}


/* math */
.stem {
    font-family: monospace;
}

div.stem {
    overflow-x: auto;

    margin: 1.8rem 0;

    text-align: center;
}


/* source code */

code,
pre {
    font-family: monospace;
}

code {
    font-size: 0.9em;
}

.article-body pre {
    overflow-x: auto;

    width: min(96ch, calc(100vw - 2rem));

    margin: 2rem 50%;
    padding: 1rem 1.1rem;

    transform: translateX(-50%);

    background: var(--code-bg);
    color: var(--fg);

    border: 0;
    border-left: 2px solid var(--fg);

    font-size: 0.9rem;
    line-height: 1.5;

    tab-size: 4;
}

.article-body pre code {
    font-size: inherit;
}


/* figures */
figure {
    width: min(100ch, calc(100vw - 2rem));

    margin: 2.5rem 50%;

    transform: translateX(-50%);
}

figure img,
figure svg {
    display: block;

    max-width: 100%;
    height: auto;

    margin: 0 auto;
}

figcaption {
    max-width: 80ch;

    margin: 0.7rem auto 0;

    color: var(--muted);

    font-size: 0.9rem;
    line-height: 1.45;
}


/* article end */

.article-end {
    margin-top: 4rem;

    text-align: center;
}

.article-end::before {
    content: "∎";

    font-size: 0.85rem;
}


/* site footer */
.site-footer {
    width: 100%;

    /* Absorbs whatever height the page did not need, which is what pins the
     * footer to the bottom on a short page and does nothing on a long one.
     * On the footer rather than on the main elements, so it holds whichever
     * layout is above it without naming them. */
    margin: auto 0 0;
    padding: 0;

    /* The header's rule, the other way up. */
    background-image: url("/assets/zigzag-rule.gif");
    background-repeat: repeat-x;
    background-position: left top;

    font-family: monospace;
}

.site-footer-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.65rem;

    max-width: 80rem;
    margin: 0 auto;
    padding: 2.25rem 2rem 3rem;

    color: var(--muted);

    font-size: 0.875rem;
    line-height: 1.4;
}

.site-footer-inner span + span::before {
    content: "·";

    margin-right: 0.65rem;

    color: var(--rule-strong);
}

.site-footer a,
.site-footer a:visited {
    color: inherit;
}


/* selection */
::selection {
    background: var(--fg);
    color: var(--bg);
}


/* narrow displays */
@media (max-width: 42rem) {
    .site-header-inner {
        grid-template-columns: 1fr;
        gap: 0.55rem;

        padding: 0.8rem 1rem;
    }

    .site-logo {
        display: none;
    }

    .site-title-text {
        position: static;

        width: auto;
        height: auto;

        margin: 0;

        overflow: visible;

        clip: auto;
        clip-path: none;

        white-space: normal;

        font-size: 1rem;
        font-weight: bold;
        line-height: 1.25;
    }

    .site-nav {
        justify-self: start;
    }

    .site-nav ul {
        justify-content: flex-start;
        gap: 0.25rem 0.85rem;
    }

    .site-main,
    .document-shell {
        padding: 2.5rem 1rem 4rem;
    }

    .intro {
        margin-bottom: 2.75rem;
    }

    .featured-post {
        grid-template-columns: 1fr;
        gap: 0.25rem;

        padding: 1.35rem 0;
    }

    .post-date {
        padding-top: 0;
    }

    .archive-row {
        grid-template-columns: 1fr;
        gap: 0.12rem;

        padding: 0.75rem 0;
    }

    .archive-title {
        order: 1;
    }

    .archive-date {
        order: 2;
    }

    .archive-author {
        order: 3;
    }

    .article-title {
        font-size: 2rem;
    }

    .article-header {
        margin-bottom: 3rem;
    }

    blockquote {
        margin-left: 0.75rem;
        margin-right: 0;
    }

    .article-body pre,
    figure {
        width: 100%;

        margin-left: 0;
        margin-right: 0;

        transform: none;
    }

    .site-footer-inner {
        padding: 1.75rem 1rem 2.5rem;
    }
}


/* print */
@media print {

    :root {
        --bg: #ffffff;
        --fg: #000000;

        --muted: #444444;

        --rule: #aaaaaa;
        --rule-strong: #000000;

        --code-bg: #ffffff;
    }

    @page {
        margin: 0.75in;
    }

    body {
        background: #ffffff;
        color: #000000;

        font-size: 11pt;
        line-height: 1.4;
    }

    .site-header,
    .site-footer,
    .skip-link {
        display: none;
    }

    .site-main,
    .document-shell {
        max-width: none;

        margin: 0;
        padding: 0;
    }

    .article,
    .article-body {
        max-width: none;
    }

    a,
    a:visited {
        color: inherit;

        text-decoration: none;
    }

    .article-body pre,
    figure {
        width: 100%;

        margin-left: 0;
        margin-right: 0;

        transform: none;
    }

    .article-body pre {
        white-space: pre-wrap;

        border-left: 1pt solid #000000;
    }

    h2,
    h3,
    figure,
    pre {
        break-inside: avoid;
    }
}
