/* ========== СТИЛИ ДЛЯ ТРЕНИРОВОК ПО ХИМИИ ========== */

/* Анимации */
@keyframes chemFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chemPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes progressBarShimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes cloneAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 0.9;
        transform: scale(1.1);
    }
}

/* Контейнер тренировки */
.chem-training-container {
    animation: chemFadeIn 0.4s ease-out;
}

/* ========== ПОЛЯ ДЛЯ ВСТАВКИ ========== */
[id^="chem-"] {
    transition: all 0.3s ease;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Пустые поля - пунктирная обводка */
[id^="chem-"]:empty {
    background: rgba(72, 187, 120, 0.1) !important;
    border: 2px dashed #48bb78 !important;
    box-shadow: none !important;
}

/* Заполненные поля - без обводки и фона */
[id^="chem-"]:not(:empty) {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Поле валентности */
[id^="chem-valence-field"] {
    width: 40px;
    height: 30px;
    border-radius: 8px;
    margin-bottom: 5px;
    font-size: 16px;
    font-weight: bold;
    color: #2d3748;
}

/* Поле индекса */
[id^="chem-subscript-field"] {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    margin-left: 2px;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: bold;
    color: #2d3748;
}

/* Подсветка при наведении/перетаскивании */
[id^="chem-"].touch-highlight {
    background: rgba(72, 187, 120, 0.3) !important;
    border: 3px solid #48bb78 !important;
    transform: scale(1.02);
    box-shadow: 0 0 15px rgba(72, 187, 120, 0.5);
}

/* ========== КНОПКИ С ЦИФРАМИ ========== */
.chem-keyboard {
    width: 100%;
    box-sizing: border-box;
    background: white;
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Контейнер для цифр */
.digits-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    padding: 20px 15px;
    background: #f8f9fa;
    border-radius: 16px;
}

/* Ряд с цифрами */
.digits-row {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: nowrap;
}

/* Кнопка с цифрой */
.chem-symbol-btn {
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    -webkit-touch-callout: none;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(66, 153, 225, 0.3);
    flex-shrink: 0;
}

.chem-symbol-btn:active {
    cursor: grabbing;
    opacity: 0.7;
    transform: scale(0.95) !important;
}

.chem-symbol-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(66, 153, 225, 0.4) !important;
}

/* ========== КНОПКА УДАЛЕНИЯ ========== */
.remove-symbol-btn {
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    z-index: 10;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    background: #fed7d7 !important;
    color: #c53030 !important;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    position: absolute;
    top: -8px;
    right: -8px;
    padding: 0;
    line-height: 1;
}

.remove-symbol-btn:hover {
    background: #feb2b2 !important;
    transform: scale(1.1);
}

.remove-symbol-btn:active {
    transform: scale(0.95);
}

/* ========== ПОЛОСКА ПРОГРЕССА ========== */
.chem-progress-bar {
    animation: progressBarSlideDown 0.3s ease forwards;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    border-radius: 12px;
    padding: 8px 16px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.5);
    width: 100%;
    box-sizing: border-box;
    min-height: 48px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    position: relative;
    overflow: hidden;
    margin-bottom: 5px;
}

@keyframes progressBarSlideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== СТИЛИ ДЛЯ КЛОНА ПРИ ПЕРЕТАСКИВАНИИ ========== */
#dragging-clone {
    position: fixed;
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 10000;
    transform: scale(1.1);
    transition: none;
    opacity: 0.9;
    backdrop-filter: blur(2px);
    border: 2px solid white;
    animation: cloneAppear 0.2s ease-out;
}

/* Предотвращаем выделение текста при перетаскивании */
.chem-training-container,
.gaps-container,
[id^="chem-"],
.word-blocks-container {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Индикатор загрузки для touch-действий */
.chem-training-container.dragging-active {
    cursor: grabbing !important;
}

/* Предотвращаем скролл страницы при перетаскивании на мобильных */
body.dragging-active {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ========== АДАПТИВНОСТЬ ========== */

/* ПК и планшеты */
@media (min-width: 769px) {
    .digits-container {
        padding: 20px 15px;
    }
    
    .digits-row {
        gap: 15px;
    }
    
    .chem-symbol-btn {
        width: 55px;
        height: 55px;
        font-size: 24px;
    }
}

/* Планшеты */
@media (max-width: 768px) {
    .digits-container {
        padding: 15px 10px;
    }
    
    .digits-row {
        gap: 12px;
    }
    
    .chem-symbol-btn {
        width: 50px;
        height: 50px;
        font-size: 22px;
    }
}

/* Мобильные */
@media (max-width: 500px) {
    .chem-training-container {
        padding: 20px !important;
    }

    .chem-training-container div[style*="font-size: 56px"] {
        font-size: 48px !important;
    }

    /* Поля для вставки */
    [id^="chem-valence-field"] {
        width: 35px !important;
        height: 28px !important;
        font-size: 14px !important;
    }

    [id^="chem-subscript-field"] {
        width: 25px !important;
        height: 25px !important;
        font-size: 12px !important;
    }

    /* Контейнер с цифрами */
    .digits-container {
        padding: 15px 10px;
    }
    
    .digits-row {
        gap: 10px;
    }
    
    .chem-symbol-btn {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
    }

    /* Полоска прогресса */
    .chem-progress-bar {
        padding: 8px 15px !important;
        min-height: 45px !important;
    }

    .chem-progress-bar span {
        font-size: 12px !important;
    }

    .chem-progress-bar .task-value,
    .chem-progress-bar .points-value {
        font-size: 16px !important;
    }
    
    /* Клон при перетаскивании */
    #dragging-clone {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
    }

    /* Кнопка удаления */
    .remove-symbol-btn {
        width: 16px !important;
        height: 16px !important;
        font-size: 10px !important;
        top: -6px !important;
        right: -6px !important;
    }
}

/* Очень маленькие мобильные */
@media (max-width: 380px) {
    .chem-training-container div[style*="font-size: 56px"] {
        font-size: 42px !important;
    }

    [id^="chem-valence-field"] {
        width: 32px !important;
        height: 26px !important;
    }

    [id^="chem-subscript-field"] {
        width: 22px !important;
        height: 22px !important;
    }

    .digits-row {
        gap: 8px;
    }
    
    .chem-symbol-btn {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
    
    #dragging-clone {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
}

@media (max-width: 350px) {
    .chem-training-container div[style*="font-size: 56px"] {
        font-size: 40px !important;
    }

    .digits-row {
        gap: 6px;
    }
    
    .chem-symbol-btn {
        width: 35px !important;
        height: 35px !important;
        font-size: 16px !important;
    }
    
    #dragging-clone {
        width: 35px !important;
        height: 35px !important;
        font-size: 16px !important;
    }
}

/* Высота экрана */
@media (max-height: 700px) {
    .chem-training-container {
        padding: 20px !important;
    }

    .chem-training-container div[style*="min-height: 150px"] {
        min-height: 120px !important;
        padding: 20px !important;
    }
    
    .chem-symbol-btn {
        height: 42px !important;
    }
}

@media (max-height: 600px) {
    .chem-training-container {
        padding: 15px !important;
    }
    
    .chem-symbol-btn {
        height: 38px !important;
    }
}

/* Ландшафтная ориентация */
@media (max-height: 500px) and (orientation: landscape) {
    .chem-training-container {
        padding: 10px !important;
    }
    
    .digits-row {
        gap: 8px;
    }
    
    .chem-symbol-btn {
        width: 35px !important;
        height: 35px !important;
        font-size: 16px !important;
    }
    
    [id^="chem-"] {
        min-width: 35px !important;
        min-height: 28px !important;
    }
    
    #dragging-clone {
        width: 35px !important;
        height: 35px !important;
        font-size: 16px !important;
    }
}

/* ========== УЛУЧШЕНИЯ ДЛЯ TOUCH-УСТРОЙСТВ ========== */
@media (hover: none) and (pointer: coarse) {
    .chem-symbol-btn {
        width: 48px !important;
        height: 48px !important;
        margin: 2px;
    }
    
    [id^="chem-"] {
        min-width: 44px !important;
        min-height: 38px !important;
    }
    
    .remove-symbol-btn {
        width: 20px !important;
        height: 20px !important;
        font-size: 12px !important;
    }
}

/* Отключаем hover-эффекты на touch-устройствах */
@media (hover: none) {
    .chem-symbol-btn:hover {
        transform: none !important;
        box-shadow: 0 4px 10px rgba(66, 153, 225, 0.3) !important;
    }
    
    [id^="chem-"]:hover {
        transform: none !important;
        box-shadow: none !important;
    }
}

/* Стили для активного состояния на touch */
.chem-symbol-btn.touch-active {
    transform: scale(0.92) !important;
    opacity: 0.8;
    transition: all 0.1s ease;
}

/* Индикатор возможности перетаскивания */
.chem-symbol-btn[draggable="true"] {
    cursor: grab;
}

.chem-symbol-btn[draggable="true"]:active {
    cursor: grabbing;
}