body {
    margin: 0;
    overflow: hidden;
    background-color: #001219;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    user-select: none;
    touch-action: none;
}

canvas {
    display: block;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* SMALL TOP LEFT BUTTONS */
#sound-btn,
#rules-btn,
#fullscreen-btn {
    position: absolute;
    left: 20px;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #555;
    color: white;
    padding: 0;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: 0.2s;
    z-index: 200;
    font-weight: bold;
}

#sound-btn {
    top: 20px;
}

#rules-btn {
    top: 70px;
}

/* Position the new button below the rules button */
#fullscreen-btn {
    top: 120px;
    font-size: 1.5rem;
}

#sound-btn:hover,
#rules-btn:hover,
#fullscreen-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: white;
}

#fps-display {
    position: absolute;
    top: 5px;
    left: 5px;
    /* Positioned to the right of the sound/rules buttons */
    color: #949494ef;
    font-size: 10px;
    font-family: monospace;
    font-weight: bold;
    pointer-events: none;
    z-index: 200;
    text-shadow: 1px 1px 0 #000;
}

/* RULES OVERLAY */
#rules-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 18, 25, 0.95);
    z-index: 1000;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.rules-content {
    background: #001219;
    border: 2px solid #0A9396;
    padding: 10px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    color: #ddd;
    box-shadow: 0 0 30px rgba(10, 147, 150, 0.2);
    text-align: left;
    max-height: 85vh;
    overflow-y: auto;
    touch-action: pan-y;
}

.rules-content h2 {
    text-align: center;
    color: #0A9396;
    margin-top: 0;
    text-transform: uppercase;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

.rules-section {
    margin-bottom: 15px;
}

.rules-section h3 {
    color: #AE2012;
    margin-bottom: 5px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.rules-section p {
    margin: 5px 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.warning {
    color: #EE9B00;
    font-weight: bold;
}

.item-list {
    list-style: none;
    padding: 0;
}

.item-list li {
    margin: 5px 0;
    font-size: 0.9rem;
}

.item-list span {
    display: inline-block;
    width: 25px;
    font-size: 1.2rem;
    vertical-align: middle;
}

.rules-icon {
    width: 20px;
    height: 20px;
    vertical-align: top;
}


.close-btn {
    display: block;
    width: 100%;
    padding: 12px;
    background: #0A9396;
    border: none;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    margin-top: 20px;
    border-radius: 5px;
    transition: 0.2s;
}

.close-btn:hover {
    background: #fff;
    transform: scale(1.02);
}

#boss-timer-container {
    position: absolute;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
}

#boss-label {
    font-size: 0.8rem;
    color: #AE2012;
    font-weight: bold;
    letter-spacing: 2px;
    margin-bottom: 2px;
    text-shadow: 0 0 5px black;
}

#boss-timer {
    font-size: 3.5rem;
    font-weight: 900;
    color: #AE2012;
    text-shadow: 0 0 10px #AE2012;
    font-variant-numeric: tabular-nums;
    margin-top: 5px;
}

#score-board {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
    display: flex;
    gap: 40px;
    align-items: center;
}

.hud-stat {
    display: flex;
    flex-direction: column;
}

#current-score,
#current-kills {
    font-size: 3rem;
    font-weight: 900;
    color: white;
    display: block;
    line-height: 1;
}

.hud-label {
    font-size: 0.9rem;
    color: #aaa;
    font-weight: bold;
    letter-spacing: 1px;
}

#personal-best-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 15px;
    border-radius: 10px;
    border-left: 4px solid #0A9396;
    pointer-events: none;
}

.pb-label {
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#personal-best-score {
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
}

#buffs-container {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    pointer-events: none;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 90%;
}

.buff-box {
    background: rgba(0, 0, 0, 0.8);
    padding: 8px 20px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 1.5rem;
    display: none;
    align-items: center;
    gap: 10px;
    border: 3px solid white;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#buff-boost {
    border-color: #00ffff;
    color: #00ffff;
    text-shadow: 0 0 5px #00ffff;
}



#buff-gun {
    border-color: #AE2012;
    color: #AE2012;
    text-shadow: 0 0 5px #AE2012;
}

#lb-container {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}


.lb-box {
    background: rgba(0, 0, 0, 0.6);
    padding: 10px 12px;
    border-radius: 12px;
    text-align: left;
    border: 1px solid #333;
    width: 200px;
    /* Fixed width */
    box-sizing: border-box;
}

.lb-box h3 {
    margin: 0 0 5px 0;
    color: #888;
    font-size: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-bottom: 1px solid #444;
    padding-bottom: 3px;
    text-align: center;
    /* Center header */
}

.lb-box ol {
    padding: 0;
    margin: 0;
    list-style: none;
}

.lb-box li {
    margin-bottom: 3px;
    font-size: 0.85rem;
    color: #ccc;
    display: flex;
    align-items: center;
}

.lb-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.lb-score {
    flex-shrink: 0;
    margin-left: 8px;
    font-weight: bold;
    text-align: right;
}

.highlight-me {
    color: #0A9396 !important;
    text-shadow: 0 0 5px #0A9396;
}

.highlight-me .lb-score {
    color: #0A9396;
}

.king-icon {
    color: #EE9B00;
    margin-right: 4px;
    flex-shrink: 0;
}

#notification-area {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    width: 100%;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.toast {
    display: block;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.9), transparent);
    color: black;
    font-weight: bold;
    padding: 10px 60px;
    font-size: 1.5rem;
    margin-bottom: 10px;
    opacity: 0;
    transition: opacity 0.5s;
    text-shadow: none;
    border-top: 2px solid white;
    border-bottom: 2px solid white;
    max-width: 90%;
}

.toast.show {
    opacity: 1;
}

#start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 18, 25, 0.95);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    pointer-events: auto;
    border: 2px solid #333;
    box-shadow: 0 0 60px rgba(10, 147, 150, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 95vh;
    z-index: 100;
    overflow-y: auto;
}

h1 {
    margin: 0 0 10px 0;
    font-size: 2.5rem;
    text-shadow: 3px 3px 0 #000;
    letter-spacing: 2px;
    width: 100%;
}

.title-part {
    color: #0A9396;
}

.instruction-label {
    color: #0A9396;
    font-size: 1rem;
    margin: 10px 0 5px 0;
    font-weight: bold;
    width: 100%;
    text-align: center;
}

/* BUTTONS AND INPUT UNIFORMITY */
#username-input,
button#play-btn,
button#skins-menu-btn,
button#leaderboard-btn,
button#main-rules-btn {
    width: 100%;
    box-sizing: border-box;
}

/* USERNAME INPUT */
#username-input {
    background: #001219;
    border: 2px solid #005F73;
    color: white;
    padding: 12px 20px;
    border-radius: 30px;
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    transition: all 0.2s;
    font-weight: bold;
    margin-bottom: 10px;
    font-family: inherit;
}

#username-input:focus {
    border-color: #0A9396;
    box-shadow: 0 0 15px rgba(10, 147, 150, 0.3);
    background: #001219;
}

#username-input::placeholder {
    color: #555;
    font-weight: normal;
}

.skin-section-title {
    color: #aaa;
    font-size: 0.9rem;
    text-align: left;
    margin-left: 10px;
    margin-top: 5px;
    font-weight: bold;
}

.skin-section-title.boss-title {
    color: #AE2012;
}

.skin-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    background: #001219;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #333;
    /* max-height: 150px; Removed to allow full height */
    overflow-y: auto;
}

.skin-grid::-webkit-scrollbar {
    width: 8px;
}

.skin-grid::-webkit-scrollbar-track {
    background: #001219;
}

.skin-grid::-webkit-scrollbar-thumb {
    background: #005F73;
    border-radius: 4px;
}

.skin-card {
    position: relative;
    background: #001219;
    border: 2px solid #005F73;
    border-radius: 8px;
    height: 70px;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.skin-card:hover {
    transform: scale(1.05);
    border-color: #555;
}

.skin-card.selected {
    border-color: #EE9B00;
    box-shadow: 0 0 10px rgba(238, 155, 0, 0.3);
}

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

.skin-preview {
    width: 45px;
    height: 45px;
    background: transparent;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.skin-name {
    font-size: 0.6rem;
    color: #ccc;
}

.lock-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.unlock-req {
    position: absolute;
    top: 2px;
    font-size: 0.9rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 4px;
    border-radius: 4px;
}

/* BUTTONS */
@keyframes pulse-btn {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(10, 147, 150, 0);
    }

    50% {
        transform: scale(1.03);
        box-shadow: 0 0 10px rgba(10, 147, 150, 0.3);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(10, 147, 150, 0);
    }
}

button#play-btn {
    padding: 12px 0;
    font-size: 1.3rem;
    background: linear-gradient(135deg, #0A9396, #94D2BD);
    border: none;
    border-radius: 30px;
    color: #000;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s, box-shadow 0.2s;
    margin-bottom: 10px;
    animation: pulse-btn 2s infinite ease-in-out;
}

button#play-btn:hover {
    animation: none;
    transform: scale(1.06);
    filter: brightness(1.1);
    box-shadow: 0 0 15px rgba(10, 147, 150, 0.6);
}

button#play-btn:active {
    animation: none;
    transform: scale(0.95);
}

button#play-btn:disabled {
    filter: grayscale(1);
    cursor: not-allowed;
    transform: none;
}

button#main-rules-btn {
    padding: 12px 0;
    font-size: 1.1rem;
    background: transparent;
    border: 2px solid #0A9396;
    border-radius: 30px;
    color: #0A9396;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 10px;
}

button#main-rules-btn:hover {
    background: rgba(10, 147, 150, 0.1);
    transform: scale(1.05);
}

#game-over-container {
    display: none;
    width: 100%;
    margin-bottom: 15px;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #333;
    box-sizing: border-box;
}

#game-over-title {
    color: #AE2012;
    font-size: 1.8rem;
    font-weight: 900;
    margin: 0 0 10px 0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    margin: 5px 0;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
}

.stat-row span:last-child {
    font-weight: bold;
    color: #0A9396;
}

/* --- SKINS MENU BUTTON --- */
button#skins-menu-btn {
    padding: 12px 0;
    font-size: 1.1rem;
    background: transparent;
    border: 2px solid #EE9B00;
    /* Purple theme for skins */
    border-radius: 30px;
    color: #EE9B00;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 10px;
}

button#skins-menu-btn:hover {
    background: rgba(238, 155, 0, 0.1);
    transform: scale(1.05);
    border-color: #E9D8A6;
}

/* --- LEADERBOARD BUTTON --- */
button#leaderboard-btn {
    padding: 12px 0;
    font-size: 1.1rem;
    background: transparent;
    border: 2px solid #9B2226;
    /* Ruby Red for Leaderboard */
    border-radius: 30px;
    color: #9B2226;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 10px;
}

button#leaderboard-btn:hover {
    background: rgba(155, 34, 38, 0.1);
    transform: scale(1.05);
    color: #ff99ac;
    border-color: #ff99ac;
}

.credits {
    margin: 10px 0 0 0;
    font-size: 0.9rem;
    color: #888;
    width: 100%;
    text-align: center;
}

.credits a {
    color: #0A9396;
    text-decoration: none;
    transition: 0.2s;
}

.credits a:hover {
    color: #94D2BD;
}


/* --- SKINS PAGE OVERLAY --- */
#skins-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 18, 25, 0.95);
    z-index: 1000;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

.skins-content {
    background: #001219;
    border: 2px solid #EE9B00;
    padding: 10px;
    border-radius: 20px;
    max-width: 800px;
    width: 90%;
    color: #ddd;
    box-shadow: 0 0 50px rgba(238, 155, 0, 0.15);
    text-align: center;
    height: 85vh !important;
    max-height: 85vh !important;
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
}

.skins-content h2 {
    color: #EE9B00;
    margin: 0;
    text-shadow: 0 0 10px rgba(238, 155, 0, 0.5);
    font-size: 2rem;
}

/* SKIN PREVIEW */
#skin-preview-container {
    display: flex;
    justify-content: center;
}

#skin-preview-canvas {

    width: 100%;
    max-width: 600px;
}

/* --- ADJUST GRID FOR DEDICATED PAGE --- */
/* We override the previous max-height because we have more room now */


/* --- MOBILE CONTROLS --- */
#mobile-controls {
    display: none;
    /* Hidden by default, shown via JS on mobile */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

#joystick-zone {
    position: absolute;
    bottom: 40px;
    left: 40px;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
    /* Prevents browser zooming/scrolling */
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(10, 147, 150, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px rgba(10, 147, 150, 0.5);
    pointer-events: none;
    transition: 0.1s;
}

#mobile-boost-btn {
    position: absolute;
    bottom: 50px;
    right: 40px;
    width: 90px;
    height: 90px;
    background: rgba(174, 32, 18, 0.6);
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    color: white;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    cursor: pointer;
}

#mobile-boost-btn:active {
    background: rgba(174, 32, 18, 0.9);
    transform: scale(0.95);
}

/* --- RESPONSIVE FIXES --- */
/* --- RESPONSIVE FIXES --- */
@media (max-width: 768px) {
    #start-screen {
        min-width: 0;
        width: 85%;
        padding: 10px;
        max-height: 85vh;
        /* Ensure it fits */
    }

    h1 {
        font-size: 1.8rem;
        margin-bottom: 5px;
    }

    #username-input {
        padding: 8px 15px;
        font-size: 1rem;
        margin-bottom: 10px;
    }

    /* Adjust grids for smaller screens */
    .skin-grid {
        grid-template-columns: repeat(3, 1fr);
        /* max-height: 100px; REMOVED */
    }

    /* Scale down and hide All-Time Best leaderboard on mobile */
    #lb-container {
        transform: scale(0.65);
        transform-origin: top right;
        top: 10px;
        right: 5px;
    }

    /* Hide the All-Time Best leaderboard (second box) on mobile */
    #lb-container .lb-box:nth-child(2) {
        display: none;
    }

    #boss-timer-container {
        top: 60px;
        transform: scale(0.7) translateX(-60%);
    }

    #boss-timer {
        font-size: 2.5rem;
    }

    #score-board {
        top: 5px;
        transform: scale(0.75) translateX(-60%);
    }

    /* Make buff notifications smaller on mobile */
    #buffs-container {
        bottom: 70px;
        gap: 8px;
        max-width: 95%;
    }

    .buff-box {
        padding: 4px 12px;
        font-size: 1rem;
        border-width: 2px;
        gap: 6px;
    }

    /* Make toast notifications smaller */
    .toast {
        font-size: 1rem;
        padding: 6px 30px;
        max-width: 85%;
    }

    #notification-area {
        top: 15%;
    }

    /* Tweaks for small buttons */
    button#play-btn,
    button#skins-menu-btn,
    button#leaderboard-btn,
    button#main-rules-btn {
        padding: 8px 20px;
        font-size: 0.9rem;
        width: 60%;
        margin-top: 5px;
        margin-bottom: 5px;
    }

    /* Hide desktop-specific instructions */
    .rules-section p,
    .item-list li {
        font-size: 0.7rem;
    }
}

/* Landscape Mode Fixes - Short screens (landscape mobile/tablet) */
@media (max-height: 500px) {
    #start-screen {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: flex-start;
        gap: 8px;
        padding: 8px 15px;
        width: 95%;
        max-height: 96vh;
    }

    h1 {
        width: 100%;
        font-size: 1.3rem;
        margin: 0 0 5px 0;
    }

    #game-over-container {
        flex: 0 0 40%;
        min-width: 180px;
        max-width: 280px;
        margin: 0;
        padding: 8px;
        font-size: 0.85rem;
    }

    #game-over-title {
        font-size: 1.3rem;
        margin-bottom: 5px;
    }

    .stat-row {
        font-size: 0.85rem;
        margin: 3px 0;
        padding-bottom: 4px;
    }

    .instruction-label {
        font-size: 0.85rem;
        margin: 3px 0;
        width: 100%;
    }

    #username-input {
        width: 45%;
        min-width: 150px;
        padding: 6px 12px;
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    button#play-btn {
        width: 45%;
        min-width: 150px;
        padding: 8px 12px;
        font-size: 1rem;
        margin-bottom: 5px;
    }

    button#skins-menu-btn,
    button#leaderboard-btn,
    button#main-rules-btn {
        width: 30%;
        min-width: 100px;
        padding: 6px 8px;
        font-size: 0.8rem;
        margin: 3px;
    }

    /* Make HUD even smaller in landscape */
    #boss-timer-container {
        top: 40px;
        transform: scale(0.5) translateX(-100%);
    }

    #boss-timer {
        font-size: 2rem;
    }

    #score-board {
        transform: scale(0.6) translateX(-80%);
        gap: 15px;
    }

    #buffs-container {
        bottom: 40px;
        gap: 5px;
    }

    .buff-box {
        padding: 3px 8px;
        font-size: 0.8rem;
        gap: 4px;
    }

    .toast {
        font-size: 0.8rem;
        padding: 4px 20px;
    }

    .credits {
        font-size: 0.65rem;
        margin-top: 5px;
    }
}

/* Skin Preview - Mobile Landscape Fix */
@media (max-height: 500px) and (orientation: landscape) {
    #skin-preview-container {
        height: 80px;
        overflow: hidden;
    }

    #skin-preview-canvas {
        height: 80px !important;
        max-height: 80px;
    }

    .skins-content h2 {
        font-size: 1.2rem;
        margin-bottom: 5px;
    }

    .skin-tabs {
        margin: 5px 0 !important;
    }

    .tab-btn {
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }
}

/* --- LEADERBOARD OVERLAY --- */
#leaderboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 18, 25, 0.95);
    z-index: 1000;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

.leaderboard-content {
    background: #001219;
    border: 2px solid #9B2226;
    padding: 10px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    color: #ddd;
    box-shadow: 0 0 50px rgba(155, 34, 38, 0.15);
    text-align: center;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
}

.leaderboard-content h2 {
    color: #9B2226;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(155, 34, 38, 0.5);
    font-size: 2rem;
    text-transform: uppercase;
}

.lb-scroll-area {
    overflow-y: auto;
    flex: 1;
    /* Take remaining space */
    margin-bottom: 15px;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 5px;
    background: rgba(0, 0, 0, 0.3);
}

/* Custom Scrollbar */
.lb-scroll-area::-webkit-scrollbar {
    width: 8px;
}

.lb-scroll-area::-webkit-scrollbar-track {
    background: #001219;
}

.lb-scroll-area::-webkit-scrollbar-thumb {
    background: #9B2226;
    border-radius: 4px;
}

#lb-full-table {
    width: 100%;
    border-collapse: collapse;
    color: #ccc;
    font-size: 0.9rem;
}

#lb-full-table th {
    position: sticky;
    top: 0;
    background: #001219;
    /* Opaque background for sticky header */
    color: #9B2226;
    padding: 10px 5px;
    text-transform: uppercase;
    font-size: 0.9rem;
    border-bottom: 2px solid #333;
    z-index: 2;
}

#lb-full-table td {
    padding: 8px 5px;
    border-bottom: 1px solid #222;
}

#lb-full-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.rank-col {
    width: 40px;
    font-weight: bold;
    color: #EE9B00;
}

.score-col {
    text-align: right;
    font-weight: bold;
    color: #0A9396;
}

.top-3-row {
    color: #EE9B00;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(238, 155, 0, 0.3);
}

#lb-loading {
    font-size: 1.2rem;
    color: #888;
    margin: 20px 0;
}

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 768px) {

    /* Adjust Start Screen */
    #start-screen {
        min-width: unset;
        width: 90%;
        padding: 15px;
        gap: 5px;
    }

    h1 {
        font-size: 2rem;
    }

    /* Buttons */
    #username-input,
    button#play-btn,
    button#skins-menu-btn,
    button#leaderboard-btn,
    button#main-rules-btn {
        width: 100%;
        /* Use full width of container */
        max-width: unset;
        font-size: 1rem;
        padding: 10px 0;
    }

    /* HUD elements */
    #score-board {
        top: 10px;
    }

    #current-score {
        font-size: 2rem;
    }

    /* Move leaderboards (in-game) down or hide */
    #lb-container {
        transform: scale(0.8);
        transform-origin: top right;
        top: 50px;
    }

    #personal-best-container {
        transform: scale(0.8);
        transform-origin: bottom left;
    }

    #boss-timer {
        font-size: 1.2rem;
    }

    /* Overlays */
    .skins-content,
    .leaderboard-content,
    .rules-content {
        padding: 30px 20px;
        max-height: calc(100% - 60px);
        width: 90%;
        margin: auto;
        box-sizing: border-box;
    }

    .skins-content h2,
    .leaderboard-content h2,
    .rules-content h2 {
        font-size: 1.5rem;
    }

    .skin-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 480px) {
    .skin-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Scale down leaderboard even more on very small screens */
    #lb-container {
        transform: scale(0.55);
        transform-origin: top right;
        top: 5px;
        right: 2px;
    }

    /* Keep All-Time Best hidden on very small screens too */
    #lb-container .lb-box:nth-child(2) {
        display: none;
    }
}

.credits {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    margin-top: 15px;
    font-weight: normal;
    letter-spacing: 1px;
    margin-bottom: 0;
}

.credits a {
    color: white;
    text-decoration: underline dotted;
    font-weight: bold;
}

/* --- NEW SKINS PAGE STYLES --- */
.skin-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.tab-btn {
    background: transparent;
    border: 2px solid #555;
    color: #888;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    transition: 0.2s;
    text-transform: uppercase;
}

.tab-btn:hover {
    border-color: #aaa;
    color: #ccc;
}

.tab-btn.active {
    border-color: #EE9B00;
    color: #EE9B00;
    background: rgba(238, 155, 0, 0.1);
    box-shadow: 0 0 10px rgba(238, 155, 0, 0.2);
}

/* Override Grid to use Main Grid ID and be bigger */

#skins-overlay #main-skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
    align-content: start;
    background: #001219;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #333;
    max-height: none !important;
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
}



/* Larger cards for better visibility */
.skin-card {
    height: 100px;
    border-width: 2px;
}

.skin-preview {
    width: 60px;
    height: 60px;
}

.skin-name {
    font-size: 0.8rem;
    font-weight: bold;
    margin-top: 5px;
}

/* Custom Scrollbar for grid */
#main-skin-grid::-webkit-scrollbar {
    width: 20px;
}

#main-skin-grid::-webkit-scrollbar-track {
    background: #111;
    border-radius: 10px;
    border: 1px solid #333;
}

#main-skin-grid::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 10px;
    border: 3px solid #111;
    /* Padding effect */
}

/* --- NEW MODAL CLOSE BUTTON --- */
.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.8rem;
    color: #888;
    cursor: pointer;
    line-height: 1;
    transition: 0.2s;
    font-weight: bold;
    z-index: 1001;
    /* Ensure on top */
}

.modal-close:hover {
    color: #ff4444;
    transform: scale(1.1);
}

/* Ensure parents are relative for absolute positioning of close button */
.skins-content,
.rules-content,
.leaderboard-content {
    position: relative;
    max-width: 650px;
    /* Slightly wider for better skin grid */
}

/* RESPONSIVE */
@media (max-width: 768px) {
    /* .skins-content override REMOVED to share styles with other modals (border, padding etc) */


    /* Make grid take available space */
    #skins-overlay #main-skin-grid {
        flex: 1;
        max-height: none;
        grid-template-columns: repeat(3, 1fr);
        /* 3 cols on mobile */
        gap: 8px;
    }

    .skin-card {
        height: 80px;
    }

    .skin-preview {
        width: 40px;
        height: 40px;
    }

    .skin-name {
        font-size: 0.7rem;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    #skin-preview-canvas {
        width: 100%;
        height: auto;
        margin-top: 20px;
    }

    /* Hide the old grid scrollbar on mobile if native feels better, 
       but keeping custom is usually fine for Games feel */
}

/* --- TUTORIAL OVERLAY --- */


@media (max-width: 768px) {


    /* Fixed HUD consistency for mobile */
    .hud-stat {
        flex-direction: column-reverse;
    }

    #current-score,
    #current-kills {
        font-size: 2rem;
        /* Ensure consistent size */
    }

    .hud-label {
        font-size: 0.7rem;
    }

    #score-board {
        gap: 20px;
        top: 10px;
    }

    #boss-timer {
        font-size: 1.5rem;
    }

    /* Reduce font size / stack layout for stats page on mobile */
    .stats-container {
        grid-template-columns: 1fr;
        /* Stack vertically */
    }
}

/* IN-GAME WATERMARK */
#ingame-watermark {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1rem;
    font-weight: 900;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 0 10px rgba(10, 147, 150, 0.4);
    pointer-events: none;
    z-index: 100;
    opacity: 0.8;
}

.watermark-part {
    color: #0A9396
}

/* --- RESPONSIVE FIXES FOR MENU LAYOUT --- */
#menu-controls {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
    align-items: center;
    /* Center children */
}

/* Landscape Mobile / Small Tablets - Better range for tablets/large phones */
@media screen and (max-height: 650px) and (min-height: 501px) and (orientation: landscape) {
    #start-screen {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: flex-start;
        width: 90%;
        max-width: 900px;
        min-width: 0;
        padding: 10px 20px;
        max-height: 96vh;
        gap: 8px;
    }

    #start-screen h1 {
        width: 100%;
        flex-basis: 100%;
        margin-bottom: 8px;
        font-size: 1.6rem;
    }

    /* Game over stats on the left (if visible) */
    #game-over-container {
        flex: 0 0 42%;
        width: 42%;
        margin: 0 10px 0 0;
        padding: 10px;
        min-width: 200px;
        box-sizing: border-box;
    }

    /* Controls on the right */
    #menu-controls {
        flex: 1;
        min-width: 250px;
        gap: 6px;
        margin-left: auto;
        margin-right: auto;
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    /* Shrink controls to fit vertical space nicely */
    #menu-controls input,
    #menu-controls button {
        margin-bottom: 4px !important;
        padding: 8px 0 !important;
        font-size: 0.95rem !important;
        width: 100% !important;
    }

    .instruction-label {
        font-size: 0.9rem;
        margin-top: 0;
        margin-bottom: 5px;
    }

    /* Scale down HUD for medium landscape */
    #boss-timer-container {
        transform: scale(0.65) translateX(-75%);
    }

    #lb-container {
        transform: scale(0.7);
        transform-origin: top right;
    }
}

/* Loading Screen */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #001219;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Arial', sans-serif;
    transition: opacity 0.5s ease-out;
}

.loading-content {
    text-align: center;
}

.loading-content h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    letter-spacing: 2px;
    background: linear-gradient(45deg, #FF0000, #FFD700);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 0px 20px rgba(255, 0, 0, 0.5);
    animation: pulse 1.5s infinite;
}

.loader {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top: 5px solid #FFD700;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 0.8;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.05);
    }

    100% {
        opacity: 0.8;
        transform: scale(1);
    }
}