/* The squad container is a query target so children can size with cqi */
.lineup-container {
    container-type: inline-size;
    container-name: lineup;
    width: 100%;
}

.lineup-pitch {
    width: 100%;
}

.squad {
    background-color: green;
    background-image: url("../assets/football-field-vertical.jpg");
    width: 100%;
    position: relative;
    background-size: cover;
    background-position: bottom 0 left 50%;
    aspect-ratio: 1 / 1.1;
}

/* Lineup strength overlay in top-left corner of pitch */
.lineup-strength-overlay {
    position: absolute;
    top: 2cqi;
    left: 2cqi;
    z-index: 10;
    font-size: 5cqi;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

/* Player pill — all dimensions relative to container width */
.squad .player {
    position: absolute;
    width: 15cqi;
    height: 6cqi;
    background-color: rgba(0, 0, 0, 0.4);
    border: solid 1px white;
    border-radius: 1.7cqi;
    transform: translateX(-50%) translateY(50%);
    color: white;
    text-align: center;
    line-height: 6cqi;
    font-size: 1.9cqi;
    box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
}

.squad .player .player-image {
    width: 15cqi !important;
    height: auto !important;
    transform: translateY(-90%);
}

.squad .player .player-image svg {
    width: 100%;
    height: auto;
}

.player .position-badge {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(-35%) translateY(-50%);
    padding: 0;
    width: 3.8cqi;
    min-width: 0;
    height: 3.8cqi;
    line-height: 3.8cqi;
    font-size: 1.7cqi;
    box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
}

.player .freshness-badge {
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    transform: translateX(-25%) translateY(50%);
    width: 5.5cqi;
    height: 2.7cqi;
    background-color: rgb(0 0 0 / 66%);
    border-radius: 0.5cqi;
    box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
    font-size: 1.9cqi;
    line-height: 2.7cqi;
}

.player .name {
    display: block;
    font-weight: normal;
    font-size: 1.9cqi;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

.player .level-badge {
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    transform: translateX(35%) translateY(50%);
    box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
    /* Override fixed sizes from level-badge.css */
    width: 4.7cqi !important;
    height: 4.7cqi !important;
    line-height: 5cqi !important;
    font-size: 2.5cqi !important;
}

.squad .player:hover {
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.5);
}

/* Position-group border colors — match bootstrap text color groups */
.squad .player.GK {
    border-color: rgb(var(--bs-danger-rgb));
}

.squad .player.LD,
.squad .player.CD,
.squad .player.RD {
    border-color: rgb(var(--bs-warning-rgb));
}

.squad .player.LM,
.squad .player.DM,
.squad .player.CM,
.squad .player.RM,
.squad .player.OM {
    border-color: rgb(var(--bs-info-rgb));
}

.squad .player.LA,
.squad .player.CA,
.squad .player.RA {
    border-color: rgb(var(--bs-success-rgb));
}

.squad .player.GK {
    top: 85%;
    left: 50%;
    z-index: 6;
}

.squad .player.LD {
    top: 65%;
    left: 15%;
    z-index: 5;
}

.squad .player.CD {
    top: 70%;
    left: 50%;
    z-index: 5;
}

.squad .player.RD {
    top: 65%;
    left: 85%;
    z-index: 5;
}

.squad .player.CM {
    top: 40%;
    left: var(--lineup-offset, 50%);
    z-index: 3;
}

.squad .player.LM {
    top: 40%;
    left: 15%;
    z-index: 3;
}

.squad .player.RM {
    top: 40%;
    left: 85%;
    z-index: 3;
}

.squad .player.DM {
    top: 55%;
    left: var(--lineup-offset, 50%);
    z-index: 4;
}

.squad .player.OM {
    top: 25%;
    left: 50%;
    z-index: 2;
}

.squad .player.CA {
    top: 10%;
    left: 50%;
    z-index: 1;
}

.squad .player.RA {
    top: 10%;
    left: 75%;
    z-index: 1;
}

.squad .player.LA {
    top: 10%;
    left: 25%;
    z-index: 1;
}

.squad .player.CD {
    left: var(--lineup-offset, 50%);
}

/* Landscape layout — rotate pitch 90° clockwise when viewport is wider than tall */
@media (orientation: landscape) {
    .squad {
        background-image: url("../assets/football-field-horizontal.jpg");
        background-position: left;
        aspect-ratio: 1.5 / 1;
    }

    /* Scale players down ~20% in landscape */
    .squad .player {
        width: 12cqi;
        height: 4.8cqi;
        border-radius: 1.4cqi;
        line-height: 4.8cqi;
        font-size: 1.5cqi;
    }

    .squad .player .player-image {
        width: 12cqi !important;
    }

    .player .position-badge {
        width: 3cqi;
        height: 3cqi;
        line-height: 3cqi;
        font-size: 1.4cqi;
    }

    .player .freshness-badge {
        width: 4.4cqi;
        height: 2.2cqi;
        border-radius: 0.4cqi;
        font-size: 1.5cqi;
        line-height: 2.2cqi;
    }

    .player .name {
        font-size: 1.5cqi;
    }

    .player .level-badge {
        width: 3.8cqi !important;
        height: 3.8cqi !important;
        line-height: 4cqi !important;
        font-size: 2cqi !important;
    }

    .squad .player.GK {
        top: 46%;
        left: 10%;
    }

    .squad .player.LD {
        top: 9%;
        left: 35%;
    }

    .squad .player.CD {
        top: calc(var(--lineup-offset, 50%) - 4%);
        left: 30%;
    }

    .squad .player.RD {
        top: 85%;
        left: 35%;
    }

    .squad .player.DM {
        top: calc(var(--lineup-offset, 50%) - 4%);
        left: 45%;
    }

    .squad .player.CM {
        top: calc(var(--lineup-offset, 50%) - 4%);
        left: 60%;
    }

    .squad .player.LM {
        top: 9%;
        left: 60%;
    }

    .squad .player.RM {
        top: 85%;
        left: 60%;
    }

    .squad .player.OM {
        top: 46%;
        left: 75%;
    }

    .squad .player.CA {
        top: 46%;
        left: 90%;
    }

    .squad .player.LA {
        top: 19%;
        left: 90%;
    }

    .squad .player.RA {
        top: 75%;
        left: 90%;
    }
}

.bench-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 150px;
    padding: 6px;
    text-align: center;
    border: 2px solid rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

/* Position-group border colors for bench */
.bench-slot.GK {
    border-color: rgb(var(--bs-danger-rgb));
}

.bench-slot.LD,
.bench-slot.CD,
.bench-slot.RD {
    border-color: rgb(var(--bs-warning-rgb));
}

.bench-slot.LM,
.bench-slot.DM,
.bench-slot.CM,
.bench-slot.RM,
.bench-slot.OM {
    border-color: rgb(var(--bs-info-rgb));
}

.bench-slot.LA,
.bench-slot.CA,
.bench-slot.RA {
    border-color: rgb(var(--bs-success-rgb));
}

.bench-slot:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.bench-slot__image {
    width: 100px;
    height: 105px;
}

.bench-slot__info {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.bench-slot__info .position-badge {
    padding: 1px 5px;
    font-size: 11px;
    min-width: 0;
}

.bench-slot__info .level-badge {
    width: 22px !important;
    height: 22px !important;
    line-height: 22px !important;
    font-size: 11px !important;
}

.bench-slot__name {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.bench-slot__freshness {
    font-size: 11px;
    font-weight: bold;
}

.bench-substitution-mode {
    margin-top: 6px;
    width: 100%;
    font-size: 11px;
    padding: 2px 4px;
    cursor: pointer;
}

/* Empty bench slot */
.bench-slot--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 150px;
    height: 150px;
    background-color: rgba(0, 0, 0, 0.05);
    border: 2px dashed rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    color: rgba(0, 0, 0, 0.4);
    font-size: 13px;
}

.bench-slot--empty .bench-slot__label {
    text-align: center;
}

@media screen and (max-width: 768px) {
    #squad {
        width: calc(100% + 4rem);
        margin: 0 -2rem;
    }

    .bench-slots {
        justify-content: center;
    }

    .bench-slot,
    .bench-slot--empty {
        flex: 1 1 calc(50% - 1rem);
    }
}
