/* SECTION: nav (sticky section index; the current section is highlighted) */
.nav {
  position: sticky;
  z-index: 10;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: var(--page);
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  max-width: calc(var(--container-wide) + 2 * var(--gutter));
  min-height: var(--nav-h);
}

/* the ball, as the page's mark; the Home tab names the top of the page */
.nav__home {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  font-size: 1.8rem;
}

.nav__home:hover {
  text-decoration: none;
}

.nav__ball {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: var(--accent);
}

.nav__list {
  position: relative;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav__list::-webkit-scrollbar {
  display: none;
}

.nav__list a {
  display: block;
  padding: 10px 20px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 1.45rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color var(--dur-ui), color var(--dur-ui);
}

.nav__list a:hover {
  background: var(--accent-soft);
  color: var(--ink);
  text-decoration: none;
}

.nav__list a[aria-current="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

/* ---------- narrow screens: the bar naming the current section ----------
   nav.js adds .is-ready once it keeps the bar current; until then (or without
   the script) the index stays a row of tabs that scrolls sideways. */
.nav__now,
.nav__progress {
  display: none;
}

@media (max-width: 1279px) {
  .nav__home {
    display: none;
  }

  .nav__inner {
    padding-inline: var(--gutter);
  }

  .nav__list a {
    padding: 8px 14px;
    font-size: 1rem;
  }

  .nav.is-ready .nav__now {
    display: flex;
    flex: 1;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    min-height: var(--nav-h);
    padding: 0;
    border: 0;
    background: none;
    text-align: left;
    cursor: pointer;
  }

  .nav__now .nav__ball {
    display: none;
    flex: none;
    width: 1.35rem;
    height: 1.35rem;
  }

  .nav.is-home .nav__now .nav__ball {
    display: block;
  }

  .nav__count {
    flex: none;
    padding: 3px 13px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-family: var(--font-head);
    font-size: 1.2rem;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    line-height: 1.5;
  }

  .nav.is-home .nav__count {
    display: none;
  }

  .nav__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-head);
    font-size: 1.6rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav__icon {
    flex: none;
    width: 39px;
    height: 39px;
  }

  .nav__icon--close,
  .nav.is-open .nav__icon--menu {
    display: none;
  }

  .nav.is-open .nav__icon--close {
    display: block;
  }

  /* the list, folded under the bar, numbered like the section titles */
  .nav.is-ready .nav__list {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--gutter) var(--space-4);
    border-bottom: 1px solid var(--line);
    background: var(--page);
    box-shadow: 0 16px 24px rgba(36, 41, 47, 0.08);
    counter-reset: nav;
  }

  .nav.is-ready.is-open .nav__list {
    display: flex;
  }

  .nav.is-ready .nav__list a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 13px 18px;
    color: var(--ink);
    font-size: 1.5rem;
  }

  .nav.is-ready .nav__list a::before {
    counter-increment: nav;
    content: counter(nav, decimal-leading-zero);
    min-width: 1.6em;
    color: var(--ink-2);
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
  }

  .nav.is-ready .nav__list a[aria-current="true"],
  .nav.is-ready .nav__list a[aria-current="true"]::before {
    color: var(--on-accent);
  }

  /* Home is not a numbered section */
  .nav.is-ready .nav__list li:first-child a::before {
    counter-increment: none;
    content: "";
  }

  /* how far down the page the reader is */
  .nav.is-ready .nav__progress {
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    display: block;
    height: 4px;
  }

  .nav__progress span {
    display: block;
    height: 100%;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: 0 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav__list a {
    transition: none;
  }
}
