/* A pitch, attacking upwards. Slots are positioned by the formation's x/y. */
.pitch {
    position: relative;
    aspect-ratio: 68 / 80;
    width: 100%;
    background-color: var(--pitch);
    /* Mown stripes across the pitch. */
    background-image: repeating-linear-gradient(
        to bottom,
        var(--pitch) 0 10%,
        var(--pitch-stripe) 10% 20%
    );
    border: 0.125rem solid var(--pitch-line);
    overflow: hidden;
    /* Slot sizes below use cqi (1% of the pitch's width), so everything
       scales with the pitch rather than the screen. */
    container-type: inline-size;
}

.pitch--large {
    max-width: 30rem;
}

.pitch__halfway {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 0.125rem solid var(--pitch-line);
}

.pitch__circle {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 24%;
    aspect-ratio: 1;
    border: 0.125rem solid var(--pitch-line);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.pitch__box {
    position: absolute;
    left: 25%;
    width: 50%;
    height: 14%;
    border: 0.125rem solid var(--pitch-line);
}

.pitch__box--own {
    bottom: -0.125rem;
}

.pitch__box--opponent {
    top: -0.125rem;
}

.pitch__slot {
    position: absolute;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    /* Slots in a line of n are 100/(n+1) % of the pitch apart; labels take
       90% of that gap, so neighbours never touch - narrow in a back five,
       roomy for a front two. */
    width: min(5.5rem, calc(90cqi / (var(--line-size, 1) + 1)));
    transform: translate(-50%, 50%);
    text-align: center;
}

.pitch__position {
    display: grid;
    place-items: center;
    width: clamp(1.35rem, 8.5cqi, 2.25rem);
    height: clamp(1.35rem, 8.5cqi, 2.25rem);
    border: 0.125rem solid var(--black);
    border-radius: 50%;
    background-color: var(--tertiary);
    color: var(--black);
    font-size: clamp(0.5rem, 2.4cqi, 0.7rem);
    font-weight: 700;
    white-space: nowrap;
}

/* A taller pitch on phones gives the lines more room vertically. */
@media (max-width: 40rem) {
    .pitch--large {
        aspect-ratio: 68 / 100;
    }
}

.pitch__slot--close .pitch__position {
    background-color: var(--white);
    border-style: dashed;
}

/*
 * An empty slot is a dimple in the grass: full white on a faint dark fill, so
 * the label reads (about 7:1; white at 70% opacity on the green was 3:1),
 * inside a dashed, faint ring (docs/adr/0120).
 */
.pitch__slot--empty .pitch__position {
    background-color: oklch(0% 0 0 / 0.25);
    border: 0.125rem dashed var(--pitch-line);
    color: var(--white);
    font-weight: 800;
}

/* Up to two lines, breaking between the parts of a name (docs/adr/0042). */
.pitch__name {
    display: -webkit-box;
    max-width: 100%;
    padding: 0 0.25rem;
    overflow: hidden;
    background-color: var(--black);
    color: var(--white);
    font-size: clamp(0.55rem, 2.6cqi, 0.7rem);
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* Legend swatches match the slot styles above. */
.legend {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    white-space: nowrap;
}

.legend__swatch {
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    border: 0.125rem solid var(--black);
    border-radius: 50%;
}

.legend__swatch--exact {
    background-color: var(--tertiary);
}

.legend__swatch--close {
    background-color: var(--white);
    border-style: dashed;
}

.legend__swatch--empty {
    border: 0.125rem dashed var(--border);
}

/* Catalogue / preference cards */
.formations__list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: 1.5rem;
}

.formation-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/*
 * Phones: two a row, so twelve formations are six screens' worth less to
 * scroll (docs/adr/0112). The pitches are drawn to the width they're given.
 */
@media (max-width: 47.99rem) {
    .formations__list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .formation-card__name {
        font-size: 1.05rem;
    }

    .formation-card--choice {
        padding: 0.5rem;
    }

    /* Room for a name over two lines, so the pitches line up. */
    .formation-card--choice .formation-card__pick {
        min-height: 3.25rem;
    }
}

.formation-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
}

.formation-card__name {
    font-size: 1.25rem;
    font-weight: 700;
}

.formation-card__description {
    font-size: 0.875rem;
    opacity: 0.85;
}

/*
 * Picking preferred formations (docs/adr/0098): a tile each, as the
 * formation list's (lineup-switcher), yellow while it's ticked. Its
 * label's ::after covers the tile, pitch and all, so a tap anywhere on it
 * ticks or unticks the box, as a tap on its name does.
 */
.formation-card--choice {
    position: relative;
    /* The label's cover (z-index: 2) stacks inside the tile, not over Save's bar. */
    isolation: isolate;
    padding: 0.75rem;
    border: 0.125rem solid var(--black);
    border-radius: 0.5rem;
    background-color: var(--white);
}

.formation-card--choice:has(:checked) {
    background-color: var(--tertiary);
    box-shadow: var(--box-shadow);
}

/* Not on touch screens, where a tapped tile keeps :hover, and so the shadow, ticked or not. */
@media (hover: hover) {
    .formation-card--choice:hover {
        box-shadow: var(--box-shadow);
    }
}

.formation-card__pick {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.formation-card__pick::after {
    content: "";
    position: absolute;
    inset: 0;
    /* Over the pitch's slots (z-index: 1). */
    z-index: 2;
}

.formation-card__pick input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--tertiary);
}

/* Black on the tile's yellow, where a yellow box would disappear. */
.formation-card__pick input:checked {
    accent-color: var(--black);
}

/*
 * A lineup, one formation at a time (docs/adr/0042, 0051): the formation
 * list, then the formation's name, legend, pitch and what's beside it. The
 * frame round it is a container, so the layout goes by the room the lineup
 * has - in a box on an event, the page's width elsewhere - not the screen's.
 */
.lineup-frame {
    display: block;
    container: lineup / inline-size;
}

/* With room for three columns: the list down the left of the pitch. */
@container lineup (min-width: 60rem) {
    .lineup-layout {
        display: grid;
        grid-template-columns: 12rem minmax(0, 1fr);
        align-items: start;
        gap: 2rem;
    }
}

.lineup__name {
    font-size: 1.125rem;
    font-weight: 700;
}

.lineup__filled {
    font-weight: 700;
}

/* The pitch, then what's beside it - sized to their content, not stretched. */
.lineup__body {
    display: grid;
    gap: 1.5rem;
    padding-bottom: 0.5rem;
}

@container lineup (min-width: 40rem) {
    .lineup__body {
        grid-template-columns: minmax(0, 30rem) minmax(12rem, 20rem);
        justify-content: start;
        align-items: start;
        gap: 2rem;
    }
}

.lineup__side h3 {
    margin-bottom: 0.5rem;
}

.lineup__side li + li {
    margin-top: 0.25rem;
}

.lineup__help {
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.badge {
    padding: 0.1rem 0.5rem;
    background-color: var(--tertiary);
    color: var(--black);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* Out of position (a manager's choice) */
.pitch__slot--out_of_position .pitch__position {
    background-color: var(--warning);
    color: var(--black);
}

.legend__swatch--out {
    background-color: var(--warning);
}

/* Pinned by the manager: a small marker on the position circle */
.pitch__slot--pinned .pitch__position {
    position: relative;
}

.pitch__slot--pinned .pitch__position::after,
.legend__pin {
    content: "";
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border: 0.1rem solid var(--black);
    border-radius: 50%;
    background-color: var(--white);
}

.pitch__slot--pinned .pitch__position::after {
    position: absolute;
    top: -0.2rem;
    right: -0.2rem;
}

/* Editing: slots and bench players are links/buttons */
.swap-form {
    display: contents;
}

.swap-target {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: inherit;
    text-decoration: none;
    cursor: pointer;
}

.pitch__slot .swap-target:hover .pitch__position,
.pitch__slot .swap-target:focus-visible .pitch__position {
    outline: 0.2rem solid var(--white);
    outline-offset: 0.1rem;
}

.pitch__slot.is-selected .pitch__position {
    outline: 0.25rem solid var(--white);
    outline-offset: 0.15rem;
    transform: scale(1.15);
}

/* While something is selected, every other target pulses gently. */
@media (prefers-reduced-motion: no-preference) {
    .pitch--selecting .pitch__slot:not(.is-selected) .pitch__position {
        animation: swap-hint 1.2s ease-in-out infinite alternate;
    }
}

@keyframes swap-hint {
    to { outline: 0.15rem solid var(--white); outline-offset: 0.1rem; }
}

.lineup__bench-list {
    display: grid;
    gap: 0.25rem;
}

.bench-player .swap-target {
    flex-direction: row;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.2rem 0.4rem;
    border: 0.125rem solid transparent;
}

.bench-player .swap-target:hover,
.bench-player .swap-target:focus-visible,
.bench-player.is-selected .swap-target {
    border-color: var(--tertiary);
}

.bench-player.is-selected .swap-target {
    background-color: var(--tertiary);
    color: var(--black);
}

/* Black on white, or yellow for their main position - as on the roster. */
.bench-player__positions .position-list__item:not(.position-list__item--primary) {
    background-color: var(--white);
    color: var(--black);
}

.bench-player__none {
    font-size: 0.8rem;
    opacity: 0.8;
}

.lineup__hint {
    margin-bottom: 1rem;
    font-weight: 700;
}

.lineup__note {
    font-size: 0.875rem;
    opacity: 0.85;
}

.lineup__reset {
    margin-top: 1.5rem;
}

/* Squad builder: taking the selected player off, above the bench. */
.lineup__to-bench {
    margin-bottom: 0.75rem;
}

.badge--edited {
    background-color: var(--white);
}

/* Close fits and Ranked preference: side by side when there's room. */
.fit-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 2rem;
    margin-bottom: 0.75rem;
}

.fit-toggle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.fit-toggle__label {
    font-weight: 700;
}

.fit-toggle__option {
    padding: 0.2rem 0.75rem;
    border: 0.125rem solid var(--border);
    text-decoration: none;
}

.fit-toggle__option.is-active {
    border-color: var(--black);
    background-color: var(--tertiary);
    color: var(--black);
    font-weight: 700;
}

.fit-toggle__link {
    margin-left: 0.5rem;
}

/* A row of them, each centred on the others: "picked by you"'s smaller circle would otherwise sit it lower. */
.legends {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    margin-bottom: 1rem;
}

/*
 * An event's lineup, one formation at a time (docs/adr/0042): the
 * options, a link per formation, then that formation's pitch and bench.
 */
.lineup-options {
    margin-bottom: 1rem;
    border: 0.125rem solid var(--border);
    border-radius: 0.5rem;
}

.lineup-options__summary {
    padding: 0.5rem 0.875rem;
    font-weight: 700;
    cursor: pointer;
}

.lineup-options__body {
    padding: 0 0.875rem 0.875rem;
}

.fit-toggles__help {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
    font-size: 0.875rem;
}

/*
 * The formation list (docs/adr/0051): one row that scrolls sideways rather
 * than wrapping onto several, each formation a tile - its shape, name and
 * how full it is. The tabs controller starts it with the one shown in view;
 * a thin scrollbar stays, for a mouse.
 */
.lineup-switcher {
    margin-bottom: 1rem;
}

.lineup-switcher__list {
    position: relative;
    display: flex;
    gap: 0.5rem;
    /* Room inside the scrolling box for the shown one's shadow. */
    padding: 0.125rem 0.25rem 0.5rem 0.125rem;
    overflow-x: auto;
    scrollbar-width: thin;
}

.lineup-switcher__list > li {
    flex: 0 0 auto;
}

.lineup-switcher__option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 4.75rem;
    padding: 0.5rem 0.5rem 0.375rem;
    border: 0.125rem solid var(--black);
    border-radius: 0.5rem;
    background-color: var(--white);
    color: var(--black);
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
}

.lineup-switcher__option:hover,
.lineup-switcher__option:focus-visible {
    box-shadow: var(--box-shadow);
}

.lineup-switcher__option.is-current {
    background-color: var(--tertiary);
    box-shadow: var(--box-shadow);
}

.lineup-switcher__filled {
    font-size: 0.8rem;
    font-weight: 400;
}

.lineup-switcher__star {
    margin-left: 0.2rem;
    font-size: 0.8rem;
}

/* Down the side of the pitch: a row per formation - shape, name, how full. */
@container lineup (min-width: 60rem) {
    .lineup-switcher {
        margin-bottom: 0;
    }

    .lineup-switcher__list {
        flex-direction: column;
        gap: 0;
        padding: 0;
        overflow: visible;
    }

    /* A row each, banded white and grey like a table's; the one shown yellow. */
    .lineup-switcher__option {
        flex-direction: row;
        gap: 0.75rem;
        min-width: 0;
        padding: 0.3rem 0.625rem 0.3rem 0.375rem;
        border-color: transparent;
        border-radius: 0;
    }

    :where(.lineup-switcher__list > li:nth-child(even)) > .lineup-switcher__option {
        background-color: var(--row-stripe);
    }

    .lineup-switcher__option:hover,
    .lineup-switcher__option:focus-visible,
    .lineup-switcher__option.is-current {
        border-color: var(--black);
        box-shadow: none;
    }

    .lineup-switcher__label {
        flex: 1;
    }

    .lineup-switcher__filled {
        font-size: 0.875rem;
    }
}

/*
 * A formation's shape (pitch.shape): its slots as dots on a little pitch.
 * In the row of tiles it takes the same share of the lineup's width (cqi) on
 * any phone; its dots grow with it, in cqi of the shape itself.
 */
.formation-shape {
    position: relative;
    flex: none;
    width: clamp(2.5rem, 17cqi, 4.5rem);
    aspect-ratio: 68 / 80;
    border-radius: 0.1875rem;
    background-color: var(--pitch);
    container-type: inline-size;
}

.formation-shape__dot {
    position: absolute;
    width: max(0.3125rem, 12.5cqi);
    height: max(0.3125rem, 12.5cqi);
    border: max(0.0625rem, 2.5cqi) solid var(--white);
    border-radius: 50%;
    transform: translate(-50%, 50%);
}

.formation-shape__dot.is-filled {
    background-color: var(--white);
}

@container lineup (min-width: 60rem) {
    .formation-shape {
        width: 2rem;
    }
}

.lineup__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
    margin-bottom: 0.5rem;
}

.lineup__bench-heading {
    margin-bottom: 0.5rem;
}

/* The bench as a row of names that wraps, like the subs under a team sheet. */
.lineup--single .lineup__bench-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.lineup--single .lineup__side li + li {
    margin-top: 0;
}

.lineup--single .bench-player {
    border: 0.0625rem solid var(--border);
    border-radius: 0.375rem;
    background-color: var(--white);
}

.lineup--single .bench-player:not(:has(.swap-target)) {
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.2rem 0.4rem;
}

.lineup__share {
    margin-top: 1rem;
}

/*
 * The squad builder's slot picker (docs/adr/0044): who could play the slot
 * picked, best first - in the side column on wide screens, a sheet over the
 * bottom of the screen (above the bottom bar) on phones.
 */
.slot-picker {
    margin-bottom: 1.25rem;
    padding: 0.75rem;
    border: 0.125rem solid var(--black);
    border-radius: 0.5rem;
    box-shadow: var(--box-shadow);
    background-color: var(--white);
}

/* The heading, and Cancel beside it (docs/adr/0119). */
.slot-picker__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.slot-picker__heading {
    font-size: 1rem;
}

/* A row each, banded white and grey like a table's. */
.slot-picker__list {
    display: grid;
}

.slot-picker__option {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.6rem;
    border: 0.125rem solid transparent;
    background-color: var(--white);
    color: var(--black);
    text-decoration: none;
}

/* :where(), so hovering or focusing a grey row still turns it yellow. */
:where(.slot-picker__list > li:nth-child(even)) > .slot-picker__option {
    background-color: var(--row-stripe);
}

.slot-picker__option:hover,
.slot-picker__option:focus-visible {
    border-color: var(--black);
    background-color: var(--tertiary);
}

.slot-picker__name {
    font-weight: 700;
}

.slot-picker__fit {
    font-size: 0.8rem;
    white-space: nowrap;
}

.slot-picker__option--exact .slot-picker__fit {
    font-weight: 700;
}

.slot-picker__option--out-of-position {
    opacity: 0.8;
}

@media (max-width: 47.99rem) {
    .slot-picker {
        position: fixed;
        right: 0;
        bottom: calc(4rem + env(safe-area-inset-bottom));
        left: 0;
        z-index: 40;
        max-height: 45vh;
        margin: 0;
        padding-top: 0;
        overflow-y: auto;
        border-width: 0.1875rem 0 0;
        border-radius: 0.75rem 0.75rem 0 0;
        box-shadow: 0 -0.25rem 0 var(--black);
    }

    /* Cancel stays in view as the names scroll under it. */
    .slot-picker__head {
        position: sticky;
        top: 0;
        z-index: 1;
        margin-bottom: 0;
        padding: 0.75rem 0 0.5rem;
        background-color: var(--white);
    }
}
