/* ==========================================================================
   SP Exam Quiz — Public Styles
   Mobile-first · BEM · Scoped under .sp-exam
   Design adapted from sp-psych-quiz
   ========================================================================== */

/* ---------- Reset & Custom Properties ---------- */

.sp-exam {
    --_primary: var(--sp-exam-primary, #4A6FA5);
    --_primary-rgb: var(--sp-exam-primary-rgb, 74, 111, 165);
    --_primary-light: rgba(var(--_primary-rgb), 0.08);
    --_primary-hover: rgba(var(--_primary-rgb), 0.12);
    --_primary-focus: rgba(var(--_primary-rgb), 0.2);
    --_text: #1a1a1a;
    --_text-secondary: #555;
    --_text-muted: #888;
    --_bg: #fff;
    --_border: #e2e2e2;
    --_radius: 12px;
    --_radius-sm: 8px;
    --_transition: 300ms ease;

    position: relative;
    max-width: 100%;
    margin: 2rem auto;
    background: var(--_bg);
    border: 1px solid #f59e0b;
    border-radius: var(--_radius);
    overflow: hidden;
    color: var(--_text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.sp-exam *,
.sp-exam *::before,
.sp-exam *::after {
    box-sizing: border-box;
}

/* ---------- Progress Bar ---------- */

.sp-exam__progress {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 4px;
    background: rgba(var(--_primary-rgb), 0.1);
}

.sp-exam__progress-bar {
    height: 100%;
    width: 0;
    background: var(--_primary);
    border-radius: 0 2px 2px 0;
    transition: width 400ms ease;
}

/* ---------- Screens ---------- */

.sp-exam__screen {
    display: none;
    padding: 24px 20px 28px;
}

.sp-exam__screen--active {
    display: block;
    animation: sp-exam-fade-in var(--_transition) forwards;
}

.sp-exam__screen--from-right.sp-exam__screen--active {
    animation-name: sp-exam-slide-right;
}

.sp-exam__screen--from-left.sp-exam__screen--active {
    animation-name: sp-exam-slide-left;
}

@keyframes sp-exam-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes sp-exam-slide-right {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes sp-exam-slide-left {
    from { opacity: 0; transform: translateX(-30px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---------- Intro Screen ---------- */

.sp-exam__title {
    margin: 0 0 16px;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--_text);
}

.sp-exam__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--_text-secondary);
}

.sp-exam__meta-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sp-exam__icon {
    flex-shrink: 0;
    color: var(--_text-muted);
}

.sp-exam__description {
    margin-bottom: 20px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--_text-secondary);
}

.sp-exam__description p {
    margin: 0 0 12px;
}

.sp-exam__description p:last-child {
    margin-bottom: 0;
}

.sp-exam__timer-info {
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    border-radius: 0 var(--_radius-sm) var(--_radius-sm) 0;
    font-size: 14px;
    color: #92400e;
}

/* ---------- Buttons ---------- */

.sp-exam__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 32px;
    border: 2px solid transparent;
    border-radius: var(--_radius-sm);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--_transition), border-color var(--_transition), opacity var(--_transition);
    -webkit-tap-highlight-color: transparent;
}

.sp-exam__btn:focus-visible {
    outline: 3px solid rgba(var(--_primary-rgb), 0.5);
    outline-offset: 2px;
}

.sp-exam__btn--primary {
    width: 100%;
    background: var(--_primary);
    color: #fff;
    border-color: var(--_primary);
}

.sp-exam__btn--primary:hover {
    background: rgba(var(--_primary-rgb), 0.85);
}

.sp-exam__btn--primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sp-exam__btn--secondary {
    background: transparent;
    color: var(--_text-secondary);
    border-color: var(--_border);
}

.sp-exam__btn--secondary:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

.sp-exam__start-btn {
    margin-top: 8px;
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
    font-size: 20px;
}

.sp-exam__start-btn:hover {
    background: #15803d;
    border-color: #15803d;
}

.sp-exam__next-btn {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.sp-exam__next-btn:hover {
    background: #15803d;
    border-color: #15803d;
}

/* ---------- Page Header ---------- */

.sp-exam__page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.sp-exam__page-counter {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--_primary);
}

.sp-exam__timer-display {
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--_primary);
    padding: 4px 12px;
    background: var(--_primary-light);
    border-radius: var(--_radius-sm);
}

.sp-exam__timer-display--warning {
    color: #dc2626;
    background: #fef2f2;
    animation: sp-exam-pulse 1s ease infinite;
}

@keyframes sp-exam-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ---------- Page Progress ---------- */

.sp-exam__page-progress {
    height: 4px;
    background: rgba(var(--_primary-rgb), 0.1);
    border-radius: 2px;
    margin-bottom: 20px;
    overflow: hidden;
}

.sp-exam__page-progress-bar {
    height: 100%;
    background: var(--_primary);
    border-radius: 2px;
    width: 0;
    transition: width 400ms ease;
}

/* ---------- Mobile Question Counter ---------- */

.sp-exam__mobile-q-counter {
    display: none;
    text-align: center;
    font-size: 14px;
    color: var(--_text-muted);
    margin-bottom: 12px;
}

/* ---------- Question Cards ---------- */

.sp-exam__question-card {
    padding: 0 0 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--_border);
}

.sp-exam__question-card:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.sp-exam__question-text {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--_text);
}

.sp-exam__question-number {
    font-weight: 700;
    color: var(--_primary);
}

.sp-exam__question-marks {
    font-size: 13px;
    font-weight: 400;
    color: var(--_text-muted);
    margin-left: 4px;
}

/* ---------- Option Buttons ---------- */

.sp-exam__options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sp-exam__option-btn {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    gap: 12px;
    background: var(--_bg) !important;
    border: 1.5px solid var(--_border);
    border-radius: var(--_radius-sm);
    font-size: 15px;
    font-family: inherit;
    color: var(--_text) !important;
    text-align: left;
    cursor: pointer;
    transition: all 200ms ease;
    -webkit-tap-highlight-color: transparent;
}

.sp-exam__option-btn:hover,
.sp-exam__option-btn:focus {
    border-color: var(--_primary);
    background: var(--_primary-light) !important;
    color: var(--_text) !important;
}

.sp-exam__option-btn:focus-visible {
    outline: 3px solid rgba(var(--_primary-rgb), 0.5);
    outline-offset: 2px;
}

.sp-exam__option-btn--selected {
    border-color: var(--_primary);
    background: var(--_primary-light) !important;
    color: var(--_primary) !important;
    font-weight: 600;
}

.sp-exam__option-btn--correct {
    border-color: #059669 !important;
    background: #ecfdf5 !important;
    color: #065f46 !important;
    font-weight: 600;
}

.sp-exam__option-btn--correct .sp-exam__option-letter {
    background: #059669;
    color: #fff;
}

.sp-exam__option-btn--wrong {
    border-color: #dc2626 !important;
    background: #fef2f2 !important;
    color: #991b1b !important;
    font-weight: 600;
}

.sp-exam__option-btn--wrong .sp-exam__option-letter {
    background: #dc2626;
    color: #fff;
}

.sp-exam__question-card--locked .sp-exam__option-btn {
    pointer-events: none;
    opacity: 0.85;
}

.sp-exam__question-card--locked .sp-exam__option-btn--correct,
.sp-exam__question-card--locked .sp-exam__option-btn--wrong {
    opacity: 1;
}

.sp-exam__option-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(var(--_primary-rgb), 0.08);
    font-weight: 700;
    font-size: 13px;
    color: var(--_text-muted);
    flex-shrink: 0;
    transition: all 200ms ease;
}

.sp-exam__option-btn--selected .sp-exam__option-letter {
    background: var(--_primary);
    color: #fff;
}

.sp-exam__option-text {
    flex: 1;
}

/* ---------- Multiple Select ---------- */

.sp-exam__ms-instruction {
    font-size: 13px;
    font-style: italic;
    color: var(--_text-muted);
    margin: -6px 0 10px;
}

/* ---------- Navigation ---------- */

.sp-exam__nav {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.sp-exam__prev-btn {
    flex: 0 0 auto;
    min-width: 90px;
}

.sp-exam__next-btn {
    flex: 1;
}

/* ---------- Open Response ---------- */

.sp-exam__open-textarea {
    display: block;
    width: 100%;
    min-height: 6em;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.6;
    color: var(--_text);
    background: var(--_bg);
    border: 1.5px solid var(--_border);
    border-radius: var(--_radius-sm);
    resize: vertical;
    transition: border-color 200ms ease;
    box-sizing: border-box;
    margin-bottom: 12px;
    -webkit-appearance: none;
}

.sp-exam__open-textarea:focus {
    outline: none;
    border-color: var(--_primary);
    box-shadow: 0 0 0 3px rgba(var(--_primary-rgb), 0.15);
}

.sp-exam__reveal-btn {
    margin-bottom: 12px;
}

.sp-exam__open-model {
    background: var(--_primary-light);
    border-left: 3px solid var(--_primary);
    border-radius: 0 var(--_radius-sm) var(--_radius-sm) 0;
    padding: 16px 20px;
    margin-bottom: 12px;
}

.sp-exam__open-model-heading {
    font-size: 15px;
    font-weight: 700;
    color: var(--_text);
    margin: 0 0 6px;
}

.sp-exam__open-model-heading:not(:first-child) {
    margin-top: 14px;
}

.sp-exam__open-model-text {
    font-size: 14px;
    color: var(--_text-secondary);
    line-height: 1.7;
}

.sp-exam__open-model-text p {
    margin: 0 0 8px;
}

.sp-exam__open-model-text p:last-child {
    margin-bottom: 0;
}

/* ---------- Self Rate ---------- */

.sp-exam__self-rate {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    border-radius: 0 var(--_radius-sm) var(--_radius-sm) 0;
    margin-bottom: 8px;
}

.sp-exam__self-rate-label {
    font-size: 14px;
    font-weight: 600;
    color: #92400e;
}

.sp-exam__self-rate-input {
    width: 56px;
    padding: 6px 8px;
    font-size: 15px;
    text-align: center;
    border: 1.5px solid var(--_border);
    border-radius: 6px;
    background: var(--_bg);
    font-family: inherit;
}

.sp-exam__self-rate-input:focus {
    outline: none;
    border-color: var(--_primary);
    box-shadow: 0 0 0 3px rgba(var(--_primary-rgb), 0.15);
}

.sp-exam__self-rate-max {
    font-size: 14px;
    color: var(--_text-muted);
}

.sp-exam__self-rate-confirm {
    padding: 8px 20px;
    font-size: 14px;
    min-height: 36px;
}

/* ---------- Answered Card ---------- */

.sp-exam__question-card--answered {
    /* Subtle left accent when answered */
}

/* ---------- Loading Screen ---------- */

.sp-exam__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    text-align: center;
    color: var(--_text-secondary);
}

.sp-exam__spinner {
    width: 40px;
    height: 40px;
    margin-bottom: 16px;
    border: 3px solid rgba(var(--_primary-rgb), 0.2);
    border-top-color: var(--_primary);
    border-radius: 50%;
    animation: sp-exam-spin 0.8s linear infinite;
}

@keyframes sp-exam-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Results Screen ---------- */

.sp-exam__result-header {
    text-align: center;
    margin-bottom: 28px;
}

.sp-exam__result-score-ring {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid var(--_primary);
    margin-bottom: 12px;
}

.sp-exam__result-percent {
    font-size: 28px;
    font-weight: 800;
    color: var(--_primary);
}

.sp-exam__result-title {
    margin: 0 0 6px;
    font-size: 24px;
    font-weight: 700;
    color: var(--_primary);
    line-height: 1.3;
}

.sp-exam__result-summary {
    margin: 0;
    font-size: 16px;
    line-height: 1.6;
    color: var(--_text-secondary);
}

.sp-exam__result-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--_radius-sm);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
}

.sp-exam__result-status--pass {
    background: #ecfdf5;
    color: #065f46;
}

.sp-exam__result-status--fail {
    background: #fef2f2;
    color: #991b1b;
}

.sp-exam__result-status-icon {
    font-size: 20px;
}

.sp-exam__result-message {
    padding: 16px 20px;
    background: var(--_primary-light);
    border-left: 3px solid var(--_primary);
    border-radius: 0 var(--_radius-sm) var(--_radius-sm) 0;
    margin-bottom: 20px;
    color: var(--_text-secondary);
    line-height: 1.7;
    font-size: 15px;
}

.sp-exam__result-time {
    text-align: center;
    font-size: 14px;
    color: var(--_text-muted);
    margin-bottom: 24px;
}

.sp-exam__result-time-exceeded {
    color: #dc2626;
    font-weight: 600;
}

/* ---------- Answer Review ---------- */

.sp-exam__review {
    margin-bottom: 28px;
}

.sp-exam__review-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--_text);
    margin: 0 0 16px;
}

.sp-exam__review-item {
    border: 1px solid var(--_border);
    border-radius: var(--_radius);
    padding: 16px;
    margin-bottom: 12px;
    border-left: 4px solid;
}

.sp-exam__review-item--correct {
    border-left-color: #059669;
    background: #f0fdf4;
}

.sp-exam__review-item--wrong {
    border-left-color: #dc2626;
    background: #fef2f2;
}

.sp-exam__review-question {
    font-weight: 600;
    color: var(--_text);
    margin: 0 0 10px;
    line-height: 1.5;
}

.sp-exam__review-num {
    color: var(--_primary);
}

.sp-exam__review-option {
    padding: 6px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    font-size: 15px;
    color: var(--_text-secondary);
}

.sp-exam__review-option--correct {
    background: #d1fae5;
    font-weight: 600;
    color: #065f46;
}

.sp-exam__review-option--chosen-wrong {
    background: #fee2e2;
    color: #991b1b;
    text-decoration: line-through;
}

.sp-exam__review-option--chosen-correct {
    background: #d1fae5;
    font-weight: 600;
    color: #065f46;
}

.sp-exam__review-option--correct-missed {
    background: #d1fae5;
    color: #065f46;
    opacity: 0.65;
    font-weight: 600;
}

.sp-exam__review-option-letter {
    font-weight: 700;
    margin-right: 4px;
}

.sp-exam__review-explanation {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--_primary-light);
    border-radius: 6px;
    font-size: 14px;
    color: var(--_text-secondary);
    line-height: 1.6;
}

/* ---------- Review — Open Response ---------- */

.sp-exam__review-open {
    margin-top: 8px;
}

.sp-exam__review-open-response,
.sp-exam__review-open-model,
.sp-exam__review-open-scheme {
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--_text-secondary);
}

.sp-exam__review-open-response {
    background: #f5f5f5;
}

.sp-exam__review-open-response p {
    margin: 4px 0 0;
    white-space: pre-wrap;
}

.sp-exam__review-open-model {
    background: var(--_primary-light);
}

.sp-exam__review-open-model p {
    margin: 4px 0 0;
}

.sp-exam__review-open-scheme {
    background: #fef3c7;
}

.sp-exam__review-open-scheme p {
    margin: 4px 0 0;
}

.sp-exam__review-open-score {
    padding: 8px 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--_primary);
}

/* ---------- Retake Button ---------- */

.sp-exam__retake-btn {
    width: 100%;
    margin-top: 8px;
}

/* ---------- Error State ---------- */

.sp-exam__error {
    text-align: center;
    padding: 32px 0;
    color: var(--_text-secondary);
}

.sp-exam__error p {
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.6;
}

/* ---------- Small screens (max-width: 400px) ---------- */

@media (max-width: 400px) {
    .sp-exam__screen {
        padding: 20px 16px 24px;
    }

    .sp-exam__nav {
        flex-direction: column-reverse;
    }

    .sp-exam__prev-btn {
        min-width: auto;
        width: 100%;
    }
}

/* ---------- Mobile (max-width: 639px) ---------- */

@media (max-width: 639px) {
    .sp-exam__mobile-q-counter {
        display: block;
    }

    .sp-exam__question-card {
        display: none;
    }

    .sp-exam__question-card--active {
        display: block;
        animation: sp-exam-slide-right 250ms ease;
    }

    .sp-exam__question-card[data-question-type="open_response"] {
        display: block;
    }

    .sp-exam__open-textarea {
        width: 100%;
        min-height: 8em;
    }

    .sp-exam__self-rate {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sp-exam__nav {
        flex-direction: column;
    }

    .sp-exam__btn {
        width: 100%;
    }
}

/* ---------- Desktop (min-width: 640px) ---------- */

@media (min-width: 640px) {
    .sp-exam__screen {
        padding: 32px 40px 36px;
    }

    .sp-exam__title {
        font-size: 28px;
    }

    .sp-exam__question-text {
        font-size: 18px;
    }

    .sp-exam__option-btn {
        padding: 14px 20px;
    }
}
