:root {
    --bg: #faf8ef;
    --board-bg: #bbada0;
    --cell-bg: #cdc1b4;
    --text: #776e65;
    --text-light: #f9f6f2;
    --accent: #8f7a66;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    padding: 12px;
    min-height: 100vh;
    overflow-x: hidden;
}

.app {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.game-title {
    font-size: 44px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.game-subtitle {
    font-size: 12px;
    color: #998d80;
    margin-top: 4px;
    max-width: 160px;
}

.scores {
    display: flex;
    gap: 8px;
}

.score-box {
    background: var(--board-bg);
    border-radius: 6px;
    padding: 6px 14px;
    text-align: center;
    color: var(--text-light);
    min-width: 60px;
    display: flex;
    flex-direction: column;
}

.score-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #eee4da;
}

.score-value {
    font-size: 20px;
    font-weight: 800;
}

.toolbar {
    display: flex;
    justify-content: flex-end;
}

.btn-new {
    background: var(--accent);
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.btn-new:active { transform: scale(0.96); }

.board-wrap {
    position: relative;
    width: 100%;
}

.board {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--board-bg);
    border-radius: 8px;
    touch-action: none;
}

/* Background grid cells */
.cell {
    position: absolute;
    width: 22%;
    height: 22%;
    background: var(--cell-bg);
    border-radius: 5px;
}

/* Tiles */
.tile {
    position: absolute;
    width: 22%;
    height: 22%;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 30px;
    color: var(--text);
    background: #eee4da;
    transition: left 0.12s ease-in-out, top 0.12s ease-in-out;
    z-index: 2;
}

.tile-new { animation: appear 0.16s ease; }
.tile-merged { animation: pop 0.16s ease; }

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

/* Tile colors by value */
.tile[data-val="2"]    { background:#eee4da; }
.tile[data-val="4"]    { background:#ede0c8; }
.tile[data-val="8"]    { background:#f2b179; color:#f9f6f2; }
.tile[data-val="16"]   { background:#f59563; color:#f9f6f2; }
.tile[data-val="32"]   { background:#f67c5f; color:#f9f6f2; }
.tile[data-val="64"]   { background:#f65e3b; color:#f9f6f2; }
.tile[data-val="128"]  { background:#edcf72; color:#f9f6f2; font-size:26px; }
.tile[data-val="256"]  { background:#edcc61; color:#f9f6f2; font-size:26px; }
.tile[data-val="512"]  { background:#edc850; color:#f9f6f2; font-size:26px; }
.tile[data-val="1024"] { background:#edc53f; color:#f9f6f2; font-size:22px; }
.tile[data-val="2048"] { background:#edc22e; color:#f9f6f2; font-size:22px; box-shadow:0 0 20px rgba(237,194,46,0.6); }
.tile[data-val="4096"], .tile[data-val="8192"], .tile[data-val="16384"] { background:#3c3a32; color:#f9f6f2; font-size:20px; }

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(238, 228, 218, 0.78);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay-content {
    text-align: center;
}

.result-title {
    font-size: 34px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
}

.result-score {
    font-size: 16px;
    margin-bottom: 16px;
    color: #776e65;
    font-weight: 700;
}

.btn-retry {
    background: var(--accent);
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 10px 22px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.btn-retry:active { transform: scale(0.96); }

.hint {
    text-align: center;
    font-size: 12px;
    color: #998d80;
    margin-bottom: 70px;
}

/* Roiify banner (also styled inline in JS as fallback) */
#roiify-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 50px;
    z-index: 99999;
    pointer-events: none;
}
