/* Shared header grouping for primary, tool, and trust navigation. */
.nav-links {
    align-items: center;
    row-gap: 0.25rem;
}

.nav-section-label {
    flex: 0 0 100%;
    margin-top: 0.2rem;
    padding: 0.35rem 0.75rem 0.15rem;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.nav-link.nav-secondary,
.nav-link.nav-legal {
    white-space: nowrap;
}

.mobile-nav-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.mobile-nav-button {
    display: none;
}

/* Also covers older headers that have not yet received the helper classes. */
.nav-links > a[href$="keyboard-tester.html"],
.nav-links > a[href$="privacy-policy.html"] {
    border-left: 1px solid var(--border);
    margin-left: 0.25rem;
    padding-left: 1.15rem;
}

@media (max-width: 768px) {
    .nav-container {
        position: relative;
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 0.8rem 1rem;
    }

    .logo {
        order: 1;
        margin-right: auto;
    }

    .mobile-nav-button {
        order: 2;
        display: inline-flex;
        width: 40px;
        height: 40px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 1px solid var(--border);
        border-radius: 6px;
        background: var(--surface-hover);
        cursor: pointer;
    }

    .mobile-nav-button span {
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .mobile-nav-toggle:checked + .mobile-nav-button {
        background: var(--accent);
        color: white;
    }

    .mobile-nav-toggle:checked + .mobile-nav-button span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .mobile-nav-toggle:checked + .mobile-nav-button span:nth-child(2) {
        opacity: 0;
    }

    .mobile-nav-toggle:checked + .mobile-nav-button span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .nav-controls {
        order: 3;
    }

    .nav-links {
        order: 4;
        display: none;
        flex: 0 0 100%;
        flex-wrap: wrap;
        align-content: flex-start;
        width: 100%;
        max-height: min(70vh, 520px);
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: 0 10px 24px var(--shadow);
    }

    .mobile-nav-toggle:checked ~ .nav-links {
        display: flex;
    }

    .nav-links {
        justify-content: center;
        width: 100%;
    }

    .nav-section-label {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
        text-align: left;
    }

    .nav-links > a[href$="keyboard-tester.html"],
    .nav-links > a[href$="privacy-policy.html"] {
        margin-left: 0;
        padding-left: 1rem;
    }
}
