/* M4: Ghép Tranh Động Vật - Style */


h1, h2, h3 { font-family: 'Baloo 2', cursive; color: #4CAF50; }

.game-wrapper {
    max-width: 600px;
    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: #4CAF50; 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: 10px; }
.game-header h1 { font-size: 2.2rem; color: #388E3C; margin-bottom: 5px; }
.game-header p { font-size: 1.1rem; color: #555; margin-bottom: 10px; }

.score-board {
    display: inline-block; background: #C8E6C9; padding: 6px 20px;
    border-radius: 99px; font-weight: 800; font-size: 1.1rem; color: #2E7D32;
    box-shadow: 0 4px 0px #A5D6A7; margin-bottom: 10px;
}

/* Khu vực Bảng Ghép (Puzzle Board) */
.game-area {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-around;
}

.puzzle-board-wrapper {
    position: relative;
    width: 280px; height: 280px;
    background: white;
    border: 8px solid #81C784;
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    margin-bottom: 15px;
}

.hint-image {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    /* Update hình nền thông qua JS */
    background-size: 280px 280px; /* Bằng với Board */
    opacity: 0.15; z-index: 1; pointer-events: none;
}

.puzzle-board {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: grid; grid-template-columns: 140px 140px; grid-template-rows: 140px 140px;
    z-index: 2;
}

.puzzle-slot {
    width: 140px; height: 140px;
    border: 2px dashed #A5D6A7;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: #C8E6C9; font-weight: 900; font-family: 'Baloo 2', cursive;
    transition: background 0.2s;
}

.puzzle-slot.hover { background: rgba(165, 214, 167, 0.3); border-color: #4CAF50; }

/* Khu chứa miếng ghép ở dưới */
.pieces-container {
    width: 100%; height: 180px;
    background: rgba(255,255,255,0.6); border-radius: 20px; border: 4px dashed #C8E6C9;
    display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px;
    position: relative; padding: 10px;
}

/* Các mảnh ghép (Pieces) */
.puzzle-piece {
    width: 140px; height: 140px;
    background-size: 280px 280px; /* Render gốc là 280x280 (cho mảnh ghép 2x2) */
    background-repeat: no-pos;
    box-shadow: 0 5px 10px rgba(0,0,0,0.2);
    cursor: grab;
    z-index: 10;
    touch-action: none;
    transition: transform 0.2s;
    user-select: none;
    border: 2px solid white;
}

.puzzle-piece.dragging {
    position: absolute; z-index: 100; transform: scale(1.1); transition: none;
}

.puzzle-piece.matched {
    position: absolute !important; z-index: 5;
    border: none; box-shadow: none;
    transition: all 0.3s !important; transform: scale(1) !important; cursor: default;
}

/* Tọa độ Background của 4 mảnh 140x140 trên lưới 280x280 */
.piece-bg-1 { background-position: 0 0; }
.piece-bg-2 { background-position: -140px 0; }
.piece-bg-3 { background-position: 0 -140px; }
.piece-bg-4 { background-position: -140px -140px; }

/* 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: 4rem; margin-bottom: 10px; animation: bounce 2s infinite; }
.win-image-preview {
    width: 150px; height: 150px; margin: 0 auto 20px;
    background-size: cover; border-radius: 12px; border: 4px solid #81C784;
}

.btn-primary {
    background: #4CAF50; 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 #2E7D32; margin: 5px;
}

.btn-secondary {
    display: inline-block; background: #E2E8F0; color: #4A5568; margin: 5px;
    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;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-15px);}
    60% {transform: translateY(-7px);}
}

/* Media Query cho màn rất nhỏ (Ví dụ iPhone SE) */
@media (max-width: 350px) {
    .puzzle-board-wrapper { width: 240px; height: 240px; }
    .puzzle-board { grid-template-columns: 120px 120px; grid-template-rows: 120px 120px; }
    .puzzle-slot { width: 120px; height: 120px; }
    .hint-image { background-size: 240px 240px; }
    .puzzle-piece { 
        width: 120px; height: 120px; background-size: 240px 240px; 
    }
    .piece-bg-2 { background-position: -120px 0; }
    .piece-bg-3 { background-position: 0 -120px; }
    .piece-bg-4 { background-position: -120px -120px; }
    .pieces-container { height: 150px; padding: 5px; }
    .game-header h1 { font-size: 1.8rem; }
}
