/* --- Global Styles --- */
:root {
    --primary-color: #007bff; /* Blue */
    --secondary-color: #6c757d; /* Gray */
    --background-color: #f4f6f8; /* Light off-white */
    --card-background: #ffffff;
    --text-color: #343a40; /* Dark text */
    --border-color: #e9ecef; /* Very light border */
    --highlight-correct: #28a745; /* Green */
    --highlight-wrong: #dc3545; /* Red */
    --accent-color: #ffc107; /* Yellow/Gold */
    --xp-bar-color: #00bcd4; /* Cyan */
    --light-primary: #e6f2ff; /* Very light blue for hover/selection */
    --header-height: 180px; /* New fixed header height */
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

#app-container {
    width: 100%;
    max-width: 400px; 
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05); /* Softer shadow */
    background-color: var(--card-background);
    min-height: 100vh;
}

/* --- Header Styles --- */
#main-header {
    background-color: var(--primary-color);
    color: white;
    padding: 15px 20px 25px; /* Increased bottom padding */
    text-align: center;
    position: relative;
    height: var(--header-height);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#logo {
    width: 60px;
    height: 60px;
    margin-bottom: 5px;
}

#main-header h1 {
    margin: 0;
    font-size: 2em;
    font-weight: 800; /* Bolder title */
}

#slogan {
    display: block;
    font-size: 1em;
    font-style: italic;
    font-weight: 400;
}

#sub-title {
    display: block;
    font-size: 0.85em;
    margin-top: 5px;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.8;
}

#premium-status {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--accent-color);
    color: var(--text-color);
    padding: 3px 10px;
    border-radius: 15px;
    font-size: 0.7em;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none !important;
}

/* --- View Management (Screen Flash Fix) --- */
.view {
    padding: 20px;
    position: absolute;
    top: var(--header-height); 
    left: 0;
    right: 0;
    width: 100%;
    max-width: 400px;
    min-height: calc(100vh - var(--header-height));
    background-color: var(--card-background);
    box-sizing: border-box;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.active-view {
    opacity: 1;
    pointer-events: all;
    position: relative; /* Only the active view takes up space */
    top: auto;
    min-height: calc(100vh - var(--header-height));
    left: auto;
    right: auto;
    z-index: 20;
}

/* Exam View takes over the whole screen, hiding the header */
#main-header.hidden {
    position: absolute;
    left: -9999px;
    height: 0;
    padding: 0;
}
#exam-view.active-view, #summary-view.active-view {
    top: 0;
    min-height: 100vh;
    padding-top: 15px; 
}
#exam-view.active-view {
    padding-top: 15px; 
}

/* --- Buttons (Cleaned up) --- */
.btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn-large {
    padding: 18px;
    font-size: 1.2em;
    font-weight: 800;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #0069d9;
}

.btn-secondary {
    background-color: #f8f9fa; /* Light background */
    color: var(--text-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
    background-color: #e9ecef;
}

.btn-danger {
    background-color: var(--highlight-wrong);
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-small {
    width: auto;
    display: inline-block;
    padding: 8px 15px;
    font-size: 0.85em;
    box-shadow: none;
}

/* --- Main Menu --- */
#main-menu-view {
    text-align: center;
    padding-top: 40px; /* Extra spacing from header */
}

#tip-container {
    margin-top: 30px;
    padding: 15px;
    border-left: 5px solid var(--accent-color);
    background-color: #fffde7; /* Light yellow background */
    text-align: left;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

#tip-container strong {
    color: var(--accent-color);
    display: block;
    margin-bottom: 5px;
    font-weight: 700;
}

/* --- Options View --- */
#options-view h2 {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    margin-bottom: 25px;
}

#options-view fieldset {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 25px;
}

/* FIX: Categories on new lines */
#category-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#category-list label {
    font-weight: 500;
}


/* --- Stats View (Improved Layout) --- */
.rank-display {
    text-align: center;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--light-primary); /* Light blue background for rank */
    border-radius: 8px;
}

#stats-rank {
    font-size: 2em;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 5px;
}

#stats-level {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--secondary-color);
}

/* Progress bar styles */
.progress-bar-container {
    width: 100%;
    background-color: var(--border-color);
    border-radius: 5px;
    margin: 10px 0 5px;
    height: 15px;
}

#level-progress-bar {
    height: 100%;
    width: 0;
    background-color: var(--xp-bar-color);
    border-radius: 5px;
    transition: width 0.5s ease-out;
}

#level-progress-text {
    text-align: center;
    font-size: 0.9em;
    margin-bottom: 20px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.stat-grid .stat-item {
    background-color: var(--light-primary);
    padding: 10px;
    border-radius: 5px;
    text-align: center;
}

.stat-grid .stat-item strong {
    display: block;
    font-size: 0.8em;
    color: var(--secondary-color);
}

.stat-grid .stat-item span {
    display: block;
    font-size: 1.5em;
    font-weight: 700;
    color: var(--primary-color);
}

#stats-category-details .stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    background-color: transparent;
    text-align: left;
}


/* --- Exam View --- */
.exam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 5px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

#question-timer {
    font-size: 1.4em;
    font-weight: 800;
    color: var(--primary-color);
}

#question-wrapper {
    position: relative;
    min-height: 250px; /* Ensure space for the loader */
}

/* Loader/Placeholder for MathJax */
#math-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--card-background);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
    font-weight: 500;
    color: var(--secondary-color);
    border-radius: 12px;
    z-index: 50;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}
/* Spinner styling - simple implementation */
#math-loader::before {
    content: "↻";
    animation: spin 1s linear infinite;
    margin-right: 10px;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#question-card {
    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05); /* Soft card shadow */
    transition: opacity 0.3s;
}

#question-card.hidden {
    opacity: 0;
    pointer-events: none;
}


#question-category {
    font-size: 0.9em;
    font-weight: 600;
    color: white;
    background-color: var(--primary-color);
    display: inline-block;
    padding: 5px 10px;
    border-radius: 20px;
    margin-bottom: 15px;
}

#question-text {
    font-size: 1.2em;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 25px;
    line-height: 1.6;
}

/* --- CHOICES CONTAINER --- */
#choices-container {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two columns */
    gap: 10px;
}

#choices-container .choice-btn {
    background-color: #f8f9fa; /* Lightest gray for choices */
    color: var(--text-color);
    text-align: center; /* Center align text/math */
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
    font-weight: 500;
    padding: 15px 10px; /* Increased padding */
    border: 2px solid var(--border-color); /* Thicker border */
    border-radius: 8px; /* Rounded corners */
    height: auto; 
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
}

#choices-container .choice-btn:hover:not(:disabled) {
    background-color: var(--light-primary); /* Light blue hover */
    border-color: var(--primary-color);
}

#choices-container .choice-btn.correct,
#choices-container .choice-btn.correct-answer {
    background-color: var(--highlight-correct);
    color: white;
    border-color: var(--highlight-correct);
    font-weight: 700;
}

#choices-container .choice-btn.wrong {
    background-color: var(--highlight-wrong);
    color: white;
    border-color: var(--highlight-wrong);
    font-weight: 700;
}

/* MathJax Specific Styles - Ensure size is readable */
.choice-btn .MathJax, #question-text .MathJax, #feedback-modal .MathJax {
    font-size: 1.2em !important;
    display: inline-block !important; /* Fix for layout within choice buttons */
}

/* --- Exam XP Display --- */
#exam-rank-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
#exam-xp-bar-container {
    width: 100px;
    background-color: var(--border-color);
    border-radius: 5px;
    height: 10px;
    margin-bottom: 3px;
}
#exam-xp-bar {
    height: 100%;
    width: 0;
    background-color: var(--xp-bar-color);
    border-radius: 5px;
    transition: width 0.5s ease-out;
}
#exam-xp-text {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--secondary-color);
}
#xp-animation-text {
    position: absolute;
    right: 5px;
    top: 55px; /* Adjust based on layout */
    font-weight: 700;
    font-size: 1.1em;
    opacity: 0;
}
.xp-gain-anim {
    color: var(--highlight-correct);
    animation: fade-up 1.5s ease-out;
}
.xp-loss-anim {
    color: var(--highlight-wrong);
    animation: fade-down 1.5s ease-out;
}

@keyframes fade-up {
    0% { transform: translateY(0); opacity: 1; }
    50% { opacity: 1; }
    100% { transform: translateY(-20px); opacity: 0; }
}
@keyframes fade-down {
    0% { transform: translateY(0); opacity: 1; }
    50% { opacity: 1; }
    100% { transform: translateY(20px); opacity: 0; }
}


/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    overflow-y: auto; /* Allow scrolling for large modals like feedback */
}

.modal-content {
    background-color: var(--card-background);
    padding: 30px;
    border-radius: 10px;
    width: 90%;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    transition: transform 0.2s;
}

.modal-content.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

/* --- Feedback Modal Styles --- */
#feedback-display-card {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#feedback-modal.correct #feedback-display-card {
    background-color: #d4edda;
    border: 1px solid var(--highlight-correct);
}

#feedback-modal.wrong #feedback-display-card {
    background-color: #f8d7da;
    border: 1px solid var(--highlight-wrong);
}

#feedback-text {
    margin-top: 0;
    font-size: 1.8em;
    font-weight: 800;
    margin-bottom: 10px;
}

#feedback-modal.correct #feedback-text {
    color: var(--highlight-correct);
}

#feedback-modal.wrong #feedback-text {
    color: var(--highlight-wrong);
}

#feedback-display-card p {
    margin: 0;
    line-height: 1.5;
    font-weight: 500;
}

#explanation-box {
    text-align: left;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

#explanation-box h4 {
    margin-top: 0;
    color: var(--primary-color);
    border-bottom: 2px solid var(--light-primary);
    padding-bottom: 5px;
    font-size: 1.1em;
}

#explanation-box p {
    margin-bottom: 0;
    line-height: 1.5;
}


/* --- Keypad Styles --- */
#keypad-display {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}
#keypad-display span {
    width: 30px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    background-color: #f1f3f5;
    transition: background-color 0.2s;
}
#keypad-display span.filled {
    background-color: var(--accent-color);
}
#keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}
.keypad-btn {
    padding: 15px;
    font-size: 1.2em;
    font-weight: 700;
    background-color: #e9ecef;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}
.keypad-btn:active {
    background-color: var(--primary-color);
    color: white;
}
.keypad-special {
    font-size: 0.8em;
    background-color: var(--secondary-color);
    color: white;
}

/* --- Ad Modal --- */
.ad-placeholder {
    padding: 20px;
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 5px;
    margin-bottom: 15px;
}

/* --- Confirm Modal --- */
.confirm-buttons {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
}
#confirm-yes-btn, #confirm-no-btn {
    width: 45%;
}

/* --- Ranks Modal --- */
#ranks-mechanics {
    font-size: 0.9em;
    color: var(--secondary-color);
    line-height: 1.4;
    margin-bottom: 15px;
}
#ranks-list-container {
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    margin: 15px 0;
}
.rank-modal-item {
    padding: 8px 0;
    border-bottom: 1px dotted var(--border-color);
    display: flex;
    flex-direction: column;
}
.rank-modal-item:last-child {
    border-bottom: none;
}
.rank-modal-item strong {
    font-size: 1.1em;
    color: var(--primary-color);
}
.rank-modal-item span {
    font-size: 0.8em;
    color: var(--secondary-color);
}