@import url(https://fonts.googleapis.com/css2?family=Audiowide&display=swap);
@import url(https://fonts.googleapis.com/css2?family=Lilita+One&display=swap);
@import url(https://fonts.googleapis.com/css2?family=Iceberg&display=swap);

:root {
  --glow-primary: rgba(56, 189, 248, 0.7);
  --neon-pink: rgba(236, 72, 153, 0.8);
  --neon-blue: rgba(143, 25, 158, 0.8);
}

/* === BASE STYLES === */
body {
  font-family: 'Lilita One', cursive;
  color: #fff;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: linear-gradient(0deg, #0b0111 5%, #ad1ac0 100%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-overflow-scrolling: touch;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

/* Mobile background optimization */
@media (max-width: 768px) {
  body {
    background-attachment: scroll;
    background-size: 100% 100%;
  }
}

/* === CANVAS PROTECTION === */
#projector, canvas {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  position: absolute !important;
  top: -9999px !important;
  left: -9999px !important;
  width: 0 !important;
  height: 0 !important;
  z-index: -1000 !important;
  opacity: 0 !important;
}

/* Show canvas only on large screens */
@media (min-width: 1025px) {
  #projector {
    display: block !important;
    visibility: visible !important;
    pointer-events: auto !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: -1 !important;
    opacity: 1 !important;
  }
}

/* === TITLE SECTION === */
.title-section {
  text-align: center;
  padding: 200px 1rem 0 1rem;
  animation: titleFadeIn 1s ease-out;
  position: relative;
  z-index: 10;
}

@media screen and (max-width: 900px) {
  .title-section {
    padding: 100px 1rem 0 1rem;
  }
}

@keyframes titleFadeIn {
  0% { opacity: 0; transform: translateY(-30px); }
  100% { opacity: 1; transform: translateY(0); }
}

.title-section h1 {
  font-size: 3.5rem;
  font-family: Audiowide, cursive !important;
  color: #fff;
  text-shadow: 0 2px 16px #7b2cbf, 0 0 8px #38bdf8;
  letter-spacing: 0.1em;
  margin: 0;
}

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

/* === MODE CONTAINER === */
.mode-container {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 4rem;
  flex-wrap: wrap;
  padding: 3rem 1rem;
  margin-top: 2vh;
  margin-bottom: 6vh;
  animation: containerFadeIn 1.2s ease-out 0.3s both;
  position: relative;
  z-index: 10;
}

@keyframes containerFadeIn {
  0% { opacity: 0; transform: translateY(40px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* === MODE BLOCKS === */
.mode-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 400px;
  max-width: 100%;
  animation: blockSlideIn 0.8s ease-out;
}

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

.mode-image {
  position: relative;
  width: 100%;
  max-width: 400px;
  height: 400px;
  background-size: cover;
  background-position: center;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(56, 189, 248, 0.3);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.mode-image:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 50px var(--glow-primary), inset 0 0 30px rgba(56, 189, 248, 0.1);
}

/* === OVERLAY === */
.mode-image .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent 70%);
  padding: 2rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  text-align: center;
  transition: background 0.3s ease;
}

.mode-image:hover .overlay {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent 60%);
}

.overlay-title {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.overlay-title h2 {
  margin: 0;
  font-size: 2.2rem;
  text-shadow: 0 2px 12px rgba(0,0,0,0.8);
  font-weight: bold;
  letter-spacing: 2px;
}

.overlay-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}

/* === BUTTONS === */
.button {
  display: block;
  width: 60%;
  margin: 0 auto;
  padding: 0.7em 0;
  font-size: 1.4rem;
  font-family: 'Lilita One', 'Exo 2', sans-serif;
  background: linear-gradient(135deg, #632eb9, #7b2cbf);
  border: none;
  border-radius: 25px;
  box-shadow: 0 4px 20px var(--glow-primary), 0 0 12px var(--neon-pink);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-shadow: 0 2px 8px #7b2cbf, 0 0 6px #38bdf8;
  text-decoration: none;
  letter-spacing: 1px;
  position: relative;
  z-index: 2;
  color: #fff;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  pointer-events: none;
}

/* Loading state */
.button.loading {
  position: relative;
  color: transparent;
}

.button.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: buttonSpinner 1s linear infinite;
}

@keyframes buttonSpinner {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error state */
.button.error {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  box-shadow: 0 4px 20px rgba(231, 76, 60, 0.4), 0 0 12px rgba(192, 57, 43, 0.3);
  animation: errorPulse 0.5s ease-in-out;
}

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

/* Offline state */
.button.offline {
  background: linear-gradient(135deg, #7f8c8d, #95a5a6);
  box-shadow: 0 4px 20px rgba(127, 140, 141, 0.4), 0 0 12px rgba(149, 165, 166, 0.3);
}

.button:focus,
.button:hover {
  background: linear-gradient(135deg, #8b5cf6, #a855f7);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 30px var(--neon-pink), 0 0 20px var(--neon-blue);
  outline: 0;
}

.button:active {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 4px 15px var(--neon-pink), 0 0 10px var(--neon-blue);
}

/* === SLIDER === */
.slider {
  width: 85%;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  margin: 1rem 0;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.slider:hover {
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #632eb9, #7b2cbf);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 12px var(--glow-primary), 0 0 8px rgba(0,0,0,0.4);
  transition: all 0.3s ease;
  touch-action: none;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 16px var(--glow-primary), 0 0 12px rgba(0,0,0,0.5);
}

.slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #632eb9, #7b2cbf);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 12px var(--glow-primary), 0 0 8px rgba(0,0,0,0.4);
  transition: all 0.3s ease;
  touch-action: none;
}

/* === DIFFICULTY BARS === */
#difficultyBars {
  display: flex !important;
  justify-content: center !important;
  gap: 10px !important;
  margin: 0.8rem 0 !important;
  padding: 0.5rem 0 !important;
  flex-wrap: wrap !important;
}

#difficultyBars > div {
  min-width: 30px !important;
  height: 15px !important;
  border-radius: 8px !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3) !important;
  position: relative !important;
}

#difficultyBars > div::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: inherit;
  background: linear-gradient(45deg, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#difficultyBars > div:hover::after {
  opacity: 1;
}

/* Difficulty level labels (hidden by default, shown on hover/focus) */
#difficultyBars > div[data-index="1"]::before { content: 'Easy'; }
#difficultyBars > div[data-index="2"]::before { content: 'Normal'; }
#difficultyBars > div[data-index="3"]::before { content: 'Medium'; }
#difficultyBars > div[data-index="4"]::before { content: 'Hard'; }
#difficultyBars > div[data-index="5"]::before { content: 'Expert'; }

#difficultyBars > div::before {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

/* === MODE DESCRIPTION === */
.mode-desc {
  margin-top: 2rem;
  font-size: 1.4rem;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* === FOOTER === */
.nom-auteur {
  font-family: Iceberg, cursive !important;
  text-align: center;
  padding: 1rem;
  font-size: 1rem;
  opacity: 0.8;
  position: relative;
  z-index: 10;
}

footer {
  position: relative;
  z-index: 10;
}

/* === RESPONSIVE DESIGN === */

/* === LARGE TABLETS === */
@media (max-width: 1024px) {
  .title-section h1 {
    font-size: 3.2rem;
  }
  
  .mode-container {
    gap: 3rem;
    padding: 2.5rem 1rem;
  }
  
  .mode-block {
    width: 380px;
  }
  
  .mode-image {
    height: 380px;
  }
  
  .overlay-title h2 {
    font-size: 2rem;
  }
  
  .button {
    font-size: 1.3rem;
  }
}

/* === TABLETS === */
@media (max-width: 768px) {
  body {
    background-attachment: scroll; /* Better for mobile performance */
    padding-top: 80px; /* Space for mobile header */
    min-height: calc(100vh - 80px);
  }
  
  .title-section {
    position: relative;
    z-index: 10;
    pointer-events: auto;
  }
  
  .title-section h1 {
    font-size: 2.8rem;
    letter-spacing: 2px;
  }
  
  .mode-container {
    gap: 2.5rem;
    padding: 2rem 1rem;
    margin-bottom: 4vh;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 10;
    pointer-events: auto;
  }
  
  /* Corriger les éléments interactifs */
  .button {
    position: relative;
    z-index: 15;
    pointer-events: auto;
  }
  
  .slider {
    position: relative;
    z-index: 15;
    pointer-events: auto;
  }
  
  .mode-image {
    position: relative;
    z-index: 12;
    pointer-events: auto;
  }
  
  .mode-block {
    width: 100%;
    max-width: 450px;
  }
  
  .mode-image {
    height: 350px;
    border-radius: 16px;
  }
  
  .mode-image .overlay {
    padding: 1.5rem;
  }
  
  .overlay-title h2 {
    font-size: 1.9rem;
  }
  
  .button {
    width: 65%;
    font-size: 1.25rem;
    padding: 0.8em 0;
  }
  
  .mode-desc {
    font-size: 1.25rem;
    margin-top: 1.5rem;
    padding: 0 1rem;
  }
  
  .slider {
    width: 90%;
    height: 12px;
  }
  
  .slider::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
  }
  
  .slider::-moz-range-thumb {
    width: 32px;
    height: 32px;
  }
  
  #difficultyBars > div {
    min-width: 35px !important;
    height: 16px !important;
  }
}

/* === MOBILE DEVICES === */
@media (max-width: 480px) {
  body {
    padding-top: 100px; /* Espace réduit pour très petits écrans */
  }
  
  .title-section h1 {
    font-size: 2.2rem;
    letter-spacing: 1px;
    line-height: 1.2;
  }
  
  .mode-container {
    gap: 2rem;
    padding: 1.5rem 1rem;
    margin-top: 1vh;
    margin-bottom: 3vh;
  }
  
  .mode-block {
    width: 100%;
    max-width: 350px;
  }
  
  .mode-image {
    height: 320px;
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(56, 189, 248, 0.4);
  }
  
  .mode-image:hover {
    transform: translateY(-4px) scale(1.01);
  }
  
  .mode-image .overlay {
    padding: 1.2rem;
    gap: 1rem;
  }
  
  .overlay-title h2 {
    font-size: 1.6rem;
    letter-spacing: 1px;
  }
  
  .overlay-bottom {
    gap: 1rem;
  }
  
  .button {
    width: 75%;
    font-size: 1.15rem;
    padding: 0.9em 0;
    border-radius: 20px;
    min-height: 50px;
  }
  
  .button:hover {
    transform: translateY(-2px) scale(1.03);
  }
  
  .slider {
    width: 95%;
    height: 14px;
    margin: 0.8rem 0;
  }
  
  .slider::-webkit-slider-thumb {
    width: 36px;
    height: 36px;
    border: 4px solid #fff;
  }
  
  .slider::-moz-range-thumb {
    width: 36px;
    height: 36px;
    border: 4px solid #fff;
  }
  
  #difficultyBars {
    gap: 8px !important;
    margin: 1rem 0 !important;
  }
  
  #difficultyBars > div {
    min-width: 30px !important;
    height: 14px !important;
    border-radius: 6px !important;
  }
  
  .mode-desc {
    font-size: 1.15rem;
    margin-top: 1.2rem;
    padding: 0 0.5rem;
    line-height: 1.4;
  }
}

/* === SMALL MOBILE DEVICES === */
@media (max-width: 360px) {
  .title-section h1 {
    font-size: 1.9rem;
    letter-spacing: 0.5px;
  }
  
  .mode-container {
    gap: 1.5rem;
    padding: 1.2rem 0.8rem;
  }
  
  .mode-block {
    max-width: 300px;
  }
  
  .mode-image {
    height: 280px;
    border-radius: 12px;
  }
  
  .mode-image .overlay {
    padding: 1rem;
  }
  
  .overlay-title h2 {
    font-size: 1.4rem;
  }
  
  .button {
    width: 80%;
    font-size: 1.1rem;
    padding: 0.8em 0;
    min-height: 48px;
  }
  
  .slider {
    height: 16px;
  }
  
  .slider::-webkit-slider-thumb {
    width: 40px;
    height: 40px;
  }
  
  .slider::-moz-range-thumb {
    width: 40px;
    height: 40px;
  }
  
  #difficultyBars > div {
    min-width: 25px !important;
    height: 12px !important;
  }
  
  .mode-desc {
    font-size: 1.05rem;
    margin-top: 1rem;
  }
}

/* === TOUCH DEVICE OPTIMIZATIONS === */
@media (hover: none) and (pointer: coarse) {
  .mode-image:hover {
    transform: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(56, 189, 248, 0.3);
  }
  
  .button:hover {
    transform: none;
    background: linear-gradient(135deg, #632eb9, #7b2cbf);
    box-shadow: 0 4px 20px var(--glow-primary), 0 0 12px var(--neon-pink);
  }
  
  .mode-image:active {
    transform: scale(0.98);
    transition: transform 0.1s;
  }
  
  .button:active {
    transform: scale(0.96);
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
    box-shadow: 0 2px 15px var(--neon-pink), 0 0 8px var(--neon-blue);
    transition: all 0.1s;
  }
  
  .slider::-webkit-slider-thumb:hover {
    transform: none;
  }
  
  /* Improved touch targets */
  .button {
    min-height: 48px;
    padding: 1rem 0;
    min-width: 120px;
  }
  
  .slider {
    min-height: 20px;
    padding: 5px 0;
  }
  
  .slider::-webkit-slider-thumb {
    min-width: 44px;
    min-height: 44px;
  }
  
  .slider::-moz-range-thumb {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Touch device class styles */
.touch-device .button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-device .slider {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Keyboard navigation styles */
.keyboard-navigation .button:focus {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
  box-shadow: 0 8px 30px var(--neon-pink), 0 0 20px var(--neon-blue), 0 0 0 3px rgba(56, 189, 248, 0.5);
}

.keyboard-navigation .slider:focus {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3), 0 0 0 3px rgba(56, 189, 248, 0.5);
}

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
  .title-section,
  .mode-container,
  .mode-block,
  .mode-image,
  .button,
  .slider,
  #difficultyBars > div {
    animation: none;
    transition: none;
  }
  
  .title-section h1 {
    animation: none;
    background: #38bdf8;
    -webkit-background-clip: initial;
    -webkit-text-fill-color: initial;
    background-clip: initial;
    color: #38bdf8;
  }
  
  .mode-image:hover {
    transform: none;
  }
  
  .button:hover {
    transform: none;
  }
}

/* === HIGH DPI DISPLAYS === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .mode-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* === LANDSCAPE MOBILE === */
@media (max-width: 768px) and (orientation: landscape) {
  .title-section h1 {
    font-size: 2.5rem;
  }
  
  .mode-container {
    flex-direction: row;
    gap: 1.5rem;
    padding: 1.5rem 1rem;
    margin-bottom: 2vh;
  }
  
  .mode-block {
    width: 45%;
    max-width: 300px;
  }
  
  .mode-image {
    height: 250px;
  }
  
  .overlay-title h2 {
    font-size: 1.4rem;
  }
  
  .button {
    font-size: 1rem;
    padding: 0.6em 0;
  }
  
  .mode-desc {
    font-size: 1rem;
    margin-top: 0.8rem;
  }
}