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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100svh; /* Use small viewport height for mobile */
    overflow: hidden;
    padding: 10px;
}

.game-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    max-height: 100vh;
    max-height: 100svh; /* Use small viewport height for mobile */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h1 {
    color: #764ba2;
    margin-bottom: 10px;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.title-icon {
    height: 1.2em;
    width: auto;
    vertical-align: middle;
    margin-right: 10px;
    display: inline-block;
}

.score-container {
    display: flex;
    justify-content: space-around;
    margin-bottom: 10px;
    font-size: 1em;
    font-weight: bold;
    gap: 10px;
    flex-shrink: 0;
}

.score {
    color: #667eea;
}

.timer {
    color: #00b894;
}

.timer.warning {
    color: #e17055;
}

.timer.danger {
    color: #d63031;
    animation: blink 0.5s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.high-score {
    color: #ff6b6b;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(4, 75px);
    gap: 0;
    border: 4px solid #764ba2;
    border-radius: 10px;
    overflow: hidden;
    background: #f0f0f0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    position: relative;
    margin: 0 auto;
    flex-shrink: 1;
    min-height: 0;
}

.tile {
    width: 75px;
    height: 110px;
    background: white;
    border: 1px solid #ddd;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2em;
    transition: all 0.1s ease;
    user-select: none;
    position: relative;
}

.tile.not-bottom {
    cursor: not-allowed;
    opacity: 0.4;
    background: #e8e8e8;
    pointer-events: none;
}

.tile.not-bottom:hover {
    background: #e8e8e8;
}

.tile:not(.not-bottom):hover {
    background: #f8f8f8;
}

.tile.active {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    animation: pulse 0.5s ease-in-out infinite alternate;
}

.tile.active.not-bottom {
    background: linear-gradient(135deg, #e8d89a 0%, #d4b85e 100%);
    animation: none;
    opacity: 0.4;
}

.tile.clicked {
    background: #00b894;
    pointer-events: none;
}

.tile.wrong {
    background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
    animation: shake 0.3s;
}

.tile.shifting {
    transition: transform 0.2s ease-out;
}

@keyframes pulse {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(1.05);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    max-width: 90%;
}

.game-over.hidden {
    display: none;
}

.game-over h2 {
    color: #d63031;
    margin-bottom: 10px;
    font-size: 1.8em;
}

.game-over p {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 10px;
}

#restart-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.1em;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
    font-weight: bold;
}

#restart-btn:hover {
    transform: scale(1.05);
}

#restart-btn:active {
    transform: scale(0.95);
}

/* Mobile-specific adjustments */
@media (max-height: 700px) {
    .game-container {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 8px;
    }
    
    .score-container {
        font-size: 0.9em;
        margin-bottom: 8px;
        gap: 8px;
    }
    
    .tile {
        height: 90px;
        font-size: 2em;
        width: 65px;
    }
    
    #game-board {
        grid-template-columns: repeat(4, 65px);
    }
}

@media (max-height: 600px) {
    .game-container {
        padding: 8px;
    }
    
    h1 {
        font-size: 1.3em;
        margin-bottom: 5px;
    }
    
    .score-container {
        font-size: 0.85em;
        margin-bottom: 5px;
    }
    
    .tile {
        height: 75px;
        font-size: 1.8em;
        width: 55px;
    }
    
    #game-board {
        grid-template-columns: repeat(4, 55px);
    }
    
    .game-over {
        padding: 20px;
    }
    
    .game-over h2 {
        font-size: 1.5em;
    }
    
    .game-over p {
        font-size: 1em;
    }
    
    #restart-btn {
        padding: 10px 20px;
        font-size: 1em;
    }
}

/* Very small screens */
@media (max-height: 500px) {
    .tile {
        height: 60px;
        font-size: 1.5em;
        width: 50px;
    }
    
    #game-board {
        grid-template-columns: repeat(4, 50px);
    }
}

.start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    max-width: 90%;
    text-align: center;
}

.start-screen.hidden {
    display: none;
}

.start-screen h2 {
    color: #764ba2;
    margin-bottom: 15px;
    font-size: 2em;
}

.start-screen p {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 10px;
}

#start-btn {
    background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.3em;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
    font-weight: bold;
    margin-top: 10px;
}

#start-btn:hover {
    transform: scale(1.05);
}

#start-btn:active {
    transform: scale(0.95);
}

@media (max-height: 600px) {
    .start-screen {
        padding: 25px;
    }
    
    .start-screen h2 {
        font-size: 1.5em;
        margin-bottom: 10px;
    }
    
    .start-screen p {
        font-size: 1em;
        margin-bottom: 8px;
    }
    
    #start-btn {
        padding: 12px 30px;
        font-size: 1.1em;
    }
}
