@import url("./main.css");

*,
button {
    --font-size: calc(var(--font-size-em, 1) * var(--doc-font-size-pt, 12));

    font-size: calc(1pt * var(--font-size));

    --font-wdth: 100;
    --font-wght: 400;

    font-variation-settings:
        "opsz" var(--font-size),
        "wght" var(--font-wght),
        "wdth" var(--font-wdth);
}

:root {
    --font-size-em: 1;
}

*,
body {
    --font-size-change: 1.2;
    --font-size-em: 1.2;
}

pre {
    max-width: 100%;
    overflow: auto;
}

.typeroof-docs {
    --font-size-change: 1.3;

    .wrapper {
        grid-template-areas:
            "sidebar"
            "main";
        grid-template-rows: auto auto;
        grid-template-columns: auto;
        height: fit-content;
    }

    header {
        padding: 2rem 0;
        background: black;
        color: white;

        h1,
        h1 > .typeroof {
            font-size: calc(1pt * var(--font-size));
            font-variation-settings:
                "opsz" var(--font-size),
                "wght" var(--font-wght),
                "wdth" var(--font-wdth);
            text-align: center;
            margin: 0;

            --font-wdth: 70;
            --font-wght: 800;
        }

        h1 {
            --font-size-em: 2;
            --font-wght: 500;
        }

        h1 > .typeroof {
            --font-size-em: 3.5;

            display: block;
        }
    }

    .typeroof-ui_sidebar {
        & > nav,
        & > .toggle-menu-bottom {
            display: none;
        }

        &.menu-visible > nav,
        &.menu-visible > .toggle-menu-bottom {
            display: block;
        }
    }
}

@media (width >= 800px) {
    .typeroof-docs {
        --font-size-change: 1.3;

        .wrapper {
            grid-template-columns: var(--sidebar-width) calc(
                    100vw - var(--sidebar-width)
                );
            grid-template-areas: "sidebar main";
            grid-template-rows: auto;
        }

        .typeroof-ui_sidebar {
            button.toggle-menu {
                display: none;
            }

            & > nav {
                display: block;
            }
        }
    }
}

/******************************************************************************
sidebar
*******************************************************************************/

button.toggle-menu {
    width: 100%;
    margin-top: 0.75rem;
    height: 1.5em;
}

.typeroof-docs .typeroof-ui_sidebar {
    font-size: 0.8em;
    font-optical-sizing: auto;
    padding: 1em 2em;

    a {
        color: inherit;
        text-decoration: none;
    }

    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    nav > ul > li > a {
        font-size: 1.1em;
    }

    ul > li {
        padding: 0.3em 0;

        > a {
            display: inline;
            margin-bottom: 0.2em;
        }
    }

    li.active {
        > a {
            font-weight: 700;
        }
    }

    li > ul > li {
        padding: 0.2em 0;

        > ul {
            margin-left: 1em;
        }

        &::before {
            /* stylelint-disable-next-line font-family-no-missing-generic-family-keyword */
            font-family: "Material Symbols Outlined";
            font-size: 1.2rem;
            font-variation-settings: "wght" 250;
            content: "\e5cc";
            line-height: 1.2rem;
            margin-left: -0.4em;
            vertical-align: middle;
        }
    }

    h3 {
        font-size: 1.1em;
        font-weight: 600;
        margin-top: 2em;
        margin-bottom: 0.5em;
    }
}

/******************************************************************************
main
*******************************************************************************/

body.typeroof-docs > .wrapper > .typeroof-main {
    overflow: auto;
    container-type: inline-size;
}

/******************************************************************************
content
*******************************************************************************/

.typeroof-docs_content .heading_anchor {
    color: gray;
    font-weight: normal;
    margin-right: 0.1em;
    text-decoration: none;
}

@container (width > 0) {
    /* the @container query is only required to establish the cqi unit
   * https://developer.mozilla.org/en-US/docs/Web/CSS/length#container_query_length_units
   */
    .typeroof-docs_content {
        --max-width: 50rem;

        /* The max rule guards the free-space to not become negative, that
     * way the actual width of the content plus its inline padding are
     * always available before we add margin.
     */
        --free-space: max(1em, calc(100cqi - var(--max-width)));

        max-width: var(--max-width);

        /* Try to balance the distance to the left side
     * it grows with the available horizontal space
     * but it would loose contact to the left edge when too big, so we
     * stop growing distance at 1/3 of the content max width.
     * It can't become negative, because --free-space will never be < 0;
     */
        --margin-inline-start: min(
            var(--free-space) * 1/3,
            var(--max-width) * 1/3
        );

        margin-inline-start: var(--margin-inline-start);
    }

    .typeroof-docs_content .heading_anchor {
        /* Because the # is painted in a light gray it creates visually a gap.
     * For the appearance of the left border it's better to move these out,
     * if there's space.
     * The .8em is determined visually with Roboto Flex, it would differ
     * for other fonts and other relative width of the #, also e.g. when
     * e.g. the wdth axis would be used.
     * */
        --move-out: 0.9em;

        /* if the left margin doesn't have --move-out space the calculation
     * in the second argument of clamp(min, val, max) will be lower than
     * 0 and thus 0; otherwise it will be between 0 and 0.8em. The
     * round(up, valueToRound, roundingInterval) will round up to 0.8em.
     * This means there's either enough space to fit the --move-out left
     * to the content and then the whole value is used or there's not and
     * then the --move-out is not applied at all, without transition in
     * between.
     */
        --use-move-out: round(
            up,
            clamp(
                0em,
                var(--margin-inline-start, 0em) + var(--gap-size) -
                    var(--move-out),
                var(--move-out)
            ),
            var(--move-out)
        );

        margin-inline-start: calc(var(--use-move-out) * -1);
    }

    .state_button {
        display: inline-block;
        border: 1px solid var(--button-border-color);
        border-radius: 0.3em;
        padding: 0.3em 0.4em 0.3em 0.3em;

        .material-symbols-outlined {
            font-size: 2em !important;
            vertical-align: middle;
        }
    }
}
