/* Bug Ball Blitz - Stylesheet */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Safe area padding for notched phones */
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#gameContainer {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 800px;
    background: #2a2a2a;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    position: relative;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    padding: 20px 20px 60px 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 40px;
}

/* Title Screen */
#titleScreen {
    background: linear-gradient(180deg, #1a0033 0%, #2d004d 50%, #1a0033 100%);
    position: relative;
    overflow: hidden;
    justify-content: center !important;
    padding-top: 20px !important;
}

#titleScreen.active {
    justify-content: center;
}

/* Main Menu and other screens */
#mainMenu, #profileSelection, #bugSelection, #arenaSelection, 
#difficultySelection, #statsScreen, #stylesScreen {
    background: linear-gradient(180deg, #0d001a 0%, #1a0033 50%, #0d001a 100%);
    position: relative;
}

#mainMenu::before, #profileSelection::before, #bugSelection::before, 
#arenaSelection::before, #difficultySelection::before, #statsScreen::before,
#stylesScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(255, 0, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(0, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(255, 255, 0, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

#mainMenu > *, #profileSelection > *, #bugSelection > *, 
#arenaSelection > *, #difficultySelection > *, #statsScreen > *,
#stylesScreen > * {
    position: relative;
    z-index: 1;
}

/* Menu Background Canvas */
#menuBackgroundCanvas, #mainMenuBackgroundCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none; /* Don't block clicks on buttons */
    opacity: 1; /* Ensure full opacity */
}

/* Title Screen Styling */
.title-content, .menu-content {
    margin-bottom: 50px;
    text-align: center;
    position: relative;
    z-index: 10;
    pointer-events: auto; /* Ensure content is interactive */
}

.game-title {
    position: relative;
    margin-bottom: 30px;
}

.title-main {
    font-size: 84px;
    font-weight: 900;
    margin: 0;
    line-height: 1;
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, #ffff00 0%, #ff00ff 50%, #00ffff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    -webkit-text-stroke: 3px #fff;
    letter-spacing: 8px;
    animation: titlePulse 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px rgba(255, 255, 0, 0.8));
}

.title-sub {
    font-size: 56px;
    font-weight: 900;
    margin: 5px 0 0 0;
    line-height: 1;
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, #00ffff 0%, #ff00ff 50%, #ffff00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    -webkit-text-stroke: 2px #fff;
    letter-spacing: 20px;
    animation: titlePulse 2s ease-in-out infinite 0.3s;
    filter: drop-shadow(0 0 15px rgba(0, 255, 255, 0.8));
}

@keyframes titlePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.soccer-ball {
    font-size: 64px;
    position: absolute;
    top: -20px;
    right: -40px;
    animation: ballBounce 1s ease-in-out infinite;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.5));
}

@keyframes ballBounce {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-20px) rotate(180deg);
    }
}

.version-info {
    position: absolute;
    bottom: 20px;
    right: 20px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    z-index: 1;
}

/* Developer Button */
.dev-btn {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.3);
    border: 2px solid rgba(255, 0, 0, 0.6);
    color: white;
    font-size: 24px;
    cursor: pointer;
    z-index: 1;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dev-btn:hover {
    background: rgba(255, 0, 0, 0.5);
    border-color: rgba(255, 0, 0, 0.9);
    transform: scale(1.1);
}

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

.dev-icon {
    display: block;
    filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.5));
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 400px;
    z-index: 10;
    position: relative;
    pointer-events: auto; /* Ensure buttons are clickable */
    margin-bottom: 20px;
}

.menu-btn {
    padding: 20px 40px;
    font-size: 20px;
    font-weight: bold;
    background: linear-gradient(135deg, #ff00ff 0%, #00ffff 100%);
    color: white;
    border: 4px solid #ffff00;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: auto; /* Ensure individual buttons are clickable */
    box-shadow: 
        0 5px 15px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(255, 0, 255, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.6),
        0 0 30px rgba(255, 255, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    border-color: #ff00ff;
    background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
}

.menu-btn:active {
    transform: translateY(0px) scale(0.98);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.primary-btn {
    background: linear-gradient(135deg, #ffff00 0%, #ff00ff 50%, #00ffff 100%);
    border-color: #fff;
    animation: buttonPulse 2s ease-in-out infinite;
    box-shadow: 
        0 5px 15px rgba(0, 0, 0, 0.4),
        0 0 30px rgba(255, 255, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.primary-btn:hover {
    background: linear-gradient(135deg, #00ffff 0%, #ff00ff 50%, #ffff00 100%);
    animation: none;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(255, 0, 255, 0.8),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

@keyframes buttonPulse {
    0%, 100% { box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4), 0 0 15px rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5), 0 0 25px rgba(255, 215, 0, 0.5); }
}

.secondary-btn {
    background: linear-gradient(135deg, #666 0%, #444 100%);
}

.secondary-btn:hover {
    background: linear-gradient(135deg, #777 0%, #555 100%);
}

.btn-icon {
    font-size: 24px;
    animation: bounceIcon 1s ease-in-out infinite;
}

@keyframes bounceIcon {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-3px); }
}

.btn-text {
    font-size: 20px;
    letter-spacing: 1px;
}

/* Profile Screens */
#profileCreateScreen, #profileLoadScreen, #mainMenu, #statsScreen,
#bugSelectScreen, #difficultyScreen, #arenaSelectScreen {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    color: white;
    position: relative;
}

#profileCreateScreen::before, #profileLoadScreen::before, #mainMenu::before,
#statsScreen::before, #bugSelectScreen::before, #difficultyScreen::before,
#arenaSelectScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(126, 211, 33, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 215, 0, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

h2 {
    font-size: 48px;
    margin-top: 20px;
    margin-bottom: 40px;
    background: linear-gradient(90deg, #ff00ff 0%, #00ffff 50%, #ffff00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    -webkit-text-stroke: 2px rgba(255, 255, 255, 0.3);
    position: relative;
    z-index: 1;
    letter-spacing: 4px;
    font-weight: 900;
    text-transform: uppercase;
    filter: drop-shadow(0 0 20px rgba(255, 0, 255, 0.6));
    animation: headerGlow 3s ease-in-out infinite;
}

@keyframes headerGlow {
    0%, 100% {
        filter: drop-shadow(0 0 20px rgba(255, 0, 255, 0.6));
    }
    50% {
        filter: drop-shadow(0 0 30px rgba(0, 255, 255, 0.8));
    }
}

input[type="text"] {
    padding: 18px 20px;
    font-size: 20px;
    border: 3px solid #ff00ff;
    border-radius: 12px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 400px;
    background: rgba(20, 0, 40, 0.9);
    color: #fff;
    transition: all 0.3s ease;
    box-shadow: 
        inset 0 2px 5px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(255, 0, 255, 0.3);
    position: relative;
    z-index: 1;
}

input[type="text"]:focus {
    outline: none;
    border-color: #00ffff;
    background: rgba(20, 0, 40, 1);
    box-shadow: 
        0 0 30px rgba(0, 255, 255, 0.6),
        inset 0 2px 5px rgba(0, 0, 0, 0.5);
    transform: scale(1.02);
}

/* Profile List */
#profileList {
    width: 100%;
    max-width: 500px;
    margin-bottom: 20px;
}

.profile-item {
    background: #2a2a2a;
    padding: 20px;
    margin-bottom: 10px;
    border-radius: 8px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.profile-item:hover {
    border-color: #7ed321;
    transform: translateX(5px);
}

.profile-content {
    flex: 1;
    cursor: pointer;
}

.profile-name {
    font-size: 24px;
    font-weight: bold;
    color: #7ed321;
}

.profile-stats {
    font-size: 14px;
    color: #aaa;
    margin-top: 5px;
}

.delete-profile-btn {
    background: #e74c3c;
    border: 2px solid #c0392b;
    color: white;
    font-size: 20px;
    width: 45px;
    height: 45px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.delete-profile-btn:hover {
    background: #c0392b;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.6);
}

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

/* Profile Info Display */
.profile-info {
    background: #2a2a2a;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.profile-info h3 {
    color: #7ed321;
    margin-bottom: 10px;
}

/* Stats Display */
#statsDisplay {
    background: #2a2a2a;
    padding: 30px;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #444;
}

.stat-label {
    color: #aaa;
}

.stat-value {
    color: #7ed321;
    font-weight: bold;
}

/* Bug Selection Grid */
.bug-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 800px;
    margin-bottom: 20px;
}

/* Difficulty Selection */
.difficulty-subtitle {
    color: #95a5a6;
    font-size: 18px;
    margin-bottom: 30px;
}

.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 25px;
    width: 100%;
    max-width: 900px;
    margin: 0 auto 30px;
    padding: 20px;
}

.difficulty-card {
    text-align: center;
}

.difficulty-card .difficulty-btn {
    width: 100%;
    padding: 30px 20px;
    font-size: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
    border: 3px solid #3498db;
}

.difficulty-card .difficulty-btn:hover {
    transform: scale(1.08);
    border-color: #7ed321;
    box-shadow: 0 8px 20px rgba(126, 211, 33, 0.4);
}

.diff-icon {
    font-size: 48px;
    line-height: 1;
}

.diff-name {
    font-size: 24px;
    font-weight: bold;
}

.diff-description {
    color: #95a5a6;
    font-size: 14px;
    margin-top: 10px;
    line-height: 1.4;
    min-height: 40px;
}

.difficulty-btn[data-difficulty="easy"]:hover {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
}

.difficulty-btn[data-difficulty="medium"]:hover {
    background: linear-gradient(135deg, #2980b9, #3498db);
}

.difficulty-btn[data-difficulty="hard"]:hover {
    background: linear-gradient(135deg, #d35400, #e67e22);
}

.difficulty-btn[data-difficulty="pro"]:hover {
    background: linear-gradient(135deg, #8e44ad, #9b59b6);
}

.bug-card {
    background: #2a2a2a;
    padding: 20px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    text-align: center;
}

.bug-card:hover {
    border-color: #7ed321;
    transform: scale(1.05);
}

.bug-card.selected {
    border-color: #7ed321;
    background: #3a3a3a;
}

.bug-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.bug-card.locked:hover {
    border-color: transparent;
    transform: none;
}

.locked-sprite {
    filter: grayscale(100%) brightness(0.6);
}

.unlock-requirement {
    color: #888;
    font-size: 13px;
    margin: 5px 0;
    font-style: italic;
}

.bug-sprite {
    width: 80px;
    height: 80px;
    margin: 0 auto 10px;
}

.bug-name {
    font-size: 20px;
    font-weight: bold;
    color: #7ed321;
    margin-bottom: 10px;
}

.bug-stats {
    font-size: 12px;
    color: #aaa;
}

.stat-bar-container {
    margin: 5px 0;
    text-align: left;
}

.stat-bar {
    background: #444;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 3px;
}

.stat-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #7ed321 0%, #5fb304 100%);
    transition: width 0.3s ease;
}

/* Arena Selection Grid */
.arena-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 900px;
    margin-bottom: 20px;
}

.arena-card {
    background: #2a2a2a;
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    text-align: center;
    min-height: 150px;
}

.arena-card:hover {
    border-color: #7ed321;
    transform: scale(1.05);
}

.arena-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.arena-card.locked:hover {
    border-color: transparent;
    transform: none;
}

.locked-preview {
    filter: grayscale(100%) brightness(0.6);
}

.arena-unlock-requirement {
    color: #888;
    font-size: 13px;
    margin-top: 5px;
    font-style: italic;
}

.arena-preview {
    width: 100%;
    height: 100px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.arena-name {
    font-size: 18px;
    font-weight: bold;
    color: #7ed321;
}

/* Game Screen */
#gameScreen {
    padding: 0;
    background: #000;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* HUD */
.hud {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    align-items: center;
    z-index: 10;
}

.score-display {
    background: rgba(0, 0, 0, 0.8);
    padding: 15px 30px;
    border-radius: 12px;
    font-size: 36px;
    font-weight: bold;
    color: #7ed321;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.timer-display {
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 24px;
    color: white;
}

.level-info {
    position: absolute;
    top: 20px;
    left: 20px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    padding: 10px 25px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    color: #2d1a00;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    text-align: center;
    z-index: 100;
}

.level-info::before {
    content: '🏆 ';
}

.settings-btn, .pause-btn, .fullscreen-btn {
    background: rgba(0, 0, 0, 0.8);
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.settings-btn:hover, .pause-btn:hover, .fullscreen-btn:hover {
    background: rgba(126, 211, 33, 0.8);
}

.settings-btn {
    margin-right: 10px;
}

.fullscreen-btn {
    margin-left: 10px;
}

/* Achievements */
.achievement-progress {
    background: #2a2a2a;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 800px;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
}

.progress-percentage {
    color: #7ed321;
}

.progress-bar-container {
    background: #1a1a1a;
    height: 20px;
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar {
    background: linear-gradient(90deg, #7ed321, #ffd700);
    height: 100%;
    width: 0%;
    transition: width 0.5s ease;
}

.achievement-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.filter-btn {
    padding: 10px 20px;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 8px;
    color: #aaa;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.filter-btn:hover {
    border-color: #7ed321;
    color: #fff;
}

.filter-btn.active {
    background: #7ed321;
    border-color: #7ed321;
    color: #000;
    font-weight: bold;
}

.achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 800px;
    margin-bottom: 20px;
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
}

.achievement-card {
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 12px;
    padding: 15px;
    transition: all 0.3s ease;
    position: relative;
}

.achievement-card.unlocked {
    border-color: #ffd700;
    background: linear-gradient(135deg, #2a2a2a 0%, #3a3a1a 100%);
}

.achievement-card.locked {
    opacity: 0.5;
}

.achievement-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.achievement-icon {
    font-size: 36px;
    filter: grayscale(100%);
}

.achievement-card.unlocked .achievement-icon {
    filter: grayscale(0%);
    animation: achievementPulse 2s infinite;
}

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

.achievement-info {
    flex: 1;
}

.achievement-name {
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 5px;
}

.achievement-card.locked .achievement-name {
    color: #666;
}

.achievement-description {
    font-size: 13px;
    color: #aaa;
}

.achievement-card.locked .achievement-description {
    color: #555;
}

.achievement-progress-text {
    font-size: 12px;
    color: #7ed321;
    margin-top: 8px;
}

.achievement-card.locked .achievement-progress-text {
    color: #666;
}

.achievement-card.unlocked::before {
    content: "✓";
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: #ffd700;
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 200px;
    z-index: 10;
    padding-bottom: env(safe-area-inset-bottom, 0px); /* Safe area for notched phones */
}

.joystick-container {
    position: absolute;
    left: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.joystick {
    width: 100px;
    height: 100px;
    background: rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(126, 211, 33, 0.8);
    border-radius: 50%;
    position: relative;
}

.joystick-stick {
    width: 45px;
    height: 45px;
    background: rgba(126, 211, 33, 0.9);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.1s ease;
}

.action-buttons {
    position: absolute;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    display: flex;
    gap: 12px;
}

.action-btn {
    width: 70px;
    height: 70px;
    background: rgba(126, 211, 33, 0.9);
    border: 3px solid rgba(95, 179, 4, 1);
    border-radius: 50%;
    font-size: 13px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    touch-action: manipulation; /* Prevent double-tap zoom */
}

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

/* Mobile Landscape Mode - Smaller Controls */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .mobile-controls {
        height: 120px;
    }
    
    .joystick-container {
        left: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }
    
    .joystick {
        width: 80px;
        height: 80px;
    }
    
    .joystick-stick {
        width: 35px;
        height: 35px;
    }
    
    .action-buttons {
        right: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }
    
    .action-btn {
        width: 55px;
        height: 55px;
        font-size: 11px;
    }
    
    .mobile-controls-p2 .joystick-container {
        right: 120px;
        left: auto;
    }
    
    .mobile-controls-p2 .action-buttons {
        left: 15px;
        right: auto;
    }
}

/* Small Phone Portrait Mode */
@media screen and (max-width: 400px) and (orientation: portrait) {
    .joystick-container {
        left: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }
    
    .joystick {
        width: 90px;
        height: 90px;
    }
    
    .joystick-stick {
        width: 40px;
        height: 40px;
    }
    
    .action-buttons {
        right: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom, 0px));
        gap: 10px;
    }
    
    .action-btn {
        width: 65px;
        height: 65px;
        font-size: 12px;
    }
}

/* Overlay Menus */
.overlay-menu {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.overlay-menu.active {
    display: flex;
}

.menu-panel {
    background: linear-gradient(135deg, #3a3a3a 0%, #1e1e1e 100%);
    padding: 40px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.menu-panel h2 {
    margin-bottom: 20px;
}

/* Pause Menu Enhancements */
.pause-panel {
    max-width: 450px;
}

.pause-info {
    margin: 30px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    border: 2px solid rgba(126, 211, 33, 0.3);
}

.pause-score {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.score-display {
    font-size: 48px;
    font-weight: bold;
    color: #7ed321;
    text-shadow: 0 0 10px rgba(126, 211, 33, 0.8);
}

.score-separator {
    font-size: 36px;
    color: rgba(255, 255, 255, 0.5);
}

.pause-time {
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: bold;
}

.primary-btn {
    background: linear-gradient(135deg, #7ed321 0%, #5fa919 100%);
    border-color: #9ae841;
}

.primary-btn:hover {
    background: linear-gradient(135deg, #9ae841 0%, #7ed321 100%);
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.6),
        0 0 30px rgba(126, 211, 33, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.danger-btn {
    background: linear-gradient(135deg, #ff3b30 0%, #d32f2f 100%);
    border-color: #ff6b60;
}

.danger-btn:hover {
    background: linear-gradient(135deg, #ff6b60 0%, #ff3b30 100%);
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.6),
        0 0 30px rgba(255, 59, 48, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Settings Menu */
.settings-panel {
    max-width: 600px;
}

.settings-options {
    margin: 30px 0;
    text-align: left;
    max-height: 60vh;
    overflow-y: auto;
}

.setting-section {
    margin-bottom: 30px;
}

.setting-section h3 {
    color: #7ed321;
    font-size: 20px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(126, 211, 33, 0.3);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-bottom: 15px;
}

.slider-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.slider-item label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.setting-item label {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting-item label span {
    font-size: 18px;
    font-weight: bold;
    color: #fff;
}

.setting-item label small {
    font-size: 14px;
    color: #aaa;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 60px;
    height: 30px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #444;
    transition: 0.3s;
    border-radius: 30px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

/* Volume Sliders */
.volume-slider {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7ed321 0%, #5fa919 100%);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(126, 211, 33, 0.6);
}

.volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7ed321 0%, #5fa919 100%);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(126, 211, 33, 0.6);
}

.volume-value {
    color: #7ed321;
    font-weight: bold;
    font-size: 16px;
    min-width: 45px;
    text-align: right;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #7ed321;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(30px);
}

/* Quality Select */
.quality-select {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    color: #ecf0f1;
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 16px;
    font-family: 'Comic Sans MS', cursive;
    cursor: pointer;
    outline: none;
    min-width: 120px;
    transition: all 0.3s ease;
}

.quality-select:hover {
    border-color: #5dade2;
    background: linear-gradient(135deg, #3d566e 0%, #34495e 100%);
}

.quality-select:focus {
    border-color: #2ecc71;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.quality-select option {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 10px;
}

#matchStats, #towerVictoryStats {
    background: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    color: white;
}

.victory-text {
    font-size: 18px;
    color: #7ed321;
    margin-bottom: 20px;
}

/* Active state for touch controls (works on all devices when manually enabled) */
.mobile-controls.active {
    display: block !important;
}

.mobile-controls-p2.active {
    display: block !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    #gameContainer {
        border-radius: 0;
        max-width: 100%;
        max-height: 100%;
    }

    .screen {
        padding: 20px;
    }

    h2 {
        font-size: 28px;
    }

    .menu-btn {
        font-size: 18px;
        padding: 15px 25px;
    }

    .game-logo {
        max-width: 350px;
    }

    .bug-grid, .arena-grid {
        grid-template-columns: 1fr;
    }

    .hud {
        top: 10px;
        gap: 10px;
    }

    .score-display {
        font-size: 24px;
        padding: 10px 20px;
    }

    .timer-display {
        font-size: 18px;
        padding: 8px 15px;
    }

    .mobile-controls.active {
        display: block;
    }

    #localMultiplayerBtn.hidden {
        display: none;
    }
}

/* Player 2 Mobile Controls (mirrored on right side) */
.mobile-controls-p2 {
    display: none;
}

.mobile-controls-p2 .joystick-container {
    left: auto;
    right: 180px;
}

.mobile-controls-p2 .action-buttons {
    right: auto;
    left: 40px;
}

/* Celebration Cards */
.styles-subtitle {
    text-align: center;
    color: #aaa;
    font-size: 16px;
    margin: -10px 0 20px 0;
}

#celebrationGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.celebration-card {
    background: linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%);
    border: 3px solid #7ed321;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.celebration-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(126, 211, 33, 0.4);
}

.celebration-card.locked {
    border-color: #555;
    opacity: 0.6;
    cursor: not-allowed;
}

.celebration-card.locked:hover {
    transform: none;
    box-shadow: none;
}

.celebration-card.selected {
    border-color: #FFD700;
    background: linear-gradient(135deg, #3d3d0d 0%, #2a2a00 100%);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.celebration-icon {
    font-size: 60px;
    margin-bottom: 15px;
    filter: drop-shadow(0 0 10px rgba(126, 211, 33, 0.5));
}

.celebration-card.locked .celebration-icon {
    filter: grayscale(100%) brightness(0.5);
}

.celebration-card h3 {
    color: #fff;
    font-size: 22px;
    margin: 10px 0;
}

.celebration-description {
    color: #aaa;
    font-size: 14px;
    margin: 10px 0;
    min-height: 40px;
}

.unlock-condition {
    color: #7ed321;
    font-size: 13px;
    font-weight: bold;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #333;
}

.celebration-card.locked .unlock-condition {
    color: #ff6b6b;
}

.celebration-card.selected::before {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    background: #FFD700;
    color: #000;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.mobile-controls-p2.active {
    display: block;
}

/* Hidden class */
.hidden {
    display: none !important;
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ===== MOBILE OPTIMIZATION ===== */

/* Prevent zoom on double-tap */
* {
    touch-action: manipulation;
}

/* Ensure full viewport usage on mobile */
html {
    width: 100%;
    height: 100%;
    position: fixed;
    overflow: hidden;
}

body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Smooth orientation change transitions */
#gameContainer {
    transition: none; /* Disable transitions during resize */
}

/* Mobile-specific adjustments */
@media screen and (max-width: 768px) {
    body {
        padding: 0; /* Remove padding on small screens */
    }
    
    #gameContainer {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    
    .screen {
        padding: 15px 15px 40px 15px;
        padding-top: max(15px, env(safe-area-inset-top, 0px));
        padding-bottom: max(40px, env(safe-area-inset-bottom, 0px));
        padding-left: max(15px, env(safe-area-inset-left, 0px));
        padding-right: max(15px, env(safe-area-inset-right, 0px));
    }
    
    .screen.active {
        padding-top: max(25px, env(safe-area-inset-top, 0px));
    }
    
    h2 {
        font-size: 36px;
        margin-top: 10px;
        margin-bottom: 25px;
    }
    
    .game-title {
        margin-bottom: 30px;
    }
    
    .title-main {
        font-size: 48px;
    }
    
    .title-sub {
        font-size: 28px;
    }
    
    .menu-btn {
        width: 100%;
        max-width: 300px;
        padding: 15px 25px;
        font-size: 16px;
    }
    
    .hud {
        padding: 10px;
        gap: 10px;
    }
    
    .score-display, .timer-display {
        font-size: 20px;
        padding: 8px 15px;
    }
    
    .profile-item {
        padding: 15px;
        flex-direction: column;
        align-items: stretch;
    }
    
    .profile-content {
        margin-bottom: 10px;
    }
    
    .profile-name {
        font-size: 20px;
    }
    
    .profile-stats {
        font-size: 12px;
    }
    
    .delete-profile-btn {
        width: 100%;
        height: 40px;
        font-size: 18px;
    }
}

/* Landscape mobile optimization */
@media screen and (max-height: 600px) and (orientation: landscape) {
    .screen {
        padding: 10px 10px 30px 10px;
    }
    
    .screen.active {
        padding-top: 15px;
    }
    
    h2 {
        font-size: 28px;
        margin-top: 5px;
        margin-bottom: 15px;
    }
    
    .game-title {
        margin-bottom: 15px;
    }
    
    .title-main {
        font-size: 36px;
    }
    
    .title-sub {
        font-size: 20px;
    }
    
    .menu-buttons {
        gap: 10px;
    }
    
    .menu-btn {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    .hud {
        padding: 5px;
        gap: 5px;
    }
    
    .score-display, .timer-display {
        font-size: 16px;
        padding: 5px 10px;
    }
}

/* Ultra-small screens */
@media screen and (max-width: 360px) {
    .title-main {
        font-size: 40px;
    }
    
    .title-sub {
        font-size: 24px;
    }
    
    .menu-btn {
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .btn-icon {
        font-size: 20px;
    }
}

/* Arena Preview Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    margin: 5% auto;
    padding: 30px;
    border: 3px solid #3498db;
    border-radius: 15px;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.3s ease;
}

.arena-preview-content {
    text-align: center;
}

.arena-preview-content h2 {
    color: #3498db;
    margin-bottom: 20px;
    font-size: 32px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#arenaPreviewCanvas {
    width: 100%;
    max-width: 600px;
    height: auto;
    border: 3px solid #2c3e50;
    border-radius: 10px;
    margin: 20px auto;
    display: block;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.arena-description {
    color: #ecf0f1;
    font-size: 18px;
    line-height: 1.6;
    margin: 20px 0;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.close-modal {
    color: #ecf0f1;
    float: right;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    line-height: 20px;
    margin-top: -10px;
}

.close-modal:hover,
.close-modal:focus {
    color: #e74c3c;
    transform: scale(1.2);
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

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

@media screen and (max-width: 768px) {
    .modal-content {
        width: 95%;
        padding: 20px;
        margin: 10% auto;
    }
    
    .arena-preview-content h2 {
        font-size: 24px;
    }
    
    .arena-description {
        font-size: 16px;
    }
}

/* Prevent text selection on mobile */
.mobile-controls, .mobile-controls * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Optimize buttons for touch */
button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Ensure canvas scales properly */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}
