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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent-gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  --bg: linear-gradient(160deg, #dbeafe 0%, #e8e0ff 35%, #fce7f3 70%, #fef3c7 100%);
  --card: rgba(255, 255, 255, 0.72);
  --card-hover: rgba(255, 255, 255, 0.85);
  --card-border: rgba(255, 255, 255, 0.55);
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: rgba(148, 163, 184, 0.25);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.1);
  --radius: 22px;
  --radius-sm: 14px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  position: relative;
}

/* ===== 背景装饰 ===== */
.bg-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: float 20s ease-in-out infinite;
}
.shape-1 {
  width: 300px;
  height: 300px;
  background: #93c5fd;
  top: -80px;
  right: -60px;
  animation-delay: 0s;
}
.shape-2 {
  width: 250px;
  height: 250px;
  background: #c4b5fd;
  bottom: 10%;
  left: -80px;
  animation-delay: -7s;
}
.shape-3 {
  width: 200px;
  height: 200px;
  background: #fbcfe8;
  bottom: -50px;
  right: 20%;
  animation-delay: -14s;
}
@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  33% { transform: translateY(-25px) scale(1.05); }
  66% { transform: translateY(15px) scale(0.95); }
}

/* ===== 屏幕切换 ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  transform: scale(0.97);
  z-index: 1;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* ===== 卡片（毛玻璃） ===== */
.card {
  background: var(--card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 44px 34px;
  width: 100%;
  max-width: 390px;
  text-align: center;
  transition: background 0.3s;
}

/* ===== Logo ===== */
.logo {
  margin-bottom: 38px;
}
.logo h1 {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 8px;
  margin-top: 18px;
  background: linear-gradient(135deg, #1e293b 0%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 8px;
  letter-spacing: 12px;
  font-weight: 500;
}
.logo-stones {
  display: flex;
  justify-content: center;
  gap: 14px;
}
.logo-stone {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-block;
  transition: transform 0.3s ease;
}
.logo-stone:hover {
  transform: scale(1.15);
}
.logo-stone.black {
  background: radial-gradient(circle at 30% 30%, #777, #1a1a1a);
  box-shadow: 2px 3px 10px rgba(0, 0, 0, 0.35), inset -2px -2px 6px rgba(0,0,0,0.3);
}
.logo-stone.white {
  background: radial-gradient(circle at 30% 30%, #fff, #c8c8c8);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 2px 3px 10px rgba(0, 0, 0, 0.12), inset -1px -1px 4px rgba(0,0,0,0.05);
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 15px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.btn:active {
  transform: scale(0.96);
}
.btn-primary {
  background: var(--primary-gradient);
  color: white;
  width: 100%;
  box-shadow: 0 4px 18px var(--primary-glow);
  letter-spacing: 2px;
}
.btn-primary:hover {
  box-shadow: 0 8px 28px rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0) scale(0.98);
}
.btn-accent {
  background: var(--primary-gradient);
  color: white;
  width: 100%;
  box-shadow: 0 4px 14px var(--primary-glow);
}
.btn-accent:hover {
  box-shadow: 0 6px 22px rgba(99, 102, 241, 0.45);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.6);
  color: var(--primary);
  border: 1px solid var(--border);
  width: 100%;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--primary);
}
.btn-outline {
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
  border: 1.5px solid var(--border);
  padding: 10px 24px;
  font-size: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.8);
}
.btn-danger-outline {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.25);
}
.btn-danger-outline:hover {
  background: rgba(254, 242, 242, 0.7);
}

/* ===== 首页操作区 ===== */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mode-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mode-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-align: left;
}
.ai-levels {
  display: flex;
  gap: 10px;
}
.btn-ai {
  flex: 1;
  padding: 14px 0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: white;
  border: none;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
}
.btn-ai:active {
  transform: scale(0.95);
}
#btn-ai-easy {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}
#btn-ai-easy:hover {
  box-shadow: 0 6px 22px rgba(16, 185, 129, 0.45);
  transform: translateY(-1px);
}
#btn-ai-medium {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}
#btn-ai-medium:hover {
  box-shadow: 0 6px 22px rgba(245, 158, 11, 0.45);
  transform: translateY(-1px);
}
#btn-ai-hard {
  background: linear-gradient(135deg, #f87171, #ef4444);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
}
#btn-ai-hard:hover {
  box-shadow: 0 6px 22px rgba(239, 68, 68, 0.45);
  transform: translateY(-1px);
}
.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-light);
  font-size: 13px;
  font-weight: 500;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.join-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.join-group input {
  width: 100%;
  padding: 15px 16px;
  border: 2px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius-sm);
  font-size: 22px;
  text-align: center;
  letter-spacing: 12px;
  font-weight: 700;
  outline: none;
  transition: all 0.25s ease;
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.join-group input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}
.join-group input::placeholder {
  letter-spacing: 1px;
  font-size: 14px;
  font-weight: 400;
  color: #94a3b8;
}
.join-group .btn {
  width: 100%;
}
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
  font-weight: 500;
}
.btn-back-lobby {
  display: inline-block;
  margin-top: 18px;
  color: var(--text-light);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 1px;
  transition: color 0.2s;
}
.btn-back-lobby:hover { color: var(--primary); }

/* ===== 等待页 ===== */
.waiting-card h2 {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 28px;
  color: var(--text);
}
.waiting-icon {
  position: relative;
  width: 70px;
  height: 70px;
  margin: 0 auto 28px;
}
.pulse-dot {
  position: absolute;
  inset: 23px;
  border-radius: 50%;
  background: var(--primary-gradient);
  box-shadow: 0 0 16px var(--primary-glow);
}
.pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--primary);
  animation: pulse-ring 1.8s ease-out infinite;
}
.pulse-ring::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(99, 102, 241, 0.3);
  animation: pulse-ring 1.8s ease-out infinite 0.4s;
}
@keyframes pulse-ring {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}
.room-code-display {
  background: linear-gradient(135deg, rgba(248, 250, 252, 0.8), rgba(241, 245, 249, 0.8));
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--radius-sm);
  padding: 22px;
  margin-bottom: 18px;
}
.room-code-label {
  display: block;
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 600;
}
.room-code-value {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 16px;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 22px;
  line-height: 1.6;
}
.btn-cancel {
  margin-top: 8px;
  color: var(--text-light);
  border-color: transparent;
}
.btn-cancel:hover {
  color: var(--danger);
  background: rgba(254, 226, 226, 0.5);
}

/* ===== 游戏页 ===== */
#screen-game {
  flex-direction: column;
  padding: 14px 14px 18px;
  gap: 8px;
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 440px;
  gap: 8px;
}
.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1.5px solid transparent;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.35s ease;
  min-width: 0;
}
.player-card.active-turn {
  border-color: var(--primary);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
  background: rgba(255, 255, 255, 0.9);
}
.player-stone {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
.black-stone {
  background: radial-gradient(circle at 30% 30%, #666, #1a1a1a);
  box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.35);
}
.white-stone {
  background: radial-gradient(circle at 30% 30%, #fff, #d4d4d4);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.1);
}
.player-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.player-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.player-tag {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
}

/* ===== 计时器 ===== */
.timer-display {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
  transition: all 0.3s ease;
}
.timer-value {
  font-size: 32px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.3s;
}
.timer-display.warning .timer-value {
  color: var(--warning);
}
.timer-display.danger .timer-value {
  color: var(--danger);
}
.timer-display.danger {
  animation: timer-pulse 0.5s ease-in-out infinite alternate;
  box-shadow: 0 2px 20px rgba(239, 68, 68, 0.15);
}
@keyframes timer-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}
.timer-label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
}

/* ===== 游戏状态 ===== */
.game-status {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
  transition: color 0.3s;
  letter-spacing: 1px;
}

/* ===== 棋盘 ===== */
.board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  min-height: 0;
}
#game-board {
  border-radius: 12px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  touch-action: none;
  cursor: pointer;
}

/* ===== 游戏底栏 ===== */
.game-footer {
  display: flex;
  gap: 14px;
  justify-content: center;
  padding-top: 4px;
}

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 34px;
  max-width: 350px;
  width: 100%;
  text-align: center;
  transform: scale(0.88) translateY(20px);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}
.modal-card h3 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 10px;
  letter-spacing: 1px;
}
.modal-card p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 30px;
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  gap: 12px;
}
.modal-actions .btn {
  flex: 1;
}

/* ===== 响应式 ===== */
@media (max-height: 640px) {
  #screen-game { padding: 8px 10px 10px; gap: 4px; }
  .game-header { gap: 4px; }
  .player-card { padding: 6px 10px; gap: 6px; }
  .timer-value { font-size: 26px; }
  .game-status { font-size: 13px; }
  .card { padding: 32px 26px; }
}
@media (min-width: 768px) {
  .card { padding: 52px 44px; max-width: 420px; }
  .game-header { max-width: 520px; }
  .shape-1 { width: 450px; height: 450px; }
  .shape-2 { width: 350px; height: 350px; }
  .shape-3 { width: 300px; height: 300px; }
}
