/* GHOST CACHE — Cloud Library browser (flags / icon packs) */
.ghost-library-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(4px);
}
.ghost-library-overlay[hidden] { display: none; }

.ghost-library-modal {
    width: min(940px, 94vw);
    height: min(720px, 88vh);
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: var(--ghost-panel, #1f1f1f);
    color: var(--ghost-text, #d6d6d6);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.glib-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--ghost-border, #3a3a3a);
    background: var(--ghost-surface, #262626);
}
.glib-title { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; white-space: nowrap; }
.glib-search {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: var(--ghost-input, #1a1a1a);
    color: inherit;
    font-size: 12px;
}
.glib-search:focus { outline: none; border-color: var(--ghost-accent, #2d8ceb); }
.glib-close {
    width: 26px; height: 26px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
.glib-close:hover { background: rgba(255, 255, 255, 0.08); }

.glib-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--ghost-border, #3a3a3a);
}
.glib-chip {
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: transparent;
    color: inherit;
    font-size: 11px;
    cursor: pointer;
}
.glib-chip:hover { background: rgba(255, 255, 255, 0.06); }
.glib-chip.active {
    background: var(--ghost-accent, #2d8ceb);
    border-color: var(--ghost-accent, #2d8ceb);
    color: #fff;
}

.glib-grid {
    flex: 1;
    overflow: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 10px;
    padding: 12px;
}

.glib-card {
    position: relative;
    margin: 0;
    border-radius: 8px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: var(--ghost-surface, #262626);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* remove extra vertical padding */
    padding: 0;
}

/* thumbnail occupies top part, no extra padding */
.glb‑thumb {
    margin: 0;
}

.glb‑thumb img {
    display: block;
    width: 100%;
    height: auto;
    max-height: none;
}

.glb‑thumb::after {
    /* keep loader spinner but without extra space */
    content: "";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.glb‑figcaption {
    padding: 4px 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.glb‑name {
    font-size: 11px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.glb‑cat {
    font-size: 9px;
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: -2px;
}.glib-card.busy { opacity: 0.55; }
.glib-card.downloaded { border-color: var(--ghost-accent, #2d8ceb); }
.glib-card.preview-only .glib-actions button { opacity: .45; cursor: not-allowed; }

.glib-thumb {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(rgba(255,255,255,0.04) 0% 25%, transparent 0% 50%) 50% / 12px 12px;
}
.glib-thumb img { 
    display: block;
    width: auto;
    height: auto;
    max-width: 88%; 
    max-height: 60px; 
    object-fit: contain; 
    flex-shrink: 0;
}
.glib-card:not(.thumb-ready):not(.thumb-error) .glib-thumb::after {
    content: "";
    width: 22px;
    height: 22px;
    border: 2px solid var(--ghost-border, #3a3a3a);
    border-top-color: var(--ghost-accent, #2d8ceb);
    border-radius: 50%;
    animation: glib-spin .8s linear infinite;
}
.glib-card.thumb-error .glib-thumb::after {
    content: "!";
    opacity: .55;
    font: 600 18px/1 sans-serif;
}
@keyframes glib-spin { to { transform: rotate(360deg); } }

.glib-card figcaption {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 8px 8px;
}
.glib-name { font-size: 11px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glib-cat { font-size: 9px; opacity: 0.55; text-transform: uppercase; letter-spacing: 0.05em; }

.glib-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.glib-card:hover .glib-actions { opacity: 1; }
.glib-actions button {
    width: 22px; height: 22px;
    border-radius: 5px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: rgba(0, 0, 0, 0.6);
    color: inherit;
    font-size: 11px;
    cursor: pointer;
}
.glib-actions button:hover { background: var(--ghost-accent, #2d8ceb); color: #fff; }

.glib-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--ghost-border, #3a3a3a);
    background: var(--ghost-surface, #262626);
    font-size: 11px;
}
.glib-status { flex: 1; opacity: 0.75; }
.glib-foot button {
    height: 24px;
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid var(--ghost-border, #3a3a3a);
    background: transparent;
    color: inherit;
    font-size: 11px;
    cursor: pointer;
}
.glib-foot button:hover { background: var(--ghost-accent, #2d8ceb); border-color: var(--ghost-accent, #2d8ceb); color: #fff; }

/* Pack switcher (Flags / White Icons / …) */
.glib-packs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 6px;
}
.glib-pack {
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* ─────────────────────────────────────────────────────────────
   v3.6.9 — Sources rail: slim rows, scrollable, collapsible
   ───────────────────────────────────────────────────────────── */

.folder-section {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column;
    min-height: 0 !important;
    overflow: hidden;
}

.section-header-row { gap: 4px; align-items: center; }

.sources-toggle {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #8c8c8c;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    transition: transform 130ms ease, color 130ms ease;
}
.sources-toggle:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sources-toggle[aria-expanded="false"] { transform: rotate(-90deg); }

/* slim scrollable list */
.folder-history {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding-right: 3px;
    gap: 1px !important;
    scrollbar-width: thin;
}
.folder-history::-webkit-scrollbar { width: 8px; }
.folder-history::-webkit-scrollbar-track { background: transparent; }
.folder-history::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border: 2px solid transparent;
    background-clip: content-box;
    border-radius: 8px;
}
.folder-history::-webkit-scrollbar-thumb:hover { background: #6a6a6a; background-clip: content-box; }

.folder-history .history-item,
.folder-history > [role="listitem"] {
    min-height: 24px !important;
    margin: 0 !important;
    padding: 3px 4px 3px 7px !important;
    font-size: 11px !important;
    border-radius: 4px !important;
}
.folder-history .history-item::before,
.folder-history > [role="listitem"]::before { height: 11px !important; width: 2px !important; }
.folder-history .history-name { font-size: 11px !important; font-weight: 500 !important; }
.folder-history .folder-action,
.folder-history button { width: 18px !important; height: 18px !important; font-size: 10px; }
.folder-history .history-empty { padding: 12px 8px !important; font-size: 10px; }

.folder-section.collapsed .folder-history { display: none !important; }
.folder-section.collapsed { flex: 0 0 auto !important; }

/* Cloud Section entry pinned under the sources list */
.cloud-source-block {
    flex: 0 0 auto;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-soft, #303030);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cloud-source-item {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    min-height: 26px;
    padding: 4px 6px 4px 7px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #bdbdbd;
    font-size: 11px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.cloud-source-item:hover { background: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .08); color: #fff; }
.cloud-source-item.active {
    background: linear-gradient(90deg, rgba(38, 128, 235, .22), rgba(38, 128, 235, .07));
    border-color: rgba(38, 128, 235, .38);
    color: #fff;
}
.cloud-source-icon { font-size: 12px; opacity: .85; }
.cloud-source-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-source-badge {
    flex: 0 0 auto;
    min-width: unset;
    padding: 0;
    border-radius: 0;
    background: transparent !important;
    border: none !important;
    color: var(--ghost-text-muted, #71717A) !important;
    font-size: 9px !important;
    font-weight: 400 !important;
    text-align: right;
    opacity: 0.45 !important;
}
.cloud-browse-item {
    padding: 3px 7px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #7d7d7d;
    font-size: 10px;
    text-align: left;
    cursor: pointer;
}
.cloud-browse-item:hover { color: #cfe1f8; background: rgba(255, 255, 255, .04); }

/* ─────────────────────────────────────────────────────────────
   Cloud results strip (unified search)
   ───────────────────────────────────────────────────────────── */

.cloud-strip {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    max-height: 46%;
    border-top: 1px solid var(--ghost-border, #3a3a3a);
    background: #1c1c1c;
    box-shadow: 0 -8px 22px rgba(0, 0, 0, .45);
}
.cloud-strip[hidden] { display: none; }

.cloud-strip-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    background: #232323;
}
.cloud-strip-title { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: #d6d6d6; }
.cloud-strip-status { flex: 1 1 auto; font-size: 10px; color: #8c8c8c; }
.cloud-strip-collapse {
    width: 20px; height: 20px;
    border: 0; border-radius: 4px;
    background: transparent; color: #9a9a9a;
    cursor: pointer; font-size: 11px; line-height: 1;
}
.cloud-strip-collapse:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.cloud-strip.collapsed .cloud-strip-grid { display: none; }
.cloud-strip.collapsed .cloud-strip-collapse { transform: rotate(-90deg); }

.cloud-strip-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    padding: 10px;
}
/* Grouped mode: the strip renders category sections, so it flows as blocks. */
.cloud-strip-grid.grouped {
    display: block;
    padding: 0 0 10px;
}
.cloud-strip-grid::-webkit-scrollbar { width: 9px; }
.cloud-strip-grid::-webkit-scrollbar-thumb { background: #4a4a4a; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }

.cloud-group { border-bottom: 1px solid rgba(255, 255, 255, .05); }
.cloud-group-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    background: #262626;
    color: #d6d6d6;
    font: 700 10px/1.2 inherit;
    letter-spacing: .04em;
    text-transform: uppercase;
    cursor: pointer;
    text-align: left;
}
.cloud-group-head:hover { background: #2d2d2d; color: #fff; }
.cloud-group-caret { font-size: 9px; color: #8c8c8c; transition: transform 140ms ease; }
.cloud-group-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-group-count {
    flex: 0 0 auto;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .07);
    color: #9a9a9a;
    font-size: 9px;
}
.cloud-group.collapsed .cloud-group-caret { transform: rotate(-90deg); }
.cloud-group.collapsed .cloud-group-grid { display: none; }
.cloud-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 8px;
    padding: 8px 10px 10px;
}

.cloud-item {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid #303030;
    border-radius: 6px;
    background: #202020;
    overflow: hidden;
}
/* Square, contained thumbnails — icons must never stretch or grow tall. */
.cloud-item-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 96px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: repeating-conic-gradient(#242424 0% 25%, #1d1d1d 0% 50%) 50% / 12px 12px;
}
.cloud-item-thumb img {
    width: 84%;
    height: 84%;
    object-fit: contain;
    filter: blur(6px) saturate(.7);
    transform: scale(1.02);
    transition: filter 180ms ease;
}

.cloud-item.downloaded .cloud-item-thumb img { filter: none; }
.cloud-item-lock {
    position: absolute;
    inset: auto 4px 4px auto;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .6);
    color: #d6d6d6;
}
.cloud-item.downloaded .cloud-item-lock { display: none; }
.cloud-item-name {
    padding: 4px 6px 0;
    font-size: 10px;
    color: #cfcfcf;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cloud-item-meta { padding: 0 6px 4px; font-size: 9px; color: #7d7d7d; }
.cloud-item-actions { display: flex; gap: 4px; padding: 0 6px 6px; }
.cloud-item-actions button {
    flex: 1 1 auto;
    height: 20px;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    background: #262626;
    color: #d6d6d6;
    font-size: 10px;
    cursor: pointer;
}
.cloud-item-actions button:hover { background: var(--ghost-accent, #2d8ceb); border-color: var(--ghost-accent, #2d8ceb); color: #fff; }
.cloud-item-actions button:disabled { opacity: .45; cursor: default; }
.cloud-item.busy { opacity: .6; }
.cloud-item.downloaded { border-color: rgba(38, 128, 235, .45); }

/* ---------- audio packs (sound effects, bg music) ---------- */
.glib-thumb.glib-audio,
.cloud-item-thumb.glib-audio {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, color-mix(in oklab, var(--ghost-accent, #7c5cff) 22%, transparent), transparent);
}
.glib-play {
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 1px solid color-mix(in oklab, var(--ghost-accent, #7c5cff) 60%, transparent);
    background: color-mix(in oklab, var(--ghost-accent, #7c5cff) 28%, transparent);
    color: inherit;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.glib-play:hover { background: color-mix(in oklab, var(--ghost-accent, #7c5cff) 45%, transparent); }
.glib-wave { display: flex; align-items: flex-end; gap: 2px; height: 26px; }
.glib-wave i {
    display: block;
    width: 3px;
    border-radius: 2px;
    background: color-mix(in oklab, var(--ghost-accent, #7c5cff) 70%, transparent);
    height: 30%;
}
.glib-wave i:nth-child(2) { height: 65%; }
.glib-wave i:nth-child(3) { height: 40%; }
.glib-wave i:nth-child(4) { height: 90%; }
.glib-wave i:nth-child(5) { height: 55%; }
.glib-wave i:nth-child(6) { height: 100%; }
.glib-wave i:nth-child(7) { height: 45%; }
.glib-wave i:nth-child(8) { height: 75%; }
.glib-wave i:nth-child(9) { height: 35%; }
.glib-audio.playing .glib-wave i { animation: glibWave 900ms ease-in-out infinite alternate; }
.glib-audio.playing .glib-wave i:nth-child(even) { animation-delay: 160ms; }
.glib-audio.playing .glib-wave i:nth-child(3n) { animation-delay: 320ms; }
@keyframes glibWave { from { transform: scaleY(0.45); } to { transform: scaleY(1); } }
.glib-card.is-audio .glib-thumb::after,
.cloud-item.is-audio .cloud-item-thumb::after { content: none !important; }

/* New cloud upload notifier — one click pulls only the new files. */
.cloud-new-button {
    display: flex; align-items: center; gap: 8px; width: 100%;
    margin: 6px 0 0; padding: 8px 10px; border-radius: 9px; cursor: pointer;
    border: 1px solid rgba(90, 210, 160, .45);
    background: linear-gradient(180deg, rgba(60, 200, 150, .22), rgba(60, 200, 150, .10));
    color: #d8fff0; font-size: 11.5px; font-weight: 600; text-align: left;
}
.cloud-new-button:hover { border-color: rgba(120, 240, 190, .8); }
.history-item.cloud-source .history-name { color: #cfe8ff; }

/* ── Source tree (v3.8.3) ─────────────────────────────────────────────
   Labels wrap instead of collapsing into "Sound Effe…" and cloud packs
   group into expandable folders so one category can hold many others. */
.folder-history .history-name {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    line-height: 1.25;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow-wrap: anywhere;
}
.folder-history .history-item { align-items: center; }
.history-item.history-group {
    grid-template-columns: 14px minmax(0, 1fr) auto !important;
    gap: 4px;
    font-weight: 600;
    color: #e6e6e6;
    background: rgba(255, 255, 255, .035);
    margin-top: 3px !important;
}
.history-item.history-group:hover { background: rgba(255, 255, 255, .075); }
.history-item.history-group.open { background: rgba(38, 128, 235, .12); }
.history-caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #9a9a9a;
}
.history-children {
    margin: 1px 0 3px;
    padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, .09);
}
.history-item.history-child {
    grid-template-columns: minmax(0, 1fr) 18px 18px !important;
    padding-left: 8px !important;
    color: #b9c6d4;
}
.sidebar { overflow: hidden; }
.folder-section { min-height: 0; display: flex; flex-direction: column; }
.folder-history { overflow-y: auto !important; overscroll-behavior: contain; }
