* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: #0d0b09;
  color: #f4e8d6;
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  overflow: hidden;
}

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  pointer-events: none;
  font-weight: 700;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(20, 16, 12, 0.72);
  border: 1px solid rgba(255, 220, 160, 0.18);
}

.hud-label {
  font-size: 12px;
  color: #c9b89a;
}

#score, #depth {
  font-size: 20px;
  color: #ffd34d;
  font-variant-numeric: tabular-nums;
}

.hud-unit {
  font-size: 12px;
  color: #c9b89a;
}

#mineral-counts {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 10px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(20, 16, 12, 0.72);
  border: 1px solid rgba(255, 220, 160, 0.18);
  font-size: 14px;
}

.count {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.dot.copper { background: #d07a3a; }
.dot.iron { background: #c9a98c; }
.dot.silver { background: #cfd8e2; }
.dot.gold { background: #f7c948; }
.dot.platinum { background: #dff2ff; }
.dot.uranium { background: #8fe07a; }
.dot.diamond { background: #7fe8ff; }
.dot.lucat { background: #ff8de8; }

/* 랭킹 */
#rank-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: auto;
}

#submit-score-btn {
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 220, 160, 0.35);
  background: rgba(255, 211, 77, 0.18);
  color: #ffd34d;
  font-size: 14px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}

#submit-score-btn:hover {
  background: rgba(255, 211, 77, 0.32);
}

#submit-score-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

#rankingStatus {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #d8cbb6;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

#rankingStatus:empty {
  display: none;
}

/* 랜턴 설치 */
#lantern-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: auto;
}

#install-lantern-btn {
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 240, 170, 0.4);
  background: rgba(255, 236, 150, 0.2);
  color: #ffe98a;
  font-size: 14px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}

#install-lantern-btn:hover {
  background: rgba(255, 236, 150, 0.34);
}

#install-lantern-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

#lantern-status {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #d8cbb6;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

#lantern-status:empty {
  display: none;
}

/* 지상 상점 */
#shop-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 250px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(20, 16, 12, 0.82);
  border: 1px solid rgba(255, 220, 160, 0.22);
  pointer-events: auto;
}

.shop-title {
  margin: 0;
  font-size: 14px;
  color: #ffd34d;
}

.shop-hint {
  margin: 0;
  font-size: 12px;
  color: #c9b89a;
}

#shop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shop-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.shop-name {
  font-size: 13px;
  color: #f4e8d6;
}

.shop-desc {
  font-size: 11px;
  color: #a99a83;
}

.shop-owned {
  font-size: 11px;
  color: #c9b89a;
  white-space: nowrap;
}

.shop-item button {
  flex: none;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 220, 160, 0.35);
  background: rgba(255, 211, 77, 0.18);
  color: #ffd34d;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.shop-item button:hover {
  background: rgba(255, 211, 77, 0.32);
}

.shop-item button:disabled {
  opacity: 0.5;
  cursor: default;
}

.shop-item button.cant-afford {
  opacity: 0.65;
}

#shop-status {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: #d8cbb6;
}

#shop-status:empty {
  display: none;
}

/* 조작 */
#touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  pointer-events: none;
}

#joystick {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 220, 160, 0.25);
  pointer-events: auto;
  touch-action: none;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 211, 77, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  will-change: transform;
}

#mine-btn {
  position: absolute;
  right: 26px;
  bottom: 30px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px solid rgba(255, 220, 160, 0.35);
  background: rgba(255, 211, 77, 0.18);
  color: #ffd34d;
  font-size: 18px;
  font-weight: 800;
  font-family: inherit;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}

#mine-btn.active {
  background: rgba(255, 211, 77, 0.45);
  transform: scale(0.96);
}

/* 시작·종료 화면 */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 6, 4, 0.72);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(420px, 100%);
  padding: 28px 26px;
  border-radius: 18px;
  background: #1d1712;
  border: 1px solid rgba(255, 220, 160, 0.25);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.overlay-card h1 {
  margin: 0 0 10px;
  font-size: 26px;
  color: #ffd34d;
}

.overlay-card p {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.6;
  color: #d8cbb6;
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin: 0 0 16px;
  padding: 0;
  font-size: 13px;
  color: #c9b89a;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.help {
  font-size: 13px !important;
  color: #a99a83 !important;
}

#start-btn {
  margin-top: 4px;
  padding: 12px 34px;
  border: none;
  border-radius: 12px;
  background: #ffd34d;
  color: #241a08;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}

#start-btn:hover {
  background: #ffe17a;
}

@media (max-width: 520px) {
  #hud { gap: 8px; padding: 8px 10px; }
  .hud-item { padding: 5px 9px; }
  #score, #depth { font-size: 17px; }
  #mineral-counts { padding: 5px 9px; font-size: 12px; gap: 7px; }
  #joystick { width: 104px; height: 104px; left: 16px; bottom: 16px; }
  #mine-btn { width: 84px; height: 84px; right: 18px; bottom: 22px; font-size: 16px; }
  #submit-score-btn { padding: 6px 11px; font-size: 12px; }
  #rankingStatus { font-size: 11px; }
  #install-lantern-btn { padding: 6px 11px; font-size: 12px; }
  #lantern-status { font-size: 11px; }
  .overlay-card { padding: 22px 18px; }
  .overlay-card h1 { font-size: 22px; }
}
