/* Tumbling ? Cube Button - Neobrutalist Style */

/* Container - Fixed positioning */
.cube-button-container {
  position: fixed;
  bottom: 5rem;
  right: 3rem;
  z-index: 9996; /* Below modals (9998+), above content */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  transform: scale(0);
}

.cube-button-container.visible {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
  animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Main Cube Button - 3D Container */
.cube-button {
  width: 70px;
  height: 70px;
  position: relative;
  cursor: pointer;
  perspective: 600px; /* 3D perspective */
  transition: transform 0.2s ease;
}

.cube-button:active {
  transform: scale(0.95);
}

/* Cube Inner Wrapper - This rotates */
.cube-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: tumble 8s linear infinite;
  transition: transform 0.3s ease;
}

.cube-button:hover .cube-inner {
  animation-play-state: paused; /* Pause tumbling on hover for clarity */
}

/* Cube Faces - 6 sides with question marks */
.cube-face {
  position: absolute;
  width: 70px;
  height: 70px;
  background: #FFD700;
  border: 5px solid #000;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 2.5rem;
  color: #000;
  user-select: none;
  line-height: 1;
  backface-visibility: visible;
  box-sizing: border-box;
}

/* Position each face in 3D space */
.cube-face.front  {
  transform: translateZ(35px);
}

.cube-face.back   {
  transform: translateZ(-35px) rotateY(180deg);
}

.cube-face.left   {
  transform: translateX(-35px) rotateY(-90deg);
}

.cube-face.right  {
  transform: translateX(35px) rotateY(90deg);
}

.cube-face.top    {
  transform: translateY(-35px) rotateX(90deg);
}

.cube-face.bottom {
  transform: translateY(35px) rotateX(-90deg);
}

/* Tumbling Animation - Rotate on both X and Y axes */
@keyframes tumble {
  0% {
    transform: rotateX(0deg) rotateY(0deg);
  }
  100% {
    transform: rotateX(360deg) rotateY(360deg);
  }
}

@keyframes bounceIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* Expanded Menu */
.cube-expanded-menu {
  position: absolute;
  bottom: 80px; /* Above the cube button */
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.8);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cube-expanded-menu.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* Menu Buttons */
.cube-menu-btn {
  width: 70px;
  height: 70px;
  background: #FFF;
  border: 4px solid #000;
  box-shadow: 5px 5px 0 0 #000;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-family: 'Press Start 2P', cursive;
  padding: 0.5rem;
}

.cube-menu-btn span:first-child {
  font-size: 1.5rem;
  line-height: 1;
}

.cube-menu-label {
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #000;
}

.cube-menu-btn:hover {
  transform: translate(-3px, -3px);
  box-shadow: 8px 8px 0 0 #000;
}

.cube-menu-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 0 #000;
}

/* Back to Top Button - Green theme */
#cubeBackToTop {
  background: #00FF00;
}

#cubeBackToTop:hover {
  background: #33FF33;
}

/* Create Button - Blue theme */
#cubeOpenModal {
  background: #00D4FF;
}

#cubeOpenModal:hover {
  background: #33DDFF;
}

/* Demos Button - Purple theme */
#cubeDemos {
  background: #9D4EDD;
}

#cubeDemos:hover {
  background: #B565F2;
}

/* Cube Button Expanded State - Stop tumbling */
.cube-button-container.expanded .cube-inner {
  animation-play-state: paused;
}

.cube-button-container.expanded .cube-face {
  background: #FFF;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .cube-button-container {
    bottom: 3rem;
    right: 3rem;
  }

  .cube-button {
    width: 60px;
    height: 60px;
  }

  .cube-inner {
    width: 60px;
    height: 60px;
  }

  .cube-face {
    width: 60px;
    height: 60px;
    font-size: 2rem;
  }

  /* Update 3D positioning for smaller cube */
  .cube-face.front  { transform: translateZ(30px); }
  .cube-face.back   { transform: translateZ(-30px) rotateY(180deg); }
  .cube-face.left   { transform: translateX(-30px) rotateY(-90deg); }
  .cube-face.right  { transform: translateX(30px) rotateY(90deg); }
  .cube-face.top    { transform: translateY(-30px) rotateX(90deg); }
  .cube-face.bottom { transform: translateY(30px) rotateX(-90deg); }

  .cube-menu-btn {
    width: 60px;
    height: 60px;
  }

  .cube-menu-btn span:first-child {
    font-size: 1.2rem;
  }

  .cube-menu-label {
    font-size: 0.45rem;
  }

  .cube-expanded-menu {
    bottom: 70px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .cube-button-container {
    bottom: 3rem;
    right: 2rem;
  }

  .cube-button {
    width: 55px;
    height: 55px;
  }

  .cube-inner {
    width: 55px;
    height: 55px;
  }

  .cube-face {
    width: 55px;
    height: 55px;
    font-size: 1.8rem;
  }

  /* Update 3D positioning for extra small cube */
  .cube-face.front  { transform: translateZ(27.5px); }
  .cube-face.back   { transform: translateZ(-27.5px) rotateY(180deg); }
  .cube-face.left   { transform: translateX(-27.5px) rotateY(-90deg); }
  .cube-face.right  { transform: translateX(27.5px) rotateY(90deg); }
  .cube-face.top    { transform: translateY(-27.5px) rotateX(90deg); }
  .cube-face.bottom { transform: translateY(27.5px) rotateX(-90deg); }

  .cube-menu-btn {
    width: 55px;
    height: 55px;
  }

  .cube-menu-btn span:first-child {
    font-size: 1rem;
  }

  .cube-menu-label {
    font-size: 0.4rem;
  }

  .cube-expanded-menu {
    bottom: 65px;
  }
}

/* Accessibility - Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .cube-button {
    animation: none;
  }

  .cube-button-container,
  .cube-expanded-menu {
    transition: opacity 0.3s ease;
    animation: none;
  }
}
