/* --- Multiplayer Race Styles --- */

.multiplayer-lobby {
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.lobby-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 3rem;
}

.lobby-card {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    transition: transform 0.2s, border-color 0.2s;
}

.lobby-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-primary);
}

.lobby-card h3 {
    color: var(--accent-primary);
    font-size: 1.5rem;
}

.lobby-card input {
    width: 100%;
    padding: 1rem;
    border-radius: 8px;
    border: 2px solid var(--bg-tertiary);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.lobby-card input:focus {
    border-color: var(--accent-primary);
    outline: none;
}

/* Race Room */
.race-room {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

.race-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    border-radius: 12px;
    border: 1px solid var(--bg-tertiary);
}

.room-code {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.room-code strong {
    color: var(--accent-primary);
    font-family: monospace;
    font-size: 1.4rem;
    padding: 0.2rem 0.5rem;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 4px;
}

.race-status {
    font-weight: bold;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.status-waiting {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

.status-countdown {
    background: rgba(255, 87, 34, 0.2);
    color: #ff5722;
}

.status-racing {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
}

.status-finished {
    background: rgba(33, 150, 243, 0.2);
    color: #2196f3;
}

/* Participants List in Lobby */
.participants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.participant-card {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--bg-tertiary);
    transition: transform 0.2s;
}

.participant-card.me {
    border-color: var(--accent-primary);
    background: rgba(76, 175, 80, 0.05);
}

.participant-card.empty {
    opacity: 0.5;
    border-style: dashed;
}

.p-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5rem;
    color: var(--text-primary);
}

/* Track Lane Styles */
.race-track-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 2rem 0;
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--bg-tertiary);
}

.track-lane {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 60px;
}

.track-lane.my-lane .lane-track {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.lane-info {
    width: 120px;
    text-align: right;
    display: flex;
    flex-direction: column;
}

.lane-name {
    font-weight: bold;
    color: var(--text-primary);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lane-wpm {
    font-size: 0.8rem;
    color: var(--accent-primary);
    font-family: monospace;
    font-weight: bold;
}

.lane-acc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.lane-track {
    flex: 1;
    height: 40px;
    background: var(--bg-primary);
    border-radius: 20px;
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 10px;
}

.finish-line {
    position: absolute;
    right: 10px;
    /* actually left because RTL? No, stick to physical right for finish line if track moves LTR */
    /* Wait, Arabic website usually RTL. If we want track to go Right-to-Left (start right), we position finish at Left. */
    /* Let's assume standard progress bar behavior: 0% at Start, 100% at End. */
    /* For RTL, 0% is Right, 100% is Left in CSS normally? Check direction. */
    /* The main styles have `direction: rtl`. So `left: 0` is physically left. */
    /* If we use `left: %` for position, 0% is left. 100% right. */
    /* But if direction is RTL, natural reading expectation is Right to Left. */
    /* Let's look at `renderTrack`: style="left: ${leftPos}%" */
    /* If `left: 0%` is start, that's Left side. */
    /* That means the race runs Left -> Right. */
    /* This might be counter-intuitive for Arabic users who read Right -> Left. */
    /* Let's fix this in CSS or JS. Let's make it LTR for the visual track to be safe/standard or consistent with 'left' style. */
    /* Or keep it `left` based but visually flip if needed. */
    /* Let's forcefully set direction: ltr for the track container to ensure left:0 is left. */

    left: auto;
    right: 10px;
    /* Visual finish line at the end (Right side if LTR, Left side needs adjustment) */
    /* Actually, if we use left 0->100, the finish is at the right. */
    font-size: 1.5rem;
    opacity: 0.5;
}

.rat-runner {
    position: absolute;
    /* 'left' is set inline via JS */
    top: -15px;
    /* pop above track slightly */
    transition: left 0.5s linear;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
}

.rat-icon {
    font-size: 2rem;
    /* Mirror the rat so it faces right (destination) */
    transform: scaleX(-1);
}


/* Host Controls */
.host-controls {
    text-align: center;
    margin-top: 2rem;
}

.limit-msg {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.pulse {
    animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* Waiting/Status Messages */
.waiting-msg {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 2rem;
    font-style: italic;
}

.race-text-preview {
    background: var(--bg-secondary);
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--accent-secondary);
    color: var(--text-muted);
}

/* Results & Podium */
.race-results {
    text-align: center;
}

.podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 1rem;
    height: 300px;
    /* Ensure space for podium heights */
    margin: 3rem 0;
}

.podium-place {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.podium-place .podium-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    border: 3px solid var(--bg-secondary);
    position: relative;
    z-index: 2;
    margin-bottom: -10px;
}

.podium-place .podium-rank {
    width: 80px;
    background: var(--bg-tertiary);
    /* fallback */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 1rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: bold;
    font-size: 2rem;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.podium-place .podium-name {
    margin-top: 0.5rem;
    font-weight: bold;
}

.podium-place .podium-wpm {
    color: var(--accent-primary);
    font-size: 0.9rem;
}

/* First Place */
.podium-place.first .podium-rank {
    height: 150px;
    background: linear-gradient(to bottom, #FFD700, #B8860B);
}

.podium-errors {
    font-size: 0.8rem;
    color: var(--error);
    margin-top: 2px;
}

.podium-place.first .podium-avatar {
    width: 70px;
    height: 70px;
    border-color: #FFD700;
}

.podium-place.first .podium-crown {
    font-size: 2rem;
    margin-bottom: 5px;
    animation: bounce 2s infinite;
}

/* Second Place */
.podium-place.second .podium-rank {
    height: 100px;
    background: linear-gradient(to bottom, #C0C0C0, #808080);
}

.podium-place.second .podium-avatar {
    border-color: #C0C0C0;
}

/* Third Place */
.podium-place.third .podium-rank {
    height: 70px;
    background: linear-gradient(to bottom, #CD7F32, #8B4513);
}

.podium-place.third .podium-avatar {
    border-color: #CD7F32;
}

.results-list {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    background: var(--bg-secondary);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    align-items: center;
}

.result-row .acc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    width: 60px;
}

.next-race-countdown {
    margin-top: 3rem;
    color: var(--text-secondary);
}

.loader {
    border: 4px solid var(--bg-tertiary);
    border-top: 4px solid var(--accent-primary);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 1rem auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Countdown Overlay */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.countdown-number {
    font-size: 8rem;
    font-weight: bold;
    color: var(--accent-primary);
    animation: zoom-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoom-in {
    from {
        transform: scale(0);
        opacity: 0;
    }
}

/* Potion Animation */
.potion-container {
    position: absolute;
    top: -15px;
    /* Adjust to sit on top of line */
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    left: auto !important;
    /* Force override inline styles if conflict */
    right: 10px;
    /* Position at end */
}

/* Force LTR for track container to ensure consistent positioning */
.race-track-container {
    direction: ltr;
    /* Ensure 0% is Left, 100% is Right */
}

.lab-potion {
    font-size: 2rem;
    filter: drop-shadow(0 0 5px var(--accent-primary));
    animation: float 2s ease-in-out infinite;
    z-index: 2;
}

.potion-glow {
    position: absolute;
    width: 30px;
    height: 30px;
    background: radial-gradient(circle, var(--accent-primary) 0%, transparent 70%);
    opacity: 0.6;
    animation: radiate 1.5s infinite ease-out;
    z-index: 1;
    top: 5px;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

@keyframes radiate {
    0% {
        transform: scale(0.5);
        opacity: 0.8;
    }

    100% {
        transform: scale(2.0);
        opacity: 0;
    }
}

/* Ensure typing display in race looks good */
.race-active-area {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    text-align: center;
    border: 2px solid var(--border-color);
}

#race-typing-display {
    font-size: 1.5rem;
    line-height: 2.2;
    direction: rtl;
    text-align: justify;
}

/* Key Selector Styles */
.key-selector-container {
    display: flex;
    flex-wrap: wrap;
    /* Grid layout */
    gap: 0.3rem;
    padding: 0.5rem;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--bg-tertiary);
    max-height: 150px;
    overflow-y: auto;
}

.key-select-item {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    font-weight: bold;
    color: var(--text-secondary);
    transition: all 0.1s;
}

.key-select-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.key-select-item.selected {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    box-shadow: none;
}
@keyframes wiggle { 0% { transform: translateX(0) rotate(0deg); } 25% { transform: translateX(2px) rotate(5deg); } 50% { transform: translateX(0) rotate(0deg); } 75% { transform: translateX(-2px) rotate(-5deg); } 100% { transform: translateX(0) rotate(0deg); } }
.progress-rat.wiggle { animation: wiggle 0.2s ease-in-out; }
