/* ===== CSS VARIABLES (THEMING) ===== */
:root {
    --bg: #0a0a1a;
    --overlay-bg: radial-gradient(ellipse at center, rgba(8, 8, 35, 0.88) 0%, rgba(4, 4, 18, 0.96) 100%);
    --text: #fff;
    --text-dim: rgba(255, 255, 255, 0.45);
    --text-hint: rgba(255, 255, 255, 0.28);
    --border: rgba(100, 120, 255, 0.25);
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --hud-bg: rgba(10, 10, 30, 0.55);
    --score-glow: rgba(100, 120, 255, 0.5);
    --btn-icon-bg: rgba(255, 255, 255, 0.1);
    --btn-icon-border: rgba(255, 255, 255, 0.2);
    --gameover-color: #ff4a6a;
    --gameover-glow: rgba(255, 74, 106, 0.5);
    --final-label: rgba(255, 255, 255, 0.35);
    --final-value: #ffd700;
    --final-value-glow: rgba(255, 215, 0, 0.35);
    --title-glow-1: rgba(80, 200, 120, 0.5);
    --title-glow-2: rgba(100, 120, 255, 0.7);
}

body.light-theme {
    --bg: #e8f0f8;
    --overlay-bg: radial-gradient(ellipse at center, rgba(220, 230, 245, 0.92) 0%, rgba(200, 215, 240, 0.97) 100%);
    --text: #1a1a2e;
    --text-dim: rgba(26, 26, 46, 0.55);
    --text-hint: rgba(26, 26, 46, 0.35);
    --border: rgba(80, 100, 200, 0.3);
    --card-bg: rgba(0, 0, 0, 0.04);
    --card-border: rgba(0, 0, 0, 0.1);
    --hud-bg: rgba(255, 255, 255, 0.7);
    --score-glow: rgba(60, 80, 200, 0.3);
    --btn-icon-bg: rgba(0, 0, 0, 0.06);
    --btn-icon-border: rgba(0, 0, 0, 0.12);
    --gameover-color: #d63050;
    --gameover-glow: rgba(214, 48, 80, 0.4);
    --final-label: rgba(26, 26, 46, 0.45);
    --final-value: #d4a800;
    --final-value-glow: rgba(212, 168, 0, 0.3);
    --title-glow-1: rgba(40, 160, 80, 0.4);
    --title-glow-2: rgba(70, 90, 220, 0.5);
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    transition: background 0.4s ease;
}

/* ===== CANVAS ===== */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* ===== SCORE HUD ===== */
#scoreHud {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--hud-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 40px;
    padding: 6px 28px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s, background 0.4s;
}

#scoreHud.visible {
    opacity: 1;
}

#scoreValue {
    font-size: 26px;
    font-weight: 900;
    color: var(--text);
    letter-spacing: 2px;
    text-shadow: 0 0 12px var(--score-glow);
    transition: color 0.4s;
}

/* ===== ICON BUTTONS ===== */
.icon-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--btn-icon-bg);
    border: 1px solid var(--btn-icon-border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ===== OVERLAYS ===== */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    background: var(--overlay-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: opacity 0.4s ease, visibility 0.4s ease, background 0.4s ease;
}

.overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    max-width: 400px;
    padding: 20px;
}

/* ===== TITLE ===== */
.game-title {
    font-size: 52px;
    font-weight: 900;
    line-height: 1.05;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 5px;
    margin-bottom: 6px;
    text-shadow:
        0 0 20px var(--title-glow-1),
        0 0 60px rgba(80, 200, 120, 0.2);
    transition: color 0.4s;
}

.game-title span {
    color: #6478ff;
    font-size: 68px;
    display: block;
    text-shadow:
        0 0 25px var(--title-glow-2),
        0 0 70px rgba(100, 120, 255, 0.3);
}

.subtitle {
    color: var(--text-dim);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 20px;
    transition: color 0.4s;
}



/* ===== CHARACTER PREVIEW ===== */
#characterPreview {
    display: block;
    margin: 0 auto 24px;
    filter: drop-shadow(0 0 25px rgba(80, 100, 255, 0.45));
}

/* ===== BUTTONS ===== */
.glow-btn {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #38c960, #2aad4e, #45d975);
    border: none;
    border-radius: 50px;
    padding: 15px 54px;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.3s;
    box-shadow:
        0 4px 24px rgba(56, 201, 96, 0.4),
        0 0 50px rgba(56, 201, 96, 0.12);
}

.glow-btn:hover {
    transform: scale(1.05);
    box-shadow:
        0 6px 32px rgba(56, 201, 96, 0.55),
        0 0 70px rgba(56, 201, 96, 0.2);
}

.glow-btn:active {
    transform: scale(0.97);
}

.glow-btn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
            transparent 40%,
            rgba(255, 255, 255, 0.1) 50%,
            transparent 60%);
    animation: btnShine 3s ease-in-out infinite;
}

@keyframes btnShine {

    0%,
    100% {
        transform: translateX(-100%) rotate(45deg);
    }

    50% {
        transform: translateX(100%) rotate(45deg);
    }
}

/* ===== LEADERS BUTTON MODIFIER ===== */
.leaders-btn {
    background: linear-gradient(135deg, #daa520, #b8860b, #f0c040);
    box-shadow:
        0 4px 24px rgba(218, 165, 32, 0.35),
        0 0 50px rgba(218, 165, 32, 0.1);
    display: block;
    margin: 12px auto 0;
    font-size: 18px;
    padding: 13px 44px;
}

.leaders-btn:hover {
    box-shadow:
        0 6px 32px rgba(218, 165, 32, 0.5),
        0 0 70px rgba(218, 165, 32, 0.18);
}

/* ===== HINT ===== */
.hint {
    color: var(--text-hint);
    font-size: 13px;
    margin-top: 16px;
    letter-spacing: 1px;
    transition: color 0.4s;
}

/* ===== GAME OVER ===== */
.gameover-title {
    font-size: 46px;
    font-weight: 900;
    color: var(--gameover-color);
    letter-spacing: 4px;
    margin-bottom: 20px;
    text-shadow:
        0 0 20px var(--gameover-glow),
        0 0 60px rgba(255, 74, 106, 0.2);
    transition: color 0.4s;
}

.score-boxes {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-bottom: 22px;
}

.final-score-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 14px 28px;
    transition: background 0.4s, border-color 0.4s;
}

.final-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--final-label);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 4px;
    transition: color 0.4s;
}

.final-value {
    font-size: 38px;
    font-weight: 900;
    color: var(--final-value);
    text-shadow: 0 0 14px var(--final-value-glow);
    transition: color 0.4s;
}

/* ===== USERNAME SCREEN ===== */
.username-form {
    margin: 20px 0 10px;
}

.input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 280px;
}

.username-input {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 14px 50px 14px 20px;
    width: 100%;
    outline: none;
    transition: border-color 0.3s, background 0.3s, color 0.3s;
    letter-spacing: 1px;
}

.username-input:focus {
    border-color: #6478ff;
    box-shadow: 0 0 20px rgba(100, 120, 255, 0.2);
}

.username-input::placeholder {
    color: var(--text-hint);
    font-weight: 400;
}

.username-input.valid {
    border-color: #38c960;
    box-shadow: 0 0 15px rgba(56, 201, 96, 0.2);
}

.username-input.taken {
    border-color: #ff4a6a;
    box-shadow: 0 0 15px rgba(255, 74, 106, 0.2);
}

.username-status {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    opacity: 0;
    transition: opacity 0.3s;
}

.username-status.show {
    opacity: 1;
}

.username-error {
    color: #ff4a6a;
    font-size: 13px;
    margin-top: 8px;
    min-height: 18px;
    transition: color 0.3s;
}

.glow-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== WELCOME USER ===== */
.welcome-user {
    color: #6478ff;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    letter-spacing: 1px;
    text-shadow: 0 0 12px rgba(100, 120, 255, 0.3);
}

/* ===== HUD USERNAME ===== */
.hud-username {
    font-size: 14px;
    font-weight: 700;
    color: #6478ff;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(100, 120, 255, 0.3);
    margin-right: 4px;
}

.hud-username::after {
    content: '•';
    margin-left: 8px;
    color: var(--text-dim);
    font-size: 10px;
}

/* ===== SECONDARY BUTTON ===== */
.secondary-btn {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 50px;
    padding: 12px 36px;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 12px;
    display: inline-block;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.3s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.15);
}

.secondary-btn:active {
    transform: scale(0.97);
}

/* ===== LEADERBOARD ===== */
.leaderboard-content {
    max-width: 360px;
    width: 100%;
}

.leaderboard-title {
    font-size: 32px;
    font-weight: 900;
    color: var(--final-value);
    letter-spacing: 3px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px var(--final-value-glow);
    transition: color 0.4s;
}

.leaderboard-list {
    margin-bottom: 16px;
    min-height: 200px;
}

.leaderboard-loading {
    color: var(--text-dim);
    font-size: 15px;
    letter-spacing: 2px;
    padding: 40px 0;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    transition: all 0.3s;
    animation: lbRowIn 0.4s ease backwards;
}

.leaderboard-row.current-player {
    border: 1.5px solid rgba(100, 140, 255, 0.45);
    box-shadow: 0 0 12px rgba(100, 140, 255, 0.15);
    background: rgba(100, 140, 255, 0.08);
}

.leaderboard-row:nth-child(1) {
    animation-delay: 0.05s;
}

.leaderboard-row:nth-child(2) {
    animation-delay: 0.1s;
}

.leaderboard-row:nth-child(3) {
    animation-delay: 0.15s;
}

.leaderboard-row:nth-child(4) {
    animation-delay: 0.2s;
}

.leaderboard-row:nth-child(5) {
    animation-delay: 0.25s;
}

@keyframes lbRowIn {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.lb-rank {
    font-size: 18px;
    font-weight: 900;
    min-width: 36px;
    text-align: center;
    color: var(--text-dim);
}

.lb-rank.gold {
    color: #ffd700;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.lb-rank.silver {
    color: #c0c0c0;
    text-shadow: 0 0 8px rgba(192, 192, 192, 0.3);
}

.lb-rank.bronze {
    color: #cd7f32;
    text-shadow: 0 0 8px rgba(205, 127, 50, 0.3);
}

.lb-name {
    flex: 1;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 1px;
    text-align: left;
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    font-size: 16px;
    font-weight: 900;
    color: var(--final-value);
    letter-spacing: 1px;
    text-shadow: 0 0 8px var(--final-value-glow);
}

/* Player's own rank */
.player-rank-section {
    margin-top: 4px;
    margin-bottom: 16px;
}

.player-rank-section.hidden {
    display: none;
}

.player-rank-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0 10px;
}

.player-row {
    background: rgba(100, 120, 255, 0.1);
    border-color: rgba(100, 120, 255, 0.3);
    animation: lbRowIn 0.4s ease 0.35s backwards;
}

.player-row .lb-name {
    color: #6478ff;
}

.leaderboard-empty {
    color: var(--text-hint);
    font-size: 14px;
    padding: 30px 0;
    letter-spacing: 1px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 500px) {
    .game-title {
        font-size: 38px;
    }

    .game-title span {
        font-size: 50px;
    }

    .gameover-title {
        font-size: 34px;
    }

    .glow-btn {
        font-size: 18px;
        padding: 13px 42px;
    }

    .final-value {
        font-size: 30px;
    }

    .username-input {
        font-size: 17px;
        padding: 12px 44px 12px 16px;
    }
}