/* ==========================================================================
   AESTHETIC SYSTEM & DESIGN TOKENS
   Concept: "Modern Archive" 
   - Không lạm dụng màu sắc sặc sỡ, dùng tone đất (terracotta/brick) làm điểm nhấn.
   - Typography: Lora (Serif) cho cảm giác lịch sử, Outfit (Sans-serif) cho UI.
   ========================================================================== */

   :root {
    /* TYPOGRAPHY */
    --font-serif: 'Lora', Georgia, serif;
    --font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
    
    /* LIGHT MODE (Parchment & Ink) */
    --bg-main: #f5f4f0;       /* Giấy da cũ, ấm nhẹ */
    --bg-surface: #ffffff;    /* Khối nội dung nổi bật */
    --text-primary: #1c1d1a;  /* Mực đen hơi ám xanh rêu */
    --text-secondary: #6b6a65;
    --border-subtle: #e6e4dc;
    --border-strong: #d1cfc7;
    
    --accent: #b44d33;        /* Đỏ gạch nung (Terracotta) */
    --accent-hover: #963d26;
    --accent-light: #fbeae5;
    
    --success: #3c7d58;
    --success-light: #e6f4ea;
    --error: #b44d33;
    
    --shadow-sm: 0 2px 8px -2px rgba(28, 29, 26, 0.05), 0 1px 4px -1px rgba(28, 29, 26, 0.03);
    --shadow-md: 0 8px 24px -4px rgba(28, 29, 26, 0.08), 0 4px 10px -2px rgba(28, 29, 26, 0.04);
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    --transition: 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-theme="dark"] {
    /* DARK MODE (Night Archive) */
    --bg-main: #0c0d0f;       /* Đen sâu */
    --bg-surface: #15171a;    /* Xám tối */
    --text-primary: #e6e7eb;
    --text-secondary: #8b9098;
    --border-subtle: #25282d;
    --border-strong: #373b43;
    
    --accent: #df6e52;        /* Đỏ gạch sáng hơn cho Darkmode */
    --accent-hover: #e88d75;
    --accent-light: #3d231e;
    
    --success: #4ebf7c;
    --success-light: #183825;
    
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   RESET & GLOBAL
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   HEADER & NAVIGATION
   ========================================================================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem;
    position: sticky;
    top: 0;
    background-color: rgba(var(--bg-main), 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    border-bottom: 1px solid var(--border-subtle);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent);
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

.brand span {
    font-family: var(--font-sans);
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 1rem;
}

.nav-tabs {
    display: flex;
    background-color: var(--bg-surface);
    padding: 0.25rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
}

.nav-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition);
}

.nav-btn i {
    width: 16px;
    height: 16px;
}

.nav-btn:hover {
    color: var(--text-primary);
}

.nav-btn.active {
    background-color: var(--bg-main);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.icon-btn:hover {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

/* Theme Toggle logic */
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* ==========================================================================
   MAIN CONTENT VIEWS
   ========================================================================== */
.app-main {
    flex: 1;
    padding: 2rem 1.5rem;
}

.view-section {
    display: none;
    animation: fadeIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   VIEW 1: REVISION (Kho Lưu Trữ)
   ========================================================================== */
.section-header {
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
}

.search-bar {
    margin-top: 1.5rem;
    position: relative;
}

.search-bar i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    width: 20px;
}

.search-bar input {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-light);
}

.revision-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.qa-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}

.qa-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.qa-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: var(--success-light);
    color: var(--success);
    margin-bottom: 1rem;
}

.qa-badge.essay {
    background-color: var(--accent-light);
    color: var(--accent);
}

.q-text {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    font-family: var(--font-serif);
}

.a-text {
    color: var(--text-secondary);
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.correct-indicator {
    color: var(--success);
    margin-top: 2px;
}

/* ==========================================================================
   VIEW 2: SETUP TEST
   ========================================================================== */
.setup-container {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    max-width: 600px;
    margin: 0 auto;
}

.setup-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.setup-header h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.form-group input[type="number"] {
    width: 100%;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.125rem;
    font-weight: 600;
}

.form-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.options-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.custom-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all var(--transition);
}

.custom-checkbox:hover {
    background-color: var(--bg-main);
}

.custom-checkbox input {
    display: none;
}

.checkmark {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 2px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: all var(--transition);
    flex-shrink: 0;
    margin-top: 2px;
}

.custom-checkbox input:checked + .checkmark {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

.checkmark i {
    width: 14px;
    height: 14px;
}

.checkbox-text strong {
    display: block;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.checkbox-text span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.btn-primary {
    width: 100%;
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 1.125rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color var(--transition), transform var(--transition);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
}

/* ==========================================================================
   VIEW 3: TESTING ENVIRONMENT
   ========================================================================== */
.test-environment {
    max-width: 700px;
    margin: 0 auto;
}

.test-header {
    margin-bottom: 2rem;
}

.progress-container {
    background-color: var(--bg-surface);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.question-counter {
    font-weight: 600;
    color: var(--text-primary);
}

.timer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.progress-bar-bg {
    height: 6px;
    background-color: var(--border-subtle);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--accent);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

.question-container {
    margin-bottom: 2rem;
}

.q-type-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    display: block;
    margin-bottom: 1rem;
}

.testing-q-text {
    font-size: 1.75rem;
    margin-bottom: 2.5rem;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.option-btn {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    width: 100%;
    padding: 1.25rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
}

.option-btn:hover {
    border-color: var(--border-strong);
    background-color: var(--bg-main);
}

.option-btn.selected {
    border-color: var(--accent);
    background-color: var(--accent-light);
    box-shadow: 0 0 0 1px var(--accent);
}

.opt-letter {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-main);
    border-radius: 6px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    border: 1px solid var(--border-subtle);
    transition: all var(--transition);
}

.option-btn.selected .opt-letter {
    background-color: var(--accent);
    color: white;
    border-color: var(--accent);
}

.opt-text {
    font-family: var(--font-sans);
    font-size: 1.125rem;
    color: var(--text-primary);
}

.test-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.btn-outline {
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    padding: 1.125rem 2rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-outline:hover {
    background-color: var(--bg-surface);
    border-color: var(--text-primary);
}

.btn-danger {
    background-color: var(--error);
    color: white;
    border: none;
    padding: 1.125rem 2rem;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger:hover {
    opacity: 0.9;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   VIEW 4: RESULT
   ========================================================================== */
.result-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.score-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.score-circle {
    width: 160px;
    height: 160px;
    margin: 0 auto 2rem;
}

.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 250px;
}

.circle-bg {
    fill: none;
    stroke: var(--border-subtle);
    stroke-width: 2.5;
}

.circle {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke: var(--success);
    animation: progress 1s ease-out forwards;
}

@keyframes progress {
    0% { stroke-dasharray: 0 100; }
}

.percentage {
    fill: var(--text-primary);
    font-family: var(--font-serif);
    font-size: 0.5em;
    text-anchor: middle;
    font-weight: 700;
}

.score-card h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.score-card p {
    color: var(--text-secondary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-box {
    background-color: var(--bg-surface);
    padding: 1.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.stat-box i {
    color: var(--accent);
}

.stat-data {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Mobile First considerations up to Desktop)
   ========================================================================== */
@media (max-width: 600px) {
    /* Header & Layout */
    .app-header {
        flex-wrap: wrap;
        gap: 1rem;
        padding: 1rem;
    }
    .app-main {
        padding: 1.5rem 1rem;
    }
    .nav-tabs {
        order: 3;
        width: 100%;
        justify-content: space-between;
    }
    .nav-btn {
        flex: 1;
        justify-content: center;
    }

    /* Typography */
    .section-header h2, .setup-header h2, .score-card h2 {
        font-size: 1.5rem;
    }
    .testing-q-text {
        font-size: 1.35rem;
        margin-bottom: 1.5rem;
    }

    /* Setup View */
    .setup-container {
        padding: 1.5rem 1rem;
    }

    /* Testing View - MCQ */
    .option-btn {
        padding: 1rem;
        gap: 0.75rem;
    }
    .opt-text {
        font-size: 1rem;
    }

    /* Testing View - T/F */
    .tf-statement {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1rem;
    }
    .tf-actions {
        width: 100%;
        justify-content: flex-end;
    }
    .tf-toggle-btn {
        flex: 1;
        text-align: center;
    }

    /* Testing View - Footer */
    .test-footer {
        flex-direction: column;
    }
    .test-footer button {
        width: 100%;
        justify-content: center;
    }

    /* Result View */
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .result-actions {
        flex-direction: column;
    }
}

/* ==========================================================================
   SCROLLABLE TEST UI & T/F BUTTONS
   ========================================================================== */
.questions-list {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-bottom: 2rem;
}

.question-item {
    background-color: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.tf-statement {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-main);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-subtle);
    gap: 1.5rem;
}

.tf-statement p {
    flex: 1;
    margin: 0;
    color: var(--text-primary);
    line-height: 1.5;
}

.tf-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.tf-toggle-btn {
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--border-strong);
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
}

.tf-toggle-btn:hover:not(:disabled) {
    background-color: var(--bg-main);
}

.tf-toggle-btn.selected.true {
    background-color: var(--success-light);
    color: var(--success);
    border-color: var(--success);
}

.tf-toggle-btn.selected.false {
    background-color: var(--accent-light);
    color: var(--error);
    border-color: var(--error);
}

.tf-toggle-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.essay-textarea {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
    font-size: 1rem;
    line-height: 1.5;
    margin-top: 1rem;
}

.essay-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.review-feedback {
    margin-top: 1.5rem;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    background-color: var(--bg-main);
    border-left: 4px solid var(--accent);
}

.review-feedback h4 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.correct-highlight {
    background: var(--success-light) !important;
    border-color: var(--success) !important;
}

.incorrect-highlight {
    background: var(--accent-light) !important;
    border-color: var(--error) !important;
}