/* ==========================================
   Wow! Link - Owen Wilson 连连看游戏
   电影感暗色调 + 霓虹点缀主题
   ========================================== */

/* Tailwind CSS CDN */
@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

/* ==========================================
   CSS Variables & Design Tokens
   ========================================== */
:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #1C2333;
  --bg-card: #21262D;
  --text-primary: #FFFFFF;
  --text-secondary: #C9D1D9;
  --text-muted: #8B949E;
  --accent-gold: #F5A623;
  --accent-gold-light: #FFD700;
  --accent-gold-dark: #E8961A;
  --accent-green: #3FB950;
  --accent-red: #F85149;
  --accent-blue: #58A6FF;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.12);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(245, 166, 35, 0.3);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}

/* Subtle background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(245, 166, 35, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(88, 166, 255, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ==========================================
   Header / Navbar
   ========================================== */
.game-header {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 800px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  margin-top: 8px;
  background: rgba(22, 27, 34, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.game-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent-gold-light), var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 8px rgba(245, 166, 35, 0.4));
}

.game-stats {
  display: flex;
  gap: 24px;
  align-items: center;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.stat-icon {
  font-size: 18px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 50px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ==========================================
   Game Board
   ========================================== */
.board-container {
  position: relative;
  z-index: 5;
  margin-top: 12px;
}

#game-board {
  display: grid;
  position: relative;
  z-index: 6;
}

#path-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 7;
  pointer-events: none;
}

/* ==========================================
   Cells
   ========================================== */
.cell {
  border-radius: var(--radius-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.cell-border {
  /* 外围透明边框单元格 */
  background: transparent;
}

.cell-card {
  background-color: var(--bg-card);
  cursor: pointer;
  position: relative;
  border: 2px solid transparent;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.cell-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.3) 100%);
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.cell-card:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 12px rgba(245, 166, 35, 0.2);
  border-color: rgba(245, 166, 35, 0.4);
  z-index: 8;
}

.cell-card:hover::after {
  opacity: 0.5;
}

/* 选中状态 */
.cell-card.selected {
  border-color: var(--accent-gold-light) !important;
  box-shadow: 0 0 16px rgba(245, 166, 35, 0.5), var(--shadow-card) !important;
  animation: pulseGold 1.2s ease-in-out infinite;
  z-index: 9;
}

/* 提示状态 */
.cell-card.hint {
  border-color: var(--accent-blue) !important;
  box-shadow: 0 0 16px rgba(88, 166, 255, 0.5), var(--shadow-card) !important;
  animation: pulseBlue 0.8s ease-in-out infinite;
}

/* 空单元格 */
.cell-empty {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
}

/* 占位文字 */
.cell-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px;
  word-break: break-word;
}

/* 消除动画 */
.cell-card.eliminating {
  animation: eliminatePop 0.5s ease-out forwards;
  pointer-events: none;
}

/* 抖动 */
.cell-card.shake {
  animation: shake 0.4s ease;
}

/* ==========================================
   Controls
   ========================================== */
.game-controls {
  position: relative;
  z-index: 10;
  display: flex;
  gap: 16px;
  margin-top: 16px;
  padding: 8px 0;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(245, 166, 35, 0.4);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.control-btn .btn-icon {
  font-size: 16px;
}

.control-btn.primary {
  background: linear-gradient(135deg, var(--accent-gold-dark), var(--accent-gold));
  border-color: transparent;
  color: #0D1117;
  font-weight: 600;
}

.control-btn.primary:hover {
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-light));
  box-shadow: 0 4px 16px rgba(245, 166, 35, 0.4);
  color: #0D1117;
}

/* ==========================================
   Video Modal
   ========================================== */
#video-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#video-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: linear-gradient(180deg, #1a1f2e 0%, #0D1117 100%);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 700px;
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s ease-out;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(245, 166, 35, 0.1);
}

#video-modal.active .modal-content {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  z-index: 101;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: rgba(248, 81, 73, 0.3);
  color: var(--accent-red);
}

.modal-video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
}

.modal-video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.modal-poster-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.15;
  filter: blur(20px);
  transform: scale(1.1);
}

.modal-info {
  padding: 20px 24px;
  position: relative;
}

.modal-movie-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.modal-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.modal-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.modal-line {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 15px;
  padding: 12px 16px;
  background: rgba(245, 166, 35, 0.06);
  border-left: 3px solid var(--accent-gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  line-height: 1.5;
}

/* ==========================================
   Loading Overlay
   ========================================== */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.95);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

.loading-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.loading-bar-track {
  width: 240px;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

#loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-gold-dark), var(--accent-gold-light));
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ==========================================
   Victory Overlay
   ========================================== */
#victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#victory-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.victory-content {
  text-align: center;
  animation: victorySlideIn 0.6s ease-out;
}

.victory-title {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-gold-light), var(--accent-gold), var(--accent-gold-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.victory-subtitle {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.victory-stats {
  display: flex;
  gap: 40px;
  margin-bottom: 32px;
}

.victory-stat {
  text-align: center;
}

.victory-stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-gold-light);
}

.victory-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.victory-btn {
  padding: 14px 40px;
  font-size: 16px;
  font-weight: 600;
  font-family: 'Poppins', sans-serif;
  background: linear-gradient(135deg, var(--accent-gold-dark), var(--accent-gold));
  border: none;
  border-radius: var(--radius-md);
  color: #0D1117;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.victory-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(245, 166, 35, 0.4);
}

/* ==========================================
   Error Message
   ========================================== */
#error-message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  padding: 12px 24px;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-md);
  color: var(--accent-red);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#error-message.active {
  opacity: 1;
}

/* ==========================================
   Keyframes
   ========================================== */
@keyframes pulseGold {
  0%, 100% { box-shadow: 0 0 8px rgba(245, 166, 35, 0.3), var(--shadow-card); }
  50% { box-shadow: 0 0 20px rgba(245, 166, 35, 0.6), var(--shadow-card); }
}

@keyframes pulseBlue {
  0%, 100% { box-shadow: 0 0 8px rgba(88, 166, 255, 0.3), var(--shadow-card); }
  50% { box-shadow: 0 0 20px rgba(88, 166, 255, 0.6), var(--shadow-card); }
}

@keyframes eliminatePop {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.3); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

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

@keyframes particleBurst {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
  .game-header {
    padding: 12px 16px;
    margin-top: 4px;
  }

  .game-title {
    font-size: 20px;
  }

  .stat-value {
    font-size: 15px;
  }

  .stat-item {
    gap: 4px;
    font-size: 12px;
  }

  .game-stats {
    gap: 12px;
  }

  .game-controls {
    gap: 8px;
    margin-top: 8px;
  }

  .control-btn {
    padding: 8px 14px;
    font-size: 12px;
    gap: 4px;
  }

  .modal-content {
    width: 95%;
  }

  .modal-movie-title {
    font-size: 18px;
  }

  .modal-line {
    font-size: 13px;
  }

  .victory-title {
    font-size: 32px;
  }
}

@media (max-width: 480px) {
  .game-header {
    flex-direction: column;
    gap: 8px;
  }
}
