* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0d1018; }
body { font-family: "Segoe UI", "맑은 고딕", sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; }

#wrap { position: fixed; inset: 0; }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; cursor: crosshair; }

/* HUD */
#hud {
  position: fixed; top: 12px; left: 14px; z-index: 10;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  font-weight: 800; font-size: 15px; color: #cfe3ff;
  text-shadow: 0 2px 6px #000a;
}
#hud span { background: #1a2233cc; padding: 5px 12px; border-radius: 20px; border: 1px solid #ffffff1a; pointer-events: none; }
#hud-stage { color: #7fb4ff; }
#hud-score { color: #ffe08a; }
#hud-kills { color: #ff9a6b; }
#hud-lives { color: #ff5d7a; letter-spacing: 2px; font-size: 15px; }
#hud-special { color: #c08bff; }
#hud-mute { cursor: pointer; pointer-events: auto !important; }

/* 콤보 */
#combo {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 10;
  font-weight: 900; font-size: clamp(24px, 5vw, 44px); color: #ffd24d;
  text-shadow: 0 3px 0 #a8621b, 0 0 22px #ffae3c88; pointer-events: none;
  transition: opacity .2s; letter-spacing: 1px;
}
#combo.hidden { display: none; }

/* 보스바 */
#boss-bar {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 10;
  width: min(560px, 84vw); text-align: center; pointer-events: none;
}
#boss-bar.hidden { display: none; }
#boss-name { font-weight: 900; color: #ff8098; text-shadow: 0 2px 6px #000; font-size: 16px; }
#boss-track { height: 16px; background: #2a0d16; border: 2px solid #ff5d7a55; border-radius: 10px; overflow: hidden; margin-top: 5px; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff2d55, #ff7a3c); transition: width .12s; }

/* 오버레이 */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  justify-content: safe center;   /* 내용이 넘쳐도 위가 잘리지 않음 */
  overflow-y: auto;
  text-align: center; color: #eaf2ff; padding: 12px 20px;
  background: radial-gradient(circle at 50% 40%, #1a2740ee, #070a12f5);
  backdrop-filter: blur(2px);
}
.overlay > * { flex-shrink: 0; }
.overlay.hidden { display: none; }

.overlay h1 {
  font-size: clamp(34px, 7vw, 66px); font-weight: 900; letter-spacing: 4px;
  background: linear-gradient(180deg, #8fd0ff, #3a7bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 20px #2a5cff66);
}
.overlay h1.win {
  background: linear-gradient(180deg, #fff0a0, #ff9d3c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 20px #ffae3c66);
}
.overlay h1.fail {
  background: linear-gradient(180deg, #ff9db0, #e0324a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 20px #e0324a55);
}
#over-stat { font-size: 19px; line-height: 1.9; margin: 6px 0 24px; color: #ffd6de; font-weight: 700; }
#over-stat b { color: #fff; }
.over-btns { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
button.ghost {
  background: #1a2233; color: #cfe0ff; box-shadow: inset 0 0 0 2px #ffffff22;
}
button.ghost:hover { box-shadow: inset 0 0 0 2px #ffffff44; }
.overlay .sub { letter-spacing: 8px; color: #6f86b8; font-weight: 700; margin: 2px 0 10px; font-size: 15px; }

.keys {
  background: #0f1626cc; border: 1px solid #ffffff14; border-radius: 18px;
  padding: 14px; margin-bottom: 10px; color: #c3d3ee;
  width: min(720px, 94vw);
}
.keys b { color: #7fb4ff; }
.keys .dim { color: #6b7ba0; font-size: 13px; }

/* 🎚️ 난이도 */
#diff-row { display:flex; gap:8px; justify-content:center; margin:12px 0 4px; }
.diff-btn {
  font: inherit; font-weight:800; font-size:14px; padding:8px 16px;
  border-radius:20px; cursor:pointer; color:#9fb0d0;
  background:#141c30; border:1.5px solid #ffffff1c; box-shadow:none;
}
.diff-btn.on {
  color:#04101f; background:linear-gradient(180deg,#ffd98a,#f0a129);
  border-color:transparent; box-shadow:0 4px 14px #f0a12955;
}

/* 🏅 업적 */
.ach-head { text-align:center; font-weight:900; color:#ffd68a; padding:6px 0 10px; font-size:16px; }
.ach-lock { opacity:.5; filter:grayscale(.6); }
.ach-lock .up-name { color:#8b97b8; }

/* 🗺️ 스테이지 선택 */
#stage-legend {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  font-size: 12.5px; color: #7d8db4; margin: 2px 0 10px;
}
#stage-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 7px; max-height: 44vh; overflow-y: auto; padding: 4px;
  width: min(560px, 92vw);
}
.sbtn {
  position: relative; font: inherit; font-weight: 900; font-size: 15px;
  padding: 0; height: 50px; border-radius: 12px; cursor: pointer; color: #04101f;
  background: linear-gradient(180deg, #7fc4ff, #3a7bff);
  border: none; box-shadow: 0 4px 0 #1b3a7a, inset 0 1px 0 #ffffff55;
  display: flex; align-items: center; justify-content: center;
}
.sbtn:hover { transform: translateY(-1px); }
.sbtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #1b3a7a; }
.sbtn .si { position: absolute; top: -4px; right: -2px; font-size: 15px; }
.sbtn.mini { background: linear-gradient(180deg, #ffd98a, #f0a129); box-shadow: 0 4px 0 #8a5510, inset 0 1px 0 #ffffff66; }
.sbtn.boss { background: linear-gradient(180deg, #ff9db0, #e0324a); box-shadow: 0 4px 0 #7a1024, inset 0 1px 0 #ffffff55; color: #fff; }
.sbtn.locked {
  background: #1b2437; color: #55618a; cursor: not-allowed;
  box-shadow: none; border: 1px solid #ffffff10;
}
.sbtn.locked .si { position: static; font-size: 17px; opacity: .55; }

/* 조작 카드 — 아이콘 + 이름 + 키캡이 한눈에 */
.key-grid { display: grid; gap: 8px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kcard {
  background: #16203488; border: 1px solid #ffffff12; border-radius: 14px;
  padding: 9px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.kicon { font-size: 27px; line-height: 1; }
.kname { font-weight: 900; font-size: 17px; color: #eaf2ff; letter-spacing: .5px; }
.kkeys { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; justify-content: center; }
.khint { font-size: 12px; color: #7d8db4; }

kbd {
  display: inline-block; min-width: 16px; text-align: center;
  padding: 6px 9px; border-radius: 8px;
  background: linear-gradient(180deg, #35486e, #223050);
  border: 1px solid #ffffff26; box-shadow: 0 3px 0 #0a1120, inset 0 1px 0 #ffffff33;
  color: #dceaff; font-weight: 800; font-size: 14px; font-family: inherit; line-height: 1;
}

.keys .goal { margin-top: 11px; font-size: clamp(16px, 2.4vw, 19px); font-weight: 800; color: #ffd68a; }
.keys .goal b { color: #ffe9a8; }
.keys .unlock { margin-top: 6px; font-size: 12.5px; color: #6b7ba0; }

@media (max-width: 640px) {
  .key-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kicon { font-size: 26px; }
  .kname { font-size: 15px; }
}

button {
  font: inherit; font-weight: 800; font-size: 20px; color: #04101f;
  padding: 12px 44px; border: none; border-radius: 40px; cursor: pointer;
  background: linear-gradient(180deg, #7fc4ff, #3a7bff);
  box-shadow: 0 8px 24px #2a5cff55, inset 0 1px 0 #ffffff66;
  transition: transform .08s ease, box-shadow .08s ease;
}
button:hover { transform: translateY(-2px); box-shadow: 0 12px 30px #2a5cff77, inset 0 1px 0 #ffffff66; }
button:active { transform: translateY(1px) scale(.98); }

#clear-stat { font-size: 19px; line-height: 1.9; margin-bottom: 20px; color: #ffe9c2; font-weight: 700; }
#clear-stat b { color: #fff; }

/* 메인 로비 */
#home-top { position: absolute; top: 22px; right: 24px; }
.gold-badge { background: #1a2233cc; border: 1px solid #ffd24d55; color: #ffe08a; font-weight: 800; padding: 8px 16px; border-radius: 20px; font-size: 17px; }
.home-h1 { font-size: clamp(30px, 7vw, 60px) !important; margin-bottom: 14px; }
#home-tabs { display: flex; gap: 10px; margin-bottom: 18px; }
.htab { font-size: 16px; padding: 10px 22px; border-radius: 24px; background: #141d2e; color: #9fb2d6; box-shadow: none; }
.htab:hover { transform: none; box-shadow: none; }
.htab.active { background: linear-gradient(180deg,#7fc4ff,#3a7bff); color: #04101f; }
.hpanel { display: none; width: min(520px, 92vw); }
.hpanel.active { display: block; }
#hp-play { text-align: center; }
.hp-lead { color: #b9c9e6; line-height: 1.7; margin-bottom: 22px; font-size: 16px; }
.list-box { max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.up-row, .sp-row { display: flex; align-items: center; gap: 12px; background: #101828cc; border: 1px solid #ffffff12; border-radius: 14px; padding: 12px 14px; }
.sp-row.on { border-color: #c08bff88; background: #1a1230cc; }
.up-info { flex: 1; text-align: left; }
.up-name { font-weight: 800; color: #e8f0ff; font-size: 15px; }
.up-lv { color: #7fb4ff; font-size: 13px; margin-left: 4px; }
.up-desc { color: #8fa2c4; font-size: 13px; margin-top: 3px; }
.buy-btn { font-size: 15px; padding: 10px 16px; border-radius: 12px; min-width: 82px;
  background: linear-gradient(180deg,#ffd98a,#f5a63c); color: #3a2200; box-shadow: 0 4px 12px #f5a63c44; }
.buy-btn:hover { transform: translateY(-1px); }
.buy-btn:disabled { background: #2a3346; color: #6f7ea0; cursor: default; box-shadow: none; transform: none; }
button.small { font-size: 15px; padding: 9px 20px; margin-top: 16px; }
.home-foot { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
button.ghost.danger { box-shadow: inset 0 0 0 2px #ff5d7a55; color: #ff9db0; }
button.ghost.danger:hover { box-shadow: inset 0 0 0 2px #ff5d7a99; }

/* 능력 해금 사다리 */
#ability-ladder { margin-top: 20px; text-align: left; background: #0f1626cc; border: 1px solid #ffffff12; border-radius: 14px; padding: 12px 16px; }
.ladder-title { color: #ffd24d; font-weight: 800; font-size: 14px; margin-bottom: 8px; }
.ladder-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; color: #6f7ea0; border-bottom: 1px dashed #ffffff10; }
.ladder-row:last-child { border-bottom: none; }
.ladder-row.ok { color: #cfe3ff; }
.ladder-when { color: #6f86b8; font-size: 12px; }
.ladder-row.ok .ladder-when { color: #7fffb0; }
.dex-cnt { color: #ff9a6b; font-weight: 800; font-size: 13px; align-self: center; }

/* 랭킹 */
.rank-box {
  margin-top: 22px; background: #0f1626cc; border: 1px solid #ffffff14; border-radius: 14px;
  padding: 14px 20px; min-width: 260px; font-size: 15px; color: #c3d3ee;
}
.rank-box.hidden { display: none; }
.rank-box h3 { color: #ffd24d; font-size: 15px; margin-bottom: 8px; letter-spacing: 2px; }
.rank-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed #ffffff12; }
.rank-row:last-child { border-bottom: none; }
.rank-row .rk { color: #7fb4ff; font-weight: 800; }
.rank-row .rs { color: #fff; font-weight: 800; }
.rank-row .rd { color: #6f86b8; font-size: 12px; }
.rank-empty { color: #6f86b8; }

/* 터치 조작 */
#touch { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#touch.hidden { display: none; }
#touch .tpad { position: absolute; bottom: 26px; left: 24px; display: flex; gap: 16px; }
#touch .tacts { position: absolute; bottom: 26px; right: 24px; display: flex; gap: 16px; align-items: flex-end; }
.tbtn {
  pointer-events: auto; width: 66px; height: 66px; border-radius: 50%;
  background: #1a2233bb; border: 2px solid #ffffff2a; color: #dbe8ff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; -webkit-user-select: none; user-select: none;
  box-shadow: 0 6px 16px #0007;
}
.tbtn.big { width: 84px; height: 84px; font-size: 34px; }
.tbtn:active { background: #2a5cff88; transform: scale(.94); }

/* ===== 닉네임 입력 (온라인 랭킹) ===== */
.nick-row { display:flex; align-items:center; gap:8px; margin:12px 0 2px; }
.nick-label { font-size:18px; }
#nick-input {
  width: 200px; padding: 9px 14px; border-radius: 10px;
  background: #101528; border: 1px solid #31406b; color: #e8f0ff;
  font: inherit; font-weight: 700; text-align: center; outline: none;
}
#nick-input:focus { border-color: #7fb4ff; box-shadow: 0 0 0 3px #7fb4ff22; }
#nick-input::placeholder { color: #56648c; font-weight: 400; }

/* ===== 온라인 랭킹 — 상위 3명 강조 ===== */
.rank-row .rn {
  flex: 1; text-align: left; margin: 0 10px; color: #cfe0ff; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-row.top1, .rank-row.top2, .rank-row.top3 {
  border-radius: 8px; padding: 6px 8px; border-bottom: none; margin: 2px 0;
}
.rank-row.top1 { background: linear-gradient(90deg, #ffd24d2e, transparent); }
.rank-row.top2 { background: linear-gradient(90deg, #cdd6ea24, transparent); }
.rank-row.top3 { background: linear-gradient(90deg, #cd7f3226, transparent); }
.rank-row.top1 .rk, .rank-row.top1 .rs { color: #ffd24d; font-size: 15px; }
.rank-row.top2 .rk, .rank-row.top2 .rs { color: #dbe4f5; }
.rank-row.top3 .rk, .rank-row.top3 .rs { color: #e8a35c; }
.rank-row.top1 .rn { color: #fff; }
.rank-row.me { background: #6c7bff22; border-radius: 8px; padding: 5px 8px; border-bottom: none; margin-top: 6px; }
.rank-row.me .rn { color: #aeb9ff; }
