/* Site header + primary navigation.
   Narrow screens: nav collapses behind the header button.
   Wide screens: nav is a fixed left sidebar.
   No JavaScript -- the toggle is a hidden checkbox, which lets the
   wide-screen media query force the sidebar visible regardless of
   whether the box happens to be checked. */

:root {
    --header-h: 3rem;
    --nav-w: 15rem;
    --nav-bg: #e9e9e9;
}

/* ---- header ---------------------------------------------------- */

/* No dark band -- a hairline separates it instead, so the header reads
   as part of the page rather than a bar bolted to the top. */
.site-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: var(--header-h);
    padding: 0 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    position: sticky;
    top: 0;
    z-index: 30;
}

.site-header .logo {
    /* margin:0 matters -- the legacy .logo rule sets 2em side margins. */
    margin: 0;
    font-size: 1.0625rem;
    font-weight: bold;
    letter-spacing: 0.12em;
    color: var(--ink);
    text-decoration: none;
    border-bottom: 0;
}

.site-header .logo:hover {
    color: var(--accent);
}

/* ---- toggle ---------------------------------------------------- */

/* Visually hidden but still focusable, so the button works from the
   keyboard. display:none would break that. */
.nav-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.nav-button {
    margin-left: auto;
    margin-right: -0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.5rem;
    cursor: pointer;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
}

.nav-button::before {
    content: "\2630";           /* hamburger */
    font-size: 1.35rem;
    line-height: 1;
}

.nav-toggle:checked ~ .site-header .nav-button::before {
    content: "\00D7";           /* multiplication sign, reads as a close X */
    font-size: 1.75rem;
}

.nav-toggle:focus-visible ~ .site-header .nav-button {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

/* ---- nav ------------------------------------------------------- */

.site-nav {
    display: none;
    background: var(--nav-bg);
}

/* While the overlay menu is open the page behind it is not reachable, so
   it shouldn't offer a scrollbar.  Without this you get two: the panel's
   own and the document's. */
body:has(> .nav-toggle:checked) {
    overflow: hidden;
}

/* Reserve the scrollbar gutter permanently, so opening the menu doesn't
   shift the layout sideways as the document scrollbar disappears. */
html {
    scrollbar-gutter: stable;
}

.nav-toggle:checked ~ .site-nav {
    display: block;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0 1rem;
    border-top: 1px solid var(--rule);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Label and group separator in one: --- GALLERY ---
   Deliberately quieter than the links; these are labels, not targets. */
.site-nav h2 {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0 0 0.2rem;
    /* 12px above the rule, 3px below.  The list below contributes no
       margin of its own, so this is the whole gap. */
    padding: 0.75rem 1.25rem 0;
    font-size: 0.8125rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #555;
    text-align: left;
}

.site-nav h2::before,
.site-nav h2::after {
    content: "";
    flex: 1 1 0;
    border-top: 1px solid var(--rule);
}

.site-nav ul {
    list-style: none;
    /* No bottom margin: it stacked with the next heading's padding and
       doubled the gap above each separator. */
    margin: 0;
    padding: 0;
}

/* The base stylesheet puts margin-bottom on every li, for prose lists.
   Here the anchor's padding is the tap target, so the extra margin is
   just ~100px of dead space spread over 16 rows. */
.site-nav li {
    margin: 0;
}

/* The headings carry their own rule now.  The last group has no heading,
   so it still needs a plain one to read as separate rather than as a
   continuation of the group above. */
/* Same 12px-above / 3px-below rhythm as a heading's rule, so the
   unlabelled group reads as a peer of the labelled ones. */
.site-nav ul + ul {
    border-top: 1px solid var(--rule);
    margin-top: 0.75rem;
    padding-top: 0.2rem;
}

.site-nav a {
    display: block;
    /* 0.7rem puts the row at 45px, just over the 44px touch minimum,
       without making 16 rows unnecessarily tall. */
    padding: 0.7rem 1.25rem;
    line-height: 1.4;
    color: var(--ink);
    font-size: 1rem;
    font-weight: normal;
    text-decoration: none;
    border-bottom: 0;
}

.site-nav a:hover {
    background: #ddd;
    color: #000;
}

.site-nav a[aria-current="page"] {
    background: #c9c9c9;
    font-weight: bold;
}

/* ---- skip link ------------------------------------------------- */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 40;
}

.skip-link:focus {
    left: 0;
    padding: 0.5rem 1rem;
    background: #fff;
    color: var(--ink);
}

/* ---- wide screens ---------------------------------------------- */

@media (min-width: 60rem) {
    .nav-button {
        display: none;
    }

    /* The sidebar is always visible here and covers nothing, so the
       checkbox must not lock the page. */
    body:has(> .nav-toggle:checked) {
        overflow: visible;
    }

    /* Both selectors, so the checkbox state is irrelevant here. */
    .site-nav,
    .nav-toggle:checked ~ .site-nav {
        display: block;
        position: fixed;
        top: var(--header-h);
        left: 0;
        right: auto;
        bottom: 0;
        width: var(--nav-w);
        overflow-y: auto;
        /* No bottom padding: trailing padding counts toward scroll
           height, so it produced a scrollbar even when every item was
           visible.  Now only real content can cause one. */
        padding: 0.5rem 0 0;
        border-top: 0;
        border-right: 1px solid #d2d2d2;
        box-shadow: none;
    }

    /* Mouse targets here, not touch, so rows can be tighter than the
       44px touch minimum.  Not tuned to make all 16 rows fit a
       particular window -- the window resizes, so it scrolls when it
       has to and that's fine. */
    .site-nav a {
        padding: 0.5rem 1.25rem;
    }

    /* The footer is a sibling of .mainwrapper, not a child, so it needs
       clearing the sidebar too or it slides underneath it. */
    .mainwrapper,
    footer.footer {
        margin-left: var(--nav-w);
    }
}

/* Short windows: tighten the rows so 16 of them still clear the
   viewport.  Keyed to the actual constraint -- available height -- so it
   adapts as the window is resized instead of being tuned to one size. */
@media (min-width: 60rem) and (max-height: 52rem) {
    .site-nav a {
        padding: 0.35rem 1.25rem;
    }

    .site-nav h2 {
        padding-top: 0.6rem;
    }
}
