* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #1a1a2e;
    overflow: hidden;
    touch-action: none;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

#gameCanvas {
    display: block;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #0f0f23 0%, #1a1a3e 50%, #2d1b4e 100%);
}

#uiOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.screen {
    display: none;
    pointer-events: auto;
    text-align: center;
    width: 100%;
    max-width: 100%;
    padding: 0 1rem;
    animation: fadeIn 0.3s ease-out;
}

.screen.active {
    display: block;
}

/* #gameUI ialah ID selector (spesifisiti lebih tinggi daripada .screen),
   jadi keadaan tersembunyi/aktifnya dinyatakan semula di sini. */
#gameUI.screen {
    display: none;
}

#gameUI.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

#startScreen h1 {
    font-size: clamp(1.9rem, 10vw, 4rem);
    line-height: 1.05;
    font-weight: 800;
    overflow-wrap: anywhere;
    background: linear-gradient(135deg, #ff6b6b 0%, #ffd93d 50%, #6bcb77 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    text-shadow: 0 4px 20px rgba(255, 107, 107, 0.3);
}

.subtitle {
    color: #a0a0c0;
    font-size: 1.1rem;
    margin-bottom: 2rem;
    font-weight: 300;
}

button {
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.4);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(255, 107, 107, 0.6);
}

button:active {
    transform: translateY(0);
}

#gameUI {
    position: absolute;
    top: 1.5rem;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: fit-content;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
    pointer-events: none;
}

#gameUI > div {
    pointer-events: auto;
    background: rgba(15, 15, 35, 0.85);
    backdrop-filter: blur(10px);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#gameUI span {
    color: #ffd93d;
    font-weight: 700;
    margin-left: 0.5rem;
}

#powerupDisplay {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 36px;
}

.powerup-icon {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    animation: pulse 2s ease-in-out infinite;
    white-space: nowrap;
}

.powerup-icon.jump-boost { background: linear-gradient(135deg, #ff6b6b, #ff4444); }
.powerup-icon.speed-boost { background: linear-gradient(135deg, #ffd93d, #ffcc00); color: #333; }
.powerup-icon.double-jump { background: linear-gradient(135deg, #6bcb77, #44aa55); }
.powerup-icon.magnet { background: linear-gradient(135deg, #a29bfe, #8880fe); }
.powerup-icon.shield { background: linear-gradient(135deg, #74b9ff, #5599ff); }

.powerup-icon.fading {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 2px 10px rgba(0,0,0,0.3); }
    50% { transform: scale(1.05); box-shadow: 0 4px 20px rgba(0,0,0,0.4); }
}

@keyframes fadeOut {
    to { opacity: 0; transform: scale(0.8); }
}

#gameOverScreen {
    background: rgba(15, 15, 35, 0.95);
    backdrop-filter: blur(20px);
    padding: 3rem;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
}

#gameOverScreen h2 {
    font-size: 2rem;
    color: #ff6b6b;
    margin-bottom: 1.5rem;
}

#gameOverScreen p {
    color: #e0e0e0;
    font-size: 1.2rem;
    margin: 0.75rem 0;
}

#gameOverScreen span {
    color: #ffd93d;
    font-weight: 700;
    font-size: 1.5rem;
}

.controls-hint {
    margin-top: 2rem;
    color: #606080;
    font-size: 0.9rem;
}

.controls-hint span {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-family: monospace;
    color: #a0a0c0;
}

.credit {
    margin-top: 2.5rem;
    color: #4a4a68;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    font-weight: 400;
}

@media (max-width: 600px) {
    #gameUI {
        flex-direction: column;
        gap: 0.5rem;
        top: 1rem;
    }
    
    #gameOverScreen {
        padding: 2rem 1.5rem;
    }
}

/* ---- Safe area (notch) & responsif (F-06 / AC-05) ---- */
#uiOverlay {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#gameUI {
    top: calc(1.5rem + env(safe-area-inset-top));
}

/* ---- Tombol bisu/suara (F-09 / BR-12) ---- */
#muteBtn {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top));
    right: calc(0.75rem + env(safe-area-inset-right));
    z-index: 30;
    width: 48px;
    height: 48px;
    padding: 0;
    font-size: 1.4rem;
    line-height: 1;
    border-radius: 50%;
    background: rgba(15, 15, 35, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    color: #fff;
}

/* ---- HUD level & bar kemajuan (F-06) ---- */
#gameUI #levelBarWrap {
    padding: 0;
    width: 60vw;
    max-width: 320px;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(15, 15, 35, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

#levelBar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #6bcb77, #ffd93d, #ff6b6b);
    transition: width 0.25s ease-out;
}

/* ---- Toast naik level (F-04) ---- */
.toast {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 40;
    padding: 1rem 1.75rem;
    border-radius: 16px;
    background: rgba(15, 15, 35, 0.92);
    border: 1px solid rgba(255, 217, 61, 0.5);
    color: #ffd93d;
    font-weight: 800;
    font-size: 1.2rem;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ---- Menu stats ---- */
.menu-stats {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-top: 1.5rem;
    color: #a0a0c0;
    font-size: 1rem;
}

.menu-stats span {
    color: #ffd93d;
    font-weight: 700;
}

/* ---- Game over: badge rekor & tombol ---- */
.badge {
    color: #ffd93d !important;
    font-weight: 800;
    font-size: 1rem !important;
    letter-spacing: 0.08em;
    animation: pulse 1.2s ease-in-out infinite;
}

.badge.hidden {
    display: none;
}

#gameOverScreen #finalLevel {
    font-size: 1.1rem;
}

#gameOverScreen button {
    display: block;
    margin: 0.9rem auto 0;
}

button.secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
    font-size: 1rem;
    padding: 0.8rem 2rem;
}

button.secondary:hover {
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
}
/* ---- Papan Skor (leaderboard lokal) + input nama ---- */
.name-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    justify-content: center;
    align-items: stretch;
    margin: 0.9rem auto 0;
    max-width: 340px;
}

#gameOverScreen .name-row button {
    display: inline-block;
    margin: 0;
    white-space: nowrap;
    width: 100%;
}

#nameInput {
    flex: none;
    width: 100%;
    min-width: 0;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
}

#nameInput::placeholder { color: #8a8ab0; }
#nameInput:disabled { opacity: 0.55; }
#nameInput:focus { outline: none; border-color: #ffd93d; box-shadow: 0 0 0 2px rgba(255, 217, 61, 0.25); }

#leaderboardScreen {
    background: rgba(15, 15, 35, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 2rem 1.5rem;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 92vw;
}

#leaderboardScreen h2 {
    font-size: 1.8rem;
    color: #ffd93d;
    margin-bottom: 1rem;
}

#leaderboardList {
    list-style: none;
    padding: 0;
    margin: 0 auto 1rem;
    max-width: 340px;
    text-align: left;
}

#leaderboardList li {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.55rem 0.85rem;
    margin-bottom: 0.4rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: #e0e0e0;
    font-size: 1rem;
}

#leaderboardList .lb-rank { color: #ffd93d; font-weight: 700; min-width: 1.6em; }
#leaderboardList .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboardList .lb-score { color: #6bcb77; font-weight: 700; }
#leaderboardList .lb-highlight { background: rgba(255, 217, 61, 0.14); box-shadow: inset 0 0 0 2px #ffd93d; }
#leaderboardList .lb-empty { justify-content: center; color: #8a8ab0; }

#leaderboardScreen button { margin-top: 0; }

.lb-status {
    color: #8a8ab0;
    font-size: 0.85rem;
    margin-bottom: 0.6rem;
    min-height: 1.1em;
}
.lb-status.online { color: #6bcb77; }
.lb-status.offline { color: #ffb86b; }
.lb-status.loading { color: #8a8ab0; }
