:root {
  --primary-color: #667eea;
  --primary-hover: #5568d3;
  --secondary-color: #6c757d;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border-radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
  --transition: all 0.3s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-primary);
  overflow-x: hidden;
}

/* 顶部导航栏 */
.header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.online-status {
  color: var(--success-color);
  font-size: 0.875rem;
  font-weight: 500;
}

.room-code {
  background: var(--primary-color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.875rem;
}

.room-code strong {
  font-weight: 700;
  letter-spacing: 1px;
}

/* 主游戏区域 */
.game-wrapper {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 2rem;
}

.game-container {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 2rem;
  margin-bottom: 2rem;
}

/* 玩家信息面板 */
.player-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.player-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}

.player-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.my-card {
  border: 2px solid var(--primary-color);
}

.player-avatar {
  position: relative;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  position: relative;
  overflow: hidden;
}

.avatar::before {
  content: '♔';
  font-size: 2.5rem;
}

.black-side {
  background: linear-gradient(135deg, #434343 0%, #000000 100%);
  color: white;
}

.red-side {
  background: linear-gradient(135deg, #ff6b6b 0%, #c92a2a 100%);
  color: white;
}

.avatar.active {
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.3);
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.3);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(102, 126, 234, 0.1);
  }
}

.player-info {
  text-align: center;
  width: 100%;
}

.player-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.player-side {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.timer {
  background: #f3f4f6;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-color);
}

.status-indicator {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-color);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* 棋盘区域 */
.board-section {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 600px;
}

#gameCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
}

.game-status {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 10;
}

/* 控制按钮栏 */
.controls-bar {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  min-width: 100px;
  justify-content: center;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn .icon {
  font-size: 1.125rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

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

.btn-secondary {
  background: #e5e7eb;
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #d1d5db;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

/* 对话框 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: var(--border-radius);
  min-width: 400px;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
}

.modal-body p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}

.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.9375rem;
  transition: var(--transition);
  outline: none;
}

.input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* 加载提示 */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading p {
  margin-top: 1rem;
  color: white;
  font-size: 0.9375rem;
}

/* Toast提示 */
.toast {
  position: fixed;
  top: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 1rem 2rem;
  border-radius: 8px;
  font-size: 0.9375rem;
  z-index: 1001;
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease-out, fadeOut 0.3s ease-out 2.7s;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
  }
}

.hidden {
  display: none !important;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .game-container {
    grid-template-columns: 240px 1fr 240px;
    gap: 1.5rem;
  }

  .player-card {
    padding: 1rem;
  }

  .avatar {
    width: 60px;
    height: 60px;
  }
}

@media (max-width: 992px) {
  .game-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .player-left {
    order: 1;
  }

  .board-section {
    order: 2;
  }

  .player-right {
    order: 3;
  }

  .player-card {
    flex-direction: row;
    justify-content: flex-start;
  }

  .player-info {
    text-align: left;
  }
}

@media (max-width: 768px) {
  .header-content {
    padding: 1rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .game-wrapper {
    padding: 0 1rem;
    margin: 1rem auto;
  }

  .board-section {
    padding: 1rem;
  }

  .controls-bar {
    padding: 1rem;
  }

  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    min-width: auto;
  }

  .modal {
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .controls-bar {
    gap: 0.5rem;
  }

  .btn span:not(.icon) {
    display: none;
  }

  .btn {
    min-width: 48px;
    padding: 0.75rem;
  }
}
