/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Bradley Hand', 'Segoe Print', 'Trebuchet MS', Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

#gameContainer {
    width: 90%;
    max-width: 800px;
    min-height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    padding: 20px 40px;
    text-align: center;
    height: 100%;
    min-height: 600px;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 30px;
}

.screen.active {
    display: flex;
}

/* Start Screen */
#startScreen {
    justify-content: flex-start;
    padding-top: 20px;
    gap: 25px;
}

#startScreen h1 {
    font-size: 3.5em;
    color: #4a90e2;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

#startScreen h2 {
    font-size: 2em;
    color: #666;
    margin-bottom: 15px;
}

#startScreen p {
    font-size: 1.5em;
    color: #888;
    margin-bottom: 20px;
}

/* Buttons */
.big-button {
    font-family: inherit;
    font-size: 1.8em;
    font-weight: bold;
    padding: 20px 40px;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-button {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    color: white;
}

.start-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.next-button {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    margin-top: 30px;
}

.next-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

/* Game Screen */
#gameScreen {
    justify-content: space-between;
    padding-top: 20px;
    padding-bottom: 60px;
}

#gameHeader {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 20px;
}

#progressContainer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #f9f9f9;
    border-radius: 15px;
    border: 2px solid #ddd;
    gap: 20px;
    width: 100%;
    max-width: 700px;
}

#progressIcons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    flex-shrink: 1;
    min-width: 0;
}

.progress-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.progress-icon {
    font-size: 1.8em;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e0e0e0;
    color: #999;
    transition: all 0.3s ease;
    position: relative;
}

.progress-icon.current {
    background: #4a90e2;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

.progress-icon.gold {
    background: #ffd700;
    color: #b8860b;
    transform: scale(1.05);
}

.progress-icon.silver {
    background: #c0c0c0;
    color: #696969;
    transform: scale(1.05);
}

.progress-icon.wrong {
    background: #ff6b6b;
    color: white;
    transform: scale(1.05);
}

#scoreDisplay {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex-shrink: 0;
}

.score-label {
    font-size: 1.1em;
    font-weight: bold;
    color: #666;
    margin-bottom: 2px;
}

.score-number {
    font-size: 2em;
    font-weight: bold;
    color: #4a90e2;
    line-height: 1;
}

/* Problem Display */
#problemDisplay {
    margin-bottom: 25px;
    margin-top: 15px;
    text-align: center;
}

#mathProblem {
    font-size: 3.5em;
    font-weight: bold;
    color: #333;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    padding: 20px 30px;
    background: #f9f9f9;
    border-radius: 15px;
    border: 3px solid #ddd;
    display: inline-block;
    min-width: 280px;
}

/* Answer Buttons */
#answersContainer {
    display: grid;
    grid-template-columns: repeat(4, 130px);
    grid-template-rows: repeat(3, 70px);
    gap: 12px;
    justify-content: center;
    margin-bottom: 25px;
    margin-left: auto;
    margin-right: auto;
    contain: layout style;
}

.answer-button {
    font-family: inherit;
    font-size: 2.1em;
    font-weight: bold;
    padding: 0;
    border: 3px solid #4a90e2;
    border-radius: 12px;
    background: white;
    color: #4a90e2;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.3s ease;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
    width: 130px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout style;
    font-variant-numeric: tabular-nums;
}

.answer-button:hover {
    background: #4a90e2;
    color: white;
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.answer-button.correct {
    background: #4caf50;
    color: white;
    border-color: #4caf50;
    animation: correctPulse 0.6s ease;
}

.answer-button.wrong {
    background: #f44336;
    color: white;
    border-color: #f44336;
    animation: wrongShake 0.6s ease;
    position: relative;
    overflow: hidden;
}

.answer-button.wrong::after {
    content: '✗';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5em;
    color: white;
    animation: cancelOut 0.6s ease;
}

.answer-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Feedback Area */
#feedbackArea {
    height: 0px;
    overflow: hidden;
}

/* Feedback Overlay */
#feedbackOverlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: auto;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

#feedbackOverlay.show {
    opacity: 1;
}

#feedbackOverlay.fade-out {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1s ease-out, transform 1s ease-out;
}

#feedbackMessage {
    font-size: 1.4em;
    font-weight: bold;
    padding: 12px 20px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 700px;
    min-height: 90px;
    line-height: 1.2;
}

#feedbackMessage.success {
    color: #4caf50;
    background: rgba(232, 245, 232, 0.95);
    border: 2px solid #4caf50;
}

#feedbackMessage.try-again {
    color: #ff9800;
    background: rgba(255, 243, 224, 0.95);
    border: 2px solid #ff9800;
}

#feedbackMessage.correct-second {
    color: #2196f3;
    background: rgba(227, 242, 253, 0.95);
    border: 2px solid #2196f3;
}


/* End Screen */
#endScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#endTitle {
    font-size: 3em;
    margin-bottom: 40px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#finalResults {
    margin-bottom: 50px;
}

#starRating {
    font-size: 4em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#finalScore {
    font-size: 2.5em;
    font-weight: bold;
    margin-bottom: 20px;
}

#finalMessage {
    font-size: 1.5em;
    margin-bottom: 30px;
    opacity: 0.9;
}

.badge {
    display: inline-block;
    font-size: 1.8em;
    padding: 20px 30px;
    background: gold;
    color: #333;
    border-radius: 50px;
    border: 3px solid #fff;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    animation: badgeBounce 1s ease infinite alternate;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Quit Button - Bottom Position */
.quit-button-bottom {
    background: rgba(0, 0, 0, 0.1);
    border: 2px solid #999;
    color: #666;
    font-family: inherit;
    font-size: 1.1em;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.quit-button-bottom:hover {
    background: rgba(0, 0, 0, 0.2);
    border-color: #666;
    color: #333;
    transform: translateY(-1px);
}

/* Motivational Message Fade Out - Using transitions instead of animations */

/* Animations */
@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

@keyframes cancelOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes badgeBounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-10px); }
}

@keyframes fadeOut {
    0% { 
        opacity: 1; 
        transform: translateY(0); 
    }
    100% { 
        opacity: 0; 
        transform: translateY(10px); 
    }
}

/* Confetti */
#confettiContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #ff6b6b;
    animation: confettiFall 3s linear forwards;
}

.confetti:nth-child(2n) { background: #4ecdc4; }
.confetti:nth-child(3n) { background: #ffe66d; }
.confetti:nth-child(4n) { background: #ff6b6b; }
.confetti:nth-child(5n) { background: #a8e6cf; }

@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    /* BULLETPROOF mobile font override - targets everything aggressively */
    *, *::before, *::after,
    body, html,
    h1, h2, h3, h4, h5, h6,
    p, span, div, a, button,
    .screen, .big-button, .answer-button, .quit-button-bottom,
    #startScreen, #gameScreen, #endScreen,
    #mathProblem, #feedbackMessage, #finalMessage,
    .progress-icon, .score-label, .score-number,
    .badge, .confetti {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    }
    
    #gameContainer {
        width: 95%;
        min-height: 500px;
    }
    
    .screen {
        padding: 20px;
        min-height: 500px;
    }
    
    #startScreen h1 {
        font-size: 2.5em;
    }
    
    #mathProblem {
        font-size: 2.8em;
        min-width: 240px;
        padding: 15px 20px;
    }
    
    #answersContainer {
        grid-template-columns: repeat(4, 110px);
        grid-template-rows: repeat(3, 55px);
        gap: 8px;
    }
    
    .answer-button {
        width: 110px;
        height: 55px;
        font-size: 1.7em;
        padding: 0;
        border-width: 2px;
    }
    
    #scoreDisplay {
        font-size: 1.2em;
        padding: 8px 15px;
        margin: 12px auto 15px auto;
    }
    
    #feedbackArea {
        height: 0px;
    }
    
    #feedbackOverlay {
        top: 15px;
        left: 15px;
        right: 15px;
        height: auto;
    }
    
    #feedbackMessage {
        font-size: 1.2em;
        min-height: 70px;
        max-width: 95%;
        padding: 12px 15px;
    }
    
    #progressContainer {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        max-width: 95%;
    }
    
    #scoreDisplay {
        order: -1;
        margin-bottom: 5px;
    }
    
    .score-label {
        font-size: 1em;
    }
    
    .score-number {
        font-size: 1.8em;
    }
    
    #progressIcons {
        width: 100%;
    }
}

/* NUCLEAR OPTION: Catch-all mobile font override with maximum specificity */
@media (max-width: 768px) {
    /* This overrides EVERYTHING on mobile devices - no exceptions! */
    html *, html *::before, html *::after,
    body *, body *::before, body *::after {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    }
}