body {
  background: #222;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

:root {
  --ui-bar-height: 100px;
}

#game-container {
  box-shadow: 0 0 32px #000a;
  border-radius: 16px;
  background: #333;
  padding: 8px;
  width: min(100vw, calc(100vh - var(--ui-bar-height)));
  height: min(100vw, calc(100vh - var(--ui-bar-height)));
  max-width: 100vw;
  max-height: calc(100vh - var(--ui-bar-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 125px;
  opacity: 1;
  transition: opacity 0.22s cubic-bezier(.4,0,.2,1), visibility 0.22s;
}

#game-container.fade-out {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

#game-container.fade-in {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

#game-container.level-room-active {
  margin-top: 50px !important;
}
#game-container.level-room-active #button-row {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 30 !important;
  margin-bottom: 35px !important;
  width: 100%;
}

canvas {
  width: min(100vw, calc(100vh - var(--ui-bar-height)));
  height: min(100vw, calc(100vh - var(--ui-bar-height)));
  max-width: 100vw;
  max-height: calc(100vh - var(--ui-bar-height));
  background: #444;
  border-radius: 8px;
  display: block;
  margin: auto;
  touch-action: none;
}

#button-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  margin-bottom: 85px;
  position: relative;
  margin-top: 24px;
  min-height: 40px; /* Fixed height to prevent movement */
}

#button-row button,
#orb-count {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.3em;
  font-weight: 700;
  letter-spacing: 1px;
  color: #e6c200;
  background: linear-gradient(90deg, #fffbe6 0%, #ffe066 30%, #e6c200 60%, #bfa13a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  /* Sharper, metallic gold with minimal shadow for crispness */
  text-shadow:
    0 1px 0 #fffbe6,    /* crisp white highlight */
    0 2px 0 #bfa13a;    /* sharp gold shadow */
}

#button-row button {
  background: #444;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 16px; /* Reduced padding */
  font-size: 1em; /* Reduced font size */
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px #0006;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a;
  background-clip: unset;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  text-fill-color: unset;
  min-width: 80px; /* Fixed width */
  text-align: center;
}
#button-row button:hover, #button-row button:focus {
  background: #666;
  color: #ffe066; /* Gold on hover/focus */
  outline: none;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006;
  transform: translateY(-2px) scale(1.04);
}

#orb-count {
  color: #e6c200;
  font-size: 1.2em;
  margin-left: 32px;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  min-width: 120px;
  text-align: left;
  text-shadow: 0 1px 0 #bfa13a;
  flex-shrink: 0;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

/* If you add more buttons elsewhere, use this class for consistency: */
.fantasy-btn {
  background: #444;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 28px;
  font-size: 1.2em;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px #0006;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a;
  background-clip: unset;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  text-fill-color: unset;
}
.fantasy-btn:hover, .fantasy-btn:focus {
  background: #666;
  color: #ffe066;
  outline: none;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006;
  transform: translateY(-2px) scale(1.04);
}

#mobile-controls {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  user-select: none;
  pointer-events: none; /* Enable only for children */
}
#mobile-controls .arrow-row {
  display: flex;
  justify-content: center;
  margin: 2px 0;
}
.arrow-btn {
  width: 56px;
  height: 56px;
  margin: 0 8px;
  font-size: 2rem;
  border-radius: 50%;
  border: 2px solid #444;
  background: #222;
  color: #fff; /* White arrows */
  opacity: 0.9;
  pointer-events: auto;
  touch-action: manipulation;
  transition: color 0.15s, background 0.15s;
}
.arrow-btn:active,
.arrow-btn.pressed {
  color: #ffe066; /* Gold when pressed */
  background: #444;
}
@media (min-width: 700px) {
  #mobile-controls {
    display: none;
  }
}

/* Mobile layout improvements */
@media (max-width: 700px) {
  html, body {
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  #game-container {
    width: 100vw !important;
    height: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vw !important;
    margin-top: 90px !important;
  }
  #orb-count {
    order: -1;
    width: 100vw;
    text-align: center;
    margin: 4px 0 2px 0;
    position: static;
    z-index: 1001;
    background: none !important;
    color: #e6c200;
    font-size: 0.75em;
    font-family: 'Cinzel Decorative', serif;
    font-weight: 700;
    letter-spacing: 1px;
    min-width: unset;
    margin-left: 0;
    display: block;
  }
  #button-row {
    order: 0;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100vw !important;
    margin: 10px 0 0 0 !important;
    gap: 8px !important;
    min-width: unset !important;
    padding: 0 !important;
    position: static !important;
    z-index: 1002 !important;
    margin-top: 16px;
    min-height: 32px; /* Smaller fixed height on mobile */
  }
  #button-row button {
    padding: 4px 12px;
    font-size: 0.9em;
    min-width: 60px;
  }
  canvas {
    width: 100vw !important;
    height: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vw !important;
  }
  #mobile-controls {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    margin-top: 0;
    bottom: 19px !important;
  }
  .arrow-btn,
  #mobile-controls .arrow-btn {
    width: 72px !important;
    height: 72px !important;
    font-size: 2.4rem !important;
    background: #222 !important;
    color: #fff !important;
    border: 2px solid #444 !important;
    box-shadow: none !important;
    background-image: none !important;
    opacity: 0.95;
    transition: color 0.15s, background 0.15s;
  }
  .arrow-btn:active,
  .arrow-btn.pressed {
    color: #ffe066 !important;
    background: #444 !important;
  }
  #button-row button:focus,
  #button-row button:hover,
  .fantasy-btn:focus,
  .fantasy-btn:hover {
    color: #fff !important;
    background: #444 !important;
    outline: none !important;
    box-shadow: 0 2px 8px #0006 !important;
    transform: none !important;
  }
  #button-row button:active,
  .fantasy-btn:active {
    color: #ffe066 !important;
    background: #666 !important;
    outline: none !important;
    box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006 !important;
    transform: translateY(-2px) scale(1.04) !important;
  }
  #orb-counter-ui, #move-counter, #timer {
    font-size: 1.1em;
    min-width: 80px;
  }
}

/* --- Force buttons to be gold ONLY on hover/focus, not on active/pressed --- */
#button-row button,
.fantasy-btn {
  color: #fff !important;
  background: #444 !important;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
}

/* Gold on hover/focus */
#button-row button:hover,
#button-row button:focus,
.fantasy-btn:hover,
.fantasy-btn:focus {
  color: #ffe066 !important;
  background: #666 !important;
  outline: none !important;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006 !important;
  transform: translateY(-2px) scale(1.04) !important;
}

/* Force white on active/pressed, even if focused */
#button-row button:active,
.fantasy-btn:active,
#button-row button:focus:not(:hover),
.fantasy-btn:focus:not(:hover) {
  color: #fff !important;
  background: #444 !important;
  box-shadow: 0 2px 8px #0006 !important;
  transform: none !important;
}

#ui-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  min-width: 0;
  flex-shrink: 0;
  flex-wrap: nowrap;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

#orb-counter-ui, #move-counter, #timer {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.3em;
  font-weight: 700;
  letter-spacing: 1px;
  color: #e6c200;
  background: linear-gradient(90deg, #fffbe6 0%, #ffe066 30%, #e6c200 60%, #bfa13a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 1px;
  min-width: 70px;
  white-space: nowrap;
  text-align: center;
  justify-content: center;
}

#timer {
  min-width: 110px;
  max-width: 110px;
  width: 110px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel Decorative', serif;
  font-variant-numeric: tabular-nums;
  overflow: visible;
  margin-left: 10px;
}

#timer span, #timer {
  font-family: 'Roboto Mono', monospace;
  font-variant-numeric: tabular-nums;
}

#timer::before {
  content: "⏱️";
  font-size: 1.2em;
  margin-left: 0;
  margin-right: 15px;
  display: inline-block;
  width: 22px;
  min-width: 22px;
  text-align: center;
  color: inherit;
  vertical-align: middle;
}

#orb-counter-ui {
  min-width: 70px;
  justify-content: center;
}

#orb-counter-ui svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  margin-right: 5px;
}

#orb-counter-ui .orb-numbers {
  min-width: 35px;
  text-align: center;
}

#move-counter {
  min-width: 70px;
  justify-content: center;
}

#move-counter .move-emoji {
  width: 24px;
  text-align: center;
  display: inline-block;
  margin-right: 5px;
}

#move-counter .move-numbers {
  min-width: 20px;
  text-align: center;
}

@media (max-width: 700px) {
  #ui-bar {
    gap: 2px;
  }
  
  #orb-counter-ui, #move-counter, #timer {
    font-size: 1.1em;
    min-width: 60px;
  }
  
  #timer::before,
  #orb-counter-ui svg,
  #move-counter .move-emoji {
    width: 18px;
  }
  
  #orb-counter-ui .orb-numbers,
  #move-counter .move-numbers {
    min-width: 30px;
  }
}

#move-counter span, .move-numbers {
  font-family: 'Roboto Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* --- MENU OVERLAY STYLES --- */
#menu-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: 100vh;
  background: #111;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.22s cubic-bezier(.4,0,.2,1), visibility 0.22s;
}
#menu-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
#menu-overlay.fade-in {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}
#menu-logo-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 48px;
}
#menu-logo {
  width: 320px;
  max-width: 80vw;
  animation: floatLogo 2.8s ease-in-out infinite alternate;
  /* Reduced feathering at the top */
  -webkit-mask-image: radial-gradient(ellipse 60% 48% at 50% 55%, #fff 25%, transparent 100%);
  mask-image: radial-gradient(ellipse 60% 48% at 50% 55%, #fff 25%, transparent 100%);
}
@keyframes floatLogo {
  0% { transform: translateY(0px) scale(1.01); }
  100% { transform: translateY(-18px) scale(1.04); }
}
#menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
}
.menu-btn {
  background: #444;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 36px;
  font-size: 1.3em;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px #0006;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a, 0 1px 0 #fffbe6, 0 2px 0 #bfa13a;
  min-width: 180px;
  text-align: center;
  background-clip: unset;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  text-fill-color: unset;
}
.menu-btn:hover, .menu-btn:focus {
  background: #666;
  color: #ffe066;
  outline: none;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006;
  transform: translateY(-2px) scale(1.04);
}
@media (max-width: 700px) {
  #menu-logo {
    width: 80vw;
    max-width: 95vw;
  }
  .menu-btn {
    padding: 10px 0;
    font-size: 1.05em;
    min-width: 120px;
  }
  #menu-buttons {
    gap: 16px;
  }
}
/* --- END MENU OVERLAY STYLES --- */

/* --- Level Editor Styles --- * padding-top: 20px;  /* Add this line */
#level-editor-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #232323;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
}

/* Add this new section 
#editor-objects {
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 10px;
}*/

#editor-layout {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  height: 100vh;
}
#editor-grid-container {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
  margin-top: 30px; /* é iciiii */
}
#editor-grid-canvas {
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: #444;
  border-radius: 8px;
  box-shadow: 0 0 8px #0008;
}
.editor-object-icon {
  width: 56px;
  height: 56px;
  background: #333;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px #0004;
}
.editor-object-icon.selected {
  border: 2.5px solid #FFD700;
  box-shadow: 0 0 16px #FFD70088, 0 2px 8px #0004;
}
.editor-object-icon img, .editor-object-icon svg {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
}
/* éé cycling */
.editor-object-icon.selected-rotatable {
  border: 2.5px solid #ffffff;
  box-shadow: 0 0 16px #FFD70088, 0 2px 8px #0004;
}

/* é modifier hauteur des boutons editor */
#editor-buttons-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 18px; 
  margin-top: 20px; /* é ici à 0 des que plus d'objets */
  margin-bottom: 50px;
}
#editor-buttons-row button {
  font-family: 'Cinzel', serif;
  font-size: 1.1em;
  padding: 10px 28px;
  border-radius: 8px;
  border: 2px solid #FFD700;
  background: #232323;
  color: #FFD700;
  box-shadow: 0 2px 8px #0004;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
#editor-buttons-row button:hover {
  background: #FFD700;
  color: #232323;
  box-shadow: 0 0 16px #FFD70088, 0 2px 8px #0004;
}
#editor-message {
  margin-top: 18px;
  color: #FFD700;
  font-family: 'Cinzel', serif;
  font-size: 1.2em;
  text-align: center;
  background: #232323;
  border-radius: 8px;
  padding: 10px 24px;
  box-shadow: 0 2px 8px #0004;
}
/* é iciiii */
#editor-column-left, #editor-column-right {
  margin-top: 30px;
}

.level-room-offset {
  margin-top: 0px !important;
}

.level-room-raise {
  margin-top: 0px !important;
}

.level-title-lower {
  margin-top: +25px !important;
}

.level-controls-lower {
  margin-top: 15px !important;
}

#return-to-levels-btn {
  background: #444;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 1em;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px #0006;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a;
  min-width: 80px;
  text-align: center;
  margin-left: 12px;
}
#return-to-levels-btn:hover, #return-to-levels-btn:focus {
  background: #666;
  color: #ffe066;
  outline: none;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006;
  transform: translateY(-2px) scale(1.04);
}

#level-victory-modal {
  font-family: 'Cinzel Decorative', serif;
}
.level-victory-modal-box {
  background: #222;
  border-radius: 18px;
  box-shadow: 0 4px 32px #000a, 0 1.5px 0 #ffe066;
  padding: 36px 32px 28px 32px;
  min-width: 340px;
  max-width: 90vw;
  color: #ffe066;
  text-align: center;
  border: 2px solid #ffe066;
  position: relative;
}
.level-victory-modal-box .modal-title {
  font-size: 2.1em;
  font-weight: 700;
  color: #ffe066;
  margin-bottom: 18px;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px #000a;
}
.level-victory-modal-box .modal-label {
  font-size: 1.1em;
  color: #ffe066;
  margin-right: 8px;
}
.level-victory-modal-box .star {
  font-size: 2em;
  color: #fff;
  cursor: pointer;
  transition: color 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a;
}
.level-victory-modal-box .star:hover,
.level-victory-modal-box .star:focus {
  color: #ffe066;
  transform: scale(1.15);
}
.level-victory-modal-box .modal-username {
  margin: 18px 0 12px 0;
}
.level-victory-modal-box input[type="text"] {
  background: #333;
  color: #ffe066;
  border: 1.5px solid #ffe066;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 1em;
  font-family: inherit;
  margin-left: 6px;
  outline: none;
  transition: border 0.2s;
}
.level-victory-modal-box input[type="text"]:focus {
  border: 2px solid #ffe066;
  background: #222;
}
.level-victory-modal-box .modal-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  gap: 18px;
}
.level-victory-modal-box button {
  background: #444;
  color: #ffe066;
  border: none;
  border-radius: 8px;
  padding: 8px 22px;
  font-size: 1.1em;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px #0006;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  text-shadow: 0 1px 2px #000a;
}
.level-victory-modal-box button:hover, .level-victory-modal-box button:focus {
  background: #ffe066;
  color: #222;
  outline: none;
  box-shadow: 0 4px 16px #ffe06655, 0 2px 8px #0006;
  transform: translateY(-2px) scale(1.04);
}

#page-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20px;
  background: #222;
  z-index: 9999;
  width: 100vw;
  pointer-events: none;
}
