/* The cx book's style, on top of Doxygen's (HTML_EXTRA_STYLESHEET in the Doxyfile).
 *
 * Doxygen's own variables set the colors, so its light and dark schemes both work;
 * the rules below restyle the page for reading: a readable text column, code that
 * scrolls instead of breaking mid-word, tables that scroll on their own, and, below
 * 768px, a top bar (added by cx.js) whose menu opens the sidebar as a drawer.
 *
 * navtree.js sets the panels' widths and heights as inline styles, so the phone
 * layout overrides those with !important. Written for Doxygen 1.18 (the pinned one). */

/* --- colors and fonts ----------------------------------------------------------- */

/* Doxygen's dark scheme sets its variables on `html:not(.dark-mode)`; this file uses the
 * same selector, so (loaded later) it wins in both schemes. */
html:not(.dark-mode) {
    --cx-accent: #4353d1;
    --cx-accent-soft: rgba(67, 83, 209, 0.1);
    --cx-muted: #5b6474;
    --cx-border: #e3e6eb;
    --cx-code-bg: #f5f6f8;
    --cx-topbar-height: 56px;

    --page-background-color: #ffffff;
    --page-foreground-color: #1d2330;
    --page-link-color: var(--cx-accent);
    --page-visited-link-color: var(--cx-accent);
    --page-external-link-color: var(--cx-accent);
    --header-background-color: transparent;
    --header-separator-color: var(--cx-border);
    --title-background-color: transparent;
    --title-separator-color: transparent;
    --footer-foreground-color: var(--cx-muted);
    --blockquote-background-color: var(--cx-accent-soft);
    --blockquote-border-color: var(--cx-accent);
    --scrollbar-thumb-color: #c9ced6;
    --scrollbar-background-color: transparent;

    --table-cell-border-color: var(--cx-border);
    --table-header-background-color: #f3f4f7;
    --table-header-foreground-color: #1d2330;

    --nav-background-color: #f8f9fb;
    --nav-foreground-color: #2c3445;
    --nav-text-normal-color: #2c3445;
    --nav-border-color: var(--cx-border);
    --nav-menu-active-bg: var(--cx-accent-soft);
    --nav-arrow-color: #9aa3b2;
    --nav-arrow-selected-color: var(--cx-accent);
    --nav-splitbar-bg-color: var(--cx-border);
    --nav-breadcrumb-separator-color: var(--cx-border);
    --nav-breadcrumb-color: var(--cx-muted);
    --nav-breadcrumb-active-bg: var(--cx-accent-soft);

    --fragment-background-color: var(--cx-code-bg);
    --fragment-foreground-color: #1d2330;
    --fragment-border-color: var(--cx-border);

    --search-background-color: #ffffff;
    --search-foreground-color: #1d2330;
    --search-box-border-color: #d3d8e0;
    --search-results-background-color: var(--page-background-color);
    --search-filter-background-color: var(--page-background-color);

    --font-family-normal: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell,
        "Helvetica Neue", Arial, sans-serif;
    --font-family-title: var(--font-family-normal);
    --font-family-nav: var(--font-family-normal);
    --font-family-toc: var(--font-family-normal);
    --font-family-search: var(--font-family-normal);
    --font-family-monospace: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas,
        "DejaVu Sans Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    html:not(.dark-mode) {
        --cx-accent: #9aa8ff;
        --cx-accent-soft: rgba(154, 168, 255, 0.12);
        --cx-muted: #9aa3b2;
        --cx-border: #262c38;
        --cx-code-bg: #161b24;

        --page-background-color: #0e1117;
        --page-foreground-color: #e3e7ee;
        --scrollbar-thumb-color: #3a4252;
        --table-header-background-color: #161b24;
        --table-header-foreground-color: #e3e7ee;
        --nav-background-color: #11151c;
        --nav-foreground-color: #c9d0db;
        --nav-text-normal-color: #c9d0db;
        --nav-arrow-color: #5e6778;
        --fragment-foreground-color: #e3e7ee;
        --search-background-color: #0e1117;
        --search-foreground-color: #e3e7ee;
        --search-box-border-color: #343c4b;
    }
}

/* --- text ------------------------------------------------------------------------ */

body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

div.header,
div.contents {
    box-sizing: border-box;
    max-width: 52rem;
    margin: 0 auto;
    padding: 0 2rem;
}

div.header {
    border-bottom: none;
    padding-top: 2rem;
}

div.headertitle {
    padding: 0;
}

.title {
    margin: 0;
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

div.contents {
    padding-bottom: 4rem;
}

div.contents,
div.contents p,
div.contents li,
div.contents dl,
div.contents td,
div.contents th {
    font-size: 1rem;
    line-height: 1.7;
}

div.contents p {
    margin: 0.9em 0;
}

div.contents h1,
div.contents h2,
div.contents h3,
div.contents h4 {
    margin: 2em 0 0.6em;
    font-weight: 650;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

div.contents h1 {
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--cx-border);
    font-size: 1.6rem;
}

div.contents h2 {
    font-size: 1.3rem;
}

div.contents h3 {
    font-size: 1.1rem;
}

div.contents a {
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
    text-underline-offset: 0.2em;
}

div.contents a:hover {
    text-decoration-color: currentColor;
}

div.contents ul,
div.contents ol {
    padding-left: 1.5em;
}

blockquote {
    margin: 1.2em 0;
    padding: 0.6em 1em;
    border-left: 3px solid var(--blockquote-border-color);
    border-radius: 0 6px 6px 0;
}

/* --- code ------------------------------------------------------------------------ */

/* Long paths wrap rather than widen the page (break-word, unlike anywhere, leaves table
 * columns as wide as their code). */
span.tt,
code {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.875em;
    background-color: var(--cx-code-bg);
}

div.contents a span.tt {
    color: inherit;
}

/* Blocks keep their lines (commands and output line up) and scroll sideways. */
div.fragment {
    margin: 1em 0;
    padding: 0.85em 1em;
    border-radius: 8px;
    overflow-x: auto;
}

div.fragment div.line {
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    text-indent: 0;
    padding-left: 0;
}

/* --- tables ---------------------------------------------------------------------- */

/* As a block, a wide table scrolls by itself instead of widening the page. */
table.markdownTable {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    margin: 1.2em 0;
    border-collapse: collapse;
    -webkit-overflow-scrolling: touch;
}

table.markdownTable td,
table.markdownTable th {
    padding: 0.5em 0.85em;
    vertical-align: top;
    text-align: left;
}

th.markdownTableHeadLeft,
th.markdownTableHeadRight,
th.markdownTableHeadCenter,
th.markdownTableHeadNone {
    font-size: 0.9rem;
    font-weight: 650;
}

/* --- sidebar --------------------------------------------------------------------- */

#titlearea {
    padding: 1rem 0.75rem 0.5rem 1rem;
}

/* Doxygen lays the title and the search box out as a table, which grows wider than the
 * sidebar around a full-width search box; as blocks, they fit. */
#titlearea table,
#titlearea tbody,
#titlearea tr,
#titlearea td {
    display: block;
    width: 100%;
}

#side-nav #projectname {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

#projectbrief {
    margin-top: 0.15rem;
    color: var(--cx-muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

#MSearchBox {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 100%;
    margin: 0.75rem 0 0;
    padding: 0.2rem 0.5rem;
    border-radius: 8px;
}

#MSearchBox .left {
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    height: auto;
}

#MSearchField {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 1.9rem;
    font-size: 0.9rem;
}

#MSearchResultsWindow,
#MSearchSelectWindow {
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

#MSearchResultsWindow {
    max-width: calc(100vw - 2rem);
}

#nav-tree .label {
    font-size: 0.875rem;
    line-height: 2rem;
}

#nav-tree .item {
    margin-right: 0.5rem;
}

#nav-tree .selected {
    border-radius: 0 6px 6px 0;
    box-shadow: inset 2px 0 var(--cx-accent);
}

#nav-tree .selected a {
    font-weight: 600;
}

#nav-tree a {
    color: var(--nav-text-normal-color);
}

#nav-tree a:hover {
    color: var(--cx-accent);
}

/* The page outline on the right. */
ul.page-outline div.item {
    font-size: 0.8rem;
    line-height: 1.75rem;
}

ul.page-outline li.vis {
    background-color: transparent;
    box-shadow: inset 2px 0 var(--cx-accent);
}

/* The footer. */
#nav-path ul {
    background: var(--page-background-color);
}

#nav-path li.footer {
    color: var(--cx-muted);
    font-size: 0.75rem;
}

#nav-path img.footer {
    opacity: 0.6;
}

/* Only cx.js's phone layout shows these. */
#cx-topbar,
#cx-scrim {
    display: none;
}

/* The outline needs room: without it, the text column gets the width. */
@media (max-width: 1199px) {
    #page-nav {
        display: none !important;
    }

    #container {
        grid-template-columns: auto !important;
    }
}

/* --- phones and narrow windows --------------------------------------------------- */

@media (max-width: 767px) {
    /* The page scrolls as a whole, under a bar that stays at the top. */
    #container {
        display: block !important;
        overflow: visible !important;
    }

    #doc-content {
        height: auto !important;
        margin-left: 0 !important;
        overflow: visible !important;
    }

    #nav-path {
        margin-left: 0 !important;
    }

    #cx-topbar {
        position: sticky;
        top: 0;
        z-index: 100;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        height: var(--cx-topbar-height);
        padding: 0 0.5rem;
        border-bottom: 1px solid var(--cx-border);
        background-color: color-mix(in srgb, var(--page-background-color) 88%, transparent);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }

    #cx-title {
        flex: 1;
        overflow: hidden;
        color: var(--page-foreground-color);
        font-size: 1.05rem;
        font-weight: 700;
        text-align: center;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .cx-icon-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border: none;
        border-radius: 10px;
        color: var(--page-foreground-color);
        background: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .cx-icon-button:hover,
    .cx-icon-button:focus-visible {
        background-color: var(--cx-accent-soft);
    }

    /* The sidebar becomes a drawer; hidden (not just moved) when closed, so Tab skips it. */
    #side-nav {
        position: fixed !important;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 300;
        width: min(85vw, 320px) !important;
        height: 100% !important;
        padding: 0 !important;
        border-right: 1px solid var(--cx-border);
        background-color: var(--nav-background-color);
        box-shadow: 0 0 32px rgba(0, 0, 0, 0.25);
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform 0.22s ease, visibility 0s linear 0.22s;
    }

    html.cx-nav-open #side-nav {
        transform: none;
        visibility: visible;
        transition: transform 0.22s ease;
    }

    #side-nav #titlearea {
        border-right: none;
    }

    #nav-tree {
        border-right: none;
    }

    #nav-tree .label {
        font-size: 0.95rem;
        line-height: 2.5rem;
    }

    #splitbar,
    #nav-sync {
        display: none !important;
    }

    #cx-scrim {
        position: fixed;
        inset: 0;
        z-index: 200;
        display: block;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }

    html.cx-nav-open #cx-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    html.cx-nav-open,
    html.cx-nav-open body {
        overflow: hidden;
    }

    div.header,
    div.contents {
        padding-right: 1.1rem;
        padding-left: 1.1rem;
    }

    div.header {
        padding-top: 1.25rem;
    }

    .title {
        font-size: 1.75rem;
    }

    div.contents h1 {
        font-size: 1.35rem;
    }

    div.contents h2 {
        font-size: 1.15rem;
    }

    /* Code and tables run to the screen's edges, so more of them fits. */
    div.fragment,
    table.markdownTable {
        margin-right: -1.1rem;
        margin-left: -1.1rem;
    }

    table.markdownTable {
        max-width: calc(100% + 2.2rem);
    }

    div.fragment {
        padding-right: 1.1rem;
        padding-left: 1.1rem;
        border-right: none;
        border-left: none;
        border-radius: 0;
    }

    table.markdownTable td,
    table.markdownTable th {
        padding: 0.45em 0.7em;
    }

    table.markdownTable td:first-child,
    table.markdownTable th:first-child {
        padding-left: 1.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #side-nav,
    #cx-scrim {
        transition: none !important;
    }
}
