/* Mobile CSS */

@media (max-width: 500px) {
    .container {
        padding: 10px;
    }

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

    .grid {
        width: 100%;
    }

    .tile {
        font-size: 20px;
    }

    h1 {
        font-size: 36px;
    }

    .score-container {
        padding: 10px 15px;
    }

    .header {
        flex-direction: column;
        gap: 10px;
    }

    .name-container {
        width: 100%;
        padding: 10px 15px;
    }
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 20px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

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

.title-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

h1 {
    font-size: 52px;
    font-weight: bold;
    margin: 0;
    color: #776e65;
}

.subtitle {
    font-size: 16px;
    color: #776e65;
    margin-top: 5px;
}

.score-container {
    background: #bbada0;
    padding: 15px 25px;
    border-radius: 6px;
    color: white;
    min-width: 100px;
    text-align: center;
}

.score-title {
    font-size: 13px;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.score {
    font-size: 25px;
    font-weight: bold;
}

.game-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    position: relative;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 10px;
    background-color: #bbada0;
    padding: 10px;
    border-radius: 6px;
    width: 100%;
    position: relative;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.cell {
    width: 100%;
    padding-bottom: 100%;
    /* Makes cells square */
    background-color: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
}

.tile {
    position: absolute;
    width: calc(25% - 10px);
    height: calc(25% - 10px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    color: #776e65;
    background-color: #eee4da;
    border-radius: 3px;
    transition: all 0.15s ease-in-out;
    z-index: 1;
}

.button {
    background: #8f7a66;
    border-radius: 6px;
    /* padding: 10px 20px; */
    font-size: 18px;
    font-weight: bold;
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    margin: 20px 0;
}

.button:hover {
    background: #7f6a56;
}

.instructions {
    background: white;
    border-radius: 6px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.instructions h2 {
    color: #776e65;
    margin-top: 0;
}

.controls {
    display: flex;
    gap: 10px;
    margin: 15px 0;
}

.key {
    background: #eee4da;
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
}

.leaderboard {
    background: white;
    border-radius: 6px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.leaderboard h2 {
    color: #776e65;
    margin-top: 0;
    margin-bottom: 15px;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

#leaderboard-table th,
#leaderboard-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee4da;
}

#leaderboard-table th {
    background-color: #bbada0;
    color: white;
}

#leaderboard-table tr:nth-child(even) {
    background-color: #faf8ef;
}

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

.name-container {
    width: 100%;
    max-width: 400px;
    /* Same as game-container */
    margin: 0 auto 20px auto;
    /* Centers and adds space between name input and game */
    background: #bbada0;
    padding: 10px;
    border-radius: 6px;
    color: white;
}

.name-title {
    font-size: 13px;
    text-transform: uppercase;
    margin-bottom: 5px;
    text-align: center;
}

.name-input {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 3px;
    font-size: 16px;
    text-align: center;
    background: #f9f6f2;
    color: #776e65;
    font-family: inherit;
    box-sizing: border-box;
}

.name-input:focus {
    outline: none;
    box-shadow: 0 0 3px rgba(255, 255, 255, 0.5);
}

.name-input::placeholder {
    color: #bbb;
}

.score-button-container {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    width: 100%;
}

.score-button-container .score-container,
.score-button-container .button {
    flex: 1;
    margin: 0;
    box-sizing: border-box;
}

.score-button-container .button {
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px 25px;
    margin: 0;
    font-size: 18px;
    min-width: 100px;
    box-sizing: border-box;  /* Add this */
    width: 100%;            /* Add this */
    
}

.score-button-container .score-container {
    margin: 0;
}

.name-container {
    margin-bottom: 10px;
}

/* Existing tile styles */
.tile[data-value="2"] {
    background-color: #eee4da;
}

.tile[data-value="4"] {
    background-color: #ede0c8;
}

.tile[data-value="8"] {
    background-color: #f2b179;
    color: #f9f6f2;
}

.tile[data-value="16"] {
    background-color: #f59563;
    color: #f9f6f2;
}

.tile[data-value="32"] {
    background-color: #f67c5f;
    color: #f9f6f2;
}

.tile[data-value="64"] {
    background-color: #f65e3b;
    color: #f9f6f2;
}

.tile[data-value="128"] {
    background-color: #edcf72;
    color: #f9f6f2;
}

.tile[data-value="256"] {
    background-color: #edcc61;
    color: #f9f6f2;
}

.tile[data-value="512"] {
    background-color: #edc850;
    color: #f9f6f2;
}

.tile[data-value="1024"] {
    background-color: #edc53f;
    color: #f9f6f2;
}

.tile[data-value="2048"] {
    background-color: #edc22e;
    color: #f9f6f2;
}

.tile.new {
    animation: appear 0.2s;
}

.tile.merge {
    animation: merge 0.2s;
    z-index: 2;
}

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

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.timeframe-select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #bbada0;
    background-color: #f9f6f2;
    color: #776e65;
    font-family: inherit;
    cursor: pointer;
}

.timeframe-select:focus {
    outline: none;
    border-color: #8f7a66;
}

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

    100% {
        transform: scale(1);
    }
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(119, 110, 101, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: #faf8ef;
    border-radius: 8px;
    padding: 32px 28px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(119, 110, 101, 0.35), 0 0 0 1px rgba(187, 173, 160, 0.4);
    transform: scale(0.92);
    transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.modal-overlay.is-open .modal {
    transform: scale(1);
}

.modal-title {
    margin: 0 0 18px 0;
    color: #776e65;
    font-size: 32px;
    font-weight: bold;
    letter-spacing: -0.5px;
}

.modal-score-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #bbada0;
    margin-bottom: 6px;
}

.modal-score {
    font-size: 48px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 24px;
    line-height: 1;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .button {
    flex: 1;
    margin: 0;
    padding: 12px 16px;
    font-size: 16px;
}

.modal-button-secondary {
    background: transparent;
    color: #8f7a66;
    box-shadow: inset 0 0 0 2px #bbada0;
}

.modal-button-secondary:hover {
    background: #eee4da;
}
