* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.screen {
    display: none;
    width: 100%;
    max-width: 500px;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container {
    background: white;
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.container.center {
    text-align: center;
}

h1 {
    color: #667eea;
    text-align: center;
    margin-bottom: 25px;
    font-size: 28px;
    font-weight: 700;
}

h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 600;
}

/* Главный экран */
.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
}

.settings {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
}

.settings h2 {
    margin-bottom: 20px;
    font-size: 18px;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 15px;
}

.setting-item input[type="number"],
.setting-item select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    background: white;
}

.setting-item input[type="number"]:focus,
.setting-item select:focus {
    outline: none;
    border-color: #667eea;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.3s;
}

.radio-label:hover {
    background: #f0f0f0;
}

.radio-label input[type="radio"] {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.radio-label input[type="radio"]:checked + span {
    font-weight: 600;
    color: #667eea;
}

.radio-label span {
    font-size: 15px;
    color: #555;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 10px;
    width: 22px;
    height: 22px;
    cursor: pointer;
}

.checkbox-label span {
    font-size: 15px;
    color: #555;
}

/* Кнопки */
.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 10px;
    touch-action: manipulation;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:active {
    transform: scale(0.98);
    background: #5a6268;
}

/* Экран обратного отсчета */
.countdown-number {
    font-size: 120px;
    font-weight: 700;
    color: #667eea;
    margin: 40px 0;
    animation: pulse 1s ease-in-out;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Игровой экран */
.game-header {
    margin-bottom: 30px;
    position: relative;
}

.progress-info {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: #555;
    margin-bottom: 15px;
}

.btn-exit {
    position: absolute;
    top: 0;
    right: 0;
    padding: 8px 16px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-exit:active {
    transform: scale(0.95);
    background: #d32f2f;
}

.timer-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50 0%, #ffeb3b 50%, #f44336 100%);
    transition: width 0.1s linear;
    border-radius: 10px;
}

.question-display {
    background: #f8f9fa;
    padding: 40px 20px;
    border-radius: 15px;
    text-align: center;
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 20px;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    transition: all 0.3s;
}

.question-display.correct {
    background: #4caf50;
    color: white;
}

.question-display.incorrect {
    background: #f44336;
    color: white;
}

.operand, .operator, .equals {
    color: #333;
}

.question-display.correct .operand,
.question-display.correct .operator,
.question-display.correct .equals,
.question-display.incorrect .operand,
.question-display.incorrect .operator,
.question-display.incorrect .equals {
    color: white;
}

.answer-display {
    min-width: 80px;
    border-bottom: 4px solid #667eea;
    color: #667eea;
}

.question-display.correct .answer-display,
.question-display.incorrect .answer-display {
    border-bottom-color: white;
    color: white;
}

.feedback-message {
    text-align: center;
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 20px;
    min-height: 45px;
}

.feedback-message.correct {
    color: #4caf50;
}

.feedback-message.incorrect {
    color: #f44336;
}

/* Клавиатура */
.keyboard {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.keyboard-row {
    display: flex;
    gap: 10px;
}

.key-btn {
    flex: 1;
    padding: 20px;
    font-size: 24px;
    font-weight: 600;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.key-btn:active {
    transform: scale(0.95);
    background: #f0f0f0;
}

.key-clear {
    background: #ff9800;
    color: white;
    border-color: #ff9800;
    font-size: 16px;
}

.key-clear:active {
    background: #f57c00;
}

.key-confirm {
    background: #4caf50;
    color: white;
    border-color: #4caf50;
    font-size: 28px;
}

.key-confirm:active {
    background: #388e3c;
}

.key-confirm:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

/* Экран результатов */
.results-summary {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #e0e0e0;
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    font-size: 16px;
    color: #555;
    font-weight: 500;
}

.result-value {
    font-size: 20px;
    font-weight: 700;
}

.result-value.correct {
    color: #4caf50;
}

.result-value.incorrect {
    color: #f44336;
}

.problem-areas {
    margin-bottom: 20px;
}

.problem-areas h3 {
    font-size: 18px;
    color: #555;
    margin-bottom: 15px;
}

.problem-list {
    background: #fff3cd;
    padding: 15px;
    border-radius: 10px;
    border-left: 4px solid #ff9800;
}

.problem-item {
    padding: 8px 0;
    color: #666;
    font-size: 15px;
}

/* Статистика */
.user-stats {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
}

.stat-header {
    font-size: 18px;
    color: #667eea;
    font-weight: 600;
    margin-bottom: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: #555;
    font-size: 15px;
}

.stat-value {
    font-weight: 600;
    color: #333;
    font-size: 15px;
}

.daily-stats {
    margin-bottom: 20px;
}

.daily-stats h3 {
    font-size: 18px;
    color: #555;
    margin-bottom: 15px;
}

.day-stat {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    border-left: 4px solid #667eea;
}

.day-date {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 8px;
    font-size: 16px;
}

.day-details {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 14px;
    color: #666;
}

.button-group {
    display: flex;
    gap: 10px;
}

.button-group .btn {
    margin-bottom: 0;
}

/* Лидерборд */
.leaderboard-filters {
    margin-bottom: 20px;
}

.leaderboard-filters label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 15px;
}

.leaderboard-filters select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    background: white;
}

.leaderboard-filters select:focus {
    outline: none;
    border-color: #667eea;
}

.leaderboard-list {
    margin-bottom: 20px;
}

.leaderboard-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: transform 0.2s;
}

.leaderboard-item:hover {
    transform: translateX(5px);
}

.leaderboard-item.current-user {
    background: linear-gradient(135deg, #fff3cd 0%, #ffe8a1 100%);
    border: 2px solid #ffc107;
    font-weight: 600;
}

.leaderboard-position {
    font-size: 24px;
    font-weight: 700;
    min-width: 40px;
    text-align: center;
}

.leaderboard-position.top1 {
    color: #ffd700;
    text-shadow: 0 2px 4px rgba(255, 215, 0, 0.3);
}

.leaderboard-position.top2 {
    color: #c0c0c0;
}

.leaderboard-position.top3 {
    color: #cd7f32;
}

.leaderboard-info {
    flex: 1;
}

.leaderboard-name {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.leaderboard-stats {
    font-size: 14px;
    color: #666;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.leaderboard-metric {
    font-size: 20px;
    font-weight: 700;
    color: #667eea;
    white-space: nowrap;
}

.no-leaderboard-data {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 16px;
}

/* Адаптация для маленьких экранов */
@media (max-width: 380px) {
    .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 22px;
        margin-bottom: 15px;
    }
    
    h2 {
        font-size: 18px;
    }
    
    .question-display {
        font-size: 32px;
        padding: 20px 10px;
        min-height: 100px;
    }
    
    .countdown-number {
        font-size: 80px;
        margin: 30px 0;
    }
    
    .key-btn {
        padding: 12px 8px;
        font-size: 18px;
    }
    
    .feedback-message {
        font-size: 24px;
        margin-bottom: 15px;
        min-height: 35px;
    }
    
    .keyboard {
        gap: 8px;
    }
    
    .keyboard-row {
        gap: 8px;
    }
    
    .game-header {
        margin-bottom: 20px;
    }
    
    .progress-info {
        font-size: 16px;
        margin-bottom: 10px;
    }
}

/* Дополнительная адаптация для очень маленьких экранов (iPhone SE) */
@media (max-width: 350px) {
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 20px;
    }
    
    .question-display {
        font-size: 28px;
        padding: 15px 8px;
        min-height: 90px;
        gap: 10px;
    }
    
    .key-btn {
        padding: 10px 6px;
        font-size: 16px;
    }
    
    .key-clear, .key-confirm {
        font-size: 14px;
    }
    
    .feedback-message {
        font-size: 20px;
        min-height: 30px;
    }
    
    .keyboard {
        gap: 6px;
    }
    
    .keyboard-row {
        gap: 6px;
    }
}

/* Улучшение для iPhone */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
    
    .container {
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Убираем эффекты выделения на touch устройствах */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

input, select {
    -webkit-user-select: text;
    user-select: text;
}
