:root {
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --grid-bg: #bbada0;
    --empty-tile: rgba(238, 228, 218, 0.35);
    --text-dark: #776e65;
    --text-light: #f9f6f2;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-dark);
    color: #f8fafc;
    overflow-x: hidden;
    touch-action: none;
}

.game-container {
    max-width: 500px;
    margin: 60px auto 20px;
    padding: 15px;
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-icon-small {
    width: 40px;
    height: 40px;
}

.back-btn {
    padding: 8px 16px;
    background: #334155;
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
}

.game-info {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.score-container {
    background: #334155;
    padding: 10px 25px;
    border-radius: 12px;
    text-align: center;
}

.info-label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #94a3b8;
}

.info-value {
    font-size: 1.5rem;
    font-weight: bold;
}

.game-screen {
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
    background: #111827;
    border-radius: 16px;
    padding: 12px;
    box-sizing: border-box;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
    background: var(--grid-bg);
    border-radius: 8px;
    padding: 12px;
    box-sizing: border-box;
}

.tile {
    width: 100%;
    height: 100%;
    background: var(--empty-tile);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    transition: transform 0.1s, background-color 0.1s;
}

/* Tile Colors */
.tile-2 {
    background: #eee4da;
    color: var(--text-dark);
}

.tile-4 {
    background: #ede0c8;
    color: var(--text-dark);
}

.tile-8 {
    background: #f2b179;
    color: var(--text-light);
}

.tile-16 {
    background: #f59563;
    color: var(--text-light);
}

.tile-32 {
    background: #f67c5f;
    color: var(--text-light);
}

.tile-64 {
    background: #f65e3b;
    color: var(--text-light);
}

.tile-128 {
    background: #edcf72;
    color: var(--text-light);
    font-size: 1.6rem;
}

.tile-256 {
    background: #edcc61;
    color: var(--text-light);
    font-size: 1.6rem;
}

.tile-512 {
    background: #edc850;
    color: var(--text-light);
    font-size: 1.6rem;
}

.tile-1024 {
    background: #edc53f;
    color: var(--text-light);
    font-size: 1.2rem;
}

.tile-2048 {
    background: #edc22e;
    color: var(--text-light);
    font-size: 1.2rem;
}

/* Screens */
.start-screen,
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 16px;
    backdrop-filter: blur(4px);
}

.hidden {
    display: none !important;
}

.start-content,
.game-over-content {
    text-align: center;
    padding: 20px;
    max-width: 80%;
}

.setup-group {
    margin: 20px 0;
    text-align: left;
}

.setup-group label {
    display: block;
    margin-bottom: 8px;
    color: #94a3b8;
}

.setup-group input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #475569;
    background: #0f172a;
    color: white;
    box-sizing: border-box;
}

.game-start-btn,
.restart-btn {
    width: 100%;
    padding: 15px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1.1rem;
}

.controls-hint {
    margin: 20px 0;
    color: #94a3b8;
    font-size: 0.9rem;
}

.record-box {
    margin: 15px 0;
    padding: 15px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
}

.bottom-ad {
    margin-top: 20px;
    text-align: center;
}

@media (max-width: 400px) {
    .grid-container {
        gap: 8px;
        padding: 8px;
    }

    .tile {
        font-size: 1.5rem;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 1.2rem;
    }
}