/* ==========================================================================
   PUZZLE DU TOUTOU - LES 4 SAISONS 🐾
   Feuille de style chaleureuse, naturelle et adaptée aux 4 saisons
   ========================================================================== */

:root {
  --primary: #d97706;          /* Ambre doré / caramel toutou */
  --primary-hover: #b45309;
  --primary-light: #fef3c7;
  --primary-glow: rgba(217, 119, 6, 0.3);
  --secondary: #10b981;        /* Vert nature / printemps */
  --secondary-light: #d1fae5;
  --accent-gold: #f59e0b;
  --accent-orange: #ea580c;     /* Automne */
  --accent-blue: #0284c7;       /* Hiver */
  --bg-gradient: linear-gradient(135deg, #fefce8 0%, #f0fdf4 40%, #fff7ed 100%);
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-border: rgba(255, 255, 255, 0.8);
  --card-shadow: 0 12px 32px rgba(180, 83, 9, 0.08), 0 4px 12px rgba(0, 0, 0, 0.03);
  --text-main: #292524;
  --text-muted: #78716c;
  --correct-green: #10b981;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --transition-fast: 0.18s ease;
  --transition-normal: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-main);
  position: relative;
  overflow-x: hidden;
  padding: 16px 12px 40px;
}

/* Particules flottantes d'ambiance (Pattes, os, feuilles, flocons) */
.bg-hearts-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.floating-heart-bg {
  position: absolute;
  color: rgba(217, 119, 6, 0.15);
  animation: floatUp 14s infinite linear;
  user-select: none;
}

@keyframes floatUp {
  0% {
    transform: translateY(105vh) scale(0.6) rotate(0deg);
    opacity: 0;
  }
  15% {
    opacity: 0.85;
  }
  85% {
    opacity: 0.85;
  }
  100% {
    transform: translateY(-10vh) scale(1.1) rotate(45deg);
    opacity: 0;
  }
}

/* Conteneur principal */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   EN-TÊTE DU JEU
   ========================================================================== */
.header-card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-hover);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  width: fit-content;
}

.app-title {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title .paw-icon {
  display: inline-block;
  animation: pawWiggle 2.2s infinite ease-in-out;
}

@keyframes pawWiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-12deg) scale(1.15); }
  75% { transform: rotate(12deg) scale(1.15); }
}

.app-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Boutons icônes */
.icon-btn {
  background: white;
  border: 1px solid rgba(217, 119, 6, 0.2);
  color: var(--primary);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.15rem;
  transition: var(--transition-fast);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.icon-btn:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* ==========================================================================
   GALERIE DES 4 SAISONS / CARROUSEL
   ========================================================================== */
.photo-selector-section {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--card-shadow);
}

.section-label {
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.photos-scroll-row {
  display: flex;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.photos-scroll-row::-webkit-scrollbar {
  height: 6px;
}
.photos-scroll-row::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}

/* Carte miniature de saison */
.photo-thumb-card {
  flex: 0 0 auto;
  width: 110px;
  height: 110px;
  border-radius: var(--radius-md);
  border: 3px solid transparent;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: var(--transition-normal);
  background: #f5f5f4;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.photo-thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition-normal);
}

.photo-thumb-card:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 18px var(--primary-glow);
}

.photo-thumb-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light), 0 8px 20px var(--primary-glow);
  transform: translateY(-2px);
}

.photo-thumb-card .thumb-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 16px 6px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.photo-thumb-card.active::after {
  content: "🐾";
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.78rem;
  background: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Carte pour uploader une autre photo */
.upload-btn-card {
  flex: 0 0 auto;
  width: 110px;
  height: 110px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--primary);
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  color: var(--primary-hover);
  transition: var(--transition-fast);
  padding: 8px;
  text-align: center;
}

.upload-btn-card:hover {
  background: var(--primary-light);
  border-color: var(--primary-hover);
  transform: translateY(-2px);
}

.upload-btn-card .upload-icon {
  font-size: 1.5rem;
}

.upload-btn-card .upload-text {
  font-size: 0.72rem;
  font-weight: 700;
}

/* ==========================================================================
   BARRE DE CONTRÔLE ET PARAMÈTRES
   ========================================================================== */
.controls-card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Groupes de boutons pilule */
.pill-group {
  display: inline-flex;
  background: #f5f5f4;
  padding: 4px;
  border-radius: 999px;
  gap: 2px;
  border: 1px solid #e7e5e4;
}

.pill-btn {
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
}

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

.pill-btn.active {
  background: white;
  color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Boutons d'action */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-gold) 100%);
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px var(--primary-glow);
}

.btn-secondary {
  background: white;
  color: var(--text-main);
  border: 1px solid rgba(217, 119, 6, 0.25);
}

.btn-secondary:hover {
  background: var(--primary-light);
  color: var(--primary-hover);
}

.btn.active-toggle {
  background: var(--secondary-light);
  border-color: var(--secondary);
  color: #065f46;
}

/* Compteur de stats */
.stats-pill {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  background: white;
  padding: 6px 18px;
  border-radius: 999px;
  border: 1px solid rgba(217, 119, 6, 0.2);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.stat-item .stat-icon {
  font-size: 1rem;
}

.stat-item .stat-val {
  color: var(--primary-hover);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
}

/* ==========================================================================
   ZONE DE JEU PRINCIPALE
   ========================================================================== */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.game-layout.mode-jigsaw {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  width: 100%;
}

@media (min-width: 820px) {
  .game-layout.mode-jigsaw {
    grid-template-columns: minmax(340px, 460px) 1fr;
    align-items: start;
  }
}

/* Cadre du puzzle (style Polaroid naturel) */
.puzzle-frame-card {
  background: white;
  padding: 14px;
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.9);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  max-width: 480px;
  width: 100%;
}

.board-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

.current-photo-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.board-progress-text {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-hover);
  background: var(--primary-light);
  padding: 3px 12px;
  border-radius: 999px;
}

/* Conteneur du plateau (respecte l'orientation portrait sans déborder) */
.puzzle-board-wrapper {
  position: relative;
  width: 100%;
  max-height: min(65vh, 540px);
  aspect-ratio: 1 / 1;
  background: #f5f5f4;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.08);
}

.puzzle-board {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 2px;
  padding: 2px;
  background: #d6d3d1;
  transition: gap 0.3s ease;
}

.puzzle-board.solved {
  gap: 0;
  padding: 0;
  background: transparent;
}

/* Calque d'aperçu fantôme (Aperçu) */
.board-ghost-overlay {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 5;
}

.board-ghost-overlay.visible {
  opacity: 0.38;
}

/* Emplacements en mode Jigsaw */
.board-slot {
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px dashed rgba(214, 211, 209, 0.9);
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.board-slot.drag-hover {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: scale(0.98);
}

.board-slot .slot-index-hint {
  font-size: 0.85rem;
  font-weight: 700;
  color: #a8a29e;
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

/* ==========================================================================
   PIÈCES DU PUZZLE
   ========================================================================== */
.puzzle-tile {
  position: relative;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  background-repeat: no-repeat;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 4px;
}

.puzzle-tile:hover {
  transform: scale(1.02);
  z-index: 2;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}

/* Pièce sélectionnée (Mode Échange) */
.puzzle-tile.selected {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
  box-shadow: 0 0 0 4px var(--primary-light), 0 8px 24px var(--primary-glow);
  transform: scale(1.04);
  z-index: 10;
  animation: tileSelectedPulse 1.2s infinite alternate ease-in-out;
}

@keyframes tileSelectedPulse {
  0% { outline-color: var(--primary); }
  100% { outline-color: var(--accent-gold); }
}

/* Pièce bien placée (Indice) */
.puzzle-tile.is-correct-hint::after {
  content: "✓";
  background: rgba(16, 185, 129, 0.95);
  color: white;
  font-size: 0.65rem;
  font-weight: 900;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.puzzle-board.solved .puzzle-tile {
  border-radius: 0;
  box-shadow: none;
  cursor: default;
}
.puzzle-board.solved .puzzle-tile:hover {
  transform: none;
}

/* ==========================================================================
   PLATEAU DE PIÈCES DU BAS (MODE PUZZLE / JIGSAW)
   ========================================================================== */
.piece-tray-card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.piece-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.piece-tray-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  min-height: 140px;
  max-height: 380px;
  overflow-y: auto;
  padding: 8px 4px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  border: 1.5px dashed rgba(217, 119, 6, 0.25);
}

.piece-tray-grid:empty::before {
  content: "Toutes les pièces sont posées sur le plateau ! 🐾";
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100px;
}

.piece-tray-grid .puzzle-tile {
  border: 2px solid white;
  border-radius: 8px;
}
.piece-tray-grid .puzzle-tile:nth-child(3n+1) { transform: rotate(-2deg); }
.piece-tray-grid .puzzle-tile:nth-child(3n+2) { transform: rotate(1.5deg); }
.piece-tray-grid .puzzle-tile:nth-child(3n) { transform: rotate(-1deg); }
.piece-tray-grid .puzzle-tile:hover {
  transform: scale(1.08) rotate(0deg);
}

/* Instructions */
.instructions-card {
  text-align: center;
  font-size: 0.86rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.75);
  padding: 8px 18px;
  border-radius: 999px;
  width: fit-content;
  margin: 0 auto;
  border: 1px solid rgba(217, 119, 6, 0.15);
}

/* ==========================================================================
   MODALE DE VICTOIRE
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(41, 37, 36, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.victory-modal {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 460px;
  width: 100%;
  padding: 26px 22px 22px;
  box-shadow: 0 25px 60px rgba(180, 83, 9, 0.25), 0 10px 20px rgba(0, 0, 0, 0.1);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  transform: scale(0.85) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  overflow: hidden;
}

.modal-backdrop.open .victory-modal {
  transform: scale(1) translateY(0);
}

.modal-paw-badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: white;
  box-shadow: 0 8px 20px var(--primary-glow);
  animation: pawPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pawPop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.victory-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
}

.victory-polaroid {
  background: #fff;
  padding: 8px 8px 20px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  border: 1px solid #f5f5f4;
  width: 200px;
  transform: rotate(-2deg);
  transition: transform 0.3s ease;
}

.victory-polaroid:hover {
  transform: rotate(0deg) scale(1.03);
}

.victory-polaroid img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
}

.polaroid-caption {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 8px;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe Print", cursive, sans-serif;
}

.dog-message-box {
  background: linear-gradient(135deg, #fefce8 0%, #fffbeb 100%);
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  color: #78350f;
  font-size: 0.96rem;
  line-height: 1.5;
  font-weight: 600;
  position: relative;
  width: 100%;
}

.victory-stats-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  width: 100%;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.victory-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

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

.victory-actions-row .btn {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.9rem;
}

/* Bouton Partager le score */
.btn-share {
  background: #f0fdf4;
  color: #166534;
  border: 1.5px solid #bbf7d0;
  width: 100%;
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition-fast);
}

.btn-share:hover {
  background: #dcfce7;
  border-color: #86efac;
  transform: translateY(-1px);
}

/* Toast de confirmation de copie */
.toast-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: #1f2937;
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-notice.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Canvas Confettis */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1050;
}

/* ==========================================================================
   RESPONSIVITÉ
   ========================================================================== */
@media (max-width: 600px) {
  body {
    padding: 10px 8px 30px;
  }
  .header-card {
    padding: 14px 16px;
  }
  .app-title {
    font-size: 1.35rem;
  }
  .controls-card {
    padding: 10px 12px;
  }
  .photo-thumb-card, .upload-btn-card {
    width: 88px;
    height: 88px;
  }
  .puzzle-frame-card {
    padding: 10px;
  }
  .btn {
    padding: 7px 12px;
    font-size: 0.82rem;
  }
  .pill-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }
  .stats-pill {
    padding: 5px 12px;
    gap: 10px;
  }
}
