header {
    height: 5em;
    padding-left: 5em;
    padding-right: 5em;
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    align-items: center;
}

.header-logo {
    height: 3em;
}

.nav-buttons {
    background-color: white;
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-end;
    align-items: center;
    gap: 2em;
    flex: 1; /* take up remaining space so items can align right without overflow */
}

/* Style only direct children so nested dropdown divs aren't forced into the row. */
.nav-buttons > a {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
}

/* Only style top-level nav items, not the dropdown menu container */
.nav-buttons > .nav-item {
    display: inline-flex;
    align-items: center;
    color: inherit;
}

/* Hidden on desktop; toggles the menu on mobile */
.hamburger {
    display: none;
    background: none;
    border: none;
    padding: 0.5em 0;
    cursor: pointer;
}

/* Simple hamburger bars */
.hamburger .bar {
    display: block;
    width: 1.6em;
    height: 2px;
    background-color: black;
    margin: 0.2em 0;
    transition: transform 200ms ease, opacity 200ms ease;
}

/* Dropdown container stays in the main nav flow */
.dropdown {
    position: relative; /* anchor for the absolute menu */
}

/* Bridge the hover gap so the menu doesn't close when moving the mouse down */
.dropdown::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 0.4em;
    top: 100%;
}

/* Make the SERVICES button look like the other nav items */
.dropdown-toggle {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.6em;
    text-decoration: none;
}

/* Caret indicator for dropdown */
.dropdown-toggle::after {
    content: "";
    width: 0.35em;
    height: 0.35em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-0.1em) rotate(45deg); /* v-shaped caret aligned to text center */
}

/* Hidden menu that appears below SERVICES */
.dropdown-menu {
    position: absolute;
    top: calc(100% + .3em); /* add a bit of space below the toggle */
    left: -0.5em;
    display: none; /* hide by default */
    min-width: 12em;
    background-color: white;
    border: 2px solid transparent;
    padding: 0.5em 0;
    border-radius: 12px;
    box-shadow: none;
}


/* Stack menu items vertically */
.dropdown-menu a {
    display: block;
    padding: 0.5em 1em;
    text-decoration: none;
    color: inherit;
}

/* More specific selector wins in the cascade (this overrides .nav-buttons a). */
.nav-buttons a.get-started {
    color: rgb(255, 255, 255);
    background-color: rgb(0, 0, 0);
    padding: 0.5em 1.25em;
    border-radius: 999px;
    display: inline-block;
}

@media (max-width: 768px) {
    header {
        height: auto;
        padding-left: 1.5em;
        padding-right: 1.5em;
        flex-wrap: wrap;
        position: relative; /* anchor the mobile menu under the hamburger */
    }

    .hamburger {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    /* Hide the nav until the hamburger opens it */
    .nav-buttons {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        width: auto;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        margin-top: 0;
        padding-left: 1.5em;
        padding-right: 1.5em;
        padding-top: 1em;
        padding-bottom: 2em;
        border-top: 1px solid rgba(0, 0, 0, 0.15); /* thin separator under header */
        background-color: white;
        border-radius: 0 0 12px 12px;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        z-index: 10;
    }

    /* JS adds this class to show the menu */
    .nav-buttons.is-open {
        display: flex;
    }

    .nav-buttons > a,
    .nav-buttons > .nav-item {
        display: block;
        width: 100%;
        padding: 0.5em 0;
    }

    /* Keep the pill inside the menu width on mobile */
    .nav-buttons a.get-started {
        display: inline-block;
        width: auto;
        box-sizing: border-box;
        border-radius: 999px;
        background-color: black;
        color: white;
        padding: 0.5em 1.25em;
        text-align: left;
    }

    /* Let the dropdown menu flow naturally in the column layout */
    .dropdown-menu {
        position: static;
        border: none;
        padding: 0;
        background-color: transparent;
        margin-top: 0.5em; /* space between SERVICES and its items */
        border-radius: 0;
        display: block; /* always open in the hamburger menu */
    }

    /* Make SERVICES align above its dropdown items */
    .dropdown-toggle {
        width: 100%;
        text-align: left;
        padding: 0;
    }

    /* Remove caret in the hamburger menu */
    .dropdown-toggle::after {
        display: none;
    }

    .dropdown-menu a {
        padding-left: 1.25em; /* indent dropdown items */
    }

    /* Animate hamburger into an X when open */
    .hamburger.open .bar:nth-child(1) {
        transform: translateY(8.7px) rotate(45deg);
        transform-origin: center;
    }

    .hamburger.open .bar:nth-child(2) {
        opacity: 0;
    }

    .hamburger.open .bar:nth-child(3) {
        transform: translateY(-5px) rotate(-45deg);
        transform-origin: center;
    }

    /* Dim only the main content when the menu is open */
    .nav-overlay {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: 0;
        background: rgba(0, 0, 0, 0.35);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 220ms ease, visibility 0s linear 220ms;
        z-index: 5;
    }

    .nav-overlay.is-visible {
        opacity: 1;
        visibility: visible;
        transition: opacity 220ms ease;
    }

    /* Remove mobile tap highlight flashes */
    .nav-buttons > a,
    .dropdown-menu a,
    .dropdown-toggle {
        -webkit-tap-highlight-color: transparent;
        outline: none;
    }
}

@media (min-width: 769px) {
    /* Desktop-only hover styles */
    .nav-buttons > a:hover,
    .dropdown-toggle:hover {
        color: #666;
    }

    .dropdown:hover .dropdown-menu {
        display: block;
        border-color: rgba(0, 0, 0, 0.08);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    }

    .dropdown-menu a:hover {
        background-color: #f0f0f0;
    }

    .nav-buttons a.get-started:hover {
        color: black;
        background-color: aquamarine;
    }
}
