/* =========================================================
   DARK SLATE / GRAPHITE AESTHETIC (MATCHING SCREENSHOT)
   ========================================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --keyboard-offset: 18px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #121316;
  background-image:
    radial-gradient(circle at 50% 32%, #1e1f26 0%, #15161b 50%, #0d0e11 100%);
  color: #dedee4;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  outline: none;
}

.hidden {
  display: none !important;
}

/* =========================================================
   TOP NAV (CAM & MIC LEFT // RESET RIGHT)
   ========================================================= */
#top-nav {
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 40;
  pointer-events: none;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.top-tool-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(30, 31, 38, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #9d9da8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  outline: none;
}

.top-tool-btn svg {
  width: 16px;
  height: 16px;
}

.top-tool-btn:hover {
  background: rgba(45, 46, 56, 0.9);
  color: #f0f0f5;
  border-color: rgba(255, 255, 255, 0.22);
}

.top-tool-btn.active {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
  color: #ffffff;
}

/* =========================================================
   EXPANDABLE & ROTATABLE OPTICAL VIEWPORT
   ========================================================= */
#camera-frame {
  position: absolute;
  top: 66px;
  left: 18px;
  width: 155px;
  height: 110px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #1b1c22;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55);
  z-index: 45;
  transition: all 0.38s cubic-bezier(0.16, 1, 0.3, 1);
}

#camera-frame.expanded {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(88vw, 680px);
  height: min(65vh, 480px);
  border-radius: 20px;
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: 0 32px 70px rgba(0, 0, 0, 0.85);
  z-index: 55;
}

#camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translateZ(0);
  will-change: transform;
}

#camera-feed.mirrored {
  transform: scaleX(-1) translateZ(0);
}

#camera-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 2;
}

.cam-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(20, 21, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #dedee4;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  outline: none;
}

.cam-icon-btn svg {
  width: 15px;
  height: 15px;
}

.cam-icon-btn:hover {
  background: rgba(40, 42, 52, 0.95);
  border-color: rgba(255, 255, 255, 0.26);
}

/* =========================================================
   CENTER STAGE // AVATAR FOREGROUND & DIALOGUE BACKDROP
   ========================================================= */
#center-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: clamp(40px, 8vh, 72px);
  padding-bottom: 84px;
  gap: 12px;
  position: relative;
}

/* Monolith Stage sits on top (z-index: 20) so exiting cards hide BEHIND it */
#monolith-stage {
  position: relative;
  width: 275px;
  height: 235px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 20;
}

#ambient-fog {
  position: absolute;
  width: 310px;
  height: 310px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.06) 0%, rgba(50, 52, 64, 0.04) 50%, transparent 70%);
  filter: blur(38px);
  pointer-events: none;
  transform: scale(1);
  transition: transform 0.35s ease, background 0.4s ease;
  z-index: 0;
}

#monolith-stage.hearing #ambient-fog {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, rgba(85, 88, 105, 0.08) 50%, transparent 70%);
}

#monolith-stage.speaking #ambient-fog {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.22) 0%, rgba(120, 125, 145, 0.1) 50%, transparent 70%);
}

#acoustic-ring {
  position: absolute;
  width: 245px;
  height: 245px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.3s ease;
  z-index: 2;
}

#acoustic-ring.active {
  opacity: 0.75;
  animation: pulseAcoustic 1.6s infinite cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pulseAcoustic {
  0% { transform: scale(0.96); opacity: 0.75; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Avatar stays strictly locked without any translate sway */
#monolith-svg {
  position: relative;
  z-index: 3;
  width: 270px;
  height: 225px;
  overflow: visible;
  filter: drop-shadow(0 16px 36px rgba(0, 0, 0, 0.65));
  transform: none !important;
}

#gyro-orbit {
  transform-origin: 130px 110px;
  animation: gyroSpin 36s linear infinite;
}

@keyframes gyroSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#vocal-spectrogram {
  position: absolute;
  bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 22px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 4;
}

#vocal-spectrogram.speaking {
  opacity: 1;
}

.vocal-bar {
  width: 3px;
  height: 6px;
  border-radius: 2px;
  background: linear-gradient(to top, #484852, #b8b8c2, #ffffff);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.35);
  transition: height 0.06s ease;
}

/* =========================================================
   DIALOGUE STAGE DIRECTLY UNDER ROBOT
   z-index: 5 renders BEHIND the monolith-stage (z-index: 20)
   ========================================================= */
#dialogue-stage {
  position: relative;
  width: 90%;
  max-width: 520px;
  min-height: 110px;
  max-height: 195px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  pointer-events: auto;
  z-index: 5;
  overflow: visible;
}

.statement-card {
  border-radius: 13px;
  padding: 10px 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  will-change: opacity, transform, filter, margin-top;
  transition:
    transform 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    filter 0.9s ease,
    margin-top 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Smoothly glides upward behind the avatar chin while dissolving */
.statement-card.sliding-out {
  opacity: 0 !important;
  transform: translateY(-44px) scale(0.92) !important;
  filter: blur(3.5px) !important;
  margin-top: -65px !important;
  pointer-events: none;
}

.statement-card.entering {
  opacity: 0;
  transform: translateY(16px);
}

.statement-card.active {
  opacity: 1;
  transform: translateY(0);
}

.origin-label {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.statement-body {
  font-size: 14.5px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  max-height: 105px;
  overflow-y: auto;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
  padding-right: 4px;
}

.statement-body::-webkit-scrollbar {
  width: 3.5px;
}
.statement-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}

.statement-card.user-role {
  align-self: flex-end;
  background: rgba(40, 41, 48, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f2f2f6;
  max-width: 86%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.statement-card.user-role .origin-label {
  color: #9d9da8;
}

.statement-card.ai-role {
  align-self: flex-start;
  background: rgba(26, 27, 32, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #dedee4;
  max-width: 92%;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}

.statement-card.ai-role .origin-label {
  color: #787882;
}

/* =========================================================
   BOTTOM INPUT DOCK (CLEAN PILL WITH SEND BUTTON ONLY)
   ========================================================= */
#input-dock {
  position: absolute;
  bottom: var(--keyboard-offset, 18px);
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 520px;
  z-index: 30;
  transition: bottom 0.12s ease-out;
}

#chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(28, 29, 36, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9999px;
  padding: 6px 8px 6px 18px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14.5px;
  color: #f2f2f6;
  font-family: inherit;
  caret-color: #ffffff;
}

#chat-input::placeholder {
  color: #6a6a75;
}

#btn-send-text {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

#btn-send-text svg {
  width: 14px;
  height: 14px;
}

#btn-send-text:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.32);
}

@media (max-width: 600px) {
  #camera-frame {
    width: 125px;
    height: 90px;
    top: 62px;
    left: 16px;
  }

  #monolith-stage {
    width: 245px;
    height: 205px;
  }

  #monolith-svg {
    width: 235px;
    height: 195px;
  }
}
