*, 
*::before, 
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, 
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000000;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#background-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 15vh;
}

#mission-bg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  opacity: 0;
  transition: opacity 15s ease-in-out;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

#mission-bg.fade-visible {
  opacity: 0.25;
}

#title-wrapper {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  opacity: 0;
  transform-origin: top left;
  transition: opacity 1s ease-in-out 0.5s, transform 3s ease-in-out, top 3s ease-in-out, left 3s ease-in-out;
  pointer-events: none;
  width: max-content;
}

#title-wrapper.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#title-wrapper.docked {
  top: 40px;
  left: 40px;
  transform: translate(0, 0) scale(0.3);
  opacity: 0.3;
  transition: opacity 1s ease-in-out 0.5s, transform 4s cubic-bezier(0.4, 0, 0.2, 1), top 4s cubic-bezier(0.4, 0, 0.2, 1), left 4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.user-idle #title-wrapper.docked {
  opacity: 0.05;
  transition: opacity 2s ease-in-out;
}

#mission-title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(1.2rem, 4.8vw, 3.2rem);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 
    0 0 20px rgba(255, 100, 100, 0.8),
    0 0 40px rgba(255, 50, 50, 0.6),
    0 0 60px rgba(255, 0, 0, 0.4),
    0 4px 8px rgba(0, 0, 0, 0.8);
  margin: 0;
  text-align: center;
}

#mission-subtitle {
  font-family: 'Audiowide', cursive;
  font-size: clamp(0.9rem, 2.5vw, 1.8rem);
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.4em;
  margin-top: 0.2em;
  text-shadow: 
    0 0 10px rgba(0, 200, 255, 0.8),
    0 0 20px rgba(0, 100, 200, 0.5);
  opacity: 0;
  transition: opacity 1s ease-in-out;
}

#title-wrapper.show #mission-subtitle {
  opacity: 1;
  transition-delay: 1s;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  display: block;
  z-index: 5;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  position: absolute;
  top: -100px;
  left: 0;
}

/* Controls Container */
#controls {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  display: flex;
  gap: 40px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease-out;
}

#controls.visible {
  opacity: 1;
  pointer-events: auto;
}

/* For initial load slow fade-in */
#controls.slow-fade {
  transition: opacity 3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Idle State - Dim Controls */
body.user-idle #controls.visible {
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.5s ease-in-out;
}

/* Idle State - Hide Cursor */
body.user-idle {
  cursor: none;
}

/* Start/Stop and Reset buttons */
#startStopBtn, #resetBtn, #rotateBtn, #vidBtn {
  width: 60px; 
  height: 60px;
  padding: 0; 
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 50%; 
  border: none;
  /* Inner glowing orb look */
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 1) 0%, rgba(200, 220, 255, 1) 40%, rgba(150, 180, 255, 1) 100%);
  color: #001a33;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  user-select: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 0 15px rgba(255, 255, 255, 0.5),
    inset 0 -2px 5px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: visible;
  font-family: 'Orbitron', sans-serif;
}

/* The Loop/Ring around the button */
#startStopBtn::after, #resetBtn::after, #rotateBtn::after, #vidBtn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
  pointer-events: none;
  transition: all 0.4s ease;
}

#startStopBtn:hover, #resetBtn:hover, #rotateBtn:hover, #vidBtn:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 0 25px rgba(255, 255, 255, 0.8),
    inset 0 -2px 5px rgba(0, 0, 0, 0.1);
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 1) 0%, rgba(220, 240, 255, 1) 50%, rgba(180, 210, 255, 1) 100%);
}

#startStopBtn:hover::after, #resetBtn:hover::after, #rotateBtn:hover::after, #vidBtn:hover::after {
  width: 94px;
  height: 94px;
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
}

#startStopBtn:active, #resetBtn:active, #rotateBtn:active, #vidBtn:active {
  transform: translateY(1px) scale(0.95);
}

/* Mobile: scale controls down ~30% */
@media (max-width: 600px) {
  #startStopBtn, #resetBtn, #rotateBtn, #vidBtn {
    width: 42px;
    height: 42px;
    font-size: 9px;
  }

  #startStopBtn::after, #resetBtn::after, #rotateBtn::after, #vidBtn::after {
    width: 60px;
    height: 60px;
  }

  #startStopBtn:hover::after, #resetBtn:hover::after, #rotateBtn:hover::after, #vidBtn:hover::after {
    width: 66px;
    height: 66px;
  }

  #controls {
    gap: 24px;
    bottom: 30px;
  }

  /* Hide mini animation (indicators) entirely on mobile */
  #indicators {
    display: none !important;
  }
}

/* Timer Indicators */
#indicators {
  position: absolute;
  bottom: 30px;
  right: 30px;
  display: flex;
  gap: 12px;
  z-index: 20;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(15, 20, 30, 0.6), rgba(5, 8, 15, 0.8));
  border-radius: 24px;
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 
    0 4px 20px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transform-origin: bottom right;
  transition: opacity 0.4s ease-out;
}

#indicators.visible {
  opacity: 1;
  pointer-events: auto;
}

.indicator-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.25);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 
    0 0 6px rgba(255, 255, 255, 0.4),
    inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.indicator-dot.active {
  background: radial-gradient(circle, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.95) 100%);
  border-color: rgba(255, 255, 255, 1);
  box-shadow: 
    0 0 7px rgba(255, 255, 255, 0.4), 
    0 0 15px rgba(255, 255, 255, 0.25),
    inset 0 0 3px rgba(255, 255, 255, 0.4);
}

/* Surge Animations for synchronized hoop movement */
@keyframes surgeContainerPulse1 {
  0% { border-color: rgba(255,255,255,0.3); }
  15% { border-color: #00ffff; box-shadow: 0 0 10px rgba(0, 255, 255, 0.4); background: rgba(0, 50, 100, 0.6); }
  100% { border-color: rgba(255,255,255,0.3); }
}

@keyframes surgeContainerPulse2 {
  0% { border-color: rgba(255,255,255,0.3); }
  10% { border-color: #ff0055; box-shadow: 0 0 20px rgba(255, 0, 85, 0.5); background: rgba(100, 0, 20, 0.6); }
  20% { border-color: #ff0055; }
  30% { border-color: #ff0055; }
  100% { border-color: rgba(255,255,255,0.3); }
}

@keyframes surgeDotFlash1 {
  0% { background: rgba(255, 255, 255, 0.9); }
  20% { background: #00ffff; box-shadow: 0 0 8px #00ffff; }
  100% { background: rgba(255, 255, 255, 0.9); }
}

@keyframes surgeDotFlash2 {
  0% { background: rgba(255, 255, 255, 0.9); }
  10% { background: #ff0055; box-shadow: 0 0 12px #ff0055; }
  100% { background: rgba(255, 255, 255, 0.9); }
}

#indicators.surge-1 {
  animation: surgeContainerPulse1 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#indicators.surge-2 {
  animation: surgeContainerPulse2 1.0s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Target only the specific dots that changed */
.indicator-dot.surge-active-1 {
  animation: surgeDotFlash1 0.8s ease-out;
}

.indicator-dot.surge-active-2 {
  animation: surgeDotFlash2 1.0s ease-out;
}

@media (min-width: 600px) {
  #indicators {
    bottom: 40px;
    right: 40px;
    gap: 16px;
  }
  
  .indicator-dot {
    width: 24px;
    height: 24px;
    border-width: 2px;
  }
}

/* Video Modal */
#video-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 2s ease-in-out;
}

#video-modal.show {
  opacity: 1;
  pointer-events: auto;
}

#mission-video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 1);
  outline: none;
  background: #000;
}

#close-video-btn {
  position: absolute;
  top: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 10000;
}

#close-video-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

@media (max-width: 600px) {
  #mission-video {
    max-width: 100vw;
    border-radius: 0;
  }
  #close-video-btn {
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}