:root {
    --bg: #0f1220;
    --bg2: #171d31;
    --card: #1d2440;
    --card-border: #334066;
    --text: #f2f0e8;
    --text2: #b8b3a4;
    --text3: #7f8293;
    --blue: #79a8ff;
    --green: #34d399;
    --red: #f87171;
    --orange: #f0c36a;
    --purple: #8f88c8;
    --gold: #f2d27a;
    --silver: #d8d7d2;
    --bronze: #d69a4c;
    --radius: 14px;
    --shadow: 0 18px 44px rgba(5, 8, 18, .34);
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(242, 210, 122, .08), transparent 28%),
        radial-gradient(circle at top right, rgba(121, 168, 255, .08), transparent 24%),
        linear-gradient(180deg, #0d111d 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* ---- HEADER ---- */
header {
    padding: 28px 0 20px;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 24px;
    position: sticky;
    top: 0;
    background: rgba(15, 18, 32, .92);
    backdrop-filter: blur(14px);
    z-index: 100;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

header h1 {
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.update-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .8rem;
    color: var(--text2);
}

.update-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--red);
    display: inline-block;
    flex-shrink: 0;
}

.update-dot.live {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%,100% { opacity:1; }
    50% { opacity:.4; }
}

/* ---- CARDS ---- */
.card {
    background: linear-gradient(180deg, rgba(35, 43, 72, .96), rgba(28, 35, 61, .96));
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.card-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.card-header .subtitle {
    width: 100%;
    font-size: .8rem;
    color: var(--text3);
    margin-top: -6px;
}

.badge {
    font-size: .7rem;
    font-weight: 600;
    padding: 4px 10px;
    background: rgba(242, 210, 122, .08);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    color: var(--gold);
}

/* ---- TABS ---- */
.tab-bar { display:flex; gap:4px; }

.tab {
    padding: 5px 14px;
    font-size: .75rem;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid var(--card-border);
    background: transparent;
    color: var(--text2);
    border-radius: 8px;
    cursor: pointer;
    transition: .15s;
}

.tab:hover { border-color: var(--blue); color: var(--text); }
.tab.active {
    background: linear-gradient(180deg, var(--gold), var(--orange));
    border-color: var(--orange);
    color:#33270d;
}

/* ---- TABLES ---- */
.table-wrap { overflow-x:auto; }

table { width:100%; border-collapse:collapse; font-size:.85rem; }

thead th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text3);
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}

tbody td {
    padding: 12px;
    border-bottom: 1px solid rgba(36,48,81,.5);
    white-space: nowrap;
}

tbody tr { transition: background .1s; }
tbody tr:hover { background: rgba(78,140,255,.06); }

.rank-col { width:40px; text-align:center; }
.player-col { font-weight: 600; }
.player-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    border: 1px solid var(--card-border);
    background: var(--bg2);
    flex-shrink: 0;
    padding: 2px;
}

.loading-cell {
    text-align: center;
    padding: 30px;
    color: var(--text3);
    font-style: italic;
}

/* Rank medals */
.rank-1 { color: var(--gold); font-weight:800; }
.rank-2 { color: var(--silver); font-weight:700; }
.rank-3 { color: var(--bronze); font-weight:700; }

/* Points bar */
.pts-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pts-bar {
    flex:1;
    height: 6px;
    background: var(--bg2);
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.pts-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .5s ease;
}

.pts-value {
    font-weight: 700;
    min-width: 30px;
}

.max-pts { color: var(--text2); font-size:.8rem; }

.win-prob {
    font-weight: 700;
    font-size: .95rem;
}

.leaderboard-card {
    padding: 28px;
}

.leaderboard-card .card-header h2 {
    font-size: 1.4rem;
}

#leaderboard {
    font-size: 1rem;
}

#leaderboard thead th {
    padding: 14px 14px;
    font-size: .82rem;
}

#leaderboard tbody td {
    padding: 18px 14px;
}

#leaderboard .rank-col {
    width: 64px;
    font-size: 1.35rem;
    font-weight: 800;
}

#leaderboard .player-col {
    font-size: 1.15rem;
    font-weight: 700;
}

#leaderboard .player-avatar {
    width: 44px;
    height: 44px;
}

#leaderboard .pts-value {
    min-width: 42px;
    font-size: 1.35rem;
    font-weight: 800;
}

#leaderboard .pts-bar {
    height: 10px;
    border-radius: 999px;
}

#leaderboard .pts-bar-fill {
    border-radius: 999px;
}

#leaderboard .max-pts {
    font-size: 1rem;
    font-weight: 600;
}

#leaderboard .win-prob {
    font-size: 1.15rem;
    font-weight: 800;
}

/* ---- GAMES GRID ---- */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
}

.game-card {
    background: var(--bg2);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 16px;
    transition: .15s;
}

.game-card.state-in {
    border-color: var(--red);
    box-shadow: 0 0 12px rgba(248,113,113,.15);
}

.game-card.state-post { opacity: .7; }
.game-card.state-post:hover { opacity: 1; }

.game-round {
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text3);
    margin-bottom: 10px;
}

.game-matchup {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.game-team-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.game-seed {
    font-size: .7rem;
    font-weight: 700;
    color: var(--text3);
    background: var(--card);
    width: 22px; height: 22px;
    display: flex; align-items:center; justify-content:center;
    border-radius: 4px;
    flex-shrink: 0;
}

.game-team-name {
    flex: 1;
    font-weight: 600;
    font-size: .9rem;
}

.game-team-name.winner { color: var(--green); }
.game-team-name.loser { color: var(--text3); text-decoration: line-through; }

.game-score {
    font-weight: 800;
    font-size: 1.05rem;
    min-width: 30px;
    text-align: right;
}

.game-score.winner { color: var(--green); }

.game-status {
    font-size: .7rem;
    font-weight: 600;
    text-align: center;
    padding-top: 6px;
    border-top: 1px solid var(--card-border);
}

.game-status.live { color: var(--red); }
.game-status.final { color: var(--text3); }
.game-status.pre { color: var(--text2); }

/* ---- ROOTING GUIDE ---- */
.rooting-game {
    background: var(--bg2);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 14px;
}

.rooting-game-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.rooting-game-header .matchup-label {
    font-weight: 700;
    font-size: 1.05rem;
}

.rooting-game-header .vs { color: var(--text3); font-weight: 400; }

.rooting-game-header .live-badge {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    background: var(--red);
    color: white;
    border-radius: 4px;
    letter-spacing: .5px;
}

.rooting-game-header .spread-badge {
    font-size: .75rem;
    color: var(--text2);
    margin-left: auto;
}

.rooting-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.rooting-col {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
}

.rooting-col.team1-col { border-left: 3px solid var(--blue); }
.rooting-col.team2-col { border-left: 3px solid var(--red); }

.rooting-col h4 {
    font-size: .8rem;
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rooting-col.team1-col h4 { color: var(--blue); }
.rooting-col.team2-col h4 { color: var(--red); }

.rooting-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: .82rem;
    border-bottom: 1px solid rgba(36,48,81,.4);
}

.rooting-player:last-child { border-bottom: none; }

.rooting-player .rp-name {
    font-weight: 500;
    min-width: 0;
}

.rooting-player .rp-name .player-label {
    display: inline-flex;
    max-width: 100%;
}

.rooting-player .rp-delta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    font-weight: 800;
    font-size: .92rem;
    text-align: right;
}

.rp-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 999px;
    letter-spacing: .02em;
    line-height: 1;
}

.rp-pill-label {
    font-size: .68rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.rp-pill-value {
    font-size: 1rem;
    font-weight: 900;
}

.rp-pill-win {
    background: rgba(52,211,153,.14);
    box-shadow: inset 0 0 0 1px rgba(52,211,153,.22);
    color: var(--green);
}

.rp-pill-lose {
    background: rgba(248,113,113,.14);
    box-shadow: inset 0 0 0 1px rgba(248,113,113,.22);
    color: var(--red);
}

.rp-pill-points {
    background: rgba(78,140,255,.12);
    box-shadow: inset 0 0 0 1px rgba(78,140,255,.18);
    color: var(--blue);
}

.rooting-empty {
    font-size: .78rem;
    color: var(--text3);
    font-style: italic;
}

/* ---- SURVIVAL ---- */
.alive-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
}

.alive-tag.yes { background: rgba(52,211,153,.15); color: var(--green); }
.alive-tag.no { background: rgba(248,113,113,.15); color: var(--red); }

/* ---- FOOTER ---- */
footer {
    text-align: center;
    padding: 20px;
    font-size: .75rem;
    color: var(--text3);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 640px) {
    main {
        display: flex;
        flex-direction: column;
    }

    .leaderboard-card { order: 1; }
    .games-card { order: 2; }
    .rooting-card { order: 3; }
    .survival-card { order: 4; }

    header {
        position: static;
        padding: 20px 0 14px;
        margin-bottom: 18px;
    }

    header h1 { font-size: 1rem; }
    .update-bar { font-size: .72rem; }
    .card { padding: 16px; margin-bottom: 16px; }
    .games-grid { grid-template-columns: 1fr; }
    .rooting-columns { grid-template-columns: 1fr; }
    .tab { padding: 4px 10px; font-size:.7rem; }

    .rooting-game {
        padding: 16px;
    }

    .rooting-game-header {
        gap: 8px;
        margin-bottom: 12px;
    }

    .rooting-game-header .matchup-label {
        font-size: 1rem;
    }

    .rooting-game-header .spread-badge {
        width: 100%;
        margin-left: 0;
    }

    .rooting-player {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 10px 0;
    }

    .rooting-player .rp-delta {
        justify-content: flex-start;
        text-align: left;
        width: 100%;
        font-size: .82rem;
    }

    .rp-pill {
        width: 100%;
        justify-content: space-between;
    }

    .leaderboard-card {
        padding: 18px 16px;
    }

    .leaderboard-card .card-header h2 {
        font-size: 1.15rem;
    }

    #leaderboard thead th:nth-child(4),
    #leaderboard tbody td:nth-child(4) {
        display: none;
    }

    #leaderboard {
        font-size: .86rem;
        table-layout: fixed;
    }

    #leaderboard thead th,
    #leaderboard tbody td {
        padding: 12px 8px;
    }

    #leaderboard .rank-col {
        width: 42px;
        font-size: 1rem;
    }

    #leaderboard .player-col {
        font-size: .96rem;
    }

    #leaderboard .player-avatar {
        width: 28px;
        height: 28px;
    }

    #leaderboard .player-label {
        gap: 8px;
    }

    #leaderboard .pts-bar {
        display: none;
    }

    #leaderboard .pts-value {
        min-width: 0;
        font-size: 1rem;
    }

    #leaderboard .win-prob {
        font-size: 1rem;
    }
}
