* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0e14;
  font-family: 'Malgun Gothic', sans-serif;
}

canvas {
  display: block;
}

/* ----- 모바일 터치 컨트롤 ----- */
#touchControls {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none; /* 자식 버튼에만 개별적으로 pointer-events를 켠다(빈 공간은 그대로 터치 통과) */
  user-select: none;
  -webkit-user-select: none;
}

#touchControls button {
  pointer-events: auto;
  touch-action: none; /* 더블탭 확대/스크롤 등 브라우저 기본 제스처 방지 */
  background: rgba(20, 24, 32, 0.65);
  color: #f0f4f8;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  font-size: 14px;
  font-weight: bold;
}

#touchControls button:active {
  background: rgba(255, 210, 63, 0.35);
}

.touch-menu-bar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
}

.touch-menu-btn {
  padding: 8px 10px;
  font-size: 12px;
}

.touch-dpad {
  position: fixed;
  left: 18px;
  bottom: 22px;
  width: 150px;
  height: 150px;
}

.touch-dpad-btn {
  position: absolute;
  width: 50px;
  height: 50px;
  font-size: 18px;
}

.touch-dpad-up { top: 0; left: 50px; }
.touch-dpad-down { top: 100px; left: 50px; }
.touch-dpad-left { top: 50px; left: 0; }
.touch-dpad-right { top: 50px; left: 100px; }

.touch-actions {
  position: fixed;
  right: 18px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.touch-actions-row {
  display: flex;
  gap: 10px;
}

.touch-small-btn {
  width: 44px;
  height: 44px;
}

.touch-interact-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.touch-attack-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(192, 72, 60, 0.55);
  font-size: 15px;
}

#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  max-width: min(320px, 78vw);
  color: #f0f4f8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  background: rgba(8, 10, 14, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  pointer-events: none;
  user-select: none;
  z-index: 10;
}

#hudTitle {
  font-size: 18px;
  font-weight: bold;
}

#hudStage {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 2px;
}

#hudNickname {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 6px;
}

#hudMap {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 2px;
}

#hudLevel {
  font-size: 13px;
  margin-top: 4px;
}

#hudHp {
  font-size: 14px;
  font-weight: bold;
  margin-top: 2px;
}

#hudMp {
  font-size: 13px;
  color: #7ec8ff;
  margin-top: 2px;
}

#hudGold {
  font-size: 13px;
  color: #ffd23f;
  margin-top: 2px;
}

#hudSkills {
  font-size: 12px;
  color: #c9a8ff;
  margin-top: 4px;
}

#hudHint {
  font-size: 13px;
  opacity: 0.7;
  margin-top: 6px;
}

#hudCombatLog {
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

#hudFps {
  font-size: 12px;
  opacity: 0.55;
  margin-top: 2px;
}

.hidden {
  display: none !important;
}

#hudTarget {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 14, 20, 0.75);
  border: 1px solid rgba(255, 244, 194, 0.4);
  border-radius: 8px;
  padding: 8px 16px;
  min-width: 160px;
  text-align: center;
  pointer-events: none;
  user-select: none;
  z-index: 10;
}

#hudTargetName {
  color: #fff4c2;
  font-weight: bold;
  font-size: 14px;
}

#hudTargetHpBar {
  margin-top: 5px;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}

#hudTargetHpFill {
  height: 100%;
  background: #c0483c;
  width: 100%;
  transition: width 0.15s;
}

#hudInteract {
  position: fixed;
  bottom: 26%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 14, 20, 0.75);
  color: #ffd23f;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  pointer-events: none;
  user-select: none;
  z-index: 10;
}

#dialogueBox {
  position: fixed;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  width: min(560px, 88vw);
  background: rgba(12, 16, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 16px 20px;
  color: #f0f4f8;
  z-index: 20;
}

#dialogueName {
  font-weight: bold;
  color: #ffd23f;
  margin-bottom: 8px;
}

#dialogueText {
  font-size: 15px;
  line-height: 1.5;
  min-height: 44px;
}

.dialogue-hint {
  margin-top: 10px;
  text-align: right;
  font-size: 12px;
  opacity: 0.6;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, 92vw);
  max-height: 78vh;
  overflow-y: auto;
  background: rgba(12, 16, 24, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 18px 22px;
  color: #f0f4f8;
  z-index: 30;
}

.panel h2 {
  font-size: 18px;
}

.panel h3 {
  font-size: 14px;
  margin-top: 14px;
  margin-bottom: 6px;
  opacity: 0.85;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 10px;
}

.panel-header button {
  margin-left: auto;
}

.panel-gold {
  color: #ffd23f;
  font-size: 14px;
}

.panel-sub {
  font-size: 13px;
  opacity: 0.8;
  margin-top: 8px;
}

.panel-columns {
  display: flex;
  gap: 20px;
}

.panel-column {
  flex: 1;
  min-width: 0;
}

.equip-slot {
  font-size: 14px;
  padding: 6px 0;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  padding: 6px 10px;
}

.item-row button,
.equip-slot button {
  background: #2c3444;
  color: #f0f4f8;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}

.item-row button:hover,
.equip-slot button:hover,
.panel-header button:hover {
  background: #3a4358;
}

.panel-header button {
  background: #2c3444;
  color: #f0f4f8;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  padding: 5px 12px;
  cursor: pointer;
}

.item-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ending-panel {
  text-align: center;
  border-color: #ffd23f;
  box-shadow: 0 0 40px rgba(255, 210, 63, 0.3);
}

.ending-panel h1 {
  color: #ffd23f;
  font-size: 24px;
  margin-bottom: 16px;
}

.ending-text {
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-line;
  margin-bottom: 20px;
}

.ending-panel button {
  background: #ffd23f;
  color: #14100f;
  border: none;
  border-radius: 6px;
  padding: 10px 22px;
  font-weight: bold;
  cursor: pointer;
}

/* ----- 캐릭터 생성 화면 ----- */
#characterCreateScreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at center, #1a2230 0%, #0a0e14 75%);
  overflow-y: auto;
  padding: 24px 16px;
}

.create-panel {
  width: min(480px, 92vw);
  background: rgba(12, 16, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 24px 28px;
  color: #f0f4f8;
}

.create-panel h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.create-panel .subtitle {
  font-size: 13px;
  opacity: 0.75;
  margin-bottom: 18px;
}

.create-panel label,
.section-label {
  display: block;
  font-size: 13px;
  opacity: 0.8;
  margin-bottom: 6px;
}

.section-label {
  margin-top: 18px;
}

#nicknameInput {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 9px 12px;
  color: #f0f4f8;
  font-size: 14px;
}

#nicknameInput:focus {
  outline: none;
  border-color: #ffd23f;
}

.class-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.class-option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.class-option:hover {
  background: rgba(255, 255, 255, 0.09);
}

.class-option.selected {
  border-color: #ffd23f;
  background: rgba(255, 210, 63, 0.1);
}

.class-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}

.class-option-text .class-name {
  font-weight: bold;
  font-size: 14px;
}

.class-option-text .class-desc {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

.error-text {
  color: #ff6b6b;
  font-size: 13px;
  min-height: 18px;
  margin-top: 12px;
}

.start-button {
  width: 100%;
  background: #ffd23f;
  color: #14100f;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.start-button:hover {
  background: #ffdb66;
}

.controls-note {
  text-align: center;
  font-size: 12px;
  opacity: 0.55;
  margin-top: 14px;
}

.continue-panel {
  text-align: center;
}

.continue-summary {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 16px;
  line-height: 1.6;
}

.continue-actions {
  display: flex;
  gap: 10px;
}

.continue-actions .start-button {
  flex: 1;
}

.delete-save-button {
  background: transparent;
  color: #ff6b6b;
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  cursor: pointer;
}

.delete-save-button:hover {
  background: rgba(255, 107, 107, 0.1);
}

/* ----- 모바일 화면 보정 -----
   좁은 화면에서는 원래 레이아웃이 세 군데서 서로 겹쳤다:
   1) HUD가 화면 높이의 40% 이상을 차지해서 게임 화면을 가림
   2) 상단 메뉴 버튼(가방/도감 등)이 그 HUD 글씨 위에 그대로 겹침
   3) 하단 물약/스킬 버튼 줄이 넓어지면서 방향패드와 겹침
   그래서 HUD는 꼭 필요한 정보만 작게 남기고, 메뉴 버튼은 방향패드/액션 버튼 사이 빈 공간으로
   옮기고, 방향패드·액션 버튼 자체도 줄여서 서로 안 닿게 한다. */
@media (max-width: 700px) {
  #hud {
    max-width: 46vw;
    padding: 6px 8px;
    border-radius: 8px;
  }
  #hudTitle { font-size: 12px; }
  #hudStage, #hudHint, #hudFps, #hudNickname { display: none; }
  #hudMap, #hudLevel, #hudHp, #hudMp, #hudGold {
    font-size: 10px;
    margin-top: 1px;
  }
  #hudSkills {
    font-size: 9px;
    margin-top: 2px;
  }
  #hudCombatLog {
    font-size: 10px;
    margin-top: 2px;
  }

  #hudTarget {
    padding: 5px 10px;
    min-width: 110px;
  }
  #hudTargetName { font-size: 11px; }

  /* 상단 좌우 구석 대신, 방향패드/액션 버튼 사이 빈 공간(화면 중앙 하단)에 가로로 배치한다. */
  .touch-menu-bar {
    top: auto;
    right: auto;
    bottom: 118px;
    left: 50%;
    transform: translateX(-50%);
    gap: 4px;
  }
  .touch-menu-btn {
    padding: 5px 7px;
    font-size: 10px;
  }

  .touch-dpad {
    left: 10px;
    bottom: 14px;
    width: 116px;
    height: 116px;
  }
  .touch-dpad-btn {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }
  .touch-dpad-up { top: 0; left: 39px; }
  .touch-dpad-down { top: 78px; left: 39px; }
  .touch-dpad-left { top: 39px; left: 0; }
  .touch-dpad-right { top: 39px; left: 78px; }

  .touch-actions {
    right: 10px;
    bottom: 14px;
    gap: 6px;
  }
  .touch-actions-row {
    gap: 6px;
  }
  .touch-small-btn {
    width: 34px;
    height: 34px;
    font-size: 11px;
  }
  .touch-interact-btn {
    width: 40px;
    height: 40px;
    font-size: 12px;
  }
  .touch-attack-btn {
    width: 56px;
    height: 56px;
    font-size: 12px;
  }
}
