@counter-style fallback-circled
{
    system: cyclic;
    suffix: '  ';
    symbols: '◯';
}

@counter-style circled
{
    system: fixed;
    suffix: '  ';
    range: 1 9;
    symbols: '1' '2' '3' '4' '5' '6' '7' '8' '9';
    speak-as: numbers;
    fallback: fallback-circled;
}

html
{
    --padding: 0.7rem;
    --rider-padding: 0.3rem;
    --radius: var(--padding);
    --line: 2px solid #373737;

    background-color: #fbf7f0;
    scroll-behavior: smooth;
    color-scheme: only light;

    color: #373737;
    font-family: noto-serif, serif;
    font-weight: 430;
    font-size: 14.7px;
    line-height: 1.45em;
    font-variant-ligatures: common-ligatures;

    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

body
{
    margin: 0;
    padding-top: max(var(--padding), env(safe-area-inset-top));
    padding-left: max(var(--padding), env(safe-area-inset-left));
    padding-right: max(var(--padding), env(safe-area-inset-right));
    padding-bottom: max(var(--padding), env(safe-area-inset-bottom));

    display: flex;
    justify-content: center;
    gap: var(--padding);

    @media (width <=710px)
    {
        flex-direction: column-reverse;
    }

    >aside
    {
        inline-size: 220px;
        display: flex;
        flex-direction: column;
        gap: inherit;

        >header
        {
            background-color: #fee484;
            padding-inline: var(--padding);
            padding-block: calc(var(--padding) * 1.5);
            box-sizing: border-box;

            font-size: 53px;
            line-height: 0.85;
            letter-spacing: -0.008em;
        }

        .thin-screen
        {
            display: none;
        }

        @media (width <=1020px)
        {
            inline-size: 190px;

            >header
            {
                font-size: 46px;
            }
        }

        @media (width <=850px)
        {
            inline-size: 175px;

            >header
            {
                font-size: 41px;
            }
        }

        @media (width <=710px)
        {
            inline-size: 100%;
            flex-direction: row;
            flex-wrap: wrap;
            justify-content: center;
            align-items: flex-start;

            >header
            {
                width: 100%;
            }

            >*:not(header)
            {
                flex: 1;
                box-sizing: border-box;
            }

            .thin-screen
            {
                display: block;
            }

            .wide-screen
            {
                display: none;
            }
        }

        ol
        {
            list-style-type: circled;
            padding-inline-start: 2.5ch;

            li+li
            {
                padding-block-start: 0.4em;
            }

            ::marker
            {
                font-size: 92%;
                font-feature-settings: "ss05" 1, "cv01" 1;
                font-variant: normal;
            }

            :nth-child(6n - 5)::marker
            {
                color: #10505b;
            }

            :nth-child(6n - 4)::marker
            {
                color: #d48207;
            }

            :nth-child(6n - 3)::marker
            {
                color: #e36942;
            }

            :nth-child(6n - 2)::marker
            {
                color: #b72c31;
            }

            :nth-child(6n - 1)::marker
            {
                color: #353a71;
            }

            :nth-child(6n)::marker
            {
                color: #25476d;
            }
        }
    }
}

body>aside> :is(header, details), summary, figcaption,
h1, h2, h3, h4, h5, h6
{
    font-family: inter, system-ui;
    font-weight: 600;
    font-feature-settings: "cv01" 1, "ss03" 1;
    text-wrap: balance;

    &:not(h1, h2, h3, h4, h5, h6, body>aside>header)
    {
        font-variation-settings: "opsz" 26;
    }
}

h1, h2, h3, h4, h5, h6
{
    line-height: 1.1em;
    /* https://www.joshwcomeau.com/css/surprising-truth-about-pixels-and-accessibility/ */
}

a, a:visited
{
    color: inherit;
    text-decoration-thickness: 0.134em;
    text-underline-offset: 0.1em;

    text-decoration-color: #0074d9;

    &:hover
    {
        text-decoration-color: #6f9ec7;
    }

    &:active
    {
        text-decoration-color: #2168a5;
    }

    &[href^='mailto:']
    {
        text-decoration-color: #ffa349;

        &:hover
        {
            text-decoration-color: #f3b06d;
        }

        &:active
        {
            text-decoration-color: #e09040;
        }
    }
}

article, figure, details, header
{
    border-radius: var(--radius);
}

figcaption
{
    border-end-start-radius: var(--radius);
    border-end-end-radius: var(--radius);
}

article, details, figcaption
{
    border: var(--line);
}

article
{
    flex: 0 1 840px;
    min-inline-size: 0;
    padding-inline: 1rem;
    padding-block: 1.3rem;
    container-type: inline-size;

    @media (width <=710px)
    {
        padding-inline: 0;
        padding-block: 0.5rem;
        border: none;
    }

    >header
    {
        margin-block-end: 1.3rem;

        a[href^='mailto:']
        {
            &::before, &::after
            {
                display: inline-block;
            }

            &::before
            {
                content: "<";
            }

            &::after
            {
                content: ">";
            }

            @media (width <=500px)
            {
                display: none;
            }
        }

        span
        {
            display: inline-block;
            inline-size: 100%;

            &::before
            {
                font-weight: bolder;
                margin-inline-end: 1ch;
            }

            &.from::before
            {
                content: "From:";
            }

            &.date::before
            {
                content: "Date:";
            }

            &.subject::before
            {
                content: "Subject:";
            }

            &.message-id::before
            {
                content: "Message-Id:";
            }

            &.location::before
            {
                content: "Location:";
            }

            &.part::before
            {
                content: "Part:";
            }

            &.in-reply-to::before
            {
                content: "In-Reply-To:";
            }

            &.see-also::before
            {
                content: "See-Also:";
            }
        }
    }
}

span.currently-at
{
    font-style: normal;

    &::before
    {
        content: "⌘";
        padding-inline-end: 0.5ch;
        font-size: 1.15em;
    }
}

img
{
    width: 100%;
    height: auto;
    object-fit: contain;
    display: block;
}

details
{
    padding-inline: var(--padding);
    padding-block: var(--rider-padding);

    summary
    {
        cursor: pointer;
        margin-inline: calc(-1 * var(--padding));
        padding-inline: var(--padding);
    }

    &[open] summary
    {
        border-block-end: var(--line);
        padding-block-end: var(--rider-padding);
        margin-block-end: var(--padding);
    }

    article &
    {
        margin-block: 1em;
    }
}

figure
{
    margin-block: var(--padding);
    margin-inline: 0;
    overflow: clip;

    &.pair>*
    {
        border-radius: var(--radius);
    }

    & img
    {
        object-fit: cover;
    }

    >pre
    {
        margin: 0;
        overflow-x: auto;
    }


    &.pair
    {
        display: flex;
        column-gap: var(--padding);
        align-items: center;
        justify-content: center;
        margin-block: 2.4rem;

        >img
        {
            max-width: 45%;
        }
    }

    &.scroll
    {
        >:not(figcaption)
        {
            cursor: s-resize;
            display: flex;
            column-gap: var(--rider-padding);
            align-items: center;

            justify-content: start;
            /* border-radius: var(--radius); */
            margin: 0;

            overflow-x: auto;
            scroll-snap-type: x proximity;

            >img
            {
                width: auto !important;
            }

            >*
            {
                scroll-snap-align: start;
                margin: 0;
                max-height: min(500px, min(95vh, calc(100vh - calc(2*env(safe-area-inset-bottom)))));
            }
        }

        figcaption
        {
            &::after
            {
                content: " | scroll <-->";
            }

            &:empty::after
            {
                content: " scroll <-->";
            }
        }
    }

    &.preview
    {
        columns: 200px;
        gap: var(--padding);

        >*
        {
            border-radius: var(--radius);
            margin-block-end: inherit;
        }
    }
}

.float
{
    @media (width >600px)
    {
        max-width: 40%;
        margin-block-start: 0;

        &.start
        {
            float: inline-start;
            margin-inline-end: var(--padding);
        }

        &.end
        {
            float: inline-end;
            margin-inline-start: var(--padding);
        }
    }

    &.remain
    {
        max-width: 40%;
        margin-block-start: 0;

        &.start
        {
            float: inline-start;
            margin-inline-end: var(--padding);
        }

        &.end
        {
            float: inline-end;
            margin-inline-start: var(--padding);
        }
    }

    &~:not(p, h1, h2, h3, h4, h5, h6)
    {
        clear: both;
    }
}


figcaption
{
    text-align: end;
    border-block-start: none;
    padding-inline: 0.65em;
    padding-block: var(--rider-padding);
}

article>header, pre~figcaption, code, var
{
    font-family: noto-sans-mono, monospace;
    font-size: 90%;
}

img, video,
pre, var, code
{
    background: #e7e2dd;
}

pre
{
    code
    {
        display: block;
        margin: 0.5rem 0.8rem;
    }

    ~figcaption
    {
        border: none;
        background: #dbd5d0;
    }
}

:not(pre)>code
{
    white-space: pre-wrap;
}

mark, cite, del, ins, :not(pre)>code
{
    padding-inline: 0.6ch;
    border-radius: calc(var(--radius) / 2);
}