* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Orbitron', 'Arial', sans-serif;
    background: linear-gradient(45deg, #0a0a0a, #1a1a2e, #16213e, #0f3460);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #00ffff;
    overflow-x: hidden;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.container {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #00ffff;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 
        0 0 50px rgba(0, 255, 255, 0.5),
        inset 0 0 50px rgba(0, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #00ffff, #ff00ff, #ffff00, #00ffff);
    border-radius: 20px;
    z-index: -1;
    animation: borderGlow 3s linear infinite;
}

@keyframes borderGlow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

h1 {
    text-align: center;
    font-size: 3.5rem;
    margin-bottom: 20px;
    background: linear-gradient(45deg, #00ffff, #ff00ff, #ffff00);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: neonPulse 2s ease-in-out infinite alternate;
    text-shadow: 
        0 0 10px #00ffff,
        0 0 20px #00ffff,
        0 0 30px #00ffff;
    font-weight: bold;
    letter-spacing: 3px;
}

@keyframes neonPulse {
    from { 
        text-shadow: 
            0 0 10px #00ffff,
            0 0 20px #00ffff,
            0 0 30px #00ffff;
    }
    to { 
        text-shadow: 
            0 0 20px #ff00ff,
            0 0 30px #ff00ff,
            0 0 40px #ff00ff;
    }
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.score-container {
    display: flex;
    gap: 15px;
}

.score-box {
    background: linear-gradient(45deg, #1a1a2e, #16213e);
    border: 1px solid #00ffff;
    border-radius: 10px;
    padding: 15px 20px;
    text-align: center;
    color: #00ffff;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    min-width: 90px;
    box-shadow: 
        0 0 20px rgba(0, 255, 255, 0.3),
        inset 0 0 20px rgba(0, 255, 255, 0.1);
    animation: scoreGlow 3s ease-in-out infinite alternate;
}

@keyframes scoreGlow {
    0% { box-shadow: 0 0 20px rgba(0, 255, 255, 0.3), inset 0 0 20px rgba(0, 255, 255, 0.1); }
    100% { box-shadow: 0 0 30px rgba(255, 0, 255, 0.4), inset 0 0 30px rgba(255, 0, 255, 0.1); }
}

.score-box span:first-child {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-box span:last-child {
    font-size: 1.8rem;
    text-shadow: 0 0 10px currentColor;
}

#new-game-btn {
    background: linear-gradient(45deg, #00ffff, #ff00ff);
    color: #000;
    border: none;
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 0 20px rgba(0, 255, 255, 0.5),
        0 4px 15px rgba(0, 0, 0, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#new-game-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 
        0 0 30px rgba(255, 0, 255, 0.7),
        0 8px 25px rgba(0, 0, 0, 0.4);
    background: linear-gradient(45deg, #ff00ff, #ffff00);
}

.game-container {
    position: relative;
    width: 400px;
    height: 400px;
    margin: 0 auto 30px;
}

.grid-container {
    position: absolute;
    z-index: 1;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #0a0a0a, #1a1a2e);
    border: 2px solid #00ffff;
    border-radius: 15px;
    padding: 10px;
    display: grid;
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    box-shadow: 
        0 0 30px rgba(0, 255, 255, 0.4),
        inset 0 0 30px rgba(0, 255, 255, 0.1);
}

.grid-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.grid-cell {
    background: linear-gradient(45deg, #16213e, #0f3460);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.1);
}

.tile-container {
    position: absolute;
    z-index: 2;
    width: 100%;
    height: 100%;
    padding: 10px;
}

.tile {
    position: absolute;
    width: 87.5px;
    height: 87.5px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    transition: all 0.3s ease;
    animation: tileAppear 0.5s ease;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-shadow: 0 0 10px currentColor;
}

@keyframes tileAppear {
    from {
        transform: scale(0) rotate(180deg);
        opacity: 0;
    }
    to {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.tile-2 { 
    background: linear-gradient(45deg, #ff6b6b, #ff8e8e); 
    color: #fff; 
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.5);
}
.tile-4 { 
    background: linear-gradient(45deg, #4ecdc4, #45b7aa); 
    color: #fff; 
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
}
.tile-8 { 
    background: linear-gradient(45deg, #45b7d1, #3a9bc1); 
    color: #fff; 
    box-shadow: 0 0 20px rgba(69, 183, 209, 0.5);
}
.tile-16 { 
    background: linear-gradient(45deg, #f9ca24, #f39c12); 
    color: #fff; 
    box-shadow: 0 0 20px rgba(249, 202, 36, 0.5);
}
.tile-32 { 
    background: linear-gradient(45deg, #f0932b, #eb4d4b); 
    color: #fff; 
    box-shadow: 0 0 20px rgba(240, 147, 43, 0.5);
}
.tile-64 { 
    background: linear-gradient(45deg, #eb4d4b, #c0392b); 
    color: #fff; 
    box-shadow: 0 0 25px rgba(235, 77, 75, 0.6);
}
.tile-128 { 
    background: linear-gradient(45deg, #00ffff, #0099cc); 
    color: #000; 
    font-size: 1.5rem; 
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.8);
    animation: superGlow 2s ease-in-out infinite alternate;
}
.tile-256 { 
    background: linear-gradient(45deg, #ff00ff, #cc0099); 
    color: #fff; 
    font-size: 1.5rem; 
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.8);
    animation: superGlow 2s ease-in-out infinite alternate;
}
.tile-512 { 
    background: linear-gradient(45deg, #ffff00, #cccc00); 
    color: #000; 
    font-size: 1.5rem; 
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.8);
    animation: superGlow 2s ease-in-out infinite alternate;
}
.tile-1024 { 
    background: linear-gradient(45deg, #00ff00, #00cc00); 
    color: #000; 
    font-size: 1.2rem; 
    box-shadow: 0 0 40px rgba(0, 255, 0, 0.8);
    animation: epicGlow 1.5s ease-in-out infinite alternate;
}
.tile-2048 { 
    background: linear-gradient(45deg, #ff00ff, #00ffff, #ffff00); 
    background-size: 200% 200%;
    animation: rainbowShift 3s ease infinite, epicGlow 1s ease-in-out infinite alternate;
    color: #000; 
    font-size: 1.2rem; 
    box-shadow: 0 0 50px rgba(255, 255, 255, 0.9);
    border: 2px solid #fff;
}

@keyframes superGlow {
    0% { box-shadow: 0 0 30px currentColor; }
    100% { box-shadow: 0 0 50px currentColor, 0 0 80px currentColor; }
}

@keyframes epicGlow {
    0% { box-shadow: 0 0 40px currentColor; }
    100% { box-shadow: 0 0 60px currentColor, 0 0 100px currentColor; }
}

@keyframes rainbowShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.highscore-section {
    text-align: center;
    margin-top: 30px;
}

.highscore-section h2 {
    margin-bottom: 20px;
    color: #00ffff;
    font-size: 2rem;
    text-shadow: 0 0 20px #00ffff;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#highscore-list {
    display: grid;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: linear-gradient(45deg, rgba(0, 0, 0, 0.5), rgba(26, 26, 46, 0.5));
    border-radius: 10px;
    border: 1px solid rgba(0, 255, 255, 0.3);
}

.highscore-item {
    background: linear-gradient(45deg, #1a1a2e, #16213e);
    padding: 12px 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(0, 255, 255, 0.2);
    color: #00ffff;
    transition: all 0.3s ease;
}

.highscore-item:hover {
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.4);
    transform: translateY(-2px);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
}

.modal-content {
    background: linear-gradient(45deg, #0a0a0a, #1a1a2e);
    margin: 15% auto;
    padding: 40px;
    border-radius: 20px;
    width: 400px;
    text-align: center;
    box-shadow: 
        0 0 50px rgba(0, 255, 255, 0.5),
        inset 0 0 50px rgba(0, 255, 255, 0.1);
    border: 2px solid #00ffff;
    color: #00ffff;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #00ffff;
    font-size: 2.5rem;
    text-shadow: 0 0 20px #00ffff;
    text-transform: uppercase;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 20px;
}

.modal-content input {
    padding: 15px;
    border: 2px solid #00ffff;
    border-radius: 10px;
    font-size: 1.1rem;
    background: rgba(0, 0, 0, 0.7);
    color: #00ffff;
    transition: all 0.3s ease;
}

.modal-content input:focus {
    outline: none;
    border-color: #ff00ff;
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.5);
}

.modal-content input::placeholder {
    color: rgba(0, 255, 255, 0.6);
}

.modal-content button {
    background: linear-gradient(45deg, #00ffff, #ff00ff);
    color: #000;
    border: none;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-content button:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.7);
    background: linear-gradient(45deg, #ff00ff, #ffff00);
}

#close-modal-btn {
    background: linear-gradient(45deg, #666, #999);
    color: #fff;
    margin-top: 10px;
}

#close-modal-btn:hover {
    background: linear-gradient(45deg, #999, #ccc);
    color: #000;
}

#modal-message {
    margin: 15px 0;
    padding: 15px;
    border-radius: 8px;
    display: none;
    font-weight: bold;
    text-align: center;
    animation: messageGlow 0.5s ease;
}

#modal-message.success {
    background: linear-gradient(45deg, #00ff00, #00cc00);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
    display: block;
}

#modal-message.error {
    background: linear-gradient(45deg, #ff0000, #cc0000);
    color: #fff;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
    display: block;
}

.success-message {
    background: linear-gradient(45deg, #00ff00, #00cc00);
    color: #000;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    text-align: center;
    animation: messageGlow 0.5s ease;
    font-weight: bold;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
}

.error-message {
    background: linear-gradient(45deg, #ff0000, #cc0000);
    color: #fff;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    text-align: center;
    animation: messageGlow 0.5s ease;
    font-weight: bold;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
}

@keyframes messageGlow {
    from { opacity: 0; transform: translateY(-20px) scale(0.8); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content .message {
    margin-bottom: 15px;
}

@media (max-width: 600px) {
    body {
        padding: 10px;
        align-items: flex-start;
        min-height: 100vh;
    }
    
    .container {
        padding: 15px;
        margin: 10px 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    h1 {
        font-size: 2rem;
        margin-bottom: 15px;
        letter-spacing: 1px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 15px;
    }
    
    .score-container {
        justify-content: center;
        gap: 20px;
    }
    
    .score-box {
        padding: 10px 15px;
        min-width: 70px;
    }
    
    .score-box span:first-child {
        font-size: 0.8rem;
    }
    
    .score-box span:last-child {
        font-size: 1.4rem;
    }
    
    #new-game-btn {
        padding: 12px 25px;
        font-size: 1rem;
        width: 100%;
    }
    
    .game-container {
        width: 280px;
        height: 280px;
        margin: 0 auto 20px;
    }
    
    .grid-container {
        padding: 8px;
        gap: 8px;
    }
    
    .grid-row {
        gap: 8px;
    }
    
    .tile {
        width: 60px;
        height: 60px;
        font-size: 1.3rem;
        border-radius: 6px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.9rem;
    }
    
    .highscore-section h2 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .highscore-item {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    
    .modal-content {
        width: 90%;
        max-width: 350px;
        margin: 10% auto;
        padding: 25px;
    }
    
    .modal-content h2 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }
    
    .modal-content input {
        padding: 12px;
        font-size: 1rem;
    }
    
    .modal-content button {
        padding: 12px;
        font-size: 1rem;
    }
}

@media (max-width: 400px) {
    .container {
        padding: 10px;
        margin: 5px 0;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .game-container {
        width: 250px;
        height: 250px;
    }
    
    .tile {
        width: 52px;
        height: 52px;
        font-size: 1.1rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 0.9rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.8rem;
    }
    
    .score-box {
        padding: 8px 12px;
        min-width: 60px;
    }
    
    .score-box span:last-child {
        font-size: 1.2rem;
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
    }
}

@media (max-width: 320px) {
    .game-container {
        width: 220px;
        height: 220px;
    }
    
    .tile {
        width: 46px;
        height: 46px;
        font-size: 1rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 0.8rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.7rem;
    }
    
    .score-container {
        gap: 15px;
    }
    
    .score-box {
        padding: 6px 10px;
        min-width: 55px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .highscore-item {
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    #new-game-btn {
        min-height: 48px;
        touch-action: manipulation;
    }
    
    .modal-content button {
        min-height: 48px;
        touch-action: manipulation;
    }
    
    .tile-container {
        touch-action: none;
        user-select: none;
    }
}
