/* ===================================
   Tournament Brackets - Frontend
   =================================== */

/* CSS Variables */
.tb-bracket-wrap {
    --tb-bg: #0f1923;
    --tb-surface: #1a2736;
    --tb-surface-hover: #223344;
    --tb-border: #2a3a4a;
    --tb-text: #e8edf2;
    --tb-text-muted: #7a8fa0;
    --tb-accent: #3b82f6;
    --tb-accent-glow: rgba(59, 130, 246, 0.3);
    --tb-winner: #22c55e;
    --tb-winner-bg: rgba(34, 197, 94, 0.1);
    --tb-loser-opacity: 0.45;
    --tb-home: #3b82f6;
    --tb-away: #f59e0b;
    --tb-connector: #2a3a4a;
    --tb-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --tb-game-width: 240px;
    --tb-game-gap: 8px;
    --tb-round-gap: 48px;

    font-family: var(--tb-font);
    color: var(--tb-text);
    background: var(--tb-bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

/* Light theme overrides */
.tb-theme-light {
    --tb-bg: #f4f6f8;
    --tb-surface: #ffffff;
    --tb-surface-hover: #f0f2f5;
    --tb-border: #d4d9e0;
    --tb-text: #1a2332;
    --tb-text-muted: #6b7a8d;
    --tb-connector: #c4cdd6;
    --tb-winner-bg: rgba(34, 197, 94, 0.08);
}

/* Header */
.tb-bracket-header {
    padding: 24px 28px 16px;
    border-bottom: 1px solid var(--tb-border);
}

.tb-bracket-title {
    font-size: 22px;
    font-weight: 800;
    margin: 0 0 8px 0;
    color: var(--tb-text);
    letter-spacing: -0.3px;
}

.tb-bracket-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--tb-text-muted);
}

.tb-sport-badge {
    background: var(--tb-accent);
    color: #fff;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tb-live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tb-text-muted);
    margin-top: 8px;
}

.tb-live-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: tb-pulse 1.5s infinite;
}

@keyframes tb-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* Bracket container */
.tb-bracket-container {
    padding: 20px;
}

.tb-bracket-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 16px;
}

.tb-bracket-rounds {
    display: flex;
    align-items: flex-start;
    gap: var(--tb-round-gap);
    min-width: min-content;
}

/* Round column */
.tb-round {
    flex-shrink: 0;
    width: var(--tb-game-width);
}

.tb-round-header {
    text-align: center;
    padding: 8px 0 16px;
}

.tb-round-name {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--tb-text-muted);
}

/* Games in a round - use flexbox with spacing that aligns to bracket lines */
.tb-round-games {
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Dynamically space games based on round depth */
.tb-round[data-round="0"] .tb-round-games {
    gap: var(--tb-game-gap);
}

.tb-round[data-round="1"] .tb-round-games {
    gap: calc(var(--tb-game-gap) + 60px);
    padding-top: 30px;
}

.tb-round[data-round="2"] .tb-round-games {
    gap: calc(var(--tb-game-gap) + 190px);
    padding-top: 96px;
}

.tb-round[data-round="3"] .tb-round-games {
    gap: calc(var(--tb-game-gap) + 440px);
    padding-top: 226px;
}

.tb-round[data-round="4"] .tb-round-games {
    padding-top: 486px;
}

/* 24-team specific: first round has 8 games, round 2 also has 8 */
.tb-size-24 .tb-round[data-round="1"] .tb-round-games {
    gap: var(--tb-game-gap);
    padding-top: 0;
}

.tb-size-24 .tb-round[data-round="2"] .tb-round-games {
    gap: calc(var(--tb-game-gap) + 60px);
    padding-top: 30px;
}

.tb-size-24 .tb-round[data-round="3"] .tb-round-games {
    gap: calc(var(--tb-game-gap) + 190px);
    padding-top: 96px;
}

.tb-size-24 .tb-round[data-round="4"] .tb-round-games {
    padding-top: 226px;
}

/* 32-team adjustments */
.tb-size-32 .tb-round[data-round="0"] .tb-round-games {
    gap: 4px;
}

.tb-size-32 .tb-round[data-round="1"] .tb-round-games {
    gap: calc(4px + 52px);
    padding-top: 26px;
}

.tb-size-32 .tb-round[data-round="2"] .tb-round-games {
    gap: calc(4px + 160px);
    padding-top: 82px;
}

.tb-size-32 .tb-round[data-round="3"] .tb-round-games {
    gap: calc(4px + 376px);
    padding-top: 190px;
}

.tb-size-32 .tb-round[data-round="4"] .tb-round-games {
    padding-top: 406px;
}

/* Individual game card */
.tb-game {
    background: var(--tb-surface);
    border: 1px solid var(--tb-border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
}

.tb-game:hover {
    border-color: var(--tb-accent);
    box-shadow: 0 0 0 1px var(--tb-accent-glow);
}

.tb-game-complete {
    border-color: var(--tb-winner);
}

.tb-game-final {
    border-width: 2px;
}

/* Game location bar */
.tb-game-location {
    font-size: 10px;
    text-align: center;
    padding: 3px 8px;
    background: rgba(255,255,255,0.05);
    color: var(--tb-text-muted);
    border-bottom: 1px solid var(--tb-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tb-location-icon {
    margin-right: 3px;
}

/* Team row */
.tb-team {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    min-height: 34px;
    transition: background-color 0.2s, opacity 0.2s;
}

.tb-team:first-child {
    border-bottom: 1px solid var(--tb-border);
}

.tb-team-winner {
    background: var(--tb-winner-bg);
}

.tb-team-loser {
    opacity: var(--tb-loser-opacity);
}

.tb-team-info {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

/* Seed number */
.tb-seed {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 10px;
    font-weight: 700;
    color: var(--tb-text-muted);
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    flex-shrink: 0;
}

.tb-theme-light .tb-seed {
    background: rgba(0,0,0,0.06);
}

/* Team logo */
.tb-team-logo {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    object-fit: contain;
    flex-shrink: 0;
}

/* Team name */
.tb-team-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tb-tbd {
    color: var(--tb-text-muted);
    font-style: italic;
    font-weight: 400;
}

/* Home/away tags */
.tb-home-away-tag {
    font-size: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 4px;
    border-radius: 3px;
    flex-shrink: 0;
}

.tb-home-tag {
    background: rgba(59, 130, 246, 0.15);
    color: var(--tb-home);
}

.tb-away-tag {
    background: rgba(245, 158, 11, 0.15);
    color: var(--tb-away);
}

/* Score */
.tb-score {
    font-size: 15px;
    font-weight: 800;
    min-width: 28px;
    text-align: center;
    color: var(--tb-text-muted);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.tb-score-final {
    color: var(--tb-text);
}

.tb-team-winner .tb-score {
    color: var(--tb-winner);
}

.tb-bye-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--tb-text-muted);
    letter-spacing: 1px;
}

/* Bye game */
.tb-game-bye {
    padding: 3px 0;
}

.tb-team-bye-winner {
    padding: 8px 10px;
}

/* Champion column */
.tb-champion-column {
    flex-shrink: 0;
    width: 160px;
    text-align: center;
}

.tb-champion-card {
    background: var(--tb-surface);
    border: 2px dashed var(--tb-border);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    margin-top: 20px;
    transition: all 0.3s;
}

.tb-champion-card.tb-has-champion {
    border-style: solid;
    border-color: #f59e0b;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(234, 179, 8, 0.05));
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.15);
}

.tb-champion-trophy {
    font-size: 36px;
    margin-bottom: 8px;
}

.tb-trophy-pending {
    opacity: 0.3;
}

.tb-champion-logo {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: contain;
    margin: 0 auto 8px;
    display: block;
}

.tb-champion-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--tb-text);
}

/* Connector lines */
/* These use CSS pseudo-elements to draw lines between rounds */
.tb-round[data-round]:not([data-round="0"]) .tb-game::before {
    content: '';
    position: absolute;
    left: -25px;
    top: 50%;
    width: 25px;
    height: 1px;
    background: var(--tb-connector);
}

.tb-size-24 .tb-round[data-round="1"] .tb-game::before {
    content: '';
    left: -25px;
    top: 50%;
    width: 25px;
    height: 1px;
    background: var(--tb-connector);
}

/* Error state */
.tb-error {
    padding: 20px;
    text-align: center;
    color: #ef4444;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .tb-bracket-wrap {
        --tb-game-width: 200px;
        --tb-round-gap: 32px;
        border-radius: 8px;
    }

    .tb-bracket-header {
        padding: 16px 18px 12px;
    }

    .tb-bracket-title {
        font-size: 18px;
    }

    .tb-team-name {
        font-size: 12px;
    }

    .tb-score {
        font-size: 13px;
    }

    .tb-home-away-tag {
        display: none;
    }
}

@media (max-width: 480px) {
    .tb-bracket-wrap {
        --tb-game-width: 180px;
        --tb-round-gap: 24px;
    }

    .tb-bracket-container {
        padding: 12px;
    }

    .tb-seed {
        display: none;
    }
}

/* Print styles */
@media print {
    .tb-bracket-wrap {
        background: #fff !important;
        color: #000 !important;
    }

    .tb-live-indicator {
        display: none;
    }

    .tb-game {
        break-inside: avoid;
    }
}

/* ===========================
   Seed Legend
   =========================== */
.tb-seed-legend {
    margin: 0 20px 20px;
    background: var(--tb-surface);
    border: 1px solid var(--tb-border);
    border-radius: 8px;
    overflow: hidden;
}

.tb-seed-legend-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--tb-border);
    background: rgba(255,255,255,0.03);
}

.tb-seed-legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--tb-text-muted);
}

.tb-seed-legend-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0;
}

.tb-seed-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.15s;
}

.tb-theme-light .tb-seed-legend-item {
    border-bottom-color: rgba(0,0,0,0.04);
}

.tb-seed-legend-item:hover {
    background: rgba(255,255,255,0.03);
}

.tb-theme-light .tb-seed-legend-item:hover {
    background: rgba(0,0,0,0.02);
}

.tb-seed-legend-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    font-size: 11px;
    font-weight: 800;
    color: var(--tb-accent);
    background: rgba(59, 130, 246, 0.12);
    border-radius: 5px;
    flex-shrink: 0;
    padding: 0 4px;
}

.tb-seed-legend-logo {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    object-fit: contain;
    flex-shrink: 0;
}

.tb-seed-legend-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--tb-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .tb-seed-legend-list {
        grid-template-columns: 1fr;
    }
}
