:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #ec4899;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --card-bg: #1e293b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-layout {
    width: 95%;
    max-width: 1200px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

.game-area {
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #818cf8, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 1.5rem;
}

.stats-container {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.stat-box {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem 2rem;
    border-radius: 16px;
    min-width: 140px;
    border: 1px solid var(--glass-border);
    transition: transform 0.3s ease;
}

.stat-box:hover {
    transform: translateY(-5px);
}

.label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 12px;
    perspective: 1000px;
    margin-bottom: 2rem;
}

.card {
    aspect-ratio: 1/1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.hidden-cell {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.card.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-back {
    background: var(--card-bg);
    border: 2px solid var(--glass-border);
    transition: background 0.3s ease;
}

.card-back::after {
    content: '?';
    font-size: 2rem;
    font-weight: 700;
    color: var(--glass-border);
}

.card:hover .card-back {
    background: #334155;
    border-color: var(--primary);
}

.card-front {
    background: #fff;
    transform: rotateY(180deg);
}

.card-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.btn {
    padding: 0.75rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    outline: none;
}

.btn.primary {
    background: var(--primary);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Ranking */
.ranking-sidebar {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
}

.ranking-sidebar h2 {
    font-size: 1.25rem;
    text-align: center;
    margin-bottom: 1rem;
    color: #fca311;
}

.ranking-list {
    flex-grow: 1;
    overflow-y: auto;
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.9rem;
    animation: slideIn 0.4s ease forwards;
    opacity: 0;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

.ranking-item.top-rank {
    background: rgba(251, 191, 36, 0.1);
    border-radius: 8px;
    border-bottom-color: rgba(251, 191, 36, 0.2);
}

.rank-num {
    font-weight: 700;
    color: var(--text-muted);
    width: 25px;
}

.player-name {
    flex-grow: 1;
    margin-left: 0.5rem;
    display: flex;
    align-items: center;
}

.player-time {
    color: #4ade80;
    font-family: monospace;
    font-weight: 700;
    font-size: 1rem;
}

.crown {
    margin-left: 0.5rem;
    font-size: 1.1rem;
    filter: drop-shadow(0 0 5px rgba(251, 191, 36, 0.5));
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
}

/* Input Modal */
#player-name {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: white;
    margin: 1rem 0;
    text-align: center;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    border: 1px solid var(--glass-border);
    max-width: 400px;
    width: 90%;
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #fca311;
}

.final-stats {
    margin: 1.5rem 0;
    font-size: 1.25rem;
    color: var(--text-muted);
}

.final-stats span {
    color: var(--text-main);
    font-weight: 700;
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    .ranking-sidebar {
        margin-top: 2rem;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
    .game-board {
        gap: 8px;
    }
    h1 {
        font-size: 1.75rem;
    }
    .stats-container {
        gap: 1rem;
    }
    .stat-box {
        padding: 0.75rem 1rem;
        min-width: 110px;
    }
}
