body {
    padding-bottom: env(safe-area-inset-bottom);
}

.start-card {
    max-width: 28rem;
}

.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.divider::before,
.divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--bs-border-color);
}

/* Leaderboard: player column stays put while rounds scroll sideways */
.leaderboard-wrap {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
}
.leaderboard th,
.leaderboard td {
    white-space: nowrap;
    padding-inline: 0.6rem;
}
.leaderboard {
    --player-col: 11.5rem;
    --total-col: 4rem;
}
/* Player and Total stay put while the round columns scroll sideways */
.leaderboard .sticky-col,
.leaderboard .total-col {
    position: sticky;
    z-index: 1;
    background: var(--bs-body-bg);
}
.leaderboard .sticky-col {
    left: 0;
    width: var(--player-col);
    min-width: var(--player-col);
    max-width: var(--player-col);
}
.leaderboard .total-col {
    left: var(--player-col);
    width: var(--total-col);
    min-width: var(--total-col);
    box-shadow: inset -1px 0 0 var(--bs-border-color);
}
.leaderboard .player-cell {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
}
.leaderboard .player-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.leaderboard .player-cell .badge {
    flex: none;
    font-size: 0.65em;
}
@media (min-width: 576px) {
    .leaderboard {
        --player-col: 16rem;
    }
}
.leaderboard tr.me > * {
    background: var(--bs-primary-bg-subtle);
}
.leaderboard .round-col {
    min-width: 3rem;
}
.leaderboard .rank {
    flex: none;
    display: inline-block;
    min-width: 1.5em;
    color: var(--bs-secondary-color);
    font-variant-numeric: tabular-nums;
}
.leaderboard .rank.leader {
    min-width: 1.5em;
    border-radius: 50rem;
    text-align: center;
    color: #000;
    background: var(--bs-warning);
    font-weight: 700;
}
.leaderboard td {
    font-variant-numeric: tabular-nums;
}

#toast-container {
    width: min(100%, 26rem);
    z-index: 1090;
}
#toast-container .toast {
    width: 100%;
}

.presence {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    flex: none;
    border-radius: 50%;
    vertical-align: middle;
    background: var(--bs-secondary-bg);
    border: 1px solid var(--bs-border-color);
}
.presence.online {
    background: var(--bs-success);
    border-color: var(--bs-success);
}

.invite-qr {
    max-width: 240px;
    background: #fff; /* QR codes need a light quiet zone, even in dark mode */
    border-radius: var(--bs-border-radius);
}
.invite-qr svg {
    display: block;
    width: 100%;
    height: auto;
}

/* ---------------------------------------------------------------------------
   Big board (TV / laptop view, templates/tv.html). Sized from the viewport so
   any number of players fits a 16:9 screen without scrolling.
   --------------------------------------------------------------------------- */
main.tv {
    height: 100vh;
    padding: 2.5vh 2.5vw;
    overflow: hidden;
}
body.tv-idle {
    cursor: none;
}
.tv-layout {
    display: grid;
    grid-template-columns: 1fr minmax(13rem, 19vw);
    gap: 3vw;
    height: 100%;
}
.tv-main {
    --rows: 1;
    --round-cols: 1;
    /* the round header takes about half a row */
    --row-h: min(12vh, calc(72vh / (var(--rows) + 0.5)));
    --cols: 1.6em 0.45em minmax(4em, 2.8fr) repeat(var(--round-cols), minmax(0, 1fr)) 3.6em;
    display: flex;
    flex-direction: column;
    min-height: 0;
    container-type: inline-size;
}
.tv-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 2vw;
    margin-bottom: 2vh;
}
.tv-title {
    font-size: clamp(1.5rem, 4.5vh, 3.5rem);
    font-weight: 700;
    color: var(--bs-success);
    margin: 0;
}
.tv-round {
    font-size: clamp(1rem, 3vh, 2.2rem);
    color: var(--bs-secondary-color);
    margin: 0;
    text-align: right;
}
.tv-board {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: min(1.2vh, calc(var(--row-h) * 0.12));
}
.tv-row {
    display: grid;
    grid-template-columns: var(--cols);
    align-items: center;
    gap: 0.5em;
    height: var(--row-h);
    padding: 0 0.6em;
    font-size: calc(var(--row-h) * 0.42);
    border-radius: 0.35em;
    background: var(--bs-secondary-bg);
}
.tv-row.leader {
    background: linear-gradient(90deg, rgba(255, 193, 7, 0.28), var(--bs-secondary-bg) 70%);
    box-shadow: inset 0.18em 0 0 var(--bs-warning);
}
.tv-rank {
    font-weight: 700;
    color: var(--bs-secondary-color);
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.tv-row.leader .tv-rank {
    color: var(--bs-warning);
}
.tv-presence {
    width: 0.4em;
    height: 0.4em;
    border-radius: 50%;
    background: var(--bs-secondary-color);
    opacity: 0.4;
}
.tv-presence.online {
    background: var(--bs-success);
    opacity: 1;
}
.tv-name {
    font-size: 0.8em;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tv-head {
    height: calc(var(--row-h) * 0.5);
    background: none;
    color: var(--bs-secondary-color);
    margin-bottom: 0.4vh;
}
.tv-head[hidden] {
    display: none;
}
.tv-head .tv-cell,
.tv-total-label {
    font-size: min(0.4em, calc(14cqi / (var(--round-cols) + 1)));
    text-transform: uppercase;
    letter-spacing: 0.05em;
    align-self: end;
}
.tv-total-label {
    text-align: right;
}
.tv-cell {
    /* shrink as the number of round columns grows, so 4-5 digit scores fit */
    font-size: min(0.55em, calc(18cqi / (var(--round-cols) + 1)));
    text-align: center;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    color: var(--bs-body-color);
    opacity: 0.85;
}
.tv-cell.empty {
    color: var(--bs-secondary-color);
    opacity: 0.5;
}
.tv-cell.current {
    font-weight: 700;
    opacity: 1;
}
.tv-head .tv-cell.current {
    color: var(--bs-success);
}
.tv-cell.bump {
    animation: tv-cell-bump 900ms ease-out;
}
@keyframes tv-cell-bump {
    0% { color: var(--bs-success); transform: scale(1.4); }
    100% { transform: scale(1); }
}
.tv-total {
    font-weight: 800;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.tv-total.bump {
    animation: tv-bump 900ms ease-out;
}
@keyframes tv-bump {
    0% { color: var(--bs-success); transform: scale(1.35); }
    100% { color: inherit; transform: scale(1); }
}
.tv-empty {
    font-size: clamp(1.25rem, 4vh, 3rem);
    color: var(--bs-secondary-color);
    margin: auto;
}

.tv-side {
    display: flex;
    flex-direction: column;
    gap: 3vh;
    min-height: 0;
}
.tv-join {
    text-align: center;
    padding: 1.8vh 1.2vw;
    border-radius: 0.75rem;
    background: var(--bs-secondary-bg);
}
.tv-qr {
    width: min(100%, 21vh);
    margin: 0 auto 1.2vh;
    background: #fff;
    border-radius: 0.5rem;
}
.tv-qr svg {
    display: block;
    width: 100%;
    height: auto;
}
.tv-join-label {
    font-size: clamp(0.8rem, 1.7vh, 1.2rem);
    color: var(--bs-secondary-color);
    margin: 0;
}
.tv-code {
    font-family: var(--bs-font-monospace);
    font-size: clamp(1.4rem, 4.8vh, 3.4rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--bs-warning);
    margin: 0;
}
.tv-host {
    font-size: clamp(0.85rem, 1.8vh, 1.2rem);
    color: var(--bs-secondary-color);
    margin: 0.5vh 0 0;
}
.tv-feed-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.tv-feed-title {
    font-size: clamp(0.9rem, 2.2vh, 1.5rem);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--bs-secondary-color);
}
.tv-feed {
    list-style: none;
    padding: 0;
    margin: 0;
}
.tv-feed-item {
    font-size: clamp(0.9rem, 2.3vh, 1.6rem);
    padding: 0.8vh 0;
    border-bottom: 1px solid var(--bs-border-color);
    animation: tv-feed-in 500ms ease-out;
}
.tv-feed-item:not(:first-child) {
    opacity: 0.65;
}
@keyframes tv-feed-in {
    from { opacity: 0; transform: translateX(1rem); }
}
.tv-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: opacity 300ms;
}
body.tv-idle .tv-controls {
    opacity: 0.25;
}
.tv-overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 5vw;
    text-align: center;
    font-size: clamp(1.5rem, 6vh, 4rem);
    font-weight: 700;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
}

/* Portrait phones/tablets: stack, let the page scroll */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
    main.tv {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
    .tv-layout {
        grid-template-columns: 1fr;
    }
    .tv-main {
        --row-h: 4rem;
    }
    .tv-header {
        flex-direction: column;
    }
    .tv-round {
        text-align: left;
    }
}
@media (max-width: 500px) {
    /* too narrow for a round grid: names and totals only */
    .tv-main {
        --cols: 1.6em 0.45em minmax(0, 1fr) 3.2em;
    }
    .tv-cell,
    .tv-head {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tv-total.bump,
    .tv-cell.bump,
    .tv-feed-item {
        animation: none;
    }
}
