#nheader {
    position: sticky;
    top: 0;
    z-index: 60;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid #e4e7ec;
    box-shadow: 0 4px 20px rgba(16, 24, 40, 0.035);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

#nheader .nheader-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(1180px, calc(100% - 40px));
    max-width: none;
    height: 70px;
    margin: 0 auto;
    padding: 0;
}

#nheader .nheader-brand {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
}

#nheader img {
    display: block;
    width: 155px;
    max-width: 100%;
    height: auto;
}

#nheader nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

#nheader nav a {
    margin: 0;
    padding: 9px 12px;
    border-radius: 999px;
    color: #475467;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.4;
    letter-spacing: -0.01em;
    text-decoration: none;
}

#nheader nav a:hover {
    color: #111827;
    background: #f2f4f7;
}

#nheader nav a[aria-current="page"] {
    color: #4d49e5;
    background: #ecebff;
}

#nheader .language-menu {
    position: relative;
    flex: 0 0 auto;
    margin-inline-start: 4px;
    color: #475467;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#nheader .language-menu summary {
    display: inline-flex;
    min-width: 52px;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 11px;
    border: 1px solid #dfe3e9;
    border-radius: 999px;
    background: #fff;
    color: #344054;
    cursor: pointer;
    font-size: 12px;
    font-weight: 750;
    line-height: 1;
    list-style: none;
    user-select: none;
}

#nheader .language-menu summary::-webkit-details-marker {
    display: none;
}

#nheader .language-menu summary::after {
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    content: "";
    transform: translateY(-2px) rotate(45deg);
    transition: transform 160ms ease;
}

#nheader .language-menu summary:hover,
#nheader .language-menu[open] summary {
    border-color: #c9c7f7;
    background: #f5f4ff;
    color: #3f3bd3;
}

#nheader .language-menu summary:focus-visible {
    outline: 3px solid rgba(77, 73, 229, 0.28);
    outline-offset: 2px;
}

#nheader .language-menu[open] summary::after {
    transform: translateY(2px) rotate(225deg);
}

#nheader .language-menu__panel {
    position: absolute;
    z-index: 80;
    inset-block-start: calc(100% + 10px);
    inset-inline-end: 0;
    display: grid;
    width: min(360px, calc(100vw - 28px));
    max-height: min(430px, calc(100vh - 100px));
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    padding: 10px;
    overflow-y: auto;
    border: 1px solid #e1e4ea;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 20px 50px rgba(16, 24, 40, 0.17);
    animation: language-menu-in 150ms ease-out both;
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

#nheader .language-menu__panel a {
    display: flex !important;
    min-width: 0;
    align-items: center;
    margin: 0 !important;
    padding: 10px 11px !important;
    border-radius: 8px !important;
    color: #344054 !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
    white-space: normal;
}

#nheader .language-menu__panel a:hover {
    background: #f2f4f7 !important;
    color: #111827 !important;
}

#nheader .language-menu__panel a[aria-current="true"] {
    background: #ecebff !important;
    color: #3f3bd3 !important;
}

@keyframes language-menu-in {
    from { opacity: 0; transform: translateY(-5px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Keep legacy Speaking pages aligned even when an older topic stylesheet is cached. */
body.speaking-page #nheader {
    background: rgba(255, 255, 255, 0.92) !important;
    border-bottom-color: #e4e7ec !important;
}

body.speaking-page #nheader .nheader-wrap {
    height: 70px !important;
}

body.speaking-page #nheader nav a {
    color: #475467 !important;
}

body.speaking-page #nheader nav a:hover {
    color: #111827 !important;
    background: #f2f4f7 !important;
}

body.speaking-page #nheader nav a[aria-current="page"] {
    color: #4d49e5 !important;
    background: #ecebff !important;
}

@media (max-width: 680px) {
    #nheader .nheader-wrap {
        width: min(100% - 28px, 1180px);
    }

    #nheader nav a {
        display: none;
    }

    #nheader nav a:nth-child(2),
    #nheader nav a:nth-child(3) {
        display: inline-flex;
        padding: 8px 9px;
        font-size: 12px;
    }

    #nheader .language-menu {
        margin-inline-start: 0;
    }

    #nheader .language-menu__panel {
        position: fixed;
        inset-block-start: 64px;
        inset-inline-end: 14px;
    }
}

@media (max-width: 480px) {
    #nheader img {
        width: 140px;
    }

    #nheader nav a:nth-child(2) {
        display: none !important;
    }

    #nheader nav a:nth-child(3) {
        display: inline-flex !important;
    }

    #nheader .language-menu summary {
        min-width: 48px;
        padding-inline: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #nheader .language-menu summary::after,
    #nheader .language-menu__panel {
        animation: none;
        transition: none;
    }
}
