@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;
    tab-size: 4;

    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,
button
{
    font-family: inter, system-ui;
    font-weight: 600;
    font-feature-settings: "cv01" 1, "ss03" 1;
    text-wrap: balance;

    p
    {
        text-wrap: initial;
    }

    &:not(h1, h2, h3, h4, h5, h6, body>aside>header, button)
    {
        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 910px;
    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:";
            }

            &.last-updated::before
            {
                content: "Last-Updated:";
            }
        }
    }
}

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

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

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

details
{
    summary
    {
        cursor: pointer;
        padding-inline: var(--padding);
        padding-block: var(--rider-padding);
    }

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

        &::details-content
        {
            padding-inline: var(--padding);
        }
    }

    &:has(> summary:active)
    {
        transform-origin: center;
        transform: scale(0.98);
    }

    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)))));
            }
        }

        &.small-height>:not(figcaption)
        {
            >*
            {
                max-height: min(250px, 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
{
    --max-width: 40%;

    @media (width >600px)
    {
        max-width: var(--max-width);
        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: var(--max-width);
        margin-block-start: 0;

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

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

    &.small
    {
        --max-width: 30%;
    }

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

section
{
    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
{

    &:not(.no-background)
    {
        background: #e7e2dd;
    }
}

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

        &[data-language=json]
        {
            tab-size: 2;
        }
    }

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

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

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

button, details
{
    transition: transform 0.195s ease;
}

button
{
    appearance: none;
    background: none;
    border: var(--line);
    border-radius: 31.7rem;
    padding-inline: var(--padding);
    padding-block: 0.35rem;
    cursor: pointer;

    &:hover
    {
        background-color: #373737;
        color: #fbf7f0;
    }

    &:active
    {
        transform-origin: center;
        transform: scale(0.97);
    }
}

/* ------- experimental ------- */
details-tabgroup
{
    &[tabs="2"]
    {
        --tabs: 2;
    }

    &[tabs="3"]
    {
        --tabs: 3;
    }

    &[tabs="4"]
    {
        --tabs: 4;
    }

    &[tabs="5"]
    {
        --tabs: 5;
    }

    position: relative;
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: repeat(var(--tabs), auto);

    &>details
    {
        display: contents;

        &>summary
        {
            grid-row: 1;
            border-block-start: var(--line);
            border-inline-end: var(--line);
            border-block-end: none;
            display: flex;
            justify-content: start;

            &::marker
            {
                display: none;
                content: "";
            }
        }

        &:first-child>summary
        {
            border-inline-start: var(--line);
            border-start-start-radius: var(--radius);
        }

        &:last-child>summary
        {
            border-start-end-radius: var(--radius);
        }

        &>*:not(summary)
        {
            border: var(--line);
            border-radius: 0;
            border-end-end-radius: var(--radius);
            border-end-start-radius: var(--radius);

            grid-column: 1 / -1;
        }

        &[open]
        {
            >summary
            {
                background-color: #373737;
                color: #fbf7f0;
            }

            &::details-content
            {
                display: contents;
            }

            &::details-content
            {
                padding-inline: var(--padding);
            }
        }

        >figure
        {
            margin-block: 0;

            >figcaption
            {
                border-radius: 0;
            }
        }

        >*:not(summary)
        {
            overflow: clip;
            overflow-x: auto;


        }
    }
}