.library-page {
  --library-control: var(--surface, #212129);
  --library-line: var(--line, #ffffff1c);
  --library-muted: var(--muted, #a9abb5);
}
.library-toolbar {
  position: sticky;
  top: max(8px, var(--safe-top));
  z-index: 4;
  width: max-content;
  max-width: calc(100% - 20px);
  margin: 0 auto 12px;
  padding: 5px;
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--library-control);
  border: 1px solid var(--library-line);
  border-radius: 25px;
  box-shadow: 0 4px 18px #0002;
}
.library-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 11px;
  border-radius: 19px;
  white-space: nowrap;
  font-size: .88rem;
}
.library-toolbar #library-refresh, .library-toolbar #library-back {
  min-width: 44px;
}
.library-scope-title {
  min-width: 0;
  max-width: min(200px, 28vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .88rem;
}
.library-page #library-status, .library-page #library-filter-summary {
  padding: 0 2px;
  margin-block: 6px;
  font-size: .82rem;
}
.library-grid + #library-nearest, .library-page #library-retry {
  margin: 8px 12px;
}
#library-filters {
  position: fixed;
  inset: max(12px, var(--safe-top)) max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
  width: min(30rem, calc(100% - max(12px, var(--safe-left)) - max(12px, var(--safe-right))));
  max-height: calc(var(--app-height) - max(12px, var(--safe-top)) - max(12px, var(--safe-bottom)));
  border-radius: 22px;
  color: var(--text, #fff);
  background: var(--library-control);
  border: 1px solid var(--library-line);
  padding: 18px;
}
#library-filters::backdrop { background: #0008; }
#library-filters form > header, #library-filters form > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#library-filters h2 { margin: 0; font-size: 1.2rem; }
#library-filters form footer { margin-top: 16px; }
#library-filters form > header {
  position: sticky;
  top: 0;
  z-index: 2;
  justify-content: flex-start;
  background: var(--library-control);
}
#library-filter-cancel { display: grid; place-items: center; width: 44px; min-height: 44px; padding: 0; }
#library-filters .library-filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: transparent;
  margin: 0;
}
#library-filters label {
  color: var(--library-muted);
  font-size: .85rem;
}
#library-filters input, #library-filters select {
  min-height: 44px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  font-size: 16px;
}
.library-filters > .media-owner-search { grid-column: 1 / -1; }
.media-date-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 6px;
}
.media-date-field > label { grid-column: 1 / -1; }
.media-date-field > button { min-height: 44px; padding-inline: 8px; white-space: nowrap; font-size: .81rem; }
.library-grid {
  gap: 4px;
}
.library-card {
  aspect-ratio: 1;
  border-radius: 9px;
}
.library-card .library-source,
.library-card .library-flag,
.inspect-card .inspect-badge,
.inspect-card .inspect-play {
  position: absolute;
  top: 5px;
  left: 5px;
  right: auto;
  display: grid;
  place-items: center;
  z-index: 2;
  min-width: 20px;
  min-height: 20px;
  padding: 2px 6px;
  margin: 0;
  color: #fff;
  font-size: .69rem;
  font-weight: 700;
  border-radius: 6px;
  background: #000b;
  pointer-events: none;
}
.library-card .library-flag,
.inspect-card .inspect-verdict {
  left: auto;
  right: 5px;
}
.library-card .library-flag,
.inspect-card .inspect-verdict[data-explicit] { background: #982240; }
.library-card .media-open > .media-duration,
.inspect-card .inspect-play {
  inset: auto auto 5px 5px;
  max-width: calc(100% - 49px);
  background: #000b;
  color: #fff;
  font-size: .69rem !important;
  font-variant-numeric: tabular-nums;
}
.inspect-card .inspect-play .icon { width: 13px; height: 13px; }
.library-card .media-open:not(.visual-open) > span:not(.media-state) {
  -webkit-line-clamp: 1;
}
.library-card .preview-failed { bottom: 43px; }
.library-card .media-tile-info,
.inspect-card .media-tile-info {
  position: absolute;
  inset: auto 0 0 auto;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #fff;
  touch-action: manipulation;
}
.media-tile-info::before {
  content: '';
  grid-area: 1 / 1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #000c;
}
.media-tile-info .icon {
  grid-area: 1 / 1;
  z-index: 1;
  width: 19px;
  height: 19px;
}
.media-tile-info:is(:hover, :focus-visible)::before { background: #342f53; }
.profile .profile-media-link {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  margin: 12px auto;
}
@media (max-width: 700px) {
  .library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .library-toolbar:has(.library-scope-title) {
    width: calc(100% - 20px);
    flex-wrap: wrap;
  }
  .library-toolbar:has(.library-scope-title) .library-scope-title {
    max-width: none;
    flex: 1 1 calc(100% - 60px);
  }
  .library-toolbar button { flex-grow: 1; }
  .library-toolbar #library-back { flex-grow: 0; }
}
@media (max-width: 380px) {
  #library-filters .library-filters { grid-template-columns: 1fr; }
}
