/* ============================================
    메인 화면 스타일 (캐릭터 선택/관리)
    ============================================ */

/* 메인 레이아웃 */
.main-layout {
    display: grid;
    grid-template-columns: minmax(760px, 1fr) 300px;
    gap: 24px;
    align-items: start;
}

.left-panel h2 {
    color: #667eea;
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 20px;
}

/* (메인) 팀 분류 */
.teams-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.team-box {
    background: #f8f9fc;
    border: 2px solid #e3e6f0;
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s ease;
    width: 100%;
}

/* 팀 컬러(히어로/정부/빌런) 강조 */
.teams-grid .team-box:nth-child(1) { border-top: 5px solid var(--team-hero); }
.teams-grid .team-box:nth-child(2) { border-top: 5px solid var(--team-gov); }
.teams-grid .team-box:nth-child(3) { border-top: 5px solid var(--team-villain); }

.teams-grid .team-box:nth-child(1) .team-title { color: var(--team-hero); }
.teams-grid .team-box:nth-child(2) .team-title { color: var(--team-gov); }
.teams-grid .team-box:nth-child(3) .team-title { color: var(--team-villain); }

.team-box:hover {
    border-color: #667eea;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.15);
}

.teams-grid .team-box:nth-child(1):hover { border-color: var(--team-hero); box-shadow: 0 4px 16px rgba(37, 99, 235, 0.18); }
.teams-grid .team-box:nth-child(2):hover { border-color: var(--team-gov); box-shadow: 0 4px 16px rgba(22, 163, 74, 0.18); }
.teams-grid .team-box:nth-child(3):hover { border-color: var(--team-villain); box-shadow: 0 4px 16px rgba(220, 38, 38, 0.18); }

.team-title {
    color: #4a5568;
    font-size: 1.05em;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.team-icon {
    font-size: 1.2em;
}

/* 검색 입력 */
.search-input {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: white;
    border: 2px solid #e3e6f0;
    border-radius: 10px;
    font-size: 0.9em;
    color: #2c3e50;
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 팀별 입력 포커스 색상 */
#team1-search:focus { border-color: var(--team-hero); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }
#team2-search:focus { border-color: var(--team-gov); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18); }
#team3-search:focus { border-color: var(--team-villain); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18); }

.search-input::placeholder {
    color: #a0aec0;
}

/* (메인) 캐릭터 리스트 박스 */
.character-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
}

.character-list::-webkit-scrollbar {
    width: 6px;
}

.character-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.character-list::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

.character-list::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* (메인) 캐릭터 개개인 박스 */
.character-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border: 1.5px solid #e3e6f0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.character-item:hover {
    border-color: #667eea;
    transform: translateX(2px);
}

.character-item.selected {
    background: #eef2ff;
    border-color: #667eea;
}

.character-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #667eea;
}

.character-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.character-name {
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.95em;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-hp {
    font-size: 0.85em;
    color: #718096;
    flex: 0 0 auto;
    white-space: nowrap;
}

.btn-remove {
    background: transparent;
    border: none;
    color: #e53e3e;
    font-size: 1.2em;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 0 4px;
}

.character-item:hover .btn-remove {
    opacity: 1;
}

.btn-remove:hover {
    color: #c53030;
}

/* 추가 버튼 */
.btn-add-character {
    width: 100%;
    padding: 10px;
    background: white;
    border: 2px dashed #cbd5e0;
    border-radius: 10px;
    color: #718096;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-add-character:hover {
    border-color: #667eea;
    color: #667eea;
    background: #f7fafc;
}

/* 팀별 '추가' 버튼 */
#add-team1 { border-color: #93c5fd; }
#add-team2 { border-color: #86efac; }
#add-team3 { border-color: #fca5a5; }

/* 대량 등록 버튼(히어로) */
.btn-bulk-import {
    margin-top: 8px;
    border-style: solid;
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.btn-bulk-import:hover {
    border-color: #2563eb;
    background: #dbeafe;
    color: #1d4ed8;
}

/* 팀별 대량 등록 버튼 컬러 */
#bulk-import-team1 { border-color: #93c5fd; }
#bulk-import-team2 { border-color: #86efac; background: #f0fdf4; color: #15803d; }
#bulk-import-team3 { border-color: #fca5a5; background: #fff1f2; color: #be123c; }

#bulk-import-team1:hover { border-color: var(--team-hero); }
#bulk-import-team2:hover { border-color: var(--team-gov); background: #dcfce7; color: #166534; }
#bulk-import-team3:hover { border-color: var(--team-villain); background: #ffe4e6; color: #9f1239; }

#add-team1:hover { border-color: var(--team-hero); color: var(--team-hero); }
#add-team2:hover { border-color: var(--team-gov); color: var(--team-gov); }
#add-team3:hover { border-color: var(--team-villain); color: var(--team-villain); }

/* 캐릭터 상태(사망/실종) - JS에서 클래스로 붙임 */
.character-item.is-dead { opacity: 0.65; background: #fff1f2; border-color: #fecdd3; }
.character-item.is-missing { opacity: 0.75; background: #fffbeb; border-color: #fde68a; }

/* 선택된 캐릭터 섹션 */
.selected-characters-section {
    background: #f8f9fc;
    border: 2px solid #e3e6f0;
    border-radius: 16px;
    padding: 20px;
    margin-top: 20px;
}

.selected-title {
    color: #4a5568;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 16px;
}

.selected-characters-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.selected-team {
    background: white;
    border: 2px solid #e3e6f0;
    border-radius: 12px;
    padding: 16px;
    min-height: 120px;
}

.selected-team:nth-child(1) {
    border-color: var(--team-hero);
}

.selected-team:nth-child(2) {
    border-color: var(--team-gov);
}

.selected-team:nth-child(3) {
    border-color: var(--team-villain);
}

#hero-selected .team-label { color: var(--team-hero); }
#gov-selected .team-label { color: var(--team-gov); }
#villain-selected .team-label { color: var(--team-villain); }

#hero-selected .selected-character { background: var(--team-hero-soft); border-color: #93c5fd; }
#gov-selected .selected-character { background: var(--team-gov-soft); border-color: #86efac; }
#villain-selected .selected-character { background: var(--team-villain-soft); border-color: #fca5a5; }

.team-label {
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95em;
}

.selected-character {
    background: #eef2ff;
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: #4a5568;
    border: 1px solid #cbd5e0;
}

/* 오른쪽 패널 */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-self: start;
    width: 100%;
    max-width: 300px;
}

.time-display {
    background: #f8f9fc;
    border: 2px solid #e3e6f0;
    border-radius: 16px;
    padding: 24px;
    text-align: center;
}

.time-label {
    color: #718096;
    font-size: 0.9em;
    font-weight: 500;
    margin-bottom: 8px;
}

.time-value {
    color: #2c3e50;
    font-size: 2em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}

.date-value {
    color: #718096;
    font-size: 0.9em;
    margin-top: 6px;
}

/* 전투 모드 */
.battle-mode {
    background: #f8f9fc;
    border: 2px solid #e3e6f0;
    border-radius: 16px;
    padding: 20px;
}

.mode-label {
    color: #4a5568;
    font-size: 1em;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mode-icon {
    font-size: 1.2em;
}

.mode-toggle {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mode-btn {
    padding: 14px 20px;
    border: 2px solid #e3e6f0;
    border-radius: 12px;
    background: white;
    color: #4a5568;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-btn:hover {
    border-color: #667eea;
    background: #eef2ff;
}

.mode-btn.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.mode-btn:last-child {
    background: #e53e3e;
    border-color: #e53e3e;
    color: white;
}

.mode-btn:last-child:hover {
    background: #c53030;
    border-color: #c53030;
}

/* 캐릭터 관리 */
.character-management {
    background: #f8f9fc;
    border: 2px solid #e3e6f0;
    border-radius: 16px;
    padding: 20px;
}

.management-title {
    color: #4a5568;
    font-size: 1em;
    font-weight: 600;
    margin-bottom: 12px;
}

.management-status {
    background: #c6f6d5;
    border: 2px solid #9ae6b4;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 0.85em;
    color: #276749;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-icon {
    font-size: 1.1em;
}

.management-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* 파일 자동 저장 상태 */
.autosave-status {
    margin-top: 16px;
    padding: 16px;
    background: white;
    border: 2px solid #e3e6f0;
    border-radius: 12px;
    text-align: center;
}

.autosave-title {
    font-weight: 600;
    color: #4a5568;
    font-size: 0.95em;
    margin-bottom: 12px;
}

.autosave-state {
    font-size: 0.9em;
    padding: 6px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-weight: 600;
}

.autosave-state.active {
    background: #c6f6d5;
    color: #276749;
}

.autosave-state.inactive {
    background: #fed7d7;
    color: #9b2c2c;
}

.autosave-time {
    font-size: 0.85em;
    color: #718096;
    margin-bottom: 4px;
}

.autosave-countdown {
    font-size: 0.85em;
    color: #4a5568;
    margin-bottom: 12px;
}

.btn-autosave {
    width: 100%;
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-autosave:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.btn-autosave.active {
    background: #e53e3e;
}

.btn-autosave.active:hover {
    background: #c53030;
}

/* 버튼 텍스트 줄바꿈 및 작은 화면 대응 */
@media (max-width: 768px) {
    .management-buttons {
        grid-template-columns: 1fr;
    }
    
    .btn-management {
        padding: 10px 8px;
        font-size: 0.85em;
        white-space: normal;
        word-break: break-word;
    }
}

/* 반응형 */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .teams-grid {
        grid-template-columns: 1fr;
    }

    .selected-characters-list {
        grid-template-columns: 1fr;
    }

    .right-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .time-display,
    .battle-mode,
    .character-management {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 768px) {
    main {
        padding: 20px;
    }
}
