/**
 * BILIKIDS JIGSAW PUZZLE ADVENTURE STYLES
 * Modern, colorful, responsive & tactile design for Kids & Babies
 */

:root {
  --font-display: 'Fredoka One', cursive, sans-serif;
  --font-main: 'Nunito', sans-serif;
  --color-primary: #3b82f6;
  --color-accent: #f59e0b;
  --color-pink: #ec4899;
  --color-purple: #8b5cf6;
  --color-green: #10b981;
  --bg-gradient: linear-gradient(135deg, #eff6ff 0%, #fdf4ff 50%, #fefce8 100%);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.15);
  --board-size: 480px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  color: #1e293b;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ==========================================================================
   TOP HEADER
   ========================================================================== */
.puzzle-header {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 2px solid rgba(226, 232, 240, 0.8);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.back-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  border: 2px solid #e2e8f0;
  padding: 8px 18px;
  border-radius: 999px;
  color: #334155;
  font-weight: 800;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.back-nav-btn:hover {
  background: #e2e8f0;
  transform: translateX(-3px);
  color: #0f172a;
}

.back-icon {
  font-size: 1.2rem;
  transition: transform 0.2s;
}

.back-nav-btn:hover .back-icon {
  transform: translateX(-3px);
}

.header-title-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.header-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.puzzle-emoji-spin {
  display: inline-block;
  animation: gentleWobble 3s infinite ease-in-out;
}

@keyframes gentleWobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

.header-subtitle {
  font-size: 0.85rem;
  font-weight: 800;
  color: #0284c7;
  letter-spacing: 0.3px;
}

.babies-listening-task {
  margin: 8px auto;
  padding: 8px 14px;
  width: fit-content;
  max-width: 95%;
  border: 2px solid #fbbf24;
  border-radius: 16px;
  background: #fffbeb;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  font-weight: 800;
  color: #713f12;
}
.babies-listening-task[hidden] { display: none; }
.babies-listening-task button { border: 0; border-radius: 999px; padding: 8px 14px; background: #f59e0b; color: white; font: inherit; cursor: pointer; }

/* Difficulty Switcher */
.difficulty-switcher {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 999px;
  border: 2px solid #e2e8f0;
  gap: 4px;
}

.diff-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 0.9rem;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.diff-btn:hover {
  color: #1e293b;
}

.diff-btn.active[data-mode="babies"] {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
  transform: scale(1.04);
}

.diff-btn.active[data-mode="toddlers"] {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
  transform: scale(1.04);
}

.diff-btn.active[data-mode="kids"] {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
  transform: scale(1.04);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stars-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fef3c7;
  border: 2px solid #fde68a;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #b45309;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
}

.star-icon {
  font-size: 1.25rem;
  animation: pulseStar 2s infinite ease-in-out;
}

@keyframes pulseStar {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.action-round-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-sm);
}

.action-round-btn:hover {
  transform: translateY(-2px) scale(1.06);
  border-color: #cbd5e1;
  background: #f8fafc;
}

/* ==========================================================================
   MAIN GAME WORKSPACE
   ========================================================================== */
.puzzle-workspace {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Info Bar */
.puzzle-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 20px;
  padding: 10px 22px;
  box-shadow: var(--shadow-sm);
}

.info-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.current-puzzle-icon {
  font-size: 1.8rem;
}

.current-puzzle-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: #1e293b;
}

.info-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.9rem;
  color: #475569;
}

.hint-btn {
  background: #eff6ff;
  border: 2px solid #bfdbfe;
  color: #1d4ed8;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 0.9rem;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hint-btn:hover {
  background: #dbeafe;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.hint-btn.active {
  background: #fde68a;
  border-color: #f59e0b;
  color: #92400e;
}

/* ==========================================================================
   GAMEPLAY STAGE: BOARD & TRAY
   ========================================================================== */
.game-stage {
  display: grid;
  grid-template-columns: var(--board-size) 1fr;
  gap: 24px;
  align-items: start;
}

/* Board Wrapper */
.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-frame {
  width: var(--board-size);
  height: var(--board-size);
  background: #ffffff;
  border: 8px solid #ffffff;
  border-radius: 28px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
}

.puzzle-board {
  width: 100%;
  height: 100%;
  background: #f1f5f9;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
}

.ghost-guide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.28;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.ghost-guide.show-hint {
  opacity: 0.72;
}

.ghost-guide.hide-hint {
  opacity: 0.04;
}

/* Grid Slots Overlay */
.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  pointer-events: none;
}

.slot-cell {
  border: 1.5px dashed rgba(148, 163, 184, 0.45);
  box-sizing: border-box;
  position: relative;
  pointer-events: auto;
  transition: background-color 0.2s ease;
}

.slot-cell.drag-over {
  background-color: rgba(56, 189, 248, 0.25);
  border-color: #0284c7;
}

.slot-cell.target-hint {
  animation: pulseSlot 1.5s infinite;
}

@keyframes pulseSlot {
  0%, 100% { background-color: rgba(250, 204, 21, 0.15); }
  50% { background-color: rgba(250, 204, 21, 0.35); }
}

/* Placed Pieces on Board */
.placed-piece {
  position: absolute;
  pointer-events: none;
  animation: snapPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
}

@keyframes snapPop {
  0% { transform: scale(1.18); filter: brightness(1.2); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Pieces Tray */
.tray-wrapper {
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 24px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: var(--board-size);
  box-shadow: var(--shadow-sm);
}

.tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px dashed #f1f5f9;
  padding-bottom: 10px;
}

.tray-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #1e293b;
}

.tray-progress {
  font-weight: 800;
  font-size: 0.85rem;
  color: #10b981;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 4px 12px;
  border-radius: 999px;
}

.pieces-tray {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-height: 280px;
  background: #f8fafc;
  border-radius: 18px;
  border: 1px solid #f1f5f9;
  overflow-y: auto;
  max-height: 380px;
}

.tray-help-hint {
  font-size: 0.85rem;
  color: #64748b;
  text-align: center;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 10px;
}

/* Jigsaw Canvas Pieces in Tray */
.jigsaw-piece-canvas {
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 6px 12px rgba(15, 23, 42, 0.14));
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.22s ease;
  transform-origin: center center;
}

.jigsaw-piece-canvas:hover {
  transform: translateY(-4px) scale(1.05);
  filter: drop-shadow(0 10px 18px rgba(15, 23, 42, 0.2));
}

.jigsaw-piece-canvas:active {
  cursor: grabbing;
}

.jigsaw-piece-canvas.selected {
  transform: translateY(-6px) scale(1.1);
  filter: drop-shadow(0 12px 24px rgba(245, 158, 11, 0.45));
  animation: pulseSelected 1.2s infinite ease-in-out;
}

@keyframes pulseSelected {
  0%, 100% { filter: drop-shadow(0 8px 18px rgba(245, 158, 11, 0.4)); }
  50% { filter: drop-shadow(0 12px 26px rgba(245, 158, 11, 0.7)); }
}

/* Floating Drag Ghost */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  display: none;
  filter: drop-shadow(0 16px 28px rgba(15, 23, 42, 0.35));
  transform: translate(-50%, -50%) scale(1.08);
}

/* ==========================================================================
   PICTURE GALLERY CAROUSEL
   ========================================================================== */
.gallery-section {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto 30px auto;
  padding: 0 20px;
}

.gallery-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.gallery-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gallery-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: #64748b;
}

.gallery-carousel {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 8px 4px 16px 4px;
  scrollbar-width: thin;
}

.gallery-carousel::-webkit-scrollbar {
  height: 6px;
}

.gallery-carousel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.gallery-card {
  flex: 0 0 125px;
  background: #ffffff;
  border: 3px solid #e2e8f0;
  border-radius: 18px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: #38bdf8;
  box-shadow: 0 8px 18px rgba(56, 189, 248, 0.25);
}

.gallery-card.active {
  border-color: #0284c7;
  background: #f0f9ff;
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.35);
}

.gallery-thumb-box {
  width: 105px;
  height: 85px;
  background: #f1f5f9;
  border-radius: 12px;
  overflow: hidden;
}

.gallery-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-card-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: #334155;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 105px;
}

/* ==========================================================================
   VICTORY CELEBRATION MODAL
   ========================================================================== */
.victory-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.victory-card {
  background: #ffffff;
  border-radius: 32px;
  padding: 32px 36px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  border: 4px solid #fef08a;
}

@keyframes popIn {
  0% { transform: scale(0.6) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.victory-trophy-wrap {
  position: relative;
  margin-bottom: 12px;
}

.victory-trophy {
  font-size: 4.5rem;
  display: inline-block;
  animation: bounceTrophy 1.5s infinite;
}

@keyframes bounceTrophy {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
}

.victory-stars-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 2rem;
  margin-top: -6px;
}

.v-star {
  animation: starPop 0.5s ease backwards;
}

.star-1 { animation-delay: 0.15s; }
.star-2 { animation-delay: 0.35s; }
.star-3 { animation-delay: 0.55s; }

@keyframes starPop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

.victory-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: #1e293b;
  margin-bottom: 6px;
}

.victory-desc {
  font-size: 0.95rem;
  color: #64748b;
  margin-bottom: 20px;
}

.victory-stats-box {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 10px;
  width: 100%;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 24px;
}

.v-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.v-stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.v-stat-value {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #1e293b;
  margin-top: 2px;
}

.highlight-reward .v-stat-value {
  color: #d97706;
}

.reward-glow {
  animation: pulseGlow 1.2s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); color: #b45309; }
}

.victory-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}

.v-action-btn {
  flex: 1;
  padding: 12px;
  border-radius: 16px;
  border: none;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-replay {
  background: #f1f5f9;
  color: #475569;
}

.btn-replay:hover {
  background: #e2e8f0;
  transform: translateY(-2px);
}

.btn-next {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35);
}

.btn-next:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.45);
}

/* ==========================================================================
   CONFETTI FULLSCREEN CANVAS
   ========================================================================== */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 300;
}

/* ==========================================================================
   RESPONSIVE DESIGN (TABLETS & MOBILE)
   ========================================================================== */
@media (max-width: 960px) {
  :root {
    --board-size: 380px;
  }

  .game-stage {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .tray-wrapper {
    width: 100%;
    max-width: var(--board-size);
    min-height: 220px;
  }

  .header-title {
    font-size: 1.25rem;
  }
}

@media (max-width: 640px) {
  :root {
    --board-size: 320px;
  }

  .puzzle-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .header-title-box {
    order: -1;
    width: 100%;
  }

  .difficulty-switcher {
    order: 1;
  }

  .header-actions {
    order: 2;
  }

  .puzzle-info-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .info-stats {
    width: 100%;
    justify-content: space-between;
  }
}
