:root {
    /* Newsprint palette: ink on white, one accent that only marks wins */
    --bg: #ffffff;
    --ink: #222222;
    --ink-2: #555555;
    --muted: #8a8a8a;
    --rule: #e4e4e4;
    --rule-strong: #222222;

    --accent: #ed713a;
    --accent-ink: #b5470f;
    --win-bg: #fbd9c4;
    --win-ink: #74300c;
    --loss-bg: #f3f3f3;
    --loss-ink: #7a7a7a;
    --row-highlight: #fdf1ea;

    /* Fonts */
    --font-ui: 'IBM Plex Sans', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

[hidden] {
    display: none !important;
}

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

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding: 2rem 1rem 3rem;
}

.dashboard {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2.75rem;
}

/* --- MASTHEAD --- */
.masthead {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--rule);
}

.league-name {
    color: var(--ink);
    font-weight: 500;
}

.picker {
    field-sizing: content;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px dotted var(--muted);
    padding: 0.1rem 0;
    cursor: pointer;
}

.picker:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.status-badge {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--rule);
    border-radius: 3px;
    color: var(--muted);
}

.status-badge.live {
    color: var(--accent-ink);
    border-color: var(--accent);
}

/* --- HERO --- */
.headline-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.winner-logo {
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--rule);
}

.headline {
    font-size: clamp(1.75rem, 5vw, 2.75rem);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: #111;
}

.dek {
    margin-top: 0.75rem;
    font-size: 1.1rem;
    color: var(--ink-2);
    max-width: 44rem;
}

.dek:empty {
    display: none;
}

.streak-pill {
    display: inline-block;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0 0.4rem;
    border-radius: 3px;
    background: var(--win-bg);
    color: var(--win-ink);
}

.fineprint {
    margin-top: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--muted);
}

.hero.is-loading .headline {
    color: var(--muted);
    font-weight: 500;
}

.hero.is-error .headline {
    color: #a33;
}

/* --- PANELS --- */
.section-head {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-top: 2px solid var(--rule-strong);
    padding-top: 0.5rem;
    margin-bottom: 1rem;
}

/* Shown when the live season can't be loaded and an archive stands in */
.notice {
    margin-bottom: 1rem;
    padding-left: 0.6rem;
    border-left: 3px solid #a33;
    font-size: 0.8rem;
    color: var(--ink-2);
}

.note {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.note-tight {
    margin-top: 0.15rem;
}

.key-win {
    background: var(--win-bg);
    color: var(--win-ink);
    padding: 0 0.25rem;
    border-radius: 2px;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fade the right edge while there are more columns off-screen (phones hide scrollbars) */
.table-scroll.can-scroll-right {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
}

/* --- TABLES --- */
.grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
    padding: 0.45rem 0.4rem;
    text-align: center;
    white-space: nowrap;
}

.grid thead th {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 1px solid var(--rule-strong);
}

.grid tbody tr + tr td {
    border-top: 1px solid var(--rule);
}

/* Row headers (team names) stay put while the table scrolls */
.grid td:first-child,
.grid th:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg);
    padding-right: 0.75rem;
    z-index: 1;
}

.grid tr.row-winner td:first-child {
    font-weight: 700;
}

.matrix {
    min-width: 760px;
    border-collapse: separate;
    border-spacing: 2px;
}

.matrix tbody tr + tr td {
    border-top: 0;
}

.matrix td.cell-win {
    background: var(--win-bg);
    color: var(--win-ink);
}

.matrix td.cell-loss {
    background: var(--loss-bg);
    color: var(--loss-ink);
}

.matrix td.cell-tie {
    background: var(--bg);
    color: var(--ink-2);
    box-shadow: inset 0 0 0 1px var(--rule);
}

.matrix td.cell-self {
    color: var(--rule);
}

.grid .total-col {
    text-align: right;
    font-weight: 600;
    padding-left: 0.75rem;
}

.grid tr.row-winner .total-col {
    color: var(--accent-ink);
}

.stats {
    min-width: 640px;
}

.stats td.cell-best {
    font-weight: 700;
    color: var(--accent-ink);
}

/* --- SEASON RECAP --- */
.recap-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}

.leaderboard td:first-child,
.leaderboard th:first-child {
    position: static;
    white-space: normal;
}

.leaderboard th:not(:first-child),
.leaderboard td:not(:first-child) {
    width: 4rem;
}

.leaderboard td.zero {
    color: var(--rule);
}

.timeline {
    list-style: none;
}

.timeline li + li {
    border-top: 1px solid var(--rule);
}

.timeline-item {
    width: 100%;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.4rem 0.25rem;
    background: none;
    border: 0;
    color: var(--ink);
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

.timeline-item:hover,
.timeline-item:focus-visible {
    background: var(--row-highlight);
    outline: none;
}

.timeline-item.active {
    background: var(--row-highlight);
    box-shadow: inset 3px 0 0 var(--accent);
}

.timeline-week {
    flex: 0 0 7rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--muted);
}

.timeline-winner {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-winner.none {
    font-weight: 400;
    color: var(--muted);
}

.colophon {
    font-size: 0.8rem;
    color: var(--muted);
    border-top: 1px solid var(--rule);
    padding-top: 1rem;
}

@media (max-width: 720px) {
    body {
        padding: 1.25rem 1rem 2rem;
    }

    .dashboard {
        gap: 2rem;
    }

    /* League name on its own line, pickers below at 16px so iOS doesn't zoom on tap */
    .masthead {
        row-gap: 0.4rem;
    }

    .league-name {
        flex-basis: 100%;
    }

    .league-name + .divider {
        display: none;
    }

    .picker {
        font-size: 16px;
        letter-spacing: 0.02em;
        padding: 0.2rem 0;
    }

    .recap-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .winner-logo {
        width: 44px;
        height: 44px;
    }

    .dek {
        font-size: 1rem;
    }

    .grid {
        font-size: 0.8rem;
    }

    .grid th,
    .grid td {
        padding: 0.4rem 0.3rem;
    }

    .grid .team-name {
        display: block;
        max-width: 6.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .matrix {
        min-width: 560px;
        font-size: 0.72rem;
    }

    .stats {
        min-width: 520px;
    }

    .timeline-item {
        padding: 0.6rem 0.25rem;
    }

    .timeline-week {
        flex-basis: 6rem;
    }
}

/* --- CONFETTI --- */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti-particle {
    position: absolute;
    font-size: 1.5rem;
    opacity: 0;
    /* Transformation set by JS */
}

@keyframes dropAndFade {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(0.5) rotate(0deg);
    }

    60% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(var(--rot));
    }
}
