:root {
    --platform-h: 50px;
    --bg: #0b0b0b;
}

html,
body {
    height: 100%;
    margin: 0;
    background: #000;
    overflow: hidden;
    font-family: 'Press Start 2P', monospace, Arial, sans-serif;
    -webkit-user-select: none;
    user-select: none;
}

#gameRoot {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    overflow: hidden;
    transform-origin: top left;
}

#game {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
    touch-action: none;
}

#bgCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    z-index: 0;
}

#particleCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 11;
    pointer-events: none;
}

#player {
    position: absolute;
    width: 100px;
    height: 100px;
    z-index: 5;
    top: 50%;
    left: 50px;
    /* border: 1px solid red; */
    /* debug */
}

/* Inner visual for sprite handling (separates rotation from flip) */
#playerVisual {
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: contain;
    /* Transition for smooth rotation */
    transition: transform 0.1s linear;
}

.sky {
    position: absolute;
    inset: 0;
    background-repeat: repeat-x;
    background-size: auto 100%;
    will-change: background-position, opacity;
    transition: opacity 900ms ease;
    z-index: 0;
}

.sky.bot {
    z-index: 0;
    opacity: 1;
}

.sky.top {
    z-index: 1;
    opacity: 0;
}

#ground,
#ceiling {
    position: absolute;
    left: 0;
    width: 200%;
    height: var(--platform-h);
    background-repeat: repeat-x;
    background-size: auto 100%;
    z-index: 5;
    image-rendering: pixelated;
    will-change: background-position;
}

#ground {
    bottom: 0;
}

#ceiling {
    top: 0;
    transform: scaleY(-1);
}

#player {
    position: absolute;
    z-index: 12;
    image-rendering: pixelated;
    background-repeat: no-repeat;
    pointer-events: none;
    will-change: left, top, transform, background-position, background-size;
    display: none;
}

/* playerVisual handles rotation */
#playerVisual.jumping {
    animation: none;
    background-size: contain;
}

#playerVisual.dead {
    animation: none;
    background-size: contain;
    display: block;
}

.obstacle {
    position: absolute;
    z-index: 10;
    background-repeat: no-repeat;
    background-size: contain;
    image-rendering: pixelated;
    pointer-events: none;
    will-change: left, top, transform;
}

.obstacle.flip {
    transform: scaleY(-1);
}

.ninja-star {
    animation: spin 1s linear infinite;
    transform-origin: center;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Player Animations */
@keyframes roll {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes roll-reverse {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(-360deg);
    }
}

#playerVisual.rolling {
    animation: roll 0.6s linear infinite;
}

#playerVisual.rolling.ceiling {
    animation: roll-reverse 0.6s linear infinite;
}

#ui {
    position: absolute;
    top: 5px;
    left: 20px;
    z-index: 60;
    color: #fff;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
}

#score {
    font-size: clamp(24px, 6vw, 42px);
    color: #FFD700;
    text-shadow: 4px 4px 0 #000, 2px 2px 0 #8B4513, -1px -1px 0 #FFA500;
    font-family: 'Press Start 2P', monospace;
    image-rendering: pixelated;
    letter-spacing: 2px;
    animation: scoreGlow 2s ease-in-out infinite;
}

@keyframes scoreGlow {

    0%,
    100% {
        text-shadow: 4px 4px 0 #000, 2px 2px 0 #8B4513, -1px -1px 0 #FFA500;
    }

    50% {
        text-shadow: 4px 4px 0 #000, 2px 2px 0 #8B4513, -1px -1px 0 #FFA500, 0 0 10px #FFD700;
    }
}

#high {
    font-size: clamp(8px, 1.5vw, 11px);
    color: #FFF;
    text-shadow: 2px 2px 0 #000;
    font-family: 'Press Start 2P', monospace;
    background: rgba(0, 0, 0, 0.6);
    padding: clamp(6px, 1vw, 8px) clamp(8px, 1.5vw, 12px);
    border: 2px solid #34495e;
    border-radius: 4px;
}

#controls {
    position: absolute;
    top: 5px;
    right: 20px;
    z-index: 90;
    display: flex;
    flex-direction: row;
    gap: 10px;
}

#bmcBtn {
    background: linear-gradient(180deg, #FFDD00 0%, #FFB800 100%);
    color: #000;
    border: 4px solid #FFB800;
    padding: clamp(6px, 1.5vw, 10px);
    width: clamp(40px, 8vw, 50px);
    height: clamp(40px, 8vw, 50px);
    cursor: pointer;
    box-shadow: 4px 4px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    text-decoration: none;
    box-sizing: border-box;
    flex-shrink: 0;
}

#bmcBtn:hover {
    background: linear-gradient(180deg, #FFE44D 0%, #FFDD00 100%);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

#bmcBtn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #000, inset 0 -2px 0 rgba(0, 0, 0, 0.2);
    background: linear-gradient(180deg, #FFB800 0%, #FF9500 100%);
}

#bmcBtn img {
    height: clamp(14px, 3vw, 18px);
    width: clamp(14px, 3vw, 18px);
    filter: drop-shadow(1px 1px 0 #000);
    display: block;
}

#settingsBtn,
#helpBtn,
#statsBtn {
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    color: #fff;
    border: 4px solid #34495e;
    padding: clamp(6px, 1.5vw, 10px);
    width: clamp(40px, 8vw, 50px);
    height: clamp(40px, 8vw, 50px);
    cursor: pointer;
    font-size: clamp(18px, 4vw, 24px);
    box-shadow: 4px 4px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.1s;
    image-rendering: pixelated;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', monospace;
    font-weight: bold;
    position: relative;
}

#settingsBtn:hover,
#helpBtn:hover,
#statsBtn:hover {
    background: linear-gradient(180deg, #3d5a6e 0%, #34495e 100%);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

#settingsBtn:active,
#helpBtn:active,
#statsBtn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #000, inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
}

#settingsPanel,
#helpPanel,
#statsPanel {
    position: absolute;
    top: 70px;
    right: 0;
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    border: 4px solid #34495e;
    box-shadow: 8px 8px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.1);
    padding: 20px;
    display: none;
    min-width: 250px;
    max-width: 350px;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#settingsPanel.show,
#helpPanel.show,
#statsPanel.show {
    display: block;
}

#settingsPanel h3,
#helpPanel h3,
#statsPanel h3,
#leaderboardPanel h3 {
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #FFD700;
    font-size: 11px;
    color: #FFD700;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #FFA500;
    font-family: 'Press Start 2P', monospace;
    letter-spacing: 1px;
    text-align: center;
}

.stat-item {
    margin: 12px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #34495e;
}

.stat-item label {
    font-size: 9px;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    font-family: 'Press Start 2P', monospace;
}

.stat-item span {
    font-size: 10px;
    color: #FFD700;
    text-shadow: 1px 1px 0 #000;
    font-family: 'Press Start 2P', monospace;
    font-weight: bold;
}

.setting-item {
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-item label {
    font-size: 10px;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
    font-family: 'Press Start 2P', monospace;
    flex: 1;
}

.setting-btn {
    background: linear-gradient(180deg, #e74c3c 0%, #c0392b 100%);
    color: #fff;
    border: 3px solid #c0392b;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 9px;
    box-shadow: 3px 3px 0 #000, inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.1s;
    font-family: 'Press Start 2P', monospace;
    min-width: 50px;
}

.setting-btn:hover {
    background: linear-gradient(180deg, #ff5544 0%, #e74c3c 100%);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #000, inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.setting-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 #000, inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}

.setting-btn.active {
    background: linear-gradient(180deg, #27ae60 0%, #229954 100%);
    border-color: #229954;
}

.help-section {
    margin: 15px 0;
    padding: 10px 0;
    border-top: 2px solid #34495e;
}

.help-section:first-of-type {
    border-top: none;
    margin-top: 0;
}

.help-label {
    font-size: 10px;
    color: #FFD700;
    text-shadow: 2px 2px 0 #000;
    font-family: 'Press Start 2P', monospace;
    margin: 0 0 8px 0;
}

.help-section p {
    font-size: 9px;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    font-family: 'Press Start 2P', monospace;
    margin: 5px 0;
    line-height: 1.6;
}

.help-section a {
    color: #FFD700;
    text-decoration: none;
    word-break: break-all;
}

.help-section a:hover {
    color: #FFA500;
}

a.bmc-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #FFDD00 !important;
    color: #000000 !important;
    text-decoration: none;
    padding: 12px 28px;
    border-radius: 12px;
    border: 2px solid #000000;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    font-family: 'Lato', Arial, sans-serif !important;
    font-size: 16px;
    font-weight: 700;
    transition: all 0.2s ease;
    line-height: 1;
    margin-top: 10px;
    word-break: normal !important;
}

a.bmc-button:hover {
    background: #FFE44D !important;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
    color: #000000 !important;
}

a.bmc-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.bmc-logo {
    height: 28px;
    width: 28px;
    margin: 0;
    display: block;
}

.bmc-button-text {
    color: #000000 !important;
    font-weight: 700;
}

.overlay {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.85);
}

.card {
    pointer-events: auto;
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    color: #fff;
    padding: clamp(20px, 4vw, 35px) clamp(25px, 5vw, 40px);
    border: clamp(4px, 0.8vw, 6px) solid #34495e;
    box-shadow: 12px 12px 0 #000, inset 0 4px 0 rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: min(500px, 90vw);
    position: relative;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent, #FFD700, transparent);
    opacity: 0.5;
}

.card h2 {
    font-size: clamp(18px, 4vw, 28px);
    margin: 0 0 clamp(12px, 2vw, 20px) 0;
    color: #FFD700;
    text-shadow: 4px 4px 0 #000, -1px -1px 0 #FFA500;
    font-family: 'Press Start 2P', monospace;
    line-height: 1.5;
    letter-spacing: 2px;
}

.card p {
    font-size: clamp(9px, 1.5vw, 11px);
    margin: clamp(8px, 1.5vw, 12px) 0;
    line-height: 1.8;
    font-family: 'Press Start 2P', monospace;
    color: #ecf0f1;
    text-shadow: 1px 1px 0 #000;
}

.card .btn {
    margin-top: clamp(15px, 3vw, 25px);
    background: linear-gradient(180deg, #e74c3c 0%, #c0392b 100%);
    color: #fff;
    border: clamp(3px, 0.6vw, 4px) solid #c0392b;
    padding: clamp(10px, 2vw, 15px) clamp(20px, 4vw, 35px);
    cursor: pointer;
    font-size: clamp(11px, 1.8vw, 13px);
    box-shadow: 6px 6px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.1s;
    font-family: 'Press Start 2P', monospace;
    letter-spacing: 1px;
}

.card .btn:hover {
    background: linear-gradient(180deg, #ff5544 0%, #e74c3c 100%);
    transform: translate(-2px, -2px);
    box-shadow: 8px 8px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.card .btn:active {
    transform: translate(2px, 2px);
    box-shadow: 4px 4px 0 #000, inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    background: linear-gradient(180deg, #c0392b 0%, #a02818 100%);
}

#startOverlay {
    display: flex;
}

#gameOverOverlay {
    display: none;
    pointer-events: auto;
}

@keyframes shake {
    0% {
        transform: translateX(0)
    }

    20% {
        transform: translateX(-8px)
    }

    40% {
        transform: translateX(8px)
    }

    60% {
        transform: translateX(-6px)
    }

    80% {
        transform: translateX(4px)
    }

    100% {
        transform: translateX(0)
    }
}

.shake {
    animation: shake 360ms ease-in-out;
}

#debug {
    position: absolute;
    bottom: 12px;
    left: 12px;
    z-index: 120;
    color: #0f0;
    background: rgba(0, 0, 0, 0.8);
    padding: 6px 8px;
    border: 2px solid #0f0;
    font-size: 10px;
    display: none;
    font-family: 'Press Start 2P', monospace;
}

.bmc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #FFDD00;
    color: #000000;
    text-decoration: none;
    padding: 10px 24px;
    border-radius: 8px;
    border: 2px solid #000000;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
    transition: all 0.2s ease;
    line-height: 1;
}

.bmc-btn:hover {
    background: #FFE44D;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.bmc-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.bmc-btn img {
    height: 24px;
    width: 24px;
}

/* Leaderboard Styles */
#leaderboardBtn {
    background: linear-gradient(180deg, #f39c12 0%, #e67e22 100%);
    color: #fff;
    border: 4px solid #e67e22;
    padding: clamp(6px, 1.5vw, 10px);
    width: clamp(40px, 8vw, 50px);
    height: clamp(40px, 8vw, 50px);
    cursor: pointer;
    font-size: clamp(18px, 4vw, 24px);
    box-shadow: 4px 4px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.1s;
    image-rendering: pixelated;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', monospace;
    font-weight: bold;
    position: relative;
}

#leaderboardBtn:hover {
    background: linear-gradient(180deg, #f5ab35 0%, #f39c12 100%);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000, inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

#leaderboardBtn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #000, inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    background: linear-gradient(180deg, #e67e22 0%, #d35400 100%);
}

#leaderboardPanel {
    position: absolute;
    top: 70px;
    right: 0;
    background: linear-gradient(165deg, #2c3e50 0%, #1a252f 100%);
    border: 4px solid #34495e;
    border-radius: 0 0 0 12px;
    box-shadow: -8px 8px 24px rgba(0, 0, 0, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.08);
    padding: 20px;
    display: none;
    min-width: 320px;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideDown 0.2s ease-out;
}

#leaderboardPanel.show {
    display: block;
}

.username-section {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

#usernameInput {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #34495e;
    color: #fff;
    padding: 8px;
    font-size: 9px;
    font-family: 'Press Start 2P', monospace;
    outline: none;
}

#usernameInput:focus {
    border-color: #FFD700;
}

.current-user {
    font-size: 8px;
    color: #ecf0f1;
    text-shadow: 1px 1px 0 #000;
    margin-bottom: 12px;
    text-align: center;
    font-family: 'Press Start 2P', monospace;
}

.current-user span {
    color: #FFD700;
    font-weight: bold;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.tab-btn {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #34495e;
    color: #fff;
    padding: 8px;
    font-size: 8px;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
    transition: all 0.1s;
}

.tab-btn:hover {
    background: rgba(0, 0, 0, 0.5);
}

.tab-btn.active {
    background: linear-gradient(180deg, #f39c12 0%, #e67e22 100%);
    border-color: #e67e22;
    color: #fff;
}

.leaderboard-date {
    font-size: 8px;
    color: #95a5a6;
    text-align: center;
    margin-bottom: 12px;
    font-family: 'Press Start 2P', monospace;
}

.leaderboard-list {
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid #34495e;
    border-radius: 6px;
    padding: 12px;
    min-height: 200px;
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin: 5px 0;
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid #34495e;
    border-radius: 4px;
    font-size: 9px;
    font-family: 'Press Start 2P', monospace;
    transition: all 0.15s ease;
}

.leaderboard-entry:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 215, 0, 0.6);
    transform: translateX(2px);
}

.leaderboard-entry.current-user-entry {
    border-color: #27ae60;
    background: rgba(39, 174, 96, 0.25);
    box-shadow: 0 0 8px rgba(39, 174, 96, 0.3);
}

.leaderboard-entry.top-1 {
    border-color: #FFD700;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 193, 7, 0.1) 100%);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.25);
}

.leaderboard-entry.top-2 {
    border-color: #C0C0C0;
    background: rgba(192, 192, 192, 0.12);
}

.leaderboard-entry.top-3 {
    border-color: #CD7F32;
    background: rgba(205, 127, 50, 0.12);
}

.entry-rank {
    min-width: 36px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 1px 1px 0 #000;
    font-size: 9px;
}

.entry-rank.rank-1 {
    color: #FFD700;
    font-size: 10px;
}

.entry-rank.rank-2 {
    color: #C0C0C0;
}

.entry-rank.rank-3 {
    color: #CD7F32;
}

.entry-username {
    flex: 1;
    color: #ecf0f1;
    text-shadow: 1px 1px 0 #000;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-score {
    color: #2ecc71;
    font-weight: bold;
    text-shadow: 1px 1px 0 #000;
    font-size: 10px;
}

.entry-time {
    font-size: 7px;
    color: #95a5a6;
    margin-left: auto;
}

.leaderboard-actions {
    display: flex;
    gap: 8px;
}

.leaderboard-actions .setting-btn {
    flex: 1;
    font-size: 8px;
    padding: 10px;
}

.leaderboard-info {
    font-size: 7px;
    color: #95a5a6;
    text-align: center;
    margin-top: 10px;
    font-family: 'Press Start 2P', monospace;
    line-height: 1.4;
}

.loading {
    text-align: center;
    color: #95a5a6;
    font-size: 9px;
    padding: 20px;
    font-family: 'Press Start 2P', monospace;
}

.error-message {
    text-align: center;
    color: #e74c3c;
    font-size: 8px;
    padding: 15px;
    font-family: 'Press Start 2P', monospace;
    line-height: 1.5;
}

.empty-leaderboard {
    text-align: center;
    color: #95a5a6;
    font-size: 8px;
    padding: 20px;
    font-family: 'Press Start 2P', monospace;
    line-height: 1.6;
}

/* Username Prompt on Start Screen */
.username-prompt {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
    width: 100%;
}

#startUsernameInput {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #FFD700;
    color: #fff;
    padding: 12px;
    font-size: 10px;
    font-family: 'Press Start 2P', monospace;
    outline: none;
    text-align: center;
}

#startUsernameInput:focus {
    border-color: #FFA500;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

#saveStartUsername {
    margin-top: 5px;
}

.username-prompt.hidden {
    display: none;
}

/* Game Over Buttons */
.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px dashed #666;
}

.game-over-buttons .btn {
    width: 100%;
    margin: 0;
}

.btn-secondary {
    background: linear-gradient(180deg, #f39c12 0%, #e67e22 100%);
    border-color: #e67e22;
}

.btn-secondary:hover {
    background: linear-gradient(180deg, #f5ab35 0%, #f39c12 100%);
}

.btn-secondary:active {
    background: linear-gradient(180deg, #e67e22 0%, #d35400 100%);
}

/* Settings Username Edit */
.username-edit-section {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #34495e;
}

.username-edit-controls {
    display: flex;
    gap: 8px;
    margin: 10px 0;
}

#settingsUsernameInput {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #34495e;
    color: #fff;
    padding: 8px;
    font-size: 9px;
    font-family: 'Press Start 2P', monospace;
    outline: none;
}

#settingsUsernameInput:focus {
    border-color: #FFD700;
}

.current-username-display {
    font-size: 8px;
    color: #ecf0f1;
    text-shadow: 1px 1px 0 #000;
    margin-top: 8px;
    font-family: 'Press Start 2P', monospace;
}

/* Leaderboard Actions - 3 buttons */
.leaderboard-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.leaderboard-actions .setting-btn {
    flex: 1;
    font-size: 8px;
    padding: 10px 8px;
}

.leaderboard-entry.user-preview {
    border-color: #3498db;
    background: rgba(52, 152, 219, 0.2);
    border-style: dashed;
}

/* Daily Rank on Game Over */
#dailyRankText {
    font-family: 'Press Start 2P', monospace;
    text-shadow: 2px 2px 0 #000;
}

/* Username Edit Icon in Settings */
.username-display-edit {
    display: flex;
    align-items: center;
    gap: 10px;
}

.edit-icon-btn {
    background: transparent;
    border: 2px solid #FFD700;
    color: #FFD700;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    font-family: 'Press Start 2P', monospace;
}

.edit-icon-btn:hover {
    background: #FFD700;
    color: #000;
    transform: scale(1.1);
}

/* Username Edit Modal */
.username-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.username-modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    border: 4px solid #FFD700;
    padding: 25px;
    min-width: 300px;
    box-shadow: 8px 8px 0 #000;
}

.modal-content h4 {
    margin: 0 0 15px 0;
    color: #FFD700;
    font-size: 11px;
    text-align: center;
    font-family: 'Press Start 2P', monospace;
    text-shadow: 2px 2px 0 #000;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.modal-buttons .setting-btn {
    flex: 1;
}

/* Leaderboard Pagination */
.leaderboard-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #34495e;
    margin-bottom: 12px;
}

.page-btn {
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    color: #fff;
    border: 2px solid #34495e;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 8px;
    font-family: 'Press Start 2P', monospace;
    transition: all 0.1s;
}

.page-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #3d5a6e 0%, #34495e 100%);
    transform: translateY(-2px);
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    font-size: 9px;
    color: #FFD700;
    font-family: 'Press Start 2P', monospace;
    text-shadow: 1px 1px 0 #000;
}

/* Game Over Leaderboard - Full Page */
.game-over-leaderboard-full {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: linear-gradient(165deg, #1a1a2e 0%, #16213e 35%, #0f3460 70%, #1a1a2e 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: clamp(20px, 4vw, 40px);
    box-sizing: border-box;
    pointer-events: auto;
}

.game-over-leaderboard-inner {
    width: 100%;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.close-leaderboard-btn {
    align-self: flex-end;
    background: rgba(231, 76, 60, 0.9);
    color: #fff;
    border: 3px solid #c0392b;
    padding: 12px 20px;
    cursor: pointer;
    font-size: clamp(10px, 1.5vw, 12px);
    font-family: 'Press Start 2P', monospace;
    box-shadow: 4px 4px 0 #000;
    transition: all 0.15s;
    margin-bottom: 15px;
}

.close-leaderboard-btn:hover {
    background: #e74c3c;
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000;
}

.leaderboard-full-title {
    font-size: clamp(22px, 4vw, 36px);
    color: #FFD700;
    text-shadow: 4px 4px 0 #000;
    margin: 0 0 8px 0;
    font-family: 'Press Start 2P', monospace;
    letter-spacing: 4px;
    text-align: center;
}

.game-over-rank-big {
    font-size: clamp(12px, 2vw, 18px);
    color: #FFD700;
    text-align: center;
    margin: 0 0 12px 0;
    font-family: 'Press Start 2P', monospace;
    text-shadow: 2px 2px 0 #000;
}

.leaderboard-date-full {
    font-size: clamp(9px, 1.2vw, 12px);
    color: #95a5a6;
    text-align: center;
    margin: 0 0 20px 0;
    font-family: 'Press Start 2P', monospace;
}

.leaderboard-list-full {
    flex: 1;
    min-height: 260px;
    max-height: min(70vh, 520px);
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.35);
    border: 3px solid rgba(255, 215, 0, 0.4);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.leaderboard-list-full .leaderboard-entry {
    padding: 10px 14px;
    font-size: clamp(8px, 1.2vw, 12px);
    border-radius: 6px;
    gap: 12px;
}

.leaderboard-list-full .entry-rank {
    min-width: 52px;
    font-size: clamp(10px, 1.4vw, 14px);
}

.leaderboard-list-full .entry-username {
    font-size: clamp(9px, 1.3vw, 13px);
}

.leaderboard-list-full .entry-score {
    font-size: clamp(10px, 1.4vw, 14px);
}

.full-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #34495e;
    border-radius: 8px;
}

.full-pagination .page-btn {
    padding: 12px 20px;
    font-size: clamp(9px, 1.2vw, 11px);
}

.full-pagination .page-info {
    font-size: clamp(10px, 1.3vw, 13px);
}

.leaderboard-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.header-spacer {
    width: clamp(40px, 8vw, 50px);
}

.back-btn {
    background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
    color: #fff;
    border: 3px solid #34495e;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 10px;
    font-family: 'Press Start 2P', monospace;
    box-shadow: 3px 3px 0 #000;
    transition: all 0.1s;
}

.back-btn:hover {
    background: linear-gradient(180deg, #3d5a6e 0%, #34495e 100%);
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 #000;
}

.back-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 #000;
}

.leaderboard-header h2 {
    text-align: center;
    margin: 0;
}

/* Connection Status */
.connection-status {
    font-size: 8px;
    color: #95a5a6;
    text-align: center;
    margin-bottom: 10px;
    font-family: 'Press Start 2P', monospace;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.connection-status.connected {
    color: #27ae60;
}

.connection-status.disconnected {
    color: #e74c3c;
}

/* User rank highlight separator */
.user-rank-separator {
    border-top: 3px dashed #27ae60;
    margin: 8px 0;
}

/* Event Mode Styles - Polished */
#startBtn.pulse {
    animation: pulse 1.5s infinite;
    font-size: 1.5rem;
    background: #e74c3c;
    border: 4px solid #c0392b;
    box-shadow: 0 0 15px #e74c3c;
    text-shadow: 2px 2px 0 #000;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 25px rgba(231, 76, 60, 0.9);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
    }
}

#eventInputSection {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

#eventInputSection p {
    font-size: clamp(9px, 1.5vw, 11px);
    color: #bdc3c7;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
    font-family: 'Press Start 2P', monospace;
}

#gameOverUsernameInput {
    font-family: 'Press Start 2P', monospace;
    padding: clamp(10px, 2vw, 15px);
    font-size: clamp(10px, 2vw, 14px);
    text-align: center;
    border: 3px solid #f1c40f;
    background: #2c3e50;
    color: #ecf0f1;
    width: 90%;
    max-width: 250px;
    border-radius: 4px;
    outline: none;
    text-transform: uppercase;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.3);
}

#gameOverUsernameInput::placeholder {
    color: #7f8c8d;
    font-size: clamp(8px, 1.5vw, 10px);
}

#gameOverUsernameInput:focus {
    border-color: #FFA500;
    box-shadow: 0 0 15px rgba(255, 165, 0, 0.5);
}

#submitScoreBtn,
#viewLeaderboardBtn {
    width: 90%;
    max-width: 250px;
    font-size: clamp(10px, 1.8vw, 12px);
    padding: clamp(10px, 2vw, 15px);
    background: linear-gradient(180deg, #27ae60 0%, #229954 100%);
    border: 3px solid #2ecc71;
    color: white;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 0 #1e8449;
    transition: all 0.1s;
    border-radius: 4px;
    font-family: 'Press Start 2P', monospace;
    letter-spacing: 1px;
}

#submitScoreBtn:hover,
#viewLeaderboardBtn:hover {
    background: linear-gradient(180deg, #2ecc71 0%, #27ae60 100%);
    transform: translate(-2px, -2px);
    box-shadow: 0 6px 0 #1e8449;
}

#submitScoreBtn:active,
#viewLeaderboardBtn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1e8449;
}

#submitScoreBtn:disabled,
#viewLeaderboardBtn:disabled {
    background: linear-gradient(180deg, #7f8c8d 0%, #95a5a6 100%);
    border-color: #95a5a6;
    box-shadow: 0 2px 0 #6c7b7d;
    cursor: not-allowed;
    opacity: 0.7;
}

#viewLeaderboardBtn {
    background: linear-gradient(180deg, #3498db 0%, #2980b9 100%);
    border-color: #3498db;
    box-shadow: 0 4px 0 #1f4e79;
}

#viewLeaderboardBtn:hover {
    background: linear-gradient(180deg, #5dade2 0%, #3498db 100%);
    box-shadow: 0 6px 0 #1f4e79;
}

#restartBtn2 {
    font-size: clamp(9px, 1.5vw, 11px);
    color: #95a5a6;
    background: transparent;
    border: 2px solid #95a5a6;
    padding: clamp(8px, 1.5vw, 12px) clamp(16px, 3vw, 24px);
    border-radius: 20px;
    text-decoration: none;
    margin-top: 15px;
    opacity: 0.7;
    transition: all 0.2s;
    font-family: 'Press Start 2P', monospace;
    cursor: pointer;
}

#restartBtn2:hover {
    opacity: 1;
    color: white;
    border-color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Character selection on start screen */
.character-selection {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 20px 0;
}

.character-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.4);
    border: 3px solid #34495e;
    color: #ecf0f1;
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    transition: all 0.15s;
}

.character-option:hover {
    border-color: #f39c12;
    background: rgba(243, 156, 18, 0.15);
}

.character-option.selected {
    border-color: #FFD700;
    background: rgba(255, 215, 0, 0.2);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

.char-preview {
    width: 80px;
    height: 80px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.char-name {
    text-align: center;
    line-height: 1.4;
}