.background-library {
  margin: auto; width: min(1040px, calc(100vw - 48px)); height: min(780px, calc(100vh - 48px));
  max-width: none; max-height: none; padding: 22px; border: 1px solid var(--line-strong); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 80px var(--shadow);
}
.background-library[open] { display: flex; flex-direction: column; gap: 14px; }
.background-library::backdrop { background: rgba(5, 13, 24, .62); }
.bgl-head, .bgl-footer, .bgl-filters, .bgl-head-actions { display: flex; align-items: center; gap: 10px; }
.bgl-head, .bgl-footer { justify-content: space-between; flex: 0 0 auto; }
.bgl-head h2 { font-size: 23px; margin-top: 3px; }
.bgl-filters { align-items: end; }
.bgl-filters label { display: flex; flex-direction: column; align-items: stretch; gap: 5px; font-size: 12px; color: var(--label); text-align: left; }
.bgl-filters label:first-child { flex: 1; min-width: 130px; }
.bgl-filters label:nth-child(2) { width: 210px; }
.bgl-filters input, .bgl-filters select { width: 100%; min-height: 34px; }
.bgl-filters input[type="search"] { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--text); font: inherit; }
.bgl-filters input[type="search"]::placeholder { color: var(--muted); }
#bgl-count { white-space: nowrap; color: var(--muted); font-size: 12px; padding-bottom: 8px; }
.bgl-status { color: var(--muted); font-size: 12px; line-height: 1.4; min-height: 17px; }
.bgl-scroll { flex: 1; min-height: 90px; overflow: auto; padding: 3px 6px 3px 3px; }
.bgl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.bgl-tile { display: flex; flex-direction: column; gap: 6px; padding: 7px; min-width: 0; text-align: left; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.bgl-tile[aria-pressed="true"] { outline: 2px solid var(--accent); background: var(--accent-soft); }
.bgl-tile strong { font-size: 12px; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bgl-tile small { color: var(--muted); font-size: 10px; }
.bgl-thumbnail { aspect-ratio: 17 / 6; width: 100%; border-radius: 5px; background: var(--surface-3); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 12px; }
.bgl-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.bgl-empty { text-align: center; color: var(--muted); padding: 45px 25px; line-height: 1.8; font-size: 14px; }
.bgl-footer { padding-top: 12px; border-top: 1px solid var(--line); }
.bgl-footer > div { min-width: 0; }
#bgl-selected { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px; }
#bgl-apply { flex: 0 0 auto; padding: 11px 20px; }
@media (max-height: 700px) {
  .background-library { padding: 16px; gap: 10px; }
  .bgl-head h2 { font-size: 20px; }
}
