* {
    box-sizing: border-box;
}

:root {
    --bg: #f6f1e8;
    --bg-grad-1: #faf7f1;
    --bg-grad-2: #efe7d9;
    --panel: #fffaf3;
    --panel-2: #f2eadc;
    --text: #4d4338;
    --muted: #857868;
    --accent: #6d8f74;
    --accent-2: #4f7056;
    --board: #c8b8a5;
    --empty: rgba(255, 248, 239, 0.42);
    --shadow: 0 10px 34px rgba(0,0,0,0.08);
    --radius: 22px;
    --tile-2: #f8f1e7;
    --tile-4: #f1e3cc;
    --tile-8: #e8b88b;
    --tile-16: #dc956f;
    --tile-32: #d6765d;
    --tile-64: #cb5e54;
    --tile-128: #b8cc8e;
    --tile-256: #9ec37d;
    --tile-512: #85b567;
    --tile-1024: #679f57;
    --tile-2048: #4f884c;
    --tile-super: #355940;
    --ad-bg: #efe7da;
    --ad-border: #ddcfb9;
}

body.theme-dark {
    --bg: #171a1c;
    --bg-grad-1: #1d2124;
    --bg-grad-2: #121416;
    --panel: #22272b;
    --panel-2: #2a3034;
    --text: #eef2f4;
    --muted: #a4afb5;
    --accent: #7abf91;
    --accent-2: #5aa172;
    --board: #4e5961;
    --empty: rgba(255, 255, 255, 0.11);
    --shadow: 0 10px 34px rgba(0,0,0,0.28);
    --tile-2: #e8edf0;
    --tile-4: #d6e0e6;
    --tile-8: #6eb9d1;
    --tile-16: #5ca4c6;
    --tile-32: #4e8cb4;
    --tile-64: #3c739f;
    --tile-128: #78c39d;
    --tile-256: #5bb987;
    --tile-512: #47ab77;
    --tile-1024: #3a9467;
    --tile-2048: #2f7d58;
    --tile-super: #255641;
    --ad-bg: #293036;
    --ad-border: #3a434b;
}

body.theme-neon {
    --bg: #140f20;
    --bg-grad-1: #1a1230;
    --bg-grad-2: #110b1d;
    --panel: #211a34;
    --panel-2: #2d2350;
    --text: #f7f2ff;
    --muted: #c7b9e8;
    --accent: #b15cff;
    --accent-2: #8a39da;
    --board: #4d3e74;
    --empty: rgba(255, 255, 255, 0.09);
    --shadow: 0 10px 34px rgba(0,0,0,0.30);
    --tile-2: #f7efff;
    --tile-4: #eadcff;
    --tile-8: #ffb86b;
    --tile-16: #ff8f6b;
    --tile-32: #f96f8a;
    --tile-64: #e05cab;
    --tile-128: #b377ff;
    --tile-256: #9d61ff;
    --tile-512: #8e52f3;
    --tile-1024: #7e47e2;
    --tile-2048: #6f3fd1;
    --tile-super: #5826a9;
    --ad-bg: #2a2042;
    --ad-border: #433462;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
}

/* padding moved from body to wrapper so it doesn't affect the site header/footer */
.game-2048-wrap {
    padding: 20px;
}

.site-shell {
    max-width: 1380px;
    margin: 0 auto;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: start;
}

.main-column {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.card {
    background: var(--panel);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.hero {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    position: relative;
    --hero-toggle-space: 124px;
    transition: width .2s ease, max-width .2s ease;
}

.hero-body {
    min-width: 0;
    flex: 1 1 420px;
    padding-right: var(--hero-toggle-space);
}

.hero-toggle-wrap {
    position: absolute;
    top: 10px;
    right: 12px;
    width: var(--hero-toggle-space);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    z-index: 2;
}

.hero-more-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
}

.hero-toggle {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-2);
    color: var(--text);
}

.hero.is-collapsed {
    align-self: flex-start;
    width: min(100%, 520px);
}

.hero.is-collapsed .hero-body {
    flex-basis: 100%;
    padding-right: 96px;
}

.hero.is-collapsed #heroText,
.hero.is-collapsed .toolbar-row,
.hero.is-collapsed .toolbar,
.hero.is-collapsed .stats {
    display: none;
}

.hero h1 {
    margin: 0;
    font-size: 44px;
    line-height: 1;
    letter-spacing: -1.2px;
}

.hero p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
    max-width: 720px;
}

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-right: var(--hero-toggle-space);
}

select, button, input {
    font: inherit;
}

.control, .btn {
    border: none;
    border-radius: 14px;
    padding: 12px 14px;
    background: var(--panel-2);
    color: var(--text);
}

.btn {
    cursor: pointer;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    transition: transform .12s ease, opacity .12s ease, background .12s ease;
}

.btn:hover {
    background: var(--accent-2);
}

.btn:active {
    transform: scale(0.98);
}

.btn.secondary {
    background: #b3a48f;
    color: #fff;
}

body.theme-dark .btn.secondary {
    background: #5d6972;
}

body.theme-neon .btn.secondary {
    background: #6c55a8;
}

.toolbar-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 12px;
    margin-top: 16px;
}

.stat {
    background: var(--panel-2);
    border-radius: 16px;
    padding: 14px;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .9px;
    color: var(--muted);
}

.stat-value {
    margin-top: 6px;
    font-size: 28px;
    font-weight: 800;
}

.game-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.game-panel {
    min-width: 0;
}

.hint {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    margin: 14px 0 0;
}

.board-wrap {
    margin-top: 18px;
    position: relative;
}

.board {
    display: grid;
    gap: 12px;
    background: var(--board);
    border-radius: 22px;
    padding: 12px;
    touch-action: none;
    user-select: none;
}

.cell {
    aspect-ratio: 1 / 1;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    font-size: clamp(18px, 3.2vw, 34px);
    transition: transform .12s ease, background .2s ease, color .2s ease;
    will-change: transform;
}

.cell.spawn {
    animation: pop .18s ease;
}

.cell.merge {
    animation: mergePulse .18s ease;
}

@keyframes pop {
    0% {
        transform: scale(.72);
        opacity: .55;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes mergePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.tile-0 {
    background: var(--empty);
    color: transparent;
}

.tile-2 {
    background: var(--tile-2);
    color: #5d5143;
}

.tile-4 {
    background: var(--tile-4);
    color: #5d5143;
}

.tile-8 { background: var(--tile-8); }
.tile-16 { background: var(--tile-16); }
.tile-32 { background: var(--tile-32); }
.tile-64 { background: var(--tile-64); }
.tile-128 { background: var(--tile-128); }
.tile-256 { background: var(--tile-256); }
.tile-512 { background: var(--tile-512); }

.tile-1024 {
    background: var(--tile-1024);
    font-size: clamp(16px, 2.6vw, 26px);
}

.tile-2048 {
    background: var(--tile-2048);
    font-size: clamp(16px, 2.6vw, 26px);
}

.tile-super {
    background: var(--tile-super);
    font-size: clamp(14px, 2.4vw, 22px);
}

.overlay {
    position: absolute;
    inset: 0;
    border-radius: 22px;
    background: rgba(255,255,255,.78);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    text-align: center;
}

body.theme-dark .overlay,
body.theme-neon .overlay {
    background: rgba(16,18,22,.65);
}

.overlay.show {
    display: flex;
}

.overlay-card {
    background: var(--panel);
    color: var(--text);
    border-radius: 20px;
    padding: 20px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow);
}

.overlay-card h2 {
    margin: 0 0 8px;
    font-size: 34px;
}

.overlay-card p {
    margin: 0 0 14px;
    color: var(--muted);
    line-height: 1.5;
}

.save-score-box {
    display: none;
    margin-top: 14px;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.save-score-box.show {
    display: flex;
}

.save-score-box input {
    min-width: 180px;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 12px;
    padding: 12px 14px;
    background: var(--panel-2);
    color: var(--text);
    outline: none;
}

.sidebar-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.leaderboard-list {
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--panel-2);
    border-radius: 14px;
    padding: 10px 12px;
}

.leaderboard-rank {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.06);
    font-weight: 800;
}

.leaderboard-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
}

.leaderboard-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.leaderboard-score {
    font-weight: 800;
}

.daily-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--panel-2);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
}

.ad-slot {
    border: 2px dashed var(--ad-border);
    background: var(--ad-bg);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-align: center;
    padding: 14px;
    line-height: 1.45;
}

.ad-right {
    min-height: 600px;
    position: sticky;
    /* offset for the site's sticky header (~64px) */
    top: 80px;
}

.ad-bottom {
    min-height: 120px;
}

.seo-copy h2 {
    margin: 0 0 10px;
    font-size: 28px;
}

.seo-copy h3 {
    margin: 18px 0 8px;
    font-size: 20px;
}

.seo-copy p, .seo-copy li {
    color: var(--muted);
    line-height: 1.7;
    font-size: 15px;
}

.seo-copy ul {
    margin: 10px 0 0 18px;
    padding: 0;
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: var(--panel-2);
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}

.small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .ad-right {
        min-height: 180px;
        position: static;
    }
}

@media (max-width: 980px) {
    .game-area {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0,1fr));
    }
}

@media (max-width: 560px) {
    .game-2048-wrap {
        padding: 12px;
    }

    .card {
        padding: 16px;
        border-radius: 20px;
    }

    .hero h1 {
        font-size: 34px;
    }

    .toolbar, .toolbar-row {
        gap: 8px;
    }

    .toolbar {
        margin-right: 0;
    }

    .control, .btn {
        width: 100%;
    }

    .save-score-box input {
        width: 100%;
        min-width: 0;
    }
}
