/* Language switcher and script/direction adjustments shared by every page. */
.lang-switch {
    --lang-fg: currentColor;
    --lang-menu-bg: #fffdf8;
    --lang-menu-fg: #1f2420;
    --lang-menu-line: rgba(31, 36, 32, 0.14);
    --lang-menu-hover: rgba(31, 36, 32, 0.07);
    --lang-menu-current: #2f6b4f;
    position: relative;
    display: inline-block;
    flex: 0 0 auto;
    font-size: 0.82rem;
    line-height: 1.2;
}

.lang-switch > summary {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 0.4em;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    color: var(--lang-fg);
    cursor: pointer;
    list-style: none;
    white-space: nowrap;
    user-select: none;
}

.lang-switch > summary::-webkit-details-marker {
    display: none;
}

.lang-switch > summary:hover {
    background: color-mix(in srgb, currentColor 9%, transparent);
}

.lang-switch > summary:focus-visible,
.lang-switch-menu a:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.lang-switch-icon {
    flex: 0 0 auto;
}

.lang-switch-caret {
    flex: 0 0 auto;
    transition: transform 0.15s ease-out;
}

.lang-switch[open] .lang-switch-caret {
    transform: rotate(180deg);
}

.lang-switch-menu {
    position: absolute;
    z-index: 1000;
    inset-block-start: calc(100% + 0.35rem);
    inset-inline-end: 0;
    display: grid;
    width: max-content;
    max-width: min(26rem, calc(100vw - 1.5rem));
    max-height: min(70vh, 32rem);
    margin: 0;
    padding: 0.4rem;
    grid-template-columns: repeat(2, minmax(9rem, 1fr));
    gap: 0.1rem 0.3rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--lang-menu-line);
    border-radius: 0.75rem;
    color: var(--lang-menu-fg);
    background: var(--lang-menu-bg);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
    list-style: none;
    text-align: start;
}

.lang-switch-menu li {
    margin: 0;
    padding: 0;
}

details.lang-switch ul.lang-switch-menu a {
    display: flex;
    place-items: initial;
    justify-content: flex-start;
    border: 0;
    background: none;
    box-shadow: none;
    transform: none;
    flex: none;
    min-height: 40px;
    align-items: center;
    padding: 0.4rem 0.65rem;
    border-radius: 0.5rem;
    color: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    letter-spacing: normal;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
}

details.lang-switch ul.lang-switch-menu a:hover {
    background: var(--lang-menu-hover);
}

details.lang-switch ul.lang-switch-menu a[aria-current="true"] {
    color: var(--lang-menu-current);
    font-weight: 700;
}

details.lang-switch ul.lang-switch-menu a[aria-current="true"]::after {
    content: "✓";
    margin-inline-start: auto;
    padding-inline-start: 0.6rem;
}

@media (prefers-color-scheme: dark) {
    .lang-switch {
        --lang-menu-bg: #1d2321;
        --lang-menu-fg: #eef2ec;
        --lang-menu-line: rgba(238, 242, 236, 0.16);
        --lang-menu-hover: rgba(238, 242, 236, 0.09);
        --lang-menu-current: #9fd8b3;
    }
}

/* Hitloom pages are always dark. */
.hitloom-page .lang-switch {
    --lang-menu-bg: #1d1f1c;
    --lang-menu-fg: #f0ede4;
    --lang-menu-line: rgba(240, 237, 228, 0.16);
    --lang-menu-hover: rgba(240, 237, 228, 0.08);
    --lang-menu-current: #ff8b6b;
}

.lang-switch-standalone {
    position: absolute;
    inset-block-start: 0.75rem;
    inset-inline-end: 0.75rem;
}

.legal-binding-note {
    margin: 0 0 1.5rem;
    padding: 0.8rem 1rem;
    border-inline-start: 3px solid currentColor;
    border-radius: 0.4rem;
    background: color-mix(in srgb, currentColor 6%, transparent);
    font-size: 0.92em;
}

@media (max-width: 560px) {
    .lang-switch-current {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    /* Anchor the menu to the page width instead of the (possibly wrapped) button. */
    .lang-switch {
        position: static;
    }

    .lang-switch-menu {
        inset-block-start: auto;
        inset-inline: 0.75rem;
        width: auto;
        max-width: none;
        max-height: 70vh;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    details.lang-switch ul.lang-switch-menu a {
        white-space: normal;
    }
}

/* Long compound words (de, nl, fi-like, ta, ml…) wrap instead of overflowing. */
:lang(de) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(nl) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(sv) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(hu) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(el) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(ta) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(te) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(ru) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(uk) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(pl) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(cs) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(fr) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(it) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(es) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(pt-BR) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(ro) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(tr) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(id) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(ms) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(sw) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span),
:lang(vi) :is(h1, h2, h3, h4, p, li, a, button, th, td, summary, label, span) {
    overflow-wrap: break-word;
    hyphens: auto;
}

:lang(ja) :is(h1, h2, h3, h4),
:lang(ko) :is(h1, h2, h3, h4),
:lang(zh-Hans) :is(h1, h2, h3, h4),
:lang(zh-Hant) :is(h1, h2, h3, h4) {
    word-break: normal;
    line-break: strict;
    overflow-wrap: anywhere;
}

:lang(ko) :is(h1, h2, h3, h4, p, li) {
    word-break: keep-all;
}

/*
 * Cursive and complex scripts: tracking breaks Arabic joining and crowds
 * Indic/Thai clusters; tight display line heights clip their marks. System
 * fonts that cover each script are listed before the generic fallback.
 */
:lang(ar) *, :lang(fa) *, :lang(ur) *,
:lang(hi) *, :lang(mr) *, :lang(bn) *, :lang(ta) *, :lang(te) *, :lang(th) * {
    letter-spacing: normal !important;
}

:lang(ar) :is(h1, h2, h3, h4), :lang(fa) :is(h1, h2, h3, h4), :lang(ur) :is(h1, h2, h3, h4),
:lang(hi) :is(h1, h2, h3, h4), :lang(mr) :is(h1, h2, h3, h4), :lang(bn) :is(h1, h2, h3, h4),
:lang(ta) :is(h1, h2, h3, h4), :lang(te) :is(h1, h2, h3, h4), :lang(th) :is(h1, h2, h3, h4) {
    line-height: 1.35 !important;
}

:lang(ja) :is(h1, h2, h3), :lang(ko) :is(h1, h2, h3),
:lang(zh-Hans) :is(h1, h2, h3), :lang(zh-Hant) :is(h1, h2, h3),
:lang(el) :is(h1, h2, h3), :lang(ru) :is(h1, h2, h3), :lang(uk) :is(h1, h2, h3), :lang(vi) :is(h1, h2, h3) {
    line-height: 1.2 !important;
}

:lang(ar) body, :lang(fa) body {
    font-family: system-ui, -apple-system, "Segoe UI", "Geeza Pro", "Noto Sans Arabic", Tahoma, sans-serif;
}

:lang(ur) body {
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Nastaliq Urdu", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
}

:lang(hi) body, :lang(mr) body {
    font-family: system-ui, -apple-system, "Kohinoor Devanagari", "Nirmala UI", "Noto Sans Devanagari", "Mangal", sans-serif;
}

:lang(bn) body {
    font-family: system-ui, -apple-system, "Kohinoor Bangla", "Nirmala UI", "Noto Sans Bengali", "Vrinda", sans-serif;
}

:lang(ta) body {
    font-family: system-ui, -apple-system, "Tamil Sangam MN", "Nirmala UI", "Noto Sans Tamil", "Latha", sans-serif;
}

:lang(te) body {
    font-family: system-ui, -apple-system, "Kohinoor Telugu", "Telugu Sangam MN", "Nirmala UI", "Noto Sans Telugu", "Gautami", sans-serif;
}

:lang(th) body {
    font-family: system-ui, -apple-system, "Thonburi", "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
}

:lang(ja) body {
    font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
}

:lang(ko) body {
    font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

:lang(zh-Hans) body {
    font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

:lang(zh-Hant) body {
    font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

/* Non-Latin headings use the page's typeface where it has glyphs, then system fonts. */
:lang(ar) :is(h1, h2, h3, h4, em), :lang(fa) :is(h1, h2, h3, h4, em), :lang(ur) :is(h1, h2, h3, h4, em),
:lang(hi) :is(h1, h2, h3, h4, em), :lang(mr) :is(h1, h2, h3, h4, em), :lang(bn) :is(h1, h2, h3, h4, em),
:lang(ta) :is(h1, h2, h3, h4, em), :lang(te) :is(h1, h2, h3, h4, em), :lang(th) :is(h1, h2, h3, h4, em),
:lang(ja) :is(h1, h2, h3, h4, em), :lang(ko) :is(h1, h2, h3, h4, em),
:lang(zh-Hans) :is(h1, h2, h3, h4, em), :lang(zh-Hant) :is(h1, h2, h3, h4, em) {
    font-style: normal;
}

/* Right-to-left: keep code, versions, keys and LTR samples readable. */
[dir="rtl"] :is(code, kbd, pre, samp, .code, .comparison-ms, .comparison-bar-value, .release-version, .release-badge-number) {
    direction: ltr;
    unicode-bidi: isolate;
}

[dir="rtl"] time {
    unicode-bidi: isolate;
}

/* Bold runs often hold file names, UI names or versions: order them by their own first strong character. */
[dir="rtl"] :is(strong, b) {
    unicode-bidi: plaintext;
}

[dir="rtl"] .lang-switch-caret {
    transform: none;
}

[dir="rtl"] .lang-switch[open] .lang-switch-caret {
    transform: rotate(180deg);
}

/* Translated navigation labels are longer than English: let headers wrap instead of overflowing. */
@media (max-width: 600px) {
    :not(:lang(en)) > .home-site-header {
        flex-wrap: wrap;
        row-gap: 0.25rem;
    }

    :not(:lang(en)) > .home-site-header .home-nav {
        flex-wrap: wrap;
        justify-content: flex-end;
        margin-inline-start: auto;
    }
}

@media (max-width: 560px) {
    .lang-switch > summary {
        padding-inline: 0.4rem;
    }
}

/* CJK: break headlines at phrase boundaries and keep full-width glyphs inside narrow screens. */
:lang(ja) :is(h1, h2, h3) {
    word-break: auto-phrase;
}

@media (max-width: 560px) {
    :is(:lang(ja), :lang(zh-Hans), :lang(zh-Hant), :lang(ko)) .home-hero h1 {
        font-size: clamp(2.2rem, 10.5vw, 4rem) !important;
    }
}
