/* Сброс стилей и базовые настройки */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Заголовок */
header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 30px 20px;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 15px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-switcher {
    margin-top: 15px;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

/* Основной контент */
main {
    padding: 40px 20px;
}

.question-section {
    text-align: center;
    margin-bottom: 30px;
}

.question {
    font-size: 2rem;
    font-weight: 600;
    color: #2c3e50;
    padding: 30px;
    background: #f8f9fa;
    border-radius: 15px;
    border: 2px solid #e9ecef;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    word-break: break-word;
}

/* Состояния вопроса */
.question.question-correct {
    border-color: #28a745;
    background: #d4edda;
    color: #155724;
}

.question.question-incorrect {
    border-color: #dc3545;
    background: #f8d7da;
    color: #721c24;
}

/* Секция ввода */
.input-section {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

#answerInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    font-size: 1.2rem;
    font-weight: 500;
    transition: all 0.3s ease;
    min-width: 200px;
}

#answerInput:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

#answerInput:disabled {
    background: #f8f9fa;
    color: #6c757d;
    cursor: not-allowed;
}

.submit-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 140px;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}

.submit-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Результат */
/* Блок результата удалён */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Встроенный вывод правильного ответа под вопросом */
.correct-answer-inline {
    margin-top: 10px;
    text-align: center;
    font-size: 1.1rem;
    color: #6c757d;
    font-style: italic;
}

.correct-answer {
    font-size: 1.1rem;
    color: #6c757d;
    font-style: italic;
}

/* Управление */
.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.new-question-btn, .reset-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 140px;
}

.new-question-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.new-question-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.reset-btn {
    background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%);
    color: white;
    margin: 0 auto;
}

.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

/* Настройки */
.settings {
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    border: 2px solid #e9ecef;
}

.settings label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #495057;
}

#elementRange {
    padding: 10px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

#elementRange:focus {
    outline: none;
    border-color: #4facfe;
}

/* Статистика */
footer {
    background: #f8f9fa;
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stats {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 20px;
}

.stat {
    text-align: center;
    min-width: 100px;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 5px;
    font-weight: 500;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c3e50;
}

/* Адаптивность */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        border-radius: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .question {
        font-size: 1.5rem;
        padding: 20px;
        min-height: 100px;
    }
    
    .input-section {
        flex-direction: column;
    }
    
    #answerInput {
        min-width: auto;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
    }
    
    .new-question-btn, .reset-btn {
        width: 100%;
        max-width: 200px;
    }
    
    .stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .stat {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    header {
        padding: 20px 15px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    main {
        padding: 30px 15px;
    }
    
    .question {
        font-size: 1.3rem;
        padding: 15px;
    }
    
    #answerInput {
        font-size: 1.1rem;
        padding: 12px 15px;
    }
    
    .submit-btn {
        padding: 12px 20px;
        font-size: 1rem;
        width: 100%;
    }
    
    .result {
        font-size: 1.3rem;
    }
}

/* Кнопка ручного выбора */
.manual-select-btn {
    background: linear-gradient(135deg, #6f42c1 0%, #e83e8c 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
    width: 100%;
}

.manual-select-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(111, 66, 193, 0.4);
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 0;
    border-radius: 20px;
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-body {
    padding: 20px 30px;
    max-height: 60vh;
    overflow-y: auto;
}

.selection-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.control-btn {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    color: #495057;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #e9ecef;
    border-color: #dee2e6;
    transform: translateY(-1px);
}

.selected-count {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 20px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
}

.periodic-table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    gap: 2px;
    min-width: 900px;
    margin: 0 auto;
}

.element-cell {
    position: relative;
    aspect-ratio: 1;
    min-height: 50px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.7rem;
    font-weight: 600;
    color: #495057;
    user-select: none;
}

.element-cell:hover {
    background: #e9ecef;
    transform: scale(1.05);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.element-cell.selected {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border-color: #4facfe;
    transform: scale(1.05);
}

.element-cell.selected::after {
    content: '✓';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.8rem;
    font-weight: bold;
}

.element-symbol {
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
}

.element-number {
    font-size: 0.6rem;
    opacity: 0.8;
    margin-top: 2px;
}

.element-name {
    font-size: 0.5rem;
    opacity: 0.7;
    text-align: center;
    line-height: 1;
    margin-top: 2px;
    display: none;
}

.element-cell:hover .element-name {
    display: block;
}

/* Пустые ячейки */
.element-cell.empty {
    background: transparent;
    border: none;
    cursor: default;
}

.element-cell.empty:hover {
    background: transparent;
    transform: none;
    box-shadow: none;
}

.modal-footer {
    background: #f8f9fa;
    padding: 20px 30px;
    display: flex;
    gap: 15px;
    justify-content: center;
    border-top: 1px solid #e9ecef;
}

.save-btn, .cancel-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.save-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.cancel-btn {
    background: #6c757d;
    color: white;
}

.cancel-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

/* Адаптивность для модального окна */
@media (max-width: 768px) {
    .modal-content {
        margin: 5% auto;
        width: 98%;
        max-height: 85vh;
    }
    
    .modal-header {
        padding: 15px 20px;
    }
    
    .modal-header h2 {
        font-size: 1.5rem;
    }
    
    .modal-body {
        padding: 15px 20px;
    }
    
    .selection-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .control-btn {
        width: 100%;
        max-width: 200px;
    }
    
    .periodic-table {
        grid-template-columns: repeat(9, 1fr);
        min-width: 450px;
        gap: 1px;
    }
    
    .element-cell {
        min-height: 40px;
        font-size: 0.6rem;
    }
    
    .element-symbol {
        font-size: 0.8rem;
    }
    
    .element-number {
        font-size: 0.5rem;
    }
    
    .modal-footer {
        padding: 15px 20px;
        flex-direction: column;
        align-items: center;
    }
    
    .save-btn, .cancel-btn {
        width: 100%;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    .periodic-table {
        grid-template-columns: repeat(6, 1fr);
        min-width: 300px;
    }
    
    .element-cell {
        min-height: 35px;
        font-size: 0.5rem;
    }
    
    .element-symbol {
        font-size: 0.7rem;
    }
    
    .element-number {
        font-size: 0.4rem;
    }
}

/* Анимации и эффекты */
.fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
