/* Unified file browser.
 * Gallery, Files and Works share this layout and interaction model. */
.library-browser-screen {
  --library-card-size: 218px;
  position: relative;
  display: flex;
  height: 100%;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  /* Снизу поля нет: список должен доходить до низа экрана, а не обрываться за
     полосой воздуха — прокручиваемая область и так кончается кромкой окна.
     Мобильному запас снизу нужен (док), он ниже своим правилом. */
  padding: clamp(22px, 3vw, 42px) clamp(22px, 3vw, 42px) 0;
  overflow: hidden;
  background: var(--paper);
}

.library-browser-screen.is-picker {
  min-height: 0;
}

.library-browser-context {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
}

.library-context-inner {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.library-context-head {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Полоса первой строки панели общая для всех разделов — см. .context-head
     в shell.css. Своя высота здесь снова развела бы «Галерею» с «Задачами». */
  min-height: var(--panel-head-h, 30px);
  margin: var(--panel-head-top, 3px) 4px 16px;
}

.library-context-head strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: .1em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.library-search {
  margin-bottom: 12px;
}

.library-search input {
  min-width: 0;
}

.library-search {
  border: 1px solid transparent;
  transition: border-color 100ms ease, box-shadow 100ms ease, background 100ms ease;
}

.library-search.is-drop-target {
  background: color-mix(in srgb, var(--accent-soft) 76%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 13%, transparent);
}

.library-nav-actions {
  display: flex;
  margin-right: 12px;
  margin-left: auto;
  gap: 2px;
}

.library-nav-actions .icon-btn {
  /* Размер кнопки сворачивания панели — стрелки стоят с ней в одном ряду и
     должны читаться одной деталью, а не двумя разными. */
  width: 30px;
  height: 30px;
}

/* В покое кнопки остаются лёгкими — ни фона, ни рамки. Под курсором они
   становятся ровно кнопкой сворачивания панели: те же чернила, та же бумага,
   та же линия. Значения повторяют .panel-collapse-button из primitives.css. */
.library-nav-actions .icon-btn:hover,
.library-nav-actions .icon-btn:focus-visible {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line-strong);
}

.library-search input {
  padding-right: 12px;
}

.library-search.has-reference input {
  padding-left: 73px;
}

.library-search-image-hint {
  margin: -6px 2px 11px 34px;
  color: var(--muted-2);
  font-size: 9px;
  line-height: 1.35;
}

.library-search-image-hint button {
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font: inherit;
  line-height: inherit;
  text-decoration-color: color-mix(in srgb, var(--muted) 58%, transparent);
  text-decoration-line: underline;
  text-decoration-style: dashed;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.library-search-image-hint button:hover,
.library-search-image-hint button:focus-visible {
  color: var(--ink);
  outline: 0;
  text-decoration-color: currentColor;
}

.library-search-reference {
  position: absolute;
  z-index: 3;
  left: 34px;
  display: block;
  width: 30px;
  height: 30px;
}

.library-search-reference img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-8);
}

.library-search-reference button {
  position: absolute;
  top: -4px;
  right: -4px;
  display: grid;
  width: 14px;
  height: 14px;
  place-items: center;
  padding: 0;
  color: var(--paper);
  background: color-mix(in srgb, var(--ink) 86%, transparent);
  border: 1px solid color-mix(in srgb, var(--surface) 50%, transparent);
  border-radius: var(--radius-pill);
  opacity: 0;
  transition: opacity 70ms ease;
}

.library-search-reference:hover button,
.library-search-reference button:focus-visible {
  opacity: 1;
}

.library-search-reference .icon {
  width: 8px;
  height: 8px;
}

.library-search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: -5px 0 11px;
}

.library-search-filters:empty {
  display: none;
}

.library-search-filter {
  display: inline-flex;
  min-width: 0;
  min-height: 25px;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 10px;
  line-height: 1;
}

button.library-search-filter:hover,
button.library-search-filter:focus-visible {
  background: var(--surface);
  border-color: var(--line-strong);
  outline: 0;
}

.library-search-filter > span {
  overflow: hidden;
  max-width: 132px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-search-filter > small {
  color: var(--muted-2);
  font-size: 8px;
  letter-spacing: .03em;
}

.library-search-filter.is-manual {
  border-style: solid;
}

.library-search-filter.is-inferred {
  border-style: dashed;
}

.library-search-filter .icon {
  width: 9px;
  height: 9px;
  color: var(--muted);
}

.library-context-scroll {
  min-height: 0;
  min-width: 0;
  padding: 12px 4px 18px 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.library-tree-branch {
  min-width: 0;
}

.library-tree-children {
  transform-origin: top left;
  animation: library-tree-reveal 130ms ease-out;
}

@keyframes library-tree-reveal {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.library-tree-row {
  position: relative;
  display: grid;
  min-width: 0;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  padding-left: calc(var(--tree-depth, 0) * 15px);
  border-radius: var(--radius-8);
}

.library-tree-row::after {
  position: absolute;
  inset: 2px;
  z-index: -1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  content: "";
  pointer-events: none;
}

.library-tree-row:hover::after {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

/* Открытая папка — как выделенная строка в Finder и проводнике. Прежде она
   отличалась от соседей лишь подложкой в цвет поверхности: на пятом уровне
   вложенности её приходилось искать глазами, и было непонятно, куда ты
   вообще зашёл. Подсвечивается ровно одна строка — текущая. */
.library-tree-row.active::after {
  background: color-mix(in srgb, var(--accent-soft) 82%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
}

.library-tree-row.active .library-tree-open,
.library-tree-row.active .library-tree-open > .icon {
  color: var(--ink);
}

.library-tree-row.active .library-tree-open > span {
  font-weight: 680;
}

.library-tree-row.can-drop.is-drop-target::after {
  background: color-mix(in srgb, var(--accent-soft) 84%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 14%, transparent);
}

.library-tree-toggle {
  display: grid;
  width: 24px;
  height: 32px;
  place-items: center;
  color: var(--muted-2);
}

.library-tree-toggle .icon {
  width: 12px;
  height: 12px;
}

.library-tree-open {
  display: grid;
  min-width: 0;
  min-height: 36px;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 7px 7px 2px;
  color: var(--ink-2);
  background: transparent;
  text-align: left;
}

.library-tree-open > .icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.library-tree-open > span {
  overflow: hidden;
  font-size: 13px;
  font-weight: 590;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-tree-open > small {
  color: var(--muted-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.library-tree-open.active {
  color: var(--ink);
  background: var(--surface);
}

.library-browser-head {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.library-browser-head > :first-child {
  min-width: 0;
}

.library-browser-head h1 {
  max-width: 900px;
  margin: 8px 0 4px;
  font-family: var(--serif);
  font-size: clamp(34px, 4vw, 48px);
  font-weight: 520;
  line-height: .98;
  letter-spacing: -.045em;
}

.library-browser-head .screen-subtitle {
  margin: 0;
}

.library-browser-head-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.library-breadcrumbs {
  display: flex;
  max-width: min(780px, 70vw);
  align-items: center;
  gap: 4px;
  overflow: hidden;
  color: var(--muted);
}

/* В корне раздела путь пуст — заголовок и есть весь путь. */
.library-breadcrumbs:empty {
  display: none;
}

.library-breadcrumbs > span {
  overflow: hidden;
  max-width: 220px;
  color: inherit;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-breadcrumbs > span[role="link"] {
  cursor: pointer;
}

.library-breadcrumbs > span[role="link"]:hover,
.library-breadcrumbs > span[role="link"]:focus-visible,
.library-breadcrumbs > span[aria-current="page"] {
  color: var(--ink);
  outline: 0;
}

.library-breadcrumbs > i {
  color: var(--muted-2);
  font-style: normal;
}

.library-browser-toolbar {
  display: flex;
  /* Экран — колоночный флекс, и по умолчанию строка фильтров сжималась до
     min-height. Фильтры при этом переносятся на три ряда и, центрируясь в
     сорока пикселях, вылезали ВВЕРХ прямо на заголовок раздела. Полоса
     обязана занимать столько, сколько нужно её содержимому. */
  flex: none;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.library-browser-filters,
.library-view-controls,
.library-filter-group {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}

.library-browser-filters {
  flex-wrap: wrap;
}

.library-designer-filter {
  position: relative;
}

.library-designer-filter > summary {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  list-style: none;
  cursor: pointer;
}

.library-designer-filter > summary::-webkit-details-marker {
  display: none;
}

.library-designer-filter > summary .icon:last-child {
  width: 11px;
  height: 11px;
  margin-left: 2px;
}

.library-designer-filter-menu {
  position: absolute;
  z-index: 22;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  width: min(280px, calc(100vw - 32px));
  max-height: min(360px, 60svh);
  gap: 2px;
  padding: 6px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-12);
}

.library-designer-filter-menu button,
.library-designer-filter-menu label {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  color: var(--ink);
  background: transparent;
  border-radius: var(--radius-8);
  font-size: 12px;
  text-align: left;
}

.library-designer-filter-menu button:hover,
.library-designer-filter-menu button.active,
.library-designer-filter-menu label:hover {
  background: var(--paper);
}

.library-designer-filter-menu input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.library-view-controls {
  margin-left: auto;
  flex: 0 0 auto;
}

.library-view-controls .icon-btn {
  width: 34px;
  height: 34px;
}

.library-view-controls .icon-btn.active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.library-scale {
  display: grid;
  width: 154px;
  grid-template-columns: 16px minmax(80px, 1fr) 16px;
  align-items: center;
  gap: 7px;
  margin-left: 5px;
}

.library-scale .icon {
  width: 13px;
  height: 13px;
  color: var(--muted);
}

.library-scale input {
  width: 100%;
  accent-color: var(--ink);
}

.library-inline-editor {
  position: absolute;
  top: clamp(118px, 16vw, 166px);
  right: clamp(22px, 3vw, 42px);
  z-index: 12;
  display: grid;
  width: min(340px, calc(100% - 32px));
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-16);
}

.library-inline-editor-head,
.library-inline-editor-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.library-inline-editor-head {
  justify-content: space-between;
}

.library-inline-editor-head strong {
  font-size: 15px;
}

.library-inline-editor label {
  display: grid;
  gap: 6px;
}

.library-inline-editor label > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.library-inline-editor input,
.library-inline-editor select,
.library-inline-editor textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-8);
  outline: 0;
  resize: vertical;
}

.library-inline-editor input:focus,
.library-inline-editor select:focus,
.library-inline-editor textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 10%, transparent);
}

.library-inline-editor-actions {
  justify-content: flex-end;
}

.library-context-menu {
  position: fixed;
  z-index: 40;
  top: min(var(--menu-y), calc(100svh - 220px));
  left: min(var(--menu-x), calc(100vw - 220px));
  display: grid;
  width: 204px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-12);
}

.library-context-menu button {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: var(--radius-8);
  text-align: left;
}

.library-context-menu button:hover,
.library-context-menu button:focus-visible {
  background: var(--paper);
  outline: 0;
}

.library-context-menu .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}

.library-browser-content {
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.library-search-results {
  display: grid;
  min-width: 0;
  gap: 26px;
}

.library-search-section {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.library-search-section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.library-search-section-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
  letter-spacing: .01em;
}

.library-search-section-head span {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.library-search-fallback,
.library-search-judging {
  display: flex;
  width: fit-content;
  max-width: 720px;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.library-search-fallback .icon {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
}

.library-search-judging > span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: var(--radius-pill);
  animation: library-search-pulse 900ms ease-in-out infinite alternate;
}

.library-search-confidence {
  display: flex;
  max-width: 760px;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 10px 10px 12px;
  background: color-mix(in srgb, var(--accent-soft) 30%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
  border-radius: var(--radius-12);
}

.library-search-confidence > div {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  gap: 9px;
}

.library-search-confidence .icon {
  width: 15px;
  height: 15px;
  margin-top: 1px;
  color: var(--accent);
  flex: 0 0 auto;
}

.library-search-confidence span {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
}

.library-search-confidence strong {
  color: var(--ink);
  font-size: 12px;
}

@keyframes library-search-pulse {
  from {
    opacity: .32;
    transform: scale(.8);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.library-progressive-more {
  display: flex;
  justify-content: center;
  padding: 18px 0 8px;
}

.library-card-grid {
  /* Наведение приподнимает карточку, а прокручиваемая область режет всё выше
     своего верха. Первая строка стояла к нему вплотную, и у поднятой карточки
     срезало верхнюю грань. Запас сверху равен подъёму и задаётся здесь же,
     чтобы эти два числа не разъехались. */
  --library-card-lift: 2px;
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(auto-fill, var(--library-card-size));
  align-items: start;
  gap: 18px;
  padding-top: var(--library-card-lift);
}

.library-card {
  position: relative;
  display: grid;
  width: var(--library-card-size);
  min-width: 0;
  grid-template-rows: auto minmax(58px, auto) auto;
  overflow: visible;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-16);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.library-card:hover,
.library-card:focus-within {
  z-index: 5;
  border-color: var(--line-strong);
  transform: translateY(calc(var(--library-card-lift, 2px) * -1));
}

.library-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* Карточка папки — такая же цель для броска, как строка дерева, но состояния
   «сюда положить» у неё не было вовсе: перетаскивание из дерева в сетку папок
   выглядело мёртвым — ни рамки, ни подложки, понять, куда ляжет объект, нечем.
   Язык берём у строки дерева (акцентная рамка и свечение), кольцо чуть шире
   выделения, чтобы «сюда положить» не путалось с «выбрано». */
.library-card.is-drop-target {
  background: color-mix(in srgb, var(--accent-soft) 64%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.library-card[tabindex]:focus-visible,
.library-table tr[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.library-card.is-dragging {
  opacity: .52;
  transform: scale(.98);
}

.library-table tr.is-dragging {
  opacity: .52;
}

/* Поверхности перехода карточки — ссылки (Cmd+клик, средняя кнопка,
   «открыть в новой вкладке»), поэтому им нужен сброс подчёркивания. */
a.library-card-media,
a.library-card-open {
  text-decoration: none;
}

.library-card-media {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--surface-2) 80%, var(--paper)), var(--surface-2));
  aspect-ratio: 1 / .78;
  border-radius: var(--radius-16) var(--radius-16) 0 0;
}

.library-item-card .library-card-media {
  background:
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--surface) 55%, transparent), transparent 58%),
    var(--surface-2);
}

.library-item-card .library-card-media img,
.library-item-card .library-card-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.library-card-open {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: inherit;
}

.library-card-open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.library-card-copy {
  display: grid;
  min-width: 0;
  align-content: center;
  gap: 4px;
  padding: 12px 13px 10px;
}

.library-card-copy strong,
.library-card-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-card-copy strong {
  font-size: 14px;
  font-weight: 690;
}

.library-card-copy small {
  color: var(--muted);
  font-size: 11px;
}

.library-card-reason {
  display: -webkit-box;
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 10px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-folder-search-reason {
  display: -webkit-box;
  margin: 0;
  padding: 10px 12px;
  overflow: hidden;
  color: var(--ink-2);
  border-top: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-card-actions {
  display: flex;
  min-height: 43px;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 5px 7px;
  border-top: 1px solid var(--line);
}

.library-card-actions .icon-btn {
  position: relative;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--muted);
}

.library-card-actions .icon-btn:hover,
.library-card-actions .icon-btn:focus-visible,
.library-card-actions .icon-btn.active {
  color: var(--ink);
  background: var(--surface-2);
}

.library-retrieval-reject,
.library-retrieval-undo {
  min-height: 28px;
  padding: 0 7px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-8);
  font-size: 10px;
  font-weight: 620;
  line-height: 1;
}

.library-retrieval-reject:hover,
.library-retrieval-reject:focus-visible,
.library-retrieval-undo:hover,
.library-retrieval-undo:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: 0;
}

.library-card-actions > .library-retrieval-reject {
  margin-right: auto;
}

.library-folder-actions > .library-retrieval-reject {
  color: rgba(255, 255, 255, .9);
  background: rgba(24, 24, 24, .58);
  border: 1px solid rgba(255, 255, 255, .12);
  backdrop-filter: blur(10px);
}

.library-folder-actions > .library-retrieval-reject:hover,
.library-folder-actions > .library-retrieval-reject:focus-visible {
  color: white;
  background: rgba(24, 24, 24, .78);
}

.library-retrieval-rejected {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  border-style: dashed;
  animation: library-retrieval-collapse 180ms ease-out;
  font-size: 11px;
}

.library-table .library-retrieval-rejected td {
  padding: 10px 14px;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

.library-table .library-retrieval-rejected td > span {
  margin-right: 10px;
  color: var(--muted);
  font-size: 11px;
}

.library-table-actions > .library-retrieval-reject {
  margin-right: 2px;
}

@keyframes library-retrieval-collapse {
  from {
    opacity: .35;
    transform: scale(.985);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.library-card-select {
  position: absolute;
  z-index: 5;
  top: 9px;
  left: 9px;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 34%, transparent);
  border-radius: 50%;
  backdrop-filter: blur(9px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 80ms ease, transform 80ms ease;
}

.library-card-select .icon {
  width: 13px;
  height: 13px;
}

.library-card.selected .library-card-select {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.library-card:hover .library-card-select,
.library-card:focus-within .library-card-select,
.library-browser-screen.selecting .library-card-select {
  opacity: 1;
  pointer-events: auto;
}

.library-preview-count {
  position: absolute;
  /* Выше кликового оверлея карточки (.library-card-open, z-index 2) — иначе
     счётчик уходит под него. pointer-events снимаем, чтобы клик по углу
     по-прежнему открывал работу. */
  z-index: 4;
  right: 9px;
  bottom: 9px;
  padding: 4px 7px;
  color: white;
  background: rgba(25, 25, 25, .72);
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.library-near-twins {
  position: absolute;
  z-index: 4;
  bottom: 9px;
  left: 9px;
  padding: 4px 7px;
  color: white;
  background: rgba(25, 25, 25, .72);
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 680;
  line-height: 1;
  pointer-events: none;
}

button.library-near-twins {
  border: 0;
  cursor: pointer;
  pointer-events: auto;
  transition: background 90ms ease, transform 90ms ease;
}

button.library-near-twins:hover,
button.library-near-twins:focus-visible,
button.library-near-twins[aria-expanded="true"] {
  background: rgba(25, 25, 25, .9);
  outline: 0;
  transform: translateY(-1px);
}

.library-near-twin-list {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0 10px 11px;
  animation: library-variants-open 140ms ease-out;
}

.library-near-twin-list > a,
.library-near-twin-item {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding: 5px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  font-size: 9px;
  line-height: 1.25;
  text-decoration: none;
}

.library-near-twin-list > a:hover,
.library-near-twin-list > a:focus-visible {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line-strong);
  outline: 0;
}

.library-near-twin-list > :is(a, .library-near-twin-item) > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-near-twin-thumb {
  display: grid;
  overflow: hidden;
  aspect-ratio: 1.35 / 1;
  place-items: center;
  background: var(--paper);
  border-radius: var(--radius-4);
}

.library-near-twin-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.library-near-twin-thumb .icon {
  width: 15px;
  height: 15px;
  color: var(--muted-2);
}

.library-table .library-near-twins.is-table {
  position: static;
  width: max-content;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.library-table .library-near-twins.is-table:hover,
.library-table .library-near-twins.is-table:focus-visible,
.library-table .library-near-twins.is-table[aria-expanded="true"] {
  color: var(--ink);
  background: var(--surface-2);
  transform: none;
}

.library-table-variants td {
  padding: 10px 12px !important;
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.library-table-variants .library-near-twin-list {
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  padding: 0;
}

@keyframes library-variants-open {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.library-folder-card .library-near-twins {
  top: 9px;
  right: 9px;
  bottom: auto;
  left: auto;
}

.library-item-card.retrieval-updated {
  animation: library-retrieval-update 480ms ease-out;
}

@keyframes library-retrieval-update {
  from {
    border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
  }

  to {
    border-color: var(--line);
  }
}

.library-quality-badges {
  position: absolute;
  z-index: 4;
  right: 8px;
  top: 8px;
  display: flex;
  max-width: calc(100% - 50px);
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  pointer-events: none;
}

.library-quality-badge {
  padding: 4px 6px;
  color: rgba(255, 255, 255, .94);
  background: rgba(24, 24, 24, .72);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(8px);
  font-size: 9px;
  font-weight: 680;
  line-height: 1;
}

.library-quality-badge.conversion {
  background: color-mix(in srgb, var(--accent) 78%, rgba(24, 24, 24, .72));
}

.library-preview-stack {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  gap: 2px;
  background: var(--surface-2);
}

.library-preview-stack.preview-1 {
  grid-template-columns: 1fr;
}

.library-preview-stack.preview-2 {
  grid-template-columns: 1fr 1fr;
}

/* Скраб листает до восьми кадров, но мозаика в покое остаётся из четырёх
   плиток: восемь клеток на карточке — уже не превью, а рябь. Пятая и дальше
   картинки лежат в разметке и показываются только под курсором. */
.library-preview-stack.preview-3,
.library-preview-stack.preview-4,
.library-preview-stack.preview-5,
.library-preview-stack.preview-6,
.library-preview-stack.preview-7,
.library-preview-stack.preview-8 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.library-preview-stack.preview-3 img:first-child {
  grid-row: 1 / span 2;
}

/* Первый ребёнок стопки — иконка-заглушка, поэтому пятая картинка это шестой
   ребёнок. При скрабе правило снимается: кадры позиционируются абсолютно. */
.library-preview-stack:not(.is-scrubbing) img:nth-child(n + 6) {
  display: none;
}

.library-preview-stack img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  opacity: 0;
  transition: opacity 140ms ease;
}

.library-preview-stack img.is-loaded {
  opacity: 1;
}

/* Вытянутая картинка показывается целиком: у тумбы просто нет пикселей по
   короткой стороне, а cover растягивал её и давал мыло. */
.library-preview-stack img.fit-contain {
  object-fit: contain;
}

.library-preview-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-2);
  background:
    radial-gradient(circle at 28% 24%, color-mix(in srgb, var(--accent-soft) 52%, transparent), transparent 46%),
    var(--surface-2);
  transition: opacity 140ms ease;
}

/* Заглушка нужна, только пока картинок нет: под плитками она просвечивала
   сквозь зазоры и поля и читалась как «превью не загрузилось». */
.library-preview-stack.has-preview .library-preview-fallback {
  opacity: 0;
}

.library-preview-fallback .icon {
  width: 42px;
  height: 42px;
  stroke-width: 1.2;
}

.library-preview-stack.is-scrubbing {
  display: block;
  position: relative;
}

.library-preview-stack.is-scrubbing img {
  position: absolute;
  inset: 0;
  opacity: 0;
  object-fit: contain;
}

.library-preview-stack.is-scrubbing img.is-scrub-frame {
  opacity: 1;
}

/* Плитки карточки заполняют клетку целиком — обрезка тут допустима (решение
   Эдварда 28.07). Кадр скраба ниже, наоборот, показывает макет целиком. */
.library-item-preview-stack img {
  object-fit: cover;
}

.library-preview-stack.is-scrubbing {
  background: var(--surface-3, var(--surface-2));
}

.library-folder-card {
  display: block;
  aspect-ratio: 1 / .82;
  overflow: visible;
  background: var(--surface-2);
  container-name: library-folder-card;
  container-type: inline-size;
}

.library-folder-card.archived {
  opacity: .64;
}

.library-folder-card .library-card-media {
  height: 100%;
  aspect-ratio: auto;
  border-radius: var(--radius-16);
}

.library-folder-overlay {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  min-width: 0;
  gap: 3px;
  padding: 42px 13px 12px;
  color: white;
  background: linear-gradient(transparent, rgba(18, 18, 18, .84));
  text-align: left;
  pointer-events: none;
}

.library-folder-overlay strong,
.library-folder-overlay small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-folder-overlay strong {
  font-size: 14px;
  font-weight: 720;
}

.library-folder-overlay small {
  color: rgba(255, 255, 255, .72);
  font-size: 10px;
}

.library-folder-menu {
  position: relative;
  z-index: 9;
}

.library-folder-menu summary {
  position: relative;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: rgba(255, 255, 255, .88);
  background: rgba(24, 24, 24, .58);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius-8);
  list-style: none;
  cursor: pointer;
  backdrop-filter: blur(9px);
}

.library-folder-menu summary::-webkit-details-marker {
  display: none;
}

.library-folder-menu-popup {
  position: absolute;
  z-index: 12;
  top: calc(100% + 6px);
  right: 0;
  bottom: auto;
  display: grid;
  width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-12);
}

.library-folder-menu-popup button {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: var(--radius-8);
  text-align: left;
}

.library-folder-menu-popup button:hover,
.library-folder-menu-popup button:focus-visible {
  background: var(--paper);
  outline: 0;
}

.library-folder-menu-popup .icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
}

/* Кнопки действий живут под курсором. Постоянно висящий ряд из пяти плашек
   закрывал саму папку (в блюдах — половину мозаики) и перехватывал клики,
   которыми папку выделяют. Мышью их видно на наведении, с клавиатуры — на
   фокусе, на тач-экране (где наведения нет) — всегда. */
.library-folder-actions {
  position: absolute;
  z-index: 8;
  top: 9px;
  right: 9px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.library-card:hover > .library-folder-actions,
.library-card:focus-within > .library-folder-actions,
.library-card.selected > .library-folder-actions,
.library-folder-actions:has(details[open]) {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none) {
  .library-folder-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

.library-folder-actions > .icon-btn {
  position: relative;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: rgba(255, 255, 255, .88);
  background: rgba(24, 24, 24, .58);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius-8);
  backdrop-filter: blur(10px);
}

.library-folder-inline-action.action-priority-3,
.library-folder-menu-popup .overflow-priority-1,
.library-folder-menu-popup .overflow-priority-2 {
  display: none;
}

/* «Выше»/«Ниже» — только там, где нет мыши: порядок папок меняют
   перетаскиванием, а две лишние кнопки в каждой карточке стоили больше, чем
   давали. На тач-экране перетаскивать нечем, поэтому там они остаются. */
.library-folder-reorder-action {
  display: none;
}

@media (hover: none) {
  .library-folder-reorder-action {
    display: flex;
  }
}

@container library-folder-card (min-width: 158px) {
  .library-folder-inline-action.action-priority-3 {
    display: grid;
  }

  .library-folder-menu-popup .overflow-priority-3 {
    display: none;
  }
}

@container library-folder-card (min-width: 158px) {
  @media (hover: hover) {
    .library-folder-menu {
      display: none;
    }
  }
}

.library-folder-actions > .icon-btn:hover,
.library-folder-actions > .icon-btn:focus-visible,
.library-folder-menu summary:hover,
.library-folder-menu summary:focus-visible {
  color: white;
  background: rgba(24, 24, 24, .78);
}

.library-folder-empty,
.library-file-empty {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--muted-2);
}

.library-folder-empty .icon,
.library-file-empty .icon {
  width: 42px;
  height: 42px;
  stroke-width: 1.2;
}

.library-actions-menu {
  position: relative;
}

.library-actions-menu summary {
  display: flex;
  align-items: center;
  gap: 7px;
  list-style: none;
  cursor: pointer;
}

.library-actions-menu summary::-webkit-details-marker {
  display: none;
}

.library-actions-popup {
  position: absolute;
  z-index: 20;
  top: calc(100% + 7px);
  right: 0;
  display: grid;
  width: max-content;
  min-width: 176px;
  gap: 3px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-12);
}

.library-actions-popup button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  color: var(--ink);
  background: transparent;
  border-radius: var(--radius-8);
  text-align: left;
}

.library-actions-popup button:hover {
  background: var(--surface-2);
}

.library-actions-popup .icon {
  width: 16px;
  height: 16px;
}

.library-table-wrap {
  overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-12);
}

.library-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  font-size: 12px;
}

.library-table th,
.library-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.library-table th {
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.library-table th > button {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 5px;
  margin: -7px -8px;
  padding: 7px 8px;
  color: inherit;
  background: transparent;
  border-radius: var(--radius-4);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.library-table th > button:hover,
.library-table th > button:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: 0;
}

.library-table th > button .icon {
  width: 11px;
  height: 11px;
}

.library-table th > .library-table-select-all {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  margin: 0;
  padding: 0;
}

.library-table th > .library-table-select-all:hover,
.library-table th > .library-table-select-all:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: 0;
}

.library-table th > .library-table-select-all .icon {
  width: 12px;
  height: 12px;
}

.library-table tbody tr:last-child td {
  border-bottom: 0;
}

.library-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-2) 34%, transparent);
}

.library-table tbody tr:hover {
  background: var(--surface);
}

.library-table-name {
  display: flex;
  width: min(320px, 30vw);
  min-width: 180px;
  max-width: 320px;
  align-items: center;
  gap: 10px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 680;
  text-align: left;
}

.library-table-thumb {
  position: relative;
  display: block;
  width: 42px;
  height: 34px;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--surface-2);
  border-radius: var(--radius-4);
}

.library-table-thumb > img,
.library-table-thumb > video,
.library-table-thumb .library-preview-stack,
.library-table-thumb .library-file-empty,
.library-table-thumb .library-folder-empty {
  width: 100%;
  height: 100%;
}

.library-table-thumb > img,
.library-table-thumb > video,
.library-table-thumb .library-preview-stack img {
  object-fit: contain;
}

.library-table-thumb .library-preview-fallback .icon,
.library-table-thumb .library-file-empty .icon,
.library-table-thumb .library-folder-empty .icon {
  width: 16px;
  height: 16px;
}

.library-table-name-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.library-table-name-copy strong,
.library-table-name-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-table-name-copy strong {
  font-size: 12px;
  font-weight: 680;
}

.library-table-name-copy small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
}

.library-table-check {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: white;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 80ms ease;
}

.library-table-check.selected,
.library-table tbody tr:hover .library-table-check,
.library-table tbody tr:focus-within .library-table-check,
.library-browser-screen.selecting .library-table-check {
  opacity: 1;
  pointer-events: auto;
}

.library-table-check.selected {
  background: var(--accent);
  border-color: var(--accent);
}

/* ОДНА линия на всю галерею: и дерево, и сетка, и таблица показывают место
   вставки одним элементом, который ставится в середину щели (см. showDropLine).
   Раньше это были ::before у соседей — «после A» и «до B» рисовались в разных
   точках одной щели и дрожали на пиксель при каждом движении мыши. */
.library-drop-line {
  position: fixed;
  z-index: 180;
  background: var(--accent);
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 14%, transparent);
  opacity: 0;
  pointer-events: none;
}

.library-drop-line.is-visible {
  opacity: 1;
}

.library-table tr.is-drop-target td {
  background: color-mix(in srgb, var(--accent-soft) 72%, var(--surface));
}

.library-table-check .icon {
  width: 12px;
  height: 12px;
}

.library-table-actions {
  position: relative;
  display: flex;
  gap: 2px;
}

.library-table-actions .icon-btn {
  position: relative;
  width: 28px;
  height: 28px;
}

.library-empty,
.library-browser-error {
  display: grid;
  min-height: 300px;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.library-empty > .icon {
  width: 42px;
  height: 42px;
  margin-bottom: 14px;
}

.library-empty h2,
.library-browser-error h1 {
  margin: 0 0 7px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 520;
}

.library-empty p,
.library-browser-error p {
  margin: 0 0 18px;
}

.library-node-loading {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.library-browser-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}

.library-browser-skeleton span {
  min-height: 230px;
  background: var(--surface-2);
  border-radius: var(--radius-16);
  animation: gallery-pulse 1.2s ease-in-out infinite alternate;
}

.library-picker-bar {
  position: fixed;
  z-index: 25;
  right: clamp(16px, 3vw, 42px);
  bottom: max(16px, env(safe-area-inset-bottom));
  left: calc(var(--rail-w) + var(--context-w) + clamp(16px, 3vw, 42px));
  display: grid;
  min-height: 58px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 9px;
  color: var(--on-dark);
  background: color-mix(in srgb, var(--surface-dark) 94%, transparent);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius-16);
  backdrop-filter: blur(16px);
}

.library-selection-bar {
  position: fixed;
  z-index: 25;
  right: clamp(16px, 3vw, 42px);
  bottom: max(16px, env(safe-area-inset-bottom));
  left: calc(var(--rail-w) + var(--context-w) + clamp(16px, 3vw, 42px));
  display: grid;
  min-height: 58px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 9px 10px 9px 16px;
  color: var(--on-dark);
  background: color-mix(in srgb, var(--surface-dark) 94%, transparent);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius-16);
  backdrop-filter: blur(16px);
}

.library-selection-bar > strong {
  font-size: 13px;
}

.library-selection-bar > span {
  overflow: hidden;
  color: rgba(255, 255, 255, .62);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-selection-bar > div {
  display: flex;
  align-items: center;
  gap: 5px;
}

.library-selection-bar .btn,
.library-selection-bar .icon-btn {
  color: var(--on-dark);
  border-color: rgba(255, 255, 255, .18);
}

.library-bulk-panel {
  display: grid;
  width: min(760px, 100%);
  max-height: min(520px, calc(100svh - 250px));
  gap: 12px;
  margin: -4px 0 20px;
  padding: 14px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-16);
}

.library-bulk-panel > header,
.library-bulk-panel > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.library-bulk-panel > header > div {
  display: grid;
  gap: 2px;
}

.library-bulk-panel > header strong {
  font-size: 14px;
}

.library-bulk-panel > header small,
.library-bulk-targets > p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.library-bulk-panel .search-field {
  margin: 0;
}

.library-bulk-targets {
  display: grid;
  min-height: 0;
  gap: 2px;
  overflow-y: auto;
}

.library-bulk-targets > button,
.library-bulk-targets > label {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: var(--ink);
  background: transparent;
  border-radius: var(--radius-8);
  font-size: 12px;
  text-align: left;
}

.library-bulk-targets > button:hover,
.library-bulk-targets > button:focus-visible,
.library-bulk-targets > label:hover {
  background: var(--paper);
  outline: 0;
}

.library-bulk-targets .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}

.library-bulk-targets input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.library-bulk-panel > footer {
  justify-content: flex-end;
  padding-top: 2px;
}

/* В пикере на один элемент подтверждать нечего — третьей колонки под кнопку
   «Добавить» нет, и подсказка занимает всё оставшееся место. */
.library-picker-bar.is-single {
  grid-template-columns: auto minmax(0, 1fr);
}

.library-picker-bar > span {
  overflow: hidden;
  font-size: 12px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-picker-bar .btn.ghost {
  color: var(--on-dark);
  border-color: rgba(255, 255, 255, .2);
}

.library-marquee {
  position: fixed;
  z-index: 120;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 76%, transparent);
  border-radius: var(--radius-4);
  box-shadow: 0 0 0 1px color-mix(in srgb, white 28%, transparent) inset;
  pointer-events: none;
}

/* Призрак = точная копия взятого объекта (клон элемента, см. createDragGhost).
   Собственной вёрстки у него больше нет: раньше это была сетка
   «иконка | подпись | счётчик», и у строки дерева без превью подпись попадала
   в колонку 24px — от названия оставалась одна буква. */
.library-drag-ghost {
  position: fixed;
  z-index: 180;
  top: 0;
  left: 0;
  padding: 0;
  transform-origin: top left;
  color: var(--ink);
  /* Ни рамки, ни своего радиуса, ни тени: призрак должен выглядеть ровно как
     взятый объект. Фон и радиус подставляет createDragGhost — от исходника. */
  border: 0;
  pointer-events: none;
}

/* Клон рисуем как есть, только гасим наведённые состояния. */
.library-drag-ghost > * {
  pointer-events: none;
}

.library-drag-ghost .library-card-actions,
.library-drag-ghost .library-card-select {
  display: none;
}

/* Никакой анимации положения: призрак обязан показывать место, куда объект
   упадёт ПРЯМО СЕЙЧАС. С transition он отставал от курсора на быстрых
   движениях, то есть врал о будущем месте. */
.library-drag-ghost {
  transition: none;
}

/* Цель не принимает объект: призрак остаётся на месте, но глохнет — это
   честнее прыжка к курсору, который читался как поломка. */
.library-drag-ghost.is-rejected {
  opacity: .45;
}

/* Заглушка нативного drag image: 1×1 в цвет фона, лежит за экраном. Пустой
   битмап Chrome не отображает и подставляет свою иконку — поэтому пиксель
   именно закрашен, а не прозрачен. */
.library-drag-stub {
  position: fixed;
  z-index: -1;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* Сколько объектов едет, если взяли выделение. ТОЛЬКО прямой потомок: внутри
   клона свои <small> (счётчик элементов узла), и общий селектор перекрашивал
   их в красный бейдж. */
.library-drag-ghost > small {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  color: white;
  background: var(--accent);
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 720;
}

@media (max-width: 900px) {
  .library-browser-screen {
    min-height: 0;
    padding: 20px 16px 92px;
  }

  .library-browser-head {
    gap: 12px;
  }

  .library-browser-head h1 {
    font-size: clamp(32px, 10vw, 46px);
  }

  .library-browser-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .library-view-controls {
    width: 100%;
    margin-left: 0;
  }

  .library-scale {
    width: min(180px, 52vw);
    margin-left: auto;
  }

  .library-card-grid {
    grid-template-columns: repeat(auto-fill, var(--library-card-size));
    gap: 14px;
  }

  .library-card {
    width: var(--library-card-size);
  }

  .library-picker-bar {
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 12px;
  }

  .library-selection-bar {
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 12px;
    grid-template-columns: 1fr auto;
  }

  .library-selection-bar > span {
    display: none;
  }

  .library-selection-bar > div {
    max-width: min(68vw, 440px);
    flex-wrap: wrap;
    justify-content: flex-end;
    overflow: visible;
  }

  .library-selection-bar .btn {
    min-height: 38px;
    white-space: nowrap;
  }

  .library-bulk-panel {
    max-height: calc(100svh - 230px);
    margin-top: -8px;
  }

  .library-inline-editor {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 12px;
    width: auto;
  }

}

@media (max-width: 720px) {
  .library-browser-screen {
    padding-top: calc(70px + env(safe-area-inset-top));
  }

  .library-search-confidence {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .library-search-confidence .btn {
    align-self: flex-start;
  }
}

@media (hover: none), (pointer: coarse) {
  /* На тач-экране нет состояния hover: явный контрол выбора — доступный
   * эквивалент рамочного выбора и DnD, а не постоянно раскрытый action bar. */
  .library-card-select,
  .library-table-check {
    opacity: 1;
    pointer-events: auto;
  }

  .library-search-reference button {
    opacity: 1;
  }

}

@media (max-width: 360px) {
  .library-card-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .library-card {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-tree-children,
  .library-search-judging > span,
  .library-item-card.retrieval-updated,
  .library-retrieval-rejected {
    animation: none;
  }
}

/* «Открытая» работа в ленте (ТЗ 04.08, §10): бейдж состояния и карточка
   раскладки вместо пустой обложки. */
.library-state-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--panel, rgba(20, 20, 20, .82));
  color: var(--accent, #ff5c38);
  border: 1px solid currentColor;
  font-size: 11px;
  line-height: 16px;
}

.library-layout-card {
  width: 100%;
  height: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
  overflow: hidden;
}

.library-layout-row {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-layout-row b {
  font-weight: 600;
}

.library-layout-row i {
  font-style: normal;
  opacity: .7;
  margin-left: 6px;
}

.library-layout-more {
  font-size: 11px;
  opacity: .6;
}

/* Где ищем: раздел, из которого пришли, или вся библиотека. Полоска стоит над
   выдачей, потому что сужение без неё выглядит пропажей результатов. */
.library-search-scope {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  color: var(--muted-2, var(--muted));
  font-size: 12px;
}

.library-search-scope button {
  padding: 0;
  color: var(--muted-2, var(--muted));
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 500;
}

.library-search-scope button:hover {
  color: var(--ink);
}

.library-search-scope button.active {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 0 var(--accent, currentColor);
}

.library-search-scope small {
  margin-left: auto;
  font-size: 11px;
}
