/* Sticky header and nav, ported from the homepage's css/header.css.
   Course site differences: seven nav items (tighter pills, and the menu
   collapses at 900px rather than 768px), the site title is a <p> so each
   page has a single <h1>, and the collapsed menu is hidden from keyboard
   and screen reader users as well as visually. */

header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--color-primary);
  color: var(--color-header-title);
  padding: var(--spacing-sm) var(--spacing-md);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-md);
  max-width: 960px;
  margin: 0 auto;
}

.site-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.site-title a {
  color: var(--color-header-title);
  text-decoration: none;
}

.site-term {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--color-nav-link);
  margin-left: var(--spacing-mini);
}

.nav-toggle {
  display: none;
  align-items: center;
  gap: var(--spacing-sm);
  font: inherit;
  font-weight: 600;
  background: none;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: var(--radius);
  color: var(--color-header-title);
  cursor: pointer;
  padding: var(--spacing-mini) var(--spacing-sm);
  margin-left: auto;
  flex-shrink: 0;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--spacing-mini);
}

.nav-list a {
  display: block;
  color: var(--color-nav-link);
  text-decoration: none;
  font-weight: 600;
  padding: var(--spacing-mini) var(--spacing-sm);
  border-radius: var(--radius);
  transition: background-color 0.2s;
}

.nav-list a:hover,
.nav-list a.active {
  background-color: rgba(236, 240, 241, 0.2);
  color: var(--color-header-title);
  text-decoration: none;
}

/* Current page is also marked by an underline, not only the pill fill */
.nav-list a.active {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

header a:focus-visible,
.nav-toggle:focus-visible {
  outline: 2px solid var(--color-header-title);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .header-bar {
    position: static;   /* the dropdown anchors to <header> */
  }

  .site-title {
    font-size: 1.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-toggle {
    display: inline-flex;
  }

  /* visibility (not just max-height) keeps hidden links out of the tab order */
  .navbar {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--color-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    max-height: 0;
    overflow: hidden;
    visibility: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out, visibility 0s linear 0.3s;
  }

  .navbar.open {
    max-height: 30rem;
    visibility: visible;
    opacity: 1;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out, visibility 0s;
  }

  .nav-list {
    flex-direction: column;
    align-items: stretch;
    padding: var(--spacing-sm) var(--spacing-md);
    gap: 0;
  }

  .nav-list a {
    text-align: right;
    padding: var(--spacing-sm) var(--spacing-md);  /* ~44px touch target */
  }
}

@media (max-width: 420px) {
  .site-term {
    display: none;
  }
}
