:root {
    --color-bg: #161923;
    --color-fg: #bcbdd0;
    --color-header-bg: var(--color-bg);
    --color-header-fg: #737480;
    --color-quote-bg: #252832;
    --color-quote-border: hsl(226, 15%, 22%);
    --links: #2b79a2;

    --color-rm-green: rgb(0, 128, 128);
    --color-rm-green-dark: rgb(4, 38, 44);
    --color-rm-green-light: rgb(50%, 75.097656%, 75.097656%);

    --color-rm-blue: #0073c0;
    --color-rm-blue-dark: #092d44;

    --font-weight-normal: "wght" 250;
    --font-weight-bold: "wght" 500;

    font-synthesis: none; /* avoids synthetic bold/italic */
    font-variation-settings: var(--font-weight-normal);
}

html {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    font-size: 16px;
}

/*
 * We are using a rather light weight for the "normal" font weight, and a default bold weight of 700 is to heavy. Hence,
 * we take advantage of the way LaTeXML renders font series to set up a nice bold-face weight
 */
.ltx_font_bold {
    font-variation-settings: var(--font-weight-bold);
}

.ltx_font_medium {
    font-variation-settings: var(--font-weight-normal);
}

body {
    background-color: var(--color-bg);
    color: var(--color-fg);
    font-optical-sizing: auto;
    margin: 0;
}

h1.ltx_title_document {
    font-size: 3rem;
}

header.section-header {
    position: sticky;
    top: 0;
    padding: 10px;
    color: var(--color-header-fg);
    background-color: var(--color-header-bg);
    border-bottom: 1px solid var(--color-header-fg);
    z-index: 10;

    a {
        color: var(--color-header-fg);

        &:hover {
            text-decoration: none;
        }
    }

    div.section-header-content {
        display: flex;
        flex-direction: row;

        div.section-header-left, div.section-header-right {
            min-width: 5em;
        }

        div.section-header-middle {
            flex: 1;
            text-align: center;
            font-size: 1.5rem;
        }
    }
}

nav.toc {
    a {
        color: var(--color-fg);

        &:hover {
            color: var(--links);
            text-decoration: none;
        }
    }

    li.toc-entry-section:first-child {
        margin-top: 0.5em;
    }
}

/* Avoid FOUCE on the drawer contents */
sl-drawer:not(:defined) {
    display: none;
}

a {
    color: var(--links);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

a:visited {
    color: var(--links);
}

.ltx_page_content a.ltx_ref {
    font-weight: 400;
}

header.ltx_page_header, footer.ltx_page_footer {
    font-family: system-ui, sans-serif;
    font-size: 0.9rem;
}

header.ltx_page_header {
    padding-bottom: 1ex;
}

footer.ltx_page_footer {
    padding-top: 1ex;
}

h6.ltx_title.ltx_title_contents {
    font-size: 2rem;
    font-variation-settings: var(--font-weight-bold);
    margin: 0;
}

li.ltx_tocentry_chapter + li.ltx_tocentry_chapter {
    margin-top: 2ex;
}
li.ltx_tocentry.ltx_tocentry_section + li.ltx_tocentry.ltx_tocentry_section {
    margin-top: 0.5ex;
}

ol.ltx_toclist.ltx_toclist_chapter {
    margin-top: 1ex;
}

.ltx_tocentry.ltx_tocentry_chapter > div > .ltx_ref_title {
    font-variation-settings: var(--font-weight-bold);
    font-size: 1.25rem;

    .ltx_tag.ltx_tag_ref {
        display: inline-block;
        margin-right: -0.075ex;
    }
}

.ltx_tocentry.ltx_tocentry_bibliography {
    margin-top: 2ex;
    .ltx_ref {
        font-variation-settings: var(--font-weight-bold);
        font-size: 1.25rem;

        .ltx_tag.ltx_tag_ref {
            display: inline-block;
            margin-right: -0.075ex;
        }
    }
}

.ltx_title.ltx_title_chapter {
    font-variation-settings: var(--font-weight-bold);
    font-size: 2.5rem;

    .ltx_tag.ltx_tag_chapter {
        font-size: 2rem;
    }
}

.ltx_title.ltx_title_section {
    font-variation-settings: var(--font-weight-bold);
    font-size: 1.75rem;
}

div.ltx_page_content {
    font-size: 1rem;
    max-width: 45em;
    margin: 0 auto;
}

section > .ltx_title + .ltx_para > .ltx_p:first-child,
section > .ltx_title + .ltx_date + .ltx_para > .ltx_p:first-child {
    text-indent: 2em;
}

div.ltx_para:last-child > p.ltx_p:last-child {
    margin-bottom: 0;
}

p.ltx_p {
    &:has(+ div.equation-wrapper) {
        margin-bottom: 0;
    }

    &:has(~ div.equation-wrapper) {
        margin-top: 0;
    }
}

div.equation-wrapper + p.ltx_p {
    margin-top: 0;
}

ol.ltx_enumerate + p.ltx_p {
    margin-top: 0.75em !important;
}

div.equation-wrapper {
    width: 100%;
    overflow-x: auto;
}

div.ltx_theorem:has(div.equation-wrapper:last-child) {
    padding-bottom: 0;
}

div.ltx_theorem:not(.ltx_theorem_proof) {
    padding: 2ex;
    background-color: var(--color-quote-bg);
    border-block-start: 0.1rem solid var(--color-quote-border);
    border-block-end: 0.1rem solid var(--color-quote-border);
}

.ltx_enumerate {
    margin-bottom: 0;
    padding-left: 1.5em;
}

figure.ltx_figure div.ltx_flex_figure {
    column-gap: 4em;
}

figcaption.ltx_caption.ltx_centering {
    max-width: 30em;

    .ltx_tag.ltx_tag_figure {
        font-variation-settings: var(--font-weight-bold);
    }
}

nav.toc {
    font-size: 0.9rem;

    ol.toc-entries {
        list-style: none;
        padding-left: 2em;

        &:first-child {
            padding-left: 0;
        }

        li.toc-entry.toc-entry-chapter > a {
            font-variation-settings: var(--font-weight-bold);
            font-size: 110%;
        }

        li.toc-entry.toc-entry-chapter + li.toc-entry.toc-entry-chapter {
            margin-top: 1em;
        }
    }
}

span.pending-reference {
    padding: 2px;
    border: solid 1px var(--color-header-fg);

    sl-icon {
        color: #d0a36a;
    }
}

ul.ltx_biblist {
    > li.ltx_bibitem {
        margin: 1ex 0;

        span.ltx_tag.ltx_bib_key.ltx_role_refnum.ltx_tag_bibitem {
            display: inline-block;
            width: auto;
            margin-right: 2ex;
            margin-left: calc(-2em - 2ex);
        }
    }
}
