/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#app {
    width: 100%;
    max-width: 1200px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-height: 600px;
    position: relative;
}


.copyright-text {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 0.75rem;
    color: #888;
    font-weight: 500;
    z-index: 10;
    user-select: none;
}

/* Screens */
.screen {
    display: none;
    padding: 30px;
}

.screen.active {
    display: block;
}

/* Setup Screen */
.setup-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 40px 20px;
}

.header-section {
    text-align: center;
    margin-bottom: 4px;
}

.header-section h1 {
    font-size: 2.2rem;
    color: #1a237e;
    margin-bottom: 0;
}

.setup-container .subtitle {
    color: #666;
    font-size: 1.1rem;
    margin-bottom: 40px;
    text-align: center;
}

.exam-config {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 30px;
    text-align: left;
}

.config-group {
    margin-bottom: 18px;
}

.config-group:last-child {
    margin-bottom: 0;
}

.config-group label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.config-group input[type="number"] {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.config-group input[type="number"]:focus {
    border-color: #1a237e;
    outline: none;
}

/* ============================================
   Question Count Group
   ============================================ */
.question-count-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 4px;
    justify-content: flex-start;
}

.use-all-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    order: 1;
}

.use-all-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #1a237e;
}

.count-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    order: 2;
    transition: opacity 0.3s ease;
}

.count-input-wrapper input[type="number"] {
    width: 70px;
    padding: 8px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    text-align: center;
    transition: border-color 0.2s, opacity 0.3s ease;
}

.count-input-wrapper input[type="number"]:focus {
    border-color: #1a237e;
    outline: none;
}

.count-input-wrapper input[type="number"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Random Questions Label
   ============================================ */
.count-label {
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.3s ease, opacity 0.3s ease;
    text-transform: none;
}

.count-label.enabled {
    color: #1a237e;
    opacity: 1;
}

.count-label.disabled {
    color: #b0b0b0;
    opacity: 0.6;
}

/* ============================================
   Shuffle Group
   ============================================ */
.shuffle-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.shuffle-group.hidden {
    display: none;
}

.shuffle-group label {
    margin-bottom: 0;
    display: inline;
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
}

.shuffle-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 0;
    cursor: pointer;
    accent-color: #1a237e;
}

/* ============================================
   Buttons
   ============================================ */
.btn-primary {
    background: #1a237e;
    color: white;
    border: none;
    padding: 14px 40px;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover {
    background: #0d1555;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 12px 32px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 20px;
    font-size: 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

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

.btn-save {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-save:hover {
    background: #5a6268;
}

.btn-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-save.locked {
    background: #9b59b6;
    cursor: not-allowed;
}

.btn-save.locked:hover {
    background: #9b59b6;
}

.btn-review {
    background: #f39c12;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-review:hover {
    background: #e67e22;
}

.btn-review:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-next {
    background: #1a237e;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-next:hover {
    background: #0d1555;
}

.btn-prev {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-prev:hover {
    background: #5a6268;
}

.info-text {
    color: #666;
    font-size: 0.9rem;
    margin-top: 12px;
}

/* ============================================
   Exam Screen
   ============================================ */
.exam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 2px solid #e9ecef;
    flex-wrap: wrap;
    gap: 12px;
}

.exam-title h2 {
    font-size: 1.2rem;
    color: #1a237e;
}

.question-counter {
    font-size: 0.9rem;
    color: #666;
    display: block;
}

.exam-timer {
    display: flex;
    align-items: center;
    gap: 16px;
}

#timer-display {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #1a237e;
    min-width: 80px;
}

#timer-display.warning {
    color: #dc3545;
}

/* Exam Body */
.exam-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 20px;
    width: 100%;
}

.question-panel {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.question-text {
    font-size: 1.1rem;
    line-height: 1.6;
    padding: 16px 0;
    color: #1a1a1a;
    word-wrap: break-word;
    word-break: break-word;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0 20px;
    width: 100%;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    width: 100%;
}

.option-item:hover {
    border-color: #1a237e;
    background: #f8f9ff;
}

.option-item input[type="radio"],
.option-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    flex-shrink: 0;
    cursor: pointer;
}

.option-item .option-label {
    font-size: 0.95rem;
    line-height: 1.6;
    cursor: pointer;
    word-wrap: break-word;
    word-break: break-word;
    flex: 1;
    min-width: 0;
    white-space: normal;
}

.option-item.selected {
    border-color: #1a237e;
    background: #e8eaf6;
}

.option-item.correct {
    border-color: #28a745;
    background: #d4edda;
}

.option-item.correct .option-label {
    color: #155724;
}

.option-item.wrong {
    border-color: #dc3545;
    background: #f8d7da;
}

.option-item.wrong .option-label {
    color: #721c24;
}

.option-item.reveal-correct {
    border-color: #28a745;
    background: #d4edda;
}

.option-item.disabled {
    pointer-events: none;
    opacity: 0.8;
}

.option-item.locked {
    pointer-events: none;
    opacity: 0.8;
}

.question-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.feedback-container {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    display: none;
}

.feedback-container.show {
    display: block;
}

.feedback-container.correct {
    background: #d4edda;
    border: 1px solid #28a745;
    color: #155724;
}

.feedback-container.wrong {
    background: #f8d7da;
    border: 1px solid #dc3545;
    color: #721c24;
}

/* Question Navigator */
.question-navigator {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    align-content: flex-start;
    margin-top: 10px;
}

.nav-btn {
    width: 36px;
    height: 36px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    border-color: #1a237e;
    background: #f0f2ff;
}

.nav-btn.active {
    border-color: #1a237e;
    background: #1a237e;
    color: white;
}

.nav-btn.answered {
    border-color: #28a745;
    background: #d4edda;
}

.nav-btn.answered-correct {
    border-color: #28a745;
    background: #28a745;
    color: white;
}

.nav-btn.answered-wrong {
    border-color: #dc3545;
    background: #dc3545;
    color: white;
}

.nav-btn.unsaved {
    background: #ffd700;
    border-color: #ffd700;
    color: #333;
}

/* Lavender color for saved/locked questions */
.nav-btn.saved-lavender {
    background: #d4a5e0;
    border-color: #9b59b6;
    color: #6c3483;
}

/* ============================================
   Results Screen
   ============================================ */
.results-container {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

.results-container h1 {
    font-size: 2rem;
    color: #1a237e;
    margin-bottom: 20px;
}

.results-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.result-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
}

.result-label {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 4px;
}

.result-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a237e;
}

.results-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
}

.review-container {
    margin-top: 24px;
    text-align: left;
}

.review-container.hidden {
    display: none;
}

.review-item {
    padding: 16px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.review-item:hover {
    background: #f8f9fa;
}

.review-item .q-text {
    font-weight: 600;
    margin-bottom: 6px;
}

.review-item .q-result {
    font-size: 0.9rem;
}

.review-item .q-result.correct {
    color: #28a745;
}

.review-item .q-result.wrong {
    color: #dc3545;
}

.review-item .expand-text {
    font-size: 0.8rem;
    color: #888;
    margin-left: 10px;
    cursor: pointer;
}

.review-item .q-answer-detail {
    display: none;
    margin-top: 10px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.6;
}

.review-item .q-answer-detail.show {
    display: block;
}

.review-item .q-answer-detail .explanation {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #dee2e6;
    font-style: italic;
    color: #555;
}

/* ============================================
   Topic Tabs
   ============================================ */
.topic-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 0;
}

.topic-tab {
    padding: 8px 14px;
    border: 2px solid #dee2e6;
    border-radius: 20px;
    background: white;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: #495057;
    transition: all 0.2s;
    white-space: nowrap;
}

.topic-tab:hover {
    border-color: #1a237e;
    background: #f8f9ff;
}

.topic-tab.active {
    border-color: #1a237e;
    background: #1a237e;
    color: white;
}

.topic-tab .topic-count {
    font-weight: 400;
    font-size: 0.75rem;
    opacity: 0.7;
}

.topic-tab.active .topic-count {
    opacity: 1;
}

/* ============================================
   Range Selector
   ============================================ */
#range-container {
    display: block;
}

#range-container.hidden {
    display: none;
}

.range-selector {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 16px 20px;
    margin-top: 6px;
}

.range-inputs {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.range-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-field label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.range-field input[type="number"] {
    width: 70px;
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    text-align: center;
    transition: border-color 0.2s;
}

.range-field input[type="number"]:focus {
    border-color: #1a237e;
    outline: none;
}

.range-slider-container {
    position: relative;
    padding: 8px 0;
}

.range-slider-container input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: transparent;
    border-radius: 2px;
    outline: none;
    position: absolute;
    pointer-events: none;
}

.range-slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #1a237e;
    cursor: pointer;
    pointer-events: auto;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.15s;
}

.range-slider-container input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.range-slider-container input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #1a237e;
    cursor: pointer;
    pointer-events: auto;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#range-slider-start {
    z-index: 2;
}

#range-slider-end {
    z-index: 1;
}

.range-track-overlay {
    position: absolute;
    height: 4px;
    background: #1a237e;
    border-radius: 2px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 0;
    pointer-events: none;
}

.range-track {
    display: flex;
    justify-content: space-between;
    padding-top: 30px;
    font-size: 0.8rem;
    color: #888;
}

.range-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.range-info strong {
    color: #1a237e;
    font-size: 1.1rem;
}

.range-hint {
    font-size: 0.85rem;
    color: #6c757d;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .exam-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .exam-timer {
        justify-content: space-between;
    }

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

    .question-navigator {
        max-height: 200px;
        width: 100%;
        min-width: unset;
    }

    .question-actions {
        justify-content: center;
    }

    .setup-container h1 {
        font-size: 1.6rem;
    }

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

    .topic-tabs {
        flex-wrap: wrap;
    }
    .topic-tab {
        font-size: 0.75rem;
        padding: 6px 10px;
    }
    .range-inputs {
        flex-direction: row;
        justify-content: center;
    }
    .range-info {
        flex-direction: column;
        text-align: center;
    }
    .range-field input[type="number"] {
        width: 60px;
    }
    .shuffle-group {
        flex-wrap: wrap;
        gap: 8px;
    }
    .question-count-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

@media (max-width: 480px) {
    .topic-tab {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    .question-text {
        font-size: 0.95rem;
    }
    .option-item .option-label {
        font-size: 0.85rem;
    }
    .nav-btn {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }
    .shuffle-group label {
        font-size: 0.8rem;
    }
    .shuffle-group input[type="checkbox"] {
        width: 16px;
        height: 16px;
    }
    .question-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .question-actions button {
        width: 100%;
        justify-content: center;
    }
}
