/*=============== LANGUAGES (see assets/js/i18n.js) ===============*/

/* Hide the page for the split second it takes to swap in a saved language,
   so visitors don't see English flash first. The inline head script lifts
   this after 2.5s at most, even if the translation never arrives. */
html.i18n-pending body { opacity: 0; }

/* Scripts with their own letters: Poppins has none, so these take over
   letter by letter while Latin text and numbers stay in Poppins. */
html[lang="am"] {
    --body-font: 'Poppins', 'Noto Sans Ethiopic', 'Nyala', 'Abyssinica SIL', sans-serif;
}
html[lang="ar"] {
    --body-font: 'Noto Sans Arabic', 'Poppins', 'Segoe UI', Tahoma, sans-serif;
}
/* Ethiopic and Arabic letters need more room than tight Latin headings. */
html[lang="am"] :is(h1, h2, h3),
html[lang="ar"] :is(h1, h2, h3) { line-height: 1.35; letter-spacing: 0; }
html[lang="ar"] body { letter-spacing: 0; }

/* ---------- the globe menu ---------- */
.lang-switch {
    position: relative;
    display: inline-flex;
    font-family: 'Poppins', 'Noto Sans Ethiopic', 'Noto Sans Arabic', sans-serif;
}
.lang-switch__button {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    height: 2.25rem;
    padding: 0 .7rem;
    border: 1px solid hsla(0, 0%, 50%, .3);
    border-radius: 999px;
    background: transparent;
    color: var(--title-color, #222);
    font: inherit;
    font-size: .8rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: border-color .2s, color .2s, background-color .2s;
}
.lang-switch__button i { font-size: 1.05rem; }
.lang-switch__button:hover,
.lang-switch__button[aria-expanded="true"] {
    border-color: #2C5E48;
    background: hsla(152, 36%, 27%, .12);
}
.lang-switch__button:focus-visible,
.lang-switch__option:focus-visible {
    outline: 2px solid #E8A33D;
    outline-offset: 2px;
}
.lang-switch__list {
    position: absolute;
    top: calc(100% + .5rem);
    inset-inline-end: 0;
    z-index: 200;
    min-width: 11rem;
    margin: 0;
    padding: .4rem;
    list-style: none;
    border: 1px solid hsla(0, 0%, 50%, .22);
    border-radius: .9rem;
    background: var(--container-color, #fff);
    box-shadow: 0 16px 40px rgba(0, 0, 0, .28);
}
.lang-switch__list[hidden] { display: none; }
.lang-switch__option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: .6rem .75rem;
    border: 0;
    border-radius: .6rem;
    background: transparent;
    color: var(--title-color, #222);
    font: inherit;
    font-size: .92rem;
    text-align: start;
    cursor: pointer;
}
.lang-switch__option:hover { background: hsla(152, 36%, 40%, .14); }
.lang-switch__option[aria-current]::after {
    content: '\eb7b'; /* remixicon check-line */
    font-family: 'remixicon';
    color: #3F9A6F;
}
.lang-switch__option[aria-current] { font-weight: 600; }

/* Certificate page top bar uses its own palette. */
.cv-topbar__actions .lang-switch__button { height: 2.5rem; color: var(--cv-title, inherit); border-color: var(--cv-border, hsla(0,0%,50%,.3)); }
.cv-topbar__actions .lang-switch__list { background: var(--cv-surface, var(--container-color, #fff)); }

/* Main navbar on phones: logo, globe, theme and menu buttons share the pill,
   so the globe drops its letters and the buttons sit a little closer. */
@media screen and (max-width: 767px) {
    .nav__btns { column-gap: .7rem; }
    .nav__btns .lang-switch__button { width: 2.25rem; padding: 0; justify-content: center; }
    .nav__btns .lang-switch__code { display: none; }
}
@media screen and (max-width: 389px) {
    .nav__btns { column-gap: .5rem; }
    .nav__logo-image { height: 1.55rem; }
}
@media screen and (max-width: 339px) {
    .nav__logo-image { height: 1.35rem; }
}
/* Blog header on small phones: the back link keeps only its arrow (the
   words stay readable to screen readers). */
@media screen and (max-width: 480px) {
    .bp-back { font-size: 0; gap: 0; padding: .55rem .7rem; }
    .bp-back i { font-size: 1.1rem; }
}

/* Certificate page on phones: logo, globe, back arrow and theme button
   share one pill, so the globe drops its letters there. */
@media screen and (max-width: 576px) {
    .cv-topbar__actions { gap: .4rem; }
    .cv-topbar__actions .lang-switch__button { width: 2.5rem; padding: 0; justify-content: center; }
    .cv-topbar__actions .lang-switch__code { display: none; }
    .cv-topbar__logo { max-width: 46vw; }
}

@media screen and (max-width: 359px) {
    .lang-switch__button { padding: 0 .5rem; }
    .lang-switch__code { display: none; }
}

/* ---------- navbar room for longer labels ---------- */
/* Oromo and Swahili menu words are longer than English ones. */
@media screen and (min-width: 1024px) {
    html[lang="om"] .nav__list,
    html[lang="sw"] .nav__list { column-gap: 1.5rem; }
    html[lang="om"] .nav__list { column-gap: 1.15rem; }
    html[lang="om"] .nav { column-gap: 2rem; }
}
/* If the links still don't fit (i18n.js measures this and adds the class),
   use the same slide-out menu as tablets. */
@media screen and (min-width: 1024px) {
    html.nav-compact .nav__toggle { display: inline-flex; }
    html.nav-compact .nav__close { display: block; }
    html.nav-compact .nav__menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: min(80%, 360px);
        height: 100%;
        margin-left: 0;
        padding: 4rem 0 0 3rem;
        background-color: var(--container-color);
        box-shadow: -2px 0 4px hsla(var(--hue), 24%, 15%, .1);
        border-radius: 1rem 0 0 1rem;
        transition: .3s;
        z-index: var(--z-fixed);
    }
    html.nav-compact .nav__menu.show-menu { right: 0; }
    html.nav-compact .nav__list { flex-direction: column; row-gap: 1.5rem; }
    html.nav-compact[dir="rtl"] .nav__menu { padding: 4rem 3rem 0 1.5rem; }
    html.nav-compact[dir="rtl"] .nav__close { right: auto; left: 1.25rem; }
}

/*=============== RIGHT-TO-LEFT (Arabic) ===============*/
/* Flex and grid layouts flip on their own with dir="rtl"; these cover the
   bits that use left/right directly. */
[dir="rtl"] :is(.ri-arrow-right-line, .ri-arrow-left-line, .ri-arrow-right-up-line, .ri-arrow-right-s-line, .ri-arrow-left-s-line) {
    display: inline-block;
    transform: scaleX(-1);
}
[dir="rtl"] body { text-align: right; }
/* Phone/tablet slide-out menu: its padding and close button sit on the
   left for English, so mirror them. */
@media screen and (max-width: 1023px) {
    [dir="rtl"] .nav__menu { padding: 4rem 3rem 0 1.5rem; }
    [dir="rtl"] .nav__close { right: auto; left: 1.25rem; }
}
[dir="rtl"] input, [dir="rtl"] textarea { text-align: right; }
/* Email addresses, phone numbers and links stay left to right. */
[dir="rtl"] :is(a[href^="mailto:"], a[href^="tel:"], input[type="email"], input[type="tel"], input[type="url"]) {
    direction: ltr;
    unicode-bidi: isolate;
}
