/* Global Styles */
:root {
    --primary-color: #667eea;
    --primary-dark: #5a67d8;
    --secondary-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --bg-primary: #ffffff;
    --bg-secondary: #f7fafc;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --text-primary: #f7fafc;
    --text-secondary: #cbd5e0;
    --border-color: #4a5568;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
    min-height: 100vh;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

.loading-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Navigation Bar */
.navbar {
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.brand-icon {
    font-size: 2rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.theme-toggle, .sound-toggle {
    background: none;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 1.2rem;
}

.theme-toggle:hover, .sound-toggle:hover {
    background: var(--bg-secondary);
    transform: rotate(180deg);
}

.sound-toggle .sound-icon {
    transition: var(--transition);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-logout {
    padding: 0.5rem 1rem;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-logout:hover {
    background: #e53e3e;
    transform: translateY(-2px);
}

/* Main Container */
.main-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* Screens */
.screen {
    display: none;
    animation: fadeIn 0.5s;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Authentication Screen */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-tabs {
    display: flex;
    background: var(--bg-secondary);
}

.auth-tab {
    flex: 1;
    padding: 1rem;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
    font-weight: 600;
}

.auth-tab.active {
    background: var(--bg-primary);
    color: var(--primary-color);
}

.auth-form {
    display: none;
    padding: 2rem;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group input {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-primary);
}

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-block;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Auto-progress countdown styling */
.btn-primary:not(:disabled):not(:hover) {
    animation: pulse-countdown 1s ease-in-out infinite;
}

@keyframes pulse-countdown {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
    }
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* Dashboard Screen */
.dashboard-header {
    text-align: center;
    margin-bottom: 3rem;
}

.dashboard-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.dashboard-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.dashboard-card h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-item {
    text-align: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.action-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.leaderboard-rank {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    font-weight: bold;
}

.leaderboard-name {
    flex: 1;
    font-weight: 600;
}

.leaderboard-score {
    color: var(--text-secondary);
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.activity-item {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.activity-category {
    font-weight: 600;
    color: var(--text-primary);
}

.activity-score {
    color: var(--secondary-color);
    font-weight: bold;
}

/* Setup Screen */
.setup-container {
    max-width: 600px;
    margin: 2rem auto;
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.setup-container h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.setup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.setup-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.setup-group select {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
    cursor: pointer;
}

.setup-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-primary);
}

.setup-actions {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
}

.setup-actions .btn {
    flex: 1;
}

/* Quiz Screen */
.quiz-header {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quiz-progress {
    flex: 1;
}

#questionNumber {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-bar {
    width: 100%;
    max-width: 300px;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.5s ease;
}

.quiz-timer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.timer-icon {
    animation: pulse 1s infinite;
}

.quiz-content {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.question-container h2 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.answers-container {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
}

.answer-option {
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
    text-align: left;
}

.answer-option:hover:not(.selected):not(.correct):not(.wrong) {
    background: var(--border-color);
    transform: translateX(4px);
}

.answer-option.selected {
    border-color: var(--primary-color);
    background: rgba(102, 126, 234, 0.1);
}

.answer-option.correct {
    border-color: var(--secondary-color);
    background: rgba(72, 187, 120, 0.1);
    animation: correctPulse 0.5s;
}

.answer-option.wrong {
    border-color: var(--danger-color);
    background: rgba(245, 101, 101, 0.1);
    animation: wrongShake 0.5s;
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.quiz-actions {
    text-align: center;
}

/* Results Screen */
.results-container {
    max-width: 600px;
    margin: 2rem auto;
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.results-header h1 {
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.score-circle {
    width: 200px;
    height: 200px;
    margin: 0 auto 2rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    animation: scoreReveal 1s ease-out;
}

@keyframes scoreReveal {
    0% { transform: scale(0) rotate(0deg); }
    50% { transform: scale(1.1) rotate(180deg); }
    100% { transform: scale(1) rotate(360deg); }
}

.score-value {
    display: flex;
    align-items: baseline;
    color: white;
}

.score-value #finalScore {
    font-size: 4rem;
    font-weight: bold;
}

.score-percent {
    font-size: 2rem;
    margin-left: 0.25rem;
}

.score-label {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    margin-top: 0.5rem;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.result-stat {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.stat-icon {
    font-size: 2rem;
}

.stat-text {
    color: var(--text-primary);
    font-weight: 600;
}

.results-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.results-actions .btn {
    flex: 1;
    min-width: 140px;
}

/* Review Screen */
.review-container {
    max-width: 800px;
    margin: 2rem auto;
}

.review-container h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.review-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.review-item {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.review-question {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.review-answers {
    display: grid;
    gap: 0.75rem;
}

.review-answer {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
}

.review-answer.user-correct {
    border-color: var(--secondary-color);
    background: rgba(72, 187, 120, 0.1);
}

.review-answer.user-wrong {
    border-color: var(--danger-color);
    background: rgba(245, 101, 101, 0.1);
}

.review-answer.correct-answer {
    border-color: var(--secondary-color);
    font-weight: 600;
}

.review-label {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.review-label.correct {
    background: var(--secondary-color);
    color: white;
}

.review-label.wrong {
    background: var(--danger-color);
    color: white;
}

.review-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
    max-width: 350px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left: 4px solid var(--secondary-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.info {
    border-left: 4px solid var(--primary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-container {
        padding: 0 1rem;
    }
    
    .nav-brand {
        font-size: 1.2rem;
    }
    
    .brand-icon {
        font-size: 1.5rem;
    }
    
    .dashboard-header h1 {
        font-size: 2rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .setup-grid {
        grid-template-columns: 1fr;
    }
    
    .quiz-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .progress-bar {
        max-width: 100%;
    }
    
    .results-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .results-actions {
        flex-direction: column;
    }
    
    .results-actions .btn {
        width: 100%;
    }
    
    .score-value #finalScore {
        font-size: 3rem;
    }
    
    .toast {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .dashboard-header h1 {
        font-size: 1.5rem;
    }
    
    .auth-container {
        margin: 2rem 1rem;
    }
    
    .setup-container {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .quiz-content {
        padding: 1.5rem;
    }
    
    .question-container h2 {
        font-size: 1.2rem;
    }
    
    .answer-option {
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dashboard-card {
    animation: slideUp 0.5s ease-out;
}

.dashboard-card:nth-child(1) { animation-delay: 0.1s; }
.dashboard-card:nth-child(2) { animation-delay: 0.2s; }
.dashboard-card:nth-child(3) { animation-delay: 0.3s; }
.dashboard-card:nth-child(4) { animation-delay: 0.4s; }

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }