/* ============================================
   TERRITORY (DOTS AND BOXES) STYLES
   ============================================ */

/* Game Canvas */
#game-canvas {
  display: block;
  margin: 0 auto;
  width: auto;
  max-width: 100%;
  height: auto;
  touch-action: none;
  border-radius: 8px;
  background: #1a1a2e;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Board Container */
.board-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 10px;
  background: linear-gradient(145deg, #16213e, #0f0f23);
  border-radius: 12px;
  margin: 10px 0;
  box-sizing: border-box;
}

/* ============================================
   PLAYER CARD - Territory-specific styles only
   Base styles inherited from common.css
   ============================================ */
/* Color indicator for Territory */
.player-card .color-indicator {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}

.player-card .color-indicator.player1-color {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  border: 1px solid #c0392b;
}

.player-card .color-indicator.player2-color {
  background: linear-gradient(135deg, #3498db, #2980b9);
  border: 1px solid #2980b9;
}
/* Territory uses score instead of timer */
.player-card .score {
  font-family: monospace;
  font-size: 14px;
  font-weight: bold;
}

#player1-card .score {
  color: #e74c3c;
}

#player2-card .score {
  color: #3498db;
}

/* Chat Tabs (Omok style) */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0;
}

.chat-tab {
  flex: 1;
  padding: 10px 15px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.chat-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-weight: 500;
}

.participant-count {
  background: var(--accent);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
}

/* Tab Content (Omok style) */
.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#chat-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#chat-content .chat-messages {
  flex: 1;
}

/* Participants List (Omok style) */
.participants-list {
  padding: 10px;
  overflow-y: auto;
  height: 100%;
}
.participant-section {
  margin-bottom: 15px;
}
.participant-section-header {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-color);
}
.participant-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.participant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-size: 13px;
}
.participant-item.player {
  border-left: 3px solid var(--accent);
}
.participant-item.host {
  border-left: 3px solid #f1c40f;
}
.participant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.participant-info {
  flex: 1;
}
.participant-name {
  font-weight: 500;
  color: var(--text-primary);
}
.participant-role {
  font-size: 11px;
  color: var(--text-secondary);
}
.participant-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}
.participant-badge.host {
  background: #f1c40f;
  color: #000;
}
.participant-badge.red {
  background: #e74c3c;
  color: #fff;
}
.participant-badge.blue {
  background: #3498db;
  color: #fff;
}
.empty-participants {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  font-size: 13px;
}

/* ============================================
   GAME OVER MODAL (match other board games)
   ============================================ */
#game-over-modal .modal {
  width: min(560px, 94vw);
}

#game-over-modal .game-over-content h2 {
  font-size: 42px;
  margin-bottom: 14px;
  letter-spacing: -0.4px;
}

#game-over-modal .game-over-content .result {
  margin-bottom: 14px;
}

#game-over-modal .game-over-content .rating-change {
  margin-bottom: 10px;
  font-size: 19px;
}

#game-over-modal .modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 6px;
}

#game-over-modal .modal-actions .btn {
  min-height: 58px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 800;
}

#game-over-modal .btn-close-gameover {
  background: linear-gradient(135deg, #4a5d83 0%, #374968 100%);
  border: 1px solid rgba(202, 219, 245, 0.35);
  color: #f6fbff;
}

#game-over-modal .btn-rematch-gameover {
  background: linear-gradient(135deg, #ff607f 0%, #ea3d65 100%);
  border: 1px solid rgba(255, 192, 211, 0.45);
  color: #fff;
}

#game-over-modal .modal-actions .btn:hover {
  filter: brightness(1.06);
}

@media (max-width: 480px) {
  #game-over-modal .game-over-content h2 {
    font-size: 34px;
  }

  #game-over-modal .modal-actions .btn {
    min-height: 52px;
    font-size: 16px;
  }
}

/* Final Score in Game Over Modal */
.final-score {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
  color: var(--text-primary);
}

/* AI Badge */
.ai-badge {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
}

/* AI board cards in AI modal */
.ai-board-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.ai-board-card {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(180deg, rgba(40, 57, 97, 0.55), rgba(25, 36, 64, 0.6));
  color: var(--text-primary);
  border-radius: 8px;
  min-height: 42px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.ai-board-card:hover {
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}

.ai-board-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 94, 130, 0.45) inset;
  background: linear-gradient(180deg, rgba(75, 96, 158, 0.65), rgba(49, 64, 112, 0.72));
}

.ai-board-card-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

/* Create-room time limit cards */
.time-limit-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Waiting Overlay */
.waiting-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 12px;
  z-index: 10;
}

.waiting-overlay.active {
  display: flex;
}

.waiting-overlay h3 {
  margin-top: 20px;
  color: var(--text-primary);
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive - 820px 이하: 게임판 화면 너비 꽉 차게 */
@media (max-width: 820px) {
  .board-container {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
  }

  #game-canvas {
    width: 100%;
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 480px) {
  .player-card {
    min-width: 140px;
    padding: 8px 10px;
  }

  .player-card .name {
    font-size: 13px;
  }

  .player-card .score {
    font-size: 16px;
  }

  .player-card .color-indicator {
    width: 16px;
    height: 16px;
  }

  .board-container {
    padding: 4px;
  }
}

/* Light Theme Adjustments */
.theme-light .board-container {
  background: linear-gradient(145deg, #e8e8e8, #f5f5f5);
}

.theme-light #game-canvas {
  background: #f0f0f0;
}

.theme-light .player-card {
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.theme-light .player-score {
  background: rgba(0, 0, 0, 0.05);
}

/* Responsive Ads */
@media (max-width: 768px) {
  .ad-pc-only { display: none !important; }
}
@media (min-width: 769px) {
  .ad-mobile-only { display: none !important; }
}

/* Ad Lobby Center */
.ad-lobby {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

/* 게임방 모바일 하단 광고 320x50 (스크롤) */
.ad-mobile-fixed {
  position: static;
  margin: 10px auto;
  width: 320px;
  height: 50px;
}

.ad-mobile-fixed.hidden {
  display: none;
}

/* ============================================
   SIDEBAR TAB (탭 기반 통합 사이드바)
   ============================================ */
.sidebar {
  padding: 1px;
  gap: 1px;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1px;
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.sidebar-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -1px;
}

.sidebar-tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}

#sidebar-chat-content .chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--bg-card);
  border-radius: 1px;
  overflow: hidden;
  min-height: 0;
}

#sidebar-chat-content .chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#sidebar-chat-content .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1px;
  min-height: 150px;
}

#sidebar-chat-content .game-controls {
  padding: 10px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

#sidebar-chat-content .game-controls .btn {
  flex: 1;
  min-width: 80px;
}

.sidebar .ad-sidebar {
  flex-shrink: 0;
  margin-top: auto;
  display: flex;
  justify-content: center;
}

@media (max-width: 820px) {
  .sidebar-tabs {
    display: none;
  }
}


/* chat-fab: mobile only */
.chat-fab {
  display: none !important;
}

@media (max-width: 820px) {
  .chat-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 48px;
    height: 48px;
    border-radius: 24px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
  }
}
