* {
    box-sizing: border-box;
}

body {
    background: #faf8ef;
    color: #776e65;
    font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
    font-size: 18px;
    margin: 0;
    padding: 0;
}

.container {
    width: 500px;
    margin: 0 auto;
    padding: 20px;
}

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

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

.score-container {
    background: #bbada0;
    padding: 10px;
    font-size: 25px;
    height: 50px;
    font-weight: bold;
    border-radius: 3px;
    color: white;
    text-align: center;
    min-width: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.score-label {
    font-size: 13px;
    line-height: 13px;
    text-transform: uppercase;
    color: #eee4da;
    margin-bottom: 2px;
}

.score {
    font-size: 25px;
    line-height: 1;
}

.ai-controls {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    justify-content: center;
    width: 500px;
}

.control-container {
    background: #bbada0;
    padding: 10px;
    font-size: 25px;
    height: 50px;
    font-weight: bold;
    border-radius: 3px;
    color: white;
    text-align: center;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: help;
}

.control-label {
    font-size: 13px;
    line-height: 13px;
    text-transform: uppercase;
    color: #eee4da;
    margin-bottom: 2px;
    position: relative;
    cursor: help;
}

.control-label[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 5px;
    font-weight: normal;
    text-transform: none;
}

.control-label[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid rgba(0, 0, 0, 0.9);
    z-index: 1000;
}

.control-value {
    font-size: 20px;
    line-height: 1;
    background: transparent;
    border: none;
    color: white;
    text-align: center;
    width: 100%;
    font-weight: bold;
    outline: none;
}

.control-value:focus {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.ai-toggle-container {
    cursor: pointer;
    transition: background-color 0.15s ease;
    user-select: none;
}

.ai-toggle-container:hover {
    background: #cbb7a7;
}

.ai-toggle-container:active {
    background: #ab9789;
}

.ai-toggle-container.running {
    background: #dc5e2a;
}

.ai-toggle-container.running:hover {
    background: #ec6e3a;
}

.ai-status {
    pointer-events: none;
}

.game-container {
    position: relative;
    padding: 15px;
    cursor: default;
    touch-action: none;
    background: #bbada0;
    border-radius: 10px;
    width: 500px;
    height: 500px;
    margin: 0 auto;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.73);
    z-index: 100;
    text-align: center;
    border-radius: 10px;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    height: 60px;
    line-height: 60px;
    margin-top: 150px;
}

.game-message .lower {
    display: block;
    margin-top: 59px;
}

.game-message button {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    margin-left: 9px;
    border: none;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.3s ease-in-out;
}

.game-message button:hover {
    background: #9f8a76;
}

.game-over {
    background: rgba(238, 228, 218, 0.73);
    color: #776e65;
}

.game-over p {
    color: #776e65;
}

.grid-container {
    position: absolute;
    z-index: 1;
    top: 15px;
    left: 15px;
}

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

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

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

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

.tile-container {
    position: absolute;
    z-index: 2;
    top: 15px;
    left: 15px;
}

.tile {
    position: absolute;
    width: 106.25px;
    height: 106.25px;
    background: #eee4da;
    color: #776e65;
    border-radius: 6px;
    font-weight: bold;
    text-align: center;
    font-size: 55px;
    transition: all 0.15s ease-in-out;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
}

/* Tile positions */
.tile-position-1-1 { left: 0; top: 11px; }
.tile-position-1-2 { left: 121.25px; top: 11px; }
.tile-position-1-3 { left: 242.5px; top: 11px; }
.tile-position-1-4 { left: 363.75px; top: 11px; }
.tile-position-2-1 { left: 0; top: 130px; }
.tile-position-2-2 { left: 121.25px; top: 130px; }
.tile-position-2-3 { left: 242.5px; top: 130px; }
.tile-position-2-4 { left: 363.75px; top: 130px; }
.tile-position-3-1 { left: 0; top: 249px; }
.tile-position-3-2 { left: 121.25px; top: 249px; }
.tile-position-3-3 { left: 242.5px; top: 249px; }
.tile-position-3-4 { left: 363.75px; top: 249px; }
.tile-position-4-1 { left: 0; top: 366px; }
.tile-position-4-2 { left: 121.25px; top: 366px; }
.tile-position-4-3 { left: 242.5px; top: 366px; }
.tile-position-4-4 { left: 363.75px; top: 366px; }

/* Tile values styling */
.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;
}
.tile-256 { 
    background: #edcc61; 
    color: #f9f6f2; 
    font-size: 45px;
}
.tile-512 { 
    background: #edc850; 
    color: #f9f6f2; 
    font-size: 45px;
}
.tile-1024 { 
    background: #edc53f; 
    color: #f9f6f2; 
    font-size: 35px;
}
.tile-2048 { 
    background: #edc22e; 
    color: #f9f6f2; 
    font-size: 35px;
}

.tile-super {
    background: #000000;
    color: #ffffff;
    font-size: 25px;
}

.ai-info {
    display: flex;
    gap: 20px;
    margin-top: 15px;
    justify-content: center;
}

.ai-stat {
    background: #bbada0;
    padding: 8px 12px;
    border-radius: 3px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    min-width: 120px;
    text-align: center;
}

.ai-stat .label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    color: #eee4da;
    margin-bottom: 3px;
    line-height: 1;
}

.ai-stat .value {
    display: block;
    font-size: 16px;
    line-height: 1;
    color: white;
}

hr {
    border: none;
    border-bottom: 1px solid #d8d4d0;
    margin-top: 20px;
    margin-bottom: 30px;
}

footer {
    text-align: center;
    color: #776e65;
    font-size: 14px;
}

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

.tile-new {
    animation: appear 200ms ease-out;
}

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

.tile-merged {
    animation: pop 200ms ease-out;
}

/* Mobile responsiveness */
@media screen and (max-width: 520px) {
    html, body {
        font-size: 15px;
    }

    .container {
        width: 280px;
        margin: 0 auto;
    }

    h1 {
        font-size: 50px;
    }

    .score-container {
        min-width: 60px;
        height: 40px;
        font-size: 20px;
        padding: 5px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .score-label {
        font-size: 11px;
        margin-bottom: 1px;
    }

    .score {
        font-size: 18px;
        line-height: 1;
    }

    .game-container {
        padding: 10px;
        width: 280px;
        height: 280px;
    }

    .grid-container {
        top: 10px;
        left: 10px;
    }

    .tile-container {
        top: 10px;
        left: 10px;
    }

    .grid-cell {
        width: 57.5px;
        height: 57.5px;
        margin-right: 10px;
        margin-bottom: 10px;
    }

    .tile {
        width: 57.5px;
        height: 57.5px;
        line-height: 57.5px;
        font-size: 30px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 25px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 20px;
    }

    .tile-super {
        font-size: 18px;
    }

    /* Mobile tile positions */
    .tile-position-1-1 { left: 0; top: 0; }
    .tile-position-1-2 { left: 67.5px; top: 0; }
    .tile-position-1-3 { left: 135px; top: 0; }
    .tile-position-1-4 { left: 202.5px; top: 0; }
    .tile-position-2-1 { left: 0; top: 67.5px; }
    .tile-position-2-2 { left: 67.5px; top: 67.5px; }
    .tile-position-2-3 { left: 135px; top: 67.5px; }
    .tile-position-2-4 { left: 202.5px; top: 67.5px; }
    .tile-position-3-1 { left: 0; top: 135px; }
    .tile-position-3-2 { left: 67.5px; top: 135px; }
    .tile-position-3-3 { left: 135px; top: 135px; }
    .tile-position-3-4 { left: 202.5px; top: 135px; }
    .tile-position-4-1 { left: 0; top: 202.5px; }
    .tile-position-4-2 { left: 67.5px; top: 202.5px; }
    .tile-position-4-3 { left: 135px; top: 202.5px; }
    .tile-position-4-4 { left: 202.5px; top: 202.5px; }

    .game-message p {
        font-size: 40px;
        margin-top: 80px;
    }

    .game-message .lower {
        margin-top: 30px;
    }
}