/* Slime Press G0 — 화면 배치.
   무대(#stage)는 JS가 360:800 비율로 맞추고 --u(논리 1px의 CSS 크기)를 넣는다.
   캔버스 위 DOM(HUD·안내·화면)은 모두 var(--u) 단위로 배치해 무대와 함께 커지고 작아진다. */

:root {
  color-scheme: dark;
  --bg: #0d1118;
  --ink: #eef2f7;
  --soft: #a9b3c4;
  --panel: rgba(13, 17, 26, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ffd166;
  --good: #6ee7a0;
  --bad: #ff7b6b;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* 주소창 높이 변화 대응: 100dvh(미지원이면 100vh) + 노치·홈 표시줄 안전 영역 */
#app {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  display: grid;
  place-items: center;
}

#stage {
  --u: 1px;
  position: relative;
  width: 360px;
  height: 800px;
  overflow: hidden;
  background: #141a25;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 전장 캔버스에만 터치 제스처(스크롤·확대) 차단. 페이지 전체 확대는 막지 않는다. */
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ───────── HUD (논리 y 0~72) ───────── */
.hud {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(72 * var(--u));
  box-sizing: border-box;
  padding: calc(8 * var(--u)) calc(8 * var(--u)) calc(8 * var(--u)) calc(12 * var(--u));
  display: grid;
  grid-template-columns: 1fr 1.15fr 0.9fr auto;
  align-items: center;
  gap: calc(6 * var(--u));
  background: linear-gradient(#0c1017, #111620);
  border-bottom: 1px solid var(--line);
  pointer-events: none; /* 빈 곳 터치는 아래 캔버스로 — y<80이라 조준되지 않는다 */
}
.hud-cell {
  display: flex;
  flex-direction: column;
  gap: calc(2 * var(--u));
  min-width: 0;
}
.hud-label {
  font-size: calc(11 * var(--u));
  color: var(--soft);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.hud-value {
  font-size: calc(19 * var(--u));
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hud-value small {
  font-size: 0.62em;
  font-weight: 600;
  color: var(--soft);
  margin-left: 0.1em;
}
.hud-time {
  align-items: center;
  text-align: center;
}
.hud-time .hud-value {
  font-size: calc(18 * var(--u));
}
.hud-ammo {
  align-items: flex-end;
  text-align: right;
}
.hud-ammo.empty .hud-value b {
  color: var(--bad);
}
.hud-ammo.full .hud-value b {
  color: var(--accent);
}
.hp-bar {
  display: block;
  height: calc(5 * var(--u));
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.hp-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--good);
  border-radius: inherit;
  transition: width 0.2s ease;
}
.hud-hp.low .hp-bar i {
  background: var(--bad);
}
.hud-hp.low b {
  color: var(--bad);
}
.hud-hp.hit {
  animation: hit 0.35s ease;
}
@keyframes hit {
  0%, 100% { transform: none; }
  25% { transform: translateX(calc(-3 * var(--u))); }
  60% { transform: translateX(calc(3 * var(--u))); }
}

.hud-pause {
  pointer-events: auto;
  width: max(44px, calc(44 * var(--u)));
  height: max(44px, calc(44 * var(--u)));
  border-radius: calc(12 * var(--u));
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
.hud-pause span {
  width: calc(14 * var(--u));
  height: calc(16 * var(--u));
  border-left: calc(5 * var(--u)) solid var(--ink);
  border-right: calc(5 * var(--u)) solid var(--ink);
  box-sizing: border-box;
}
.hud-pause:disabled {
  opacity: 0.35;
  cursor: default;
}

/* 탄창 옆 숫자 (탄창 중심 318, 752) */
.mag-count {
  position: absolute;
  left: calc(318 * var(--u));
  top: calc(786 * var(--u));
  transform: translate(-50%, -50%);
  font-size: calc(12 * var(--u));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
.mag-count.full {
  color: var(--accent);
}

/* ───────── 안내 ─────────
   보정 1차(Codex 시각 검수 1): 진행 중 안내는 적 이동 경로를 가리지 않게 화면 하단(공장 바닥)으로.
   중심 (150, 787), 최대 폭 280, 높이 22 이하, 글자 12, 배경 알파 0.75. 오른쪽 끝 x 290 → 탄창 수량(x 318)과 간격 확보. */
.hint {
  position: absolute;
  left: calc(150 * var(--u));
  top: calc(787 * var(--u));
  transform: translate(-50%, -50%) scale(0.96);
  max-width: calc(280 * var(--u));
  height: calc(22 * var(--u));
  line-height: calc(20 * var(--u));
  box-sizing: border-box;
  padding: 0 calc(10 * var(--u));
  border-radius: 999px;
  background: rgba(9, 12, 19, 0.75);
  border: 1px solid var(--line);
  font-size: calc(12 * var(--u));
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.hint.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.hint[data-tone="good"] {
  color: var(--good);
}
.hint[data-tone="warn"] {
  color: var(--bad);
}
.hint[data-tone="soft"] {
  color: var(--soft);
  font-weight: 600;
}

.toast {
  position: absolute;
  right: calc(8 * var(--u));
  top: calc(712 * var(--u));
  padding: calc(5 * var(--u)) calc(10 * var(--u));
  border-radius: calc(8 * var(--u));
  background: rgba(60, 20, 18, 0.9);
  border: 1px solid rgba(255, 123, 107, 0.5);
  color: #ffd2cb;
  font-size: calc(12 * var(--u));
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(calc(4 * var(--u)));
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.toast.show {
  opacity: 1;
  transform: none;
}

/* ───────── 시작·일시정지·결과 화면 ───────── */
.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 9, 14, 0.62);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.panel {
  width: calc(290 * var(--u));
  box-sizing: border-box;
  padding: calc(24 * var(--u)) calc(20 * var(--u));
  border-radius: calc(18 * var(--u));
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: calc(10 * var(--u));
  text-align: center;
  box-shadow: 0 calc(10 * var(--u)) calc(40 * var(--u)) rgba(0, 0, 0, 0.45);
}
.title {
  margin: 0;
  font-size: calc(36 * var(--u));
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #9ff0c0;
}
.title.small {
  font-size: calc(24 * var(--u));
  color: var(--ink);
}
#result-title[data-result="win"] {
  color: var(--good);
}
#result-title[data-result="lose"] {
  color: var(--bad);
}
.subtitle {
  margin: calc(-4 * var(--u)) 0 0;
  font-size: calc(14 * var(--u));
  color: var(--soft);
}
.lead {
  margin: calc(4 * var(--u)) 0 calc(6 * var(--u));
  font-size: calc(14 * var(--u));
  line-height: 1.55;
}
.note {
  margin: 0;
  font-size: calc(11 * var(--u));
  color: var(--soft);
}
.btn {
  min-height: max(44px, calc(46 * var(--u)));
  border-radius: calc(12 * var(--u));
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font: inherit;
  font-size: calc(16 * var(--u));
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary {
  background: #6ee7a0;
  border-color: #6ee7a0;
  color: #0b1a12;
  font-size: calc(18 * var(--u));
  font-weight: 900;
}
.btn.small {
  min-height: 44px;
  font-size: calc(13 * var(--u));
  font-weight: 600;
  padding: 0 calc(8 * var(--u));
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn:focus-visible,
.hud-pause:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(8 * var(--u));
}
.stats {
  margin: calc(4 * var(--u)) 0 calc(6 * var(--u));
  display: grid;
  gap: calc(6 * var(--u));
}
.stats div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: calc(6 * var(--u)) calc(4 * var(--u));
  border-bottom: 1px solid var(--line);
}
.stats dt {
  font-size: calc(13 * var(--u));
  color: var(--soft);
}
.stats dd {
  margin: 0;
  font-size: calc(16 * var(--u));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* 가로 전환 안내(무대 밖, 화면 전체) */
.rotate {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  background: rgba(6, 9, 14, 0.94);
  z-index: 10;
}
.rotate p {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}
.rotate small {
  color: var(--soft);
  font-size: 14px;
}

/* ?debug=1 */
.debug {
  position: absolute;
  left: calc(4 * var(--u));
  top: calc(76 * var(--u));
  margin: 0;
  padding: 4px 6px;
  max-width: calc(352 * var(--u));
  background: rgba(0, 0, 0, 0.62);
  color: #b8ffea;
  font: 10px/1.35 ui-monospace, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
  z-index: 5;
}

@media (prefers-reduced-motion: reduce) {
  .hud-hp.hit {
    animation: none;
  }
  .hint,
  .toast {
    transition: none;
  }
}
