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

/* ─── Seega ────────────────────────────────────────────────
   5×5 sandstone board, the centre square carved with a rosette. Light limestone stones
   are yours, dark basalt stones are the computer's. */
body { background: radial-gradient(120% 80% at 50% 0%, #1a1712 0%, #0b0a09 60%) fixed, #0b0a09; }

#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}
.sg-top, .sg-bot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px, calc(100dvh - 268px));
  min-width: 260px;
  align-self: center;
}
.sg-c, .sg-info, .sg-lvl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  min-height: 28px;
  border-radius: 999px;
  background: #17140f;
  border: 1px solid #2e271d;
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.sg-c .sg-who { font-size: 12px; font-weight: 700; color: #b9ad98; }
.sg-c i { width: 13px; height: 13px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.sg-c.me i { background: radial-gradient(circle at 35% 30%, #fffdf6, #e8dcc3 55%, #b7a684); }
.sg-c.foe i { background: radial-gradient(circle at 35% 30%, #6d7a86, #2c333b 60%, #15191d); box-shadow: 0 0 0 1px #6f7c88; }
.sg-c em { font-style: normal; font-size: 11.5px; font-weight: 700; color: #d9b878; }
.sg-c em:empty { display: none; }
.sg-c.turn { border-color: #d9a441; box-shadow: 0 0 0 1px rgba(217, 164, 65, 0.45); }
.sg-info, .sg-lvl { font-size: 12px; font-weight: 700; color: #b9ad98; }
.sg-info.warn { color: #ffb36b; border-color: #6a4a22; }

.sg-board {
  position: relative;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
  padding: 7px;
  width: min(92vw, 420px, calc(100dvh - 268px));
  min-width: 260px;
  aspect-ratio: 1;
  border-radius: 14px;
  background:
    radial-gradient(140% 100% at 30% 20%, rgba(255, 240, 205, 0.16), transparent 60%),
    linear-gradient(160deg, #b98c52, #8f6534 70%, #7a5429);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), inset 0 0 0 2px rgba(60, 36, 12, 0.55), inset 0 2px 0 rgba(255, 235, 190, 0.25);
}
.sg-sq {
  position: relative;
  padding: 0;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  background:
    radial-gradient(120% 120% at 30% 25%, rgba(255, 244, 214, 0.22), transparent 55%),
    linear-gradient(150deg, #dcb77a, #c99d5d);
  box-shadow: inset 0 2px 3px rgba(70, 40, 10, 0.45), inset 0 -1px 0 rgba(255, 240, 200, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
  font: inherit;
}
/* carved rosette on the centre square */
.sg-sq.centre::before {
  content: "";
  position: absolute;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 22%, rgba(90, 52, 16, 0.55) 23% 27%, transparent 28% 44%, rgba(90, 52, 16, 0.45) 45% 49%, transparent 50%),
    repeating-conic-gradient(from 0deg, rgba(90, 52, 16, 0.38) 0 10deg, transparent 10deg 45deg);
  -webkit-mask: radial-gradient(circle, #000 0 50%, transparent 51%);
          mask: radial-gradient(circle, #000 0 50%, transparent 51%);
  opacity: 0.9;
}
/* placement hint dot on empty squares you may use */
.sg-sq.open::after {
  content: "";
  position: absolute;
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 248, 230, 0.55);
  box-shadow: 0 0 0 2px rgba(120, 76, 30, 0.25);
}
.sg-sq > .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;
}
.sg-sq.me > .st, .sg-sq.foe > .st { opacity: 1; transform: scale(1); }
.sg-sq.me > .st {
  background: radial-gradient(circle at 34% 28%, #ffffff 0 8%, #f6efe0 22%, #e3d5b8 58%, #b29d76 100%);
  box-shadow: 0 3px 0 rgba(60, 36, 12, 0.55), 0 5px 8px rgba(40, 20, 0, 0.35), inset 0 -3px 5px rgba(120, 96, 60, 0.35);
}
.sg-sq.foe > .st {
  background: radial-gradient(circle at 34% 28%, #9aa6b1 0 7%, #4d5762 26%, #262c33 62%, #111418 100%);
  box-shadow: 0 3px 0 rgba(30, 18, 6, 0.65), 0 5px 8px rgba(20, 10, 0, 0.4), inset 0 -3px 5px rgba(0, 0, 0, 0.45);
}
.sg-sq.can > .st { box-shadow: 0 3px 0 rgba(60, 36, 12, 0.55), 0 0 0 3px rgba(255, 255, 255, 0.55); }
.sg-sq.sel > .st {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 6px 10px rgba(40, 20, 0, 0.45), 0 0 0 3px #ffd36b, 0 0 14px rgba(255, 211, 107, 0.7);
}
.sg-sq.threat > .st { animation: sg-wobble 0.9s ease-in-out infinite; box-shadow: 0 3px 0 rgba(30, 18, 6, 0.65), 0 0 0 3px #ff5a4a; }
.sg-sq.to::after {
  content: "";
  position: absolute;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 250, 235, 0.75);
  box-shadow: 0 0 0 3px rgba(110, 70, 25, 0.35);
}
.sg-sq.to.cap {
  background: radial-gradient(circle, #ffe9a8 0 30%, #f0bf4f 70%, #d79a2b);
  box-shadow: inset 0 0 0 2px #fff1c4, 0 0 12px rgba(255, 196, 70, 0.6);
}
.sg-sq.to.cap::before { display: none; }
.sg-sq.to.cap::after {
  content: attr(data-cap);
  width: auto;
  background: none;
  box-shadow: none;
  font-size: clamp(13px, 4.4vw, 19px);
  font-weight: 900;
  color: #5a3200;
}
.sg-sq.last { box-shadow: inset 0 2px 3px rgba(70, 40, 10, 0.45), inset 0 0 0 3px rgba(255, 222, 130, 0.95); }
.sg-sq.fresh > .st { animation: sg-drop 0.26s ease-out; }
.sg-sq.gone > .st { opacity: 0; transform: scale(1); animation: sg-gone 0.52s ease-in forwards; }
.sg-sq.gone::after {
  content: "";
  position: absolute;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(255, 110, 80, 0.9);
  animation: sg-ring 0.52s ease-out forwards;
}
@keyframes sg-drop { from { transform: scale(1.35) translateY(-6px); opacity: 0.2; } to { transform: scale(1); opacity: 1; } }
@keyframes sg-gone { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(0.3) rotate(25deg); } }
@keyframes sg-ring { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
@keyframes sg-wobble { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

.sg-msg {
  margin: 0;
  min-height: 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: #d8ccb4;
  line-height: 1.35;
}
.sg-msg.ok { color: #7ee2a0; }
.sg-msg.bad { color: #ff8a7a; }
.sg-msg.dim { color: #9a8f7c; }

/* start card */
.sg-howto { text-align: left; font-size: 14px; line-height: 1.45; color: #d6d0c4; }
.sg-howto p { margin: 0 0 6px; }
.sg-howto b { color: #ffd98a; }
.sg-demo { display: flex; gap: 6px; padding: 6px; border-radius: 10px; background: linear-gradient(150deg, #dcb77a, #c99d5d); }
.sg-demo i { width: 30px; height: 30px; border-radius: 50%; display: block; }
.sg-demo i.me { background: radial-gradient(circle at 34% 28%, #fff, #e3d5b8 58%, #b29d76); }
.sg-demo i.foe { background: radial-gradient(circle at 34% 28%, #9aa6b1 0 7%, #4d5762 26%, #262c33 62%, #111418); animation: sg-demo-foe 2.4s ease-in infinite; }
.sg-demo i.arrive { animation: sg-demo-arrive 2.4s ease-out infinite; }
@keyframes sg-demo-arrive { 0%, 15% { transform: translateX(36px); opacity: 0.3; } 40%, 100% { transform: none; opacity: 1; } }
@keyframes sg-demo-foe { 0%, 45% { opacity: 1; transform: none; } 70%, 85% { opacity: 0; transform: scale(0.3); } 100% { opacity: 1; transform: none; } }

@media (max-height: 600px) {
  #game { gap: 7px; }
  .sg-c, .sg-info, .sg-lvl { min-height: 26px; padding: 3px 9px; }
}

@media (max-height: 640px) {
  .overlay-card.sg-card { padding: 16px 18px; gap: 8px; }
  .overlay-card.sg-card .overlay-score { font-size: 44px; }
  .overlay-card.sg-card h2 { font-size: 20px; }
  .overlay-card.sg-card button { min-height: 40px; padding: 9px 18px; }
}
.overlay { padding-top: max(64px, env(safe-area-inset-top)); }
