/* Reset en basis styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(45deg, #0a0000 0%, #1a0000 50%, #0f0f23 100%);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    color: #ff6b6b;
    position: relative;
}

/* Stranger Things style glitch effect */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255, 107, 107, 0.03) 2px,
            rgba(255, 107, 107, 0.03) 4px
        );
    pointer-events: none;
    z-index: 1000;
}

.game-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(255, 0, 0, 0.1), transparent 70%);
}

#gameCanvas {
    background: linear-gradient(180deg, #1a0000 0%, #0d1117 50%, #000000 100%);
    border: 2px solid #ff6b6b;
    border-radius: 5px;
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
    box-shadow: 
        0 0 20px rgba(255, 107, 107, 0.5),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
}

/* HUD Styling */
.hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    font-size: 0.9em;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    color: #ff6b6b;
}

.health-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.health-label {
    font-size: 0.8em;
    color: #ff3333;
}

.health-fill {
    width: 100px;
    height: 8px;
    background: #330000;
    border: 1px solid #ff6b6b;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.health-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff3333 0%, #ff6b6b 50%, #ff9999 100%);
    transition: width 0.3s ease;
    border-radius: 3px;
}

.ammo, .score, .level {
    font-size: 0.9em;
    color: #ff6b6b;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Screen Styling - Stranger Things Theme */
.screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: 
        linear-gradient(135deg, 
            rgba(26, 0, 0, 0.95) 0%, 
            rgba(13, 17, 23, 0.95) 50%, 
            rgba(0, 0, 0, 0.95) 100%);
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 
        0 0 30px rgba(255, 107, 107, 0.6),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
    z-index: 1000;
    backdrop-filter: blur(10px);
    border: 2px solid #ff6b6b;
    min-width: 320px;
}

.screen h1 {
    font-size: 2.8em;
    color: #ff3333;
    margin-bottom: 10px;
    text-shadow: 
        0 0 10px #ff3333,
        2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
    animation: glow 2s ease-in-out infinite alternate;
}

.screen h2 {
    font-size: 2.2em;
    color: #ff6b6b;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 2px;
}

@keyframes glow {
    from {
        text-shadow: 
            0 0 10px #ff3333,
            2px 2px 4px rgba(0, 0, 0, 0.8);
    }
    to {
        text-shadow: 
            0 0 20px #ff3333,
            0 0 30px #ff6b6b,
            2px 2px 4px rgba(0, 0, 0, 0.8);
    }
}

.screen p {
    font-size: 1.1em;
    margin: 10px 0;
    color: #cccccc;
    line-height: 1.4;
}

.controls-info {
    background: rgba(0, 0, 0, 0.6);
    padding: 15px;
    border-radius: 5px;
    margin: 20px 0;
    border: 1px solid #ff6b6b;
}

.controls-info p {
    font-size: 0.9em;
    margin: 5px 0;
    color: #ff9999;
}

button {
    background: linear-gradient(45deg, #ff3333, #ff6b6b);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    border-radius: 5px;
    cursor: pointer;
    margin: 10px;
    box-shadow: 
        0 4px 15px rgba(255, 51, 51, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 150px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(255, 51, 51, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    background: linear-gradient(45deg, #ff1a1a, #ff5555);
}

button:active {
    transform: translateY(1px);
    box-shadow: 
        0 2px 10px rgba(255, 51, 51, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Name input styling */
.name-input-section {
    margin: 20px 0;
    text-align: center;
}

.name-input-section label {
    display: block;
    margin-bottom: 10px;
    color: #ff9999;
    font-size: 1.1em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#playerName {
    background: linear-gradient(45deg, #2a0000, #1a0000);
    border: 2px solid #ff6b6b;
    color: #ff9999;
    padding: 12px 20px;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
    border-radius: 5px;
    width: 250px;
    max-width: 90%;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
}

#playerName:focus {
    border-color: #ff3333;
    box-shadow: 0 0 15px rgba(255, 51, 51, 0.5);
    background: linear-gradient(45deg, #3a0000, #2a0000);
}

#playerName::placeholder {
    color: #ff6666;
    opacity: 0.7;
}

.hidden {
    display: none !important;
}

.high-score {
    margin-top: 20px;
    font-size: 1em;
    color: #ff9999;
    padding: 10px;
    background: rgba(255, 51, 51, 0.1);
    border-radius: 5px;
    border: 1px solid #ff6b6b;
}

/* Mobile Controls */
.mobile-controls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 200;
}

.move-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 5px;
    width: 120px;
    height: 120px;
}

.move-controls #upBtn {
    grid-column: 1 / 3;
}

.move-controls #downBtn {
    grid-column: 1 / 3;
}

.action-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-btn {
    background: rgba(255, 51, 51, 0.8);
    border: 2px solid #ff6b6b;
    color: white;
    padding: 10px;
    border-radius: 50%;
    font-size: 1em;
    font-weight: bold;
    touch-action: manipulation;
    user-select: none;
    min-width: 45px;
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn {
    border-radius: 10px;
    min-width: 80px;
    font-size: 0.9em;
    letter-spacing: 1px;
}

.control-btn:active {
    background: rgba(255, 51, 51, 1);
    transform: scale(0.95);
}

/* Responsive Design */
@media (max-width: 768px) {
    .screen {
        width: 90%;
        max-width: 400px;
        padding: 25px 20px;
    }
    
    .screen h1 {
        font-size: 2.2em;
    }
    
    .screen h2 {
        font-size: 1.8em;
    }
    
    .screen p {
        font-size: 1em;
    }
    
    button {
        font-size: 1.1em;
        padding: 12px 25px;
        min-width: 130px;
    }
    
    .hud {
        font-size: 0.8em;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .health-fill {
        width: 80px;
        height: 6px;
    }
}

@media (max-width: 480px) {
    .screen h1 {
        font-size: 1.8em;
    }
    
    .screen p {
        font-size: 0.9em;
    }
    
    button {
        font-size: 1em;
        padding: 10px 20px;
        min-width: 120px;
    }
    
    .hud {
        font-size: 0.7em;
    }
}

/* Hide mobile controls on desktop */
@media (min-width: 769px) {
    .mobile-controls {
        display: none;
    }
}

/* Landscape mode optimizations */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .screen {
        max-height: 90vh;
        overflow-y: auto;
        padding: 20px 15px;
    }
    
    .screen h1 {
        font-size: 1.8em;
        margin-bottom: 8px;
    }
    
    .screen h2 {
        font-size: 1.5em;
        margin-bottom: 15px;
    }
    
    .controls-info {
        padding: 10px;
        margin: 15px 0;
    }
    
    button {
        font-size: 0.9em;
        padding: 8px 16px;
        margin: 5px;
    }
}

/* Glitch animation for dramatic effect */
.screen h1 {
    animation: glow 2s ease-in-out infinite alternate, textGlitch 5s infinite;
}

@keyframes textGlitch {
    0%, 90%, 100% {
        transform: translateX(0);
    }
    92% {
        transform: translateX(-2px);
    }
    94% {
        transform: translateX(2px);
    }
    96% {
        transform: translateX(-1px);
    }
    98% {
        transform: translateX(1px);
    }
}

/* Leaderboard styling */
.leaderboard-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    gap: 10px;
}

.tab-button {
    padding: 8px 16px;
    background: transparent;
    color: #ff6b6b;
    border: 1px solid #ff6b6b;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.tab-button.active,
.tab-button:hover {
    background: #ff6b6b;
    color: #1a0000;
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

.leaderboard-content {
    max-height: 300px;
    overflow-y: auto;
    margin: 20px 0;
    padding: 10px;
    border: 1px solid #ff6b6b;
    background: rgba(26, 0, 0, 0.3);
    
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #ff6b6b #1a0000;
}

.leaderboard-content::-webkit-scrollbar {
    width: 8px;
}

.leaderboard-content::-webkit-scrollbar-track {
    background: #1a0000;
}

.leaderboard-content::-webkit-scrollbar-thumb {
    background: #ff6b6b;
    border-radius: 4px;
}

.score-entry {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin: 2px 0;
    background: rgba(255, 107, 107, 0.1);
    border-left: 3px solid #ff6b6b;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    transition: background 0.3s ease;
    gap: 10px;
}

.score-entry:hover {
    background: rgba(255, 107, 107, 0.2);
}

/* Special styling for top 3 */
.score-entry:nth-child(1) { 
    border-left-color: #ffd700; 
    background: rgba(255, 215, 0, 0.1);
}
.score-entry:nth-child(2) { 
    border-left-color: #c0c0c0; 
    background: rgba(192, 192, 192, 0.1);
}
.score-entry:nth-child(3) { 
    border-left-color: #cd7f32; 
    background: rgba(205, 127, 50, 0.1);
}

.score-rank {
    font-weight: bold;
    min-width: 35px;
    font-size: 16px;
    flex-shrink: 0;
}

.score-name {
    font-weight: bold;
    color: #ff9999;
    font-size: 16px;
    min-width: 120px;
    flex-shrink: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.score-details {
    flex: 1;
    color: #ff9999;
    font-size: 14px;
}

.score-value {
    font-weight: bold;
    color: #ff6b6b;
    font-size: 16px;
    min-width: 80px;
    text-align: right;
    flex-shrink: 0;
}

.score-entry:nth-child(1) .score-value { color: #ffd700; }
.score-entry:nth-child(2) .score-value { color: #c0c0c0; }
.score-entry:nth-child(3) .score-value { color: #cd7f32; }

#viewLeaderboardButton,
#leaderboardButton {
    margin-top: 10px;
}

/* Empty leaderboard state */
.leaderboard-content:empty::before {
    content: "No scores yet! Be the first to play!";
    display: block;
    text-align: center;
    color: #ff6b6b;
    font-style: italic;
    padding: 20px;
}