/* Toplist Game Styles - Themeable (light/dark/auto) */

.toplist-game-container {
    /* Theme tokens (default = light) */
    --tg-surface: #ffffff;
    --tg-surface2: #f8f9fa;
    --tg-text: #1f2937;
    --tg-muted: #6c757d;
    --tg-border: rgba(15, 23, 42, 0.10);
    --tg-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --tg-rank-bg1: #667eea;
    --tg-rank-bg2: #764ba2;
    --tg-btn1a: #667eea;
    --tg-btn1b: #764ba2;
    --tg-btn2a: #f093fb;
    --tg-btn2b: #f5576c;
    --tg-star-empty: #e4e5e9;
    --tg-star-filled: #ffb900;

    /* Rank highlight colors (1/2/3) */
    --tg-rank-1a: #f59e0b;
    --tg-rank-1b: #f97316;
    --tg-rank-2a: #9ca3af;
    --tg-rank-2b: #6b7280;
    --tg-rank-3a: #c08457;
    --tg-rank-3b: #a16207;
    width: 100%;
    margin: 0 auto;
}

/* ===== Color palettes (override button + default rank gradient) ===== */
.toplist-game-container.tg-palette-purple_pink {
    --tg-rank-bg1: #667eea; --tg-rank-bg2: #764ba2;
    --tg-btn1a: #667eea; --tg-btn1b: #764ba2;
    --tg-btn2a: #f093fb; --tg-btn2b: #f5576c;
}
.toplist-game-container.tg-palette-ocean {
    --tg-rank-bg1: #2563eb; --tg-rank-bg2: #14b8a6;
    --tg-btn1a: #2563eb; --tg-btn1b: #14b8a6;
    --tg-btn2a: #06b6d4; --tg-btn2b: #22c55e;
}
.toplist-game-container.tg-palette-sky {
    --tg-rank-bg1: #06b6d4; --tg-rank-bg2: #3b82f6;
    --tg-btn1a: #06b6d4; --tg-btn1b: #3b82f6;
    --tg-btn2a: #38bdf8; --tg-btn2b: #6366f1;
}
.toplist-game-container.tg-palette-emerald {
    --tg-rank-bg1: #10b981; --tg-rank-bg2: #84cc16;
    --tg-btn1a: #10b981; --tg-btn1b: #84cc16;
    --tg-btn2a: #22c55e; --tg-btn2b: #a3e635;
}
.toplist-game-container.tg-palette-sunset {
    --tg-rank-bg1: #f97316; --tg-rank-bg2: #ef4444;
    --tg-btn1a: #f97316; --tg-btn1b: #ef4444;
    --tg-btn2a: #fb7185; --tg-btn2b: #f59e0b;
}
.toplist-game-container.tg-palette-royal {
    --tg-rank-bg1: #4f46e5; --tg-rank-bg2: #f59e0b;
    --tg-btn1a: #4f46e5; --tg-btn1b: #7c3aed;
    --tg-btn2a: #f59e0b; --tg-btn2b: #f97316;
}
.toplist-game-container.tg-palette-cherry {
    --tg-rank-bg1: #ef4444; --tg-rank-bg2: #fb7185;
    --tg-btn1a: #ef4444; --tg-btn1b: #fb7185;
    --tg-btn2a: #f43f5e; --tg-btn2b: #8b5cf6;
}
.toplist-game-container.tg-palette-mint {
    --tg-rank-bg1: #14b8a6; --tg-rank-bg2: #34d399;
    --tg-btn1a: #14b8a6; --tg-btn1b: #34d399;
    --tg-btn2a: #2dd4bf; --tg-btn2b: #60a5fa;
}
.toplist-game-container.tg-palette-coffee {
    --tg-rank-bg1: #92400e; --tg-rank-bg2: #f59e0b;
    --tg-btn1a: #92400e; --tg-btn1b: #f59e0b;
    --tg-btn2a: #b45309; --tg-btn2b: #f97316;
}
.toplist-game-container.tg-palette-mono {
    --tg-rank-bg1: #334155; --tg-rank-bg2: #64748b;
    --tg-btn1a: #334155; --tg-btn1b: #64748b;
    --tg-btn2a: #475569; --tg-btn2b: #94a3b8;
}
.toplist-game-container.tg-palette-neon {
    --tg-rank-bg1: #7c3aed; --tg-rank-bg2: #06b6d4;
    --tg-btn1a: #7c3aed; --tg-btn1b: #06b6d4;
    --tg-btn2a: #22c55e; --tg-btn2b: #f43f5e;
}

/* ===== Rank colors: 1/2/3 special, others use palette default ===== */
.toplist-game-card[data-rank="1"] .game-rank,
.toplist-game-card[data-rank="01"] .game-rank {
    background: linear-gradient(135deg, var(--tg-rank-1a) 0%, var(--tg-rank-1b) 100%);
}
.toplist-game-card[data-rank="2"] .game-rank,
.toplist-game-card[data-rank="02"] .game-rank {
    background: linear-gradient(135deg, var(--tg-rank-2a) 0%, var(--tg-rank-2b) 100%);
}
.toplist-game-card[data-rank="3"] .game-rank,
.toplist-game-card[data-rank="03"] .game-rank {
    background: linear-gradient(135deg, var(--tg-rank-3a) 0%, var(--tg-rank-3b) 100%);
}

.toplist-game-container *,
.toplist-game-container *::before,
.toplist-game-container *::after {
    box-sizing: border-box;
}

.toplist-game-container.tg-theme-dark {
    --tg-surface: #0b1220;
    --tg-surface2: #0f1a2e;
    --tg-text: rgba(255, 255, 255, 0.92);
    --tg-muted: rgba(255, 255, 255, 0.68);
    --tg-border: rgba(255, 255, 255, 0.10);
    --tg-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --tg-star-empty: rgba(255, 255, 255, 0.22);
}

/* Auto theme uses prefers-color-scheme */
@media (prefers-color-scheme: dark) {
    .toplist-game-container.tg-theme-auto {
        --tg-surface: #0b1220;
        --tg-surface2: #0f1a2e;
        --tg-text: rgba(255, 255, 255, 0.92);
        --tg-muted: rgba(255, 255, 255, 0.68);
        --tg-border: rgba(255, 255, 255, 0.10);
        --tg-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
        --tg-star-empty: rgba(255, 255, 255, 0.22);
    }
}

.toplist-game-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.toplist-game-card {
    background: linear-gradient(135deg, var(--tg-surface) 0%, var(--tg-surface2) 100%);
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid var(--tg-border);
    width: 100%;
}

.toplist-game-card:hover {
    transform: translateY(-4px);
}

.game-content {
    padding: 16px 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.game-logo-wrapper {
    position: relative;
    flex-shrink: 0;
}

.game-rank {
    position: absolute;
    top: -8px;
    left: -8px;
    background: linear-gradient(135deg, var(--tg-rank-bg1) 0%, var(--tg-rank-bg2) 100%);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    z-index: 10;
    border: 3px solid rgba(255, 255, 255, 0.92);
}

.game-rank .rank-number {
    line-height: 1;
}

.game-logo {
    width: 72px;
    height: 72px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.96);
}

.game-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.game-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    align-items: flex-start;
}

.game-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--tg-text);
    line-height: 1.2;
}

.game-rating {
    display: flex;
    gap: 2px;
    align-items: center;
}

.game-rating .star {
    color: var(--tg-star-empty);
    font-size: 16px;
    transition: color 0.2s ease;
    line-height: 1;
}

.game-rating .star.filled {
    color: var(--tg-star-filled);
}

.game-description {
    margin: 0;
    padding-top: 0;
}

.game-description p {
    margin: 0;
    color: var(--tg-muted);
    font-size: 13px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-align: left;
}

.game-actions {
    display: flex;
    gap: 10px;
    margin-top: 2px;
    padding-top: 6px;
}

.game-btn {
    flex: 1;
    padding: 11px 18px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.game-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.game-btn-icon svg {
    display: block;
}

.game-btn-primary {
    background: linear-gradient(135deg, var(--tg-btn1a) 0%, var(--tg-btn1b) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.game-btn-primary:hover {
    background: linear-gradient(135deg, color-mix(in srgb, var(--tg-btn1a) 88%, #000 12%) 0%, color-mix(in srgb, var(--tg-btn1b) 88%, #000 12%) 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.game-btn-secondary {
    background: linear-gradient(135deg, var(--tg-btn2a) 0%, var(--tg-btn2b) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.3);
}

.game-btn-secondary:hover {
    background: linear-gradient(135deg, color-mix(in srgb, var(--tg-btn2a) 88%, #000 12%) 0%, color-mix(in srgb, var(--tg-btn2b) 88%, #000 12%) 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(245, 87, 108, 0.4);
}

/* Responsive Design */
@media (max-width: 768px) {
    .toplist-game-container {
        padding: 15px;
    }

    .toplist-game-grid {
        gap: 14px;
    }

    .toplist-game-card {
        border-radius: 12px;
    }

    .game-content {
        padding: 14px;
        gap: 8px;
    }

    .game-header {
        gap: 12px;
    }

    .game-rank {
        width: 32px;
        height: 32px;
        font-size: 12px;
        top: -6px;
        left: -6px;
        border-width: 2px;
    }

    .game-logo {
        width: 62px;
        height: 62px;
        border-radius: 10px;
    }

    .game-title {
        font-size: 16px;
    }

    .game-rating .star {
        font-size: 15px;
    }

    .game-description p {
        font-size: 13px;
    }

    .game-actions {
        flex-direction: row;
        gap: 10px;
    }

    .game-btn {
        width: auto;
        padding: 11px 14px;
    }
}

@media (max-width: 480px) {
    .toplist-game-container {
        padding: 10px;
    }

    .toplist-game-grid {
        gap: 12px;
    }

    .game-content {
        padding: 12px;
        gap: 8px;
    }

    .game-rank {
        width: 30px;
        height: 30px;
        font-size: 11px;
        top: -5px;
        left: -5px;
    }

    .game-logo {
        width: 56px;
        height: 56px;
    }

    .game-title {
        font-size: 16px;
    }

    .game-rating .star {
        font-size: 15px;
    }

    .game-description {
        padding-top: 2px;
    }

    .game-description p {
        font-size: 12px;
        -webkit-line-clamp: 1;
        line-clamp: 1;
    }

    .game-actions {
        margin-top: 2px;
        padding-top: 6px;
    }

    .game-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Loading animation */
.toplist-game-card {
    animation: fadeInUp 0.6s ease-out forwards;
}

.toplist-game-card:nth-child(1) { animation-delay: 0.1s; }
.toplist-game-card:nth-child(2) { animation-delay: 0.2s; }
.toplist-game-card:nth-child(3) { animation-delay: 0.3s; }
.toplist-game-card:nth-child(4) { animation-delay: 0.4s; }
.toplist-game-card:nth-child(5) { animation-delay: 0.5s; }

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Focus states for accessibility */
.game-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .toplist-game-card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .game-btn {
        display: none;
    }
}