/**
 * Character System Styles
 * UI elements, overlays, and responsive design
 */

/* ============================================
   CANVAS CONTAINER
   ============================================ */
#character-canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 1;
  transition: opacity 1s ease-out;
}

#character-canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ============================================
   SPEECH BUBBLE
   ============================================ */
#character-speech-bubble {
  position: fixed;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  color: white;
  padding: 12px 18px;
  border-radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: 220px;
  white-space: nowrap;
}

#character-speech-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

#character-speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid rgba(0, 0, 0, 0.85);
}

/* Speech bubble text */
#character-speech-bubble .greeting {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

#character-speech-bubble .instruction {
  display: block;
  font-size: 13px;
  opacity: 0.9;
}

/* ============================================
   ROPE ELEMENT (for climbing)
   ============================================ */
.character-rope {
  position: fixed;
  width: 3px;
  background: linear-gradient(
    to bottom,
    rgba(139, 69, 19, 0.9),
    rgba(160, 82, 45, 0.8),
    rgba(139, 69, 19, 0.9)
  );
  box-shadow: 0 0 8px rgba(139, 69, 19, 0.5);
  transform-origin: top center;
  pointer-events: none;
  z-index: 9998;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.character-rope::before,
.character-rope::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  background: rgba(139, 69, 19, 0.6);
  border-radius: 50%;
}

.character-rope::before {
  top: 0;
}

.character-rope::after {
  bottom: 0;
}

/* Rope texture pattern */
.character-rope {
  background-image: repeating-linear-gradient(
    0deg,
    rgba(139, 69, 19, 0.9) 0px,
    rgba(160, 82, 45, 0.8) 2px,
    rgba(139, 69, 19, 0.9) 4px
  );
}

/* ============================================
   DIZZY STARS (CSS fallback if needed)
   ============================================ */
.character-dizzy-stars {
  position: absolute;
  width: 100px;
  height: 100px;
  pointer-events: none;
  z-index: 10001;
  animation: dizzy-rotate 1.5s linear;
}

@keyframes dizzy-rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(1440deg);
  }
}

/* ============================================
   LOADING STATE
   ============================================ */
.character-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  z-index: 10000;
  opacity: 0;
  animation: fade-in 0.3s ease forwards;
}

@keyframes fade-in {
  to {
    opacity: 1;
  }
}

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

/* Disable on mobile and tablets */
@media (max-width: 1279px) {
  #character-canvas-container,
  #character-speech-bubble,
  .character-rope {
    display: none !important;
  }
}

/* Optimize for smaller laptops */
@media (min-width: 1280px) and (max-width: 1440px) {
  #character-canvas-container canvas {
    /* Reduce render scale on smaller screens for performance */
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  #character-canvas-container,
  #character-speech-bubble,
  .character-rope {
    display: none !important;
  }
  
  .character-dizzy-stars {
    animation: none;
  }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
  #character-speech-bubble {
    background: black;
    border: 2px solid white;
  }
  
  .character-rope {
    background: white;
    box-shadow: 0 0 8px white;
  }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* GPU acceleration hints */
#character-canvas-container,
#character-speech-bubble,
.character-rope {
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Prevent layout shifts */
#character-canvas-container {
  contain: layout style paint;
}

/* ============================================
   WEBKIT SPECIFIC FIXES
   ============================================ */
@supports (-webkit-backdrop-filter: blur(10px)) {
  #character-speech-bubble {
    -webkit-backdrop-filter: blur(10px);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  #character-canvas-container,
  #character-speech-bubble,
  .character-rope {
    display: none !important;
  }
}
