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

html {
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    height: 100%;
}

body {
    background-color: #1a1a2e;
    /* Dark background */
    font-family: Arial, sans-serif;
    color: #ffffff;
    /* White text */
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

h1 {
    font-size: 48px;
    color: #A855F7;
    /* Purple */
    margin: 20px 0;
    text-shadow: 0 0 10px rgba(168, 85, 247, 0.3);
    /* Subtle glow effect */
}

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

.title {
    margin: 0;
    font-size: 36px;
    font-weight: bold;
    color: #776e65;
}

.score-container {
    background: #3B1F5E;
    /* Dark purple */
    padding: 15px 25px;
    border-radius: 6px;
    color: #ffffff;
    font-size: 18px;
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.1);
}

#game-board {
    background: #3B1F5E;
    /* Dark purple */
    padding: 15px;
    border-radius: 6px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 15px;
    position: relative;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.1);
    aspect-ratio: 1;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    /* Prevent scrolling on touch devices - STRICT for mini apps */
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    /* Make it a clear touch target */
    -webkit-tap-highlight-color: transparent;
    /* Prevent any pointer events that might interfere */
    pointer-events: auto;
    /* Prevent momentum scrolling */
    -webkit-overflow-scrolling: auto;
}

#game-board.disabled {
    opacity: 0.7;
    pointer-events: none;
    cursor: not-allowed;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    background: #1a1a2e;
    /* Dark background */
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(20px, 5vw, 35px);
    font-weight: bold;
    color: #ffffff;
    transition: all 0.2s;
    /* Prevent touch interference */
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    pointer-events: auto;
}

/* Tile colors for different numbers */
.tile[data-value="2"] {
    background: #4C1D95;
    color: #ffffff;
}

.tile[data-value="4"] {
    background: #5B21B6;
    color: #ffffff;
}

.tile[data-value="8"] {
    background: #6D28D9;
    color: #ffffff;
}

.tile[data-value="16"] {
    background: #7C3AED;
    color: #ffffff;
}

.tile[data-value="32"] {
    background: #8B5CF6;
    color: #ffffff;
}

.tile[data-value="64"] {
    background: #A78BFA;
    color: #ffffff;
}

.tile[data-value="128"] {
    background: #C4B5FD;
    color: #1a1a2e;
}

.tile[data-value="256"] {
    background: #DDD6FE;
    color: #1a1a2e;
}

.tile[data-value="512"] {
    background: #EDE9FE;
    color: #1a1a2e;
}

.tile[data-value="1024"] {
    background: #F3E8FF;
    color: #1a1a2e;
}

.tile[data-value="2048"] {
    background: #FAF5FF;
    color: #1a1a2e;
}

#name-input-container {
    background: #3B1F5E;
    /* Dark purple */
    padding: 20px;
    border-radius: 6px;
    margin-top: 20px;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.1);
}

input {
    padding: 10px;
    margin: 10px;
    font-size: 16px;
    border: 2px solid #A855F7;
    border-radius: 4px;
    background: #1a1a2e;
    color: #ffffff;
    outline: none;
}

input::placeholder {
    color: #A78BFA;
}

button {
    background: #A855F7;
    color: #ffffff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

button:hover {
    background: #9333EA;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
}

/* Add glow effect when tiles merge */
.tile-merged {
    animation: merge 0.2s ease-in-out;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
}

@keyframes merge {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.leaderboard {
    background: #3B1F5E;
    padding: 20px;
    border-radius: 6px;
    margin-top: 20px;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.1);
}

.leaderboard h2 {
    color: #A855F7;
    margin-bottom: 15px;
    font-size: 24px;
}

#high-scores-list {
    color: #ffffff;
    text-align: left;
    margin: 10px 0;
}

.high-score-entry {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

.high-score-entry:last-child {
    border-bottom: none;
}

.clear-scores {
    margin-top: 10px;
    background: #ff4444;
}

.clear-scores:hover {
    background: #cc0000;
}

.wallet-btn, .stats-btn {
    background: #A855F7;
    color: #ffffff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.wallet-btn:hover, .stats-btn:hover {
    background: #9333EA;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
}

/* Game Over Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: linear-gradient(135deg, #3B1F5E 0%, #4C1D95 100%);
    border-radius: 12px;
    padding: 0;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 10px 40px rgba(168, 85, 247, 0.4), 0 0 20px rgba(168, 85, 247, 0.2);
    animation: slideUp 0.3s ease;
    border: 2px solid rgba(168, 85, 247, 0.3);
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 25px 25px 15px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.3);
}

.modal-header h2 {
    color: #A855F7;
    font-size: 28px;
    margin: 0;
    text-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
    text-align: center;
}

.modal-body {
    padding: 25px;
    text-align: center;
}

.score-display {
    margin-bottom: 20px;
}

.score-label {
    color: #A78BFA;
    font-size: 16px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    color: #ffffff;
    font-size: 48px;
    font-weight: bold;
    margin: 0;
    text-shadow: 0 0 15px rgba(168, 85, 247, 0.6);
}

.modal-message {
    color: #ffffff;
    font-size: 16px;
    line-height: 1.5;
    margin: 15px 0 0;
    opacity: 0.9;
}

.modal-footer {
    padding: 20px 25px 25px;
    display: flex;
    gap: 15px;
    justify-content: center;
    border-top: 1px solid rgba(168, 85, 247, 0.3);
}

.modal-btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #A78BFA;
    border: 2px solid rgba(168, 85, 247, 0.3);
}

.modal-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(168, 85, 247, 0.5);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
}

.modal-btn-confirm {
    background: #A855F7;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
}

.modal-btn-confirm:hover {
    background: #9333EA;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
    transform: translateY(-2px);
}

.modal-btn:active {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        max-width: 95%;
    }
    
    .modal-header h2 {
        font-size: 24px;
    }
    
    .score-value {
        font-size: 36px;
    }
    
    .modal-message {
        font-size: 14px;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-btn {
        width: 100%;
    }
}