/* Style Buddy Math Quest CSS Rules */

:root {
    --primary: #BFDBFE;
    --primary-dark: #2563EB;
    --primary-hover: #1D4ED8;
    --background: #EFF6FF;
    --card: #FFFFFF;
    --text: #1E3A5F;
    --muted: #64748B;
    --success: #22C55E;
    --danger: #EF4444;
    --warning: #F59E0B;
    --border: #DBEAFE;
    
    --shadow-sm: 0 4px 6px -1px rgba(30, 58, 95, 0.05), 0 2px 4px -1px rgba(30, 58, 95, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(30, 58, 95, 0.07), 0 4px 6px -2px rgba(30, 58, 95, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(30, 58, 95, 0.1), 0 10px 10px -5px rgba(30, 58, 95, 0.04);
}

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

body {
    font-family: "Nunito", sans-serif;
    background-color: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 700px; /* Centered, solid desktop max width */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Utility Styles */
.text-center {
    text-align: center;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Emojis */
.buddy-emoji {
    font-size: 5rem;
    display: block;
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}

/* Card Design */
.card {
    background-color: var(--card);
    border: 6px solid var(--border);
    border-radius: 32px;
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    animation: slideIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Titles and Headers */
.main-title {
    font-size: 2.25rem;
    font-weight: 900;
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.welcome-banner h2 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-top: 1rem;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 1.25rem;
    color: var(--muted);
    font-weight: 600;
}

/* Instructions Box */
.instructions-box {
    background-color: var(--background);
    border-radius: 20px;
    padding: 1.5rem;
    margin: 2rem 0;
    border: 3px dashed var(--primary);
    font-size: 1.1rem;
    line-height: 1.6;
}

.instructions-box p {
    margin-bottom: 1rem;
    color: var(--text);
}

.rules-list {
    list-style: none;
    text-align: left;
    display: inline-block;
    margin: 0 auto;
}

.rules-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.rules-list li strong {
    font-weight: 800;
}

/* Badges */
.best-score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #FEF3C7;
    border: 3px solid #FCD34D;
    color: #92400E;
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    font-size: 1.2rem;
    font-weight: 800;
    margin: 0.5rem auto;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    font-family: "Nunito", sans-serif;
    font-weight: 800;
    font-size: 1.25rem;
    padding: 1rem 2rem;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 6px 0 var(--border);
    position: relative;
    top: 0;
    width: 100%;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--border);
}

.btn-primary {
    background-color: var(--primary-dark);
    color: white;
    box-shadow: 0 6px 0 #1D4ED8;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-primary:active {
    box-shadow: 0 2px 0 #1D4ED8;
}

.btn-secondary {
    background-color: #E2E8F0;
    color: #475569;
    box-shadow: 0 6px 0 #CBD5E1;
}

.btn-secondary:hover {
    background-color: #CBD5E1;
}

.btn-secondary:active {
    box-shadow: 0 2px 0 #CBD5E1;
}

.btn-submit {
    background-color: var(--success);
    color: white;
    box-shadow: 0 6px 0 #16A34A;
}

.btn-submit:hover {
    background-color: #15803D;
}

.btn-submit:active {
    box-shadow: 0 2px 0 #16A34A;
}

.btn-large {
    font-size: 1.4rem;
    padding: 1.25rem 2.5rem;
}

/* Quiz Screen Styles */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.progress-details {
    flex-grow: 1;
    font-weight: 800;
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-track {
    background-color: var(--border);
    height: 14px;
    border-radius: 99px;
    width: 100%;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(30, 58, 95, 0.05);
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-dark);
    border-radius: 99px;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-badge {
    background-color: #FEF3C7;
    border: 3px solid #FCD34D;
    color: #92400E;
    padding: 0.5rem 1.25rem;
    border-radius: 99px;
    font-size: 1.1rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    animation: popScore 0.3s ease;
}

/* Question Area */
.question-container {
    margin: 2.5rem 0;
    background-color: var(--background);
    border: 4px solid var(--border);
    border-radius: 24px;
    padding: 2.5rem 1.5rem;
}

.question-intro {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

.question-equation {
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--text);
    letter-spacing: 2px;
    text-shadow: 0 4px 0 rgba(191, 219, 254, 0.3);
}

/* Answer Controls */
.answer-box {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2.5rem;
}

#answer-input {
    width: 100%;
    padding: 1.2rem;
    border: 4px solid var(--border);
    border-radius: 20px;
    font-family: "Nunito", sans-serif;
    font-size: 2rem;
    font-weight: 900;
    text-align: center;
    color: var(--text);
    background-color: #FFFFFF;
    outline: none;
    transition: all 0.2s ease;
}

#answer-input:focus {
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 6px var(--primary);
}

/* Timer styles */
.timer-container {
    margin-top: 2rem;
    border-top: 3px solid var(--border);
    padding-top: 1.5rem;
}

.timer-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
}

.timer-countdown {
    font-size: 1.5rem;
    color: var(--text);
    font-weight: 900;
    transition: color 0.3s ease;
}

.timer-track {
    background-color: var(--border);
    height: 12px;
    border-radius: 99px;
    width: 100%;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    background-color: var(--primary-dark);
    border-radius: 99px;
    width: 100%;
    transition: width 1s linear, background-color 0.3s ease;
}

/* Dynamic Timer Colors */
.timer-warning-color {
    background-color: var(--warning) !important;
}

.timer-danger-color {
    background-color: var(--danger) !important;
}

.text-danger {
    color: var(--danger) !important;
}

/* Animations for timer */
.timer-shake {
    animation: timerPulseShake 0.5s infinite alternate;
}

/* Feedback Overlay */
.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(30, 58, 95, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    animation: fadeIn 0.25s forwards ease-out;
}

.feedback-card {
    background-color: var(--card);
    border-radius: 32px;
    padding: 3rem 2.5rem;
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.85);
    animation: popIn 0.35s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feedback-card-correct {
    border: 8px solid var(--success);
}

.feedback-card-wrong {
    border: 8px solid var(--danger);
    animation: shakeCard 0.4s cubic-bezier(.36,.07,.19,.97) both, popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feedback-card-timeout {
    border: 8px solid var(--warning);
}

.feedback-emoji {
    font-size: 5rem;
    margin-bottom: 1.5rem;
    display: block;
}

.feedback-title {
    font-size: 2.25rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
}

.success-text { color: var(--success); }
.danger-text { color: var(--danger); }
.warning-text { color: var(--warning); }

.feedback-msg-title {
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.feedback-msg {
    font-size: 1.1rem;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.points-earned, .points-lost {
    display: inline-block;
    padding: 0.75rem 1.75rem;
    border-radius: 99px;
    font-size: 1.25rem;
    font-weight: 800;
    animation: bounce 1s infinite alternate;
}

.success-badge {
    background-color: #DCFCE7;
    border: 3px solid #86EFAC;
    color: #166534;
}

.danger-badge {
    background-color: #FEE2E2;
    border: 3px solid #FCA5A5;
    color: #991B1B;
}

/* Result Screen Styles */
.completion-subtitle {
    font-size: 1.15rem;
    color: var(--muted);
    font-weight: 600;
    margin-top: 0.5rem;
    line-height: 1.5;
}

.new-high-score-badge {
    background: linear-gradient(135deg, #FEF08A, #FDE047);
    border: 4px solid #FACC15;
    border-radius: 20px;
    padding: 1.25rem;
    margin: 1.5rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    animation: bouncePulse 1s infinite alternate;
}

.new-high-score-badge h3 {
    font-weight: 900;
    color: #854D0E;
    font-size: 1.25rem;
    margin-bottom: 0.2rem;
}

.new-high-score-badge p {
    color: #A16207;
    font-weight: 700;
    font-size: 1rem;
}

.celebrate-emoji {
    font-size: 2.5rem;
}

.result-summary {
    margin: 2rem 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.score-card {
    background-color: var(--background);
    border: 4px solid var(--border);
    border-radius: 24px;
    padding: 1.75rem;
}

.score-card-label {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--muted);
    letter-spacing: 1px;
}

.score-ratio {
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--primary-dark);
    margin: 0.5rem 0;
}

.percentage-badge {
    display: inline-block;
    background-color: var(--primary-dark);
    color: white;
    padding: 0.4rem 1.25rem;
    border-radius: 99px;
    font-weight: 800;
    font-size: 1.1rem;
}

/* Learning Stats Table/Grid */
.stats-box {
    text-align: left;
}

.stats-title {
    font-weight: 900;
    font-size: 1.25rem;
    color: var(--text);
    margin-bottom: 1rem;
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.stats-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.5rem;
    border-radius: 18px;
    text-align: center;
    border: 3px solid transparent;
}

.stats-emoji {
    font-size: 1.75rem;
    margin-bottom: 0.35rem;
}

.stats-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.stats-val {
    font-size: 1.35rem;
    font-weight: 900;
    color: var(--text);
}

.success-bg {
    background-color: #E8F5E9;
    border-color: #C8E6C9;
}
.success-bg .stats-val { color: #2E7D32; }

.danger-bg {
    background-color: #FFEBEE;
    border-color: #FFCDD2;
}
.danger-bg .stats-val { color: #C62828; }

.warning-bg {
    background-color: #FFF9C4;
    border-color: #FFF59D;
}
.warning-bg .stats-val { color: #F57F17; }

/* Motivation Message */
.motivation-box {
    background-color: #FFFBEB;
    border: 3px solid #FEF3C7;
    border-radius: 20px;
    padding: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.6;
}

.motivation-box h3 {
    font-size: 1.35rem;
    font-weight: 900;
    color: #B45309;
    margin-bottom: 0.5rem;
}

.motivation-box p {
    color: #92400E;
    font-weight: 600;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    from {
        transform: scale(0.85);
    }
    to {
        transform: scale(1);
    }
}

@keyframes popScore {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

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

@keyframes bouncePulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.03); }
}

@keyframes timerPulseShake {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1) rotate(-1deg);
    }
}

@keyframes shakeCard {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Bounce for welcome screen button */
.animate-bounce {
    animation: bounceButton 1.5s infinite ease-in-out;
}

@keyframes bounceButton {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

/* Loops for feedback emojis */
.bounce-loop {
    animation: emojiBounce 0.8s infinite alternate ease-in-out;
    display: inline-block;
}

.shake-loop {
    animation: emojiShake 0.6s infinite ease-in-out;
    display: inline-block;
}

.pulse-loop {
    animation: emojiPulse 1s infinite alternate ease-in-out;
    display: inline-block;
}

@keyframes emojiBounce {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-15px) scale(1.1); }
}

@keyframes emojiShake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

@keyframes emojiPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.2); }
}

/* Media Queries */
@media (max-width: 576px) {
    body {
        padding: 0.75rem;
    }
    
    .card {
        padding: 1.5rem;
        border-radius: 24px;
        border-width: 4px;
    }
    
    .main-title {
        font-size: 1.75rem;
    }
    
    .question-equation {
        font-size: 2.5rem;
    }
    
    #answer-input {
        font-size: 1.75rem;
        padding: 1rem;
        border-radius: 16px;
    }
    
    .btn {
        padding: 0.85rem 1.5rem;
        font-size: 1.1rem;
        border-radius: 16px;
    }
    
    .btn-large {
        font-size: 1.2rem;
        padding: 1rem 1.75rem;
    }
    
    .stats-grid {
        gap: 0.5rem;
    }
    
    .stats-emoji {
        font-size: 1.4rem;
    }
    
    .stats-val {
        font-size: 1.1rem;
    }
    
    .feedback-card {
        padding: 2rem 1.5rem;
    }
    
    .feedback-emoji {
        font-size: 4rem;
    }
    
    .feedback-title {
        font-size: 1.8rem;
    }
}

@media (min-width: 768px) {
    .result-actions {
        flex-direction: row;
    }
    
    .result-actions button {
        flex: 1;
    }
    
    .answer-box {
        flex-direction: row;
    }
    
    #answer-input {
        flex: 2;
    }
    
    .btn-submit {
        flex: 1;
        height: auto;
    }
}

/* Sound Toggle Floating Button styling */
.sound-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: var(--card);
    border: 4px solid var(--border);
    font-size: 1.5rem;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    width: 55px;
    height: 55px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.sound-toggle-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-dark);
    box-shadow: var(--shadow-lg);
}

.sound-toggle-btn:active {
    transform: scale(0.9);
}

@media (max-width: 576px) {
    .sound-toggle-btn {
        top: 10px;
        right: 10px;
        width: 45px;
        height: 45px;
        font-size: 1.25rem;
    }
}
