/* Stress Out, Bunny In — Styles */

:root {
  --sky-top: #c9dbb2;
  --sky-bottom: #e8f0df;
  --grass-dark: #5a8a5a;
  --grass-mid: #7ab87a;
  --grass-light: #9dd19d;
  --text-soft: #4a6a4a;
  --overlay-bg: rgba(232, 240, 223, 0.85);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
}

body {
  font-family: 'Cormorant Garamond', Georgia, serif;
}

#scene {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Hidden camera video */
#camera {
  position: fixed;
  top: 0;
  right: 0;
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transform: scaleX(-1);
  z-index: 15;
  transition: opacity 0.3s ease;
}

#camera.visible {
  opacity: 0.7;
  pointer-events: auto;
}

/* Control buttons container */
.controls {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  display: flex;
  gap: 2rem;
  z-index: 20;
  flex-wrap: nowrap;
}

.control-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.control-btn {
  width: 4.5rem;
  height: 4.5rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.control-btn:hover,
.control-btn:focus {
  background: rgba(255, 255, 255, 0.7);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  outline: none;
}

.control-btn:active {
  transform: translateY(0);
}

.control-btn svg {
  width: 2.25rem;
  height: 2.25rem;
  stroke-width: 1.5;
}

/* Camera button active state */
#camera-btn.active {
  background: rgba(122, 184, 122, 0.6);
  color: var(--grass-dark);
}

#camera-btn .camera-status {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.3s ease;
  pointer-events: none;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

#camera-btn.active .camera-status {
  background: #6abe6a;
  box-shadow: 0 0 8px rgba(106, 190, 106, 0.8);
}

/* Theme button states */
#theme-btn.theme-night {
  background: rgba(45, 55, 85, 0.7);
  color: #e8e0d4;
}

#theme-btn.theme-wetlands {
  background: rgba(75, 130, 130, 0.7);
  color: #e8f5f5;
}

/* Audio button states */
#audio-btn .audio-icon-off {
  display: none;
}

#audio-btn.muted .audio-icon-on {
  display: none;
}

#audio-btn.muted .audio-icon-off {
  display: block;
}

#audio-btn.playing {
  background: rgba(122, 184, 122, 0.7);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(122, 184, 122, 0.4);
}

#audio-btn.playing::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(122, 184, 122, 0.6);
  animation: audioWave 2s ease-out infinite;
  pointer-events: none;
}

/* Audio status indicator (like camera) */
#audio-btn::before {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.6);
  transition: all 0.3s ease;
}

#audio-btn.playing::before {
  background: #6abe6a;
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 8px rgba(106, 190, 106, 0.8);
}

@keyframes audioWave {
  0% {
    width: 100%;
    height: 100%;
    opacity: 0.6;
  }
  100% {
    width: 140%;
    height: 140%;
    opacity: 0;
  }
}

/* Auto-loop button states */
#autoloop-btn.active {
  background: rgba(255, 200, 100, 0.6);
  animation: loopPulse 2s ease-in-out infinite;
}

#autoloop-btn .loop-timer {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 6px;
  border-radius: 8px;
  min-width: 20px;
  text-align: center;
  display: none;
}

#autoloop-btn.active .loop-timer {
  display: block;
}

@keyframes loopPulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(255, 200, 100, 0.7);
  }
  50% {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(255, 200, 100, 0);
  }
}

/* Control labels */
.control-label {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1rem;
  font-weight: 400;
  color: #ffffff;
  text-align: center;
  white-space: nowrap;
  text-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.8),
    0 2px 6px rgba(0, 0, 0, 0.6),
    0 0 10px rgba(0, 0, 0, 0.4);
  background: rgba(0, 0, 0, 0.3);
  padding: 0.35rem 0.75rem;
  border-radius: 1rem;
  backdrop-filter: blur(4px);
}

/* Hand tracking instructions */
.hand-instructions {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 2rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  color: var(--text-soft);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 300;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 15;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.hand-instructions.visible {
  opacity: 1;
}

.hand-instructions .hand-icon {
  width: 2.5rem;
  height: 2.5rem;
  stroke: var(--grass-mid);
  stroke-width: 1.5;
  animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

/* Camera video positioning moved to separate @supports block below */

/* Overlay — fades out after a few seconds */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
  background: var(--overlay-bg);
  opacity: 1;
  transition: opacity 2s ease-out;
  z-index: 10;
}

.overlay.hidden {
  opacity: 0;
}

.overlay-logo {
  width: clamp(120px, 30vw, 200px);
  height: auto;
  margin-bottom: 1.5rem;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
  animation: logoFadeIn 1s ease-out;
}

@keyframes logoFadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overlay h1 {
  font-size: clamp(1.8rem, 6vw, 3rem);
  font-weight: 300;
  color: var(--text-soft);
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.overlay p {
  font-size: clamp(1rem, 3vw, 1.3rem);
  font-weight: 300;
  font-style: italic;
  color: var(--text-soft);
  opacity: 0.8;
  max-width: 24ch;
  line-height: 1.5;
}

/* Reset button — tiny, tucked away */
/* Reset button styles merged with control-btn above */

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .controls {
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
    left: calc(1.5rem + env(safe-area-inset-left));
    right: calc(1.5rem + env(safe-area-inset-right));
  }
  
  #camera {
    top: calc(0.5rem + env(safe-area-inset-top));
    right: calc(0.5rem + env(safe-area-inset-right));
  }
  
  @media (max-width: 768px) {
    .controls {
      bottom: calc(0.75rem + env(safe-area-inset-bottom));
      left: calc(0.75rem + env(safe-area-inset-left));
      right: calc(0.75rem + env(safe-area-inset-right));
    }
  }
  
  @media (max-width: 480px) {
    .controls {
      bottom: calc(0.5rem + env(safe-area-inset-bottom));
      left: calc(0.5rem + env(safe-area-inset-left));
      right: calc(0.5rem + env(safe-area-inset-right));
    }
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .overlay {
    transition: opacity 0.5s ease-out;
  }
  
  .control-btn {
    transition: opacity 0.1s ease;
  }
  
  .hand-instructions .hand-icon {
    animation: none;
  }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .controls {
    bottom: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .control-item {
    gap: 0.35rem;
  }
  
  .control-btn {
    width: 3.25rem;
    height: 3.25rem;
  }
  
  .control-btn svg {
    width: 1.5rem;
    height: 1.5rem;
  }
  
  .control-label {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
  
  .hand-instructions {
    padding: 1rem 1.25rem;
    font-size: 0.95rem;
    max-width: 85%;
  }
  
  .hand-instructions .hand-icon {
    width: 1.75rem;
    height: 1.75rem;
  }
}

@media (max-width: 480px) {
  .controls {
    bottom: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    gap: 0.5rem;
  }
  
  .control-btn {
    width: 3rem;
    height: 3rem;
  }
  
  .control-btn svg {
    width: 1.4rem;
    height: 1.4rem;
  }
  
  .control-label {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }
  
  /* Smaller status indicators on mobile */
  #camera-btn .camera-status,
  #audio-btn::before {
    width: 8px;
    height: 8px;
    top: 6px;
    right: 6px;
  }
  
  #autoloop-btn .loop-timer {
    font-size: 0.65rem;
    padding: 1px 4px;
    bottom: 6px;
    right: 6px;
  }
}

/* Extra small phones (iPhone SE, etc.) */
@media (max-width: 375px) {
  .controls {
    gap: 0.4rem;
  }
  
  .control-btn {
    width: 2.75rem;
    height: 2.75rem;
  }
  
  .control-btn svg {
    width: 1.25rem;
    height: 1.25rem;
  }
  
  .control-label {
    font-size: 0.65rem;
  }
}

/* =============================================================================
   NATIVE BUNNY CHAT - Speech bubbles above bunny
   ============================================================================= */

/* Speech bubble that appears above bunny */
.bunny-speech-bubble {
  position: fixed;
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, -180px);
  max-width: 400px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 15;
  animation: speechFloat 3s ease-in-out infinite;
}

.bunny-speech-bubble.visible {
  opacity: 1;
}

@keyframes speechFloat {
  0%, 100% { transform: translate(-50%, -180px); }
  50% { transform: translate(-50%, -190px); }
}

.speech-bubble-content {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
  backdrop-filter: blur(10px);
  padding: 1.25rem 1.5rem;
  border-radius: 1.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(122, 184, 122, 0.3);
  position: relative;
}

.speech-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--text-soft);
  margin: 0;
  word-wrap: break-word;
}

.speech-bubble-tail {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid rgba(255, 255, 255, 0.98);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Typing indicator (appears above bunny) */
.bunny-typing {
  position: fixed;
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, -180px);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 0.75rem 1.25rem;
  border-radius: 2rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 15;
}

.bunny-typing.visible {
  opacity: 1;
}

/* Chat indicator (shows bunny is tappable) */
.chat-indicator {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  width: 4rem;
  height: 4rem;
  background: linear-gradient(135deg, var(--grass-mid), var(--grass-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(122, 184, 122, 0.4);
  transition: all 0.3s ease;
  z-index: 26;
  animation: chatPulse 2s ease-in-out infinite;
}

.chat-indicator:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(122, 184, 122, 0.5);
}

.chat-indicator.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

.chat-indicator svg {
  width: 2rem;
  height: 2rem;
}

@keyframes chatPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(122, 184, 122, 0.4), 0 0 0 0 rgba(122, 184, 122, 0.7);
  }
  50% {
    box-shadow: 0 4px 16px rgba(122, 184, 122, 0.4), 0 0 0 12px rgba(122, 184, 122, 0);
  }
}

.typing-dots {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.typing-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--grass-mid);
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Voice control panel (appears at top) */
.voice-panel {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1.25rem 2rem;
  border-radius: 4rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 25;
}

.voice-panel.visible {
  transform: translateX(-50%) translateY(0);
}

.voice-btn {
  padding: 1rem 2rem;
  background: linear-gradient(135deg, var(--grass-mid), var(--grass-dark));
  color: white;
  border: none;
  border-radius: 3rem;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(122, 184, 122, 0.3);
  white-space: nowrap;
}

.voice-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(122, 184, 122, 0.4);
}

.voice-btn:active {
  transform: translateY(0);
}

.voice-btn.recording {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  animation: recordPulse 1.5s ease-in-out infinite;
}

@keyframes recordPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(231, 76, 60, 0.3), 0 0 0 0 rgba(231, 76, 60, 0.7);
  }
  50% {
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4), 0 0 0 16px rgba(231, 76, 60, 0);
  }
}

.voice-btn .mic-icon {
  width: 1.75rem;
  height: 1.75rem;
}

.voice-btn .voice-label {
  font-size: 1rem;
}

/* Voice mode toggle (small button next to voice button) */
.voice-mode-toggle-small {
  background: rgba(122, 184, 122, 0.15);
  border: 2px solid rgba(122, 184, 122, 0.3);
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--grass-dark);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.voice-mode-toggle-small:hover {
  background: rgba(122, 184, 122, 0.25);
  transform: scale(1.05);
}

.voice-mode-toggle-small.active {
  background: var(--grass-mid);
  border-color: var(--grass-mid);
  color: white;
}

.voice-mode-toggle-small svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Mobile native chat adjustments */
@media (max-width: 768px) {
  .bunny-speech-bubble {
    max-width: calc(100vw - 4rem);
    bottom: 55%;
  }
  
  .speech-bubble-content {
    padding: 1rem 1.25rem;
  }
  
  .speech-text {
    font-size: 1rem;
  }
  
  .voice-panel {
    top: 1rem;
    padding: 1rem 1.5rem;
    gap: 0.75rem;
    max-width: calc(100vw - 2rem);
  }
  
  .voice-btn {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
  }
  
  .voice-btn .mic-icon {
    width: 1.5rem;
    height: 1.5rem;
  }
  
  .voice-mode-toggle-small {
    width: 2.75rem;
    height: 2.75rem;
  }
  
  .voice-mode-toggle-small svg {
    width: 1.1rem;
    height: 1.1rem;
  }
}

@media (max-width: 480px) {
  .bunny-speech-bubble {
    max-width: calc(100vw - 3rem);
  }
  
  .speech-bubble-content {
    padding: 0.875rem 1rem;
  }
  
  .speech-text {
    font-size: 0.95rem;
  }
  
  .voice-panel {
    top: 0.75rem;
    padding: 0.875rem 1.25rem;
  }
  
  .voice-btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
  }
  
  .voice-btn .voice-label {
    font-size: 0.9rem;
  }
}

@supports (padding: env(safe-area-inset-top)) {
  .voice-panel {
    top: calc(1.5rem + env(safe-area-inset-top));
  }
  
  .chat-indicator {
    top: calc(1.5rem + env(safe-area-inset-top));
    left: calc(1.5rem + env(safe-area-inset-left));
  }
  
  @media (max-width: 768px) {
    .voice-panel {
      top: calc(1rem + env(safe-area-inset-top));
    }
    
    .chat-indicator {
      top: calc(1rem + env(safe-area-inset-top));
      left: calc(1rem + env(safe-area-inset-left));
      width: 3.5rem;
      height: 3.5rem;
    }
    
    .chat-indicator svg {
      width: 1.75rem;
      height: 1.75rem;
    }
  }
  
  @media (max-width: 480px) {
    .voice-panel {
      top: calc(0.75rem + env(safe-area-inset-top));
    }
    
    .chat-indicator {
      top: calc(0.75rem + env(safe-area-inset-top));
      left: calc(0.75rem + env(safe-area-inset-left));
      width: 3.25rem;
      height: 3.25rem;
    }
    
    .chat-indicator svg {
      width: 1.5rem;
      height: 1.5rem;
    }
  }
}
