/* ============================================================
   SHARED.CSS - Unified Styles for All Game Pages
   Merged from hub.css and shared-systems.css
   ============================================================ */

/* ============================================================
   CSS VARIABLES & RESET
   ============================================================ */
:root {
  --primary-font: 'Nunito', 'FbSpacer', sans-serif;
  --btn-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  --btn-hover-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  --star-gold: #FFD700;
  --star-empty: #E0E0E0;
  --glass-bg: rgba(255, 255, 255, 0.8);
  --primary-kids: #FF6B6B;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background-color: #7fd4ff;
  font-family: var(--primary-font);
}

/* ============================================================
   SYSTEM CONTROLS
   ============================================================ */
.system-controls {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 10px;
  z-index: 1000;
}

.speaker-btn, .music-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border: 4px solid var(--primary-kids);
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .speaker-btn:hover, .music-toggle:hover {
    transform: scale(1.1);
  }
}

.speaker-btn:active, .music-toggle:active {
  transform: scale(0.9);
}

.music-toggle.muted {
  border-color: #999;
  filter: grayscale(1);
}

/* ============================================================
   HOME BUTTON — Global reusable component
   ============================================================ */
.home-btn {
  position: fixed;
  top: 4px;
  right: 20px;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 25px;
  background-color: #f7f7f7;
  color: #4a86d9;
  border: 3px solid #4a86d9;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
  box-shadow: 0 4px 15px rgba(74, 134, 217, 0.2);
  direction: ltr;
  min-height: 44px;
  touch-action: manipulation;
}
.levels-btn {
  position: fixed;
  top: 4px;
  right: 300px;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 25px;
  background-color: #f7f7f7;
  color: #4a86d9;
  border: 3px solid #4a86d9;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(74, 134, 217, 0.2);
  direction: ltr;
}

.home-btn:hover {
  background-color: #e8f0fb;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(74, 134, 217, 0.3);
}

.home-btn__text {
  direction: rtl;
  white-space: nowrap;
}

.home-btn__icon {
  font-size: 1.2rem;
}
#menu-btn {
  position: fixed;
  top: 4px;
  right: 300px;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 25px;
  background-color: #f7f7f7;
  color: #4a86d9;
  border: 3px solid #4a86d9;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(74, 134, 217, 0.2);
  direction: ltr;
}

/* ============================================================
   MODAL SYSTEM
   ============================================================ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.modal.hidden {
  display: none !important;
}

.modal.active.hidden {
  display: flex !important;
}

.modal-content {
  background-color: white;
  padding: 2.5rem;
  border-radius: 40px;
  text-align: center;
  border: 8px solid var(--primary-kids);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  max-width: 90%;
  width: 450px;
  transform: scale(0.7);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-title {
  font-size: 3rem;
  color: var(--primary-kids);
  margin-bottom: 0.5rem;
  font-family: 'FbSpacer', 'Nunito', sans-serif;
  line-height: 1.2;
}

.modal-text {
  font-size: 1.6rem;
  font-weight: 800;
  color: #333;
  margin-bottom: 2rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-modal {
  padding: 15px 40px;
  font-size: 1.5rem;
  font-weight: 900;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  width: 80%;
  max-width: 300px;
  text-decoration: none;
  display: inline-block;
  touch-action: manipulation;
}

.btn-modal-primary {
  background-color: #2ed573;
  color: white;
  box-shadow: 0 8px 0 #21a351, 0 15px 20px rgba(46, 213, 115, 0.2);
}

.btn-modal-secondary {
  background-color: #70a1ff;
  color: white;
  box-shadow: 0 8px 0 #4776d0, 0 15px 20px rgba(112, 161, 255, 0.2);
}

.btn-modal-danger {
  background-color: #ff4757;
  color: white;
  box-shadow: 0 8px 0 #d93846, 0 15px 20px rgba(255, 71, 87, 0.2);
}

@media (hover: hover) and (pointer: fine) {
  .btn-modal:hover {
    transform: translateY(-2px);
  }
}

.btn-modal:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 currentColor;
}

/* ============================================================
   REWARD STARS
   ============================================================ */
.reward-container {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 20px 0;
}

.reward-star {
  font-size: 50px;
  color: var(--star-empty);
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.3s;
  transform: scale(0.85);
  opacity: 0.45;
  filter: none;
}

.reward-star.active {
  color: var(--star-gold);
  transform: scale(1);
  opacity: 1;
  filter: none;
  animation: star-pop 0.5s forwards;
  /* Pas de animation-delay ici — le décalage est géré par le JS (index * 200ms) */
}

/* ============================================================
   CONFETTI
   ============================================================ */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
}

.confetti.hidden {
  display: none;
}

/* ============================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================ */
@media (max-width: 768px) {
  .speaker-btn, .music-toggle {
    width: 50px;
    height: 50px;
    font-size: 24px;
    top: 10px;
    left: 10px;
    min-width: 44px;
    min-height: 44px;
  }

  .reward-star {
    font-size: 40px;
  }

  .modal {
    padding: 10px;
    overflow-y: auto;
  }

  .modal-content {
    padding: 1.5rem;
    border-radius: 30px;
    border: 6px solid var(--primary-kids);
    width: 95%;
    max-width: calc(100vw - 20px);
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-title {
    font-size: 2rem;
  }

  .modal-text {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
  }

  .btn-modal {
    padding: 12px 30px;
    font-size: 1.2rem;
    width: 90%;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .home-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 10px;
    width: 55px;
    height: 55px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
    gap: 0;
  }

  .home-btn__text {
    display: none;
  }

  .home-btn__icon {
    font-size: 1.6rem;
  }

  /* Fix off-screen position on phones (right: 300px in base is wider than phone viewport) */
  .levels-btn {
    right: 80px;
    width: 55px;
    height: 55px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
    gap: 0;
  }

  #menu-btn {
    right: 80px;
  }
}

@media (max-width: 600px) {
  .speaker-btn, .music-toggle {
    width: 44px;
    height: 44px;
    font-size: 20px;
    top: 8px;
    left: 8px;
    min-width: 44px;
    min-height: 44px;
  }

  .reward-star {
    font-size: 35px;
  }
}

@media (max-width: 480px) {
  .speaker-btn, .music-toggle {
    width: 40px;
    height: 40px;
    font-size: 20px;
    top: 8px;
    left: 8px;
  }

  .reward-star {
    font-size: 32px;
  }

  .modal-content {
    padding: 1.5rem;
    border-radius: 30px;
    border: 6px solid var(--primary-kids);
    width: 95%;
  }

  .modal-title {
    font-size: 2rem;
  }

  .modal-text {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
  }

  .btn-modal {
    padding: 12px 30px;
    font-size: 1.2rem;
    width: 90%;
  }

  .home-btn {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 8px;
    width: 50px;
    height: 50px;
  }

  .speaker-btn, .music-toggle {
    top: calc(8px + env(safe-area-inset-top, 0px));
  }
}

/* ============================================================
   DESKTOP SAFEGUARDS (1200px+)
   ============================================================ */
@media (min-width: 1200px) {
  .system-controls {
    gap: 10px;
  }

  .modal {
    padding: 20px;
  }

  .modal-content {
    width: 450px;
    max-width: 90%;
  }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes star-pop {
  0% {
    transform: scale(0) rotate(-30deg);
  }
  70% {
    transform: scale(1.2) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.bounce {
  animation: bounce 0.6s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .bounce {
    animation: none;
  }
}

/* ============================================================
   GLOBAL UX POLISH
   ============================================================ */
button, .choice-card, .card, .shape, .object-emoji, .shadow-card, .emoji-cell, .thumbnail-wrapper, .puzzle-piece {
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

/* Landscape phone: unlock scroll for games whose content overflows (shapes, counting, shadow) */
@media (orientation: landscape) and (max-height: 500px) {
  html, body {
    overflow-y: auto;
  }
}

/* Portrait phone: unlock scroll on short-height screens where level 2+ content overflows */
@media (orientation: portrait) and (max-height: 700px) {
  html, body {
    overflow-y: auto;
  }
}
