/* РИМСКИЕ ЦИФРЫ - ОСНОВНЫЕ СТИЛИ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Times New Roman', Georgia, serif;
    background: linear-gradient(135deg, #2c3e50 0%, #1a1a2e 100%);
    min-height: 100vh;
    overflow: hidden;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    overflow-y: auto;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* ЭКРАН ВЫБОРА УРОВНЯ */
.levels-screen {
    background: linear-gradient(135deg, #2c3e50 0%, #1a1a2e 100%);
}

.levels-container {
    max-width: 1100px;
    width: 100%;
    background: white;
    border-radius: 25px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideUp 0.5s ease;
    max-height: 95vh;
    overflow-y: auto;
}

.levels-header {
    text-align: center;
    margin-bottom: 25px;
}

.levels-header h1 {
    font-size: 2.2em;
    color: #8B4513;
    margin-bottom: 10px;
}

.level-progress {
    background: #e9ecef;
    border-radius: 20px;
    height: 10px;
    overflow: hidden;
    margin: 15px 0;
}

.level-progress-bar {
    background: linear-gradient(90deg, #8B4513, #D2691E);
    height: 100%;
    border-radius: 20px;
    transition: width 0.3s;
}

/* Справка */
.reference-panel {
    background: linear-gradient(135deg, #F5E6D3, #E8D5B7);
    border-radius: 20px;
    padding: 15px;
    margin: 20px 0;
    border: 2px solid #D2691E;
}

.reference-panel h3 {
    color: #8B4513;
    margin-bottom: 10px;
    font-size: 1em;
}

.reference-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.ref-item {
    background: white;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: bold;
    color: #8B4513;
}

.reference-rules {
    font-size: 0.8em;
    color: #666;
    text-align: center;
}

/* Панель настроек */
.settings-panel {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 20px;
    padding: 20px;
    margin: 20px 0;
    border: 2px solid #dee2e6;
}

.settings-panel h3 {
    color: #333;
    margin-bottom: 15px;
}

.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 150px;
}

.setting-group label {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

.setting-group select {
    padding: 10px 12px;
    border: 2px solid #dee2e6;
    border-radius: 12px;
    font-size: 1em;
    background: white;
    cursor: pointer;
}

.apply-settings-btn {
    background: linear-gradient(135deg, #8B4513, #D2691E);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 20px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    height: 44px;
}

/* Сетка уровней */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin: 25px 0;
}

.level-card {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 15px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    border: 3px solid transparent;
    position: relative;
}

.level-card:hover:not(.locked) {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    background: white;
    border-color: #8B4513;
}

.level-card.completed {
    background: #e8f5e9;
    border-color: #4CAF50;
}

.level-card.current {
    background: #FFF3E0;
    border-color: #D2691E;
    animation: pulseBorder 2s infinite;
}

.level-card.locked {
    background: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

.level-number {
    font-size: 1.8em;
    font-weight: bold;
    color: #333;
}

.level-difficulty {
    font-size: 0.8em;
    font-weight: 600;
    color: #D2691E;
    margin: 5px 0;
}

.level-info {
    font-size: 0.7em;
    color: #888;
}

.level-stars {
    margin-top: 8px;
    color: #FFD700;
    font-size: 1em;
}

.lock-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.9em;
}

/* ЭКРАН ИГРЫ */
.game-screen {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.game-container {
    width: 100%;
    max-width: 700px;
    background: white;
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 95vh;
    height: 95vh;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, #8B4513, #D2691E);
    color: white;
    flex-shrink: 0;
}

.back-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 15px;
    cursor: pointer;
    font-family: inherit;
}

.game-level-info {
    display: flex;
    gap: 15px;
    align-items: center;
}

.level-badge, .timer-display {
    background: rgba(255,255,255,0.2);
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.rules-btn, .pause-btn, .reference-toggle-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 10px;
    width: 45px;
    height: 45px;
    font-size: 1.3em;
    cursor: pointer;
}

.game-board {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stats-bar {
    display: flex;
    justify-content: space-around;
    background: #FFF3E0;
    padding: 15px;
    border-radius: 25px;
}

.stat {
    text-align: center;
}

.stat-label {
    font-size: 0.7em;
    color: #888;
    display: block;
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: #D2691E;
}

.level-progress-bar-container {
    background: #e9ecef;
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
}

.level-progress-fill {
    background: linear-gradient(90deg, #8B4513, #D2691E);
    height: 100%;
    transition: width 0.3s;
}

/* Карточка вопроса */
.question-card {
    background: linear-gradient(135deg, #FFF8F0, #FFEFD5);
    border-radius: 30px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.question-number {
    font-size: 0.9em;
    color: #D2691E;
    background: white;
    padding: 5px 15px;
    border-radius: 20px;
}

.direction-badge {
    font-size: 0.9em;
    background: #D2691E;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
}

.question-content {
    text-align: center;
}

.question-text {
    font-size: 3em;
    font-weight: bold;
    color: #8B4513;
    margin-bottom: 30px;
}

.question-value {
    font-family: 'Times New Roman', serif;
    letter-spacing: 5px;
}

.answer-area {
    margin: 20px 0;
}

.answer-input {
    width: 200px;
    padding: 15px;
    font-size: 1.5em;
    text-align: center;
    border: 3px solid #FFCC80;
    border-radius: 20px;
    font-family: inherit;
    font-weight: bold;
    letter-spacing: 2px;
}

.answer-input:focus {
    outline: none;
    border-color: #D2691E;
    box-shadow: 0 0 0 3px rgba(210, 105, 30, 0.2);
}

.answer-input.active-field {
    border-color: #D2691E;
    background: #FFF8F0;
}

/* Нумпад */
.numpad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 20px;
}

.numpad-btn {
    background: white;
    border: 2px solid #FFCC80;
    border-radius: 15px;
    padding: 12px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    font-family: inherit;
}

.numpad-btn:active {
    transform: scale(0.95);
    background: #FFECB3;
}

.numpad-btn.roman-btn {
    background: #FFF3E0;
    color: #8B4513;
    font-family: 'Times New Roman', serif;
    font-size: 1.3em;
}

.numpad-btn.backspace,
.numpad-btn.clear {
    background: #FFE0B2;
    color: #E65100;
}

/* Сообщения */
.message {
    text-align: center;
    padding: 12px;
    border-radius: 20px;
    font-weight: bold;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s;
}

.message.show {
    opacity: 1;
    transform: translateY(0);
}

.message.success {
    background: #C8E6C9;
    color: #2E7D32;
}

.message.error {
    background: #FFCDD2;
    color: #C62828;
}

.message.warning {
    background: #FFF3CD;
    color: #856404;
}

/* Кнопки управления */
.controls {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: #FFF8F0;
    border-top: 2px solid #FFEFD5;
    flex-wrap: wrap;
}

.control-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.check-btn {
    background: linear-gradient(135deg, #4CAF50, #388E3C);
    color: white;
}

.skip-btn {
    background: linear-gradient(135deg, #FF9800, #F57C00);
    color: white;
}

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

/* ЭКРАН РЕЗУЛЬТАТОВ */
.result-screen {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
}

.result-container {
    max-width: 500px;
    width: 100%;
    background: white;
    border-radius: 40px;
    padding: 35px;
    text-align: center;
}

.result-stars {
    font-size: 2.5em;
    color: #FFD700;
    margin: 15px 0;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 25px 0;
}

.result-stat {
    background: #FFF8F0;
    padding: 15px;
    border-radius: 20px;
}

.result-value {
    font-size: 1.8em;
    font-weight: bold;
    display: block;
    color: #D2691E;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-buttons button {
    padding: 15px;
    border: none;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.next-level-btn {
    background: linear-gradient(135deg, #4CAF50, #388E3C);
    color: white;
}

.levels-btn, .restart-btn {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
}

/* ЭКРАН ВРЕМЯ ВЫШЛО */
.timeout-screen {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.timeout-container {
    max-width: 400px;
    width: 100%;
    background: white;
    border-radius: 40px;
    padding: 35px;
    text-align: center;
}

.timeout-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.timeout-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.timeout-buttons button {
    padding: 14px;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
}

/* Всплывающая справка */
.floating-reference {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    width: 250px;
    z-index: 100;
    border: 2px solid #D2691E;
}

.reference-header {
    background: #D2691E;
    color: white;
    padding: 10px 15px;
    border-radius: 18px 18px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-reference {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
}

.reference-content {
    padding: 15px;
}

.ref-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 1em;
}

.ref-row .roman {
    font-weight: bold;
    color: #8B4513;
    font-family: 'Times New Roman', serif;
}

.ref-divider {
    height: 1px;
    background: #eee;
    margin: 10px 0;
}

/* Модальное окно */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: white;
    border-radius: 30px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #FFECB3;
}

.close-modal {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: #D2691E;
}

.rules-content {
    padding: 20px;
    line-height: 1.6;
}

.rules-content h3 {
    color: #D2691E;
    margin: 15px 0 10px;
}

.rules-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.tips {
    background: #FFF8F0;
    padding: 15px;
    border-radius: 20px;
    margin-top: 15px;
}

/* ПАУЗА */
.paused-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
    cursor: pointer;
}

.paused-text {
    color: white;
    font-size: 2em;
    text-align: center;
    background: rgba(0,0,0,0.7);
    padding: 40px;
    border-radius: 30px;
}

/* АНИМАЦИИ */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(50px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseBorder {
    0%, 100% { border-color: #D2691E; }
    50% { border-color: #FFB347; }
}

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

.shake {
    animation: shake 0.3s ease;
}

/* АДАПТАЦИЯ */
@media (max-width: 768px) {
    .levels-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
    
    .level-number {
        font-size: 1.4em;
    }
    
    .settings-row {
        flex-direction: column;
    }
    
    .numpad {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .question-text {
        font-size: 2em;
    }
    
    .answer-input {
        width: 150px;
        font-size: 1.2em;
    }
    
    .controls {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .levels-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .game-header {
        flex-wrap: wrap;
    }
    
    .game-level-info {
        order: 2;
        width: 100%;
        justify-content: space-between;
    }
    
    .back-btn {
        order: 1;
    }
    
    .header-controls {
        order: 3;
    }
    
    .stat-value {
        font-size: 1.2em;
    }
    
    .numpad-btn {
        padding: 8px;
        font-size: 1em;
    }
    
    .question-text {
        font-size: 1.5em;
    }
}

.continue-btn, .home-btn {
    padding: 22px;
    margin: 22px;
    border: none;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
}

.continue-btn {
    background: linear-gradient(135deg, #8B4513, #D2691E);
    color: white;
}

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