:root {
  --primary: #00d4aa;
  --danger: #ff4757;
  --bg: #0f172a;
  --ui-bg: rgba(15, 23, 42, 0.85);
  --invincible: #f9dc5c;
  --shield: #5eead4;
  --toast-bg: #334155;
  --boundary: rgba(255, 255, 255, 0.5);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #05050a; touch-action: none; user-select: none;
  font-family: system-ui, -apple-system, sans-serif;
}

#game-wrapper {
  width: 100%; height: 100%;
  display: flex; justify-content: center; align-items: center;
  position: relative;
}

#game-container {
  position: relative;
  width: 100%; height: 100%;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  overflow: hidden;
  box-shadow: inset 0 0 0 10px var(--boundary);
}
@media (min-width: 768px) {
  #game-container {
    width: 375px; height: 100vh; max-height: 812px;
    border-left: 1px solid #222; border-right: 1px solid #222;
    box-shadow: inset 0 0 0 10px var(--boundary), 0 0 40px rgba(0,0,0,0.8);
  }
}

/* 🔥 화면 흔들림 효과 */
@keyframes screenShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.shake { animation: screenShake 0.35s cubic-bezier(.36,.07,.19,.97) both; }

#player {
  position: absolute;
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 15px var(--primary);
  transform: translate(-50%, -50%);
  z-index: 5;
  will-change: left, top, width, height, box-shadow;
  transition: width 0.2s ease, height 0.2s ease;
}
#player.invincible {
  background: var(--invincible) !important;
  box-shadow: 0 0 20px var(--invincible), 0 0 40px var(--invincible) !important;
  animation: pulsePlayer 0.6s infinite;
}
#player.shield {
  box-shadow: 0 0 18px var(--shield), inset 0 0 8px rgba(255,255,255,0.6), 0 0 30px var(--shield) !important;
}
@keyframes pulsePlayer {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.15); }
}

.bullet {
  position: absolute; width: 16px; height: 16px;
  background: var(--danger); border-radius: 50%;
  box-shadow: 0 0 8px var(--danger);
  transform: translate(-50%, -50%); z-index: 3;
}
.item {
  position: absolute; width: 36px; height: 36px;
  display: flex; justify-content: center; align-items: center;
  font-size: 1.2rem; border-radius: 50%;
  box-shadow: 0 0 12px rgba(255,255,255,0.5);
  transform: translate(-50%, -50%); z-index: 4;
}
@keyframes itemBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
.item.blink { animation: itemBlink 0.4s infinite; pointer-events: none; }
.item[data-type="shrink"] { background: #8ecae6; }
.item[data-type="invincible"] { background: var(--invincible); }
.item[data-type="skip"] { background: var(--shield); }
.item[data-type="slow"] { background: #a78bfa; }
.item[data-type="clear"] { background: #fca311; }

#ui-layer {
  position: absolute; top: 20px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
  z-index: 10; pointer-events: none; gap: 8px;
}
#timer {
  font-size: 2rem; font-weight: 800; color: #fff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
}
#effect-status {
  font-size: 0.9rem; font-weight: 600; color: #cbd5e1;
  background: rgba(0,0,0,0.6); padding: 4px 10px;
  border-radius: 12px; opacity: 0; transition: opacity 0.3s;
}
#effect-status.visible { opacity: 1; }

#start-btn {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 32px; background: var(--primary); color: #000;
  font-size: 1.2rem; font-weight: bold; border: none;
  border-radius: 12px; cursor: pointer; z-index: 11;
}
#start-btn:active { transform: translate(-50%, -50%) scale(0.95); }

#joystick-wrapper {
  position: absolute; width: 120px; height: 120px;
  pointer-events: none; z-index: 20;
  transform: translate(-50%, -50%); display: none;
}
#joystick-base {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.15); border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}
#joystick-stick {
  position: absolute; top: 50%; left: 50%;
  width: 48px; height: 48px; background: rgba(255,255,255,0.5);
  border-radius: 50%; transform: translate(-50%, -50%);
  will-change: transform; /* ✅ transition을 지우고 하드웨어 가속을 켜줍니다 */
}

#modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  z-index: 30; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
#modal.visible { opacity: 1; pointer-events: auto; }
#modal h2 { color: #fff; font-size: 2rem; margin-bottom: 8px; text-align: center; }
#modal p { color: #ccc; font-size: 1.1rem; margin-bottom: 20px; text-align: center; }
#modal em { color: var(--primary); font-style: normal; font-weight: bold; }

#share-area {
  position: absolute; top: 16px;
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 35;
  width: 280px; justify-content: flex-end;
}
.share-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; background: rgba(255,255,255,0.15); color: #fff;
  transition: transform 0.15s, background 0.15s;
}
.share-btn:hover { transform: scale(1.1); background: rgba(255,255,255,0.25); }
.share-btn:active { transform: scale(0.95); }
.share-btn.copy { background: #6366f1; }
.share-btn.kakao { background: #fee500; color: #3c1e1e; }
.share-btn.facebook { background: #1877f2; }
.share-btn.x { background: #000; border: 1px solid #333; }

#leaderboard-list {
  list-style: none; width: 280px;
  background: var(--ui-bg); border-radius: 12px;
  padding: 16px; margin-bottom: 24px;
}
#leaderboard-list li {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  align-items: center;
  color: #fff; padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  gap: 8px;
}
#leaderboard-list li:last-child { border-bottom: none; }
#leaderboard-list span { 
  color: var(--primary); 
  font-weight: 700;
  white-space: nowrap;
}
#leaderboard-list strong { 
  text-align: center; 
  color: #aaa; 
  font-size: 0.85rem;
  white-space: nowrap;
}
#leaderboard-list em { 
  text-align: right; 
  color: var(--primary);
  font-weight: 700;
  white-space: nowrap;
  font-size: 1.05rem;
}
@media (max-width: 380px) {
  #leaderboard-list { width: 260px; padding: 12px; }
  #leaderboard-list li { 
    grid-template-columns: 40px 1fr auto;
    padding: 8px 0;
    gap: 6px;
  }
  #leaderboard-list span { font-size: 0.9rem; }
  #leaderboard-list strong { font-size: 0.8rem; }
  #leaderboard-list em { font-size: 0.95rem; }
}

#restart-btn {
  padding: 14px 28px; background: var(--danger); color: #fff;
  font-size: 1.1rem; font-weight: bold; border: none;
  border-radius: 10px; cursor: pointer;
}
#restart-btn:active { transform: scale(0.95); }
.hidden { display: none !important; }

@keyframes effectEnd { 0% { box-shadow: 0 0 30px currentColor; } 100% { box-shadow: 0 0 0 currentColor; } }
.flash-end { animation: effectEnd 0.4s ease-out; }

#toast {
  position: fixed; bottom: 124px;
  left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--toast-bg); color: #fff;
  padding: 12px 24px; border-radius: 8px;
  font-size: 0.95rem; font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 100; opacity: 0; transition: transform 0.3s ease, opacity 0.3s ease;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

#kakao-ad-container {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 100px; background: #111;
  display: flex; justify-content: center; align-items: center;
  z-index: 1;
  pointer-events: auto;
}
#kakao-ad-container .kakao_ad_area {
  display: block !important;
  margin: 0 auto;
}
@media (max-width: 374px) {
  #kakao-ad-container { height: 100px; }
}