/*
 * Reset
 */
* {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    font-size: inherit;
}

/*
 * Variables
 */
:root {
    --header-footer-min-height: 3.5rem;
    --body-padding: 1rem;
    --article-max-width: 8.5in;
    --indent-size: min(0.5in, 6vw);
    --margin-size: min(1in, 9vw);
    --min-font-size: 14px;
}

/*
 * Font imports
 */


/*
 * Print-only styles
 */
@media print {
    html {
        font-size: 10pt;
    }

    header, footer {
        /* Hide the header and footer nav links */
        display: none;
    }

    a, a:visited {
        /* Remove link styling from printed document */
        color: inherit;
        text-decoration: none;
    }
}

/*
 * Styles for both print and screen
 */
@media screen, print {
    html {
        font-family: 'Iowan Old Style', 'URW Palladio L', 'Palatino Linotype', P052, serif;
        line-height: 1.3;
    }

    article {
        /*
         * Ensure the article stretches vertically to contain floated elements.
         */
        display: flow-root;
        hyphens: auto;
        text-align: justify;
    }
    
    /* Add vertical margin between block elements */
    article p,
    article table,
    /* Top-level lists have block margin, but nested lists do not */
    article > :is(ul, ol) {
        margin-block: 1rem;
    }

    /* indent lists */
    article :is(ul, ol) {
        margin-inline-start: var(--indent-size);
    }

    article pre {
        /* Allow long lines in <pre> tags to wrap */
        white-space: pre-wrap;
    }

    article :is(pre, code) {
        margin-block: 1rem;
        font-family: 'DejaVu Sans Mono', Menlo, 'Fira Code', monospace;
        font-size: 0.85em;
        hyphens: none;
        text-align: left;
    }

    pre:has(> code) {
        --border-thickness: 1px;
        --padding: 0.5em;
        border: 1px solid #ddd;
        border-radius: 0.25em;
        background: #f6f6f6;
        padding: 0.5em;
    }

    pre:has(> code):not(:is([float-left], [float-right]) *) {
        margin-inline: calc(-1 * (var(--border-thickness) + var(--padding)));
    }

    article blockquote {
        /* Indent block quotes */
        margin-inline: var(--indent-size);
    }
    
    article p:has(cite) {
        /* Indent the citations of block quotes */
        margin-inline: calc(2 * var(--indent-size));
    }

    article img {
        display: block;
        margin: 1em auto;
        max-width: 100%;
        page-break-inside: avoid;
    }

    article figure, article figure > * {
        /* center figures that are narrower than the text block */
        margin-inline: auto;
    }

    article figcaption {
        margin-block: 1em;
        font-size: 0.875em;
        text-align: center;
    }

    /*
     * Headings
     *
     * We combine margin and padding the way we do in headings (1em of each
     * at block-start) to ensure headings stay at least 1em away from floated
     * elements.
     */

    article :is(h1, h2, h3, h4, h5, h6, hgroup) {
        /* Don't justify headings */
        text-align: left;
    }

    article h1:not(hgroup > *),
    article hgroup:has(> h1) {
        margin-block: 1em;
        border-block-end: 1px solid #000;
        padding-block: 1em 0.25em;
        font-size: 2rem;
        page-break-after: avoid;
        clear: both;
    }

    article h2:not(hgroup > *),
    article hgroup:has(> h2) {
        margin-block: 1em;
        border-block-end: 1px solid #000;
        padding-block: 1em 0.25em;
        font-size: 1.5rem;
        page-break-after: avoid;
        clear: both;
    }

    article h3:not(hgroup > *),
    article hgroup:has(> h3) {
        margin-block: 1em;
        padding-block: 1em 0.25em;
        font-size: 1.25rem;
        page-break-after: avoid;
        clear: both;
    }

    article h4:not(hgroup > *),
    article hgroup:has(> h4) {
        margin-block: 1em;
        padding-block: 1em 0.25em;
        font-size: 1.1rem;
        page-break-after: avoid;
        clear: both;
    }

    article h5:not(hgroup > *),
    article hgroup:has(> h5) {
        margin-block: 1em;
        padding-block: 1em 0.25em;
        font-size: 1rem;
        page-break-after: avoid;
        clear: both;
    }

    article h6:not(hgroup > *),
    article hgroup:has(> h6) {
        margin-block: 1em;
        padding-block: 1em 0.25em;
        font-size: 0.9rem;
        page-break-after: avoid;
        clear: both;
    }


    hgroup > p {
        margin-block: 0.5em;
        font-style: italic;
        font-size: max(0.625em, var(--min-font-size));
    }

    article > hr {
        border: none;
    }

    article > hr::after {
        display: block;
        margin-block: 2em;
        content: '✥ ✥ ✥';
        text-align: center;
        color: #000;
    }

    article > :first-child {
        margin-block-start: 0;
    }

    article table {
        text-align: left;
        font-size: 0.9375em;
        border-collapse: collapse;
    }

    article :is(td, th) {
        padding-inline: 0.5em;
        padding-block: 0.25em;
    }

    article th {
        background: #eee;
    }

    article tr:not(:last-child) {
        border-block-end: 1px solid #bbb;
    }

    /*
     * Syntax highlighting
     */
    
    .hljs-keyword,
    .hljs-name,
    .hljs-meta {
        font-weight: bold;
        color: #118;
    }
    
    .hljs-string,
    .hljs-regexp {
        font-weight: bold;
        color: #484;
    }
    
    .hljs-number,
    .hljs-attribute,
    .hljs-symbol {
        color: #118;
    }

    .hljs-attr,
    .hljs-selector-class {
        color: #826;
    }

    .hljs-title.class_ {
        font-weight: bold;
        color: #605;
    }
}

/*
 * Screen-only styles
 */
@media screen {
    html {
        overflow-y: scroll;
    }
    
    body {
        background: #bbb;
        padding: var(--body-padding);
        min-height: 100vh;
    }

    header, footer {
        margin-inline: auto;
        max-width: var(--article-max-width);
        min-height: var(--header-footer-min-height);
        padding-block: 1rem;
        padding-inline: var(--margin-size);
        font-family: Verdana, Geneva, Tahoma, sans-serif;
        font-size: 0.875rem;
    }

    :is(header, footer) nav :is(a, a:visited) {
        display: inline-block;
        color: #800;
        /* text-shadow: 0 1px #fff; */
        text-decoration: none;
        padding-inline-end: 0.5em;
    }

    :is(header, footer) nav a::before {
        content: "➤";
        display: inline-block;
        padding-inline-end: 0.5em;
    }

    article {
        margin-inline: auto;
        min-height: calc(
            100vh
            - var(--header-footer-min-height)
            - 2 * var(--body-padding)
        );
        border: 1px solid #999;
        box-shadow: 0 2px 6px #0004;
        background: #fff;
        padding-inline: var(--margin-size);
        padding-block: 0.75in;
        max-width: var(--article-max-width);
    }
}

/*
 * Styles for narrow screens
 */

@media screen and (max-width: 600px) {
    :root {
        --body-padding: 0;
    }

    article {
        border-inline: none;
    }
}

/*
 * Styles for wide screens and print
 */

@media (min-width: 601px) {
    [float-right] {
        float: right;
        margin-left: 1em;
    }

    [float-left] {
        float: left;
        margin-right: 1em;
    }

    [float-right], [float-left] {
        max-width: 50%;
    }

    article figcaption:not([float-right] *, [float-left] *) {
        margin-inline: calc(1.5 * var(--indent-size));
    }
}
