* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --league-red: #dc2626;
    --league-red-dark: #991b1b;
    --league-black: #0a0a0a;
    --league-gray: #1f1f1f;
    --chalk-white: #f8f9fa;
    --white-soft: #e5e7eb;
    --red-glow: rgba(220, 38, 38, 0.3);
    --shadow-deep: rgba(0, 0, 0, 0.6);
}

body {
    font-family: 'Pathway Extreme', sans-serif;
    background: linear-gradient(135deg, var(--league-black) 0%, var(--league-gray) 100%);
    color: var(--chalk-white);
    min-height: 100vh;
    padding-bottom: 2rem;
    position: relative;
    overflow-x: hidden;
}

body.admin {
    --league-black: #f8f9fa;
    --league-gray: #e5e7eb;
    --chalk-white: #0a0a0a;
    --white-soft: #1f1f1f;
    --shadow-deep: rgba(0, 0, 0, 0.08);
    background: linear-gradient(135deg, #f8f9fa 0%, #e5e7eb 100%) !important;
    color: #0a0a0a !important;
}

body.admin .mode-badge {
    background: var(--league-red-dark);
    color: var(--chalk-white);
}

body.admin header {
    background: rgba(255, 255, 255, 0.7);
    border: 2px solid var(--league-red-dark);
}

body.admin .container,
body.admin .bracket-container,
body.admin .division-selector {
    background: rgba(255, 255, 255, 0.7) !important;
    color: var(--league-black) !important;
    border-color: var(--league-red-dark) !important;
}

body.admin .auth-btn,
body.admin .reset-btn,
body.admin .logout-btn {
    background: linear-gradient(135deg, var(--league-red-dark) 0%, var(--league-red) 100%) !important;
    color: var(--chalk-white) !important;
    border-color: var(--league-red-dark) !important;
}

body.admin .game-card,
body.admin .bracket-game,
body.admin .team,
body.admin .bracket-team {
    background: rgba(0, 0, 0, 0.04) !important;
    color: var(--chalk-white) !important;
}

body.admin .team.winner,
body.admin .bracket-team.winner {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.08) 0%, rgba(220, 38, 38, 0.04) 100%) !important;
    color: var(--league-red-dark) !important;
}

body.admin .team.loser,
body.admin .bracket-team.loser {
    opacity: 0.5;
}

body.admin .championship-banner {
    background: linear-gradient(135deg, var(--league-red-dark) 0%, var(--league-red) 100%) !important;
    color: var(--chalk-white) !important;
    border-color: var(--league-red-dark) !important;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 50px,
            rgba(220, 38, 38, 0.02) 50px,
            rgba(220, 38, 38, 0.02) 52px);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1.5rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px var(--shadow-deep);
}

h1 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 2.5rem;
    letter-spacing: 3px;
    color: var(--league-red);
    text-shadow: 3px 3px 0 var(--shadow-deep);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--chalk-white);
    opacity: 0.9;
    letter-spacing: 1px;
}

.league-logo {
    width: 90px;
    height: 90px;
    object-fit: contain;
    margin-bottom: 0.75rem;
    filter: drop-shadow(0 4px 12px rgba(220, 38, 38, 0.4));
}

.mode-badge {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: var(--league-red);
    color: var(--chalk-white);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.mode-badge.viewer {
    background: rgba(220, 38, 38, 0.3);
}

.auth-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.auth-modal.active {
    display: flex;
}

.auth-box {
    background: var(--league-gray);
    border: 2px solid var(--league-red);
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.auth-box h2 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.8rem;
    letter-spacing: 2px;
    color: var(--league-red);
    margin-bottom: 1rem;
}

.auth-box p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

.password-input {
    width: 100%;
    padding: 0.875rem;
    margin-bottom: 1rem;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(220, 38, 38, 0.3);
    border-radius: 8px;
    color: var(--chalk-white);
    font-size: 1rem;
    font-family: 'Pathway Extreme', sans-serif;
}

.password-input:focus {
    outline: none;
    border-color: var(--league-red);
    background: rgba(0, 0, 0, 0.6);
}

.password-input::placeholder {
    color: rgba(248, 249, 250, 0.4);
}

.auth-btn {
    width: 100%;
    padding: 0.875rem;
    background: linear-gradient(135deg, var(--league-red) 0%, var(--league-red-dark) 100%);
    border: 2px solid var(--league-red);
    border-radius: 8px;
    color: var(--chalk-white);
    font-family: 'Bebas Neue', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.auth-btn:active {
    transform: scale(0.98);
}

.auth-cancel-btn {
    width: 100%;
    padding: 0.75rem;
    margin-top: 0.5rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--chalk-white);
    font-family: 'Pathway Extreme', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.auth-cancel-btn:hover {
    opacity: 1;
}

.auth-error {
    color: #ff6b6b;
    margin-bottom: 1rem;
    font-weight: 600;
    min-height: 1.2rem;
}

.division-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.division-btn {
    flex: 1;
    padding: 0.875rem 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--chalk-white);
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.1rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.division-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: var(--red-glow);
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.division-btn:active::before {
    width: 300px;
    height: 300px;
}

.division-btn.active {
    background: var(--league-red);
    color: var(--chalk-white);
    border-color: var(--league-red);
    font-weight: 800;
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--red-glow);
}

.bracket-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 1.5rem 1rem;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px var(--shadow-deep);
}

.round-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.3rem;
    letter-spacing: 2px;
    color: var(--league-red);
    margin-bottom: 1rem;
    text-align: center;
    border-bottom: 2px solid rgba(220, 38, 38, 0.4);
    padding-bottom: 0.5rem;
}

.game-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.game-card:active {
    transform: scale(0.98);
}

.game-card.disabled {
    cursor: default;
    opacity: 0.7;
}

.game-header {
    font-size: 0.75rem;
    color: var(--white-soft);
    margin-bottom: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.7;
}

.matchup {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.team {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.team::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--league-red);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.team:active {
    transform: scale(0.97);
}

.team.winner {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.25) 0%, rgba(220, 38, 38, 0.15) 100%);
    border-color: var(--league-red);
}

.team.winner::before {
    transform: scaleY(1);
}

.team.loser {
    opacity: 0.4;
    background: rgba(0, 0, 0, 0.5);
}

.team.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.team-name {
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.team.winner .team-name {
    color: var(--league-red);
    font-weight: 800;
}

.winner-indicator {
    font-size: 1.2rem;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.team.winner .winner-indicator {
    opacity: 1;
    transform: scale(1);
}

.bracket-view {
    display: none;
    padding: 1rem 0.5rem;
    overflow-x: auto;
}

.bracket-view.active {
    display: block;
}

.rounds-container {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
    min-width: max-content;
}

.round {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-width: 180px;
    position: relative;
}

.bracket-game-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 5.75rem;
    position: relative;
    width: 100%;
}

.round-connected .connected-slot::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 50%;
    width: 1.5rem;
    height: 2px;
    background: rgba(220, 38, 38, 0.65);
    transform: translateY(-50%);
}

.round-connected .connected-slot::after {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: calc(0.85rem / -2);
    bottom: calc(0.85rem / -2);
    width: 2px;
    background: rgba(220, 38, 38, 0.65);
}

/* first game in a multi-game round (nth-child(2) = first slot after the round title) */
.round-connected .connected-slot:nth-child(2):not(:last-child)::after {
    top: 50%;
    bottom: calc(0.85rem / -2);
}

/* last game in a multi-game round */
.round-connected .connected-slot:last-of-type::after {
    top: calc(0.85rem / -2);
    bottom: 50%;
}

/* single game in a round (championship, winners finals, etc.) — full-height bracket */
.round-connected .connected-slot:nth-child(2):last-child::after {
    top: 0;
    bottom: 0;
}

.bracket-bye {
    text-align: center;
    padding: 0.4rem 0.8rem;
    color: var(--chalk-white);
    opacity: 0.35;
    font-size: 0.8rem;
    font-style: italic;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    letter-spacing: 1px;
    width: 100%;
}

.bracket-game {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 0.5rem;
    margin: 0;
    border: 2px solid rgba(255, 255, 255, 0.1);
    width: 100%;
}

.bracket-team {
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    margin: 0.25rem 0;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: default;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.bracket-team.selectable {
    cursor: pointer;
}

.bracket-team.winner {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.25) 0%, rgba(220, 38, 38, 0.15) 100%);
    border-color: var(--league-red);
    font-weight: 700;
    color: var(--league-red);
}

.bracket-team.loser {
    opacity: 0.4;
}

.bracket-team.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.reset-btn {
    width: 100%;
    padding: 1rem;
    margin-top: 1.5rem;
    background: rgba(220, 38, 38, 0.1);
    border: 2px solid var(--league-red);
    border-radius: 10px;
    color: var(--chalk-white);
    font-family: 'Pathway Extreme', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:active {
    transform: scale(0.98);
    background: rgba(220, 38, 38, 0.2);
}

.reset-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.top-bar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 500;
    background: rgba(10, 10, 10, 0.97);
    border-bottom: 2px solid var(--league-red);
    padding: 0.6rem 1rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    backdrop-filter: blur(8px);
}

.top-bar-admin-label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--league-red);
    text-transform: uppercase;
}

.top-bar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.viewer-refresh-btn {
    padding: 0.4rem 0.9rem;
    background: rgba(220, 38, 38, 0.2);
    border: 1px solid var(--league-red);
    border-radius: 6px;
    color: var(--chalk-white);
    font-family: 'Pathway Extreme', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.viewer-refresh-btn:active {
    transform: scale(0.96);
    background: rgba(220, 38, 38, 0.4);
}

.viewer-refresh-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--chalk-white);
    opacity: 0.5;
    white-space: nowrap;
}

.logout-btn {
    width: 100%;
    padding: 0.75rem;
    margin-top: 1rem;
    background: rgba(220, 38, 38, 0.2);
    border: 2px solid var(--league-red);
    border-radius: 8px;
    color: var(--chalk-white);
    font-family: 'Pathway Extreme', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.logout-btn:active {
    transform: scale(0.98);
}

.championship-banner {
    background: linear-gradient(135deg, var(--league-red) 0%, var(--league-red-dark) 100%);
    color: var(--chalk-white);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    margin-top: 1.5rem;
    border: 3px solid var(--league-red);
    box-shadow: 0 8px 32px var(--red-glow);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

.championship-banner h2 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 2rem;
    letter-spacing: 3px;
    margin-bottom: 0.5rem;
    color: var(--chalk-white);
}

.championship-banner .champion {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--chalk-white);
}

.bracket-section-banner {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.1rem;
    letter-spacing: 3px;
    text-align: center;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    margin: 1.5rem 0 0.75rem 0;
}

.bracket-section-banner.winners {
    background: rgba(220, 38, 38, 0.15);
    border: 2px solid rgba(220, 38, 38, 0.5);
    color: var(--league-red);
}

.bracket-section-banner.losers {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: var(--white-soft);
}

.bracket-section-banner.finals {
    background: rgba(234, 179, 8, 0.1);
    border: 2px solid rgba(234, 179, 8, 0.5);
    color: #eab308;
}

.vs-divider {
    text-align: center;
    color: var(--white-soft);
    font-size: 0.8rem;
    font-weight: 700;
    margin: 0.25rem 0;
    letter-spacing: 2px;
    opacity: 0.6;
}

@media (max-width: 768px) {
    .bracket-container {
        padding: 1.25rem 0.85rem;
    }

    .rounds-container {
        gap: 1rem;
    }

    .round-connected .connected-slot::before {
        left: -1rem;
        width: 1rem;
    }

    .round-connected .connected-slot::after {
        left: -1rem;
        top: calc(0.7rem / -2);
        bottom: calc(0.7rem / -2);
    }

    .round-connected .connected-slot:nth-child(2):not(:last-child)::after {
        top: 50%;
        bottom: calc(0.7rem / -2);
    }

    .round-connected .connected-slot:last-of-type::after {
        top: calc(0.7rem / -2);
        bottom: 50%;
    }

    .round {
        gap: 0.7rem;
        min-width: 152px;
    }

    .round-title {
        font-size: 1.15rem;
        letter-spacing: 1.5px;
    }

    .bracket-game-slot {
        min-height: 5.1rem;
    }

    .bracket-game {
        padding: 0.4rem;
    }

    .bracket-team {
        padding: 0.55rem 0.7rem;
        font-size: 0.9rem;
    }

    .bracket-bye {
        padding: 0.35rem 0.6rem;
        font-size: 0.74rem;
    }
}


@media (max-width: 400px) {
    h1 {
        font-size: 2rem;
    }

    .division-btn {
        font-size: 0.95rem;
        padding: 0.75rem 0.5rem;
    }
}
