: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;
}

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

.bi-lap {
  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);
}

.bi-marks { display: flex; gap: 4px; }

.bi-mark {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #20242c;
  border: 1px solid #333945;
}

.bi-mark.hit { background: #6ee787; border-color: #6ee787; }
.bi-mark.miss { background: #ff5a5a; border-color: #ff5a5a; }

/* 맥박 / 다리 게이지 */
.bi-bars { display: flex; flex-direction: column; gap: 6px; }

.bi-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
}

.bi-bar em { font-style: normal; width: 42px; color: #8f8f8f; text-transform: uppercase; letter-spacing: 0.05em; }
.bi-bar i { flex: 1; height: 9px; border-radius: 999px; background: #1a1d23; overflow: hidden; }
.bi-bar b { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 0.08s linear; }
.bi-bar u {
  text-decoration: none;
  width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #b8b8b8;
}

.bi-bar.pulse b { background: linear-gradient(to right, #6ee787, #ffca57); }
.bi-bar.pulse.hot b { background: linear-gradient(to right, #ffca57, #ff5a5a); }
.bi-bar.pulse.hot u { color: #ff6b6b; }
.bi-bar.stam b { background: #4f9eff; }

/* 코스와 사격장이 같은 자리를 쓴다 */
.bi-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: #0e1219;
  border: 1px solid #1c222e;
  padding: 12px;
}

.bi-stage > *[hidden] { display: none; }

/* 스키 코스 */
.bi-track {
  position: relative;
  width: 100%;
  height: 34px;
  border-radius: 999px;
  background: #161b24;
  border: 1px solid #232a36;
  overflow: visible;
}

.bi-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 999px;
  background: linear-gradient(to right, rgba(79, 158, 255, 0.25), rgba(79, 158, 255, 0.5));
}

.bi-skier {
  position: absolute;
  top: 50%;
  margin-top: -14px;
  font-size: 22px;
  line-height: 28px;
}

/* 사격장 */
.bi-range { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.bi-clock {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #1a1d23;
  overflow: hidden;
}

.bi-clock span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(to right, #4f9eff, #ff5a5a);
}

/* 조준면: 가운데가 표적, 조준점이 그 위를 떠다닌다 */
.bi-scope {
  position: relative;
  width: min(74vw, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #161b24 0 42%, #10141b 42% 100%);
  border: 1px solid #262d3a;
}

.bi-target {
  position: absolute;
  left: 50%; top: 50%;
  width: 32%;
  height: 32%;
  margin: -16% 0 0 -16%;
  border-radius: 50%;
  background: #2b3340;
  border: 2px solid #46536a;
}

.bi-retic {
  position: absolute;
  left: 50%; top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid #ff8a4f;
  box-shadow: 0 0 10px rgba(255, 138, 79, 0.5);
}

.bi-retic::before,
.bi-retic::after {
  content: "";
  position: absolute;
  background: #ff8a4f;
}

.bi-retic::before { left: 50%; top: -7px; width: 2px; height: 6px; margin-left: -1px; }
.bi-retic::after { top: 50%; left: -7px; height: 2px; width: 6px; margin-top: -1px; }

.bi-retic.on { border-color: #6ee787; box-shadow: 0 0 14px rgba(110, 231, 135, 0.7); }
.bi-retic.on::before, .bi-retic.on::after { background: #6ee787; }

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

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

/* 한 버튼이 국면에 따라 '밀기'와 '사격'으로 바뀐다 */
.bi-btn {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.04em;
  color: #f5f5f5;
  background: #1e2a3a;
  border: 1px solid #33506f;
  border-radius: 16px;
  min-height: 74px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.08s ease;
}

.bi-btn:active { background: #2a3b52; }
.bi-btn.fire { background: #34201c; border-color: #6f3d33; color: #ffc2ad; }
.bi-btn.fire:active { background: #452a24; }

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

@media (max-height: 680px) {
  .bi-scope { width: min(60vw, 190px); }
  .bi-btn { min-height: 60px; font-size: 15px; }
}
