:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(60px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  gap: 16px;
}

/* 점수바: SCORE | BEST | New 버튼 */
.score-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.score-box {
  flex: 1;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0a0a0;
}

.score-val,
.best-val {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  margin-top: 2px;
  line-height: 1.1;
}

.new-btn {
  flex: 0 0 auto;
  font: inherit;
  color: #fff;
  background: #4f9eff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 56px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.new-btn:active { background: #3d8ae8; }

/* 게임 영역 — 보드/캠버스/그리드 등을 여기에 */
#game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 chrome */
.home-link,
.hof-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 10;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.home-link { left:  max(12px, env(safe-area-inset-left)); }
.hof-link  { right: max(12px, env(safe-area-inset-right)); }

@media (hover: hover) {
  .home-link:hover,
  .hof-link:hover {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* 오버레이 (게임 종료 / 완료 시 점수 + 저장 버튼) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 18px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  min-width: 240px;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay-score {
  margin: 0;
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.overlay-card button {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.overlay-card button:active {
  background: rgba(255, 255, 255, 0.18);
}

.overlay-card .save-btn {
  background: #4f9eff;
  border-color: #4f9eff;
}

.overlay-card .save-btn:active {
  background: #3d8ae8;
}

/* ─── 해머던지기 ───────────────────────────────────────────
   위에서부터: 시기/기록 · 회전·균형 게이지 · 원형 드래그 링 · 문구 · 놓기 버튼. */
#game {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 12px;
  min-height: 0;
}

.hm-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
}

.hm-att {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #9fd0ff;
  padding: 3px 11px;
  border-radius: 999px;
  background: rgba(79, 158, 255, 0.12);
  border: 1px solid rgba(79, 158, 255, 0.28);
}

.hm-marks { display: flex; gap: 5px; }

.hm-mark {
  min-width: 30px;
  padding: 3px 6px;
  border-radius: 7px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: #6a6a6a;
  background: #17191f;
  border: 1px solid #262b35;
  font-variant-numeric: tabular-nums;
}

.hm-mark.ok { color: #6ee787; border-color: #2c5539; }
.hm-mark.foul { color: #ff6b6b; border-color: #5a2a2a; }

.hm-bars { display: flex; flex-direction: column; gap: 6px; }

.hm-bar { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700; }
.hm-bar em {
  font-style: normal;
  min-width: 46px;
  white-space: nowrap;
  font-size: 10px;
  color: #8f8f8f;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hm-bar i { flex: 1; height: 9px; border-radius: 999px; background: #1a1d23; overflow: hidden; }
.hm-bar b { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 0.06s linear; }
.hm-bar.spin b { background: linear-gradient(to right, #4f9eff, #6ee787); }
.hm-bar.spin.hot b { background: linear-gradient(to right, #ffca57, #ff5a5a); }
.hm-bar.ctrl b { background: #6ee787; }
.hm-bar.ctrl.low b { background: #ff5a5a; }

/* 원형 드래그 링 — 여기서 손가락으로 원을 그린다.
   ⚠ 처음엔 flex:1 + aspect-ratio:1 로 뒀는데, flex가 높이를 먼저 정하는 바람에
     가로 390 × 세로 493짜리 '타원'이 됐다. 그러면 팔이 가로로 누울 때 반지름을
     넘어가서 overflow:hidden에 해머 공이 통째로 잘렸다 — 화면에서 공이 사라졌다.
     정사각형을 명시적으로 잡고 남는 세로 공간은 margin:auto로 흘려보낸다. */
.hm-ring {
  position: relative;
  flex: 0 1 auto;
  align-self: center;
  margin: auto 0;
  width: min(84vw, 320px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at center, #141922 0 58%, #0e1219 58% 100%);
  border: 2px dashed #2a3342;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}

.hm-ring:active { cursor: grabbing; }

/* 착지 부채꼴 (정면 ±40°) — conic-gradient로 그린다 */
.hm-sector {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from -40deg,
    rgba(110, 231, 135, 0.18) 0deg 80deg, transparent 80deg 360deg);
  pointer-events: none;
}

/* 해머 팔 — 중심에서 뻗어 나가며 회전한다 */
.hm-arm {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 44%;
  margin-left: -1.5px;
  transform-origin: 50% 100%;
  margin-top: -44%;
  background: linear-gradient(to bottom, rgba(255, 138, 79, 0.9), rgba(255, 138, 79, 0.25));
  pointer-events: none;
}

.hm-ball {
  position: absolute;
  left: 50%;
  top: -9px;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  border-radius: 50%;
  background: #ff8a4f;
  box-shadow: 0 0 14px rgba(255, 138, 79, 0.6);
}

.hm-hint {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #7e8899;
  pointer-events: none;
  line-height: 1.4;
}

.hm-hint[hidden] { display: none; }

.hm-msg {
  margin: 0;
  min-height: 22px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: #b8b8b8;
}

.hm-msg.ok { color: #6ee787; }
.hm-msg.bad { color: #ff6b6b; }

.hm-btn {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.04em;
  color: #f5f5f5;
  background: #34201c;
  border: 1px solid #6f3d33;
  border-radius: 16px;
  min-height: 68px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: opacity 0.1s ease, background 0.08s ease;
}

.hm-btn:active { background: #452a24; }
.hm-btn:disabled { opacity: 0.35; cursor: default; }

.overlay-score small { font-size: 22px; font-weight: 700; margin-left: 2px; }
.overlay-sub { margin: 0; font-size: 14px; font-weight: 700; color: #a0a0a0; font-variant-numeric: tabular-nums; }

@media (max-height: 700px) {
  .hm-ring { width: min(70vw, 250px); }
  .hm-btn { min-height: 54px; font-size: 15px; }
}
