/* EAFC Tactics Simulator - Main Styles */
/* 모바일 9:16 비율 최적화 */

/* 기본 설정 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 브라우저 호환성 및 뷰포트 안정화 */
html {
    width: 100%;
    height: 100%;
    /* 다양한 브라우저에서 일관된 렌더링 */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* 스크롤 부드럽게 */
    scroll-behavior: smooth;
    /* 안전 영역 대응 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

:root {
    /* 컬러 팔레트 */
    --primary-green: #2d7a2d;
    --secondary-green: #4a9d4a;
    --light-green: #6db36d;
    --dark-green: #1a5d1a;
    --field-green: #3e8e3e;
    --white: #ffffff;
    --black: #000000;
    --gray: #666666;
    --light-gray: #cccccc;
    --blue: #007acc;
    --red: #cc0000;
    --yellow: #ffcc00;
    
    /* 화면 스케일링 시스템 (1080px 높이, 동적 너비 607.5px~900px) */
    --base-height: 1080px;
    --base-width: 607.5px; /* JavaScript에서 동적 설정 (607.5px~900px) */
    --max-content-width: 900px; /* 컨텐츠 최대 너비 제한 */
    --screen-scale: 1; /* JavaScript에서 동적 설정 */
    --app-width: 100vw;
    --app-height: 100vh;
    --scaled-width: calc(var(--base-width) * var(--screen-scale));
    --scaled-height: calc(var(--base-height) * var(--screen-scale));
    
    /* 최소 폰트 사이즈 보장 (모바일 가독성) */
    --min-font-tiny: 10px;      /* 가장 작은 텍스트 */
    --min-font-small: 12px;     /* 작은 텍스트 */
    --min-font-medium: 14px;    /* 중간 텍스트 */
    --min-font-large: 16px;     /* 큰 텍스트 */
    --min-font-xlarge: 18px;    /* 매우 큰 텍스트 */
    
    /* 사이즈 (스케일링 적용) */
    --header-height: calc(70px * var(--screen-scale)); /* 제목 오버플로우 방지를 위한 높이 증가 */
    --button-height: calc(50px * var(--screen-scale));
    --border-radius: calc(8px * var(--screen-scale));
    --grid-size: calc(50px * var(--screen-scale));
    
    /* 그림자 */
    --shadow-light: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-medium: 0 4px 8px rgba(0,0,0,0.15);
    --shadow-heavy: 0 8px 16px rgba(0,0,0,0.2);
}

body {
    font-family: 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
    background: linear-gradient(135deg, #0D0D0D, #181717);
    color: var(--white);
    overflow: hidden;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* 동적 뷰포트 높이 (iOS 사파리 대응) */
    min-height: 100vh;
    min-height: 100dvh;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    margin: 0;
    padding: 0;
    position: relative;
    /* 브라우저별 일관성 확보 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 터치 스크롤 개선 */
    -webkit-overflow-scrolling: touch;
    /* 확대/축소 시 텍스트 크기 고정 */
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* 매우 작은 화면에서 body 최적화 - 클래스 기반으로 대체됨 */
@media screen and (max-width: 400px), screen and (max-height: 600px) {
    /* 클래스 기반 시스템으로 처리되므로 빈 미디어쿼리 유지 */
}

/* 스케일링 앱 컨테이너 */
.app-container {
    position: absolute;
    top: 0%;
    left: 50%;
    width: var(--base-width);
    height: var(--base-height);
    /* 900px 제한 적용 - 스케일링된 크기가 900px을 초과하지 않도록 */
    max-width: min(var(--max-content-width), calc(100vw - 40px));
    max-height: 100vh;
    transform: translate(-50%, 0%) scale(var(--screen-scale));
    transform-origin: center top;
    overflow: visible;
    /* 브라우저 호환성 향상 */
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale));
    -moz-transform: translate(-50%, 0%) scale(var(--screen-scale));
    -ms-transform: translate(-50%, 0%) scale(var(--screen-scale));
    /* 스케일링 품질 개선 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    /* 터치 이벤트 최적화 */
    touch-action: manipulation;
    /* GPU 가속 활성화 */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 매우 작은 화면에서 화면 가득 채우기 - 클래스 기반으로 대체됨 */
@media screen and (max-width: 400px), screen and (max-height: 600px) {
    /* 클래스 기반 시스템으로 처리되므로 빈 미디어쿼리 유지 */
}

/* 작은 화면에서 화면 최적화 - 컨텐츠 잘림 방지 */
@media screen and (max-width: 600px) {
    .app-container {
        /* 작은 화면에서 안전한 중앙 정렬 */
        left: 50%;
        transform: translate(-50%, 0%) scale(var(--screen-scale));
        /* 컨텐츠가 화면을 벗어나지 않도록 제한 */
        max-width: 100vw;
        /* 좌우 여백 확보 */
        margin-left: auto;
        margin-right: auto;
        /* 오버플로우 방지 */
        box-sizing: border-box;
    }
}

/* 매우 작은 화면에서 추가 보호 */
@media screen and (max-width: 400px) {
    .app-container {
        /* 더 안전한 스케일링을 위해 좌우 여백 확보 */
        max-width: calc(100vw - 10px);
    }
}

/* 화면 전환 시스템 */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--base-width);
    height: var(--base-height);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.screen.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

/* 타이틀 화면 */
#titleScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.title-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 0 20px;
    animation: fadeInUp 1s ease-out;
    background: rgba(0, 0, 0, 0.3); /* 텍스트 가독성을 위한 반투명 오버레이 */
    border-radius: 15px;
    margin: 20px;
}

/* 기존 .main-title 스타일을 .main-logo로 변경 */
.main-logo {
    max-width: calc(400px * var(--screen-scale));
    width: calc(300px * var(--screen-scale));
    height: auto;
    margin-bottom: calc(10px * var(--screen-scale));
    filter: drop-shadow(calc(3px * var(--screen-scale)) calc(3px * var(--screen-scale)) calc(6px * var(--screen-scale)) rgba(0,0,0,0.3));
    transition: all 0.3s ease;
}

.subtitle {
    font-size: calc(1.4rem * var(--screen-scale));
    font-weight: 300;
    opacity: 0.9;
    margin-bottom: calc(30px * var(--screen-scale));
    text-shadow: calc(1px * var(--screen-scale)) calc(1px * var(--screen-scale)) calc(2px * var(--screen-scale)) rgba(0,0,0,0.3);
}

.tap-hint {
    font-size: calc(1.1rem * var(--screen-scale));
    font-weight: 400;
    opacity: 0.8;
    animation: pulse 2s infinite;
}

/* 구글 로그인 버튼 섹션 - 향후 로그인 기능 적용시까지 숨김 */
.login-section {
    position: absolute;
    bottom: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: none; /* 임시 숨김 - 로그인 기능 적용시 제거 */
}

.google-login-btn {
    max-width: clamp(200px, 50vw, 350px);
    height: auto;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
    border-radius: 8px;
}

.google-login-btn:hover {
    transform: scale(1.05);
    filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.4));
}

.google-login-btn:active {
    transform: scale(0.98);
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3));
}

/* 메뉴 화면 */
#menuScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2); /* 텍스트와 버튼 가독성을 위한 반투명 오버레이 */
    border-radius: 15px;
    margin: 20px;
}

/* 기존 .screen-title 스타일을 .menu-logo로 변경 */
.menu-logo {
    max-width: calc(300px * var(--screen-scale));
    width: calc(250px * var(--screen-scale));
    height: auto;
    margin-bottom: calc(40px * var(--screen-scale));
    filter: drop-shadow(calc(2px * var(--screen-scale)) calc(2px * var(--screen-scale)) calc(4px * var(--screen-scale)) rgba(0,0,0,0.3));
    transition: all 0.3s ease;
}

/* 기존 .screen-title 클래스는 다른 화면에서도 사용되므로 유지 */
.screen-title {
    font-size: calc(1.5rem * var(--screen-scale)); /* 폰트 크기 스케일링 적용 */
    font-weight: 700;
    text-align: center;
    margin: 0; /* 마진 제거하여 헤더 중앙 정렬 */
    padding: 0 calc(15px * var(--screen-scale)); /* 좌우 패딩 스케일링 적용 */
    text-shadow: calc(2px * var(--screen-scale)) calc(2px * var(--screen-scale)) calc(4px * var(--screen-scale)) rgba(0,0,0,0.3);
    word-wrap: break-word; /* 긴 텍스트 줄바꿈 */
    overflow: hidden; /* 넘치는 텍스트 숨김 */
    text-overflow: ellipsis; /* 말줄임표 */
    box-sizing: border-box; /* 패딩 포함 너비 계산 */
    
    /* 헤더 완전 중앙 정렬을 위한 절대 위치 */
    position: absolute;
    left: 50%; /* 좌측에서 50% 위치 */
    top: 50%; /* 상단에서 50% 위치 */
    transform: translate(-50%, -50%); /* 정확한 중앙 정렬 */
    width: auto; /* 자동 너비 */
    max-width: calc((100% - 200px) * var(--screen-scale)); /* 좌우 버튼 공간 확보 스케일링 적용 */
    white-space: nowrap; /* 한 줄로 표시 */
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: calc(20px * var(--screen-scale));
    width: 100%;
    max-width: calc(300px * var(--screen-scale));
}

.menu-btn {
    background: linear-gradient(145deg, var(--secondary-green), var(--primary-green));
    border: none;
    border-radius: var(--border-radius);
    color: var(--white);
    font-size: calc(1.1rem * var(--screen-scale));
    font-weight: 600;
    height: var(--button-height);
    box-shadow: var(--shadow-medium);
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-btn:hover, .menu-btn:active {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
    background: linear-gradient(145deg, var(--light-green), var(--secondary-green));
}

/* 설정 버튼 섹션 */
.settings-section {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
}

.settings-btn {
    width: calc(50px * var(--screen-scale));
    height: auto;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(calc(2px * var(--screen-scale)) calc(2px * var(--screen-scale)) calc(4px * var(--screen-scale)) rgba(0,0,0,0.3));
    border-radius: calc(8px * var(--screen-scale));
    opacity: 0.9;
}

.settings-btn:hover {
    transform: scale(1.1);
    filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.4));
    opacity: 1;
}

.settings-btn:active {
    transform: scale(0.95);
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3));
}

/* 포메이션 설정 화면 */
#formationScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.formation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px; /* 패딩 축소로 제목 공간 확보 */
    background: rgba(0,0,0,0.3);
    height: var(--header-height);
    min-height: var(--header-height); /* 최소 높이 보장 */
    box-sizing: border-box; /* 패딩 포함 높이 계산 */
    position: relative; /* 제목 절대 위치를 위한 기준점 */
}

.back-btn, .save-btn {
    background: var(--dark-green);
    border: none;
    border-radius: var(--border-radius);
    color: var(--white);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-btn:hover, .save-btn:hover {
    background: var(--primary-green);
    transform: translateY(-1px);
}

.formation-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: rgba(0, 0, 0, 0.1); /* 배경 이미지와의 대비를 위한 가벼운 오버레이 */
}

.formation-selector,
.phase-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.formation-selector label,
.phase-selector label {
    font-weight: 600;
    font-size: 0.95rem;
}

.formation-selector select,
.phase-selector select {
    background: var(--white);
    border: 2px solid var(--light-gray);
    border-radius: var(--border-radius);
    color: var(--black);
    padding: 12px;
    font-size: 1rem;
    cursor: pointer;
}

.phase-selector {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: 15px;
}

.phase-selector label {
    color: var(--yellow);
    font-size: 0.9rem;
}

/* 축구장 그리드 */
.field-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 300px;
}

.field {
    background: linear-gradient(135deg, var(--field-green), var(--light-green));
    border: 3px solid var(--white);
    border-radius: 15px;
    padding: 20px;
    box-shadow: var(--shadow-heavy);
    position: relative;
    width: 280px;
    height: 350px;
}

.field::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 2px solid var(--white);
    border-radius: 50%;
    opacity: 0.3;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    width: 100%;
    height: 100%;
}

.grid-cell {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.grid-cell:hover {
    background: rgba(255,255,255,0.2);
}

.grid-cell.highlight {
    background: rgba(255,204,0,0.3);
    box-shadow: 0 0 10px rgba(255,204,0,0.5);
}

/* Phase별 하이라이트 스타일 */
/* 하이라이트 스타일 (현재 JavaScript에서 동적 색상 적용으로 대체됨) */
/* Formation Screen에서 선수 활동범위는 파란색 기반 투명도로 표시 */

/* 기존 하이라이트 클래스들 (JavaScript 동적 적용으로 대체됨) */
/*
.grid-cell.highlight-original - 동적 적용: rgba(0, 123, 255, 0.6)
.grid-cell.highlight-anchor - 동적 적용: rgba(0, 123, 255, 0.45) 
.grid-cell.highlight-primary - 동적 적용: rgba(0, 123, 255, 0.3)
.grid-cell.highlight-secondary - 동적 적용: rgba(0, 123, 255, 0.15)
*/

/* 일반 하이라이트 (하위 호환성) */
.grid-cell.highlight {
    background: rgba(0, 123, 255, 0.2) !important;
    border: 1px solid rgba(0, 123, 255, 0.5) !important;
    box-shadow: 0 0 6px rgba(0, 123, 255, 0.3);
}

/* 선수 아이콘 */
.player {
    width: max(32px, calc(30px * var(--screen-scale)));
    height: max(32px, calc(30px * var(--screen-scale)));
    border-radius: 50%;
    border: calc(2px * var(--screen-scale)) solid var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(var(--min-font-small), calc(0.7rem * var(--screen-scale)));
    font-weight: bold;
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-medium);
}

/* 골키퍼 포지션 (진한 노란색 계열) */
.player.player-goalkeeper {
    background: linear-gradient(135deg, #ffcc00 0%, #e6a800 100%);
    color: var(--black);
}

/* 수비 포지션 (파란색 계열) */
.player.player-defender {
    background: linear-gradient(135deg, #1e90ff 0%, #0066cc 100%);
}

/* 미드필더 포지션 (녹색 계열) */  
.player.player-midfielder {
    background: linear-gradient(135deg, #32cd32 0%, #228b22 100%);
}

/* 공격 포지션 (붉은색 계열) */
.player.player-attacker {
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
}

.player.selected {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(255,255,255,0.8);
}

/* 배틀 화면 선수 원형 도형 */
.battle-player {
    width: max(22px, calc(20px * var(--screen-scale)));
    height: max(22px, calc(20px * var(--screen-scale)));
    border-radius: 50%;
    border: calc(1px * var(--screen-scale)) solid var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(var(--min-font-tiny), calc(0.5rem * var(--screen-scale)));
    font-weight: bold;
    color: var(--white);
    transition: all 0.2s ease;
    box-shadow: 0 calc(1px * var(--screen-scale)) calc(4px * var(--screen-scale)) rgba(0, 0, 0, 0.4);
    position: relative;
    z-index: 5;
}

/* 배틀 화면 포지션별 색상 */
.battle-player.player-goalkeeper {
    background: linear-gradient(135deg, #ffcc00 0%, #e6a800 100%);
    color: var(--black);
}

.battle-player.player-defender {
    background: linear-gradient(135deg, #1e90ff 0%, #0066cc 100%);
}

.battle-player.player-midfielder {
    background: linear-gradient(135deg, #32cd32 0%, #228b22 100%);
}

.battle-player.player-attacker {
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
}

/* 픽셀 기반 선수 아이콘 (Formation Screen) */
.player.pixel-player {
    width: max(30px, calc(28px * var(--screen-scale)));
    height: max(30px, calc(28px * var(--screen-scale)));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(var(--min-font-small), calc(0.7rem * var(--screen-scale)));
    font-weight: bold;
    color: var(--white);
    text-shadow: 0 calc(1px * var(--screen-scale)) calc(2px * var(--screen-scale)) rgba(0, 0, 0, 0.8);
    border: calc(2px * var(--screen-scale)) solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 calc(2px * var(--screen-scale)) calc(6px * var(--screen-scale)) rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    /* 스케일링 적용을 위한 정확한 위치 설정 */
    position: absolute;
    transform-origin: center center;
    /* GPU 가속 및 정확한 렌더링 */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.player.pixel-player:hover {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

.player.pixel-player.selected {
    border-color: #ff5722;
    box-shadow: 0 0 0 3px rgba(255, 87, 34, 0.3), 0 3px 8px rgba(0, 0, 0, 0.4);
    transform: translate(-50%, -50%) scale(1.15);
}

/* 픽셀 기반 배틀 선수 아이콘 (Battle Screen) */
.battle-player.battle-pixel-player {
    width: max(26px, calc(22px * var(--screen-scale)));
    height: max(26px, calc(22px * var(--screen-scale)));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(var(--min-font-tiny), calc(0.45rem * var(--screen-scale)));
    font-weight: bold;
    color: var(--white);
    text-shadow: 0 0 calc(2px * var(--screen-scale)) rgba(0, 0, 0, 0.8);
    border: calc(1px * var(--screen-scale)) solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 calc(2px * var(--screen-scale)) calc(4px * var(--screen-scale)) rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    /* 스케일링 적용을 위한 정확한 위치 설정 */
    position: absolute;
    transform-origin: center center;
    /* GPU 가속 및 정확한 렌더링 */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.battle-player.battle-pixel-player:hover {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

/* 선수 정보 패널 */
.player-info {
    background: rgba(255,255,255,0.1);
    border-radius: var(--border-radius);
    padding: 15px;
    backdrop-filter: blur(10px);
}

.player-info h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    text-align: center;
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.info-row label {
    font-weight: 600;
    font-size: 0.9rem;
}

.info-row select, .info-row span {
    background: var(--white);
    border: 1px solid var(--light-gray);
    border-radius: 4px;
    color: var(--black);
    padding: 5px 8px;
    font-size: 0.9rem;
}

/* 전술 설정 */
.tactics-settings {
    background: rgba(255,255,255,0.1);
    border-radius: var(--border-radius);
    padding: 15px;
    backdrop-filter: blur(10px);
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    font-weight: 600;
    font-size: 0.95rem;
}

.setting-row select {
    background: var(--white);
    border: 2px solid var(--light-gray);
    border-radius: var(--border-radius);
    color: var(--black);
    padding: 10px;
    font-size: 1rem;
}

/* 프리셋 화면 */
#presetScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.preset-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px; /* 패딩 축소로 제목 공간 확보 */
    background: rgba(0,0,0,0.3);
    height: var(--header-height);
    min-height: var(--header-height); /* 최소 높이 보장 */
    box-sizing: border-box; /* 패딩 포함 높이 계산 */
    position: relative; /* 제목 절대 위치를 위한 기준점 */
}

.preset-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0, 0, 0, 0.1); /* 배경 이미지와의 대비를 위한 가벼운 오버레이 */
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
}

.preset-slot {
    background: rgba(255,255,255,0.1);
    border: calc(2px * var(--screen-scale)) solid transparent;
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    padding: calc(15px * var(--screen-scale));
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(calc(5px * var(--screen-scale)));
}

.preset-slot:hover {
    border-color: var(--white);
    transform: translateY(calc(-2px * var(--screen-scale)));
}

.preset-slot.empty {
    opacity: 0.5;
    border-style: dashed;
}

.preset-slot-number {
    font-size: calc(1.2rem * var(--screen-scale));
    font-weight: bold;
    margin-bottom: calc(8px * var(--screen-scale));
}

.preset-slot-name {
    font-size: calc(0.9rem * var(--screen-scale));
    opacity: 0.8;
}

/* 프리셋 로컬 환경 알림 */
.preset-local-notice {
    margin-top: calc(30px * var(--screen-scale));
    padding: calc(15px * var(--screen-scale));
    background: rgba(255, 165, 0, 0.1); /* 주황색 배경 */
    border: calc(1px * var(--screen-scale)) solid rgba(255, 165, 0, 0.3);
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    color: #ffb347; /* 연한 주황색 텍스트 */
    font-size: calc(0.8rem * var(--screen-scale));
    text-align: center;
    opacity: 0.9;
    backdrop-filter: blur(calc(5px * var(--screen-scale)));
    line-height: 1.4;
}

/* 설정 화면 */
#settingScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.setting-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: rgba(0,0,0,0.3);
    height: var(--header-height);
    min-height: var(--header-height);
    box-sizing: border-box;
    position: relative;
}

.setting-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    background: rgba(0, 0, 0, 0.1);
    position: relative;
}

.setting-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 350px;
}

/* 언어 설정 스타일 */
.language-setting {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 20px;
}

.language-setting label {
    color: var(--white);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.language-select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    color: var(--white);
    font-size: 1rem;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    
    /* 브라우저별 호환성 개선 */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 5"><path fill="%23ffffff" d="M2 0L0 2h4zm0 5L0 3h4z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 40px;
}

.language-select:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

.language-select option {
    background: #1e3a8a !important;
    background-color: #1e3a8a !important;
    color: #ffffff !important;
    padding: 8px 12px !important;
    font-size: 1rem !important;
    font-weight: 500 !important;
    border: none !important;
    outline: none !important;
}

/* Windows Chrome/Edge 특별 처리 */
.language-select option:checked {
    background: #22c55e !important;
    background-color: #22c55e !important;
    color: #ffffff !important;
}

.language-select option:hover {
    background: #2563eb !important;
    background-color: #2563eb !important;
    color: #ffffff !important;
}

/* 드롭다운이 열렸을 때 배경 보정 */
.language-select:active,
.language-select[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.15);
}

/* 브라우저별 특수 처리 - Windows Chrome/Edge 대응 */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .language-select option {
        background: #1e3a8a;
        color: #ffffff;
    }
}

/* Firefox 특별 처리 */
@-moz-document url-prefix() {
    .language-select option {
        background: #1e3a8a;
        color: #ffffff;
    }
}

/* Edge 특별 처리 */
@supports (-ms-ime-align: auto) {
    .language-select option {
        background: #1e3a8a !important;
        color: #ffffff !important;
    }
}

.setting-menu-btn {
    background: linear-gradient(145deg, var(--secondary-green), var(--primary-green));
    border: none;
    border-radius: var(--border-radius);
    color: var(--white);
    font-size: 1.1rem;
    font-weight: 600;
    height: var(--button-height);
    padding: 0 20px;
    box-shadow: var(--shadow-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.setting-menu-btn:hover, .setting-menu-btn:active {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
    background: linear-gradient(145deg, var(--light-green), var(--secondary-green));
}

.setting-menu-btn.help-btn {
    background: linear-gradient(145deg, #17a2b8, #007bff);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.setting-menu-btn.help-btn:hover, .setting-menu-btn.help-btn:active {
    background: linear-gradient(145deg, #138496, #0056b3);
}

/* 프리미엄 업그레이드 버튼 - 향후 기능 적용시까지 숨김 */
#premiumBtn {
    display: none; /* 임시 숨김 - 프리미엄 기능 적용시 제거 */
}

.setting-menu-btn.logout-btn {
    background: linear-gradient(145deg, var(--red), #cc0000);
    margin-top: 20px;
    display: none; /* 임시 숨김 - 로그인 기능 적용시 제거 */
}

.setting-menu-btn.logout-btn:hover, .setting-menu-btn.logout-btn:active {
    background: linear-gradient(145deg, #ff4444, var(--red));
}

/* 설정 화면 버전 정보 */
.version-info {
    position: absolute;
    bottom: 50px;
    right: 20px;
    font-size: 0.9rem;
    color: var(--white);
    opacity: 0.7;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-radius: 4px;
    backdrop-filter: blur(5px);
}

/* 타이틀 화면 버전 정보 - 우측하단 */
.title-version-info {
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: clamp(10px, calc(0.8rem * var(--screen-scale)), 14px);
    color: var(--white);
    opacity: 0.6;
    background: rgba(0, 0, 0, 0.4);
    padding: calc(6px * var(--screen-scale)) calc(10px * var(--screen-scale));
    border-radius: calc(4px * var(--screen-scale));
    backdrop-filter: blur(5px);
    font-weight: 500;
    /* 스케일링에 따라 반응형으로 조정되는 폰트 크기 */
    white-space: nowrap;
}

/* 탈퇴 버튼 섹션 - 최하단, 작은 크기로 가독성 낮게 */
.withdraw-section {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    display: flex;
    justify-content: center;
}

.withdraw-btn {
    background: rgba(128, 128, 128, 0.3);
    border: none;
    border-radius: calc(3px * var(--screen-scale));
    color: rgba(255, 255, 255, 0.4);
    font-size: calc(0.7rem * var(--screen-scale));
    font-weight: 400;
    padding: calc(6px * var(--screen-scale)) calc(12px * var(--screen-scale));
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    opacity: 0.5;
    min-width: calc(60px * var(--screen-scale));
}

.withdraw-btn:hover {
    background: rgba(220, 53, 69, 0.4);
    color: rgba(255, 255, 255, 0.6);
    opacity: 0.7;
    transform: scale(1.02);
}

.withdraw-btn:active {
    background: rgba(220, 53, 69, 0.5);
    transform: scale(0.98);
}

/* 배틀 화면 */
#battleScreen {
    /* 배경 이미지는 JavaScript에서 ImageOptimizer로 설정 */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.battle-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px; /* 패딩 축소로 제목 공간 확보 */
    background: rgba(0,0,0,0.3);
    height: var(--header-height);
    min-height: var(--header-height); /* 최소 높이 보장 */
    box-sizing: border-box; /* 패딩 포함 높이 계산 */
    position: relative; /* 제목 절대 위치를 위한 기준점 */
}

.battle-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    max-width: 600px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.1); /* 배경 이미지와의 대비를 위한 가벼운 오버레이 */
}

/* 팀 정보 섹션 */
.team-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    margin: 5px 0;
}

.team-info h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
    color: var(--yellow) !important; /* 홈팀설정, 원정팀 설정 텍스트를 노란색으로 강제 변경 */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5); /* 가독성을 위한 그림자 */
}

/* 배틀스크린 h4 제목들도 노란색으로 변경 (홈팀 설정, 원정팀 설정) */
.battle-content h4 {
    color: var(--yellow) !important; /* 홈팀 설정, 원정팀 설정 h4 제목도 노란색으로 강제 변경 */
    font-weight: 700;
    margin: 10px 0 5px 0;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5); /* 가독성을 위한 그림자 */
}

.team-score {
    font-size: 1rem;
    font-weight: 600;
    color: var(--yellow); /* 녹색에서 노란색으로 변경 */
}

/* Battle Screen 점수 상태별 색상 - 노란색 계열 */
.team-score.winning {
    color: #ffd700; /* 골드 색상 (승리) */
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
    font-weight: 700;
}

.team-score.losing {
    color: #ffb347; /* 연한 오렌지 (패배) */
    text-shadow: 0 0 6px rgba(255, 179, 71, 0.4);
    font-weight: 500;
}

.team-score.draw {
    color: var(--yellow); /* 기본 노란색 (무승부) */
    text-shadow: 0 0 4px rgba(255, 204, 0, 0.3);
    font-weight: 600;
}

/* 가로형 축구장 필드 */
.battle-field.horizontal {
    width: 100%;
    max-width: 500px;
    height: auto; /* 고정 높이 제거 */
    aspect-ratio: 2/1; /* 2:1 비율 유지 */
    background: var(--field-green);
    border: 2px solid var(--white);
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    padding: 8px;
    box-sizing: border-box;
    gap: 2px;
    border-radius: 0;
    margin: 10px auto; /* 중앙 정렬 */
}

/* 원정팀 필드 (위쪽) */
.battle-field.away-field {
    border-bottom: 1px dashed var(--white);
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    margin-bottom: 0px;
}

/* 홈팀 필드 (아래쪽) */
.battle-field.home-field {
    border-top: 1px dashed var(--white);
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    margin-top: 0px;
}

.battle-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: calc(3px * var(--screen-scale));
    position: relative;
    font-size: max(var(--min-font-tiny), calc(0.6rem * var(--screen-scale)));
    min-height: max(20px, calc(18px * var(--screen-scale)));
    padding: calc(1px * var(--screen-scale));
    line-height: 1.1;
}

/* 배틀 시작 버튼 하단 섹션 */
.battle-center {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* 팀 설정 섹션 */
.team-settings {
    width: 100%;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    padding: 20px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    margin-top: 20px;
    box-sizing: border-box;
}

/* 배틀 화면 전체 컨테이너 최적화 */
.screen.battle-screen {
    padding: calc(10px * var(--screen-scale));
    overflow-y: auto;
    overflow-x: hidden;
}

/* 배틀 컨텐츠 최적화 */
.battle-content {
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    box-sizing: border-box;
}

.setting-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.setting-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--primary-green);
}

.formation-selector-battle,
.phase-selector-battle,
.tactics-settings-battle {
    width: 100%;
    margin: 0 0 15px 0;
}

.formation-select-battle,
.phase-select-battle,
.tactics-select-battle {
    width: 100%;
    background: var(--white);
    border: 2px solid var(--light-gray);
    border-radius: var(--border-radius);
    color: var(--black);
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* 전술 설정 섹션 */
.tactics-settings-battle {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 10px;
}

.setting-row-battle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.setting-row-battle label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #ffffff;
    white-space: nowrap;
    min-width: 80px;
}

.tactics-select-battle {
    flex: 1;
    min-width: 120px;
    font-size: 0.75rem;
    padding: 6px 8px;
}

.formation-select-battle:focus,
.phase-select-battle:focus,
.tactics-select-battle:focus {
    border-color: var(--primary-green);
    outline: none;
}

.phase-selector-battle label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--yellow);
}

/* 포메이션 편집 버튼 */
.formation-edit-btn-container {
    width: 100%;
    margin: 8px 0;
    display: flex;
    justify-content: center;
}

.formation-edit-btn {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    padding: 8px 20px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 80px;
}

.formation-edit-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #7c868d 0%, #596067 100%);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.formation-edit-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.formation-edit-btn:disabled {
    background: linear-gradient(135deg, #666666 0%, #555555 100%);
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.formation-select-battle option {
    padding: 5px;
}

.battle-btn {
    background: linear-gradient(145deg, var(--red), #ff3333);
    border: none;
    border-radius: var(--border-radius);
    color: var(--white);
    font-size: 1.2rem;
    font-weight: 700;
    padding: 18px 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-medium);
    min-width: 200px;
}

.battle-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
}

/* 로딩 스피너 */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid var(--white);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* 모달 - 스케일링 적용 */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--base-width);
    height: var(--base-height);
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.modal-content {
    background: var(--white);
    color: var(--black);
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    box-shadow: var(--shadow-heavy);
    max-width: calc(400px * var(--screen-scale));
    max-height: calc(600px * var(--screen-scale));
    min-width: calc(300px * var(--screen-scale));
    overflow: hidden;
    animation: modalFadeIn 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(20px * var(--screen-scale));
    background: var(--primary-green);
    color: var(--white);
}

.modal-header h3 {
    font-size: calc(1.2rem * var(--screen-scale));
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--white);
    font-size: calc(1.5rem * var(--screen-scale));
    cursor: pointer;
    padding: 0;
    width: calc(30px * var(--screen-scale));
    height: calc(30px * var(--screen-scale));
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: calc(20px * var(--screen-scale));
    min-height: calc(100px * var(--screen-scale));
    font-size: calc(1rem * var(--screen-scale));
}

.modal-footer {
    display: flex;
    gap: calc(10px * var(--screen-scale));
    justify-content: flex-end;
    padding: calc(20px * var(--screen-scale));
    background: var(--light-gray);
}

.btn {
    padding: calc(10px * var(--screen-scale)) calc(20px * var(--screen-scale));
    border: none;
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    font-size: calc(1rem * var(--screen-scale));
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.confirm {
    background: var(--blue);
    color: var(--white);
}

.btn.cancel {
    background: var(--gray);
    color: var(--white);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-light);
}

/* 애니메이션 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 900px 제한을 위한 스케일링 조정 */
@media screen and (min-width: calc(900px / var(--screen-scale))) {
    .app-container {
        /* 스케일링 후 크기가 900px을 초과하지 않도록 제한 */
        max-width: var(--max-content-width);
    }
}

/* 중간 크기 화면 최적화 (601px ~ 800px) */
@media screen and (min-width: 601px) and (max-width: 800px) {
    .app-container {
        min-width: 90vw;
        min-height: 90vh;
        max-width: min(var(--max-content-width), 98vw);
        max-height: 98vh;
    }
}

/* 중간 크기 화면 최적화 (801px ~ 1024px) */
@media screen and (min-width: 801px) and (max-width: 1024px) {
    .app-container {
        min-width: 85vw;
        min-height: 85vh;
        max-width: min(var(--max-content-width), 95vw);
        max-height: 95vh;
    }
}

/* 큰 화면에서 900px 제한 적용 */
@media screen and (min-width: 1025px) {
    .app-container {
        /* 큰 화면에서는 스케일링하되 900px을 넘지 않도록 */
        max-width: var(--max-content-width);
        /* 비율 유지를 위한 최대 높이 계산 */
        max-height: min(100vh, calc(var(--max-content-width) * var(--base-height) / var(--base-width)));
    }
}

/* 화면 높이 기반 최적화 */
@media screen and (max-height: 500px) {
    .app-container {
        /* 매우 낮은 화면에서 높이 최대 활용 */
        min-height: 100vh;
        height: 100vh;
        top: 0;
        transform: translate(-50%, 0) scale(var(--screen-scale));
        -webkit-transform: translate(-50%, 0) scale(var(--screen-scale));
    }
}

@media screen and (max-height: 600px) and (min-width: 401px) {
    .app-container {
        /* 낮은 화면에서 높이 활용 개선 */
        min-height: 95vh;
        max-height: 100vh;
    }
}

/* 세로 방향 길쭉한 화면 최적화 */
@media screen and (max-width: 500px) and (min-height: 800px) {
    .app-container {
        /* 세로 길쭉한 화면에서 너비 최대 활용 */
        min-width: 100vw;
        width: 100vw;
        left: 0;
        transform: translate(0, 0%) scale(var(--screen-scale));
        -webkit-transform: translate(0, 0%) scale(var(--screen-scale));
        transform-origin: left top;
    }
}

/* 가로 방향 넓은 화면 최적화 */
@media screen and (min-width: 800px) and (max-height: 600px) {
    .app-container {
        /* 가로 넓은 화면에서 높이 최대 활용 */
        min-height: 100vh;
        height: 100vh;
        top: 0;
        transform: translate(-50%, 0) scale(var(--screen-scale));
        -webkit-transform: translate(-50%, 0) scale(var(--screen-scale));
        transform-origin: center top;
    }
}

/* 반응형 디자인 */
@media screen and (max-width: 480px) {
    .formation-content {
        padding: 15px;
    }
    
    /* 배틀 화면 모바일 최적화 */
    .battle-field.horizontal {
        width: 100% !important;
        max-width: min(90vw, 350px) !important;
        height: auto !important;
        aspect-ratio: 2/1 !important;
        padding: 4px !important;
        gap: 1px !important;
        margin: 5px auto !important;
    }
    
    .battle-cell {
        min-height: 12px !important;
        font-size: 0.4rem !important;
        padding: 1px !important;
    }
    
    .team-settings {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 10px !important;
        margin-top: 15px !important;
    }
    
    .setting-section {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .formation-select-battle {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        min-height: 32px !important;
    }
    
    .team-info h3 {
        font-size: 0.8rem !important;
        margin-bottom: 8px !important;
    }
    
    .team-score {
        font-size: 1.5rem !important;
        min-height: 40px !important;
    }
    
    .field {
        width: 250px;
        height: 320px;
        padding: 15px;
    }
    
    .player {
        width: 25px;
        height: 25px;
        font-size: 0.6rem;
    }

    /* 모바일에서 로고 이미지 크기 조정 */
    .main-logo {
        max-width: clamp(150px, 45vw, 280px);
    }
    
    .menu-logo {
        max-width: clamp(120px, 35vw, 220px);
    }

    .battle-player {
        width: 16px;
        height: 16px;
        font-size: 0.4rem;
    }

    .formation-edit-btn {
        padding: 6px 16px;
        font-size: 0.7rem;
        min-width: 70px;
    }
    
    .battle-field.horizontal {
        height: 100px;
        padding: 6px;
        gap: 1px;
    }
    
    .battle-cell {
        min-height: 15px;
        font-size: 0.5rem;
    }
    
    .formation-select-battle {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    .team-info h3 {
        font-size: 1rem;
        /* 노란색 색상은 상위에서 상속 */
    }
    
    .team-score {
        font-size: 0.9rem;
    }
    
    /* 모바일 화면에서 제목 더 작게 */
    .screen-title {
        font-size: clamp(1rem, 3.5vw, 1.4rem); /* 모바일에서 더 작게 */
        padding: 0 10px;
        max-width: calc(100% - 160px); /* 모바일에서 버튼 공간 확보 */
        /* 절대 위치 속성은 상위에서 이미 설정됨 */
    }
    
    /* 모바일 헤더 패딩 더 축소 */
    .formation-header,
    .preset-header,
    .battle-header {
        padding: 8px 12px;
        height: 60px; /* 모바일에서 헤더 높이 축소 */
        min-height: 60px;
    }
    
    .battle-content {
        gap: 5px;
        padding: 10px;
    }
    
    .battle-center {
        padding: 15px 0;
        margin-top: 15px;
    }
    
    .team-settings {
        flex-direction: column;
        gap: 15px;
        padding: 15px 10px;
    }
    
    .setting-section h4 {
        font-size: 0.9rem;
    }
}

/* 태블릿 크기 화면 대응 (481px ~ 768px) */
@media screen and (min-width: 481px) and (max-width: 768px) {
    /* 배틀 화면 태블릿 최적화 */
    .battle-field.horizontal {
        width: 100% !important;
        max-width: min(85vw, 450px) !important;
        height: auto !important;
        aspect-ratio: 2/1 !important;
        padding: 6px !important;
        gap: 2px !important;
        margin: 8px auto !important;
    }
    
    .battle-cell {
        min-height: 16px !important;
        font-size: 0.5rem !important;
        padding: 2px !important;
    }
    
    .team-settings {
        flex-direction: row !important;
        gap: 15px !important;
        padding: 15px !important;
        margin-top: 20px !important;
    }
    
    .setting-section {
        flex: 1 !important;
        max-width: calc(50% - 7.5px) !important;
    }
    
    .formation-select-battle {
        font-size: 0.8rem !important;
        padding: 6px 10px !important;
        min-height: 36px !important;
    }
    
    .team-info h3 {
        font-size: 0.9rem !important;
        margin-bottom: 10px !important;
    }
    
    .team-score {
        font-size: 1.8rem !important;
        min-height: 50px !important;
    }
}

/* 매우 작은 모바일 화면 대응 (400px 이하) */
@media screen and (max-width: 400px) {
    /* 배틀 화면 초소형 화면 최적화 */
    .battle-field.horizontal {
        max-width: min(95vw, 320px) !important;
        padding: 3px !important;
        gap: 1px !important;
        margin: 3px auto !important;
    }
    
    .battle-cell {
        min-height: 10px !important;
        font-size: 0.35rem !important;
        padding: 0.5px !important;
    }
    
    .team-settings {
        gap: 8px !important;
        padding: 8px !important;
        margin-top: 10px !important;
    }
    
    .formation-select-battle {
        font-size: 0.65rem !important;
        padding: 3px 6px !important;
        min-height: 28px !important;
    }
    
    .team-info h3 {
        font-size: 0.7rem !important;
        margin-bottom: 6px !important;
    }
    
    .team-score {
        font-size: 1.3rem !important;
        min-height: 35px !important;
    }
}

@media screen and (max-height: 640px) {
    .formation-content {
        gap: 15px;
    }
    
    .field {
        height: 280px;
    }
}

/* 새로 추가된 스타일들 */
.battle-result {
    text-align: center;
    padding: 20px;
    line-height: 1.6;
}

.battle-result-text {
    font-size: 1.1rem;
    margin-bottom: 20px;
    white-space: pre-line;
}

.battle-result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.battle-result.battle-result-home-win .battle-result-text {
    color: var(--blue);
}

.battle-result.battle-result-away-win .battle-result-text {
    color: var(--yellow);
}

.battle-result.battle-result-draw .battle-result-text {
    color: var(--gray);
}

.detailed-analysis {
    text-align: left;
    line-height: 1.6;
}

.formation-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 15px;
}

.team-analysis {
    background: rgba(0,0,0,0.05);
    padding: 15px;
    border-radius: 8px;
}

.team-analysis h5 {
    margin-bottom: 10px;
    color: var(--primary-green);
}

.prompt-dialog {
    text-align: left;
}

.prompt-dialog input {
    width: 100%;
    padding: calc(10px * var(--screen-scale));
    margin-top: calc(10px * var(--screen-scale));
    border: calc(2px * var(--screen-scale)) solid var(--light-gray);
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    font-size: calc(1rem * var(--screen-scale));
}

.prompt-dialog input:focus {
    border-color: var(--primary-green);
    outline: none;
}

/* 모달 내 폼 요소들 스케일링 */
.modal-body label {
    font-size: calc(1rem * var(--screen-scale));
    font-weight: 600;
    margin-bottom: calc(8px * var(--screen-scale));
    display: block;
}

.modal-body input[type="text"] {
    width: 100%;
    padding: calc(10px * var(--screen-scale));
    margin-top: calc(8px * var(--screen-scale));
    border: calc(2px * var(--screen-scale)) solid var(--light-gray);
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    font-size: calc(1rem * var(--screen-scale));
    box-sizing: border-box;
}

.modal-body input[type="text"]:focus {
    border-color: var(--primary-green);
    outline: none;
}

.loading-content {
    text-align: center;
    padding: 30px;
}

.loading-content .spinner {
    margin: 0 auto 20px;
}

.loading-content p {
    color: var(--gray);
    font-size: 1.1rem;
}

.preset-options {
    display: flex;
    flex-direction: column;
    gap: calc(10px * var(--screen-scale));
    margin-top: calc(15px * var(--screen-scale));
}

.preset-option-btn {
    background: var(--primary-green);
    color: white;
    border: none;
    padding: calc(12px * var(--screen-scale));
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    cursor: pointer;
    font-size: calc(1rem * var(--screen-scale));
    transition: all 0.2s ease;
}

.preset-option-btn:hover {
    background: var(--secondary-green);
    transform: translateY(calc(-1px * var(--screen-scale)));
}

.empty-formation {
    opacity: 0.3;
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    .menu-btn:hover,
    .back-btn:hover,
    .save-btn:hover,
    .battle-btn:hover,
    .btn:hover,
    .preset-option-btn:hover {
        transform: none;
    }
    
    .menu-btn:active,
    .back-btn:active,
    .save-btn:active,
    .battle-btn:active,
    .btn:active,
    .preset-option-btn:active {
        transform: scale(0.98);
    }
}

/* 화면 크기별 특수 처리 */
/* 너비 가득 채우기 모드 (500px 이하) - 중앙 정렬 유지 */
body.fill-width-mode.narrow-width .app-container {
    /* 너비를 100% 활용하되 상단 정렬 유지 */
    position: absolute !important;
    top: 0% !important;
    left: 50% !important;
    width: var(--base-width) !important;
    height: var(--base-height) !important;
    transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    transform-origin: center top !important;
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -moz-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -ms-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
}

/* 높이 가득 채우기 모드 (1070px 이하) */
body.fill-height-mode.short-height .app-container {
    /* 높이를 100% 활용 - 상단 정렬 */
    position: absolute !important;
    top: 0% !important;
    left: 50% !important;
    width: var(--base-width) !important;
    height: var(--base-height) !important;
    transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    transform-origin: center top !important;
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -moz-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -ms-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
}

/* 매우 작은 화면 전용 최적화 - 중앙 정렬 유지 */
body.very-small-screen .app-container {
    /* 화면을 완전히 가득 채우되 상단 정렬 유지 */
    position: absolute !important;
    top: 0% !important;
    left: 50% !important;
    width: var(--base-width) !important;
    height: var(--base-height) !important;
    min-width: var(--base-width) !important;
    min-height: var(--base-height) !important;
    transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    transform-origin: center top !important;
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -moz-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -ms-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    overflow: visible !important;
}

/* 화면 모드별 body 최적화 */
body.fill-width-mode.narrow-width,
body.fill-height-mode.short-height,
body.very-small-screen {
    /* 작은 화면에서 body 완전 최적화 */
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

/* 화면 모드별 screen 요소 최적화 */
body.fill-width-mode.narrow-width .screen,
body.fill-height-mode.short-height .screen,
body.very-small-screen .screen {
    /* 작은 화면에서 screen 요소 최적화 */
    width: var(--base-width) !important;
    height: var(--base-height) !important;
    max-width: none !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

/* 추가 최적화: 너비가 매우 작을 때 */
body.narrow-width .app-container {
    /* 500px 이하에서 상단 정렬 보장 */
    left: 50% !important;
    top: 0% !important;
    transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
}

/* 추가 최적화: 높이가 작을 때 */
body.short-height .app-container {
    /* 1070px 이하에서 상단 정렬 */
    top: 0% !important;
    transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale)) !important;
}

/* 작은 화면 전용 최적화 */
body.small-screen .app-container {
    min-width: 95vw;
    min-height: 95vh;
    max-width: 100vw;
    max-height: 100vh;
}

/* 중간 화면 전용 최적화 */
body.medium-screen .app-container {
    min-width: 85vw;
    min-height: 85vh;
    max-width: 95vw;
    max-height: 95vh;
}

/* 브라우저별 특수 처리 */
/* 삼성인터넷 브라우저 최적화 */
body.samsung-browser .app-container {
    /* 삼성인터넷에서 과도한 스케일링 방지 */
    max-width: 100vw;
    max-height: 100vh;
}

body.samsung-browser {
    /* 삼성인터넷에서 텍스트 크기 고정 */
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
}

/* 웨일 브라우저 최적화 */
body.whale-browser .app-container {
    /* 웨일에서 렌더링 최적화 */
    image-rendering: auto;
    -webkit-image-rendering: auto;
}

body.whale-browser {
    /* 웨일에서 텍스트 렌더링 최적화 */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: subpixel-antialiased;
}

/* iOS 디바이스 최적화 */
body.ios-device {
    /* iOS에서 스크롤 바운스 방지 */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

body.ios-device .app-container {
    /* iOS Safari의 주소창 변화 대응 */
    height: 100vh;
    height: 100dvh;
}

/* 안드로이드 디바이스 최적화 */
body.android-device {
    /* 안드로이드에서 성능 최적화 */
    -webkit-tap-highlight-color: transparent;
}

body.android-device .app-container {
    /* 안드로이드에서 하드웨어 가속 최적화 - 상단 정렬 */
    transform: translate3d(-50%, 0%, 0) scale(var(--screen-scale));
    -webkit-transform: translate3d(-50%, 0%, 0) scale(var(--screen-scale));
}

/* 고해상도 디스플레이 최적화 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .app-container {
        /* 고해상도에서 선명한 렌더링 */
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    .player, .battle-player {
        /* 고해상도에서 아이콘 선명도 향상 */
        image-rendering: auto;
        -webkit-image-rendering: auto;
    }
}

/* 매우 작은 화면 (320px 이하) 대응 */
@media screen and (max-width: 320px) {
    body.samsung-browser .app-container,
    body.whale-browser .app-container {
        /* 초소형 화면에서 추가 스케일 조정 - 상단 정렬 */
        transform: translate(-50%, 0%) scale(calc(var(--screen-scale) * 0.9));
        -webkit-transform: translate(-50%, 0%) scale(calc(var(--screen-scale) * 0.9));
    }
}

/* 세로 모드 최적화 */
@media screen and (orientation: portrait) {
    body.samsung-browser,
    body.whale-browser {
        /* 세로 모드에서 뷰포트 안정화 */
        height: 100vh;
        height: 100dvh;
        width: 100vw;
    }
}

/* 가로 모드 최적화 */
@media screen and (orientation: landscape) {
    body.samsung-browser .app-container,
    body.whale-browser .app-container {
        /* 가로 모드에서 상단 정렬 강화 */
        left: 50%;
        top: 0%;
        transform: translate(-50%, 0%) scale(var(--screen-scale));
        -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale));
    }
}

/* 개발자 도구 및 시뮬레이션 모드 최적화 */
body.devtools-mode {
    /* 개발자 도구 환경에서 안정적인 렌더링 */
    overflow: hidden;
    position: relative;
}

body.devtools-mode .app-container {
    /* 시뮬레이션 환경에서 엄격한 크기 제한 */
    max-width: 100vw !important;
    max-height: 100vh !important;
    overflow: hidden;
    
    /* 더 정확한 상단 정렬 */
    position: fixed;
    left: 50%;
    top: 0%;
    transform: translate(-50%, 0%) scale(var(--screen-scale));
    -webkit-transform: translate(-50%, 0%) scale(var(--screen-scale));
    -moz-transform: translate(-50%, 0%) scale(var(--screen-scale));
    
    /* 시뮬레이션에서 성능 최적화 */
    image-rendering: auto;
    -webkit-image-rendering: auto;
    
    /* 강제 GPU 가속 */
    will-change: transform;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

/* 개발자 도구에서 화면이 잘리지 않도록 추가 보호 */
body.devtools-mode .screen {
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* 시뮬레이션 모드에서 스크롤 완전 차단 */
body.devtools-mode {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* 개발자 도구 환경에서 폰트 렌더링 최적화 */
body.devtools-mode * {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 프리셋 슬롯 선택 UI */
.preset-slot-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: calc(8px * var(--screen-scale));
    padding: calc(10px * var(--screen-scale));
    max-height: calc(400px * var(--screen-scale));
    overflow-y: auto;
}

.preset-slot-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(60px * var(--screen-scale));
    border: calc(2px * var(--screen-scale)) solid var(--light-gray);
    border-radius: calc(var(--border-radius) * var(--screen-scale));
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--white);
    padding: calc(5px * var(--screen-scale));
    text-align: center;
}

.preset-slot-selector.empty {
    background: #f9f9f9;
    border-color: var(--light-gray);
}

.preset-slot-selector.occupied {
    background: var(--light-green);
    border-color: var(--primary-green);
    color: var(--white);
}

.preset-slot-selector:hover {
    transform: scale(1.05);
    box-shadow: 0 calc(4px * var(--screen-scale)) calc(8px * var(--screen-scale)) rgba(0,0,0,0.1);
}

.preset-slot-selector .slot-number {
    font-size: calc(0.8rem * var(--screen-scale));
    font-weight: bold;
    margin-bottom: calc(2px * var(--screen-scale));
}

.preset-slot-selector .slot-name {
    font-size: calc(0.7rem * var(--screen-scale));
    word-break: break-all;
    line-height: 1.2;
}

.preset-slot-selector.empty .slot-name {
    color: var(--gray);
}

/* 모바일에서 프리셋 슬롯 그리드 조정 */
@media screen and (max-width: 480px) {
    .preset-slot-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: calc(5px * var(--screen-scale));
        padding: calc(8px * var(--screen-scale));
    }
    
    .preset-slot-selector {
        min-height: calc(50px * var(--screen-scale));
        padding: calc(3px * var(--screen-scale));
    }
    
    .preset-slot-selector .slot-number {
        font-size: calc(0.7rem * var(--screen-scale));
    }
    
    .preset-slot-selector .slot-name {
        font-size: calc(0.6rem * var(--screen-scale));
    }
}

/* 포지션별 텍스트 색상 클래스 */
.position-text-goalkeeper {
    color: #ffcc00 !important; /* 골키퍼 - 노란색 계열 */
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.position-text-defender {
    color: #1e90ff !important; /* 수비 - 파란색 계열 */
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.position-text-midfielder {
    color: #32cd32 !important; /* 미드필더 - 녹색 계열 */
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.position-text-attacker {
    color: #ff4444 !important; /* 공격 - 빨강색 계열 */
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* 포지션별 배경 색상 클래스 (formation-screen용) */
.position-display {
    display: inline-block;
    text-align: center;
    transition: all 0.3s ease;
}

.position-background-goalkeeper {
    background: linear-gradient(135deg, #ffcc00, #e6a800) !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 6px;
}

.position-background-defender {
    background: linear-gradient(135deg, #1e90ff, #0066cc) !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 6px;
}

.position-background-midfielder {
    background: linear-gradient(135deg, #32cd32, #228b22) !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 6px;
}

.position-background-attacker {
    background: linear-gradient(135deg, #ff4444, #cc0000) !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 12px;
    border-radius: 6px;
}

/* 어두운 배경에서 더 밝게 보이도록 하는 버전 */
.position-text-bright-goalkeeper {
    color: #ffd700 !important; /* 더 밝은 골드 */
    font-weight: bold !important;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

.position-text-bright-defender {
    color: #4db8ff !important; /* 더 밝은 파란색 */
    font-weight: bold !important;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

.position-text-bright-midfielder {
    color: #5aff5a !important; /* 더 밝은 녹색 */
    font-weight: bold !important;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

.position-text-bright-attacker {
    color: #ff6666 !important; /* 더 밝은 빨강색 */
    font-weight: bold !important;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

/* 매우 작은 화면에서 제목 추가 보호 */
@media screen and (max-width: 400px) {
    .screen-title {
        font-size: clamp(0.9rem, 3vw, 1.2rem) !important; /* 더 작은 폰트 강제 적용 */
        padding: 0 8px !important;
        line-height: 1.2 !important; /* 줄간격 축소 */
        max-width: calc(100% - 120px) !important; /* 초소형 화면에서 버튼 공간 확보 */
        /* 절대 위치 속성은 상위에서 이미 설정됨 */
    }
    
    .formation-header,
    .preset-header,
    .battle-header {
        padding: 6px 10px !important; /* 패딩 더 축소 */
        height: 55px !important; /* 헤더 높이 더 축소 */
        min-height: 55px !important;
    }
    
    .back-btn, .save-btn {
        padding: 8px 12px !important; /* 버튼 크기 축소 */
        font-size: 0.8rem !important;
    }
}
