:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --text-primary: #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted: #484F58;
  --accent: #3B82F6;
  --border: #30363D;
  --btn-bg: #21262D;
  --btn-active: #30363D;
  --overlay-bg: rgba(0, 0, 0, 0.85);
  --board-bg: #0A0E14;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F8FA;
    --bg-tertiary: #E9ECF0;
    --text-primary: #1B1E28;
    --text-secondary: #57606A;
    --text-muted: #8C959F;
    --accent: #3182F6;
    --border: #D0D7DE;
    --btn-bg: #E9ECF0;
    --btn-active: #D0D7DE;
    --overlay-bg: rgba(255, 255, 255, 0.9);
    --board-bg: #F0F2F5;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

/* ── App Container ── */
#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Overlay Screens ── */
.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
  padding: 24px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Title ── */
.game-title {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 50%, #EC4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  line-height: 1.1;
}

.game-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: -8px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  width: 100%;
  max-width: 260px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--btn-active);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
  background: #2563EB;
  border-color: #2563EB;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5);
}

/* ── Difficulty Selector ── */
.difficulty-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 260px;
}

.difficulty-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.difficulty-pills {
  display: flex;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  width: 100%;
}

.diff-btn {
  flex: 1;
  padding: 8px 4px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.diff-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Stats ── */
.stats-row {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  min-width: 72px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
}

/* ── Result Overlay ── */
.result-icon {
  font-size: 4rem;
  line-height: 1;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
}

.result-score {
  font-size: 1rem;
  color: var(--text-secondary);
}

.result-score strong {
  color: var(--accent);
}

/* ── Game Screen ── */
#game-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 12px 12px 8px;
  gap: 10px;
}

/* ── Header ── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  background: var(--btn-bg);
  color: var(--text-primary);
}

/* ── Score Panel ── */
.score-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
}

.player-score {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-score.right {
  flex-direction: row-reverse;
}

.disc-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.disc-icon.black {
  background: radial-gradient(circle at 35% 35%, #555, #111);
  border: 2px solid #333;
}

.disc-icon.white {
  background: radial-gradient(circle at 35% 35%, #fff, #ccc);
  border: 2px solid #ddd;
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.player-score.right .player-info {
  align-items: flex-end;
}

.player-name {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.player-count {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}

.score-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 48px;
}

.turn-indicator {
  font-size: 0.68rem;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-align: center;
  font-weight: 600;
}

.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.turn-dot.black { background: #888; }
.turn-dot.white { background: #ddd; }

/* ── Active player highlight ── */
.player-score.active .player-name {
  color: var(--accent);
}

.player-score.active .player-count {
  color: var(--accent);
}

/* ── Status Bar ── */
.status-bar {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-height: 18px;
  font-weight: 500;
  transition: opacity 0.3s;
}

/* ── Board ── */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: min(100%, calc(100dvh - 200px));
  max-width: 420px;
  background: var(--board-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  gap: 0;
}

/* ── Cells ── */
.cell {
  position: relative;
  cursor: pointer;
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cell:hover {
  background: var(--bg-tertiary);
}

.cell.valid-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.45;
  pointer-events: none;
}

.cell.valid-move:hover::after {
  opacity: 0.7;
}

/* ── Disc ── */
.disc {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  position: absolute;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.disc.black {
  background: radial-gradient(circle at 35% 35%, #555, #0a0a0a);
  box-shadow: 0 3px 8px rgba(0,0,0,0.6), inset 0 1px 2px rgba(255,255,255,0.1);
}

.disc.white {
  background: radial-gradient(circle at 35% 35%, #ffffff, #c8c8c8);
  box-shadow: 0 3px 8px rgba(0,0,0,0.35), inset 0 1px 2px rgba(255,255,255,0.8);
}

/* Flip animation */
@keyframes flip-to-white {
  0%   { transform: rotateY(0deg) scale(1); }
  40%  { transform: rotateY(90deg) scale(0.85); }
  50%  { transform: rotateY(90deg) scale(0.85); }
  100% { transform: rotateY(0deg) scale(1); }
}

@keyframes flip-to-black {
  0%   { transform: rotateY(0deg) scale(1); }
  40%  { transform: rotateY(-90deg) scale(0.85); }
  50%  { transform: rotateY(-90deg) scale(0.85); }
  100% { transform: rotateY(0deg) scale(1); }
}

@keyframes place-disc {
  0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
  60%  { transform: scale(1.12) rotate(5deg); }
  80%  { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

.disc.flip-to-white {
  animation: flip-to-white 0.35s ease forwards;
}

.disc.flip-to-black {
  animation: flip-to-black 0.35s ease forwards;
}

.disc.placing {
  animation: place-disc 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ── Footer ── */
.game-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 4px;
}

.footer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.footer-btn:hover {
  background: var(--btn-active);
  color: var(--text-primary);
}

/* ── AI Thinking ── */
.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%            { opacity: 1;   transform: scale(1.1); }
}

/* ── Corner highlights ── */
.cell[data-row="0"][data-col="0"],
.cell[data-row="0"][data-col="7"],
.cell[data-row="7"][data-col="0"],
.cell[data-row="7"][data-col="7"] {
  border-color: color-mix(in srgb, var(--accent) 20%, var(--border));
}

/* ── Scrollbar hide ── */
::-webkit-scrollbar { display: none; }
