* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s ease;
}

body.dark-mode {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

body.dark-mode .container {
    background: rgba(30, 30, 45, 0.95);
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.7);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 4em;
    font-weight: bold;
    color: #776e65;
    margin: 0;
    transition: color 0.3s ease;
}

body.dark-mode h1 {
    color: #ffd89b;
}

.score-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 8px;
    text-align: center;
    min-width: 80px;
    transition: background 0.3s ease;
}

body.dark-mode .score-box {
    background: #4a4a5e;
}

.score-label {
    font-size: 0.8em;
    color: #eee4da;
    font-weight: bold;
    text-transform: uppercase;
    transition: color 0.3s ease;
}

body.dark-mode .score-label {
    color: #c4c4d4;
}

.score-value {
    font-size: 1.5em;
    color: white;
    font-weight: bold;
}

.theme-toggle {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 15px;
}

.theme-button {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 10px 18px;
    font-size: 1.3em;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-button:hover {
    background: #9f8a76;
    transform: translateY(-2px) rotate(15deg);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .theme-button {
    background: #ffd89b;
}

body.dark-mode .theme-button:hover {
    background: #ffe4b5;
}

.theme-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.game-intro {
    margin-bottom: 20px;
}

.game-description {
    color: #776e65;
    font-size: 1.1em;
    margin-bottom: 15px;
    transition: color 0.3s ease;
}

body.dark-mode .game-description {
    color: #d4d4e4;
}

.button-container {
    display: flex;
    gap: 10px;
}

.new-game-button, .undo-button {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.new-game-button:hover, .undo-button:hover {
    background: #9f8a76;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.undo-button {
    background: #ed9f3f;
}

.undo-button:hover {
    background: #f0a64f;
}

.undo-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

body.dark-mode .undo-button:disabled {
    background: #555;
}

.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 10px;
    padding: 15px;
    margin: 20px 0;
    width: 500px;
    height: 500px;
    transition: background 0.3s ease;
}

body.dark-mode .game-container {
    background: #3a3a4e;
}

.grid-container {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 470px;
    height: 470px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 15px;
    z-index: 1;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    width: 106.25px;
    height: 106.25px;
    transition: background 0.3s ease;
}

body.dark-mode .grid-cell {
    background: rgba(60, 60, 80, 0.5);
    border: 2px solid rgba(80, 80, 100, 0.6);
}

.tile-container {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 470px;
    height: 470px;
    z-index: 2;
}

.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 106.25px;
    height: 106.25px;
    background: #eee4da;
    border-radius: 8px;
    font-size: 2em;
    font-weight: bold;
    color: #776e65;
    transition: all 0.15s ease-in-out;
}

body.dark-mode .tile {
    border: 3px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.tile.new-tile {
    animation: appear 0.2s ease-in-out;
}

.tile.merged-tile {
    animation: merge 0.2s ease-in-out;
}

@keyframes appear {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

@keyframes merge {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Tile colors */
.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: 1.8em; }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 1.8em; }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 1.8em; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 1.5em; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 1.5em; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.5); }
.tile-super { background: #3c3a32; color: #f9f6f2; font-size: 1.2em; }

/* Dark mode tile colors */
body.dark-mode .tile-2 { background: #5a5a6e; color: #e4e4f4; border-color: rgba(200, 200, 220, 0.4); }
body.dark-mode .tile-4 { background: #6a6a7e; color: #e4e4f4; border-color: rgba(200, 200, 220, 0.4); }
body.dark-mode .tile-8 { background: #d4824f; color: #f9f6f2; border-color: rgba(255, 160, 100, 0.5); }
body.dark-mode .tile-16 { background: #d47043; color: #f9f6f2; border-color: rgba(255, 140, 80, 0.5); }
body.dark-mode .tile-32 { background: #d4573f; color: #f9f6f2; border-color: rgba(255, 120, 70, 0.5); }
body.dark-mode .tile-64 { background: #d43f1b; color: #f9f6f2; border-color: rgba(255, 100, 50, 0.6); }
body.dark-mode .tile-128 { background: #d4af52; color: #f9f6f2; font-size: 1.8em; border-color: rgba(255, 200, 100, 0.6); }
body.dark-mode .tile-256 { background: #d4ac41; color: #f9f6f2; font-size: 1.8em; border-color: rgba(255, 195, 80, 0.6); }
body.dark-mode .tile-512 { background: #d4a830; color: #f9f6f2; font-size: 1.8em; border-color: rgba(255, 190, 70, 0.7); }
body.dark-mode .tile-1024 { background: #d4a51f; color: #f9f6f2; font-size: 1.5em; border-color: rgba(255, 185, 60, 0.7); }
body.dark-mode .tile-2048 { background: #ffd700; color: #1a1a2e; font-size: 1.5em; box-shadow: 0 0 30px 10px rgba(255, 215, 0, 0.6), 0 3px 10px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.3); border: 3px solid rgba(255, 215, 0, 0.9); }
body.dark-mode .tile-super { background: #1c1c22; color: #f9f6f2; font-size: 1.2em; border-color: rgba(150, 150, 180, 0.5); }

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.95);
    border-radius: 10px;
    z-index: 100;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: background 0.3s ease;
}

body.dark-mode .game-message {
    background: rgba(40, 40, 60, 0.95);
}

.game-message p {
    font-size: 3em;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
    transition: color 0.3s ease;
}

body.dark-mode .game-message p {
    color: #d4d4e4;
}

.game-message.game-over,
.game-message.game-won {
    display: flex;
}

.game-message.game-won p {
    color: #f59563;
}

body.dark-mode .game-message.game-won p {
    color: #ffd89b;
}

.retry-button {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.retry-button:hover {
    background: #9f8a76;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.about-game {
    background: #8f7a66;
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
    transition: background 0.3s ease;
}

body.dark-mode .about-game {
    background: #4a4a5e;
}

.about-game h2 {
    color: white;
    margin-bottom: 10px;
    font-size: 1.8em;
}

.about-game p {
    font-size: 1.1em;
    line-height: 1.6;
}

.instructions {
    background: #f9f6f2;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    transition: background 0.3s ease;
}

body.dark-mode .instructions {
    background: #2a2a3e;
}

.instructions h3 {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 1.5em;
    transition: color 0.3s ease;
}

body.dark-mode .instructions h3 {
    color: #ffd89b;
}

.instructions ul {
    list-style: none;
    padding: 0;
}

.instructions li {
    color: #776e65;
    line-height: 1.8;
    margin: 12px 0;
    padding-left: 20px;
    position: relative;
    transition: color 0.3s ease;
}

body.dark-mode .instructions li {
    color: #d4d4e4;
}

.instructions li:before {
    content: '•';
    position: absolute;
    left: 0;
    color: #f59563;
    font-weight: bold;
    font-size: 1.5em;
}

.controls-info {
    background: #f9f6f2;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    transition: background 0.3s ease;
}

body.dark-mode .controls-info {
    background: #2a2a3e;
}

.controls-info h3 {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 1.5em;
    transition: color 0.3s ease;
}

body.dark-mode .controls-info h3 {
    color: #ffd89b;
}

.controls-info ul {
    list-style: none;
    padding: 0;
}

.controls-info li {
    margin: 10px 0;
    color: #776e65;
    padding-left: 20px;
    position: relative;
    line-height: 1.6;
    transition: color 0.3s ease;
}

body.dark-mode .controls-info li {
    color: #d4d4e4;
}

.controls-info li:before {
    content: '▶';
    position: absolute;
    left: 0;
    color: #ed9f3f;
    font-size: 0.8em;
}

.game-tips {
    background: #edc22e;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    transition: background 0.3s ease;
}

body.dark-mode .game-tips {
    background: #4a4a3e;
}

.game-tips h3 {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 1.5em;
    font-weight: bold;
    transition: color 0.3s ease;
}

body.dark-mode .game-tips h3 {
    color: #ffd89b;
}

.game-tips ul {
    list-style: none;
    padding: 0;
}

.game-tips li {
    margin: 12px 0;
    color: #776e65;
    padding-left: 25px;
    position: relative;
    line-height: 1.8;
    transition: color 0.3s ease;
}

body.dark-mode .game-tips li {
    color: #d4d4e4;
}

@media (max-width: 600px) {
    h1 {
        font-size: 2.5em;
    }
    
    .game-container {
        width: 320px;
        height: 320px;
    }
    
    .grid-container,
    .tile-container {
        width: 290px;
        height: 290px;
    }
    
    .grid-cell, .tile {
        width: 60px;
        height: 60px;
    }
    
    .tile {
        font-size: 1.5em;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.2em;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1em;
    }
}
