/* ============================================================
   FunisLearn — Live Session (Race Mode) UI
   Loaded on game pages only when ?room= is present, plus the lobby.
   RTL-first; the HUD is pinned to the top-left so it never covers the
   mute button (bottom-right) or a game's own score pill (top-right).
   ============================================================ */

:root {
    --live-purple: #667eea;
    --live-deep: #764ba2;
    --live-green: #4CAF50;
    --live-amber: #FFB300;
    --live-ink: #2b2d42;
}

/* ---------- Floating leaderboard ---------- */

#live-hud {
    position: fixed;
    top: 90px;
    left: 16px;
    z-index: 9998;
    width: 220px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
    border: 3px solid var(--live-purple);
    font-family: 'Tajawal', 'Cairo', sans-serif;
    overflow: hidden;
    direction: rtl;
}

.live-hud-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: linear-gradient(135deg, var(--live-purple) 0%, var(--live-deep) 100%);
    color: #fff;
    font-weight: 700;
}

.live-hud-title { font-size: .95rem; }

.live-hud-code {
    margin-inline-start: auto;
    font-size: .8rem;
    letter-spacing: 1px;
    background: rgba(255, 255, 255, .22);
    padding: 2px 8px;
    border-radius: 20px;
}

.live-hud-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}

.live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ff4d4d;
    box-shadow: 0 0 0 0 rgba(255, 77, 77, .7);
    animation: live-pulse 1.6s infinite;
}

@keyframes live-pulse {
    70%  { box-shadow: 0 0 0 9px rgba(255, 77, 77, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

#live-hud.collapsed .live-board,
#live-hud.collapsed .live-btn-sm { display: none !important; }

.live-board {
    list-style: none;
    margin: 0;
    padding: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.live-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 12px;
    font-size: .9rem;
    color: var(--live-ink);
    transition: background .2s;
}

.live-row + .live-row { margin-top: 3px; }
.live-row:nth-child(odd) { background: #f6f7fb; }
.live-row.is-host { background: #fff6e0; }
.live-row.is-away { opacity: .45; }
.live-row.is-done { box-shadow: inset 0 0 0 2px var(--live-green); }

.live-rank {
    flex: 0 0 22px;
    text-align: center;
    font-weight: 700;
}

.live-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-score {
    font-weight: 700;
    color: var(--live-purple);
    min-width: 24px;
    text-align: center;
}

.live-btn-sm {
    display: block;
    width: calc(100% - 16px);
    margin: 0 8px 8px;
    padding: 8px;
    border: none;
    border-radius: 12px;
    color: #fff;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    font-size: .9rem;
}

.live-start-btn { background: var(--live-green); }
.live-start-btn:hover { background: #3d9140; }

.live-end-btn { background: #ef476f; }
.live-end-btn:hover { background: #d63e61; }

/* ---------- Blocking overlays (waiting room, results) ---------- */

.live-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(20, 20, 40, .88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    direction: rtl;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

.live-overlay-card {
    background: #fff;
    border-radius: 28px;
    padding: 32px 28px;
    text-align: center;
    max-width: 460px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border: 5px solid var(--live-amber);
}

.live-overlay-emoji { font-size: 3.4rem; line-height: 1; }
.live-overlay-card h2 { color: var(--live-deep); margin: 12px 0 8px; font-size: 1.7rem; }
.live-overlay-card p { color: #555; margin: 0 0 14px; }
.live-overlay-code { font-size: .95rem; letter-spacing: 1px; }
.live-winner { font-weight: 700; color: var(--live-green); font-size: 1.1rem; }

.live-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 14px;
}

.live-chip {
    background: #eef0ff;
    color: var(--live-deep);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: .9rem;
    font-weight: 500;
}

.live-results-list {
    list-style: none;
    padding: 0;
    margin: 0 0 18px;
    text-align: start;
}

.live-results-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    background: #f6f7fb;
    margin-bottom: 6px;
}

.live-results-list li b { flex: 1; }

.live-btn {
    display: inline-block;
    background: var(--live-green);
    color: #fff;
    text-decoration: none;
    padding: 12px 30px;
    border-radius: 40px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
}

.live-btn:hover { background: #3d9140; color: #fff; }

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
    #live-hud {
        top: auto;
        bottom: 12px;
        left: 12px;
        width: 168px;
        border-radius: 14px;
    }

    #live-hud .live-board { max-height: 150px; }
    .live-row { font-size: .82rem; padding: 5px 6px; }
    .live-overlay-card { padding: 24px 18px; border-radius: 22px; }
    .live-overlay-card h2 { font-size: 1.4rem; }
}
