* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8E8 50%, #B0E0E6 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: auto;
    padding: 8px;
}

.game-container {
    position: relative;
    background: #000;
    border: 5px solid #333;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    contain: layout paint;
    max-width: 800px;
    width: 100%;
}

.game-canvas-wrap {
    display: block;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    max-width: 800px;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8E8 100%);
    touch-action: none;
}

/* Full-screen on mobile */
@media (max-width: 768px), (pointer: coarse) {
    html, body {
        height: 100%;
        min-height: 100dvh;
        overflow: hidden;
        padding: 0;
        margin: 0;
        align-items: stretch;
    }
    body {
        display: block;
    }
    .game-container {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        border: none;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }
    .game-canvas-wrap {
        flex: 1;
        min-height: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(to bottom, #87CEEB 0%, #98D8E8 100%);
    }
    .game-canvas-wrap #gameCanvas {
        width: 100%;
        height: 100%;
        max-width: none;
        object-fit: contain;
    }
}

/* On-screen touch controls – shown on small screens */
.touch-controls {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 140px;
    pointer-events: none;
    z-index: 50;
}
.touch-controls .touch-btn {
    position: absolute;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    font-size: 28px;
    font-weight: bold;
    background: rgba(255, 215, 0, 0.85);
    color: #000;
    border: 3px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    padding: 0;
}
.touch-controls .touch-btn:active {
    background: rgba(255, 165, 0, 0.95);
    transform: scale(0.92);
}
.touch-left     { left: 24px;   bottom: 24px; }
.touch-right    { left: 112px;  bottom: 24px; }
.touch-air-jump { right: 104px; bottom: 24px; }  /* mid-air / double jump (mobile) */
.touch-jump     { right: 24px;  bottom: 24px; }

@media (max-width: 768px), (pointer: coarse) {
    .touch-controls { display: flex; }
}

.game-header {
    background: #333;
    color: #fff;
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: clamp(14px, 4vw, 18px);
    font-weight: bold;
}

.score-board {
    display: flex;
    gap: 30px;
}

.score-board span {
    color: #FFD700;
}

.controls-info {
    font-size: clamp(12px, 3vw, 14px);
    color: #ccc;
}
@media (max-width: 500px) {
    .controls-info { display: none; }
}

.level-progress-container {
    width: 100%;
    height: 12px;
    background: #222;
    border-bottom: 2px solid #444;
    overflow: hidden;
}

.level-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #228B22, #32CD32);
    border-radius: 0 4px 4px 0;
    transition: width 0.15s ease-out;
}

.game-over,
.start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    z-index: 100;
    border: 3px solid #FFD700;
}

.start-screen {
    display: block;
}

.game-over.hidden,
.start-screen.hidden {
    display: none;
}

.game-over h2,
.start-screen h1 {
    font-size: clamp(24px, 8vw, 36px);
    margin-bottom: 20px;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.start-screen, .game-over {
    max-width: min(92vw, 420px);
    padding: clamp(12px, 4vw, 24px) clamp(12px, 4vw, 20px);
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Start screen / game-over scale on small screens */
@media (max-width: 480px) {
    .start-screen, .game-over {
        max-width: calc(100vw - 24px);
        padding: 16px 12px;
    }
    .game-over h2, .start-screen h1 {
        font-size: clamp(20px, 6vw, 28px);
        margin-bottom: 12px;
    }
    .game-over p, .start-screen p {
        font-size: clamp(14px, 4vw, 18px);
        margin: 8px 0;
    }
    .character-select {
        gap: 8px;
        margin: 12px 0;
    }
    .character-name {
        min-width: 80px;
        font-size: clamp(14px, 4vw, 16px);
    }
    .character-select button {
        padding: 6px 10px;
        font-size: 14px;
    }
    .start-screen #startBtn,
    .game-over-actions button {
        padding: 10px 20px;
        font-size: 16px;
        margin-top: 12px;
    }
    .character-preview {
        height: 40px;
    }
    .character-preview .char-box {
        width: 28px;
        height: 34px;
    }
    .high-score-line, .game-over p {
        font-size: clamp(14px, 4vw, 18px);
    }
    #finalScore {
        font-size: clamp(18px, 5vw, 24px);
    }
    .leaderboard-icon-btn {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
}

.character-select {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 18px 0;
}

.character-select > span:first-child {
    margin-right: 4px;
}

.character-select button {
    margin: 0;
    padding: 8px 14px;
    font-size: 16px;
}

.character-name {
    min-width: 120px;
    font-weight: bold;
    color: #FFD700;
}

.character-preview {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.character-preview .char-box {
    width: 32px;
    height: 40px;
    border-radius: 4px;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.character-preview .char-box.selected {
    border-color: #FFD700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.game-over p,
.start-screen p {
    font-size: clamp(14px, 4.5vw, 18px);
    margin: clamp(6px, 2vw, 10px) 0;
}

#finalScore {
    color: #FFD700;
    font-size: 24px;
    font-weight: bold;
}

.new-record {
    color: #FFD700;
    font-size: 20px;
    font-weight: bold;
    margin: 8px 0 4px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
}
.new-record.hidden {
    display: none;
}

.high-score-line {
    font-size: 18px;
    margin: 6px 0 4px;
    color: #ccc;
}
.high-score-line span {
    color: #FFD700;
    font-weight: bold;
}

.game-over-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.leaderboard-icon-btn {
    width: 48px;
    height: 48px;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 24px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 215, 0, 0.9);
    color: #000;
    border: 2px solid rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}
.leaderboard-icon-btn:hover {
    background: #FFA500;
    transform: scale(1.08);
}

/* Leaderboard modal */
.leaderboard-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.leaderboard-modal.hidden {
    display: none;
}

.leaderboard-panel {
    background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
    color: #fff;
    border-radius: 12px;
    padding: 20px 24px;
    max-width: 320px;
    width: 100%;
    border: 2px solid #FFD700;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.leaderboard-header h3 {
    margin: 0;
    font-size: 22px;
    color: #FFD700;
}
.leaderboard-close {
    width: 32px;
    height: 32px;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 24px;
    line-height: 1;
    background: transparent;
    color: #ccc;
    border: 1px solid #555;
    border-radius: 6px;
    cursor: pointer;
}
.leaderboard-close:hover {
    color: #fff;
    background: #444;
}

.leaderboard-list {
    list-style: none;
    margin: 0 0 16px 0;
    padding: 0;
    font-size: 16px;
}
.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid #333;
}
.leaderboard-list li:nth-child(1) { color: #FFD700; }
.leaderboard-list li:nth-child(2) { color: #C0C0C0; }
.leaderboard-list li:nth-child(3) { color: #CD7F32; }

.leaderboard-submit {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #444;
}
.leaderboard-submit.hidden {
    display: none !important;
}
.leaderboard-submit-msg {
    font-size: 14px;
    margin: 0 0 8px 0 !important;
    color: #aaa;
}
.leaderboard-name-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    border: 2px solid #555;
    border-radius: 6px;
    background: #222;
    color: #fff;
    margin-bottom: 10px;
    box-sizing: border-box;
}
.leaderboard-name-input:focus {
    outline: none;
    border-color: #FFD700;
}
.leaderboard-submit button {
    margin: 0 !important;
    width: 100%;
}

.leaderboard-error,
.leaderboard-loading {
    font-size: 14px;
    margin: 8px 0 0 0 !important;
}
.leaderboard-error {
    color: #f66;
}
.leaderboard-loading {
    color: #aaa;
}
.leaderboard-error.hidden,
.leaderboard-loading.hidden {
    display: none !important;
}

.leaderboard-local-record {
    margin: 12px 0 0 0 !important;
    padding-top: 10px;
    border-top: 1px solid #444;
    font-size: 14px;
    color: #888;
}
.leaderboard-local-record span {
    color: #FFD700;
    font-weight: bold;
}

button {
    margin-top: 20px;
    padding: 12px 30px;
    font-size: 18px;
    background: #FFD700;
    color: #000;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

button:hover {
    background: #FFA500;
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

button:active {
    transform: scale(0.95);
}
