 /* === GLOBAL === */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(135deg, #001f3f, #003366, #0074D9, #00bcd4, #a2ffff);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
  margin: 0;
  padding: 0;
}


@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* === PILE (pioche) === */
#pile-container {
  position: relative;
  width: 100%;
  padding-bottom: 36px;
  background: rgba(255,255,255,0.05);
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.1);
  justify-content: center;
}

#pile {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 8px;
  max-height: 90px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  box-shadow: 0 0 15px rgba(0,0,0,0.2);
  backdrop-filter: blur(6px);
  width: 96%;
  max-width: 98%;
  scrollbar-width: auto;
  scrollbar-color: #ffcc00 transparent;
  padding: 0;
}

.triangle {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: var(--color);
}

.triangle.top {
  clip-path: polygon(0% 0%, 100% 0%, 50% 50%);
}
.triangle.right {
  clip-path: polygon(100% 0%, 100% 100%, 50% 50%);
}
.triangle.bottom {
  clip-path: polygon(0% 100%, 100% 100%, 50% 50%);
}
.triangle.left {
  clip-path: polygon(0% 0%, 0% 100%, 50% 50%);
}

#pile::-webkit-scrollbar {
  width: 8px;
}
#pile::-webkit-scrollbar-track {
  background: transparent;
}
#pile::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 4px;
}

.pile-tile {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pile-tile:hover {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(255,255,255,0.3);
}

#pile-badge {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(to right, #ffcc00, #ffaa00);
  color: #000;
  font-weight: bold;
  border-radius: 16px;
  padding: 6px 10px;
  font-size: 14px;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  z-index: 10;
  transition: transform 0.2s ease-in-out;
  pointer-events: none;
}
#pile-badge.pulse {
  transform: translateX(-50%) scale(1.2);
}

#pile.highlight {
  box-shadow: 0 0 18px 6px #ffee58;
  animation: pulse-pile 1s infinite;
  border-radius: 12px;
  transition: box-shadow 0.3s ease;
}

@keyframes pulse-pile {
  0%   { box-shadow: 0 0 8px 2px #ffee58; }
  50%  { box-shadow: 0 0 18px 6px #ffff8d; }
  100% { box-shadow: 0 0 8px 2px #ffee58; }
}

/* === GAME BOARD === */
#game-board {
  position: relative;
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  gap: 1px;
  background: #ddd;
  border-radius: 16px;
  z-index: 0;
  margin: 1em auto;
  flex-shrink: 0;
}

#game-board::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  z-index: -1;
  border-radius: 26px;
  background: linear-gradient(135deg, #001f3f, #0074D9, #00bcd4, #001f3f);
  background-size: 300% 300%;
  animation: borderFlow 10s linear infinite;
}

@keyframes borderFlow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.board-cell.highlight {
  outline: 2px dashed #00e676;
  animation: pulse-highlight 1s infinite;
}

@keyframes pulse-highlight {
  0% { outline-color: #00e676; }
  50% { outline-color: #69f0ae; }
  100% { outline-color: #00e676; }
}

/* === Animation de secousse (shake) === */
@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake {
  animation: shake 1s;
}

.main-play-area {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  max-width: 100%;
  margin: auto;
  padding: 1em;
}

#right-panel {
  flex: 0 0 15%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  max-height: 100%;
  min-width: 200px;
  gap: 12px;
}


/* === SELECTED TILE AREA === */
.selected-tile-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  
  position: relative;
  width: 100px; /* ou taille de ta tuile */
  height: 100px;
  margin: auto;
  z-index: 1;
}

#buttons-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  align-items: center;
}

#buttons-area button {
  width: 100%;
  max-width: 180px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
}

#buttons-area button:hover {
  transform: scale(1.02);
}

.selected-tile {
  position: relative;
  width: 144px;  /* 2x72px */
  height: 144px;
  margin-bottom: 20px;
}

.selected-preview {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* Boutons autour */
.selected-tile .tile-buttons {
  position: absolute;
  width: 36px;
  height: 36px;
  background: white;
  color: black;
  border-radius: 50%;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 10;
}

.selected-tile .tile-buttons:hover {
  transform: scale(1.2);
  background: linear-gradient(to right, #ffee58, #fdd835);
}

/* Positions relatives au centre de la grande tuile */
.selected-tile .top-left {
  top: -18px;
  left: -18px;
}
.selected-tile .top-right {
  top: -18px;
  right: -18px;
}
.selected-tile .bottom-left {
  bottom: -18px;
  left: -18px;
}
.selected-tile .bottom-right {
  bottom: -18px;
  right: -18px;
}



#buttons-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  align-items: center;
}

#buttons-area button {
  width: 100%;
  max-width: 180px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
}

#end-game-button {
  background-color: #1a0000;
  color: #ff4444;
  border: 2px solid #ff4444;
}
#end-game-button:hover {
  background-color: #ff0000;
  color: black;
  box-shadow: 0 0 20px #ff2222;
  transform: scale(1.05);
}

#legend-button {
  background-color: #fff8b5;
  color: #8a6d00;
  border: 2px solid #ffe066;
}
#legend-button:hover {
  background-color: #ffe066;
  color: #4d3c00;
  box-shadow: 0 0 25px rgba(255, 220, 50, 0.6);
  transform: scale(1.05);
}

#audio-control {
  background-color: #ccc;
  color: white;
}
#audio-control:hover {
  background: linear-gradient(to right, #3a7bd5, #45a049);
  transform: translateY(-2px);
}

/* === BUTTONS === */
#selected-tile-area button {
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  border: none;
  transition: all 0.2s ease;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  position: relative;
  z-index: 10;
}

#end-game-button {
  background-color: #1a0000;
  color: #ff4444;
  border: 2px solid #ff4444;
}
#end-game-button:hover {
  background-color: #ff0000;
  color: black;
  box-shadow: 0 0 20px #ff2222;
  transform: scale(1.05);
}

#legend-button {
  background-color: #fff8b5;
  color: #8a6d00;
  border: 2px solid #ffe066;
}
#legend-button:hover {
  background-color: #ffe066;
  color: #4d3c00;
  box-shadow: 0 0 25px rgba(255, 220, 50, 0.6);
  transform: scale(1.05);
}

#audio-control {
  background-color: #ccc;
  color: white;
}
#audio-control:hover {
  background: linear-gradient(to right, #3a7bd5, #45a049);
  transform: translateY(-2px);
}

/* === LEGEND POPUP === */
#legend-popup {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.7);
  z-index: 10000;
}

#legend-popup .popup-content {
  position: relative;
  background: white;
  color: black;
  margin: 5% auto;
  padding: 20px;
  border-radius: 15px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.close-button-legend {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  color: #ffcc00;
}

.legend-grid {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
}

.legend-column {
  flex: 1 1 200px;
  min-width: 200px;
}

.legend-column ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.legend-column li {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.legend-color,
.legend-volcano {
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-color.desert   { background-color: #e4c97b; }
.legend-color.water    { background-color: #4ab0de; }
.legend-color.plains   { background-color: #9dd765; }
.legend-color.forest   { background-color: #2e8b57; }

.legend-volcano.off    { background-color: #8b4513; }
.legend-volcano.on     { background-color: #ff6600; }

.animal-legend {
  columns: 3;
  column-gap: 20px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.animal-legend li {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  break-inside: avoid;
}

.legend-animal {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  background: gray;
  border-radius: 3px;
}

.tile {
  width: 72px;
  height: 72px;
  position: relative;
}

.tile.selected-preview {
  width: 100%;
  height: 100%;
}

.selected-tile .tile-buttons {
  user-select: none;
}

.selected-tile .tile-buttons {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.selected-tile:not(.has-tile) .tile-buttons {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none; /* désactive les clics pendant la disparition */
}

.animal {
  position: absolute;
  width: 20%;
  height: 20%;
  border-radius: 50%;
  background: gray;
  z-index: 5;
}

/* Animation de rotation */
@keyframes rotate-left {
  from { transform: rotate(0deg); }
  to { transform: rotate(-90deg); }
}
@keyframes rotate-right {
  from { transform: rotate(0deg); }
  to { transform: rotate(90deg); }
}

/* Animation de flip horizontal */
@keyframes flip-horizontal {
  from { transform: scaleX(1); }
  to { transform: scaleX(-1); }
}

/* Classe temporaire pour appliquer l’animation */
.tile.animate-rotate-left {
  animation: rotate-left 0.3s ease;
}
.tile.animate-rotate-right {
  animation: rotate-right 0.3s ease;
}
.tile.animate-flip {
  animation: flip-horizontal 0.3s ease;
}


.animal.snake {
  background: linear-gradient(45deg, #D2B48C 25%, #8B4513 25%, #8B4513 50%, #D2B48C 50%, #D2B48C 75%, #8B4513 75%);
  background-size: 5px 5px;
}
.animal.scorpion {
  background: radial-gradient(circle at 30% 30%, #F4A460 10%, #000000 10%, #000000 20%, #F4A460 20%);
  background-size: 4px 4px;
}
.animal.ostrich {
  background: radial-gradient(circle at 40% 40%, #D3D3D3 15%, #FFFFFF 15%, #FFFFFF 30%, #D3D3D3 30%);
  background-size: 6px 6px;
}
.animal.lizard {
  background: linear-gradient(to right, #6B8E23 25%, #A0522D 25%, #A0522D 50%, #6B8E23 50%);
  background-size: 5px 5px;
}
.animal.whale {
  background: linear-gradient(to bottom, #4682B4 50%, #FFFFFF 50%);
}
.animal.penguin {
  background: radial-gradient(circle at 50% 50%, #000000 20%, #FFFFFF 20%, #FFFFFF 40%, #000000 40%);
  background-size: 5px 5px;
}
.animal.turtle {
  background: radial-gradient(circle at 30% 30%, #2E8B57 15%, #8B4513 15%, #8B4513 30%, #2E8B57 30%);
  background-size: 5px 5px;
}
.animal.orca {
  background: linear-gradient(to right, #000000 25%, #FFFFFF 25%, #FFFFFF 50%, #000000 50%);
  background-size: 6px 6px;
}
.animal.elephant {
  background: linear-gradient(to bottom, #808080 50%, #404040 50%);
}
.animal.buffalo {
  background: radial-gradient(circle at 40% 40%, #4A2C2A 20%, #000000 20%, #000000 40%, #4A2C2A 40%);
  background-size: 5px 5px;
}
.animal.zebra {
  background: linear-gradient(to right, #FFFFFF 25%, #000000 25%, #000000 50%, #FFFFFF 50%);
  background-size: 5px 5px;
}
.animal.antelope {
  background: linear-gradient(to right, #DEB887 40%, #CD853F 40%, #CD853F 60%, #DEB887 60%);
  background-size: 4px 4px;
}
.animal.parrot {
  background: radial-gradient(circle at 50% 50%, #FF0000 15%, #FFFF00 15%, #FFFF00 30%, #008000 30%, #008000 45%, #FF0000 45%);
  background-size: 6px 6px;
}
.animal.tiger {
  background: linear-gradient(to right, #FFA500 25%, #000000 25%, #000000 50%, #FFA500 50%);
  background-size: 5px 5px;
}
.animal.panda {
  background: radial-gradient(circle at 40% 40%, #FFFFFF 20%, #000000 20%, #000000 40%, #FFFFFF 40%);
  background-size: 5px 5px;
}
.animal.gorilla {
  background: linear-gradient(to bottom, #333333 50%, #000000 50%);
}


.volcano {
  position: absolute;
  width: 20%;
  height: 20%;
  border-radius: 50%;
  background-color: red;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
}



/* === MODE PORTRAIT POUR TÉLÉPHONE === */
@media screen and (max-width: 600px) and (orientation: portrait) {
  .main-play-area {
    flex-direction: column;
    align-items: stretch;
    padding: 1em 0.5em;
    gap: 12px;
  }

  #pile-container {
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    padding: 10px;
  }

  #pile {
    display: inline-flex;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    padding: 0;
  }

  .pile-tile {
    width: 64px;
    height: 64px;
    flex: 0 0 auto;
  }

  #game-board {
    aspect-ratio: 1 / 1;
    width: 100%;
    max-width: 100%;
    max-height: calc(100vw - 20px);
    margin: auto;
  }

  #right-panel {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
  }

  .selected-tile {
    width: 80px;
    height: 80px;
    margin-bottom: 0;
  }

  .tile-buttons {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  #buttons-area {
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  #buttons-area button {
    padding: 6px 10px;
    font-size: 12px;
    max-width: 120px;
  }

  #pile-badge {
    font-size: 12px;
    padding: 4px 8px;
    bottom: 4px;
  }
  
   #game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 1px;
  }

  .board-cell {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
  }

  .board-cell .tile {
    width: 100%;
    height: 100%;
  }

  #game-over button {
    position: absolute;
    bottom: -10px;
    right: -10px;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
    background-color: #6a8a54;
    color: white;
    border: none;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  }

  #selected-tile {
    position: relative;
  }
}


#restart-button-inline {
  margin: 25px auto 0;
  padding: 10px 20px;
  font-size: clamp(14px, 2vw, 18px);
  cursor: pointer;
  background-color: #43a047;
  color: white;
  border: none;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

#restart-button-inline:hover {
  background-color: #388e3c;
}

.show-leaderboard-button {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  align-items: center;

  width: 100%;
  max-width: 180px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;

  background-color: #388e3c;
}

.show-leaderboard-button2 {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  align-items: center;

  width: 100%;
  max-width: 180px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;

  background-color: #388e3c;
}


#restart-button-popup {
  margin: 25px auto 0;
  padding: 10px 20px;
  font-size: clamp(14px, 2vw, 18px);
  cursor: pointer;
  background-color: #43a047;
  color: white;
  border: none;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

#restart-button-popup:hover {
  background-color: #388e3c;
}

  /* S'assurer qu’il ne déborde pas */
  #right-panel {
    position: relative;
  }
}
  #selected-tile {
    position: relative;
  }

}



/* Effet tuile gelée */
.frozen {
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(173, 216, 230, 0.8), inset 0 0 10px rgba(255, 255, 255, 0.7);
  filter: brightness(0.7) blur(1px);
}

.frozen::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(circle at top left, rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(circle at bottom right, rgba(255,255,255,0.7), transparent 50%);
  pointer-events: none;
  opacity: 0.6;
}

.frozen::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(173, 216, 230, 0.5);
  pointer-events: none;
  z-index: 1;
}
