:root {
    --bg-color: #f0f4f8;
    --primary-color: #4a90e2;
    --accent-color: #f5a623;
    --text-color: #333;
    --board-bg: rgba(255, 255, 255, 0.8);
    --tile-size: 50px;
    --gap: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    color: var(--text-color);
}

#game-container {
    width: 100%;
    max-width: 500px;
    height: auto;
    max-height: 98vh;
    display: flex;
    flex-direction: column;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

header {
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
    background: white;
    border-radius: 15px;
    margin-bottom: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.label {
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 5px;
}

#score, #level, #target, #moves {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-color);
}

#board-wrapper {
    position: relative;
    padding: 5px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-board {
    position: relative;
    width: calc(8 * var(--tile-size) + 9 * var(--gap));
    height: calc(12 * var(--tile-size) + 13 * var(--gap));
    background: var(--board-bg);
    border-radius: 12px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.1);
    touch-action: none;
    overflow: hidden;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    user-select: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tile:active {
    transform: scale(0.9);
}

.tile.selected {
    outline: 3px solid var(--accent-color);
    box-shadow: 0 0 15px var(--accent-color);
    z-index: 10;
}

.tile.match {
    animation: pop-out 0.3s forwards;
}

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

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 50;
    animation: particle-fly 0.6s ease-out forwards;
}

@keyframes particle-fly {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    z-index: 100;
}

#overlay.hidden {
    display: none;
}

.message {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
}

.message h2 {
    margin-bottom: 10px;
    color: var(--primary-color);
}

.message button {
    margin: 20px 5px 5px 5px;
    padding: 10px 30px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

.message button:hover {
    background: #357abd;
}

#next-level-btn {
    background: var(--accent-color);
}

#next-level-btn:hover {
    background: #e69516;
}

footer {
    padding: 10px 0 5px 0;
}

.progress-container {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #62cff4, #2c67f2);
    transition: width 0.3s ease;
}

/* Mobile Adaptation */
@media (max-width: 500px) {
    :root {
        --tile-size: 10vw;
        --gap: 1.5vw;
    }
    
    #game-container {
        padding: 10px;
        border-radius: 0;
    }
}
