* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #0b0812; color: #f5ead6;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  word-break: keep-all; overflow-wrap: break-word; /* 한국어를 음절 중간에서 자르지 않음 */
}
#wrap { position: fixed; inset: 0; }
#game { width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; touch-action: manipulation; }

/* HUD 버튼: 모든 오버레이 위 (일시정지·레벨업·결과 중에도 소리를 끌 수 있게) */
#hud {
  position: absolute; z-index: 5; display: flex; gap: 8px;
  top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
}
.icon {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid #ffffff30;
  background: #0007; color: #fff; font-size: 18px; cursor: pointer;
}
.icon.wide { width: auto; min-width: 44px; padding: 0 10px; font-size: 13px; font-weight: bold; }

.overlay {
  position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 45%, #0000 0, #0b0812cc 70%);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto; touch-action: pan-y;
}
#levelup, #pause, #end, #shop { background: #0b0812c0; }
.panel {
  text-align: center; max-width: 440px; width: 100%; margin: auto;
  background: #15101fe6; border: 1px solid #ffcf6b40; border-radius: 16px; padding: 18px 20px;
  box-shadow: 0 0 60px #ff9a3c22;
}
.panel.wide { max-width: 780px; }
h1 { margin: 0; font-size: clamp(26px, 8.5vw, 40px); color: #ffcf6b; letter-spacing: 2px; text-shadow: 0 0 24px #ff9a3c88; }
h2 { margin: 0 0 10px; font-size: 22px; color: #ffcf6b; }
#endTitle.won { color: #bfe8ff; }
.sub { margin: 2px 0 10px; font-size: 12px; letter-spacing: 6px; opacity: .65; }
p { line-height: 1.5; margin: 8px 0; }
.hint { font-size: 12px; opacity: .78; }
em { color: #ffcf6b; font-style: normal; font-weight: bold; }
.reward { font-size: 18px; font-weight: bold; color: #ffd36b; margin: 6px 0 2px; min-height: 1em; }
.goal { font-size: 13px; opacity: .9; margin: 2px 0 6px; }
.goal b { color: #9fe6ff; }
.goal .bar { display: block; height: 6px; margin: 5px auto 0; max-width: 240px; background: #ffffff18; border-radius: 3px; overflow: hidden; }
.goal .bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff9a3c, #ffd36b); }

button.big {
  display: block; width: 100%; max-width: 300px; margin: 10px auto 4px;
  padding: 13px 20px; min-height: 54px; font-size: 19px; font-weight: bold; border-radius: 12px; border: 0;
  background: linear-gradient(#ffd36b, #ff9a3c); color: #2a1606; cursor: pointer; box-shadow: 0 4px 0 #a85a1a;
}
button.big:active { transform: translateY(2px); box-shadow: 0 2px 0 #a85a1a; }
button.big.locked { pointer-events: none; opacity: .55; }
#reviveBtn small { opacity: .7; margin-left: 4px; font-size: 15px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
button.secondary {
  min-height: 44px; padding: 8px 16px; font-size: 14px; font-weight: bold; border-radius: 10px;
  border: 1px solid #ffcf6b66; background: #241a33; color: #f5ead6; cursor: pointer; position: relative;
}
button.secondary:hover, button.secondary:focus-visible { background: #33264a; border-color: #ffcf6b; outline: none; }
#doubleBtn { margin: 4px auto; display: block; }
.dot { position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%; background: #ff5a3c; box-shadow: 0 0 8px #ff5a3c; }

/* 밤 단계 선택 */
#tiers { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tier {
  min-height: 44px; min-width: 64px; padding: 6px 10px; border-radius: 10px; border: 1px solid #ffffff30;
  background: #1c1528; color: #f5ead6; font-size: 13px; font-weight: bold; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.tier small { font-size: 12px; color: #ffd36b; font-weight: normal; }
.tier.on { border-color: #ffd36b; background: #3a2a12; box-shadow: 0 0 12px #ffd36b44; }
.tier:disabled { opacity: .45; cursor: default; }

/* 첫 방문 준비 화면 */
#ready { position: absolute; inset: 0; z-index: 2; cursor: pointer; }
#ready .readyName {
  position: absolute; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top)); text-align: center;
  font-size: 22px; font-weight: bold; color: #ffcf6b; letter-spacing: 2px; text-shadow: 0 0 18px #ff9a3c88; pointer-events: none;
}
#ready .readyHint {
  position: absolute; left: 0; right: 0; bottom: calc(18% + env(safe-area-inset-bottom)); text-align: center;
  font-size: 17px; font-weight: bold; color: #fff; text-shadow: 0 2px 10px #000; pointer-events: none;
  animation: lkPulse 1.6s ease-in-out infinite;
}
#ready .readyHook {
  position: absolute; left: 12px; right: 12px; top: calc(96px + env(safe-area-inset-top)); text-align: center;
  font-size: 14px; color: #f5ead6; opacity: .9; text-shadow: 0 2px 8px #000; pointer-events: none;
}
@keyframes lkPulse { 50% { opacity: .45; } }
.why { font-size: 13px; color: #ffd9b0; margin: 4px 0; }

/* 레벨업 카드 */
#cards { display: flex; gap: 10px; justify-content: center; }
#cards.locked { pointer-events: none; opacity: .85; }
.card {
  flex: 1 1 0; min-width: 0; min-height: 120px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  padding: 14px 10px; border-radius: 12px; border: 1px solid #ffcf6b55; background: #241a33; color: #f5ead6;
  font-size: 13px; cursor: pointer; position: relative;
}
.card:hover, .card:focus-visible { background: #33264a; border-color: #ffcf6b; outline: none; }
.card b { font-size: 16px; color: #ffcf6b; }
.card small { opacity: .75; font-size: 12px; }
.card .pair { font-size: 12px; color: #9fd8ff; opacity: .95; }
.card .key { position: absolute; top: 6px; left: 8px; font-size: 12px; opacity: .45; }
.card .tagNew { position: absolute; top: 6px; right: 8px; font-size: 12px; font-weight: bold; color: #7ee0ff; }
.card.evo { background: linear-gradient(#4a3510, #2a1d08); border: 2px solid #ffd36b; box-shadow: 0 0 24px #ffd36b55; }
.card.evo b { color: #fff1b8; }
#rerollBtn { margin-top: 10px; }

/* 공방 */
.shards { font-size: 18px; color: #ffd36b; margin: 4px 0 10px; }
#shopItems { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; text-align: left; }
.shopItem {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: #241a33; border: 1px solid #ffcf6b33;
}
.shopItem .info { flex: 1; min-width: 0; }
.shopItem .info b { display: block; color: #ffcf6b; font-size: 14px; }
.shopItem .info span { display: block; font-size: 12px; opacity: .85; }
.shopItem .pips { font-size: 12px; color: #ffd36b; letter-spacing: 2px; margin-top: 2px; }
.shopItem button { min-width: 84px; min-height: 44px; border-radius: 8px; border: 0; font-weight: bold; cursor: pointer; background: linear-gradient(#ffd36b, #ff9a3c); color: #2a1606; }
.shopItem button:disabled { background: #3a3046; color: #b3a6c4; cursor: default; }

.touch { display: none; }
@media (pointer: coarse) {
  .touch { display: inline; }
  .pc { display: none; }
  .card .key { display: none; }
}
@media (max-height: 480px) {
  h2 { font-size: 18px; margin-bottom: 6px; }
  .panel { padding: 10px 14px; }
  p { margin: 3px 0; line-height: 1.35; }
  .sub { margin-bottom: 4px; }
  button.big { margin: 6px auto 2px; padding: 8px 20px; min-height: 46px; font-size: 17px; }
  .card { padding: 8px 6px; min-height: 96px; }
  .row { margin: 3px 0; }
  .pitch { display: none; }
  #shopItems { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (max-height: 340px) {
  .sub, #best, #title .hint { display: none; }
}
@media (max-width: 560px) and (orientation: portrait) {
  #cards { flex-direction: column; }
  .card { flex: 0 0 auto; min-height: 76px; }
}

/* 홍보 커버·영상 캡처 모드: 모든 DOM 을 숨기고 캔버스(커버 아트)만 */
body.cover #title, body.cover #hud, body.cover #ready { display: none !important; }
