/* M3: Tìm Hình Giống Nhau - Style */
body {
    background: #FFF5E1;
    font-family: 'Nunito', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

h1, h2, h3 { font-family: 'Baloo 2', cursive; }

.game-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px; font-weight: 700;
    color: #FF8BA0; background: #fff;
    padding: 8px 16px; border-radius: 99px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    align-self: flex-start; margin-bottom: 5px;
    transition: transform 0.2s;
}

.back-btn:active { transform: scale(0.95); }

.game-header { text-align: center; margin-bottom: 20px; }
.game-header h1 { font-size: 2.5rem; color: #FF8BA0; margin-bottom: 5px; }
.game-header p { font-size: 1.1rem; color: #7B8B9A; margin-bottom: 15px; }

.score-board, .moves-board {
    display: inline-block;
    padding: 6px 20px; border-radius: 99px; font-weight: 800; font-size: 1.1rem;
    margin: 0 5px; margin-bottom: 10px;
}

.score-board { background: #FFD18C; color: #A0522D; }
.moves-board { background: #A0DEFF; color: #1E6B9B; }

/* Memory Grid */
.game-area {
    flex: 1; display: flex; align-items: center; justify-content: center;
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    gap: 15px;
    perspective: 1000px;
    width: 100%;
    max-width: 500px;
}

/* Card Class */
.memory-card {
    width: 100%;
    aspect-ratio: 1 / 1; /* Thẻ vuông */
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.memory-card.flip { transform: rotateY(180deg); }
.memory-card.match { opacity: 0.8; pointer-events: none; }
.memory-card.wrong { animation: shake 0.5s; }

/* Front & Back Faces */
.front-face, .back-face {
    width: 100%; height: 100%;
    position: absolute;
    border-radius: 16px;
    backface-visibility: hidden;
    display: flex; align-items: center; justify-content: center;
    font-size: 3.5rem;
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.back-face {
    /* Mặt sau (khi chưa lật, là ảnh Pattern/Logo biểu tượng ?) */
    background: linear-gradient(135deg, #FF9EBB 0%, #FF6B8B 100%);
    color: white; font-family: 'Baloo 2', cursive; font-size: 3rem;
    transform: rotateY(0deg); /* Mặc định úp, CSS 3D thì mặt này là ngửa về phía người dùng */
    border: 3px solid white;
}

.front-face {
    /* Mặt trước (khi đã lật, chứa HÌNH ẢNH) */
    background: #ffffff;
    transform: rotateY(180deg);
    border: 3px solid #FFD18C;
}

@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    20%, 60% { transform: rotateY(180deg) translateX(-5px); }
    40%, 80% { transform: rotateY(180deg) translateX(5px); }
}

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 1000;
}

.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal-content {
    background: white; padding: 40px; border-radius: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    transform: scale(0.8); transition: transform 0.3s;
    max-width: 90%; width: 400px;
}
.modal-overlay.show .modal-content { transform: scale(1); }

.modal-icon { font-size: 5rem; margin-bottom: 20px; animation: bounce 2s infinite; }
.btn-primary {
    background: #FF5A79; color: white; border: none; padding: 12px 30px;
    font-size: 1.2rem; font-family: 'Baloo 2', cursive; border-radius: 99px;
    cursor: pointer; box-shadow: 0 6px 0px #D83A5A; margin: 10px;
}
.btn-secondary {
    display: inline-block; background: #E2E8F0; color: #4A5568;
    border: none; padding: 12px 30px; font-size: 1.2rem; font-family: 'Baloo 2', cursive;
    border-radius: 99px; cursor: pointer; box-shadow: 0 6px 0px #CBD5E0; margin: 10px;
}
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-20px);}
    60% {transform: translateY(-10px);}
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .memory-grid { gap: 10px; padding: 0 10px; }
    .front-face, .back-face { font-size: 2.5rem; border-radius: 12px; }
    .back-face { font-size: 2rem; }
    .game-header h1 { font-size: 2rem; }
}
