/* ═══════════════════════════════════════════════
   모자이크 바둑 9×9 — Global Styles
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --wood:       #c8a45a;
  --wood-light: #ddb96e;
  --wood-dark:  #9a6f2e;
  --grid:       #5a3a0a;
  --bg:         #0f1520;
  --bg2:        #141e30;
  --accent:     #e8b84b;
  --panel-bg:   rgba(255,255,255,0.05);
  --radius:     12px;
  --cell:       72px;   /* 9×9 기본 셀 크기 */
  --stone-r:    28px;
  --font:       'Noto Sans KR', sans-serif;

  /* 배경 격자 */
  --gutter: 60px;
  --gline:  rgba(255,255,255,0.055);
}

html, body {
  height: 100%;
  font-family: var(--font);
  color: #f0f0f0;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════
   배경 격자무늬 (전체 페이지)
══════════════════════════════════════════════ */
body {
  background-color: var(--bg);
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent calc(var(--gutter) - 1px),
      var(--gline) calc(var(--gutter) - 1px),
      var(--gline) var(--gutter)
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent calc(var(--gutter) - 1px),
      var(--gline) calc(var(--gutter) - 1px),
      var(--gline) var(--gutter)
    );
  background-position: 30px 30px;
}

/* 격자 교점 점 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(
    circle, rgba(255,255,255,0.12) 1px, transparent 1px
  );
  background-size: var(--gutter) var(--gutter);
  background-position: 30px 30px;
}

/* 은은한 빛 번짐 */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%,
      rgba(100,120,255,0.09) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%,
      rgba(232,184,75,0.07) 0%, transparent 60%);
}

.hidden { display: none !important; }

/* ─── HEADER ──────────────────────────────── */
.game-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(15,21,32,0.85);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(14px);
  gap: 14px;
  flex-wrap: wrap;
}

.game-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

.score-bar { display: flex; gap: 10px; }

.score-card {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 0.84rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.09);
  transition: border-color 0.3s, background 0.3s;
}
/* 플레이어 카드 강조 (내 차례) */
.score-card.active-turn {
  border-color: rgba(80,200,120,0.5);
  background: rgba(80,200,120,0.09);
}

.score-val {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  min-width: 34px;
  text-align: right;
}

.stone-mini {
  display: inline-block;
  width: 15px; height: 15px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stone-mini.black {
  background: radial-gradient(circle at 38% 35%, #555, #111);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.6);
}
.stone-mini.white {
  background: radial-gradient(circle at 38% 35%, #fff, #ccc);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

.turn-indicator {
  font-size: 0.85rem;
  padding: 5px 14px;
  border-radius: 14px;
  background: rgba(232,184,75,0.12);
  border: 1px solid rgba(232,184,75,0.26);
  white-space: nowrap;
  transition: background 0.3s, border-color 0.3s;
}


/* ─── MAIN LAYOUT ─────────────────────────── */
.game-main {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 26px;
  padding: 26px 18px;
  min-height: calc(100vh - 60px);
  flex-wrap: wrap;
}

/* ─── BOARD WRAP ──────────────────────────── */
.board-wrap {
  position: relative;
  /* half-cell 패딩: 교점이 보드 가장자리 안으로 들어옴 */
  padding: calc(var(--cell) / 2);
  /* 나무결 느낌: 베이스 wood색 위에 미세한 결 그라데이션 */
  background:
    repeating-linear-gradient(
      102deg,
      transparent 0px,
      rgba(255,255,255,0.03) 1px,
      transparent 2px,
      transparent 18px
    ),
    repeating-linear-gradient(
      8deg,
      transparent 0px,
      rgba(0,0,0,0.04) 1px,
      transparent 2px,
      transparent 22px
    ),
    linear-gradient(160deg, #dbb870 0%, #c8a45a 40%, #b8913e 100%);
  border: 4px solid var(--wood-dark);
  border-radius: 12px;
  box-shadow:
    0 0 0 2px #7a4e10,
    0 20px 60px rgba(0,0,0,0.75),
    0 4px 12px rgba(0,0,0,0.4),
    inset 0 0 0 3px #e8c878,
    inset 0 2px 8px rgba(255,240,180,0.18);
  display: inline-block;
  user-select: none;
  flex-shrink: 0;
}

/* SVG 격자선 (교점 기준) */
.board-grid-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows:    repeat(9, var(--cell));
  position: relative;
  z-index: 2;
  background: transparent;
}

/* ─── CELL ────────────────────────────────── */
.cell {
  position: relative;
  width:  var(--cell);
  height: var(--cell);
  cursor: pointer;
  overflow: visible;
  /* 셀마다 아주 미세한 나무결 오버레이 */
  background: linear-gradient(
    135deg,
    rgba(255,240,180,0.04) 0%,
    transparent 50%,
    rgba(100,60,0,0.04) 100%
  );
}

/* 타일 이미지 */
.cell-img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  transition: opacity 0.45s ease, filter 0.45s ease;
  opacity: 0.82;          /* 나무 배경이 살짝 비쳐 자연스럽게 블렌딩 */
  border-radius: 3px;
  z-index: 0;
  mix-blend-mode: multiply; /* 나무 배경색과 자연스럽게 합성 */
}

/* 바둑돌 */
.stone {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(0);
  width:  calc(var(--stone-r) * 2);
  height: calc(var(--stone-r) * 2);
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  transition: transform 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.stone.placed { transform: translate(-50%, -50%) scale(1); }

.stone.black {
  background: radial-gradient(circle at 38% 32%, #666, #0a0a0a);
  box-shadow: 2px 3px 8px rgba(0,0,0,0.8),
              inset 0 1px 2px rgba(255,255,255,0.14);
}
.stone.white {
  background: radial-gradient(circle at 38% 32%, #ffffff, #c8c8c8);
  box-shadow: 2px 3px 7px rgba(0,0,0,0.45),
              inset 0 1px 3px rgba(255,255,255,0.6);
}

/* 마지막 수 마커 */
.stone.last-move::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(255,70,70,0.88);
}

/* 착수 가능 hover 미리보기 */
.cell.can-place { cursor: crosshair; }
.cell.can-place:hover .stone-preview { display: block; }
.stone-preview {
  display: none;
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width:  calc(var(--stone-r) * 2);
  height: calc(var(--stone-r) * 2);
  border-radius: 50%;
  z-index: 9;
  pointer-events: none;
  background: radial-gradient(circle at 38% 32%, #555, #111);
  opacity: 0.38;
}

/* ─── START 셀 ────────────────────────────── */
.cell.start-cell {
  cursor: default;
  overflow: hidden;
  border-radius: 4px;
}
.cell.start-cell::before,
.cell.start-cell::after { display: none; }

.start-btn {
  position: absolute;
  inset: 4px;
  border: none;
  border-radius: 7px;
  background: linear-gradient(135deg, #e8b84b 0%, #d4920a 60%, #b87a00 100%);
  box-shadow:
    0 2px 10px rgba(0,0,0,0.5),
    inset 0 1px 2px rgba(255,255,255,0.38);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  z-index: 20;
}
.start-btn:hover {
  transform: scale(1.07);
  box-shadow: 0 4px 18px rgba(232,184,75,0.6),
              inset 0 1px 2px rgba(255,255,255,0.45);
  filter: brightness(1.1);
}
.start-btn:active { transform: scale(0.96); }
.start-btn.launching {
  animation: launchPulse 0.55s ease forwards;
}
@keyframes launchPulse {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(0);    opacity: 0; }
}
.start-icon {
  font-size: 1.35rem;
  line-height: 1;
  color: #1a1a1a;
}
.start-text {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #1a1a1a;
}

/* ─── SIDE PANEL ──────────────────────────── */
.side-panel {
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 2px;
}
.side-panel h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #666;
  margin-bottom: 8px;
}

.captured-info,
.move-log-wrap,
.rules-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 12px 14px;
  backdrop-filter: blur(6px);
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.84rem;
  color: #ccc;
  margin-bottom: 5px;
}
.captured-row:last-child { margin-bottom: 0; }
.captured-row strong { margin-left: auto; color: var(--accent); font-size: 0.95rem; }

.move-log-wrap { max-height: 220px; overflow: hidden; }
.move-log {
  list-style: decimal inside;
  font-size: 0.74rem;
  color: #999;
  max-height: 168px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.move-log li:last-child { color: var(--accent); font-weight: 600; }

.rules-box ul {
  list-style: none;
  font-size: 0.76rem;
  color: #888;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rules-box ul li::before { content: ''; }

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.87rem;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.1s;
}
button:hover  { opacity: 0.86; }
button:active { transform: scale(0.97); }

.btn-secondary { background: rgba(255,255,255,0.10); color: #eee; }
.btn-danger    { background: rgba(220,60,60,0.26); color: #ff9090;
                 border: 1px solid rgba(220,60,60,0.36); }
.btn-outline   { background: transparent; color: #999;
                 border: 1px solid rgba(255,255,255,0.13); }

/* ─── AI THINKING ─────────────────────────── */
.ai-thinking {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,14,22,0.90);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 0.87rem;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 200;
  backdrop-filter: blur(10px);
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.18s; }
.dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes dotBounce {
  0%,80%,100% { transform: scale(0.7); opacity: 0.5; }
  40%          { transform: scale(1.2); opacity: 1;   }
}

/* ─── REVEAL OVERLAY ──────────────────────── */
#reveal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,8,18,0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(10px);
  animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.reveal-inner {
  text-align: center;
  padding: 38px 30px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 22px;
  max-width: 860px;
  width: 96%;
  max-height: 96vh;
  overflow-y: auto;
}
#result-title {
  font-size: 1.85rem;
  color: var(--accent);
  margin-bottom: 8px;
}
#result-desc {
  color: #bbb;
  font-size: 0.91rem;
  margin-bottom: 24px;
}

.reveal-boards {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.reveal-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.reveal-label {
  font-size: 0.8rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
#final-canvas, #mosaic-canvas {
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  max-width: 340px;
  width: 100%;
}
.reveal-arrow {
  font-size: 2rem;
  color: var(--accent);
  align-self: center;
}
.reveal-score-detail {
  margin-bottom: 22px;
  font-size: 0.88rem;
  color: #ccc;
}
.score-table {
  margin: 0 auto 10px;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.score-table th, .score-table td {
  padding: 5px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
  text-align: center;
}
.score-table th { color: #666; font-weight: 500; font-size: 0.76rem; }
.score-table td b { color: var(--accent); }

#btn-play-again {
  padding: 13px 48px;
  font-size: 0.97rem;
  background: var(--accent);
  color: #1a1a1a;
  border-radius: 40px;
  font-weight: 700;
}

/* ─── 색 선택 모달 ────────────────────────── */
#color-modal {
  position: fixed;
  inset: 0;
  background: rgba(5,8,18,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  backdrop-filter: blur(14px);
  animation: fadeIn 0.3s ease;
}

.color-modal-inner {
  text-align: center;
  padding: 44px 40px 38px;
  background: rgba(20,28,48,0.96);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 24px;
  box-shadow: 0 24px 72px rgba(0,0,0,0.7);
  width: min(480px, 94vw);
}

.color-modal-title {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}
.color-modal-sub {
  font-size: 0.88rem;
  color: #888;
  margin-bottom: 32px;
}

.color-options {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.color-pick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 160px;
  padding: 24px 16px 20px;
  border-radius: 18px;
  border: 2px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s, background 0.18s;
  font-family: var(--font);
}

.pick-black:hover {
  border-color: rgba(200,200,200,0.6);
  background: rgba(255,255,255,0.07);
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
  transform: translateY(-4px);
}
.pick-white:hover {
  border-color: rgba(232,184,75,0.7);
  background: rgba(232,184,75,0.07);
  box-shadow: 0 8px 28px rgba(232,184,75,0.25);
  transform: translateY(-4px);
}

.color-pick-btn:active { transform: scale(0.97) translateY(0); }

.pick-stone {
  display: block;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.color-pick-btn:hover .pick-stone { transform: scale(1.1); }

.pick-stone-black {
  background: radial-gradient(circle at 36% 32%, #888, #0a0a0a);
  box-shadow: 3px 4px 12px rgba(0,0,0,0.8),
              inset 0 1px 3px rgba(255,255,255,0.18);
}
.pick-stone-white {
  background: radial-gradient(circle at 36% 32%, #ffffff, #c0c0c0);
  box-shadow: 3px 4px 12px rgba(0,0,0,0.45),
              inset 0 1px 3px rgba(255,255,255,0.8);
}

.pick-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: #eee;
  letter-spacing: 0.04em;
}
.pick-desc {
  font-size: 0.74rem;
  color: #777;
  line-height: 1.4;
}

/* 색 선택 모달 하단 안내 */
.color-modal-note {
  margin-top: 20px;
  font-size: 0.74rem;
  color: #555;
  line-height: 1.5;
}

/* ─── 페이지 이동 버튼 (바둑 ↔ 퍼즐) ────── */
.btn-goto-puzzle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.75);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s,
              color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.btn-goto-puzzle svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.btn-goto-puzzle:hover {
  background: rgba(232,184,75,0.15);
  border-color: rgba(232,184,75,0.55);
  color: var(--accent);
  box-shadow: 0 0 14px rgba(232,184,75,0.2);
  transform: translateY(-1px);
}
.btn-goto-puzzle:hover svg { transform: rotate(45deg) scale(1.1); }
.btn-goto-puzzle:active   { transform: scale(0.96); }

/* 바둑 대국 버튼 — 청록 강조 */
.btn-goto-game:hover {
  background: rgba(72,199,170,0.15);
  border-color: rgba(72,199,170,0.55);
  color: #48c7aa;
  box-shadow: 0 0 14px rgba(72,199,170,0.2);
}
.btn-goto-game:hover svg { transform: scale(1.12); }

/* ─── 장면 저장 버튼 ──────────────────────── */
.btn-snapshot {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: 14px;
  border: 1px solid rgba(232,184,75,0.35);
  background: rgba(232,184,75,0.10);
  color: #e8b84b;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s,
              transform 0.1s, box-shadow 0.2s;
}
.btn-snapshot:hover {
  background: rgba(232,184,75,0.20);
  border-color: rgba(232,184,75,0.60);
  box-shadow: 0 0 12px rgba(232,184,75,0.25);
}
.btn-snapshot:active { transform: scale(0.96); }
.btn-snapshot.saving { opacity: 0.6; cursor: wait; }
.btn-snapshot.saved  {
  background: rgba(80,200,120,0.18);
  border-color: rgba(80,200,120,0.55);
  color: #7effa0;
  animation: snapFlash 1.6s ease forwards;
}
@keyframes snapFlash {
  0%   { box-shadow: 0 0 0   rgba(80,200,120,0); }
  30%  { box-shadow: 0 0 20px rgba(80,200,120,0.5); }
  100% { box-shadow: 0 0 0   rgba(80,200,120,0); }
}
.snapshot-icon { font-size: 1rem; line-height: 1; }
.snapshot-text { letter-spacing: 0.02em; }

/* ─── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.13);
  border-radius: 3px;
}

/* ─── RESPONSIVE ──────────────────────────── */
@media (max-width: 860px) {
  :root { --cell: 54px; --stone-r: 21px; --gutter: 54px; }
  .side-panel { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .move-log-wrap { display: none; }
  .game-main { padding: 14px 10px; gap: 14px; }
}
@media (max-width: 560px) {
  :root { --cell: 40px; --stone-r: 15px; --gutter: 40px; }
  .btn-goto-puzzle span { display: none; }
  .btn-goto-puzzle { padding: 5px 8px; }
  .game-header { padding: 8px 12px; }
  .start-text  { display: none; }
  .start-icon  { font-size: 1rem; }
  .reveal-arrow { transform: rotate(90deg); }
  .rules-box { display: none; }
  .snapshot-text { display: none; }
  .btn-snapshot  { padding: 5px 9px; }
}
@media (max-width: 400px) {
  :root { --cell: 34px; --stone-r: 12px; }
}
