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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    color: white;
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
}

.mobile-instructions {
    display: none;
    font-size: 1rem;
    margin-top: 5px;
    font-style: italic;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.score-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 15px;
    border-radius: 10px;
    text-align: center;
    backdrop-filter: blur(10px);
}

.score-label {
    color: white;
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.score-box div:last-child {
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

#new-game-btn, #restart-btn, #continue-btn, #new-game-won-btn {
    background: #ff6b6b;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

#new-game-btn:hover, #restart-btn:hover, #continue-btn:hover, #new-game-won-btn:hover {
    background: #ff5252;
}

.game-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.game-board {
    position: relative;
    width: min(90vw, 420px);
    aspect-ratio: 1 / 1;
    background: rgba(255, 255, 255, 0.2);
    padding: var(--board-padding);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    margin: 0 auto;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    touch-action: none;
}

:root {
    --cell-gap: 12px;
    --board-padding: 18px;
}

.grid-container {
    position: absolute;
    inset: var(--board-padding);
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: var(--cell-gap);
}

.grid-cell {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.tile {
    position: absolute;
    z-index: 2;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    transition: transform 0.15s ease-in-out;
    top: 0;
    left: 0;
}

/* Mobile-first scaling */
@media (max-width: 600px) {
    :root {
        --cell-gap: 10px;
        --board-padding: 14px;
    }
    header h1 { font-size: 2.4rem; }
}

@media (max-width: 480px) {
    :root {
        --cell-gap: 8px;
        --board-padding: 10px;
    }
    .container { padding: 12px; }
    header h1 { font-size: 1.8rem; }
    .mobile-instructions { display: block; color: rgba(255,255,255,0.85); }
}

@media (max-width: 360px) {
    :root {
        --cell-gap: 6px;
        --board-padding: 8px;
    }
    .container { padding: 8px; }
    header h1 { font-size: 1.6rem; }
}

.tile-appear {
    animation: appear 0.2s ease-in-out;
}

.tile-merge {
    animation: merge 0.15s ease-in-out;
}

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

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

.tile.letter-A { background: #ff9ff3; color: #333; }
.tile.letter-B { background: #f368e0; color: #333; }
.tile.letter-C { background: #ff6b9d; color: white; }
.tile.letter-D { background: #c44569; color: white; }
.tile.letter-E { background: #f8b500; color: #333; }
.tile.letter-F { background: #feca57; color: #333; }
.tile.letter-G { background: #ff9f43; color: #333; }
.tile.letter-H { background: #ff6348; color: white; }
.tile.letter-I { background: #ff4757; color: white; }
.tile.letter-J { background: #c44569; color: white; }
.tile.letter-K { background: #8854d0; color: white; }
.tile.letter-L { background: #4834d4; color: white; }
.tile.letter-M { background: #30336b; color: white; }
.tile.letter-N { background: #130f40; color: white; }
.tile.letter-O { background: #6c5ce7; color: white; }
.tile.letter-P { background: #a29bfe; color: #333; }
.tile.letter-Q { background: #fd79a8; color: #333; }
.tile.letter-R { background: #fdcb6e; color: #333; }
.tile.letter-S { background: #e17055; color: white; }
.tile.letter-T { background: #d63031; color: white; }
.tile.letter-U { background: #74b9ff; color: #333; }
.tile.letter-V { background: #0984e3; color: white; }
.tile.letter-W { background: #00b894; color: white; }
.tile.letter-X { background: #00cec9; color: #333; }
.tile.letter-Y { background: #55a3ff; color: #333; }
.tile.letter-Z { background: #ffd700; color: #333; font-size: 2.5rem; box-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }

.game-over, .game-won {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
}

.game-over-content, .game-won-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
}

.game-over-content h2, .game-won-content h2 {
    margin-bottom: 15px;
    color: #333;
}

.game-over-content p, .game-won-content p {
    margin-bottom: 20px;
    color: #666;
}

.game-won-content {
    background: linear-gradient(135deg, #ffd700, #ffed4e);
}

.game-won-content h2 {
    color: #333;
}

.hidden {
    display: none !important;
}

.instructions {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    margin-bottom: 20px;
}

.instructions h3 {
    color: white;
    margin-bottom: 10px;
}

.instructions p {
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.5;
    margin-bottom: 10px;
}

footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-style: italic;
}

footer p {
    margin-bottom: 5px;
}

footer a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.3s;
}

footer a:hover {
    color: white;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}