/* ==========================================================================
   Tournament Generator
   Design language: monochrome-dominant, hairline structure, mono metadata.
   Depth comes from layered surfaces + hairlines, never from nested boxes.
   ========================================================================== */

/* ===== Tokens ============================================================ */

:root {
    /* Type */
    --font-sans: 'Satoshi', ui-sans-serif, -apple-system, 'Segoe UI Variable Text',
                 'Segoe UI', 'Helvetica Neue', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono',
                 'Segoe UI Mono', Menlo, monospace;

    /* Scale — one ratio, used everywhere */
    --step--1: 0.75rem;
    --step-0:  0.875rem;
    --step-1:  1rem;
    --step-2:  1.25rem;
    --step-3:  1.625rem;
    --step-4:  2.125rem;

    /* Rhythm — 4px base */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --s-8: 72px;

    --radius: 6px;
    --radius-lg: 10px;

    /* Motion */
    --ease: cubic-bezier(0.32, 0.72, 0, 1);
    --fast: 120ms;
    --base: 150ms;

    /* Bracket geometry */
    --card-w: 208px;
    --row-h: 34px;
    --conn: 26px;
    --bracket-gap: 14px;
}

/* Light — warm paper, ink accent */
:root,
[data-theme="light"] {
    --bg: #fbfbfa;
    --panel: #ffffff;
    --panel-2: #f5f5f3;
    --panel-3: #ededea;

    --text: #17171a;
    --text-2: #5f5f6a;
    --text-3: #91919c;

    --line: rgba(23, 23, 26, 0.10);
    --line-2: rgba(23, 23, 26, 0.18);

    --accent: #17171a;
    --accent-fg: #ffffff;
    --accent-soft: rgba(23, 23, 26, 0.06);

    --ok: #1a7f37;
    --ok-soft: rgba(26, 127, 55, 0.09);
    --bad: #cf222e;
    --bad-soft: rgba(207, 34, 46, 0.08);
    --gold: #8a6100;
    --gold-soft: rgba(191, 138, 10, 0.12);

    --shadow: 0 1px 2px rgba(23, 23, 26, 0.05),
              0 8px 24px -12px rgba(23, 23, 26, 0.14);
    --shadow-lg: 0 1px 2px rgba(23, 23, 26, 0.06),
                 0 24px 56px -20px rgba(23, 23, 26, 0.26);
    --scrim: rgba(23, 23, 26, 0.28);
}

/* Dark — near-black, paper-white accent */
[data-theme="dark"] {
    --bg: #08090a;
    --panel: #0e0f11;
    --panel-2: #15171a;
    --panel-3: #1d1f23;

    --text: #f2f3f5;
    --text-2: #9aa0a6;
    --text-3: #6a7075;

    --line: rgba(255, 255, 255, 0.09);
    --line-2: rgba(255, 255, 255, 0.17);

    --accent: #f2f3f5;
    --accent-fg: #08090a;
    --accent-soft: rgba(255, 255, 255, 0.07);

    --ok: #3fb950;
    --ok-soft: rgba(63, 185, 80, 0.12);
    --bad: #f85149;
    --bad-soft: rgba(248, 81, 73, 0.12);
    --gold: #e3b341;
    --gold-soft: rgba(227, 179, 65, 0.13);

    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset,
              0 8px 24px -12px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
                 0 32px 64px -24px rgba(0, 0, 0, 0.9);
    --scrim: rgba(0, 0, 0, 0.62);
}

/* ===== Reset ============================================================= */

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

* {
    margin: 0;
    padding: 0;
}

html {
    scrollbar-gutter: stable;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 0 var(--s-5) var(--s-8);
    accent-color: var(--accent);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01';
    text-rendering: optimizeLegibility;
}

::selection {
    background: var(--accent);
    color: var(--accent-fg);
}

.container {
    max-width: 1120px;
    margin: 0 auto;
}

/* Shared typographic primitives ------------------------------------------ */

.mono,
.stat-label,
.eyebrow,
.match-status,
.section-hint,
.champion-label,
.bracket-rounds span,
.league-table th,
.player-num,
.ps-score,
.mr-score,
.stat-value,
.league-table td,
.match-modal-team label {
    font-family: var(--font-mono);
    font-feature-settings: 'zero' 1, 'ss02' 1;
}

/* Tracked-out uppercase metadata — the app's signature detail */
.eyebrow,
.stat-label,
.match-status,
.champion-label,
.bracket-rounds span,
.league-table th,
.match-modal-team label {
    font-size: var(--step--1);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
}

h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
    text-wrap: balance;
}

/* ===== Top bar =========================================================== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    height: 68px;
    margin-bottom: var(--s-7);
    border-bottom: 1px solid var(--line);
}

.wordmark {
    display: flex;
    align-items: baseline;
    gap: var(--s-3);
    min-width: 0;
}

.wordmark strong {
    font-size: var(--step-1);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.wordmark span {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    color: var(--text-3);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* Icon button — the only circular element in the app */
.icon-btn {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: color var(--fast) var(--ease),
                border-color var(--fast) var(--ease),
                background var(--fast) var(--ease);
}

.icon-btn:hover {
    color: var(--text);
    border-color: var(--line-2);
    background: var(--accent-soft);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
    display: block;
}

/* ===== Screens =========================================================== */

.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: rise 320ms var(--ease) both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

/* ===== Setup ============================================================= */
/* No card. Content sits on the page, separated by hairlines. */

.setup-screen {
    max-width: 616px;
    margin: 0 auto;
}

.form-section {
    padding: var(--s-6) 0;
    border-top: 1px solid var(--line);
}

.form-section:first-child {
    padding-top: 0;
    border-top: 0;
}

.section-head {
    margin-bottom: var(--s-4);
}

.section-head h2 {
    font-size: var(--step-0);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.section-head p {
    margin-top: var(--s-1);
    font-size: var(--step--1);
    color: var(--text-3);
}

/* Options panel — a recessed surface, not a bordered card */
.options-panel {
    background: var(--panel-2);
    border: 0;
    border-radius: var(--radius-lg);
    padding: var(--s-5);
    margin-top: var(--s-2);
}

/* Tournament type — hairline grid, no icons ------------------------------ */

.tournament-types {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--s-2);
}

.tournament-option {
    position: relative;
    padding: var(--s-4);
    padding-top: var(--s-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    cursor: pointer;
    user-select: none;
    transition: border-color var(--fast) var(--ease),
                background var(--fast) var(--ease),
                transform var(--fast) var(--ease);
}

.tournament-option::before {
    content: '';
    position: absolute;
    top: var(--s-4);
    left: var(--s-4);
    width: 5px;
    height: 5px;
    border-radius: 1px;
    background: var(--line-2);
    transition: background var(--fast) var(--ease),
                transform var(--base) var(--ease);
}

.tournament-option:hover {
    border-color: var(--line-2);
    transform: translateY(-1px);
}

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

.tournament-option.selected {
    border-color: var(--accent);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.tournament-option.selected::before {
    background: var(--accent);
    transform: scale(1.15);
}

.tournament-option h3 {
    margin-top: var(--s-4);
    font-size: var(--step-0);
    font-weight: 600;
}

.tournament-option p {
    margin-top: 2px;
    font-size: var(--step--1);
    color: var(--text-3);
    line-height: 1.4;
}

/* Radio pills ------------------------------------------------------------ */

.radio-pills {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    background: var(--panel-3);
    border-radius: var(--radius);
    margin-bottom: var(--s-5);
}

.radio-pill input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-pill span {
    display: block;
    padding: 5px var(--s-3);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: var(--step--1);
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color var(--fast) var(--ease),
                background var(--fast) var(--ease),
                box-shadow var(--fast) var(--ease);
}

.radio-pill:hover span {
    color: var(--text);
}

.radio-pill input:checked + span {
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
}

.radio-pill input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Checkbox rows --------------------------------------------------------- */

/* A control label, not metadata — opt out of the global mono/uppercase label rule */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--step-0);
    font-weight: 500;
    text-transform: none;
    letter-spacing: -0.005em;
    color: var(--text);
    cursor: pointer;
}

.checkbox-row input {
    flex: none;
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.checkbox-row + .help-text {
    margin: var(--s-1) 0 0 27px;
}

.help-text {
    font-size: var(--step--1);
    color: var(--text-3);
    line-height: 1.45;
}

.field-gap {
    margin-top: var(--s-5);
}

.divider-soft {
    height: 1px;
    margin: var(--s-5) 0;
    background: var(--line);
}

/* Tabs ------------------------------------------------------------------- */

.input-tabs {
    display: flex;
    gap: var(--s-5);
    margin-bottom: var(--s-4);
    border-bottom: 1px solid var(--line);
}

.input-tab {
    position: relative;
    padding: 0 0 var(--s-3);
    border: 0;
    background: none;
    font-family: var(--font-mono);
    font-size: var(--step--1);
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-3);
    cursor: pointer;
    transition: color var(--fast) var(--ease);
}

.input-tab::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transition: transform var(--base) var(--ease);
}

.input-tab:hover {
    color: var(--text);
}

.input-tab.active {
    color: var(--text);
}

.input-tab.active::after {
    transform: scaleX(1);
}

.input-content {
    display: none;
}

.input-content.active {
    display: block;
}

/* Fields ---------------------------------------------------------------- */

label {
    display: block;
    margin-bottom: var(--s-2);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 9px var(--s-3);
    font-family: var(--font-sans);
    font-size: var(--step-0);
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: border-color var(--fast) var(--ease),
                box-shadow var(--fast) var(--ease);
}

input[type="text"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
    border-color: var(--line-2);
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-3);
}

textarea {
    min-height: 108px;
    resize: vertical;
    line-height: 1.55;
}

select {
    cursor: pointer;
    appearance: none;
    padding-right: var(--s-6);
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

/* Strip number spinners — scores are typed, not nudged */
input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Roster ---------------------------------------------------------------- */

.roster-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-3);
}

.roster-count {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.player-list {
    max-height: 248px;
    overflow-y: auto;
    border-top: 1px solid var(--line);
}

.empty-players {
    padding: var(--s-5) 0;
    font-size: var(--step-0);
    color: var(--text-3);
}

.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    font-size: var(--step-0);
}

.player-item > span {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-width: 0;
}

.player-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-num {
    flex: none;
    width: 22px;
    font-size: var(--step--1);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Quiet destructive affordance — reveals on row hover */
.btn-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--text-3);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--fast) var(--ease),
                color var(--fast) var(--ease),
                background var(--fast) var(--ease);
}

.player-item:hover .btn-icon,
.btn-icon:focus-visible {
    opacity: 1;
}

.btn-icon:hover {
    color: var(--bad);
    background: var(--bad-soft);
}

/* ===== Buttons =========================================================== */

button {
    font-family: var(--font-sans);
    font-size: var(--step-0);
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
    padding: 9px var(--s-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: var(--step-0);
    font-weight: 500;
    letter-spacing: -0.005em;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--fast) var(--ease),
                border-color var(--fast) var(--ease),
                color var(--fast) var(--ease),
                transform var(--fast) var(--ease),
                opacity var(--fast) var(--ease);
}

.btn-primary:active,
.btn-secondary:active,
.btn-danger:active,
.btn-ghost:active {
    transform: scale(0.985);
}

:where(.btn-primary, .btn-secondary, .btn-danger, .btn-ghost):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    opacity: 0.86;
}

.btn-secondary {
    background: var(--panel);
    border-color: var(--line);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--line-2);
    background: var(--panel-2);
}

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

.btn-ghost:hover {
    background: var(--accent-soft);
    color: var(--text);
}

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

.btn-danger:hover {
    background: var(--bad-soft);
    border-color: transparent;
}

.btn-small {
    padding: 6px var(--s-3);
    font-size: var(--step--1);
}

.btn-block {
    display: block;
    width: 100%;
}

.button-group {
    display: flex;
    gap: var(--s-2);
    align-items: flex-start;
    flex-wrap: wrap;
}

.button-group input {
    flex: 1;
    min-width: 180px;
}

.form-actions {
    display: flex;
    gap: var(--s-2);
    padding-top: var(--s-6);
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}

.form-actions .btn-primary {
    flex: 1 1 180px;
}

/* ===== Tournament screen ================================================= */

.tournament-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--s-5);
    padding-bottom: var(--s-5);
    margin-bottom: var(--s-5);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.tournament-header h2 {
    font-size: var(--step-3);
    letter-spacing: -0.03em;
}

.tournament-subtitle {
    margin-top: var(--s-2);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.02em;
    color: var(--text-3);
}

.tournament-controls {
    display: flex;
    gap: var(--s-2);
    flex-wrap: wrap;
}

/* Stats — a measured row, divided by hairlines, no cards ----------------- */

/* Packed left, hairline-divided — a measured readout, not three floating thirds */
.stats-grid {
    grid-auto-flow: column;
    grid-auto-columns: minmax(132px, max-content);
    justify-content: start;
    gap: 0;
    padding: var(--s-1) 0 var(--s-5);
    margin-bottom: var(--s-6);
    border-bottom: 1px solid var(--line);
}

.stat {
    padding: 0 var(--s-6);
}

.stat:first-child {
    padding-left: 0;
}

.stat:not(:first-child) {
    border-left: 1px solid var(--line);
}

.stat-label {
    margin-bottom: var(--s-2);
}

.stat-value {
    font-size: var(--step-2);
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.meter {
    height: 2px;
    margin-top: var(--s-3);
    background: var(--panel-3);
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    background: var(--accent);
    transition: width 420ms var(--ease);
}

/* Champion — typographic, gold rule, no gradient ------------------------ */

.champion {
    padding: var(--s-4) 0 var(--s-4) var(--s-5);
    border-left: 2px solid var(--gold);
    background: linear-gradient(90deg, var(--gold-soft), transparent 62%);
    margin-bottom: var(--s-6);
    animation: rise 380ms var(--ease) both;
}

.champion-label {
    color: var(--gold);
    margin-bottom: var(--s-1);
}

.champion-name {
    font-size: var(--step-4);
    font-weight: 600;
    letter-spacing: -0.035em;
    line-height: 1.05;
}

/* Section headings ------------------------------------------------------ */

.section-title {
    font-size: var(--step-0);
    font-weight: 600;
    margin: var(--s-7) 0 var(--s-4);
}

.section-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-4);
    margin: var(--s-7) 0 var(--s-4);
    flex-wrap: wrap;
}

.section-title-row .section-title {
    margin: 0;
}

.gameweek-title-row {
    margin-top: var(--s-5);
    margin-bottom: var(--s-3);
}

.gameweek-title-row .section-title {
    font-size: var(--step--1);
}

.section-hint {
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.finals-heading {
    margin: var(--s-8) 0 var(--s-5);
    padding-top: var(--s-6);
    border-top: 1px solid var(--line);
    font-size: var(--step-2);
    letter-spacing: -0.025em;
}

/* ===== League table ===================================================== */
/* Borderless. Hairline rows, mono tabular figures. */

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

.league-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 560px;
}

.league-table th,
.league-table td {
    padding: 9px var(--s-3);
    text-align: right;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.league-table th {
    padding-bottom: var(--s-2);
    font-weight: 500;
}

.league-table td {
    font-size: var(--step-0);
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.league-table th:first-child,
.league-table td:first-child {
    padding-left: 0;
    width: 40px;
    text-align: right;
}

.league-table .col-team {
    text-align: left;
    width: 100%;
    padding-left: var(--s-4);
}

.league-table td.col-team {
    font-family: var(--font-sans);
    color: var(--text);
    font-weight: 500;
    white-space: normal;
}

.league-table tbody tr:last-child td {
    border-bottom: 0;
}

.league-table tbody tr {
    transition: background var(--fast) var(--ease);
}

.league-table tbody tr:hover td {
    background: var(--panel-2);
}

.league-position {
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* Points column carries the weight */
.league-table td:last-child {
    color: var(--text);
    font-weight: 600;
    padding-right: 0;
}

.league-table th:last-child {
    padding-right: 0;
}

/* Advancing — a gold edge marker, not a filled row */
.league-table tr.advancing td:first-child {
    position: relative;
}

.league-table tr.advancing td:first-child::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 15px;
    background: var(--gold);
}

.league-table tr.advancing .league-position,
.league-table tr.advancing td.col-team {
    color: var(--text);
}

.advance-check {
    margin-left: var(--s-2);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
}

/* ===== Match rows (league / round-robin) ================================ */

.matches-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(316px, 1fr));
    gap: 0 var(--s-6);
    border-top: 1px solid var(--line);
}

/* Fixed height so rows keep an even rhythm whether or not a button shows */
.match-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    min-height: 60px;
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--line);
}

.mr-teams {
    flex: 1;
    min-width: 0;
}

.mr-team {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: 1px 0;
    font-size: var(--step-0);
    color: var(--text-2);
}

.mr-team.is-win {
    color: var(--text);
    font-weight: 600;
}

.mr-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mr-score {
    flex: none;
    font-variant-numeric: tabular-nums;
    color: var(--text-3);
}

.mr-team.is-win .mr-score {
    color: var(--text);
}

.mr-action {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    flex: none;
}

.match-status {
    font-size: 10px;
    letter-spacing: 0.1em;
}

.match-status.completed {
    color: var(--ok);
}

.match-status.pending {
    color: var(--text-3);
}

/* Reveal the edit affordance on hover; keep it reachable by keyboard */
.match-row .btn-ghost {
    opacity: 0;
    transition: opacity var(--fast) var(--ease),
                background var(--fast) var(--ease),
                color var(--fast) var(--ease);
}

.match-row:hover .btn-ghost,
.match-row .btn-ghost:focus-visible {
    opacity: 1;
}

/* ===== Bracket =========================================================== */
/*
   Recursive tree. Each .node is a flex row: [feeders][self], vertically
   centred — so a match always sits exactly on the midpoint of its two
   feeders regardless of card height or bracket depth. No magic numbers.
*/

.bracket-view {
    overflow-x: auto;
    padding-bottom: var(--s-4);
    scrollbar-width: thin;
    scrollbar-color: var(--line-2) transparent;
}

.bracket-view::-webkit-scrollbar {
    height: 8px;
}

.bracket-view::-webkit-scrollbar-thumb {
    background: var(--line-2);
    border-radius: 4px;
}

.bracket {
    display: inline-block;
    min-width: 100%;
}

/* Column headers — pitch matches the tree exactly:
   card width + both connector halves. */
.bracket-rounds {
    display: flex;
    margin-bottom: var(--s-4);
}

.bracket-rounds span {
    flex: none;
    width: var(--card-w);
    text-align: center;
}

.bracket-rounds span + span {
    margin-left: calc(var(--conn) * 2);
}

.bracket-rounds span:last-child {
    color: var(--text-2);
}

.node {
    display: flex;
    align-items: center;
}

.node-children {
    display: flex;
    flex-direction: column;
    gap: var(--bracket-gap);
    margin-right: calc(var(--conn) * 2);
}

.node-self {
    flex: none;
    width: var(--card-w);
    position: relative;
}

/* Horizontal stub leaving each feeder */
.node-children > .node::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    width: var(--conn);
    height: 1px;
    background: var(--line-2);
}

.node-children > .node {
    position: relative;
}

/* Vertical halves meeting at the parent's centre.
   50% of the feeder's own height + half the gap lands precisely on the
   midpoint between the two feeders — exact at every depth. */
.node-children > .node::before {
    content: '';
    position: absolute;
    left: calc(100% + var(--conn));
    width: 1px;
    height: calc(50% + var(--bracket-gap) / 2);
    background: var(--line-2);
}

.node-children > .node:first-child::before {
    top: 50%;
}

.node-children > .node:last-child::before {
    bottom: 50%;
}

/* Horizontal run into the parent card */
.node:not(.leaf) > .node-self::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    width: var(--conn);
    height: 1px;
    background: var(--line-2);
}

/* Match card — uniform height by construction, whole surface is the control */
.match-card {
    display: block;
    width: 100%;
    padding: 0 var(--s-3);
    text-align: left;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: border-color var(--fast) var(--ease),
                background var(--fast) var(--ease),
                box-shadow var(--fast) var(--ease),
                transform var(--fast) var(--ease);
}

.match-card:hover:not(:disabled) {
    border-color: var(--line-2);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.match-card:active:not(:disabled) {
    transform: none;
}

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

.match-card:disabled {
    cursor: default;
    background: transparent;
    border-style: dashed;
}

/* A settled match needs no badge — the scores and the bold winner say it. */
.match-card.is-done {
    background: var(--panel-2);
}

.ps {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    height: var(--row-h);
    font-size: var(--step-0);
    color: var(--text-2);
}

.ps + .ps {
    border-top: 1px solid var(--line);
}

.ps-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ps-score {
    flex: none;
    font-variant-numeric: tabular-nums;
    color: var(--text-3);
}

.ps.is-win {
    color: var(--text);
    font-weight: 600;
}

.ps.is-win .ps-score {
    color: var(--text);
}

.ps.is-ph .ps-name {
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ===== Modal ============================================================= */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    padding: var(--s-5);
    background: var(--scrim);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fade 140ms var(--ease) both;
}

@keyframes fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-content {
    width: 100%;
    max-width: 424px;
    padding: var(--s-5);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: pop 200ms var(--ease) both;
}

@keyframes pop {
    from { opacity: 0; transform: translateY(6px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

.modal-header {
    margin-bottom: var(--s-5);
}

.modal-header h2 {
    font-size: var(--step--1);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-family: var(--font-mono);
    color: var(--text-3);
}

.modal-header p {
    margin-top: var(--s-2);
    font-size: var(--step-1);
    font-weight: 500;
    letter-spacing: -0.015em;
    color: var(--text);
}

.modal-body {
    margin-bottom: var(--s-4);
}

.match-modal-content {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: var(--s-3);
    align-items: end;
}

.match-modal-team {
    min-width: 0;
}

.match-modal-team h3 {
    margin-bottom: var(--s-3);
    font-size: var(--step-0);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-modal-team label {
    margin-bottom: var(--s-2);
}

.match-modal-team input {
    padding: var(--s-3);
    font-family: var(--font-mono);
    font-size: var(--step-2);
    font-weight: 500;
    text-align: center;
    font-variant-numeric: tabular-nums;
    background: var(--panel-2);
}

.modal-vs {
    padding-bottom: var(--s-3);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

.modal-hint {
    margin-top: var(--s-4);
    font-size: var(--step--1);
    color: var(--text-3);
}

.modal-footer {
    display: flex;
    gap: var(--s-2);
    padding-top: var(--s-4);
    border-top: 1px solid var(--line);
}

.modal-footer button {
    flex: 1;
}

/* ===== Alerts ============================================================ */

.error {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-3) 0 var(--s-3) var(--s-3);
    margin-top: var(--s-4);
    border-left: 2px solid var(--bad);
    background: var(--bad-soft);
    color: var(--text);
    font-size: var(--step-0);
    animation: rise 180ms var(--ease) both;
}

.empty-state {
    padding: var(--s-8) 0;
    color: var(--text-3);
}

.empty-state h3 {
    margin-bottom: var(--s-2);
    color: var(--text);
}

/* ===== Responsive ======================================================== */

/* Column flow can't wrap — fall back to a wrapping row grid on narrow viewports */
@media (max-width: 880px) {
    .stats-grid {
        grid-auto-flow: row;
        grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
        row-gap: var(--s-5);
    }

    .stat {
        padding: 0 var(--s-4);
    }

    .stat:not(:first-child) {
        border-left: 1px solid var(--line);
    }
}

/* Two per row keeps labels on one line so the values share a baseline.
   Dividers would land mid-row once items wrap, so drop them here. */
@media (max-width: 680px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        column-gap: var(--s-4);
    }

    .stat,
    .stat:first-child {
        padding: 0;
    }

    .stat:not(:first-child) {
        border-left: 0;
    }
}

@media (max-width: 680px) {
    body {
        padding: 0 var(--s-4) var(--s-7);
    }

    :root {
        --card-w: 172px;
        --conn: 16px;
    }

    .topbar {
        height: 60px;
        margin-bottom: var(--s-6);
    }

    .wordmark span {
        display: none;
    }

    .tournament-types {
        grid-template-columns: 1fr;
    }

    .tournament-option {
        padding: var(--s-3) var(--s-4) var(--s-4) var(--s-6);
    }

    .tournament-option::before {
        top: 50%;
        left: var(--s-4);
        margin-top: -2px;
    }

    .tournament-option h3 {
        margin-top: 0;
    }

    .tournament-header h2 {
        font-size: var(--step-2);
    }

    /* Explicit track minimum (not auto/min-content) so a long label can never
       push the row wider than the viewport — it wraps or ellipsises instead. */
    .tournament-controls {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
        width: 100%;
    }

    .tournament-controls button {
        min-width: 0;
        padding-left: var(--s-2);
        padding-right: var(--s-2);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .matches-section {
        grid-template-columns: 1fr;
    }

    .match-row .btn-ghost {
        opacity: 1;
    }

    .btn-icon {
        opacity: 1;
    }

    .match-modal-content {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .modal-vs {
        padding: 0;
        text-align: center;
    }

    .champion-name {
        font-size: var(--step-3);
    }
}

/* ===== Preferences ======================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
        padding: 0;
    }

    .topbar,
    .tournament-controls,
    .match-card:disabled,
    .modal {
        display: none !important;
    }
}
