/**
 * Frontend Styles for the Quiz.
 * All styles are scoped to the parent ID to prevent conflicts.
 */

/* Base styles for all themes */
#mmcqg-quiz-block {
    direction: rtl;
    font-family: 'Cairo', sans-serif;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
    min-height: 80vh; /* Ensure it takes up enough vertical space */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#mmcqg-quiz-block .quiz-wrapper {
    width: 100%;
    max-width: 1000px;
    border-radius: 25px;
    overflow: hidden; /* For background animations */
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    display: flex; /* Use flex to center content inside wrapper */
    justify-content: center;
    align-items: center;
    flex-direction: column;
    min-height: 70vh; /* Minimum height for the wrapper */
}

#mmcqg-quiz-block .container {
    width: 100%;
    padding: clamp(15px, 4vw, 30px);
    border-radius: 25px;
    text-align: center;
    animation: mmcqg-fadeIn 1s ease-out;
    box-sizing: border-box; /* Include padding in width */
}

@keyframes mmcqg-fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Question Styles */
#mmcqg-quiz-block .question-header { 
    margin-bottom: 20px; 
    width: 80%; /* Adjusted width */
    margin-left: auto;
    margin-right: auto;
}
#mmcqg-quiz-block .question-text-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    cursor: pointer;
}
#mmcqg-quiz-block .question-text {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 700;
    margin: 0;
}
#mmcqg-quiz-block .audio-icon {
    font-size: clamp(1.5rem, 4vw, 2rem);
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
}
#mmcqg-quiz-block .audio-icon:hover { opacity: 1; transform: scale(1.1); }

/* Progress Bar (RTL) */
#mmcqg-quiz-block .progress-bar {
    width: 100%; /* Relative to its parent (question-header) */
    height: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    margin-top: 15px;
    overflow: hidden;
    direction: rtl; /* Ensures bar grows from the right */
}
#mmcqg-quiz-block .progress-bar-inner {
    height: 100%;
    width: 0%;
    border-radius: 5px;
    transition: width 0.5s ease-in-out;
    float: right; /* Aligns the inner bar to the right */
}

/* Options Grid */
#mmcqg-quiz-block .options-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: clamp(15px, 3vw, 20px);
    justify-content: center;
    margin-top: 20px;
}
#mmcqg-quiz-block .option {
    border: 2px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s;
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column; /* Allow content to stack */
    justify-content: center;
    align-items: center;
    font-size: clamp(2.5rem, 8vw, 5rem); /* Adjusted for text options */
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal; /* Allow text to wrap if needed */
    word-break: break-word; /* Break long words */
    word-wrap: break-word; /* For older browsers */
}
#mmcqg-quiz-block .option:hover { transform: scale(1.05); }
#mmcqg-quiz-block .option img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
}
#mmcqg-quiz-block .option audio {
    width: 80%; /* Adjust width for audio player */
    max-width: 250px;
    margin: 5px 0;
}

/* Feedback Styles */
@keyframes mmcqg-correct-answer {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes mmcqg-incorrect-answer {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

/* Buttons and Score */
#mmcqg-quiz-block .container h1, #mmcqg-quiz-block .container h2 { font-size: clamp(2rem, 5vw, 3rem); }
#mmcqg-quiz-block .quiz-button {
    border: none;
    border-radius: 15px;
    padding: 15px 40px;
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: bold;
    font-family: 'Cairo', sans-serif;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    margin-top: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
#mmcqg-quiz-block .quiz-button:hover { transform: scale(1.05); }
#mmcqg-quiz-block .score-container { display: none; flex-direction: column; align-items: center; justify-content: center; }
#mmcqg-quiz-block .final-score { font-size: clamp(3rem, 10vw, 5rem); font-weight: bold; margin: 20px 0; }

/* New styles for user score updates */
#mmcqg-quiz-block .user-score-updates {
    font-size: 0.9em;
    margin-top: 10px;
    text-align: center;
    line-height: 1.5;
}

/* --- Dark Theme (Default) --- */
#mmcqg-quiz-block.dark-theme {
    color: #ffffff;
}
#mmcqg-quiz-block.dark-theme .quiz-wrapper {
    background: linear-gradient(-45deg, #141e30, #243b55, #3a608a, #141e30);
    background-size: 400% 400%;
    animation: mmcqg-gradientBG 15s ease infinite;
}
@keyframes mmcqg-gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
#mmcqg-quiz-block.dark-theme .container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}
#mmcqg-quiz-block.dark-theme .progress-bar-inner {
    background-color: #ffc300;
}
#mmcqg-quiz-block.dark-theme .option {
    background-color: rgba(255, 255, 255, 0.1);
}
#mmcqg-quiz-block.dark-theme .option:hover { border-color: #ffc300; }
#mmcqg-quiz-block.dark-theme .option.correct {
    background-color: #4CAF50;
    border-color: #fff;
}
#mmcqg-quiz-block.dark-theme .option.incorrect {
    background-color: #F44336;
    border-color: #fff;
}
#mmcqg-quiz-block.dark-theme .quiz-button {
    background-color: #ffc300;
    color: #141e30;
}
#mmcqg-quiz-block.dark-theme .quiz-button:hover { box-shadow: 0 0 20px #ffc300; }
#mmcqg-quiz-block.dark-theme .final-score { 
    color: #ffc300; 
    text-shadow: 0 0 10px rgba(255,195,0,0.5); 
}
#mmcqg-quiz-block.dark-theme .container p { color: #ffffff; }
#mmcqg-quiz-block.dark-theme .user-score-updates { color: #add8e6; }


/* --- Light Theme --- */
#mmcqg-quiz-block.light-theme {
    color: #333;
}
#mmcqg-quiz-block.light-theme .quiz-wrapper {
    background: linear-gradient(135deg, #e0f2f7, #c1e4ed, #a2d7e3, #e0f2f7);
    background-size: 400% 400%;
    animation: mmcqg-lightGradientBG 15s ease infinite;
}
@keyframes mmcqg-lightGradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
#mmcqg-quiz-block.light-theme .container {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
#mmcqg-quiz-block.light-theme .progress-bar-inner {
    background-color: #007bff; /* Blue */
}
#mmcqg-quiz-block.light-theme .option {
    background-color: rgba(255, 255, 255, 0.7);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
#mmcqg-quiz-block.light-theme .option:hover { border-color: #007bff; }
#mmcqg-quiz-block.light-theme .option.correct {
    background-color: #28a745; /* Green */
    color: #fff;
    border-color: #fff;
}
#mmcqg-quiz-block.light-theme .option.incorrect {
    background-color: #dc3545; /* Red */
    color: #fff;
    border-color: #fff;
}
#mmcqg-quiz-block.light-theme .quiz-button {
    background-color: #007bff;
    color: #fff;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
#mmcqg-quiz-block.light-theme .quiz-button:hover { box-shadow: 0 0 20px #007bff; }
#mmcqg-quiz-block.light-theme .final-score { 
    color: #007bff; 
    text-shadow: none; 
}
#mmcqg-quiz-block.light-theme .container p { color: #555; }
#mmcqg-quiz-block.light-theme .user-score-updates { color: #666; }


/* --- Preschool Kindergarten Theme --- */
#mmcqg-quiz-block.kindergarten-theme {
    color: #333;
    font-family: 'Comic Sans MS', cursive, sans-serif; /* Playful font */
}
#mmcqg-quiz-block.kindergarten-theme .quiz-wrapper {
    background: linear-gradient(45deg, #ffeb3b, #ff9800, #ffc107, #ffeb3b); /* Warm, playful gradient */
    background-size: 400% 400%;
    animation: mmcqg-kindergartenGradientBG 20s ease infinite;
    border: 5px dashed #f44336; /* Dashed border for fun */
}
@keyframes mmcqg-kindergartenGradientBG {
    0% { background-position: 0% 50%; }
    25% { background-position: 100% 50%; }
    50% { background-position: 0% 50%; }
    75% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
#mmcqg-quiz-block.kindergarten-theme .container {
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #9c27b0; /* Purple border */
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), 0 0 0 8px #e91e63; /* Layered shadow for pop */
    transform: rotate(-2deg); /* Slightly tilted */
    animation: mmcqg-popIn 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards;
}
@keyframes mmcqg-popIn {
    0% { transform: scale(0.5) rotate(0deg); opacity: 0; }
    100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}
#mmcqg-quiz-block.kindergarten-theme .question-text {
    color: #4a148c; /* Dark purple */
    text-shadow: 2px 2px 0 #ffeb3b; /* Yellow shadow */
}
#mmcqg-quiz-block.kindergarten-theme .audio-icon {
    color: #e91e63; /* Pink */
}
#mmcqg-quiz-block.kindergarten-theme .progress-bar {
    background-color: #ffcc80; /* Light orange */
    border: 1px solid #ff9800;
}
#mmcqg-quiz-block.kindergarten-theme .progress-bar-inner {
    background-color: #4caf50; /* Green */
    box-shadow: 0 0 10px #4caf50;
}
#mmcqg-quiz-block.kindergarten-theme .option {
    background-color: #fff;
    border: 3px solid #2196f3; /* Blue border */
    box-shadow: 0 5px 10px rgba(0,0,0,0.15);
    transition: all 0.2s ease-in-out;
}
#mmcqg-quiz-block.kindergarten-theme .option:hover {
    transform: scale(1.1) rotate(3deg); /* More playful hover */
    border-color: #e91e63; /* Pink on hover */
    box-shadow: 0 8px 15px rgba(0,0,0,0.25);
}
#mmcqg-quiz-block.kindergarten-theme .option.correct {
    background-color: #8bc34a; /* Light green */
    border-color: #4caf50;
    animation: mmcqg-correct-answer-kindergarten 0.6s ease;
}
@keyframes mmcqg-correct-answer-kindergarten {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.2) rotate(10deg); }
    50% { transform: scale(1.2) rotate(-10deg); }
    75% { transform: scale(1.2) rotate(5deg); }
}
#mmcqg-quiz-block.kindergarten-theme .option.incorrect {
    background-color: #ff7043; /* Orange-red */
    border-color: #f44336;
    animation: mmcqg-incorrect-answer-kindergarten 0.6s ease;
}
@keyframes mmcqg-incorrect-answer-kindergarten {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    20% { transform: translateX(-15px) rotate(-5deg); }
    40% { transform: translateX(15px) rotate(5deg); }
    60% { transform: translateX(-10px) rotate(-3deg); }
    80% { transform: translateX(10px) rotate(3deg); }
}
#mmcqg-quiz-block.kindergarten-theme .quiz-button {
    background-color: #ffc107; /* Amber */
    color: #4a148c; /* Dark purple */
    border: 3px solid #9c27b0;
    box-shadow: 0 5px 0 #ff9800, 0 8px 15px rgba(0,0,0,0.2); /* 3D effect */
    transform: translateY(-2px);
    transition: all 0.1s ease-out;
}
#mmcqg-quiz-block.kindergarten-theme .quiz-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 0 #ff9800, 0 5px 10px rgba(0,0,0,0.2);
}
#mmcqg-quiz-block.kindergarten-theme .quiz-button:hover {
    box-shadow: 0 5px 0 #ff9800, 0 0 20px #ffc107;
}
#mmcqg-quiz-block.kindergarten-theme .final-score { 
    color: #e91e63; /* Pink */
    text-shadow: 3px 3px 0 #ffeb3b, -3px -3px 0 #2196f3; /* Multi-color shadow */
}
#mmcqg-quiz-block.kindergarten-theme .container p { color: #673ab7; } /* Deep purple */
#mmcqg-quiz-block.kindergarten-theme .user-score-updates { color: #03a9f4; } /* Light blue */