/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #1a1a2e;
    color: #ffffff;
    
    /* Prevent pull-to-refresh */
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
    
    /* Disable text selection */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    
    /* Disable tap highlight */
    -webkit-tap-highlight-color: transparent;
    
    /* Prevent zoom on double-tap */
    touch-action: manipulation;
    
    /* Fixed positioning (no scrolling) */
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    
    /* Handle notched devices (iPhone X+) */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Game Container */
#game-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Canvas Container */
#canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* UI Overlay */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    max-height: 150px; /* Constrain to top UI area only */
    z-index: 100;
    pointer-events: none;
}

#ui-overlay * {
    pointer-events: auto;
}

/* Blocked Feedback Overlay */
#blocked-feedback-overlay {
    position: fixed;
    top: 70px; /* Start below top bar UI to avoid covering top arrows */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 75; /* Above canvas (0), below UI overlay (100) */
    pointer-events: none;
    transition: box-shadow 0.1s ease-out;
}

/* Top Bar */
#top-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(26, 26, 46, 0.95) 0%, rgba(26, 26, 46, 0) 100%);
    pointer-events: none; /* Don't block clicks on canvas below */
}

#seed-display {
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    backdrop-filter: blur(10px);
}

#seed-display.hidden {
    display: none;
}

#seed-value {
    font-family: 'Courier New', monospace;
    color: #ffcc00;
}

#seed-value:hover {
    text-decoration: underline;
}

#level-counter {
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 700;
    backdrop-filter: blur(10px);
}

#lives-display {
    display: flex;
    gap: 5px;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
}

#lives-display.shake {
    animation: heartShake 0.4s ease;
}

@keyframes heartShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.heart {
    font-size: 20px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.heart.filled {
    filter: drop-shadow(0 0 5px rgba(255, 100, 100, 0.8));
}

.heart.empty {
    opacity: 0.3;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #16213e;
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    font-size: 28px;
    margin-bottom: 20px;
}

.coins-earned {
    font-size: 36px;
    font-weight: 700;
    color: #ffd700;
    margin: 20px 0;
    animation: coinPop 0.5s ease-out;
}

@keyframes coinPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.life-lost {
    font-size: 48px;
    margin: 20px 0;
    animation: lifeLost 0.5s ease-out;
}

@keyframes lifeLost {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.3) rotate(-10deg); opacity: 0.8; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.stats {
    margin: 20px 0;
    font-size: 16px;
}

.stats p {
    margin: 5px 0;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.regen-timer {
    margin-top: 15px;
    font-size: 14px;
    color: #aaa;
}

/* Buttons */
.btn {
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    font-family: inherit;
}

.btn:active {
    transform: scale(0.97);
}

.btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn.primary:hover {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn.secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}

.btn.secondary:hover {
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.6);
}

.btn.tertiary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn.tertiary:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Ad Container */
#ad-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f0f1e;
    z-index: 50;
}

/* Mobile Adjustments */
@media (min-width: 768px) {
    #ad-container {
        height: 90px;
    }
    
    .modal-content {
        max-width: 500px;
    }
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 24px;
}

/* Home Screen */
#home-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

#home-screen.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

#home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    flex: 1;
    justify-content: center;
    padding-bottom: 60px; /* Account for fixed bottom nav */
}

#home-logo {
    display: flex;
    align-items: baseline;
}

.logo-arrow {
    font-size: 64px;
    color: #667eea;
    line-height: 1;
}

.logo-text {
    font-size: 56px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -1px;
}

#home-level-subtitle {
    font-size: 20px;
    font-weight: 600;
    color: #667eea;
}

#home-difficulty {
    font-size: 16px;
    font-weight: 500;
    color: #00e5ff;
    margin-top: 4px;
    margin-bottom: 8px;
}

.play-btn {
    width: 60%;
    min-width: 200px;
    max-width: 320px;
    font-size: 20px;
    padding: 18px 30px;
    border-radius: 16px;
    margin-top: 16px;
}

/* Bottom Nav */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 501; /* Above home-screen (500) */
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-weight: 500;
}

.nav-item.active {
    color: #ffffff;
    background: rgba(102, 126, 234, 0.2);
    margin: 0 4px;
}

.nav-item.locked {
    opacity: 0.4;
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* Settings Panel */
#settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px; /* Above bottom nav */
    z-index: 499;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    overflow-y: auto;
}

#settings-panel.hidden {
    display: none;
}

#settings-panel h2 {
    font-size: 24px;
    margin-bottom: 30px;
    color: #ffffff;
}

.settings-section {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-section h3 {
    font-size: 16px;
    color: #a0a0c0;
    margin-bottom: 4px;
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-field label {
    font-size: 13px;
    color: #8080a0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-field input,
.settings-field select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 10px 12px;
    color: #ffffff;
    font-size: 16px;
    outline: none;
    -webkit-appearance: none;
}

.settings-field input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.settings-field input:focus,
.settings-field select:focus {
    border-color: rgba(102, 126, 234, 0.6);
}

.settings-field select option {
    background: #1a1a2e;
    color: #ffffff;
}

/* Tutorial Overlay */
#tutorial-overlay {
    position: fixed;
    bottom: 15%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 200;
    pointer-events: none;
}

#tutorial-overlay.hidden {
    display: none;
}

.tutorial-pill {
    background: rgba(255, 255, 255, 0.1);
    color: #667eea;
    padding: 12px 32px;
    border-radius: 24px;
    font-size: 18px;
    font-weight: 600;
    backdrop-filter: blur(10px);
}

/* Hidden states for game UI */
#canvas-container.hidden,
#ui-overlay.hidden {
    display: none;
}

/* Disable iOS bounce */
#game-container {
    -webkit-overflow-scrolling: touch;
}
