/* Chapter navigation docks at the bottom on narrower screens and becomes a
   rail outside the centered content width on wide ones. */
.chapter-nav {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 2px;
  width: max-content;
  max-width: calc(100% - 24px);
  height: auto;
  margin: 0 auto;
  padding: 4px;
  box-sizing: border-box;
  border: 1px solid rgba(24, 43, 73, .14);
  border-radius: 12px;
  background: color-mix(in srgb, var(--band, #FAFAF8) 50%, #FFFFFF);
  box-shadow: 0 6px 24px rgba(24, 43, 73, .14);
  font-family: 'JetBrains Mono', monospace;
  overflow-x: auto;
  scrollbar-width: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

/* Stay out of the way until the hero has mostly scrolled past. */
@media (max-width: 1511.98px) {
  .chapter-nav:not(.is-shown):not(:focus-within) {
    opacity: 0;
    transform: translate(-50%, 16px);
    pointer-events: none;
  }
  .chapter-content { padding-bottom: 72px; }
}

.chapter-nav__link {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  box-sizing: border-box;
  border-radius: 8px;
  color: #526476;
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background-color 140ms ease, color 140ms ease;
}

.chapter-nav__link svg {
  flex: none;
  width: 18px;
  height: 18px;
}

.chapter-nav__link:hover {
  color: #182B49;
  background: color-mix(in srgb, var(--band, #FAFAF8) 94%, var(--accent));
}

.chapter-nav__link[aria-current="location"] {
  color: var(--accent);
  background: #FFFFFF;
  box-shadow: 0 1px 4px rgba(24, 43, 73, .08);
}

.chapter-nav__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chapter-nav__home { margin-right: 8px; padding-inline: 10px; }
.chapter-nav__home img { display: block; width: 24px; height: 24px; }
.chapter-nav__home::after {
  content: '';
  position: absolute;
  top: 12px;
  right: -5px;
  width: 1px;
  height: 20px;
  background: rgba(24, 43, 73, .14);
}

/* Land each chapter's eyebrow 24px under the site nav; html's scroll-padding
   already clears the nav plus 12px. */
#page .chapter-section { scroll-margin-top: calc(12px - var(--band-pad-top, 0px)); }
#page .chapter-section:focus { outline: none; }

.chapter-content { min-width: 0; }

/* 1280px content, plus an 80px rail, 24px gap and 12px outer margin. */
@media (min-width: 1512px) {
  .chapter-layout {
    display: grid;
    grid-template-columns: 0 minmax(0, 1fr);
    align-items: start;
  }

  .chapter-nav {
    position: sticky;
    top: calc(var(--site-nav-height) + 24px);
    bottom: auto;
    left: auto;
    transform: none;
    flex-direction: column;
    align-items: stretch;
    width: 80px;
    max-width: none;
    max-height: calc(100dvh - var(--site-nav-height) - 48px);
    margin: clamp(40px, 6vh, 68px) 0 0 calc((100vw - 1280px) / 2 - 104px);
    padding: 6px;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .chapter-nav__link {
    flex: none;
    flex-direction: column;
    gap: 5px;
    min-height: 54px;
    padding: 8px 4px;
    font-size: 10px;
  }

  .chapter-nav__home { margin: 0 0 8px; }
  .chapter-nav__home::after {
    top: auto;
    right: 8px;
    bottom: -5px;
    left: 8px;
    width: auto;
    height: 1px;
  }
}

@media (min-width: 641px) and (max-width: 960px) {
  body.project--retargetingkit .chapter-content .motion-stage__caption {
    top: 16px;
    right: 16px;
    bottom: auto;
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .chapter-nav { bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .chapter-nav__link {
    flex-direction: column;
    gap: 4px;
    padding: 6px 4px;
    font-size: 9px;
  }
  .chapter-nav__home { align-self: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-nav, .chapter-nav__link { transition: none; }
}
