* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --warning-color: #ea580c;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
}

.header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Card */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.card h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #15803d;
}

.btn-large {
    width: 100%;
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--border-color);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Screens */
.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Test Header */
.test-header {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.test-progress {
    flex: 1;
}

.progress-bar {
    height: 12px;
    background: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.test-timer {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    font-family: monospace;
}

.test-timer.warning {
    color: var(--warning-color);
    animation: pulse 1s infinite;
}

.test-timer.danger {
    color: var(--danger-color);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.test-points {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Question Card */
.question-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.question-code {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.question-points {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-color);
    background: #eff6ff;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
}

.question-media {
    margin-bottom: 1.5rem;
    text-align: center;
}

.question-media img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.question-text {
    font-size: 1.2rem;
    line-height: 1.8;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.question-category {
    background: #f0f9ff;
    border-left: 3px solid var(--primary-color);
    padding: 0.75rem 1rem;
    margin-bottom: 2rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.question-category strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
}

/* Answers */
.answers {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.answer-option {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.answer-option:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
    transform: translateX(4px);
}

.answer-option.selected {
    border-color: var(--primary-color);
    background: #dbeafe;
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.answer-option.correct {
    border-color: var(--success-color);
    background: #f0fdf4;
}

.answer-option.incorrect {
    border-color: var(--danger-color);
    background: #fef2f2;
}

.answer-option.disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.answer-radio {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.answer-option.selected .answer-radio {
    border-color: var(--primary-color);
    background: var(--primary-color);
    position: relative;
}

.answer-option.selected .answer-radio::after {
    content: '✓';
    color: white;
    font-weight: bold;
    font-size: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}

.answer-option.correct .answer-radio {
    border-color: var(--success-color);
    background: var(--success-color);
    position: relative;
}

.answer-option.correct .answer-radio::after {
    content: '✓';
    color: white;
    font-weight: bold;
    font-size: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}

.answer-option.incorrect .answer-radio {
    border-color: var(--danger-color);
    background: var(--danger-color);
    position: relative;
}

.answer-option.incorrect .answer-radio::after {
    content: '✗';
    color: white;
    font-weight: bold;
    font-size: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}

.answer-text {
    flex: 1;
    font-size: 1rem;
    line-height: 1.6;
}

.answer-media {
    margin-top: 0.5rem;
}

.answer-media img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 6px;
}

/* Question Actions */
.question-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.question-actions .btn {
    flex: 1;
    min-width: 120px;
}

/* Question Navigator */
.question-navigator {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.navigator-title {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.question-nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 0.5rem;
}

.nav-question-btn {
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.nav-question-btn:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.nav-question-btn.answered {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.nav-question-btn.current {
    border-width: 3px;
    border-color: var(--warning-color);
}

/* Results */
.results-summary {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.result-summary-text {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.result-progress-container {
    margin: 2rem 0;
}

.result-progress-bar {
    height: 40px;
    background: var(--border-color);
    border-radius: 8px;
    position: relative;
    overflow: visible;
    margin-bottom: 0.5rem;
}

.result-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #16a34a);
    border-radius: 8px;
    transition: width 1s ease;
    position: relative;
}

.result-progress-fill.failed {
    background: linear-gradient(90deg, var(--danger-color), #dc2626);
}

.result-progress-threshold {
    position: absolute;
    left: 85%;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--warning-color);
    z-index: 2;
}

.result-progress-threshold::before {
    content: '85%';
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--warning-color);
}

.result-progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.result-progress-labels span:nth-child(2) {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.result-question-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.result-overview-item {
    aspect-ratio: 1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    border: 2px solid;
}

.result-overview-item.correct {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.result-overview-item.incorrect {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

.result-status {
    margin-bottom: 2rem;
}

.result-badge {
    display: inline-block;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: 700;
}

.result-badge.passed {
    background: var(--success-color);
    color: white;
}

.result-badge.failed {
    background: var(--danger-color);
    color: white;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
}

.result-stat {
    padding: 1rem;
}

.result-stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.result-stat-value.correct {
    color: var(--success-color);
}

.result-stat-value.incorrect {
    color: var(--danger-color);
}

.result-stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Results Details */
.results-details {
    margin-bottom: 2rem;
}

.results-details h2 {
    margin-bottom: 1.5rem;
}

.result-item {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--border-color);
}

.result-item.correct {
    border-left-color: var(--success-color);
    background: #f0fdf4;
}

.result-item.incorrect {
    border-left-color: var(--danger-color);
    background: #fef2f2;
}

.result-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-item-status {
    font-weight: 600;
    font-size: 0.9rem;
}

.result-item-status.correct {
    color: var(--success-color);
}

.result-item-status.incorrect {
    color: var(--danger-color);
}

.result-question {
    font-weight: 600;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.result-answers {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.result-answer {
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.95rem;
}

.result-answer.user-selected {
    background: #eff6ff;
    border: 2px solid var(--primary-color);
}

.result-answer.correct-answer {
    background: #f0fdf4;
    border: 2px solid var(--success-color);
    font-weight: 600;
}

.result-answer.user-selected.incorrect {
    background: #fef2f2;
    border: 2px solid var(--danger-color);
}

.result-explanation {
    background: #fefce8;
    border-left: 3px solid var(--warning-color);
    padding: 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.result-explanation strong {
    display: block;
    margin-bottom: 0.5rem;
}

/* Results Actions */
.results-actions {
    display: flex;
    gap: 1rem;
}

.results-actions .btn {
    flex: 1;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: white;
    margin-top: 1rem;
    font-size: 1.2rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .test-header {
        flex-direction: column;
        gap: 1rem;
    }

    .question-card {
        padding: 1.5rem;
    }

    .question-text {
        font-size: 1.1rem;
    }

    .results-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .results-actions {
        flex-direction: column;
    }

    .question-actions {
        flex-direction: column;
    }

    .question-actions .btn {
        width: 100%;
    }
}
