/* Red Globe Room overlay (2D + VR DOM chrome) */

#rg-room-overlay {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 2800;
  pointer-events: none;
  padding: 0;
  font-family: inherit;
  color: #fce7f3;
}

#rg-room-overlay.open {
  display: block;
}

/* ── Presence stage: training-room Scarlett (bed, breathing) ── */
.rg-presence-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #050308;
  overflow: hidden;
}

.rg-presence-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
}

.rg-presence-vignette {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.rg-presence-live {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(248, 113, 113, 0.45);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fecaca;
}

.rg-presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  animation: rg-presence-blink 1.2s ease-in-out infinite;
}

@keyframes rg-presence-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.rg-presence-caption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(118px + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: rgba(253, 242, 248, 0.92);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9);
}

/* Presence mode (flat only): hide globe under DOM stage.
   In VR/AR keep the canvas visible so the 3D Scarlett mesh is not a ghost. */
body.rg-presence-mode.rg-room-open:not(.in-vr):not(.in-ar) #globe-canvas,
body.rg-presence-mode.rg-room-open:not(.in-vr):not(.in-ar) canvas#c {
  opacity: 0 !important;
  pointer-events: none !important;
}

body.in-vr #rg-room-overlay,
body.in-ar #rg-room-overlay {
  /* Keep compact chrome available; age gate already handles VR DOM */
  opacity: 0.95;
}

/* Companion mode: Scarlett in passthrough living room — hide heavy chrome noise */
body.rg-companion-mode #rg-room-overlay .rg-room-streams {
  max-height: 40px;
}
body.rg-companion-mode #rg-room-overlay .rg-room-chat {
  max-height: 72px;
}
.rg-room-anims,
.rg-room-pose {
  margin-top: 6px;
}

.rg-room-anims .rg-room-btn.rg-anim-active {
  background: rgba(236, 72, 153, 0.45);
  border-color: rgba(251, 207, 232, 0.75);
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.35);
}
.rg-room-hint {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.35;
  opacity: 0.75;
  color: #fbcfe8;
}

.rg-room-voice {
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.rg-room-btn.rg-voice-on {
  background: rgba(34, 197, 94, 0.35);
  border-color: rgba(134, 239, 172, 0.75);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.4);
  animation: rg-voice-pulse 1.4s ease-in-out infinite;
}

@keyframes rg-voice-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(34, 197, 94, 0.3); }
  50% { box-shadow: 0 0 16px rgba(34, 197, 94, 0.55); }
}

.rg-room-voice-heard {
  font-size: 11px;
  opacity: 0.85;
  color: #bbf7d0;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rg-room-btn-exit {
  background: rgba(236, 72, 153, 0.35) !important;
  border-color: rgba(251, 207, 232, 0.55) !important;
  font-weight: 800 !important;
}

/* Companion: minimal chrome — focus on Leave + pose, not stream clutter */
body.rg-companion-mode #rg-room-overlay .rg-room-streams,
body.rg-companion-mode #rg-room-overlay .rg-room-chat,
body.rg-companion-mode #rg-room-overlay .rg-room-compose {
  display: none !important;
}
body.rg-companion-mode #rg-room-overlay .rg-room-chrome {
  max-width: 360px;
  padding: 8px 10px 10px;
}

/* ── Chrome shell (collapsible chat dock) ─────────────────────────── */
.rg-room-chrome {
  pointer-events: auto;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 0 calc(10px + env(safe-area-inset-bottom, 0px));
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(236, 72, 153, 0.35);
  border-bottom: 0;
  background: rgba(12, 6, 14, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  transition: max-height 0.28s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

/* Talk bar: Exit · Mic · input · Send (studio practice style) */
.rg-presence-talkbar {
  display: flex !important;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 10px !important;
  flex-wrap: nowrap !important;
}

.rg-presence-input {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 11px 12px;
  font-size: 16px;
  font-family: inherit;
}

.rg-btn-mic {
  min-width: 46px !important;
  font-size: 18px !important;
  padding: 8px 10px !important;
}

.rg-btn-mic.rg-mic-on {
  background: rgba(239, 68, 68, 0.5) !important;
  border-color: rgba(252, 165, 165, 0.75) !important;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.45);
}

.rg-room-btn-send {
  background: linear-gradient(135deg, #ec4899, #be185d) !important;
  border-color: transparent !important;
  font-weight: 800 !important;
}

/* Pull-tab / arrow handle */
.rg-room-dock-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 10px 12px 6px;
  border: 0;
  background: transparent;
  color: #f9a8d4;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.rg-room-dock-toggle:active {
  opacity: 0.85;
}

.rg-room-dock-grip {
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(251, 207, 232, 0.45);
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
}

.rg-room-dock-toggle {
  position: relative;
  padding-top: 16px;
}

.rg-room-dock-arrow {
  font-size: 14px;
  line-height: 1;
  color: #fbcfe8;
}

.rg-room-dock-label {
  opacity: 0.9;
}

/* Always-visible compact controls (Exit / Voice / Talk) */
.rg-room-dock-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 12px 8px;
}

.rg-room-title-dock {
  font-size: 13px;
  margin-right: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.rg-room-btn-expand {
  min-width: 40px;
  padding-left: 10px;
  padding-right: 10px;
  font-size: 14px;
}

.rg-room-status-mini {
  display: none;
  padding: 0 12px 8px;
  font-size: 11px;
  color: #f9a8d4;
  min-height: 0;
  max-height: 2.6em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Full chat + actions panel */
.rg-room-panel {
  padding: 0 12px 4px;
  max-height: min(58vh, 520px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: max-height 0.28s ease, opacity 0.2s ease, padding 0.2s ease;
  opacity: 1;
}

/* Collapsed: hide chat body, keep thin dock so Scarlett is visible */
.rg-room-chrome.is-collapsed {
  padding-bottom: 6px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
}

.rg-room-chrome.is-collapsed .rg-room-panel {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.rg-room-chrome.is-collapsed .rg-room-status-mini {
  display: block;
}

.rg-room-chrome.is-collapsed .rg-room-btn-expand {
  background: rgba(236, 72, 153, 0.35);
  border-color: rgba(251, 207, 232, 0.65);
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.35);
}

/* When expanded on mobile, dock expand button less needed */
.rg-room-chrome:not(.is-collapsed) .rg-room-btn-expand {
  display: none;
}

.rg-room-chrome:not(.is-collapsed) .rg-room-title-dock {
  display: none;
}

.rg-room-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.rg-room-title {
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #f9a8d4;
}

.rg-room-btn {
  border: 1px solid rgba(244, 114, 182, 0.4);
  background: rgba(236, 72, 153, 0.15);
  color: #fce7f3;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 40px;
}

.rg-room-btn:hover {
  background: rgba(236, 72, 153, 0.28);
}

.rg-room-streams {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  max-height: 72px;
  overflow: auto;
}

.rg-stream-chip {
  border: 1px solid rgba(244, 114, 182, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: #fbcfe8;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.rg-room-empty,
.rg-room-performer {
  font-size: 12px;
  color: #f9a8d4;
  margin-bottom: 6px;
}

.rg-room-chat {
  height: 96px;
  overflow-y: auto;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.rg-chat-line {
  margin-bottom: 4px;
  color: #fce7f3;
}

.rg-chat-line strong {
  color: #f472b6;
}

.rg-room-compose {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#rg-room-chat-input {
  flex: 1;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  padding: 10px 12px;
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  font-family: inherit;
}

.rg-room-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}

#rg-room-jumpin {
  display: inline-flex;
  align-items: center;
}

.rg-room-status {
  min-height: 16px;
  font-size: 11px;
  color: #f9a8d4;
}

/* Mobile: she fills the screen; chrome is a thin talk strip */
@media (max-width: 720px) {
  .rg-room-chrome {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
  }

  .rg-room-panel {
    max-height: min(38vh, 320px);
  }

  .rg-room-chat {
    height: 64px;
  }

  .rg-room-dock-bar .rg-room-btn {
    flex: 0 0 auto;
    padding: 8px 10px;
    font-size: 12px;
  }

  .rg-room-chrome:not(.is-collapsed) .rg-room-dock-bar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 4px;
  }

  .rg-room-hint {
    font-size: 10px;
  }

  .rg-presence-caption {
    bottom: calc(108px + env(safe-area-inset-bottom, 0px));
    font-size: 12px;
  }

  /* Collapsed = only talk bar + presence (no wall of controls) */
  .rg-room-chrome.is-collapsed .rg-room-panel {
    max-height: 0 !important;
    opacity: 0;
    padding: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .rg-room-title-dock {
    display: none !important;
  }
}

/* Desktop presence: still prioritize her image over chrome */
@media (min-width: 721px) {
  .rg-presence-stage {
    /* soft letterbox for wide screens */
  }
  .rg-presence-video {
    object-fit: contain;
    background: #050308;
  }
}

/* Collapsed overlay = almost full-screen view of Scarlett */
#rg-room-overlay.rg-chrome-collapsed {
  /* keep pointer events only on the thin dock */
}

.tip-msg-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  margin: 0 0 4px;
}

#tip-message.tip-message,
.tip-message {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.35);
  color: #e2e8f0;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

body.rg-room-open #globe-canvas,
body.rg-room-open canvas#c {
  /* room uses same canvas; keep interactive */
}
