/* ========== СТИЛИ ДЛЯ МАТЕМАТИЧЕСКОГО ПРИЛОЖЕНИЯ ========== */

/* Главное меню математики */
.main-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bottom-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Стили для тренировок */
.training-container {
    animation: fadeIn 0.3s ease;
    padding: 6px 0;
}

/* Полоска с прогрессом и счетом */
.training-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border-radius: 8px;
    border: 1px solid #667eea30;
    font-size: 13px;
}

.training-info div {
    font-weight: 600;
    font-size: 13px;
}

.training-info #trainingProgress {
    color: #667eea;
}

.training-info #trainingScore {
    color: #764ba2;
}

/* Отображение ответа */
.answer-display {
    background: white;
    border-radius: 8px;
    border: 1px solid #667eea;
    margin-bottom: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.answer-input {
    padding: 12px;
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    color: #333;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Клавиатура тренировки */
.numeric-keyboard {
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    margin-bottom: 8px;
    padding: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Одна строка с 10 цифрами */
.keyboard-row.single-row {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.keyboard-row.single-row::-webkit-scrollbar {
    display: none;
}

.keyboard-row.single-row .key {
    flex: 0 0 auto;
    width: 32px;
    height: 40px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    touch-action: manipulation;
    user-select: none;
    min-width: 32px;
}

.keyboard-row.single-row .key:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.keyboard-row.single-row .key:active {
    transform: translateY(0);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Кнопки действий под цифровой строкой */
.keyboard-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.key-action {
    flex: 1;
    height: 36px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    touch-action: manipulation;
    user-select: none;
    padding: 0 8px;
}

.key-clear {
    background: #f0f0f0;
    color: #666;
    border: 1px solid #ddd;
}

.key-clear:hover {
    background: #e0e0e0;
}

.key-backspace {
    background: #fff5f5;
    color: #c53030;
    border: 1px solid #fc8181;
}

.key-backspace:hover {
    background: #fed7d7;
    border-color: #f56565;
}

.key-enter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 1px solid #5a6fd8;
}

.key-enter:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

/* Улучшенная клавиатура с MathJax */
.keyboard-main {
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    margin-bottom: 8px;
    padding: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Строка переключения */
.keyboard-toggle-row {
    display: flex;
    gap: 6px;
    margin: 8px 0;
}

.key-toggle {
    flex: 1;
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border: 1px solid #667eea40;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #667eea;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    user-select: none;
}

.key-toggle:hover {
    background: linear-gradient(135deg, #667eea25 0%, #764ba225 100%);
    border-color: #667eea60;
    transform: translateY(-1px);
}

.toggle-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
}

/* Область специальных символов */
.keyboard-special {
    animation: fadeIn 0.3s ease;
    margin: 10px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.special-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 8px;
}

.special-row:last-child {
    margin-bottom: 0;
}

.key-special {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    width: 40px;
    height: 40px;
    font-size: 14px;
    font-weight: 700;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    touch-action: manipulation;
    user-select: none;
}

.key-special:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.key-special:active {
    transform: translateY(0);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

/* Тригонометрические кнопки */
.key-special[data-symbol="sin"],
.key-special[data-symbol="cos"],
.key-special[data-symbol="tg"],
.key-special[data-symbol="ctg"] {
    width: 60px;
    font-size: 12px;
}

/* Стили для MathJax выражений */
.math-expression {
    text-align: center;
    padding: 15px;
    margin: 10px 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 10px;
    border: 1px solid #dee2e6;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mjx-chtml {
    font-size: 20px !important;
    text-align: center;
}

@keyframes mathFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.math-expression {
    animation: mathFadeIn 0.5s ease-out;
}

/* Стили для дробей */
.fraction-display {
    display: none;
    width: 100%;
}

.fraction-input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.fraction-input {
    width: 100px;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    background: white;
    transition: all 0.2s ease;
    outline: none;
}

.fraction-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.fraction-input.active {
    border-color: #667eea;
    background-color: #f8f9fa;
}

.fraction-line {
    width: 80px;
    height: 2px;
    background-color: #333;
    margin: 4px 0;
}

.fraction-controls {
    animation: fadeIn 0.3s ease;
    margin: 8px 0;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.fraction-switcher {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.fraction-switch-btn {
    flex: 1;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.fraction-switch-btn[data-active="true"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.fraction-switch-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Мигающая анимация */
@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

.blinking {
    animation: blink 1s infinite;
    background-color: rgba(102, 126, 234, 0.1) !important;
}

/* Контейнер ответа */
.answer-input-container {
    position: relative;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Адаптивность математики */
@media (max-width: 500px) {
    .math-expression {
        padding: 12px;
        min-height: 40px;
    }

    .mjx-chtml {
        font-size: 18px !important;
    }

    .fraction-input {
        width: 80px;
        font-size: 16px;
        padding: 6px 10px;
    }

    .key-special[data-symbol="sin"],
    .key-special[data-symbol="cos"],
    .key-special[data-symbol="tg"],
    .key-special[data-symbol="ctg"] {
        width: 50px;
        font-size: 11px;
    }

    .key-toggle {
        padding: 6px 10px;
        font-size: 11px;
    }

    .keyboard-row.single-row .key {
        width: 30px;
        height: 38px;
        font-size: 15px;
        min-width: 30px;
    }

    .key-action {
        height: 34px;
        font-size: 12px;
        padding: 0 6px;
    }
}

@media (max-width: 380px) {
    .key-special[data-symbol="sin"],
    .key-special[data-symbol="cos"],
    .key-special[data-symbol="tg"],
    .key-special[data-symbol="ctg"] {
        width: 45px;
        font-size: 10px;
    }

    .fraction-input {
        width: 70px;
        font-size: 15px;
        padding: 5px 8px;
    }

    .keyboard-toggle-row {
        flex-direction: column;
    }
}

@media (min-width: 400px) {
    .keyboard-row.single-row {
        justify-content: space-between;
        overflow-x: visible;
    }

    .keyboard-row.single-row .key {
        flex: 1;
        min-width: 0;
        width: auto;
    }
}