/* =====================================================
   Game History Page — Phase 3 (v9.2.0)
   Premium dark theme with glassmorphism
   ===================================================== */

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(18, 18, 42, 0.85);
    --bg-card-hover: rgba(30, 30, 60, 0.95);
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #5a5a7a;
    --accent: #7c5cfc;
    --accent-light: #9d82ff;
    --accent-glow: rgba(124, 92, 252, 0.25);
    --gold: #f5c842;
    --gold-glow: rgba(245, 200, 66, 0.2);
    --green: #34d399;
    --red: #f87171;
    --blue: #60a5fa;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Navbar ─────────────────────────────────────────── */
.navbar {
    background: rgba(10, 10, 26, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary) !important;
    transition: var(--transition);
}

.navbar-brand:hover {
    color: var(--accent-light) !important;
}

.brand-text {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.user-badge {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ── Main Container ─────────────────────────────────── */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ── Stats Hero ─────────────────────────────────────── */
.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.title-icon {
    font-size: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    text-align: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--accent-light);
    line-height: 1.2;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Achievements ───────────────────────────────────── */
.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-icon {
    font-size: 1.25rem;
}

.achievements-section {
    margin-bottom: 2.5rem;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    transition: var(--transition);
}

.achievement-card.earned {
    border-color: var(--gold);
    background: linear-gradient(135deg, rgba(245, 200, 66, 0.06), var(--bg-card));
}

.achievement-card.earned:hover {
    box-shadow: 0 4px 16px var(--gold-glow);
    transform: translateY(-1px);
}

.achievement-card.unearned {
    opacity: 0.45;
    filter: grayscale(0.5);
}

.achievement-card.unearned:hover {
    opacity: 0.65;
}

.ach-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
    width: 40px;
    text-align: center;
}

.ach-info {
    flex: 1;
    min-width: 0;
}

.ach-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.ach-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.ach-earned-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 3px;
}

/* ── Games List (Active Games) ──────────────────────── */
.games-section {
    margin-bottom: 2.5rem;
}

.games-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.active-game-card {
    background: var(--bg-card);
    border: 1px solid var(--green);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: var(--transition);
}

.active-game-card:hover {
    box-shadow: 0 4px 20px rgba(52, 211, 153, 0.15);
    transform: translateY(-2px);
}

.active-game-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.active-game-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.btn-resume {
    background: var(--green);
    color: #0a0a1a;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.4rem 1rem;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-resume:hover {
    background: #5ee8b7;
    transform: translateY(-1px);
    color: #0a0a1a;
}

/* ── History Table ──────────────────────────────────── */
.history-section {
    margin-bottom: 2rem;
}

.game-history-table {
    color: var(--text-primary);
    border-collapse: separate;
    border-spacing: 0;
}

.game-history-table thead th {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    padding: 0.75rem 0.85rem;
    white-space: nowrap;
}

.game-history-table tbody tr {
    transition: var(--transition);
}

.game-history-table tbody tr:hover {
    background: var(--glass-bg);
}

.game-history-table tbody td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding: 0.75rem 0.85rem;
    font-size: 0.85rem;
    vertical-align: middle;
}

.game-title-cell {
    font-weight: 600;
    color: var(--accent-light);
}

.type-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.type-badge.clue_hunt {
    background: rgba(124, 92, 252, 0.15);
    color: var(--accent-light);
}

.type-badge.escape_room {
    background: rgba(245, 200, 66, 0.15);
    color: var(--gold);
}

.type-badge.trivia {
    background: rgba(96, 165, 250, 0.15);
    color: var(--blue);
}

.status-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.status-badge.completed {
    background: rgba(52, 211, 153, 0.15);
    color: var(--green);
}

.status-badge.active {
    background: rgba(96, 165, 250, 0.15);
    color: var(--blue);
}

.status-badge.withdrawn {
    background: rgba(248, 113, 113, 0.15);
    color: var(--red);
}

.rank-cell {
    font-weight: 700;
    font-size: 1rem;
}

.rank-cell.rank-1 {
    color: var(--gold);
}

.rank-cell.rank-2 {
    color: #c0c0c0;
}

.rank-cell.rank-3 {
    color: #cd7f32;
}

.score-cell {
    font-weight: 600;
    color: var(--accent-light);
}

.time-cell {
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.ach-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.ach-pill {
    font-size: 0.95rem;
    cursor: default;
}

.date-cell {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Pagination ─────────────────────────────────────── */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ── Auth Prompt ────────────────────────────────────── */
.auth-prompt {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.auth-card {
    text-align: center;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 3rem;
    max-width: 420px;
}

.auth-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.auth-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.auth-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.7rem 1.5rem;
    font-weight: 600;
    color: white;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
}

/* ── Placeholder / Empty State ──────────────────────── */
.placeholder-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.85rem;
    max-width: 400px;
    margin: 0 auto;
}

/* ── Animations ─────────────────────────────────────── */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card,
.achievement-card,
.active-game-card {
    animation: fadeInUp 0.4s ease-out both;
}

.stat-card:nth-child(1) {
    animation-delay: 0.05s;
}

.stat-card:nth-child(2) {
    animation-delay: 0.1s;
}

.stat-card:nth-child(3) {
    animation-delay: 0.15s;
}

.stat-card:nth-child(4) {
    animation-delay: 0.2s;
}

.stat-card:nth-child(5) {
    animation-delay: 0.25s;
}

.stat-card:nth-child(6) {
    animation-delay: 0.3s;
}

.achievement-card:nth-child(n) {
    animation-delay: calc(0.05s * var(--i, 0));
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
    .main-container {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .achievements-grid {
        grid-template-columns: 1fr;
    }

    .games-list {
        grid-template-columns: 1fr;
    }

    .game-history-table {
        font-size: 0.8rem;
    }

    /* Horizontally scrollable table on mobile */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-card {
        padding: 0.85rem 0.65rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}