/* ==========================================================================
   HEADER
   desktop (>= 960px): fixed, shrinks from 152px to 120px while scrolling (scroll-driven animation).
   mobile (< 960px): scrolls with the page. the menu is an off-canvas panel,
   toggled by the #header-menu-toggle checkbox (css only, no js).
   ========================================================================== */

.header {
    position: relative;
    z-index: 1001;
    background: var(--color-white);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(var(--content-max-width), 90%);
    margin-inline: auto;
}

/* the padding lives on the logo, so the menu is centered within the full header height. */
.header-logo-link {
    display: block;
    flex: 0 1 275px;
    max-width: calc(100% - 80px);
    padding-top: 7px;
    padding-bottom: 15px;
}

.header-logo {
    display: block;
    width: 100%;
    height: auto;
}

.header-menu {
    margin: 0;
    padding: 0;
    list-style: none;
}

.header-menu a {
    display: block;
    text-decoration: none;
}


/* --------------------------------------------------------------------------
   mobile: toggle button + off-canvas panel
   -------------------------------------------------------------------------- */

@media (max-width: 959px) {

    /* visually hidden, but still focusable and toggleable by keyboard. */
    .header-menu-checkbox {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .header-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: 1px solid var(--color-grey-200);
        border-radius: 3px;
        background: var(--color-grey-100);
        color: var(--color-green-light);
        font-size: 25px;
        cursor: pointer;
        transition: background-color .15s, color .15s;
    }

    .header-menu-toggle:hover {
        background: var(--color-green);
        color: var(--color-white);
    }

    .header-menu-checkbox:focus-visible + .header-menu-toggle {
        outline: 2px solid var(--color-blue);
        outline-offset: 2px;
    }

    .header-nav {
        position: fixed;
        top: var(--admin-bar-height);
        right: 0;
        bottom: 0;
        z-index: 2;
        width: 300px;
        max-width: 100%;
        padding-bottom: 30px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: var(--color-grey-150);
        font-size: 18.3px;
        line-height: 30px;
        transform: translateX(100%);
        visibility: hidden;
        transition: transform .3s, visibility 0s .3s;
    }

    .header-nav-close {
        display: flex;
        align-items: center;
        height: 50px;
        padding-inline: 20px;
        background: rgb(0 0 0 / .1);
        color: var(--color-green);
        font-size: 18px;
        cursor: pointer;
    }

    .header-menu li {
        border-bottom: 1px solid var(--color-grey-250);
    }

    .header-menu li:first-child {
        border-top: 1px solid var(--color-grey-250);
    }

    .header-menu li:last-child {
        border-bottom: 0;
    }

    .header-menu a {
        padding: 12px 20px;
        color: var(--color-green);
    }

    .header-menu a:hover {
        color: var(--color-grey-650);
    }

    .header-nav-overlay {
        position: fixed;
        inset: 0;
        z-index: 1;
        background: rgb(0 0 0 / .6);
        opacity: 0;
        visibility: hidden;
        transition: opacity .3s, visibility 0s .3s;
    }

    .header-menu-checkbox:checked ~ .header-nav {
        transform: none;
        visibility: visible;
        transition: transform .3s;
    }

    .header-menu-checkbox:checked ~ .header-nav-overlay {
        opacity: 1;
        visibility: visible;
        transition: opacity .3s;
    }

    /* no page scrolling behind the open menu. */
    html:has(.header-menu-checkbox:checked) {
        overflow: hidden;
    }
}

@media (max-width: 959px) and (prefers-reduced-motion: reduce) {
    .header-nav,
    .header-nav-overlay,
    .header-menu-checkbox:checked ~ .header-nav,
    .header-menu-checkbox:checked ~ .header-nav-overlay {
        transition: none;
    }
}


/* --------------------------------------------------------------------------
   desktop: fixed header, horizontal menu
   -------------------------------------------------------------------------- */

@media (min-width: 960px) {

    /* space for the fixed header at full size: 7px + 130px logo + 15px. */
    body {
        padding-top: 152px;
    }

    .header {
        position: fixed;
        top: var(--admin-bar-height);
        inset-inline: 0;
        box-shadow: 0 2px 5px rgb(0 0 0 / .1);
        contain: content;
    }

    .header-logo-link {
        flex: none;
        max-width: none;
    }

    .header-logo {
        width: auto;
        height: 130px;
    }

    .header-menu-checkbox,
    .header-menu-toggle,
    .header-nav-close,
    .header-nav-overlay {
        display: none;
    }

    .header-nav {
        margin-right: -15px;
    }

    .header-menu {
        display: flex;
    }

    .header-menu a {
        padding-inline: 15px;
        color: var(--color-grey-700);
        font-size: 19px;
        line-height: 50px;
        transition: color .15s ease-in-out;
    }

    .header-menu a:hover {
        color: var(--color-blue);
    }
}

/* --------------------------------------------------------------------------
   progressive enhancement (desktop): shrink the header while scrolling the first 120px.
   everything above works without it; older browsers keep the header at full size, with shadow.
   -------------------------------------------------------------------------- */

/* 0 = full size, 1 = shrunk. registered so it animates smoothly (without @property it would switch at 50%). */
@property --header-shrink {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

@supports (animation-timeline: scroll()) {
    @media (min-width: 960px) {
        .header {
            box-shadow: 0 2px 5px rgb(0 0 0 / calc(.1 * var(--header-shrink, 0)));
            animation: header-shrink linear both;
            animation-timeline: scroll(root);
            animation-range: 0 120px;
        }

        .header-logo-link {
            padding-top: calc(7px + 3px * var(--header-shrink, 0));
            padding-bottom: calc(15px - 5px * var(--header-shrink, 0));
        }

        .header-logo {
            height: calc(130px - 30px * var(--header-shrink, 0));
        }
    }
}

@keyframes header-shrink {
    to {
        --header-shrink: 1;
    }
}
