/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes animLand    { 0% { background-position: 0px 0px; }    100% { background-position: -335px 0px; } }
@keyframes animSky     { 0% { background-position: 0px 100%; }   100% { background-position: -275px 100%; } }
@keyframes animBird    { from { background-position: 0px 0px; }  to   { background-position: 0px -96px; } }
@keyframes animPipe    { 0% { left: 900px; }                      100% { left: -100px; } }
@keyframes animCeiling { 0% { background-position: 0px 0px; }    100% { background-position: -63px 0px; } }

/* Webkit prefixes */
@-webkit-keyframes animLand    { 0% { background-position: 0px 0px; }    100% { background-position: -335px 0px; } }
@-webkit-keyframes animSky     { 0% { background-position: 0px 100%; }   100% { background-position: -275px 100%; } }
@-webkit-keyframes animBird    { from { background-position: 0px 0px; }  to   { background-position: 0px -96px; } }
@-webkit-keyframes animPipe    { 0% { left: 900px; }                      100% { left: -100px; } }
@-webkit-keyframes animCeiling { 0% { background-position: 0px 0px; }    100% { background-position: -63px 0px; } }

/* ── Base ───────────────────────────────────────────────────────────────── */
*, *:before, *:after {
    -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
}

html, body {
    height: 100%; overflow: hidden;
    font-family: monospace; font-size: 12px; color: #fff;
}

/* ── Game container ─────────────────────────────────────────────────────── */
#gamecontainer { position: relative; width: 100%; height: 100%; min-height: 525px; }
#gamescreen    { position: absolute; width: 100%; height: 100%; }

#sky {
    position: absolute; top: 0; width: 100%; height: 80%;
    background-image: url('../assets/sky.png');
    background-repeat: repeat-x; background-position: 0px 100%;
    background-color: #4ec0ca;
    -webkit-animation: animSky 7s linear infinite;
    animation: animSky 7s linear infinite;
}

#flyarea { position: absolute; bottom: 0; height: 420px; width: 100%; }

#ceiling {
    position: absolute; top: -16px; height: 16px; width: 100%;
    background-image: url('../assets/ceiling.png'); background-repeat: repeat-x;
    -webkit-animation: animCeiling 481ms linear infinite;
    animation: animCeiling 481ms linear infinite;
}

#land {
    position: absolute; bottom: 0; width: 100%; height: 20%;
    background-image: url('../assets/land.png');
    background-repeat: repeat-x; background-position: 0px 0px;
    background-color: #ded895;
    -webkit-animation: animLand 2516ms linear infinite;
    animation: animLand 2516ms linear infinite;
}

/* ── HUD ────────────────────────────────────────────────────────────────── */
#bigscore { position: absolute; top: 20px; left: 150px; z-index: 100; }
#bigscore img { display: inline-block; padding: 1px; }

#splash {
    position: absolute; opacity: 0; top: 75px; left: 65px;
    width: 188px; height: 170px;
    background-image: url('../assets/splash.png'); background-repeat: no-repeat;
}

/* ── Scoreboard ─────────────────────────────────────────────────────────── */
#scoreboard {
    position: absolute; display: none; opacity: 0;
    top: 64px; left: 43px; width: 236px; height: 280px;
    background-image: url('../assets/scoreboard.png'); background-repeat: no-repeat;
    z-index: 1000;
}

#medal { position: absolute; opacity: 0; top: 114px; left: 32px; width: 44px; height: 44px; }

#currentscore { position: absolute; top: 105px; left: 107px; width: 104px; height: 14px; text-align: right; }
#currentscore img { padding-left: 2px; }

#highscore { position: absolute; top: 147px; left: 107px; width: 104px; height: 14px; text-align: right; }
#highscore img { padding-left: 2px; }

#replay { position: absolute; opacity: 0; top: 205px; left: 61px; height: 115px; width: 70px; cursor: pointer; }

/* ── Bird & pipes ───────────────────────────────────────────────────────── */
#player { left: 60px; top: 200px; }

.bird {
    position: absolute; width: 34px; height: 24px;
    background-image: url('../assets/bird.png');
    -webkit-animation: animBird 300ms steps(4) infinite;
    animation: animBird 300ms steps(4) infinite;
}

.pipe {
    position: absolute; left: -100px; width: 52px; height: 100%; z-index: 10;
    -webkit-animation: animPipe 7500ms linear;
    animation: animPipe 7500ms linear;
}

.pipe_upper {
    position: absolute; top: 0; width: 52px;
    background-image: url('../assets/pipe.png'); background-repeat: repeat-y; background-position: center;
}
.pipe_upper:after {
    content: ""; position: absolute; bottom: 0; width: 52px; height: 26px;
    background-image: url('../assets/pipe-down.png');
}
.pipe_lower {
    position: absolute; bottom: 0; width: 52px;
    background-image: url('../assets/pipe.png'); background-repeat: repeat-y; background-position: center;
}
.pipe_lower:after {
    content: ""; position: absolute; top: 0; width: 52px; height: 26px;
    background-image: url('../assets/pipe-up.png');
}

/* ── Debug ──────────────────────────────────────────────────────────────── */
.boundingbox { position: absolute; display: none; top: 0; left: 0; width: 0; height: 0; border: 1px solid red; }

/* ── Action buttons (shown after game over, below scoreboard) ───────────── */
#action-buttons {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    z-index: 2000;
    width: 200px;
}

.action-btn {
    width: 100%;
    padding: 11px 0;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0,0,0,0.35);
    transition: opacity .15s;
}
.action-btn:disabled { opacity: .6; cursor: default; }

#btn-submit   { background: #e74c3c; color: #fff; }
#btn-show-lb  { background: #2980b9; color: #fff; }

/* ── Leaderboard overlay ────────────────────────────────────────────────── */
#leaderboard-panel {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.93);
    z-index: 9000;
    display: none;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

#lb-title {
    color: #FFD700;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 2px;
    padding: 18px 0 8px;
    text-shadow: 2px 2px 0 #000;
    text-align: center;
}

#lb-my-rank {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 6px;
    display: none;
}

#lb-list {
    flex: 1;
    overflow-y: auto;
    width: 100%;
    max-width: 420px;
    padding: 4px 12px;
}

.lb-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin: 4px 0;
    background: rgba(255,255,255,.08);
    border-radius: 8px;
    color: #fff;
    gap: 8px;
}
.lb-row.lb-me {
    background: rgba(255,215,0,.2);
    border: 1px solid #FFD70088;
}

.lb-rank {
    min-width: 36px;
    font-size: 16px;
    text-align: center;
}

.lb-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: #444;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.lb-avatar img { width: 100%; height: 100%; object-fit: cover; }
.lb-avatar-fallback { color: #fff; font-size: 15px; font-weight: bold; }

.lb-name {
    flex: 1;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}
.lb-name .lb-username { color: #888; font-size: 10px; display: block; }

.lb-score {
    font-size: 14px;
    color: #2ecc71;
    font-weight: bold;
    white-space: nowrap;
}

.lb-empty {
    text-align: center;
    color: #888;
    font-size: 13px;
    padding: 40px 20px;
    line-height: 1.8;
}

#lb-buttons {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    width: 100%;
    max-width: 420px;
}

.lb-btn {
    flex: 1; padding: 12px 0;
    border: none; border-radius: 8px;
    font-size: 13px; font-weight: bold;
    cursor: pointer;
}
#lb-play-again { background: #27ae60; color: #fff; }
#lb-close-btn  { background: #555;    color: #fff; }

/* ── Not-registered overlay ─────────────────────────────────────────────── */
#not-registered-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.97);
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px;
    gap: 16px;
}
#not-registered-overlay h2 { font-size: 16px; color: #FFD700; }
#not-registered-overlay p  { font-size: 12px; color: #bbb; line-height: 1.7; max-width: 280px; }
#btn-go-to-bot {
    padding: 14px 28px;
    background: #2980b9; color: #fff;
    border: none; border-radius: 8px;
    font-size: 14px; font-weight: bold; cursor: pointer;
    margin-top: 8px;
}
