:root { --topbar-h: 50px; }

* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #1a1a1a;
    color: #eee;
}
header {
    height: var(--topbar-h);
    padding: 0 1.25rem;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    background: #1a1a1a;
    z-index: 60;
}
header h1 {
    font-size: 1.05rem;
    margin: 0;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.header-right::-webkit-scrollbar { display: none; }
#stats { color: #999; font-size: 0.85rem; white-space: nowrap; }
#f-sort {
    background: #222;
    color: #eee;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    cursor: pointer;
}
.link-btn {
    background: none;
    border: none;
    color: #4fa3e0;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
}
.link-btn:hover { color: #6fbff5; text-decoration: underline; }

aside#filters {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: 252px;
    padding: 0.75rem 1rem;
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    border-right: 1px solid #333;
    background: #1a1a1a;
}
aside#filters h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #888;
    margin: 0.8rem 0 0.3rem;
    letter-spacing: 0.05em;
}
aside#filters h2:first-child { margin-top: 0; }

aside#filters .filter-group {
    margin-bottom: 0.3rem;
    border-top: 1px solid #2a2a2a;
    padding-top: 0.25rem;
}
aside#filters .filter-group:first-of-type { border-top: none; padding-top: 0; }
aside#filters .filter-group > summary {
    cursor: pointer;
    list-style: none;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.05em;
    padding: 0.4rem 0 0.25rem;
    user-select: none;
    display: flex;
    align-items: center;
}
aside#filters .filter-group > summary::-webkit-details-marker { display: none; }
aside#filters .filter-group > summary::before {
    content: "\25BE";
    display: inline-block;
    width: 0.9rem;
    color: #555;
    transition: transform 0.1s;
    flex-shrink: 0;
}
aside#filters .filter-group:not([open]) > summary::before {
    content: "\25B8";
}
aside#filters .filter-group > summary:hover { color: #ccc; }
aside#filters .filter-group > summary:hover::before { color: #999; }
aside#filters .filter-group input[type="text"],
aside#filters .filter-group input[type="number"] {
    margin-top: 0.1rem;
}
aside#filters label {
    display: block;
    font-size: 0.85rem;
    margin: 0.15rem 0;
    cursor: pointer;
}
aside#filters input[type="text"],
aside#filters input[type="search"],
aside#filters select {
    width: 100%;
    padding: 0.3rem;
    background: #222;
    color: #eee;
    border: 1px solid #444;
    border-radius: 3px;
    font-size: 0.85rem;
}
aside#filters input[type="search"] {
    padding-right: 1.8rem;
    -webkit-appearance: none;
    appearance: none;
}
aside#filters input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}
.search-wrap { position: relative; }
.search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #888;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.4rem;
    cursor: pointer;
    width: auto !important;
    margin: 0 !important;
}
.search-clear:hover { color: #eee; }
aside#filters input[type="number"] { width: 4rem; }

.pc-slider-wrap { padding: 0.3rem 0.2rem 0.5rem; }
.pc-display { font-size: 0.8rem; color: #ccc; margin-bottom: 0.5rem; text-align: center; }
.pc-slider {
    position: relative;
    height: 22px;
}
.pc-slider::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    background: #333;
    border-radius: 2px;
    z-index: 0;
}
.pc-slider input[type="range"] {
    position: absolute;
    width: 100%;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 22px;
    margin: 0;
    padding: 0;
    top: 0;
    left: 0;
    z-index: 2;
}
.pc-slider input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #4fa3e0;
    border: 2px solid #1a1a1a;
    cursor: grab;
}
.pc-slider input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; }
.pc-slider input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4fa3e0;
    border: 2px solid #1a1a1a;
    cursor: grab;
}
.pc-slider input[type="range"]::-webkit-slider-runnable-track { background: transparent; }
.pc-slider input[type="range"]::-moz-range-track { background: transparent; }

.pc-inputs { display: none; }
.pc-inputs label { display: block; }

@media (max-width: 768px) {
    .pc-slider-wrap { display: none; }
    .pc-inputs { display: block; }
}
aside#filters button {
    width: 100%;
    padding: 0.4rem;
    margin-top: 0.25rem;
    background: #2b6cb0;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
}
aside#filters button:hover { background: #3182ce; }
aside#filters details summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.5rem;
}
aside#filters details input[type="file"] {
    width: 100%;
    font-size: 0.75rem;
    margin: 0.4rem 0;
}

#status-block {
    font-size: 0.8rem;
    color: #bbb;
    background: #222;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.5rem;
}
#status-block .stat-row { display: flex; justify-content: space-between; margin: 0.1rem 0; }
#status-block .stat-row b { color: #eee; font-weight: 500; }
#status-block .stat-row.sub { color: #888; font-size: 0.75rem; padding-left: 0.4rem; }
#status-block .stat-row.sub b { color: #aaa; }
#status-block .progress-bar {
    background: #333;
    border-radius: 2px;
    height: 6px;
    margin: 0.3rem 0 0.4rem;
    overflow: hidden;
}
#status-block .progress-fill {
    background: #4fa3e0;
    height: 100%;
    transition: width 0.3s;
}
#status-block .last-run {
    margin-top: 0.4rem;
    font-size: 0.72rem;
    color: #888;
}
#status-block .last-run .fail { color: #e88; }
#status-block .last-run .ok { color: #8e8; }

main#games {
    margin-left: 282px;
    padding: 1rem 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.card {
    background: #252525;
    border: 1px solid #333;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.card .cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #111 center / cover no-repeat;
}
.card .body {
    padding: 0.5rem 0.75rem 0.75rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.card .title {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
    line-height: 1.2;
}
.card .meta { font-size: 0.75rem; color: #999; flex-grow: 1; }
.card .badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
}
.badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: #444;
    color: #eee;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card .mp-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-top: 0.4rem;
}
.mp-pill {
    font-size: 0.62rem;
    padding: 0.1rem 0.35rem;
    border-radius: 8px;
    background: #2a2a2a;
    color: #666;
    border: 1px solid #333;
    letter-spacing: 0.04em;
    user-select: none;
    transition: background 0.1s, color 0.1s;
}
.mp-pill.on {
    background: #2b6cb0;
    color: #fff;
    border-color: #4fa3e0;
}
body.logged-in .mp-pill { cursor: pointer; }
body.logged-in .mp-pill:hover { background: #3a3a3a; }
body.logged-in .mp-pill.on:hover { background: #3182ce; }
.badge.steam { background: #1b2838; }
.badge.bgg { background: #ff5100; color: white; }
.badge.psn { background: #006fcd; }
.badge.epic { background: #313131; color: #eee; }
.badge.ubisoft { background: #0072c6; }
.badge.blizzard { background: #00aeff; color: #002133; }
.badge.meta-quest { background: #1c1e20; color: #00b3ff; border: 1px solid #00b3ff; }
.badge.play-store { background: #2e8b57; color: white; }
.badge.humble { background: #cc2929; color: white; }
.badge.vr { background: #6f3cff; color: white; }
.badge.vr-mode { background: #2a1a4d; color: #c5b3ff; border: 1px solid #6f3cff; }

#ingest-status {
    font-size: 0.8rem;
    color: #aaa;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

aside#filters details .hint {
    font-size: 0.75rem;
    color: #aaa;
    margin: 0.4rem 0;
    line-height: 1.4;
}
aside#filters details ol.hint {
    padding-left: 1.2rem;
    margin: 0.4rem 0;
}
aside#filters details ol.hint li { margin: 0.15rem 0; }
aside#filters details code {
    background: #333;
    padding: 0.05rem 0.25rem;
    border-radius: 2px;
    font-size: 0.7rem;
}
aside#filters details a { color: #4fa3e0; }
aside#filters details textarea {
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.3rem;
    background: #111;
    color: #ddd;
    border: 1px solid #333;
    border-radius: 3px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.65rem;
    resize: vertical;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-overlay.open { display: flex; }

body.modal-open { overflow: hidden; }
.modal-overlay { overscroll-behavior: contain; touch-action: pan-y; }
.game-modal-card { overscroll-behavior: contain; }

.card { cursor: pointer; transition: transform 0.1s; }
.card:hover { transform: translateY(-2px); }

.game-modal-card {
    background: #1d1d1d;
    border-radius: 10px;
    width: min(820px, 95vw);
    max-height: 92vh;
    overflow-y: auto;
    padding: 0;
    position: relative;
    color: #eee;
    border: 1px solid #333;
}
.close-x {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 1.6rem;
    cursor: pointer;
    z-index: 1;
    padding: 0 0.4rem;
}
.close-x:hover { color: #fff; }
.game-modal-body {
    display: grid;
    grid-template-columns: minmax(180px, 240px) 1fr;
    gap: 1.25rem;
    padding: 1.5rem;
}
.game-modal-cover-wrap { display: flex; align-items: flex-start; }
.game-modal-cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #111 center / cover no-repeat;
    border-radius: 6px;
    border: 1px solid #333;
}
.game-modal-cover.empty { background: #222; }
.game-modal-info h2 { margin: 0 0 0.4rem; font-size: 1.25rem; color: #f0c060; }
.game-modal-info h3 {
    margin: 1rem 0 0.4rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.05em;
}
.gm-meta { color: #aaa; font-size: 0.9rem; margin-bottom: 0.5rem; }
.gm-badges { margin-bottom: 0.5rem; display: flex; gap: 0.3rem; flex-wrap: wrap; }
.gm-genres { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.genre-chip {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #ccc;
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}
.gm-ownership { list-style: none; padding: 0; margin: 0; }
.gm-ownership li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid #2a2a2a;
    font-size: 0.85rem;
}
.gm-ownership li:last-child { border-bottom: none; }
.ownership-plat { color: #aaa; }
.ownership-pt { color: #888; font-size: 0.78rem; flex-grow: 1; }
.src-link {
    color: #4fa3e0;
    text-decoration: none;
    font-size: 0.8rem;
}
.src-link:hover { text-decoration: underline; }
.gm-actions { margin-top: 0.75rem; }
.action-link {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    background: #2b6cb0;
    color: #fff;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
}
.action-link:hover { background: #3182ce; }
.muted { color: #666; font-size: 0.8rem; }

#gm-editor-wrap { margin-top: 1rem; }
#gm-editor-wrap summary { cursor: pointer; color: #888; padding: 0.4rem 0; }
.gm-edit-form { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.gm-edit-form label {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.gm-edit-form input {
    padding: 0.4rem 0.6rem;
    background: #111;
    color: #eee;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 0.9rem;
    text-transform: none;
    font-family: inherit;
}
.gm-edit-form .row {
    flex-direction: row;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.gm-edit-form button {
    flex: 1;
    padding: 0.5rem 0.8rem;
    border: none;
    border-radius: 4px;
    background: #2b6cb0;
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
}
.gm-edit-form button.ghost { background: transparent; color: #aaa; border: 1px solid #444; }
.gm-edit-form button:hover { background: #3182ce; }
.gm-edit-form button.ghost:hover { background: #222; color: #fff; }

.gm-raw-wrap {
    margin-top: 0.75rem;
    border-top: 1px solid #2a2a2a;
    padding-top: 0.5rem;
}
.gm-raw-wrap > summary {
    cursor: pointer;
    color: #888;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.3rem 0;
}
.gm-raw {
    background: #0d0d0d;
    color: #b0c5d8;
    border: 1px solid #222;
    border-radius: 4px;
    padding: 0.6rem;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.7rem;
    line-height: 1.4;
    overflow: auto;
    max-height: 50vh;
    white-space: pre-wrap;
    word-wrap: break-word;
}

@media (max-width: 600px) {
    .game-modal-body {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
    .game-modal-cover { max-width: 60vw; margin: 0 auto; }
}
.modal-card {
    background: #16213e;
    border-radius: 12px;
    padding: 36px 32px;
    width: 320px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    color: #eee;
}
.modal-card h2 {
    font-size: 1.3rem;
    margin: 0 0 4px;
    color: #f0c060;
    font-weight: 600;
}
.modal-card .sub { font-size: 0.85rem; color: #888; margin-bottom: 20px; }
.modal-card label {
    display: block;
    font-size: 0.8rem;
    color: #aaa;
    margin: 14px 0 4px;
}
.modal-card input[type="text"],
.modal-card input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    border-radius: 6px;
    border: 1px solid #333;
    background: #0f3460;
    color: #eee;
    font-size: 0.95rem;
    outline: none;
}
.modal-card input:focus { border-color: #f0c060; }
.modal-card .error {
    background: #5c1a1a;
    color: #f88;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
    margin-top: 16px;
}
.modal-card .row {
    display: flex;
    gap: 0.5rem;
    margin-top: 22px;
}
.modal-card button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: #f0c060;
    color: #1a1a2e;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.modal-card button:hover { background: #f5d080; }
.modal-card button.ghost {
    background: transparent;
    color: #aaa;
    border: 1px solid #444;
}
.modal-card button.ghost:hover { background: #222; color: #eee; }

#filters-toggle {
    display: none;
    background: none;
    border: 1px solid #444;
    color: #eee;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
}

@media (max-width: 768px) {
    :root { --topbar-h: 46px; }

    header { padding: 0 0.75rem; gap: 0.5rem; }
    header h1 { font-size: 0.95rem; }
    .header-right {
        gap: 0.4rem;
        overflow-x: visible;
        flex-shrink: 0;
    }
    #stats { display: none; }
    #f-sort {
        font-size: 0.7rem;
        padding: 0.15rem 0.3rem;
        max-width: 110px;
    }
    #filters-toggle {
        display: inline-block;
        padding: 0.2rem 0.5rem;
        font-size: 0.75rem;
    }
    .link-btn { font-size: 0.75rem; }

    aside#filters {
        top: var(--topbar-h);
        height: calc(100vh - var(--topbar-h));
        width: 84vw;
        max-width: 320px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
    }
    aside#filters.open { transform: translateX(0); }
    aside#filters .close-btn {
        display: block;
        width: 100%;
        margin-bottom: 0.5rem;
        background: #333;
    }

    main#games {
        margin-left: 0;
        padding: 0.5rem 0.4rem;
        grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
        gap: 0.4rem;
    }
    .card .body { padding: 0.35rem 0.45rem 0.5rem; }
    .card .title { font-size: 0.72rem; line-height: 1.15; }
    .card .meta { font-size: 0.62rem; }
    .badge {
        font-size: 0.55rem;
        padding: 0.05rem 0.25rem;
        letter-spacing: 0.02em;
    }
    .card .badges { gap: 0.15rem; margin-top: 0.3rem; }
    .mp-pill { font-size: 0.55rem; padding: 0.05rem 0.25rem; }

    .modal-card {
        width: calc(100vw - 2rem);
        max-width: 340px;
        margin: 1rem;
        padding: 24px 20px;
    }

    .filters-backdrop {
        display: none;
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }
    .filters-backdrop.open { display: block; }
}

@media (max-width: 360px) {
    header h1 { font-size: 0.85rem; }
    #f-sort { max-width: 95px; font-size: 0.65rem; }
    main#games {
        grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
        gap: 0.3rem;
    }
}

@media (min-width: 769px) {
    aside#filters .close-btn { display: none; }
}
