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

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

.game-container {
    background: white;
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    max-width: 100%;
    width: 100%;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 15px;
    font-size: 24px;
}

/* Start Menu Styles */
.start-menu {
    text-align: center;
    padding: 10px;
}

.start-menu h2 {
    color: #444;
    margin-bottom: 15px;
    font-size: 20px;
}

.hero-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    max-height: 50vh; /* Reduced from 60vh to ensure scrolling starts earlier */
    overflow-y: auto;
    padding: 10px;
    
    /* Critical for finger scrolling */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    touch-action: pan-y; /* Explicitly allow vertical panning */
    
    /* Scrollbar styling - thinner and less intrusive */
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f0f0f0;
}

/* Custom scrollbar for WebKit browsers */
.hero-grid::-webkit-scrollbar {
    width: 4px; /* Even thinner */
}

.hero-grid::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 10px;
}

.hero-grid::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.hero-card {
    background: #f5f5f5;
    border: 2px solid #ddd;
    border-radius: 10px;
    padding: 12px 8px; /* Slightly more padding */
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    min-height: 150px; /* Slightly taller */
    display: flex;
    flex-direction: column;
    /* Prevent cards from interfering with scroll */
    touch-action: manipulation;
    -webkit-touch-callout: none;
}

.hero-card:active {
    transform: scale(0.95);
    background: #e0e0e0;
}

.hero-card.selected {
    border-color: #4CAF50;
    background: #e8f5e9;
    box-shadow: 0 2px 10px rgba(76, 175, 80, 0.3);
}

.hero-preview {
    width: 70px;
    height: 70px;
    margin: 0 auto 8px;
    background: #fff;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    pointer-events: none; /* Prevents images from blocking touch events */
}

.hero-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.hero-preview.fallback {
    background: linear-gradient(135deg, #FF6B6B, #4ECDC4);
    color: white;
    font-size: 30px;
    font-weight: bold;
    pointer-events: none;
}

.hero-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 3px;
    font-size: 14px;
    pointer-events: none;
}

.hero-stats {
    font-size: 10px;
    color: #666;
    pointer-events: none;
}

.menu-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 10px;
}

.start-btn, .refresh-btn {
    padding: 12px 20px;
    font-size: 16px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    flex: 1;
    max-width: 200px;
    touch-action: manipulation;
}

.start-btn:active, .refresh-btn:active {
    transform: scale(0.95);
}

.start-btn {
    background: #4CAF50;
    color: white;
}

.start-btn:disabled {
    background: #cccccc;
    opacity: 0.5;
}

.refresh-btn {
    background: #FFA500;
    color: white;
}

.menu-info {
    color: #666;
    font-size: 14px;
    margin-top: 10px;
    padding: 8px;
    background: #f0f0f0;
    border-radius: 20px;
}

/* Game Screen Styles */
.game-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: bold;
    color: #555;
    background: #f5f5f5;
    padding: 8px 15px;
    border-radius: 25px;
}

#gameCanvas {
    border: 3px solid #333;
    border-radius: 15px;
    background: #87CEEB;
    width: 100%;
    height: auto;
    touch-action: none;
}

/* Мобильное сенсорное управление */
.touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    gap: 10px;
}

.d-pad {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.d-pad-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.d-pad-btn {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    border: none;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 0 #4a5aa0;
    transition: all 0.05s;
    touch-action: manipulation;
}

.d-pad-btn:active {
    transform: translateY(4px);
    box-shadow: none;
    background: #5a67d8;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    width: 90px;
    height: 60px;
    border-radius: 30px;
    border: none;
    background: #FF6B6B;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #c23b3b;
    transition: all 0.05s;
    touch-action: manipulation;
}

.action-btn:active {
    transform: translateY(4px);
    box-shadow: none;
    background: #ff5252;
}

#touchDoubleJump {
    background: #4ECDC4;
    box-shadow: 0 4px 0 #2f9c94;
    font-size: 20px;
}

.game-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 15px 0 10px;
}

#restartBtn, #menuBtn {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    border: none;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 0 #666;
    touch-action: manipulation;
}

#restartBtn {
    background: #4CAF50;
    color: white;
}

#menuBtn {
    background: #FFA500;
    color: white;
}

#restartBtn:active, #menuBtn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.config-status {
    margin-top: 8px;
    text-align: center;
    font-size: 12px;
    color: #888;
    padding: 5px;
    background: #f9f9f9;
    border-radius: 20px;
}

/* Адаптация для очень маленьких экранов */
@media (max-width: 400px) {
    .d-pad-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .action-btn {
        width: 70px;
        height: 50px;
        font-size: 14px;
    }
    
    .hero-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Game Complete Screen */
.game-complete-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

.complete-content {
    background: white;
    border-radius: 30px;
    padding: 30px 20px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.complete-title {
    font-size: 32px;
    color: #4CAF50;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.1);
}

.hero-complete-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 25px;
    padding: 15px;
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
    border-radius: 20px;
}

.hero-complete-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 10px;
    border: 4px solid #4CAF50;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hero-complete-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.hero-complete-name {
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

.stats-container {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 25px;
    color: white;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    font-size: 18px;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    font-weight: normal;
    opacity: 0.9;
}

.stat-value {
    font-weight: bold;
    font-size: 24px;
}

.images-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.image-box {
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.result-image {
    width: 100%;
    max-width: 150px;
    height: auto;
    border-radius: 15px;
    box-shadow: 0 8px 15px rgba(0,0,0,0.2);
    background: #f5f5f5;
    padding: 10px;
    transition: transform 0.3s;
}

.result-image:hover {
    transform: scale(1.05);
}

.image-label {
    margin-top: 8px;
    color: #666;
    font-size: 14px;
}

.complete-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.complete-btn {
    padding: 15px 25px;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    max-width: 200px;
    touch-action: manipulation;
}

.complete-btn:active {
    transform: scale(0.95);
}

.play-again-btn {
    background: #4CAF50;
    color: white;
    box-shadow: 0 4px 0 #2d6a2d;
}

.menu-btn {
    background: #FFA500;
    color: white;
    box-shadow: 0 4px 0 #b37400;
}

.play-again-btn:active, .menu-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

@media (max-width: 480px) {
    .complete-title {
        font-size: 28px;
    }
    
    .stat-item {
        font-size: 16px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .complete-btn {
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .images-container {
        gap: 10px;
    }
    
    .result-image {
        max-width: 120px;
    }
}