/**
 * Game Library — separate from the grail rail (.card in menu.css).
 * Flat tiles, CSS grid, minimal paint cost.
 */

.lib-app {
    --lib-bg: #0a0a0c;
    --lib-surface: #141418;
    --lib-border: rgba(255, 255, 255, 0.08);
    --lib-text: #f4f4f5;
    --lib-muted: rgba(255, 255, 255, 0.45);
    --lib-accent: #8b5cf6;
    --lib-pin: #fbbf24;
    --lib-tile-w: 168px;

    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    background: var(--lib-bg);
    color: var(--lib-text);
    font-family: inherit;
    isolation: isolate;
    transition: visibility 0.28s ease;
}

.lib-app::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--lib-bg);
    z-index: -1;
}

.lib-app.hidden {
    visibility: hidden;
    pointer-events: none;
}

.lib-app:not(.hidden) {
    visibility: visible;
}

/* Hide home screen completely while library is open */
body.library-open #main-menu {
    display: none !important;
}

body.library-open #starfield,
body.library-open .vignette {
    visibility: hidden;
}

/*
 * Override menu.css `header { max-width: 800px; margin: ... }` which was
 * constraining and left-aligning the library top bar on wide screens.
 */
#library-view.lib-app > .lib-topbar {
    flex: 0 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 24px clamp(16px, 4vw, 40px) 20px;
    border-bottom: 1px solid var(--lib-border);
    background: var(--lib-bg);
    z-index: 1;
}

.lib-topbar-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    width: min(100%, 400px);
}

.lib-topbar-title {
    margin: 0;
    padding: 0;
    font-size: clamp(18px, 3vw, 24px);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.2;
    color: var(--lib-text);
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: unset;
    text-shadow: none;
    filter: none;
    animation: none;
}

.lib-topbar-title::before,
.lib-topbar-title::after {
    content: none;
    display: none;
}

.lib-topbar-count {
    margin: 0;
    font-size: 12px;
    color: var(--lib-muted);
    letter-spacing: 0.04em;
}

.lib-search-wrap {
    position: relative;
    width: 100%;
    max-width: 360px;
}

.lib-search-wrap .fa-magnifying-glass {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--lib-muted);
    pointer-events: none;
}

.lib-search-input {
    width: 100%;
    height: 40px;
    padding: 0 12px 0 36px;
    border: 1px solid var(--lib-border);
    border-radius: 10px;
    background: var(--lib-surface);
    color: var(--lib-text);
    font: inherit;
    font-size: 14px;
}

.lib-search-input:focus {
    outline: none;
    border-color: rgba(139, 92, 246, 0.55);
}

.lib-search-input::placeholder {
    color: var(--lib-muted);
}

#library-view .lib-back-btn {
    position: absolute;
    left: clamp(16px, 4vw, 40px);
    top: 24px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--lib-border);
    border-radius: 10px;
    background: var(--lib-surface);
    color: var(--lib-text);
    cursor: pointer;
    font-size: 16px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.lib-back-btn:hover {
    background: #1c1c22;
    border-color: rgba(255, 255, 255, 0.14);
}

.lib-back-btn:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
}

/* Scrollable grid area */
#library-view .lib-scroll {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 20px clamp(16px, 4vw, 40px) 32px;
    background: var(--lib-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lib-scroll::-webkit-scrollbar {
    width: 6px;
}

.lib-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 99px;
}

#library-view .lib-grid {
    display: grid;
    width: 100%;
    max-width: 1400px;
    grid-template-columns: repeat(auto-fill, minmax(var(--lib-tile-w), var(--lib-tile-w)));
    justify-content: center;
    gap: 12px;
    margin: 0 auto;
    list-style: none;
}

/* Simple game tile */
.lib-tile {
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 1px solid var(--lib-border);
    border-radius: 12px;
    background: var(--lib-surface);
    color: inherit;
    cursor: pointer;
    text-align: left;
    font: inherit;
    position: relative;
    overflow: hidden;
    contain: layout style paint;
    content-visibility: auto;
    contain-intrinsic-size: 188px 220px;
    transition: border-color 0.18s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.lib-tile[data-cat="arcade"]  { --c-rgb: var(--cat-arcade-rgb); }
.lib-tile[data-cat="sandbox"] { --c-rgb: var(--cat-sandbox-rgb); }
.lib-tile[data-cat="puzzle"]  { --c-rgb: var(--cat-puzzle-rgb); }
.lib-tile[data-cat="relax"]   { --c-rgb: var(--cat-relax-rgb); }
.lib-tile[data-cat="sports"]  { --c-rgb: var(--cat-sports-rgb); }

.lib-tile:hover {
    border-color: rgba(var(--c-rgb, 139, 92, 246), 0.42);
    transform: translate3d(0, -4px, 0);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.32), 0 0 24px rgba(var(--c-rgb, 139, 92, 246), 0.12);
}

.lib-tile:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
    border-color: rgba(var(--c-rgb, 139, 92, 246), 0.45);
}

.lib-tile:active {
    transform: translate3d(0, -1px, 0) scale(0.99);
}

.lib-tile[data-pinned="true"] {
    border-color: rgba(251, 191, 36, 0.45);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24), 0 0 18px rgba(251, 191, 36, 0.14);
}

.lib-tile-art {
    position: relative;
    height: 132px;
    overflow: hidden;
    border-radius: 11px 11px 0 0;
    background: #0e0e12;
    flex-shrink: 0;
    isolation: isolate;
}

.lib-tile-art::before,
.lib-tile-art::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    z-index: 2;
}

.lib-tile-art::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 38%);
    opacity: 0.75;
}

.lib-tile-art::after {
    background: linear-gradient(180deg, transparent 35%, rgba(0, 0, 0, 0.72) 100%);
}

.lib-tile-cover {
    border-radius: inherit;
}

.lib-tile-icon-badge {
    position: absolute;
    left: 8px;
    top: 8px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.48);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.82rem;
    z-index: 3;
    transition: opacity 180ms ease;
}

.lib-tile-scrim {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 132px;
    padding: 8px 10px 10px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;
    pointer-events: none;
}

.lib-tile-scrim .lib-tile-title {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lib-tile-scrim .lib-tile-cat {
    align-self: flex-start;
}

.lib-tile-body {
    display: none;
}

.lib-tile-meta {
    display: none;
}

.lib-tile-pin {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.55);
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    font-family: inherit;
    transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.lib-tile-pin:focus-visible {
    opacity: 1;
    outline: 2px solid var(--lib-accent);
    outline-offset: 1px;
}

.lib-tile:hover .lib-tile-pin,
.lib-tile:focus-within .lib-tile-pin,
.lib-tile[data-pinned="true"] .lib-tile-pin {
    opacity: 1;
}

.lib-tile-pin:hover {
    background: rgba(255, 255, 255, 0.9);
    color: #111;
}

.lib-tile[data-pinned="true"] .lib-tile-pin {
    color: var(--lib-pin);
    background: rgba(0, 0, 0, 0.65);
}

/* Empty state */
.lib-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 16px;
    color: var(--lib-muted);
}

.lib-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--lib-text);
    margin: 0 0 6px;
}

.lib-empty-sub {
    margin: 0;
    font-size: 13px;
}

/* Budget / Chromebook: fewer effects */
.budget-device .lib-tile,
.chromebook-mode .lib-tile {
    contain-intrinsic-size: 188px 210px;
}

.budget-device .lib-tile:active,
.chromebook-mode .lib-tile:active {
    transform: none;
}

@media (max-width: 480px) {
    .lib-app {
        --lib-tile-w: 140px;
    }

    .lib-topbar {
        padding-top: 20px;
        padding-bottom: 16px;
    }
}
