/**
 * English Test Plugin CSS — v0.3.0
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Base ──────────────────────────────────────────────────────────────── */

#english-test-app {
    max-width: 760px;
    margin: 32px auto;
    padding: 40px;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.65;
    color: #334155;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 32px rgba(0, 0, 0, .08), 0 1px 4px rgba(0, 0, 0, .04);

    /* Fade-out for transitions */
    transition: opacity 0.2s ease;
}

#english-test-app.fade-out {
    opacity: 0;
}

#english-test-app h2 {
    color: #0f172a;
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px;
}

/* ─── Loading spinner ───────────────────────────────────────────────────── */

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 14px;
    gap: 16px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e8f0;
    border-top-color: #4d77cc;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ─── Registration form ─────────────────────────────────────────────────── */

.english-test-form {
    padding: 0;
}

.form-subtitle {
    color: #64748b;
    margin: 0 0 28px;
    font-size: 14px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-group {
    flex: 1;
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.required {
    color: #ef4444;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    color: #1e293b;
    background: #f8fafc;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-group input:focus {
    border-color: #4d77cc;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

.form-group input::placeholder {
    color: #94a3b8;
}

/* ─── Briefing ──────────────────────────────────────────────────────────── */

.english-test-briefing {
    padding: 0;
}

.english-test-briefing p {
    color: #475569;
    margin: 0 0 20px;
}

.briefing-list {
    list-style: none;
    padding: 0;
    margin: 0 0 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.briefing-list li {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 18px;
}

.briefing-num {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    background: #4d77cc;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 1px;
}

.briefing-note {
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    color: #78350f;
    margin-bottom: 20px !important;
}

.opt-in-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    color: #334155;
    cursor: pointer;
    margin-bottom: 24px;
    transition: border-color 0.15s, background 0.15s;
}

.opt-in-label:hover {
    border-color: #c7d2fe;
    background: #f1f5f9;
}

.opt-in-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: #4d77cc;
    cursor: pointer;
}

/* ─── Step indicator ────────────────────────────────────────────────────── */

.step-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    margin-bottom: 28px;
}

.step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
    gap: 6px;
}

.step-item:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 14px;
    left: calc(50% + 18px);
    right: calc(-50% + 18px);
    height: 2px;
    background: #e2e8f0;
}

.step-item.completed:not(:last-child)::after {
    background: #4d77cc;
}

.step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #94a3b8;
    font-size: 12px;
    font-weight: 700;
    z-index: 1;
    transition: background 0.2s, color 0.2s;
}

.step-item.active .step-num {
    background: #4d77cc;
    color: #fff;
}

.step-item.completed .step-num {
    background: #10b981;
    color: #fff;
}

.step-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.step-item.active .step-label {
    color: #4d77cc;
}

.step-item.completed .step-label {
    color: #10b981;
}

/* ─── Progress bar ──────────────────────────────────────────────────────── */

.progress-container {
    margin: 0 0 24px;
}

.progress-bar {
    height: 6px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ea6464, #cd5656);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* ─── Section label ─────────────────────────────────────────────────────── */

.section-label {
    font-size: 13px;
    font-weight: 700;
    color: #4d77cc;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 16px;
}

.section-label-total {
    font-weight: 400;
    color: #94a3b8;
    text-transform: none;
    letter-spacing: 0;
}

/* ─── Question container ────────────────────────────────────────────────── */

.question-container {
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 28px 32px;
    margin-bottom: 20px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .05);
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.question-text {
    font-size: 17px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 22px;
    line-height: 1.5;
}

/* ─── Options ───────────────────────────────────────────────────────────── */

.option-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    user-select: none;
}

.option-item:hover {
    background: #f1f5f9;
    border-color: #c7d2fe;
}

.option-item.selected {
    background: #eef2ff;
    border-color: #4d77cc;
    border-left-width: 4px;
    padding-left: 14px;
    font-weight: 600;
    color: #4d77cc;
}

.option-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.option-item.selected .option-letter {
    background: #4d77cc;
    color: #fff;
}

/* ─── Reading comprehension layout ─────────────────────────────────────── */

.reading-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    padding: 0;
    border: none;
    box-shadow: none;
    background: transparent;
}

.reading-passage {
    flex: 1;
    position: sticky;
    top: 24px;
    align-self: flex-start;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px 24px;
    font-size: 14px;
    line-height: 1.75;
    color: #475569;
    scroll-behavior: smooth;
}

.reading-passage::-webkit-scrollbar {
    width: 4px;
}

.reading-passage::-webkit-scrollbar-track {
    background: transparent;
}

.reading-passage::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.reading-questions {
    flex: 1;
    transition: opacity 0.25s ease;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px 24px;
}

/* ─── Audio phase ───────────────────────────────────────────────────────── */

.audio-phase {
    text-align: center;
}

.audio-instruction {
    color: #64748b;
    font-size: 14px;
    margin: 0 0 28px;
}

.audio-custom-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
}

.audio-waveform {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 40px;
}

.audio-waveform span {
    display: block;
    width: 5px;
    border-radius: 3px;
    background: #4d77cc;
    animation: wave 1.2s ease-in-out infinite;
}

.audio-waveform span:nth-child(1)  { height: 14px; animation-delay: 0s; }
.audio-waveform span:nth-child(2)  { height: 28px; animation-delay: .1s; }
.audio-waveform span:nth-child(3)  { height: 20px; animation-delay: .2s; }
.audio-waveform span:nth-child(4)  { height: 36px; animation-delay: .3s; }
.audio-waveform span:nth-child(5)  { height: 22px; animation-delay: .4s; }
.audio-waveform span:nth-child(6)  { height: 34px; animation-delay: .5s; }
.audio-waveform span:nth-child(7)  { height: 18px; animation-delay: .6s; }
.audio-waveform span:nth-child(8)  { height: 30px; animation-delay: .7s; }
.audio-waveform span:nth-child(9)  { height: 16px; animation-delay: .8s; }
.audio-waveform span:nth-child(10) { height: 24px; animation-delay: .9s; }

@keyframes wave {
    0%, 100% { opacity: 1; transform: scaleY(1); }
    50%       { opacity: 0.4; transform: scaleY(0.5); }
}

.audio-progress-track {
    width: 100%;
    height: 6px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
}

.audio-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ea6464, #ea6464);
    border-radius: 99px;
    transition: width 0.5s linear;
}

.audio-time-label {
    font-size: 13px;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.audio-start-btn {
    margin-top: 8px;
}

/* ─── Part 3 questions — replay row ─────────────────────────────────────── */

.replay-row {
    margin-bottom: 20px;
}

.replay-button {
    font-size: 13px;
    padding: 8px 16px;
}

.replay-count {
    opacity: 0.65;
    font-size: 12px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */

.button-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 24px 0 4px;
}

.btn {
    padding: 11px 26px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    transition: opacity 0.15s, transform 0.1s;
    outline: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    opacity: 0.88;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, #4d77cc 0%, #4d77cc 100%);
    color: #fff;
    box-shadow: 0 2px 10px rgba(99, 102, 241, .35);
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1.5px solid #e2e8f0;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* ─── Results ───────────────────────────────────────────────────────────── */

.results-container {
    text-align: center;
    padding: 20px 0;
}

.results-icon {
    font-size: 48px;
    margin-bottom: 12px;
    line-height: 1;
}

.score-display {
    font-size: 64px;
    font-weight: 800;
    color: #4d77cc;
    line-height: 1;
    margin: 20px 0;
    letter-spacing: -.02em;
}

.score-total {
    font-size: 28px;
    color: #cbd5e1;
    font-weight: 500;
}

.cefr-level {
    font-size: 20px;
    font-weight: 500;
    color: #1e293b;
    margin: 0 0 8px;
}

.results-note {
    color: #94a3b8;
    font-size: 14px;
    margin-bottom: 28px;
}

/* ─── Error ─────────────────────────────────────────────────────────────── */

.error-message {
    text-align: center;
    padding: 40px 20px;
    color: #ef4444;
}

.error-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.error-message p {
    margin-bottom: 20px;
    color: #64748b;
    font-size: 15px;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    #english-test-app {
        padding: 24px 16px;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .reading-layout {
        flex-direction: column;
    }

    .reading-passage {
        position: static;
        max-height: 240px;
    }

    .reading-questions {
        border-top: none;
    }

    .question-text {
        font-size: 16px;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .step-label {
        display: none;
    }
}
