/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --card-bg: #1a1a2e;
  --card-hover: #252542;
  --accent: #00d4ff;
  --accent2: #ff6ec7;
  --accent3: #ffd700;
  --accent4: #7c3aed;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --border: #2a2a4a;
  --radius: 16px;
  --radius-sm: 10px;
}

.hidden { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== ANIMATED BACKGROUND ===== */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0, 212, 255, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(255, 110, 199, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(124, 58, 237, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
header {
  position: relative;
  text-align: center;
  padding: 60px 20px 40px;
  z-index: 1;
  overflow: hidden;
}

.header-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, rgba(0,212,255,0.08) 0%, rgba(124,58,237,0.08) 100%);
  clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
  z-index: -1;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.logo-icon { font-size: 2.8rem; animation: bounce 2s infinite; }

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

h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 400;
}

/* ===== GAMES GRID ===== */
main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
  position: relative;
  z-index: 1;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 24px;
  padding: 10px 0 40px;
}

.game-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.game-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent4));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.game-card:hover::before { transform: scaleX(1); }

.game-card:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0, 212, 255, 0.15);
}

.game-card .game-icon {
  font-size: 3rem;
  line-height: 1;
}

.game-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.game-card .game-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.game-card .play-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

.game-card:hover .play-badge {
  opacity: 1;
  transform: translateY(0);
}

/* Difficulty tags */
.game-card .difficulty {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
}

.diff-easy { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.diff-medium { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.diff-hard { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
  line-height: 1;
}

.close-btn:hover { color: var(--text); }

.modal-body {
  padding: 24px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

/* ===== GAME CANVAS STYLING ===== */
canvas {
  display: block;
  max-width: 100%;
  border-radius: var(--radius-sm);
  background: #000;
  image-rendering: pixelated;
}

.game-controls {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-controls button {
  padding: 8px 24px;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-play {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}

.btn-play:hover { filter: brightness(1.2); transform: scale(1.05); }

.btn-reset {
  background: var(--border);
  color: var(--text);
}

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

.game-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.stat-box {
  background: var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  text-align: center;
}

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

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

/* ===== GAME SPECIFIC ===== */
.game-info {
  text-align: center;
  margin-bottom: 16px;
}

.game-info p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Tic-Tac-Toe special grid */
.ttt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  width: 306px;
  height: 306px;
}

.ttt-cell {
  background: var(--card-bg);
  border: none;
  font-size: 2.8rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  width: 98px;
  height: 98px;
  color: var(--accent);
  font-family: 'Press Start 2P', monospace;
}

.ttt-cell:hover { background: var(--card-hover); }
.ttt-cell.taken { cursor: default; }
.ttt-cell.x-color { color: var(--accent); }
.ttt-cell.o-color { color: var(--accent2); }

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--border);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  h1 { font-size: 1rem; }
  .games-grid { grid-template-columns: 1fr; }
  .modal-body { padding: 16px; min-height: 320px; }
  .ttt-grid { width: 240px; height: 240px; }
  .ttt-cell { width: 78px; height: 78px; font-size: 2rem; }
}
