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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252542;
  --border: #333355;
  --text: #e0e0f0;
  --text2: #8888aa;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --green: #00d2a0;
  --red: #ff6b6b;
  --orange: #ffa726;
  --yellow: #ffd93d;
  --blue: #54a0ff;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.app-header h1 { font-size: 20px; font-weight: 700; color: var(--text); }

.btn-back {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
}
.btn-back:hover { background: var(--border); }

/* === Home Page === */
.home-page { padding: 40px 24px; max-width: 1000px; margin: 0 auto; width: 100%; }

.hero {
  text-align: center;
  margin-bottom: 40px;
}
.hero h2 { font-size: 28px; margin-bottom: 8px; color: var(--accent2); }
.hero p { font-size: 16px; color: var(--text2); }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.game-card .game-icon { font-size: 40px; }
.game-card .game-name { font-size: 18px; font-weight: 600; }
.game-card .game-desc { font-size: 13px; color: var(--text2); line-height: 1.5; }
.game-card .game-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.game-card .tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
}

/* === Game Page === */
.game-page { padding: 20px 24px 40px; max-width: 700px; margin: 0 auto; width: 100%; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.game-header h2 { font-size: 22px; color: var(--accent2); }

.game-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.game-stats { display: flex; gap: 16px; }

.stat {
  background: var(--surface2);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text2);
}
.stat span { color: var(--text); font-weight: 600; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: var(--transition);
}
.btn:hover { opacity: 0.85; transform: scale(1.02); }
.btn:active { transform: scale(0.98); }
.btn.small { padding: 5px 12px; font-size: 12px; }

.game-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* === Footer === */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text2);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* === Memory Game === */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 80px);
  grid-template-rows: repeat(4, 80px);
  gap: 8px;
}

.memory-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, background var(--transition);
  user-select: none;
}
.memory-card:hover { border-color: var(--accent); }
.memory-card.flipped { background: var(--accent); border-color: var(--accent2); }
.memory-card.matched { background: var(--green); border-color: var(--green); opacity: 0.7; }

/* === 2048 === */
.game-2048 { width: 100%; max-width: 400px; }
.board-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  aspect-ratio: 1;
  background: var(--surface2);
  padding: 8px;
  border-radius: var(--radius);
}

.cell-2048 {
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  transition: all 0.1s ease;
}

/* === Minesweeper === */
.mine-grid {
  display: grid;
  gap: 2px;
  background: var(--surface2);
  padding: 4px;
  border-radius: var(--radius);
}

.mine-cell {
  width: 32px;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.mine-cell:hover { background: #2a2a4a; }
.mine-cell.revealed { background: var(--surface2); }
.mine-cell.flagged { background: var(--orange); }
.mine-cell.mine { background: var(--red); }

/* === Sliding Puzzle === */
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(4, 70px);
  grid-template-rows: repeat(4, 70px);
  gap: 4px;
  background: var(--surface2);
  padding: 8px;
  border-radius: var(--radius);
}

.puzzle-tile {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background var(--transition);
  user-select: none;
}
.puzzle-tile:hover { opacity: 0.85; }
.puzzle-tile.empty { background: transparent; cursor: default; }

/* === Snake / Tetris Canvas === */
canvas.game-canvas {
  border-radius: 8px;
  display: block;
  background: var(--bg);
}

.instructions {
  text-align: center;
  color: var(--text2);
  font-size: 13px;
  margin-top: 12px;
}

/* === Game Over Overlay === */
.game-over-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  gap: 16px;
}
.game-over-overlay h3 { font-size: 24px; }

/* === Responsive === */
@media (max-width: 600px) {
  .app-header { padding: 12px 16px; }
  .app-header h1 { font-size: 17px; }
  .hero h2 { font-size: 22px; }
  .home-page { padding: 24px 16px; }
  .game-page { padding: 16px; }
  .game-grid { grid-template-columns: 1fr; }
  .game-area { padding: 16px; }

  .memory-grid {
    grid-template-columns: repeat(4, 70px);
    grid-template-rows: repeat(4, 70px);
    gap: 6px;
  }
  .memory-card { font-size: 28px; }

  .puzzle-grid {
    grid-template-columns: repeat(4, 60px);
    grid-template-rows: repeat(4, 60px);
  }
  .puzzle-tile { font-size: 18px; }

  .mine-cell { width: 28px; height: 28px; font-size: 11px; }

  .cell-2048 { font-size: 18px; }
}

/* === Tile colors for 2048 === */
.tile-2    { background: #eee4da; color: #776e65; }
.tile-4    { background: #ede0c8; color: #776e65; }
.tile-8    { background: #f2b179; color: #f9f6f2; }
.tile-16   { background: #f59563; color: #f9f6f2; }
.tile-32   { background: #f67c5f; color: #f9f6f2; }
.tile-64   { background: #f65e3b; color: #f9f6f2; }
.tile-128  { background: #edcf72; color: #f9f6f2; }
.tile-256  { background: #edcc61; color: #f9f6f2; }
.tile-512  { background: #edc850; color: #f9f6f2; }
.tile-1024 { background: #edc53f; color: #f9f6f2; }
.tile-2048 { background: #edc22e; color: #f9f6f2; }

/* Position relative for game area to support overlays */
.game-area { position: relative; }

/* === Delta Force Randomizer === */
.delta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
}

.delta-slot {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.delta-photo {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
  margin-bottom: 8px;
  background: var(--bg);
}

.delta-photo-icon {
  font-size: 36px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

.photo-done {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(108,92,231,0.4);
}

.delta-label-sm {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 4px;
}

.delta-display {
  font-size: 14px;
  font-weight: 700;
  min-height: 20px;
  transition: color 0.1s;
}

.delta-display.rolling {
  animation: deltaShake 0.06s infinite;
}

.delta-display.done {
  animation: deltaPop 0.3s ease;
}

@keyframes deltaShake {
  0% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

@keyframes deltaPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108,92,231,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(108,92,231,0); }
}

.btn.pulse {
  animation: pulse 2s infinite;
}

.delta-result-card {
  background: var(--surface2);
  padding: 16px;
  border-radius: 12px;
  text-align: left;
  line-height: 2;
  border: 1px solid var(--border);
}

.delta-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.delta-result-item:last-child { border-bottom: none; }

.delta-result-icon { font-size: 18px; }
.delta-result-name { color: var(--text2); font-size: 13px; min-width: 40px; }
.delta-result-val { color: var(--accent2); font-weight: 700; margin-left: auto; }

@media (max-width: 600px) {
  .delta-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .delta-photo-icon { font-size: 28px; }
  .delta-display { font-size: 12px; }
}
