/* ======================================================
   QUIZ SECTION — quiz.css
   Стиль в духе Memphis Messenger (использует CSS-переменные темы,
   см. :root в style.css). Раньше раздел жил в <iframe> (см. старый
   quiz.js) со своим отдельным светлым Georgia-оформлением — теперь
   всё рисуется прямо в панели мессенджера, поэтому здесь свой набор
   классов с общей темой приложения.
   ====================================================== */

.chat-panel.quiz-mode .chat-messages {
    overflow-y: auto;
    padding: 0;
}

.quiz-screen {
    padding: 14px 14px 28px;
    animation: quizFadeIn .18s ease;
}

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

.quiz-intro {
    text-align: center;
    font-weight: 700;
    color: var(--m-dark);
    opacity: .65;
    font-size: .88rem;
    margin: 4px 0 16px;
}

.quiz-loading,
.quiz-empty {
    text-align: center;
    padding: 40px 16px;
    font-weight: 600;
    opacity: .6;
}

/* ── Header back button (тот же приём, что и .tg-back-btn) ──── */
.quiz-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-right: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}
.quiz-back-btn:hover { opacity: .7; }
.quiz-back-btn::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    transform: rotate(135deg);
    margin-left: 3px;
}
.quiz-header-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    #chatHeader:has(.quiz-back-btn) .quiz-back-btn {
        order: 1;
        width: 30px;
        height: 30px;
        min-width: 30px;
        margin-right: 8px;
    }
    #chatHeader:has(.quiz-back-btn) .quiz-back-btn::before {
        width: 11px;
        height: 11px;
        border-width: 0 2.5px 2.5px 0;
        margin-left: 4px;
    }
    #chatHeader:has(.quiz-back-btn) .quiz-header-title {
        order: 2;
        flex: 1;
        min-width: 0;
        text-align: center;
        padding: 0 8px;
    }
    #chatHeader:has(.quiz-back-btn) .back-btn {
        order: 3;
        margin-right: 0;
        margin-left: 12px;
    }
}

/* ── Generic buttons ──── */
.quiz-btn,
.quiz-start-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: 2.5px solid var(--m-dark);
    border-radius: 10px;
    background: var(--m-yellow);
    color: var(--m-dark);
    font-family: inherit;
    font-weight: 800;
    font-size: .92rem;
    cursor: pointer;
    box-shadow: 3px 3px 0 var(--m-dark);
    transition: transform .12s, box-shadow .12s, background .12s;
}
.quiz-btn:hover,
.quiz-start-btn:hover:not(.disabled) {
    background: color-mix(in srgb, var(--m-yellow) 80%, white);
}
.quiz-btn:active,
.quiz-start-btn:active:not(.disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--m-dark);
}
.quiz-start-btn.disabled {
    background: var(--m-surface2);
    color: var(--m-dark);
    opacity: .45;
    cursor: not-allowed;
    box-shadow: none;
}

/* ── Error / retry state ──── */
.quiz-error {
    text-align: center;
    padding: 40px 20px;
}
.quiz-error-emoji { font-size: 2.2rem; margin-bottom: 8px; }
.quiz-error p { opacity: .7; font-weight: 600; margin-bottom: 16px; }

/* ── Subjects grid (lobby) ──── */
.quiz-subject-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.quiz-subject-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 22px 10px 16px;
    border: 2.5px solid var(--m-dark);
    border-radius: 14px;
    background: var(--m-surface);
    cursor: pointer;
    font-family: inherit;
    box-shadow: 4px 4px 0 var(--m-dark);
    transition: transform .12s, box-shadow .12s;
}
.quiz-subject-card:hover {
    transform: translateY(-2px);
}
.quiz-subject-card:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--m-dark);
}
.quiz-subject-card.soon {
    background: var(--m-surface2);
}
.quiz-subject-icon { font-size: 2rem; line-height: 1; }
.quiz-subject-title {
    font-weight: 800;
    color: var(--m-dark);
    text-align: center;
    font-size: .95rem;
}
.quiz-soon-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--m-pink);
    color: var(--m-dark);
    border: 1.5px solid var(--m-dark);
    border-radius: 6px;
    padding: 2px 7px;
    font-size: .65rem;
    font-weight: 900;
    text-transform: uppercase;
}

/* ── Grades grid ──── */
.quiz-grade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.quiz-grade-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 2.5px solid var(--m-dark);
    border-radius: 12px;
    background: var(--m-surface);
    overflow: hidden;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 3px 3px 0 var(--m-dark);
    transition: transform .12s, box-shadow .12s;
}
.quiz-grade-card:hover { transform: translateY(-2px); }
.quiz-grade-card:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--m-dark);
}
.quiz-grade-cover {
    display: block;
    width: 100%;
    background: var(--m-surface2);
}
.quiz-grade-cover img {
    display: block;
    width: 100%;
    height: auto; /* контейнер растёт под картинку — она показывается целиком, без обрезки и без сжатия */
}
.quiz-grade-cover-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 110px; /* картинки в этом состоянии нет — задаём высоту явно, как раньше */
    font-size: 1.8rem;
}
.quiz-grade-title {
    display: block;
    padding: 10px 12px;
    font-weight: 800;
    font-size: .88rem;
    color: var(--m-dark);
    text-align: center;
}

.quiz-grade-hero {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: 12px;
    border: 2.5px solid var(--m-dark);
    margin-bottom: 14px;
}

/* ── Timeline (хронология учебника) ──── */
.quiz-timeline-heading {
    font-weight: 800;
    font-size: .9rem;
    margin: 4px 0 8px;
    color: var(--m-dark);
}
.quiz-timeline {
    display: flex;
    /* На десктопе работает только стандартный нативный горизонтальный
       скролл (колесо мыши со Shift, трекпад, перетаскивание скроллбара) —
       никакого кастомного drag/wheel-перехвата. */
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    gap: 10px;
    padding: 10px 2px 18px;
    scroll-snap-type: x proximity;
    scroll-padding-left: 2px;
    /* мягкое затухание по краям — подсказывает, что список продолжается */
    -webkit-mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
    mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
}
/* видимый скроллбар — единственная подсказка о скролле теперь, когда
   кастомного drag-а мышью больше нет */
.quiz-timeline::-webkit-scrollbar {
    height: 8px;
}
.quiz-timeline::-webkit-scrollbar-track {
    background: var(--m-surface2);
    border-radius: 4px;
}
.quiz-timeline::-webkit-scrollbar-thumb {
    background: var(--m-dark);
    border-radius: 4px;
}
.quiz-timeline::-webkit-scrollbar-thumb:hover {
    background: var(--m-teal);
}
@supports (scrollbar-width: thin) {
    .quiz-timeline {
        scrollbar-width: thin;
        scrollbar-color: var(--m-dark) var(--m-surface2);
    }
}
.quiz-timeline-item {
    flex: 0 0 auto;
    width: 140px;
    position: relative;
    padding-top: 16px;
    scroll-snap-align: start;
}
.quiz-timeline-dot {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--m-teal);
    border: 2px solid var(--m-dark);
}
.quiz-timeline-card {
    border: 2px solid var(--m-dark);
    border-radius: 8px;
    background: var(--m-surface);
    padding: 8px 9px;
    text-align: center;
}
.quiz-timeline-year { font-weight: 900; color: var(--m-dark); font-size: .82rem; margin-bottom: 3px; }
.quiz-timeline-event { font-size: .74rem; opacity: .75; line-height: 1.3; }

/* ── Конспект главы (текст/картинки перед карточкой главы) ──── */
.quiz-chapter-conspect {
    border: 2px dashed var(--m-dark);
    border-radius: 12px;
    background: var(--m-surface2);
    padding: 12px 14px;
    opacity: .92;
}
.quiz-conspect-text p { margin: 0 0 8px; font-size: .86rem; line-height: 1.5; color: var(--m-dark); }
.quiz-conspect-text p:last-child { margin-bottom: 0; }
.quiz-conspect-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quiz-conspect-text + .quiz-conspect-images { margin-top: 10px; }
.quiz-conspect-img {
    display: block;
    width: 92px;
    height: 68px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid var(--m-dark);
    flex-shrink: 0;
}
.quiz-conspect-img img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ── Chapters list ──── */
.quiz-chapter-list { display: flex; flex-direction: column; gap: 12px; }
.quiz-chapter-card {
    display: flex;
    gap: 12px;
    border: 2.5px solid var(--m-dark);
    border-radius: 12px;
    background: var(--m-surface);
    overflow: hidden;
    box-shadow: 3px 3px 0 var(--m-dark);
}
.quiz-chapter-cover { flex: 0 0 90px; }
.quiz-chapter-cover img { display: block; width: 90px; height: 100%; min-height: 84px; object-fit: cover; object-position: center 50%; }
/* object-position переопределяется инлайново в quiz.js из chapter.coverPos
   (0-100, % от верха) — см. cover-upload.php, где эта позиция настраивается. */
.quiz-chapter-body {
    flex: 1;
    padding: 10px 12px 10px 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}
.quiz-chapter-title { margin: 0; font-size: .96rem; color: var(--m-dark); }
.quiz-chapter-meta { font-size: .76rem; opacity: .65; font-weight: 600; }
.quiz-chapter-meta.warn { color: var(--m-pink); opacity: 1; }
.quiz-mixed-note { color: var(--m-teal); opacity: 1; font-weight: 800; }
.quiz-chapter-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.quiz-chapter-actions .quiz-start-btn { padding: 7px 14px; font-size: .84rem; box-shadow: 2px 2px 0 var(--m-dark); }

/* --- Черточки истории попыток за сегодня (заменили текст "Попыток сегодня: X из Y") --- */
.quiz-attempt-dashes { display: inline-flex; gap: 1px; align-items: center;
    max-width: calc(12px * 10 + 1px * 9); overflow: hidden; vertical-align: middle; }
.quiz-attempt-dash { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 1px; flex-shrink: 0; }
.quiz-attempt-dash:last-child { margin-right: 0; }
/* 10 или 9 из 10 — зелёный; 7 или 8 из 10 — жёлтый;
   6 из 10 и меньше — красный; не завершено — чёрный. */
.quiz-attempt-dash--green  { background: #4caf50; }
.quiz-attempt-dash--yellow { background: #e0b400; }
.quiz-attempt-dash--red    { background: var(--m-pink); }
.quiz-attempt-dash--black  { background: var(--m-dark); }

/* ── Несколько уровней сложности доступны пользователю ──── */
/* Если админ подключил ученику уровень 2/3 (см. editor.php → «Уровни
   доступа»), вместо одной кнопки «Начать тест» показывается по кнопке на
   каждый доступный уровень — см. quiz.js, ветка available.length > 1. */
.quiz-chapter-actions .quiz-level-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}
.quiz-chapter-actions .quiz-level-row + .quiz-level-row { margin-top: 2px; }

/* --- Переключатель "смешивать вопросы всех глав/уровней класса" ---
   Визуально "отрезанная" 1/5 часть кнопки "Начать тест": общий контур на
   двоих (border+shadow — на группе, у кнопки внутри своих уже нет), между
   ними тонкая разделительная полоса. См. quizToggleMix() в quiz.js. */
.quiz-start-group {
    display: inline-flex;
    align-items: stretch;
    border: 2.5px solid var(--m-dark);
    border-radius: 10px;
    box-shadow: 2px 2px 0 var(--m-dark);
    overflow: hidden;
}
.quiz-start-group .quiz-start-btn {
    border: none;
    box-shadow: none;
    border-radius: 0;
}
.quiz-mix-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    flex: 0 0 30px;
    background: var(--m-surface2);
    color: var(--m-dark);
    border: none;
    border-left: 2.5px solid var(--m-dark);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
}
.quiz-mix-toggle:hover { filter: brightness(0.95); }
.quiz-mix-toggle.on { background: var(--m-teal); color: #fff; }
.quiz-mix-row { gap: 8px; }
.quiz-mix-banner {
    background: color-mix(in srgb, var(--m-teal) 14%, var(--m-surface2));
    border: 2px dashed var(--m-teal);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: .84rem;
    font-weight: 700;
    color: var(--m-dark);
}

@media (max-width: 480px) {
    .quiz-subject-grid { grid-template-columns: repeat(2, 1fr); }
    .quiz-chapter-card { flex-direction: column; }
    .quiz-chapter-cover, .quiz-chapter-cover img { width: 100%; height: 92px; }
    .quiz-chapter-body { padding: 10px 12px; }
}

/* ── Blocked (no attempts left today) ──── */
.quiz-blocked-card {
    text-align: center;
    padding: 30px 20px;
    border: 2.5px solid var(--m-dark);
    border-radius: 14px;
    background: var(--m-surface);
    box-shadow: 4px 4px 0 var(--m-dark);
}
.quiz-blocked-emoji { font-size: 2.2rem; margin-bottom: 8px; }
.quiz-blocked-card p { font-weight: 600; opacity: .75; margin: 4px 0; }
.quiz-blocked-card .quiz-btn { margin-top: 14px; }

/* ── Quiz taking screen ──── */
.quiz-cover-hero {
    display: block;
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    object-position: center 50%; /* переопределяется инлайново из chapter.coverPos в quiz.js */
    border-radius: 12px;
    border: 2.5px solid var(--m-dark);
    margin-bottom: 14px;
    box-shadow: 3px 3px 0 var(--m-dark);
}
.quiz-progress {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    font-size: .82rem;
    font-weight: 700;
    opacity: .8;
}
.quiz-bar-outer {
    background: var(--m-surface2);
    border: 1.5px solid var(--m-dark);
    border-radius: 6px;
    height: 8px;
    flex: 1;
    margin: 0 12px;
    overflow: hidden;
}
.quiz-bar-inner {
    background: var(--m-teal);
    height: 100%;
    width: 0%;
    transition: width .3s ease;
}
.quiz-card {
    border: 2.5px solid var(--m-dark);
    border-radius: 14px;
    background: var(--m-surface);
    padding: 18px;
    box-shadow: 4px 4px 0 var(--m-dark);
}
.quiz-q-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--m-dark);
    margin-bottom: 16px;
    line-height: 1.4;
}
.quiz-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 11px 14px;
    margin-bottom: 9px;
    border: 2px solid var(--m-dark);
    border-radius: 9px;
    background: var(--m-surface2);
    color: var(--m-dark);
    cursor: pointer;
    font-family: inherit;
    font-size: .93rem;
    font-weight: 600;
    transition: background .15s, transform .1s;
}
.quiz-option:hover:not(:disabled) { background: color-mix(in srgb, var(--m-teal) 18%, var(--m-surface2)); }
.quiz-option.selected {
    border-color: var(--m-dark);
    background: var(--m-yellow);
}
.quiz-option:disabled { cursor: default; opacity: .85; }
.quiz-nav-row { display: flex; justify-content: space-between; margin-top: 16px; gap: 10px; }
.quiz-nav-btn {
    padding: 10px 18px;
    border: 2.5px solid var(--m-dark);
    border-radius: 10px;
    background: var(--m-yellow);
    color: var(--m-dark);
    font-weight: 800;
    font-size: .9rem;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 3px 3px 0 var(--m-dark);
}
.quiz-nav-btn:disabled {
    background: var(--m-surface2);
    opacity: .45;
    cursor: not-allowed;
    box-shadow: none;
}
.quiz-nav-btn.secondary { background: var(--m-surface); }

/* ── Result screen ──── */
.quiz-result-card {
    text-align: center;
    padding: 26px 20px;
    border: 2.5px solid var(--m-dark);
    border-radius: 14px;
    background: var(--m-surface);
    box-shadow: 4px 4px 0 var(--m-dark);
    margin-bottom: 16px;
}
.quiz-result-verdict { font-weight: 700; opacity: .7; margin-bottom: 6px; }
.quiz-result-score { font-size: 2.6rem; font-weight: 900; color: var(--m-dark); margin: 4px 0 10px; }
.quiz-result-comment { font-weight: 600; opacity: .8; margin-bottom: 16px; }
.quiz-review-list { display: flex; flex-direction: column; gap: 10px; }
.quiz-review-item {
    text-align: left;
    padding: 12px 14px;
    border: 2px solid var(--m-dark);
    border-radius: 10px;
    background: var(--m-surface);
}
.quiz-review-item.correct { border-left: 5px solid var(--m-teal); }
.quiz-review-item.incorrect { border-left: 5px solid var(--m-pink); }
.quiz-review-q { font-weight: 700; margin-bottom: 4px; color: var(--m-dark); }
.quiz-review-a { font-size: .85rem; opacity: .8; }
.quiz-review-correct { font-size: .85rem; opacity: .8; }
.quiz-review-explain { font-size: .83rem; opacity: .65; font-style: italic; margin-top: 4px; }