* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: #4a3f63;
  background: #ffd7e8;
  font-family: "Jua", "Baloo 2", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- 높이 / 조작 버튼 ---------- */
#hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  pointer-events: none;
}

/* 시작 화면에서는 높이·소리·다시 시작 버튼을 감춘다 (게임을 시작하면 나타난다) */
#hud.hidden {
  display: none;
}

/* 높이 표시 — 보라색 입체 버튼 (윗면 밝은 보라 → 아랫면 진한 보라 + 아래쪽 두꺼운 그림자) */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 22px;
  color: #fff;
  background: linear-gradient(180deg, #b692f2 0%, #9268de 52%, #7b4bd0 100%);
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 4px 0 #5b34a4, 0 7px 12px rgba(91, 52, 164, 0.32);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(81, 46, 150, 0.7);
}

/* ---------- 상단 가운데 탄(스테이지) 표시 ---------- */
/* 검은 글씨에 흰 굵은 외곽선. ::before 가 같은 글자를 흰색 + 굵은 외곽선으로 뒤에 그려
   주므로, 굵은 외곽선이 검은 글자를 먹지 않고 글자 바깥으로 퍼진다. */
.stage-label {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 0;
  color: #1b1b22;
  font-size: clamp(15px, 4.6vw, 26px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.stage-label::before {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  color: #fff;
  -webkit-text-stroke: 0.34em #fff;
}

#controls {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #6b4fa3;
  background: linear-gradient(180deg, #ffffff, #f2ecff);
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(120, 96, 190, 0.45);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(120, 96, 190, 0.45);
}

.icon-btn:focus-visible {
  outline: 3px solid #ffd0e6;
  outline-offset: 2px;
}

/* ---------- 안내 / 결과 화면 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 240, 248, 0.86), rgba(232, 230, 255, 0.9));
}

.overlay.hidden {
  display: none;
}

.logo {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.logo-title {
  margin: 0;
  padding: 4px 22px;
  color: #fff;
  background: linear-gradient(180deg, #ffb6d5, #ff8fbe);
  border: 3px solid #ffffff;
  border-radius: 18px;
  box-shadow: 0 4px 0 rgba(219, 108, 158, 0.55);
  font-size: clamp(22px, 7vw, 36px);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgba(200, 90, 140, 0.6);
}

.logo-sub {
  color: #7a6a9a;
  font-size: 13px;
  font-weight: 700;
}

.over-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.overlay button.hidden {
  display: none;
}

.overlay h2 {
  margin: 0;
  color: #7a4a86;
  font-size: 24px;
}

.overlay p {
  max-width: 32em;
  margin: 0;
  color: #5a4e78;
  font-size: 15px;
  line-height: 1.55;
}

.overlay button {
  margin-top: 4px;
  padding: 12px 32px;
  color: #fff;
  background: linear-gradient(180deg, #b9a4ef, #9a83dd);
  border: 3px solid #ffffff;
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(120, 96, 190, 0.5);
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}

.overlay button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(120, 96, 190, 0.5);
}

/* ---------- 결과 화면 (성공 'CLEAR!' · 실패 'FAIL!') ---------- */
/* 결과 화면에서는 위쪽 높이·탄·소리·다시 시작 버튼(HUD)을 감춘다 (script.js 에서 숨긴다) */

/* 'CLEAR!' — 둥글둥글한 글씨에 흰 굵은 외곽선.
   바탕 글자는 흰색 + 굵은 외곽선으로 뒤에 두고, ::after 가 같은 글자를
   노랑~분홍 그라데이션으로 위에 덮어 흰 외곽선만 남긴다. */
#overScreen h2.result-clear {
  position: relative;
  z-index: 0;
  margin: 0;
  font-family: "Baloo 2", "Jua", "Malgun Gothic", system-ui, sans-serif;
  font-size: clamp(52px, 16vw, 104px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: #fff;
  -webkit-text-stroke: 0.15em #fff;
  text-shadow: 0 0 20px rgba(255, 196, 226, 0.95), 0 0 42px rgba(255, 214, 120, 0.75);
  animation: clearPop 0.55s cubic-bezier(0.2, 1.5, 0.45, 1) both;
}

#overScreen h2.result-clear::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  -webkit-text-stroke: 0;
  background: linear-gradient(180deg, #fff8bd 0%, #ffd25e 46%, #ff7fba 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 왼쪽 위에서 반짝이는 장식 */
#overScreen h2.result-clear::before {
  content: "\2726";
  position: absolute;
  left: -0.30em;
  top: -0.30em;
  z-index: 3;
  -webkit-text-stroke: 0;
  color: #fff3a6;
  font-size: 0.38em;
  text-shadow: 0 0 14px #ffd76a;
  animation: clearTwinkle 1.5s ease-in-out infinite;
}

@keyframes clearPop {
  0% { transform: scale(0.45) rotate(-9deg); opacity: 0; }
  65% { transform: scale(1.09) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}

@keyframes clearTwinkle {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* 'FAIL!' — 'CLEAR!'와 같은 둥글고 화려한 글씨지만 빨간색.
   흰 굵은 외곽선은 그대로 두고, ::after 가 빨강 그라데이션으로 위에 덮는다. */
#overScreen h2.result-fail {
  position: relative;
  z-index: 0;
  margin: 0;
  font-family: "Baloo 2", "Jua", "Malgun Gothic", system-ui, sans-serif;
  font-size: clamp(52px, 16vw, 104px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: #fff;
  -webkit-text-stroke: 0.15em #fff;
  text-shadow: 0 0 20px rgba(255, 168, 168, 0.95), 0 0 42px rgba(255, 90, 90, 0.7);
  animation: clearPop 0.55s cubic-bezier(0.2, 1.5, 0.45, 1) both;
}

#overScreen h2.result-fail::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  -webkit-text-stroke: 0;
  background: linear-gradient(180deg, #ffd4d4 0%, #ff5f5f 46%, #c81e3a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 왼쪽 위에서 반짝이는 장식 */
#overScreen h2.result-fail::before {
  content: "\2726";
  position: absolute;
  left: -0.30em;
  top: -0.30em;
  z-index: 3;
  -webkit-text-stroke: 0;
  color: #ffd0d0;
  font-size: 0.38em;
  text-shadow: 0 0 14px #ff5a5a;
  animation: clearTwinkle 1.5s ease-in-out infinite;
}

/* ---------- 결과 문구 3줄 — STAGE n(작게) / CLEAR!(크게) / 100 m(작게) ---------- */
.result-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* 성공·실패 화면에서 서로 다른 줄을 쓰므로 잠시 감출 때 쓴다 */
#overScreen .hidden {
  display: none;
}

.result-stage {
  color: #ff7fb5;
  font-size: clamp(15px, 4.2vw, 22px);
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1;
  text-shadow: 0 2px 0 #ffffff, 0 3px 7px rgba(219, 108, 158, 0.4);
}

.result-height {
  color: #8a5fc9;
  font-size: clamp(15px, 4.2vw, 22px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow: 0 2px 0 #ffffff, 0 3px 7px rgba(120, 96, 190, 0.35);
}

/* 결과 화면 버튼 — '다음 단계로' / '다시하기' (볼록한 입체감) */
#overScreen .over-actions button {
  position: relative;
  padding: 15px 36px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
}

/* 위쪽 흰 하이라이트 + 아래쪽 진한 그라데이션 + 두꺼운 바닥 그림자로 볼록하게 */
#nextBtn {
  color: #fff;
  background: linear-gradient(180deg, #ffc7e3 0%, #ff9cca 46%, #ff6fb2 100%);
  text-shadow: 0 1px 0 rgba(196, 70, 132, 0.55);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.9),
    inset 0 -7px 0 rgba(196, 70, 132, 0.42),
    0 8px 0 #cf5590,
    0 13px 18px rgba(207, 85, 144, 0.34);
}

#retryBtn {
  color: #7a4fb8;
  background: linear-gradient(180deg, #ffffff 0%, #f4eeff 50%, #e3d6ff 100%);
  box-shadow:
    inset 0 3px 0 #ffffff,
    inset 0 -7px 0 rgba(160, 130, 215, 0.32),
    0 8px 0 #b9a3e6,
    0 13px 18px rgba(140, 110, 200, 0.32);
}

#overScreen .over-actions button:active {
  transform: translateY(6px);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.55),
    inset 0 -3px 0 rgba(150, 120, 200, 0.28),
    0 2px 0 rgba(140, 110, 200, 0.5);
}

@media (max-height: 520px) {
  #overScreen h2.result-clear,
  #overScreen h2.result-fail {
    font-size: clamp(38px, 13vw, 64px);
  }

  #overScreen .over-actions button {
    padding: 10px 26px;
    font-size: 16px;
  }
}

/* ---------- 시작 화면 (배너 이미지 + 시작 버튼) ---------- */
/* 제목·버튼 글자는 이미지에 들어 있으므로 배너와 버튼만 배치한다.
   배너와 버튼은 하나로 합치지 않고 별도 요소로 두어, 배너 크기가 바뀌면 버튼도 같은 비율로 따라간다. */
.overlay.start-overlay {
  padding: 0;
  gap: 0;
}

.start-banner {
  position: relative;
  /* 배너 원본 1087×1447 의 세로형 비율을 그대로 유지한 채 화면 안에 맞춘다.
     width 기준으로 높이를 정하므로 높이가 화면을 넘지 않는다. */
  aspect-ratio: 1087 / 1447;
  width: min(100%, calc(100vh * 1087 / 1447));
  max-height: 100%;
}

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

/* 배너 위에 겹쳐 놓는 시작 버튼 — 배너 원본 기준 가로 50% · 세로 85% 위치,
   배너 너비의 52% 크기(가로:세로 3:1)로 배너와 같은 비율로 함께 바뀐다. */
.overlay .start-button {
  position: absolute;
  left: 50%;
  top: 85%;
  width: 52%;
  aspect-ratio: 3 / 1;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: translate(-50%, -50%);
  transition: transform 0.08s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.overlay .start-button img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 누르면 95% 크기로 살짝 작아졌다가 복원된다 */
.overlay .start-button:active {
  transform: translate(-50%, -50%) scale(0.95);
  box-shadow: none;
}

.overlay .start-button:focus-visible {
  outline: 3px solid #ffd0e6;
  outline-offset: 4px;
}

@media (max-height: 520px) {
  .overlay {
    gap: 8px;
    padding: 12px;
  }

  .logo-title {
    font-size: 22px;
  }

  .overlay p {
    font-size: 13px;
  }

  .overlay button {
    padding: 9px 24px;
    font-size: 15px;
  }

  .pill {
    padding: 5px 13px;
    font-size: 14px;
  }

  .stage-label {
    top: 11px;
    font-size: 15px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }
}

/* ---------- 모바일 · 태블릿 좌우 조작 버튼 ---------- */
/* 평소에는 감춰 두고, 손가락으로 조작하는 기기에서만 화면 아래 양 끝에 보인다.
   시작·결과 화면(z-index 2)보다 아래에 두어 안내 화면에서는 가려진다. */
#touchPad {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 1;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 14px calc(16px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.arrow-btn {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #6b4fa3;
  background: rgba(255, 255, 255, 0.66);
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 4px 0 rgba(120, 96, 190, 0.35);
  font-size: 26px;
  line-height: 1;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.arrow-btn.on {
  transform: translateY(3px);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 0 rgba(120, 96, 190, 0.35);
}

@media (hover: none), (pointer: coarse) {
  #touchPad {
    display: flex;
  }
}

@media (max-height: 520px) {
  .arrow-btn {
    width: 62px;
    height: 62px;
    font-size: 22px;
  }
}

/* ---------- 랭킹 등록 상태 ---------- */
/* 결과 화면에서 점수 등록 진행·성공·실패 안내를 보여 준다. 내용이 없으면 자리를 차지하지 않는다. */
.ranking-status {
  max-width: 32em;
  color: #6b4fa3;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}

.ranking-status:empty {
  display: none;
}
