/* ========================================
   Sliding Puzzle - game4.fun UI System
   Dark glassmorphism, neon accents
======================================== */

:root {
  --bg-dark: #0a0a0f;
  --bg-card: rgba(20, 20, 30, 0.75);
  --primary-neon: #6366f1;
  --secondary-neon: #ec4899;
  --accent-cyan: #06b6d4;
  --text-main: #f1f5f9;
  --text-dim: rgba(148, 163, 184, 0.7);
  --border-glass: rgba(255, 255, 255, 0.1);
  --radius-xl: 24px;
  --radius-lg: 16px;

  --tile-bg: rgba(30, 30, 50, 0.85);
  --tile-radius: 12px;
}

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

body {
  min-height: 100vh;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========== Game Container ========== */
.game-container {
  width: 100%;
  max-width: 560px;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  text-align: center;
  margin-bottom: 16px;
}

.game-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ========== Size Bar ========== */
.size-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.size-btn {
  padding: 8px 20px;
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.25s ease;
  backdrop-filter: blur(8px);
}

.size-btn:hover {
  border-color: var(--primary-neon);
  color: var(--text-main);
}

.size-btn.active {
  border-color: var(--primary-neon);
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-main);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

/* ========== Game Panel ========== */
.game-panel {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 20px;
  backdrop-filter: blur(16px);
}

/* ========== HUD ========== */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}

.hud-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-cyan);
}

.shuffle-btn {
  padding: 10px 24px;
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.shuffle-btn:hover {
  background: rgba(99, 102, 241, 0.3);
  border-color: var(--primary-neon);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

.shuffle-btn:active {
  transform: scale(0.95);
}

/* ========== Board ========== */
.board-wrapper {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: rgba(10, 10, 20, 0.5);
  border: 1px solid var(--border-glass);
  user-select: none;
  position: relative;
}

/* Tile */
.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--tile-radius);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  /* Smooth slide animation */
  transition: left 0.18s ease, top 0.18s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
  transform: scale(1.04);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
}

.tile:active {
  transform: scale(0.96);
}

.tile.empty {
  background: transparent !important;
  border: none !important;
  cursor: default;
  pointer-events: none;
}

.tile.empty:hover {
  transform: none;
  box-shadow: none;
}

/* ========== Best Display ========== */
.best-display {
  text-align: center;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

#best-record {
  color: var(--accent-cyan);
  font-weight: 600;
}

/* ========== Win Celebration ========== */
@keyframes tilePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes tileGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(99, 102, 241, 0.3); }
  50% { box-shadow: 0 0 24px rgba(99, 102, 241, 0.7), 0 0 48px rgba(6, 182, 212, 0.4); }
}

.tile.celebrate {
  animation: tilePop 0.4s ease forwards, tileGlow 1s ease infinite;
  pointer-events: none;
}

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

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

.modal {
  background: rgba(20, 20, 35, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 40px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  transform: scale(0.85);
  transition: transform 0.3s ease;
  backdrop-filter: blur(16px);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.modal-message {
  color: var(--text-dim);
  margin-bottom: 8px;
}

.modal-record {
  color: var(--secondary-neon);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 20px;
  min-height: 1.2em;
}

.modal-btn {
  padding: 12px 32px;
  border: 1px solid var(--primary-neon);
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-main);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.modal-btn:hover {
  background: rgba(99, 102, 241, 0.4);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
  .game-container {
    padding: 10px;
  }

  .game-panel {
    padding: 14px;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .hud-value {
    font-size: 1.2rem;
  }

  .shuffle-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
  }

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