/*
 * components.css — 재사용 컴포넌트 (버튼, 카드, 입력, 배지).
 * 클래스명만 외우면 페이지별 CSS 에서 추가 스타일 없이 바로 사용 가능.
 */

/* ─────────────────────────────────────────────────────────────────
 *  버튼
 * ───────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;             /* Apple HIG — 터치 영역 최소 */
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    cursor: pointer;
    transition: var(--transition-fast);
    user-select: none;
}

.btn:disabled {
    cursor: not-allowed;
}

/* Primary: 흰 배경 + 검은 텍스트 (게임 시작, 메인 액션) */
.btn-primary {
    background: var(--text-primary);
    color: var(--bg-base);
    border: none;
}
.btn-primary:hover:not(:disabled) {
    background: var(--text-secondary);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(1px);
}
.btn-primary:disabled {
    background: var(--border-default);
    color: var(--text-tertiary);
}

/* Secondary: 투명 + 보더 */
.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
    border-color: var(--border-strong);
}
.btn-secondary:active:not(:disabled) {
    transform: translateY(1px);
}

/* 카카오 (예외 — 카카오 가이드라인 의무) */
.btn-kakao {
    background: #FEE500;
    color: #181600;
    border: none;
    font-weight: var(--weight-semibold);
}
.btn-kakao:hover:not(:disabled) {
    /* 카카오 가이드: 색 변경 금지. 살짝 어둡게만. */
    filter: brightness(0.95);
}
.btn-kakao:active:not(:disabled) {
    transform: translateY(1px);
}

/* full-width — 모바일 풀폭 */
.btn-block {
    width: 100%;
}

/* ─────────────────────────────────────────────────────────────────
 *  카드
 * ───────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}

/*
 * 진영 색은 "왼쪽 4px 라인" 으로만 표시.
 * design.md ❌ 9: 카드마다 다른 색 배경 금지. 라인으로만.
 *
 * 진영 색은 JS 가 --faction-color CSS 변수로 인라인 주입.
 *   <div class="card card-faction" style="--faction-color: #FF7F0E"> ...
 */
.card-faction {
    border-left: 4px solid var(--faction-color, var(--border-default));
}

/* ─────────────────────────────────────────────────────────────────
 *  입력 / 체크박스 / 라디오
 * ───────────────────────────────────────────────────────────────── */

.input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    background: var(--bg-base);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 16px;              /* iOS 자동 줌인 방지 */
    transition: var(--transition-fast);
}
.input:focus {
    outline: none;
    border-color: var(--text-primary);
}

/* 체크박스 라벨: 통째로 큰 터치 영역 */
.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    cursor: pointer;
    min-height: 44px;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: 1.5;
}
.checkbox-label input[type="checkbox"] {
    /* 기본 체크박스 그대로 — 시스템 일관성. 단 크기는 살짝 키움 */
    width: 20px;
    height: 20px;
    margin-top: 2px;
    accent-color: var(--text-primary);
    flex-shrink: 0;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"]:checked + span {
    color: var(--text-primary);
}

/* 라디오 옵션 (단과대 선택용). label 통째로 큰 버튼 역할 */
.radio-option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
    color: var(--text-secondary);
    font-size: var(--text-base);
}
.radio-option:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}
.radio-option input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--faction-color, var(--text-primary));
    flex-shrink: 0;
    cursor: pointer;
}
.radio-option:has(input[type="radio"]:checked) {
    /* 선택된 단과대 = 진영색 보더로 강조 (배경은 칠 안 함 — 규칙 #9) */
    color: var(--text-primary);
    border-color: var(--faction-color, var(--text-primary));
    background: var(--bg-elevated);
}

/* ─────────────────────────────────────────────────────────────────
 *  진영 배지 (작은 색 표시)
 * ───────────────────────────────────────────────────────────────── */

.faction-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-1) var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-family: var(--font-pixel);
    font-size: var(--text-xs);
    color: var(--text-primary);
    letter-spacing: 0.02em;
}
.faction-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--faction-color, var(--text-secondary));
    /* 정사각형 = 픽셀 느낌. 둥글지 않게 그대로. */
    flex-shrink: 0;
}

/* ─────────────────────────────────────────────────────────────────
 *  로더 (간단한 텍스트)
 * ───────────────────────────────────────────────────────────────── */

.loader {
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    text-align: center;
    padding: var(--space-6);
}

/* ─────────────────────────────────────────────────────────────────
 *  Toast (일시 알림 — 쿨다운 안내, 네트워크 에러 등)
 *
 *  - 화면 하단 가운데에 살짝 떴다가 2.5초 후 사라짐
 *  - JS 가 .toast 노드 동적 생성 후 setTimeout 으로 제거
 *  - 둥근 모서리 4px, 어두운 배경 + 1px 보더 (그림자 없음)
 * ───────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--space-12) + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: calc(100vw - var(--space-8));
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    z-index: 1000;
    animation: toast-in var(--transition-base);
    /* 클릭 통과 — 토스트가 사용자 액션을 막지 않게 */
    pointer-events: none;
}
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ─────────────────────────────────────────────────────────────────
 *  모달 (전체 순위, 픽셀 확대 시트 공통 베이스)
 *
 *  design.md 의 모달 가이드 그대로:
 *  - 오버레이는 var(--bg-overlay) 어두운 반투명
 *  - content 는 8px radius (모달만 예외)
 *  - 그림자 var(--shadow-modal) (유일하게 허용)
 * ───────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 100;
    display: flex;
    align-items: flex-end;     /* 모바일 친화: 하단에서 슬라이드업 */
    justify-content: center;
    /* 모바일에서 풀폭, 데스크탑에서 480px 컨테이너 안에 정렬되도록 */
    padding: 0;
}
.modal-overlay.hidden {
    display: none;
}

.modal-content {
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;  /* 위쪽만 둥글게 — 하단 시트 느낌 */
    box-shadow: var(--shadow-modal);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: sheet-up var(--transition-slow);
    padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-default);
}
.modal-header h2 {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.02em;
}

.modal-close {
    /* SVG × 아이콘 버튼 — 이모지 사용 X (design.md #3) */
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-base);
}
.modal-close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-4) var(--space-6);
}

/* ─────────────────────────────────────────────────────────────────
 *  플로팅 액션 버튼 (FAB)
 *
 *  - 우측 하단 고정
 *  - 둥근 사각형(8px radius) — 완전 원형 X (픽셀 미학)
 *  - 텍스트 라벨 사용 (이모지 X)
 * ───────────────────────────────────────────────────────────────── */

.fab {
    position: fixed;
    /* 480px 컬럼 우측 끝에서 var(--space-4) 안쪽.
       화면 ≤ 480px: 검정 양 옆 없음 → 우측 16px.
       화면 > 480px: 컬럼 우측 끝 + 16px (양 옆 검정 폭만큼 추가). */
    right: max(var(--space-4), calc((100vw - 480px) / 2 + var(--space-4)));
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    min-width: 56px;
    min-height: 56px;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-pixel);
    font-size: var(--text-xs);
    letter-spacing: 0.05em;
    cursor: pointer;
    z-index: 50;
    box-shadow: var(--shadow-modal);
    transition: var(--transition-fast);
}
.fab:hover {
    border-color: var(--text-primary);
}
.fab:active {
    transform: translateY(1px);
}

/* ─────────────────────────────────────────────────────────────────
 *  텍스트 유틸 — 픽셀 폰트
 * ───────────────────────────────────────────────────────────────── */

.font-pixel {
    font-family: var(--font-pixel);
    letter-spacing: 0.02em;
}

/* ─────────────────────────────────────────────────────────────────
 *  공통 hidden — display: none 보장
 * ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
