.category-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 10px;
  margin-bottom: 28px;
}

.category-tabs[hidden],
.chapter[hidden],
.chapters-nav__link[hidden] {
  display: none;
}

.category-tabs__tab {
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--color-text);
  border-radius: 999px;
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-head);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.category-tabs__tab:hover,
.category-tabs__tab.is-active {
  background: var(--color-text);
  color: var(--color-bg);
}

.chapters-nav {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 28px;
  font-family: var(--font-head);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

.chapters-nav__link {
  padding: 8px 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.chapters-nav__link:hover {
  opacity: 0.6;
}

/* No content-visibility here: placeholder heights break chapter anchor scroll and clip focus rings */
.chapter {
  margin-top: var(--grid-gap);
}

/* [id] beats base.css section[id] in specificity */
.chapter[id] {
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.chapter--first {
  margin-top: 0;
}

.chapters {
  padding-top: 48px;
  padding-bottom: var(--section-y);
}

.chapter__head {
  display: none;
  text-align: center;
  margin-bottom: 32px;
}

.chapter__title {
  margin: 0;
}

.chapter__count {
  margin: 8px 0 0;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--color-muted);
}

.masonry {
  display: flex;
  gap: var(--grid-gap);
  align-items: flex-start;
}

.masonry__col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--grid-gap);
}

/* Live grid: one grid for the photos of all shown chapters, so the columns run on across chapter
   borders. Chapters and their masonry wrappers drop their boxes; portfolio.js sets the columns,
   the crop and the top offset of each item. */
.chapters--flow {
  display: grid;
  column-gap: var(--grid-gap);
  align-items: start;
}

.chapters--flow > .chapter:not([hidden]),
.chapters--flow .masonry {
  display: contents;
}

.masonry__item {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  cursor: zoom-in;
  background: var(--color-panel);
}

.masonry__item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Edit mode: plain grid, natural ratio per item */
.masonry.uniform-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

.masonry.uniform-grid .masonry__item {
  aspect-ratio: auto;
}

.masonry.uniform-grid .masonry__item img {
  position: static;
  height: auto;
}

@media (min-width: 1024px) {
  .masonry.uniform-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Touch widths: one sticky strip of 44px tap targets, so chapters stay reachable on a long page */
@media (max-width: 1023px) {
  .chapters-nav {
    display: none;
    position: sticky;
    top: var(--header-h);
    z-index: 50;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0 28px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background: var(--color-bg);
  }

  .chapters-nav::-webkit-scrollbar {
    display: none;
  }

  .chapters-nav__link {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    min-height: 44px;
    padding: 0;
    white-space: nowrap;
  }

  /* The strip clips overflow, so keep the focus ring inside the link box */
  .chapters-nav__link:focus-visible {
    outline-offset: -2px;
  }

  .chapter[id] {
    scroll-margin-top: calc(var(--header-h) + 44px + 16px);
  }
}
