html:root body #above_postlist:has(> #postpagestats_above, > #pagination_top > #postpagestats_above),
html:root body :is(#above_threadlist, #below_threadlist) {
  box-sizing: border-box;
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem .75rem;
  height: auto !important;
  padding-inline: 16px;
}

html:root body #above_postlist > #newreplylink_top,
html:root body #above_threadlist > #newthreadlink_top,
html:root body #below_threadlist > #newthreadlink_bottom {
  position: static !important;
  flex: none;
  margin: 0 !important;
  margin-inline-end: auto !important;
}

html:root body #above_postlist > #pagination_top,
html:root body :is(#above_threadlist, #below_threadlist) > .threadpagenav {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem .625rem;
  position: relative;
  inset: auto !important;
  width: auto !important;
  min-inline-size: 0;
  max-inline-size: 100%;
  margin: 0 !important;
}

html:root body #above_postlist > #pagination_top > #postpagestats_above,
html:root body #above_threadlist > .threadpagenav > #threadpagestats {
  order: -1;
  min-block-size: 34px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  inset: auto;
  margin: 0 !important;
}

html:root body #above_threadlist > .threadpagenav > #threadpagestats {
  padding: 4px 12px;
  background: var(--eco-raised);
  border: 1px solid var(--eco-control-stroke);
  border-radius: 6px;
}

html:root body #below_threadlist {
  align-items: flex-start;
}

html:root body #below_threadlist > .threadpagenav {
  flex-direction: column;
  align-items: flex-end;
}

html:root body #below_threadlist > .threadpagenav > .navpopupmenu {
  max-inline-size: 100%;
  margin: 0 !important;
}

html:root body #below_threadlist > .threadpagenav > .clear {
  display: none;
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .25rem;
  inset: auto !important;
  float: none !important;
  max-inline-size: 100%;
  margin: 0 !important;
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > span > a {
  box-sizing: border-box;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  position: relative;
  inset: auto !important;
  height: auto !important;
  min-block-size: 34px;
  min-inline-size: 34px;
  margin: 0 !important;
  line-height: 1.2;
  white-space: nowrap;
}

html:root body .threadpagenav > .pagination > span.separator {
  display: flex;
  align-items: center;
  min-block-size: 34px;
  padding-inline: .15rem;
  color: var(--eco-muted);
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > span > a.popupctrl {
  background-image: none !important;
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > span > a.popupctrl::after {
  content: '';
  flex: none;
  inline-size: 9px;
  block-size: 7px;
  background: currentColor;
  clip-path: polygon(0 22%, 16% 0, 50% 53%, 84% 0, 100% 22%, 50% 100%);
}

/* Keep the legacy images' accessible link names while drawing theme-colored arrows. */
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > :is(.prev_next, .first_last) > a > img {
  position: absolute;
  inset: auto;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .prev_next > a::after,
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .first_last > a[rel="start"]::before,
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .first_last > a:not([rel="start"])::after {
  content: '';
  flex: none;
  inline-size: 8px;
  block-size: 12px;
  background: currentColor;
  clip-path: path('M 1 0 L 7 6 L 1 12 L 0 10.5 L 4.5 6 L 0 1.5 Z');
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .first_last > a[rel="start"]::before,
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .first_last > a:not([rel="start"])::after {
  inline-size: 13px;
  clip-path: path('M 1 0 L 7 6 L 1 12 L 0 10.5 L 4.5 6 L 0 1.5 Z M 7 0 L 13 6 L 7 12 L 6 10.5 L 10.5 6 L 6 1.5 Z');
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .prev_next > a[rel="prev"]::after,
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > .first_last > a[rel="start"]::before {
  transform: scaleX(-1);
}

html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > :is(.prev_next, .first_last) > a:has(> img[src$="-left.png"])::before,
html:root body :is(#pagination_top, #pagination_bottom, .threadpagenav) > .pagination > :is(.prev_next, .first_last) > a:has(> img[src$="-left.png"])::after {
  scale: -1 1;
}

@media (max-width: 600px) {
  html:root body #above_threadlist > .threadpagenav {
    display: contents !important;
  }

  html:root body #above_threadlist > .threadpagenav > #threadpagestats {
    order: 0;
  }

  html:root body #above_threadlist > .threadpagenav > .pagination {
    order: 1;
    flex: 0 0 100%;
  }
}
