:root {
    --bg-color: #0F0F1A;
    --card-bg: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #FFFFFF;
    --text-secondary: #94A3B8;
    
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --accent: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --xp-color: #FBBF24;
    
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 30px;
}

.logo {
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--primary);
    text-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.level-badge {
    background: var(--card-bg);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
}

.player-info .xp-bar-container {
    width: 100px;
    height: 8px;
    background: var(--card-bg);
    border-radius: 4px;
    overflow: hidden;
}

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

.xp-text {
    font-size: 0.85rem;
    color: var(--xp-color);
    font-weight: 600;
}

/* Screens */
.screen {
    display: none;
    flex: 1;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

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

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn.secondary {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Home Screen */
.home-hero {
    text-align: center;
    margin-bottom: 40px;
}

.home-hero h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #fff, #94A3B8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.home-hero p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: var(--card-bg);
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.difficulty-selector select {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: var(--font-sans);
    outline: none;
}

/* Topic Grid */
.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.topic-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.topic-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 3px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform 0.3s;
}

.topic-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.topic-card:hover::before {
    transform: scaleX(1);
}

.topic-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.topic-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.topic-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Gameplay Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.topic-badge {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-right: 10px;
}

#game-progression {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.score-display {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--accent);
}

.timer-container {
    height: 6px;
    background: var(--card-bg);
    border-radius: 3px;
    margin-bottom: 5px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: var(--primary);
    transition: width 1s linear, background-color 0.3s;
}

.timer-bar.warning { background: var(--warning); }
.timer-bar.danger { background: var(--danger); }

.timer-text {
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-family: var(--font-mono);
}

.quiz-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px;
    backdrop-filter: blur(10px);
}

.quiz-card.pulse-correct {
    animation: pulseGreen 0.5s;
}
.quiz-card.pulse-wrong {
    animation: pulseRed 0.5s;
}

@keyframes pulseGreen {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); border-color: var(--accent); }
    70% { box-shadow: 0 0 0 15px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulseRed {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); border-color: var(--danger); }
    70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.question-text {
    font-size: 1.4rem;
    margin-bottom: 30px;
    line-height: 1.4;
}

/* Question Code Blocks */
.question-code {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    margin-top: 15px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    color: #e2e8f0;
    white-space: pre-wrap;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 15px 20px;
    border-radius: 10px;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
}

.option-btn:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    transform: translateX(5px);
}

.option-btn.correct {
    background: rgba(16, 185, 129, 0.15) !important;
    border-color: var(--accent) !important;
    color: var(--accent);
}

.option-btn.wrong {
    background: rgba(239, 68, 68, 0.15) !important;
    border-color: var(--danger) !important;
    color: var(--danger);
}

.option-btn:disabled {
    cursor: default;
    opacity: 0.8;
}

.game-footer {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.streak-indicator {
    background: var(--card-bg);
    padding: 6px 15px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid var(--warning);
    color: var(--warning);
    opacity: 0;
    transition: opacity 0.3s;
}

.streak-indicator.visible { opacity: 1; }

/* Results Screen */
.results-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    margin-bottom: 30px;
}

.results-header h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.final-score {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin: 10px 0;
    text-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.score-subtitle {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.stat-box {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.stat-val {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.achievements-unlocked {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
}

.achievement-badge {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid var(--xp-color);
    color: var(--xp-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.results-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* Review Section */
.review-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
}

.review-section h3 {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.review-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.review-q { font-weight: 600; margin-bottom: 10px; }
.review-code {
    background: rgba(255,255,255,0.05);
    padding: 10px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    border-radius: 6px;
    margin-bottom: 10px;
}
.review-a { color: var(--accent); font-size: 0.9rem; margin-bottom: 5px;}
.review-y { color: var(--danger); font-size: 0.9rem; text-decoration: line-through; }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: #1a1a2e;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-title { margin-bottom: 20px; text-align: center; }

.lifetime-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.l-stat {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.05);
}

.l-stat .val { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.l-stat .lbl { font-size: 0.8rem; color: var(--text-secondary); }

.lb-list { margin-top: 10px; background: rgba(0,0,0,0.3); border-radius: 10px; padding: 10px; }
.lb-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}
.lb-item:last-child { border-bottom: none; }
.lb-item.top-1 { color: #FFD700; font-weight: bold; }
.lb-item.top-2 { color: #C0C0C0; }
.lb-item.top-3 { color: #CD7F32; }

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px; left: 50%;
    transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 10px;
    z-index: 2000;
}

.toast {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    color: white;
    padding: 12px 20px;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    .controls-row { flex-direction: column; gap: 15px; }
    .results-stats { grid-template-columns: 1fr; }
}