.library-finder {
  min-height: 0;
  padding-bottom: 3rem;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-ui);
}
.library-finder__heading h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
}

/* Chips: 36px tall, 0 14px padding, pill, 15px 600, 8px apart. Active = a teal outline with a pastel teal fill (the same
   treatment as the chart's key picker); the others are a quiet outline. */
.library-finder__chip {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  text-decoration: none;
}

.library-finder__content {
  width: min(56rem, calc(100% - 2rem));
  margin: 0 auto;
  padding-top: 0;
}

.library-finder--picking .library-finder__list {
  border: 2px solid var(--selected-line);
  border-radius: var(--radius-control);
  padding: 0 0.75rem;
}

.library-finder__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.library-finder__heading h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); }
.library-finder .library__count { margin: 0.2rem 0 0; color: var(--muted); }


.library-finder__form { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 0.7rem; margin: 1.25rem 0 0; }
.library-finder__search { position: relative; }
.library-finder__search label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.library-finder .library-filters__search input[type="search"] {
  min-height: 52px;
  padding: 0.65rem 1rem;
  border-color: var(--hairline);
  border-radius: 12px;
  color: var(--ink);
  background: var(--surface);
  font-size: 17px;
}
@media (min-width: 768px) {
  .library-finder .library-filters__search input[type="search"] { min-height: 56px; }
}
/* No JavaScript: a 44x44 icon button sits inside the field. With JavaScript it is hidden. */
.library-finder:not([data-library-finder-ready]) .library-filters__search input[type="search"] { padding-right: 3.5rem; }
.library-finder__submit {
  position: absolute;
  top: 50%;
  right: 4px;
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transform: translateY(-50%);
}
.library-finder__submit:hover { background: var(--tint); }
.library-finder__submit-icon { width: 1.375rem; height: 1.375rem; vertical-align: baseline; }
.library-finder[data-library-finder-ready] .library-finder__submit { display: none; }
.library-finder .library-filters__search input[type="search"]:focus {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
  border-color: var(--accent);
}
.library-finder__chips { display: flex; min-height: 44px; align-items: center; gap: 8px; }
.library-finder__chip { border: 1.5px solid var(--hairline); }
.library-finder__chip { background: transparent; }
.library-finder__chip:hover { background: var(--row-hover); }
.library-finder__chip--active,
.library-finder__chip--active:hover { border-color: var(--selected-line); color: var(--selected-ink); background: var(--selected-fill); }

.library-finder__filters { position: relative; }
.library-finder__filters summary { display: grid; min-width: 44px; min-height: 56px; place-items: center; padding: 0.65rem 0.75rem; border: 1.5px solid var(--selected-line); border-radius: var(--radius-control); color: var(--selected-ink); background: var(--selected-fill); font-weight: 700; cursor: pointer; list-style: none; }
.library-finder__filters summary::-webkit-details-marker { display: none; }
.library-finder__filters-panel {
  position: absolute;
  z-index: 3;
  top: calc(100% + 0.5rem);
  right: 0;
  display: grid;
  width: min(28rem, calc(100vw - 2rem));
  gap: 1rem;
  margin-top: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
}
.library-finder .library-filters__actions { display: flex; flex-wrap: wrap; }
.library-finder .library-filters__actions .button { width: auto; }

/* The single mustard action belongs with the personal Songs controls, not member chrome. */
.library-finder__quick-add {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0 1rem;
  border: 1px solid var(--primary);
  border-radius: var(--radius-control);
  color: var(--on-primary);
  background: var(--primary);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.library-finder__quick-add:hover { border-color: var(--chrome-cta-hover); color: var(--on-primary); background: var(--chrome-cta-hover); }
.library-finder__quick-add .icon { width: 1.1rem; height: 1.1rem; }
.library-finder__add-songs { min-height: 52px; white-space: nowrap; }

.library-finder .library { display: block; }
.library-finder .list-selection-rail { margin-bottom: 0.75rem; }
/* Rows: two lines at every width (title, then artist), a fixed 48px key column, one rule underneath. */
.library-finder .chart-list { border: 0; border-radius: 0; background: transparent; }
.library-finder .library-finder__row {
  grid-template-columns: minmax(0, 1fr);
  min-height: 60px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
}
.library-finder .chart-selection-row:last-child { border-bottom: 1px solid var(--rule); }
/* Pointed at: a neutral lift. Keyboard focus: the row is outlined in teal (teal = the focused row). */
.library-finder .library-finder__row:hover { background: var(--row-hover); }
.library-finder .library-finder__row:has(:focus-visible) { outline: 2.5px solid var(--selected-line); outline-offset: -2.5px; border-radius: 6px; }
.library-finder .library-finder__select { position: absolute; opacity: 0; pointer-events: none; }
.library-finder--selecting .library-finder__row { grid-template-columns: auto minmax(0, 1fr); gap: 12px; }
.library-finder--selecting .library-finder__select { position: static; align-self: center; opacity: 1; pointer-events: auto; }
.library-finder .library-finder__card {
  display: grid;
  min-height: 40px;
  grid-template-columns: minmax(0, 1fr) 48px;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-content: center;
  align-items: center;
  padding: 0;
}
.library-finder .library-finder__row:has(.group-pick-action) { grid-template-columns: minmax(0, 1fr) 48px 10rem; gap: 0.75rem; align-items: center; }
.library-finder .library-finder__row:has(.group-pick-action--set) { grid-template-columns: minmax(0, 1fr) 48px 14rem; }
.library-finder .library-finder__row:has(.group-pick-action) .library-finder__card { grid-column: 1 / span 2; }
.library-finder .library-finder__row:has(.group-pick-action) .group-pick-action { grid-column: 3; }
.group-pick-action { display: flex; min-width: 0; min-height: 44px; align-items: center; justify-content: flex-end; gap: 0.5rem; }
.group-pick-action form { flex: none; margin: 0; }
.group-pick-action .button { min-height: 44px; justify-content: center; }
.group-pick-action__link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.25rem; border: 0; color: var(--accent); background: transparent; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.group-pick-action__link:hover, .group-pick-action__link:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
.group-pick-action__link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
/* A row already in the container is marked by its look: a kind-tinted fill, a coloured left edge and a tick before the title.
   The rules key off the Remove / Undo link inside the row (:has with one plain descendant, never nested) so they also hold
   after Turbo swaps a row's action without re-rendering the row. */
.library-finder .library-finder__row:has(.group-pick-action__link) { padding-left: calc(0.5rem - 3px); border-left: 3px solid var(--tag-line); background: var(--context-group-fill); }
.library-finder .library-finder__row:has(.group-pick-action--set .group-pick-action__link) { border-left-color: var(--selected-line); background: var(--context-set-fill); }
.library-finder .library-finder__row:has(.group-pick-action--collection .group-pick-action__link) { border-left-color: var(--tag-neutral-line); background: var(--row-hover); }
.library-finder .library-finder__row:has(.group-pick-action__link) .chart-card__title::before { content: "✓"; display: inline-block; width: 1rem; margin-right: 0.25rem; color: var(--accent); }
.library-finder__picked-mark { display: none; }
.library-finder__picked-count { margin-right: 0.25rem; line-height: 1; color: var(--muted); font-size: 0.82em; font-weight: 600; }
@media (prefers-reduced-motion: no-preference) { .library-finder__row--just-added, .library-finder__row:has(.group-pick-action--just-added) { animation: library-picker-added 1.2s ease-out; } }
@keyframes library-picker-added { from { filter: brightness(1.08); } to { filter: brightness(1); } }

@media screen and (max-width: 40rem) {
  .library-finder .library-finder__row:has(.group-pick-action) { grid-template-columns: minmax(0, 1fr) 40px 8rem; gap: 0.5rem; }
  .library-finder .library-finder__row:has(.group-pick-action--set) { grid-template-columns: minmax(0, 1fr) 40px 9.5rem; }
  .group-pick-action--set { flex-wrap: wrap; row-gap: 0; }
  .group-pick-action { gap: 0.25rem; }
  .group-pick-action__link { padding: 0 0.125rem; font-size: 0.9rem; }
  .library-finder .chart-card__title { overflow: visible; text-overflow: clip; white-space: normal; }
}
.library-finder .chart-card__title {
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 600;
  line-height: 24px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-finder .chart-card__artist {
  grid-column: 1;
  overflow: hidden;
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-finder .chart-card__lyric-snippet { grid-column: 1 / -1; overflow-wrap: anywhere; }
.library-finder .library-finder__key {
  display: block;
  width: 40px;
  height: 32px;
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: center;
  overflow: hidden;
  border: 1.5px solid var(--key-line);
  border-radius: 8px;
  color: var(--key-ink);
  background: var(--key-fill);
  font-family: var(--font-ui);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 29px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* No key recorded: the column stays, the badge does not. */
.library-finder .library-finder__key:empty { visibility: hidden; }
.library-finder__empty { margin-top: 1rem; }

@media (max-width: 40rem) {
  .library-finder__content { width: min(100% - 1.5rem, 56rem); }
}

/* Row titles are ink, never amber; pointed at (or focused) the title takes the accent colour and underlines. */
.library-finder .library-finder__card,
.library-finder .chart-card__title { color: var(--ink); text-decoration: none; }
.library-finder .library-finder__card:hover .chart-card__title,
.library-finder .library-finder__card:focus-visible .chart-card__title { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

/* ------------------------------------------------------------------------------------------------------------------
   Controls that stay in reach, and the filter panel beside the list.

   --library-pin-top is how far below the viewport top a pinned element sits: the sticky member bar plus its stripe
   (member_bar.css), plus the preview notice when it is showing (the notice script sets --preview-notice-height).
   The filter panel is NEUTRAL (--sidebar-* tokens: tan in light appearance, a charcoal slightly darker than the page in
   dark, a 1px rule on its right edge). Colour inside it is only the teal of selection: checkboxes, links on hover, the
   outlined Apply button. */
.library-finder { --library-pin-top: var(--member-sticky-offset, 0px); }

/* Below 1100px the search row (search field and the Filters button) pins under the bar; the chips scroll away. The
   title scrolls away too, so the pinned row is the slim bar. Page colour behind it, a hairline once the page has moved. */
@media screen {
  .library-finder__form {
    position: sticky;
    z-index: 1;
    top: var(--library-pin-top);
    margin: 0;
    padding: 0.75rem 0 0.5rem;
    background: var(--bg);
  }

  /* The form and filter chips form one opaque pinned control block above the list. */
  .library-finder__chips {
    position: sticky;
    z-index: 1;
    top: calc(var(--library-pin-top) + 4.5rem);
    margin-top: 0;
    padding: 0 0 0.5rem;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
  }

  .library-finder__heading { margin-bottom: 0.25rem; }
  .library-finder__chips { margin-top: 0.25rem; }
}

@supports (animation-timeline: scroll()) {
  @keyframes library-finder-hairline {
    from { border-bottom-color: transparent; }
    to { border-bottom-color: var(--rule); }
  }

  .library-finder__form,
  .library-finder__chips {
    border-bottom: 1px solid transparent;
    animation: library-finder-hairline linear both;
    animation-range: 40px 120px;
    animation-timeline: scroll(root);
  }
}

@supports not (animation-timeline: scroll()) {
  .library-finder__form { border-bottom: 1px solid var(--rule); }
}

/* Phones: the pinned row is one compact row, search field plus the Filters button, about 60px tall. */
@media (max-width: 42rem) {
  .library-finder__form { gap: 0.35rem; padding: 0.5rem 0; }
  .library-finder .library-filters__search input[type="search"] { min-height: 44px; font-size: 16px; }
  .library-finder__quick-add { width: 44px; min-width: 44px; min-height: 44px; padding: 0; }
  .library-finder__quick-add span { display: none; }
  .library-finder__quick-add .icon { width: 1.25rem; height: 1.25rem; }
  .library-finder__add-songs { min-height: 44px; padding: 0 0.65rem; }
  .library-finder__filters summary { min-height: 44px; }
  .library-finder__chips { top: calc(var(--library-pin-top) + 3.5rem); }
}

/* 1100px and wider: the filters live in a panel to the left of the list (the navigation is the top bar, so the left is
   free for the page's own controls). Same form and same fields as the Filters disclosure; one copy. The details is
   shown open by CSS (::details-content) and its summary hidden. Browsers without ::details-content keep the button. */
@supports selector(::details-content) {
  @media screen and (min-width: 68.75rem) {
    .library-finder__content {
      display: grid;
      width: min(100%, 83rem);
      grid-template-columns: 16rem minmax(0, 1fr);
      grid-template-rows: auto auto auto 1fr;
      column-gap: 2.5rem;
      margin: 0;
      align-items: start;
    }

    /* The title sits over the list column, so the panel can run the full height beside it. */
    .library-finder__heading { grid-column: 2; grid-row: 1; margin-bottom: 1rem; }

    /* The panel's fill is full bleed: from the left edge of the viewport to the panel's right edge, from the bar to the
       bottom of the page (the shell's own bottom padding plus the main column's 5rem), and at least as tall as the window.
       The panel itself is the sticky column on top of it. A pseudo-element, because the page's centred column cannot
       paint to the viewport's edge. Screen only (print shows no panel colours). */
    .library-finder {
      position: relative;
      min-height: calc(100dvh - var(--library-pin-top) - 2rem);
    }

    .library-finder::before {
      content: "";
      position: absolute;
      top: -2rem;
      right: calc(100% - 16rem - 1px);
      bottom: -5rem;
      left: calc(50% - 50vw);
      pointer-events: none;
      border-right: 1px solid var(--sidebar-rule);
      background: var(--sidebar-bg);
    }

    /* The form stops being a box so its two children (the search field and the panel) are placed on the page grid. */
    .library-finder__form { display: contents; }

    .library-finder__search,
    .library-finder__chips {
      position: sticky;
      z-index: 1;
      grid-column: 2;
      background: var(--bg);
    }

    /* The button sits over the search row's own opaque background; it keeps its own fill (mustard Quick add, pastel Add songs). */
    .library-finder__quick-add,
    .library-finder__add-songs { position: sticky; z-index: 1; grid-column: 2; }

    /* Search and chips pin as one bar: the search at the pin line, the chips directly under it (heights are fixed here
       so the second offset is exact). */
    .library-finder__search { top: var(--library-pin-top); grid-row: 2; padding: 0.5rem 0 0.25rem; height: 4.25rem; box-sizing: border-box; }
    .library-finder__search { padding-right: 9rem; }
    .library-finder__quick-add,
    .library-finder__add-songs { top: calc(var(--library-pin-top) + 0.5rem); grid-column: 2; grid-row: 2; justify-self: end; z-index: 2; }
    .library-finder__chips { top: calc(var(--library-pin-top) + 4.25rem); grid-row: 3; margin: 0; padding: 0 0 0.5rem; }
    .library { grid-column: 2; grid-row: 4; }
    /* A group list has no filter panel: its owner/curator panels and the sharing statement stack in the list column under the list. */
    .library-finder__content > .group-library-panel,
    .library-finder__content > [id="add"] { grid-column: 2; }

    .library-finder__filters {
      position: sticky;
      top: calc(var(--library-pin-top) + 0.5rem);
      grid-column: 1;
      grid-row: 1 / span 4;
      max-height: calc(100dvh - var(--library-pin-top) - 1.5rem);
      overflow-y: auto;
      overscroll-behavior: contain;
      padding: 0.25rem 1.5rem 1rem 0;
      color: var(--ink);
      background: var(--sidebar-bg);
      /* The panel sits on its own neutral ground: dividers and fields take the sidebar tokens, text keeps the page's. */
      --rule: var(--sidebar-rule);
      --muted: var(--sidebar-label);
      --surface: var(--sidebar-field);
      --paper: var(--sidebar-field);
    }

    /* Section headings (Chart state, Collection, ...) are plain: the small uppercase label over a neutral hairline. */
    .library-filters__scopes + .library-filters__collection { padding-top: 1rem; border-top: 1px solid var(--sidebar-rule); }

    /* Apply filters: the outlined teal button (generic primary buttons), with the quietest pastel fill. */
    .library-finder__filters .library-filters__actions .button--primary,
    .library-finder__filters .library-filters__actions .button--primary:hover { background: var(--selected-fill-quiet); }

    .library-finder__filters > summary { display: none; }

    .library-finder__filters::details-content {
      display: block;
      content-visibility: visible;
    }

    .library-finder__filters-panel {
      position: static;
      width: auto;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 0;
      color: var(--ink);
      background: var(--sidebar-bg);
    }

    .library-finder__filters-panel::before {
      content: "Filters";
      font-family: var(--font-display);
      font-size: 1.25rem;
      font-weight: 400;
      line-height: 1.2;
    }


  }
}
