:root {
    --bg-main: #020617;
    --sea-blue: #0284c7;
    --accent-blue: #38bdf8;
    --accent-gold: #fbbf24;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --text-main: #ffffff;
    --text-dim: #94a3b8;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
  html, body {
    height: 100%; overflow: hidden;
    background: #000000; color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
    touch-action: none; overscroll-behavior: none;
  }
  #app {
    width: 100%; max-width: 440px; height: 100dvh; max-height: 100dvh;
    margin: 0 auto; display: flex; flex-direction: column;
    position: relative; overflow: hidden;
    background: #020617;
  }

  /* 상단 HUD (스크린샷 원본 HUD + 스테이지 / 사운드 토글) */
  #hud {
    position: absolute; top: 0; left: 0; right: 0; z-index: 25;
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 10px 6px;
    pointer-events: none;
  }
  .hud-left {
    display: flex; align-items: center; gap: 6px; pointer-events: auto;
  }
  .avatar-card {
    position: relative; width: 42px; height: 42px;
    background: linear-gradient(135deg, #1e3a8a 0%, #0284c7 100%);
    border: 2px solid #38bdf8; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  }
  .avatar-icon { font-size: 22px; }
  .avatar-lvl {
    position: absolute; bottom: -4px; left: -2px;
    background: #0f172a; border: 1px solid #38bdf8;
    color: #fff; font-size: 9px; font-weight: 900;
    padding: 1px 3px; border-radius: 4px;
  }
  .avatar-bolt {
    position: absolute; bottom: -4px; right: -2px;
    background: #15803d; border: 1px solid #4ade80;
    color: #fff; font-size: 9px; font-weight: 900;
    padding: 1px 3px; border-radius: 4px;
  }

  .stage-badge {
    background: rgba(15,23,42,0.85); border: 1.5px solid #38bdf8;
    border-radius: 12px; padding: 4px 8px; font-size: 11px; font-weight: 900;
    color: #38bdf8; letter-spacing: -0.2px; text-shadow: 0 1px 3px #000;
    display: flex; align-items: center; gap: 4px;
  }

  .hud-right {
    display: flex; align-items: center; gap: 5px; flex-wrap: wrap; justify-content: flex-end;
    pointer-events: auto;
  }
  .res-pill {
    display: flex; align-items: center; gap: 3px;
    background: rgba(15,23,42,0.85); border: 1px solid rgba(255,255,255,0.18);
    border-radius: 12px; padding: 3px 6px; font-size: 10.5px; font-weight: 900;
    color: #fff; text-shadow: 0 1px 2px #000;
  }
  .res-star {
    background: rgba(30,41,59,0.9); border: 1px solid #fbbf24;
    color: #fbbf24; font-size: 10.5px; font-weight: 900;
  }

  .btn-sound {
    background: rgba(15,23,42,0.85); border: 1px solid rgba(255,255,255,0.25);
    border-radius: 10px; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; cursor: pointer; color: #fff;
  }

  /* 캔버스 */
  #game {
    flex: 1; width: 100%; height: 100%; display: block;
    cursor: grab;
  }
  #game:active { cursor: grabbing; }

  /* 헬리콥터 공중지원 액션 버튼 */
  #airstrikeBtn {
    position: absolute; right: 14px; bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
    z-index: 24; width: 56px; height: 56px; border-radius: 28px;
    background: linear-gradient(135deg, #1e3a8a 0%, #0284c7 100%);
    border: 2px solid #38bdf8;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #fff; font-size: 10px; font-weight: 900;
    box-shadow: 0 6px 18px rgba(2,132,199,0.6);
    cursor: pointer; transition: transform 0.15s, opacity 0.15s;
  }
  #airstrikeBtn.ready {
    animation: pulseStrike 1.2s infinite;
  }
  #airstrikeBtn.cooldown {
    opacity: 0.55; filter: grayscale(0.5); pointer-events: none;
  }
  #airstrikeBtn .icon { font-size: 20px; line-height: 1; }
  @keyframes pulseStrike {
    0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(56,189,248,0.6); }
    50% { transform: scale(1.08); box-shadow: 0 0 22px rgba(56,189,248,1); }
  }

  /* 하단 안내 배너 */
  #actionPrompt {
    position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    left: 0; right: 0; z-index: 20; text-align: center;
    pointer-events: none;
  }
  .prompt-text {
    display: inline-block;
    font-size: 24px; font-weight: 900; letter-spacing: -0.5px;
    color: #ffffff;
    text-shadow:
      -2.5px -2.5px 0 #0284c7, 2.5px -2.5px 0 #0284c7,
      -2.5px 2.5px 0 #0284c7, 2.5px 2.5px 0 #0284c7,
      0 4px 14px rgba(2,132,199,0.95);
  }

  /* 오버레이 */
  #overlay {
    position: absolute; inset: 0; z-index: 50;
    background: rgba(2,6,23,0.92); backdrop-filter: blur(10px);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 24px; text-align: center;
    transition: opacity 0.25s ease, visibility 0.25s;
  }
  #overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
  #ovTitle {
    font-size: 28px; font-weight: 900; line-height: 1.15;
    background: linear-gradient(135deg, #38bdf8 0%, #fbbf24 60%, #ef4444 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    margin-bottom: 8px; text-shadow: 0 4px 24px rgba(56,189,248,0.4);
  }
  #ovSub {
    font-size: 13.5px; color: var(--text-dim); line-height: 1.5; margin-bottom: 16px;
    max-width: 320px;
  }

  .stars-row {
    display: flex; gap: 8px; font-size: 32px; margin-bottom: 12px;
  }

  .stats-box {
    width: 100%; max-width: 300px; background: rgba(30,41,59,0.7);
    border: 1px solid rgba(255,255,255,0.12); border-radius: 12px;
    padding: 10px 14px; margin-bottom: 16px; display: none;
    flex-direction: column; gap: 6px; text-align: left;
  }
  .stat-row { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; }
  .stat-val { color: #38bdf8; font-weight: 900; }

  #shopRow {
    display: flex; gap: 8px; margin-bottom: 18px; width: 100%; max-width: 300px;
  }
  .shop-card {
    flex: 1; background: rgba(30,41,59,0.7); border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px; padding: 8px 6px; display: flex; flex-direction: column;
    align-items: center; gap: 3px;
  }
  .shop-card .title { font-size: 10.5px; color: var(--text-dim); font-weight: 700; }
  .shop-card .val { font-size: 14px; font-weight: 900; color: #fff; }
  .shop-card button {
    margin-top: 4px; width: 100%; padding: 5px 0; border: none; border-radius: 6px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fff; font-size: 11px; font-weight: 800; cursor: pointer;
    box-shadow: 0 2px 8px rgba(245,158,11,0.4);
  }
  .shop-card button:active { transform: scale(0.96); }

  .stage-selector {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    margin-bottom: 14px; width: 100%; max-width: 350px;
  }
  .stage-pill {
    background: rgba(30, 41, 59, 0.85);
    border: 1.5px solid #475569;
    color: #e2e8f0;
    padding: 6px 3px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: all 0.2s;
  }
  .stage-pill.active {
    background: linear-gradient(135deg, #2563eb, #38bdf8);
    border-color: #60a5fa;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.45);
  }
  .stage-pill:active { transform: scale(0.95); }

  #ovBtn {
    width: 100%; max-width: 280px; padding: 14px 0; border: none; border-radius: 30px;
    background: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
    color: #fff; font-size: 17px; font-weight: 900; letter-spacing: 0.5px;
    cursor: pointer; box-shadow: 0 8px 24px rgba(56,189,248,0.5);
    transition: transform 0.15s ease;
  }
  #ovBtn:active { transform: scale(0.96); }
