:root {
    --font-body: "Manrope", "Segoe UI", sans-serif;
    --font-display: "Baloo 2", "Segoe UI", sans-serif;
    --bg-color: #ffdae9;
    --bg-gradient: radial-gradient(circle at 18% 12%, rgba(255, 128, 185, 0.45), transparent 42%), radial-gradient(circle at 85% 88%, rgba(255, 94, 163, 0.35), transparent 44%), linear-gradient(145deg, #ffe0ef 0%, #ffcbe3 45%, #ffa6ce 100%);
    --panel-bg: rgba(255, 235, 245, 0.82);
    --surface-border: rgba(255, 182, 218, 0.75);
    --grid-bg: #ff6eab;
    --cell-bg: rgba(255, 212, 232, 0.78);
    --text-dark: #cc1467;
    --text-light: #fff8fb;
    --button-bg: #ff3385;
    --button-hover: #e61c6c;
    --accent-soft: rgba(255, 51, 133, 0.25);
    --accent-strong: rgba(255, 51, 133, 0.55);
    --theme-chip-bg: rgba(255, 224, 238, 0.85);
    --theme-chip-border: rgba(255, 51, 133, 0.35);
    --status-won-bg: rgba(255, 163, 209, 0.85);
    --status-over-bg: rgba(255, 196, 226, 0.88);
    --status-over-text: #cc1467;
    --grid-size: 500px;
    --cell-size: 106.25px;
    --cell-gap: 15px;

    --tile-2-bg: #ffb3d9;
    --tile-2-text: #cc1467;
    --tile-4-bg: #ff80bf;
    --tile-4-text: #cc1467;
    --tile-8-bg: #ff4d94;
    --tile-8-text: #fff8fb;
    --tile-16-bg: #ff1a75;
    --tile-16-text: #fff8fb;
    --tile-32-bg: #e6005c;
    --tile-32-text: #fff8fb;
    --tile-64-bg: #cc0052;
    --tile-64-text: #fff8fb;
    --tile-128-bg: #ff99cc;
    --tile-128-text: #99003d;
    --tile-256-bg: #ff66a3;
    --tile-256-text: #99003d;
    --tile-512-bg: #ff3385;
    --tile-512-text: #fff8fb;
    --tile-1024-bg: #e6006e;
    --tile-1024-text: #fff8fb;
    --tile-2048-bg: #b30056;
    --tile-2048-text: #fff8fb;
}

body[data-theme="pink"] {
    --bg-gradient: radial-gradient(circle at 18% 12%, rgba(255, 107, 171, 0.45), transparent 42%), radial-gradient(circle at 85% 88%, rgba(255, 61, 142, 0.35), transparent 44%), linear-gradient(145deg, #ffcbe3 0%, #ffa6ce 45%, #ff7db5 100%);
}

body[data-theme="pink"] .title {
    background: linear-gradient(145deg, #ff3385 0%, #ff66a3 38%, #e6005c 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 12px 26px rgba(255, 51, 133, 0.45);
}

body[data-theme="pink"] .score-box {
    background: linear-gradient(165deg, #ff66a3 0%, #e6005c 100%);
    border-color: rgba(255, 255, 255, 0.6);
}

body[data-theme="pink"] .theme-switcher {
    box-shadow: 0 12px 24px rgba(232, 106, 163, 0.14);
}

body[data-theme="pink"] .game-container::before {
    content: "";
    position: absolute;
    inset: 8px;
    border-radius: 10px;
    pointer-events: none;
    background-image: radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.35) 0 3px, transparent 4px), radial-gradient(circle at 78% 24%, rgba(255, 255, 255, 0.28) 0 2px, transparent 3px), radial-gradient(circle at 36% 78%, rgba(255, 255, 255, 0.25) 0 2px, transparent 3px), radial-gradient(circle at 83% 70%, rgba(255, 255, 255, 0.23) 0 3px, transparent 4px);
    opacity: 0.9;
}

/* Option 1: Girly/Sweet Decorations (Hearts & Bows) for Pink Theme */
body[data-theme="pink"] .container {
    border: 4px solid rgba(255, 102, 163, 0.4);
    outline: 3px dashed rgba(255, 102, 163, 0.6);
    outline-offset: 6px;
    box-shadow: 0 0 0 12px rgba(255, 182, 218, 0.3), 0 28px 60px rgba(255, 0, 102, 0.15);
}

body[data-theme="pink"] .title {
    position: relative;
    display: inline-block;
}

body[data-theme="pink"] .title::before {
    content: "🌸";
    position: absolute;
    top: -24px;
    left: -38px;
    font-size: 38px;
    filter: drop-shadow(0 4px 8px rgba(255, 51, 133, 0.4));
    animation: drift-blossom 4s ease-in-out infinite alternate;
    pointer-events: none;
}

body[data-theme="pink"] .title::after {
    content: "♥";
    position: absolute;
    top: -12px;
    right: -42px;
    font-size: 42px;
    color: #ff4f86;
    text-shadow: 0 4px 12px rgba(255, 79, 134, 0.45);
    -webkit-text-fill-color: #ff4f86;
    background: none;
    animation: heart-beat 1.5s ease-in-out infinite;
    pointer-events: none;
}

body[data-theme="pink"] .score-box {
    position: relative;
}

body[data-theme="pink"] .score-box::before {
    content: "🎀";
    position: absolute;
    top: -16px;
    left: -12px;
    font-size: 26px;
    filter: drop-shadow(0 4px 8px rgba(232, 106, 163, 0.4));
    z-index: 10;
    animation: float-bow 3s ease-in-out infinite;
    pointer-events: none;
}

body[data-theme="pink"] .score-box:last-child::before {
    left: auto;
    right: -12px;
    animation-delay: 1.5s;
}

body[data-theme="pink"] .score-box:last-child::after {
    content: "👑";
    position: absolute;
    top: -20px;
    left: 40%;
    font-size: 20px;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.8));
    animation: float-crown 2s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 10;
}

body[data-theme="pink"] .game-intro {
    position: relative;
}

body[data-theme="pink"] .game-intro::before {
    content: "🍓";
    position: absolute;
    top: -20px;
    left: -20px;
    font-size: 24px;
    filter: drop-shadow(0 4px 6px rgba(255, 51, 133, 0.5));
    animation: bounce-berry 3s ease infinite;
    pointer-events: none;
}

body[data-theme="pink"] .game-intro::after {
    content: "🐾";
    position: absolute;
    bottom: -15px;
    left: 50%;
    font-size: 20px;
    opacity: 0.6;
    color: #ff66a3;
    animation: paw-print 4s step-end infinite;
    pointer-events: none;
}

body[data-theme="pink"] .game-container::after {
    content: "✦";
    position: absolute;
    bottom: -15px;
    right: -15px;
    font-size: 32px;
    font-family: Arial, sans-serif;
    color: #ff89b5;
    text-shadow: 0 0 10px #ff89b5, 0 0 20px #ff89b5;
    animation: twinkle 2s ease-in-out infinite alternate;
    z-index: 10;
    pointer-events: none;
}

body[data-theme="pink"] .scores-container {
    position: relative;
}

body[data-theme="pink"] .scores-container::after {
    content: "✨";
    position: absolute;
    top: -30px;
    left: 45%;
    font-size: 24px;
    animation: float-sparkle 2.5s ease-out infinite;
    pointer-events: none;
    z-index: 15;
}

body[data-theme="pink"] .grid-cell {
    border: 2px dashed rgba(255, 51, 133, 0.25);
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.4) 0%, var(--cell-bg) 100%);
}

body[data-theme="pink"] .game-message {
    border: 4px solid #ff66a3;
    background: rgba(255, 224, 238, 0.92);
    box-shadow: 0 0 30px rgba(255, 51, 133, 0.4);
}

@keyframes heart-beat {
    0%, 100% { transform: scale(1) rotate(12deg); }
    14% { transform: scale(1.15) rotate(12deg); }
    28% { transform: scale(1) rotate(12deg); }
    42% { transform: scale(1.15) rotate(12deg); }
    70% { transform: scale(1) rotate(12deg); }
}

@keyframes float-bow {
    0%, 100% { transform: translateY(0) rotate(-8deg); }
    50% { transform: translateY(-5px) rotate(-14deg); }
}

@keyframes twinkle {
    0% { transform: scale(0.8) rotate(0deg); opacity: 0.5; }
    100% { transform: scale(1.2) rotate(45deg); opacity: 1; }
}

@keyframes float-crown {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-5px) rotate(5deg); }
}

@keyframes bounce-berry {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.1); }
}

@keyframes paw-print {
    0% { opacity: 0; transform: scale(0.8) translate(0, 0); }
    10% { opacity: 0.8; transform: scale(1) translate(0, 0); }
    40% { opacity: 0; transform: scale(1) translate(0, 0); }
    50% { opacity: 0.8; transform: scale(1) translate(15px, -15px) rotate(15deg); }
    90% { opacity: 0; transform: scale(1) translate(15px, -15px) rotate(15deg); }
    100% { opacity: 0; transform: scale(0.8); }
}

@keyframes drift-blossom {
    0% { transform: translate(0, 0) rotate(-10deg) scale(0.9); }
    100% { transform: translate(-10px, 15px) rotate(15deg) scale(1.1); }
}

@keyframes float-sparkle {
    0% { transform: translateY(10px) scale(0); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translateY(-30px) scale(1.5) rotate(20deg); opacity: 0; }
}

body[data-theme="pink"] header {
    position: relative;
    z-index: 20;
}

body[data-theme="pink"] header::before {
    content: "🐰";
    position: absolute;
    top: -55px;
    right: 20px;
    font-size: 34px;
    z-index: -1;
    animation: peek-bunny 5s ease-in-out infinite;
    pointer-events: none;
}

body[data-theme="pink"] .theme-switcher {
    position: relative;
}

body[data-theme="pink"] .theme-switcher::after {
    content: "🍭";
    position: absolute;
    right: -25px;
    top: -10px;
    font-size: 28px;
    animation: swing-lollipop 3s ease-in-out infinite alternate;
    transform-origin: bottom center;
    pointer-events: none;
}

body[data-theme="pink"] #restart-button {
    position: relative;
}

body[data-theme="pink"] #restart-button::after {
    content: "🪄";
    position: absolute;
    right: -22px;
    top: -20px;
    font-size: 26px;
    animation: wave-wand 2.5s ease-in-out infinite;
    transform-origin: bottom left;
    pointer-events: none;
}

body[data-theme="pink"] .game-container::before {
    content: "💌";
    position: absolute;
    left: -20px;
    bottom: -20px;
    font-size: 28px;
    animation: float-letter 3.5s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 10;
}

@keyframes peek-bunny {
    0% { transform: translateY(40px) rotate(15deg); opacity: 0; }
    15%, 85% { transform: translateY(0) rotate(-5deg); opacity: 1; filter: drop-shadow(0 4px 8px rgba(255, 51, 133, 0.4)); }
    100% { transform: translateY(40px) rotate(15deg); opacity: 0; }
}

@keyframes swing-lollipop {
    0% { transform: rotate(-25deg); filter: drop-shadow(-2px 4px 4px rgba(255, 51, 133, 0.4)); }
    100% { transform: rotate(25deg); filter: drop-shadow(2px 4px 4px rgba(255, 51, 133, 0.4)); }
}

@keyframes wave-wand {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(45deg) scale(1.1); filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)); }
    50% { transform: rotate(-15deg); }
    75% { transform: rotate(30deg) scale(1.1); filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)); }
}

@keyframes float-letter {
    0% { transform: translateY(0) rotate(-15deg) scale(0.9); filter: drop-shadow(0 2px 4px rgba(255, 51, 133, 0.3)); }
    100% { transform: translateY(-20px) rotate(10deg) scale(1.15); filter: drop-shadow(0 6px 12px rgba(255, 51, 133, 0.6)); }
}

/* Additional Pink Theme Animations */
body[data-theme="pink"] {
    background-size: 200% 200%;
    animation: pink-bg-shift 12s ease infinite;
}

body[data-theme="pink"]::before {
    animation: float-blob 8s ease-in-out infinite alternate;
}

body[data-theme="pink"]::after {
    animation: float-blob-reverse 10s ease-in-out infinite alternate;
}

body[data-theme="pink"] #restart-button {
    animation: pink-pulse 2s infinite;
}

body[data-theme="pink"] .tile {
    box-shadow: 0 12px 24px rgba(255, 0, 102, 0.45), inset 0 3px 10px rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 204, 225, 0.9);
}

@keyframes pink-bg-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes float-blob {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, -40px) scale(1.1); }
}

@keyframes float-blob-reverse {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-40px, 30px) scale(1.15); }
}

@keyframes pink-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 51, 133, 0.7); }
    70% { box-shadow: 0 0 0 16px rgba(255, 51, 133, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 51, 133, 0); }
}

body[data-theme="ocean"] {
    --bg-color: #eff9ff;
    --bg-gradient: radial-gradient(circle at 15% 18%, rgba(131, 206, 243, 0.34), transparent 42%), radial-gradient(circle at 86% 82%, rgba(58, 148, 201, 0.2), transparent 45%), linear-gradient(145deg, #f5fbff 0%, #e7f5ff 45%, #d6eeff 100%);
    --panel-bg: rgba(255, 255, 255, 0.74);
    --surface-border: rgba(255, 255, 255, 0.58);
    --grid-bg: #7fb8d9;
    --cell-bg: rgba(226, 245, 255, 0.72);
    --text-dark: #2f5d79;
    --text-light: #f8fdff;
    --button-bg: #3a94c9;
    --button-hover: #2e7eb1;
    --accent-soft: rgba(58, 148, 201, 0.15);
    --accent-strong: rgba(58, 148, 201, 0.42);
    --theme-chip-bg: rgba(255, 255, 255, 0.8);
    --theme-chip-border: rgba(58, 148, 201, 0.24);
    --status-won-bg: rgba(211, 239, 255, 0.78);
    --status-over-bg: rgba(241, 250, 255, 0.84);
    --status-over-text: #2f5d79;

    --tile-2-bg: #d8f0ff;
    --tile-2-text: #2f5d79;
    --tile-4-bg: #bfdff4;
    --tile-4-text: #2f5d79;
    --tile-8-bg: #7fc2ea;
    --tile-8-text: #f8fdff;
    --tile-16-bg: #57afd9;
    --tile-16-text: #f8fdff;
    --tile-32-bg: #3c97c8;
    --tile-32-text: #f8fdff;
    --tile-64-bg: #267eaf;
    --tile-64-text: #f8fdff;
    --tile-128-bg: #9ad5ef;
    --tile-128-text: #21465c;
    --tile-256-bg: #7ac5e6;
    --tile-256-text: #21465c;
    --tile-512-bg: #5ab0d8;
    --tile-512-text: #f8fdff;
    --tile-1024-bg: #3894c5;
    --tile-1024-text: #f8fdff;
    --tile-2048-bg: #247aa8;
    --tile-2048-text: #f8fdff;
}

body[data-theme="mint"] {
    --bg-color: #effdf6;
    --bg-gradient: radial-gradient(circle at 16% 12%, rgba(125, 222, 178, 0.32), transparent 42%), radial-gradient(circle at 84% 84%, rgba(74, 190, 145, 0.2), transparent 44%), linear-gradient(145deg, #f5fff9 0%, #eafbef 45%, #d8f4e5 100%);
    --panel-bg: rgba(255, 255, 255, 0.75);
    --surface-border: rgba(255, 255, 255, 0.58);
    --grid-bg: #8bd3b3;
    --cell-bg: rgba(228, 250, 239, 0.74);
    --text-dark: #2d6b57;
    --text-light: #f7fffb;
    --button-bg: #4eb88d;
    --button-hover: #3ea379;
    --accent-soft: rgba(78, 184, 141, 0.15);
    --accent-strong: rgba(78, 184, 141, 0.42);
    --theme-chip-bg: rgba(255, 255, 255, 0.8);
    --theme-chip-border: rgba(78, 184, 141, 0.24);
    --status-won-bg: rgba(214, 246, 231, 0.8);
    --status-over-bg: rgba(239, 253, 246, 0.84);
    --status-over-text: #2d6b57;

    --tile-2-bg: #def7eb;
    --tile-2-text: #2d6b57;
    --tile-4-bg: #c8efd9;
    --tile-4-text: #2d6b57;
    --tile-8-bg: #8dd8b7;
    --tile-8-text: #f7fffb;
    --tile-16-bg: #66c99d;
    --tile-16-text: #f7fffb;
    --tile-32-bg: #48b788;
    --tile-32-text: #f7fffb;
    --tile-64-bg: #2f9a6e;
    --tile-64-text: #f7fffb;
    --tile-128-bg: #a7e3c6;
    --tile-128-text: #245746;
    --tile-256-bg: #86d8b0;
    --tile-256-text: #245746;
    --tile-512-bg: #63c896;
    --tile-512-text: #f7fffb;
    --tile-1024-bg: #44ad7b;
    --tile-1024-text: #f7fffb;
    --tile-2048-bg: #2b8e60;
    --tile-2048-text: #f7fffb;
}

body[data-theme="night"] {
    --bg-color: #16181f;
    --bg-gradient: radial-gradient(circle at 12% 12%, rgba(125, 99, 255, 0.28), transparent 44%), radial-gradient(circle at 88% 86%, rgba(83, 128, 255, 0.18), transparent 46%), linear-gradient(150deg, #151823 0%, #1c2030 45%, #1b2337 100%);
    --panel-bg: rgba(26, 29, 38, 0.88);
    --surface-border: rgba(255, 255, 255, 0.12);
    --grid-bg: #2c3447;
    --cell-bg: rgba(255, 255, 255, 0.06);
    --text-dark: #f2f4ff;
    --text-light: #f8f9ff;
    --button-bg: #7d63ff;
    --button-hover: #6950e8;
    --accent-soft: rgba(125, 99, 255, 0.18);
    --accent-strong: rgba(125, 99, 255, 0.48);
    --theme-chip-bg: rgba(255, 255, 255, 0.06);
    --theme-chip-border: rgba(255, 255, 255, 0.12);
    --status-won-bg: rgba(125, 99, 255, 0.26);
    --status-over-bg: rgba(22, 24, 31, 0.74);
    --status-over-text: #f2f4ff;

    --tile-2-bg: #2c3447;
    --tile-2-text: #f2f4ff;
    --tile-4-bg: #384158;
    --tile-4-text: #f2f4ff;
    --tile-8-bg: #45506b;
    --tile-8-text: #f8f9ff;
    --tile-16-bg: #566181;
    --tile-16-text: #f8f9ff;
    --tile-32-bg: #667299;
    --tile-32-text: #f8f9ff;
    --tile-64-bg: #7a86ad;
    --tile-64-text: #f8f9ff;
    --tile-128-bg: #8d99c0;
    --tile-128-text: #1a1d26;
    --tile-256-bg: #a0abd2;
    --tile-256-text: #1a1d26;
    --tile-512-bg: #b5bfe0;
    --tile-512-text: #1a1d26;
    --tile-1024-bg: #cad3ef;
    --tile-1024-text: #1a1d26;
    --tile-2048-bg: #e0e6fb;
    --tile-2048-text: #1a1d26;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-color);
    background-image: var(--bg-gradient);
    color: var(--text-dark);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    touch-action: none;
    overflow-x: hidden;
    position: relative;
}

body::before,
body::after {
    content: "";
    position: fixed;
    pointer-events: none;
    z-index: 0;
    border-radius: 50%;
}

body::before {
    width: min(38vw, 420px);
    aspect-ratio: 1;
    top: -90px;
    left: -80px;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-strong) 64%, white 6%) 0%, transparent 70%);
    filter: blur(6px);
}

body::after {
    width: min(42vw, 500px);
    aspect-ratio: 1;
    right: -110px;
    bottom: -120px;
    background: radial-gradient(circle, color-mix(in srgb, var(--grid-bg) 52%, white 8%) 0%, transparent 70%);
    filter: blur(10px);
}

.container {
    width: calc(var(--grid-size) + 52px);
    background: var(--panel-bg);
    border: 1px solid var(--surface-border);
    border-radius: 22px;
    padding: 26px;
    backdrop-filter: blur(12px);
    box-shadow: 0 28px 60px rgba(0, 0, 0, 0.14);
    animation: panel-enter 450ms ease both;
    position: relative;
    z-index: 1;
}

.container::before,
.container::after {
    content: "";
    position: absolute;
    pointer-events: none;
    z-index: -1;
}

.container::before {
    width: 180px;
    height: 180px;
    right: -40px;
    top: -34px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-strong) 42%, transparent) 0%, transparent 72%);
}

.container::after {
    width: 200px;
    height: 200px;
    left: -44px;
    bottom: -50px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--grid-bg) 38%, transparent) 0%, transparent 72%);
}

header {
    margin-bottom: 20px;
}

.title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.title {
    font-family: var(--font-display);
    font-size: 82px;
    font-weight: 800;
    line-height: 0.92;
    letter-spacing: 0.5px;
    color: var(--text-dark);
    text-shadow: 0 10px 20px color-mix(in srgb, var(--accent-soft) 85%, transparent);
}

.scores-container {
    display: flex;
    gap: 8px;
}

.score-box {
    background: var(--grid-bg);
    padding: 10px 22px;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--surface-border) 70%, transparent);
    color: var(--text-light);
    text-align: center;
    min-width: 100px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 18px rgba(0, 0, 0, 0.08);
}

.score-label {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: var(--text-light);
}

#score,
#best-score {
    font-size: 24px;
    font-weight: 800;
}

.game-intro {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#restart-button {
    background: var(--button-bg);
    color: var(--text-light);
    border: none;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s, transform 0.2s;
    box-shadow: 0 10px 18px var(--accent-soft);
}

#restart-button:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
}

.theme-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    padding: 10px;
    border: 1px solid var(--theme-chip-border);
    border-radius: 14px;
    background: color-mix(in srgb, var(--theme-chip-bg) 90%, transparent);
}

.theme-button {
    border: 1px solid var(--theme-chip-border);
    background: var(--theme-chip-bg);
    color: var(--text-dark);
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.06);
}

.theme-button:hover {
    transform: translateY(-1px);
    border-color: var(--button-bg);
}

.theme-button.is-active {
    background: var(--button-bg);
    color: var(--text-light);
    border-color: transparent;
    box-shadow: 0 10px 20px var(--accent-soft), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.theme-button:focus-visible,
#restart-button:focus-visible,
.icp-footer a:focus-visible,
.game-message a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent-strong) 66%, white 10%);
    outline-offset: 3px;
}

.game-container {
    position: relative;
    width: var(--grid-size);
    height: var(--grid-size);
    background: var(--grid-bg);
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--surface-border) 72%, transparent);
    padding: var(--cell-gap);
    user-select: none;
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    display: flex;
    margin-bottom: var(--cell-gap);
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--cell-bg);
    border-radius: 10px;
    margin-right: var(--cell-gap);
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
    top: var(--cell-gap);
    left: var(--cell-gap);
    right: var(--cell-gap);
    bottom: var(--cell-gap);
}

.tile {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 55px;
    font-weight: 800;
    transition: transform 100ms ease-in-out, box-shadow 180ms ease;
    z-index: 10;
    box-shadow: 0 9px 16px rgba(0, 0, 0, 0.12);
}

.tile-2 { background: var(--tile-2-bg); color: var(--tile-2-text); }
.tile-4 { background: var(--tile-4-bg); color: var(--tile-4-text); }
.tile-8 { background: var(--tile-8-bg); color: var(--tile-8-text); }
.tile-16 { background: var(--tile-16-bg); color: var(--tile-16-text); }
.tile-32 { background: var(--tile-32-bg); color: var(--tile-32-text); }
.tile-64 { background: var(--tile-64-bg); color: var(--tile-64-text); }
.tile-128 { background: var(--tile-128-bg); color: var(--tile-128-text); font-size: 45px; box-shadow: 0 0 30px 10px color-mix(in srgb, var(--tile-128-bg) 45%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.tile-256 { background: var(--tile-256-bg); color: var(--tile-256-text); font-size: 45px; box-shadow: 0 0 30px 10px color-mix(in srgb, var(--tile-256-bg) 45%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.tile-512 { background: var(--tile-512-bg); color: var(--tile-512-text); font-size: 45px; box-shadow: 0 0 30px 10px color-mix(in srgb, var(--tile-512-bg) 45%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.tile-1024 { background: var(--tile-1024-bg); color: var(--tile-1024-text); font-size: 35px; box-shadow: 0 0 30px 10px color-mix(in srgb, var(--tile-1024-bg) 42%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.tile-2048 { background: var(--tile-2048-bg); color: var(--tile-2048-text); font-size: 35px; box-shadow: 0 0 30px 10px color-mix(in srgb, var(--tile-2048-bg) 42%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }

@keyframes appear {
    0% { opacity: 0; transform: scale(0); }
    100% { opacity: 1; transform: scale(1); }
}

.tile-new {
    animation: appear 200ms ease 100ms;
    animation-fill-mode: backwards;
}

@keyframes pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.tile-merged {
    z-index: 20;
    animation: pop 200ms ease;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: color-mix(in srgb, var(--panel-bg) 90%, white 10%);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 14px;
    animation: fade-in 800ms ease 1200ms;
    animation-fill-mode: both;
}

.game-message p {
    font-size: 60px;
    font-weight: 800;
    height: 60px;
    line-height: 60px;
    margin-bottom: 30px;
}

.game-message .lower {
    display: flex;
    gap: 10px;
}

.game-message a {
    background: var(--button-bg);
    border-radius: 10px;
    padding: 0 20px;
    text-decoration: none;
    color: var(--text-light);
    height: 40px;
    line-height: 42px;
    cursor: pointer;
    font-weight: 700;
}

@keyframes fade-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.game-won { background: var(--status-won-bg); color: var(--text-light); }
.game-over { background: var(--status-over-bg); color: var(--status-over-text); }

.game-explanation {
    margin-top: 40px;
    line-height: 1.6;
    opacity: 0.94;
}

.icp-footer {
    margin-top: 24px;
    display: flex;
    justify-content: center;
}

.icp-footer a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 999px;
    border: 2px solid rgba(136, 120, 101, 0.28);
    background: linear-gradient(180deg, color-mix(in srgb, var(--panel-bg) 92%, white 8%), color-mix(in srgb, var(--panel-bg) 72%, var(--bg-color) 28%));
    color: var(--text-dark);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-decoration: none;
    box-shadow: 0 10px 24px rgba(119, 110, 101, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.icp-footer a:hover {
    transform: translateY(-1px);
    border-color: rgba(119, 110, 101, 0.5);
    box-shadow: 0 14px 28px rgba(119, 110, 101, 0.18);
}

@media screen and (max-width: 520px) {
    :root {
        --grid-size: 280px;
        --cell-size: 57.5px;
        --cell-gap: 10px;
    }

    body {
        padding: 12px;
    }

    .container {
        width: calc(var(--grid-size) + 28px);
        padding: 14px;
        border-radius: 18px;
    }

    .title {
        font-size: 52px;
    }

    .score-box {
        min-width: 60px;
        padding: 5px 10px;
        border-radius: 11px;
    }

    #score,
    #best-score {
        font-size: 18px;
    }

    .game-intro p {
        font-size: 14px;
    }

    #restart-button {
        font-size: 14px;
        padding: 8px 12px;
        border-radius: 10px;
    }

    .tile {
        font-size: 30px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 25px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 20px;
    }

    .game-message p {
        font-size: 30px;
    }

    .theme-switcher {
        gap: 6px;
        margin-top: 12px;
        padding: 8px;
    }

    .theme-button {
        padding: 7px 11px;
        font-size: 13px;
    }

    .icp-footer {
        margin-top: 18px;
    }

    .icp-footer a {
        font-size: 17px;
        padding: 9px 14px;
        letter-spacing: 0.2px;
    }
}

@keyframes panel-enter {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
