:root {
    color-scheme: dark;
    --bg: #15181f;
    --bg-elevated: #1d2027;
    --bg-elevated-2: #262a33;
    --bg-hover: #2c303b;
    --fg: #e1e3e8;
    --fg-muted: #93989f;
    --fg-strong: #f5f6f8;
    --border: #2e323d;
    --border-strong: #404553;
    --primary: #6ba2ff;
    --primary-hover: #8eb8ff;
    --primary-fg: #0b1018;
    --approved-bg: rgba(70, 200, 110, 0.18);
    --approved-text: #6ee097;
    --denied-bg: rgba(220, 100, 100, 0.18);
    --denied-text: #ff9999;
    --flash-bg: rgba(107, 162, 255, 0.12);
    --flash-border: rgba(107, 162, 255, 0.4);
    --flash-text: #b5cfff;
    --error-text: #ff9999;
}

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    max-width: 80rem;
    margin: 2rem auto;
    padding: 0 1rem;
    color: var(--fg);
    background: var(--bg);
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--fg-strong);
}

.user-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.9rem;
    color: var(--fg-muted);
}

.user-link {
    color: var(--fg);
    text-decoration: none;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
}

.user-link:hover {
    background: var(--bg-hover);
    color: var(--fg-strong);
}

.header-action {
    display: inline;
    margin: 0;
}

.header-action button {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
}

.header-action button:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

/* Add-game bar */

.add-game-bar { margin-bottom: 1rem; }

.add-game-bar form {
    display: flex;
    gap: 0.5rem;
}

.add-game-bar input[type="url"] {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    background: var(--bg-elevated);
    color: var(--fg);
}

.add-game-bar input[type="url"]::placeholder { color: var(--fg-muted); }

.add-game-bar input[type="url"]:focus {
    outline: none;
    border-color: var(--primary);
}

.add-game-bar button {
    padding: 0.5rem 1.25rem;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}

.add-game-bar button:hover { background: var(--primary-hover); }

/* Filter tabs */

.filters {
    display: flex;
    gap: 0.25rem;
    margin: 1rem 0;
    flex-wrap: wrap;
    align-items: center;
}

.view-toggle {
    margin-left: auto;
    color: var(--fg-muted);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    user-select: none;
}

.view-toggle input { cursor: pointer; }

.filter-link {
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--fg-muted);
    text-decoration: none;
    font-size: 0.9rem;
    background: var(--bg-elevated);
    cursor: pointer;
}

.filter-link:hover {
    background: var(--bg-hover);
    color: var(--fg);
}

.filter-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-fg);
    font-weight: 600;
}

.filter-link .count {
    margin-left: 0.3rem;
    font-size: 0.8rem;
    opacity: 0.75;
}

/* Games table */

.games {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.92rem;
}

.games th, .games td {
    text-align: left;
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.games thead th {
    background: var(--bg-elevated-2);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--fg-strong);
    border-bottom: 1px solid var(--border-strong);
}

.games tbody tr:nth-child(even) { background: var(--bg-elevated-2); }
.games tbody tr:hover { background: var(--bg-hover); }
.games tbody tr:last-child td { border-bottom: none; }

/* Played rows: kept at the bottom by ORDER BY, visually muted so the active
   games read first. Vote/played cell colors stay so the row is still scannable. */
.played-row td.name a,
.played-row td.release,
.played-row td.reviews,
.played-row td.price,
.played-row td.notes {
    color: var(--fg-muted);
}

body.hide-played #dashboard.status-all .games tr.played-row { display: none; }

/* When played rows are hidden, plain :nth-child(even) breaks the alternation
   because it still counts the (now-invisible) played rows. Re-derive the
   zebra by counting only the rows that are actually visible. Both the odd
   and even override are needed — the default :nth-child(even) above would
   otherwise still match by DOM position. */
body.hide-played #dashboard.status-all .games tbody tr:nth-child(odd of :not(.played-row)) {
    background: var(--bg-elevated);
}
body.hide-played #dashboard.status-all .games tbody tr:nth-child(even of :not(.played-row)) {
    background: var(--bg-elevated-2);
}

.games td.name a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.games td.name a:hover { text-decoration: underline; }

.games td.release, .games td.reviews { color: var(--fg-muted); white-space: nowrap; }
.games td.price { white-space: nowrap; font-variant-numeric: tabular-nums; }

.games td.price .discount {
    display: inline-block;
    margin-left: 0.25rem;
    padding: 0.05rem 0.35rem;
    background: var(--approved-bg);
    color: var(--approved-text);
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 600;
}

.games th.vote-col { text-align: center; width: 2.5rem; }
.games td.vote { text-align: center; cursor: pointer; user-select: none; width: 2.5rem; }
.games td.vote-approved { background: var(--approved-bg); color: var(--approved-text); }
.games td.vote-denied { background: var(--denied-bg); color: var(--denied-text); }
.games td.vote-none { color: var(--fg-muted); }
.games td.vote:hover { filter: brightness(1.25); }

.games td.played { text-align: center; cursor: pointer; user-select: none; }
.games td.played-yes { background: var(--approved-bg); color: var(--approved-text); }
.games td.played-no { color: var(--fg-muted); }
.games td.played:hover { filter: brightness(1.25); }

.games td.notes {
    color: var(--fg-muted);
    font-size: 0.88rem;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty {
    color: var(--fg-muted);
    text-align: center;
    padding: 2rem 1rem;
}

/* Flash */

.flash {
    background: var(--flash-bg);
    border: 1px solid var(--flash-border);
    color: var(--flash-text);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
}

/* Detail page */

header h1 .back {
    color: var(--primary);
    text-decoration: none;
    margin-right: 0.25rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.detail-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}

.detail-card h2 {
    margin: 0 0 0.75rem 0;
    font-size: 1.05rem;
    color: var(--fg-strong);
}

.detail-card dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1rem;
    margin: 0;
    font-size: 0.92rem;
}

.detail-card dt { color: var(--fg-muted); }
.detail-card dd { margin: 0; word-break: break-word; color: var(--fg); }

.detail-card dd.err {
    color: var(--error-text);
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
}

.vote-summary { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.vote-summary td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); }

.played-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
    font-size: 0.95rem;
}

.played-status .played {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    min-width: 1.5rem;
    text-align: center;
}

.chart-card #chart {
    width: 100%;
    height: 240px;
}

.notes-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.notes-form textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    resize: vertical;
    background: var(--bg);
    color: var(--fg);
}

.notes-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.notes-form button {
    align-self: flex-start;
    padding: 0.4rem 1rem;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.notes-form button:hover { background: var(--primary-hover); }

.card-actions {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.card-actions button {
    background: var(--bg-elevated-2);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
}

.card-actions button:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.card-actions button.danger {
    color: var(--denied-text);
    border-color: rgba(220, 100, 100, 0.4);
}

.card-actions button.danger:hover {
    background: rgba(220, 100, 100, 0.15);
    border-color: var(--denied-text);
}

/* Login & users */

.login-body { background: var(--bg); }

.login {
    max-width: 24rem;
    margin: 4rem auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
}

.login h1 {
    margin: 0 0 1rem 0;
    color: var(--fg-strong);
}

.login form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login .field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: var(--fg-muted);
}

.login input[type="password"],
.login input[type="text"] {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    background: var(--bg);
    color: var(--fg);
}

.login input:focus {
    outline: none;
    border-color: var(--primary);
}

.login fieldset {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--bg);
}

.login fieldset legend {
    padding: 0 0.25rem;
    font-size: 0.85rem;
    color: var(--fg-muted);
}

.user-option {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    color: var(--fg);
}

/* /users page: each row is a pair of mini-forms — pick + delete */

.users-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.user-row {
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
}

.user-select-form {
    flex: 1;
    margin: 0;
}

.user-pick {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
}

.user-pick:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.user-row.current .user-pick {
    border-color: var(--primary);
}

.user-pick .current-marker {
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 600;
}

.user-delete-form { margin: 0; }

.user-delete {
    padding: 0 0.7rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg-muted);
    cursor: pointer;
    font: inherit;
    font-size: 1.1rem;
    line-height: 1;
}

.user-delete:hover {
    color: var(--denied-text);
    border-color: rgba(220, 100, 100, 0.4);
    background: rgba(220, 100, 100, 0.08);
}

.login button[type="submit"] {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
}

.login button[type="submit"]:hover { background: var(--primary-hover); }

.login-hint, .hint {
    font-size: 0.8rem;
    color: var(--fg-muted);
    margin-top: 0.75rem;
    line-height: 1.4;
}

.login-hint code {
    background: var(--bg);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: ui-monospace, monospace;
    color: var(--fg);
}

.new-user-form { margin-top: 1.5rem; }

.users-sep {
    margin: 1.5rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

.back-link {
    margin-top: 1.5rem;
    font-size: 0.85rem;
    text-align: center;
}

.back-link a {
    color: var(--fg-muted);
    text-decoration: none;
}

.back-link a:hover { color: var(--fg); }

/* uPlot dark adjustments */

.uplot, .uplot * { color: var(--fg-muted); }
.u-legend { color: var(--fg-muted); }
.u-title { color: var(--fg-strong); }
