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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background: #1a3a5c;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ─── FULL-SCREEN GAME CONTAINER ─── */
.game-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;

    /* Sky gradient that fills the entire background */
    background:
        radial-gradient(ellipse 60% 40% at 15% 20%, rgba(255,240,200,0.18) 0%, transparent 60%),   /* sun glow */
        linear-gradient(180deg,
            #0a1628 0%,       /* deep night at very top */
            #1a2d4a 12%,      /* dark blue upper sky */
            #1e3f6e 28%,      /* mid-night blue */
            #2a5298 42%,      /* horizon blue */
            #3a7bd5 55%,      /* warm horizon */
            #f4a261 68%,      /* sunset/ground line */
            #8B6914 72%,      /* dirt transition */
            #5D4E1A 80%,      /* deep dirt */
            #3d2f0f 100%      /* underground dark */
        );
}

canvas {
    position: absolute;
    /* Canvas renders the game scene; it sits over our CSS sky/ground */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* ─── UI OVERLAY ─── */
.ui-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

/* ─── TOP BAR - Score, Speed, HiScore ─── */
.score-display {
    position: absolute;
    top: 18px;
    right: 24px;
    font-size: clamp(22px, 3vw, 34px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 12px rgba(255,220,100,0.7), 2px 2px 0px rgba(0,0,0,0.6);
    letter-spacing: 4px;
    font-variant-numeric: tabular-nums;
}

.high-score {
    position: absolute;
    top: 60px;
    right: 24px;
    font-size: clamp(11px, 1.4vw, 16px);
    color: rgba(255,220,150,0.85);
    text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
    letter-spacing: 1px;
}

.speed-indicator {
    position: absolute;
    top: 22px;
    left: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.speed-label {
    color: rgba(255,255,255,0.9);
    font-size: clamp(9px, 1.1vw, 13px);
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

.speed-bar {
    width: clamp(70px, 9vw, 130px);
    height: 8px;
    background: rgba(0,0,0,0.4);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.2);
}

.speed-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00ff88, #FFD700, #FF6B6B);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* ─── COMBO - Mid-top ─── */
.combo-display {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(16px, 2.2vw, 26px);
    font-weight: 900;
    color: #FF6B6B;
    text-shadow: 0 0 10px rgba(255,107,107,0.6), 2px 2px 0 rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
}

.combo-display.active {
    opacity: 1;
    animation: comboPulse 0.5s ease-in-out;
}

@keyframes comboPulse {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.3); }
    100% { transform: translateX(-50%) scale(1); }
}

/* ─── POWER-UPS - centered below combo ─── */
.powerup-indicator {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
}

.powerup-icon {
    width: clamp(32px, 4vw, 44px);
    height: clamp(32px, 4vw, 44px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(14px, 2vw, 22px);
    background: rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
    opacity: 0.3;
    transition: all 0.3s;
    position: relative;
}

.powerup-icon.active {
    opacity: 1;
    border-color: #FFD700;
    box-shadow: 0 0 15px rgba(255,215,0,0.5), inset 0 0 8px rgba(255,215,0,0.2);
    animation: powerupPulse 1s ease-in-out infinite;
}

@keyframes powerupPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.powerup-timer {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 26px;
    height: 3px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    overflow: hidden;
}

.powerup-timer-fill {
    height: 100%;
    background: #FFD700;
    width: 100%;
    transition: width 0.1s linear;
}

/* ─── TG CHIP ─── */
.tg-chip {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    padding: 3px 10px 3px 6px;
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    pointer-events: none;
    z-index: 15;
}

.tg-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00e5ff, #0055aa);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
}

/* ─── BOTTOM STATS BAR - anchored to ground ─── */
.stats-panel {
    position: absolute;
    bottom: clamp(14px, 3vh, 30px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: clamp(16px, 3vw, 36px);
    color: rgba(255,255,255,0.95);
    font-size: clamp(11px, 1.4vw, 15px);
    font-weight: 700;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.8);
    background: rgba(0,0,0,0.35);
    padding: 8px 22px;
    border-radius: 30px;
    border: 1px solid rgba(255,255,255,0.15);
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ─── BACK BUTTON ─── */
.back-button {
    position: absolute;
    top: 50px;
    left: 24px;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.9);
    padding: 7px 16px;
    border-radius: 30px;
    font-size: clamp(10px, 1.2vw, 13px);
    font-weight: 700;
    cursor: pointer;
    pointer-events: all;
    z-index: 15;
    transition: all 0.3s ease;
    letter-spacing: 1px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.back-button:hover {
    background: rgba(200,50,50,0.7);
    border-color: rgba(255,150,150,0.5);
    transform: translateX(-3px);
    box-shadow: 0 5px 18px rgba(0,0,0,0.4);
}

.back-button:active {
    transform: translateX(-1px);
}

/* ─── ACHIEVEMENT POPUP ─── */
.achievement-popup {
    position: absolute;
    top: 110px;
    left: 50%;
    transform: translateX(-50%) scale(0);
    background: linear-gradient(135deg, #FFD700, #FFA500);
    padding: 14px 32px;
    border-radius: 16px;
    text-align: center;
    z-index: 30;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 8px 30px rgba(255,180,0,0.5), 0 0 0 3px rgba(255,255,255,0.3);
}

.achievement-popup.show {
    transform: translateX(-50%) scale(1);
}

.achievement-popup h3 {
    color: #1a1a2e;
    font-size: clamp(16px, 2vw, 22px);
    margin-bottom: 4px;
}

.achievement-popup p {
    color: #333;
    font-size: clamp(11px, 1.2vw, 14px);
}

/* ─── LEADERBOARD OVERLAY ─── */
.lb-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 25;
    background: rgba(5,12,30,0.92);
    backdrop-filter: blur(12px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

.lb-overlay.show { display: flex; }

.lb-title {
    font-size: clamp(22px, 3vw, 34px);
    font-weight: 900;
    color: #FFD700;
    margin-bottom: 4px;
    letter-spacing: 3px;
    text-shadow: 0 0 20px rgba(255,215,0,0.4);
}

.lb-sub {
    font-size: clamp(10px, 1.2vw, 13px);
    color: rgba(255,255,255,0.35);
    margin-bottom: 18px;
}

.lb-list {
    width: 100%;
    max-width: 520px;
    max-height: 50vh;
    overflow-y: auto;
    scrollbar-width: none;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.lb-list::-webkit-scrollbar { display: none; }

.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 10px 14px;
}

.lb-row.me  { background: rgba(0,229,255,0.1); border-color: rgba(0,229,255,0.3); }
.lb-row.top1{ background: rgba(255,215,0,0.1);  border-color: rgba(255,215,0,0.35); }
.lb-row.top2{ background: rgba(192,192,192,0.08);border-color: rgba(192,192,192,0.2); }
.lb-row.top3{ background: rgba(205,127,50,0.08); border-color: rgba(205,127,50,0.2); }

.lb-rank   { font-size: 20px; font-weight: 900; width: 30px; text-align: center; flex-shrink: 0; color: #fff; }
.lb-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #00e5ff, #005588); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; }
.lb-info   { flex: 1; min-width: 0; }
.lb-name   { font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-detail { font-size: 9px; color: rgba(255,255,255,0.35); letter-spacing: 1px; }
.lb-score  { font-size: 16px; font-weight: 900; color: #FFD700; flex-shrink: 0; }
.lb-qualify   { font-size: 9px; color: #00ff88; }
.lb-noqualify { font-size: 9px; color: rgba(255,255,255,0.3); }
.lb-loading   { text-align: center; color: rgba(255,255,255,0.3); font-size: 13px; padding: 20px 0; }

.lb-btn-row { display: flex; gap: 12px; }
.lb-btn { padding: 10px 26px; border-radius: 30px; border: none; cursor: pointer; font-size: 14px; font-weight: 700; transition: all 0.2s; }
.lb-btn-close   { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.2); }
.lb-btn-refresh { background: rgba(0,229,255,0.15); color: #00e5ff; border: 1px solid rgba(0,229,255,0.3); }
.lb-btn:hover   { transform: scale(1.05); }

/* ─── START SCREEN ─── */
.start-screen, .game-over-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(5, 12, 30, 0.75);
    backdrop-filter: blur(14px);
    pointer-events: all;
    z-index: 20;
    transition: opacity 0.5s ease;
}

.game-over-screen { display: none; }

.title {
    font-size: clamp(36px, 7vw, 80px);
    font-weight: 900;
    color: #FFD700;
    text-shadow: 0 0 30px rgba(255,215,0,0.5), 4px 4px 0px rgba(0,0,0,0.4);
    margin-bottom: 8px;
    animation: float 3s ease-in-out infinite;
}

.subtitle {
    font-size: clamp(13px, 2vw, 22px);
    color: rgba(255,255,255,0.85);
    margin-bottom: 36px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

.btn {
    padding: clamp(12px, 1.8vh, 18px) clamp(32px, 5vw, 60px);
    font-size: clamp(16px, 2.5vw, 26px);
    font-weight: 700;
    border: none;
    border-radius: 60px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.btn-start {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #1a1a2e;
}

.btn-start:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 18px 40px rgba(255,215,0,0.45);
}

.btn-restart {
    background: linear-gradient(135deg, #FF6B6B, #EE5A5A);
    color: white;
    margin-top: 16px;
}

.btn-restart:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 18px 40px rgba(255,107,107,0.45);
}

.controls-hint {
    margin-top: 24px;
    color: rgba(255,255,255,0.65);
    font-size: clamp(11px, 1.4vw, 15px);
    text-align: center;
    line-height: 2;
}

.key {
    display: inline-block;
    padding: 3px 12px;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.3);
    font-weight: 700;
    margin: 0 4px;
}

/* ─── GAME OVER SCREEN ─── */
.final-score {
    font-size: clamp(52px, 9vw, 96px);
    font-weight: 900;
    color: #FFD700;
    text-shadow: 0 0 40px rgba(255,215,0,0.55), 4px 4px 0 rgba(0,0,0,0.4);
    margin: 10px 0;
    line-height: 1;
}

.new-record {
    color: #FF6B6B;
    font-size: clamp(16px, 2.5vw, 28px);
    font-weight: 700;
    animation: pulse 1s ease-in-out infinite;
    display: none;
    text-shadow: 0 0 12px rgba(255,107,107,0.5);
}

.qualify-msg {
    font-size: clamp(11px, 1.3vw, 14px);
    margin-bottom: 14px;
    color: rgba(255,255,255,0.45);
    text-align: center;
}

/* ─── ANIMATIONS ─── */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-14px); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ─── STARS in background (decorative via pseudo-elements) ─── */
.game-container::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    /* Tiny dot stars scattered across the sky portion */
    background-image:
        radial-gradient(1px 1px at 8% 5%, rgba(255,255,255,0.8) 0%, transparent 100%),
        radial-gradient(1px 1px at 18% 12%, rgba(255,255,255,0.6) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 32% 7%, rgba(255,255,255,0.9) 0%, transparent 100%),
        radial-gradient(1px 1px at 47% 3%, rgba(255,255,255,0.7) 0%, transparent 100%),
        radial-gradient(1px 1px at 62% 9%, rgba(255,255,255,0.5) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 75% 4%, rgba(255,255,255,0.8) 0%, transparent 100%),
        radial-gradient(1px 1px at 88% 14%, rgba(255,255,255,0.6) 0%, transparent 100%),
        radial-gradient(1px 1px at 5% 18%, rgba(255,255,255,0.4) 0%, transparent 100%),
        radial-gradient(1px 1px at 93% 8%, rgba(255,255,255,0.7) 0%, transparent 100%),
        radial-gradient(1px 1px at 55% 16%, rgba(255,255,255,0.5) 0%, transparent 100%),
        radial-gradient(1px 1px at 28% 20%, rgba(255,255,255,0.4) 0%, transparent 100%),
        radial-gradient(1px 1px at 70% 18%, rgba(255,255,255,0.3) 0%, transparent 100%),
        radial-gradient(1px 1px at 42% 22%, rgba(255,255,255,0.5) 0%, transparent 100%),
        radial-gradient(1px 1px at 85% 20%, rgba(255,255,255,0.4) 0%, transparent 100%),
        radial-gradient(1px 1px at 15% 25%, rgba(255,255,255,0.3) 0%, transparent 100%);
}

/* ─── GROUND TEXTURE LINE ─── */
.game-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: clamp(60px, 12vh, 110px);
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(180deg,
        transparent 0%,
        rgba(101,67,33,0.15) 30%,
        rgba(60,40,10,0.4) 70%,
        rgba(30,18,5,0.7) 100%
    );
    /* Horizontal root/crack lines */
    border-top: 2px solid rgba(139,90,20,0.3);
}