/* ===========================
   디자인 토큰
   =========================== */
:root {
  /* 배경 */
  --bg-primary: #0a0a1a;
  --bg-secondary: #1a1a3e;
  --bg-glass: rgba(255, 255, 255, 0.05);
  --bg-glass-hover: rgba(255, 255, 255, 0.1);

  /* 플레이어 색상 */
  --color-o: #00d4ff;
  --color-o-glow: rgba(0, 212, 255, 0.4);
  --color-x: #ff006e;
  --color-x-glow: rgba(255, 0, 110, 0.4);

  /* 텍스트 */
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-tertiary: rgba(255, 255, 255, 0.4);

  /* 보드 */
  --cell-border: rgba(255, 255, 255, 0.1);
  --cell-size: 120px;
  --board-gap: 8px;

  /* 효과 */
  --glass-blur: 20px;
  --border-radius: 16px;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

/* ===========================
   리셋 & 기본
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary));
  min-height: 100vh;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ===========================
   게임 컨테이너
   =========================== */
.game-container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

h1 {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--color-o), var(--color-x));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

/* ===========================
   모드 선택
   =========================== */
.mode-select {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.mode-select[hidden] {
  display: none;
}

.mode-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.mode-btn {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all var(--transition-normal);
  text-align: center;
}

.mode-btn:hover {
  background: var(--bg-glass-hover);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.2), 0 0 40px rgba(255, 0, 110, 0.1);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 1.8rem;
}

.mode-label {
  font-size: 1rem;
  font-weight: 700;
}

.mode-desc {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* ===========================
   로그인 화면
   =========================== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  width: 100%;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.login-title {
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 2rem;
}

.btn-google {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  background: white;
  color: #333;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  font-family: 'Inter', sans-serif;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-google:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.btn-google:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.login-error {
  color: #f87171;
  margin-top: 1rem;
  font-size: 0.9rem;
  min-height: 1.3em;
}

/* ===========================
   로비 화면
   =========================== */
.lobby-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  width: 100%;
}

.lobby-screen[hidden] {
  display: none;
}

.lobby-card {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 2.5rem;
  max-width: 440px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.lobby-user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
}

.btn-text {
  background: none;
  border: none;
  color: #a78bfa;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  text-decoration: underline;
}

.btn-text:hover {
  color: #c4b5fd;
}

.lobby-tabs {
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 4px;
}

.lobby-tab {
  flex: 1;
  padding: 0.6rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.lobby-tab.active {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.lobby-panel[hidden] {
  display: none;
}

.room-code-display {
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

.room-code {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0.5rem 0;
}

.waiting-text {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.room-code-input {
  width: 100%;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: white;
  font-size: 1.3rem;
  font-family: 'Inter', sans-serif;
  text-align: center;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s;
}

.room-code-input:focus {
  border-color: #a78bfa;
}

.room-code-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.1em;
  font-size: 0.95rem;
}

.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 0.85rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.lobby-error {
  color: #f87171;
  font-size: 0.9rem;
  min-height: 1.3em;
}

/* 온라인 게임 상태 배너 */
.online-status-banner {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  width: 100%;
}

.online-status-banner[hidden] {
  display: none;
}

/* ===========================
   선공 선택
   =========================== */
.first-select {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.first-select[hidden] {
  display: none;
}

.first-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
}

.first-btn {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all var(--transition-normal);
  text-align: center;
}

.first-btn:hover {
  background: var(--bg-glass-hover);
  transform: translateY(-2px);
}

#first-btn-o:hover {
  border-color: var(--color-o);
  box-shadow: 0 0 20px var(--color-o-glow);
}

#first-btn-x:hover {
  border-color: var(--color-x);
  box-shadow: 0 0 20px var(--color-x-glow);
}

.first-symbol {
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1;
}

.first-symbol.o {
  color: var(--color-o);
  text-shadow: 0 0 20px var(--color-o-glow);
}

.first-symbol.x {
  color: var(--color-x);
  text-shadow: 0 0 20px var(--color-x-glow);
}

.first-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.btn-back {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-tertiary);
  font-size: 0.85rem;
  padding: 10px 20px;
  flex: unset;
  width: auto;
}

.btn-back:hover {
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.3);
  transform: none;
}

/* ===========================
   게임 영역
   =========================== */
.game-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.game-area[hidden] {
  display: none;
}

/* 보드 + 사이드 패널 가로 배치 */
.game-body {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

/* 사이드 패널 */
.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 160px;
  flex-shrink: 0;
}

/* ===========================
   게임 헤더
   =========================== */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--cell-border);
  border-radius: var(--border-radius);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.player-badge {
  font-size: 1.1rem;
  font-weight: 900;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.player-badge.o-turn {
  color: var(--color-o);
  background: rgba(0, 212, 255, 0.15);
  box-shadow: 0 0 12px var(--color-o-glow);
}

.player-badge.x-turn {
  color: var(--color-x);
  background: rgba(255, 0, 110, 0.15);
  box-shadow: 0 0 12px var(--color-x-glow);
}

.turn-counter {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  font-weight: 600;
}

/* ===========================
   보드
   =========================== */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--board-gap);
  padding: 12px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--cell-border);
  border-radius: var(--border-radius);
  flex: 1;
  min-width: 0;
  max-width: 420px;
}

.board.disabled {
  pointer-events: none;
  opacity: 0.7;
}

/* ===========================
   셀
   =========================== */
.cell {
  aspect-ratio: 1;
  background: var(--bg-glass);
  border: 1px solid var(--cell-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: background var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
}

.cell:hover {
  background: var(--bg-glass-hover);
  transform: scale(1.02);
  border-color: rgba(255, 255, 255, 0.2);
}

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

/* 마크 텍스트 */
.cell-mark {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.cell-mark.o {
  color: var(--color-o);
  text-shadow: 0 0 20px var(--color-o-glow);
}

.cell-mark.x {
  color: var(--color-x);
  text-shadow: 0 0 20px var(--color-x-glow);
}

/* 마크 순서 번호 */
.cell-order {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.5;
  z-index: 2;
  line-height: 1;
}

.cell-order.o {
  color: var(--color-o);
}

.cell-order.x {
  color: var(--color-x);
}

/* 호버 미리보기 */
.cell[data-hover]::after {
  content: attr(data-hover);
  position: absolute;
  font-size: 2.5rem;
  font-weight: 700;
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
}

.cell[data-hover="O"]::after {
  color: var(--color-o);
  text-shadow: 0 0 20px var(--color-o-glow);
}

.cell[data-hover="X"]::after {
  color: var(--color-x);
  text-shadow: 0 0 20px var(--color-x-glow);
}

/* ===========================
   플레이어 정보
   =========================== */
.player-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.player-card {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--cell-border);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.player-card.active-o {
  border-color: rgba(0, 212, 255, 0.4);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.15);
}

.player-card.active-x {
  border-color: rgba(255, 0, 110, 0.4);
  box-shadow: 0 0 16px rgba(255, 0, 110, 0.15);
}

.player-symbol {
  font-size: 1.5rem;
  font-weight: 900;
}

.player-symbol.o {
  color: var(--color-o);
  text-shadow: 0 0 12px var(--color-o-glow);
}

.player-symbol.x {
  color: var(--color-x);
  text-shadow: 0 0 12px var(--color-x-glow);
}

.player-marks {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.player-score {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===========================
   버튼
   =========================== */
.game-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.btn {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--cell-border);
  border-radius: var(--border-radius);
  background: var(--bg-glass);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

.btn:hover {
  background: var(--bg-glass-hover);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

/* ===========================
   결과 오버레이
   =========================== */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.result-overlay[hidden] {
  display: none;
}

.result-content {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: calc(var(--border-radius) * 1.5);
  padding: 40px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 340px;
  width: 100%;
  animation: overlayAppear 0.4s ease forwards;
}

.result-title {
  font-size: 2rem;
  font-weight: 900;
}

.result-title.o-win {
  color: var(--color-o);
  text-shadow: 0 0 30px var(--color-o-glow);
}

.result-title.x-win {
  color: var(--color-x);
  text-shadow: 0 0 30px var(--color-x-glow);
}

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

.result-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  width: 100%;
}

/* ===========================
   애니메이션
   =========================== */
@keyframes markAppear {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

@keyframes markRemove {
  from { transform: scale(1); opacity: 1; }
  to   { transform: scale(0); opacity: 0; }
}

@keyframes vulnerable {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

@keyframes winGlow {
  0%, 100% { box-shadow: 0 0 10px var(--glow-color); }
  50%       { box-shadow: 0 0 30px var(--glow-color), 0 0 60px var(--glow-color); }
}

@keyframes overlayAppear {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* 애니메이션 클래스 */
.cell.mark-appear .cell-mark {
  animation: markAppear 0.3s ease forwards;
}

.cell.mark-remove .cell-mark {
  animation: markRemove 0.3s ease forwards;
}

.cell.vulnerable {
  animation: vulnerable 1s ease-in-out infinite;
}

.cell.win-cell.o-win {
  --glow-color: var(--color-o-glow);
  animation: winGlow 1s ease-in-out infinite;
  border-color: var(--color-o);
}

.cell.win-cell.x-win {
  --glow-color: var(--color-x-glow);
  animation: winGlow 1s ease-in-out infinite;
  border-color: var(--color-x);
}

/* ===========================
   반응형
   =========================== */
@media (max-width: 700px) {
  .game-body {
    flex-direction: column;
    align-items: center;
  }

  .game-sidebar {
    flex-direction: row;
    width: 100%;
    min-width: unset;
    gap: 12px;
  }

  .player-info {
    flex-direction: row;
    flex: 1;
  }

  .game-actions {
    flex-direction: column;
    flex: 0 0 auto;
  }

  .board {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  :root {
    --cell-size: 90px;
    --board-gap: 6px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .cell-mark {
    font-size: 2rem;
  }

  .mode-btn {
    padding: 16px 12px;
  }

  .mode-icon {
    font-size: 1.4rem;
  }

  .mode-label {
    font-size: 0.9rem;
  }

  .result-title {
    font-size: 1.6rem;
  }

  .game-sidebar {
    flex-direction: column;
  }

  .player-info {
    flex-direction: row;
  }
}
