* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
  font-family: Arial, sans-serif;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #7fd8ff;
}

/* =========================
   배경 이미지
========================= */

.background-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 1.4s ease-in-out;
  pointer-events: none;
}

#backgroundLayer1 {
  background-image: url("images/background1.jpg");
}

#backgroundLayer2 {
  background-image: url("images/background2.jpg");
}

.background-layer.active {
  opacity: 1;
}

/* 잔디 바닥 */
#game::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100px;
  background:
   linear-gradient(90deg, rgba(255,255,255,0.2) 0 8px, transparent 8px 28px),
    linear-gradient(#48c94a, #279b35);
  background-size: 28px 100%, 100% 100%;
  z-index: 5;
}

/* 상단 정보 */
#topInfo {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 50;
  display: flex;
  gap: 10px;
  align-items: center;
}

#scoreBox,
#stageBox,
#invincibilityTimer {
  padding: 10px 16px;
  border: 4px solid #ffd84d;
  border-radius: 16px;
  background: rgba(42, 22, 56, 0.85);
  color: white;
  font-size: 22px;
  font-weight: 900;
}

#invincibilityTimer {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 140;
  min-width: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #fff3b0;
  font-size: clamp(96px, 18vw, 220px);
  line-height: 0.9;
  text-align: center;
  text-shadow:
    0 7px 0 rgba(42, 22, 56, 0.72),
    0 0 22px rgba(255, 123, 26, 0.95),
    0 0 46px rgba(255, 216, 77, 0.7);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* TOP 5 랭킹 */
#rankingBox {
  position: fixed;
  top: 86px;
  right: 20px;
  z-index: 50;
  width: 190px;
  padding: 12px 14px;
  border: 4px solid #ffd84d;
  border-radius: 16px;
  background: rgba(42, 22, 56, 0.85);
  color: white;
  font-weight: 900;
}

#rankingBox strong {
  display: block;
  margin-bottom: 6px;
  color: #ffd84d;
  font-size: 16px;
}

#rankingList {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.45;
}

#rankingList li {
  margin-bottom: 2px;
}

/* 스테이지 배너 */
#stageBanner {
  position: fixed;
  left: 50%;
  top: 25%;
  transform: translateX(-50%);
  z-index: 90;
  padding: 18px 42px;
  border: 3px solid #ffd84d;
  border-radius: 999px;
  background: rgba(42, 22, 56, 0.92);
  color: white;
  font-size: clamp(36px, 8vw, 82px);
  font-weight: 1000;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

#stageBanner.stage-pop {
  animation: stagePop 1.2s ease forwards;
}

@keyframes stagePop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.65);
  }

  20% {
    opacity: 1;
    transform: translateX(-50%) scale(1.08);
  }

  70% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1);
  }
}

/* 플레이어 */
#player {
  position: absolute;
  left: 12vw;
  bottom: 100px;
  width: 95px;
  z-index: 30;
}

#playerImg {
  position: relative;
  z-index: 2;
  width: 100%;
  display: block;
  image-rendering: pixelated;
}

#player.invincible::before {
  content: "";
  position: absolute;
  left: -128px;
  top: 18px;
  width: 168px;
  height: 74px;
  z-index: 1;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.04) 8%, rgba(255, 255, 255, 0.2) 54%, rgba(255, 255, 255, 0.46) 100%),
    radial-gradient(ellipse at 78% 50%, rgba(185, 235, 255, 0.45), transparent 62%),
    radial-gradient(ellipse at 42% 55%, rgba(141, 77, 232, 0.18), transparent 66%);
  filter: blur(2.5px);
  transform-origin: right center;
  animation: speedAfterimage 0.5s infinite alternate ease-in-out;
  pointer-events: none;
}

#player.invincible::after {
  content: "";
  position: absolute;
  left: -182px;
  top: 36px;
  width: 210px;
  height: 42px;
  z-index: 0;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.03) 10%, rgba(255, 255, 255, 0.14) 58%, rgba(255, 255, 255, 0.32) 100%),
    radial-gradient(ellipse at 70% 50%, rgba(145, 210, 255, 0.28), transparent 66%),
    radial-gradient(ellipse at 28% 50%, rgba(141, 77, 232, 0.16), transparent 72%);
  filter: blur(7px);
  animation: softAfterimage 0.86s infinite alternate ease-in-out;
  pointer-events: none;
}

#player.invincible #playerImg {
  animation: rainbowSparkle 0.48s infinite linear;
}

@keyframes speedAfterimage {
  from {
    transform: translateX(0) scaleX(0.96);
    opacity: 0.4;
  }

  to {
    transform: translateX(-24px) scaleX(1.16);
    opacity: 0.72;
  }
}

@keyframes softAfterimage {
  from {
    transform: translateX(0) scaleX(0.92);
    opacity: 0.24;
  }

  to {
    transform: translateX(-34px) scaleX(1.22);
    opacity: 0.48;
  }
}

@keyframes rainbowSparkle {
  0% {
    filter: hue-rotate(0deg) saturate(1.35) drop-shadow(0 0 8px #ff4a4a);
  }

  20% {
    filter: hue-rotate(72deg) saturate(1.55) drop-shadow(0 0 10px #ffd84d);
  }

  40% {
    filter: hue-rotate(144deg) saturate(1.55) drop-shadow(0 0 10px #48c94a);
  }

  60% {
    filter: hue-rotate(216deg) saturate(1.55) drop-shadow(0 0 10px #49b7ff);
  }

  80% {
    filter: hue-rotate(288deg) saturate(1.55) drop-shadow(0 0 10px #b56cff);
  }

  100% {
    filter: hue-rotate(360deg) saturate(1.35) drop-shadow(0 0 8px #ff4a4a);
  }
}

#player.land-effect {
  animation: landSquash 0.12s ease;
}

#player.dead-pop {
  animation: deadPopAndFall 1.25s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
  z-index: 120;
}

@keyframes deadPopAndFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }

  22% {
    transform: translateY(-190px) rotate(-18deg) scale(1.08);
    opacity: 1;
  }

  38% {
    transform: translateY(-155px) rotate(12deg) scale(1.02);
    opacity: 1;
  }

  100% {
    transform: translateY(120vh) rotate(42deg) scale(0.96);
    opacity: 1;
  }
}
@keyframes landSquash {
  0% {
    transform: scale(1, 1);
  }

  50% {
    transform: scale(1.12, 0.86);
  }

  100% {
    transform: scale(1, 1);
  }
}

/* 포인트 */
.coin {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2px solid #fff1a6;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff9b8 0 15%, transparent 16%),
    linear-gradient(145deg, #fff06a 0%, #ffd631 42%, #f4ae00 100%);
  box-shadow:
    inset 0 -3px 0 rgba(128, 84, 0, 0.2),
    0 0 10px rgba(255, 216, 77, 0.7);
  z-index: 24;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.coin::before {
  content: "";
  display: block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(150, 96, 0, 0.72);
  border-radius: 50%;
  background: rgba(255, 246, 147, 0.35);
}

.coin::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 5px;
  width: 5px;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  transform: rotate(28deg);
}

.violet-point {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #8d4de8;
  border: none;
  box-shadow: 0 0 16px rgba(141, 77, 232, 0.9);
  z-index: 24;
}

.violet-point::after {
  content: "+3";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 16px;
  font-weight: 1000;
}

.violet-point.violet-lightning-point {
  width: 48px;
  height: 64px;
  border-radius: 0;
  background: linear-gradient(160deg, #f1dcff 0%, #a95cff 42%, #6e2bd9 100%);
  clip-path: polygon(56% 0, 16% 48%, 44% 48%, 28% 100%, 90% 36%, 60% 36%);
  box-shadow:
    0 0 16px rgba(169, 92, 255, 0.95),
    0 0 26px rgba(110, 43, 217, 0.72);
}

.violet-point.violet-lightning-point::after {
  inset: 0 0 7px 2px;
  font-size: 15px;
  text-shadow: 0 2px 0 rgba(42, 22, 56, 0.62);
  transform: rotate(-8deg);
}

/* 장애물 공통 */
.obstacle {
  position: absolute;
  bottom: 100px;
  z-index: 25;
}

/* 1단 점프 장애물 */
.cone-obstacle {
  width: 52px;
  height: 72px;
  background: linear-gradient(#ff9b1f, #e94f00);
  border-bottom: 10px solid #2a1638;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.cone-obstacle::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 16px;
  height: 8px;
  background: white;
}

.goalpost-obstacle {
  width: 74px;
  height: 78px;
  border: 8px solid white;
  border-bottom: none;
  box-shadow: 0 0 0 3px rgba(42, 22, 56, 0.35);
}

.goalpost-obstacle::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 24px;
  height: 5px;
  background: rgba(255, 255, 255, 0.65);
}

.hurdle-obstacle {
  width: 82px;
  height: 58px;
  border-top: 8px solid white;
  border-left: 7px solid white;
  border-right: 7px solid white;
  box-shadow: 0 0 0 3px rgba(42, 22, 56, 0.35);
}

/* 2단 점프 장애물 */
.high-goalpost-obstacle {
  width: 118px;
  height: 152px;
  border: 10px solid #ffffff;
  border-bottom: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.28) 0 3px, transparent 3px 18px),
    linear-gradient(rgba(255,255,255,0.22) 0 3px, transparent 3px 18px),
    rgba(141, 77, 232, 0.18);
  background-size: 18px 100%, 100% 18px, 100% 100%;
  border-radius: 4px 4px 0 0;
  box-shadow:
    inset 0 0 0 4px rgba(42, 22, 56, 0.12),
    0 0 0 4px rgba(42, 22, 56, 0.38);
}

.high-goalpost-obstacle::after {
  content: "GOAL";
  position: absolute;
  left: 50%;
  top: 36px;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 999px;
  background: #ffd84d;
  color: #2a1638;
  font-size: 13px;
  font-weight: 1000;
  box-shadow: 0 3px 0 rgba(42, 22, 56, 0.35);
}

.high-banner-obstacle {
  width: 96px;
  height: 136px;
  border: 8px solid white;
  background: rgba(141, 77, 232, 0.85);
  box-shadow: 0 0 0 3px rgba(42, 22, 56, 0.35);
}

.high-banner-obstacle::after {
  content: "JUMP";
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  color: #ffd84d;
  font-size: 15px;
  font-weight: 1000;
}

/* 점프하면 안 되는 장애물 */
.overhead-obstacle {
  width: 116px;
  height: 44px;
  border-radius: 18px;
  background: #2a1638;
  border: 5px solid #ffd84d;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.overhead-obstacle::after {
  content: "DOWN";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 15px;
  font-weight: 1000;
}

.plane-obstacle {
  width: 118px;
  height: 48px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 5px solid #2a1638;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.plane-obstacle::before {
  content: "✈";
  position: absolute;
  left: 16px;
  top: -5px;
  font-size: 46px;
}

.plane-obstacle::after {
  content: "";
  position: absolute;
  right: -28px;
  top: 17px;
  width: 34px;
  height: 10px;
  background: #ffd84d;
  border-radius: 999px;
}

/* 사이렌 */
.danger-siren {
  position: absolute;
  width: 58px;
  height: 58px;
  z-index: 26;
  pointer-events: none;
}

.danger-siren::before {
  content: "🚨";
  position: absolute;
  inset: 0;
  font-size: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.4));
}

/* 구덩이 */
.pit {
  position: absolute;
  bottom: 0;
  width: 150px;
  height: 100px;
  background: #1d1324;
  z-index: 12;
}

.pit::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 0 18px, rgba(255,255,255,0.08) 18px 22px, transparent 22px 44px);
  background-size: 44px 44px;
  opacity: 0.4;
}

/* 공통 화면 */
.screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

#startBtn {
  border: none;
  border-radius: 999px;
  padding: 18px 38px;
  background: #8d4de8;
  color: white;
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 0 #2a1638;
}

#startBtn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #2a1638;
}

/* 게임오버 */
.game-over-box {
  width: min(92vw, 580px);
  padding: 34px;
  border: 6px solid #ffd84d;
  border-radius: 28px;
  background: rgba(42, 22, 56, 0.94);
  color: white;
  text-align: center;
}

.game-over-box h1 {
  margin: 0 0 18px;
  color: #ff4a4a;
  font-size: clamp(54px, 9vw, 96px);
  line-height: 0.95;
  text-shadow: 4px 4px 0 #2a1638;
}

.final-info {
  margin-bottom: 20px;
}

.final-info p {
  margin: 8px 0;
  font-size: 24px;
  font-weight: 900;
}

.score-form {
  margin: 18px 0 20px;
}

#playerNameInput {
  width: min(72vw, 260px);
  height: 48px;
  border: 4px solid #ffd84d;
  border-radius: 999px;
  text-align: center;
  font-size: 19px;
  font-weight: 900;
  outline: none;
}

#saveScoreBtn {
  margin-left: 8px;
}

#saveCompleteText {
  margin: 10px 0 0;
  color: #ffd84d;
  font-size: 16px;
  font-weight: 900;
}

.game-over-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

#restartBtn,
#recordScoreBtn,
#mainMenuBtn,
#saveScoreBtn {
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  background: #8d4de8;
  color: white;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #2a1638;
}

#recordScoreBtn {
  background: #ffd84d;
  color: #2a1638;
}

#mainMenuBtn {
  background: #ffffff;
  color: #2a1638;
}

#restartBtn:active,
#recordScoreBtn:active,
#mainMenuBtn:active,
#saveScoreBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #2a1638;
}

/* =========================
   스폰서 배너 비행 연출
========================= */

.sponsor-banner {
  position: absolute;
  width: 230px;
  z-index: 14;
  image-rendering: pixelated;
  pointer-events: none;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.25));
}

.sponsor-banner img {
  width: 100%;
  display: block;
}

.sponsor-string {
  position: absolute;
  left: -38px;
  top: 50%;
  width: 40px;
  height: 3px;
  background: rgba(42, 22, 56, 0.6);
  transform: translateY(-50%);
}

.sponsor-plane {
  position: absolute;
  left: -92px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 48px;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.25));
}

/* 스폰서에서 떨어지는 바이올렛 포인트 */
.falling-violet-point {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #8d4de8;
  border: none;
  box-shadow: 0 0 16px rgba(141, 77, 232, 0.9);
  z-index: 23;
  pointer-events: none;
}

.falling-violet-point::after {
  content: "+3";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 16px;
  font-weight: 1000;
}

.falling-violet-point.violet-lightning-point {
  width: 44px;
  height: 58px;
  border-radius: 0;
  background: linear-gradient(160deg, #f1dcff 0%, #a95cff 42%, #6e2bd9 100%);
  clip-path: polygon(56% 0, 16% 48%, 44% 48%, 28% 100%, 90% 36%, 60% 36%);
  box-shadow:
    0 0 16px rgba(169, 92, 255, 0.95),
    0 0 26px rgba(110, 43, 217, 0.72);
}

.falling-violet-point.violet-lightning-point::after {
  inset: 0 0 6px 2px;
  font-size: 14px;
  text-shadow: 0 2px 0 rgba(42, 22, 56, 0.62);
  transform: rotate(-8deg);
}

/* =========================
   캐릭터 선택창
========================= */

#mainMenu {
  position: relative;
  z-index: 140;
}

#characterSelect {
  position: relative;
  z-index: 140;
  width: min(92vw, 620px);
  padding: 30px;
  border: 6px solid #ffd84d;
  border-radius: 28px;
  background: rgba(42, 22, 56, 0.94);
  color: white;
  text-align: center;
}

#characterSelect h2 {
  margin: 0 0 22px;
  font-size: 34px;
  font-weight: 1000;
  color: #ffd84d;
}

.character-list {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.character-card {
  width: 190px;
  padding: 18px 14px;
  border: 4px solid #ffd84d;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  color: #2a1638;
  cursor: pointer;
  box-shadow: 0 8px 0 #2a1638;
  transition: transform 0.12s ease;
}

.character-card:hover {
  transform: translateY(-4px);
}

.character-card:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #2a1638;
}

.character-card img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 10px;
}

.character-card span {
  display: block;
  font-size: 22px;
  font-weight: 1000;
}

#backToMenuBtn {
  border: none;
  border-radius: 999px;
  padding: 13px 28px;
  background: white;
  color: #2a1638;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #2a1638;
}

#backToMenuBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #2a1638;
}

/* =========================
   메인 시작 화면
========================= */

#startScreen {
  background: transparent;
  z-index: 150;
}

#mainMenu {
  position: relative;
  z-index: 160;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

#gameTitleImg {
  width: min(100vw, 900px);
  max-height: 1000px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.28));
  animation: titlePopUp 0.85s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes titlePopUp {
  0% {
    opacity: 0;
    transform: translateY(120px) scale(0.75);
  }

  65% {
    opacity: 1;
    transform: translateY(-18px) scale(1.06);
  }

  82% {
    transform: translateY(8px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.main-menu-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

#howToPlayBtn,
#startBtn,
#rankingViewBtn,
#backToMenuBtn,
#closeHowToPlayBtn,
#closeRankingBtn {
  border: none;
  border-radius: 999px;
  padding: 15px 28px;
  background: #8d4de8;
  color: white;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #2a1638;
}

#startBtn {
  background: #ffd84d;
  color: #2a1638;
}

#rankingViewBtn {
  background: white;
  color: #2a1638;
}

#howToPlayBtn:active,
#startBtn:active,
#rankingViewBtn:active,
#backToMenuBtn:active,
#closeHowToPlayBtn:active,
#closeRankingBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #2a1638;
}

/* =========================
   캐릭터 선택창
========================= */

#characterSelect {
  position: relative;
  z-index: 160;
  width: min(92vw, 620px);
  padding: 30px;
  border: 6px solid #ffd84d;
  border-radius: 28px;
  background: rgba(42, 22, 56, 0.94);
  color: white;
  text-align: center;
}

#characterSelect h2 {
  margin: 0 0 22px;
  font-size: 34px;
  font-weight: 1000;
  color: #ffd84d;
}

.character-list {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.character-card {
  width: 190px;
  padding: 18px 14px;
  border: 4px solid #ffd84d;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  color: #2a1638;
  cursor: pointer;
  box-shadow: 0 8px 0 #2a1638;
}

.character-card:hover {
  transform: translateY(-4px);
}

.character-card:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #2a1638;
}

.character-card img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 10px;
}

.character-card span {
  display: block;
  font-size: 22px;
  font-weight: 1000;
}

/* =========================
   메뉴 패널
========================= */

.menu-panel {
  position: relative;
  z-index: 170;
  width: min(90vw, 520px);
  padding: 30px;
  border: 6px solid #ffd84d;
  border-radius: 28px;
  background: rgba(42, 22, 56, 0.95);
  color: white;
  text-align: center;
}

.menu-panel h2 {
  margin: 0 0 18px;
  color: #ffd84d;
  font-size: 32px;
}

.menu-panel p {
  margin: 10px 0;
  font-size: 18px;
  font-weight: 800;
}

#menuRankingList {
  margin: 0 auto 22px;
  width: fit-content;
  text-align: left;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.6;
}

/* =========================
   사운드 조절
========================= */

#soundControl {
  position: fixed;
  top: -100px;
  right: 20px;
  z-index: 220;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 3px solid #ffd84d;
  border-radius: 999px;
  background: rgba(42, 22, 56, 0.88);
  color: white;
  font-size: 14px;
  font-weight: 900;
}

#volumeSlider {
  width: 110px;
  accent-color: #ffd84d;
  cursor: pointer;
}

#volumeValue {
  min-width: 26px;
  text-align: right;
  color: #ffd84d;
}

/* =========================
   픽셀 잔디 바닥
========================= */

#game::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 120px;
  background-image: url("images/mobile/ground-tile.png");
  background-repeat: repeat-x;
  background-size: auto 120px;
  image-rendering: pixelated;
  z-index: 6;
  pointer-events: none;
}

/* 모바일 */
@media (max-width: 600px) {
  #backgroundLayer1 {
    background-image: url("images/mobile/background1.jpg");
  }

  #backgroundLayer2 {
    background-image: url("images/mobile/background2.jpg");
  }

  .background-layer {
    transition: opacity 0.45s ease;
  }

  #game::after {
    height: 86px;
    background-image: url("images/mobile/ground-tile.png");
    background-size: auto 86px;
  }

  #player {
    bottom: 82px;
    width: 82px;
  }

  #topInfo {
    top: 14px;
    right: 12px;
    gap: 6px;
  }

  #scoreBox,
  #stageBox,
  #invincibilityTimer {
    font-size: 14px;
    padding: 7px 10px;
    border-width: 3px;
  }

  #invincibilityTimer {
    font-size: clamp(82px, 26vw, 150px);
  }

  #rankingBox {
    top: 76px;
    right: 12px;
    width: 145px;
    padding: 8px 10px;
    border-width: 3px;
  }

  #rankingBox strong {
    font-size: 13px;
  }

  #rankingList {
    font-size: 11px;
    padding-left: 16px;
  }

  .coin {
    width: 24px;
    height: 24px;
  }

  .violet-point {
    width: 40px;
    height: 40px;
  }

  .violet-point::after {
    font-size: 13px;
  }

  .violet-point.violet-lightning-point {
    width: 42px;
    height: 56px;
  }

  .obstacle {
    bottom: 86px;
  }

  .cone-obstacle {
    width: 44px;
    height: 64px;
  }

  .goalpost-obstacle {
    width: 64px;
    height: 68px;
    border-width: 7px;
    border-bottom: none;
  }

  .hurdle-obstacle {
    width: 72px;
    height: 52px;
  }

  .high-goalpost-obstacle {
    width: 82px;
    height: 126px;
    border-width: 8px;
    border-bottom: none;
  }

  .high-banner-obstacle {
    width: 84px;
    height: 118px;
    border-width: 7px;
  }

  .overhead-obstacle {
    width: 100px;
    height: 40px;
  }

  .plane-obstacle {
    width: 104px;
    height: 44px;
  }

  .danger-siren {
    width: 50px;
    height: 50px;
  }

  .danger-siren::before {
    font-size: 42px;
  }

  .pit {
    height: 86px;
    width: 132px;
  }

  #startBtn {
    font-size: 22px;
    padding: 15px 30px;
  }

  .game-over-box {
    padding: 26px 18px;
  }

  .final-info p {
    font-size: 19px;
  }

  .game-over-buttons {
    flex-direction: column;
    align-items: center;
  }

  #restartBtn,
  #recordScoreBtn,
  #mainMenuBtn,
  #saveScoreBtn {
    width: 210px;
    font-size: 17px;
  }

  #saveScoreBtn {
    margin-left: 0;
    margin-top: 10px;
  }

  #playerNameInput {
    width: 210px;
  }

.main-menu-buttons {
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.sub-menu-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

#startBtn {
  width: 270px;
  padding: 19px 0;
  font-size: 26px;
}

#howToPlayBtn,
#rankingViewBtn {
  width: 130px;
  padding: 13px 0;
  font-size: 17px;
}

}

.sponsor-banner {
  width: 165px;
}

.sponsor-plane {
  left: -72px;
  font-size: 36px;
}

.sponsor-string {
  left: -30px;
  width: 32px;
}

.falling-violet-point {
  width: 36px;
  height: 36px;
}

.falling-violet-point::after {
  font-size: 13px;
}

#characterSelect {
  width: 92vw;
  padding: 24px 16px;
}

#characterSelect h2 {
  font-size: 28px;
}

.character-list {
  gap: 14px;
}

.character-card {
  width: 140px;
  padding: 14px 10px;
}

.character-card img {
  width: 92px;
  height: 92px;
}

.character-card span {
  font-size: 18px;
}

#backToMenuBtn {
  width: 180px;
  font-size: 17px;
}

#gameTitleImg {
  width: 96vw;
  max-height: 300px;
  animation: titlePopUpMobile 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes titlePopUpMobile {
  0% {
    opacity: 0;
    transform: translateY(80px) scale(0.78);
  }

  65% {
    opacity: 1;
    transform: translateY(-14px) scale(1.05);
  }

  82% {
    transform: translateY(6px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.main-menu-buttons {
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#howToPlayBtn,
#startBtn,
#rankingViewBtn,
#backToMenuBtn,
#closeHowToPlayBtn,
#closeRankingBtn {
  width: 210px;
  font-size: 18px;
  padding: 14px 22px;
}

#characterSelect {
  width: 92vw;
  padding: 24px 16px;
}

#characterSelect h2 {
  font-size: 28px;
}

.character-list {
  gap: 14px;
}

.character-card {
  width: 140px;
  padding: 14px 10px;
}

.character-card img {
  width: 92px;
  height: 92px;
}

.character-card span {
  font-size: 18px;
}

.menu-panel {
  width: 90vw;
  padding: 24px 18px;
}

.menu-panel h2 {
  font-size: 27px;
}

.menu-panel p {
  font-size: 16px;
}

#soundControl {
  top: 12px;
  right: 12px;
  padding: 7px 9px;
  font-size: 12px;
}

#volumeSlider {
  width: 82px;
}

/* BGM 조절 배너 위치 강제 수정 */
#soundControl {
  position: fixed !important;
  top: 200px !important;
  right: 20px !important;
  bottom: auto !important;
  left: auto !important;
}

/* =========================
   메인 화면 3개 버튼 디자인
========================= */

/* 공통 디자인: 게임 설명 / 게임 시작 / 랭킹 보기 */
#howToPlayBtn,
#startBtn,
#rankingViewBtn {
  border: 4px solid #2a1638;
  border-radius: 18px;
  padding: 16px 34px;
  font-size: 22px;
  font-weight: 1000;
  font-family: Arial, sans-serif;
  cursor: pointer;
  box-shadow: 0 7px 0 #2a1638;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

/* 게임 설명 */
#howToPlayBtn {
  background: #ffffff;
  color: #5b2bbf;
}

/* 게임 시작 */
#startBtn {
  background: #ffd84d;
  color: #2a1638;
}

/* 랭킹 보기 */
#rankingViewBtn {
  background: #8d4de8;
  color: #ffffff;
}

/* 마우스 올렸을 때 */
#howToPlayBtn:hover,
#startBtn:hover,
#rankingViewBtn:hover {
  transform: translateY(-3px);
  filter: brightness(1.05);
}

/* 클릭했을 때 */
#howToPlayBtn:active,
#startBtn:active,
#rankingViewBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #2a1638;
}

/* =========================
   메인 화면 버튼 배치 수정
========================= */

.main-menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.sub-menu-buttons {
  display: flex;
  justify-content: center;
  gap: 14px;
}

/* 게임 시작 버튼: 가운데 크게 */
#startBtn {
  width: 340px;
  padding: 22px 0;
  font-size: 30px;
  font-weight: 1000;
  border-radius: 18px;
}

/* 아래 작은 버튼 2개 */
#howToPlayBtn,
#rankingViewBtn {
  width: 158px;
  padding: 15px 0;
  font-size: 21px;
  font-weight: 1000;
  border-radius: 16px;
}

/* hover / active 효과 정리 */
#startBtn:hover {
  transform: translateY(-3px);
}

#howToPlayBtn:hover,
#rankingViewBtn:hover {
  transform: translateY(-3px);
}

#startBtn:active,
#howToPlayBtn:active,
#rankingViewBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #2a1638;
}

/* 게임 시작 버튼 컬러 */
#startBtn {
  background: #6f2ed6;
  color: #ffffff;
  border-color: #ffd84d;
}

/* 랭킹 보기 버튼 컬러 */
#rankingViewBtn {
  background: #ffffff;
  color: #6f2ed6;
  border-color: #6f2ed6;
}

/* =========================
   로딩 화면
========================= */

#loadingScreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(180deg, #251039 0%, #5b2bbf 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

#loadingScreen.hidden {
  display: none;
}

.loading-box {
  width: min(82vw, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.loading-title {
  width: min(74vw, 460px);
  max-height: 220px;
  object-fit: contain;
  image-rendering: pixelated;
  animation: loadingPop 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.loading-text {
  color: #ffd84d;
  font-size: 28px;
  font-weight: 1000;
  letter-spacing: 2px;
  text-shadow: 0 4px 0 #2a1638;
}

.loading-runner-track {
  --loading-progress: 0;
  position: relative;
  width: 100%;
  height: 70px;
  margin: -2px 0 -14px;
  overflow: visible;
}

.loading-runner-pack {
  position: absolute;
  left: calc(var(--loading-progress) * 1%);
  bottom: 0;
  width: 90px;
  height: 66px;
  transform: translateX(-50%);
  transition: left 0.2s ease;
}

.loading-runner {
  position: absolute;
  bottom: 0;
  width: 48px;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.28));
  animation: loadingRunBob 0.22s infinite steps(2, end);
}

.loading-runner-player1 {
  left: 0;
}

.loading-runner-player2 {
  left: 34px;
  animation-delay: 0.11s;
}

.loading-bar {
  width: 100%;
  height: 22px;
  border: 4px solid #2a1638;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}

#loadingBarFill {
  width: 0%;
  height: 100%;
  background: #ffd84d;
  transition: width 0.2s ease;
}

#loadingPercent {
  color: white;
  font-size: 18px;
  font-weight: 900;
}

@keyframes loadingPop {
  0% {
    opacity: 0;
    transform: translateY(70px) scale(0.8);
  }

  70% {
    opacity: 1;
    transform: translateY(-12px) scale(1.05);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes loadingRunBob {
  0% {
    transform: translateY(0) scaleX(1);
  }

  50% {
    transform: translateY(-5px) scaleX(0.98);
  }

  100% {
    transform: translateY(0) scaleX(1);
  }
}

@media (max-width: 600px) {
  .loading-title {
    width: 86vw;
    max-height: 180px;
  }

  .loading-text {
    font-size: 22px;
  }

  .loading-runner-track {
    height: 56px;
    margin-bottom: -12px;
  }

  .loading-runner-pack {
    width: 72px;
    height: 52px;
  }

  .loading-runner {
    width: 38px;
  }

  .loading-runner-player2 {
    left: 28px;
  }

  .loading-bar {
    height: 18px;
  }
}

@media (max-width: 600px) {
  .sponsor-banner,
  .coin,
  .violet-point,
  .falling-violet-point,
  .obstacle,
  .danger-siren,
  #player {
    filter: none !important;
    box-shadow: none !important;
  }

  .coin,
  .violet-point,
  .falling-violet-point,
  .obstacle,
  .pit,
  .danger-siren,
  .sponsor-banner,
  #player {
    will-change: transform;
    backface-visibility: hidden;
  }

  .coin,
  .violet-point,
  .falling-violet-point,
  .high-goalpost-obstacle,
  .danger-siren::before,
  .sponsor-plane {
    text-shadow: none !important;
    filter: none !important;
    box-shadow: none !important;
  }
}

@media (max-width: 600px) {
  .background-layer {
    transition: opacity 0.4s ease !important;
    filter: none !important;
  }
}

/* 모바일 저전력 모드 */
html.mobile-performance #game {
  contain: layout paint style;
}

html.mobile-performance #backgroundLayer1 {
  background-image: url("images/mobile/background1.jpg");
}

html.mobile-performance #backgroundLayer2 {
  background-image: url("images/mobile/background2.jpg");
}

html.mobile-performance .background-layer {
  transition: opacity 0.15s linear !important;
  filter: none !important;
}

html.mobile-performance #game::after {
  height: 86px;
  background-image: url("images/mobile/ground-tile.png");
  background-size: auto 86px;
}

html.mobile-performance #player.invincible::before {
  left: -72px;
  top: 22px;
  width: 96px;
  height: 42px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.34)
  );
  filter: none;
  animation: mobileAfterimage 0.7s steps(2, end) infinite;
}

html.mobile-performance #player.invincible::after {
  display: none;
}

html.mobile-performance #player.invincible #playerImg {
  filter: none;
  animation: mobileInvincibleBlink 0.65s steps(2, end) infinite;
}

html.mobile-performance #player.land-effect {
  animation: none;
}

html.mobile-performance .sponsor-banner,
html.mobile-performance .coin,
html.mobile-performance .violet-point,
html.mobile-performance .falling-violet-point,
html.mobile-performance .obstacle,
html.mobile-performance .danger-siren,
html.mobile-performance #player {
  filter: none !important;
  box-shadow: none !important;
}

@keyframes mobileAfterimage {
  50% {
    opacity: 0.22;
    transform: translateX(-12px);
  }
}

@keyframes mobileInvincibleBlink {
  50% {
    opacity: 0.7;
  }
}

/* 캐릭터 hover 설명 */
.character-card {
  position: relative;
}

.character-tooltip {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  z-index: 220;
  width: 210px;
  max-width: 210px;
  padding: 10px 12px;
  border: 2px solid #ffd84d;
  border-radius: 10px;
  background: rgba(42, 22, 56, 0.96);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
  text-align: center;
  overflow-wrap: break-word;
  word-break: keep-all;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translate(-8px, -50%);
  transition: opacity 0.14s ease, transform 0.14s ease;
  pointer-events: none;
}

.character-card[data-character="player2"] .character-tooltip {
  left: calc(100% + 8px);
  right: auto;
  transform: translate(8px, -50%);
}

.character-tooltip strong {
  display: block;
  margin-bottom: 5px;
  color: #ffd84d;
  font-size: 12.5px;
  line-height: 1.25;
  font-weight: 1000;
}

.character-card:hover .character-tooltip,
.character-card:focus-visible .character-tooltip {
  opacity: 1;
  transform: translate(0, -50%);
}

.character-card[data-character="player2"]:hover .character-tooltip,
.character-card[data-character="player2"]:focus-visible .character-tooltip {
  transform: translate(0, -50%);
}

@media (max-width: 600px) {
  .character-tooltip {
    left: auto;
    right: calc(100% + 6px);
    top: 50%;
    bottom: auto;
    width: 170px;
    max-width: 170px;
    padding: 9px 10px;
    font-size: 11px;
    transform: translate(-8px, -50%);
  }

  .character-card[data-character="player2"] .character-tooltip {
    left: auto;
    right: calc(100% + 6px);
    transform: translate(-8px, -50%);
  }

  .character-tooltip strong {
    font-size: 11.5px;
  }

  .character-card:hover .character-tooltip,
  .character-card:focus-visible .character-tooltip,
  .character-card[data-character="player2"]:hover .character-tooltip,
  .character-card[data-character="player2"]:focus-visible .character-tooltip {
    transform: translate(0, -50%);
  }
}

/* 모바일 최종 최적화 */
@media (max-width: 600px) {
  html,
  body {
    position: fixed;
    inset: 0;
    overscroll-behavior: none;
    touch-action: none;
  }

  #game {
    height: 100dvh;
    min-height: 100dvh;
  }

  #topInfo {
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: auto;
    display: grid;
    grid-template-columns: auto auto;
    gap: 5px;
  }

  #scoreBox,
  #stageBox {
    padding: 5px 8px;
    border-width: 2px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1;
  }

  #invincibilityTimer {
    left: 50%;
    top: 42%;
    padding: 0;
    border: 0;
    font-size: clamp(82px, 30vw, 140px);
  }

  #rankingBox {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: 96px;
    max-height: 78px;
    padding: 5px 7px;
    border-width: 2px;
    border-radius: 10px;
    overflow: hidden;
  }

  #rankingBox strong {
    margin-bottom: 2px;
    font-size: 10px;
  }

  #rankingList {
    padding-left: 14px;
    font-size: 9px;
    line-height: 1.22;
  }

  #soundControl {
    top: auto !important;
    right: 8px !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    padding: 5px 7px;
    border-width: 2px;
    border-radius: 10px;
    gap: 5px;
    font-size: 10px;
  }

  #volumeSlider {
    width: 58px;
  }

  #volumeValue {
    min-width: 18px;
  }

  #player {
    left: 9vw;
    width: 76px;
  }

  #player.invincible::before {
    left: -96px;
    top: 16px;
    width: 126px;
    height: 58px;
  }

  #player.invincible::after {
    left: -132px;
    top: 30px;
    width: 150px;
    height: 34px;
  }

#stageBanner {
    top: 22%;
    padding: 12px 24px;
    font-size: clamp(34px, 15vw, 58px);
    white-space: nowrap;
  }

  #gameTitleImg {
    width: min(94vw, 390px);
    max-height: 210px;
  }

  .main-menu-buttons {
    gap: 10px;
  }

  .sub-menu-buttons {
    gap: 8px;
  }

  #startBtn {
    width: min(76vw, 270px);
    padding: 16px 0;
    font-size: 24px;
  }

  #howToPlayBtn,
  #rankingViewBtn {
    width: min(36vw, 126px);
    padding: 11px 0;
    font-size: 14px;
    border-radius: 12px;
  }

  #characterSelect {
    width: min(94vw, 360px);
    max-height: 86dvh;
    padding: 18px 12px;
    border-width: 4px;
    border-radius: 18px;
    overflow: visible;
  }

  #characterSelect h2 {
    margin-bottom: 14px;
    font-size: 24px;
  }

  .character-list {
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 16px;
  }

  .character-card {
    width: 138px;
    min-height: 132px;
    padding: 10px 8px;
    border-width: 3px;
    border-radius: 16px;
    box-shadow: 0 5px 0 #2a1638;
  }

  .character-card img {
    width: 76px;
    height: 76px;
    margin-bottom: 6px;
  }

  .character-card span {
    font-size: 16px;
  }

  .character-tooltip,
  .character-card[data-character="player2"] .character-tooltip {
    left: auto;
    right: calc(100% + 8px);
    top: 50%;
    bottom: auto;
    width: min(42vw, 142px);
    max-width: 142px;
    padding: 8px 8px;
    border-width: 2px;
    border-radius: 9px;
    font-size: 10px;
    line-height: 1.25;
    transform: translate(-6px, -50%);
  }

  .character-tooltip strong {
    margin-bottom: 4px;
    font-size: 10.5px;
    line-height: 1.18;
  }

  .character-card:hover .character-tooltip,
  .character-card:focus-visible .character-tooltip,
  .character-card[data-character="player2"]:hover .character-tooltip,
  .character-card[data-character="player2"]:focus-visible .character-tooltip {
    transform: translate(0, -50%);
  }

  #backToMenuBtn {
    width: 160px;
    padding: 11px 0;
    font-size: 14px;
  }

  .menu-panel {
    width: min(92vw, 360px);
    max-height: 84dvh;
    padding: 20px 14px;
    border-width: 4px;
    border-radius: 18px;
    overflow-y: auto;
  }

  .menu-panel h2 {
    font-size: 24px;
  }

  .menu-panel p {
    margin: 7px 0;
    font-size: 13px;
    line-height: 1.35;
  }

  .game-over-box {
    width: min(92vw, 360px);
    max-height: 88dvh;
    padding: 22px 14px;
    border-width: 4px;
    border-radius: 18px;
    overflow-y: auto;
  }

  .game-over-box h1 {
    font-size: clamp(44px, 15vw, 64px);
  }

  #restartBtn,
  #recordScoreBtn,
  #mainMenuBtn,
  #saveScoreBtn,
  #playerNameInput {
    width: min(72vw, 220px);
  }

  .sponsor-banner {
    width: 140px;
  }

}

#practiceGuide {
  position: fixed;
  left: 50%;
  top: 30%;
  z-index: 120;
  padding: 9px 16px;
  border: 2px solid #ffd84d;
  border-radius: 12px;
  background: rgba(42, 22, 56, 0.92);
  color: #ffffff;
  font-size: clamp(15px, 2.6vw, 24px);
  font-weight: 1000;
  line-height: 1.2;
  text-align: center;
  text-shadow: none;
  transform: translateX(-50%);
  pointer-events: none;
}

@media (max-width: 600px) {
  #practiceGuide {
    top: 28%;
    width: min(72vw, 260px);
    padding: 7px 10px;
    border-width: 2px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.18;
  }
}
