/* cardgame/web/cardgame.css — 사용자 등록 모달 + 실시간 랭킹 패널 */

/* ───────── 레이아웃: 캔버스는 원래대로 중앙, 랭킹은 우상단 floating ───────── */
.cg-layout { display: contents; }   /* 레이아웃에 영향 X — 캔버스 중앙 정렬 유지 */

/* 랭킹: 우상단 반투명 floating 오버레이 (데스크탑/모바일 공통) */
#cg-ranking {
  position: fixed;
  top: 8px; right: 8px;
  z-index: 60;
  width: 200px;
  max-width: 46vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: rgba(15, 19, 26, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border: 1px solid rgba(255, 212, 94, 0.35);
  border-radius: 8px;
  color: #e6e8ec;
  font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4);
}
#cg-ranking.hidden { display: none; }
.cg-rank-head {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px 7px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.cg-rank-title { font-size: 14px; font-weight: bold; color: #ffd45e; flex: 0 0 auto; }
.cg-me {
  flex: 1 1 auto; font-size: 11px; color: #8fd6ff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cg-rank-close {
  flex: 0 0 auto; width: 22px; height: 22px; line-height: 20px;
  padding: 0; border: none; border-radius: 4px; cursor: pointer;
  background: rgba(255,255,255,0.08); color: #e6e8ec; font-size: 13px;
}
.cg-rank-close:hover { background: rgba(255,255,255,0.18); }
.cg-rank-list {
  list-style: none; margin: 0; padding: 4px 0;
  overflow-y: auto; flex: 1 1 auto;
}
.cg-rank-item {
  display: flex; align-items: center;
  padding: 3px 10px; font-size: 12px; gap: 6px;
}
.cg-rank-item.mine { background: rgba(120, 200, 90, 0.22); color: #c8f5a0; }
.cg-rank-no { flex: 0 0 20px; text-align: right; color: #9aa3b2; }
.cg-rank-item.mine .cg-rank-no { color: #c8f5a0; }
.cg-rank-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-rank-money { flex: 0 0 auto; color: #ffd45e; font-variant-numeric: tabular-nums; }
.cg-rank-item.mine .cg-rank-money { color: #d6ff8f; }

/* ───────── 게임 컨트롤러 (최소 구성) — PC + 모바일 공통, 한 줄 풀폭 ─────────
   레이아웃 (full-width 3행, 우측 공백 없이 행을 가득 채움):
        [RETRY] ················· [종료]
        [▲] [▼] [   ENTER   ] [    MAX    ]
        [    100   ] [    500   ] [   1000  ]
   .btn[data-key] 는 mobile_input.js bindButton 자동 부착(touch/mouse → keydown/keyup).
   UP/DOWN 홀드 시 card_game.lua tick_bet_hold 가 베팅 stride 가속. */
#cg-controller {
  position: fixed;
  left: 12px; right: 12px; bottom: 14px;   /* 좌우 끝까지 — 한 줄 풀폭 */
  z-index: 120;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;   /* 빈 공간은 캔버스로 통과, 버튼만 auto */
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 각 행: 가로 full-width 분배 */
#cg-controller .cg-c-row  { display: flex; align-items: center; gap: 8px; }
#cg-controller .cg-c-top  { justify-content: space-between; }   /* RETRY 좌 · 종료 우 */
/* main 행: UP/DOWN 은 원형 고정, ENTER/MAX 가 늘어나 우측 공백을 채움 */
#cg-controller .cg-c-main .cg-tri  { flex: 0 0 auto; }
#cg-controller .cg-c-main .cg-c-act { flex: 1 1 0; }
/* bet 행: 100/500/1000 균등 분할로 줄을 가득 채움 */
#cg-controller .cg-c-bet  { flex: 1 1 0; }

/* 공통 버튼 베이스 (반투명, mobile_input.css .btn 톤과 동일) */
#cg-controller .btn {
  pointer-events: auto;
  margin: 0; padding: 0;
  border: 2px solid rgba(200, 200, 220, 0.6);
  background: rgba(40, 40, 60, 0.55);
  color: #f0f0f0; font-weight: bold;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  border-radius: 12px;
  touch-action: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, transform 0.05s;
}
#cg-controller .btn.pressed,
#cg-controller .btn:active {
  background: rgba(120, 160, 220, 0.85);
  transform: scale(0.92);
}

/* ENTER / MAX — flex 로 늘어남(위 .cg-c-main 규칙). 최소폭만 보장 */
#cg-controller .cg-c-act   { min-width: 66px; height: 52px; font-size: 15px; }
#cg-controller .cg-c-enter { background: rgba(80, 110, 160, 0.62); }
#cg-controller .cg-c-max   {
  background: rgba(150, 120, 60, 0.7);
  border-color: rgba(255, 212, 94, 0.6); color: #ffe9a8;
}

/* RETRY (firebase.js 가 disabled / .cg-retry-on 토글) */
#cg-controller .cg-c-retry { width: 56px; height: 44px; font-size: 18px; }

/* EXIT — 종료 확인(예/아니오) → 리더보드 (firebase.js setupExit) */
#cg-controller .cg-c-exit {
  width: 66px; height: 44px; font-size: 14px;
  background: rgba(150, 70, 70, 0.62); border-color: rgba(255, 150, 140, 0.5);
}

/* 빠른 베팅 행 100 / 500 / 1000 — 균등 분할(위 .cg-c-bet flex 규칙) */
#cg-controller .cg-c-bet    { height: 40px; font-size: 14px; }

/* UP / DOWN — 원형 + 안쪽 정삼각형 (방향키 모양 유지) */
#cg-controller .cg-tri {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 50%;
}
#cg-controller .cg-tri::before {
  content: '';
  position: absolute; inset: 0; margin: auto;
  width: 0; height: 0;
}
/* 정삼각형: 밑변 24(12+12), 높이 21 ≈ 24·(√3/2) */
#cg-controller .cg-up::before {
  border-left: 12px solid transparent; border-right: 12px solid transparent;
  border-bottom: 21px solid rgba(235, 240, 255, 0.92);
}
#cg-controller .cg-down::before {
  border-left: 12px solid transparent; border-right: 12px solid transparent;
  border-top: 21px solid rgba(235, 240, 255, 0.92);
}

/* ── 모바일: 컨트롤러를 game-wrap flex 흐름에 넣어 캔버스 아래 남은 세로를 가득 채움 ──
   #cg-controller 가 game-wrap(column, top-start) 의 flex child → flex:1 로 캔버스 하단
   ~화면 바닥까지 차지, 3행을 space-between 으로 세로 분배 + 버튼 확대.
   (캔버스 실제 높이에 의존 안 함 — flex 가 남는 공간을 자동 계산) */
@media (pointer: coarse), (max-width: 1024px) {
  #cg-controller {
    position: static;          /* fixed 해제 → game-wrap column 흐름 참여 */
    flex: 1 1 auto;            /* 캔버스 아래 남은 세로 공간 가득 */
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 0;
    justify-content: space-between;   /* row1 캔버스 아래 · row3 바닥 · 가운데 채움 */
  }
  #cg-controller .cg-c-retry { width: 64px; height: 52px; font-size: 20px; }
  #cg-controller .cg-c-exit  { min-width: 80px; height: 52px; font-size: 16px; }
  #cg-controller .cg-tri     { width: 68px; height: 68px; }
  #cg-controller .cg-c-act   { height: 68px; font-size: 18px; }
  #cg-controller .cg-c-bet   { height: 60px; font-size: 18px; }
  /* 방향 정삼각형도 비례 확대 */
  #cg-controller .cg-up::before {
    border-left-width: 15px; border-right-width: 15px; border-bottom-width: 26px;
  }
  #cg-controller .cg-down::before {
    border-left-width: 15px; border-right-width: 15px; border-top-width: 26px;
  }
}

/* 닫혔을 때 다시 열기 버튼 (우상단 작은 🏆) */
#cg-rank-open {
  position: fixed; top: 8px; right: 8px; z-index: 60;
  width: 34px; height: 30px; padding: 0;
  border: 1px solid rgba(255,212,94,0.35); border-radius: 8px; cursor: pointer;
  background: rgba(15,19,26,0.55); color: #ffd45e; font-size: 15px;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
#cg-rank-open.hidden { display: none; }

/* ───────── 게임 종료 확인 (예/아니오) ───────── */
#cg-exit-confirm {
  position: fixed; inset: 0; z-index: 9500;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.7);
}
#cg-exit-confirm.hidden { display: none; }
.cg-confirm-card {
  background: #1b212b; color: #e6e8ec;
  border: 2px solid #ffd45e; border-radius: 10px;
  padding: 24px 26px; width: 300px; max-width: 86vw; text-align: center;
  font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.cg-confirm-title { font-size: 18px; font-weight: bold; color: #ffd45e; margin-bottom: 6px; }
.cg-confirm-sub { font-size: 12px; color: #9aa3b2; margin-bottom: 18px; }
.cg-confirm-btns { display: flex; gap: 12px; }
.cg-confirm-btns button {
  flex: 1; padding: 11px 0; font-size: 15px; font-weight: bold;
  border: none; border-radius: 6px; cursor: pointer;
  font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
}
#cg-exit-yes { background: #c0392b; color: #fff; }
#cg-exit-no  { background: #3a4456; color: #e6e8ec; }

/* ───────── 종료 후 리더보드 전체화면 ───────── */
#cg-endscreen {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 11, 16, 0.96);
}
#cg-endscreen.hidden { display: none; }
.cg-end-inner {
  width: 360px; max-width: 92vw; max-height: 88vh;
  display: flex; flex-direction: column;
  color: #e6e8ec; font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
}
.cg-end-title { font-size: 24px; font-weight: bold; color: #ffd45e; text-align: center; margin-bottom: 8px; }
.cg-end-me {
  font-size: 14px; color: #8fd6ff; text-align: center;
  padding: 8px; margin-bottom: 10px;
  background: rgba(120, 200, 90, 0.14); border-radius: 6px;
}
.cg-end-list {
  list-style: none; margin: 0; padding: 4px 0;
  overflow-y: auto; flex: 1 1 auto;
  border: 1px solid rgba(255,212,94,0.25); border-radius: 8px;
  background: rgba(15,19,26,0.6);
}
/* list item 은 랭킹 패널과 동일 클래스(.cg-rank-item 등) 재사용 — firebase.js 가 생성 */
.cg-end-back {
  margin-top: 12px; padding: 11px; font-size: 14px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,0.06); color: #e6e8ec;
  font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
}
.cg-end-back:hover { background: rgba(255,255,255,0.14); }

/* ───────── 재도전(0원 충전) 버튼 ───────── */
/* 비활성(머니>0): 흐리게 + 클릭 불가. .btn 기본 스타일(mobile_input.css) 위에 override. */
#btn-retry:disabled {
  opacity: 0.38;
  cursor: default;
  filter: grayscale(0.6);
}
/* 활성(머니 0): 빨강 강조 + 깜빡임으로 충전 가능 알림. */
#btn-retry.cg-retry-on:not(:disabled) {
  opacity: 1;
  cursor: pointer;
  background: #c0392b;
  color: #fff;
  border-color: #ff8f7a;
  animation: cg-retry-pulse 1.1s ease-in-out infinite;
}
@keyframes cg-retry-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 70, 50, 0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(220, 70, 50, 0); }
}

/* ───────── 사용자 등록 모달 ───────── */
#cg-name-modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  z-index: 10000; /* splash(보통 9000대)보다 위 */
}
#cg-name-modal.hidden { display: none; }
.cg-modal-card {
  background: #1b212b; color: #e6e8ec;
  border: 2px solid #ffd45e; border-radius: 10px;
  padding: 28px 26px; width: 320px; max-width: 86vw;
  text-align: center;
  font-family: "NeoDunggeunmoPro", system-ui, sans-serif;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.cg-modal-title { font-size: 20px; font-weight: bold; color: #ffd45e; margin-bottom: 6px; }
.cg-modal-sub { font-size: 13px; color: #9aa3b2; margin-bottom: 18px; }
#cg-name-input {
  width: 100%; box-sizing: border-box;
  padding: 11px 12px; font-size: 17px;
  border: 1px solid #3a4456; border-radius: 6px;
  background: #0f131a; color: #fff; text-align: center;
  margin-bottom: 14px; outline: none;
}
#cg-name-input:focus { border-color: #ffd45e; }
#cg-name-ok {
  width: 100%; padding: 12px; font-size: 16px; font-weight: bold;
  border: none; border-radius: 6px; cursor: pointer;
  background: #ffd45e; color: #1b212b;
}
#cg-name-ok:disabled { opacity: 0.5; cursor: default; }
.cg-modal-msg { margin-top: 10px; font-size: 12px; color: #ff8f8f; min-height: 16px; }
