:root {
    --bg: #08080a;
    --bg2: #0d0d10;
    --bg3: #121216;
    --accent: #1864ff;
    --accent-soft: rgba(24, 100, 255, .12);
    --white: #f4f4f5;
    --dim: #8b8b93;
    --dimmer: #52525b;
    --border: rgba(255, 255, 255, .09);
    --font-serif: 'Instrument Serif', serif;
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Space Mono', monospace;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--white);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
}

body.library-modal-open {
    overflow: hidden;
}

img, video {
    display: block;
    max-width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
}

.library-main {
    width: min(1480px, calc(100% - 64px));
    min-height: 70vh;
    margin: 0 auto;
    padding: 116px 0 88px;
}

.library-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 32px;
    padding-bottom: 30px;
    border-bottom: 1px solid var(--border);
}

.library-kicker,
.library-dialog-category {
    display: block;
    color: #77a6ff;
    font-family: var(--font-mono);
    font-size: .68rem;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.library-head h1 {
    margin: 9px 0 10px;
    font-family: var(--font-serif);
    font-size: 3.5rem;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0;
}

.library-head p {
    max-width: 620px;
    margin: 0;
    color: var(--dim);
    font-size: .96rem;
    line-height: 1.65;
}

.library-count {
    min-width: 92px;
    text-align: right;
}

.library-count strong,
.library-count span {
    display: block;
}

.library-count strong {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 400;
}

.library-count span {
    margin-top: 3px;
    color: var(--dimmer);
    font-size: .72rem;
    text-transform: uppercase;
}

.library-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 0;
}

.library-filters {
    display: inline-flex;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg2);
}

.library-filter {
    min-height: 34px;
    padding: 7px 14px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--dim);
    cursor: pointer;
    font-size: .76rem;
    transition: background .18s, color .18s;
}

.library-filter:hover {
    color: var(--white);
}

.library-filter.active {
    background: #202027;
    color: var(--white);
}

.library-grid {
    columns: 4 260px;
    column-gap: 16px;
}

.library-card {
    position: relative;
    display: inline-block;
    min-width: 0;
    width: 100%;
    margin: 0 0 16px;
    padding: 0;
    overflow: hidden;
    break-inside: avoid;
    border: 0;
    border-radius: 8px;
    background: #111115;
    color: inherit;
    cursor: pointer;
    text-align: left;
    vertical-align: top;
    transition: transform .2s;
}

.library-card:hover {
    transform: translateY(-2px);
}

.library-card:focus-visible,
.library-filter:focus-visible,
.library-dialog-close:focus-visible,
.library-use-button:focus-visible {
    outline: 2px solid #77a6ff;
    outline-offset: 3px;
}

.library-card-media {
    position: relative;
    display: block;
    width: 100%;
    overflow: hidden;
    background: #16161b;
}

.library-card-media img {
    display: block;
    width: 100%;
    height: auto;
    opacity: 1;
    transition: transform .35s ease, opacity .18s ease;
}

.library-card-preview {
    position: absolute;
    z-index: 1;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    opacity: 0;
    transition: transform .35s ease, opacity .18s ease;
}

.library-card:hover .library-card-media img,
.library-card:hover .library-card-preview {
    transform: scale(1.018);
}

.library-card.preview-playing .library-card-media img {
    opacity: 0;
}

.library-card.preview-playing .library-card-preview {
    opacity: 1;
}

.library-media-type {
    position: absolute;
    z-index: 4;
    top: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 50%;
    background: rgba(8, 8, 10, .78);
    color: #fff;
    backdrop-filter: blur(10px);
    transition: opacity .18s ease;
}

.library-card.preview-playing .library-media-type {
    opacity: 0;
}

.library-media-type svg {
    width: 14px;
    height: 14px;
}

.library-card-overlay {
    position: absolute;
    z-index: 3;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 4px;
    padding: 18px;
    background: rgba(0, 0, 0, .32);
    opacity: 0;
    transition: opacity .2s;
}

.library-card:hover .library-card-overlay,
.library-card:focus-visible .library-card-overlay {
    opacity: 1;
}

.library-card-title {
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.25;
}

.library-card-category {
    color: rgba(255, 255, 255, .72);
    font-family: var(--font-mono);
    font-size: .6rem;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.library-dialog {
    width: min(1180px, calc(100% - 32px));
    max-width: none;
    max-height: calc(100vh - 32px);
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 8px;
    background: #0d0d10;
    color: var(--white);
    box-shadow: 0 30px 100px rgba(0, 0, 0, .72);
}

.library-dialog::backdrop {
    background: rgba(0, 0, 0, .82);
    backdrop-filter: blur(8px);
}

.library-dialog-shell {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    max-height: calc(100vh - 34px);
}

.library-dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 50%;
    background: rgba(8, 8, 10, .82);
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.library-dialog-close svg {
    width: 18px;
    height: 18px;
}

.library-dialog-media {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    overflow: auto;
    background: #050506;
}

.library-dialog-media img,
.library-dialog-media video {
    width: 100%;
    max-height: calc(100vh - 190px);
    object-fit: contain;
}

.library-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    padding: 18px 20px;
    border-top: 1px solid var(--border);
}

.library-dialog-footer h2 {
    margin: 5px 0 3px;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0;
}

.library-dialog-footer p {
    margin: 0;
    color: var(--dim);
    font-size: .78rem;
    line-height: 1.5;
}

.library-use-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background .18s;
}

.library-use-button:hover {
    background: #2d73ff;
}

.library-use-button svg {
    width: 16px;
    height: 16px;
}

:root[data-theme="light"] body {
    background: #f3f5f8;
}

:root[data-theme="light"] .library-filters,
:root[data-theme="light"] .library-dialog {
    background: #fff;
}

:root[data-theme="light"] .library-filter.active {
    background: #eef2f7;
}

:root[data-theme="light"] .library-dialog-media {
    background: #e8edf3;
}

@media (max-width: 1120px) {
    .library-grid {
        columns: 3 240px;
    }
}

@media (max-width: 780px) {
    .library-main {
        width: min(100% - 28px, 1480px);
        padding-top: 96px;
        padding-bottom: 64px;
    }

    .library-head {
        align-items: start;
    }

    .library-head h1 {
        font-size: 2.6rem;
    }

    .library-grid {
        columns: 2 170px;
        column-gap: 12px;
    }

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

    .library-dialog-footer {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
    }

    .library-use-button {
        width: 100%;
    }

    .library-dialog-media img,
    .library-dialog-media video {
        max-height: calc(100vh - 260px);
    }
}

@media (max-width: 480px) {
    .library-head p {
        font-size: .88rem;
    }

    .library-count {
        min-width: 56px;
    }

    .library-count strong {
        font-size: 1.25rem;
    }

    .library-toolbar {
        overflow-x: auto;
    }

    .library-grid {
        columns: 1;
    }
}

@media (hover: none) {
    .library-card-overlay {
        padding: 14px;
        background: rgba(0, 0, 0, .2);
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .library-card,
    .library-card-media img,
    .library-card-preview,
    .library-media-type {
        transition: none;
    }
}
