:root {
    --primary: #5c67f2;
    --primary-dark: #4a54d1;
    --secondary: #6c757d;
    --accent: #5c67f2;
    --success: #48bb78;
    --error: #f56565;
    --bg-light: #f8faff;
    --text-dark: #1a202c;
    --text-muted: #4a5568;
    --white: #ffffff;
    --shadow: 0 10px 30px rgba(92, 103, 242, 0.1);
    --shadow-lg: 0 20px 40px rgba(92, 103, 242, 0.15);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    margin-bottom: 3rem;
    text-align: center;
}

h1,
h2,
h3,
h4 {
    font-family: 'Outfit', sans-serif;
    color: var(--text-dark);
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0, 0, 0, 0.03);
    margin-bottom: 2rem;
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    width: 100%;
}

.btn:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(92, 103, 242, 0.3);
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-dark);
}

select,
input {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 2px solid #edf2f7;
    border-radius: 8px;
    font-size: 1rem;
    background-color: #ffffff;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(92, 103, 242, 0.1);
}

/* Auth Pages */
.auth-container {
    max-width: 480px;
    margin: 4rem auto;
    padding: 0 1rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 1rem;
}

.input-field {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 2px solid #edf2f7;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s;
    background: #ffffff;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(92, 103, 242, 0.1);
}

/* Exam Styles */
.question-card {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e2e8f0;
}

.question-text {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-dark);
}

.options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.option-label {
    display: flex;
    align-items: center;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.option-label:hover {
    background-color: #f1f5f9;
}

.option-input {
    width: auto;
    margin-right: 1rem;
}

/* Results Styles */
.result-header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 2rem;
    background: var(--primary-color);
    color: white;
    border-radius: 1rem;
}

.score {
    font-size: 4rem;
    font-weight: 800;
}

.explanation-box {
    margin-top: 1rem;
    padding: 1rem;
    background-color: #f0f9ff;
    border-left: 4px solid var(--accent-color);
    border-radius: 0.5rem;
}

.correct-answer {
    border-color: var(--success);
    background-color: #f0fff4;
}

.wrong-answer {
    border-color: var(--error);
    background-color: #fff5f5;
}

/* .loading definition moved to bottom for enhancements */

.level-title {
    font-size: 2rem;
    line-height: 1;
    font-weight: 800;
    margin: 0;
}

.level-subtitle {
    opacity: 0.9;
    font-size: 1rem;
    margin-top: 0.25rem;
    font-weight: 500;
}

.xp-stat {
    text-align: right;
}

.xp-value {
    font-size: 2rem;
    font-weight: 800;
}

.xp-label {
    opacity: 0.8;
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.level-progress-container {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    height: 0.75rem;
    position: relative;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.level-progress-bar {
    background: #fbbf24;
    height: 100%;
    border-radius: 999px;
    transition: width 1s ease-out;
}

.level-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: 500;
}

.stats-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
    flex: 0 1 240px;
    /* Fixed max width, allow shrinking, start at 240px */
    text-align: center;
}

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

.stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    line-height: 1;
}

.stat-value {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    gap: 0.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-weight: 500;
    color: #64748b;
    background: white;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

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

.tab-btn.active {
    color: var(--accent-color);
    background-color: #eff6ff;
    border-color: #bfdbfe;
    font-weight: 600;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

/* Header Grid Layout */
.header-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-bottom: 3rem;
    gap: 1rem;
}

/* New Vertical Header Layout */
.header-stacked {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.header-center {
    text-align: center;
}

.header-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
}

/* Navigation Buttons */
.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-weight: 500;
    color: var(--text-color);
    background-color: white;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
    font-size: 0.85rem;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.nav-btn:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.nav-btn.danger {
    color: var(--error-color);
    border-color: #fecaca;
    background-color: #fef2f2;
}

.nav-btn.danger:hover {
    background-color: #fee2e2;
    border-color: #fca5a5;
}

.nav-btn.primary {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

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

/* Info Badge */
.info-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: #f1f5f9;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    border: 1px solid #e2e8f0;
}

/* UX Improvements: Menu Active State & Icons */
.nav-btn.active {
    background-color: rgba(92, 103, 242, 0.1);
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 600;
}

/* Uniform Navigation - Consolidated */
/* Uniform Navigation - Simplified & Robust */
.nav-uniform {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    align-items: center;
    justify-content: center;
    /* Center items */
    gap: 0.5rem;
    /* Consistent gap */
    width: 100%;
    margin-top: 1rem;
}

.nav-uniform .nav-btn,
.nav-uniform .info-badge {
    /* Reset flex/width properties to defaults */
    flex: initial;
    width: auto;
    min-width: auto;
    max-width: 100%;

    /* Good spacing */
    padding: 0.6rem 1rem;
    margin: 0.25rem;
    /* Tiny margin for safety when wrapping */

    /* Prevent text overflow */
    white-space: nowrap;
}

/* Icons */
.nav-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* strict grid system */
.subject-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (min-width: 768px) {
    .subject-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.subject-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    height: 100%;
    /* enforce equal height */
    text-align: center;
}

.subject-card:hover {
    border-color: var(--accent-color);
    background-color: #f8fafc;
}

.subject-card.selected {
    border-color: var(--accent-color);
    background-color: #eff6ff;
    box-shadow: 0 0 0 1px var(--accent-color);
}

.subject-card.selected .subject-icon {
    transform: scale(1.1);
}


/* Stats Grid handled in consolidated section above */

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

@media (min-width: 640px) {
    .config-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Toggles - Restored */
.toggle-group {
    display: flex;
    background: #f1f5f9;
    padding: 0.25rem;
    border-radius: 0.5rem;
    gap: 0.25rem;
}

.toggle-option {
    flex: 1;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
    user-select: none;
    color: var(--text-color);
}

.toggle-option:hover:not(.selected) {
    background-color: rgba(255, 255, 255, 0.5);
}

.toggle-option.selected {
    background-color: white;
    color: var(--accent-color);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    font-weight: 600;
}

/* Enhancements: Sticky Header & Progress */
.sticky-exam-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    margin: -2rem -2rem 2rem -2rem;
    padding: 1rem 2rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 1rem 1rem 0 0;
}

.progress-container {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    width: 100%;
    max-width: 200px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
}

/* Enhancements: Interactive Animations */
.subject-card:active {
    transform: scale(0.95);
}

.nav-btn:active {
    transform: scale(0.98);
}

/* Enhancements: Loading Overlay */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Additional Responsive Fixes */

/* TTS Button */
.tts-btn {
    background: none;
    border: 1px solid #e2e8f0;
    color: var(--accent-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s;
    float: right;
    margin: 0.5rem;
}

.tts-btn:hover {
    background-color: #eff6ff;
    border-color: var(--accent-color);
}

.tts-btn.speaking {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}