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

body {
    background: #050a05;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    font-family: 'VT323', monospace;
    overflow: hidden;
    color: #7fdfa0;
    padding: 20px;
}

#bgAnimation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.2;
}

#topBar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    z-index: 1;
    margin-bottom: 8px;
}

#gameTitle {
    font-size: 28px;
    color: #4a9c6a;
    text-shadow: 0 0 20px rgba(80, 200, 120, 0.5);
    letter-spacing: 6px;
    animation: titlePulse 4s ease-in-out infinite;
    user-select: none;
}

@keyframes titlePulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.02); }
    52% { opacity: 0.6; }
    54% { opacity: 1; }
}

#mainContainer {
    display: flex;
    gap: 20px;
    align-items: center;
    z-index: 1;
}

#leftPanel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

#scoreDisplay {
    font-size: 22px;
    text-shadow: 0 0 12px rgba(127, 223, 160, 0.6);
    padding: 6px 16px;
    background: transparent;
    border: 2px solid #1a5c3a;
    color: #7fdfa0;
}

#gameWrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#gameContainer {
    position: relative;
    border: 4px solid #1a5c3a;
    box-shadow: 
        0 0 25px rgba(26, 92, 58, 0.5),
        inset 0 0 60px rgba(0, 0, 0, 0.9);
    background: #0a1a0a;
    max-width: 100%;
}

#gameCanvas {
    display: block;
    background: #0d1f0d;
    touch-action: none;
    max-width: 100%;
    height: auto;
}

#scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    animation: scanlineFlicker 0.05s infinite;
    z-index: 10;
}

@keyframes scanlineFlicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.97; }
}

#controlsBar {
    display: flex;
    justify-content: center;
    gap: 25px;
    padding: 8px 15px;
    background: transparent;
    border: none;
    font-size: 14px;
    color: #4a9c6a;
    font-family: 'VT323', monospace;
}

#controlsBar span {
    display: flex;
    align-items: center;
    gap: 5px;
}

#controlsBar .key {
    background: transparent;
    padding: 1px 6px;
    color: #7fdfa0;
    font-size: 13px;
}

#rightPanel {
    width: 260px;
    background: linear-gradient(180deg, rgba(13, 31, 13, 0.8) 0%, rgba(10, 26, 10, 0.9) 100%);
    border: 2px solid #1a5c3a;
    padding: 15px;
    box-shadow: 0 0 20px rgba(26, 92, 58, 0.3);
    min-height: 320px;
}

#highscoreTitle {
    font-size: 20px;
    text-align: center;
    margin-bottom: 12px;
    text-shadow: 0 0 10px rgba(127, 223, 160, 0.5);
    border-bottom: 1px solid #1a5c3a;
    padding-bottom: 8px;
    letter-spacing: 2px;
}

#highscoreList {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 260px;
}

.highscoreEntry {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 15px;
    border-bottom: 1px dashed #122812;
    min-height: 22px;
    align-items: center;
}

.highscoreEntry .rank {
    color: #3a7a5a;
    margin-right: 8px;
    min-width: 22px;
}

.highscoreEntry .name {
    flex: 1;
    color: #7fdfa0;
    letter-spacing: 1px;
}

.highscoreEntry .score {
    color: #50c878;
    text-shadow: 0 0 6px rgba(80, 200, 120, 0.4);
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 15, 5, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #7fdfa0;
    z-index: 20;
}

#overlay.hidden {
    display: none;
}

#overlay h1 {
    font-size: 48px;
    margin-bottom: 10px;
    text-shadow: 0 0 30px rgba(127, 223, 160, 0.9);
    letter-spacing: 6px;
    animation: titleGlow 2s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { text-shadow: 0 0 30px rgba(127, 223, 160, 0.9); }
    50% { text-shadow: 0 0 50px rgba(127, 223, 160, 1), 0 0 70px rgba(80, 200, 120, 0.6); }
}

#overlay .score-display {
    font-size: 32px;
    color: #50c878;
    margin: 15px 0;
    text-shadow: 0 0 15px rgba(80, 200, 120, 0.7);
}

#overlay .mode-display {
    font-size: 16px;
    color: #4a9c6a;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

#overlay .controls {
    font-size: 14px;
    color: #3a7a5a;
    text-align: center;
    line-height: 2;
    background: transparent;
    padding: 10px;
}

#nameInputContainer {
    display: none;
    flex-direction: column;
    align-items: center;
    margin: 15px 0;
}

#nameInputLabel {
    color: #4a9c6a;
    margin-bottom: 8px;
    font-size: 16px;
}

#nameInput {
    font-family: 'VT323', monospace;
    font-size: 24px;
    background: transparent;
    border: 2px solid #1a5c3a;
    color: #7fdfa0;
    padding: 8px 12px;
    text-align: center;
    width: 160px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#nameInput:focus {
    outline: none;
    border-color: #50c878;
    box-shadow: 0 0 12px rgba(80, 200, 120, 0.4);
}

#nameInput.error {
    border-color: #c85050;
    animation: inputShake 0.3s;
}

@keyframes inputShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

#nameHint {
    font-size: 13px;
    color: #2a5a3a;
    margin-top: 6px;
}

#modeSelector {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.modeBtn {
    flex: 1;
    padding: 8px 10px;
    font-family: 'VT323', monospace;
    font-size: 15px;
    background: transparent;
    border: 2px solid #1a5c3a;
    color: #4a9c6a;
    cursor: pointer;
    transition: all 0.15s;
}

.modeBtn:hover {
    background: rgba(26, 92, 58, 0.3);
    color: #7fdfa0;
}

.modeBtn.active {
    background: #1a5c3a;
    color: #7fdfa0;
    border-color: #50c878;
}

#overlay .modeSelect {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
}

#overlay .modeSelectTitle {
    color: #4a9c6a;
    font-size: 16px;
}

#overlay .modeButtons {
    display: flex;
    gap: 8px;
}

#overlay .modeButtons button {
    padding: 8px 15px;
    font-family: 'VT323', monospace;
    font-size: 15px;
    background: transparent;
    border: 2px solid #1a5c3a;
    color: #4a9c6a;
    cursor: pointer;
    transition: all 0.15s;
    outline: none;
}

#overlay .modeButtons button:hover,
#overlay .modeButtons button:focus,
#overlay .modeButtons button.selected {
    background: #1a5c3a;
    color: #7fdfa0;
    border-color: #50c878;
}

.startHint {
    font-size: 14px;
    color: #3a7a5a;
    margin-top: 20px;
    animation: blink 1.5s infinite;
}

.start-btn {
    margin-top: 12px;
    padding: 10px 24px;
    font-family: 'VT323', monospace;
    font-size: 16px;
    background: rgba(26, 92, 58, 0.3);
    border: 2px solid #1a5c3a;
    color: #7fdfa0;
    cursor: pointer;
    border-radius: 6px;
}

.start-btn:hover,
.start-btn:focus {
    background: #1a5c3a;
    border-color: #50c878;
    outline: none;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@media (max-width: 600px) {
    body {
        padding: 8px;
    }

    #topBar {
        gap: 8px;
        margin-bottom: 6px;
    }

    #gameTitle {
        font-size: 20px;
        letter-spacing: 3px;
    }

    #scoreDisplay {
        font-size: 15px;
        padding: 4px 8px;
    }

    #mainContainer {
        flex-direction: column;
        align-items: center;
    }

    #rightPanel {
        display: none;
    }

    #overlay h1 {
        font-size: 26px;
    }

    #overlay .modeButtons {
        flex-direction: column;
        gap: 6px;
    }
}

@media (max-width: 600px) {
    #dpad {
        width: 90px;
        height: 90px;
    }

    .dpad-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    .mobile-menu-btn {
        font-size: 11px;
        padding: 4px 5px;
    }

    #mobileMenu {
        width: auto;
        max-width: none;
        gap: 4px;
    }
}

#soundLabel.muted {
    text-decoration: line-through;
    opacity: 0.5;
}

#mobileControls {
    display: none;
    grid-template-columns: 1fr auto;
    align-items: start;
    column-gap: 12px;
    width: 100%;
    max-width: 100%;
    padding: 10px 5px 5px;
    box-sizing: border-box;
}

#dpad {
    position: relative;
    width: 140px;
    height: 140px;
    flex: 0 0 auto;
    margin-left: auto;
    touch-action: none;
    justify-self: end;
}

.dpad-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    background: rgba(26, 92, 58, 0.4);
    border: 2px solid #1a5c3a;
    color: #7fdfa0;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

.dpad-btn:active, .dpad-btn.pressed {
    background: rgba(80, 200, 120, 0.5);
}

.dpad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-left {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.dpad-right {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.dpad-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 92, 58, 0.2);
    color: #3a7a5a;
    cursor: default;
}

#mobileMenu {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    align-items: center;
    flex: 0 0 auto;
    margin-right: auto;
    min-width: 0;
}

.mobile-menu-btn {
    padding: 10px 12px;
    font-family: 'VT323', monospace;
    font-size: 14px;
    background: rgba(26, 92, 58, 0.3);
    border: 2px solid #1a5c3a;
    color: #7fdfa0;
    cursor: pointer;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

.mobile-menu-btn:active {
    background: rgba(80, 200, 120, 0.4);
}

@media (max-width: 1366px) {
    #mainContainer {
        flex-direction: column;
        align-items: center;
    }

    #rightPanel {
        display: none;
    }

    #controlsBar {
        display: none;
    }

    #mobileControls {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        column-gap: 12px;
    }

    #mobileMenu {
        display: grid;
    }
}

@media (max-width: 600px) {
    #mobileControls {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        column-gap: 10px;
    }

    #mobileMenu {
        display: grid;
    }

    #controlsBar {
        display: none;
    }
}

#rotateOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #050a05;
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

#rotateContent {
    text-align: center;
    color: #4a9c6a;
    font-family: 'VT323', monospace;
}

#rotateIcon {
    font-size: 80px;
    color: #7fdfa0;
    animation: rotateAnim 2s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes rotateAnim {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

#rotateContent p {
    font-size: 22px;
    letter-spacing: 2px;
    text-shadow: 0 0 15px rgba(80, 200, 120, 0.4);
}

@media (max-width: 1024px) and (orientation: landscape) {
    #rotateOverlay {
        display: flex;
    }
}

body.left-handed #mobileControls {
    grid-template-columns: auto 1fr;
}

body.left-handed #dpad {
    margin-left: 0;
    margin-right: auto;
    justify-self: start;
}

body.left-handed #mobileMenu {
    margin-right: 0;
    margin-left: auto;
}
