/* ============================================================
   4AM 미니게임 공통 UI
   ------------------------------------------------------------
   세 미니게임(밸런스 / 작곡 / 낙서지우기)이 공유하는 화면 껍데기다.
   모달·인증폼·버튼·리더보드처럼 게임 규칙과 무관한 부분만 담는다.

   기준: 작곡게임(Composition)
   게임마다 다른 것은 아래 :root 변수뿐이고, 나머지 수치는 손대지 않는다.
   여기를 고치면 세 게임이 함께 바뀐다. 한 게임만 바꾸고 싶어지면
   그건 통일이 깨지는 신호이니 변수로 뺄 수 있는지 먼저 따져볼 것.

   ⚠️ 이 파일은 세 저장소에 같은 내용으로 복사되어 있다.
      수정 후 sync-ui-common.sh 로 나머지에 반영할 것.
   ============================================================ */

:root {
  /* 게임별로 덮어쓰는 값 — 각 게임 style.css 최상단에서 재정의한다 */
  --accent: #eed534;                                          /* 강조색: 제목·포커스·랭킹 하이라이트 */
  --accent-rgb: 238, 213, 52;                                 /* 위 색의 RGB. 투명도 조합에 쓴다 */
  --btn-primary-bg: linear-gradient(135deg, #eed534, #f39c12);
  --btn-primary-color: #12121a;                               /* 주 버튼 글자색 */
  --bg-page: #12121a;
  --bg-container: #1a162b;
  --canvas-bg: radial-gradient(circle at 50% 35%, #2a1f44, #120e20);
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: #fff;
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

#game-container {
  position: relative;
  /* 상단바가 이 상자의 폭을 기준으로 크기를 정할 수 있게 한다.
     캔버스 그림은 상자에 맞춰 줄어드는데 상단바만 고정 크기로 남으면
     좁은 기기에서 상대적으로 커져 서로 밀친다. */
  container-type: inline-size;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
  border-radius: 12px;
  overflow: hidden;
  /* 폭과 높이 중 어느 쪽이 부족하든 450:750 비율을 유지한다.
     높이만 제한하면 폭이 그대로 남아 화면이 눌리고, 캔버스가 레터박스되면서
     입력창·HUD 같은 DOM 요소와 캔버스 그림의 좌표가 어긋난다. */
  width: min(450px, 96vw, calc(92dvh * (450 / 750)));
  height: min(750px, 92dvh, calc(min(450px, 96vw) * (750 / 450)));
  aspect-ratio: 450 / 750;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-container);
}

canvas {
  background: var(--canvas-bg);
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 450 / 750;
  object-fit: contain;
}

/* ---------- 모달 ---------- */

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 8, 18, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

h1 {
  margin: 0 0 4px 0;
  font-size: 26px;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(var(--accent-rgb), 0.4);
}

.sub-title {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: var(--accent);
  font-weight: bold;
  text-shadow: 0 0 12px rgba(var(--accent-rgb), 0.3);
}

.quote-text,
.clear-quote,
.gameover-quote {
  font-size: 13.5px;
  color: #ced6e0;
  margin: 0 0 14px 0;
  font-style: italic;
  line-height: 1.45;
}

.clear-quote,
.gameover-quote {
  margin-bottom: 10px;
}

.score-main {
  font-size: 14px;
  color: #fff;
  margin: 0 0 3px 0;
  text-align: center;
}

.score-main strong {
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
}

.score-sub {
  font-size: 13px;
  color: #a4b0be;
  margin: 0 0 10px 0;
  text-align: center;
}

.celebration-badge {
  background: #2ed573;
  color: #0f2e1a;
  font-weight: 900;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
  animation: bounce 0.6s infinite alternate ease-in-out;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

/* ---------- 닉네임 · PIN 입력 ---------- */

.auth-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 250px;
  margin-bottom: 14px;
}

.input-field {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.input-field::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.input-field:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.12);
}

.auth-error {
  color: #ff4757;
  font-size: 12px;
  min-height: 16px;
}

/* ---------- 버튼 ---------- */

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 250px;
}

.primary-btn {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-color);
  border: none;
  padding: 12px;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.primary-btn:active {
  transform: scale(0.97);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #ced6e0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 9px;
  font-size: 13px;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* ---------- 리더보드 ---------- */
/* 게임마다 항목 클래스가 .rank-item / .rank-row 로 갈려 있어 둘 다 받는다 */

.leaderboard-box,
#leaderboard {
  width: 100%;
  max-width: 290px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}

.rank-header {
  font-size: 13px;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
  text-align: center;
}

.rank-item,
.rank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 2px;
}

/* 이름 칸. flex 로 두어야 스텝 알약이 이름과 정확히 같은 높이에 온다.
   inline 흐름에서 vertical-align: middle 은 글자 기준선을 기준으로 계산해
   1px 쯤 아래로 처진다. */
.rank-item > span:first-child {
  display: flex;
  align-items: center;
  min-width: 0;
  /* 줄 높이를 고정한다. 그냥 두면 앞에 오는 문자가 메달 이모지냐 '4위' 냐에
     따라 줄 높이가 23~26.7px 로 들쭉날쭉해지고, 행마다 알약이 다른 높이에 앉는다.
     알약을 얇게 잡아 둔 덕에 1.3 까지 좁혀도 알약이 줄을 밀어내지 않는다. */
  line-height: 1.3;
}

/* 점수 칸. '>' 로 바로 아래 자식만 잡는다 — 그냥 span:last-child 로 두면
   이름 칸 안에 든 스텝 알약까지 걸려 폭 60px 에 오른쪽 정렬을 받는다. */
.rank-item > span:last-child {
  /* 굵기는 행이 정한다. 1~3등과 내 순위 행만 굵고 나머지는 보통이 된다 */
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  min-width: 60px;
  text-align: right;
}

/* 등수 색은 행에 직접 붙인 클래스로 정한다.
   형제 순번(:nth-child)으로 매기면 목록 앞에 이벤트 뱃지나 랭킹 탭이
   끼어드는 순간 색이 한 칸씩 밀린다. */
.rank-item.rank-1,
.rank-item.rank-2,
.rank-item.rank-3 { font-weight: bold; }

.rank-item.rank-1 { color: #ffd700; }
.rank-item.rank-2 { color: #c0c0c0; }
.rank-item.rank-3 { color: #cd7f32; }

.rank-item.my-rank {
  background: rgba(var(--accent-rgb), 0.2);
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  font-weight: bold;
  color: var(--accent) !important;
}

/* 스텝이 돌려 쓰는 계정 표시.
   상위 입상자를 가려낼 때 사용자 기록과 구분하기 위한 것이라,
   등수 색을 가리지 않도록 자기 색을 따로 갖는다. */
.staff-tag {
  display: inline-block;
  margin-left: 0.5em;
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 700;
  /* 얇게 잡아야 이름 칸 줄 높이를 밀어내지 않는다 */
  line-height: 1.2;
  color: #a4b0be;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  /* 글꼴이 글자 위아래에 남기는 여백이 달라 그냥 가운데를 잡으면 알약이
     0.6px 처진다. flex 는 바깥여백까지 포함해 가운데를 잡으므로 아래쪽에
     그 두 배를 줘서 끌어올린다. em 이라 글자 크기를 따라간다.
     이 값으로 1~5등 모든 행에서 알약 글자와 이름 글자가 정확히 나란해진다. */
  margin-bottom: 0.12em;
}

.rank-dots {
  text-align: center;
  color: #747d8c;
  font-size: 12px;
  line-height: 1;
  margin: 2px 0;
}

.rank-my-badge {
  font-size: 12px;
  color: #2ed573;
  margin-bottom: 6px;
  font-weight: bold;
  text-align: center;
}


/* ---------- 게임 중 상단 바 ---------- */
/* 가운데에 무엇을 두는지는 게임마다 다르다(목숨·점수·진행도).
   하지만 왼쪽의 '닉네임 / 로그아웃'과 오른쪽의 '경과 시간'은 세 게임이 같다. */

#ui-layer,
#hud {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  /* 3열 격자. 가운데 열은 내용만큼만 차지하고 양옆이 남는 자리를 똑같이 나눠 갖는다.
     그래서 가운데 항목은 이름 길이와 상관없이 늘 정중앙에 박힌다.
     minmax(0, 1fr) 이라야 왼쪽 열이 자기 몫보다 좁아질 수 있어 말줄임이 걸린다. */
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  /* 450px 일 때 14px. 좁아지면 같이 줄되 11px 아래로는 안 내려간다.
     cqw = 컨테이너 폭의 1%. 3.111cqw × 450 = 14px */
  font-size: clamp(11px, 3.111cqw, 14px);
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  z-index: 10;
}

/* 왼쪽: 👤 닉네임 [로그아웃] */
.hud-user {
  display: flex;
  align-items: center;
  gap: 0.36em;
  pointer-events: auto;
  grid-column: 1;
  min-width: 0;   /* 자리가 모자라면 이름부터 양보한다 */
}

#hud-nickname {
  /* 폭을 고정하지 않는다. 자기 열에 들어가는 만큼 다 보여주고,
     넘칠 때만 말줄임한다. 넓은 기기는 이름이 다 보이고 좁은 기기는 일찍 잘린다. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 오른쪽: ⏱️ 경과 시간
   숫자 폭이 흔들리면 초 단위가 떨려 보이므로 고정폭 숫자를 쓴다 */
.hud-time {
  display: flex;
  align-items: center;
  /* 가운데 항목이 없는 게임(밸런스)에서도 오른쪽 끝에 붙도록 열을 못박는다 */
  grid-column: 3;
  justify-self: end;
  gap: 0.36em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  /* '⏱️ 0.00초' 실측 약 72px. 자릿수가 늘어도 흔들리지 않을 만큼만 잡는다.
     em 으로 두어야 좁은 기기에서 글자와 함께 줄어든다 (14px 기준 80px) */
  min-width: 5.7em;
  justify-content: flex-end;
  white-space: nowrap;
}

/* 가운데: 게임별 표시물.
   무엇이 몇 개 들어가는지는 게임마다 달라서 간격은 각 게임이 정한다. */
.hud-mid {
  display: flex;
  align-items: center;
  grid-column: 2;
  justify-self: center;
  white-space: nowrap;
}

/* 가운데 항목을 감싸는 배지. 배경 위에서도 수치가 또렷하게 읽힌다. */
.hud-badge {
  display: flex;
  align-items: center;
  gap: 0.36em;
  padding: 0.29em 0.71em;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  line-height: 1;
}


/* ---------- 5일 이벤트 랭킹 ---------- */

/* 진행 중 표시. 남은 기간은 서버 시각으로 계산하므로 사용자 시계와 무관하다. */
.event-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 800;
  color: #ff6b81;
  background: rgba(255, 71, 87, 0.12);
  border: 1px solid rgba(255, 71, 87, 0.35);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 8px;
  white-space: nowrap;
}

.event-badge span {
  color: #fff;
  background: #ff4757;
  border-radius: 4px;
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}

/* 이벤트 종료 후: 최종 결과 / 상시 랭킹 전환 */
.rank-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.rank-tab {
  flex: 1;
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  color: #a4b0be;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.rank-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.rank-tab.active {
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.45);
}


/* ---------- 게임 홈 버튼 ---------- */
/* 모달마다 따로 두면 화면별로 빠지거나 위치가 제각각이 된다.
   컨테이너에 하나만 두고, 모달이 떠 있을 때만 보이게 한다. */
#btn-game-home {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 110;              /* 모달(100)보다 위 */
  display: none;             /* 모달이 뜨면 JS 가 켠다 */
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: all 0.2s;
}

#btn-game-home:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
}

#btn-game-home.visible {
  display: flex;
  /* 모달이 fadeIn 으로 나타나는데 버튼만 가만히 있으면 따로 노는 느낌이 든다.
     같은 타이밍으로 함께 나타나게 한다.
     transform 에 translateX(-50%) 가 이미 걸려 있어 전용 키프레임을 쓴다.
     공용 fadeIn 을 그대로 쓰면 가운데 정렬이 깨진다. */
  animation: gameHomeIn 0.25s ease-out;
}

@keyframes gameHomeIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.97); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}
