/* ========================================
   四子棋 Connect Four - 样式
   ======================================== */

/* -- Reset & Base -- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-start: #0a0e27;
  --bg-end: #1a1040;
  --board-bg: #1e3a8a;
  --board-border: #2563eb;
  --board-shadow: rgba(37, 99, 235, 0.4);
  --cell-bg: #0f172a;
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.6);
  --red-light: #fca5a5;
  --yellow: #eab308;
  --yellow-glow: rgba(234, 179, 8, 0.6);
  --yellow-light: #fde68a;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.4);
  --success: #22c55e;
  --radius: 12px;
  --radius-lg: 20px;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--bg-start) 0%, var(--bg-end) 50%, #0d1137 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px 40px;
  overflow-x: hidden;
}

/* -- Container -- */
.container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
}

/* -- Header -- */
.header {
  text-align: center;
}

.title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #c084fc, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.title-icon {
  -webkit-text-fill-color: initial;
  font-size: 1.6rem;
}

.title-sub {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  align-self: flex-end;
  margin-bottom: 4px;
}

/* -- Controls -- */
.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.control-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.toggle-buttons {
  display: flex;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.toggle-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* -- Players Bar -- */
.players-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 10px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 6px 10px;
  border-radius: 10px;
  transition: all 0.3s ease;
  opacity: 0.5;
}

.player-info.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.05);
}

.player-info.player-1.active {
  box-shadow: inset 0 0 20px rgba(239, 68, 68, 0.1);
}

.player-info.player-2.active {
  box-shadow: inset 0 0 20px rgba(234, 179, 8, 0.1);
}

.player-piece {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.piece-red {
  background: radial-gradient(circle at 35% 35%, var(--red-light), var(--red) 60%, #b91c1c);
  box-shadow: 0 0 8px var(--red-glow);
}

.piece-yellow {
  background: radial-gradient(circle at 35% 35%, var(--yellow-light), var(--yellow) 60%, #a16207);
  box-shadow: 0 0 8px var(--yellow-glow);
}

.player-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.player-score {
  margin-left: auto;
  font-size: 1.2rem;
  font-weight: 800;
  opacity: 0.8;
}

.vs-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.05em;
}

/* -- Board -- */
.board-wrapper {
  position: relative;
}

.board-top {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 0 12px;
  margin-bottom: 0;
  height: 40px;
}

.col-hover {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  padding-bottom: 4px;
}

.col-hover .preview-piece {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: scale(0.7);
}

.col-hover:hover .preview-piece {
  opacity: 0.5;
  transform: scale(0.85);
}

.col-hover.disabled {
  cursor: not-allowed;
}

.col-hover.disabled .preview-piece {
  opacity: 0 !important;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  padding: 12px;
  background: linear-gradient(180deg, var(--board-bg) 0%, #1d4ed8 50%, var(--board-bg) 100%);
  border-radius: var(--radius-lg);
  border: 2px solid var(--board-border);
  box-shadow:
    0 8px 40px var(--board-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  position: relative;
}

.cell {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--cell-bg);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s ease;
}

.cell:hover {
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(255, 255, 255, 0.05),
    0 0 12px rgba(99, 102, 241, 0.3);
}

.cell.disabled {
  cursor: not-allowed;
}

.cell .piece {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  opacity: 0;
  transform: translateY(-500px);
}

.cell .piece.dropped {
  opacity: 1;
  animation: dropBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.cell .piece.instant {
  opacity: 1;
  transform: translateY(0);
}

.cell .piece.red {
  background: radial-gradient(circle at 35% 35%, var(--red-light), var(--red) 60%, #b91c1c);
  box-shadow: 0 2px 10px var(--red-glow), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}

.cell .piece.yellow {
  background: radial-gradient(circle at 35% 35%, var(--yellow-light), var(--yellow) 60%, #a16207);
  box-shadow: 0 2px 10px var(--yellow-glow), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}

/* 胜利脉冲高亮 */
.cell .piece.winning {
  animation: winPulse 0.8s ease-in-out infinite alternate;
}

.cell .piece.winning.red {
  box-shadow: 0 0 20px var(--red-glow), 0 0 40px var(--red-glow), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}

.cell .piece.winning.yellow {
  box-shadow: 0 0 20px var(--yellow-glow), 0 0 40px var(--yellow-glow), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}

@keyframes dropBounce {
  0% {
    transform: translateY(-500px);
    opacity: 1;
  }
  60% {
    transform: translateY(5px);
  }
  80% {
    transform: translateY(-3px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes winPulse {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.08);
  }
}

/* -- Status Bar -- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: dotPulse 2s ease-in-out infinite;
}

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

.status-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
}

/* -- Action Buttons -- */
.actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.action-btn:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

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

.action-btn.primary {
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.action-btn.primary:hover {
  background: #7c7ff7;
  box-shadow: 0 4px 20px var(--accent-glow);
}

/* -- Overlay -- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}

.overlay-content {
  background: linear-gradient(160deg, #1e1b4b, #1a1040);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  min-width: 280px;
}

.overlay-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  animation: bounce 1s ease-in-out infinite;
}

.overlay-title {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.overlay-desc {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 24px;
}

.overlay-btn {
  padding: 10px 32px;
  font-size: 1rem;
}

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

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* -- Thinking indicator -- */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.thinking-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinkBounce 1.2s ease-in-out infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinkBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* -- Responsive -- */
@media (max-width: 480px) {
  body {
    padding: 12px 8px 32px;
  }

  .title {
    font-size: 1.5rem;
  }

  .cell {
    width: 42px;
    height: 42px;
  }

  .col-hover .preview-piece {
    width: 36px;
    height: 36px;
  }

  .board {
    padding: 8px;
    gap: 4px;
  }

  .board-top {
    gap: 4px;
    padding: 0 8px;
    height: 32px;
  }

  .player-info {
    padding: 4px 6px;
  }

  .players-bar {
    padding: 8px 12px;
    gap: 8px;
  }

  .toggle-btn {
    padding: 5px 10px;
    font-size: 0.75rem;
  }

  .controls {
    gap: 10px;
  }

  .overlay-content {
    padding: 28px 24px;
    margin: 0 16px;
  }
}

@media (max-width: 360px) {
  .cell {
    width: 36px;
    height: 36px;
  }

  .col-hover .preview-piece {
    width: 30px;
    height: 30px;
  }
}
