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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-600: #4b5563;
    --gray-800: #1f2937;
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --border-color: #d1d5db;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-600: #9ca3af;
    --gray-800: #f3f4f6;
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: #4b5563;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Home Screen */
h1 {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.25rem;
}

.subtitle {
    text-align: center;
    color: var(--gray-600);
    margin-bottom: 2rem;
    font-size: 1.25rem;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 400px;
    margin: 0 auto 2rem;
}

.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.btn-desc {
    font-size: 0.8rem;
    font-weight: 400;
    opacity: 0.8;
    margin-top: 0.25rem;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

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

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

.btn-warning:hover {
    background: #d97706;
}

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

.missed-section {
    display: flex;
    gap: 0.5rem;
}

.missed-section .btn-warning {
    flex: 1;
}

.btn-clear,
.btn-action {
    background: var(--gray-200);
    border: none;
    border-radius: 8px;
    padding: 0 1rem;
    font-size: 1.2rem;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-clear:hover {
    background: var(--danger);
    color: white;
}

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

.btn-action:disabled,
.btn-clear:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline {
    background: var(--bg-primary);
    border: 2px solid var(--gray-300);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.btn-danger:hover {
    background: #b91c1c;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.domain-filter {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.domain-filter h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.domain-filter label {
    display: block;
    padding: 0.5rem 0;
    cursor: pointer;
}

.domain-filter input {
    margin-right: 0.5rem;
}

.question-count {
    text-align: center;
    margin-bottom: 2rem;
}

.question-count select {
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border-radius: 4px;
    border: 1px solid var(--gray-300);
}

/* Exam Screen */
.exam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.exam-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.domain-badge {
    background: var(--gray-200);
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    display: inline-block;
}

.timer {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: monospace;
    color: var(--primary);
}

.timer.warning {
    color: var(--warning);
}

.timer.danger {
    color: var(--danger);
}

.timer.hidden {
    display: none;
}

.question-container {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.question-text {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    line-height: 1.7;
}

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

.option {
    padding: 1rem;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.option:hover {
    border-color: var(--primary);
    background: #eff6ff;
}

.option.selected {
    border-color: var(--primary);
    background: #dbeafe;
}

.option.correct {
    border-color: var(--success);
    background: #dcfce7;
}

.option.incorrect {
    border-color: var(--danger);
    background: #fee2e2;
}

.option-letter {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

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

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

.option.incorrect .option-letter {
    background: var(--danger);
    color: white;
}

.feedback {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.feedback.hidden {
    display: none;
}

.feedback.correct {
    background: #dcfce7;
    border: 1px solid var(--success);
}

.feedback.incorrect {
    background: #fee2e2;
    border: 1px solid var(--danger);
}

.feedback h4 {
    margin-bottom: 0.5rem;
}

.exam-nav {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.exam-nav .btn {
    flex: 1;
    flex-direction: row;
    justify-content: center;
}

#flag-btn.flagged {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 8px;
}

.grid-item {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.grid-item:hover {
    border-color: var(--primary);
}

.grid-item.current {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.grid-item.answered {
    background: var(--gray-200);
}

.grid-item.flagged {
    background: var(--warning);
    color: white;
}

.grid-item.correct {
    background: var(--success);
    color: white;
}

.grid-item.incorrect {
    background: var(--danger);
    color: white;
}

/* Results Screen */
.score-display {
    text-align: center;
    padding: 2rem;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 2rem;
}

.score-circle {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    border: 8px solid var(--gray-200);
}

.score-circle.pass {
    border-color: var(--success);
}

.score-circle.fail {
    border-color: var(--danger);
}

#score-percent {
    font-size: 2.5rem;
    font-weight: 700;
}

#score-text {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.pass-fail {
    font-size: 1.25rem;
    font-weight: 600;
}

.pass-fail.pass {
    color: var(--success);
}

.pass-fail.fail {
    color: var(--danger);
}

.domain-breakdown {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.domain-breakdown h3 {
    margin-bottom: 1rem;
}

.domain-score {
    margin-bottom: 1rem;
}

.domain-score-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.domain-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.domain-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s;
}

.results-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Review Screen */
.review-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.review-item {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border-left: 4px solid var(--gray-300);
}

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

.review-item.incorrect {
    border-left-color: var(--danger);
}

.review-question {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.review-meta {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 1rem;
}

.review-answer {
    margin-bottom: 0.5rem;
}

.review-answer.your-answer {
    color: var(--danger);
}

.review-answer.correct-answer {
    color: var(--success);
}

.review-explanation {
    background: var(--gray-100);
    padding: 1rem;
    border-radius: 4px;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* History Screen */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.history-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--gray-600);
}

.history-item {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-date {
    font-size: 0.85rem;
    color: var(--gray-600);
}

.history-score {
    font-weight: 600;
}

.history-score.pass {
    color: var(--success);
}

.history-score.fail {
    color: var(--danger);
}

.hidden {
    display: none !important;
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: all 0.3s;
    z-index: 1000;
}

.theme-toggle:hover {
    border-color: var(--primary);
    transform: scale(1.1);
}

/* Flashcard Styles */
.flashcard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.flashcard-categories {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.flashcard-categories .btn {
    padding: 0.75rem;
    font-size: 0.9rem;
}

.flashcard-progress {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.flashcard {
    perspective: 1000px;
    cursor: pointer;
    margin-bottom: 1rem;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    min-height: 250px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    min-height: 250px;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border-radius: 12px;
    background: var(--bg-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.flashcard-front {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.flashcard-front p {
    font-size: 1.5rem;
    font-weight: 600;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: var(--bg-primary);
    border: 2px solid var(--primary);
}

.flashcard-back p {
    font-size: 1.25rem;
    line-height: 1.6;
}

.flashcard-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.flashcard-nav {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.flashcard-nav .btn {
    flex: 1;
}

/* Responsive */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .exam-header {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .exam-nav {
        flex-direction: column;
    }

    .results-actions {
        flex-direction: column;
    }
}
