/* FOUC suppression */
#loading-animation { display: none; }
/* must match the inline <style> from <head> */
:where(body>:not(#loading-animation, script)) {
    display: unset;
}

:root {
    --color-primary: #1a365d;
    --color-accent: #2b6cb0;
    --color-bg: #ffffff;
    --color-bg-alt: #f7fafc;
    --color-border: #e2e8f0;
    --color-text: #2d3748;
    --color-text-light: #718096;
    --color-sidebar-bg: #ebf8ff;
    --color-sidebar-border: #90cdf4;
    --color-example-bg: #f0fff4;
    --color-example-border: #9ae6b4;
    --color-warning-bg: #fffbeb;
    --color-warning-border: #fbd38d;
    --color-target: #FBF7FF;
    --color-deemphasized: #999;
    --color-button-bg: hsl(210 70% 91%);
    --color-search-match: #cc06;

    --standard-shadow: 0 8px 24px rgba(26, 54, 93, 0.15);

    --font-body: 'Georgia', 'Times New Roman', serif;

    --target-max-content-width: 1440px;
    --site-header-height: 4rem;

    --toc-radius: 8px;
}

.search-match-highlight, .search-match-highlight:target {
    background-color: var(--color-search-match);
    box-shadow: 0 0 2px 3px var(--color-search-match);
}

.search-match-highlight.search-match-current {
/*    box-shadow: inset 0 -2px 0 var(--color-primary), inset 0 0 0 1px var(--color-primary);*/
/*    outline: solid 1px var(--color-accent);*/
    box-shadow: 0 0 2px 3px var(--color-accent);
}

#search-match-navigation {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 10;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    color: var(--color-text);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--toc-radius);
    box-shadow: var(--standard-shadow);
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

#search-match-navigation button {
    padding: 0.25rem 0.5rem;
    color: var(--color-accent);
    background: var(--color-button-bg);
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: auto;

    /* leaves a bit of breathing room after #hash navigation */
    scroll-padding-top: 6rem;
}

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.7;
    color: var(--color-text);
    background: var(--color-bg);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header {
    min-height: var(--site-header-height);
    box-shadow: 0 2px 8px rgba(26, 54, 93, 0.2);
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg-alt);
}

.site-header-content {
    width: min(100% - 3rem, var(--target-max-content-width));
    margin: 0 auto;
}

.site-header-content {
    min-height: var(--site-header-height);
    display: flex;
    align-items: center;
    gap: 2rem;
}

.site-brand {
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
}

.site-brand-logo {
    height: 2rem;
    vertical-align: middle;
}

.site-navigation {
    margin-left: auto;
    a {
        text-decoration: none;
    }
}

.site-navigation {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1.25rem;
}

.site-navigation-logout {
    margin: 0;
}

.site-navigation-logout button {
    padding: 0;
    font: inherit;
    border: 0;
    cursor: pointer;
    background: none;
    color: var(--color-accent);

    &:hover {
        background: none;
        text-decoration: underline;
    }
}

.site-navigation-dropdown .site-navigation-dropdown-list {
    display: none;
    position: absolute;
    z-index: 6;
    background: white;

    border-radius: 1rem;
    box-shadow: 0 0.4rem 1rem #0003;

    ul {
        list-style: none;
        padding: 0.5rem 1.3rem 1rem;
    }
}

.site-navigation-dropdown:hover .site-navigation-dropdown-list {
    display: block;
}

.site-banner {
    padding: 0.75rem 0;
    color: var(--color-text);
    background: var(--color-warning-bg);
    border-bottom: 1px solid var(--color-warning-border);
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

.site-banner-content {
    width: min(100% - 3rem, var(--target-max-content-width));
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-banner-dismiss {
    flex: none;
    padding: 0.25rem 0.5rem;
    border: 1px solid currentColor;
    border-radius: 4px;
    font: inherit;
    cursor: pointer;
}

.site-content {
    flex: 1 0 auto;
}

/* this part is adapted from tailwind, which might be why it's so weird */
#layout-footer {
    font-family: "Inter var", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    color: oklch(27.9% .041 260.031);
    background-color: #fff;
    border-color: oklch(92.9% .013 255.508);
    border-top-style: solid;
    border-top-width: 1px;
    margin-top: calc(0.25rem * 20);

    line-height: 1.5;

    #layout-footer-container-page {
        padding: calc(0.25rem * 12) calc(0.25rem * 6);
        width:100%;
        max-width: 72rem;
        margin-inline: auto;

        * {
            margin: 0;
            padding: 0;
            border: 0 solid;
            box-sizing: border-box;
        }

        #layout-footer-grid {
            color: oklch(55.4% .046 257.417);
            display: grid;
            gap: calc(0.25rem * 10);
            grid-template-columns: repeat(4, minmax(0, 1fr));

            #layout-footer-logo-column {
                img {
                    width: auto;
                    max-width: 100%;
                    height: calc(0.25rem * 7);
                }
                hr {
                    border-color: oklch(92.9% .013 255.508);
                    border-top-style: solid;
                    border-top-width: 1px;
                    margin-block: calc(0.25rem * 6);
                }
            }

            h4 {
                text-transform: uppercase;
                color: oklch(55.4% .046 257.417);
                letter-spacing: 0.025em;
                font-weight: 600;
                font-size: 0.75rem;
            }

            ul {
                list-style: none;
                margin-top: calc(0.25rem * 3);

                li:not(:last-child) {
                    margin-block-end: calc(0.25rem * 2);
                }

                a {
                    color: oklch(44.6% .043 257.281);
                    font-size: 0.875rem;
                    line-height: calc(1.25 / .875);
                }
            }
        }

        #layout-footer-boilerplate {
            color: oklch(55.4% .046 257.417);
            line-height: 1.625;
            font-size: 0.75rem;
            padding-top: calc(0.25rem * 6);
            border-color: oklch(92.9% .013 255.508);
            border-top-style: solid;
            border-top-width: 1px;
            margin-top: calc(0.25rem * 10);
        }
    }
}

:target {
    box-shadow: inset 0rem 6rem 3rem -7rem var(--color-accent);
}

.book-header {
    padding: 2rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);

    .book-header-content {
        margin: 0 auto;
        max-width: var(--target-max-content-width);
        color: white;
        h1 { color: white; }
        a { color: white; text-decoration: underline; }
        display: flex;
        gap: 2rem;

        .book-header-image {
            flex: 0 0 300px;
        }
    }
}

.cover-image {
    max-width: 300px;
    width: 100%;
    height: auto;
    margin-bottom: 2rem;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border-radius: 4px;
}

.book-title {
    font-size: 2rem;
    margin: 0 0 1rem;
    font-weight: normal;
}

.book-header .authors {
    margin: 1rem 0;
}

.book-header .author {
    margin: 0.25rem 0;
    font-size: 0.95rem;
}

.publication-info {
    font-size: 110%;
}

.publication-info p {
    margin: 0.2rem 0;
}

section {
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 22pt;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--color-primary);
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

h2 { font-size: 1.6rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.4rem; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.15rem; }
h5 { font-size: 1.05rem; }
h6 { font-size: 1rem; }

.page-marker {
    text-align: right;
    color: var(--color-deemphasized);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: normal;
    text-decoration: none;
    font-style: normal;
    
    margin: 1.5rem 0.8rem 0;
    hr {
        height: 1px;
        border: 0;
        background-color: #ddd;
    }
}

.label {
    color: var(--color-accent);
    font-weight: bold;
}

li > .label {
    margin-right: 0.4em;
    float: left;
}

p, .paragraph {
    margin: 0.75rem 0;

    img {
        max-width: 100%;
    }
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
}

textarea {
    min-height: 6rem;
    resize: vertical;
}

button, input[type=submit], .button-link {
    color: white;
    background: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    padding: 0.4rem 0.7rem;
    cursor: pointer;
}

.button-link {
    display: inline-block;
}

input:disabled,
textarea:disabled,
button:disabled {
    color: var(--color-text-light);
    background: var(--color-bg-alt);
    border-color: var(--color-border);
    cursor: not-allowed;
    opacity: 0.7;
}

input:focus,
textarea:focus,
button:focus-visible,
.button-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

button:hover,
.button-link:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
    text-decoration: none;
}

.xref {
    color: var(--color-accent);
}

ul, ol {
    margin: 0.75rem 0;
    padding-left: 1rem;
}

.list-simple {
    list-style: none;
    padding-left: 0;

    .list-simple {
      padding-left: 2rem;
    }
}

.list-simple li {
    margin-bottom: 0.75rem;
}

.list-bullet li {
    margin-bottom: 0.4rem;
}

.list-number li {
    margin-bottom: 0.4rem;
}

.list-title {
    margin-bottom: 0.5rem;
}

.table-wrap {
    position: relative;
    margin: 1.5rem 0;
    overflow-x: auto;

    img {
        max-width: 100%;
    }
}

.table-caption {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    color: var(--color-primary);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    line-height: 1.4;
    margin: 0.5rem 0;
}

thead {
    background: var(--color-primary);
    color: white;
}

th {
    padding: 0.6rem 0.75rem;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
}

td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
}

tbody tr:nth-child(even) {
    background: var(--color-bg-alt);
}

tbody tr:hover {
    background: #edf2f7;
}

.table-footnotes {
    margin-top: 0.5rem;
    padding: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-light);
    border-top: 1px solid var(--color-border);
}

.table-footnotes .footnote {
    margin: 0.25rem 0;
}

figure {
    position: relative;
    margin: 1.5rem 0;
    text-align: center;
    .paragraph {
        text-align: left;
    }
}

figure img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.newsletter-article-page .relative-article-navigation {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 2px solid var(--color-primary);
    font-size: 120%;

    a.next-link {
        margin-left: auto;
    }
}

.print-item-button {
    position: absolute;
    z-index: 1;
    top: 0.5rem;
    right: 0.5rem;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-bg) 88%, transparent);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    box-shadow: 0 1px 3px #0003;
    cursor: pointer;

    &:hover {
        color: var(--color-bg);
        background: var(--color-primary);
        box-shadow: inset 0 0 0 2px var(--color-primary), 0 1px 3px #0003;
    }

    &:focus-visible {
        box-shadow: inset 0 0 0 2px var(--color-accent), 0 1px 3px #0003;
    }

    svg {
        width: 1.25rem;
        height: 1.25rem;
        fill: none;
        stroke: currentColor;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: 2;
    }
}

#printable-item-dialog {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 1.5rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 0;

    &::backdrop {
        background: var(--color-bg);
    }
}

.printable-item-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);

    h2 {
        margin: 0;
    }

    div {
        display: flex;
        gap: 0.5rem;
    }
}

#printable-item-preview {
    overflow: auto;

    & > :first-child {
        margin-top: 0;
    }
}

figcaption {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    .paragraph {
        text-align: left;
    }
}

.attribution {
    font-size: 0.8rem;
    color: var(--color-text-light);
    font-style: italic;
}

blockquote {
    margin: 0;
    padding: 1.5rem;

    border: 1px solid;
    border-radius: 6px;
    border-color: var(--color-border);

    background: var(--color-bg-alt);
}

.boxed-text {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 6px;
    border-left: 4px solid;
}

.boxed-text.sidebar-small, .boxed-text.sidebar-medium {
    background: var(--color-example-bg);
    border-color: var(--color-example-border);
}

.boxed-text.sidebar-large {
    background: var(--color-sidebar-bg);
    border-color: var(--color-sidebar-border);
}

.boxed-text h3,
.boxed-text h4,
.boxed-text h5,
.boxed-text h6 {
    margin-top: 0;
    font-size: 1.05rem;
}

.boxed-text > section {
    margin-bottom: 0;
}

.boxed-text > section > :first-child {
    margin-top: 0;
}

.boxed-text > section > :last-child {
    margin-bottom: 0;
}

.footnotes {
    margin: 1rem 0;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.footnote {
    margin: 0.3rem 0;
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.glossary {
    margin: 2rem 0;
}

dl.def-list {
    margin: 1rem 0;
}

dl.def-list dt {
    font-weight: bold;
    color: var(--color-primary);
    margin-top: 1rem;
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

dl.def-list dd {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
    padding-left: 0;
}

.references {
    margin: 2rem 0;
}

.reference-list {
    font-size: 0.9rem;
    line-height: 1.5;
    list-style: none;
}

.reference-list li {
    margin-bottom: 1rem;
    padding-left: 0.25rem;
    text-indent: 1em hanging;
}

.reference-label {
    margin-inline-end: 0.4em;
}

.chapter {
    padding-top: 2rem;
    border-top: 3px solid var(--color-deemphasized);
    margin-top: 3rem;
}

.chapter:first-child {
    border-top: none;
    margin-top: 0;
}

.front-matter-part {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.front-matter-part.copyright {
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.appendix-group, .appendix {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--color-primary);
}

.formula {
    margin: 1rem 0;
    padding: 0.5rem;
    text-align: center;
    font-style: italic;
}

.inline-formula {
    font-style: italic;
}

.small-caps {
    font-variant: small-caps;
}

.error-page-content {
    width: min(100% - 3rem, var(--target-max-content-width));
    margin: 2rem auto;
}

#book-scroll {
    --side-panel-width: 21rem;
    --body-text-width: 62rem;
    --content-gap: 2em;

    display: flex;
    gap: var(--content-gap);
    justify-content: safe center;

    #book-scroll-left-panel {
        flex: 0 0 var(--side-panel-width);

        .toc-sticky {
            position: sticky;
            top: 1rem;
            z-index: 10;
            margin: 1rem;
        }

        #book-scroll-left-panel-toggle {
            position: absolute;
            z-index: 1;
            top: 7rem;
            right: -1.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 1.5rem;
            height: 2.5rem;
            color: var(--color-primary);
            background: var(--color-button-bg);
            border: 1px solid var(--color-border);
            border-left: 0;
            border-radius: 0 var(--toc-radius) var(--toc-radius) 0;
            box-shadow: 4px 4px 8px rgba(26, 54, 93, 0.1);
            cursor: pointer;
            user-select: none;

            svg {
                width: 1rem;
                height: 1rem;
                fill: none;
                stroke: currentColor;
                stroke-linecap: round;
                stroke-linejoin: round;
                stroke-width: 2;
            }
        }

        nav.toc {
            max-height: calc(100vh - 2rem);
            overflow: auto;
            margin: 0;
            padding: 1rem;
            background: var(--color-bg-alt);
            border: 1px solid var(--color-border);
            border-radius: var(--toc-radius);
            box-shadow: var(--standard-shadow);
            font-family: 'Helvetica Neue', Arial, sans-serif;
        }

        nav.toc h4 {
            margin-top: 0;
            font-weight: bold;
        }

        nav.toc summary {
            cursor: pointer;
            color: var(--color-primary);
        }

        nav.toc .toc-root > summary {
            margin-bottom: 0.75rem;
            padding-bottom: 0.5rem;
            border-bottom: 2px solid var(--color-primary);
            font-size: 1.25rem;
        }

        nav.toc ol {
            padding-left: 0;
        }

        nav.toc .toc-list {
            margin: 0.5rem 0 0;
            list-style: none;
        }

        nav.toc .toc-list .toc-list {
            border-left: solid 1px #ccc;
            padding-left: 1em;
        }

        nav.toc .toc-list .toc-list {
            margin-top: 0.25rem;
        }

        nav.toc .toc-node>summary {
            margin-left: 1em;
            text-indent: -1em;
        }

        nav.toc li {
            margin: 0.8rem 0;
            font-size: 0.9rem;
            line-height: 1.35;
        }

        nav.toc a {
            color: var(--color-accent);
            text-decoration: none;
        }

        nav.toc a:hover {
            text-decoration: underline;
        }

        nav.toc a.is-active {
            color: var(--color-primary);
            font-weight: bold;
        }

        nav.toc span {
            color: var(--color-text);
        }

        nav.toc details[open] > summary {
            margin-bottom: 0.25rem;
        }
    }

    #book-scroll-main {
        flex: 0 1 var(--body-text-width);
        width: var(--body-text-width);
        min-width: 40rem;

        #active-toc-breadcrumb {
            position: sticky;
            top: 1em;
            z-index: 5;
            margin: 1.5rem -1rem;
            padding: 0.5rem 1rem;
            background: var(--color-bg-alt);
            border: 1px solid var(--color-border);
            border-radius: var(--toc-radius);
            box-shadow: var(--standard-shadow);
            font-family: 'Helvetica Neue', Arial, sans-serif;

            ol#breadcrumb-list {
                display: flex;
                align-items: center;
                width: 100%;
                margin: 0;
                padding: 0;
                list-style: none;

                li {
                    display: flex;
                    flex: 0 1 content;
                    align-items: center;
                    min-width: 7em;
                    max-width: 22em;
                    white-space: nowrap;
                }

                li + li::before {
                    margin: 0 0.5rem;
                    color: var(--color-text-light);
                    content: "›";
                }

                a {
                    display: block;
                    overflow: hidden;
                    color: var(--color-accent);
                    text-decoration: none;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }

                a:hover {
                    text-decoration: underline;
                }

                li:last-child a {
                    color: var(--color-primary);
                    font-weight: bold;
                }
            }

            #special-command-buttons {
                display: flex;
                gap: 1em;
                padding: 0;
                margin: 0;

                a, a:hover, button {
                    border: none;
                    color: var(--color-accent);
                    background: var(--color-button-bg);
                    border-radius: 4px;
                    padding: 4px 8px;
                    cursor: pointer;
                    text-decoration: none;
                }
            }
        }
    }

    #book-scroll-filler {
        flex: 0 999 var(--side-panel-width);
    }

    &.toc-is-collapsed {
        --side-panel-width: 2em;

        #book-scroll-left-panel {
            nav.toc {
                display: none;
            }

            #book-scroll-left-panel-toggle {
                position: fixed;
                left: 0;

                svg {
                    transform: rotate(180deg);
                }
            }
        }
    }
}

#selection-tools {
    position: absolute;
    z-index: 20;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg-alt);
    padding: 8px;
    box-shadow: var(--standard-shadow);
    white-space: nowrap;

    button {
        background: var(--color-primary);
        color: var(--color-bg-alt);
        border: 1px solid var(--color-accent);
        border-radius: 4px;
        padding: 0.4rem 0.7rem;
        cursor: pointer;
    }

    button.is-copied {
        background: var(--color-primary);
        box-shadow: inset 0 0 0 2px var(--color-accent);
    }
}

#bookmark-dialog {
    width: min(48rem, 50vw);

    h2 {
        margin-top: 0;
    }

    .bookmark-selection-form {
        display: grid;
        gap: 0.75rem;

        textarea {
            min-height: 6rem;
            resize: vertical;
        }
    }
}

.bookmark-status,
.bookmark-error {
    padding: 0.75rem;
    border-radius: 4px;
}

.bookmark-status {
    box-shadow: inset 0 0 0 2px var(--color-accent);
}

.bookmark-error {
    box-shadow: inset 0 0 0 2px #9b1c1c;
}

@media (max-width: 1720px) {
    #book-scroll #book-scroll-left-panel .toc-sticky {
        margin: 0;

        top: 0;
        bottom: 0;
        height: 100vh;

        nav.toc {
            height: 100vh;
            max-height: 100vh;
            border-radius: 0;
        }
    }
}

@media print {
    body {
        display: block !important;
        min-height: 0;
    }

    body > :not(.site-content) {
        display: none !important;
    }

    .site-content > :not(#printable-item-dialog) {
        display: none !important;
    }

    #printable-item-dialog {
        display: block !important;
        width: auto;
        height: auto;
        padding: 0;
        overflow: visible;
    }

    .printable-item-toolbar {
        display: none;
    }

    #printable-item-preview {
        overflow: visible;
    }

    #printable-item-preview .table-wrap {
        overflow: visible;
    }
}
