.library-page {
  min-height: 100vh;
  background: var(--bg-page);
  color: var(--text-main);
  padding: var(--page-top) 0 var(--page-bottom);

  --lib-row: 44px;
  --lib-line: var(--divider);
  --lib-line-strong: rgba(35,35,38,0.24);
  --lib-hover: rgba(35,35,38,0.045);
  --lib-card-hover: var(--bg-card);
}

html[data-theme="dark"] .library-page {
  --lib-line-strong: rgba(236,236,238,0.26);
  --lib-hover: rgba(236,236,238,0.05);
}

.library-page__container {
  width: 100%;
  max-width: 100%;
  padding: 0 var(--gutter);
  /* overflow visible — sheet rail crosses must not be clipped */
}

.library-layout {
  --lib-aside: 280px;
  position: relative;
  display: grid;
  grid-template-columns: var(--lib-aside) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}

/* Inside the sheet the sidebar divider becomes a rail: full page height, "+" where it meets the bottom line. */
html.has-sheet .library-sidebar__inner {
  border-right-color: transparent;
}

html.has-sheet .library-layout:not(.library-layout--single)::before,
html.has-sheet .library-layout:not(.library-layout--single)::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

html.has-sheet .library-layout:not(.library-layout--single)::before {
  top: calc(var(--page-top) * -1);
  bottom: calc(var(--page-bottom) * -1);
  left: calc(var(--lib-aside) - 1px);
  width: 1px;
  background: var(--rail-line);
}

html.has-sheet .library-layout:not(.library-layout--single)::after {
  bottom: calc(var(--page-bottom) * -1 - 5px);
  left: calc(var(--lib-aside) - 5px);
  width: 9px;
  height: 9px;
  color: var(--rail-cross);
  background:
    linear-gradient(currentColor, currentColor) 4px 0 / 1px 9px no-repeat,
    linear-gradient(currentColor, currentColor) 0 4px / 9px 1px no-repeat;
}

.library-layout--single {
  grid-template-columns: 1fr;
}

.library-count {
  flex: 0 0 auto;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* sidebar */

.library-sidebar {
  position: sticky;
  top: var(--page-top);
  align-self: start;
  height: calc(100vh - var(--page-top) - 20px);
}

.library-sidebar__inner {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-right: 20px;
  border-right: 1px solid var(--lib-line);
}

.library-sidebar__suggest {
  flex: 0 0 auto;
  margin-top: 12px;
  padding: 14px 8px 6px;
  border-top: 1px solid var(--lib-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: var(--fs-small);
  text-decoration: none;
  transition: color .2s ease;
}

.library-sidebar__suggest:visited {
  color: var(--text-muted);
}

.library-sidebar__suggest:hover {
  color: var(--text-main);
}

.library-sidebar__suggest svg {
  width: 14px;
  height: 14px;
  transition: transform .3s var(--ease-out);
}

.library-sidebar__suggest:hover svg {
  transform: translate(2px, -2px);
}

/* tree */

.library-nav {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.library-all {
  flex: 0 0 auto;
  width: 100%;
  height: var(--lib-row);
  padding: 0 8px;
  border: 0;
  border-bottom: 1px solid var(--lib-line);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-ui);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  transition: color .15s ease;
}

.library-all:hover,
.library-all.is-active {
  color: var(--text-main);
}

.library-all__title {
  flex: 1 1 auto;
}

.library-all.is-active .library-all__title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 10px 1px 0;
  border-radius: 50%;
  background: var(--text-main);
}

.library-groups {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-right: -8px;
  padding: 10px 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--lib-line) transparent;
}

.library-group__row {
  min-height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  transition: background .15s ease;
}

.library-group__row:hover {
  background: var(--lib-hover);
}

.library-group__check {
  flex: 0 0 auto;
  width: 34px;
  height: 38px;
  padding: 0 0 0 8px;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.library-group__toggle {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  padding: 0 8px 0 2px;
  border: 0;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: var(--fs-ui);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.library-group__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-group.is-selected .library-group__title {
  font-weight: 600;
}

.library-group__chevron {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  color: var(--text-soft);
  transition: transform .3s var(--ease-out), color .15s ease;
}

.library-group__chevron svg {
  width: 14px;
  height: 14px;
  display: block;
}

.library-group__row:hover .library-group__chevron {
  color: var(--text-main);
}

.library-group.is-open .library-group__chevron {
  transform: rotate(90deg);
}

.library-group__body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .3s var(--ease-out);
}

.library-group.is-open .library-group__body {
  grid-template-rows: 1fr;
}

.library-group__inner {
  min-height: 0;
  overflow: hidden;
  margin-left: 15px;
  padding-left: 18px;
  border-left: 1px solid var(--lib-line);
}

.library-group.is-open .library-group__inner {
  padding-top: 4px;
  padding-bottom: 10px;
}

.library-group__desc {
  margin: 0 8px 6px 0;
  color: var(--text-soft);
  font-size: var(--fs-caption);
  line-height: 1.45;
}

.library-group__options {
  display: flex;
  flex-direction: column;
}

.library-option {
  width: 100%;
  min-height: 32px;
  padding: 0 8px 0 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-small);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  transition: color .15s ease;
}

.library-option:hover,
.library-option[aria-checked="true"] {
  color: var(--text-main);
}

.library-option__label {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 0;
  line-height: 1.3;
}

/* checkbox */

.library-box {
  position: relative;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 1.5px solid var(--lib-line-strong);
  border-radius: var(--radius-xs);
  color: var(--bg-page);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background .15s ease,
    border-color .15s ease;
}

.library-box svg {
  position: absolute;
  width: 12px;
  height: 12px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .15s ease, transform .2s var(--ease-out);
}

[role="checkbox"]:hover .library-box {
  border-color: var(--text-main);
}

[aria-checked="true"] > .library-box,
[aria-checked="mixed"] > .library-box {
  background: var(--text-main);
  border-color: var(--text-main);
}

[aria-checked="true"] > .library-box .library-box__check,
[aria-checked="mixed"] > .library-box .library-box__dash {
  opacity: 1;
  transform: none;
}

[role="checkbox"]:focus-visible {
  outline: none;
}

[role="checkbox"]:focus-visible .library-box {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

/* content */

/* bottom spacing lives inside the grid row so the sticky sidebar is never pushed up at the end */
.library-content {
  min-width: 0;
  padding-bottom: var(--page-bottom);
}

.library-content__head {
  margin-bottom: 8px;
}

.library-content__meta {
  height: var(--lib-row);
  margin: 0 0 18px;
  border-bottom: 1px solid var(--lib-line);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  letter-spacing: 0.02em;
}

.library-crumb {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--lib-line-strong);
  text-underline-offset: 3px;
}

.library-crumb:hover {
  color: var(--text-main);
}

.library-crumb__sep {
  color: var(--lib-line-strong);
}

.library-content__title {
  margin: 0 0 12px;
  font-size: var(--fs-page-title);
  line-height: 1;
  letter-spacing: -0.045em;
  font-weight: 600;
  color: var(--text-main);
}

.library-content__desc {
  min-height: 1.55em;
  margin: 0;
  max-width: 640px;
  font-size: var(--fs-lead);
  line-height: 1.55;
  color: var(--text-muted);
  text-wrap: pretty;
}

/* toolbar: sticks under the header, its line aligns with "All resources" in the sidebar */

.library-toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  margin-bottom: 20px;
  padding-top: calc(var(--page-top) - var(--header-h));
  background: var(--bg-page);
}

.library-toolbar__row {
  min-height: var(--lib-row);
  padding: 7px 0;
  border-bottom: 1px solid var(--lib-line);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.library-toolbar__result {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.library-filters-trigger {
  display: none;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--lib-line-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: var(--fs-ui);
  font-weight: 500;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.library-filters-trigger svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.library-filters-trigger__count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-xs);
  background: var(--text-main);
  color: var(--bg-page);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 20px;
  text-align: center;
}

.library-filters-trigger__count[hidden] {
  display: none;
}

.library-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.library-chips:empty {
  display: none;
}

.library-chip {
  height: 28px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--lib-line-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: opacity .2s ease;
}

.library-chip:hover {
  opacity: .65;
}

.library-chip__x {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: color .2s ease;
}

.library-chip__x svg {
  width: 10px;
  height: 10px;
}

.library-chip:hover .library-chip__x {
  color: var(--text-main);
}

.library-chip--reset {
  padding: 0 8px;
  border-color: transparent;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--lib-line-strong);
}

.library-chip--reset:hover {
  border-color: transparent;
  color: var(--text-main);
}

/* grid */

.library-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.library-card {
  min-height: 228px;
  padding: 20px;
  border: 1px solid var(--lib-line);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  transition:
    background .25s ease,
    border-color .25s ease;
}

.library-card:visited,
.library-card:hover {
  color: var(--text-main);
  text-decoration: none;
}

.library-card:hover {
  background: var(--lib-card-hover);
  border-color: var(--lib-line-strong);
}

.library-card:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

.library-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.library-card__logo {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid var(--lib-line);
  border-radius: var(--radius-md);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.library-card__logo img {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: contain;
  border-radius: var(--radius-xs);
}

.library-card__logo:not(:has(img))::before {
  content: attr(data-letter);
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 600;
}

.library-card__tag {
  min-width: 0;
  max-width: 60%;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-card__title {
  margin: 18px 0 8px;
  font-size: var(--fs-card-title);
  line-height: 1.2;
  letter-spacing: -0.025em;
  font-weight: 600;
  color: var(--text-main);
}

.library-card__desc {
  margin: 0;
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-card__bottom {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.library-card__domain {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
}

.library-card__arrow {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 1px solid var(--lib-line);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  transition:
    background .25s ease,
    border-color .25s ease,
    color .25s ease;
}

.library-card__arrow svg {
  width: 14px;
  height: 14px;
  display: block;
  transition: transform .3s var(--ease-out);
}

.library-card:hover .library-card__arrow {
  background: var(--text-main);
  border-color: var(--text-main);
  color: var(--bg-page);
}

.library-card:hover .library-card__arrow svg {
  transform: translate(1px, -1px);
}

.library-empty {
  grid-column: 1 / -1;
  padding: 64px 0;
  text-align: center;
  font-size: var(--fs-lead);
  color: var(--text-muted);
}

/* single card */

.library-single {
  max-width: 760px;
  padding: 32px;
  border: 1px solid var(--lib-line);
  border-radius: var(--radius-lg);
}

/* Outline look from core/ui.css */
.library-single__back {
  margin-bottom: 24px;
}

.library-single__head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.library-single__title {
  margin: 20px 0 12px;
  font-size: var(--fs-page-title);
  line-height: 1.05;
  letter-spacing: -0.04em;
  font-weight: 600;
}

.library-single__desc {
  margin: 0;
  font-size: var(--fs-lead);
  line-height: 1.6;
  color: var(--text-muted);
}

.library-single__link {
  margin-top: 28px;
  height: 46px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: var(--fs-ui);
  font-weight: 500;
  transition: background .2s ease;
}

.library-single__link:hover,
.library-single__link:visited {
  color: var(--button-primary-text);
}

.library-single__link:hover {
  background: var(--button-primary-bg-hover);
}

.library-single__host {
  opacity: .6;
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
}

.library-single__link svg {
  width: 16px;
  height: 16px;
}

/* mobile sheet */

.library-filters-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear .4s;
}

.library-filters-modal.is-open {
  visibility: visible;
  pointer-events: auto;
  transition: none;
}

.library-filters-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12,12,14,0.42);
  opacity: 0;
  transition: opacity .35s ease;
}

.library-filters-modal.is-open .library-filters-modal__backdrop {
  opacity: 1;
}

.library-filters-modal__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  border-top: 1px solid var(--lib-line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(100%);
  transition: transform .4s var(--ease-out);
}

.library-filters-modal.is-open .library-filters-modal__panel {
  transform: none;
}

.library-filters-modal__head {
  min-height: 56px;
  padding: 0 10px 0 var(--gutter);
  border-bottom: 1px solid var(--lib-line);
  display: flex;
  align-items: center;
  gap: 8px;
}

.library-filters-modal__title {
  flex: 1 1 auto;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.library-filters-modal__close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-main);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.library-filters-modal__close:hover {
  background: var(--lib-hover);
}

.library-filters-modal__close svg {
  width: 20px;
  height: 20px;
}

.library-filters-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--gutter) 12px;
}

.library-nav--mobile .library-groups {
  overflow: visible;
  margin: 0;
  padding-right: 0;
}

.library-nav--mobile .library-all {
  height: 52px;
  font-size: 15px;
}

.library-nav--mobile .library-group__row,
.library-nav--mobile .library-group__check,
.library-nav--mobile .library-group__toggle {
  min-height: 46px;
  height: 46px;
}

.library-nav--mobile .library-group__toggle {
  font-size: 15px;
}

.library-nav--mobile .library-option {
  min-height: 42px;
  font-size: 14.5px;
}

.library-filters-modal__foot {
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--lib-line);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
}

.library-filters-modal__reset,
.library-filters-modal__apply {
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.library-filters-modal__reset {
  border: 1px solid var(--lib-line-strong);
  background: transparent;
  color: var(--text-main);
}

.library-filters-modal__reset:disabled {
  opacity: .4;
  cursor: default;
}

.library-filters-modal__apply {
  border: 0;
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
}

/* adaptives */

@media (max-width: 1359px) {
  .library-layout {
    --lib-aside: 256px;
    gap: 28px;
  }

  .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1023px) {
  .library-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .library-sidebar,
  html.has-sheet .library-layout:not(.library-layout--single)::before,
  html.has-sheet .library-layout:not(.library-layout--single)::after {
    display: none;
  }

  .library-toolbar {
    padding-top: 12px;
  }

  .library-filters-trigger {
    display: inline-flex;
  }
}

@media (max-width: 767px) {
  .library-content__meta {
    margin-bottom: 14px;
  }

  .library-content__title {
    margin-bottom: 10px;
  }

  .library-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .library-card {
    min-height: 0;
    padding: 16px;
  }

  .library-card__title {
    margin-top: 14px;
  }

  .library-card__bottom {
    padding-top: 14px;
  }

  .library-single {
    padding: 22px;
  }
}
