/* Only the mobile results view; hub, reference detail and desktop stay untouched. */
.library-results-alphabet { display: none; }

@media (max-width: 768px),
       (orientation: landscape) and (max-height: 500px) and (max-width: 1024px) and (hover: none) and (pointer: coarse) {
  .library-page.library-mobile-results-view .library-results-alphabet:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 4px 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background: #fff;
  }

  .library-page.library-mobile-results-view .library-results-alphabet::-webkit-scrollbar { display: none; }

  .library-page.library-mobile-results-view .library-results-alphabet button {
    display: inline-flex;
    flex: 0 0 32px;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-soft);
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
  }

  .library-page.library-mobile-results-view .library-results-alphabet [aria-current="location"] {
    background: var(--secondary-soft);
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 4px;
  }

  .library-page.library-mobile-results-view .library-letter-section {
    scroll-margin-top: calc(96px + env(safe-area-inset-top, 0px));
  }

  .library-page.library-mobile-results-view #libraryBackToTop {
    display: grid;
    place-items: center;
    z-index: 30;
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 16px);
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(15, 17, 21, 0.1);
    border-radius: 50%;
    background: #fff;
    color: var(--text);
    box-shadow: 0 3px 12px rgba(15, 17, 21, 0.08);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
  }

  .library-page.library-mobile-results-view #libraryBackToTop.is-visible { pointer-events: auto; }
  .library-page.library-mobile-results-view.dialog-open #libraryBackToTop {
    opacity: 0;
    pointer-events: none;
  }

  .library-page.library-mobile-results-view :is(.library-results-alphabet button, #libraryBackToTop):focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  .library-page.library-mobile-results-view .library-card { padding-inline: 16px; }
  .library-page.library-mobile-results-view .library-card :is(.card-footer, .button-row) {
    width: 100%;
    min-width: 0;
    margin-inline: 0;
    padding-inline: 0;
    justify-content: flex-start;
  }
  .library-page.library-mobile-results-view .library-card .detail-link {
    max-width: 100%;
    margin-inline: 0;
    padding-inline: 0;
    justify-content: flex-start;
    text-align: left;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 768px),
       (orientation: landscape) and (max-height: 500px) and (max-width: 1024px) and (hover: none) and (pointer: coarse) {
  .library-page.library-mobile-results-view .library-letter-section { scroll-margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html:has(.library-page.library-mobile-results-view) { scroll-behavior: auto; }
  .library-page.library-mobile-results-view #libraryBackToTop { transition: none; }
}
