/* ── Bracket layout ──────────────────────────────── */
.bracket-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0;
    overflow-x: auto;
    padding: 24px;
    min-height: 400px;
}

.bracket-round {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 210px;
}

/* Round labels — color-coded by distance from final */
.round-label {
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
    text-align: center;
    padding: 4px 12px;
    border-radius: 20px;
}

.round-label-final {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: #1c1917;
    box-shadow: 0 2px 8px rgba(245,158,11,0.4);
}

.round-label-semi {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    color: white;
    box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

.round-label-quarter {
    background: linear-gradient(135deg, #2563eb, #60a5fa);
    color: white;
}

.round-label-early {
    background: #e5e7eb;
    color: #6b7280;
}

.round-matches {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0;
}

/* Each match slot handles vertical spacing between rounds */
.match-slot {
    display: flex;
    align-items: center;
    position: relative;
    flex: 1;
    padding: 10px 0;
}

/* Connectors from current round to next */
.match-slot::after {
    content: '';
    position: absolute;
    right: -1px;
    top: 50%;
    width: 20px;
    height: 1px;
    background: #c4b5fd;
}

/* Original layout: hide connector on the Final (last) column */
.bracket-wrapper > .bracket-round:last-child .match-slot::after {
    display: none;
}

/* ── Split bracket layout ────────────────────────── */
.bracket-split-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 24px;
    gap: 0;
    min-height: 400px;
}

.bracket-left-side {
    display: flex;
    flex-direction: row;
    align-items: center;
}

/* Row-reverse so R1 (first in DOM) appears outermost (rightmost),
   and the innermost pre-final round sits closest to the Final column */
.bracket-right-side {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
}

/* Final (center) column: no outgoing connector */
.bracket-final .match-slot::after {
    display: none;
}

/* Right-side rounds: connectors point LEFT toward the center */
.bracket-side-right .match-slot::after {
    right: auto;
    left: -1px;
}

/* ── Match card ──────────────────────────────────── */
.match-card {
    background: #fff;
    border: 1.5px solid #e0d9ff;
    border-radius: 10px;
    width: 190px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(91,33,182,0.07);
    transition: box-shadow 0.2s, transform 0.2s;
}

.match-card:hover {
    box-shadow: 0 4px 16px rgba(91,33,182,0.15);
    transform: translateY(-1px);
}

.match-card.completed {
    border-color: #c4b5fd;
}

.match-card.final-match {
    border: 2px solid #f59e0b;
    box-shadow: 0 4px 20px rgba(245,158,11,0.25);
}

.match-card.bye-match {
    opacity: 0.55;
    border-style: dashed;
    border-color: #d1d5db;
}

/* ── Player rows ─────────────────────────────────── */
.player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    min-height: 38px;
    gap: 4px;
}

.player-row.winner {
    background: linear-gradient(90deg, #fef3c7, #fde68a);
    font-weight: 700;
    color: #92400e;
}

.player-row.winner::before {
    content: '★';
    color: #f59e0b;
    margin-right: 4px;
    font-size: 0.75rem;
}

.player-row.loser {
    background: #f9fafb;
    color: #9ca3af;
    text-decoration: line-through;
}

.player-name {
    font-size: 0.875rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.match-divider {
    height: 1px;
    background: #e0d9ff;
}

/* ── Win button ──────────────────────────────────── */
.btn-xs {
    padding: 2px 7px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.5;
    border-radius: 4px;
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
    border: none;
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-xs:hover {
    background: linear-gradient(135deg, #15803d, #166534);
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(22,163,74,0.4);
}

/* ── Connector lines ─────────────────────────────── */
.bracket-connector {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 20px;
    position: relative;
}

.bracket-connector::before {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: 0;
    width: 1px;
    background: #c4b5fd;
}

.bracket-connector::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 20px;
    height: 1px;
    background: #c4b5fd;
}

/* ── Undo / reset button ─────────────────────────── */
.reset-match-btn {
    display: block;
    width: 100%;
    background: none;
    border: none;
    border-top: 1px dashed #e0d9ff;
    color: #9ca3af;
    font-size: 0.7rem;
    padding: 3px 0;
    cursor: pointer;
    text-align: center;
    transition: color 0.15s, background 0.15s;
}

.reset-match-btn:hover {
    color: #dc2626;
    background: #fef2f2;
}

/* ── Mobile bracket ──────────────────────────────── */
@media (max-width: 767px) {
    .bracket-scroll-outer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 12px;
    }

    .match-card { width: 160px; }
    .bracket-round { min-width: 180px; }

    .btn-xs {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .reset-match-btn {
        padding: 6px 0;
        font-size: 0.75rem;
    }

    .champion-banner {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
        padding: 1.25rem 1rem;
        margin: 0 0 1rem;
        border-radius: 12px;
    }

    .champion-banner .replay-btn { margin-left: 0; }

    .round-label {
        font-size: 0.68rem;
        padding: 3px 8px;
    }

    .bracket-scroll-hint {
        display: block;
        text-align: center;
        font-size: 0.75rem;
        color: #9ca3af;
        margin-bottom: 6px;
    }
}

@media (min-width: 768px) {
    .bracket-scroll-hint { display: none; }
}

/* ── Toast ───────────────────────────────────────── */
.bracket-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    min-width: 220px;
    border-radius: 10px;
    font-weight: 600;
    animation: toastSlideIn 0.3s ease;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Winner banner (already-completed page load) ─── */
.champion-banner {
    background: linear-gradient(135deg, #4c1d95, #1e3a8a);
    color: white;
    border-radius: 16px;
    padding: 1.5rem 2rem;
    margin: 0 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 20px rgba(91,33,182,0.3);
    animation: bannerSlideDown 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.champion-banner .trophy {
    font-size: 2.5rem;
    animation: trophyFloat 2.5s ease-in-out infinite;
}

.champion-banner .title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #fde68a;
}

.champion-banner .name {
    font-size: 1.6rem;
    font-weight: 900;
    line-height: 1.1;
}

.champion-banner .replay-btn {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    font-size: 0.8rem;
    border-radius: 20px;
    padding: 4px 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s;
}

.champion-banner .replay-btn:hover {
    background: rgba(255,255,255,0.25);
}

@keyframes bannerSlideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes trophyFloat {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}
