: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: #9a9a9a; line-height: 1.4; }
.overlay-card h2.ok { color: #7ee2a0; }
.overlay-card h2.bad { color: #ff8a7a; }

/* ─── Choko ────────────────────────────────────────────────
   A 5×5 grid scratched into packed red earth. Your pieces are pale cowrie shells,
   the computer's are dark river stones. */
body { background: radial-gradient(120% 80% at 50% 0%, #1d1510 0%, #0b0908 62%) fixed, #0b0908; }

#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  --bw: min(92vw, 420px, calc(100dvh - 300px));
  --shell:
    repeating-linear-gradient(0deg, rgba(104, 64, 26, 0.7) 0 1.5px, transparent 1.5px 6px) 50% 52% / 16% 52% no-repeat,
    linear-gradient(90deg, transparent 44%, #7a4c22 45% 55%, transparent 56%) 50% 52% / 100% 66% no-repeat,
    radial-gradient(ellipse at 36% 24%, #ffffff 0 9%, #fbf3e4 26%, #ecd9b6 62%, #bfa077 100%);
  --stone: radial-gradient(circle at 34% 28%, #a3adb7 0 7%, #555f69 26%, #2a3037 62%, #121518 100%);
}
.ck-row, .ck-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: var(--bw);
  min-width: 260px;
  align-self: center;
}
.ck-c, .ck-info, .ck-lvl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  min-height: 30px;
  border-radius: 999px;
  background: #19120d;
  border: 1px solid #33261b;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ck-c .ck-who { font-size: 12px; font-weight: 700; color: #c2ae95; }
.ck-c i.pc { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.ck-c.me i.pc { width: 11px; background: linear-gradient(90deg, transparent 42%, #7a4c22 43% 57%, transparent 58%) 50% 50% / 100% 64% no-repeat, radial-gradient(circle at 35% 30%, #fffaf0, #efe0c4 55%, #c7ac80); }
.ck-c.foe i.pc { background: radial-gradient(circle at 35% 30%, #77808a, #30363d 60%, #15181c); box-shadow: 0 0 0 1px #77828d; }
.ck-c.turn { border-color: #e0a64a; box-shadow: 0 0 0 1px rgba(224, 166, 74, 0.5); }
.ck-lead {
  display: none;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #2a1700;
  background: linear-gradient(180deg, #ffd884, #e8a93c);
  border-radius: 999px;
  padding: 2px 7px 2px 6px;
}
.ck-lead::before { content: "⚑ "; }
.ck-c.has-lead .ck-lead { display: inline-block; }
.ck-hand { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; min-width: 0; }
.ck-hn { font-size: 11.5px; font-weight: 800; color: #e2c48e; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1; }
.ck-hand.empty .ck-hn { color: #7d6d5a; }
.ck-dots { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 3px; max-width: 110px; }
.ck-dots i { width: 6px; height: 6px; border-radius: 50%; background: #2e231a; transition: background 0.2s; }
.ck-hand.me .ck-dots i.on { background: #f3e6cc; box-shadow: 0 0 4px rgba(255, 236, 200, 0.35); }
.ck-hand.foe .ck-dots i.on { background: #8a96a2; }
.ck-info, .ck-lvl { font-size: 12px; font-weight: 700; color: #c2ae95; min-height: 26px; }
.ck-info.warn { color: #ffb36b; border-color: #6a4a22; }

.ck-board {
  position: relative;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  width: var(--bw);
  min-width: 260px;
  aspect-ratio: 1;
  border-radius: 16px;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 210, 160, 0.18) 0 2px, transparent 3px) 0 0 / 23px 19px,
    radial-gradient(circle at 70% 60%, rgba(60, 20, 0, 0.22) 0 1.5px, transparent 2.5px) 0 0 / 17px 21px,
    radial-gradient(130% 100% at 30% 18%, rgba(255, 214, 160, 0.20), transparent 60%),
    linear-gradient(160deg, #b5653a, #934a26 65%, #7c3d1e);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), inset 0 0 0 2px rgba(60, 22, 6, 0.5), inset 0 2px 0 rgba(255, 220, 180, 0.22);
}
.ck-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ck-lines line { stroke: rgba(58, 20, 4, 0.62); stroke-width: 3; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.ck-pt {
  position: relative;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
  font: inherit;
}
/* the scooped hollow at every point */
.ck-pt::before {
  content: "";
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 60%, #6a2e12, #85401d 70%);
  box-shadow: inset 0 2px 3px rgba(40, 10, 0, 0.6), 0 1px 0 rgba(255, 210, 170, 0.25);
}
.ck-pt.open::before { background: radial-gradient(circle at 50% 55%, #f6dcb3 0 30%, #85401d 34%); }
.ck-pt > .st {
  position: absolute;
  width: 74%;
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.6);
  transition: transform 0.16s ease, opacity 0.16s ease;
  pointer-events: none;
  z-index: 1;
}
.ck-pt.me > .st, .ck-pt.foe > .st { opacity: 1; transform: scale(1); }
/* cowrie shell: pale oval with a toothed slit down the middle */
.ck-pt.me > .st, .ck-pt.gone.me > .st { width: 60%; height: 74%; aspect-ratio: auto; background: var(--shell); }
.ck-pt.me > .st { box-shadow: 0 3px 0 rgba(60, 24, 6, 0.55), 0 5px 9px rgba(30, 10, 0, 0.4), inset 0 -3px 5px rgba(130, 96, 56, 0.35); }
.ck-pt.foe > .st, .ck-pt.gone.foe > .st { background: var(--stone); }
.ck-pt.foe > .st { box-shadow: 0 3px 0 rgba(30, 10, 2, 0.65), 0 5px 9px rgba(20, 6, 0, 0.45), inset 0 -3px 5px rgba(0, 0, 0, 0.45); }
.ck-pt.can > .st { box-shadow: 0 3px 0 rgba(60, 24, 6, 0.55), 0 0 0 3px rgba(255, 255, 255, 0.6); }
.ck-pt.sel > .st {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 6px 10px rgba(30, 10, 0, 0.5), 0 0 0 3px #ffd36b, 0 0 14px rgba(255, 211, 107, 0.7);
}
.ck-pt.threat > .st { animation: ck-wobble 0.9s ease-in-out infinite; box-shadow: 0 3px 0 rgba(30, 10, 2, 0.65), 0 0 0 3px #ff5a4a; }
.ck-pt.bonus > .st { box-shadow: 0 3px 0 rgba(30, 10, 2, 0.65), 0 0 0 3px #ff5a4a, 0 0 16px rgba(255, 90, 74, 0.75); animation: ck-pulse 0.9s ease-in-out infinite; }
.ck-pt.to::after {
  content: "";
  position: absolute;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(160, 255, 190, 0.9);
  box-shadow: 0 0 10px rgba(120, 255, 160, 0.45);
  z-index: 2;
}
.ck-pt.to.cap::after {
  content: attr(data-cap);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62%;
  border: none;
  background: radial-gradient(circle, #ffeaa8 0 40%, #f0bf4f 75%, #d79a2b);
  box-shadow: 0 0 0 2px #fff1c4, 0 0 14px rgba(255, 196, 70, 0.7);
  font-size: clamp(13px, 4.2vw, 19px);
  font-weight: 900;
  color: #5a3200;
}
.ck-pt.last::before { box-shadow: inset 0 2px 3px rgba(40, 10, 0, 0.6), 0 0 0 3px rgba(255, 214, 130, 0.9); }
.ck-pt.fresh > .st { animation: ck-drop 0.28s ease-out; }
.ck-pt.slide > .st { animation: ck-slide 0.24s ease-out; }
.ck-pt.gone > .st { opacity: 0; transform: scale(1); animation: ck-gone 0.56s ease-in forwards; }
.ck-pt.gone.late > .st { opacity: 1; animation-delay: 0.38s; }
.ck-pt.gone::after {
  content: "";
  position: absolute;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(255, 110, 80, 0.9);
  opacity: 0;
  animation: ck-ring 0.56s ease-out forwards;
}
.ck-pt.gone.late::after { animation-delay: 0.38s; }
@keyframes ck-drop { from { transform: scale(1.4) translateY(-8px); opacity: 0.2; } to { transform: scale(1); opacity: 1; } }
@keyframes ck-slide { from { transform: translate(var(--tx), var(--ty)); } to { transform: none; } }
@keyframes ck-gone { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(0.3) rotate(25deg); } }
@keyframes ck-ring { 0% { transform: scale(0.6); opacity: 1; } 100% { transform: scale(1.3); opacity: 0; } }
@keyframes ck-wobble { 0%, 100% { translate: 0; } 25% { translate: -2px 0; } 75% { translate: 2px 0; } }
@keyframes ck-pulse { 0%, 100% { scale: 1; } 50% { scale: 1.06; } }

.ck-msg {
  margin: 0;
  min-height: 38px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: #dccbb2;
  line-height: 1.35;
  width: var(--bw);
  min-width: 260px;
  align-self: center;
}
.ck-msg.ok { color: #7ee2a0; }
.ck-msg.bad { color: #ff8a7a; }
.ck-msg.warn { color: #ffcf7a; }
.ck-msg.dim { color: #a08f7a; }

/* start card */
.ck-howto { text-align: left; font-size: 14px; line-height: 1.45; color: #ddd3c4; }
.ck-howto p { margin: 0 0 6px; }
.ck-howto b { color: #ffd98a; }
.ck-demo {
  position: relative; display: flex; gap: 6px; padding: 6px; border-radius: 10px;
  background: linear-gradient(160deg, #b5653a, #8f4724);
  --shell:
    linear-gradient(90deg, transparent 44%, #7a4c22 45% 55%, transparent 56%) 50% 52% / 100% 66% no-repeat,
    radial-gradient(ellipse at 36% 24%, #ffffff 0 9%, #fbf3e4 26%, #ecd9b6 62%, #bfa077 100%);
}
.ck-demo i { width: 30px; height: 30px; border-radius: 50%; display: block; }
.ck-demo i.sp { background: radial-gradient(circle, #6a2e12 0 30%, transparent 33%); }
.ck-demo i.me { width: 24px; margin: 0 3px; background: var(--shell); z-index: 1; }
.ck-demo i.foe { background: radial-gradient(circle at 34% 28%, #a3adb7 0 7%, #555f69 26%, #2a3037 62%, #121518); }
.ck-demo i.j { animation: ck-demo-jump 3s ease-in-out infinite; }
.ck-demo i.a { animation: ck-demo-gone 3s ease-in infinite; }
.ck-demo i.b { animation: ck-demo-gone2 3s ease-in infinite; }
@keyframes ck-demo-jump { 0%, 15% { transform: none; } 35% { transform: translate(36px, -18px); } 50%, 100% { transform: translateX(72px); } }
@keyframes ck-demo-gone { 0%, 45% { opacity: 1; transform: none; } 60%, 90% { opacity: 0; transform: scale(0.3); } 100% { opacity: 1; } }
@keyframes ck-demo-gone2 { 0%, 60% { opacity: 1; transform: none; box-shadow: none; } 66% { box-shadow: 0 0 0 3px #ff5a4a; } 78%, 90% { opacity: 0; transform: scale(0.3); } 100% { opacity: 1; } }

@media (max-height: 640px) {
  #game { gap: 5px; --bw: min(92vw, 420px, calc(100dvh - 290px)); }
  .ck-c { min-height: 28px; padding: 3px 9px; }
  .ck-msg { min-height: 36px; font-size: 13px; }
  .overlay-card.ck-card { padding: 16px 18px; gap: 8px; }
  .overlay-card.ck-card .overlay-score { font-size: 44px; }
  .overlay-card.ck-card h2 { font-size: 20px; }
  .overlay-card.ck-card button { min-height: 40px; padding: 9px 18px; }
  .ck-howto { font-size: 13px; }
}
.overlay { padding-top: max(64px, env(safe-area-inset-top)); }
