/* ===== БАЗОВЫЕ СТИЛИ ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background: #faf8ef;
    color: #776e65;
    font-size: 18px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 500px;
}

/* ===== ШАПКА ===== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.title {
    font-size: 80px;
    font-weight: bold;
    color: #776e65;
}

.scores {
    display: flex;
    gap: 10px;
}

.score-container {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 6px;
    text-align: center;
    min-width: 80px;
}

.score-label {
    display: block;
    font-size: 13px;
    color: #eee4da;
    text-transform: uppercase;
}

.score-value {
    display: block;
    font-size: 25px;
    font-weight: bold;
    color: white;
}

/* ===== КНОПКИ УПРАВЛЕНИЯ ===== */
.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn:hover {
    background: #9f8a76;
}

.btn-primary {
    background: #edc53f;
    color: #776e65;
    font-weight: bold;
}

.btn-primary:hover {
    background: #edc22e;
}

/* ===== ИГРОВОЕ ПОЛЕ ===== */
.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    width: 100%;
    max-width: 500px;
    height: 500px;
    padding: 15px;
    touch-action: none;
}

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    display: flex;
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 106.25px;
    height: 106.25px;
    margin-right: 15px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
}

.grid-cell:last-child {
    margin-right: 0;
}

/* ===== ПЛИТКИ ===== */
.tile-container {
    position: absolute;
    z-index: 2;
}

.tile {
    position: absolute;
    width: 106.25px;
    height: 106.25px;
    background: #eee4da;
    border-radius: 3px;
    font-size: 55px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease-in-out;
    z-index: 10;
}

/* Анимация появления */
.tile-new {
    animation: appear 0.2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Анимация слияния */
.tile-merged {
    animation: pop 0.2s ease-in-out;
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Цвета плиток */
.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile-16 { background: #f59563; color: #f9f6f2; }
.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile-128 { 
    background: #edcf72; 
    color: #f9f6f2; 
    font-size: 45px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.2381);
}
.tile-256 { 
    background: #edcc61; 
    color: #f9f6f2; 
    font-size: 45px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.31746);
}
.tile-512 { 
    background: #edc850; 
    color: #f9f6f2; 
    font-size: 45px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.39683);
}
.tile-1024 { 
    background: #edc53f; 
    color: #f9f6f2; 
    font-size: 35px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.47619);
}
.tile-2048 { 
    background: #edc22e; 
    color: #f9f6f2; 
    font-size: 35px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556);
}

/* ===== МОБИЛЬНОЕ УПРАВЛЕНИЕ ===== */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.horizontal-arrows {
    display: flex;
    gap: 10px;
}

.arrow-btn {
    width: 70px;
    height: 70px;
    font-size: 30px;
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.arrow-btn:active {
    transform: scale(0.95);
    background: #9f8a76;
}

/* ===== МОДАЛЬНЫЕ ОКНА ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.73);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    visibility: visible;
    transition: all 0.3s;
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
}

.modal-content h2 {
    font-size: 40px;
    margin-bottom: 20px;
    color: #776e65;
}

.modal-content p {
    font-size: 20px;
    margin-bottom: 20px;
}

.name-input-container {
    margin: 20px 0;
}

#player-name {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    border: 2px solid #bbada0;
    border-radius: 6px;
    margin-bottom: 15px;
    text-align: center;
}

.success-message {
    color: #8f7a66;
    font-weight: bold;
    margin: 15px 0;
}

/* ===== ТАБЛИЦА ЛИДЕРОВ ===== */
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid #bbada0;
}

.leaderboard-table th {
    background: #bbada0;
    color: white;
    font-weight: bold;
}

.leaderboard-table tr:nth-child(even) {
    background: #f5f5f5;
}

.leaderboard-table tr:hover {
    background: #eee4da;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 520px) {
    body {
        padding: 10px;
    }
    
    .title {
        font-size: 50px;
    }
    
    .game-container {
        height: 350px;
        padding: 10px;
    }
    
    .grid-cell {
        width: 72.5px;
        height: 72.5px;
        margin-right: 10px;
    }
    
    .tile {
        width: 72.5px;
        height: 72.5px;
        font-size: 35px;
    }
    
    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 25px;
    }
    
    .tile-1024,
    .tile-2048 {
        font-size: 21px;
    }
    
    .mobile-controls {
        display: flex;
    }
    
    .controls {
        justify-content: center;
    }
    
    .btn {
        font-size: 14px;
        padding: 8px 15px;
    }
}

@media (max-width: 350px) {
    .game-container {
        height: 300px;
    }
    
    .grid-cell,
    .tile {
        width: 61.25px;
        height: 61.25px;
    }
}