:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #1f2933;
    --muted: #667085;
    --border: #dfe5ec;
    --primary: #1f5f8b;
    --primary-dark: #174866;
    --accent: #e7f2f9;
    --success-bg: #eaf6ef;
    --success: #287a4b;
    --danger-bg: #fff0ee;
    --danger: #b42318;
    --shadow: 0 8px 28px rgba(31, 41, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    line-height: 1.45;
}

button,
input {
    font: inherit;
}

.page-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 56px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.tournament-status {
    margin: 5px 0 0;
    color: var(--muted);
    font-weight: 700;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 20px;
    align-items: start;
    margin: 20px 0;
}

.card-heading {
    margin-bottom: 14px;
}

.card-heading h2 {
    margin: 0;
}

.eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.table-scroll {
    overflow-x: auto;
}

.standings-table {
    width: 100%;
    min-width: 580px;
    border-collapse: collapse;
}

.standings-table th,
.standings-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.standings-table th {
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
}

.standings-table tr:last-child td {
    border-bottom: 0;
}

.position-cell,
.points-cell {
    font-weight: 800;
}

.next-match-card {
    position: sticky;
    top: 16px;
}

.next-match-list {
    display: grid;
    gap: 10px;
}

.next-match {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 14px;
}

.match-meta {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.next-versus {
    display: grid;
    gap: 5px;
    text-align: center;
}

.next-versus span {
    color: var(--muted);
    font-size: .82rem;
}

.empty-state {
    color: var(--muted);
    text-align: center;
}

.matches-card {
    margin-top: 20px;
}

.match-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.match-list>h3 {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 1rem;
}

.match-card {
    margin: 0;
    padding: 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
}

.match-card p {
    margin: 8px 0;
}

.match-title {
    margin-top: 0 !important;
}

.match-finished {
    background: var(--surface-muted);
}

.match-next {
    border-color: #83b5d6;
    box-shadow: 0 0 0 2px rgba(31, 95, 139, .08);
}

form {
    margin: 10px 0 0;
}

button {
    border: 0;
    border-radius: 8px;
    padding: 9px 13px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    margin: 3px;
}

button:hover {
    background: var(--primary-dark);
}

.message {
    padding: 12px 14px;
    border-radius: 10px;
}

.message-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #f2b8b5;
}

/* Deltagerlisten holdes kompakt. */
.page-shell>h2:first-of-type {
    margin-top: 18px;
}

.page-shell>ul:not(.match-list) {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    padding: 0;
}

.page-shell>ul:not(.match-list) li {
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}

@media (min-width: 861px) {

    /* Ved 8 spillere ligger de to kampe stadig i samme spilleblok visuelt tæt. */
    .match-list>h3+.match-card,
    .match-list>h3+.match-card+.match-card {
        margin-top: 0;
    }
}

@media (max-width: 860px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .next-match-card {
        position: static;
    }
}

@media (max-width: 620px) {
    .page-shell {
        width: calc(100% - 20px);
        padding-top: 16px;
    }

    .page-header {
        display: block;
    }

    .card {
        padding: 15px;
        border-radius: 11px;
    }

    .standings-table {
        min-width: 520px;
    }

    .match-card button {
        width: 100%;
        margin: 4px 0;
    }

    .next-match-buttons button {
        width: 100%;
        margin: 4px 0;
    }
}


/* Tydelig vinder øverst på en afsluttet turnering. */
.winner-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px 20px;
    border: 1px solid #acd7bc;
    border-radius: 12px;
    background: var(--success-bg);
    color: var(--success);
}

.winner-banner-label {
    font-size: .82rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.winner-banner-name {
    font-size: 1.2rem;
    text-align: right;
}

/* Sørg for at brede elementer aldrig skubber mobil-layoutet sidelæns. */
.standings-card,
.next-match-card,
.matches-card,
.table-scroll {
    min-width: 0;
    max-width: 100%;
}

.matches-card {
    width: 100%;
}

@media (max-width: 620px) {

    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .page-shell {
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        padding: 16px 12px 40px;
    }

    .dashboard,
    .card,
    .matches-card {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .winner-banner {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px 16px;
    }

    .winner-banner-name {
        font-size: 1.1rem;
        text-align: left;
    }
}


.next-match-form {
    margin-top: 14px;
}

.next-match-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.next-match-buttons button {
    flex: 1 1 180px;
}

.match-list>h3:first-child {
    margin-top: 0;
}

/* Resultatknapper direkte i boksen "Næste kamp". */
.next-match-form {
    margin-top: 14px;
}

.next-match-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.next-match-buttons button {
    flex: 1 1 180px;
}

/* Når der kræves en handling mellem kampfaser. */
.next-action {
    padding: 4px 0 2px;
    text-align: center;
}

.next-action-title {
    margin: 0 0 8px;
    font-size: 1.05rem;
    font-weight: 800;
}

.next-action p {
    margin: 8px 0;
}

.next-action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.next-action-buttons button {
    flex: 1 1 150px;
}

.match-list>h3:first-child {
    margin-top: 0;
}

@media (max-width: 620px) {

    .next-match-buttons button,
    .next-action-buttons button {
        width: 100%;
        margin: 4px 0;
    }
}

/* Navigation + oversigt over tidligere turneringer */

.top-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.top-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--primary);
    padding: 7px 11px;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.top-nav a:hover {
    background: var(--accent);
    border-color: #a8c7da;
}

.archive-header {
    margin-bottom: 20px;
}

.archive-card {
    padding: 0;
    overflow: hidden;
}

.archive-table {
    width: 100%;
    border-collapse: collapse;
}

.archive-table th,
.archive-table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.archive-table th {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.archive-table tbody tr:last-child td {
    border-bottom: 0;
}

.archive-table tbody tr:hover {
    background: var(--surface-muted);
}

.archive-open-cell {
    width: 1%;
    white-space: nowrap;
    text-align: right !important;
}

.archive-open-link {
    display: inline-flex;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    padding: 7px 12px;
    font-weight: 700;
    text-decoration: none;
}

.archive-open-link:hover {
    background: var(--primary-dark);
}

@media (max-width: 620px) {
    .top-nav {
        margin-bottom: 14px;
    }

    .archive-card {
        padding: 0;
    }

    .archive-table th,
    .archive-table td {
        padding: 10px 8px;
        font-size: 0.86rem;
    }

    .archive-table th:nth-child(3),
    .archive-table td:nth-child(3) {
        display: none;
    }

    .archive-open-link {
        padding: 7px 9px;
    }
}

/* Highscore på siden "Tidligere turneringer" */

.highscore-card {
    margin-bottom: 20px;
}

.highscore-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.highscore-item {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}

.highscore-item:last-child {
    border-bottom: 0;
}

.highscore-position {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-muted);
    color: var(--muted);
    font-weight: 800;
}

.highscore-name {
    min-width: 0;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.highscore-wins {
    color: var(--primary);
    white-space: nowrap;
}

@media (max-width: 620px) {
    .highscore-item {
        grid-template-columns: 34px minmax(0, 1fr) auto;
        gap: 8px;
    }

    .highscore-position {
        width: 26px;
        height: 26px;
        font-size: 0.85rem;
    }
}

/* Spiller-highlighting på turneringssiden */

.participant-chip {
    cursor: pointer;
    user-select: none;
    transition:
        background-color 120ms ease,
        border-color 120ms ease,
        box-shadow 120ms ease,
        transform 120ms ease;
}

.participant-chip:hover {
    border-color: #a8b4c0;
    transform: translateY(-1px);
}

.participant-chip:focus-visible {
    outline: 3px solid rgba(31, 95, 139, 0.24);
    outline-offset: 2px;
}

.participant-chip[aria-pressed="true"] {
    border-color: rgba(31, 41, 51, 0.28);
    box-shadow: 0 0 0 2px rgba(31, 41, 51, 0.06);
}

.player-reference {
    border-radius: 5px;
    padding: 1px 4px;
    margin: 0 -1px;
    transition:
        background-color 120ms ease,
        box-shadow 120ms ease;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

[data-highlight-color="1"] {
    background: #fff0a8 !important;
}

[data-highlight-color="2"] {
    background: #bfe3ff !important;
}

[data-highlight-color="3"] {
    background: #c9efc7 !important;
}

[data-highlight-color="4"] {
    background: #ffd0d0 !important;
}

[data-highlight-color="5"] {
    background: #e3d1ff !important;
}

[data-highlight-color="6"] {
    background: #ffdca8 !important;
}

[data-highlight-color="7"] {
    background: #bfeee8 !important;
}

[data-highlight-color="8"] {
    background: #f5c9e5 !important;
}

[data-highlight-color="9"] {
    background: #d7e8aa !important;
}

[data-highlight-color="10"] {
    background: #cfd9ff !important;
}

[data-highlight-color="11"] {
    background: #f4d6b8 !important;
}

[data-highlight-color="12"] {
    background: #d8d8d8 !important;
}

button .player-reference[data-highlight-color] {
    color: #1f2933;
    font-weight: 800;
}

/* Mobil: få hele stillingstabellen til at være synlig uden vandret scroll */
@media (max-width: 620px) {
    .standings-card .table-scroll {
        overflow-x: visible;
    }

    .standings-table {
        width: 100%;
        min-width: 0 !important;
        table-layout: fixed;
        font-size: 0.82rem;
    }

    .standings-table th,
    .standings-table td {
        padding: 9px 5px;
        white-space: normal;
    }

    .standings-table th:nth-child(1),
    .standings-table td:nth-child(1) {
        width: 10%;
    }

    .standings-table th:nth-child(2),
    .standings-table td:nth-child(2) {
        width: 30%;
    }

    .standings-table th:nth-child(3),
    .standings-table td:nth-child(3) {
        width: 14%;
    }

    .standings-table th:nth-child(4),
    .standings-table td:nth-child(4) {
        width: 14%;
    }

    .standings-table th:nth-child(5),
    .standings-table td:nth-child(5) {
        width: 14%;
    }

    .standings-table th:nth-child(6),
    .standings-table td:nth-child(6) {
        width: 18%;
    }

    .standings-table td:nth-child(2) {
        overflow-wrap: anywhere;
    }
}

/* Holdfarver på resultatknapper */
button[name="vinder_hold"][value="1"] {
    background: #3f7398;
}

button[name="vinder_hold"][value="1"]:hover {
    background: #315d7c;
}

button[name="vinder_hold"][value="2"] {
    background: #a65f62;
}

button[name="vinder_hold"][value="2"]:hover {
    background: #884b4e;
}

body {
    cursor: url("/images/Mouse.png"), auto;
}

.highscore-position {
    position: relative;
}

/* Top 3 i highscoren */

.rank-guld,
.rank-soelv,
.rank-bronze {
    font-weight: 800;
}

/*
 * Kronen placeres foran navnet i stedet for over placeringstallet.
 * Dermed ændrer den ikke rækkens højde.
 */
.rank-guld+.highscore-name::before,
.rank-soelv+.highscore-name::before,
.rank-bronze+.highscore-name::before {
    content: "";
    display: inline-block;

    width: 22px;
    height: 18px;

    margin-right: 8px;
    vertical-align: -3px;

    -webkit-mask:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 19h20v2H2v-2zM2 5l4 3 6-5 6 5 4-3v12H2V5z'/%3E%3C/svg%3E") center / contain no-repeat;

    mask:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 19h20v2H2v-2zM2 5l4 3 6-5 6 5 4-3v12H2V5z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Guld */
.rank-guld {
    color: #b89216;
}

.rank-guld+.highscore-name::before {
    background: linear-gradient(135deg,
            #fff1a8 0%,
            #ffd700 35%,
            #d4af37 65%,
            #8e6800 100%);

    filter: drop-shadow(0 1px 2px rgb(180 135 0 / 35%));
}

/* Sølv */
.rank-soelv {
    color: #7e858c;
}

.rank-soelv+.highscore-name::before {
    background: linear-gradient(135deg,
            #ffffff 0%,
            #d9dde0 35%,
            #aeb4ba 65%,
            #686e74 100%);

    filter: drop-shadow(0 1px 2px rgb(100 100 100 / 30%));
}

/* Bronze */
.rank-bronze {
    color: #a66332;
}

.rank-bronze+.highscore-name::before {
    background: linear-gradient(135deg,
            #f0b77e 0%,
            #cd7f32 40%,
            #a95d29 70%,
            #70401f 100%);

    filter: drop-shadow(0 1px 2px rgb(130 70 30 / 30%));
}