/* =================================================
   CUP BRACKET - Tournament Bracket Visualization
   ================================================= */

/* ==================== MINI BRACKET (Horizontal Tree) ==================== */

.cup-bracket-section {
    margin-bottom: 20px;
}

.bracket-container {
    overflow-x: auto;
    padding: 20px 10px;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* Scroll hint fade on right edge */
.bracket-container::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--bg-card));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.bracket-container.can-scroll::after {
    opacity: 1;
}

.bracket {
    display: flex;
    align-items: stretch;
    min-width: fit-content;
    gap: 0;
}

/* ==================== BRACKET ROUND COLUMN ==================== */

.bracket-round {
    display: flex;
    flex-direction: column;
    min-width: 155px;
}

.bracket-round-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
}

.bracket-ties {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    flex: 1;
    gap: 4px;
}

/* ==================== BRACKET TIE (Single Match/Pair) ==================== */

.bracket-tie {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    margin: 2px 0;
}

.bracket-tie:hover {
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
    transform: translateY(-1px);
}

.bracket-tie.completed {
    border-left: 3px solid var(--success);
}

.bracket-tie.live {
    border-left: 3px solid var(--danger);
    animation: pulse-bracket 2s infinite;
}

.bracket-tie.simulating {
    border-left: 3px solid var(--info);
}

.bracket-tie.upcoming {
    border-left: 3px solid var(--warning);
}

.bracket-tie.bye {
    border-left: 3px solid var(--border-light);
    opacity: 0.6;
    cursor: default;
}

.bracket-tie.tbd {
    border-left: 3px solid var(--border-color);
    opacity: 0.4;
    cursor: default;
}

@keyframes pulse-bracket {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* ==================== BRACKET TEAM LINE ==================== */

.bracket-team {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-height: 22px;
}

.bracket-team:first-child {
    border-bottom: 1px solid var(--border-color);
}

.bracket-team.winner {
    font-weight: 700;
    color: var(--gold);
}

.bracket-team-strip {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex-shrink: 0;
}

.bracket-team-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.bracket-team-score {
    font-weight: 600;
    min-width: 12px;
    text-align: right;
    font-size: 0.75rem;
}

.bracket-team-bye,
.bracket-team-tbd {
    flex: 1;
    color: var(--text-disabled);
    font-style: italic;
    font-size: 0.7rem;
}

/* ==================== BRACKET CONNECTORS ==================== */

.bracket-connector {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 20px;
    flex-shrink: 0;
    position: relative;
}

.connector-pair {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
}

/* Right bracket line: top half goes down, bottom half goes up, both meet in middle */
.connector-pair::before {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    bottom: 25%;
    width: 0;
    border-right: 2px solid var(--border-light);
}

/* Horizontal line from vertical to next round */
.connector-pair::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    width: 100%;
    height: 0;
    border-top: 2px solid var(--border-light);
}

/* Lines from ties to connector */
.bracket-tie-wrapper {
    position: relative;
}

.bracket-tie-wrapper::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    width: 10px;
    height: 0;
    border-top: 2px solid var(--border-light);
}

.bracket-tie-wrapper.no-connector::after {
    display: none;
}

/* ==================== CHAMPION DISPLAY ==================== */

.bracket-champion {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 0 10px;
}

.champion-trophy {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.champion-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--gold);
    text-align: center;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.champion-strip {
    width: 20px;
    height: 20px;
    object-fit: contain;
    margin-bottom: 2px;
}

/* ==================== ROUND DETAIL SECTION ==================== */

.bracket-detail {
    margin-top: 20px;
}

.round-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.round-tab {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.round-tab:hover {
    border-color: var(--primary);
    color: var(--text-primary);
}

.round-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text-light);
    font-weight: 600;
}

.round-tab .tab-leg {
    font-size: 0.65rem;
    opacity: 0.8;
    display: block;
    text-align: center;
}

/* ==================== ROUND MATCH CARDS (Detail View) ==================== */

.round-matches {
    display: grid;
    gap: 12px;
}

.tie-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.tie-card.completed {
    border-left: 4px solid var(--success);
}

.tie-card.live {
    border-left: 4px solid var(--danger);
    animation: pulse-bracket 2s infinite;
}

.tie-card.simulating {
    border-left: 4px solid var(--info);
}

.tie-card.upcoming {
    border-left: 4px solid var(--warning);
}

/* Tie header with aggregate */
.tie-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.03);
}

.tie-teams-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.tie-teams-summary img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.tie-vs {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.8rem;
}

.tie-aggregate {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tie-aggregate .agg-score {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.tie-winner-badge {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Individual leg row inside a tie card */
.tie-leg {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 12px;
    align-items: center;
    padding: 10px 15px;
    border-top: 1px solid var(--border-color);
}

.leg-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.leg-match {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 15px;
    align-items: center;
}

.leg-team {
    display: flex;
    align-items: center;
    gap: 6px;
}

.leg-team.away {
    justify-content: flex-end;
}

.leg-team img {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.leg-team-name {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.leg-team-name a {
    color: var(--text-primary);
    text-decoration: none;
}

.leg-team-name a:hover {
    color: var(--text-link);
}

.leg-score {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    min-width: 45px;
}

.leg-score a {
    color: inherit;
    text-decoration: none;
    transition: transform 0.2s;
    display: inline-block;
}

.leg-score a:hover {
    transform: scale(1.1);
    color: var(--secondary);
}

.leg-score .vs-text {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
}

.leg-date {
    font-size: 0.7rem;
    color: var(--text-disabled);
    text-align: center;
    margin-top: 2px;
}

.leg-live-indicator {
    font-size: 0.65rem;
    font-weight: bold;
    color: var(--danger);
    animation: blink-live 1s infinite;
}

@keyframes blink-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Single-leg tie (no leg labels needed) */
.tie-single-leg .tie-leg {
    grid-template-columns: 1fr;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 768px) {
    .bracket-container {
        padding: 10px 5px;
    }

    .bracket-round {
        min-width: 125px;
    }

    .bracket-team-name {
        max-width: 55px;
    }

    .bracket-tie {
        min-width: 115px;
    }

    .bracket-team {
        font-size: 0.7rem;
        padding: 2px 4px;
    }

    .bracket-team-strip {
        width: 12px;
        height: 12px;
    }

    .bracket-connector {
        width: 14px;
    }

    .round-tabs {
        gap: 4px;
    }

    .round-tab {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .tie-leg {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .leg-label {
        text-align: left;
        padding-bottom: 4px;
        border-bottom: 1px solid var(--border-color);
    }

    .leg-match {
        gap: 8px;
    }

    .leg-team-name {
        font-size: 0.8rem;
    }

    .tie-header {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .bracket-round {
        min-width: 110px;
    }

    .bracket-team-name {
        max-width: 45px;
        font-size: 0.65rem;
    }

    .bracket-round-title {
        font-size: 0.6rem;
    }
}
