/**
 * SYSTÈME RESPONSIVE UNIFIÉ - Phase 2025-09-11
 * Consolidation de mobile-responsive.css + responsive.css
 * Breakpoints cohérents: 320px|480px|768px|1024px|1200px
 */

/* === VARIABLES RESPONSIVE === */
:root {
  --mobile-xs: 320px;
  --mobile: 480px;
  --tablet: 768px;
  --desktop: 1024px;
  --desktop-lg: 1200px;

  /* Espacements responsive */
  --padding-mobile: clamp(10px, 3vw, 20px);
  --padding-tablet: clamp(20px, 4vw, 30px);
  --padding-desktop: clamp(30px, 5vw, 40px);

  /* Touch targets */
  --touch-target: 44px;
  --touch-target-large: 48px;
}

/* === BASE MOBILE-FIRST === */
/* Toutes les règles de base sont pour mobile (≤479px) */

.container {
  padding: var(--padding-mobile);
  max-width: 100%;
  margin: 0 auto;
}

/* Viewport full-screen pour mobile */
body.full-screen-mobile {
  height: 100vh;
  overflow: hidden;
}

.slide {
  padding: var(--padding-mobile);
  min-height: calc(100vh - 80px); /* Space for top-bar */
}

/* === COMPOSANTS RESPONSIVE === */

/* Boutons touch-friendly */
.btn {
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  padding: 12px 16px;
  font-size: 16px; /* Évite zoom iOS */
}

.btn-mobile {
  padding: 16px 20px;
  font-size: 18px;
  min-height: var(--touch-target-large);
}

/* Images toujours responsives */
.img-responsive,
img {
  max-width: 100%;
  height: auto;
}

/* Grid système adaptatif */
.grid-responsive {
  display: grid;
  gap: 15px;
  grid-template-columns: 1fr; /* Mobile: 1 colonne */
}

/* Cards empilées sur mobile */
.card-stack {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
}

.card-base {
  width: 100%;
  margin: 5px 0;
  max-height: 85vh;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Optimisation générale layout mobile */
@media (max-width: 768px) {
  body {
    padding: 0;
    margin: 0;
  }

  .slide {
    padding: var(--padding-mobile);
    min-height: auto;
    max-height: 100vh;
    overflow-y: auto;
  }

  /* Containers adaptables mobile */
  .game-card,
  .challenge-card,
  .discovery-card {
    width: 100%;
    margin: 8px 0;
    padding: 15px;
    box-sizing: border-box;
    min-height: auto;
    max-height: 85vh;
    overflow-y: auto;
  }

  /* Boutons mobiles optimisés */
  .btn.btn-mobile-optimized {
    width: 90%;
    max-width: 280px;
    margin: 8px auto;
    padding: 12px 16px;
    font-size: 16px;
    min-height: var(--touch-target);
  }

  .user-list {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
}

/* Navigation mobile - Bandeau compact */
@media (max-width: 768px) {
  .top-bar {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 3px 8px;
    margin-bottom: 8px;
    gap: 3px;
    min-height: 40px;
    border-radius: 10px;
  }

  .top-bar .language-selector,
  .top-bar .global-volume-controls {
    gap: 3px;
  }

  .top-bar .btn {
    padding: 4px 8px;
    font-size: 0.9em;
    min-height: 32px;
    margin: 2px;
  }

  .top-bar .mute-btn {
    padding: 2px 4px;
    font-size: 1em;
    min-height: 24px;
  }

  .top-bar .volume-slider {
    width: 60px;
  }
}

/* === BREAKPOINTS === */

/* Mobile large (≥320px) */
@media (min-width: 320px) {
  .container {
    padding: 15px;
  }

  .btn {
    font-size: 16px;
    padding: 14px 18px;
  }
}

/* Mobile XL (≥480px) */
@media (min-width: 480px) {
  .container {
    max-width: 460px;
    padding: var(--padding-mobile);
  }

  .grid-responsive {
    grid-template-columns: repeat(2, 1fr);
  }

  .slide h1 {
    font-size: 2rem;
  }

  /* Cartes en 2 colonnes avec meilleure gestion hauteur */
  .card-stack {
    flex-flow: row wrap;
    align-items: flex-start;
  }

  .card-base {
    width: calc(50% - 10px);
    max-height: 80vh;
    overflow-y: auto;
  }

  /* Arcade cards plus compactes */
  #multimiam-arcade-card,
  #multimemory-arcade-card,
  #multisnake-arcade-card {
    min-height: auto;
    max-height: none;
    overflow-y: visible;
  }
}

/* Tablette (≥768px) */
@media (min-width: 768px) {
  .container {
    max-width: 740px;
    padding: var(--padding-tablet);
  }

  .grid-responsive {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .slide {
    padding: var(--padding-tablet);
    min-height: auto; /* Remove forced height on desktop */
  }

  .slide h1 {
    font-size: 2.5rem;
  }

  /* Navigation desktop */
  .top-bar {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 15px;
  }

  /* Cartes en 3 colonnes */
  .card-base {
    width: calc(33.333% - 15px);
  }

  /* Boutons plus petits sur desktop */
  .btn-sm-desktop {
    padding: 6px 12px;
    font-size: 14px;
    min-height: auto;
    min-width: auto;
  }
}

/* Desktop (≥1024px) */
@media (min-width: 1024px) {
  .container {
    max-width: 980px;
    padding: var(--padding-desktop);
  }

  .grid-responsive {
    grid-template-columns: repeat(4, 1fr);
    gap: 25px;
  }

  .slide h1 {
    font-size: 3rem;
  }

  /* Cartes en 4 colonnes */
  .card-base {
    width: calc(25% - 20px);
  }
}

/* Desktop large (≥1200px) */
@media (min-width: 1200px) {
  .container {
    max-width: 1170px;
  }

  .slide {
    padding: 60px 40px;
  }
}

/* === ORIENTATION === */

/* Arcade Canvas Mobile Optimisé */
@media (max-width: 768px) {
  .arcade-canvas,
  .arcade-game-ui > canvas,
  #arcade-canvas,
  #multimiam-canvas {
    width: 95%;
    height: auto;
    max-width: 400px;
    max-height: 50vh;
    margin: 10px auto;
    padding: 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    /* Anti-aliasing pour éviter le flou */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
  }

  /* Snake canvas - Résolution fixe pour éviter l'effet ratatiné */
  #multisnake-canvas,
  canvas#multisnake-canvas,
  .arcade-game-ui > canvas.multisnake-canvas {
    width: 90%;
    height: auto;
    max-width: 380px;
    max-height: 380px; /* Carré pour le Snake */
    min-height: 280px; /* Minimum pour être lisible */
    aspect-ratio: 1; /* Force aspect ratio carré */
    margin: 10px auto;
    padding: 0;
    /* Rendu pixel parfait pour Snake */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    /* Éviter l'anti-aliasing qui fait flou */
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
  }
}

.game-controls {
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

/* Boutons en colonne seulement dans game-controls, pas tous les boutons */
.game-controls .btn {
  width: 90%;
  margin: 5px auto;
}

/* Boutons arcade game over gardent leur taille normale */
.arcade-gameover .btn {
  width: auto;
  margin: 5px;
  display: inline-block;
}

/* Portrait mobile/tablette */
@media (max-width: 1024px) and (orientation: portrait) {
  .arcade-canvas,
  .arcade-game-ui > canvas {
    max-height: 50vh;
    width: 90%;
  }
}

/* Paysage mobile - Plus d'espace en hauteur */
@media (max-width: 768px) and (orientation: landscape) {
  .arcade-canvas,
  .arcade-game-ui > canvas {
    max-height: 60vh;
    width: 70%;
  }

  .slide {
    padding: 10px 20px;
  }

  .top-bar {
    height: 50px;
  }
}

/* === TOUCH ET GESTURES === */

/* Zones tactiles élargies */
.touch-target {
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  display: inline-block;
  position: relative;
}

/* Désactive hover sur tactile, active touch feedback */
@media (hover: none) and (pointer: coarse) {
  .hover-effect:hover {
    background: initial;
    transform: none;
  }

  .hover-effect:active {
    background: rgb(0 123 255 / 0.1);
    transform: scale(0.98);
  }
}

/* === COMPOSANTS SPÉCIFIQUES === */

/* Cartes arcade responsive - Fix overflow boutons difficulté */
.arcade-game-card {
  width: 100%;
  margin: 10px 0;
  overflow-x: hidden;
  box-sizing: border-box;
}

.arcade-game-card .improved-difficulty-select {
  width: 95%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 8px;
  margin: 5px auto 10px auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.arcade-game-card .difficulty-buttons-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}

.arcade-game-card .difficulty-btn {
  flex: 0 0 auto;
  min-width: 85px;
  max-width: 120px;
  padding: 8px 12px;
  margin: 2px;
  font-size: 0.9em;
  white-space: nowrap;
  text-align: center;
}

@media (max-width: 480px) {
  .arcade-game-card .difficulty-btn {
    min-width: 75px;
    padding: 6px 10px;
    font-size: 0.85em;
    margin: 1px;
  }

  .arcade-game-card .improved-difficulty-select {
    padding: 6px;
    margin: 3px auto 8px auto;
  }

  /* Réduction hauteur cartes mobile */
  #multimiam-arcade-card,
  #multimemory-arcade-card,
  #multisnake-arcade-card {
    min-height: 280px;
  }
}

/* Discovery Mode responsive */
.visual-grid,
.patterns-grid {
  display: grid;
  gap: 15px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

@media (max-width: 768px) {
  .visual-grid,
  .patterns-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .animation-step {
    padding: 15px;
  }

  .lab-selector {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (max-width: 480px) {
  .visual-grid,
  .patterns-grid {
    grid-template-columns: 1fr;
  }

  .lab-selector {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .equation-card {
    min-width: 100px;
    padding: 15px;
  }

  .dropzone-content {
    font-size: 18px;
  }

  /* Bouton retour fixé mobile */
  .return-btn,
  #back-btn.discovery-return-btn {
    position: fixed !important;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 16px;
    box-shadow: 0 4px 8px rgb(0 0 0 / 0.1);
    transition: all 0.3s;
  }
}

/* Scores dashboard responsive */
.dashboard-scores-card {
  border-radius: 22px;
  padding: var(--padding-tablet);
  margin: 32px auto 24px auto;
  max-width: 700px;
}

.scores-block {
  display: flex;
  flex-direction: column;
  gap: 28px 0;
}

@media (max-width: 900px) {
  .dashboard-scores-card {
    padding: 18px 4vw 10px 4vw;
    max-width: 98vw;
  }

  .scores-block {
    gap: 18px 0;
  }

  .scores-subblock {
    max-width: 98vw;
    padding: 18px 2vw 14px 2vw;
    min-height: 0;
  }
}

/* Arcade responsive */
.arcade-top5-modern {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
}

.arcade-score-item {
  min-width: 56px;
  padding: 8px 14px;
  font-size: 1.1em;
}

@media (max-width: 600px) {
  .arcade-top5-modern {
    gap: 8px;
    padding: 4px 0;
  }

  .arcade-score-item {
    min-width: 44px;
    font-size: 1em;
    padding: 6px 7px;
    margin-bottom: 2px;
  }
}

/* === OPTIMISATIONS PERFORMANCE === */

/* GPU acceleration pour animations */
.animated,
.slide-transition,
.btn:active {
  will-change: transform;
  transform: translateZ(0);
}

/* Optimisation scrolling */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Réduction motion si préféré */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === UTILITÉS === */

/* Masquer/afficher selon breakpoint */
.hidden-mobile {
  display: none;
}

@media (min-width: 768px) {
  .hidden-mobile {
    display: initial;
  }
}

.mobile-only {
  display: block;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
}

/* Texte et espacement responsive */
.text-responsive {
  font-size: clamp(14px, 4vw, 18px);
  line-height: 1.4;
}

.p-responsive {
  padding: var(--padding-mobile);
}

@media (min-width: 768px) {
  .p-responsive {
    padding: var(--padding-tablet);
  }
}

@media (min-width: 1024px) {
  .p-responsive {
    padding: var(--padding-desktop);
  }
}

.m-responsive {
  margin: clamp(5px, 2vw, 20px);
}
