:root {
    --bg-dark: #0b3d07;
    --accent: #e6f7ea;
    --shadow: rgba(2, 8, 15, 0.35);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    padding: 8px;
    min-height: 100vh;
    width: 100%;
    background: linear-gradient(135deg, #06250a 0%, #0b3d07 50%, #08310a 100%);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    color: #fff;
    overflow-x: hidden;
}

.container {
    display: flex;
    height: 100%;
    width: 100%;
    gap: 8px;
    align-items: stretch;
    justify-content: center;
    flex-direction: row;
}

.main {
    width: 88%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 6px;
    overflow: hidden;
    border-radius: 12px 0 0 12px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.4), 0 20px 50px rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.1);
}

/* Pitch: centered image with overlay for player placement */
.pitch {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    flex: 1;
}

.img-wrap {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.pitch img {
    height: auto;
    width: 100%;
    display: block;
    max-width: 100%;
    object-fit: contain;
}

.players-overlay {
    position: absolute;
    pointer-events: none;
}

/* Player and substitution circles */
.player, .sub {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 76px;
}

.player .circle, .sub .circle {
    width: clamp(42px, 5.5vw, 70px);
    height: clamp(42px, 5.5vw, 70px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #111;
    font-weight: 800;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
    transition: all 140ms cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.player .circle:active {
    transform: scale(0.98);
}

.player .circle:hover {
    transform: translateY(-8px) scale(1.08);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5), inset 0 -2px 4px rgba(0, 0, 0, 0.2);
}

/* Role colors */
.circle.portero {
    background: #e74c3c;
    color: #fff;
}

.circle.defensa {
    background: #f1c40f;
    color: #111;
}

.circle.medio {
    background: #9b59b6;
    color: #fff;
}

.circle.delantera {
    background: #3498db;
    color: #fff;
}

.number {
    font-size: 16px;
    text-align: center;
}

.player-name {
    width: 100%;
    max-width: 110px;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 8px rgba(2, 8, 15, 0.06) inset;
    background: rgba(255, 255, 255, 0.98);
    color: #111;
    font-size: 13px;
    box-sizing: border-box;
}

.player-name:focus {
    outline: none;
    border-color: rgba(0, 0, 0, 0.15);
}

.sidebar {
    width: 12%;
    height: 100%;
    border-radius: 0 12px 12px 0;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
    box-shadow: inset 2px 0 15px rgba(0, 0, 0, 0.2), -8px 0 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(4px);
}

.formation-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.formation-controls label {
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
}

.formation-controls select,
.formation-controls button {
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.98);
    color: #111;
    font-size: 13px;
    cursor: pointer;
    transition: background 120ms ease;
}

.formation-controls select:hover,
.formation-controls button:hover {
    background: #fff;
}

.formation-controls button {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.95);
}

#CAMBIOS {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    height: 100%;
    overflow: hidden;
    background: transparent;
    align-content: flex-start;
}

#CAMBIOS .sub {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    pointer-events: auto;
    min-height: fit-content;
}

#CAMBIOS .sub .circle {
    flex-shrink: 0;
    width: clamp(36px, 4.5vw, 52px);
    height: clamp(36px, 4.5vw, 52px);
}

#CAMBIOS .sub .player-name {
    flex: 1;
    font-size: 11px;
    padding: 4px 6px;
}

/* Semantic sections (kept for accessibility, hidden from display) */
#DELANTEROS,
#MEDIOCAMPISTAS,
#DEFENSAS,
#PORTERO {
    display: none;
}

/* Overlay player pointer events */
.players-overlay .player .player-name {
    pointer-events: auto;
}

/* Scrollbar styling */
#CAMBIOS::-webkit-scrollbar {
    width: 6px;
}

#CAMBIOS::-webkit-scrollbar-track {
    background: transparent;
}

#CAMBIOS::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#CAMBIOS::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* MEDIA QUERIES - TABLET (768px - 1024px) */
@media (max-width: 1024px) {
    body {
        padding: 6px;
    }

    .main {
        width: 75%;
    }

    .sidebar {
        width: 25%;
    }

    .player .circle, .sub .circle {
        width: clamp(36px, 4.5vw, 60px);
        height: clamp(36px, 4.5vw, 60px);
    }

    .number {
        font-size: 14px;
    }

    .player-name {
        font-size: 11px;
        max-width: 90px;
    }

    #CAMBIOS .sub .circle {
        width: clamp(32px, 4vw, 48px);
        height: clamp(32px, 4vw, 48px);
    }

    #CAMBIOS .sub .player-name {
        font-size: 10px;
    }

    .formation-controls {
        padding: 8px;
        gap: 6px;
    }

    .formation-controls label {
        font-size: 12px;
    }

    .formation-controls select,
    .formation-controls button {
        padding: 4px 6px;
        font-size: 11px;
    }
}

/* MEDIA QUERIES - TABLET PORTRAIT (600px - 768px) */
@media (max-width: 768px) {
    body {
        padding: 4px;
        overflow-y: auto;
    }

    .container {
        flex-direction: column;
        gap: 4px;
        height: auto;
        min-height: 100vh;
    }

    .main {
        width: 100%;
        height: auto;
        min-height: 50vh;
        border-radius: 12px;
        flex-shrink: 0;
    }

    .pitch {
        max-height: 55vh;
    }

    .pitch img {
        height: auto;
        width: 100%;
        max-height: 55vh;
    }

    .sidebar {
        width: 100%;
        height: auto;
        min-height: 40vh;
        max-height: 40vh;
        border-radius: 12px;
        border-left: none;
        border-top: 2px solid rgba(255, 255, 255, 0.1);
        overflow-y: auto;
        flex-shrink: 0;
    }

    .player .circle, .sub .circle {
        width: clamp(32px, 6vw, 52px);
        height: clamp(32px, 6vw, 52px);
    }

    .number {
        font-size: 12px;
    }

    .player-name {
        font-size: 10px;
        max-width: 80px;
        padding: 4px 6px;
    }

    .player {
        width: 60px;
    }

    #CAMBIOS {
        padding: 8px;
        gap: 6px;
        flex-wrap: wrap;
        flex-direction: row;
        overflow-y: auto;
        height: auto;
    }

    #CAMBIOS .sub {
        flex: 0 1 calc(50% - 4px);
        min-width: 120px;
        display: flex;
        flex-direction: row;
    }

    #CAMBIOS .sub .circle {
        width: clamp(28px, 5vw, 44px);
        height: clamp(28px, 5vw, 44px);
    }

    #CAMBIOS .sub .player-name {
        font-size: 9px;
        padding: 2px 4px;
    }

    .formation-controls {
        padding: 6px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .formation-controls label {
        font-size: 11px;
        width: 100%;
    }

    .formation-controls select,
    .formation-controls button {
        padding: 4px 6px;
        font-size: 10px;
        flex: 1;
        min-width: 60px;
    }
}

/* MEDIA QUERIES - MOBILE (320px - 600px) */
@media (max-width: 600px) {
    body {
        padding: 4px;
        overflow-y: auto;
    }

    .container {
        flex-direction: column;
        gap: 4px;
        height: auto;
        min-height: 100vh;
    }

    .main {
        width: 100%;
        height: auto;
        border-radius: 8px;
        padding: 4px;
        gap: 6px;
        flex-shrink: 0;
    }

    .pitch {
        position: relative;
        height: auto;
        min-height: 45vh;
        max-height: 50vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .img-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .pitch img {
        height: auto;
        width: 100%;
        max-height: 50vh;
        object-fit: contain;
    }

    .sidebar {
        width: 100%;
        height: auto;
        min-height: 35vh;
        max-height: 40vh;
        border-radius: 8px;
        border-left: none;
        border-top: 2px solid rgba(255, 255, 255, 0.1);
        overflow-y: auto;
        flex-shrink: 0;
    }

    .player .circle, .sub .circle {
        width: clamp(28px, 5.5vw, 44px);
        height: clamp(28px, 5.5vw, 44px);
    }

    .number {
        font-size: 11px;
    }

    .player-name {
        font-size: 9px;
        max-width: 70px;
        padding: 3px 5px;
    }

    .player {
        width: 55px;
        gap: 4px;
    }

    #CAMBIOS {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        padding: 8px;
        gap: 8px;
        overflow-y: auto;
        height: auto;
        flex: 1;
    }

    #CAMBIOS .sub {
        flex-direction: column;
        width: auto;
        align-items: center;
        display: flex;
    }

    #CAMBIOS .sub .circle {
        width: clamp(24px, 4.5vw, 36px);
        height: clamp(24px, 4.5vw, 36px);
    }

    #CAMBIOS .sub .player-name {
        font-size: 8px;
        padding: 2px 4px;
        max-width: 75px;
        text-align: center;
    }

    .formation-controls {
        padding: 8px;
        gap: 4px;
        flex-direction: column;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .formation-controls label {
        font-size: 10px;
        width: 100%;
    }

    .formation-controls select,
    .formation-controls button {
        padding: 6px 8px;
        font-size: 10px;
        width: 100%;
    }
}

/* MEDIA QUERIES - SMALL MOBILE (320px - 480px) */
@media (max-width: 480px) {
    body {
        padding: 2px;
    }

    .main {
        border-radius: 6px;
        padding: 2px;
        gap: 4px;
    }

    .pitch {
        min-height: 40vh;
        max-height: 45vh;
    }

    .pitch img {
        max-height: 45vh;
    }

    .sidebar {
        min-height: 30vh;
        max-height: 35vh;
        border-radius: 6px;
    }

    .player .circle, .sub .circle {
        width: clamp(24px, 5vw, 38px);
        height: clamp(24px, 5vw, 38px);
    }

    .number {
        font-size: 10px;
    }

    .player-name {
        font-size: 8px;
        max-width: 65px;
    }

    .player {
        width: 50px;
    }

    #CAMBIOS {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        padding: 6px;
        gap: 6px;
    }

    #CAMBIOS .sub .circle {
        width: clamp(20px, 4vw, 32px);
        height: clamp(20px, 4vw, 32px);
    }

    .formation-controls {
        padding: 6px;
        gap: 2px;
    }

    .formation-controls select,
    .formation-controls button {
        padding: 4px 6px;
        font-size: 9px;
    }
}