/* ===== MEMORY MATH MATCH — GAME CSS ===== */

#panel-ren-luyen {
    padding: 4px 12px 12px 12px;
    max-width: 100%;
}

/* Tab con Rèn Luyện — dùng chung "Child tab style" với Settings (hình viên thuốc) */
#renluyen-tabs-child {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
    margin-bottom: 12px;
    padding: 6px 8px;
    border-radius: 10px;
    background: #f8fbff;
    border: 1px dashed #d9eaf7;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.renluyen-child-tab-btn {
    flex: 0 0 auto;
    padding: 7px 14px;
    border: 1.5px solid #b7c7d6;
    border-radius: 999px;
    background: #ffffff;
    color: #1f4e79;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}

.renluyen-child-tab-btn:hover {
    background: #e8f1fb;
    border-color: #2f75b5;
}

.renluyen-child-tab-btn.active {
    background: #2f75b5;
    color: #ffffff;
    border-color: #2f75b5;
    box-shadow: 0 4px 10px rgba(47, 117, 181, 0.25);
}

#mg-panel {
    display: block;
}

/* --- Thanh điều khiển (GỘP 1 hàng, nén chiều cao) --- */
.mg-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: #e3f2fd;
    border-radius: 12px;
    padding: 7px 12px;
    margin-bottom: 8px;
}

/* Cụm chỉ số (lượt chơi · lật) gom gọn, đẩy về phía phải */
.mg-stats {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.mg-stat-sep {
    color: #90a4ae;
    font-weight: bold;
}

/* Nhãn thưởng nhỏ thay cho banner riêng */
.mg-reward-chip {
    display: inline-flex;
    align-items: center;
    background: #fff9c4;
    border: 1.5px solid #ffe082;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12.5px;
    font-weight: 700;
    color: #e65100;
    white-space: nowrap;
}

.mg-controls label {
    font-weight: bold;
    color: #0d47a1;
    font-size: 14px;
}

.mg-level-select {
    padding: 6px 12px;
    border: 2px solid #64b5f6;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    color: #0d47a1;
    background: #fff;
    cursor: pointer;
}

.mg-start-btn {
    padding: 8px 22px;
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.mg-start-btn:hover {
    background: #1565c0;
}

/* Số lượt chơi còn lại trong ngày */
.mg-plays-left {
    font-weight: bold;
    color: #0d47a1;
    font-size: 13px;
    white-space: nowrap;
}

/* Số lần lật thẻ còn lại (nằm trong cụm .mg-stats) */
.mg-flips-left {
    font-weight: bold;
    color: #b71c1c;
    font-size: 13px;
    white-space: nowrap;
}

.mg-flips-left strong {
    font-size: 15px;
}

/* Thông báo hết lượt lật thẻ */
.mg-out-of-flips .mg-complete-text__title {
    color: #b71c1c;
}

/* --- Phần thưởng --- */
.mg-reward-info {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
    background: #fff9c4;
    border-radius: 10px;
    padding: 8px 16px;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: bold;
    border: 2px solid #ffe082;
}

.mg-reward-info span {
    color: #e65100;
}

/* --- Khu game: bọc lưới để overlay phủ tuyệt đối lên trên (không vỡ flow) --- */
.mg-stage {
    position: relative;
}

/* Lớp phủ thông báo kết thúc — nổi GIỮA khu game, lưới giữ nguyên bên dưới (mờ) */
.mg-game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    border-radius: 14px;
    padding: 8px;
    z-index: 6;
}

.mg-overlay-panel {
    background: linear-gradient(135deg, #fff9c4, #fffde7);
    border: 2px solid #ffe082;
    border-radius: 14px;
    padding: 16px 22px;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
    max-width: 92%;
}

.mg-game-overlay.mg-out-of-flips .mg-overlay-panel {
    border-color: #ef9a9a;
    background: linear-gradient(135deg, #ffebee, #fff5f5);
}

/* --- Vùng chơi 2 cột --- */
.mg-play-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    /* Kích thước thẻ qua BIẾN → co theo cấp độ (đặt ở .mg-level-*) để hạn chế cuộn */
    --mg-cw: 96px;
    --mg-ch: 46px;
}

.mg-play-area.mg-level-8 {
    --mg-cw: 108px;
    --mg-ch: 50px;
}

.mg-play-area.mg-level-12 {
    --mg-cw: 96px;
    --mg-ch: 46px;
}

.mg-play-area.mg-level-16 {
    --mg-cw: 84px;
    --mg-ch: 42px;
}

/* Hết lượt lật / đã hoàn thành: KHÓA cả bàn thẻ.
   pointer-events:none chặn mọi chạm/bấm (quan trọng trên trình duyệt điện thoại).
   Khi Chơi lại/ván mới, state đặt outOfFlips=false nên class này tự gỡ. */
.mg-play-area.mg-board-locked {
    pointer-events: none;
}

/* Làm mờ các thẻ CÒN ÚP để thể hiện rõ đã khóa (thẻ đã ghép vẫn nổi bật). */
.mg-play-area.mg-board-locked .mg-card:not(.matched) {
    opacity: 0.45;
    filter: grayscale(0.35);
    cursor: default;
}

/* Mỗi nửa tránh overflow */
.mg-play-area>div {
    min-width: 0;
}

/* Header cột khớp đúng chiều rộng nội dung thẻ */
.mg-col-header {
    text-align: center;
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 6px;
    padding: 4px 8px;
    border-radius: 8px;
    background: #e8f5e9;
    color: #2e7d32;
    width: fit-content;
    min-width: 100%;
}

.mg-col-header.right {
    background: #e3f2fd;
    color: #0d47a1;
}

.mg-col-inner {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
}

.mg-sub-col {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: var(--mg-cw, 96px); /* co theo cấp độ */
    flex-shrink: 0;
}

/* =============================================
   THẺ BÀI
   - Chiều cao cố định 46px mọi cấp độ
   - Mặt trước và mặt sau cùng nền xanh gradient
     → kích thước trông đồng nhất, không "nhảy" khi lật
   ============================================= */
.mg-card-wrap {
    perspective: 600px;
    width: var(--mg-cw, 96px); /* co theo cấp độ */
    height: var(--mg-ch, 46px);
    flex-shrink: 0;
}

.mg-card {
    width: var(--mg-cw, 96px);
    height: var(--mg-ch, 46px);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border-radius: 10px;
}

.mg-card.face-up {
    transform: rotateY(180deg);
}

.mg-card-front,
.mg-card-back {
    position: absolute;
    width: var(--mg-cw, 96px);
    height: var(--mg-ch, 46px);
    box-sizing: border-box;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    user-select: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
}

/* Mặt sau (úp): xanh đậm */
.mg-card-back {
    color: #fff;
    font-size: 18px;
    background: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
}

/* Mặt trước (lật lên): chữ trắng, nền sáng hơn chút để phân biệt */
.mg-card-front {
    transform: rotateY(180deg);
    font-size: 13px;
    color: #fff;
    padding: 2px 4px;
    text-align: center;
    line-height: 1.2;
    /* Màu vàng cam — dễ phân biệt với thẻ úp (xanh) và thẻ đúng (xanh lá) */
    background: linear-gradient(135deg, #ffb74d 0%, #e65100 100%);
}

/* Ghép đúng: nền xanh lá */
.mg-card.matched .mg-card-front {
    background: linear-gradient(135deg, #66bb6a, #2e7d32);
    color: #fff;
    animation: mg-match-flash 0.35s ease;
}

@keyframes mg-match-flash {
    0% {
        background: #fff9c4;
    }

    100% {
        background: linear-gradient(135deg, #66bb6a, #2e7d32);
    }
}

/* Sai: nền đỏ nhạt + rung */
.mg-card.wrong .mg-card-front {
    background: linear-gradient(135deg, #ef9a9a, #c62828);
    animation: mg-shake 0.4s ease;
}

@keyframes mg-shake {

    0%,
    100% {
        transform: rotateY(180deg) translateX(0);
    }

    25% {
        transform: rotateY(180deg) translateX(-5px);
    }

    75% {
        transform: rotateY(180deg) translateX(5px);
    }
}

/* --- Overlay đếm ngược --- */
.mg-reveal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    flex-direction: column;
    gap: 12px;
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    pointer-events: none;
}

.mg-reveal-overlay .mg-big-count {
    font-size: 72px;
    line-height: 1;
    color: #fff176;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    animation: mg-count-pop 0.9s ease infinite;
}

@keyframes mg-count-pop {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }
}

/* --- Thông báo hoàn thành (dạng text trên màn hình, không popup) --- */
.mg-complete-text {
    margin: 14px auto 0;
    padding: 14px 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, #fff9c4, #fffde7);
    border: 2px solid #ffe082;
    text-align: center;
    max-width: 520px; /* thu hẹp vùng msg */
}

.mg-complete-text__title {
    font-size: 18px;
    font-weight: 800;
    color: #f57f17;
    margin-bottom: 6px;
}

.mg-complete-text__body {
    font-size: 14px;
    font-weight: 700;
    color: #2e7d32;
    margin-bottom: 6px;
}

.mg-complete-text__hint {
    font-size: 13px;
    color: #0d47a1;
}

.mg-play-again-btn {
    margin-top: 12px;
    padding: 10px 28px;
    background: #43a047;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.mg-play-again-btn:hover {
    background: #2e7d32;
}

.mg-no-student {
    text-align: center;
    color: #888;
    padding: 40px 16px;
    font-size: 16px;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .mg-play-area {
        /* Khoảng cách giữa 2 cột lớn "Phép toán" và "Kết quả" */
        gap: 8px;
        /* Mobile: co thẻ theo cấp để bớt cuộn (cấp cao nhiều hàng → thẻ nhỏ hơn) */
        --mg-cw: 76px;
        --mg-ch: 42px;
    }

    .mg-play-area.mg-level-8 {
        --mg-cw: 84px;
        --mg-ch: 46px;
    }

    .mg-play-area.mg-level-12 {
        --mg-cw: 76px;
        --mg-ch: 40px;
    }

    .mg-play-area.mg-level-16 {
        --mg-cw: 66px;
        --mg-ch: 34px;
    }

    .mg-card-front,
    .mg-card-back {
        font-size: 11px;
    }

    /* Mỗi cột (Phép toán/Kết quả) = LƯỚI 2 cột cố định (theo --mg-cw) → luôn 2 thẻ/hàng,
       đều cho mọi cấp (8/12/16), không còn thẻ lẻ rớt xuống một mình. */
    .mg-col-inner {
        display: grid;
        grid-template-columns: repeat(2, var(--mg-cw, 72px));
        justify-content: center;
        gap: 7px 7px;
    }

    /* Bỏ gom nhóm 4-thẻ: mọi thẻ chảy thẳng vào lưới 2 cột ở trên. */
    .mg-sub-col {
        display: contents;
    }

    /* Panel overlay gọn lại trên điện thoại */
    .mg-overlay-panel {
        padding: 12px 16px;
    }
}

/* 🔘 CTA game (lg) đồng bộ token chung từ style.css; GIỮ màu */
.mg-start-btn,
.mg-play-again-btn {
    border-radius: var(--btn-radius);
    padding: var(--btn-pad-y-lg) var(--btn-pad-x-lg);
    min-height: var(--btn-min-h-lg);
    font-size: var(--btn-font-lg);
}