: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;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 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; font-weight: 700; color: #b8b8b8; font-variant-numeric: tabular-nums; }
.overlay-sub.small { font-size: 12.5px; font-weight: 600; color: #a8a8a8; line-height: 1.4; }
.overlay-card h2.ok { color: #7ee2a0; }
.overlay-card h2.bad { color: #ff8a7a; }

/* ─── Bashni ───────────────────────────────────────────────
   A walnut board with ivory and crimson columns, seen slightly from the side. */
body { background: radial-gradient(120% 80% at 50% 0%, #22170f 0%, #0b0908 62%) fixed, #0b0908; }

main { gap: 10px; }

#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}
.bs-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.bs-head {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.bs-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 3px 10px;
  border-radius: 10px;
  background: #19120d;
  border: 1px solid #33261b;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.bs-chip .bs-who { font-weight: 700; color: #d6c3a8; overflow: hidden; text-overflow: ellipsis; }
.bs-chip .bs-n { margin-left: auto; font-weight: 800; color: #f2e7d6; }
.bs-chip.me { order: 2; }
.bs-chip .bs-dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.bs-chip.me .bs-dot { background: radial-gradient(circle at 35% 30%, #fffaf0, #e2d6bd 60%, #a99773); box-shadow: 0 0 0 1px #8c7b5c; }
.bs-chip.foe .bs-dot { background: radial-gradient(circle at 35% 30%, #e0676b, #b52f35 55%, #6e1519); box-shadow: 0 0 0 1px #3f0b0e; }
.bs-chip.turn { border-color: #e0a64a; box-shadow: 0 0 0 1px rgba(224, 166, 74, 0.5); }

.bs-board {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bs-canvas {
  display: block;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  touch-action: none;
}
.bs-msg {
  margin: 0;
  min-height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  color: #f2e7d6;
}
.bs-msg.dim { color: #b3a48e; font-weight: 600; }
.bs-msg.warn { color: #ffb08a; }
.bs-msg.ok { color: #9be8b5; }
.bs-meta {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #a8987f;
  font-variant-numeric: tabular-nums;
}
.bs-meta.warn { color: #ffb08a; }

.bs-card { max-width: 340px; }
.bs-demo { width: 100%; max-width: 240px; height: auto; display: block; }
.bs-howto { text-align: left; font-size: 13px; line-height: 1.45; color: #d7d0c6; }
.bs-howto p { margin: 0 0 6px; }
.bs-howto b { color: #ffd884; }
.overlay-card .start-btn { background: #e0a64a; border-color: #e0a64a; color: #1a1005; font-weight: 800; }

@media (max-height: 700px) {
  main { gap: 8px; }
  .bs-chip { min-height: 28px; font-size: 12px; }
  .bs-msg { min-height: 2.4em; font-size: 13px; }
  .bs-card { padding: 14px 16px; gap: 8px; }
  .bs-card h2 { font-size: 18px; }
  .bs-demo { max-width: 200px; }
  .bs-howto { font-size: 12px; line-height: 1.38; }
  .bs-howto p { margin-bottom: 4px; }
}
@media (max-height: 600px) {
  .overlay { padding-top: 64px; padding-bottom: 8px; }
  .bs-ready h2:first-child { display: none; }
  .bs-card .overlay-score { font-size: 44px; }
}


.bs-formula { font-variant-numeric: tabular-nums; color: #c9b89c; }
:lang(ko) .bs-howto, :lang(ko) .bs-msg, :lang(ko) .overlay-sub { word-break: keep-all; }
