body {
  margin: 0;
  overflow: hidden;
  background-color: #0b1026;
  font-family: 'Courier New', Courier, monospace;
  user-select: none;
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  /* 자식 요소들이 세로로 끝까지 늘어나 중앙에 배치되는 현상 방지 */
  padding: 20px;
  box-sizing: border-box;
  z-index: 10;
}

.hp-bar-container {
  width: 300px;
  height: 30px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #333;
  border-radius: 15px;
  overflow: hidden;
}

.hp-bar {
  height: 100%;
  transition: width 0.2s;
}

#player-hp {
  background: linear-gradient(90deg, #00f260, #0575e6);
  width: 100%;
}

#enemy-hp {
  background: linear-gradient(90deg, #e43a15, #e65245);
  width: 100%;
}

.resource-box {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: #fff;
  font-size: 24px;
  font-weight: bold;
  text-shadow: 0 0 10px #00f260;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-box {
  position: absolute;
  top: 10px !important;
  /* Force move to top */
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 32px;
  font-weight: bold;
  text-shadow: 0 0 10px #0575e6;
  background: rgba(0, 0, 0, 0.5);
  /* Darker background for readability */
  padding: 10px 30px;
  border-radius: 20px;
  border: 2px solid #0575e6;
  z-index: 100;
  /* High z-index */
  white-space: nowrap;
}

#score-display {
  position: absolute;
  top: 115px !important;
  /* resource-box 아래로 배치 */
  left: 50%;
  transform: translateX(-50%);
  color: #fdbb2d;
  font-size: 28px;
  /* Larger */
  font-weight: bold;
  text-shadow: 0 0 10px rgba(0, 0, 0, 1);
  z-index: 100;
  pointer-events: none;
}

#world-canvas {
  flex: 1;
  background: radial-gradient(circle at center, #1a2a6c, #b21f1f, #fdbb2d);
  background-size: cover;
}

#drawing-area {
  height: 38vh;
  /* 높이를 약간 줄임 */
  max-height: 90vw;
  /* 가로 여백을 위해 90vw로 제한 */
  aspect-ratio: 1 / 1;
  margin: 10px auto 20px;
  /* 위아래 여백 추가 */
  padding: 15px;
  /* 내부 여백 추가 */
  background: #1a1a1a;
  border: 2px solid #00f260;
  /* 전체 테두리 적용 */
  border-radius: 20px;
  /* 둥근 모서리 적용 */
  box-sizing: border-box;
  position: relative;
  box-shadow: 0 0 20px rgba(0, 242, 96, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
  /* Prevent scroll/zoom */
  overflow: hidden;
  /* Ensure nothing sticks out */
  z-index: 101;
  /* Higher than UI layer (100) */
}

#draw-canvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background: transparent;
  /* Let container bg show */
  touch-action: none;
  /* Critical for touch drawing */
  position: relative;
  z-index: 1;
  /* Base drawing layer */
}

/* 메시지 오버레이 (게임오버/시작 등) */
#message-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000000;
  /* Solid black to prevent see-through */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  z-index: 500;
  /* Very high to cover everything */
  color: #fff;
}

#message-title {
  font-size: 60px;
  font-weight: bold;
  margin-bottom: 20px;
  background: linear-gradient(to right, #00f260, #0575e6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
  text-align: center;
  width: 100%;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
  margin-top: 20px;
}

button {
  background: linear-gradient(45deg, #0575e6, #021b79);
  color: white;
  border: none;
  padding: 15px 40px;
  font-size: 22px;
  font-weight: bold;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(5, 117, 230, 0.4);
  transition: transform 0.1s, box-shadow 0.2s;
  border: 1px solid #4a90e2;
  width: 100%;
  max-width: 250px;
}

button.btn-tutorial {
  background: linear-gradient(45deg, #8e44ad, #c0392b);
  border: 1px solid #9b59b6;
  box-shadow: 0 5px 15px rgba(142, 68, 173, 0.4);
  font-size: 18px;
  padding: 12px 30px;
}

button:active {
  transform: translateY(3px);
  box-shadow: none;
}

button:hover {
  filter: brightness(1.2);
}

/* 인식 결과 텍스트 */
#recognition-text {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: #00f260;
  font-weight: bold;
  font-size: 18px;
  pointer-events: none;
  text-shadow: 0 0 5px #00f260;
  width: 100%;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  /* Background for text readability */
  padding: 5px 0;
  z-index: 102;
  /* Above canvas (101) */
  pointer-events: none !important;
}

.guide-panel {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.6);
  padding: 10px;
  border-radius: 5px;
  font-size: 12px;
  text-align: left;
  pointer-events: none;
  border: 1px solid #333;
  color: #ccc;
}

.guide-item {
  margin: 2px 0;
}

.shape-icon {
  display: inline-block;
  width: 12px;
  text-align: center;
  font-weight: bold;
  color: #fff;
}

/* 사운드 컨트롤 버튼 */
#sound-btn {
  background: none;
  border: none;
  color: #00f260;
  font-size: 24px;
  cursor: pointer;
  margin-right: 15px;
  text-shadow: 0 0 10px rgba(0, 242, 96, 0.5);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#sound-btn:hover {
  color: #fff;
  transform: scale(1.1);
}

/* In-game Menu Button */
#ingame-menu-btn {
  display: none !important;
  background: none;
  border: none;
  color: #0575e6;
  font-size: 24px;
  cursor: pointer;
  margin-right: 15px;
  text-shadow: 0 0 10px rgba(5, 117, 230, 0.5);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

#ingame-menu-btn:hover {
  color: #fff;
  transform: scale(1.1);
  text-shadow: 0 0 20px rgba(5, 117, 230, 1);
}

/* Volume Control Panel */
#volume-panel {
  position: absolute;
  top: 50px;
  right: 10px;
  background: rgba(11, 16, 38, 0.95);
  padding: 15px 20px;
  border-radius: 12px;
  border: 1px solid #00f260;
  box-shadow: 0 0 20px rgba(0, 242, 96, 0.3);
  z-index: 100;
  min-width: 150px;
}

#volume-panel .volume-label {
  color: #aab;
  font-size: 12px;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

#volume-panel input[type="range"] {
  width: 100%;
  margin-bottom: 12px;
  accent-color: #00f260;
  cursor: pointer;
}

#volume-panel input[type="range"]:last-child {
  margin-bottom: 0;
}

/* Skill Bar & Repair Container */
#skill-container {
  position: absolute;
  bottom: 45vh;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  z-index: 150;
  pointer-events: auto;
}

#repair-bar {
  display: flex;
  justify-content: center;
  width: 100%;
}

#skill-bar {
  display: flex;
  gap: 15px;
}

/* 모바일 및 세로가 짧은 화면(가로/세로) 대응 */
@media all and (max-width: 600px) {
  .hp-bar-container {
    width: 90px;
    height: 24px;
    /* 모바일에서 HP바 길이 및 두께 축소 */
  }

  .stage-box {
    font-size: 20px;
    padding: 5px 15px;
    top: 20px !important;
    border-radius: 15px;
  }

  .resource-box {
    top: 60px; /* 스테이지 박스가 작아졌으므로 위로 살짝 올림 */
    font-size: 16px;
    gap: 5px;
  }

  #sound-btn,
  #ingame-menu-btn {
    font-size: 18px;
    margin-right: 5px;
  }

  #skill-container {
    transform: translateX(-50%) scale(0.8);
    /* 스킬바 전체 크기 축소 */
    transform-origin: bottom center;
    bottom: 40vh;
    /* 드로잉 영역에 약간 더 가깝게 */
  }
}

@media all and (max-height: 600px) {
  #skill-container {
    transform: translateX(-50%) scale(0.7);
    /* 세로가 짧을 때 더 축소하여 게임 영역 침범 방지 */
    transform-origin: bottom center;
    bottom: 40vh;
  }
}

.skill-btn {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 5px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
  border: 2px solid #555;
}

.skill-btn:active {
  transform: translateY(2px);
}

.skill-btn:disabled {
  filter: grayscale(100%);
  opacity: 0.5;
  cursor: not-allowed;
}

.skill-icon {
  font-size: 24px;
  margin-bottom: 2px;
}

.skill-label {
  font-size: 10px;
  font-weight: bold;
  color: #ddd;
}

.skill-cost {
  font-size: 10px;
  color: #4cd137;
  /* Green for ink cost */
  font-weight: bold;
  position: absolute;
  top: 2px;
  right: 4px;
}

/* Cooldown Overlay - covers the button */
.cooldown-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: rgba(255, 0, 0, 0.5);
  /* Semi-transparent red */
  transition: height 0.1s linear;
  pointer-events: none;
}

/* Unit Specific Colors */
#btn-skill-warrior {
  border-color: #00f260;
}

#btn-skill-archer {
  border-color: #fdbb2d;
}

#btn-skill-golem {
  border-color: #0575e6;
}

#btn-skill-mage {
  border-color: #e056fd;
}