/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

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

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

.back-button {
    text-decoration: none;
    color: #2d3436;
    font-size: 1.1em;
    font-weight: 600;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.back-button:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.title {
    font-size: 3em;
    color: #2d3436;
    text-align: center;
    flex: 1;
    font-weight: 800;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* ==================== Game Info ==================== */
.game-info {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.info-box {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 30px;
    border-radius: 10px;
    text-align: center;
    min-width: 120px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.info-box.highlight {
    background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
    color: white;
}

.label {
    font-size: 0.9em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
    opacity: 0.8;
}

.value {
    font-size: 2em;
    font-weight: 800;
}

/* ==================== Instructions ==================== */
.instructions {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.instructions p {
    color: #2d3436;
    font-size: 0.95em;
    margin: 5px 0;
    font-weight: 500;
}

/* ==================== Game Board ==================== */
.game-board {
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.tile {
    aspect-ratio: 1;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: 800;
    color: #776e65;
    transition: all 0.15s ease;
    position: relative;
}

.tile.tile-2 { background: #eee4da; color: #776e65; }
.tile.tile-4 { background: #ede0c8; color: #776e65; }
.tile.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile.tile-16 { background: #f59563; color: #f9f6f2; }
.tile.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile.tile-128 { background: #edcf72; color: #f9f6f2; font-size: 1.6em; }
.tile.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 1.6em; }
.tile.tile-512 { background: #edc850; color: #f9f6f2; font-size: 1.6em; }
.tile.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 1.3em; }
.tile.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 1.3em; box-shadow: 0 0 30px #edc22e; }

.tile.tile-new {
    animation: pop 0.2s ease;
}

.tile.tile-merged {
    animation: merge 0.2s ease;
}

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

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

/* ==================== Controls ==================== */
.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.control-btn {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.new-game-btn {
    background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
    color: white;
}

.undo-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #2d3436;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== Overlays ==================== */
.game-over-overlay,
.win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.game-over-overlay.show,
.win-overlay.show {
    display: flex;
}

.game-over-content,
.win-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    animation: scaleIn 0.3s ease;
}

.game-over-title,
.win-title {
    font-size: 2.5em;
    color: #2d3436;
    margin-bottom: 15px;
}

.win-message {
    font-size: 1.2em;
    color: #636e72;
    margin-bottom: 10px;
}

.final-score {
    font-size: 1.3em;
    color: #636e72;
    margin-bottom: 25px;
}

.final-score span {
    font-weight: 800;
    color: #e17055;
    font-size: 1.3em;
}

.play-again-btn,
.continue-btn {
    padding: 15px 40px;
    border: none;
    border-radius: 50px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
}

.play-again-btn {
    background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
    color: white;
}

.continue-btn {
    background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
    color: white;
}

.play-again-btn:hover,
.continue-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

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

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ==================== Responsive ==================== */
@media (max-width: 600px) {
    .title {
        font-size: 2em;
    }

    .tile {
        font-size: 1.5em;
    }

    .tile.tile-128,
    .tile.tile-256,
    .tile.tile-512 {
        font-size: 1.2em;
    }

    .tile.tile-1024,
    .tile.tile-2048 {
        font-size: 1em;
    }
}
