* {
  box-sizing: border-box;
  user-select: none;
}

/* ========== 6번: 핀치줌/스크롤/바운스 방지 ========== */
html, body {
  overscroll-behavior: none; /* iOS 바운스 스크롤 방지 */
  touch-action: pan-x pan-y; /* 기본 스크롤 허용하되 핀치줌 방지 */
}
button, a, [role="button"] {
  touch-action: manipulation; /* 더블탭 확대 방지 */
}

/* ========== 5번: Safe Area / 노치 대응 ========== */
#top-ui {
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  padding-top: max(0px, env(safe-area-inset-top));
}


/* ========== 메인화면 ========== */
#main-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 200;
  overflow: hidden;
}

/* main.png 배경 이미지 */
#main-bg-placeholder {
  position: absolute;
  inset: 0;
  background: url('assets/images/main.png') center center / cover no-repeat;
  z-index: 0;
}

/* ::before 장식 제거 */
#main-bg-placeholder::before {
  display: none;
}

/* 타이틀 — main.png에 포함되어 있으므로 숨김 */
#main-title {
  display: none;
}

/* START 버튼 */
#btn-start {
  position: absolute;
  top: 71%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34%;
  z-index: 2;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  outline: none;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s ease;
}

#btn-start:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

#btn-start:active {
  transform: translate(-50%, -50%) scale(0.93);
}

#btn-start-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.25));
  animation: startBtnPulse 1.8s ease-in-out infinite;
}

/* 이미지 없을 때 폴백 텍스트 버튼 */
#btn-start-label {
  display: none;
  font-size: clamp(1.6rem, 4vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.15em;
  color: #ffffff;
  background: linear-gradient(135deg, #333 0%, #111 100%);
  border: 3px solid rgba(255,255,255,0.8);
  border-radius: 50px;
  padding: clamp(12px, 2.5vh, 22px) clamp(40px, 8vw, 80px);
  box-shadow: 0 0 30px rgba(255,255,255,0.2), 0 8px 24px rgba(0,0,0,0.5);
}

@keyframes startBtnPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.92);
  }
}

/* 우상단 버튼 그룹 (가이드 & 랭킹) */
#main-top-buttons {
  position: absolute;
  top: clamp(12px, 3%, 26px);
  right: clamp(12px, 3%, 26px);
  z-index: 3;
  display: flex;
  flex-direction: row;
  gap: clamp(12px, 2vw, 20px);
  align-items: center;
}

/* 우상단 버튼 공통 스타일 - 기존 크기(36~54px)의 2배(72~108px) 확대 */
.main-top-btn {
  width: clamp(72px, 10vw, 108px);
  height: clamp(72px, 10vw, 108px);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.main-top-btn:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.6);
}

.main-top-btn:active {
  transform: scale(0.94);
}

/* 메인화면 hidden */
#main-screen.hidden {
  display: none;
}

/* 게임화면 hidden */
#top-screen.hidden {
  display: none;
}

/* ========== 가이드 오버레이 ========== */
#guide-overlay {
  position: absolute;
  inset: 0;
  z-index: 300;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.88);
  cursor: pointer;
  /* 페이드인/아웃 */
  opacity: 1;
  transition: opacity 0.25s ease;
}

#guide-overlay.hidden {
  display: none;
}

/* 가이드 이미지: 화면 가득 채우되 비율 유지 */
#guide-img {
  max-width: 92%;
  max-height: 90%;
  object-fit: contain;
  border-radius: 12px;
  pointer-events: none;
}

/* 이미지 없을 때 텍스트 플레이스홀더 */
#guide-placeholder {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 20px);
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 24px;
  padding: clamp(32px, 5vh, 60px) clamp(36px, 7vw, 80px);
  max-width: 80%;
  color: #fff;
  text-align: center;
  pointer-events: none;
}

#guide-placeholder h2 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 4.5vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  font-family: 'Fredoka One', sans-serif;
}

#guide-placeholder p {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.8rem);
  line-height: 1.7;
  opacity: 0.9;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

.guide-tap-hint {
  margin-top: clamp(12px, 2vh, 20px) !important;
  font-size: clamp(0.85rem, 1.8vw, 1.3rem) !important;
  opacity: 0.5 !important;
  letter-spacing: 0.08em;
}

body {
  margin: 0;
  padding: 0;
  background-color: #111;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: 'Fredoka One', 'Nunito', 'Segoe UI', sans-serif;
  overflow: hidden;
}

/* ===== KAWAII CANDY POP 디자인 토큰 ===== */
:root {
  --candy-pink:    #FF6EB4;
  --candy-cyan:    #4FD8E8;
  --candy-yellow:  #FFE566;
  --candy-lavender:#C9A8F0;
  --candy-white:   #FFFFFF;
  --candy-dark:    #1a1033;   /* 아웃라인 다크 네이비 */
  --candy-shadow:  rgba(26, 16, 51, 0.35);
  /* 컨테이너 공통 아웃라인 */
  --ui-border: 3px solid var(--candy-dark);
  --ui-radius: 50px;
  --ui-shadow: 3px 4px 0px var(--candy-dark);
}

#game-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  max-width: calc(100vh * (16 / 9));
  aspect-ratio: 16 / 9;
  background-color: #000;
  position: relative;
  cursor: none;
  container-type: size;
  container-name: game;
}

#game-container * {
  cursor: none !important;
}

#cursor-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99999;
  pointer-events: none;
}

@media (min-aspect-ratio: 16/9) {
  #game-container {
    height: 100vh;
    width: calc(100vh * (16 / 9));
  }
}

.screen {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #2c3e50;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* TOP SCREEN */
#top-screen {
  background-color: #a0a0a0; 
  background-image: url('assets/images/top_bg.png');
  background-size: cover;
  background-position: center;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
}

#ufo-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 35;
  pointer-events: none;
}

#top-ui {
  position: absolute;
  top: 1.8cqh;
  left: 0;
  width: 100%;
  padding: 0 2cqw 0 calc(8.5cqh + 2.5cqw);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}

/* 시작 시 화면 어두워지는 효과 (Dim) */
#start-dim {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 40; /* 토스트보단 아래, UI보단 위 */
  transition: opacity 1s ease-out;
}

#start-dim.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

/* 중앙 정렬 UI 그룹 (카운트 + 피버 게이지) */
#center-ui-group {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1.8cqw;
  background: linear-gradient(135deg, var(--candy-cyan) 0%, #a8f0e8 100%);
  padding-left: 2cqw;
  padding-right: 2cqw;
  height: 8.5cqh;
  border-radius: var(--ui-radius);
  border: var(--ui-border);
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.5);
  width: 44cqw;
  flex-shrink: 0;
  overflow: hidden;
  justify-content: space-between;
  pointer-events: auto;
}

/* 카운트 영역 */
#count-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5cqw;
  color: var(--candy-dark);
  font-size: 3.8cqh;
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.03em;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.6);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

#count-white, #count-black {
  display: inline-block;
  min-width: 1.1ch;
  text-align: left;
}

.count-text-img {
  height: clamp(24px, 4vh, 46px);
  width: auto;
  margin-right: 6px;
}
.text-placeholder {
  width: 100px;
  background-color: rgba(255,255,255,0.5);
  border: 1px dashed #333;
}

.count-icon-img {
  width: 5.2cqh;
  height: 5.2cqh;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.placeholder-white { background-color: white; border: 3px solid var(--candy-dark); border-radius: 50%; }
.placeholder-black { background-color: #2a1a3e; border: 3px solid var(--candy-dark); border-radius: 50%; }

.count-x {
  margin: 0 1px 0 2px;
  font-size: 0.85em;
  opacity: 0.8;
}

/* 우상단 체력 하트 아이콘 */
#health-container {
  display: flex;
  align-items: center;
  gap: 0.8cqw;
  background: linear-gradient(135deg, var(--candy-pink) 0%, #ffaad4 100%);
  padding: 0 2cqw;
  height: 8.5cqh;
  border-radius: var(--ui-radius);
  border: var(--ui-border);
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.5);
}

@keyframes heartPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.32); filter: brightness(1.3); }
  100% { transform: scale(1); }
}
.heart-pop { animation: heartPop 0.45s ease-out; }


/* 하트 크기 */
.health-icon {
  width: 5.2cqh;
  height: auto;
  aspect-ratio: 1 / 1;
  filter: drop-shadow(1px 2px 0px var(--candy-dark));
}

.health-icon.placeholder {
  background-color: #ff4757;
  border-radius: 50%;
  border: 3px solid var(--candy-dark);
  box-shadow: 2px 2px 0 var(--candy-dark);
}

.health-icon.placeholder.empty {
  background-color: rgba(255,255,255,0.3) !important;
  border-color: rgba(26,16,51,0.4) !important;
}

/* 스코어 */
#score-container {
  background: linear-gradient(135deg, var(--candy-yellow) 0%, #fff4a0 100%);
  padding: 0 2.2cqw;
  height: 8.5cqh;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ui-radius);
  color: var(--candy-dark);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  font-size: 3.8cqh;
  border: var(--ui-border);
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.6);
  white-space: nowrap;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  min-width: 17cqw;
  font-variant-numeric: tabular-nums;
}

/* 중앙 토스트 메세지 */
#toast-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 35%;
  height: auto;
  z-index: 50;
  transition: opacity 1s ease-out; /* 1초 동안 스르륵 부드럽게 사라짐 */
}

.toast-placeholder {
  background: linear-gradient(135deg, #fff 0%, #ffe8f5 100%);
  padding: 12px 28px;
  border-radius: 40px;
  border: 4px solid var(--candy-dark);
  color: var(--candy-dark);
  text-align: center;
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  font-size: 1.5rem;
  box-shadow: 4px 5px 0 var(--candy-dark);
  letter-spacing: 0.04em;
}

#toast-message.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

/* 구간 전환 배너 */
#wave-banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 45;
  font-size: clamp(2.2rem, 6.5vw, 4.5rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
  /* 기본: 캔디팝 스타일 */
  color: var(--candy-yellow);
  -webkit-text-stroke: 3px var(--candy-dark);
  paint-order: stroke fill;
  text-shadow: 3px 4px 0 var(--candy-dark);
}

#wave-banner.hidden { opacity: 0; }

/* 유형별 색상 */
#wave-banner.type-rush {
  color: var(--candy-pink);
  -webkit-text-stroke: 3px var(--candy-dark);
  text-shadow: 3px 4px 0 var(--candy-dark);
}
#wave-banner.type-rest {
  color: var(--candy-cyan);
  -webkit-text-stroke: 3px var(--candy-dark);
  text-shadow: 3px 4px 0 var(--candy-dark);
}
#wave-banner.type-normal {
  color: var(--candy-yellow);
  -webkit-text-stroke: 3px var(--candy-dark);
  text-shadow: 3px 4px 0 var(--candy-dark);
}
#wave-banner.type-milestone {
  color: var(--candy-lavender);
  -webkit-text-stroke: 3px var(--candy-dark);
  text-shadow: 3px 4px 0 var(--candy-dark), 0 0 20px rgba(201,168,240,0.6);
}



/* 콤보 피버 게이지 */
#combo-gauge-track {
  flex: 1;
  min-width: 18cqw;
  height: 3.4cqh;
  background: rgba(255,255,255,0.55);
  border-radius: 50px;
  border: 2px solid var(--candy-dark);
  overflow: hidden;
  pointer-events: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.18);
  margin-left: 1cqw;
}

#combo-gauge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--candy-yellow) 0%, var(--candy-pink) 100%);
  transition: width 0.2s ease-out;
  border-radius: 50px;
  box-shadow: 0 0 8px rgba(255,110,180,0.5);
}

/* FEVER — 이미지 기반, 화면 중앙(캐릭터 위 공간) */
#fever-label {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44%;
  height: auto;
  max-height: 35vh;
  object-fit: contain;
  z-index: 25;
  pointer-events: none;
  display: none;
}

.fever-active #fever-label {
  display: block;
  animation: feverPop 0.7s ease-out both;
}

@keyframes feverPop {
  0%   { transform: translate(-50%, -50%) scale(0.5) rotate(-4deg); opacity: 0; }
  18%  { transform: translate(-50%, -50%) scale(1.25) rotate(3deg); opacity: 1; }
  34%  { transform: translate(-50%, -50%) scale(0.88) rotate(-2deg); }
  50%  { transform: translate(-50%, -50%) scale(1.14) rotate(1deg); }
  64%  { transform: translate(-50%, -50%) scale(0.94) rotate(-0.5deg); }
  76%  { transform: translate(-50%, -50%) scale(1.06) rotate(0deg); }
  88%  { transform: translate(-50%, -50%) scale(0.98); }
  100% { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}

/* 이미지 없을 때 폴백 — 캔디팝 텍스트 */
#fever-label.fever-fallback-text {
  width: auto;
  height: auto;
  max-width: 90vw;
  max-height: none;
  font-size: clamp(3.5rem, 12vw, 9rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  color: var(--candy-yellow);
  -webkit-text-stroke: 4px var(--candy-dark);
  paint-order: stroke fill;
  text-shadow: 5px 6px 0 var(--candy-dark), 0 0 30px rgba(255,229,102,0.7);
  white-space: nowrap;
  letter-spacing: 0.06em;
}

/* 점수 팝 — 통과 성공마다 캔디팝 플래시 + 확대/축소 */
@keyframes scorePop {
  0%   { transform: scale(1);   }
  30%  { transform: scale(1.9); filter: brightness(1.4) saturate(2); }
  100% { transform: scale(1);   }
}
.score-pop { animation: scorePop 0.4s ease-out; }

@keyframes rainbowText {
  0%   { filter: hue-rotate(0deg) saturate(2.5) brightness(1.1); }
  100% { filter: hue-rotate(360deg) saturate(2.5) brightness(1.1); }
}
.fever-active #score-container,
.fever-active #center-ui-group {
  animation: rainbowText 1.0s linear infinite;
}
.fever-active #fever-label.fever-fallback-text {
  animation: rainbowText 0.8s linear infinite;
}


/* ===== 게임오버 연출 레이어 ===== */
#gameover-anim-layer {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}
#gameover-anim-layer.hidden { display: none; }

#confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -30px;
  animation-name: confettiFallNatural;
  animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation-fill-mode: forwards;
  will-change: transform, opacity;
}

.confetti-square {
  width: var(--size, 12px);
  height: var(--size, 12px);
  border-radius: 2px;
}

.confetti-circle {
  width: var(--size, 10px);
  height: var(--size, 10px);
  border-radius: 50%;
}

.confetti-ribbon {
  width: var(--size, 8px);
  height: calc(var(--size, 8px) * 2.5);
  border-radius: 3px;
}

.confetti-star {
  width: var(--size, 14px);
  height: var(--size, 14px);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

@keyframes confettiFallNatural {
  0% {
    transform: translateY(-5vh) translateX(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  25% {
    transform: translateY(30vh) translateX(calc(var(--drift, 0px) * 0.4 + 15px)) rotate(180deg) scale(0.95);
    opacity: 1;
  }
  50% {
    transform: translateY(60vh) translateX(calc(var(--drift, 0px) * 0.7 - 15px)) rotate(360deg) scale(1.02);
    opacity: 0.95;
  }
  75% {
    transform: translateY(90vh) translateX(calc(var(--drift, 0px) * 0.9 + 10px)) rotate(540deg) scale(0.9);
    opacity: 0.85;
  }
  100% {
    transform: translateY(115vh) translateX(var(--drift, 0px)) rotate(720deg) scale(0.8);
    opacity: 0;
  }
}

#gameover-title-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  pointer-events: none;
  animation: gameoverBounce 1.1s cubic-bezier(0.25, 0.1, 0.25, 1) both;
}

#gameover-title-img {
  width: 44%;
  height: auto;
  max-width: 90%;
}

#gameover-fallback-title {
  display: none;
  font-size: clamp(3.5rem, 12vw, 9rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  color: var(--candy-pink);
  -webkit-text-stroke: 4px var(--candy-dark);
  paint-order: stroke fill;
  text-shadow: 5px 6px 0 var(--candy-dark);
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-align: center;
  margin: 0 auto;
}

/* ===== 공통 팝업 패널 스타일 ===== */
#gameover-choice-popup,
#ranking-register-screen,
#ranking-list-screen {
  position: absolute;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 16, 51, 0.7);
  backdrop-filter: blur(4px);
}
#gameover-choice-popup.hidden,
#ranking-register-screen.hidden,
#ranking-list-screen.hidden { display: none; }

#gameover-choice-panel,
#ranking-register-panel {
  background: linear-gradient(145deg, #fff5fb 0%, #e8f9ff 100%);
  border: 4px solid var(--candy-dark);
  border-radius: 32px;
  padding: clamp(32px, 5vh, 80px) clamp(32px, 4vw, 75px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3vh, 48px);
  width: clamp(340px, 40vw, 840px);
  margin: auto;
  color: var(--candy-dark);
  text-align: center;
  box-shadow: 6px 8px 0 var(--candy-dark);
  font-family: 'Fredoka One', sans-serif;
}

#gameover-final-score {
  font-size: clamp(1.5rem, 3.8vw, 2.5rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  color: var(--candy-dark);
  margin: 0 0 6px;
  letter-spacing: 0.04em;
}

.choice-btn {
  width: 100%;
  height: clamp(56px, 8.5vh, 150px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.25rem, 3vh, 3.2rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.06em;
  color: var(--candy-dark);
  background: linear-gradient(135deg, var(--candy-yellow) 0%, #ffd4a0 100%);
  border: var(--ui-border);
  border-radius: var(--ui-radius);
  cursor: pointer;
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.5);
  transition: transform 0.1s, box-shadow 0.1s;
  white-space: nowrap;
}
.choice-btn:hover {
  transform: translateY(-3px);
  box-shadow: 3px 7px 0 var(--candy-dark), inset 0 2px 0 rgba(255,255,255,0.5);
}
.choice-btn:active {
  transform: translateY(2px);
  box-shadow: 1px 2px 0 var(--candy-dark);
}

#ranking-register-panel h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4.2vw, 2.8rem);
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.06em;
  color: var(--candy-dark);
}

#ranking-list-panel h2 {
  margin: 0;
  font-size: clamp(2.0rem, 5.0vw, 3.4rem);
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.06em;
  color: var(--candy-dark);
}

#ranking-name-input {
  width: 100%;
  height: clamp(50px, 7.5vw, 72px);
  padding: 0 clamp(16px, 2.5vw, 28px);
  font-size: clamp(1.1rem, 2.8vw, 1.7rem);
  font-family: 'Fredoka One', sans-serif;
  border-radius: 50px;
  border: 3px solid var(--candy-dark);
  background: #fff;
  color: var(--candy-dark);
  text-align: center;
  box-shadow: inset 2px 3px 0 rgba(0,0,0,0.08);
}

/* ===== 랭킹 리스트 ===== */
#ranking-list-panel {
  background: linear-gradient(145deg, #fff5fb 0%, #e8f9ff 100%);
  border: 4px solid var(--candy-dark);
  border-radius: 36px;
  padding: clamp(24px, 3.5vh, 44px) clamp(24px, 3.5vw, 48px);
  width: clamp(420px, 58vw, 1100px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.2vh, 24px);
  color: var(--candy-dark);
  text-align: center;
  box-shadow: 6px 8px 0 var(--candy-dark);
  font-family: 'Fredoka One', sans-serif;
}

#ranking-list-body {
  overflow-y: auto;
  max-height: 56vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 14px 6px 6px;
}

.ranking-row {
  display: grid;
  grid-template-columns: clamp(48px, 4.5vw, 75px) 1fr auto;
  gap: clamp(12px, 2vw, 24px);
  align-items: center;
  padding: clamp(12px, 1.8vh, 20px) clamp(18px, 2.5vw, 30px);
  border-radius: 28px;
  font-size: clamp(1.35rem, 3.2vw, 2.1rem);
  border: 2px solid transparent;
  box-sizing: border-box;
}

.ranking-row:nth-child(odd) {
  background: rgba(79, 216, 232, 0.15);
}

.ranking-row-mine {
  background: rgba(255, 229, 102, 0.45) !important;
  border: 3px solid var(--candy-dark);
  font-weight: 900;
  box-shadow: 3px 4px 0 var(--candy-dark);
}

.rank-num {
  color: var(--candy-lavender);
  font-weight: 800;
  font-size: 1.05em;
  filter: drop-shadow(0 1px 0 var(--candy-dark));
}

.rank-name {
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--candy-dark);
  font-size: 1.05em;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.rank-score {
  color: var(--candy-pink);
  font-weight: 800;
  font-size: 1.15em;
  letter-spacing: 0.04em;
}

#ranking-list-buttons {
  display: flex;
  gap: clamp(16px, 2.5vw, 28px);
}
#ranking-list-buttons .choice-btn {
  flex: 1;
}

/* GAME CLEAR MODAL */
#game-clear-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7); /* 70% 딤처리 */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 1s ease-out;
}

#game-clear-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.clear-modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(24px, 4vh, 44px);
  width: min(88%, 460px);
}

#game-clear-img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.placeholder-clear-img {
  width: 100%;
  aspect-ratio: 16/9;
  background-color: #fff;
  border-radius: 20px;
  border: 4px solid #f1c40f;
  display: flex;
  justify-content: center;
  align-items: center;
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="200" viewBox="0 0 400 200"><rect width="400" height="200" fill="%23fff" rx="20"/><text x="200" y="100" font-family="sans-serif" font-size="40" font-weight="bold" text-anchor="middle" alignment-baseline="middle" fill="%23f1c40f">GAME CLEAR!</text></svg>');
}

/* ========== 일시정지 버튼 ========== */
#btn-pause {
  position: absolute;
  top: max(1.8cqh, calc(1.8cqh + env(safe-area-inset-top, 0px)));
  left: max(2cqw, calc(2cqw + env(safe-area-inset-left, 0px)));
  z-index: 30;
  width: 8.5cqh;
  height: 8.5cqh;
  border-radius: 50%;
  border: var(--ui-border);
  background: linear-gradient(135deg, var(--candy-lavender) 0%, #e0c8ff 100%);
  color: var(--candy-dark);
  font-size: 3.8cqh;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.5);
  transition: transform 0.1s, box-shadow 0.1s;
}
#btn-pause:hover {
  transform: scale(1.08);
}
#btn-pause:active {
  transform: scale(0.95);
  box-shadow: 1px 2px 0 var(--candy-dark);
}

#btn-pause-img {
  width: 60%;
  height: 60%;
  object-fit: contain;
  border-radius: 0;
}

#btn-pause-label {
  display: none;
}

/* ========== 일시정지 메뉴 오버레이 ========== */
#pause-menu {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 16, 51, 0.75);
  backdrop-filter: blur(6px);
}

#pause-menu.hidden {
  display: none;
}

#pause-panel {
  position: relative;
  width: clamp(340px, 40vw, 840px);
  background: linear-gradient(145deg, #fff5fb 0%, #e8f9ff 100%);
  border: 4px solid var(--candy-dark);
  border-radius: 32px;
  box-shadow: 6px 8px 0 var(--candy-dark);
  padding: clamp(32px, 5vh, 60px) clamp(32px, 4vw, 75px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3vh, 48px);
}

#pause-panel-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 0;
}

#pause-panel.fallback-style {
}

#pause-menu-buttons {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vh, 36px);
  width: 100%;
}

/* pause 버튼 */
.pause-btn {
  width: 100%;
  height: clamp(56px, 8.5vh, 150px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--candy-yellow) 0%, #ffd4a0 100%);
  border: var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow), inset 0 2px 0 rgba(255,255,255,0.5);
  cursor: pointer;
  padding: 0 clamp(20px, 3vw, 40px);
  transition: transform 0.1s, box-shadow 0.1s;
  overflow: hidden;
  pointer-events: auto;
}
.pause-btn:hover  { transform: translateY(-3px); box-shadow: 3px 7px 0 var(--candy-dark), inset 0 2px 0 rgba(255,255,255,0.5); }
.pause-btn:active { transform: translateY(2px);  box-shadow: 1px 2px 0 var(--candy-dark); }

/* 버튼 이미지가 있을 때 */
.pause-btn img {
  width: auto;
  max-width: 100%;
  max-height: 75%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

/* 버튼 이미지 없을 때 폴백 텍스트 */
.pause-btn span {
  display: none;
  font-size: clamp(1.25rem, 3vh, 3.2rem);
  font-weight: 700;
  font-family: 'Fredoka One', sans-serif;
  letter-spacing: 0.06em;
  color: var(--candy-dark);
  white-space: nowrap;
  line-height: 1;
}

/* ========== HOW TO PLAY 풀스크린 오버레이 ========== */
#howtoplay-overlay {
  position: absolute;
  inset: 0;
  z-index: 40; /* pause-menu(35) 위 */
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.92);
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.25s ease;
}

#howtoplay-overlay.hidden {
  display: none;
}

/* 가이드 이미지: 화면 가득 채우되 비율 유지 */
#howtoplay-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* 이미지 없을 때 텍스트 플레이스홀더 */
#howtoplay-placeholder {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 20px);
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 24px;
  padding: clamp(32px, 5vh, 60px) clamp(36px, 7vw, 80px);
  max-width: 80%;
  color: #fff;
  text-align: center;
  pointer-events: none;
}

#howtoplay-placeholder h2 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 4.5vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  font-family: 'Fredoka One', sans-serif;
}

#howtoplay-placeholder p {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.8rem);
  line-height: 1.7;
  opacity: 0.9;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

/* 배치9 — Firebase 랭킹 로딩 상태 */
.ranking-loading {
  padding: 24px 0;
  color: rgba(255,255,255,0.6);
  font-size: 0.95rem;
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== 세로모드(Portrait) 안내 오버레이 ========== */
#rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a1a;
  /* hidden 클래스로 제어 */
}
#rotate-overlay.hidden {
  display: none;
}
#rotate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
}
#rotate-icon {
  font-size: clamp(3.5rem, 18vw, 6rem);
  animation: rotateHint 1.8s ease-in-out infinite;
  display: inline-block;
}
@keyframes rotateHint {
  0%   { transform: rotate(0deg); }
  30%  { transform: rotate(-85deg); }
  60%  { transform: rotate(-90deg); }
  85%  { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
#rotate-msg {
  margin: 0;
  font-family: 'Fredoka One', 'Nunito', sans-serif;
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  color: #ffffff;
  letter-spacing: 0.02em;
}
#rotate-sub {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: clamp(0.9rem, 3.5vw, 1.3rem);
  color: rgba(255, 255, 255, 0.55);
}
