* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: radial-gradient(circle at 20% 20%, #3b0066, #0c001a 70%);
    background-size: 100% 100%;
    background-attachment: fixed;
    
    font-family: 'Poppins', sans-serif;
    color: white;
    text-align: center;
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    overflow: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(0, 234, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 0, 255, 0.02) 1px, transparent 1px);
    background-size: 40px 40px;
    animation: gridMove 25s linear infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes gridMove {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(40px, 40px);
    }
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 10% 20%, rgba(0, 234, 255, 0.08), transparent 50%),
        radial-gradient(ellipse at 90% 80%, rgba(255, 0, 255, 0.08), transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(138, 43, 226, 0.05), transparent 60%);
    filter: blur(60px);
    animation: blobFloat 20s ease-in-out infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes blobFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.6;
    }
    50% {
        transform: translate(30px, -30px) scale(1.1);
        opacity: 0.8;
    }
}
/* ======================
   GAME CONTAINER
====================== */
.game-container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: scale(0.95);
}

/* Tutorial Button Specific */
.btn-tutorial {
    background: rgba(50, 0, 70, 0.85);
    border-color: rgba(200, 100, 255, 0.45);
}

.btn-tutorial svg {
    color: rgba(200, 100, 255, 0.9);
}

.btn-tutorial:hover {
    background: rgba(200, 100, 255, 0.15);
    border-color: rgba(200, 100, 255, 0.8);
    box-shadow: 
        0 6px 25px rgba(0, 0, 0, 0.45),
        0 0 35px rgba(200, 100, 255, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-tutorial:hover svg {
    color: rgba(200, 100, 255, 1);
}

/* ==========================
   BOARD
========================== */
#board {
    width: 100%;
    max-width: min(480px, 85vmin);
    aspect-ratio: 1;
    margin: 0 auto;
    padding: clamp(10px, 2vmin, 18px);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: clamp(6px, 1.2vmin, 12px);
    background: rgba(30, 0, 50, 0.65);
    backdrop-filter: blur(12px);
    border: 2px solid rgba(0, 217, 255, 0.35);
    border-radius: 20px;
    box-shadow: 
        0 25px 70px rgba(0, 0, 0, 0.6),
        0 0 45px rgba(0, 217, 255, 0.35),
        inset 0 0 35px rgba(0, 217, 255, 0.12);
    animation: glowBorderBoard 3.5s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

@keyframes glowBorderBoard {
    0%, 100% {
        border-color: rgba(0, 217, 255, 0.4);
        box-shadow: 
            0 25px 70px rgba(0, 0, 0, 0.6),
            0 0 45px rgba(0, 217, 255, 0.35),
            inset 0 0 35px rgba(0, 217, 255, 0.12);
    }
    50% {
        border-color: rgba(255, 0, 255, 0.55);
        box-shadow: 
            0 25px 70px rgba(0, 0, 0, 0.6),
            0 0 55px rgba(255, 0, 255, 0.45),
            inset 0 0 45px rgba(255, 0, 255, 0.18);
    }
}

#board::after {
    content: "";
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 360px;
    height: 90px;
    background: radial-gradient(ellipse at center, rgba(0,234,255,0.14), transparent 65%);
    filter: blur(35px);
    z-index: -1;
}

/* ======================
   TILE
====================== */
.tile {
    width: 100%;
    height: 100%;
    border-radius: clamp(8px, 1.8vmin, 14px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 3.5vmin, 32px);
    font-weight: 800;
    color: white;
    background: rgba(255, 255, 255, 0.07);
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
    transition: transform 0.15s cubic-bezier(.2,.85,.2,1), opacity 0.13s linear, box-shadow 0.13s;
    will-change: transform, opacity, box-shadow;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.tile.new {
    animation: pop 0.24s cubic-bezier(.2,.9,.2,1);
}

@keyframes pop {
    0% { transform: scale(0.15); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.tile.merge {
    animation: mergePop 0.26s ease-out;
    z-index: 3;
}

@keyframes mergePop {
    0% { transform: scale(1); box-shadow: 0 0 8px rgba(255,255,255,0.12); }
    50% { transform: scale(1.2); box-shadow: 0 0 35px rgba(255,255,255,0.4); }
    100% { transform: scale(1); box-shadow: 0 0 8px rgba(255,255,255,0.12); }
}

#board.shake {
    animation: shakeBoard 0.4s;
}

@keyframes shakeBoard {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* Enhanced Merge Animation */
.tile.merge {
    animation: mergeBounce 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 10;
}

@keyframes mergeBounce {
    0% { 
        transform: scale(1); 
        filter: brightness(1);
    }
    40% { 
        transform: scale(1.25) rotate(5deg); 
        filter: brightness(1.4) drop-shadow(0 0 25px currentColor);
    }
    60% {
        transform: scale(0.95) rotate(-3deg);
        filter: brightness(1.2);
    }
    80% {
        transform: scale(1.08);
        filter: brightness(1.1);
    }
    100% { 
        transform: scale(1) rotate(0deg); 
        filter: brightness(1);
    }
}

/* Particle Effect */
.merge-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9998;
    box-shadow: 
        0 0 10px currentColor,
        0 0 20px currentColor,
        inset 0 0 5px rgba(255, 255, 255, 0.5);
    filter: blur(0.5px);
}

/* Score Popup Animation */
.score-popup {
    animation: scoreFloat 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes scoreFloat {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    30% {
        transform: translate(-50%, -70px) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -120px) scale(1);
        opacity: 0;
    }
}

/* Enhanced Tile Glow on Merge */
.tile.merge {
    box-shadow: 
        0 0 30px currentColor,
        0 0 50px currentColor,
        inset 0 0 20px rgba(255, 255, 255, 0.3) !important;
}

/* Smoother New Tile Animation */
.tile.new {
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% { 
        transform: scale(0) rotate(-180deg); 
        opacity: 0;
        filter: blur(4px);
    }
    70% {
        transform: scale(1.15) rotate(10deg);
        filter: blur(0);
    }
    100% { 
        transform: scale(1) rotate(0deg); 
        opacity: 1;
        filter: blur(0);
    }
}

/* Tile Hover Effect - Make it more interactive */
.tile:not(:empty):hover {
    transform: scale(1.05);
    transition: transform 0.2s ease;
    filter: brightness(1.2);
}

/* Add ripple effect on board when moving */
#board.moving {
    animation: boardPulse 0.3s ease-out;
}

@keyframes boardPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.01);
    }
}

/* Show/Hide based on device */
.mobile-controls {
    display: none;
}

/* Keys Display */
.keys-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(20px, 5vw, 40px);
    flex-wrap: nowrap;
}

.keys-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.keys-grid-wasd,
.keys-grid-arrow {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 8px;
    justify-items: center;
    align-items: center;
}

.keys-separator {
    font-size: clamp(14px, 2.2vw, 18px);
    color: rgba(255, 255, 255, 0.5);
    font-weight: 700;
    padding: 0 clamp(10px, 2vw, 15px);
}

.key-box {
    width: clamp(42px, 6.5vw, 52px);
    height: clamp(42px, 6.5vw, 52px);
    background: rgba(0, 234, 255, 0.15);
    border: 2px solid rgba(0, 234, 255, 0.5);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(17px, 2.8vw, 22px);
    font-weight: 700;
    color: #00eaff;
    text-shadow: 0 0 10px rgba(0, 234, 255, 0.8);
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(0, 234, 255, 0.2),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.key-empty {
    width: clamp(42px, 6.5vw, 52px);
    height: clamp(42px, 6.5vw, 52px);
    visibility: hidden;
}

.keys-label {
    font-size: clamp(12px, 1.8vw, 14px);
    color: rgba(255, 255, 255, 0.6);
    margin-top: 5px;
    font-weight: 600;
    text-align: center;
}

/* Swipe Demo */
.swipe-demo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.swipe-icon {
    font-size: 48px;
    animation: swipeAnimation 2s ease-in-out infinite;
}

@keyframes swipeAnimation {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-15px); }
    50% { transform: translateX(0); }
    75% { transform: translateX(15px); }
}

.swipe-demo p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}

/* Objective Text */
.objective-text {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
}

.objective-text strong {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    font-weight: 800;
}