/* ==========================================================================
   CSS CHO BÉ HỌC TOÁN - THIẾT KẾ PHONG CÁCH PASTEL CỰC ĐẸP VÀ VUI NHỘN
   ========================================================================== */

:root {
    --primary-font: 'Fredoka', 'Quicksand', 'Nunito', sans-serif;
    --color-bg-start: #FFDEE9;
    --color-bg-end: #B5FFFC;
    --color-card-bg: rgba(255, 255, 255, 0.88);

    /* Màu sắc sinh động, an toàn cho mắt bé */
    --color-pink: #FF6B8B;
    --color-pink-dark: #E04E6E;
    --color-green: #4ECA87;
    --color-green-dark: #37A869;
    --color-blue: #4EA8DE;
    --color-blue-dark: #3B88B5;
    --color-yellow: #FFD166;
    --color-yellow-dark: #E6B53B;
    --color-purple: #9B5DE5;
    --color-purple-dark: #7B3EBF;
    --color-text: #4A4A4A;
    --color-text-light: #7E7E7E;

    --shadow-3d: 0 8px 0 rgba(0, 0, 0, 0.12);
    --shadow-3d-active: 0 2px 0 rgba(0, 0, 0, 0.12);
    --card-shadow: 0 15px 35px rgba(103, 110, 144, 0.15);
}

/* --- Thiết lập chung --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    /* Tối ưu hóa chạm trên điện thoại */
}

body {
    font-family: var(--primary-font);
    background: linear-gradient(135deg, var(--color-bg-start) 0%, var(--color-bg-end) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--color-text);
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* --- Background bong bóng bay lơ lửng --- */
.bubble-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-bubble {
    position: absolute;
    bottom: -150px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    animation: bubbleUp 15s infinite linear;
    filter: blur(1px);
}

@keyframes bubbleUp {
    0% {
        transform: translateY(0) rotate(0deg) scale(0.8);
        opacity: 0;
    }

    10% {
        opacity: 0.6;
    }

    90% {
        opacity: 0.6;
    }

    100% {
        transform: translateY(-120vh) rotate(360deg) scale(1.2);
        opacity: 0;
    }
}

/* --- Container Ứng Dụng --- */
.app-container {
    width: 90%;
    max-width: 680px;
    min-height: 600px;
    z-index: 10;
    position: relative;
    margin: 20px auto;
}

/* --- Các Màn Hình --- */
.screen {
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.screen.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* --- MÀN HÌNH BẮT ĐẦU --- */
.logo-area {
    text-align: center;
    margin-bottom: 30px;
}

.logo-emoji {
    font-size: 4rem;
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.1));
    animation: float 3s ease-in-out infinite;
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    color: var(--color-pink);
    text-shadow: 3px 3px 0px #fff, 5px 5px 0px rgba(0, 0, 0, 0.08);
    letter-spacing: 2px;
    margin-top: 10px;
}

.subtitle {
    font-size: 1.15rem;
    color: var(--color-blue-dark);
    margin-top: 5px;
    font-weight: 500;
}

/* Thẻ lựa chọn */
.section-card {
    background: var(--color-card-bg);
    border-radius: 24px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    border: 3px solid #fff;
    backdrop-filter: blur(10px);
}

.section-card h3 {
    font-size: 1.15rem;
    margin-bottom: 15px;
    color: var(--color-text);
    font-weight: 600;
}

/* Lựa chọn Avatar */
.avatar-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.avatar-btn {
    background: #fff;
    border: 3px solid #EAEAEA;
    border-radius: 20px;
    padding: 12px 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: var(--primary-font);
    box-shadow: 0 4px 0 #EAEAEA;
}

.avatar-btn .emoji {
    font-size: 2.2rem;
    margin-bottom: 5px;
    transition: transform 0.2s;
}

.avatar-btn .name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-light);
}

.avatar-btn:hover {
    transform: translateY(-4px);
    border-color: var(--color-blue);
    box-shadow: 0 8px 0 var(--color-blue-dark);
}

.avatar-btn:hover .emoji {
    transform: scale(1.15);
}

.avatar-btn.active {
    border-color: var(--color-blue);
    background: #E8F5FF;
    box-shadow: 0 4px 0 var(--color-blue-dark);
    transform: translateY(2px);
}

.avatar-btn.active .name {
    color: var(--color-blue-dark);
}

/* Lựa chọn Phép Toán */
.mode-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.mode-btn {
    background: #fff;
    border: 3px solid #EAEAEA;
    border-radius: 20px;
    padding: 15px 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: var(--primary-font);
    box-shadow: 0 4px 0 #EAEAEA;
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.mode-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.mode-desc {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin-top: 3px;
    text-align: center;
}

.mode-btn:hover {
    transform: translateY(-4px);
    border-color: var(--color-green);
    box-shadow: 0 8px 0 var(--color-green-dark);
}

.mode-btn.active {
    border-color: var(--color-green);
    background: #EDFAF2;
    box-shadow: 0 4px 0 var(--color-green-dark);
    transform: translateY(2px);
}

/* Lựa chọn đồ vật đếm */
.item-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.item-btn {
    background: #fff;
    border: 3px solid #EAEAEA;
    border-radius: 16px;
    padding: 10px 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--primary-font);
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 0 #EAEAEA;
}

.item-btn:hover {
    transform: translateY(-3px);
    border-color: var(--color-yellow);
    box-shadow: 0 7px 0 var(--color-yellow-dark);
}

.item-btn.active {
    border-color: var(--color-yellow);
    background: #FFFDF0;
    box-shadow: 0 4px 0 var(--color-yellow-dark);
    transform: translateY(2px);
}

/* Lựa chọn phạm vi số */
.range-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.range-btn {
    background: #fff;
    border: 3px solid #EAEAEA;
    border-radius: 16px;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: var(--primary-font);
    font-weight: 700;
    font-size: 0.95rem;
    box-shadow: 0 4px 0 #EAEAEA;
}

.range-btn:hover {
    transform: translateY(-3px);
    border-color: var(--color-blue);
    box-shadow: 0 7px 0 var(--color-blue-dark);
}

.range-btn.active {
    border-color: var(--color-blue);
    background: #E8F5FF;
    box-shadow: 0 4px 0 var(--color-blue-dark);
    transform: translateY(2px);
}

.custom-range-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 3px solid #EAEAEA;
    border-radius: 16px;
    padding: 7px 12px;
    box-shadow: 0 4px 0 #EAEAEA;
    transition: all 0.2s;
}

.custom-range-input-container:focus-within {
    border-color: var(--color-purple);
    box-shadow: 0 6px 0 var(--color-purple-dark);
    transform: translateY(-2px);
}

.custom-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--color-text-light);
}

.custom-range-input {
    width: 60px;
    border: 2px solid #EAEAEA;
    border-radius: 10px;
    padding: 4px 8px;
    font-family: var(--primary-font);
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-purple-dark);
    text-align: center;
    outline: none;
}

/* Thu nhỏ vật thể đếm khi số lượng lớn */
.small-items .counting-item {
    font-size: 1.6rem !important;
    width: 36px !important;
    height: 36px !important;
}

.small-items .counting-item .count-badge {
    width: 16px !important;
    height: 16px !important;
    font-size: 0.65rem !important;
    bottom: -3px !important;
    right: -3px !important;
}

/* Nút lớn Bắt đầu */
.main-btn {
    width: 100%;
    background: linear-gradient(185deg, var(--color-pink) 0%, var(--color-pink-dark) 100%);
    border: none;
    border-bottom: 8px solid rgba(0, 0, 0, 0.18);
    border-radius: 25px;
    color: #fff;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 18px 30px;
    cursor: pointer;
    font-family: var(--primary-font);
    box-shadow: 0 10px 25px rgba(255, 107, 139, 0.35);
    transition: all 0.1s ease;
    margin-top: 10px;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.15);
}

.main-btn:active {
    transform: translateY(4px);
    border-bottom-width: 4px;
    box-shadow: 0 5px 15px rgba(255, 107, 139, 0.35);
}

/* --- MÀN HÌNH CHƠI GAME --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.icon-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid #EAEAEA;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #EAEAEA;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 0 #D0D0D0;
}

.icon-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #D0D0D0;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.8);
    padding: 6px 15px;
    border-radius: 20px;
    border: 2px solid #fff;
    font-weight: 600;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.03);
}

.player-info #player-avatar {
    font-size: 1.6rem;
}

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

.stat-badge {
    background: #fff;
    padding: 8px 14px;
    border-radius: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 3px solid #fff;
    box-shadow: var(--card-shadow);
}

.score-badge {
    border-color: var(--color-yellow);
    color: var(--color-yellow-dark);
}

.streak-badge {
    border-color: var(--color-pink);
    color: var(--color-pink);
}

/* Thanh Tiến Trình */
.progress-container {
    background: var(--color-card-bg);
    border-radius: 20px;
    padding: 12px 18px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    border: 2px solid #fff;
    position: relative;
}

.progress-bar-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-light);
    margin-bottom: 8px;
}

.progress-track {
    height: 16px;
    background: #E6EAF0;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-blue) 0%, var(--color-green) 100%);
    border-radius: 10px;
    width: 0%;
    transition: width 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

/* Hiệu ứng sọc chuyển động trên progress bar */
.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-image: linear-gradient(-45deg,
            rgba(255, 255, 255, .25) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, .25) 50%,
            rgba(255, 255, 255, .25) 75%,
            transparent 75%,
            transparent);
    background-size: 30px 30px;
    animation: move-stripes 2s linear infinite;
}

@keyframes move-stripes {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 30px 0;
    }
}

.star-checkpoints {
    display: flex;
    justify-content: space-between;
    position: absolute;
    width: calc(100% - 36px);
    top: 25px;
    pointer-events: none;
}

.star-node {
    font-size: 1.1rem;
    filter: grayscale(100%) opacity(0.4);
    transition: all 0.3s;
}

.star-node.active {
    filter: grayscale(0%) opacity(1);
    transform: scale(1.2);
    animation: pulse-glow 1.5s infinite alternate;
}

/* Thẻ Phép Toán */
.math-card {
    background: var(--color-card-bg);
    border-radius: 32px;
    padding: 30px 20px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    border: 3px solid #fff;
    text-align: center;
    position: relative;
}

.math-problem {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-size: 4rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.math-num {
    color: var(--color-blue-dark);
    text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.06);
}

.math-operator {
    color: var(--color-pink);
    animation: heartbeat 2s infinite;
}

.math-equal {
    color: var(--color-text);
}

.math-question {
    color: var(--color-purple);
    background: #F1EDFA;
    padding: 0 25px;
    border-radius: 20px;
    border: 4px dashed var(--color-purple);
    font-size: 3.8rem;
    animation: pulse-border 1.5s infinite alternate;
}

.hint-text {
    font-size: 0.95rem;
    color: var(--color-text-light);
    margin-top: 5px;
    margin-bottom: 25px;
    font-weight: 500;
}

/* Khu vực sân chơi đếm vật thể */
.counting-playground {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 24px;
    padding: 20px;
    border: 2px dashed rgba(0, 0, 0, 0.08);
    min-height: 150px;
    margin-bottom: 10px;
}

.item-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 10px;
    width: 42%;
    min-height: 100px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 18px;
}

.playground-operator-sym {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-pink);
    user-select: none;
}

/* Đồ vật để đếm (táo, dâu, sao...) */
.counting-item {
    font-size: 2.2rem;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.counting-item:hover {
    transform: scale(1.15) rotate(5deg);
}

/* Nhãn đếm số 1, 2, 3 nổi lên khi bé nhấn đếm */
.counting-item .count-badge {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: var(--color-purple);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.counting-item.counted .count-badge {
    opacity: 1;
    transform: scale(1);
}

.counting-item.counted {
    animation: bouncePop 0.4s ease forwards;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.count-feedback-text {
    font-size: 0.9rem;
    color: var(--color-purple);
    font-weight: 600;
    margin-top: 10px;
    min-height: 20px;
}

/* Bong bóng Đáp án */
.answers-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.answer-bubble {
    background: #fff;
    border: none;
    border-radius: 50%;
    aspect-ratio: 1;
    font-family: var(--primary-font);
    font-size: 3rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    box-shadow: var(--shadow-3d);
    transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 4px solid #fff;
}

/* Đổ màu ngẫu nhiên bắt mắt cho 4 nút đáp án */
.answers-grid .answer-bubble:nth-child(1) {
    background: var(--color-pink);
    box-shadow: 0 8px 0 var(--color-pink-dark);
}

.answers-grid .answer-bubble:nth-child(2) {
    background: var(--color-blue);
    box-shadow: 0 8px 0 var(--color-blue-dark);
}

.answers-grid .answer-bubble:nth-child(3) {
    background: var(--color-yellow);
    box-shadow: 0 8px 0 var(--color-yellow-dark);
    color: #8F6600;
}

.answers-grid .answer-bubble:nth-child(4) {
    background: var(--color-green);
    box-shadow: 0 8px 0 var(--color-green-dark);
}

.answer-bubble:hover {
    transform: translateY(-6px);
}

.answers-grid .answer-bubble:nth-child(1):hover {
    box-shadow: 0 14px 0 var(--color-pink-dark);
}

.answers-grid .answer-bubble:nth-child(2):hover {
    box-shadow: 0 14px 0 var(--color-blue-dark);
}

.answers-grid .answer-bubble:nth-child(3):hover {
    box-shadow: 0 14px 0 var(--color-yellow-dark);
}

.answers-grid .answer-bubble:nth-child(4):hover {
    box-shadow: 0 14px 0 var(--color-green-dark);
}

.answer-bubble:active {
    transform: translateY(4px);
}

.answers-grid .answer-bubble:nth-child(1):active {
    box-shadow: 0 2px 0 var(--color-pink-dark);
}

.answers-grid .answer-bubble:nth-child(2):active {
    box-shadow: 0 2px 0 var(--color-blue-dark);
}

.answers-grid .answer-bubble:nth-child(3):active {
    box-shadow: 0 2px 0 var(--color-yellow-dark);
}

.answers-grid .answer-bubble:nth-child(4):active {
    box-shadow: 0 2px 0 var(--color-green-dark);
}

/* --- Lớp Feedback khi chọn đúng/sai (đè màn hình) --- */
.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    transition: all 0.3s;
}

.feedback-overlay.correct {
    display: flex;
    background: rgba(78, 202, 135, 0.25);
    animation: fadeIn 0.2s ease;
}

.feedback-overlay.wrong {
    display: flex;
    background: rgba(255, 107, 139, 0.2);
    animation: fadeIn 0.2s ease;
}

.feedback-content {
    background: white;
    border-radius: 32px;
    padding: 35px 50px;
    text-align: center;
    border: 6px solid;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.18);
    transform: scale(0.7);
    animation: popScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.25) forwards;
    max-width: 90%;
    width: 360px;
}

.feedback-overlay.correct .feedback-content {
    border-color: var(--color-green);
}

.feedback-overlay.wrong .feedback-content {
    border-color: var(--color-pink);
}

.feedback-emoji {
    font-size: 4.5rem;
    margin-bottom: 10px;
    animation: bounce 1.2s infinite;
}

.feedback-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.feedback-overlay.correct .feedback-title {
    color: var(--color-green);
}

.feedback-overlay.wrong .feedback-title {
    color: var(--color-pink);
}

.feedback-subtitle {
    font-size: 1.1rem;
    color: var(--color-text-light);
    font-weight: 500;
}

/* --- MÀN HÌNH CHIẾN THẮNG --- */
#victory-screen {
    text-align: center;
}

.trophy-container {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto 20px;
}

.trophy {
    font-size: 8rem;
    animation: float 3s ease-in-out infinite, rotateGold 10s linear infinite;
    filter: drop-shadow(0 10px 15px rgba(230, 181, 59, 0.3));
    position: relative;
    z-index: 2;
}

@keyframes rotateGold {

    0%,
    100% {
        transform: rotate(0deg) scale(1);
    }

    50% {
        transform: rotate(10deg) scale(1.08);
    }
}

.victory-title {
    font-size: 2.3rem;
    color: var(--color-yellow-dark);
    text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.06);
    margin-bottom: 8px;
    animation: pulse-glow 1s infinite alternate;
}

.victory-subtitle {
    font-size: 1.15rem;
    color: var(--color-text);
    margin-bottom: 30px;
    font-weight: 600;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

.victory-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 35px;
}

.v-stat-card {
    background: var(--color-card-bg);
    border: 3px solid #fff;
    border-radius: 20px;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s;
}

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

.v-stat-icon {
    font-size: 2.2rem;
    margin-bottom: 5px;
}

.v-stat-val {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--color-purple);
}

.v-stat-lbl {
    font-size: 0.75rem;
    color: var(--color-text-light);
    font-weight: 600;
    text-align: center;
    margin-top: 3px;
}

.victory-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.secondary-btn {
    background: white;
    border: 3px solid var(--color-pink);
    border-radius: 20px;
    color: var(--color-pink);
    font-size: 1.15rem;
    font-weight: 700;
    padding: 12px 25px;
    cursor: pointer;
    font-family: var(--primary-font);
    transition: all 0.2s;
    box-shadow: 0 4px 0 var(--color-pink);
}

.secondary-btn:hover {
    background: #FFF5F7;
    transform: translateY(-3px);
    box-shadow: 0 7px 0 var(--color-pink);
}

.secondary-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--color-pink);
}

/* Popup khoe thanh tich */
.share-popup {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.share-popup.is-open {
    display: flex;
}

.share-popup__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(74, 74, 74, 0.34);
    backdrop-filter: blur(8px);
}

.share-popup__card {
    position: relative;
    width: min(92vw, 430px);
    background: linear-gradient(180deg, #FFFFFF 0%, #FFF7FB 100%);
    border: 4px solid #fff;
    border-radius: 28px;
    padding: 34px 28px 26px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(103, 110, 144, 0.28), 0 8px 0 rgba(255, 107, 139, 0.22);
    animation: popIn 0.28s cubic-bezier(0.2, 1.35, 0.35, 1) both;
}

.share-popup__close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: #FFF0F4;
    color: var(--color-pink-dark);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    font-family: var(--primary-font);
    font-weight: 700;
    box-shadow: 0 4px 0 rgba(224, 78, 110, 0.18);
}

.share-popup__badge {
    width: 82px;
    height: 82px;
    margin: 0 auto 12px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--color-yellow) 0%, #FFE9A8 100%);
    color: #9A6B00;
    font-size: 3.3rem;
    border: 4px solid #fff;
    box-shadow: 0 10px 0 rgba(230, 181, 59, 0.22), 0 16px 28px rgba(230, 181, 59, 0.26);
    animation: float 2.8s ease-in-out infinite;
}

.share-popup__eyebrow {
    color: var(--color-blue-dark);
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0;
    margin-bottom: 6px;
}

.share-popup__card h2 {
    color: var(--color-pink);
    font-size: 2rem;
    margin-bottom: 12px;
    text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.06);
}

.share-popup__message {
    color: var(--color-text);
    font-size: 1.08rem;
    line-height: 1.55;
    font-weight: 600;
    margin-bottom: 22px;
}

.share-popup__message strong {
    display: inline-block;
    color: var(--color-purple-dark);
    background: #F1EDFA;
    border-radius: 999px;
    padding: 2px 10px;
    margin: 0 2px;
}

.share-popup__ok {
    margin-top: 0;
    font-size: 1.2rem;
    padding: 14px 24px;
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: translateY(18px) scale(0.88);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Canvas Confetti */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    pointer-events: none;
}

/* ==========================================================================
   HOẠT HỌA & HIỆU ỨNG (ANIMATIONS)
   ========================================================================== */

/* Nảy lên liên tục */
@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-12px);
    }
}

/* Nhịp tim đập nhẹ */
@keyframes heartbeat {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }
}

/* Viền nhấp nháy dễ thương */
@keyframes pulse-border {
    0% {
        border-color: var(--color-purple);
        box-shadow: 0 0 5px rgba(155, 93, 229, 0.2);
    }

    100% {
        border-color: var(--color-pink);
        box-shadow: 0 0 20px rgba(255, 107, 139, 0.4);
    }
}

/* Phát sáng chữ / cúp */
@keyframes pulse-glow {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 2px 2px rgba(230, 181, 59, 0.2));
    }

    100% {
        transform: scale(1.03);
        filter: drop-shadow(0 6px 12px rgba(230, 181, 59, 0.5));
    }
}

/* Hiện dần nhẹ nhàng */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Nở rộng phóng to */
@keyframes popScale {
    from {
        transform: scale(0.6);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Hiệu ứng nảy bung của quả táo khi đếm */
@keyframes bouncePop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.35) rotate(-8deg);
    }

    100% {
        transform: scale(1.15) rotate(0deg);
    }
}

/* Lắc nhẹ khi sai câu hỏi */
.wiggle {
    animation: wiggleAnim 0.5s ease;
}

@keyframes wiggleAnim {

    0%,
    100% {
        transform: translateX(0);
    }

    20%,
    60% {
        transform: translateX(-10px);
    }

    40%,
    80% {
        transform: translateX(10px);
    }
}

.pulse {
    animation: heartbeat 2.5s infinite;
}

/* ==========================================================================
   RESPONSIVE DESIGN (CHO CÁC LOẠI MÀN HÌNH: MOBILE, TABLET, DESKTOP)
   ========================================================================== */

/* 1. KHÔNG GIAN DESKTOP / LAPTOP LỚN (> 1024px) */
@media (min-width: 1025px) {
    .app-container {
        max-width: 880px;
        /* Nới rộng container để chứa lưới 2 cột */
    }

    .setup-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    .math-card {
        padding: 40px 30px;
    }

    .counting-playground {
        min-height: 180px;
    }
}

/* 2. KHÔNG GIAN TABLET / IPAD (601px - 1024px) */
@media (min-width: 601px) and (max-width: 1024px) {
    .app-container {
        max-width: 760px;
        width: 92%;
    }

    .setup-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }

    .avatar-btn .emoji {
        font-size: 2.5rem;
    }

    .mode-icon {
        font-size: 2.2rem;
    }

    .math-problem {
        font-size: 3.5rem;
    }
}

/* 3. KHÔNG GIAN DI ĐỘNG NHỎ (MOBILE: <= 600px) */
@media (max-width: 600px) {
    .app-container {
        width: 95%;
        margin: 10px auto;
    }

    .setup-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .section-card {
        padding: 15px;
        margin-bottom: 0px;
        /* Giảm khoảng cách để khít màn hình di động */
        border-radius: 20px;
    }

    .section-card h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    h1 {
        font-size: 2.2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .logo-emoji {
        font-size: 3rem;
    }

    .avatar-selector {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .avatar-btn {
        padding: 8px 4px;
        border-radius: 16px;
    }

    .avatar-btn .emoji {
        font-size: 1.8rem;
    }

    .avatar-btn .name {
        font-size: 0.8rem;
    }

    .mode-selector {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .mode-btn {
        padding: 10px;
        flex-direction: row;
        justify-content: center;
        gap: 10px;
        border-radius: 16px;
    }

    .mode-icon {
        font-size: 1.5rem;
        margin-bottom: 0;
    }

    .mode-desc {
        display: none;
        /* Ẩn mô tả dài trên di động để gọn màn hình */
    }

    .range-selector {
        justify-content: space-between;
    }

    .range-btn {
        padding: 8px 10px;
        font-size: 0.85rem;
        border-radius: 12px;
        flex: 1;
        text-align: center;
        min-width: 70px;
    }

    .custom-range-input-container {
        width: 100%;
        margin-top: 5px;
        justify-content: center;
        border-radius: 12px;
        padding: 5px 10px;
    }

    .item-selector {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .item-btn {
        padding: 8px 4px;
        font-size: 0.85rem;
        border-radius: 12px;
    }

    .math-problem {
        font-size: 2.8rem;
        gap: 8px;
    }

    .math-question {
        font-size: 2.8rem;
        padding: 0 15px;
        border-radius: 14px;
    }

    .counting-playground {
        flex-direction: column;
        gap: 10px;
        padding: 12px;
        min-height: 120px;
    }

    .item-group {
        width: 100%;
        min-height: 60px;
    }

    .playground-operator-sym {
        transform: rotate(90deg);
        /* Dấu cộng xoay dọc khi nằm dọc trên mobile */
        font-size: 1.8rem;
        line-height: 1;
        margin: 2px 0;
    }

    .answers-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .answer-bubble {
        font-size: 3rem;
        box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
        aspect-ratio: auto;
        height: 65px;
        /* Chuyển thành dạng nút viên thuốc tròn dài dễ chạm hơn */
        border-radius: 20px;
    }

    .counting-item {
        font-size: 3rem;
        width: 38px;
        height: 38px;
    }

    .victory-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .v-stat-card {
        flex-direction: row;
        justify-content: flex-start;
        padding: 10px 20px;
        gap: 15px;
    }

    .v-stat-icon {
        font-size: 1.8rem;
        margin-bottom: 0;
    }

    .v-stat-val {
        font-size: 1.5rem;
    }

    .share-popup {
        padding: 16px;
    }

    .share-popup__card {
        padding: 30px 20px 22px;
        border-radius: 24px;
    }

    .share-popup__card h2 {
        font-size: 1.7rem;
    }

    .share-popup__message {
        font-size: 1rem;
    }
}

/* 4. TỐI ƯU CHO DI ĐỘNG SIÊU NHỎ (MÀN HÌNH < 360px - ví dụ iPhone SE/5S) */
@media (max-width: 360px) {
    h1 {
        font-size: 1.8rem;
    }

    .math-problem {
        font-size: 2.2rem;
    }

    .math-question {
        font-size: 2.2rem;
        padding: 0 10px;
    }

    .counting-item {
        font-size: 1.4rem;
        width: 32px;
        height: 32px;
    }
}
