/*------------------------------------*\
    CSS Variables (ESC Light Theme)
\*------------------------------------*/

:root {
    --color-bg:             #f0f2f5;
    --color-surface:        #ffffff;
    --color-surface-hover:  #f5f6f8;
    --color-surface-raised: #f8f9fb;

    --color-primary:        #D62839;
    --color-primary-hover:  #b81e2e;
    --color-secondary:      #2B5EA7;
    --color-secondary-hover:#1e4a8a;

    --color-text:           #1a1d2e;
    --color-text-light:     #4a5568;
    --color-text-muted:     #8892a4;

    --color-border:         #dce1e8;
    --color-border-light:   #c8cfd8;

    --color-pending:        #e67e22;
    --color-pending-bg:     rgba(230, 126, 34, 0.1);
    --color-done:           #27ae60;
    --color-done-bg:        rgba(39, 174, 96, 0.1);

    --color-win:            #2B5EA7;
    --color-win-bg:         rgba(43, 94, 167, 0.10);

    --color-zone-top:       #2B5EA7;
    --color-zone-top-bg:    rgba(43, 94, 167, 0.12);
    --color-zone-bottom:    #e08a1e;
    --color-zone-bottom-bg: rgba(224, 138, 30, 0.14);
    --color-zone-out:       #9aa4b4;

    --color-error:          #D62839;
    --color-error-bg:       rgba(214, 40, 57, 0.08);
    --color-success:        #27ae60;
    --color-success-bg:     rgba(39, 174, 96, 0.1);

    --radius:               8px;
    --radius-lg:            12px;
    --radius-sm:            4px;
    --shadow:               0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg:            0 8px 24px rgba(0, 0, 0, 0.1);

    --header-height:        64px;

    --font-family:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:            'SF Mono', 'Fira Code', monospace;
}

/*------------------------------------*\
    Reset & Base
\*------------------------------------*/

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

/*------------------------------------*\
    Layout
\*------------------------------------*/

.container {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 16px;
}

.main-content {
    padding: 16px 0 40px;
}

.header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    gap: 16px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-text);
}

.header-logo {
    height: 40px;
    width: auto;
}

.header-brand {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.header-brand-top {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.header-brand-bottom {
    font-family: 'Pacifico', cursive;
    font-size: 1.4rem;
    color: var(--color-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.nav-link {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-light);
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-link:hover {
    background: var(--color-surface-hover);
    color: var(--color-primary);
}

.nav-link-muted {
    color: var(--color-text-muted);
}

.nav-separator {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 0 4px;
}

.nav-user {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    padding: 0 4px;
}

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
}

.hamburger span {
    display: block;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
}

/*------------------------------------*\
    Page heading
\*------------------------------------*/

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
}

.page-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/*------------------------------------*\
    Buttons
\*------------------------------------*/

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text);
    white-space: nowrap;
}

.btn:hover {
    background: var(--color-surface-hover);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-secondary);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--color-secondary-hover);
}

.btn-ghost {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text-light);
}

.btn-danger {
    background: transparent;
    border-color: var(--color-error);
    color: var(--color-error);
}

.btn-danger:hover {
    background: var(--color-error-bg);
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.85rem;
}

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

/*------------------------------------*\
    Cards & panels
\*------------------------------------*/

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-hint {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-muted);
}

/*------------------------------------*\
    Forms
\*------------------------------------*/

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-light);
}

.form-help {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.form-input,
.form-select {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 3px rgba(43, 94, 167, 0.12);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/*------------------------------------*\
    Tables
\*------------------------------------*/

.table-wrap {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table-ranking th,
.table-ranking td:not(:nth-child(2)) {
    text-align: center;
}

.table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 700;
}

.table tbody tr:hover {
    background: var(--color-surface-hover);
}

.table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.cell-shrink {
    width: 1%;
}

/*------------------------------------*\
    Badges
\*------------------------------------*/

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.6;
}

.badge-pending {
    background: var(--color-pending-bg);
    color: var(--color-pending);
}

.badge-done {
    background: var(--color-done-bg);
    color: var(--color-done);
}

.badge-danger {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.badge-info {
    background: rgba(43, 94, 167, 0.1);
    color: var(--color-secondary);
}

.badge-muted {
    background: var(--color-surface-raised);
    color: var(--color-text-muted);
}

/*------------------------------------*\
    Team number pill
\*------------------------------------*/

.team-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--color-secondary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/*------------------------------------*\
    Team follow (visitor tap-to-highlight)
\*------------------------------------*/

.team-follow {
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 1px 3px;
}

.team-follow:hover {
    background: var(--color-surface-hover);
}

.team-follow.followed {
    font-weight: 700;
}


.my-team-chip.follow-color-0 .team-num { background: #e63946; }
.my-team-chip.follow-color-1 .team-num { background: #2d9e5e; }
.my-team-chip.follow-color-2 .team-num { background: #1d6fc4; }
.my-team-chip.follow-color-3 .team-num { background: #b8860b; }
.my-team-chip.follow-color-4 .team-num { background: #9c36b5; }
.my-team-chip.follow-color-5 .team-num { background: #e8590c; }
.my-team-chip.follow-color-6 .team-num { background: #0ca678; }
.my-team-chip.follow-color-7 .team-num { background: #d6336c; }

.team-follow.follow-color-0 .team-num { background: #e63946; color: #fff; }
.team-follow.follow-color-1 .team-num { background: #2d9e5e; color: #fff; }
.team-follow.follow-color-2 .team-num { background: #1d6fc4; color: #fff; }
.team-follow.follow-color-3 .team-num { background: #b8860b; color: #fff; }
.team-follow.follow-color-4 .team-num { background: #9c36b5; color: #fff; }
.team-follow.follow-color-5 .team-num { background: #e8590c; color: #fff; }
.team-follow.follow-color-6 .team-num { background: #0ca678; color: #fff; }
.team-follow.follow-color-7 .team-num { background: #d6336c; color: #fff; }

.team-follow.follow-color-0 { color: #e63946; }
.team-follow.follow-color-1 { color: #2d9e5e; }
.team-follow.follow-color-2 { color: #1d6fc4; }
.team-follow.follow-color-3 { color: #b8860b; }
.team-follow.follow-color-4 { color: #9c36b5; }
.team-follow.follow-color-5 { color: #e8590c; }
.team-follow.follow-color-6 { color: #0ca678; }
.team-follow.follow-color-7 { color: #d6336c; }

/*------------------------------------*\
    Followed teams: a filter strip, nothing more
\*------------------------------------*/

.my-teams {
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.my-teams.is-visible {
    display: flex;
}

.my-teams-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.my-team-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px 5px 5px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.my-team-chip:hover,
.my-team-chip.is-active {
    border-color: currentColor;
}

.my-team-chip .team-num {
    color: #fff;
}

/*------------------------------------*\
    Round tabs
\*------------------------------------*/

.tabs {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    padding: 8px 14px;
    border: 1px solid var(--color-border-light);
    border-radius: 999px;
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
}

.tab:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.tab.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.tab.active .tab-dot {
    background: rgba(255, 255, 255, 0.9);
}

.tab-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-pending);
    margin-left: 6px;
    vertical-align: middle;
}

/*------------------------------------*\
    Round strip and scoring-table toolbar
\*------------------------------------*/

/* The round selector stays reachable while scrolling a long list. */
.round-strip {
    position: sticky;
    top: 60px;
    z-index: 50;
    background: var(--color-bg);
    padding: 6px 0 2px;
    margin-bottom: 10px;
}

.round-strip .tabs {
    margin-bottom: 0;
    border-bottom: none;
}

.tab-dot.is-done {
    background: var(--color-win);
}

.tab-dot.is-empty {
    background: var(--color-border-light);
}

.refresh-line {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    padding: 14px 0 4px;
}

.link-button {
    border: none;
    background: none;
    padding: 0;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-secondary);
    cursor: pointer;
    text-decoration: underline;
}

.toolbar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-top: 20px;
    overflow: hidden;
}

.toolbar-summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.toolbar-summary::-webkit-details-marker {
    display: none;
}

.toolbar-summary::after {
    content: '▾';
    color: var(--color-text-muted);
    font-weight: 400;
}

.toolbar[open] .toolbar-summary::after {
    content: '▴';
}

.toolbar-status {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.toolbar-body {
    padding: 0 16px 16px;
    border-top: 1px solid var(--color-border);
    padding-top: 16px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.toolbar-note {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.waiting-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

/*------------------------------------*\
    Match cards
\*------------------------------------*/

/* One match per row, full width: the list lines up with the navigation above it. */
.match-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.match-card {
    display: flex;
    align-items: stretch;
    gap: 10px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 7px 10px 7px 8px;
}

.match-card.is-done {
    border-left-color: var(--color-win);
}

.match-card.is-pending {
    border-left-color: var(--color-pending);
}

.match-card.is-rematch {
    border-color: var(--color-error);
    background: var(--color-error-bg);
}

.match-order {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

.match-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.match-team {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    min-width: 0;
}

.match-team > .team-follow {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-team.is-winner {
    background: var(--color-win-bg);
    font-weight: 700;
}

.match-team.is-loser {
    color: var(--color-text-muted);
}

.match-points {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: center;
    flex-shrink: 0;
}

.match-points.is-winner {
    color: var(--color-win);
}

.match-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: 6px;
    flex-shrink: 0;
}

.match-flags {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}

.match-actions {
    display: flex;
    gap: 6px;
}

/*------------------------------------*\
    Quick team entry
\*------------------------------------*/

.quick-entry {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.quick-entry .form-group {
    flex: 1;
    min-width: 180px;
}

.quick-next-number {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 6px 12px;
    border-radius: var(--radius);
    background: var(--color-secondary);
    color: #fff;
}

.quick-next-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.quick-next-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.85;
}

/*------------------------------------*\
    Ranking zones
\*------------------------------------*/

.zone-top td {
    background: rgba(43, 94, 167, 0.10);
}

.zone-bottom td {
    background: rgba(43, 94, 167, 0.04);
}

.zone-out td {
    color: var(--color-text-muted);
}

.zone-divider td {
    background: var(--color-surface-raised);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    text-align: center;
    padding: 6px;
}

/* Provisional cut: a mark on the page, not a verdict on the teams. */
.cut-line td {
    padding: 0;
    border-bottom: none;
    background: none;
}

.cut-line span {
    display: block;
    position: relative;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding: 5px 0;
}

.cut-line span::before,
.cut-line span::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 110px);
    border-top: 2px dashed var(--color-border-light);
}

.cut-line span::before {
    left: 0;
}

.cut-line span::after {
    right: 0;
}

.table-ranking {
    table-layout: fixed;
    width: 100%;
}

/* Rank and team read as a pair, centred; the figures line up on their own columns. */
.table-ranking .rank {
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--color-text-light);
}

.table-ranking th:nth-child(1) {
    width: 16%;
}

.table-ranking th:nth-child(2) {
    width: 28%;
}

.table-ranking th:nth-child(n+3) {
    width: 11.2%;
}

.table-ranking td:nth-child(2) {
    text-align: left;
    /* Fixed layout does not clip: a badge that did not wrap would sit on the J column. */
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Sticks just below the site header, which owns the top of the viewport. */
.table-ranking thead th {
    position: sticky;
    top: var(--header-height);
    z-index: 5;
    background: var(--color-surface);
    box-shadow: inset 0 -1px 0 var(--color-border);
}

.refresh-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.refresh-time {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/*------------------------------------*\
    Bracket
\*------------------------------------*/

.bracket {
    --bracket-gap: 44px;
    display: flex;
    gap: var(--bracket-gap);
    overflow-x: auto;
    padding: 8px 4px 16px;
    align-items: stretch;
}

.bracket-round {
    display: flex;
    flex-direction: column;
    min-width: 250px;
    flex: 1;
}

.bracket-round-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 700;
    text-align: center;
    padding-bottom: 10px;
}

.bracket-cells {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* One equal-height cell per match: centres line up with the next round. */
.bracket-cell {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
    padding: 4px 0;
}

/* No overflow clipping here: it would cut off the connector coming in from the left.
   The corners are rounded on the first and last rows instead. */
.bracket-match {
    position: relative;
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.bracket-side:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
}

.bracket-side:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
}

.bracket-actions {
    border-radius: 0 0 var(--radius) var(--radius);
}

.bracket-match:hover {
    border-color: var(--color-secondary);
}

/* Outgoing stub, then the vertical bar joining each pair. */
.bracket-round:not(:last-child) .bracket-cell:not(.is-only)::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    width: calc(var(--bracket-gap) / 2);
    border-top: 2px solid var(--color-border-light);
}

.bracket-round:not(:last-child) .bracket-cell:nth-child(even)::before {
    content: '';
    position: absolute;
    left: calc(100% + var(--bracket-gap) / 2);
    top: -50%;
    height: 100%;
    border-left: 2px solid var(--color-border-light);
}

/* Incoming stub on every round but the first. */
.bracket-round:not(:first-child) .bracket-match::before {
    content: '';
    position: absolute;
    top: 50%;
    right: 100%;
    width: calc(var(--bracket-gap) / 2);
    border-top: 2px solid var(--color-border-light);
}

.bracket-side {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    font-size: 0.92rem;
    min-width: 0;
}

.bracket-side > .team-follow {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bracket-side + .bracket-side {
    border-top: 1px solid var(--color-border);
}

.bracket-side.is-winner {
    background: var(--color-win-bg);
    font-weight: 700;
}

.bracket-side.is-empty {
    color: var(--color-text-muted);
    font-style: italic;
}

.bracket-side-score {
    font-family: var(--font-mono);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 20px;
    text-align: right;
}

/*------------------------------------*\
    Modal
\*------------------------------------*/

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 30, 0.55);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.is-open {
    display: flex;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    max-height: 92vh;
    overflow-y: auto;
}

.modal-wide {
    max-width: 640px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    font-size: 1.05rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
}

/*------------------------------------*\
    Score entry
\*------------------------------------*/

.score-team {
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    padding: 8px 10px 10px;
    margin-bottom: 10px;
}

.score-team.is-active {
    border-color: var(--color-secondary);
}

.score-team-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.score-input {
    width: 64px;
    flex-shrink: 0;
    padding: 2px 4px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    -moz-appearance: textfield;
}

.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.score-input:focus {
    outline: none;
    border-color: var(--color-secondary);
}

/* Every score is on screen at once: no scrolling, no arrows, 13 always visible. */
.score-chips {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.score-chip {
    padding: 10px 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    cursor: pointer;
}

.score-chip:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.score-chip.is-selected {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: #fff;
}

.score-hint {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    min-height: 20px;
    margin-top: 4px;
}

.score-hint.is-error {
    color: var(--color-error);
    font-weight: 600;
}

/*------------------------------------*\
    Toast
\*------------------------------------*/

.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
    width: calc(100% - 32px);
    max-width: 420px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    background: var(--color-text);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
}

.toast-success {
    background: var(--color-success);
}

.toast-error {
    background: var(--color-error);
}

/*------------------------------------*\
    Login
\*------------------------------------*/

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-brand-name {
    font-family: 'Pacifico', cursive;
    font-size: 1.8rem;
    color: var(--color-primary);
}

.login-error {
    background: var(--color-error-bg);
    color: var(--color-error);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/*------------------------------------*\
    TV mode (1920x1080 projection, light)
\*------------------------------------*/

.tv-body {
    --tv-scale: 1;
    background: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* The header stays thin: the screen belongs to the matches. */
.tv-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 8px 20px;
    background: var(--color-surface);
    border-bottom: 2px solid var(--color-primary);
}

.tv-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-light);
}

.tv-rounds {
    display: flex;
    gap: 6px;
}

.tv-round-tab {
    padding: 5px 14px;
    border: 1px solid var(--color-border-light);
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text-light);
}

.tv-round-tab.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.tv-matches {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    grid-auto-rows: min-content;
    gap: 8px;
    padding: 10px 20px;
    overflow: hidden;
    align-content: start;
}

.tv-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* A played match is left exactly as it is: the board must stay readable. */

.tv-card-head {
    padding: calc(3px * var(--tv-scale)) 8px;
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border);
    text-align: center;
    font-size: calc(0.75rem * var(--tv-scale));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

/* Face to face: the two numbers are what people scan the wall for. */
.tv-card-body {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: calc(6px * var(--tv-scale)) 8px calc(8px * var(--tv-scale));
}

.tv-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.tv-side-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: calc(62px * var(--tv-scale));
    padding: calc(2px * var(--tv-scale)) 10px;
    margin-bottom: calc(3px * var(--tv-scale));
    border-radius: 999px;
    background: var(--color-secondary);
    color: #fff;
    font-family: var(--font-mono);
    font-size: calc(1.6rem * var(--tv-scale));
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.tv-side-number-empty {
    background: var(--color-text-muted);
}

.tv-side-player {
    max-width: 100%;
    font-size: calc(0.82rem * var(--tv-scale));
    line-height: 1.25;
    color: var(--color-text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tv-vs {
    align-self: center;
    font-size: calc(0.85rem * var(--tv-scale));
    font-weight: 700;
    color: var(--color-text-muted);
    padding-top: 8px;
}

.tv-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 8px 20px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    font-size: 1.05rem;
    color: var(--color-text-light);
    min-height: 20px;
}

.tv-waiting strong {
    color: var(--color-primary);
}

.tv-pager {
    display: flex;
    gap: 8px;
}

.tv-pager-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--color-border-light);
}

.tv-pager-dot.active {
    background: var(--color-primary);
}

.tv-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    font-size: 1.8rem;
    color: var(--color-text-muted);
}

/*------------------------------------*\
    Utilities
\*------------------------------------*/

.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.is-hidden { display: none !important; }

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.alert-warning {
    background: var(--color-pending-bg);
    color: #a05a12;
}

.alert-error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.alert-info {
    background: rgba(43, 94, 167, 0.1);
    color: var(--color-secondary);
}

/*------------------------------------*\
    Responsive
\*------------------------------------*/

@media (max-width: 900px) {
    .tv-matches {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .hamburger {
        display: flex;
    }

    .header-nav {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        box-shadow: var(--shadow);
        padding: 8px;
        gap: 2px;
    }

    .header-nav.is-open {
        display: flex;
    }

    .nav-separator {
        width: 100%;
        height: 1px;
        margin: 4px 0;
    }

    .match-row {
        flex-wrap: wrap;
    }

    .match-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/*------------------------------------*\
    Bracket slot actions
\*------------------------------------*/

.bracket-side-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-swap {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    width: 22px;
    height: 22px;
    line-height: 1;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
}

.btn-swap:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

/*------------------------------------*\
    Autocomplete
\*------------------------------------*/

.autocomplete {
    position: relative;
}

.autocomplete .ac-input {
    padding-right: 34px;
}

.autocomplete.has-value .ac-input {
    font-weight: 600;
    border-color: var(--color-secondary);
}

.ac-clear {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: none;
}

.autocomplete.has-value .ac-clear {
    display: block;
}

.ac-list {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 260px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.ac-list.is-open {
    display: block;
}

.ac-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    cursor: pointer;
    font-size: 0.95rem;
}

.ac-item + .ac-item {
    border-top: 1px solid var(--color-border);
}

.ac-item:hover,
.ac-item.is-active {
    background: var(--color-surface-hover);
}

.ac-item.is-rematch {
    color: var(--color-error);
}

.ac-flag {
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.ac-empty {
    padding: 12px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/*------------------------------------*\
    Section navigation (mobile first)
\*------------------------------------*/

.section-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.section-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    padding: 8px 12px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text-light);
    text-align: center;
}

.section-tab-label {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.15;
}

.section-tab-sub {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.section-tab.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.section-tab.active .section-tab-sub {
    color: rgba(255, 255, 255, 0.85);
}

.section-tab.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.sub-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 3px;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    margin-bottom: 12px;
}

.sub-tab {
    padding: 8px 12px;
    border-radius: 999px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-light);
}

.sub-tab.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow);
}

/*------------------------------------*\
    Match search
\*------------------------------------*/

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.search-input {
    flex: 1;
    font-size: 1rem;
}

.search-info {
    font-size: 0.9rem;
    color: var(--color-secondary);
    font-weight: 600;
    margin-bottom: 12px;
}

.match-card.is-filtered {
    display: none;
}

/*------------------------------------*\
    Smartphone
\*------------------------------------*/

@media (max-width: 640px) {
    .container {
        padding: 0 10px;
    }

    .main-content {
        padding: 12px 0 36px;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .card {
        padding: 12px;
        border-radius: var(--radius);
    }

    .section-tab-label {
        font-size: 1rem;
    }

    .match-points {
        font-size: 1.05rem;
    }

    /* The actions drop under the teams so names keep the full width. */
    .match-card {
        flex-wrap: wrap;
        padding: 7px 8px;
    }

    .match-side {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions .btn {
        flex: 1;
    }

    .quick-entry .form-group {
        min-width: 100%;
    }

    .quick-entry .btn {
        width: 100%;
    }

    .table th,
    .table td {
        padding: 8px 8px;
        font-size: 0.9rem;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1;
    }

    .bracket {
        --bracket-gap: 28px;
    }

    .bracket-round {
        min-width: 220px;
    }
}

/*------------------------------------*\
    Page note (replaces the redundant headings)
\*------------------------------------*/

.page-note {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 14px;
}

.table .strong {
    font-weight: 700;
}

@media (max-width: 640px) {
    /* Only the names step aside: with numbers alone, every column fits. */
    .table-ranking .team-full {
        display: none;
    }

    .table-ranking th,
    .table-ranking td {
        padding: 7px 2px;
        font-size: 0.85rem;
        text-align: center;
    }

    .table-ranking th {
        font-size: 0.65rem;
        letter-spacing: 0;
    }

    .table-ranking .team-num {
        min-width: 32px;
        height: 22px;
        font-size: 0.82rem;
    }

    .table-ranking .badge {
        font-size: 0.62rem;
        padding: 1px 4px;
    }

    /* The dividers are signposts, not headlines. */
    .zone-divider td,
    .cut-line span {
        font-size: 0.62rem;
        letter-spacing: 0.03em;
        padding: 5px 4px;
    }

    .cut-line span::before,
    .cut-line span::after {
        width: calc(50% - 92px);
    }
}

.ac-item.is-engaged {
    color: var(--color-text-muted);
    cursor: not-allowed;
    background: var(--color-surface-raised);
}

.ac-item.is-engaged:hover {
    background: var(--color-surface-raised);
}

.score-side-name {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.score-side-team {
    font-weight: 700;
    font-size: 1.05rem;
}

.score-side-players {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/*------------------------------------*\
    Followed team chip
\*------------------------------------*/

.my-team-chip {
    display: inline-flex;
    align-items: stretch;
    overflow: hidden;
}

.my-team-chip .chip-body {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px 5px 5px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
}

.my-team-chip .chip-remove {
    padding: 0 9px;
    border: none;
    border-left: 1px solid var(--color-border);
    background: none;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
}

.my-team-chip .chip-remove:hover {
    background: var(--color-error-bg);
    color: var(--color-error);
}

/*------------------------------------*\
    Confirmation dialog
\*------------------------------------*/

/* Sits above the modal it was opened from. */
.modal-ask {
    z-index: 260;
}

.modal-narrow {
    max-width: 380px;
}

.modal-ask .modal-body p {
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-ask .form-group {
    margin-top: 14px;
}

/*------------------------------------*\
    Bracket match actions
\*------------------------------------*/

.bracket-actions {
    display: flex;
    gap: 6px;
    padding: 6px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-raised);
}

.bracket-actions .btn {
    flex: 1;
    padding: 5px 6px;
    font-size: 0.8rem;
}

/*------------------------------------*\
    TV: both brackets on one screen
\*------------------------------------*/

.tv-finals {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 20px;
    overflow: hidden;
}

.tv-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tv-section-title {
    font-size: calc(0.95rem * var(--tv-scale));
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-primary);
    padding-bottom: 6px;
}

.tv-section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    grid-auto-rows: min-content;
    gap: 8px;
}

/*------------------------------------*\
    Replacement candidates
\*------------------------------------*/

#replaceList {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 60vh;
    overflow-y: auto;
}

/* The row itself is the button: nothing to reach for on the right edge. */
.candidate {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
}

.candidate:hover {
    border-color: var(--color-secondary);
    background: var(--color-surface-hover);
}

.candidate-rank {
    min-width: 34px;
    font-weight: 700;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.candidate-identity {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.candidate-players {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.candidate-meta {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--color-text-light);
}

.candidate-tags {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .candidate {
        flex-wrap: wrap;
        gap: 6px;
    }

    .candidate-identity {
        flex-basis: 100%;
        order: 2;
    }
}

/* The ranking never needs sideways scrolling, so it can keep a sticky header. */
.table-wrap-ranking {
    overflow-x: visible;
}

.tv-round-select {
    padding: 5px 10px;
    border: 1px solid var(--color-border-light);
    border-radius: 999px;
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text-light);
    cursor: pointer;
}

/*------------------------------------*\
    TV: standings on the wall
\*------------------------------------*/

.tv-rank-legend {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    padding: 6px 20px 0;
    font-size: calc(0.78rem * var(--tv-scale));
    font-weight: 700;
    color: var(--color-text-light);
}

.tv-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* The swatch repeats the accent worn by the rows of that block. */
.tv-legend-item::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.tv-legend-item.is-top::before {
    background: var(--color-zone-top);
}

.tv-legend-item.is-bottom::before {
    background: var(--color-zone-bottom);
}

.tv-legend-item.is-out::before {
    background: var(--color-zone-out);
}

.tv-ranking {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 2px 18px;
    padding: 8px 20px 10px;
    overflow: hidden;
}

.tv-legend-item sup {
    font-size: 0.7em;
}

.tv-rank-row {
    display: flex;
    align-items: center;
    gap: calc(6px * var(--tv-scale));
    padding: calc(2px * var(--tv-scale)) 10px;
    border-left: 5px solid transparent;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--color-surface);
    font-size: calc(0.95rem * var(--tv-scale));
    min-width: 0;
}

/* Each block carries its own colour, so the cut is visible from the back row. */
.tv-rank-row.is-top {
    border-left-color: var(--color-zone-top);
    background: var(--color-zone-top-bg);
}

.tv-rank-row.is-bottom {
    border-left-color: var(--color-zone-bottom);
    background: var(--color-zone-bottom-bg);
}

.tv-rank-row.is-out {
    border-left-color: var(--color-zone-out);
    color: var(--color-text-muted);
}

.tv-rank-row.is-edge {
    border-bottom: 2px solid currentColor;
}

.tv-rank-row.is-bottom .tv-rank-number {
    background: var(--color-zone-bottom);
}

.tv-rank-place {
    min-width: calc(30px * var(--tv-scale));
    font-weight: 800;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.tv-rank-number {
    min-width: calc(42px * var(--tv-scale));
    padding: 0 8px;
    border-radius: 999px;
    background: var(--color-secondary);
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.tv-rank-row.is-out .tv-rank-number {
    background: var(--color-text-muted);
}

/* Names are the confirmation, not the target: small enough to fit whole. */
.tv-rank-players {
    flex: 1;
    font-size: calc(0.62rem * var(--tv-scale));
    line-height: 1.2;
    color: var(--color-text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tv-rank-row.is-out .tv-rank-players {
    color: var(--color-text-muted);
}

.tv-rank-points,
.tv-rank-diff {
    font-family: var(--font-mono);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.tv-rank-points {
    min-width: calc(22px * var(--tv-scale));
}

.tv-rank-diff {
    min-width: calc(38px * var(--tv-scale));
    color: var(--color-text-light);
}

/*
 * Column header for a standings column. It repeats the row's flex geometry exactly —
 * same gap, same padding, same 5px zone border — so the labels sit over their figures.
 */
.tv-rank-head {
    display: flex;
    align-items: baseline;
    gap: calc(6px * var(--tv-scale));
    padding: 0 10px calc(3px * var(--tv-scale));
    margin-bottom: calc(2px * var(--tv-scale));
    border-left: 5px solid transparent;
    border-bottom: 2px solid var(--color-border);
    font-size: calc(0.6rem * var(--tv-scale));
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    min-width: 0;
}

/* The header borrows the row classes for their widths only, never their decoration. */
.tv-rank-head span {
    background: none;
    border-radius: 0;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    line-height: 1.2;
}

.tv-rank-head .tv-rank-players {
    text-align: left;
}

/*------------------------------------*\
    Replacement target
\*------------------------------------*/

.replace-target {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-error);
    border-radius: var(--radius);
    background: var(--color-error-bg);
    margin-bottom: 14px;
}

.replace-target-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-error);
}

.replace-target-team {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
}

.replace-target-round {
    margin-left: auto;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

/*------------------------------------*\
    TV: results
\*------------------------------------*/

.tv-side-score {
    font-family: var(--font-mono);
    font-size: calc(1.5rem * var(--tv-scale));
    font-weight: 800;
    line-height: 1.1;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* The winner keeps the club blue; the loser steps back. */
.tv-side.is-winner .tv-side-score {
    color: var(--color-win);
}

.tv-side.is-winner .tv-side-number {
    background: var(--color-win);
}

.tv-card.is-done .tv-side:not(.is-winner) .tv-side-number {
    background: var(--color-text-muted);
}

/*------------------------------------*\
    Refresh countdown
\*------------------------------------*/

.refresh-countdown {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.refresh-countdown:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

/* A slow pulse: the page is alive, without pulling the eye away from the results. */
.refresh-countdown-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-done);
    animation: refresh-pulse 2.4s ease-in-out infinite;
}

@keyframes refresh-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
    .refresh-countdown-dot {
        animation: none;
    }
}

body[data-visitor] .is-manage-only {
    display: none;
}

.tv-foot-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.tv-countdown {
    font-size: calc(0.8rem * var(--tv-scale));
    color: var(--color-text-muted);
}

@media (max-width: 640px) {
    .refresh-countdown {
        padding: 5px 9px;
        font-size: 0.72rem;
    }
}


/*------------------------------------*\
    TV pilot (header)
\*------------------------------------*/

/* Within reach from every screen: the wall is switched without walking to it. */
.tv-pilot {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 10px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
}

.tv-pilot-label {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

.tv-pilot-select {
    border: none;
    background: none;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-secondary);
    cursor: pointer;
}

.tv-pilot-select:focus {
    outline: none;
}

/*------------------------------------*\
    Tie-break draw
\*------------------------------------*/

.draw-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.draw-team {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-family: inherit;
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
}

.draw-team:hover {
    border-color: var(--color-secondary);
}

/* Picked out of the hat: the rank replaces the invitation to tap. */
.draw-team.is-drawn {
    border-color: var(--color-secondary);
    background: var(--color-win-bg);
    font-weight: 700;
}

.draw-rank {
    min-width: 28px;
    font-weight: 800;
    color: var(--color-secondary);
    font-variant-numeric: tabular-nums;
}

.draw-players {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/*------------------------------------*\
    Price sheets (buvette)

    The editor is the preview: same faces and same dot leaders as the printed PDF,
    so what you type is what comes out of the printer.
\*------------------------------------*/

.price-board {
    --paper:        #fbf6ec;
    --paper-line:   #e5dccb;
    --paper-ink:    #2a2119;
    --paper-muted:  #8a7f70;
    --paper-accent: #c1362f;

    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    align-items: start;
    gap: 16px;
    margin-bottom: 16px;
}

.price-section {
    background: var(--paper);
    border: 1px solid var(--paper-line);
    border-radius: var(--radius-lg);
    padding: 18px 20px 14px;
}

.price-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid var(--paper-accent);
    padding-bottom: 6px;
    margin-bottom: 12px;
}

.price-section-title {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--paper-accent);
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.3rem;
    font-weight: 600;
    padding: 2px 0;
}

.price-section-title:focus {
    outline: none;
    background: rgba(193, 54, 47, 0.07);
    border-radius: var(--radius-sm);
}

.price-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.price-line-main {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.price-line-label,
.price-line-price,
.price-line-note {
    border: 0;
    background: transparent;
    font-family: 'Alegreya Sans', var(--font-family);
    color: var(--paper-ink);
    padding: 3px 2px;
}

.price-line-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1.05rem;
    border-bottom: 2px dotted var(--paper-line);
}

.price-line-price {
    flex: 0 0 5.5rem;
    /* Without this an input keeps its intrinsic 20-character width and ignores the basis. */
    min-width: 0;
    text-align: right;
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.price-line-note {
    display: block;
    width: 100%;
    padding-left: 10px;
    font-size: 0.85rem;
    color: var(--paper-muted);
    font-style: italic;
}

/* An empty detail is an offer, not a field: it stays out of the way until wanted. */
.price-line-note:placeholder-shown {
    height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.price-line:hover .price-line-note:placeholder-shown,
.price-line:focus-within .price-line-note:placeholder-shown {
    height: auto;
    padding-top: 3px;
    padding-bottom: 3px;
    opacity: 1;
}

.price-line-note:focus {
    height: auto;
    padding-top: 3px;
    padding-bottom: 3px;
    opacity: 1;
}

.price-line-label:focus,
.price-line-price:focus,
.price-line-note:focus {
    outline: none;
    background: #fff;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 0 2px rgba(193, 54, 47, 0.25);
}

.price-line-remove {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: var(--paper-line);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0;
}

.price-line:hover .price-line-remove,
.price-line:focus-within .price-line-remove,
.price-line-remove:focus {
    opacity: 1;
}

.price-line-remove:hover {
    color: var(--paper-accent);
}

.price-add {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--paper-line);
}

.price-add .price-line-label,
.price-add .price-line-price {
    background: var(--color-surface);
    border: 1px solid var(--paper-line);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
}

.price-add .price-line-label {
    flex: 1 1 auto;
    width: 0;
}

.price-add .price-line-price {
    flex: 0 0 5rem;
}

.price-board-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    margin-bottom: 24px;
}

.btn-danger-ghost {
    color: var(--color-error);
}

.sheet-head {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

@media (max-width: 640px) {
    .price-board {
        grid-template-columns: 1fr;
    }

    .price-add {
        flex-wrap: wrap;
    }

    .price-add .price-line-label {
        flex: 1 1 100%;
    }
}

/*------------------------------------*\
    Tournament QR code
\*------------------------------------*/

.qr-block {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 20px;
}

.qr-preview {
    flex: 0 0 auto;
    width: 180px;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.qr-preview svg {
    display: block;
    width: 100%;
    height: auto;
    /* The path is one module per unit; fill it with ink, leave the rest paper. */
    fill: var(--color-text);
    shape-rendering: crispEdges;
}

.qr-details {
    flex: 1 1 260px;
    min-width: 0;
}

.qr-print {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.qr-print .form-label {
    display: block;
}

.qr-print .form-input {
    width: auto;
    min-width: 210px;
}

.qr-target {
    margin: 12px 0 0;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    word-break: break-all;
}

/*------------------------------------*\
    Price sheets: line kinds and dragging
\*------------------------------------*/

.drag-handle {
    flex: 0 0 auto;
    cursor: grab;
    color: var(--paper-line, var(--color-border-light));
    font-size: 0.9rem;
    letter-spacing: -3px;
    line-height: 1;
    user-select: none;
    padding-right: 2px;
}

.price-section:hover .drag-handle,
.price-line:hover .drag-handle,
.price-line:focus-within .drag-handle {
    color: var(--paper-muted, var(--color-text-muted));
}

.price-line.is-dragging,
.price-section.is-dragging {
    opacity: 0.45;
}

.price-line.is-drop-target {
    outline: 2px dashed var(--paper-accent, var(--color-primary));
    outline-offset: 2px;
}

.price-section.is-drop-target {
    box-shadow: 0 0 0 2px var(--paper-accent, var(--color-primary));
}

/* A title inside a section: reads as a heading, not as something you can buy. */
.price-line.is-title .price-line-label {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.05rem;
    font-weight: 600;
    border-bottom-color: transparent;
}

/* The remark the table wants read: red on paper, red on screen. */
.price-line.is-note .price-line-label {
    color: var(--paper-accent, var(--color-primary));
    font-weight: 700;
    font-style: italic;
    border-bottom-color: transparent;
}

.price-line.is-spacer .price-line-main {
    min-height: 26px;
}

.price-line-spacer {
    flex: 1 1 auto;
    border-bottom: 1px dashed var(--paper-line);
    color: var(--paper-muted);
    font-size: 0.72rem;
    font-style: italic;
    letter-spacing: 0.04em;
}

.price-section-break {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: -4px 0 12px;
    font-size: 0.78rem;
    color: var(--paper-muted);
}

.price-add-kinds {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
}

.price-add-kinds .link-button {
    font-size: 0.78rem;
    color: var(--paper-muted);
}

.price-add-kinds .link-button:hover {
    color: var(--paper-accent);
}
