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

:root {
    --bg-dark: #1a1a2e;
    --bg-medium: #16213e;
    --accent: #e94560;
    --accent-light: #ff6b6b;
    --text-light: #eee;
    --text-muted: #aaa;
    --success: #4ade80;
    --warning: #fbbf24;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-medium) 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    color: var(--text-light);
    /* iOS safe area support */
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
}

#game-container {
    width: 100%;
    max-width: 800px;
    height: 100vh;
    height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top));
    max-height: 900px;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark); /* Fallback for any gaps */
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.screen.hidden {
    display: none;
}

/* Start Screen */
#start-screen h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#start-screen .subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.instructions {
    text-align: center;
    max-width: 300px;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.high-score {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

#high-score-display {
    color: var(--warning);
    font-weight: bold;
}

/* Buttons */
.btn {
    padding: 15px 40px;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn.primary {
    background: var(--accent);
    color: white;
}

.btn.primary:hover {
    background: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

.btn.secondary {
    background: transparent;
    color: var(--text-light);
    border: 2px solid var(--text-muted);
    margin-top: 10px;
}

.btn.secondary:hover {
    border-color: var(--text-light);
    background: rgba(255, 255, 255, 0.1);
}

/* Game Screen */
#game-screen {
    padding: 0;
    justify-content: flex-start;
}

#hud {
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding: 15px 10px;
    background: rgba(0, 0, 0, 0.3);
    z-index: 10;
}

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

.hud-item .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.hud-item span:last-child {
    font-size: 1.3rem;
    font-weight: bold;
}

#level-display {
    color: var(--accent-light);
}

#score-display {
    color: var(--warning);
}

#game-canvas {
    flex: 1;
    width: 100%;
    touch-action: none;
}

#level-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 20px 40px;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    animation: pulse 0.5s ease-in-out;
    z-index: 20;
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.1); }
}

/* Game Over Screen */
#gameover-screen h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.stats {
    text-align: center;
    margin-bottom: 2rem;
}

.stats p {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.stats span {
    color: var(--warning);
    font-weight: bold;
}

#new-high-score {
    color: var(--success);
    font-size: 1.3rem;
    font-weight: bold;
    margin-bottom: 1rem;
    animation: pulse 1s ease-in-out infinite;
}

/* Responsive */
@media (max-width: 600px) {
    #start-screen h1 {
        font-size: 2rem;
    }

    .btn {
        padding: 12px 30px;
        font-size: 1rem;
    }

    #hud {
        padding: 10px 5px;
    }

    .hud-item span:last-child {
        font-size: 1.1rem;
    }
}

@media (max-height: 700px) {
    #start-screen h1 {
        font-size: 1.8rem;
    }

    .instructions {
        margin-bottom: 1rem;
    }

    #level-indicator {
        padding: 15px 30px;
        font-size: 1.2rem;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.screen:not(.hidden) {
    animation: fadeIn 0.3s ease;
}
