* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0c0a08;
    margin: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, sans-serif;
    color: #e0e0e0;
    transition: background 1s;
}

canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
}

#backBtn {
    position: fixed;
    top: 14px;
    left: 16px;
    z-index: 20;
    color: rgba(255,255,255,0.35);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 2px;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.2s;
}

#backBtn:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

#ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
}

#score {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 30px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    opacity: 0;
    transition: opacity 0.3s;
}

#score.visible { opacity: 1; }

#gems {
    position: absolute;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    font-weight: 600;
    color: #ffcc00;
    opacity: 0;
    transition: opacity 0.3s;
    font-variant-numeric: tabular-nums;
}

#gems.visible { opacity: 1; }

#gemIcon { color: #ffcc00; font-size: 14px; }

#coinBank {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 14px;
    font-weight: 600;
    color: #ffcc00;
    opacity: 0;
    transition: opacity 0.3s;
}
#coinBank.visible { opacity: 1; }

#highscore {
    position: absolute;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    color: #99a;
    opacity: 0;
    transition: opacity 0.3s;
}

#highscore.visible { opacity: 1; }

#jumpBar {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 6px;
    background: #1a1a2e;
    border-radius: 3px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s;
}

#jumpBar.visible { opacity: 1; }

#jumpFill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #44ddff, #88eeff);
    border-radius: 3px;
    transition: width 0.1s;
}

#phaseLabel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 4px;
    color: rgba(255,255,255,0.5);
    opacity: 0;
    transition: opacity 0.6s;
    pointer-events: none;
    text-transform: uppercase;
}

#phaseLabel.visible { opacity: 1; }

#coinWarning {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    color: #ff4444;
    opacity: 0;
    transition: opacity 0.3s;
    text-shadow: 0 0 10px rgba(255,0,0,0.5);
    animation: pulse-warn 0.5s ease-in-out infinite alternate;
    pointer-events: none;
}
#coinWarning.visible { opacity: 1; }
@keyframes pulse-warn {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.08); }
}

/* --- Overlays --- */
#overlay, #deathOverlay, #lobbyOverlay, #shopOverlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.75);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
    z-index: 10;
}

#overlay.visible, #deathOverlay.visible, #lobbyOverlay.visible, #shopOverlay.visible {
    opacity: 1;
    pointer-events: auto;
}

#overlay {
    justify-content: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

#overlay h1, #deathOverlay h1, #lobbyOverlay h1, #shopOverlay h1 {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: 8px;
    margin-bottom: 12px;
    text-shadow: 0 2px 20px rgba(0,0,0,0.3);
}

#deathOverlay h1 { color: #ff6666; }
#lobbyOverlay h1 { color: #44ddff; }
#shopOverlay h1 { color: #ffcc00; }

#overlay p, #deathOverlay p, #lobbyOverlay p, #shopOverlay p {
    font-size: 16px;
    color: #ccd;
    margin-bottom: 8px;
}

.controls {
    font-size: 13px !important;
    color: #aab !important;
    margin-bottom: 20px !important;
}

.gold { color: #ffcc00; }

/* Buttons */
button {
    margin-top: 8px;
    padding: 12px 40px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    color: #fff;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.6);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: auto;
}

button:hover {
    background: rgba(255,255,255,0.95);
    color: #2a5090;
    border-color: #fff;
}

.subtle-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    font-size: 13px;
    padding: 8px 20px;
    color: #99a;
    letter-spacing: 2px;
    margin-top: 16px;
}
.subtle-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

#menuButtons {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

#menuButtons button {
    min-width: 140px;
}

#multiBtn { border-color: #44ddff; color: #44ddff; }
#multiBtn:hover { background: #44ddff; color: #000; }
#shopBtn { border-color: #ffcc00; color: #ffcc00; }
#shopBtn:hover { background: #ffcc00; color: #000; }

/* Mode Selector */
#modeSelector {
    margin-top: 12px;
    text-align: center;
}

.mode-toggle-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: #778;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 6px 18px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}
.mode-toggle-btn:hover {
    color: #bbc;
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.05);
}
.mode-toggle-btn.open {
    color: #44ff88;
    border-color: rgba(68,255,136,0.3);
}

#extraModes {
    margin-top: 10px;
}

#modeButtons {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.12);
    color: #aaa;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}

.mode-btn .mode-desc {
    display: block;
    font-size: 9px;
    font-weight: 400;
    color: #556;
    margin-top: 2px;
}

.mode-btn:hover {
    border-color: rgba(255,255,255,0.3);
    color: #ddd;
    background: rgba(255,255,255,0.08);
}

.mode-btn.active {
    border-color: #44ff88;
    color: #44ff88;
    background: rgba(68,255,136,0.08);
}

.mode-btn.active .mode-desc {
    color: #44ff88aa;
}

/* Lobby */
#lobbyRow {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

#createBtn { border-color: #44ff88; color: #44ff88; padding: 8px 16px; font-size: 14px; }
#createBtn:hover { background: #44ff88; color: #000; }

#lobbyPlayers {
    margin-top: 12px;
    min-height: 30px;
    max-width: 300px;
    width: 100%;
}

.lobby-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 14px;
}

.lobby-player .lp-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.lobby-player .lp-name {
    flex: 1;
    font-weight: 600;
    letter-spacing: 1px;
}

.lobby-player .lp-host {
    font-size: 10px;
    letter-spacing: 1px;
    color: #ffcc00;
    font-weight: 700;
}

#startGameBtn:hover { background: #44ff88; color: #000; }

#roomInput {
    padding: 8px 16px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: rgba(255,255,255,0.08);
    border: 1px solid #444;
    border-radius: 4px;
    text-align: center;
    outline: none;
    width: 160px;
    text-transform: uppercase;
}
#roomInput:focus { border-color: #44ddff; }

#lobbyStatus {
    margin-top: 12px;
    font-size: 14px;
    color: #44ddff;
    min-height: 20px;
}

/* Shop */
#shopCoins {
    font-size: 22px !important;
    color: #ffcc00 !important;
    font-weight: 700;
    margin-bottom: 16px !important;
}

#shopGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    max-width: 560px;
    width: 90%;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
}

.shop-item {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.shop-item:hover {
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
}

.shop-item.owned {
    border-color: rgba(68,221,255,0.3);
}

.shop-item.active {
    border-color: #ffcc00;
    background: rgba(255,204,0,0.1);
}

.shop-item .preview {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin: 0 auto 8px;
    border: 2px solid rgba(255,255,255,0.2);
}

.shop-item .item-name {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.shop-item .item-price {
    font-size: 11px;
    color: #ffcc00;
}

.shop-item .item-price.free { color: #44ff88; }
.shop-item .item-price.equipped { color: #44ddff; }

/* Death overlay extras */
#finalScore {
    font-size: 34px !important;
    color: #fff !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#finalGems {
    font-size: 18px !important;
    color: #ffcc00 !important;
    font-weight: 600;
}

#coinsEarned {
    font-size: 14px !important;
    color: #ffcc00 !important;
}

#newHighScore {
    color: #ffcc00 !important;
    font-size: 14px !important;
    height: 20px;
}

#mpResult {
    font-size: 18px !important;
    font-weight: 700;
    min-height: 24px;
}

#nameInput, #deathNameInput {
    margin-top: 10px;
    padding: 8px 16px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: rgba(255,255,255,0.08);
    border: 1px solid #444;
    border-radius: 4px;
    text-align: center;
    outline: none;
    width: 180px;
    pointer-events: auto;
}

#nameInput:focus, #deathNameInput:focus { border-color: #ffcc00; }

#leaderboard {
    margin-top: 24px;
    text-align: center;
    width: 280px;
}

#leaderboard h2 {
    font-size: 14px;
    letter-spacing: 3px;
    color: #99a;
    margin-bottom: 8px;
}

#leaderList {
    list-style: none;
    padding: 0;
}

#leaderList li {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    font-size: 13px;
    color: #aab;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-variant-numeric: tabular-nums;
}

#leaderList li:first-child { color: #ffcc00; }
#leaderList li:nth-child(2) { color: #bbbbbb; }
#leaderList li:nth-child(3) { color: #cc8844; }

#leaderList .lb-name { text-align: left; }
#leaderList .lb-score { text-align: right; font-weight: 600; }
