/**
 * Unified Intermission Component - Styles v2
 * Cozy Blast Platform
 *
 * Design based on modern mobile game UI
 * Dark gradient background with circular progress ring
 */

/* ============================================================
   CSS VARIABLES
   ============================================================ */

:root {
    --im-bg-dark: #1a0a1f;
    --im-bg-mid: #2d1233;
    --im-bg-light: #3d1a45;
    --im-primary: #ff2d78;
    --im-primary-light: #ff5a9d;
    --im-primary-glow: rgba(255, 45, 120, 0.5);
    --im-accent: #ffd700;
    --im-text-light: #ffffff;
    --im-text-muted: rgba(255, 255, 255, 0.7);
    --im-card-dark: rgba(30, 15, 35, 0.8);
    --im-card-light: rgba(255, 255, 255, 0.95);
    --im-card-border: rgba(255, 255, 255, 0.1);
    --im-ring-track: rgba(255, 255, 255, 0.1);
    --im-ring-progress: #ff2d78;
    --im-success: #00ff88;
    --im-danger: #ff4444;
}

/* ============================================================
   BASE LAYOUT
   ============================================================ */

.intermission-wrapper {
    width: 100%;
    min-height: 100dvh;
    background: linear-gradient(180deg, var(--im-bg-mid) 0%, var(--im-bg-dark) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow-x: hidden;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    padding-bottom: 80px; /* Space for floating chat bar */
    box-sizing: border-box;
    pointer-events: auto; /* Re-enable clicks (parent #intermission-container has pointer-events: none) */
}

.intermission-wrapper.chat-expanded {
    padding-bottom: 0;
}

.intermission-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
    box-sizing: border-box; /* Ensure padding doesn't overflow width */
}

@media (max-width: 600px) {
    .intermission-container {
        padding: 0 16px; /* Slightly tighter on mobile */
        width: 100%; /* Use 100% instead of 100vw to respect scrollbars */
        overflow-x: hidden;
    }
}

/* ============================================================
   HEADER
   ============================================================ */

.intermission-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    position: relative;
}

.header-back-btn,
.header-settings-btn {
    width: 2.2rem;
    height: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 1rem; /* Matches var(--border-radius-lg) approx */
    box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.2);
    transition: background-color 0.15s ease-in-out;
}

.header-back-btn:hover,
.header-settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-title {
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--im-text-light);
    text-transform: uppercase;
    letter-spacing: 2px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */

.intermission-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 0;
}

/* ============================================================
   CIRCULAR PROGRESS RING
   ============================================================ */

.score-ring-container {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 20px auto 40px;
}

.score-ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-ring-track {
    fill: none;
    stroke: var(--im-ring-track);
    stroke-width: 12;
}

.score-ring-progress {
    fill: none;
    stroke: var(--im-ring-progress);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 754;
    stroke-dashoffset: 754;
    transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 0 10px var(--im-primary-glow));
}

.score-ring-progress.animated {
    stroke-dashoffset: var(--progress-offset, 188);
}

.score-ring-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 200px;
}

.score-ring-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.score-ring-value {
    font-family: 'Poppins', sans-serif;
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--im-text-light);
    line-height: 1;
    margin-bottom: 15px;
}

.score-ring-value.positive::before {
    content: '+';
}

.daily-goal-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--im-text-light);
}

.daily-goal-badge .icon {
    color: var(--im-accent);
    font-size: 1rem;
}

/* ============================================================
   PERSONAL BEST BADGE
   ============================================================ */

.personal-best-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 24px;
    margin: -20px auto 30px;
    max-width: 280px;
}

.personal-best-badge.new-record {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.15), rgba(0, 255, 136, 0.05));
    border: 2px solid rgba(0, 255, 136, 0.4);
    animation: new-record-pulse 2s ease-in-out infinite;
}

@keyframes new-record-pulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(0, 255, 136, 0.2);
    }
    50% {
        box-shadow: 0 0 25px rgba(0, 255, 136, 0.4);
    }
}

.pb-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.personal-best-badge.new-record .pb-label {
    color: var(--im-success);
}

.pb-value {
    font-family: 'Poppins', sans-serif;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--im-text-light);
}

.personal-best-badge.new-record .pb-value {
    color: var(--im-success);
}

/* ============================================================
   SCORE COUNT-UP MODE
   ============================================================ */

.score-countup-container {
    position: relative;
    width: 280px;
    height: auto;
    min-height: 180px;
    margin: 20px auto 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-countup-content {
    position: relative;
    text-align: center;
    width: 100%;
}

.score-countup-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.score-countup-value {
    font-family: 'Poppins', sans-serif;
    font-size: 4rem;
    font-weight: 800;
    color: var(--im-text-light);
    line-height: 1;
    text-shadow: 0 0 20px rgba(255, 45, 120, 0.5);
    transition: all 0.1s;
}

.score-countup-container.animating .score-countup-value {
    animation: score-pulse-grow 0.5s ease-in-out infinite;
}

@keyframes score-pulse-grow {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.sparkles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.sparkle {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: 1.5rem;
    animation: sparkle-float 1s ease-out forwards;
    opacity: 0;
}

@keyframes sparkle-float {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.5);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(var(--sparkle-x, 0), var(--sparkle-y, 0)) scale(1.2);
    }
}

/* ============================================================
   STAT CARDS ROW
   ============================================================ */

.stat-cards-row {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-bottom: 30px;
}

.stat-card {
    flex: 1;
    border-radius: 16px;
    padding: 18px 12px;
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    /* transform: translateY(-2px); */
}

.stat-card.dark {
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
}

.stat-card.light {
    background: var(--im-card-light);
}

.stat-card-value {
    font-family: 'Poppins', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 4px;
}

.stat-card.dark .stat-card-value {
    color: var(--im-text-light);
}

.stat-card.light .stat-card-value {
    color: var(--im-primary);
}

.stat-card-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-card.dark .stat-card-label {
    color: var(--im-text-muted);
}

.stat-card.light .stat-card-label {
    color: #666;
}

.stat-card-stars {
    color: var(--im-accent);
    font-size: 1.2rem;
    letter-spacing: 2px;
}

/* ============================================================
   FLOATING CHAT BAR (Fixed at bottom)
   ============================================================ */

.chat-floating-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 680px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(75, 50, 90, 0.65);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 1000;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(255, 45, 120, 0.2);
    /* For positioning the badge */
    position: fixed;
}

.chat-floating-bar:hover {
    background: rgba(85, 55, 100, 0.8);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.7), 0 6px 16px rgba(255, 45, 120, 0.3);
}

.chat-floating-bar.hidden {
    display: none;
}

.chat-bar-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--im-primary);
    object-fit: cover;
    flex-shrink: 0;
}

.chat-bar-content {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.chat-bar-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.chat-bar-message {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--im-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-bar-message strong {
    font-weight: 700;
}

.chat-bar-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--im-danger);
    color: white;
    font-size: 0.85rem;
    font-weight: 800;
    min-width: 32px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.5);
    border: 2px solid #1a0a1f;
}

.chat-bar-badge.hidden {
    display: none;
}

.chat-bar-expand {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: var(--im-text-muted);
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-floating-bar:hover .chat-bar-expand {
    background: rgba(255, 255, 255, 0.2);
    color: var(--im-text-light);
}

/* ============================================================
   INLINE CHAT (Expanded at bottom of content)
   ============================================================ */

.chat-inline {
    width: 100%;
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 16px;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-inline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--im-card-border);
    background: rgba(75, 50, 90, 0.7);
    backdrop-filter: blur(10px);
}

.chat-inline-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--im-text-light);
}

.chat-inline-minimize {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: var(--im-text-light);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.chat-inline-minimize:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-inline-messages {
    height: 250px;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-inline-input {
    display: flex;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--im-card-border);
    background: rgba(0, 0, 0, 0.2);
}

.chat-inline-input input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--im-card-border);
    border-radius: 10px;
    color: var(--im-text-light);
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
}

.chat-inline-input input::placeholder {
    color: var(--im-text-muted);
}

.chat-inline-input button {
    padding: 12px 20px;
    background: var(--im-primary);
    border: none;
    border-radius: 10px;
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-inline-input button:hover {
    background: var(--im-primary-light);
}

/* Chat Message */
.chat-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-message.me {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.1);
}

.chat-message.me .chat-message-bubble {
    background: var(--im-primary);
}

.chat-message-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--im-text-muted);
    margin-bottom: 3px;
}

.chat-message.me .chat-message-name {
    color: rgba(255, 255, 255, 0.8);
}

.chat-message-text {
    font-size: 0.85rem;
    color: var(--im-text-light);
    line-height: 1.4;
}

/* ============================================================
   CTA BUTTON
   ============================================================ */

.cta-button {
    width: 100%;
    padding: 18px 30px;
    background: linear-gradient(135deg, var(--im-primary) 0%, var(--im-primary-light) 100%);
    border: none;
    border-radius: 16px;
    font-family: 'Poppins', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s;
    box-shadow: 0 8px 25px var(--im-primary-glow);
    margin-bottom: 20px;
    position: relative;
}

.cta-button .icon {
    position: absolute;
    right: 30px;
}

.button-subtitle {
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.85;
    font-style: italic;
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px var(--im-primary-glow);
}

.cta-button:active {
    transform: translateY(0);
}

.cta-button .icon {
    font-size: 1rem;
}

/* ============================================================
   LEADERBOARD (Unified style for all states)
   ============================================================ */

.leaderboard {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 12px;
    transition: all 0.2s;
}

.leaderboard-row.me {
    border-color: var(--im-primary);
    background: rgba(255, 45, 120, 0.15);
}

.leaderboard-row.eliminated {
    opacity: 0.5;
    filter: grayscale(100%);
}

.leaderboard-rank {
    width: 30px;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--im-text-muted);
    text-align: center;
    flex-shrink: 0;
}

.leaderboard-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--im-card-border);
    flex-shrink: 0;
}

.leaderboard-row.me .leaderboard-avatar {
    border-color: var(--im-primary);
}

.leaderboard-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--im-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-score {
    font-size: 1rem;
    font-weight: 800;
    color: var(--im-text-light);
    flex-shrink: 0;
}

/* Elimination Line */
.elimination-line {
    display: flex;
    align-items: center;
    gap: 15px;
    margin: 15px 0;
    width: 100%;
    position: relative;
    padding: 8px 0;
}

.elimination-line::before,
.elimination-line::after {
    content: '';
    flex: 1;
    height: 3px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--im-danger) 20%,
        var(--im-danger) 80%,
        transparent 100%
    );
    position: relative;
    animation: danger-pulse 2s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(255, 45, 60, 0.5);
}

.elimination-line::before {
    background: linear-gradient(90deg,
        transparent 0%,
        var(--im-danger) 40%
    );
}

.elimination-line::after {
    background: linear-gradient(90deg,
        var(--im-danger) 60%,
        transparent 100%
    );
}

.elimination-line-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--im-danger);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    white-space: nowrap;
    background: linear-gradient(135deg, rgba(255, 45, 60, 0.2), rgba(255, 45, 60, 0.1));
    border: 1.5px solid var(--im-danger);
    border-radius: 20px;
    padding: 6px 16px;
    position: relative;
    box-shadow: 0 0 15px rgba(255, 45, 60, 0.4);
    animation: label-glow 2s ease-in-out infinite;
}

.elimination-line-label::before {
    content: '⚠';
    margin-right: 6px;
    font-size: 0.9rem;
    animation: warning-blink 1.5s ease-in-out infinite;
}

@keyframes danger-pulse {
    0%, 100% {
        opacity: 0.6;
        box-shadow: 0 0 5px rgba(255, 45, 60, 0.3);
    }
    50% {
        opacity: 1;
        box-shadow: 0 0 15px rgba(255, 45, 60, 0.6);
    }
}

@keyframes label-glow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(255, 45, 60, 0.4);
        border-color: rgba(255, 45, 60, 0.8);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 45, 60, 0.7);
        border-color: rgba(255, 45, 60, 1);
    }
}

@keyframes warning-blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* ============================================================
   TOURNAMENT BRACKET TREE
   ============================================================ */

.bracket-container {
    width: 100%;
    margin: 20px 0;
    padding: 20px;
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 16px;
    overflow-x: auto;
}

.bracket-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
    text-align: center;
}

.bracket-tree {
    display: flex;
    justify-content: center;
    gap: 40px;
    min-width: fit-content;
}

.bracket-round {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    gap: 20px;
}

.bracket-match {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}

.bracket-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--im-card-border);
    border-radius: 8px;
    min-width: 140px;
}

.bracket-player.winner {
    border-color: var(--im-success);
    background: rgba(0, 255, 136, 0.1);
}

.bracket-player.loser {
    opacity: 0.5;
}

.bracket-player.me {
    border-color: var(--im-primary);
    background: rgba(255, 45, 120, 0.15);
}

.bracket-player-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.bracket-player-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--im-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bracket-player-score {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--im-text-light);
}

/* Bracket connector lines */
.bracket-connector {
    position: absolute;
    right: -20px;
    top: 50%;
    width: 20px;
    height: 2px;
    background: var(--im-card-border);
}

.bracket-connector::after {
    content: '';
    position: absolute;
    right: 0;
    width: 2px;
    background: var(--im-card-border);
}

/* ============================================================
   ROUND ROBIN CIRCLE VISUALIZATION
   ============================================================ */

.rr-circle-container {
    width: 100%;
    margin: 20px 0;
    padding: 20px;
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 16px;
}

.rr-circle-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
    text-align: center;
}

.rr-circle-svg {
    width: 100%;
    max-width: 400px;
    height: auto;
    margin: 0 auto;
    display: block;
}

.rr-player-node {
    cursor: pointer;
}

.rr-player-avatar {
    stroke: var(--im-card-border);
    stroke-width: 2;
}

.rr-player-avatar.me {
    stroke: var(--im-primary);
    stroke-width: 3;
}

.rr-player-name {
    font-size: 10px;
    font-weight: 600;
    fill: var(--im-text-light);
    text-anchor: middle;
}

.rr-player-record {
    font-size: 8px;
    /* font-weight: 100; */
    fill: var(--im-text-light);
    text-anchor: middle;
    opacity: 1;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    text-transform: uppercase;
}

.rr-match-line {
    stroke-width: 2;
    fill: none;
}

.rr-match-line.win {
    stroke: var(--im-success);
}

.rr-match-line.loss {
    stroke: var(--im-danger);
}

.rr-match-line.pending {
    stroke: var(--im-card-border);
    stroke-dasharray: 4, 4;
}

.rr-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.rr-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--im-text-muted);
}

.rr-legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.rr-legend-line.win {
    background: var(--im-success);
}

.rr-legend-line.loss {
    background: var(--im-danger);
}

.rr-legend-line.pending {
    background: var(--im-card-border);
}

/* ============================================================
   TOURNAMENT PRE STATE (Lobby)
   ============================================================ */

.tournament-lobby {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.tournament-host {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.tournament-host-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 3px solid var(--im-primary);
    object-fit: cover;
    margin-bottom: 15px;
    box-shadow: 0 0 30px var(--im-primary-glow);
}

.tournament-name {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--im-text-light);
    text-align: center;
    margin-bottom: 5px;
}

.tournament-host-name {
    font-size: 0.9rem;
    color: var(--im-text-muted);
}

.tournament-host-name strong {
    color: var(--im-text-light);
}

.tournament-variant-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--im-primary);
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 15px;
}

.tournament-countdown {
    text-align: center;
    margin-bottom: 30px;
}

.tournament-countdown-label {
    font-size: 0.85rem;
    color: var(--im-text-muted);
    margin-bottom: 8px;
}

.tournament-countdown-value {
    font-size: 3rem;
    font-weight: 800;
    color: var(--im-accent);
    font-variant-numeric: tabular-nums;
}

.tournament-participants {
    width: 100%;
    margin-bottom: 30px;
}

.tournament-participants-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 15px;
    text-align: center;
}

.tournament-participants-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.tournament-participant-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 70px;
    transition: all 0.2s;
}

.tournament-participant-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--im-card-border);
    object-fit: cover;
    transition: all 0.2s;
}

.tournament-participant-card.me .tournament-participant-avatar {
    border-color: var(--im-primary);
    box-shadow: 0 0 15px var(--im-primary-glow);
}

.tournament-participant-name {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--im-text-light);
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.tournament-participant-card.me .tournament-participant-name {
    color: var(--im-primary);
    font-weight: 700;
}

/* Legacy support for old class names */
.tournament-participant {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--im-card-border);
    object-fit: cover;
    transition: all 0.2s;
}

.tournament-participant.me {
    border-color: var(--im-primary);
    box-shadow: 0 0 15px var(--im-primary-glow);
}

/* ============================================================
   TOURNAMENT ROUND STATE
   ============================================================ */

.tournament-round {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.round-status {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--im-text-light);
    text-align: center;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.round-status.status-collecting {
    animation: status-pulse 1.5s ease-in-out infinite;
}

.round-status.status-analyzing {
    animation: status-spin 2s linear infinite;
}

.round-status.status-outcome {
    animation: status-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.round-status.success {
    color: var(--im-success);
}

.round-status.eliminated {
    color: var(--im-danger);
}

.round-status.winner {
    color: var(--im-accent);
}

@keyframes status-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

@keyframes status-spin {
    0% {
        transform: perspective(400px) rotateY(0deg);
    }
    100% {
        transform: perspective(400px) rotateY(360deg);
    }
}

@keyframes status-bounce {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    70% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Head to Head (Knockout) */
.head-to-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    width: 100%;
}

.h2h-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 140px;
}

.h2h-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--im-card-border);
    object-fit: cover;
    margin-bottom: 10px;
    transition: all 0.3s;
}

.h2h-player.winner .h2h-avatar {
    border-color: var(--im-success);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.h2h-player.loser .h2h-avatar {
    border-color: var(--im-danger);
    opacity: 0.6;
    filter: grayscale(50%);
}

.h2h-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--im-text-light);
    margin-bottom: 5px;
}

.h2h-score {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--im-text-light);
}

.h2h-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 12px;
    margin-top: 8px;
    text-transform: uppercase;
}

.h2h-badge.win {
    background: var(--im-success);
    color: #000;
}

.h2h-badge.loss {
    background: var(--im-danger);
    color: white;
}

.h2h-vs {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--im-text-muted);
}

/* ============================================================
   TOURNAMENT POST STATE (Podium)
   ============================================================ */

.tournament-post {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    height: 220px;
}

.podium-position {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100px;
}

.podium-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid white;
    object-fit: cover;
    margin-bottom: -10px;
    z-index: 2;
    position: relative;
}

.podium-position.first .podium-avatar {
    width: 75px;
    height: 75px;
    border-color: var(--im-accent);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.5);
}

.podium-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px 10px 0 0;
    font-size: 2rem;
    font-weight: 800;
    color: rgba(0, 0, 0, 0.8);
}

.podium-position.first .podium-bar {
    height: 100px;
    background: linear-gradient(180deg, #FFD700 0%, #FFA500 100%);
}

.podium-position.second .podium-bar {
    height: 70px;
    background: linear-gradient(180deg, #C0C0C0 0%, #808080 100%);
}

.podium-position.third .podium-bar {
    height: 50px;
    background: linear-gradient(180deg, #CD7F32 0%, #8B4513 100%);
}

.podium-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--im-text-light);
    margin-top: 10px;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   HALL GAMES PRE STATE (Waiting Room)
   ============================================================ */

.hall-waiting {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.hall-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--im-text-light);
    text-align: center;
    margin-bottom: 10px;
}

.hall-subtitle {
    font-size: 0.9rem;
    color: var(--im-text-muted);
    margin-bottom: 30px;
}

.hall-activity {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 20px;
    padding: 12px 24px;
    margin-bottom: 30px;
}

.hall-activity-dot {
    width: 10px;
    height: 10px;
    background: var(--im-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.hall-activity-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--im-text-light);
}

.hall-join-warning {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 165, 0, 0.15);
    border: 1px solid rgba(255, 165, 0, 0.3);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
    width: 100%;
}

.hall-join-warning-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.hall-join-warning-text {
    font-size: 0.85rem;
    color: var(--im-text-light);
    line-height: 1.4;
}

/* ============================================================
   SINGLE PLAYER POST STATE
   ============================================================ */

.sp-post {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.sp-post-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--im-accent);
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.rewards-section {
    width: 100%;
    margin-bottom: 30px;
}

.rewards-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 15px;
    text-align: center;
}

.rewards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.reward-card {
    background: var(--im-card-dark);
    border: 1px solid var(--im-card-border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.reward-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.reward-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--im-text-light);
}

/* ============================================================
   SECTION TITLE
   ============================================================ */

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 20px 0 15px;
    text-align: center;
    width: 100%;
}

/* ============================================================
   UTILITIES
   ============================================================ */

.hidden {
    display: none !important;
}

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

.full-width {
    width: 100%;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 500px) {
    .score-ring-container {
        width: 240px;
        height: 240px;
    }

    .score-ring-value {
        font-size: 2.8rem;
    }

    .stat-cards-row {
        gap: 8px;
    }

    .stat-card {
        padding: 14px 8px;
    }

    .stat-card-value {
        font-size: 1.2rem;
    }

    .chat-floating-bar {
        bottom: 10px;
        width: calc(100% - 20px);
    }

    .head-to-head {
        gap: 10px;
    }

    .h2h-avatar {
        width: 60px;
        height: 60px;
    }

    .h2h-score {
        font-size: 1.4rem;
    }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

.chat-inline-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-inline-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-inline-messages::-webkit-scrollbar-thumb {
    background: var(--im-primary);
    border-radius: 3px;
}

/* ============================================================
   TOURNAMENT INFO CARD (for ROUND screens)
   ============================================================ */

.tournament-info-card {
    width: 100%;
    margin-top: 20px;
    background: linear-gradient(135deg, #2d1340 0%, #1a0a28 100%);
    border: 2px solid rgba(255, 45, 120, 0.3);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 32px rgba(255, 45, 120, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.tournament-info-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 45, 120, 0.5);
    box-shadow: 0 12px 40px rgba(255, 45, 120, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.tournament-info-card.expanded {
    animation: elastic-expand 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes elastic-expand {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(1.05);
    }
    50% {
        transform: scale(0.98);
    }
    70% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

.tournament-info-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    position: relative;
}

.tournament-info-header::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 45, 120, 0.3) 50%, transparent 100%);
}

.tournament-trophy-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #2d1340;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.trophy-shine {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.4) 50%, transparent 60%);
    animation: shine 3s ease-in-out infinite;
}

@keyframes shine {
    0%, 100% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    50% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

.tournament-info-main {
    flex: 1;
    min-width: 0;
}

.tournament-info-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    margin-bottom: 5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tournament-info-subtitle {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 6px;
}

.tournament-info-subtitle i {
    font-size: 0.75rem;
    color: var(--im-primary);
}

.prize-dot {
    color: var(--im-primary);
    font-weight: 700;
}

.tournament-expand-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 45, 120, 0.15);
    border: 1px solid rgba(255, 45, 120, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s;
}

.tournament-expand-btn i {
    color: var(--im-primary);
    font-size: 0.95rem;
    transition: transform 0.3s;
}

.tournament-info-card:hover .tournament-expand-btn {
    background: rgba(255, 45, 120, 0.25);
    border-color: rgba(255, 45, 120, 0.5);
}

/* Expanded Section */
.tournament-info-expanded {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.tournament-info-card.expanded .tournament-info-expanded {
    max-height: 800px;
}

.tournament-info-tabs {
    display: flex;
    gap: 8px;
    padding: 16px 16px 0 16px;
    border-bottom: 2px solid rgba(255, 45, 120, 0.2);
}

.tournament-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
}

.tournament-tab.active {
    background: rgba(255, 45, 120, 0.2);
    color: var(--im-primary);
    border-bottom: 2px solid var(--im-primary);
}

.tournament-tab i {
    font-size: 0.9rem;
}

.tournament-content-panels {
    padding: 20px;
}

.tournament-panel {
    display: none;
}

.tournament-panel.active {
    display: block;
}

.tournament-director-badge {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-bottom: 16px;
}

.director-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--im-primary);
    object-fit: cover;
}

.director-info {
    flex: 1;
}

.director-label {
    font-size: 0.7rem;
    color: var(--im-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 3px;
}

.director-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: white;
}

.tournament-description {
    font-size: 0.9rem;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.85);
}

.prizes-showcase {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.prize-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    transition: all 0.2s;
}

.prize-item.first-place {
    border-color: rgba(255, 215, 0, 0.4);
    background: rgba(255, 215, 0, 0.1);
}

.prize-item.second-place {
    border-color: rgba(192, 192, 192, 0.4);
    background: rgba(192, 192, 192, 0.1);
}

.prize-item.third-place {
    border-color: rgba(205, 127, 50, 0.4);
    background: rgba(205, 127, 50, 0.1);
}

.prize-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.prize-details {
    flex: 1;
    min-width: 0;
}

.prize-position {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--im-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.prize-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

/* ============================================================
   BRACKET TREE SCROLL INDICATOR
   ============================================================ */

.bracket-container {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
}

.bracket-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(26, 10, 31, 0.95) 100%);
    pointer-events: none;
    z-index: 100;
}

.bracket-container::before {
    content: '→';
    position: absolute;
    top: 50%;
    right: 25px;
    transform: translateY(-50%);
    font-size: 1.5rem;
    color: var(--im-primary);
    font-weight: 700;
    animation: scroll-pulse 2s ease-in-out infinite;
    pointer-events: none;
    z-index: 11;
    text-shadow: 0 0 10px rgba(255, 45, 120, 0.5);
}

/* Hide arrow and gradient when bracket fits */
.bracket-container.no-overflow::before,
.bracket-container.no-overflow::after {
    display: none;
    z-index: 11;
    text-shadow: 0 0 10px rgba(255, 45, 120, 0.5);
}

@keyframes scroll-pulse {
    0%, 100% {
        opacity: 0.5;
        transform: translateY(-50%) translateX(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-50%) translateX(5px);
    }
}

/* ============================================================
   LEADERBOARD LIVE UPDATE ANIMATIONS
   ============================================================ */

.leaderboard-row {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.leaderboard-row.fly-in {
    animation: fly-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.leaderboard-row.fly-out {
    animation: fly-out 0.5s cubic-bezier(0.6, 0, 0.8, 0.2) forwards;
}

.leaderboard-row.position-change {
    animation: position-change 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.leaderboard-score.score-update {
    animation: score-count-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fly-in {
    0% {
        opacity: 0;
        transform: translateX(-100px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fly-out {
    0% {
        opacity: 1;
        transform: translateX(0);
    }
    100% {
        opacity: 0;
        transform: translateX(100px);
    }
}

@keyframes position-change {
    0%, 100% {
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        border-color: rgba(255, 255, 255, 0.1);
    }
    50% {
        box-shadow: 0 8px 20px rgba(255, 45, 120, 0.4);
        border-color: rgba(255, 45, 120, 0.5);
    }
}

@keyframes score-count-up {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================
   LIVE LEADERBOARD ANIMATIONS
   ============================================================ */

.leaderboard.live {
    position: relative;
    display: block; /* Override flex */
    /* Height will be set dynamically via JS or fixed based on max rows */
    min-height: 60px;
    transition: height 0.3s ease;
}

.leaderboard-row.live {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), 
                opacity 0.8s ease-out, 
                background-color 0.3s ease;
    will-change: transform, opacity;
}

/* Ensure content inside doesn't shift during animation */
.leaderboard-row.live .leaderboard-rank,
.leaderboard-row.live .leaderboard-score {
    transition: color 0.3s;
}

/* Highlight flash */
.leaderboard-row.highlight {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

#intermission-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
    overflow-y: auto;
}

#intermission-container.active {
    pointer-events: auto;
}

