/* --------------------------------------------------
   배치: 앱 바, 화면 틀, 입장 패널, 게임 영역 (모바일 우선, 넓은 화면은 아래 @media)
   -------------------------------------------------- */

/* 상단 앱 바 */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(8px + var(--safe-top)) 14px 8px;
    background: rgba(15, 20, 32, 0.96);
    border-bottom: 1px solid var(--line);
    user-select: none;
    -webkit-user-select: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* 로고: 숫자 카드 한 장 */
.brand-mark {
    display: grid;
    place-items: center;
    width: 26px;
    height: 34px;
    border-radius: 5px;
    background: var(--card-face);
    color: #c2304d;
    font-weight: 800;
    font-size: 12px;
    transform: rotate(-8deg);
}

.brand-name {
    font-weight: 800;
    letter-spacing: -0.02em;
    font-size: 17px;
}

/* 버전 (업데이트되었는지 확인용) */
.app-version {
    align-self: flex-end;
    margin-bottom: 2px;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted, #8a93a6);
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.room-badge {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 6px;
    overflow: hidden;
    white-space: nowrap;
}

.room-name {
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-me {
    color: var(--muted);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-bar-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

/* 접속 전에는 '방 나가기' 버튼 숨김 */
body:not(.connected) #leave-room-button {
    display: none;
}

/* 본문 */
.app {
    width: 100%;
    max-width: var(--app-max);
    margin: 0 auto;
    padding: 10px 12px calc(16px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 게임 중에는 화면 아래 고정된 손패 독만큼 여백 */
body.in-game .app {
    padding-bottom: calc(176px + var(--safe-bottom));
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
}

/* 입장 패널(로비): 접속하면 숨김. '방 나가기'를 누르면 연결을 끊고 다시 이 화면으로 */
.join-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 440px;
    width: 100%;
    margin: 6vh auto 0;
}

body.connected .join-panel {
    display: none;
}

/* 방을 나왔거나 연결이 끊겼을 때 안내 (어느 방에서 나왔는지) */
.join-notice:empty {
    display: none;
}

.join-notice {
    padding: 10px 12px;
    border-radius: var(--radius);
    background: rgba(139, 108, 255, 0.12);
    border: 1px solid rgba(139, 108, 255, 0.35);
    color: #d9d0ff;
    font-size: 14px;
}

.join-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.join-sub {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 4px;
}

/* 게임 영역 */
.game-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.count-pill {
    font-size: 12px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 8px;
}

.start-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.start-row {
    display: flex;
    gap: 8px;
}

.start-row .btn-primary {
    flex: 2;
}

.start-row .btn-secondary {
    flex: 1;
}

/* 준비 버튼: 준비 전엔 초록으로 눈에 띄게, 준비 후엔 '취소'로 차분하게 */
.btn-ready {
    background: var(--up);
    color: #062615;
}

.btn-ready.is-ready {
    background: var(--surface-2);
    border-color: rgba(47, 212, 134, 0.55);
    color: var(--up);
}

/* 넓은 화면: 게임판 | 채팅 2단 */
@media (min-width: 900px) {
    .app {
        padding: 18px 20px 24px;
    }

    body.in-game .app {
        padding-bottom: 24px;
    }

    .game-area {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 300px;
        align-items: start;
        gap: 16px;
    }

    .start-area {
        flex-direction: row;
    }

    .start-area .btn-ready {
        flex: 1;
    }

    .start-area .start-row {
        flex: 2;
    }
}

/* --------------------------------------------------
   로비: 1단계 이름 → 2단계 방 목록·방 만들기 (lobby.js)
   접속 전: 이름이 없으면 이름 패널, 있으면(.has-name) 로비 패널
   -------------------------------------------------- */
.lobby-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    max-width: 520px;
    width: 100%;
    margin: 4vh auto 0;
}

body.has-name:not(.connected) .lobby-panel {
    display: flex;
}

body.has-name .join-panel {
    display: none;
}

.field-error:empty {
    display: none;
}

.field-error {
    color: var(--down);
    font-size: 13px;
    margin-top: -4px;
}

.lobby-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.lobby-hello {
    color: var(--muted);
    font-size: 14px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lobby-hello strong {
    color: var(--text);
    font-size: 17px;
}

.create-room {
    display: flex;
    gap: 8px;
}

.create-room .text-input {
    flex: 1;
    min-width: 0;
}

.create-room .btn {
    flex-shrink: 0;
}

.room-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 52dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.room-info {
    flex: 1;
    min-width: 0;
}

.room-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.room-status {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    padding: 0 6px;
    border-radius: 6px;
    line-height: 18px;
}

.status-open { background: rgba(47, 212, 134, 0.16); color: var(--up); }
.status-playing { background: rgba(255, 201, 61, 0.16); color: var(--gold); }
.status-full { background: rgba(255, 255, 255, 0.08); color: var(--muted); }

.room-empty {
    padding: 22px 10px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}

/* 로비 접속자 수 */
.online-pill:empty {
    display: none;
}

.online-pill {
    font-size: 12px;
    font-weight: 600;
    color: var(--up);
    background: rgba(47, 212, 134, 0.12);
    border-radius: 999px;
    padding: 1px 8px;
}

.online-pill::before {
    content: '● ';
    font-size: 9px;
}

/* 재연결 중: 상단 배너 + 게임 화면은 보이되 조작은 막음 */
.reconnect-banner {
    display: none;
    position: fixed;
    z-index: 45;
    left: 50%;
    top: calc(60px + var(--safe-top));
    transform: translateX(-50%);
    width: min(440px, calc(100vw - 20px));
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--gold);
    color: #2a2000;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

body.reconnecting .reconnect-banner {
    display: block;
}

body.reconnecting .game-area {
    pointer-events: none;
    opacity: 0.6;
}
