.top-nav-shell {
    border-bottom: 1px solid var(--ui-border-subtle);
    margin: 0 -24px 18px;
    padding: 0 24px;
    background: var(--ui-surface);
}

.top-nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    min-height: 80px;
    display: grid;
    grid-template-columns: minmax(max-content, auto) minmax(0, 1fr) max-content;
    grid-template-areas:
        "brand nav preferences";
    align-items: center;
    gap: 6px;
    padding: 10px 0;
}

.top-nav-brand-row {
    grid-area: brand;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    max-width: 100%;
    min-width: 0;
    flex-wrap: nowrap;
}

.top-nav-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    max-width: 100%;
    min-width: 0;
    color: var(--ui-text-heading);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0;
    text-align: center;
    white-space: normal;
}

.top-nav-brand-icon {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.brand-title {
    display: block;
    max-width: 100%;
    font-family: ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: clamp(0.78rem, 2.8vw, 1rem);
    font-weight: 600;
    letter-spacing: 0.015em;
    line-height: 1;
    white-space: nowrap;
}

.brand-mark {
    font-size: 0.62em;
    vertical-align: super;
    margin-left: 0.08em;
    font-weight: 700;
}

.top-nav-list {
    grid-area: nav;
    justify-self: start;
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 4px;
}

.top-nav-list > li {
    display: flex;
    align-items: center;
}

.top-nav-list > li > details {
    display: flex;
    align-items: center;
}

.top-nav-preferences {
    grid-area: preferences;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.top-nav-label-mobile {
    display: none;
}

.top-nav-secondary {
    grid-area: nav;
    justify-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 0;
    width: 100%;
}

.top-nav-secondary > .top-nav-list {
    flex: 1 1 auto;
    min-width: 0;
    grid-area: auto;
    justify-self: auto;
}

.top-nav-language {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.top-nav-language-label {
    color: var(--ui-text-muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.top-nav-menu {
    position: relative;
    margin: 0;
}

.top-nav-menu > summary {
    list-style: none;
}

.top-nav-menu > summary::-webkit-details-marker {
    display: none;
}

.top-nav-menu-toggle {
    cursor: pointer;
}

.top-nav-menu-toggle::after {
    content: "▾";
    margin-left: 6px;
    font-size: 0.78em;
    line-height: 1;
    color: currentColor;
}

.top-nav-menu[open] > .top-nav-menu-toggle::after,
.top-nav-menu:hover > .top-nav-menu-toggle::after,
.top-nav-menu:focus-within > .top-nav-menu-toggle::after {
    transform: rotate(180deg);
}

.top-nav-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    display: none;
    min-width: 240px;
    padding: 8px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    box-shadow: 0 12px 24px var(--ui-shadow-3);
}

.top-nav-dropdown-group {
    display: grid;
    gap: 2px;
}

.top-nav-dropdown-separator {
    width: 100%;
    margin: 6px 0;
    border: 0;
    border-top: 1px solid var(--ui-border-subtle);
}

.top-nav-menu[open] > .top-nav-dropdown,
.top-nav-menu:hover > .top-nav-dropdown,
.top-nav-menu:focus-within > .top-nav-dropdown {
    display: grid;
    gap: 2px;
}

.top-nav-dropdown-link {
    width: 100%;
    justify-content: flex-start;
    height: auto;
    min-height: 36px;
    padding: 8px 10px;
    border-color: transparent;
}

.top-nav-language-select {
    width: 100%;
    min-height: 32px;
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    background: var(--ui-surface);
    color: var(--ui-text-heading);
    padding: 0 8px;
    font-size: 13px;
}

.top-nav-language-dropdown {
    min-width: 190px;
}

.top-nav-language-menu > .top-nav-dropdown {
    left: auto;
    right: 0;
}

.top-nav-language-option {
    background: transparent;
    font: inherit;
    cursor: pointer;
}

.top-nav-theme-toggle {
    background: transparent;
    font: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.top-nav-language-option.is-active {
    color: var(--ui-text-heading);
    background: var(--ui-surface-muted);
    border-color: var(--ui-border);
    font-weight: 600;
}

.top-nav-link {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 12px;
    border-radius: 6px;
    color: var(--ui-text);
    text-decoration: none;
    border: 1px solid transparent;
}

.top-nav-link:hover {
    background: var(--ui-surface-muted);
}

.top-nav-link:focus-visible {
    outline: 2px solid var(--ui-focus-ring);
    outline-offset: 2px;
}

.top-nav-link.is-active {
    color: var(--ui-text-heading);
    background: var(--ui-surface-muted);
    border-color: var(--ui-border);
    font-weight: 600;
}

@media (max-width: 900px) {
    .top-nav-shell {
        margin: 0 -16px 16px;
        padding: 0 16px;
    }

    .top-nav-inner {
        min-height: 78px;
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "brand"
            "preferences"
            "nav";
    }

    .top-nav-brand {
        font-size: 13px;
    }

    .top-nav-brand-row {
        justify-self: stretch;
        justify-content: center;
        gap: 10px;
    }

    .top-nav-brand {
        flex: 0 1 auto;
    }

    .brand-title {
        white-space: normal;
    }

    .top-nav-list {
        justify-self: center;
        gap: 2px;
        flex-wrap: wrap;
    }

    .top-nav-preferences {
        justify-self: center;
    }

    .top-nav-label-desktop {
        display: none;
    }

    .top-nav-label-mobile {
        display: inline;
    }

    .top-nav-secondary {
        gap: 10px;
    }

    .top-nav-link {
        height: 34px;
        padding: 0 10px;
        font-size: 13px;
    }

    .top-nav-menu {
        width: auto;
    }

    .top-nav-dropdown {
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        right: auto;
        display: none;
        min-width: 0;
        width: min(190px, calc(100vw - 32px));
        max-width: calc(100vw - 32px);
        padding: 8px;
        box-shadow: 0 12px 24px var(--ui-shadow-3);
        z-index: 40;
        max-height: calc(100vh - 32px);
        overflow: auto;
    }

    .top-nav-menu[data-nav-menu="settings"] > .top-nav-dropdown {
        left: auto;
        right: 0;
    }

    .top-nav-menu[data-nav-menu="language"] > .top-nav-dropdown {
        left: auto;
        right: 0;
    }

    .top-nav-menu[data-nav-menu="analysis"] > .top-nav-dropdown {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    .top-nav-menu[open] > .top-nav-dropdown,
    .top-nav-menu:hover > .top-nav-dropdown,
    .top-nav-menu:focus-within > .top-nav-dropdown {
        display: grid;
    }

    .top-nav-language-dropdown {
        min-width: 0;
        width: min(190px, calc(100vw - 32px));
    }

    .top-nav-language-select {
        min-height: 30px;
    }
}

@media (max-width: 430px) and (orientation: portrait) {
    .top-nav-list {
        flex-wrap: nowrap;
    }

    .top-nav-list .top-nav-link {
        padding: 0 6px;
        font-size: 12px;
    }
}
