/* ========== ФИНАЛЬНОЕ ИСПРАВЛЕНИЕ СКРОЛЛА ========== */

/* Глобальные правила для всех экранов */
.screen {
    overflow: hidden !important;
    position: relative !important;
}

/* Только экран предметов должен иметь flex-структуру */
#subjectSelectScreen.active {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    height: 100vh !important;
    width: 100% !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
}

/* Контейнер выбора предметов */
#subjectSelectScreen.active .subject-selection {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    width: 100% !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
    position: relative !important;
}

/* Градиентный заголовок - всегда сверху */
#subjectSelectScreen.active .gradient-header-strip {
    flex-shrink: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 10 !important;
}

/* Контейнер с скроллом - исправленные стили */
#subjectSelectScreen.active .subject-grid-container {
    flex: 1 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 20px 20px 30px !important;
    min-height: 0 !important; /* Критически важно для flex */
    position: relative !important;
    z-index: 5 !important;
}

/* Скрываем скролл для красоты */
#subjectSelectScreen.active .subject-grid-container::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

/* Сетка предметов */
#subjectSelectScreen.active .subject-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 20px !important;
    width: 100% !important;
    max-width: 400px !important;
    margin: 0 auto !important;
    position: relative !important;
    z-index: 6 !important;
}

/* Принудительное восстановление после возврата */
body:not(.initial-load) #subjectSelectScreen.active .subject-grid-container {
    overflow-y: auto !important;
}

/* Кнопки должны быть кликабельны */
#subjectSelectScreen.active .subject-btn {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: pointer !important;
    position: relative !important;
    z-index: 7 !important;
}

/* Адаптивность */
@media (max-width: 500px) {
    #subjectSelectScreen.active .subject-grid-container {
        padding: 15px 15px 25px !important;
    }
    
    #subjectSelectScreen.active .subject-grid {
        grid-template-columns: 1fr !important;
        max-width: 300px !important;
        gap: 15px !important;
    }
}

@media (max-height: 700px) {
    #subjectSelectScreen.active .subject-grid-container {
        padding: 15px 15px 20px !important;
    }
}

/* Принудительное восстановление после любых переходов */
.screen-transition-complete #subjectSelectScreen.active .subject-grid-container {
    overflow-y: auto !important;
}