:root {
    --bg-color: #e0f4ff;
    --ice-dark: #2a82bb;
    --ice-light: #b3e5fc;
    --ice-accent: #ffffff;
    --text-color: #0d47a1;
    --font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --transition-speed: 900ms;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100dvh;
	
    background-image: url("images/ice_bg_body.png");
background-size: cover;
background-position: center;
background-repeat: no-repeat;

	
    font-family: var(--font-family);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
    touch-action: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 20, 40, 0.5);
    z-index: -1;
}


#game-container {
    position: relative;
    aspect-ratio: 9 / 16;
    height: 100dvh;
    width: auto;
    max-width: 100vw;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 1% 2% calc(1% + env(safe-area-inset-bottom));
	
    background: radial-gradient(circle at 50% 0%, #4fc3f7, #01579b);
	
    backdrop-filter: blur(15px);
    box-shadow: 0 0 100px rgba(0,0,0,0.8);
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    margin-bottom: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    gap: 6px;
}

.stat-box { 
    text-align: center; 
    flex: 1; 
}

.stat-label { 
    font-size: 9px; 
    font-weight: 800; 
    color: rgba(255,255,255,0.7); 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
}

.stat-value { 
    font-size: 18px; 
    font-weight: 900; 
    color: #fff; 
    text-shadow: 0 1px 3px rgba(0,0,0,0.3); 
}

.joker-progress-container {
    width: 100%;
    height: 8px;
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
    margin-bottom: 8px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.1);
}

#joker-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #ffeb3b, #fb8c00);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#grid-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 0;
}

#grid-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: rgba(0, 0, 0, 0.15);
    border: 6px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 8px;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.4);
    touch-action: none;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
}

.cell {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.2);
}

.tile {
    position: absolute;
    width: calc((100% - 16px - 24px) / 4); 
    height: calc((100% - 16px - 24px) / 4);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    font-size: clamp(14px, 9vw, 36px);
    border-radius: 10px;
    transition: top var(--transition-speed) cubic-bezier(0.25, 1, 0.5, 1), 
                left var(--transition-speed) cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 10;
    color: #fff;
    pointer-events: none;
    will-change: top, left, transform;
    white-space: nowrap;
    line-height: 1;
    
    box-shadow: 
        0 5px 0 rgba(0, 0, 0, 0.25),
        inset 0 2px 1px rgba(255, 255, 255, 0.5),
        inset 0 -1px 3px rgba(0, 0, 0, 0.2);
}

.tile::before {
    content: '';
    position: absolute;
    top: 2px; 
    left: 2px; 
    right: 2px; 
    height: 35%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.25), transparent);
    border-radius: 8px 8px 100% 100%;
}

.tile-2 { 
    background: linear-gradient(135deg, #e0f7fa, #80deea); 
    color: #006064; 
}

.tile-4 { 
    background: linear-gradient(135deg, #b3e5fc, #4fc3f7); 
    color: #01579b; 
}

.tile-8 { 
    background: linear-gradient(135deg, #81d4fa, #039be5); 
    box-shadow: 0 5px 0 #0277bd, inset 0 2px 1px rgba(255,255,255,0.5); 
}

.tile-16 { 
    background: linear-gradient(135deg, #4fc3f7, #0288d1); 
    box-shadow: 0 5px 0 #01579b, inset 0 2px 1px rgba(255,255,255,0.5); 
}

.tile-32 { 
    background: linear-gradient(135deg, #29b6f6, #0277bd); 
    box-shadow: 0 5px 0 #014d80, inset 0 2px 1px rgba(255,255,255,0.5); 
}

.tile-64 { 
    background: linear-gradient(135deg, #039be5, #01579b); 
    box-shadow: 0 5px 0 #003661, inset 0 2px 1px rgba(255,255,255,0.4); 
}

.tile-128 { 
    background: linear-gradient(135deg, #0288d1, #01579b); 
    box-shadow: 0 5px 0 #002d52; 
    border: 1px solid rgba(255,255,255,0.2); 
}

.tile-256 { 
    background: linear-gradient(135deg, #0277bd, #0d47a1); 
    box-shadow: 0 5px 0 #001f40; 
}

.tile-512 { 
    background: linear-gradient(135deg, #01579b, #1a237e); 
    box-shadow: 0 5px 0 #000; 
}

.tile-1024 { 
    background: linear-gradient(135deg, #0d47a1, #000); 
    box-shadow: 0 5px 0 #000; 
}

.tile-2048 { 
    background: linear-gradient(135deg, #1a237e, #311b92); 
    box-shadow: 0 5px 0 #000; 
    border: 2px solid rgba(255,255,255,0.3); 
}

.tile-joker { 
    background: linear-gradient(135deg, #ffd700, #ff8f00, #ff6f00); 
    box-shadow: 0 5px 0 #bf360c, 0 0 15px rgba(255, 143, 0, 0.4), inset 0 2px 2px rgba(255, 255, 255, 0.7);
    animation: joker-pulse 2s infinite ease-in-out;
}

@keyframes joker-pulse { 
    0%, 100% { 
        transform: scale(1); 
    } 
    50% { 
        transform: scale(1.02); 
    } 
}

.tile-new { 
    animation: pop-in 450ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; 
}

.tile-merged { 
    z-index: 20; 
    animation: merge-impact 500ms cubic-bezier(0.175, 0.885, 0.32, 1.5) forwards; 
}

@keyframes pop-in { 
    0% { 
        transform: scale(0); 
        opacity: 0; 
    } 
    100% { 
        transform: scale(1); 
        opacity: 1; 
    } 
}

@keyframes merge-impact { 
    0% { 
        transform: scale(1); 
        filter: brightness(1); 
    } 
    40% { 
        transform: scale(1.15); 
        filter: brightness(1.6); 
        box-shadow: 0 0 30px rgba(255,255,255,0.6); 
    } 
    100% { 
        transform: scale(1); 
        filter: brightness(1); 
    } 
}

footer {
    margin-top: auto;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 12px 0;
    flex-shrink: 0;
}

.btn {
    background: linear-gradient(to bottom, #4fc3f7, #0288d1);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 12px;
    color: #fff;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 5px 0 #014170;
    transition: all 0.1s;
    text-transform: uppercase;
}

.btn:active { 
    transform: translateY(3px); 
    box-shadow: 0 2px 0 #014170; 
}

.overlay {
    position: absolute;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(1, 22, 39, 0.98);
    z-index: 100;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
    backdrop-filter: blur(20px);
}

#overlay-start {
    background-image: url("images/start_bg.png");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

#overlay-start::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 20, 40, 0.55);
    z-index: 0;
}

#overlay-start > * {
    position: relative;
    z-index: 1;
}


.overlay h1 { 
    color: #fff; 
    font-size: 32px; 
    margin-bottom: 12px; 
    text-transform: uppercase; 
    letter-spacing: 1px; 
}

.overlay p { 
    color: #e1f5fe; 
    margin-bottom: 25px; 
    font-size: 16px; 
}

#overlay-pre-ad { 
    background: rgba(0, 0, 0, 0.9); 
    z-index: 1000; 
}

#ad-timer { 
    font-size: 80px; 
    font-weight: 900; 
    color: #ffeb3b; 
    margin: 20px 0; 
}

#overlay-start { 
    display: flex; 
}

