body {
    --text-color: #555;              /* Daha koyu bir metin rengi */
    --bg-color: #f2f0eb;             /* Hafif dokulu arka plan */
    --grid-bg: #b5a58e;              /* Daha doğal tonlarda bir ızgara */
    --cell-bg: #dcd2c0;              /* Daha açık hücre rengi */
    --button-bg: #8e7a62;            /* Daha sıcak tonlu butonlar */
    --button-text: white;
    --button-bg-hover: #a08c75;       /* Buton hover rengi */
    --tile-text: #f9f6f2;
    --accent-color: #e74c3c;          /* Seçim rengi */
    --new-tile-bg: #eee4da;           /* Yeni taş rengi */

    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Daha modern font */
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none; /* Mobil deneyimi iyileştirmek için metin seçimini engeller */
}

h1 {
    font-size: 48px;
    color: var(--text-color);
    margin-bottom: 5px;
}

.visitor-counter {
    text-align: center;
    margin-bottom: 15px;
}

.difficulty-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.difficulty-btn {
    padding: 8px 16px;
    font-size: 16px;
    background-color: var(--cell-bg);
    color: var(--text-color); /* Buton metin rengi */
    border: 2px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.difficulty-btn.active, .difficulty-btn:hover {
    background-color: var(--button-bg);
    color: var(--button-text); /* Aktif buton metin rengi */
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 90%;
    max-width: 500px; /* Oyun alanının çok büyümesini engelle */
    font-size: 24px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.score-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px; /* Skor etiketleri arası boşluk */
}

.btn {
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: bold;
    padding: 10px 15px; /* Daha dolgun butonlar */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Hafif gölge */
}

.btn:hover {
    background-color: var(--button-bg-hover);
}

.game-controls {
    flex-direction: column;
    align-items: flex-end;
}

.control-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-bottom: 8px;
}

/* Tüm kontrol butonları için ortak stil */
#undo-button, #restart-button-main, #toggle-sound-button, #how-to-play-button {
    padding: 8px 12px;
    font-size: 16px;
}

/* Ses butonunu daha ikon gibi yapmak için */
#toggle-sound-button {
    padding: 8px;
    min-width: 36px; /* Butonların zıplamasını engeller */
}

#undo-button:disabled {
    background-color: var(--grid-bg);
    cursor: not-allowed;
    opacity: 0.6;
}

#selection-info {
    font-size: 20px;
    font-weight: bold;
    color: var(--accent-color);
    min-width: 80px;
    text-align: right;
    transition: opacity 0.2s;
}

#game-board {
    display: grid;
    /* Grid boyutları artık JS tarafından ayarlanacak */
    gap: 10px;
    background-color: var(--grid-bg);
    border: 10px solid var(--grid-bg);
    border-radius: 6px;
    position: relative;
}

.cell {
    /* Genişlik ve yükseklik artık JS tarafından ayarlanacak */
    background-color: var(--cell-bg);
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Font boyutu artık JS tarafından ayarlanacak */
    font-weight: bold;
    transition: all 0.1s ease-in-out;
}

.cell.selected {
    /* !important, diğer tile-N arkaplan renklerini ezmek için kullanılır */
    background-color: rgba(255, 255, 255, 0.7) !important; /* Daha şeffaf seçim rengi */
    transform: scale(1.05);
    outline: 3px solid var(--accent-color);
    outline-offset: -3px;
}

/* Sayılar için farklı renkler */
.tile { color: var(--tile-text); }
.tile-2 { background-color: #eee4da; color: var(--text-color); }
.tile-4 { background-color: #ede0c8; color: var(--text-color); }
.tile-8 { background-color: #f2b179; }
/* Sayılar için daha belirgin ve farklı ana renkler */
.tile-16 { background-color: #f1c40f; } /* Sarı */
.tile-32 { background-color: #2ecc71; } /* Yeşil */
.tile-64 { background-color: #1abc9c; } /* Turkuaz */
.tile-128 { background-color: #3498db; } /* Mavi */
.tile-256 { background-color: #9b59b6; } /* Mor */
.tile-512 { background-color: #d35400; } /* Koyu Turuncu */
.tile-1024 { background-color: #2980b9; } /* Koyu Mavi */
.tile-2048 { background-color: #34495e; } /* Koyu Gri (Özel Renk) */

/* Oyun Bitti Ekranı */
#game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Modern bulanıklaştırma efekti için arka plan */
    background-color: rgba(242, 240, 235, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px); /* Safari uyumluluğu */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 100; /* Diğer her şeyin üzerinde olmasını garantiler */
    animation: fadeIn 0.3s ease-out; /* Yumuşak giriş animasyonu */
}

#game-over h2 {
    font-size: 50px;
    color: var(--text-color);
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1); /* Yazıya derinlik kat */
}

#game-over p {
    font-size: 20px;
    margin-top: 10px;
}

#restart-button {
    padding: 12px 24px;
    font-size: 20px;
    margin-top: 25px;
}

.hidden {
    display: none !important;
}

/* Birleşme animasyonu */
.merged {
    animation: pop 0.3s ease-out;
}

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

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

/* Yeni en yüksek skor animasyonu */
.new-high-score {
    animation: new-score-pop 0.6s ease-out;
}

@keyframes new-score-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.25) translateX(5px); color: #f59563; }
    100% { transform: scale(1); }
}

/* En küçük sayının yok olma animasyonu */
.tile-fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.5);
    }
}

/* Mobil cihazlar için medya sorgusu */
@media (max-width: 480px) {
    h1 {
        font-size: 36px;
    }
    .game-info {
        font-size: 18px;
        /* Mobil için dikey hizalama */
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    .score-container, .game-controls {
        align-items: center;
    }
    #selection-info {
        font-size: 18px;
        min-width: 80px;
        text-align: center;
    }
    #undo-button, #restart-button-main, #restart-button, #how-to-play-button {
        font-size: 14px;
        padding: 8px 12px;
    }
    .control-buttons {
        gap: 8px; /* Butonlar arası boşluğu biraz artır */
    }
    #game-over h2 {
        font-size: 40px;
    }
}

/* Nasıl Oynanır? Modalı */
.modal {
    position: fixed; /* Sayfa kaydırılsa bile yerinde kalır */
    z-index: 1000; /* Diğer her şeyin üzerinde olmalı */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5); /* Daha az opak arka plan */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.modal-content {
    background-color: var(--bg-color);
    padding: 25px 35px;
    border: 1px solid #ccc;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    color: var(--text-color);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    animation: modalopen 0.4s ease-out;
}

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

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 20px; /* Başlık altına boşluk ekle */
    color: var(--button-bg);
}
.modal-content li {
    margin-bottom: 12px;
    line-height: 1.6; /* Daha okunaklı satır yüksekliği */
}

.close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #999;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}
.close-button:hover {
    color: var(--text-color);
    transform: scale(1.1); /* Butona küçük bir etkileşim ekle */
}
