/* Сброс стилей и базовые настройки */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    outline: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden !important;
    touch-action: manipulation;
}

body {
    background-color: #f5f5f5;
    background-image: url('back.png');
    background-size: cover; /* Растягивает изображение на весь экран */
    background-position: center;
    background-repeat: no-repeat;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: Arial, sans-serif;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

body.dark-theme {
    background-color: #121212;
    background-image: url('back_dark.png');
    color: #e0e0e0;
}

#app {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Общие стили для всех экранов */
.screen {
    width: 100%;
    max-width: 500px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.dark-theme .screen {
    background-color: #1e1e1e;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Стили для главного меню */
.menu-title {
    font-size: 28px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px;
    text-align: center;
}

.dark-theme .menu-title {
    color: #3498db;
}

.menu-button {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.menu-button:hover {
    background-color: #2980b9;
}

/* Стили для выбора уровня */
.level-button {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.level-button:hover {
    background-color: #27ae60;
}

.back-button {
    background-color: #e74c3c;
    margin-top: 10px;
}

.back-button:hover {
    background-color: #c0392b;
}

/* Стили для игрового поля */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
    gap: 10px;
}

.timer {
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
}

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

.game-button {
    padding: 8px 12px;
    font-size: 14px;
    background-color: #f39c12;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
}

.game-button.exit-button {
    background-color: #e74c3c;
}

.board-container {
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 1px;
    width: 100%;
    max-width: 100vw;
    aspect-ratio: 1/1;
    background-color: #333;
    border: 2px solid #333;
    touch-action: none;
}

.dark-theme .board {
    background-color: #444;
    border-color: #444;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: white;
    font-size: min(5vw, 20px);
    font-weight: bold;
    cursor: pointer;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
}

.cell.selected {
    background-color: #b9e4ff; 
}

.dark-theme .cell.selected {
    background-color: #1f1f1f; 
}

.dark-theme .cell {
    background-color: #2d2d2d;
    color: #e0e0e0;
}

.cell.fixed {
    background-color: #f0f0f0;
    color: #000;
}

.dark-theme .cell.fixed {
    background-color: #333;
    color: #e0e0e0;
}

.cell.user-input {
    color: #3498db;
}

.dark-theme .cell.user-input {
    color: #5dade2;
}

.cell.highlighted {
    background-color: #e3f2fd;
}

.dark-theme .cell.highlighted {
    background-color: hsl(0, 0%, 15%);
}

.cell.error {
    color: #e74c3c;
}

.dark-theme .cell.error {
    color: #f1948a;
}

.cell:nth-child(3n) {
    margin-right: 2px;
}

.cell:nth-child(9n+1) {
    margin-left: 0;
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    margin-bottom: 2px;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    width: 100%;
    margin-top: 10px;
}

.number-button {
    padding: 10px;
    font-size: 18px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.number-button:hover {
    background-color: #2980b9;
}

.erase-button {
    background-color: #e74c3c;
}

.erase-button:hover {
    background-color: #c0392b;
}

/* Стили для экрана результата */
.result-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
}

.result-info {
    font-size: 16px;
    margin-bottom: 5px;
    text-align: center;
}

.stars {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    justify-content: center;
}

.star {
    font-size: 30px;
    color: #f1c40f;
}

.star.empty {
    color: #ddd;
}

.dark-theme .star.empty {
    color: #555;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.result-button {
    padding: 10px;
    font-size: 16px;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    width: 100%;
}

/* Стили для статистики */
.stats-table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th, .stats-table td {
    padding: 8px;
    text-align: center;
    border-bottom: 1px solid #ddd;
}

.dark-theme .stats-table th,
.dark-theme .stats-table td {
    border-bottom: 1px solid #444;
}

.stats-table th {
    background-color: #f2f2f2;
}

.dark-theme .stats-table th {
    background-color: #2d2d2d;
}

/* Стили для настроек */
.settings-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.dark-theme .settings-option {
    border-bottom: 1px solid #444;
}

.settings-option:last-child {
    border-bottom: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #2196F3;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Стили для подтверждения выхода */
.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.confirm-dialog {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    max-width: 80%;
    text-align: center;
}

.dark-theme .confirm-dialog {
    background-color: #2d2d2d;
}

.confirm-message {
    margin-bottom: 20px;
    font-size: 16px;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-button {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.confirm-button.cancel {
    background-color: #3498db;
    color: white;
}

.confirm-button.confirm {
    background-color: #e74c3c;
    color: white;
}

/* Стили для профиля игрока */
.player-profile {
    position: fixed;
    top: 10px;
    left: 10px;
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(58, 58, 58, 0.7);
    backdrop-filter: blur(5px);
    padding: 6px 12px;
    border-radius: 20px;
    color: white;
    font-size: 16px;
    font-weight: 500;
    z-index: 1000;
}

.player-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}

/* Адаптация для маленьких экранов */
@media (max-width: 400px) {
    .game-header {
        flex-direction: column;
    }
    
    .game-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .game-button {
        width: 48%;
        padding: 8px;
    }
    
    .number-button {
        padding: 8px;
        font-size: 16px;
    }
}

/* Специальные стили для очень маленьких экранов iPhone */
@media (max-width: 350px) and (max-height: 700px) {
    .screen {
        padding: 10px;
        gap: 8px;
    }
    
    .board {
        max-width: 95vw;
        aspect-ratio: 1/1;
    }
    
    .cell {
        font-size: 14px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 5px;
    }
    
    .timer {
        font-size: 16px;
    }
    
    .game-button {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .number-button {
        padding: 6px;
        font-size: 14px;
    }
    
    .menu-title {
        font-size: 22px;
    }
    
    .menu-button {
        padding: 10px;
        font-size: 16px;
    }
}

/* Для экранов с очень маленькой высотой */
@media (max-height: 600px) {
    #app {
        padding: 5px;
    }
    
    .screen {
        padding: 8px;
        max-height: 95vh;
    }
    
    .board {
        max-width: 90vw;
    }
}

/* Улучшение для всех маленьких экранов */
@media (max-width: 380px) {
    .board {
        gap: 0.5px;
    }
    
    .cell {
        font-size: 12px;
    }
    
    .number-pad {
        grid-template-columns: repeat(5, 1fr);
        gap: 3px;
    }
    
    .number-button {
        padding: 6px 4px;
        font-size: 14px;
    }
}