/* ===== CSS Reset & Variables ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-300: #a5b4fc;
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;

    --success-50: #ecfdf5;
    --success-100: #d1fae5;
    --success-400: #34d399;
    --success-500: #10b981;
    --success-600: #059669;

    --error-50: #fef2f2;
    --error-100: #fee2e2;
    --error-400: #f87171;
    --error-500: #ef4444;
    --error-600: #dc2626;

    --warning-500: #f59e0b;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Semantic */
    --bg-primary: #ffffff;
    --bg-secondary: var(--gray-50);
    --bg-tertiary: var(--gray-100);
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-tertiary: var(--gray-400);
    --border-color: var(--gray-200);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Topic Colors */
    --science: #8b5cf6;
    --history: #f59e0b;
    --geography: #10b981;
    --technology: #3b82f6;
    --sports: #ef4444;
    --movies: #ec4899;
}

/* ===== Base Styles ===== */
html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100%;
    overflow: hidden;
}

/* ===== App Container ===== */
.app {
    margin: 0 auto;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 580px;
}

@media (min-width: 480px) {
    body {
        padding: var(--space-lg) var(--space-md);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .app {
        height: calc(100vh - var(--space-2xl));
        max-height: 800px;
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-xl);
    }
}

/* ===== Screens ===== */
.screen {
    display: none;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes scaleIn {
    from { 
        opacity: 0; 
        transform: scale(0.9); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-family: 'Poppins', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-700);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-icon svg {
    width: 22px;
    height: 22px;
}

/* ===== HOME SCREEN ===== */
#home-screen {
    background: linear-gradient(180deg, var(--primary-50) 0%, var(--bg-primary) 50%);
}

.home-header {
    padding: var(--space-lg) var(--space-lg) 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-600);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.brand-icon svg {
    width: 22px;
    height: 22px;
}

.brand-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.home-content {
    flex: 1;
    padding: var(--space-md) var(--space-lg);
    overflow-y: auto;
    min-height: 0;
}

.hero {
    text-align: center;
    margin-bottom: var(--space-lg);
}

.hero h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    letter-spacing: -0.02em;
    font-family: 'Poppins', sans-serif;
}

.hero p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    max-width: 280px;
    margin: 0 auto;
    font-family: 'Poppins', sans-serif;
}

.topics-section {
    animation: slideUp 0.4s ease 0.1s both;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.section-header h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.section-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-family: 'Poppins', sans-serif;
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.topic-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    text-align: center;
    width: 100%;
    font-family: 'Poppins', sans-serif;
    min-height: 120px;
    justify-content: center;
}

.topic-card:hover {
    border-color: var(--primary-300);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.topic-card:active {
    transform: translateY(0);
}

.topic-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.topic-icon svg {
    width: 32px;
    height: 32px;
}

.topic-icon.science {
    background: rgba(139, 92, 246, 0.1);
    color: var(--science);
}

.topic-icon.history {
    background: rgba(245, 158, 11, 0.1);
    color: var(--history);
}

.topic-icon.geography {
    background: rgba(16, 185, 129, 0.1);
    color: var(--geography);
}

.topic-icon.technology {
    background: rgba(59, 130, 246, 0.1);
    color: var(--technology);
}

.topic-icon.sports {
    background: rgba(239, 68, 68, 0.1);
    color: var(--sports);
}

.topic-icon.movies {
    background: rgba(236, 72, 153, 0.1);
    color: var(--movies);
}

.topic-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.topic-name {
    display: block;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.topic-meta {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    font-family: 'Poppins', sans-serif;
}

.topic-arrow {
    display: none;
}

.home-footer {
    padding: var(--space-sm) var(--space-lg);
    text-align: center;
    flex-shrink: 0;
}

.home-footer p {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: 'Poppins', sans-serif;
}

/* ===== QUIZ SCREEN ===== */
#quiz-screen {
    background: var(--bg-secondary);
}

.quiz-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.quiz-progress {
    flex: 1;
}

.progress-label {
    margin-bottom: var(--space-xs);
}

#progress-text {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'Poppins', sans-serif;
}

.progress-track {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-500), var(--primary-400));
    border-radius: var(--radius-full);
    width: 10%;
    transition: width 0.4s ease;
}

.score-badge {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--warning-500);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
}

.score-badge svg {
    width: 14px;
    height: 14px;
}

.quiz-content {
    flex: 1;
    padding: var(--space-md);
    overflow-y: auto;
    min-height: 0;
}

.question-card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-sm);
    animation: scaleIn 0.3s ease;
}

.question-badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--primary-600);
    background: var(--primary-50);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: 'Poppins', sans-serif;
}

.question-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    font-family: 'Poppins', sans-serif;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.option-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    font-family: 'Poppins', sans-serif;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--primary-300);
    background: var(--primary-50);
}

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

.option-btn.selected {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

.option-btn.correct {
    border-color: var(--success-500);
    background: var(--success-50);
}

.option-btn.incorrect {
    border-color: var(--error-500);
    background: var(--error-50);
}

.option-letter {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: all var(--transition-fast);
    font-family: 'Poppins', sans-serif;
}

.option-btn.selected .option-letter {
    background: var(--primary-500);
    color: white;
}

.option-btn.correct .option-letter {
    background: var(--success-500);
    color: white;
}

.option-btn.incorrect .option-letter {
    background: var(--error-500);
    color: white;
}

.option-text {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.quiz-footer {
    padding: var(--space-sm) var(--space-md) var(--space-md);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.quiz-footer .btn {
    width: 100%;
}

/* ===== RESULTS SCREEN ===== */
#results-screen {
    background: var(--bg-secondary);
}

.results-header {
    padding: var(--space-md) var(--space-lg);
    display: flex;
    justify-content: flex-start;
}

.results-content {
    flex: 1;
    padding: 0 var(--space-md) var(--space-md);
    overflow-y: auto;
    min-height: 0;
}

.results-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    text-align: center;
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-md);
    animation: scaleIn 0.4s ease;
}

.score-ring {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto var(--space-sm);
}

.score-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: var(--bg-tertiary);
    stroke-width: 8;
}

.ring-progress {
    fill: none;
    stroke: var(--primary-500);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 339.292;
    transition: stroke-dashoffset 1s ease;
}

.score-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.score-num {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    font-family: 'Poppins', sans-serif;
}

.score-max {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    font-family: 'Poppins', sans-serif;
}

.results-info {
    margin-bottom: var(--space-sm);
}

.results-info h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    font-family: 'Poppins', sans-serif;
}

.results-info p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-family: 'Poppins', sans-serif;
}

.stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    border-top: 1px solid var(--border-color);
}

.stat-divider {
    width: 1px;
    height: 40px;
    background: var(--border-color);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon svg {
    width: 16px;
    height: 16px;
}

.stat-item.correct .stat-icon {
    background: var(--success-100);
    color: var(--success-600);
}

.stat-item.incorrect .stat-icon {
    background: var(--error-100);
    color: var(--error-600);
}

.stat-data {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    font-family: 'Poppins', sans-serif;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: 'Poppins', sans-serif;
}

.review-section {
    animation: slideUp 0.4s ease 0.2s both;
}

.review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.review-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
}

.review-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-primary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-family: 'Poppins', sans-serif;
}

.review-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.review-card {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: var(--space-sm) var(--space-md);
    border-left: 3px solid var(--border-color);
}

.review-card.correct {
    border-left-color: var(--success-500);
}

.review-card.incorrect {
    border-left-color: var(--error-500);
}

.review-question-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.review-status {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.review-status svg {
    width: 12px;
    height: 12px;
}

.review-card.correct .review-status {
    background: var(--success-100);
    color: var(--success-600);
}

.review-card.incorrect .review-status {
    background: var(--error-100);
    color: var(--error-600);
}

.review-q {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
    font-family: 'Poppins', sans-serif;
}

.review-answer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 28px;
    margin-bottom: var(--space-xs);
    font-family: 'Poppins', sans-serif;
}

.review-answer strong {
    color: var(--success-600);
    font-weight: 600;
}

.review-answer .wrong {
    color: var(--error-500);
    text-decoration: line-through;
    margin-right: var(--space-xs);
}

.review-explanation {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    margin-left: 28px;
    line-height: 1.4;
    font-family: 'Poppins', sans-serif;
}

.results-footer {
    padding: var(--space-sm) var(--space-md) var(--space-md);
    display: flex;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.results-footer .btn {
    flex: 1;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 380px) {
    .hero h1 {
        font-size: 1.5rem;
    }
    
    .topic-icon {
        width: 42px;
        height: 42px;
    }
    
    .topic-icon svg {
        width: 22px;
        height: 22px;
    }
    
    .question-text {
        font-size: 1rem;
    }
    
    .score-ring {
        width: 120px;
        height: 120px;
    }
    
    .score-num {
        font-size: 2rem;
    }
}

/* ===== Dark Mode Support ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a2e;
        --bg-secondary: #16162a;
        --bg-tertiary: #252544;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-tertiary: #64748b;
        --border-color: #334155;
    }
    
    .topic-card {
        background: var(--bg-tertiary);
    }
    
    .topic-card:hover {
        border-color: var(--primary-400);
    }
    
    .question-card,
    .option-btn,
    .results-card,
    .review-card {
        background: var(--bg-tertiary);
    }
    
    .option-btn:hover:not(:disabled) {
        background: rgba(99, 102, 241, 0.15);
    }
    
    .option-btn.selected {
        background: rgba(99, 102, 241, 0.2);
    }
    
    .option-btn.correct {
        background: rgba(16, 185, 129, 0.15);
    }
    
    .option-btn.incorrect {
        background: rgba(239, 68, 68, 0.15);
    }
    
    #home-screen {
        background: linear-gradient(180deg, rgba(99, 102, 241, 0.1) 0%, var(--bg-primary) 50%);
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

@media (prefers-color-scheme: dark) {
    ::-webkit-scrollbar-thumb {
        background: var(--gray-600);
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: var(--gray-500);
    }
}
