:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-track: #e5e3fb;
    --color-border: #e2e4e9;
    --color-danger: #dc2626;
    --color-danger-bg: #fef2f2;
    --color-success: #16a34a;
    --color-success-bg: #f0fdf4;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #14161c;
        --color-surface: #1c1f28;
        --color-text: #e9eaef;
        --color-text-muted: #9aa0ac;
        --color-primary: #6366f1;
        --color-primary-hover: #7880f5;
        --color-primary-track: #2a2a4a;
        --color-border: #2c3040;
        --color-danger: #f87171;
        --color-danger-bg: #2a1414;
        --color-success: #4ade80;
        --color-success-bg: #10241a;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

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

/* Centered card layout, used for login / password change / 2FA setup */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    width: 100%;
    max-width: 400px;
}

.card h1 {
    margin-top: 0;
    font-size: 1.5rem;
}

.card p.subtitle {
    color: var(--color-text-muted);
    margin-top: -8px;
    margin-bottom: 24px;
    font-size: 0.95rem;
}

label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 1rem;
    margin-bottom: 16px;
}

input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

button, .button {
    display: inline-block;
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

button:hover, .button:hover {
    background: var(--color-primary-hover);
}

button.secondary, .button.secondary {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.button-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 6px;
}

.button-danger {
    background: var(--color-danger);
}

.button-danger:hover {
    background: var(--color-danger);
    opacity: 0.85;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-actions form {
    margin: 0;
}

.error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.success {
    background: var(--color-success-bg);
    color: var(--color-success);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.hint {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-top: -10px;
    margin-bottom: 16px;
}

.qr-code {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}

.qr-code img {
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.secret-key {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 10px 12px;
    word-break: break-all;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* App shell layout, used once logged in. Navigation lives in the fixed
   bottom tab bar (.bottom-nav) — the header is just branding. */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-header .brand {
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--color-text);
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 20;
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    border-radius: 8px;
}

.bottom-nav-item.active {
    color: var(--color-primary);
}

.bottom-nav-icon {
    width: 22px;
    height: 22px;
}

.bottom-nav-avatar-wrap {
    position: relative;
    display: inline-flex;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--color-primary-track);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='8' r='4' fill='%234f46e5'/%3E%3Cpath d='M4 20c0-4.4 3.6-8 8-8s8 3.6 8 8' fill='%234f46e5'/%3E%3C/svg%3E");
    background-size: 100% 100%;
    overflow: hidden;
}

@media (prefers-color-scheme: dark) {
    .bottom-nav-avatar-wrap {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='8' r='4' fill='%236366f1'/%3E%3Cpath d='M4 20c0-4.4 3.6-8 8-8s8 3.6 8 8' fill='%236366f1'/%3E%3C/svg%3E");
    }
}

.bottom-nav-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bottom-nav-badge {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-danger);
    border: 1px solid var(--color-surface);
}

.settings-list {
    display: flex;
    flex-direction: column;
    margin: 16px 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.settings-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    color: var(--color-text);
    text-decoration: none;
    border-bottom: 1px solid var(--color-border);
}

.settings-list-item:last-child {
    border-bottom: none;
}

.settings-list-item:hover {
    background: var(--color-bg);
}

.app-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px calc(24px + 64px);
}

/* Tables can't shrink below their content width, so let them scroll
   sideways on narrow screens instead of forcing the whole page wider. */
@media (max-width: 600px) {
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .app-content {
        padding: 16px 14px calc(16px + 64px);
    }

    .app-header {
        padding: 10px 14px;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.95rem;
}

th {
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.admin {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge.inactive {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.muted {
    color: var(--color-text-muted);
    font-weight: normal;
    font-size: 0.85em;
}

.game-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.game-card {
    display: flex;
    gap: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
}

.play-card {
    position: relative;
    transition: border-color 0.15s ease;
}

.play-card:hover {
    border-color: var(--color-primary);
}

/* Lets the whole card act as a link to the play (via .card-stretched-link)
   while specific inner links (game name, logged-by username) stay above it
   and remain independently clickable — real <a> nesting isn't valid HTML. */
.card-stretched-link {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.play-card .inline-link {
    position: relative;
    z-index: 2;
}

.inline-link {
    color: inherit;
    text-decoration: none;
}

.inline-link:hover {
    text-decoration: underline;
}

.game-detail-header {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.game-detail-image {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    background: var(--color-bg);
}

.profile-header {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-bg);
}

.profile-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary-track);
    color: var(--color-primary);
    font-size: 2rem;
    font-weight: 700;
}

.profile-photo-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 8px 0;
}

.profile-photo-form input[type="file"] {
    width: auto;
    margin-bottom: 0;
}

.profile-name-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: flex-end;
    max-width: 480px;
    margin: 16px 0;
}

.profile-name-form .form-group {
    display: flex;
    flex-direction: column;
}

.profile-name-form label {
    margin-bottom: 6px;
}

.profile-name-form input {
    width: 160px;
    margin-bottom: 0;
}

.game-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    background: var(--color-bg);
}

.game-thumb-placeholder {
    border: 1px dashed var(--color-border);
}

.game-info {
    flex: 1;
    min-width: 0;
}

.game-info h3 {
    margin: 0 0 4px 0;
}

.status-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.pill-form {
    margin: 0;
    display: inline;
}

.pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
}

.pill-active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.filter-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0 20px 0;
}

.filter-chip {
    display: inline-block;
    padding: 5px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-muted);
    text-decoration: none;
}

.filter-chip-active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.month-chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.month-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.month-label {
    width: 80px;
    flex-shrink: 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.month-bar-track {
    flex: 1;
    background: var(--color-primary-track);
    border-radius: 6px;
    overflow: hidden;
    height: 18px;
}

.month-bar {
    background: var(--color-primary);
    height: 100%;
    border-radius: 6px;
}

.month-count {
    width: 170px;
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-align: right;
}

/* Stat tiles — headline numbers at the top of a dashboard. */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.stat-tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-tile .stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

.stat-tile .stat-value {
    font-size: 1.8rem;
    font-weight: 600;
    font-variant-numeric: proportional-nums;
    margin-top: 4px;
}

/* Meter — a value on a 0-100 scale (e.g. win rate) shown as a filled track
   next to its number, so relative standing reads at a glance. */
.meter-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.meter-track {
    flex: 1;
    background: var(--color-primary-track);
    border-radius: 999px;
    overflow: hidden;
    height: 8px;
    min-width: 60px;
}

.meter-fill {
    background: var(--color-primary);
    height: 100%;
    border-radius: 999px;
}

.meter-value {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    width: 3.2em;
    text-align: right;
    flex-shrink: 0;
}

.photo-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}

.home-profile {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.home-quick-stats {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin: 4px 0 0;
}

.home-carousel {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 10px;
    margin: 4px 0 20px;
}

.home-action-tile {
    flex-shrink: 0;
    width: 108px;
    height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-muted);
    text-decoration: none;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px;
    overflow: hidden;
}

.home-action-tile:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.home-action-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.home-action-thumb {
    width: 100%;
    height: 68px;
    object-fit: cover;
    border-radius: 6px;
}

.home-play-tile {
    flex-shrink: 0;
    width: 108px;
    text-decoration: none;
    color: var(--color-text);
    position: relative;
}

.home-play-thumb {
    width: 108px;
    height: 108px;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--color-bg);
}

.home-play-trophy {
    position: absolute;
    top: 6px;
    right: 6px;
}

.home-play-name {
    font-size: 0.82rem;
    font-weight: 600;
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-play-meta {
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

.home-collection-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 12px 0 24px;
}

.home-collection-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 16px;
    border-radius: var(--radius);
    text-decoration: none;
}

.home-collection-tile .home-tile-count {
    font-size: 1.4rem;
    font-weight: 700;
}

.home-collection-tile .home-tile-label {
    font-size: 0.85rem;
    opacity: 0.85;
}

.home-tile-blue {
    background: #dbeafe;
    color: #1e40af;
}

.home-tile-green {
    background: #dcfce7;
    color: #166534;
}

.home-tile-purple {
    background: #ede9fe;
    color: #5b21b6;
}

.home-tile-pink {
    background: #fce7f3;
    color: #9d174d;
}

@media (prefers-color-scheme: dark) {
    .home-tile-blue {
        background: #1e3a5f;
        color: #93c5fd;
    }

    .home-tile-green {
        background: #14532d;
        color: #86efac;
    }

    .home-tile-purple {
        background: #3b2a6b;
        color: #c4b5fd;
    }

    .home-tile-pink {
        background: #5c1a3d;
        color: #f9a8d4;
    }
}

.photo-thumb {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--color-border);
}
