:root {
    --page: #f3f5f1;
    --paper: #ffffff;
    --ink: #161815;
    --muted: #687267;
    --soft: #eef1ea;
    --line: #d7ddd3;
    --pitch: #18784d;
    --pitch-dark: #0f5c3a;
    --accent: #c82e34;
    --gold: #e4b73a;
    --blue: #295ea8;
    --shadow: 0 18px 48px rgba(25, 31, 24, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
    background:
        linear-gradient(180deg, rgba(24, 120, 77, 0.1), transparent 260px),
        var(--page);
    color: var(--ink);
    font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(24, 120, 77, 0.28);
    outline-offset: 2px;
}

.page {
    width: calc(100% - 32px);
    max-width: 1280px;
    margin: 0 auto;
    padding: 26px 0 40px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(220px, 0.9fr) minmax(320px, 1.4fr);
    gap: 16px;
    align-items: stretch;
    margin-bottom: 16px;
}

.brand,
.controls,
.panel,
.bracket-section {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
}

.brand>div {
    min-width: 0;
}

.brand-mark {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 48%),
        var(--pitch);
    color: #fff;
    font-weight: 900;
    letter-spacing: 0.04em;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(24px, 3vw, 36px);
    line-height: 1;
    letter-spacing: 0;
}

.status-line {
    margin-top: 8px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.status-line.is-ok {
    color: var(--pitch-dark);
}

.status-line.is-error {
    color: var(--accent);
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
    padding: 16px;
}

.field {
    display: grid;
    gap: 6px;
}

.field label,
.panel-kicker {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.field select,
.field input {
    height: 42px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    padding: 0 12px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field select:focus,
.field input:focus {
    border-color: rgba(24, 120, 77, 0.7);
    box-shadow: 0 0 0 4px rgba(24, 120, 77, 0.14);
}

.refresh-button {
    height: 42px;
    min-width: 0;
    width: 100%;
    border: 0;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    transition: transform 0.2s ease, background 0.2s ease;
}

.refresh-button:hover {
    transform: translateY(-1px);
    background: var(--pitch-dark);
}

.refresh-button:disabled {
    cursor: progress;
    opacity: 0.72;
    transform: none;
}

.quick-filters {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-filters button,
.view-toggle button,
.bracket-actions button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    padding: 0 12px;
    font-size: 13px;
    font-weight: 800;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.quick-filters button:hover,
.quick-filters button.is-active,
.view-toggle button:hover,
.view-toggle button.is-active,
.bracket-actions button:hover {
    border-color: rgba(24, 120, 77, 0.55);
    background: rgba(24, 120, 77, 0.1);
    color: var(--pitch-dark);
}

.api-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(330px, 0.85fr);
    gap: 16px;
    margin-bottom: 16px;
}

.panel {
    overflow: hidden;
}

.panel-header,
.bracket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(238, 241, 234, 0.6);
}

.panel-header h2,
.bracket-header h2 {
    font-size: 18px;
    line-height: 1.1;
    letter-spacing: 0;
}

.panel-count {
    white-space: nowrap;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.panel-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.view-toggle {
    display: inline-flex;
    gap: 6px;
}

.compact-select {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.compact-select select {
    min-width: 112px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    padding: 0 8px;
}

.compact-select select:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.match-feed {
    display: grid;
    gap: 10px;
    max-height: 386px;
    overflow: auto;
    padding: 14px;
}

.api-match {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    min-height: 74px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 8px;
    background: var(--paper);
    padding: 10px;
}

.api-match.is-live {
    border-left-color: var(--accent);
    background: rgba(200, 46, 52, 0.04);
}

.api-match.is-finished {
    border-left-color: var(--pitch);
}

.api-match.is-scheduled {
    border-left-color: var(--gold);
}

.api-team {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    min-width: 0;
    font-size: 13px;
    font-weight: 800;
}

.api-team.away {
    grid-template-columns: minmax(0, 1fr) 28px;
    text-align: right;
}

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

.api-crest,
.api-initials {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--soft);
    border: 1px solid var(--line);
    object-fit: contain;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
}

.api-score {
    min-width: 82px;
    text-align: center;
}

.api-score strong {
    display: block;
    font-size: 20px;
    line-height: 1.1;
}

.api-score span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.matches-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.matches-table th,
.matches-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.matches-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f9faf7;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.matches-table td:nth-child(3),
.matches-table th:nth-child(3) {
    text-align: center;
}

.match-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    background: var(--soft);
    color: var(--muted);
    padding: 0 9px;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.match-status.is-live {
    background: rgba(200, 46, 52, 0.12);
    color: var(--accent);
}

.match-status.is-finished {
    background: rgba(24, 120, 77, 0.12);
    color: var(--pitch-dark);
}

.empty-state {
    min-height: 120px;
    display: grid;
    place-items: center;
    padding: 22px;
    color: var(--muted);
    text-align: center;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.empty-state.is-error {
    color: var(--accent);
}

.standings-wrap {
    max-height: 386px;
    overflow: auto;
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

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

.standings-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f9faf7;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.standings-table th:first-child,
.standings-table td:first-child {
    text-align: left;
}

.standing-team {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    min-width: 170px;
    font-weight: 800;
    text-align: left;
}

.standing-team img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.standing-team span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bracket-section {
    overflow: hidden;
}

.bracket-header {
    align-items: flex-start;
}

.bracket-header p {
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.bracket-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.bracket-viewport {
    overflow: auto;
    padding: 16px;
    background:
        linear-gradient(90deg, rgba(24, 120, 77, 0.06) 1px, transparent 1px) 0 0 / 96px 96px,
        linear-gradient(180deg, rgba(24, 120, 77, 0.05) 1px, transparent 1px) 0 0 / 96px 96px,
        #fbfcfa;
}

.meta-line {
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
}

.bracket-shell {
    width: 1192px;
    height: 752px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        radial-gradient(circle at 50% 50%, rgba(24, 120, 77, 0.08), transparent 250px),
        #fff;
}

.round-title {
    position: absolute;
    top: 8px;
    width: 150px;
    text-align: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.match {
    position: absolute;
    width: 136px;
    min-height: 74px;
    border: 1px solid var(--line);
    border-left: 4px solid #aeb7ad;
    border-radius: 8px;
    background: #fff;
    padding: 9px 9px 8px 8px;
    box-shadow: 0 8px 20px rgba(22, 24, 21, 0.08);
    z-index: 2;
}

.match--finished {
    border-left-color: var(--pitch);
}

.match--scheduled {
    border-left-color: var(--gold);
}

.match--center {
    width: 196px;
    height: 150px;
    text-align: center;
    padding: 10px 16px;
    border-left-color: var(--accent);
}

.match__top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 8px;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}

.match__status {
    color: var(--ink);
    text-align: right;
}

.team {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    height: 22px;
    color: var(--ink);
    font-size: 10px;
    font-weight: 700;
}

.team img {
    width: 16px;
    height: 11px;
    display: block;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

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

.team__score {
    min-width: 14px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 900;
    text-align: right;
}

.team__score small {
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
}

.team--winner .team__name,
.team--winner .team__score {
    color: var(--pitch-dark);
}

.team--future {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 8px;
    height: 26px;
    color: var(--muted);
}

.shield {
    width: 16px;
    height: 19px;
    display: inline-block;
    opacity: 0.48;
    background:
        url("data:image/svg+xml,%3Csvg width='24' height='28' viewBox='0 0 24 28' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 1.7L22 5.4V12.1C22 18.4 18 24.2 12 26.3C6 24.2 2 18.4 2 12.1V5.4L12 1.7Z' fill='%23aeb7ad'/%3E%3Cpath d='M12 4.2V23.3C16.6 21.3 19.4 16.8 19.4 12.1V7.2L12 4.2Z' fill='%23eef1ea'/%3E%3C/svg%3E") center / contain no-repeat;
}

.connector {
    position: absolute;
    z-index: 1;
    pointer-events: none;
}

.connector::before {
    content: "";
    position: absolute;
    background: #bfc8bd;
}

.connector.h::before {
    left: 0;
    top: 0;
    width: 100%;
    height: 1px;
}

.connector.v::before {
    left: 0;
    top: 0;
    width: 1px;
    height: 100%;
}

.final-card__title {
    margin-bottom: 13px;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.final-card__date {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.final-card__time {
    margin-bottom: 14px;
    font-size: 18px;
    font-weight: 900;
}

.final-card__teams {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px;
}

.final-card__team {
    width: 48px;
    text-align: center;
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
}

.final-card__team .shield {
    width: 24px;
    height: 28px;
    display: block;
    margin: 0 auto 7px;
}

.final-card__line {
    height: 1px;
    margin-bottom: 7px;
    background: var(--line);
}

.final-card__soon {
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

@media (max-width: 980px) {

    .topbar,
    .api-grid {
        grid-template-columns: 1fr;
    }

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

    .refresh-button {
        width: 100%;
    }

    .panel-tools {
        justify-content: flex-start;
    }
}

@media (max-width: 620px) {
    .page {
        width: calc(100% - 20px);
        max-width: none;
        padding-top: 10px;
    }

    .brand,
    .controls,
    .panel,
    .bracket-section {
        width: 100%;
        max-width: calc(100vw - 20px);
    }

    .brand {
        align-items: flex-start;
        overflow: hidden;
    }

    .status-line {
        max-width: calc(100vw - 116px);
    }

    .empty-state {
        max-width: calc(100vw - 42px);
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .quick-filters button,
    .view-toggle button,
    .bracket-actions button {
        flex: 1 1 auto;
    }

    .quick-filters {
        display: grid;
        grid-template-columns: 1fr;
    }

    .quick-filters button {
        width: 100%;
        min-width: 0;
    }

    .panel-header,
    .bracket-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .api-match {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .api-team.away {
        grid-template-columns: 28px minmax(0, 1fr);
        text-align: left;
    }

    .api-team.away .api-team-name {
        order: 2;
    }

    .api-team.away .api-crest,
    .api-team.away .api-initials {
        order: 1;
    }

    .api-score {
        width: 100%;
        min-width: 0;
        padding: 8px 0;
        border-top: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
    }

    .bracket-viewport {
        padding: 10px;
    }

    .meta-line {
        text-align: left;
    }
}
