.m-anchor-menu__container {
  width: 100%;
}

.m-anchor-menu[hidden] {
  display: none;
}

.m-anchor-menu--sticky {
  position: sticky;
  top: var(--m-anchor-menu-sticky-top, 0px);
  z-index: 5;
}

.m-anchor-menu__heading {
  font-family: var(--heading-font);
  font-size: var(--font-large);
  line-height: 1.2;
  margin: 0 0 0.75rem;
}

.m-anchor-menu__list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  list-style: none;
  margin: 0;
  padding: 0 0 1rem 0;
}

.m-anchor-menu__item {
  margin: 0;
  min-width: 0;
}

.m-anchor-menu__link {
  color: inherit;
  display: block;
  opacity: 0.75;
  overflow: hidden;
  padding: 0.5rem 0.85rem;
  position: relative;
  text-decoration: none;
  text-overflow: ellipsis;
  transition: color var(--transition-duration, 0.25s) ease,
              opacity var(--transition-duration, 0.25s) ease;
  white-space: nowrap;
}

.m-anchor-menu__link:hover,
.m-anchor-menu__link:focus-visible {
  opacity: 1;
}

.m-anchor-menu__link--active {
  opacity: 1;
}

/* Active marker — a bar alongside the link, edge depends on layout */
.m-anchor-menu__link::before {
  content: '';
  opacity: 0;
  position: absolute;
  transition: opacity var(--transition-duration, 0.25s) ease;
}

.m-anchor-menu__link--active::before {
  opacity: 1;
}

/* Stacked */
.m-anchor-menu--vertical .m-anchor-menu__link::before {
  bottom: 0;
  left: 0;
  top: 0;
  width: 2px;
}

/* Inline */
.m-anchor-menu--horizontal .m-anchor-menu__list {
  -ms-overflow-style: none;
  flex-direction: row;
  gap: 0.5rem;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}

/* A clipped label reads as broken without an affordance, so fade the edges the
   row continues past. The scrollbar stays hidden; the fade is the cue. */
@property --m-anchor-menu-fade-start {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}

@property --m-anchor-menu-fade-end {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}

/* Only the end edge by default — the start edge would dim the first label on a
   row that never scrolls, while trailing space is empty either way. */
.m-anchor-menu--horizontal .m-anchor-menu__list {
  --m-anchor-menu-fade-end: 1.75rem;

  mask-image: linear-gradient(
    to right,
    transparent 0,
    #000 var(--m-anchor-menu-fade-start),
    #000 calc(100% - var(--m-anchor-menu-fade-end)),
    transparent 100%
  );
}

/* Where scroll-driven animations land, both edges track the scroll position */
@supports (animation-timeline: scroll(self inline)) {
  .m-anchor-menu--horizontal .m-anchor-menu__list {
    animation: m-anchor-menu-fade-start linear, m-anchor-menu-fade-end linear;
    animation-timeline: scroll(self inline), scroll(self inline);
  }
}

@keyframes m-anchor-menu-fade-start {
  0% { --m-anchor-menu-fade-start: 0px; }
  4%, 100% { --m-anchor-menu-fade-start: 1.75rem; }
}

@keyframes m-anchor-menu-fade-end {
  0%, 96% { --m-anchor-menu-fade-end: 1.75rem; }
  100% { --m-anchor-menu-fade-end: 0px; }
}

.m-anchor-menu--horizontal .m-anchor-menu__list::-webkit-scrollbar {
  display: none;
}

.m-anchor-menu--horizontal .m-anchor-menu__item {
  flex: 0 0 auto;
}

.m-anchor-menu--horizontal .m-anchor-menu__link::before {
  bottom: 0;
  height: 2px;
  left: 0;
  right: 0;
}

/* Both layouts collapse to a wrapping row on small screens. Touch devices never
   paint a scrollbar, so a scrolling row leaves the fade as the only cue that
   links continue past the edge — wrapping keeps every link visible instead. */
@media screen and (max-width: 767px) {
  .m-anchor-menu--horizontal .m-anchor-menu__list,
  .m-anchor-menu--vertical .m-anchor-menu__list {
    animation: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    mask-image: none;
    overflow-x: visible;
  }

  .m-anchor-menu--horizontal .m-anchor-menu__item,
  .m-anchor-menu--vertical .m-anchor-menu__item {
    flex: 0 1 auto;
  }

  .m-anchor-menu--vertical .m-anchor-menu__link::before {
    bottom: 0;
    height: 2px;
    left: 0;
    right: 0;
    top: auto;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .m-anchor-menu__list {
    scroll-behavior: auto;
  }
}
