* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b0d12; color: #e8ecf2;
  font-family: system-ui, -apple-system, "Malgun Gothic", "Noto Sans KR", sans-serif;
  touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; overscroll-behavior: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#hud {
  position: fixed; left: 8px; top: 8px; padding: 6px 9px; border-radius: 8px;
  background: rgba(0,0,0,.55); font-size: 12px; line-height: 1.5; pointer-events: none;
  font-variant-numeric: tabular-nums; max-width: 62vw; z-index: 5;
}
#hud b { color: #9fe3a5; font-weight: 600; }
#hud .small { font-size: 10px; opacity: .8; word-break: break-all; }
#hudTitle { font-weight: 700; margin-bottom: 2px; }

#panel {
  position: fixed; right: 8px; top: 8px; width: 170px; padding: 8px; border-radius: 8px;
  background: rgba(0,0,0,.55); font-size: 12px; z-index: 6; display: flex; flex-direction: column; gap: 6px;
}
#panel label { display: flex; flex-direction: column; gap: 3px; }
#panel select, #panel button {
  font: inherit; color: #fff; background: #2a3142; border: 1px solid #44506b; border-radius: 6px; padding: 5px;
}
#panel input[type=range] { width: 100%; }
.btns { display: flex; gap: 6px; }
.btns button { flex: 1; }
.btns button.on { background: #2f7d4a; }

#credits {
  position: fixed; inset: 8% 6%; overflow: auto; padding: 14px 16px; border-radius: 10px;
  background: rgba(10,12,18,.94); border: 1px solid #44506b; z-index: 20; font-size: 13px; line-height: 1.55;
  -webkit-user-select: text; user-select: text; touch-action: pan-y;
}
#credits[hidden] { display: none; }
#credits h2 { margin: 0 0 8px; font-size: 16px; }
#credits a { color: #8ab4ff; }
#credits .warn { color: #ffcf6b; }
#creditClose { float: right; font: inherit; color: #fff; background: #2a3142; border: 1px solid #44506b; border-radius: 6px; padding: 4px 10px; }

#msg {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%); text-align: center; z-index: 10;
  padding: 14px 18px; border-radius: 10px; background: rgba(0,0,0,.7); max-width: 86vw; font-size: 14px;
}
#msg.err { background: rgba(120,20,20,.9); }
#msg.hide { display: none; }
#bar { margin-top: 8px; height: 6px; width: 240px; max-width: 70vw; background: #333; border-radius: 3px; overflow: hidden; }
#barFill { display: block; height: 100%; width: 0; background: #9fe3a5; }

#hint {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; text-align: center;
  padding: 6px 12px; border-radius: 8px; background: rgba(0,0,0,.5); font-size: 12px; pointer-events: none;
}
#hint[hidden], #touchUI[hidden] { display: none; }

#touchUI { position: fixed; inset: 0; pointer-events: none; z-index: 7; }
#joy {
  position: absolute; left: calc(24px + env(safe-area-inset-left)); bottom: calc(28px + env(safe-area-inset-bottom));
  width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.12);
  border: 2px solid rgba(255,255,255,.3); pointer-events: auto; touch-action: none;
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,.45); pointer-events: none;
}
#vbtns {
  position: absolute; right: calc(18px + env(safe-area-inset-right)); bottom: calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
}
#vbtns button {
  width: 48px; height: 48px; border-radius: 50%; font-size: 18px; color: #fff; touch-action: none;
  background: rgba(255,255,255,.22); border: 2px solid rgba(255,255,255,.4);
}
#vbtns button.down { background: rgba(159,227,165,.5); }

@media (max-width: 600px) {
  #panel { width: 140px; font-size: 11px; }
  #hud { font-size: 11px; }
}
