.portal-library {
  position: absolute; z-index: 18; top: 64px; left: 12px; bottom: 30px;
  width: min(320px, calc(100% - 24px)); min-height: 0; display: flex; flex-direction: column;
  color: var(--text, #edf1f2); background: #0b0d0e; border: 1px solid var(--line-strong, #3b4043);
  border-radius: 6px; box-shadow: 0 10px 30px #0009; overflow: hidden; font-size: 14px; letter-spacing: 0;
}
.portal-library[hidden], .portal-library [hidden], .library-dialog[hidden] { display: none !important; }
.library-header { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-bottom: 1px solid #303537; flex-shrink: 0; touch-action: pan-x; }
.library-heading { flex: 1; min-width: 0; }
.library-heading h2 { font-size: 17px; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.library-heading small { display: flex; align-items: center; gap: 5px; color: var(--muted, #a4aaad); font-size: 13px; }
.library-heading small svg { width: 12px; height: 12px; }
.library-body { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-y; min-height: 0; flex: 1; }
.library-body::-webkit-scrollbar { display: none; }
.portal-library .library-button, .library-quick-favorite {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 48px; min-height: 48px;
  padding: 8px; border: 1px solid #3b4043; border-radius: 4px; background: #141719; color: inherit;
  font: inherit; cursor: pointer; flex-shrink: 0; touch-action: manipulation;
}
.portal-library .library-button svg, .library-quick-favorite svg { width: 18px; height: 18px; flex-shrink: 0; }
.portal-library .library-button:hover:not(:disabled), .library-quick-favorite:hover:not(:disabled) { border-color: var(--accent, #edf1f2); }
.portal-library :focus-visible, .library-quick-favorite:focus-visible { outline: 2px solid var(--accent, #edf1f2); outline-offset: -2px; }
.portal-library .library-button:disabled, .library-quick-favorite:disabled { opacity: .4; cursor: default; }
.portal-library .library-button[aria-pressed="true"], .library-quick-favorite[aria-pressed="true"] { color: var(--accent-strong, #edf1f2); background: var(--accent-soft, #ffffff12); border-color: var(--accent, #edf1f2); }
.library-controls { padding: 8px 10px; display: grid; gap: 7px; border-bottom: 1px solid #303537; flex-shrink: 0; }
.library-folder-line { display: grid; grid-template-columns: minmax(0, 1fr) 48px 48px; gap: 6px; }
.portal-library select, .portal-library input[type="search"], .portal-library input[type="text"] { min-width: 0; width: 100%; min-height: 48px; border: 1px solid #3b4043; border-radius: 4px; background: #141719; padding: 9px; color: inherit; font: inherit; }
.library-folder-tools, .library-filter-line { display: flex; gap: 6px; align-items: center; min-width: 0; }
.library-filter-line > label { display: flex; align-items: center; gap: 7px; min-height: 48px; flex: 1; font-size: 13px; }
.library-filter-line select { width: 116px; font-size: 13px; }
.portal-library input[type="checkbox"] { margin: 0; width: 20px; height: 20px; accent-color: var(--accent, #edf1f2); }
.library-selection { display: flex; align-items: center; gap: 5px; padding: 2px 10px; min-height: 48px; border-bottom: 1px solid #303537; flex-shrink: 0; }
.library-selection > strong { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.portal-library .library-selection .library-button { border: 0; background: transparent; }
.library-status { margin: 0; padding: 8px 10px; color: var(--muted, #a4aaad); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; flex-shrink: 0; }
.library-status[data-state="error"] { color: var(--danger, #ff4267); }
.library-status:empty { display: none; }
.library-recovery { display: flex; align-items: center; gap: 6px; padding: 0 10px 8px; flex-shrink: 0; }
.library-items { min-height: 0; padding: 0; margin: 0; list-style: none; }
.library-items::-webkit-scrollbar { display: none; }
.library-item { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 0; align-items: center; border-bottom: 1px solid #292e30; min-height: 64px; }
.library-item[data-selected="true"] { background: var(--accent-soft, #ffffff12); box-shadow: inset 3px 0 var(--accent, #edf1f2); }
.library-item > label { display: grid; place-items: center; align-self: stretch; min-height: 48px; cursor: pointer; }
.portal-library .library-portal { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; height: 100%; min-width: 0; min-height: 64px; padding: 10px 6px; text-align: left; border: 0; background: transparent; border-radius: 0; overflow-wrap: anywhere; }
.library-portal > span { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; max-width: 100%; }
.library-portal > small { font-size: 13px; color: var(--muted, #a4aaad); }
.portal-library .library-star { border: 0; background: transparent; }
.library-empty { margin: 0; padding: 22px 14px; font-size: 14px; line-height: 1.5; text-align: center; color: var(--muted, #a4aaad); }
.portal-library .library-more { margin: 8px 10px; width: calc(100% - 20px); flex-shrink: 0; }
.library-actions { padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid #3b4043; background: #101315; flex-shrink: 0; }
.portal-library .library-use { width: 100%; border-color: var(--accent, #edf1f2); }
.library-actions .library-button:not(.library-use) { flex: 1; }
.library-offered { border-bottom: 1px solid #3b4043; padding: 8px 10px; display: flex; gap: 6px; align-items: center; min-width: 0; flex-shrink: 0; }
.library-offered > span { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.library-dialog { position: absolute; inset: 0; z-index: 2; background: #0b0d0e; display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; overflow-y: auto; overscroll-behavior: contain; }
.library-dialog h3 { margin: 0; font-size: 17px; line-height: 1.4; }
.library-dialog p { margin: 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.library-dialog label { display: grid; gap: 7px; font-size: 13px; }
.library-dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.library-dialog-actions .library-button { flex: 1; }
.portal-library .library-size { display: none; }
@media (max-width: 900px) {
  .portal-library { top: auto; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom)); width: auto; max-height: min(70%, 600px); }
  .portal-library .library-size { display: inline-flex; }
  .portal-library[data-size="full"] { top: max(8px, env(safe-area-inset-top)); max-height: none; }
  .portal-library[data-size="summary"] .library-body, .portal-library[data-size="summary"] .library-controls, .portal-library[data-size="summary"] .library-selection,
  .portal-library[data-size="summary"] .library-items, .portal-library[data-size="summary"] .library-empty,
  .portal-library[data-size="summary"] .library-actions, .portal-library[data-size="summary"] .library-status,
  .portal-library[data-size="summary"] .library-recovery, .portal-library[data-size="summary"] .library-more { display: none; }
  .library-header { cursor: grab; }
  .library-dialog { position: fixed; top: max(12px, env(safe-area-inset-top)); bottom: max(90px, calc(env(safe-area-inset-bottom) + 70px)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); border: 1px solid #3b4043; border-radius: 6px; }
}
@media (max-height: 620px) {
  .portal-library { top: 60px; max-height: none; }
  .library-controls { gap: 4px; padding-block: 5px; }
  .library-folder-tools { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: no-preference) {
  .portal-library .library-button, .library-quick-favorite { transition: border-color 140ms, background-color 140ms; }
}
