/* =========================
   Base
   ========================= */

:root {
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text);
}

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

a:hover {
    text-decoration: underline;
}

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

h1,
h2 {
    line-height: 1.2;
}

h1 {
    margin: 0 0 16px;
    font-size: clamp(28px, 5vw, 48px);
}

h2 {
    margin: 0 0 16px;
    font-size: 24px;
}

p {
    color: var(--muted);
}

button,
select {
    font: inherit;
}

/* =========================
   Header
   ========================= */

body > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding: 20px max(20px, calc((100% - 1100px) / 2));
    border-bottom: 1px solid var(--border);
}

body > header > a {
    color: var(--text);
}

body > header nav {
    display: flex;
    gap: 8px;
}

body > header nav a {
    color: var(--muted);
    font-weight: 600;
}

body > header nav a:hover {
    color: var(--accent);
}

/* =========================
   Main and footer
   ========================= */

body > main {
    flex: 1;
    margin: 0 auto;
    padding: 32px 0;
}

body > footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
}

body > footer p {
    margin: 0;
}

/* =========================
   Homepage
   ========================= */

body > main > section {
    margin-bottom: 24px;
    padding: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
    scroll-margin-top: 24px;
}

body > main > section:first-child {
    padding: 64px 32px;
    text-align: center;
}

body > main > section:first-child p {
    max-width: 580px;
    margin: 16px auto;
}

body > main > nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 24px;
    margin: 28px 0;
}

body > main > section li {
    padding: 6px 0;
    color: var(--muted);
}

/* =========================
   Buttons and select
   ========================= */

button,
body > main > section:first-child > a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 10px 28px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
}

body > main > section:first-child > a {
    margin-top: 16px;
}

button:disabled {
    cursor: not-allowed;
}

select {
    min-height: 44px;
    padding: 8px 36px 8px 12px;
    border: 1px solid #41516d;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
}

/* =========================
   Game layout
   ========================= */

.game {
    max-width: 1040px;
    margin: 0 auto;
}

.game > h1 {
    font-size: 28px;
}

.game-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin: 16px 0;
    border: 1px solid var(--border);
}

#squad-count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.game-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    align-items: start;
    gap: 20px;
}

/* =========================
   Draw panel
   ========================= */

.game-draw {
    min-width: 0;
    border: 1px solid var(--border);
}

.game-draw p {
    margin: 0 0 20px;
    font-size: 14px;
}

#spin-button {
    width: 100%;
    min-width: 0;
}

.game-draw .game-draw-hint {
    margin: 16px 0 0;
}

/* =========================
   Pitch
   ========================= */

.game-pitch {
    position: relative;
    isolation: isolate;
    display: grid;
    min-width: 0;
    min-height: 400px;
    align-content: space-around;
    gap: 12px;
    padding: 16px 12px;
    overflow: hidden;
    border: 1px solid #3c685c;
}

/* Centre circle */

.game-pitch::before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Halfway line */

.game-pitch::after {
    content: "";
    position: absolute;
    z-index: -1;
    top: 50%;
    left: 0;
    right: 0;
    pointer-events: none;
}

.game-pitch-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* =========================
   Player slots
   ========================= */

.game-slot {
    flex: 1;
    min-width: 0;
    border: 1px solid #ffffff30;
    text-align: center;
}

.game-slot-position {
    display: block;
    margin-bottom: 4px;
    line-height: 1.2;
}

.game-slot-player {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* =========================
   Tablet and mobile layout
   ========================= */

@media (max-width: 991.98px) {
    .game-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }
}

@media (max-width: 760px) {

    .game-draw p {
        margin-bottom: 12px;
    }

    .game-pitch {
        padding: 16px 8px;
    }

    .game-pitch-row {
        gap: 6px;
    }

    .game-slot {
        padding: 10px 3px;
    }

    .game-slot-player {
        font-size: 11px;
    }
}

@media (max-width: 600px) {
    body > main {
        width: calc(100% - 24px);
        padding: 24px 0;
    }

    body > main > section {
        padding: 24px 20px;
    }

    body > main > section:first-child {
        padding: 40px 20px;
    }

    .game-controls {
        gap: 10px;
    }
}

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

.game-draw-actions button {
    flex: 1;
    padding: 10px 12px;
    white-space: nowrap;
    font-size: 13px;
}

.game-draw-actions #spin-button {
    width: auto;
}

.game-draw-actions .button-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.game-draw-actions .button-secondary:hover:not(:disabled) {
    background: #253149;
}

#game-status:not([hidden]) {
    margin: 14px 0 0;
    font-size: 13px;
}

.game-team-header {
    margin: 18px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.game-team-header h3 {
    margin: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.game-team-header > span {
    color: var(--muted);
}

.game-team-players {
    display: grid;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
    margin: 0;
    padding: 0 4px 0 0;
    list-style: none;
    scrollbar-width: thin;
}

.game-team-player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.game-team-player > div {
    min-width: 0;
}

.game-team-player strong {
    display: block;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.game-team-player small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.game-player-rating {
    flex-shrink: 0;
}

/* Selectable players */

.game-team-player {
    width: 100%;
    min-height: 0;
    justify-content: space-between;
    text-align: left;
    color: var(--text);
    font-weight: 400;
    cursor: pointer;
}

.game-team-player:hover:not(:disabled) {
    border-color: var(--accent);
}

.game-team-player.is-selected {
    border-color: var(--accent);
}

.game-team-player:disabled {
    border-color: var(--border);
    color: var(--muted);
    cursor: not-allowed;
}

/* Clickable pitch slots */

.game-slot {
    display: block;
    position: relative;
    color: var(--text);
    font-weight: 400;
}

.game-slot:disabled {
    color: var(--text);
    opacity: 1;
    cursor: default;
}

.game-slot.is-compatible {
    cursor: pointer;
}

.game-slot-rating {
    display: block;
    margin-top: 3px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
}

/* Empty positions */

.game-slot:not(.is-filled) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.game-slot:not(.is-filled) .game-slot-position {
    margin-bottom: 0;
}

.game-slot-player:empty {
    display: none;
}

/* Filled positions */

.game-slot.is-filled,
.game-slot.is-filled:disabled {
    border-color: #8eb8ff;
}

/* Spin animation */

.spin-reel {
    margin-top: 18px;
    text-align: center;
}

.spin-reel-title {
    margin-bottom: 12px;
}

.spin-reel-window {
    display: grid;
    place-items: center;
    height: 86px;
    overflow: hidden;
    border-top: 1px solid #f2c75c55;
    border-bottom: 1px solid #f2c75c55;
}

.spin-reel-team {
    width: 100%;
    animation: spin-team-arrive 85ms ease-out both;
}

.spin-reel-team strong {
    display: block;
    color: var(--accent);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.spin-reel-team span {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

@keyframes spin-team-arrive {
    from {
        opacity: 0.2;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .spin-reel-team {
        animation: none;
    }
}

#game .game-formation-choices {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
}

#game .game-formation-choice {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font: inherit;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color 150ms ease,
        border-color 150ms ease,
        color 150ms ease;
}

#game .game-formation-choice:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.45);
}

#game .game-formation-choice.is-selected {
    border-color: #f4c95d;
}

#game .game-formation-choice.is-selected:hover:not(:disabled) {
    border-color: #ffdc83;
}

#game .game-formation-choice:focus-visible {
    outline: 2px solid #f4c95d;
    outline-offset: 3px;
}

#game .game-formation-choice:disabled {
    cursor: default;
}

#game .game-pitch-hint {
    align-self: center;
    justify-self: center;
    margin: auto;
    padding: 20px;
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    #game .game-formation-choice {
        transition: none;
    }
}
