/* 기본 스타일 초기화 및 body 설정 */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: sans-serif;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
:root {
    --team-a-color: #f44336;
    --team-b-color: #2196f3;
}
*, *:before, *:after {
    box-sizing: inherit;
}

/* 두 팀을 감싸는 메인 컨테이너 */
.squad-container {
    display: flex;
    width: 100%;
    flex: 1; /* 남은 공간 모두 사용 */
    overflow: hidden; /* 스크롤바가 생기지 않도록 설정 */
}

/* 스코어보드 스타일 */
.scoreboard {
    background-color: white;
    height: 50px;
    display: flex;
    justify-content: center; /* 중앙 정렬 */
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
    font-weight: bold;
}

.team-color-bar {
    width: 6px;
    height: 100%;
    background-color: var(--team-a-color); /* 포인트 컬러 (A팀 색상 연동) */
}

#team-b-color-bar {
    background-color: var(--team-b-color);
}

.team-name {
    font-size: 1.2rem;
    color: black;
    padding: 0 20px;
    white-space: nowrap;
    cursor: pointer; /* 클릭 가능 표시 */
}

/* 팀 이름 래퍼 (메뉴 위치 기준) */
.team-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
}

/* 팀 설정 메뉴 */
.team-controls {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    border: 1px solid #ccc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    flex-direction: column;
    z-index: 20;
    min-width: 90px;
}

.team-wrapper.show-controls .team-controls {
    display: flex;
}

.team-controls button {
    border: none;
    background: none;
    padding: 8px 10px;
    cursor: pointer;
    text-align: center;
    font-size: 0.9rem;
    width: 100%;
    white-space: nowrap;
}

.team-controls button:hover {
    background-color: #f0f0f0;
}

/* 색상 선택기 드롭다운 스타일 */
.color-picker-dropdown {
    display: none;
    width: 100%;
    height: 30px;
    cursor: pointer;
}

.score-box {
    background-color: black;
    color: white;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 10px;
}

.score-input {
    width: 40px;
    height: 100%;
    font-size: 1.5rem;
    text-align: center;
    background-color: transparent;
    color: white;
    border: none;
    outline: none;
}
/* 입력창 화살표 제거 */
.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.timer-box {
    background-color: black;
    color: white;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 15px;
    font-family: monospace;
    font-size: 1.2rem;
    cursor: pointer; /* 클릭 가능 표시 */
    font-weight: bold; /* 글씨 굵게 */
}

.timer-part {
    background: transparent;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    width: 30px;
    text-align: center;
    outline: none;
    cursor: inherit;
}

.timer-part:not([readonly]) {
    cursor: text;
}

/* 타이머 래퍼 (메뉴 위치 기준) */
.timer-wrapper {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

/* 경기 진행 컨트롤 메뉴 */
.match-controls {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    border: 1px solid #ccc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    flex-direction: column;
    z-index: 20;
    min-width: 60px;
}

.timer-wrapper.show-controls .match-controls {
    display: flex;
}

.match-controls button {
    border: none;
    background: none;
    padding: 8px 10px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    font-size: 0.9rem;
    width: 100%;
    white-space: nowrap;
}

.match-controls button:hover {
    background-color: #f0f0f0;
}

/* 선수 목록 영역 (좌우 사이드) */
.player-list {
    flex: 1;
    background-color: #f5f5f5;
    padding: 20px;
    text-align: center;
    overflow-y: auto;
}

/* 목록 내부 섹션 구분 스타일 */
.list-section {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    margin-bottom: 15px;
    padding: 10px;
}

.list-section h3 {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-section h3::after {
    content: '▼';
    font-size: 0.8em;
}

.list-section.collapsed h3::after {
    content: '▲';
}

.list-section.collapsed .player {
    display: none;
}

.count {
    font-size: 0.9rem;
    color: #666;
    font-weight: normal;
}

/* 포메이션 버튼 영역 */
.formation-controls {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 10px;
}

.formation-select {
    padding: 5px;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 3px;
    width: 100%;
}

/* 개별 선수 아이템 */
.player {
    display: flex;
    align-items: center;
    background-color: #fafafa;
    padding: 8px 12px;
    margin: 5px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: grab;
}

.player-number {
    font-weight: bold;
    color: #f44336;
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

.player-pos {
    font-size: 0.75rem;
    font-weight: bold;
    width: 32px;
    text-align: center;
    margin-right: 8px;
    padding: 2px 0;
    border-radius: 3px;
    color: #fff;
    background-color: #9e9e9e;
}

/* 포지션별 색상 */
.player-pos[data-pos="GK"] { background-color: #ff9800; }
.player-pos[data-pos="DF"] { background-color: #2196f3; }
.player-pos[data-pos="MF"] { background-color: #4caf50; }
.player-pos[data-pos="FW"] { background-color: #f44336; }

/* 카드 스타일 */
.player-card {
    display: inline-block;
    width: 10px;
    height: 14px;
    margin-left: 5px;
    border-radius: 2px;
    border: 1px solid #ccc; /* 기본 테두리 */
    background-color: #fff; /* 기본 배경 (카드 없음) */
    opacity: 1;
}
.player-card.yellow { background-color: #ffeb3b; border: 1px solid #fbc02d; opacity: 1; }
.player-card.red { background-color: #f44336; border: 1px solid #d32f2f; opacity: 1; }

/* [신규] 부상 아이콘 스타일 */
.player-injury {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 5px;
    border-radius: 2px;
    border: 1px solid #ccc;
    background-color: #fff;
    cursor: pointer;
    position: relative; /* + 기호 위치 기준 */
    vertical-align: middle; /* 다른 아이콘과 정렬 */
}

.player-injury.injured {
    background-color: transparent;
    border-color: transparent;
}

.player-injury.injured::before {
    content: '+';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ff0000; /* 선명한 빨간색 */
    font-weight: bold;
    font-size: 20px; /* 크기 확대 */
    line-height: 1;
}

.player-name {
    flex-grow: 1;
    display: flex;
    justify-content: flex-start; /* 아이콘들을 오른쪽으로 밀기 위해 변경 */
    align-items: center;
}

.player-icons {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
}

/* 교체 표시 스타일 */
.player-sub {
    display: none;
    font-size: 0.8em;
    font-weight: bold;
    margin-right: 5px;
}
.player-sub.in { display: inline-block; color: #4caf50; } /* Green */
.player-sub.in::after { content: '▲'; }
.player-sub.out { display: inline-block; color: #f44336; } /* Red */
.player-sub.out::after { content: '▼'; }

/* 유니폼 모드에서 교체 표시 위치 조정 */
.team .player .player-sub {
    display: none; /* 유니폼 모드에서는 일단 숨김 (필요시 표시 가능) */
}

/* 드래그 중인 선수 아이템 */
.player.dragging {
    opacity: 0.5;
    background: #cce5ff;
}

/* 각 팀 영역의 공통 스타일 */
.team {
    flex: 2; /* 팀 영역을 목록보다 넓게 설정 */
    padding: 20px;
    text-align: center;
    position: relative; /* 포메이션 배치를 위해 자식 요소의 기준점 설정 */
    overflow: hidden; /* 선수가 영역 밖으로 나가는 것 방지 */
    border: 2px solid white; /* 경기장 외곽선 */
    margin: 4% 0; /* 위아래 여백을 주어 그라운드 비율 조정 */
}

/* 유니폼 스타일 (경기장 위에 있을 때) */
.team .player {
    position: absolute; /* 필드 내 절대 위치 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    padding: 0;
    width: 60px; /* 유니폼 폭 */
    box-shadow: none;
    z-index: 5; /* 라인보다 위에 표시 */
}

/* 유니폼 모드에서 카드 위치 조정 */
.team .player .player-card {
    position: static;
    display: none;
    width: 10px;
    height: 14px;
    margin-left: 4px;
    border: none;
    vertical-align: middle;
}

.team .player .player-card.yellow,
.team .player .player-card.red {
    display: inline-block;
}

/* [신규] 유니폼 모드 부상 아이콘 */
.team .player .player-injury {
    display: none; /* 기본 숨김 */
    width: 14px;
    height: 14px;
    margin-left: 4px;
    border: none;
    vertical-align: middle;
}

.team .player .player-injury.injured {
    display: inline-block; /* 부상 시 표시 */
}

/* 유니폼 모드에서는 포지션 배지 숨김 */
.team .player .player-pos {
    display: none;
}

/* 유니폼 상의 (등번호 부분) */
.team .player .player-number {
    width: 50px;
    height: 40px;
    margin-right: 0;
    margin-bottom: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    /* 티셔츠 모양 만들기 (폴리곤) */
    clip-path: polygon(15% 0%, 85% 0%, 100% 25%, 85% 35%, 85% 100%, 15% 100%, 15% 35%, 0% 25%);
    /* 그림자 효과 (clip-path 사용 시 box-shadow 대신 filter 사용) */
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
}

/* A팀 유니폼 색상 (빨강) */
.team[data-team="a"] .player .player-number {
    background-color: var(--team-a-color);
}

/* B팀 유니폼 색상 (파랑) */
.team[data-team="b"] .player .player-number {
    background-color: var(--team-b-color);
}

/* 선수 이름 (유니폼 아래) */
.team .player .player-name {
    color: white;
    text-shadow: 1px 1px 2px black;
    font-size: 0.85rem;
    font-weight: bold;
    background-color: rgba(0,0,0,0.4);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    display: inline-block;
}

/* A팀 필드 (왼쪽 진영) */
#team-a {
    background-color: #4CAF50;
    /* 잔디 패턴 + 골 라인 (왼쪽 40px 지점) */
    background-image: 
        linear-gradient(to right, transparent 40px, rgba(255, 255, 255, 0.7) 40px, rgba(255, 255, 255, 0.7) 43px, transparent 43px),
        repeating-linear-gradient(to right, #4CAF50, #4CAF50 50px, #43A047 50px, #43A047 100px);
    border-right: 1px solid rgba(255, 255, 255, 0.7); /* 하프라인 */
}

/* A팀 센터 서클 (반원) */
#team-a::before {
    content: '';
    position: absolute;
    width: 120px;
    height: 120px;
    border: 3px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    top: 50%;
    right: 0;
    transform: translate(50%, -50%); /* 오른쪽으로 절반 이동 */
    pointer-events: none; /* 드래그 방해 금지 */
}

/* A팀 페널티 박스 */
#team-a::after {
    content: '';
    position: absolute;
    width: 15%;
    height: 40%;
    border: 3px solid rgba(255, 255, 255, 0.7);
    top: 50%;
    left: 40px; /* 골 라인에 맞춰 이동 */
    transform: translateY(-50%);
    pointer-events: none;
}

/* B팀 필드 (오른쪽 진영) */
#team-b {
    background-color: #4CAF50;
    /* 잔디 패턴 + 골 라인 (오른쪽 40px 지점) */
    background-image: 
        linear-gradient(to left, transparent 40px, rgba(255, 255, 255, 0.7) 40px, rgba(255, 255, 255, 0.7) 43px, transparent 43px),
        repeating-linear-gradient(to right, #4CAF50, #4CAF50 50px, #43A047 50px, #43A047 100px);
    border-left: 1px solid rgba(255, 255, 255, 0.7); /* 하프라인 */
}

/* B팀 센터 서클 (반원) */
#team-b::before {
    content: '';
    position: absolute;
    width: 120px;
    height: 120px;
    border: 3px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    top: 50%;
    left: 0;
    transform: translate(-50%, -50%); /* 왼쪽으로 절반 이동 */
    pointer-events: none;
}

/* B팀 페널티 박스 */
#team-b::after {
    content: '';
    position: absolute;
    width: 15%;
    height: 40%;
    border: 3px solid rgba(255, 255, 255, 0.7);
    top: 50%;
    right: 40px; /* 골 라인에 맞춰 이동 */
    transform: translateY(-50%);
    pointer-events: none;
}

/* 경계선 스타일 */
#list-left { border-right: 1px solid #ddd; }
#list-right { border-left: 1px solid #ddd; }

/* 감독 표시 스타일 */
.manager-box {
    position: absolute;
    bottom: 15px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
    cursor: pointer;
}
.manager-label {
    font-weight: bold;
    color: #ffd700;
}
.team[data-team="a"] .manager-box {
    left: 20px;
}
.team[data-team="b"] .manager-box {
    right: 20px;
    flex-direction: row-reverse;
}

/* D-DAY 바 스타일 */
.d-day-bar {
    background-color: #333;
    color: white;
    text-align: center;
    padding: 8px 0;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    gap: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 9;
}

#d-day-count {
    font-weight: bold;
    color: #ffd700; /* 금색 강조 */
}

/* [신규] 팀 검색 모달 스타일 */
.modal {
    display: none; 
    position: fixed; 
    z-index: 100; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.5); 
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto; 
    padding: 20px;
    border: 1px solid #888;
    width: 90%; 
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover { color: black; }

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#team-search-input {
    flex: 1;
    padding: 10px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#btn-search-confirm {
    padding: 10px 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#search-results {
    max-height: 300px;
    overflow-y: auto;
    border-top: 1px solid #eee;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.search-result-item:hover { background-color: #f5f5f5; }

.team-logo {
    width: 30px;
    height: 30px;
    margin-right: 10px;
    object-fit: contain;
}

.team-info { display: flex; flex-direction: column; }
.team-name-txt { font-weight: bold; }
.team-country { font-size: 0.8rem; color: #666; }

.loading-msg, .error-msg, .no-result { padding: 15px; text-align: center; color: #666; }
.error-msg { color: #f44336; }