* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #2b3a5c 0%, #131a2b 55%, #0a0e18 100%);
  color: #eaf2ff;
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

/* 게임 화면이 창을 꽉 채우고, 그 위에 UI를 겹쳐 놓는다. */
.game {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* 게임 화면 위에 겹치는 UI 줄. 빈 곳은 클릭이 게임 화면으로 통과한다. */
.ui {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  pointer-events: none;
}

.ui-top {
  top: 0;
  align-items: center;
  justify-content: space-between;
  column-gap: 14px;
  row-gap: 8px;
  padding: 12px 14px;
}

.ui button {
  pointer-events: auto;
}

.game-title {
  flex: none;
  margin: 0;
  font-size: clamp(15px, 1.9vw, 24px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  color: #ffffff;
  text-shadow: 0 2px 0 #1d4e8c, 0 4px 0 #123058, 0 8px 14px rgba(0, 0, 0, 0.7);
}

/* 기록 저장·다시 시작 버튼을 오른쪽에 나란히 둔다. */
.player-bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  flex: none;
  align-items: center;
  justify-content: flex-end;
  column-gap: 8px;
  row-gap: 6px;
  margin: 0;
}

/* 제목과 그 아래 작은 닉네임을 한 덩어리로 왼쪽에 둔다. */
.title-block {
  display: flex;
  flex-direction: column;
  flex: none;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.player-name {
  display: block;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
  color: #b9cbe8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* HUD: 항목마다 아이콘 배지와 색 띠를 두어 게임 패널처럼 보이게 한다. */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  margin: 0;
}

.hud-item {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 13px;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, #3d4b69 0%, #27324a 55%, #1b2334 100%);
  border: 1px solid #5a6b90;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), 0 4px 0 #0e1522, 0 7px 14px rgba(0, 0, 0, 0.45);
}

.hud-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent, #8fb4ff);
  box-shadow: 0 0 10px var(--accent, #8fb4ff);
}

.hud-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.3), rgba(0, 0, 0, 0.3) 72%), #1b2334;
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.5);
}

.hud-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.hud-label {
  overflow: hidden;
  font-size: 9px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #a2b6d8;
}

.hud-value {
  overflow: hidden;
  font-size: clamp(13px, 1.4vw, 17px);
  line-height: 1.1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--accent, #ffe07a);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 10px rgba(255, 255, 255, 0.16);
}

.hud-money {
  --accent: #ffd45e;
}

.hud-carry {
  --accent: #8fe3ff;
}

.hud-treadmill {
  --accent: #9df58a;
}

/* 세 칸의 폭을 맞춰 한 줄로 정렬되게 한다. */
.hud-money,
.hud-carry {
  min-width: 112px;
}

.hud-treadmill {
  min-width: 156px;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #2b3a5c 0%, #131a2b 55%, #0a0e18 100%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 40%, rgba(24, 38, 66, 0.92), rgba(6, 9, 16, 0.96));
  text-align: center;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-title {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ffffff;
  text-shadow: 0 3px 0 #1d4e8c, 0 6px 0 #123058, 0 10px 16px rgba(0, 0, 0, 0.6);
}

.overlay-text {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #cfdcf5;
}

/* 기록 저장·다시 시작은 글자 대신 흰 아이콘만 두는 버튼으로 만든다. */
.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #ffffff;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.12s ease;
}

.icon-button .icon {
  display: block;
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.8));
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.icon-button:active {
  transform: translateY(2px) scale(0.95);
  background: rgba(255, 255, 255, 0.26);
}

.icon-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.16);
}

.icon-button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  background: transparent;
}

/* 저장 결과 문구는 닉네임·버튼 줄 바로 아래에 겹쳐 표시해 게임 화면을 가리지 않는다. */
.save-status {
  position: absolute;
  top: 100%;
  right: 0;
  margin: 6px 0 0;
  max-width: 60vw;
  overflow: hidden;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #cfe0ff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.save-status.is-error {
  color: #ff9b8a;
}

/* 좁거나 낮은 화면에서는 글자·버튼·HUD를 작게 줄여 게임 화면을 가리지 않게 한다. */
@media (max-width: 700px), (max-height: 460px) {
  .ui-top {
    column-gap: 8px;
    padding: 8px 10px;
  }

  .game-title {
    font-size: 15px;
    letter-spacing: 0.5px;
  }

  .hud {
    gap: 6px;
  }

  .hud-item {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 6px;
    height: 32px;
    padding: 0 9px;
  }

  .hud-money,
  .hud-carry {
    min-width: 84px;
  }

  .hud-treadmill {
    min-width: 118px;
  }

  .hud-icon {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  .hud-label {
    font-size: 8px;
    letter-spacing: 0.6px;
  }

  .hud-value {
    font-size: 13px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .icon-button .icon {
    width: 20px;
    height: 20px;
  }

  .player-bar {
    column-gap: 6px;
  }

  .player-name {
    max-width: 30vw;
    font-size: 10px;
  }

  .save-status {
    max-width: 80vw;
    font-size: 11px;
  }
}
