:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(15, 23, 42, 0.6);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #8b5cf6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --lava-color: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
}

body {
    margin: 0;
    font-family: 'Outfit', 'Inter', sans-serif;
    background: radial-gradient(circle at top right, #1e1b4b, #020617);
    color: var(--text-main);
    overflow: hidden; 
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Dynamic background elements for premium feel */
body::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(59,130,246,0.1) 0%, transparent 60%);
    animation: rotateBg 30s linear infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes rotateBg {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header / Stats Bar */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 100;
    position: relative;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.stats-container {
    display: flex;
    gap: 20px;
    align-items: center;
}

.stat-box {
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    padding: 10px 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
}

.stat-box span { color: #38bdf8; text-shadow: 0 0 10px rgba(56,189,248,0.5); }

.avatar-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background: rgba(0,0,0,0.5);
    border-radius: 5px;
    margin-top: 5px;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--primary));
    transition: width 0.4s ease-out;
}

#player-avatar {
    width: 70px;
    height: 70px;
    background: radial-gradient(circle, rgba(255,255,255,0.2), rgba(0,0,0,0.5));
    border-radius: 50%;
    border: 3px solid var(--primary);
    padding: 5px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 0 20px rgba(59,130,246,0.4);
}
#player-avatar:hover {
    transform: scale(1.15) rotate(10deg);
}

/* Main Game Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 5;
    padding: 20px;
}

.game-card {
    background: var(--bg-card);
    backdrop-filter: blur(24px);
    border-radius: 30px;
    padding: 50px;
    width: 100%;
    max-width: 700px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255,255,255,0.1);
    transition: all 0.3s ease;
    margin-bottom: auto;
    margin-top: 50px;
}

.challenge-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.challenge-content {
    font-size: 4rem;
    font-weight: 900;
    margin: 40px 0;
    letter-spacing: 3px;
    text-shadow: 0 10px 20px rgba(0,0,0,0.3);
}

/* Typing Highlight */
.typed-correct { color: var(--success); text-shadow: 0 0 10px rgba(16,185,129,0.5); }
.typed-wrong { color: #f87171; text-decoration: underline; text-decoration-thickness: 4px; }

.input-area { margin-top: 30px; }

input[type="text"], input[type="number"] {
    width: 85%;
    padding: 20px 30px;
    font-size: 2rem;
    border-radius: 20px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    text-align: center;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.4), inset 0 2px 10px rgba(0,0,0,0.5);
    transform: scale(1.02);
}

/* Advanced Floor is Lava Effect */
.lava-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    transform: translateY(100%);
    background: linear-gradient(to top, #7f1d1d 0%, #ef4444 80%, #fca5a5 100%);
    opacity: 0.4;
    z-index: 8;
    box-shadow: 0 -20px 50px rgba(239, 68, 68, 0.6);
    pointer-events: none;
    transition: transform 0.1s linear;
}

.lava-wave {
    position: absolute;
    top: -148px;
    left: 0;
    width: 200%;
    height: 150px;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 1440 320' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23fca5a5' fill-opacity='0.5' d='M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E") repeat-x;
    background-size: 50% 100%;
    animation: wave 4s infinite linear;
}

.lava-wave::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 0;
    width: 200%;
    height: 150px;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 1440 320' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23ef4444' fill-opacity='0.4' d='M0,128L48,144C96,160,192,192,288,181.3C384,171,480,117,576,128C672,139,768,213,864,224C960,235,1056,181,1152,149.3C1248,117,1344,107,1392,101.3L1440,96L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E") repeat-x;
    background-size: 50% 100%;
    animation: wave 6s infinite linear reverse;
}

@keyframes wave {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* Dancing Dog Animation */
.dog-container {
    position: absolute;
    bottom: 20px;
    left: -300px;
    width: 100px;
    height: 100px;
    z-index: 20;
    pointer-events: none;
    transition: left 6s linear; /* Slower, steady movement */
}

.dog-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.6));
    animation: boundCycle 0.4s infinite alternate cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: bottom center;
}

/* Squash and stretch bounding run effect */
@keyframes boundCycle {
    0% { transform: translateY(0) scaleY(0.85) scaleX(1.15) rotate(5deg); }
    100% { transform: translateY(-50px) scaleY(1.1) scaleX(0.95) rotate(-5deg); }
}

.dance-active {
    left: 120%;
}

/* Utilities */
.hidden { display: none !important; opacity: 0; pointer-events: none; }

/* Menu overlay */
.menu-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(15px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

.menu-overlay h1 {
    font-size: 4rem;
    margin-bottom: 50px;
    background: linear-gradient(to right, #4facfe, #00f2fe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(0,242,254,0.3);
}

.menu-btn {
    padding: 20px 50px;
    margin: 15px;
    font-size: 1.5rem;
    font-weight: 800;
    border: none;
    border-radius: 40px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.4), inset 0 2px 0 rgba(255,255,255,0.2);
    text-transform: uppercase;
    letter-spacing: 2px;
}
.menu-btn:hover {
    transform: scale(1.08) translateY(-5px);
    box-shadow: 0 15px 30px rgba(37, 99, 235, 0.6), inset 0 2px 0 rgba(255,255,255,0.2);
}
.menu-btn.typing { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 10px 20px rgba(139, 92, 246, 0.4), inset 0 2px 0 rgba(255,255,255,0.2); }
.menu-btn.typing:hover { box-shadow: 0 15px 30px rgba(139, 92, 246, 0.6), inset 0 2px 0 rgba(255,255,255,0.2); }
/* ADD TO BOTTOM OF style.css */

/* Mobile Math Numpad */
.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.numpad-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    color: white;
    font-size: 1.8rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    padding: 15px 0;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.numpad-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
}
.numpad-btn.control {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.5);
}
.numpad-btn.control:active {
    background: rgba(59, 130, 246, 0.6);
}

/* Responsive CSS for Mobile */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }
    
    .stats-container {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .game-card {
        padding: 20px;
        margin: 0 10px;
        width: calc(100% - 20px);
        box-sizing: border-box;
    }
    
    .challenge-title {
        font-size: 1.5rem;
    }
    
    .challenge-content {
        font-size: 2.5rem;
        margin: 20px 0;
    }
    
    .menu-overlay h1 {
        font-size: 2.5rem;
        text-align: center;
    }
    
    .mode-card {
        width: 40% !important;
        padding: 10px !important;
    }
    
    .map-container {
        height: 40vh;
    }

    #keyboard-container {
        display: none !important; /* Hide typing keyboard on narrow screens */
    }
}

/* Mobile Fix for Short Screens */
@media (max-height: 850px) {
    main {
        justify-content: flex-start;
        padding-top: 10px;
    }
    
    .game-card {
        padding: 15px;
    }
    
    .challenge-title {
        font-size: 1.1rem;
        margin-bottom: 5px;
    }
    
    .challenge-content {
        font-size: 2rem;
        margin: 5px 0;
    }
    
    .numpad-grid {
        margin-top: 5px;
        gap: 5px;
    }
    
    .numpad-btn {
        padding: 10px 0;
        font-size: 1.5rem;
    }
    
    input[type="text"], input[type="number"] {
        padding: 10px;
        font-size: 1.5rem;
    }
    
    #help-btn {
        padding: 10px 15px;
        font-size: 1rem;
        bottom: 10px;
        left: 10px;
    }
}

/* Ultra-compact header for mobile */
@media (max-width: 768px) {
    header {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        padding: 5px !important;
        gap: 5px !important;
        justify-content: center !important;
    }
    
    #global-avatar-img {
        width: 40px !important;
        height: 40px !important;
    }
    
    .stats-container {
        width: auto !important;
        gap: 5px !important;
    }
    
    .menu-btn {
        padding: 5px 10px !important;
        margin: 2px !important;
        font-size: 0.9rem !important;
    }
    
    .stat-box {
        padding: 5px 10px !important;
        font-size: 0.9rem !important;
    }
    
    /* Shrink the XP text */
    header span {
        font-size: 0.9rem !important;
    }
    header .progress-bar-container {
        height: 8px !important;
    }
}

/* Make game card scrollable on mobile */
@media (max-width: 768px) {
    .game-card {
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }
}

/* Premium scrollbar for the game card */
.game-card::-webkit-scrollbar {
    width: 6px;
}
.game-card::-webkit-scrollbar-track {
    background: transparent;
}
.game-card::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}
.game-card::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}
