body:not(.mode-local) #openReferencePicker { display: none }
.lib-setup { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  padding: 12px 14px; margin: 8px 0; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2) }
.lib-setup[hidden], .lib-setup [hidden] { display: none }
.lib-setup strong { color: var(--text) }
.lib-setup p { margin: 3px 0 0; color: var(--text); font-size: 13px }
.lib-setup a { color: var(--accent-2); font-size: 12px }
.lib-setup-actions { display: flex; gap: 7px; flex-wrap: wrap }
.ref-order {
  position: absolute; bottom: 2px; left: 2px; min-width: 15px; padding: 0 3px;
  border-radius: 4px; background: #161616ca; color: white; text-align: center; font: 600 11px/15px system-ui;
}
#referencePicker {
  width: min(1120px, 94vw); height: min(800px, 90dvh); max-height: 94dvh; max-width: 96vw;
  padding: 20px; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden;
}
#referencePicker[open] { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; gap: 12px }
#referencePicker::backdrop { background: #17161287 }
body:has(#referencePicker[open]) { overflow: hidden }
.lib-head, .lib-foot, .lib-pages { display: flex; align-items: center; justify-content: space-between; gap: 10px }
.lib-head h2 { font-size: 20px; margin: 0 }
.lib-tabs, .lib-angles { display: flex; flex-wrap: wrap; gap: 6px }
#referencePicker button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2) }
#referencePicker button:disabled { opacity: .55; cursor: default }
#referencePicker :focus-visible { outline: 2px solid var(--accent); outline-offset: -2px }
.lib-filters { display: grid; grid-template-columns: minmax(12em, 2fr) repeat(2, minmax(0, 1fr)); gap: 8px }
.lib-filters form { min-width: 0; margin: 0 }
.lib-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 29%); min-height: 0; gap: 16px }
.lib-browse { min-height: 0; min-width: 0; display: flex; flex-direction: column }
#libGrid { flex: 1; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; padding: 2px }
#libGrid:empty { display: none }
#libGrid button { display: flex; flex-direction: column; align-items: stretch; padding: 3px; min-width: 0;
  border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel-2) }
#libGrid button:hover { border-color: var(--accent) }
#libGrid img { display: block; width: 100%; aspect-ratio: 3/4; object-fit: contain; background: var(--chip); border-radius: 6px }
#libGrid span { padding: 4px; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden }
#libState { flex: 1; display: grid; place-items: center; padding: 10px; text-align: center; color: var(--muted) }
#libState:empty { display: none }
.lib-pages { padding-top: 8px; border-top: 1px solid var(--line) }
.lib-pages span, .lib-foot, .lib-info small { font-size: 12px; color: var(--muted) }
.lib-detail { min-height: 0; min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px }
.lib-detail[hidden] { display: none }
#libPreview { flex: 1; width: 100%; min-height: 0; object-fit: contain; border-radius: 7px; background: var(--chip) }
.lib-info strong, .lib-info small { display: block; overflow-wrap: anywhere }
.lib-angles:empty { display: none }
.lib-angles .btn { padding: 3px 9px }
#libAdd { justify-content: center }
.lib-foot { min-height: 1.5em }
#libRefCount { margin-left: auto; flex-shrink: 0 }
@media (max-width: 680px) {
  #referencePicker { width: 96vw; height: 94dvh; padding: 12px }
  #referencePicker[open] { gap: 8px }
  .lib-filters { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .lib-filters form { grid-column: 1 / -1 }
  .lib-content { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: 8px }
  #libGrid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)) }
  .lib-detail { display: grid; grid-template-columns: minmax(65px, 24%) 1fr; align-items: center; gap: 4px 10px; padding: 7px }
  #libPreview { grid-row: 1 / 4; height: clamp(82px, 15dvh, 130px) }
  #libAdd, .lib-angles, .lib-info { grid-column: 2 }
}
