:root {
    --bg-dark: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    --accent-primary: #3b82f6;
    /* Blue */
    --accent-secondary: #8b5cf6;
    /* Purple */
    --accent-glow: rgba(139, 92, 246, 0.5);

    --track-bg: rgba(0, 0, 0, 0.3);
    --track-border: rgba(255, 255, 255, 0.05);

    --player-color: #10b981;
    /* Green for self */
    --opponent-color: #f43f5e;
    /* Red/Pink for others */
    --coin-gold: #fbbf24;
}

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

body {
    font-family: 'Inter', 'Prompt', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background VFX */
.bg-vfx {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background:
        radial-gradient(circle at 20% 30%, rgba(59, 130, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(139, 92, 246, 0.15) 0%, transparent 40%),
        #050510;
    animation: pulseBGFX 10s infinite alternate linear;
}

@keyframes pulseBGFX {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1.1);
        opacity: 1;
    }
}

.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 2rem;
}

.hidden {
    display: none !important;
}

/* --- Login Screen --- */
#login-screen {
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.game-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #fff, var(--accent-primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--accent-secondary);
    font-size: 1.2rem;
    margin-bottom: 2rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

input {
    width: 100%;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 15px var(--accent-glow);
}

.status-msg {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-height: 1.2rem;
}

/* Betting UI */
.wallet-info {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    display: inline-block;
}

.coin-highlight {
    color: var(--coin-gold);
    font-weight: bold;
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.wager-input-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
}

.wager-input-row label {
    font-weight: 600;
}

/* Hide default spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.custom-number-input {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--accent-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

.custom-number-input input {
    width: 60px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1.1rem;
    padding: 0.5rem 0;
    box-shadow: none;
    border-radius: 0;
}

.custom-number-input input:focus {
    box-shadow: none;
}

.wager-btn {
    background: transparent;
    color: var(--accent-primary);
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 0 1rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    border-radius: 0;
    text-transform: none;
}

.wager-btn:hover:not(:disabled) {
    background: rgba(139, 92, 246, 0.3);
    transform: none;
    /* Override default button hover */
    box-shadow: none;
    color: white;
}

.wager-btn:active:not(:disabled) {
    background: rgba(139, 92, 246, 0.5);
    transform: none;
}

.prize-pool-banner {
    background: linear-gradient(90deg, transparent, rgba(251, 191, 36, 0.2), transparent);
    color: var(--coin-gold);
    text-align: center;
    padding: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: -0.5rem;
    z-index: 5;
}

.payout-box {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    font-size: 1.2rem;
    font-weight: 600;
}

.payout-win {
    color: var(--player-color);
    border: 1px solid var(--player-color);
}

.payout-loss {
    color: var(--opponent-color);
    border: 1px solid var(--opponent-color);
}

/* Buttons */
button {
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px var(--accent-glow);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    background: #334155;
    color: #94a3b8;
    cursor: not-allowed;
}

/* --- Game Screen --- */
#game-screen {
    animation: fadeIn 0.5s ease;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 90vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
}

.highlight {
    color: var(--player-color);
    font-weight: bold;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* Race Arena */
.race-arena {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.race-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.instructions {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
}

.track-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    padding-right: 40px;
    /* Space for finish line */
}

.finish-line-marker {
    position: absolute;
    right: 20px;
    top: 0;
    bottom: 0;
    width: 10px;
    background: repeating-linear-gradient(45deg,
            #fff,
            #fff 10px,
            #000 10px,
            #000 20px);
    border-left: 2px solid #ef4444;
    z-index: 10;
    opacity: 0.5;
}

.waiting-msg {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 3rem;
    font-style: italic;
}

/* Individual Player Tracks */
.track {
    background: var(--track-bg);
    border: 1px solid var(--track-border);
    border-radius: 50px;
    height: 50px;
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 5px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--opponent-color);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    position: absolute;
    left: 5px;
    transition: left 0.1s linear;
    /* Smooth movement */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.track.is-self .avatar {
    background: var(--player-color);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.player-name-label {
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Sidebar Hall of Fame */
.sidebar {
    display: flex;
    flex-direction: column;
}

.sidebar h3 {
    color: #fbbf24;
    /* Gold */
}

.sidebar-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--panel-border);
}

.hof-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.hof-list li {
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hof-list li:nth-child(1) {
    border-left: 3px solid #fbbf24;
}

/* Gold */
.hof-list li:nth-child(2) {
    border-left: 3px solid #9ca3af;
}

/* Silver */
.hof-list li:nth-child(3) {
    border-left: 3px solid #b45309;
}

/* Bronze */

.hof-name {
    font-weight: 600;
}

.hof-time {
    font-size: 0.8rem;
    color: var(--accent-primary);
}

/* Winner Overlay */
.winner-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 100;
    border: 2px solid var(--accent-primary);
    background: rgba(15, 23, 42, 0.95);
    width: 400px;
}

.winner-title {
    color: #fbbf24;
    font-size: 2rem;
    margin-bottom: 1rem;
}

.winner-name {
    font-size: 2.5rem;
    font-weight: bold;
    color: white;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

/* Utilities */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        height: 250px;
    }

    #game-screen {
        height: auto;
    }
}