/**
 * 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: 148px;

    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: 168px 188px;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.lib-tile:hover {
    border-color: rgba(255, 255, 255, 0.16);
    background: #1a1a20;
}

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

.lib-tile:active {
    transform: scale(0.98);
}

.lib-tile[data-pinned="true"] {
    border-color: rgba(251, 191, 36, 0.35);
}

.lib-tile-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 88px;
    background: #0e0e12;
    color: rgba(255, 255, 255, 0.35);
    font-size: 28px;
    flex-shrink: 0;
}

.lib-tile[data-kind="archive"] .lib-tile-thumb {
    background: #080808;
    color: rgba(255, 255, 255, 0.22);
}

.lib-tile[data-cat="arcade"] .lib-tile-thumb { color: rgba(217, 70, 239, 0.5); }
.lib-tile[data-cat="puzzle"] .lib-tile-thumb { color: rgba(129, 140, 248, 0.5); }
.lib-tile[data-cat="sports"] .lib-tile-thumb { color: rgba(34, 197, 94, 0.5); }
.lib-tile[data-cat="sandbox"] .lib-tile-thumb { color: rgba(245, 158, 11, 0.5); }
.lib-tile[data-cat="relax"] .lib-tile-thumb { color: rgba(16, 185, 129, 0.5); }

.lib-tile-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 10px 12px;
    min-width: 0;
}

.lib-tile-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lib-tile-meta {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--lib-muted);
}

.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: 168px 180px;
}

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

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

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