/* --- TOÁN HỌC KỲ THÚ: DESIGN SYSTEM --- */
:root {
    --primary-color: #2ec4b6;     /* Mint/Teal */
    --primary-light: #cbf3f0;
    --secondary-color: #ff9f1c;   /* Orange/Yellow */
    --secondary-light: #ffe5ec;
    --accent-red: #ff3366;        /* Coral Red */
    --accent-purple: #7209b7;
    --sky-blue: #4ea8de;
    --dark-bg: #152238;           /* Deep Midnight Blue */
    --forest-green: #1b4d3e;
    --text-dark: #222222;
    --text-light: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Fredoka', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
}

body {
    background-color: var(--dark-bg);
    color: var(--text-dark);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- GAME CONTAINER --- */
#game-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    height: 100%;
    max-height: 600px;
    background: radial-gradient(circle, #22334a 0%, #0d1622 100%);
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 4px solid #334e68;
    overflow: hidden;
}

/* --- SCREENS CONFIGURATION --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease-in-out;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}

/* --- BUTTONS --- */
.btn-primary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #ff8c00 100%);
    color: var(--text-light);
    border: none;
    padding: 15px 40px;
    font-size: 20px;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(255, 159, 28, 0.4), inset 0 -4px 0 rgba(0,0,0,0.2);
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 20px rgba(255, 159, 28, 0.6), inset 0 -4px 0 rgba(0,0,0,0.2);
}

.btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 4px 8px rgba(255, 159, 28, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-light);
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 10px 25px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 30px;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* --- 1. START SCREEN --- */
#start-screen {
    justify-content: space-between;
    padding: 40px 20px;
    background: linear-gradient(180deg, #101c2c 0%, #1c324e 100%);
}

.logo-container {
    text-align: center;
    margin-top: 10px;
}

.badge {
    background-color: var(--primary-color);
    color: var(--text-light);
    font-size: 14px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 12px;
    letter-spacing: 1px;
    box-shadow: 0 4px 10px rgba(46, 196, 182, 0.3);
}

.logo-container h1 {
    font-size: 42px;
    color: var(--secondary-color);
    text-shadow: 0 4px 8px rgba(0,0,0,0.4);
    letter-spacing: 1px;
}

.logo-container h2 {
    font-size: 28px;
    color: var(--text-light);
    font-weight: 400;
    text-shadow: 0 2px 4px rgba(0,0,0,0.4);
    margin-top: -5px;
}

.concept-preview {
    width: 90%;
    height: 250px;
    background-size: cover;
    background-position: center;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border: 3px solid #4a6b8c;
    position: relative;
    overflow: hidden;
}

.overlay-play {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
}

.footer-info {
    font-size: 14px;
    color: #8da2bb;
}

/* --- 2. INTRO STORY SCREEN --- */
#intro-screen {
    background: #0c1520;
}

.video-wrapper {
    position: relative;
    width: 90%;
    height: 85%;
    background-color: #050a0f;
    border-radius: 20px;
    border: 3px solid #2d4560;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.animation-stage {
    position: relative;
    width: 100%;
    height: 75%;
    overflow: hidden;
    background: linear-gradient(180deg, #87ceeb 0%, #e0f2fe 100%); /* Sky gradient */
}

.animated-bg {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 60px;
    background: linear-gradient(180deg, #228b22 0%, #1e4620 100%);
    border-top: 4px solid #32cd32;
}

/* Cloud Animations */
.cloud {
    position: absolute;
    background: #ffffff;
    border-radius: 100px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: #ffffff;
    border-radius: 50%;
}
.cloud-1 {
    width: 120px;
    height: 40px;
    top: 30px;
    left: -150px;
    animation: flowClouds 35s linear infinite;
}
.cloud-1::before { width: 50px; height: 50px; top: -20px; left: 15px; }
.cloud-1::after { width: 70px; height: 70px; top: -35px; left: 40px; }

.cloud-2 {
    width: 90px;
    height: 30px;
    top: 80px;
    left: -100px;
    animation: flowClouds 20s linear infinite 5s;
    opacity: 0.8;
}
.cloud-2::before { width: 35px; height: 35px; top: -15px; left: 10px; }
.cloud-2::after { width: 50px; height: 50px; top: -25px; left: 30px; }

/* Intro Character Sprites */
.tiger-intro-sprite {
    position: absolute;
    bottom: 40px;
    left: 10%;
    width: 100px;
    height: 100px;
    background-image: url('assets/vespa_boy.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: bottom center;
}

.ancient-tree-sprite {
    position: absolute;
    bottom: 50px;
    right: 15%;
    width: 100px;
    height: 120px;
    background-color: #5c4033;
    border-radius: 15px 15px 0 0;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
.ancient-tree-sprite::before {
    content: '🍂';
    font-size: 60px;
    position: absolute;
    top: -40px;
    left: 20px;
}
.ancient-tree-sprite::after {
    content: '👁️👁️';
    font-size: 24px;
    position: absolute;
    top: 30px;
    left: 25px;
}

.subtitle-box {
    height: 15%;
    background-color: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 20px;
    border-top: 2px solid #2d4560;
}

.subtitle-box p {
    color: var(--text-light);
    font-size: 18px;
    text-align: center;
    font-weight: 400;
    letter-spacing: 0.5px;
}

.control-bar {
    position: absolute;
    bottom: 80px;
    right: 20px;
    z-index: 30;
    display: flex;
    gap: 10px;
}

/* --- 3. GAME SCREEN --- */
#game-screen {
    background: linear-gradient(rgba(13, 22, 34, 0.82), rgba(13, 22, 34, 0.88)), url('assets/concept.png');
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
}

/* HUD styles */
.hud {
    position: absolute;
    top: 15px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding: 0 20px;
    z-index: 40;
}

.hud-item {
    background: rgba(15, 23, 42, 0.75);
    border: 2px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    padding: 8px 20px;
    border-radius: 20px;
    color: var(--text-light);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
}

.hud-item .label {
    color: #94a3b8;
    font-size: 12px;
}

#hearts-list {
    letter-spacing: 3px;
    font-size: 18px;
}

#score-val {
    color: var(--secondary-color);
    font-size: 20px;
}

/* Street Decorations */
.street-decor {
    position: absolute;
    color: var(--text-light);
    font-weight: 700;
    z-index: 5;
    pointer-events: none;
}

.signpost {
    top: 90px;
    left: 45px;
    background: rgba(15, 23, 42, 0.85);
    border: 2px solid var(--secondary-color);
    padding: 10px 20px;
    border-radius: 15px;
    font-size: 16px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    animation: float-decor 3s ease-in-out infinite;
}

.streetlight {
    font-size: 36px;
    filter: drop-shadow(0 0 15px #ffd700);
    animation: glow-pulse 2s infinite alternate;
}

.streetlight.left {
    bottom: 120px;
    left: 70px;
}

.streetlight.right {
    top: 110px;
    right: 80px;
}

@keyframes float-decor {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes glow-pulse {
    from { filter: drop-shadow(0 0 10px #ffd700); opacity: 0.8; }
    to { filter: drop-shadow(0 0 25px #ffd700); opacity: 1; }
}

/* Exhaust smoke particle animation */
.smoke-particle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 50%;
    pointer-events: none;
    transform-style: preserve-3d;
    transform: rotateZ(45deg) rotateX(-60deg);
    animation: drift-fade 1.2s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
    z-index: 45;
}

@keyframes drift-fade {
    0% {
        transform: rotateZ(45deg) rotateX(-60deg) translate3d(0, 0, 0) scale(1);
        opacity: 0.6;
    }
    100% {
        transform: rotateZ(45deg) rotateX(-60deg) translate3d(-35px, 20px, 25px) scale(2.8);
        opacity: 0;
        filter: blur(3px);
    }
}

/* Floating golden sunset motes */
.light-mote {
    position: absolute;
    background: radial-gradient(circle, rgba(255, 200, 0, 0.45) 0%, rgba(255, 200, 0, 0) 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 15;
}

@keyframes float-mote {
    0% {
        transform: translateY(100px) translateX(0) scale(1);
        opacity: 0;
    }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% {
        transform: translateY(-600px) translateX(60px) scale(1.6);
        opacity: 0;
    }
}

/* Isometric board design */
.board-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 50px;
}

.isometric-grid {
    position: relative;
    width: 500px;
    height: 350px;
    transform: rotateX(60deg) rotateZ(-45deg);
    transform-style: preserve-3d;
}

/* Path Stone Tiles */
.tile {
    position: absolute;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.06) 100%);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 16px;
    backdrop-filter: blur(5px);
    transform-style: preserve-3d;
    box-shadow: -1px 1px 0px rgba(255,255,255,0.15),
                -2px 2px 0px rgba(255,255,255,0.15),
                -3px 3px 0px rgba(255,255,255,0.15),
                -4px 4px 15px rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tile:hover {
    transform: translate3d(5px, -5px, 10px);
}

/* Active next step tile - mint glow */
.tile:not(.completed):not(.locked) {
    background: linear-gradient(135deg, rgba(46, 196, 182, 0.3) 0%, rgba(46, 196, 182, 0.1) 100%);
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 15px var(--primary-color),
                -1px 1px 0px var(--primary-color),
                -2px 2px 0px var(--primary-color),
                -3px 3px 15px rgba(46, 196, 182, 0.4);
    animation: tile-glow 1.5s infinite alternate;
}

@keyframes tile-glow {
    from { box-shadow: 0 0 8px var(--primary-color), -3px 3px 10px rgba(46, 196, 182, 0.3); }
    to { box-shadow: 0 0 22px var(--primary-color), -3px 3px 20px rgba(46, 196, 182, 0.7); }
}

.tile.completed {
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.4) 0%, rgba(72, 187, 120, 0.2) 100%);
    border: 2px solid #48bb78;
    box-shadow: 0 0 12px #48bb78,
                -1px 1px 0px #2f855a,
                -2px 2px 0px #2f855a,
                -3px 3px 10px rgba(72, 187, 120, 0.3);
}

.tile.locked {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, rgba(0, 0, 0, 0.25) 100%);
    border: 2px solid rgba(255, 255, 255, 0.06);
    cursor: not-allowed;
    opacity: 0.35;
    box-shadow: none;
}
.tile.locked:hover {
    transform: none;
    box-shadow: none;
}

.tile-content {
    transform: rotateZ(45deg) rotateX(-60deg) scale(1.3);
    color: var(--text-light);
    font-size: 22px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
}

.tile.completed .tile-content {
    color: #1a5c37;
}

/* Game Character on Grid */
.player-sprite {
    position: absolute;
    width: 80px;
    height: 80px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: bottom center;
    transform: rotateZ(45deg) rotateX(-60deg) translate3d(0, -50px, 50px);
    transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 50;
    pointer-events: none;
}
.player-sprite::after {
    content: '';
    position: absolute;
    bottom: 5px;
    left: 15px;
    width: 50px;
    height: 15px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    filter: blur(3px);
    transform: rotateX(60deg);
    z-index: -1;
}

.guide-banner {
    position: absolute;
    bottom: 15px;
    background-color: rgba(27, 77, 62, 0.9);
    border: 2px solid #2d6a4f;
    color: var(--text-light);
    padding: 8px 24px;
    border-radius: 20px;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* --- 4. QUESTION POPUP (MODAL) --- */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 20, 30, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--glass-bg);
    border: 3px solid var(--glass-border);
    border-radius: 24px;
    width: 90%;
    max-width: 500px;
    padding: 30px;
    box-shadow: var(--shadow);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.timer-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background-color: #e2e8f0;
}

#timer-progress {
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    transition: width 1s linear;
}

.modal-header h3 {
    font-size: 22px;
    color: var(--forest-green);
    margin-top: 10px;
    margin-bottom: 20px;
}

.question-box {
    background: linear-gradient(135deg, #eef2f3 0%, #8e9eab 100%);
    border: 2px solid #cbd5e1;
    border-radius: 16px;
    padding: 30px 15px;
    margin-bottom: 25px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

#question-text {
    font-size: 22px;
    line-height: 1.5;
    font-weight: 600;
    color: #2c3e50;
    text-shadow: 0 1px 1px rgba(255,255,255,0.8);
    white-space: pre-line;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.option-btn {
    background-color: #ffffff;
    border: 2px solid #cbd5e1;
    border-radius: 16px;
    padding: 15px 10px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

.option-btn:hover {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(46, 196, 182, 0.15);
}

.option-btn:active {
    transform: translateY(0);
}

.option-btn.correct {
    background-color: #c6f6d5 !important;
    border-color: #38a169 !important;
    color: #22543d !important;
}

.option-btn.wrong {
    background-color: #fed7d7 !important;
    border-color: #e53e3e !important;
    color: #742a2a !important;
}

/* --- 5. RESULT SCREENS --- */
#victory-screen {
    background: radial-gradient(circle, #1a2a6c 0%, #270b36 100%);
}

#defeat-screen {
    background: radial-gradient(circle, #3d0c11 0%, #150507 100%);
}

.result-card {
    background: var(--glass-bg);
    border: 3px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    max-width: 450px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.result-card h2 {
    font-size: 32px;
    color: var(--secondary-color);
    margin-top: 15px;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.result-card.error-theme h2 {
    color: var(--accent-red);
}

.result-card p {
    color: #4a5568;
    font-size: 16px;
    margin-bottom: 25px;
}

.score-summary {
    background: #edf2f7;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 30px;
}

.score-summary div {
    font-size: 20px;
    color: #2d3748;
}

.score-summary div strong {
    font-size: 28px;
    color: var(--secondary-color);
}

.stars {
    font-size: 32px;
    margin-top: 10px;
    letter-spacing: 5px;
    animation: bounce 1s infinite alternate;
}

.trophy-emitter {
    font-size: 70px;
    animation: pulse 1.5s infinite;
}

.emoji-sad {
    font-size: 70px;
    animation: headShake 2s infinite;
}

/* --- SOUND CONTROL --- */
#sound-control {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 1000;
}

#sound-control button {
    background: rgba(15, 23, 42, 0.8);
    border: 2px solid #334155;
    color: var(--text-light);
    font-size: 20px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
}

#sound-control button:hover {
    transform: scale(1.1);
    background: #1e293b;
}

#sound-control.sound-off button {
    opacity: 0.6;
}
#sound-control.sound-off button::after {
    content: '/';
    position: absolute;
    font-size: 28px;
    color: var(--accent-red);
    font-weight: 700;
}

/* --- PARTICLE ANIMATION ELEMENT --- */
.particle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 99;
    animation: particleFly 1s ease-out forwards;
}

/* --- KEYFRAME ANIMATIONS --- */
@keyframes flowClouds {
    0% { left: -150px; }
    100% { left: 100%; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes bounce-idle {
    0% { transform: translateY(0); }
    100% { transform: translateY(-10px); }
}
.bounce-idle {
    animation: bounce-idle 0.8s infinite alternate cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes float-idle {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}
.float-idle {
    animation: float-idle 1.5s infinite alternate ease-in-out;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-8px); }
}

@keyframes headShake {
    0% { transform: rotate(0deg); }
    12.5% { transform: rotate(-6deg); }
    37.5% { transform: rotate(5deg); }
    62.5% { transform: rotate(-3deg); }
    87.5% { transform: rotate(2deg); }
    100% { transform: rotate(0deg); }
}

/* Scale-in for modal contents */
.scale-in {
    animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes scaleIn {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Shake animation for errors */
.shake {
    animation: shake 0.4s ease-in-out;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* Particle animation */
@keyframes particleFly {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
