@import "variables.css";
@import "base.css";

html {
    background: var(--page-color);
    color: var(--page-contrast);
    /* container: html / inline-size; */
}

:link { color: var(--link-fg); }
:visited { color: var(--visited-fg); }

body {
    margin: 0;
}

#masthead, #skipnav:has(+ #masthead) {
    background-color: var(--masthead-color);
    color: var(--masthead-contrast);
}

#masthead {
    border-block-end: 1rem double var(--masthead-contrast);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-block-start: min(0, env(safe-area-inset-top));
    padding-inline-end: max(0.5rem, env(safe-area-inset-right));
    padding-block-end: 0;
    padding-inline-start: max(0.5rem, env(safe-area-inset-left));
}

#masthead :link { text-decoration: none; }

#masthead > hgroup > p, search button {
    font-family: var(--heading-font-stack);
    font-stretch: var(--heading-font-stretch);
}

#masthead :lang(und-fonipa) {
    font-size: 0.925em;
    color: currentColor;
    color: color-mix(in srgb, currentColor, var(--page-contrast));
}

#masthead > p {
    display: none;
    order: 2;
}

#masthead > hgroup > p {
    text-orientation: sideways;
    line-height: 1;
}

#masthead > p a {
    display: block;
}

#masthead > p img {
    aspect-ratio: 1;
    clip-path: circle(50% at 50% 50%);
    max-height: 100px;
    max-width: 100px;
}

#masthead > hgroup {
    max-width: 290px;
}

#masthead > p,
#masthead > hgroup > h1,
#masthead > hgroup > p {
    margin: 0;
    font-size: 1em;
    line-height: 1;
}

#masthead > hgroup > h1 {
    font-family: var(--brand-font-stack);
    font-stretch: var(--brand-font-stretch);
    font-style: var(--brand-font-style);
    font-weight: var(--brand-font-weight);
    background: var(--brand-color);
    background-clip: text;
    color: transparent;
}

#masthead > hgroup > h1 :link,
#masthead > hgroup > h1 :visited {
    color: inherit;
}

#masthead > hgroup > p {
    display: none;
}

@media (min-width: 330px) {
    #masthead > p {
        display: block;
    }
}

@media (min-width: 360px) {
    #masthead > hgroup {
        font-size: 1.375rem;
    }
}

@media (min-width: 500px) {
    #masthead > hgroup {
        max-width: 300px;
        font-size: 1.5rem;
    }
    #masthead > hgroup > p {
        display: block;
    }
    #masthead > p img {
        max-height: none;
        max-width: none;
    }
}

@media (min-width: 700px) {
    #masthead > hgroup {
        max-width: none;
        display: flex;
    }
}

@media (min-width: 800px) {
    #masthead > hgroup {
        display: block;
        max-width: none;
        font-size: 1.875rem;
    }
    aside.alert, aside.news {
        font-size: 1.1em;
    }
}

@media (min-width: 850px) {
    #masthead > hgroup {
        font-size: 2rem;
    }
}
@media (min-width: 930px) {
    #masthead > hgroup {
        font-size: 2.25rem;
    }
}
@media (min-width: 1010px) {
    #masthead > hgroup {
        font-size: 2.5rem;
    }
}
@media (min-width: 1100px) {
    #masthead > hgroup {
        font-size: 2.75rem;
    }
}

main {
    margin-block-start: 1rem;
}

main:has(> aside.alert), main:has(> aside.news) {
    margin-block-start: 0;
}

main > * {
    padding-inline-start: max(0.5rem, env(safe-area-inset-left));
    padding-inline-end: max(0.5rem, env(safe-area-inset-right));
}

main > :is(ul, ol),
main > :is(ul, ol) :is(ul, ol) {
    padding-inline-start: max(calc(1ic + 0.5rem), env(safe-area-inset-left));
}

main > ul {
    text-wrap: balance;
}

#hello, #muse, #writing-system {
    line-height: 1.7;
}

#hello > [lang] { display: block; }
#hello > :lang(zh),
#hello:lang(zh) > [lang] { display: inline; }

:lang(tok) #hello > [lang] { display: inline; }
:lang(tok) #hello > span:first-child,
:lang(tok) #hello > :lang(ja) {
    display: block;
}

:lang(zh) u {
    white-space: nowrap;
}

main > :is(h2, p, ul, search, #muse, #writing-system) {
    max-width: 40rem;
}

main hgroup p {
    line-height: 1.1;
}

h2 img {
    vertical-align: middle;
    width: 1em;
    height: auto;
    position: relative;
    top: -2px;
}

aside.alert, aside.news {
    padding-block: 0.25ic;
    text-align: center;
}

:is(aside.alert, aside.news) > :is(h2, h3) {
    font-size: 1em;
}

:is(aside.alert, aside.news) > :is(h2, h3),
:is(aside.alert, aside.news) > p {
    display: inline;
}

aside.news > :is(h2, h3), aside.news > :is(h2, h3)::after {
    color: var(--note-fg);
}

aside.news > :is(h2, h3)::after {
    content: ": ";
}

@media (min-width: 57em) {
    :is(aside.alert, aside.news) br {
        display: none;
    }
}

ul ul {
    margin-block-start: 0;
    margin-block-end: 0;
}

fieldset {
    border: none;
    margin: 0 0 1em 0;
    padding: 0;
}

legend {
    font-weight: bold;
    font-size: 1.625rem;
    margin: 0;
    padding: 0 0 0.5rem 0;
    line-height: 1;
}

input[type=search] {
    -webkit-appearance: textfield;
    max-width: 15rem;
}

input[type=search]::-webkit-search-decoration {
    display: none;
}

input, button {
    font-size: 1rem;
    height: auto;
    border: 1px solid #999;
    border-radius: 4px;
    margin: 0;
    padding: 0 0.5ch;
}

search button[type=submit] {
    border-color: #ccc;
    background: blue;
    color: white;
    font-weight: bold;
}

figure > img, figure > a > img {
    max-width: 100%;
    width: 100%;
}

#muse blockquote {
    font-style: italic;
    margin: 0;
}

#muse figcaption {
    text-align: left;
    text-indent: 2ch;
}

li del {
    text-decoration: line-through;
}

body > footer {
    text-align: center;
    padding-block-end: env(safe-area-inset-bottom);
}

@media (max-width: 350px) or (min-width: 1000px) {
    footer br {
        display: none;
    }
}

random-choice > * {
    width: 100%;
}

@media (min-width: 820px) { /* 11" iPad in portrait */
    main {
        display: grid;
        row-gap: 1rem;
        column-gap: 1ch;
        row-gap: 1ic;
        column-gap: 1ic;
        grid-template-columns: repeat(8, 1fr);
        align-items: baseline;
    }
    main > * {
        grid-column: 3 / 8;
        margin: 0;
    }
    main > #welcome {
        grid-column: 2 / 8;
        max-width: none;
    }
    main > random-choice, main > random-choice > * {
        grid-column: 2 / 8;
    }
    main > :is(h2, hgroup, h3) {
        grid-column: 1 / 3;
        text-align: right;
    }
    main > :is(#featured, #recent) + p + ul {
        grid-column: 3 / 9;
        max-width: none;
    }
    #hello {
        grid-column: 1 / 5;
        grid-row: 1;
        align-self: start;
        padding-inline-start: 1ic;
        padding-inline-end: 0;
    }
    search, #muse, #writing-system {
        grid-row: 1;
        align-self: start;
        grid-column: 5 / 9;
    }
    :is(aside.alert, aside.news) {
        grid-column: 1 / 9;
        grid-row: 1;
    }
    main:has(> aside.alert) > #hello,
    main:has(> aside.alert) > search,
    main:has(> aside.news) > #hello,
    main:has(> aside.news) > search {
        grid-row: 2;
    }
}

@media (min-width: 1200px) {
    #hello {
        grid-column: 2 / 5;
    }
    search, #muse, #writing-system {
        grid-column: 5 / 8;
    }
    #hello:lang(zh) {
        grid-column: 1 / 6;
        padding-left: 1ic;
    }
}

@media print {
    html {
        font-size: 100%;
    }
    #masthead > hgroup {
        font-size: 1.875rem;
    }
    #masthead > p img {
        max-height: 75px;
        max-width: 75px;
    }
    #masthead a[rel=help], #writing-system {
        display: none;
    }
    #hello {
        grid-column: 1 / 5;
    }
    #muse {
        grid-column: 5 / 9;
    }
    main > * {
        grid-column: 1 / 9;
    }
    main > :is(h2, hgroup, h3) {
        grid-column: 1 / 9;
        text-align: left;
    }
    search, #select-lang {
        display: none;
    }
    :link, :visited {
        color: black;
    }
    abbr[title]:not(.noexpand)::after {
        content: " (" attr(title) ")";
    }
}
