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

body {
    font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
    background-color: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 0;
    touch-action: none; /* Prevent default touch behaviors */
    -webkit-touch-callout: none; /* Disable callout on iOS */
    -webkit-user-select: none; /* Disable text selection */
    user-select: none;
}

.container {
    width: 540px;
    margin: 0 auto;
    padding: 20px;
    max-width: 100%;
    box-sizing: border-box;
}

h1 {
    font-size: 80px;
    font-weight: bold;
    margin: 20px 0;
    text-align: center;
}

.score-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.score-box {
    position: relative;
    background: #bbada0;
    padding: 15px 25px;
    border-radius: 3px;
    color: white;
    text-align: center;
    min-width: 100px;
}

.score-label {
    text-transform: uppercase;
    font-size: 13px;
    margin-bottom: 5px;
}

#score, #best-score {
    font-size: 25px;
    font-weight: bold;
}

.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    width: 500px;
    height: 500px;
    padding: 15px;
    margin-bottom: 30px;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.5);
    z-index: 100;
    text-align: center;
    animation: fade-in 800ms ease 1200ms;
    animation-fill-mode: both;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    height: 60px;
    line-height: 60px;
    margin-top: 180px;
}

.game-message .lower {
    margin-top: 30px;
}

.retry-button {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    cursor: pointer;
    font-weight: bold;
}

.grid-container {
    position: absolute;
    z-index: 1;
    width: 470px;
    height: 470px;
    top: 15px;
    left: 15px;
}

.grid-row {
    display: flex;
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 106.25px;
    height: 106.25px;
    margin-right: 15px;
    border-radius: 3px;
    background: rgba(238, 228, 218, 0.35);
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
    width: 470px;
    height: 470px;
    top: 15px;
    left: 15px;
}

.tile {
    position: absolute;
    width: 106.25px;
    height: 106.25px;
    border-radius: 3px;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    line-height: 106.25px;
    transition: all 150ms ease-in-out;
    transition-property: transform, opacity;
}

.tile-2 {
    background: #eee4da;
    color: #776e65;
    font-size: 55px;
}

.tile-4 {
    background: #ede0c8;
    color: #776e65;
    font-size: 55px;
}

.tile-8 {
    background: #f2b179;
    color: #f9f6f2;
    font-size: 55px;
}

.tile-16 {
    background: #f59563;
    color: #f9f6f2;
    font-size: 55px;
}

.tile-32 {
    background: #f67c5f;
    color: #f9f6f2;
    font-size: 55px;
}

.tile-64 {
    background: #f65e3b;
    color: #f9f6f2;
    font-size: 55px;
}

.tile-128 {
    background: #edcf72;
    color: #f9f6f2;
    font-size: 45px;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 45px;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 45px;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 35px;
}

.how-to-play {
    margin-top: 50px;
    line-height: 1.65;
    max-width: 500px;
}

.how-to-play h2 {
    font-size: 24px;
    color: #776e65;
    margin-bottom: 20px;
    font-weight: bold;
}

.how-to-play h3 {
    font-size: 18px;
    color: #776e65;
    margin: 20px 0 10px 0;
    font-weight: bold;
}

.controls-section, .goal-section, .scoring-section, .gameplay-section {
    margin-bottom: 25px;
}

.control-badges {
    margin: 15px 0;
}

.control-group {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.control-label {
    font-weight: bold;
    color: #776e65;
    min-width: 100px;
}

.badge-group {
    display: flex;
    gap: 5px;
}

.control-badge {
    display: inline-block;
    background: #bbada0;
    color: white;
    padding: 8px 12px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 14px;
    min-width: 30px;
    text-align: center;
}

.mobile-only {
    display: none;
}

.mobile-instruction {
    display: flex;
    align-items: center;
}

.swipe-instruction {
    background: #8f7a66;
    color: white;
    padding: 8px 12px;
    border-radius: 3px;
    font-size: 14px;
    font-weight: normal;
}

.tile-progression {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.mini-tile {
    display: inline-block;
    background: #eee4da;
    color: #776e65;
    padding: 6px 10px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 12px;
    min-width: 25px;
    text-align: center;
}

.goal-tile {
    background: #edc53f !important;
    color: #f9f6f2 !important;
    font-weight: bold;
}

.how-to-play ul {
    margin: 10px 0;
    padding-left: 20px;
}

.how-to-play li {
    margin-bottom: 8px;
    color: #776e65;
}

.how-to-play p {
    color: #776e65;
    margin: 10px 0;
}

.how-to-play strong {
    color: #776e65;
    font-weight: bold;
}

.footer {
    text-align: center;
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid #bbada0;
    background-color: #faf8ef;
}

.footer p {
    color: #776e65;
    font-size: 14px;
    margin: 0;
}

.footer a {
    color: #776e65;
    text-decoration: none;
    font-weight: bold;
}

.footer a:hover {
    color: #8f7a66;
    text-decoration: underline;
}

/* Touch Zone Visual Feedback for Mobile */
.touch-zones {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none;
}

.touch-zone {
    position: absolute;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.touch-zone-left {
    left: 0;
    top: 0;
    width: 25%;
    height: 100%;
}

.touch-zone-right {
    right: 0;
    top: 0;
    width: 25%;
    height: 100%;
}

.touch-zone-up {
    left: 25%;
    top: 0;
    width: 50%;
    height: 50%;
}

.touch-zone-down {
    left: 25%;
    bottom: 0;
    width: 50%;
    height: 50%;
}

/* Show touch zones on mobile when game starts */
@media (max-width: 520px) {
    .touch-zones.show {
        display: block;
        animation: touch-zones-fade 3s ease-out forwards;
    }
}

@keyframes touch-zones-fade {
    0% {
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

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

.tile-new {
    animation: pop 200ms ease-in-out;
}

.tile-merged {
    animation: pop 200ms ease-in-out;
    z-index: 20;
}

/* Mobile Responsive Styles */
@media screen and (max-width: 520px) {
    .container {
        width: 100%;
        padding: 10px;
    }
    
    .mobile-only {
        display: flex !important;
    }
    
    h1 {
        font-size: 48px;
        margin: 10px 0;
        text-align: center;
    }
    
    .score-container {
        justify-content: center;
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .score-box {
        padding: 10px 15px;
        min-width: 80px;
    }
    
    .score-label {
        font-size: 11px;
    }
    
    #score, #best-score {
        font-size: 20px;
    }
    
    .game-container {
        width: 320px;
        height: 320px;
        margin: 0 auto;
        position: relative;
        background: #bbada0;
        border-radius: 6px;
        padding: 15px;
        box-sizing: border-box;
    }
    
    .grid-container {
        width: 278px;
        height: 278px;
        position: absolute;
        top: 21px;
        left: 21px;
        z-index: 1;
    }
    
    .tile-container {
        width: 278px;
        height: 278px;
        position: absolute;
        top: 21px;
        left: 21px;
        z-index: 2;
    }
    
    .grid-cell, .tile {
        width: 62px;
        height: 62px;
        font-size: 24px;
        line-height: 62px;
    }
    
    .grid-cell {
        margin-right: 10px;
    }
    
    .grid-cell:last-child {
        margin-right: 0;
    }
    
    .grid-row {
        margin-bottom: 10px;
    }
    
    .grid-row:last-child {
        margin-bottom: 0;
    }
    
    .tile-2, .tile-4 {
        font-size: 32px;
    }
    
    .tile-8 {
        font-size: 32px;
    }
    
    .tile-16 {
        font-size: 28px;
    }
    
    .tile-32 {
        font-size: 28px;
    }
    
    .tile-64 {
        font-size: 24px;
    }
    
    .tile-128 {
        font-size: 20px;
    }
    
    .tile-256 {
        font-size: 20px;
    }
    
    .tile-512 {
        font-size: 18px;
    }
    
    .tile-1024 {
        font-size: 16px;
    }
    
    .how-to-play {
        margin-top: 30px;
        padding: 0 10px;
    }
    
    .how-to-play h2 {
        font-size: 20px;
        text-align: center;
    }
    
    .how-to-play h3 {
        font-size: 16px;
    }
    
    .control-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .control-label {
        min-width: auto;
        margin-bottom: 5px;
    }
    
    .control-badge {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 25px;
    }
    
    .tile-progression {
        justify-content: center;
        font-size: 12px;
    }
    
    .mini-tile {
        padding: 4px 6px;
        font-size: 10px;
        min-width: 20px;
    }
    
    .footer {
        margin-top: 20px;
        padding: 15px 10px;
    }
    
    .footer p {
        font-size: 12px;
    }
}

@media screen and (max-width: 380px) {
    h1 {
        font-size: 36px;
    }
    
    .game-container {
        width: 280px;
        height: 280px;
        padding: 12px;
    }
    
    .grid-container {
        width: 232px;
        height: 232px;
        position: absolute;
        top: 24px;
        left: 24px;
        z-index: 1;
    }
    
    .tile-container {
        width: 232px;
        height: 232px;
        position: absolute;
        top: 24px;
        left: 24px;
        z-index: 2;
    }
    
    .grid-cell, .tile {
        width: 52px;
        height: 52px;
        font-size: 20px;
        line-height: 52px;
    }
    
    .grid-cell {
        margin-right: 8px;
    }
    
    .grid-cell:last-child {
        margin-right: 0;
    }
    
    .grid-row {
        margin-bottom: 8px;
    }
    
    .grid-row:last-child {
        margin-bottom: 0;
    }
    
    .tile-16, .tile-32 {
        font-size: 18px;
    }
    
    .tile-64, .tile-128, .tile-256 {
        font-size: 14px;
    }
    
    .tile-512, .tile-1024 {
        font-size: 12px;
    }
}