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

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    background-attachment: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #fff;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(74, 86, 226, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(138, 73, 244, 0.2) 0%, transparent 50%);
    pointer-events: none;
    animation: backgroundPulse 10s ease-in-out infinite;
}

@keyframes backgroundPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

.game-container {
    position: relative;
    width: 600px;
    margin: 20px;
    z-index: 1;
    filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.5));
}

/* HUD Styles */
.hud {
    display: flex;
    justify-content: space-around;
    background: linear-gradient(135deg, rgba(30, 30, 60, 0.95) 0%, rgba(20, 20, 40, 0.95) 100%);
    padding: 20px;
    border-radius: 15px 15px 0 0;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(138, 73, 244, 0.3);
    border-bottom: none;
    box-shadow: 0 -5px 30px rgba(138, 73, 244, 0.2);
}

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

.hud-label {
    font-size: 11px;
    color: #8a49f4;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
}

.hud-value {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, #8a49f4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-top: 8px;
    text-shadow: 0 0 20px rgba(138, 73, 244, 0.5);
}

/* Canvas Styles */
#gameCanvas {
    display: block;
    background: linear-gradient(135deg, #1a1a3e 0%, #0f0f2e 100%);
    border: 2px solid rgba(138, 73, 244, 0.5);
    border-top: none;
    border-radius: 0 0 15px 15px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.6),
        inset 0 0 100px rgba(138, 73, 244, 0.1),
        0 0 50px rgba(138, 73, 244, 0.3);
    image-rendering: crisp-edges;
}

/* Menu Styles */
.menu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(30, 30, 60, 0.98) 0%, rgba(20, 20, 40, 0.98) 100%);
    padding: 45px;
    border-radius: 25px;
    text-align: center;
    min-width: 420px;
    box-shadow: 
        0 25px 80px rgba(0, 0, 0, 0.9),
        0 0 50px rgba(138, 73, 244, 0.4),
        inset 0 0 60px rgba(138, 73, 244, 0.1);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(138, 73, 244, 0.4);
    z-index: 10;
}

.menu h1 {
    margin-bottom: 25px;
    font-size: 3em;
    font-weight: 900;
    text-shadow: 
        0 0 30px rgba(138, 73, 244, 0.8),
        0 5px 15px rgba(0, 0, 0, 0.5);
    letter-spacing: -1px;
}

.menu h2 {
    margin-bottom: 20px;
    font-size: 1.4em;
    color: #b8b8ff;
    font-weight: 600;
}

.game-title {
    background: linear-gradient(135deg, #00f5ff 0%, #8a49f4 50%, #ff00ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(138, 73, 244, 0.8)); }
    50% { filter: drop-shadow(0 0 40px rgba(138, 73, 244, 1)); }
}

.game-subtitle {
    font-size: 1.3em;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 35px;
    font-weight: 700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

/* Button Styles */
.btn {
    padding: 14px 35px;
    margin: 10px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    position: relative;
    overflow: hidden;
}

.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;
}

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

.btn-primary {
    background: linear-gradient(135deg, #8a49f4 0%, #4a56e2 100%);
    color: white;
    box-shadow: 
        0 5px 20px rgba(138, 73, 244, 0.5),
        0 0 20px rgba(138, 73, 244, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 8px 30px rgba(138, 73, 244, 0.7),
        0 0 40px rgba(138, 73, 244, 0.5);
}

.btn-primary:active {
    transform: translateY(-1px);
}

.btn-secondary {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    color: white;
    border: 2px solid rgba(138, 73, 244, 0.5);
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.3);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.3) 0%, rgba(74, 86, 226, 0.3) 100%);
    border-color: rgba(138, 73, 244, 0.8);
    transform: translateY(-3px);
    box-shadow: 0 5px 25px rgba(138, 73, 244, 0.4);
}

.btn-difficulty {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(138, 73, 244, 0.1) 100%);
    color: white;
    border: 2px solid rgba(138, 73, 244, 0.4);
    padding: 12px 25px;
    margin: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.btn-difficulty:hover {
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.3) 0%, rgba(74, 86, 226, 0.2) 100%);
    border-color: rgba(138, 73, 244, 0.7);
    box-shadow: 0 5px 20px rgba(138, 73, 244, 0.4);
}

.btn-difficulty.active {
    background: linear-gradient(135deg, #00f5ff 0%, #8a49f4 100%);
    border-color: #00f5ff;
    box-shadow: 
        0 5px 25px rgba(0, 245, 255, 0.5),
        0 0 30px rgba(138, 73, 244, 0.6);
    color: #fff;
}

.btn-toggle {
    background: #4caf50;
    color: white;
    min-width: 80px;
}

.btn-toggle.off {
    background: #f44336;
}

/* Difficulty Selection */
.difficulty-selection {
    margin: 30px 0;
}

.button-group {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

/* Controls Guide */
.controls-guide {
    margin-top: 35px;
    padding: 25px;
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.15) 0%, rgba(74, 86, 226, 0.1) 100%);
    border-radius: 15px;
    font-size: 14px;
    border: 1px solid rgba(138, 73, 244, 0.3);
    box-shadow: inset 0 0 30px rgba(138, 73, 244, 0.1);
}

.controls-guide p {
    margin: 8px 0;
    color: #d0d0ff;
}

.controls-guide strong {
    color: #00f5ff;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(0, 245, 255, 0.5);
}

.swipe-hint {
    margin-top: 15px;
    padding: 10px;
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.2) 0%, rgba(0, 245, 255, 0.2) 100%);
    border-radius: 8px;
    font-weight: 700;
    color: #00f5ff;
    animation: swipeHintPulse 2s ease-in-out infinite;
}

@keyframes swipeHintPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(0, 245, 255, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(0, 245, 255, 0.6);
    }
}

/* Game Over Stats */
.game-over-stats {
    margin: 25px 0;
    padding: 25px;
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.15) 0%, rgba(74, 86, 226, 0.1) 100%);
    border-radius: 15px;
    border: 1px solid rgba(138, 73, 244, 0.3);
    box-shadow: inset 0 0 30px rgba(138, 73, 244, 0.1);
}

.final-score, .final-level {
    font-size: 1.6em;
    margin: 12px 0;
    font-weight: 600;
}

.final-score span, .final-level span {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

/* New High Score */
.new-high-score {
    margin: 25px 0;
    padding: 25px;
    background: linear-gradient(135deg, #00f5ff 0%, #8a49f4 50%, #ff00ff 100%);
    border-radius: 15px;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 
        0 0 40px rgba(138, 73, 244, 0.6),
        inset 0 0 30px rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.high-score-message {
    font-size: 1.7em;
    font-weight: 900;
    margin-bottom: 18px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    color: #fff;
}

.name-input {
    padding: 12px;
    font-size: 28px;
    width: 140px;
    text-align: center;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    margin: 12px;
    text-transform: uppercase;
    font-weight: 900;
    background: rgba(255, 255, 255, 0.95);
    color: #8a49f4;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.name-input:focus {
    outline: none;
    border-color: #fff;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8);
    transform: scale(1.05);
}

/* High Scores List */
.high-scores-list {
    margin: 35px 0;
    padding: 25px;
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.1) 0%, rgba(74, 86, 226, 0.05) 100%);
    border-radius: 15px;
    border: 1px solid rgba(138, 73, 244, 0.3);
    box-shadow: inset 0 0 30px rgba(138, 73, 244, 0.1);
}

.score-entry {
    display: flex;
    justify-content: space-between;
    padding: 18px 20px;
    margin: 12px 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(138, 73, 244, 0.1) 100%);
    border-radius: 12px;
    font-size: 1.3em;
    border: 1px solid rgba(138, 73, 244, 0.2);
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.score-entry:hover {
    transform: translateX(5px);
    box-shadow: 0 5px 20px rgba(138, 73, 244, 0.4);
    border-color: rgba(138, 73, 244, 0.5);
}

.score-entry.top {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #1a1a2e;
    font-weight: 900;
    box-shadow: 
        0 5px 25px rgba(255, 215, 0, 0.4),
        0 0 30px rgba(255, 215, 0, 0.3);
    border: 2px solid #fff;
}

.score-entry.top:hover {
    transform: translateX(5px) scale(1.02);
}

.score-rank {
    width: 50px;
    font-weight: 800;
}

.score-name {
    flex: 1;
    text-align: left;
    padding-left: 25px;
    font-weight: 700;
}

.score-value {
    font-weight: 800;
}

/* Settings */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    margin: 18px 0;
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.15) 0%, rgba(74, 86, 226, 0.1) 100%);
    border-radius: 12px;
    border: 1px solid rgba(138, 73, 244, 0.3);
    transition: all 0.3s ease;
}

.setting-item:hover {
    background: linear-gradient(135deg, rgba(138, 73, 244, 0.25) 0%, rgba(74, 86, 226, 0.15) 100%);
    box-shadow: 0 5px 20px rgba(138, 73, 244, 0.3);
}

.setting-item label {
    font-size: 1.2em;
    font-weight: 600;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 
            0 0 40px rgba(138, 73, 244, 0.6),
            inset 0 0 30px rgba(255, 255, 255, 0.2);
    }
    50% {
        transform: scale(1.03);
        box-shadow: 
            0 0 60px rgba(138, 73, 244, 0.9),
            inset 0 0 40px rgba(255, 255, 255, 0.3);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

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

.menu {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn {
    animation: slideIn 0.3s ease-out backwards;
}

.btn:nth-child(1) { animation-delay: 0.05s; }
.btn:nth-child(2) { animation-delay: 0.1s; }
.btn:nth-child(3) { animation-delay: 0.15s; }
.btn:nth-child(4) { animation-delay: 0.2s; }

/* Footer */
.game-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    z-index: 0;
}

.game-footer p {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

/* Leaderboard Filters */
.leaderboard-filters {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(138, 73, 244, 0.3);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 600;
}

.filter-btn:hover {
    background: rgba(138, 73, 244, 0.2);
    border-color: rgba(138, 73, 244, 0.6);
}

.filter-btn.active {
    background: linear-gradient(135deg, #8a49f4 0%, #4a56e2 100%);
    border-color: #8a49f4;
    box-shadow: 0 3px 15px rgba(138, 73, 244, 0.5);
}

/* Difficulty Badges */
.difficulty-badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.difficulty-badge.easy {
    background: #4caf50;
    color: #fff;
}

.difficulty-badge.medium {
    background: #ff9800;
    color: #fff;
}

.difficulty-badge.hard {
    background: #f44336;
    color: #fff;
}

.score-level {
    font-size: 0.9em;
    color: #aaa;
    margin: 0 5px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #aaa;
    font-size: 1.2em;
}

.rank-display {
    font-size: 1.2em;
    color: #ffd700;
    margin: 10px 0;
    font-weight: 700;
}

.name-input {
    font-size: 18px;
    width: 200px;
}

/* Swipe Indicator */
.swipe-indicator {
    position: fixed;
    font-size: 40px;
    pointer-events: none;
    z-index: 9999;
    animation: swipeIndicatorFade 0.5s ease-out forwards;
    text-shadow: 0 0 20px rgba(138, 73, 244, 0.8);
    transform: translate(-50%, -50%);
}

@keyframes swipeIndicatorFade {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.5);
    }
}

/* Mobile Touch Controls */
.mobile-controls {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: none; /* Hidden by default, swipe is primary */
    gap: 40px;
    align-items: center;
}

.control-dpad {
    display: grid;
    grid-template-rows: auto auto auto;
    gap: 5px;
}

.control-middle {
    display: grid;
    grid-template-columns: auto auto auto;
    gap: 5px;
}

.control-center {
    width: 50px;
    height: 50px;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    border: 2px solid rgba(138, 73, 244, 0.6);
    background: linear-gradient(135deg, rgba(30, 30, 60, 0.95) 0%, rgba(20, 20, 40, 0.95) 100%);
    backdrop-filter: blur(10px);
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active,
.control-btn.pressed {
    transform: scale(0.95);
    background: linear-gradient(135deg, #8a49f4 0%, #4a56e2 100%);
    box-shadow: 0 2px 8px rgba(138, 73, 244, 0.6);
}

.control-pause {
    width: 60px;
    height: 60px;
    border-radius: 50%;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding-bottom: 60px;
    }
    
    .game-container {
        width: 100%;
        max-width: 100vw;
        margin: 10px 0;
        padding: 0;
    }
    
    .hud {
        border-radius: 0;
        padding: 15px 10px;
    }
    
    .hud-label {
        font-size: 10px;
    }
    
    .hud-value {
        font-size: 20px;
    }
    
    #gameCanvas {
        width: 100%;
        max-width: 100vw;
        height: auto;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .menu {
        min-width: 90%;
        max-width: 400px;
        padding: 30px 20px;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .menu h1 {
        font-size: 2em;
    }
    
    .btn {
        padding: 12px 25px;
        font-size: 14px;
        margin: 8px;
    }
    
    .high-scores-list {
        max-height: 50vh;
        overflow-y: auto;
    }
    
    .score-entry {
        font-size: 1em;
        padding: 12px 15px;
        flex-wrap: wrap;
    }
    
    .name-input {
        width: 100%;
        max-width: 250px;
        font-size: 16px;
    }
    
    .game-footer {
        font-size: 12px;
        padding: 10px;
    }
    
    .controls-guide {
        font-size: 12px;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .menu {
        padding: 20px 15px;
    }
    
    .menu h1 {
        font-size: 1.8em;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .control-center {
        width: 45px;
        height: 45px;
    }
    
    .control-pause {
        width: 55px;
        height: 55px;
    }
    
    .mobile-controls {
        gap: 20px;
        bottom: 70px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .menu {
        max-height: 90vh;
        padding: 15px;
    }
    
    .menu h1 {
        font-size: 1.5em;
        margin-bottom: 15px;
    }
    
    .high-scores-list {
        max-height: 40vh;
    }
    
    .mobile-controls {
        bottom: 60px;
        scale: 0.9;
    }
}

/* Desktop optimizations */
@media (min-width: 769px) {
    .game-container {
        margin: 40px auto;
    }
    
    .mobile-controls {
        display: none !important;
    }
}

