:root {
    --primary: #1a365d;
    --primary-light: #2a4a7f;
    --primary-dark: #0f2440;
    --accent: #c53030;
    --accent-light: #fc8181;
    --success: #276749;
    --success-light: #c6f6d5;
    --danger: #c53030;
    --danger-light: #fed7d7;
    --warning: #c05621;
    --warning-light: #feebc8;
    --bg: #f7fafc;
    --bg-card: #ffffff;
    --text: #1a202c;
    --text-muted: #718096;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

#app { min-height: 100vh; }

/* Nav */
#nav {
    background: var(--primary);
    color: white;
    padding: 0 2rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.nav-brand {
    font-weight: 800;
    font-size: 1.25rem;
    cursor: pointer;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-links button {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-links button:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-links button.active { color: white; background: rgba(255,255,255,0.15); }

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Main */
main {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* Hero */
.hero {
    text-align: center;
    padding: 3rem 0 2rem;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
    margin-bottom: 1rem;
}

.hero h1 span {
    color: var(--accent);
    display: block;
}

.hero > p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 500px;
    margin: 0 auto 2rem;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 100px;
}

.stat-number { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

/* Home grid */
.home-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-top: 2rem;
}

.home-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

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

.home-card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.home-card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--primary); }
.home-card p { font-size: 0.85rem; color: var(--text-muted); }

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover { background: var(--primary-light); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--border);
    padding: 0.7rem 2rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-large { padding: 1rem 3rem; font-size: 1.1rem; }

.btn-back {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 0;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.btn-icon:hover { background: var(--bg); }

.btn-danger {
    color: var(--danger);
    border-color: var(--danger-light);
}

.btn-danger:hover { background: var(--danger-light); border-color: var(--danger); }

/* Test */
.test-intro {
    text-align: center;
    padding: 3rem 0;
}

.test-intro h2 { font-size: 2rem; color: var(--primary); margin-bottom: 1.5rem; }

.test-info-box {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow);
    max-width: 350px;
    margin: 0 auto 1.5rem;
    text-align: left;
}

.info-row { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border: none; }

.test-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.test-progress { font-weight: 700; font-size: 1rem; color: var(--primary); }

.test-timer {
    background: var(--primary);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.test-timer.warning { background: var(--warning); }
.test-timer.danger { background: var(--danger); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: 0.7; } }

.test-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    min-width: 100px;
}

.test-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

.question-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.question-chapter-tag {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg);
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: 20px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.question-card h3 {
    font-size: 1.15rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    color: var(--text);
}

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

.option-btn {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.4;
    width: 100%;
}

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

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

.option-btn.correct { border-color: var(--success); background: var(--success-light); }
.option-btn.incorrect { border-color: var(--danger); background: var(--danger-light); }
.option-btn.correct-reveal { border-color: var(--success); background: var(--success-light); }

.option-letter {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.option-btn.selected .option-letter { background: var(--primary); color: white; }
.option-btn.correct .option-letter { background: var(--success); color: white; }
.option-btn.incorrect .option-letter { background: var(--danger); color: white; }

.test-nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
}

.test-score-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.test-score-correct { color: var(--success); font-size: 1.1rem; }
.test-score-wrong { color: var(--danger); font-size: 1.1rem; }
.test-score-sep { color: var(--border); }

.test-feedback {
    margin-top: 1.25rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.test-feedback.correct-feedback {
    background: var(--success-light);
    color: var(--success);
}

.test-feedback.incorrect-feedback {
    background: var(--danger-light);
    color: var(--danger);
}

.test-explanation-details {
    margin-top: 0.75rem;
}

.test-explanation-details summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    padding: 0.4rem 0;
    user-select: none;
}

.test-explanation-details summary:hover { text-decoration: underline; }

.test-explanation-details p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    padding: 0.5rem 0 0.25rem;
}

/* Results */
.results-card {
    text-align: center;
    padding: 2rem 0;
}

.results-icon { font-size: 4rem; margin-bottom: 1rem; }

.results-card h2 { font-size: 1.75rem; margin-bottom: 1.5rem; }

.score-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto 2rem;
    font-size: 2.5rem;
    font-weight: 800;
    border: 6px solid;
}

.score-circle.pass { border-color: var(--success); color: var(--success); }
.score-circle.fail { border-color: var(--danger); color: var(--danger); }
.score-circle small { font-size: 1rem; font-weight: 500; }

.results-breakdown {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-width: 400px;
    margin: 0 auto 2rem;
}

.result-item {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius-sm);
}

.result-item-val { font-size: 1.25rem; font-weight: 700; }
.result-item-label { font-size: 0.8rem; color: var(--text-muted); }

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

/* Review */
#review-list .review-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    border-left: 4px solid;
    box-shadow: var(--shadow);
}

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

.review-item h4 { font-size: 0.95rem; margin-bottom: 0.5rem; line-height: 1.4; }

.review-answer {
    font-size: 0.85rem;
    padding: 0.3rem 0;
}

.review-answer.your-wrong { color: var(--danger); }
.review-answer.correct-ans { color: var(--success); font-weight: 600; }

/* Chapters */
.chapters-grid {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.chapter-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 2px solid transparent;
}

.chapter-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.chapter-num {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.chapter-info { flex: 1; }
.chapter-info h3 { font-size: 1.05rem; margin-bottom: 0.25rem; }
.chapter-info p { font-size: 0.85rem; color: var(--text-muted); }

.chapter-badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-weight: 600;
    background: var(--bg);
    color: var(--text-muted);
}

.chapter-quiz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chapter-quiz-header h3 { font-size: 1rem; }

.chapter-quiz-progress {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

.explanation {
    margin-top: 1.25rem;
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: #f0fff4;
    border: 1px solid #c6f6d5;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Flashcards */
.subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.flashcard-categories {
    display: grid;
    gap: 0.75rem;
}

.fc-category-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 2px solid transparent;
}

.fc-category-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.fc-cat-left { display: flex; align-items: center; gap: 1rem; }
.fc-cat-icon { font-size: 1.5rem; }
.fc-cat-name { font-weight: 600; }
.fc-cat-count { font-size: 0.85rem; color: var(--text-muted); }

.fc-cat-progress {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

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

.flashcard-controls { display: flex; gap: 0.5rem; }

.flashcard-container {
    perspective: 1000px;
    margin-bottom: 1.5rem;
}

.flashcard {
    width: 100%;
    min-height: 300px;
    cursor: pointer;
    position: relative;
}

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

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

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    min-height: 300px;
    backface-visibility: hidden;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    text-align: center;
}

.flashcard-front {
    background: var(--bg-card);
    border: 2px solid var(--border);
}

.flashcard-back {
    background: var(--primary);
    color: white;
    transform: rotateY(180deg);
}

.flashcard-category-tag {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 0.7rem;
    background: var(--bg);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    color: var(--text-muted);
    font-weight: 600;
}

.flashcard-front p { font-size: 1.2rem; font-weight: 600; line-height: 1.5; }
.flashcard-back p { font-size: 1.15rem; font-weight: 500; line-height: 1.5; }

.flashcard-nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.btn-know, .btn-dont-know {
    border: none;
    padding: 0.75rem 2rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-know {
    background: var(--success-light);
    color: var(--success);
}

.btn-know:hover { background: #9ae6b4; }

.btn-dont-know {
    background: var(--danger-light);
    color: var(--danger);
}

.btn-dont-know:hover { background: #feb2b2; }

.flashcard-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
}

.flashcard-progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

/* Stats */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 1.5rem 0 2.5rem;
}

.stat-big-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-big-number { font-size: 1.75rem; font-weight: 800; color: var(--primary); }
.stat-big-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.stats-chapters { margin-bottom: 2.5rem; }
.stats-chapters h3, .stats-history h3 { margin-bottom: 1rem; font-size: 1.1rem; }

.chapter-stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow);
}

.chapter-stat-name { font-weight: 600; font-size: 0.9rem; flex: 1; }

.chapter-stat-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    margin: 0 1rem;
    max-width: 200px;
}

.chapter-stat-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.chapter-stat-pct { font-weight: 700; font-size: 0.85rem; width: 45px; text-align: right; }

.test-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow);
}

.test-history-date { font-size: 0.85rem; color: var(--text-muted); }
.test-history-score { font-weight: 700; }
.test-history-score.pass { color: var(--success); }
.test-history-score.fail { color: var(--danger); }

.test-history-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-weight: 600;
}

.test-history-badge.pass { background: var(--success-light); color: var(--success); }
.test-history-badge.fail { background: var(--danger-light); color: var(--danger); }

.stats-actions {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .nav-links.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--primary);
        padding: 0.5rem;
        box-shadow: var(--shadow-lg);
    }
    .nav-toggle { display: block; }

    main { padding: 1.5rem 1rem 3rem; }

    .hero h1 { font-size: 1.75rem; }
    .hero-stats { flex-direction: row; gap: 0.75rem; }
    .stat-card { padding: 0.75rem 1rem; }

    .home-grid { grid-template-columns: 1fr; }

    .stats-overview { grid-template-columns: repeat(2, 1fr); }

    .flashcard-front, .flashcard-back { padding: 1.5rem; }
    .flashcard-front p { font-size: 1.05rem; }
    .flashcard-back p { font-size: 1rem; }

    .results-breakdown { grid-template-columns: 1fr; }
    .results-actions { flex-direction: column; align-items: center; }
}

@media (max-width: 480px) {
    .hero-stats { flex-direction: column; align-items: center; }
    .test-header { flex-direction: column; align-items: flex-start; }
    .chapter-card { flex-direction: column; text-align: center; }
    .chapter-num { margin: 0 auto; }
}
