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

/* 점수바: 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; }

/* 상태 안내줄 */
.status {
  text-align: center; font-size: 13px; line-height: 1.35; color: #c4c0b6;
  min-height: 2.4em; display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}

/* 게임 영역 */
#game {
  flex: 1;
  display: flex;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

.pg {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  gap: clamp(8px, 2vh, 18px);
}
.pg-side {
  background: #141619; border: 1px solid #262a30; border-radius: 14px;
  padding: 10px 14px; transition: border-color .2s, background .2s;
}
.pg-side.active { border-color: #e0a84a; background: #1b1812; }
.pg-who { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pg-name { font-size: 14px; font-weight: 700; color: #c8c8c8; }
.pg-bank { font-size: clamp(26px, 5vh, 36px); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.pg-me .pg-bank { color: #ffd884; }
.pg-ai .pg-bank { color: #9cc4ff; }
.pg-bar { position: relative; height: 10px; margin-top: 8px; background: #23262c; border-radius: 99px; overflow: hidden; }
.pg-bar i, .pg-bar b { position: absolute; top: 0; bottom: 0; left: 0; width: 0; }
.pg-me .pg-bar i { background: #e0a84a; }
.pg-ai .pg-bar i { background: #5c8fd6; }
.pg-bar b { background: rgba(255,255,255,0.35); }

.pg-mid { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(6px, 1.4vh, 12px); }
.pg-die {
  width: clamp(64px, 14vh, 104px); height: clamp(64px, 14vh, 104px);
  background: #f4f1e8; border-radius: 18%;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: clamp(9px, 2vh, 15px); gap: clamp(3px, 0.7vh, 6px); flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45), inset 0 -4px 0 rgba(0,0,0,0.12);
}
.pg-die span { border-radius: 50%; }
.pg-die span.on { background: #1d1d1d; }
.pg-die.pig { background: #f3c1bd; }
.pg-die.pig span.on { background: #a3221a; }
.pg-die.rolling { animation: pg-shake .38s linear; }
@keyframes pg-shake { 0%{transform:rotate(0)} 25%{transform:rotate(14deg)} 50%{transform:rotate(-12deg)} 75%{transform:rotate(8deg)} 100%{transform:rotate(0)} }
.pg-turn { font-size: 15px; color: #bdbdbd; }
.pg-turn-val { font-size: 24px; color: #fff; font-variant-numeric: tabular-nums; }
.pg-rolls { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; min-height: 22px; max-width: 100%; }
.pg-rolls span { min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px; background: #23262c; color: #ddd; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.pg-rolls span.x { background: #5a1c18; color: #ffb4ad; }

.pg-btns { display: flex; gap: 10px; }
.pg-btns button {
  flex: 1; font: inherit; font-weight: 800; font-size: 17px; min-height: 56px;
  border-radius: 14px; border: none; cursor: pointer; color: #111;
  -webkit-tap-highlight-color: transparent;
}
.pg-roll { background: #ffd27a; }
.pg-hold { background: #8fd3a5; }
.pg-btns button:disabled { background: #2a2c31; color: #8a8a8a; cursor: default; }
.pg-btns button:not(:disabled):active { filter: brightness(0.9); }

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 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;
}

.overlay-sub { margin: 0; font-size: 14px; color: #c4c4c4; }
