:root {
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --accent: #00cec9;
    --dark: #2d3436;
    --light: #f5f6fa;
    --success: #00b894;
    --danger: #d63031;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--dark);
    height: 100vh;
    overflow: hidden;
    touch-action: manipulation;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.5s;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    background: linear-gradient(to right, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#loading-bar-container {
    width: 80%;
    max-width: 300px;
    height: 6px;
    background: rgba(108, 92, 231, 0.2);
    border-radius: 3px;
    margin: 1rem 0;
    overflow: hidden;
}

#loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, var(--primary), var(--accent));
    transition: width 0.3s;
    border-radius: 3px;
}

#loading-text {
    margin: 0.5rem 0;
    font-size: 1rem;
    color: var(--dark);
    opacity: 0.8;
}

.btn {
    margin-top: 1.5rem;
    padding: 12px 30px;
    font-size: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    display: none;
    box-shadow: var(--shadow);
    transition: var(--transition);
    font-weight: 600;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(108, 92, 231, 0.2);
}

/* Main Game Screen */
#game-container {
    display: none;
    flex-direction: column;
    align-items: center;
    height: 100%;
    padding: 20px;
}

#header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
    margin-bottom: 20px;
}

.stat {
    background: white;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    text-align: center;
    min-width: 80px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 3px;
}

#pause-btn {
    background: white;
    border: none;
    color: var(--primary);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

#pause-btn:hover {
    background: var(--primary);
    color: white;
}

#board {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1/1;
    margin: 10px auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    background: white;
    padding: 10px;
    border-radius: 15px;
    box-shadow: var(--shadow);
}

.tile {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.1s, box-shadow 0.2s;
    user-select: none;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

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

.empty {
    background: rgba(255,255,255,0.1);
    box-shadow: none;
    cursor: default;
}

/* Pause and Win Menus */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(45, 52, 54, 0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.modal {
    background: white;
    width: 85%;
    max-width: 300px;
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease-out;
}

.modal.show {
    transform: translateY(0);
    opacity: 1;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--primary);
}

.stats {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
}

.stat-item {
    text-align: center;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--dark);
    opacity: 0.8;
}

.stat-number {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 5px;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-btn {
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.modal-btn:hover {
    transform: translateY(-2px);
}

#resume-btn {
    background: var(--success);
    color: white;
}

#restart-btn {
    background: var(--accent);
    color: white;
}

#sound-toggle {
    background: var(--secondary);
    color: white;
}

#home-btn, #win-home-btn {
    background: var(--danger);
    color: white;
}

/* Responsive Design */
@media (max-width: 400px) {
    .logo {
        font-size: 2rem;
    }
    
    .stat {
        padding: 8px 12px;
        font-size: 0.8rem;
        min-width: 70px;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    #board {
        max-width: 280px;
        gap: 6px;
    }
    
    .tile {
        font-size: 1.3rem;
    }
}

@media (max-height: 600px) {
    #board {
        max-width: 250px;
    }
    
    #header {
        margin-bottom: 15px;
    }
}