/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6c5ce7;
    --secondary-color: #00b894;
    --danger-color: #d63031;
    --warning-color: #fdcb6e;
    --dark-bg: #1a1a2e;
    --darker-bg: #16213e;
    --light-text: #ffffff;
    --gray-text: #a0a0a0;
    --card-bg: #0f3460;
    --track-bg: #2d4059;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--dark-bg);
    background-image: url('assets/background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: var(--light-text);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--darker-bg);
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* Desktop: Reduce header padding and center logo */
@media (min-width: 768px) {
    .header {
        padding: 0.5rem 1rem;
        justify-content: center;
        position: relative;
    }

    .header-right {
        position: absolute;
        right: 1rem;
    }
}

.logo {
    height: 120px;
    width: auto;
    display: block;
}

/* Desktop: Smaller logo */
@media (min-width: 768px) {
    .logo {
        height: 80px;
    }
}

.main-nav {
    background: var(--darker-bg);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-link {
    color: var(--light-text);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.nav-link:hover {
    background: rgba(108, 92, 231, 0.2);
    color: var(--primary-color);
}

.title {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.wallet-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--gray-text);
}

.btn-connect {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Main Container */
.main-container {
    flex: 1;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Race Header (State + Countdown on same line) */
.race-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    flex-wrap: wrap;
    position: relative;
    overflow: visible;
}

.race-state {
    font-size: 1.2rem;
    font-weight: bold;
    flex: 1;
    min-width: 150px;
}

.countdown-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.countdown-label {
    font-size: 0.9rem;
    color: var(--gray-text);
}

.countdown-timer {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--warning-color);
    font-family: 'Courier New', monospace;
}

/* Prize Display */
.prize-display {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-radius: 15px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.3);
}

.prize-header {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.75rem;
    text-align: center;
}

.prize-details {
    text-align: center;
}

.prize-amount {
    font-size: 1.5rem;
    font-weight: bold;
}

.prize-sponsor {
    font-size: 0.85rem;
    opacity: 0.9;
}

.prize-race-id {
    font-size: 0.75rem;
    font-family: 'Courier New', monospace;
    opacity: 0.7;
    margin-top: 0.5rem;
    word-break: break-all;
}

/* Race Track */
.race-track {
    position: relative;
    background: #000;
    border-radius: 15px;
    overflow: visible;
    margin-bottom: 1rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    display: block;
}

/* Background Video */
.background-video {
    width: 100%;
    height: auto;
    display: block;
    margin: 0;
    padding: 0;
    line-height: 0;
}

/* Background Divider */
.background-divider {
    width: 100%;
    height: auto;
    display: block;
    margin: 0;
    padding: 0;
    line-height: 0;
}

/* Track section wrapper - contains the track background and lanes */
.race-track::after {
    content: '';
    display: block;
    width: 100%;
    height: 640px;
    background-image: url('assets/track-background.png');
    background-size: cover;
    background-position: center;
    position: relative;
}

.race-lanes {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 640px;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-sizing: border-box;
    z-index: 10;
    pointer-events: none;
    overflow-x: clip;
    overflow-y: visible;
}

.race-lane {
    position: relative;
    flex: 1;
    margin: 0;
    border-bottom: 2px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: flex-end;
    pointer-events: none;
}

.racer {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 200px;
    height: 200px;
    transition: left 0.1s linear;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center bottom;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
    z-index: 1;
    pointer-events: auto;
}

.racer.racing {
    animation: bounce 0.3s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.finish-line {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    opacity: 0;
    z-index: 5;
}

.finish-line-img {
    position: absolute;
    right: 0;
    bottom: 0;
    height: 640px;
    width: auto;
    z-index: 5;
    pointer-events: none;
}

.lane-label {
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 5px;
    border-radius: 3px;
    white-space: nowrap;
    z-index: 2;
}

/* Participants */
.participants-container {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.participants-container h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-align: center;
}

.participants-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
}

.no-participants {
    text-align: center;
    padding: 2rem;
    color: var(--gray-text);
    font-size: 1rem;
    grid-column: 1 / -1;
}

.participant-card {
    background: var(--darker-bg);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
    border: 2px solid transparent;
    transition: border-color 0.3s;
}

.participant-card.selected {
    border-color: var(--secondary-color);
}

.participant-character {
    width: 40px;
    height: 40px;
    margin: 0 auto 0.5rem;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.participant-name {
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.participant-wallet {
    font-size: 0.75rem;
    color: var(--gray-text);
    font-family: monospace;
}

/* Winner Display */
.winner-display {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.winner-content {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.5s;
    position: relative;
}

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

.winner-character {
    width: 100px;
    height: 100px;
    margin: 1rem auto;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    animation: victory 1s ease-in-out infinite;
}

@keyframes victory {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.1) rotate(5deg); }
}

.winner-name {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.winner-wallet {
    font-size: 0.9rem;
    font-family: monospace;
    opacity: 0.8;
    margin-bottom: 1rem;
}

.winner-prize {
    font-size: 1.3rem;
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.payout-status {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
}

.payout-status.success {
    background: var(--secondary-color);
}

.payout-status.pending {
    background: var(--warning-color);
    color: var(--dark-bg);
}

.payout-status.error {
    background: var(--danger-color);
}

/* Prize Payout Notification Banner */
.prize-payout-notification {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: 2px solid var(--secondary-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 24px rgba(0, 184, 148, 0.3);
    animation: slideInDown 0.5s ease-out;
}

.prize-payout-notification.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

.payout-title {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 1rem;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.payout-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
}

.payout-winner {
    font-size: 1.3rem;
    font-weight: bold;
}

.payout-amount {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--secondary-color);
    text-shadow: 0 0 10px rgba(0, 184, 148, 0.5);
}

.payout-race-id {
    font-size: 0.75rem;
    font-family: 'Courier New', monospace;
    opacity: 0.8;
    word-break: break-all;
    margin-top: 0.5rem;
}

.payout-instruction {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 0.5rem;
    font-style: italic;
}

.payout-status {
    font-size: 0.85rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.winner-countdown {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
}

.winner-countdown-timer {
    display: inline-block;
    min-width: 30px;
    color: var(--warning-color);
    font-size: 1.3rem;
}

.winner-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.winner-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.network-warning {
    padding: 0.75rem;
    background: var(--warning-color);
    color: var(--dark-bg);
    border-radius: 8px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 1rem;
}

/* Character Selection */
/* Character Selection Inline Container */
.character-selection-container {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.character-selection-container h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-align: center;
}

.username-input {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    border: 2px solid var(--card-bg);
    background: var(--dark-bg);
    color: var(--light-text);
    border-radius: 10px;
    margin-bottom: 1.5rem;
    transition: border-color 0.3s;
}

.username-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.character-option {
    aspect-ratio: 1;
    background: var(--card-bg);
    border: 3px solid transparent;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    background-size: 70%;
    background-repeat: no-repeat;
    background-position: center;
    position: relative;
}

.character-option:hover {
    transform: scale(1.05);
    border-color: var(--gray-text);
}

.character-option.selected {
    border-color: var(--secondary-color);
    box-shadow: 0 0 20px rgba(0, 184, 148, 0.5);
}

.character-option.taken {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(100%);
}

.character-option.taken::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: var(--gray-text);
}

.opt-in-status {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
}

.opt-in-status.error {
    background: var(--danger-color);
}

.opt-in-status.success {
    background: var(--secondary-color);
}

/* Sponsor Container */
.sponsor-container {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    text-align: center;
    position: relative;
}

/* Desktop: Center button and make form float */
@media (min-width: 768px) {
    .sponsor-container {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 1rem;
        background: transparent;
        box-shadow: none;
    }

    .sponsor-container #sponsor-toggle-btn {
        margin: 0 auto;
    }
}

.sponsor-form {
    margin-top: 1.5rem;
    text-align: left;
}

/* Desktop: Make form float as overlay */
@media (min-width: 768px) {
    .sponsor-form {
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 0.5rem;
        z-index: 1000;
        min-width: 400px;
        max-width: 500px;
        background: var(--card-bg);
        border-radius: 15px;
        padding: 2rem;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
        border: 2px solid var(--primary-color);
    }
}

.sponsor-form h3 {
    margin-bottom: 0.5rem;
    text-align: center;
}

.sponsor-description {
    text-align: center;
    color: var(--gray-text);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.token-selector-container,
.amount-input-container {
    margin-bottom: 1.5rem;
}

.input-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--gray-text);
    font-weight: 500;
}

.token-balance {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.input-field {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0;
    background: var(--dark-bg);
    border: 2px solid var(--darker-bg);
    color: var(--light-text);
    border-radius: 8px;
    font-size: 1rem;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
}

.sponsor-status {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--card-bg);
    color: white;
}

.btn-secondary:hover {
    background: var(--darker-bg);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    width: 100%;
}

/* Footer */
.footer {
    padding: 1rem;
    text-align: center;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem;
    }

    .header-right {
        flex-shrink: 0;
    }

    .logo {
        height: 50px;
    }

    .title {
        font-size: 1.2rem;
        width: 100%;
    }

    .race-track::after {
        height: 480px;
    }

    .race-lanes {
        height: 480px;
    }

    .finish-line-img {
        height: 480px;
    }

    .racer {
        width: 140px;
        height: 140px;
    }

    .countdown-timer {
        font-size: 1.5rem;
    }

    .character-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.75rem;
    }

    .winner-content {
        padding: 1.5rem;
    }

    .winner-content h2 {
        font-size: 1.5rem;
    }

    .winner-character {
        width: 80px;
        height: 80px;
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 0.5rem;
    }

    .participants-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .prize-display {
        padding: 0.75rem;
    }

    .prize-header {
        font-size: 0.95rem;
    }

    .prize-amount {
        font-size: 1.2rem;
    }
}
