.sorting-options {
  display: flex;
  border: 0.0625rem solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.875em;
  box-shadow:
    0 0.25em 0.25em rgba(106, 106, 106, 0.05),
    0 0.5em 0.5em rgba(0, 0, 0, 0.02);
  width: 20em;
  margin: 0 auto 1em;

  & > * {
    border-right: 0.0625rem solid var(--border-color);
  }

  & > *:first-child {
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5em;
  }

  & > *:last-child {
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
    border-right: none;
  }
}

.sort-option {
  flex: 1;
  display: block;
  padding: 0.5em 1em;
  font-weight: bold;
  text-align: center;
  color: var(--fg-color);
  transition: 0.2s ease-out all;

  &:hover {
    text-decoration: none;
    color: var(--fg-color);
    background-color: var(--bg-highlight-color);
  }

  &.active {
    background-color: var(--header-bg-color);
    border-color: var(--header-bg-color);
    color: var(--highlight-contrast-color);
  }
}

#tags {
  columns: 10em auto;
  column-gap: 1em;

  & > section {
    break-inside: avoid-column;
  }

  h2 {
    margin: 0;
    padding: 1em 0 0;
    text-transform: uppercase;
    font-weight: 900;

    &:target {
      color: var(--highlight-color);
    }
  }

  .tag {
    display: block;
    color: var(--fg-color);
    font-weight: bold;
    text-decoration: underline;
    text-decoration-thickness: 0.125rem;
    text-decoration-color: var(--highlight-color);
    transition: 0.2s ease-out all;

    &:hover {
      color: var(--link-color);
    }
  }
}

/* Tag filtering interface */
.tag-filters {
  margin-bottom: 2em;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  vertical-align: middle;
  padding: 0.1em 0.75em 0.2em;
  border-radius: 1em;
  background-color: var(--bg-highlight-color);
  color: var(--fg-color);
  text-decoration: none;
  transition: 0.2s linear padding;
}

.tag-pill:hover {
  padding: 0.1em 0.3em 0.2em;
  background-color: var(--header-bg-color);
  border-color: var(--header-bg-color);
  color: var(--highlight-contrast-color);
  text-decoration: none;
}

.tag-pill-x {
  width: 0;
  margin-left: 0;
  opacity: 0;
  overflow: hidden;
  font-weight: bold;
  transition:
    width 0.2s linear,
    margin-left 0.2s linear,
    opacity 0.2s linear;
}

.tag-pill:hover .tag-pill-x {
  width: 0.65em;
  margin-left: 0.25em;
  opacity: 1;
}

/* No hover on touch devices: keep the × visible so the affordance reads. */
@media (hover: none) {
  .tag-pill-x {
    width: 0.65em;
    margin-left: 0.25em;
    opacity: 1;
  }
}

.related-tags {
  margin-bottom: 2em;
}

.related-tags h3 {
  margin-top: 0;
  margin-bottom: 0.25em;
  color: var(--fg-color);
  font-size: 1em;
}

.tag-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tag-button {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  padding: 0.1em 0.5em;
  background-color: var(--bg-highlight-color);
  color: var(--fg-color);
  border-radius: 1rem;
  text-decoration: none;
  font-size: 0.875em;

  .tag-count {
    color: var(--mid-color);
    font-size: 0.75rem;
  }
}

.tag-button:hover {
  background-color: var(--header-bg-color);
  color: var(--highlight-contrast-color);
  border-color: var(--header-bg-color);
  text-decoration: none;
}
