/* Keep the document, reading panes and market menus on the same paper-and-ink palette. */
@media screen and (forced-colors: none) {
  :root {
    --scroll-thumb: #76887a;
    --scroll-thumb-active: #416a57;
  }

  :where(html, dialog, textarea, [role="listbox"], .original-sheet, .table-scroll) {
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) transparent;
  }

  @supports not (scrollbar-width: thin) {
    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; }
    ::-webkit-scrollbar-thumb:hover, ::-webkit-scrollbar-thumb:active { background: var(--scroll-thumb-active); }
  }

  /* Touch users swipe the document and modals. Keep a scroll cue on sideways evidence and long menus. */
  @media (hover: none) and (pointer: coarse) {
    :where(html, dialog) { scrollbar-width: none; }
    @supports not (scrollbar-width: thin) {
      html::-webkit-scrollbar, dialog::-webkit-scrollbar { width: 0; height: 0; }
    }
  }

  /* The gutter keeps its width, so showing the thumb never shifts the page. */
  @media (hover: hover) and (pointer: fine) and (prefers-contrast: no-preference) {
    html[data-scroll-idle] { scrollbar-color: transparent transparent; }
    @supports not (scrollbar-width: thin) {
      html[data-scroll-idle]::-webkit-scrollbar-thumb { background: transparent; }
    }
  }
}

/* Let the OS supply its normal, high-contrast scroll controls. */
@media (prefers-contrast: more), (forced-colors: active) {
  :where(html, dialog, textarea, [role="listbox"], .original-sheet, .table-scroll) {
    scrollbar-width: auto;
    scrollbar-color: auto;
  }
  ::-webkit-scrollbar, ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner, ::-webkit-scrollbar-thumb {
    all: revert;
  }
}
