.menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: white;
    font-family: Arial, sans-serif;
    text-align: center;
}

body.booting .menu,
body.booting #hud {
    visibility: hidden;
}

#mainMenu {
    background: #000;
    justify-content: flex-start;
    box-sizing: border-box;
    padding: clamp(18px, 4vh, 38px) 12px 18px;
    overflow: hidden;
}

#pauseMenu,
#gameOverScreen {
    background: rgba(0, 0, 0, 0.88);
}

.menu.hidden {
    display: none;
}

.menu h1 {
    font-size: 3rem;
    margin: 0 0 0.85rem;
    color: #ff6600;
    text-shadow: 0 0 10px rgba(255, 102, 0, 0.7);
}

.menu h2 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: #4caf50;
}

.menu button {
    background: linear-gradient(to bottom, #4a4a4a, #2a2a2a);
    color: white;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 11px 24px;
    margin: 6px;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 200px;
    outline: none;
}

.menu button:hover {
    background: linear-gradient(to bottom, #5a5a5a, #3a3a3a);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 102, 0, 0.5);
}

.menu button:active {
    transform: scale(0.95);
}

.menu button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
    transform: none;
    box-shadow: none;
}

.volume-controls {
    margin-top: 30px;
    width: 80%;
    max-width: 400px;
}

.volume-controls.hidden {
    display: none;
}

.volume-controls label {
    display: block;
    margin: 10px 0;
    font-size: 1.1rem;
    color: #ddd;
}

.volume-controls input[type="range"] {
    width: 100%;
    margin-top: 5px;
}

#finalScore {
    font-size: 2rem;
    margin: 20px 0;
    color: #ffcc00;
}

#wallet-display {
    margin: 0 0 10px;
    color: #ffdd66;
    font-size: 1.15rem;
    font-weight: 700;
}

#menuRequirementHint {
    width: min(680px, calc(100vw - 28px));
    margin: 0 0 14px;
    padding: 10px 16px;
    border: 1px solid rgba(255, 204, 102, 0.65);
    border-radius: 8px;
    color: #ffe08a;
    background: rgba(78, 42, 0, 0.55);
    box-shadow: 0 0 18px rgba(255, 160, 32, 0.45), inset 0 0 18px rgba(255, 204, 102, 0.08);
    font-size: clamp(1.12rem, 2.4vw, 1.45rem);
    font-weight: 900;
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 0;
}

#menuRequirementHint.ready {
    color: #b6ff9d;
    border-color: rgba(144, 224, 138, 0.72);
    background: rgba(21, 68, 27, 0.45);
    box-shadow: 0 0 16px rgba(100, 255, 110, 0.34), inset 0 0 18px rgba(144, 224, 138, 0.08);
}

.main-menu-layout {
    width: min(520px, calc(100vw - 24px));
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.main-menu-top {
    width: 100%;
    display: flex;
    justify-content: center;
}

.main-menu-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.gacha-panel,
.drone-select-overlay,
.leaderboard-overlay,
.name-overlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    overflow: hidden;
    margin-top: 0;
    padding: clamp(12px, 3vh, 28px);
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.82);
    z-index: 180;
    box-sizing: border-box;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gacha-panel.hidden,
.drone-select-overlay.hidden,
.leaderboard-overlay.hidden,
.name-overlay.hidden {
    display: none;
}

.name-overlay {
    z-index: 240;
    background: rgba(0, 0, 0, 0.9);
}

.name-window {
    width: min(460px, calc(100vw - 28px));
    padding: 24px;
    border: 1px solid rgba(255, 204, 102, 0.55);
    border-radius: 10px;
    background: #111;
    box-shadow: 0 0 28px rgba(255, 122, 24, 0.25);
    box-sizing: border-box;
}

.name-window h2 {
    margin: 0 0 10px;
    color: #ffcc00;
    font-size: 2rem;
}

.name-window p {
    margin: 0 0 14px;
    color: #ddd;
    font-size: 1.05rem;
}

#playerNameInput {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 14px;
    border: 2px solid #666;
    border-radius: 8px;
    background: #050505;
    color: #fff;
    font-size: 1.2rem;
    outline: none;
}

#playerNameInput:focus {
    border-color: #ffcc00;
    box-shadow: 0 0 12px rgba(255, 204, 0, 0.35);
}

#playerNameError {
    min-height: 24px;
    margin: 8px 0 4px;
    color: #ff6b6b;
    font-weight: 800;
}

#savePlayerNameBtn {
    width: 100%;
    margin: 8px 0 0;
}

.overlay-window {
    width: min(1080px, calc(100vw - 24px));
    max-height: min(760px, calc(100dvh - 24px));
    display: flex;
    flex-direction: column;
    border: 1px solid #555;
    border-radius: 8px;
    background: #111;
    box-shadow: 0 0 28px rgba(0, 0, 0, 0.75);
    overflow: hidden;
}

.overlay-header {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
    gap: 12px;
    align-items: center;
    margin: 0;
    padding: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
}

.overlay-header h2 {
    margin: 0;
    color: #ffcc00;
    font-size: clamp(1.35rem, 4vw, 2.4rem);
}

.overlay-header > :last-child {
    justify-self: end;
    color: #ffdd66;
    font-weight: 800;
}

.menu button.back-button {
    justify-self: start;
    min-width: 120px;
    margin: 0;
}

.overlay-content {
    width: 100%;
    min-height: 0;
    flex: 1;
    margin: 0;
    overflow: auto;
    padding: 14px;
    box-sizing: border-box;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

#gachaStatus,
#selectedDrone {
    margin: 8px 0;
    color: #ddd;
}

.collection-title {
    margin: 12px 0 6px;
    color: #f4f4f4;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: left;
}

.gacha-machine {
    position: relative;
    margin: 10px 0 0;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.gacha-reel {
    position: relative;
    display: flex;
    gap: 10px;
    min-height: 132px;
    padding: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    opacity: 0.48;
    touch-action: pan-x;
}

.gacha-reel::-webkit-scrollbar {
    display: none;
}

.gacha-machine::before,
.gacha-machine::after {
    content: "";
    position: absolute;
    left: 50%;
    width: 46px;
    height: 18px;
    transform: translateX(-50%);
    background: #ff8a18;
    clip-path: polygon(50% 100%, 0 0, 100% 0);
    filter: drop-shadow(0 0 8px rgba(255, 138, 24, 0.9));
    pointer-events: none;
    z-index: 3;
}

.gacha-machine::before {
    top: 0;
}

.gacha-machine::after {
    bottom: 0;
    transform: translateX(-50%) rotate(180deg);
}

.gacha-reel.rolling .drone-slot {
    box-shadow: 0 0 10px rgba(255, 122, 24, 0.18);
}

.gacha-reel.rolling .drone-slot.highlighted {
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.55);
}

#droneCollection {
    margin-top: 0;
}

.leaderboard-window {
    max-width: 760px;
}

.leaderboard-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    text-align: left;
}

.leaderboard-name {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 900;
}

.leaderboard-device {
    color: #bdbdbd;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.leaderboard-kills {
    color: #ffdd66;
    font-size: 1.1rem;
    font-weight: 900;
    white-space: nowrap;
}

.drone-collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
    gap: 12px;
    align-items: stretch;
    touch-action: pan-y;
}

.drone-collection-grid .drone-slot {
    min-width: 0;
    width: 100%;
    flex-basis: auto;
    touch-action: pan-y;
}

.drone-slot {
    position: relative;
    flex: 0 0 150px;
    min-width: 150px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 10px;
    margin: 0;
    border: 1px solid #383838;
    border-radius: 6px;
    background: #171717;
    color: #ddd;
    font-size: 0.95rem;
    scroll-snap-align: start;
    transform: none;
}

.menu .drone-slot:hover {
    transform: none;
}

.drone-slot.owned {
    border-color: #4caf50;
}

.drone-slot.selected {
    border-color: #ffcc00;
    box-shadow: 0 0 14px rgba(255, 204, 0, 0.35);
}

.drone-slot.locked {
    opacity: 0.7;
    filter: grayscale(0.85);
}

.drone-lock {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 2px 5px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 4px;
    color: #f2f2f2;
    background: rgba(0, 0, 0, 0.72);
    font-size: 0.58rem;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
}

.drone-slot.compact {
    flex-basis: 118px;
    min-width: 118px;
    min-height: 126px;
}

.drone-slot.highlighted {
    border-color: #ff7a18;
    box-shadow: 0 0 18px rgba(255, 122, 24, 0.42);
}

.drone-preview {
    position: relative;
    width: 88px;
    height: 62px;
    display: block;
    border-radius: 6px;
    background: #242424;
    overflow: hidden;
}

.drone-preview::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.12) 25%, transparent 25% 50%, rgba(0, 0, 0, 0.18) 50% 75%, transparent 75%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.28));
    background-size: 14px 14px, auto;
}

.preview-body,
.preview-arm {
    position: absolute;
    display: block;
    background: currentColor;
}

.preview-body {
    left: 31px;
    top: 20px;
    width: 28px;
    height: 22px;
    border-radius: 4px;
    box-shadow:
        -25px -14px 0 -7px currentColor,
        25px -14px 0 -7px currentColor,
        -25px 14px 0 -7px currentColor,
        25px 14px 0 -7px currentColor;
}

.preview-arm {
    left: 18px;
    top: 30px;
    width: 52px;
    height: 5px;
    border-radius: 4px;
    opacity: 0.82;
}

.preview-arm.a {
    transform: rotate(35deg);
}

.preview-arm.b {
    transform: rotate(-35deg);
}

.preview-twig { color: #8b5e3c; background: #26351f; }
.preview-trash { color: #5d6048; background: #251f1b; }
.preview-plank { color: #8a6239; background: #201c16; }
.preview-stock { color: #6f6f6f; background: #242424; }
.preview-ugly { color: #9b7230; background: #302a19; }
.preview-scout { color: #517b86; background: #16292e; }
.preview-hornet { color: #a68a1c; background: #201d10; }
.preview-night { color: #4d5c73; background: #11151d; }
.preview-manta { color: #679aa0; background: #101f22; }
.preview-royal { color: #8b7b3a; background: #231c17; }
.preview-phantom { color: #9fb2ff; background: #101421; }
.preview-apex { color: #ffb84d; background: #1c1712; }
.preview-comet { color: #b8c0c8; background: #18272c; }
.preview-empty { color: transparent; background: repeating-linear-gradient(135deg, #101010 0 12px, #1f1f1f 12px 24px); }

.drone-trash .preview-body,
.drone-plank .preview-body,
.drone-ugly .preview-body {
    left: 25px;
    top: 24px;
    width: 38px;
    height: 14px;
    border-radius: 2px;
    transform: rotate(-9deg);
    box-shadow:
        -18px -7px 0 -8px currentColor,
        22px 12px 0 -8px currentColor;
}

.drone-trash .preview-arm,
.drone-plank .preview-arm,
.drone-ugly .preview-arm {
    left: 29px;
    width: 29px;
    height: 6px;
    opacity: 0.65;
}

.drone-trash .preview-arm.b,
.drone-plank .preview-arm.b {
    display: none;
}

.drone-manta .preview-body,
.drone-phantom .preview-body,
.drone-apex .preview-body {
    left: 25px;
    width: 40px;
    border-radius: 12px 12px 4px 4px;
    box-shadow:
        -29px -12px 0 -8px currentColor,
        29px -12px 0 -8px currentColor,
        -29px 12px 0 -8px currentColor,
        29px 12px 0 -8px currentColor;
}

.preview-empty .preview-body,
.preview-empty .preview-arm {
    display: none;
}

.drone-name {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.1;
}

.drone-rarity {
    color: #aaa;
    font-size: 0.78rem;
    line-height: 1.1;
}

@media (max-width: 768px) {
    .menu h1 {
        font-size: 2rem;
    }
    
    .menu h2 {
        font-size: 1.8rem;
    }
    
    .menu button {
        padding: 12px 20px;
        font-size: 1rem;
        min-width: 180px;
    }

    .overlay-header {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 10px;
    }

    .overlay-header > *,
    .overlay-header > :last-child,
    .menu button.back-button {
        justify-self: center;
    }

    .overlay-content {
        padding: 10px;
    }

    .drone-collection-grid {
        grid-template-columns: repeat(2, minmax(118px, 1fr));
    }

    .leaderboard-row {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .leaderboard-kills {
        white-space: normal;
    }
}

@media (max-height: 760px) {
    #mainMenu {
        padding-top: 12px;
    }

    .menu h1 {
        font-size: 2.15rem;
        margin-bottom: 0.35rem;
    }

    #wallet-display {
        margin-bottom: 6px;
        font-size: 1rem;
    }

    #menuRequirementHint {
        margin-bottom: 8px;
        padding: 8px 12px;
        font-size: 1.05rem;
    }

    .menu button {
        padding: 9px 20px;
        margin: 4px;
        font-size: 0.98rem;
    }

    .gacha-panel,
    .drone-select-overlay,
    .leaderboard-overlay,
    .name-overlay {
        padding: 10px;
    }

    .drone-slot {
        min-height: 126px;
    }
}

#leaderboardDevice, .leaderboard-device {
    display: none;
}
