:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-back: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --card-matched: #10b981;
    --text-color: #f8fafc;
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.game-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    backdrop-filter: blur(10px);
}

.stats {
    display: flex;
    gap: 20px;
}

.stat-box {
    display: flex;
    flex-direction: column;
}

.stat-box .label {
    font-size: 0.8rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.header-btns {
    display: flex;
    gap: 10px;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn.secondary {
    background: #475569;
}
.btn.secondary:hover {
    background: #334155;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 60vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.countdown-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    transition: opacity 0.3s;
}

.countdown-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#countdown-text {
    font-size: 6rem;
    font-weight: bold;
    color: var(--primary);
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
    animation: pop 1s infinite;
}

@keyframes pop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

.game-board {
    display: grid;
    gap: 10px;
    width: 100%;
    height: 100%;
}

/* Card Styles */
.card {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

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

.card.matched {
    transform: rotateY(180deg) scale(0.95);
    /* opacity: 0.8 removed to prevent preserve-3d flattening bug */
    cursor: default;
}

.card.matched .card-front::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(16, 185, 129, 0.3);
    border-radius: 12px;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem; /* Adjusted dynamically in JS maybe, but this is a good default */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.card-front {
    background: var(--card-bg);
    transform: rotateY(180deg);
    border: 2px solid rgba(255, 255, 255, 0.1);
    position: relative; /* For ::after overlay */
    overflow: hidden;
}



.card-back {
    background-image: url('/assets/games/card-match/card_back.png');
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

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

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--card-matched);
}

.modal-content p {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #cbd5e1;
}

.modal-content .btn {
    margin-top: 20px;
    font-size: 1rem;
    padding: 12px 20px;
}

.input-group {
    margin: 15px 0;
}

.input-group input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.2);
    color: white;
    font-size: 1.1rem;
    text-align: center;
}

.ranking-list {
    text-align: left;
    margin: 20px 0;
    max-height: 200px;
    overflow-y: auto;
}

.rank-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 1.1rem;
}

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

.rank-item .rank-name {
    font-weight: bold;
    color: #f8fafc;
}

.rank-item .rank-score {
    color: var(--primary);
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-5px); }
    75% { transform: rotateY(180deg) translateX(5px); }
}

.card.wrong {
    animation: shake 0.4s ease-in-out;
}

/* Responsive adjustments */
@media (max-width: 400px) {
    .card-face {
        font-size: 2rem;
    }
}
