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

body {
  background-color: #1a1e1b;
  font-family: 'Do Hyeon', 'Jua', sans-serif;
  color: #f1f5f2;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

#game-container {
  position: relative;
  width: 960px;
  height: 540px;
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(78, 110, 80, 0.3);
  border: 4px solid #3d4a3e;
  border-radius: 8px;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* 상단 HUD */
.hud-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0) 100%);
  z-index: 10;
}

.hud-panel {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge-stage {
  background: #2b3a2f;
  color: #92e697;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #4a634e;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.badge-rank {
  background: #3e2f1f;
  color: #fbd38d;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #6c5438;
  font-size: 14px;
  font-weight: bold;
}

.skill-slot {
  background: #3f2e1a !important;
  color: #ffda79 !important;
  border-color: #8b6533 !important;
}

.touch-btn.skill-btn {
  width: 72px;
  font-size: 14px;
  background: rgba(90, 60, 20, 0.9);
  border-color: #f59e0b;
  color: #fef08a;
}

/* 계급 선택 카드 스타일 */
.rank-select-box {
  max-width: 780px !important;
  padding: 22px 28px !important;
}

.rank-selection-container {
  margin-bottom: 16px;
}

.rank-select-title {
  font-size: 18px;
  color: #fef08a;
  margin-bottom: 12px;
  font-family: 'Black Han Sans', sans-serif;
  letter-spacing: 1px;
}

.rank-card-list {
  display: flex;
  gap: 14px;
  justify-content: center;
}

.rank-card {
  flex: 1;
  background: #151e17;
  border: 2px solid #3c5240;
  border-radius: 8px;
  padding: 12px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.rank-card:hover {
  background: #1e2b20;
  border-color: #648a6a;
  transform: translateY(-3px);
}

.rank-card.selected {
  background: #253929;
  border-color: #facc15;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.4);
  transform: translateY(-4px);
}

.rank-card.selected::after {
  content: '선택됨 ✔';
  position: absolute;
  top: -10px;
  background: #facc15;
  color: #111;
  font-size: 11px;
  font-weight: bold;
  padding: 1px 8px;
  border-radius: 10px;
}

.rank-icon {
  font-size: 32px;
  margin-bottom: 4px;
}

.rank-name {
  font-size: 18px;
  color: #ffffff;
  font-weight: bold;
  margin-bottom: 6px;
}

.rank-desc {
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.4;
  margin-bottom: 8px;
  min-height: 50px;
}

.rank-diff {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
}

.diff-hard {
  background: #7f1d1d;
  color: #fca5a5;
}

.diff-medium {
  background: #78350f;
  color: #fde68a;
}

.diff-fun {
  background: #14532d;
  color: #86efac;
}

.stealth-meter-container {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 26, 22, 0.85);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #3e4f41;
}

.hud-label {
  font-size: 13px;
  color: #bdc8bf;
}

.stealth-bar-bg {
  width: 130px;
  height: 14px;
  background: #181d19;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid #4e5f51;
}

.stealth-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #facc15, #ef4444);
  transition: width 0.1s ease-out;
}

.stealth-val {
  font-size: 13px;
  font-weight: bold;
  color: #facc15;
  min-width: 32px;
}

.progress-bar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.route-bar {
  position: relative;
  width: 200px;
  height: 8px;
  background: #26332a;
  border-radius: 4px;
  border: 1px solid #405747;
}

.map-pin {
  position: absolute;
  top: -12px;
  left: 0%;
  font-size: 16px;
  transform: translateX(-50%);
  transition: left 0.1s linear;
}

.map-goal {
  position: absolute;
  right: -8px;
  top: -10px;
  font-size: 15px;
}

.item-slot {
  background: rgba(20, 26, 22, 0.85);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #3e4f41;
  font-size: 14px;
  color: #f7d58b;
}

.key-hint {
  color: #9cb0a1;
  font-size: 11px;
}

.audio-toggle-btn {
  pointer-events: auto;
  cursor: pointer;
  background: #2b3a2f;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #4a634e;
  font-size: 16px;
  transition: background 0.2s, transform 0.1s;
}

.audio-toggle-btn:hover {
  background: #3e5343;
  transform: scale(1.05);
}

/* 하단 컨트롤 안내 */
.controls-guide {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 20, 16, 0.85);
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid #374639;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: #c0d4c4;
  pointer-events: none;
  z-index: 10;
}

/* 터치 & 마우스 온스크린 가상 패드 */
.touch-controls {
  position: absolute;
  bottom: 15px;
  left: 0;
  width: 100%;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 15;
}

.touch-group {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.touch-btn {
  width: 58px;
  height: 52px;
  background: rgba(30, 42, 33, 0.85);
  border: 2px solid #56725b;
  border-radius: 8px;
  color: #fff;
  font-family: 'Do Hyeon', sans-serif;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.5);
  transition: background 0.1s, transform 0.05s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.touch-btn:active, .touch-btn.active {
  background: #46694c;
  transform: translateY(2px);
}

.touch-btn.special-btn {
  width: 80px;
  font-size: 14px;
  background: rgba(45, 60, 48, 0.85);
  border-color: #6a8c71;
}

.touch-btn.biscuit-btn {
  width: 75px;
  font-size: 14px;
  background: rgba(70, 52, 28, 0.85);
  border-color: #a17a42;
  color: #fed7aa;
}

@media (max-width: 980px) {
  #game-container {
    width: 100vw;
    height: 56.25vw; /* 16:9 비율 유지 */
    max-height: 100vh;
    border: none;
    border-radius: 0;
  }
  .controls-guide {
    display: none;
  }
}

/* 오버레이 화면 공통 */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 15, 12, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  transition: opacity 0.3s ease;
}

.hidden {
  display: none !important;
}

.screen-box {
  background: #1e2821;
  border: 3px solid #4d6652;
  border-radius: 12px;
  padding: 30px 40px;
  max-width: 620px;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0,0,0,0.7), inset 0 0 15px rgba(50, 75, 55, 0.4);
  position: relative;
}

.tag-alert {
  font-family: 'Black Han Sans', sans-serif;
  color: #ffcc00;
  font-size: 15px;
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.main-title {
  font-family: 'Black Han Sans', sans-serif;
  font-size: 42px;
  color: #f7eed7;
  text-shadow: 2px 2px 0px #0e1610, 0 0 15px rgba(255, 230, 150, 0.4);
  margin-bottom: 6px;
}

.subtitle {
  color: #a8b8aa;
  font-size: 15px;
  font-style: italic;
  margin-bottom: 18px;
}

.story-card {
  background: #141c16;
  border-left: 4px solid #facc15;
  padding: 10px 14px;
  margin-bottom: 18px;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
  color: #d1ddd3;
}

.controls-summary {
  background: #253328;
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 22px;
  text-align: left;
}

.controls-summary h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: #92e697;
}

.grid-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 14px;
  color: #e4ebe5;
}

kbd {
  background: #111813;
  border: 1px solid #57705c;
  border-bottom: 2px solid #57705c;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: monospace;
  color: #ffea79;
}

.tip-msg {
  margin-top: 10px;
  font-size: 13px;
  color: #e2cca5;
}

.btn-military {
  background: linear-gradient(180deg, #4b734e 0%, #2e4d31 100%);
  color: #ffffff;
  border: 2px solid #73a877;
  border-radius: 6px;
  padding: 12px 36px;
  font-size: 20px;
  font-family: 'Black Han Sans', sans-serif;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.btn-military:hover {
  background: linear-gradient(180deg, #5b8a5f 0%, #3a5e3d 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.6);
}

.btn-military:active {
  transform: translateY(1px);
}

.pulse {
  animation: pulseAnim 1.4s infinite;
}

@keyframes pulseAnim {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* 게임오버 전용 스타일 */
.game-over-box {
  border-color: #8b2b2b;
  background: #241414;
}

.danger-header {
  font-family: 'Black Han Sans', sans-serif;
  font-size: 32px;
  color: #ef4444;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
  margin-bottom: 15px;
}

.commander-bust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 15px;
}

.commander-face {
  font-size: 55px;
  background: #3c1e1e;
  border: 2px solid #7e2d2d;
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speech-bubble {
  background: #ffffff;
  color: #1a1a1a;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  position: relative;
  max-width: 320px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 8px 0 8px 10px;
  border-style: solid;
  border-color: transparent transparent transparent #ffffff;
}

.reason-text {
  font-size: 15px;
  color: #d1b4b4;
  margin-bottom: 15px;
}

.stats-panel {
  background: rgba(0, 0, 0, 0.35);
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 15px;
  color: #ffd2d2;
}

/* 승리 전용 스타일 */
.victory-box {
  border-color: #ffd700;
  background: #18281b;
}

.victory-header {
  font-family: 'Black Han Sans', sans-serif;
  font-size: 34px;
  color: #ffd700;
  text-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
  margin-bottom: 12px;
}

.banner-emoji {
  font-size: 48px;
  margin-bottom: 5px;
}

.victory-banner h2 {
  font-size: 26px;
  color: #a4f4ac;
}

.victory-sub {
  color: #cfdec8;
  font-size: 15px;
  margin-top: 4px;
  margin-bottom: 15px;
}

.clear-stats {
  display: flex;
  justify-content: space-around;
  color: #e3ffe6;
  font-size: 16px;
}

.rank-badge {
  background: #f59e0b;
  color: #1a1a1a;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
}
