: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라 세로 스택으로 덮어쓴다.
   위에서부터: 남은 목숨 · 피스트(거리) · 판정 문구 · 박자 게이지 · 행동 버튼. */
#game {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 14px;
  min-height: 0;
}

/* 남는 세로 공간은 피스트 위·문구 아래로 반씩 흘려보낸다 — 목숨은 위에,
   게이지+버튼은 아래에 붙고, 피스트와 판정 문구가 그 사이 가운데에 모인다. */
.fe-piste { margin-top: auto; }

/* 남은 목숨 — 5번 찔리면 끝 */
.fe-lives {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 14px;
}

.fe-life {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #ff5a5a;
  box-shadow: 0 0 10px rgba(255, 90, 90, 0.45);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.fe-life.gone {
  background: #2a2a2a;
  box-shadow: none;
}

/* 피스트 — 두 선수 사이 거리를 한눈에 */
.fe-piste {
  position: relative;
  height: 74px;
  border-radius: 14px;
  background:
    repeating-linear-gradient(
      to right,
      rgba(255, 255, 255, 0.10) 0 1px,
      transparent 1px calc(100% / 8)
    ),
    #131313;
  border: 1px solid #2a2a2a;
  overflow: hidden;
}

/* 사거리 안에 들어오면 피스트가 달아오른다 — "지금 찌르면 닿는다" */
.fe-range {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 90, 90, 0.28),
    rgba(255, 90, 90, 0) 70%
  );
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.fe-mark {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 40px;
  margin-top: -20px;
  border-radius: 8px;
  transition: left 0.16s ease;
}

.fe-mark::after {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -17px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #8a8a8a;
}

.fe-mark.me {
  background: #4f9eff;
  box-shadow: 0 0 14px rgba(79, 158, 255, 0.5);
}

.fe-mark.me::after { content: "\25B6"; color: #4f9eff; }

.fe-mark.foe {
  background: #ff8a4f;
  box-shadow: 0 0 14px rgba(255, 138, 79, 0.5);
}

.fe-mark.foe::after { content: "\25C0"; color: #ff8a4f; }

/* 판정 문구 — 매 박자의 결과 + 상대가 무엇을 했는지 */
.fe-msg {
  margin: 0 0 auto;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: #b8b8b8;
}

.fe-msg.ok   { color: #6ee787; }
.fe-msg.bad  { color: #ff6b6b; }
.fe-msg.warn { color: #ffca57; }

/* 박자 게이지 — 남은 시간이 줄어드는 걸 눈으로 본다 */
.fe-timer {
  height: 6px;
  margin-bottom: -4px;
  border-radius: 999px;
  background: #1d1d1d;
  overflow: hidden;
}

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

/* 행동 버튼 — 엄지 닿는 아래쪽에 큼직하게 */
.fe-acts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fe-acts.locked {
  opacity: 0.45;
  pointer-events: none;
}

.fe-row {
  display: flex;
  gap: 10px;
}

.fe-btn {
  flex: 1;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #f5f5f5;
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 14px;
  min-height: 58px;
  padding: 8px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fe-btn:active { background: #262626; }

.fe-btn.move { background: #16202c; border-color: #2c4055; }
.fe-btn.move:active { background: #1e2c3c; }

.fe-btn.atk { background: #2c1616; border-color: #5a2a2a; color: #ffb3b3; }
.fe-btn.atk:active { background: #3a1c1c; }

.fe-btn.def { background: #16261c; border-color: #2c5539; color: #a8e9bd; }
.fe-btn.def:active { background: #1c3326; }

.fe-btn.fnt { background: #26221a; border-color: #55482c; color: #e9d6a8; }
.fe-btn.fnt:active { background: #332d22; }

/* 세로 여유가 없는 폰(작은 화면)에서는 피스트를 줄인다 */
@media (max-height: 660px) {
  .fe-piste { height: 58px; }
  .fe-mark { height: 32px; margin-top: -16px; }
  .fe-btn { min-height: 50px; font-size: 14px; }
}
