/* ---------- base ---------- */
:root {
    --bg: #0f1115;
    --panel: #16181d;
    --line: rgba(255, 255, 255, .14);
    --text: #e9eaee;
    --dim: rgba(233, 234, 238, .62);
    --accent: #2b7cd3;
    --card: 200px;
    --cols: 6;          /* six covers per row, then wrap */
    --gap: 18px;
    /* the shared content width everything lines up against */
    --maxw: calc(var(--card) * var(--cols) + var(--gap) * (var(--cols) - 1));
    --side: max(22px, calc((100% - var(--maxw)) / 2));
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: inherit; }

/* ---------- filter bar ---------- */
#bar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: end;
    /* full-width bar, but its contents sit above the grid's left edge */
    padding: 14px var(--side);
    background: rgba(15, 17, 21, .93);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}

#bar h1 {
    margin: 0 12px 0 0;
    font-size: 20px;
    letter-spacing: -.4px;
    align-self: center;
}
#bar h1 span { color: var(--accent); }

#bar label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--dim);
}

select, input[type=search] {
    font: inherit;
    color: var(--text);
    background: #1b1e24;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    min-width: 150px;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#f-search { align-self: end; min-width: 200px; }

#count { margin-left: auto; align-self: center; color: var(--dim); font-size: 13px; }

#tabs { display: flex; gap: 6px; align-self: center; margin-right: 6px; }
.tab {
    font: inherit;
    color: var(--dim);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { background: var(--accent); border-color: var(--accent); color: #fff; }

label.off { opacity: .35; pointer-events: none; }

/* ---------- view settings ---------- */
#view-btn {
    font: inherit;
    color: var(--dim);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
    align-self: end;
}
#view-btn:hover, #view-btn.on { color: var(--text); border-color: var(--text); }

#view-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: var(--side);
    z-index: 60;
    width: 330px;
    padding: 14px 16px 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, .6);
}
#view-panel[hidden] { display: none; }
#view-panel h3 {
    margin: 12px 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--dim);
    font-weight: 600;
}
#view-panel h3:first-child { margin-top: 0; }
#view-panel .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 9px;
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
}

.seg { display: flex; gap: 4px; }
.seg button {
    font: inherit;
    font-size: 12px;
    color: var(--dim);
    background: rgba(127, 127, 127, .12);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 4px 9px;
    cursor: pointer;
    white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- paging controls ---------- */
#pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 4px 22px 24px;
}
#pager[hidden] { display: none; }
#pager button, #load-more {
    font: inherit;
    color: var(--text);
    background: rgba(127, 127, 127, .14);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 18px;
    cursor: pointer;
}
#pager button:hover:not(:disabled), #load-more:hover { border-color: var(--text); }
#pager button:disabled { opacity: .35; cursor: default; }
#page-label { color: var(--dim); font-size: 13px; }

#load-more { display: block; margin: 0 auto 26px; }
#load-more[hidden] { display: none; }

/* ---------- library: statuses, ratings, my page ---------- */
.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 9px;
}
#m-actions { margin: 12px 20px 4px; }

.status-seg button.on[data-s="want"]    { background: #7a5bd6; border-color: #7a5bd6; color: #fff; }
.status-seg button.on[data-s="playing"] { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.status-seg button.on[data-s="played"]  { background: #2b7cd3; border-color: #2b7cd3; color: #fff; }

.stars { display: flex; gap: 1px; }
.stars button {
    font: inherit;
    font-size: 17px;
    line-height: 1;
    background: none;
    border: 0;
    padding: 0 2px;
    cursor: pointer;
    color: rgba(255, 255, 255, .22);
}
.stars button.on { color: #f5b301; }
.stars:hover button { color: rgba(255, 255, 255, .35); }
.stars button:hover, .stars button:hover ~ button { color: rgba(255, 255, 255, .35); }

/* marker on cards already in the library */
.mine {
    position: absolute;
    top: 8px; left: 8px;
    z-index: 2;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .5);
}
.mine.want    { background: #7a5bd6; }
.mine.playing { background: #1f9d55; }
.mine.played  { background: #2b7cd3; }

#mine-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 16px 22px 0;
    flex-wrap: wrap;
}
#mine-bar[hidden] { display: none; }
#mine-empty { padding: 40px 22px; color: var(--dim); }

/* ---------- grid ----------
   A fixed six-across layout, centred, so there is breathing room down both
   sides instead of covers running edge to edge. Card size controls how wide
   those six columns are; narrower screens drop columns rather than shrink. */
#grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--gap);
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 22px 0;
}

/* everything else lines up with the grid's edges */
#mine-bar, #status, #pager, #mine-empty {
    width: 100%;
    max-width: var(--maxw);
    margin-left: auto;
    margin-right: auto;
    padding-left: 0;
    padding-right: 0;
}

@media (max-width: 1500px) { :root { --cols: 5; } }
@media (max-width: 1200px) { :root { --cols: 4; } }
@media (max-width: 950px)  { :root { --cols: 3; } }
@media (max-width: 680px)  { :root { --cols: 2; } }

.card {
    position: relative;
    display: block;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-4px); border-color: rgba(255, 255, 255, .4); }
.card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    transform: translateY(-4px);
}

.cover { position: relative; aspect-ratio: 3 / 4; background: #0d0f12; overflow: hidden; }
.cover img {
    position: relative;
    width: 100%; height: 100%;
    object-fit: cover;             /* portrait box art fills the card */
    object-position: center;
    display: block;
}
/* landscape art is shown whole instead of cropped to a slice ... */
.cover img.fit { object-fit: contain; }
/* ... with a blurred copy of itself filling the space around it */
.cover .blurbg {
    position: absolute;
    inset: -12%;
    background-size: cover;
    background-position: center;
    filter: blur(18px) saturate(.75) brightness(.45);
}

.score {
    position: absolute;
    top: 8px; right: 8px;
    z-index: 2;               /* the art is position:relative, so it would cover this */
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 12px;
    color: #fff;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .5);
}
.score.good { background: #1f9d55; }
.score.mid  { background: #c48a12; }
.score.low  { background: #c0392b; }
.score.mine-rating { background: #f5b301; }

.info { padding: 9px 11px 12px; }
.name {
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.sub { margin-top: 4px; font-size: 12px; color: var(--dim); }

/* average time to finish, straight from RAWG's playtime figure */
.hrs {
    margin-top: 3px;
    font-size: 12px;
    font-weight: 600;
    color: #e86ea4;
}

/* ---------- hover preview ---------- */
#hover {
    position: fixed;
    z-index: 200;
    display: flex;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity .12s ease, transform .12s ease;
}
#hover.on { opacity: 1; transform: none; pointer-events: auto; }

.pane {
    width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 14px 38px rgba(0, 0, 0, .6);
}

.stage { position: relative; aspect-ratio: 16 / 9; background: #0d0f12; }
.stage img, .stage video, .stage iframe {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    border: 0;
    object-fit: cover;
}
.stage img { opacity: 0; transition: opacity .15s linear; }
.stage img.on { opacity: 1; }

.tag, .counter {
    position: absolute;
    z-index: 2;
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(0, 0, 0, .65);
    color: #fff;
}
.tag { top: 7px; left: 7px; }
.counter { bottom: 7px; right: 8px; }

/* third pane: community numbers scraped from Backloggd */
.stats-pane { width: 260px; padding: 10px; }
#h-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.stat {
    padding: 10px 4px;
    border-radius: 9px;
    background: rgba(127, 127, 127, .12);
    border: 1px solid var(--line);
    text-align: center;
}
.stat b {
    display: block;
    font-size: 17px;
    line-height: 1.15;
    font-weight: 700;
}
.stat span {
    display: block;
    margin-top: 2px;
    font-size: 10.5px;
    color: var(--dim);
}
.stat.time b { color: #e86ea4; }
.stat.empty b { color: var(--dim); }
#h-stats .none {
    grid-column: 1 / -1;
    padding: 16px 4px;
    text-align: center;
    font-size: 12px;
    color: var(--dim);
}

/* the third pane is the first thing to drop on a narrow screen */
@media (max-width: 1250px) { .stats-pane { display: none; } }

.meta { padding: 10px 12px 12px; }
#h-title { font-weight: 700; }
#h-sub { margin-top: 3px; font-size: 12px; color: var(--dim); }

/* shown when RAWG has no trailer for a game */
.yt {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 12px;
    text-decoration: none;
}
.yt:hover { background: rgba(255, 255, 255, .12); }
/* a class with display: beats the hidden attribute, so restate it */
.yt[hidden] { display: none; }
#m-yt { margin: 10px 20px 0; }

/* ---------- modal ---------- */
#modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: grid;
    place-items: start center;
    padding: 40px 20px;
    overflow: auto;
    background: rgba(0, 0, 0, .72);
}
#modal[hidden] { display: none; }

#modal-box {
    position: relative;
    width: min(900px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}
#modal-box h2 { margin: 16px 20px 6px; }
#modal-box #m-facts { margin: 0 20px; color: var(--dim); font-size: 13px; }
#modal-box #m-desc { margin: 12px 20px 18px; color: rgba(233, 234, 238, .85); }

#modal-close {
    position: absolute;
    top: 10px; right: 12px;
    z-index: 3;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

#m-shots {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    padding: 0 20px 20px;
}
#m-shots img { width: 100%; border-radius: 8px; display: block; }

/* ---------- misc ---------- */
/* ---------- loading feedback ---------- */
/* A bar across the top, so it is obvious work is happening without the
   page moving under the reader. */
#progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    z-index: 200;
    background: rgba(43, 124, 211, .18);
    overflow: hidden;
}
#progress[hidden] { display: none; }
#progress span {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--accent);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform .25s ease;
}

/* placeholder cards: the space the next page will occupy is reserved
   before it arrives, so nothing shifts when it lands */
.card.skeleton { pointer-events: none; border-color: rgba(255, 255, 255, .05); }
.skeleton .cover {
    background: linear-gradient(90deg,
        rgba(255, 255, 255, .04), rgba(255, 255, 255, .10), rgba(255, 255, 255, .04));
    background-size: 200% 100%;
    animation: shimmer 1.3s linear infinite;
}
.skeleton .bar {
    height: 11px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .09);
    margin-bottom: 6px;
}
.skeleton .bar.short { width: 55%; height: 9px; background: rgba(255, 255, 255, .06); }
@keyframes shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

#status { padding: 6px 22px 26px; color: var(--dim); }
#sentinel { height: 1px; }

#foot {
    padding: 22px var(--side);
    border-top: 1px solid var(--line);
    color: var(--dim);
    font-size: 12px;
}

@media (max-width: 700px) {
    .pane { width: 44vw; }
    :root { --card: 150px; }
}
