/* 기본 스타일 초기화 및 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;
    position: relative; /* 로고 절대 위치 배치를 위해 추가 */
}

/* [신규] 사이트 로고 스타일 */
.site-logo {
    position: absolute;
    left: 20px;
    height: 44px; /* 로고 크기 확대 (꽉 차게) */
    width: auto;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
}

.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 10px;
    white-space: nowrap;
    cursor: pointer; /* 클릭 가능 표시 */
}

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

/* [신규] 상단 팀 로고 스타일 */
.team-logo-header {
    height: 30px;
    display: none; /* 이미지가 있을 때만 스크립트로 block 처리 */
    object-fit: contain; /* 로고 비율 유지 및 중앙 정렬 */
}

#team-a-logo {
    margin-left: 15px;
    margin-right: 5px;
}

#team-b-logo {
    margin-left: 5px;
    margin-right: 15px;
}

/* 팀 설정 메뉴 */
.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 !important;
}

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

/* [신규] 포지션 필터 버튼 */
.filter-controls {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 10px;
}

.filter-btn {
    padding: 5px 10px;
    border: 1px solid #ccc;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    transition: all 0.2s;
}

.filter-btn.active {
    background-color: #333;
    color: white;
    border-color: #333;
}

/* 포메이션 버튼 영역 */
.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;
}

/* [신규] 필드와 감독 정보를 감싸는 래퍼 */
.field-wrapper {
    flex: 2;
    display: flex;
    flex-direction: column;
    margin: 4% 0;
    position: relative;
}

/* 각 팀 영역의 공통 스타일 */
.team {
    flex: 1; /* 래퍼 내부에서 남은 공간 차지 */
    padding: 20px;
    text-align: center;
    position: relative; /* 포메이션 배치를 위해 자식 요소의 기준점 설정 */
    overflow: hidden; /* 선수가 영역 밖으로 나가는 것 방지 */
    border: 2px solid white; /* 경기장 외곽선 */
}

/* 유니폼 스타일 (경기장 위에 있을 때) */
.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 {
    margin-top: 10px;
    background-color: #333; /* 배경색 조금 더 진하게 */
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 10;
    cursor: pointer;
    width: fit-content;
}
#manager-box-a {
    align-self: flex-start; /* 왼쪽 정렬 */
}
#manager-box-b {
    align-self: flex-end; /* 오른쪽 정렬 */
}
.manager-label {
    font-weight: bold;
    color: #ffd700;
}

/* 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: 1000; /* z-index 상향 조정 */
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.6); /* 배경 더 어둡게 */
    backdrop-filter: blur(4px); /* 배경 블러 효과 */
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: #fff;
    margin: 5% auto; /* 상단 여백 조정 */
    padding: 0; /* 내부 패딩 제거 (헤더/바디 분리) */
    border: none;
    width: 90%; 
    max-width: 800px; /* [변경] 그리드 뷰를 위해 너비 확대 */
    border-radius: 12px; /* 둥근 모서리 */
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 85vh; /* 최대 높이 제한 */
    animation: slideDown 0.3s ease-out;
}

/* 모달 헤더 */
.modal-header {
    padding: 15px 20px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
}

.close-modal {
    color: #999;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-modal:hover { color: #333; }

/* 모달 본문 */
.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.search-control-group {
    margin-bottom: 20px;
}

.search-control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    font-size: 0.9rem;
    color: #333;
}

.search-select {
    width: 100%;
    padding: 12px 10px;
    font-size: 0.95rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    outline: none;
    background-color: white;
    cursor: pointer;
}

.search-input-group {
    display: flex;
}

#team-search-input {
    flex: 1;
    padding: 12px 15px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px 0 0 8px;
    border-right: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#team-search-input:focus {
    border-color: #2196f3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

#btn-search-confirm {
    padding: 0 20px;
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

#btn-search-confirm:hover {
    background-color: #1976d2;
}

#search-results {
    /* max-height 제거 (modal-body 스크롤 이용) */
    display: grid; /* [신규] 그리드 레이아웃 적용 */
    grid-template-columns: repeat(5, 1fr); /* 5열 배치 (5*5 바둑판형) */
    gap: 10px;
    border-top: none;
    padding-top: 10px;
}

.search-result-item {
    display: flex;
    flex-direction: column; /* [변경] 세로 정렬 (로고 위, 이름 아래) */
    align-items: center;
    justify-content: center;
    padding: 15px 10px;
    border: 1px solid #eee; /* 박스 테두리 추가 */
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    margin-bottom: 0;
    text-align: center;
    background-color: #fff;
}

.search-result-item:hover { 
    background-color: #f0f7ff; 
    transform: translateY(-3px); /* 호버 시 살짝 떠오르는 효과 */
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.team-logo {
    width: 60px; /* [변경] 로고 크기 확대 */
    height: 60px;
    margin-right: 0;
    margin-bottom: 10px;
    object-fit: contain;
    background-color: transparent;
    border: none;
    padding: 0;
}

/* [신규] 로고 없을 때 대체 스타일 */
.team-logo.team-logo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    color: #888;
    font-size: 1.8rem;
    font-weight: bold;
    border-radius: 50%;
    border: 2px solid #e0e0e0;
}

.team-info { display: flex; flex-direction: column; justify-content: center; width: 100%; }
.team-name-txt { font-weight: bold; font-size: 1rem; color: #333; margin-bottom: 2px; }
.team-country { font-size: 0.8rem; color: #666; }
.team-name-txt .english-name {
    font-size: 0.85em;
    color: #888;
    font-weight: normal;
    margin-left: 4px;
    display: block; /* [변경] 영문 이름 줄바꿈 */
}

/* [신규] 선수 이름 내 영문 표기 스타일 */
/* 리스트 내 영문 이름 */
.player-list .player-name .english-name {
    font-size: 0.85em;
    color: #666;
    font-weight: normal;
    margin-left: 4px;
}
/* 필드 위 영문 이름 */
.team .player .player-name .english-name {
    font-size: 0.8em;
    color: #ddd;
    font-weight: normal;
    margin-left: 3px;
}

.loading-msg, .error-msg, .no-result { 
    padding: 20px; text-align: center; color: #666; 
    grid-column: 1 / -1; /* [신규] 메시지는 그리드 전체 너비 사용 */
}
.error-msg { color: #f44336; }

/* 애니메이션 정의 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* [신규] 프리뷰 단계 스타일 */
.preview-header {
    display: flex;
    align-items: center;
    padding: 0 0 15px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 15px;
}

.preview-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
}

#preview-player-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    padding: 10px;
    background: #fafafa;
}

.preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#btn-preview-back {
    padding: 10px 20px;
    background-color: #9e9e9e;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

#btn-preview-apply {
    padding: 10px 20px;
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}