/* Master AI ("Te") floating orb + call HUD. Body-level overlay, above toasts. */

.master-orb {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: inherit;
}

.master-orb__btn {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  /* Own the touch gesture so press-and-drag repositions the orb instead of
     scrolling / zooming the page underneath it. */
  touch-action: none;
  color: #fff;
  background: radial-gradient(circle at 30% 28%, #6ea8ff 0%, #3f6fe0 46%, #274bb5 100%);
  box-shadow: 0 6px 20px rgba(39, 75, 181, 0.45), inset 0 1px 2px rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.5, 1), box-shadow 0.25s ease, filter 0.2s ease;
}
.master-orb__btn:hover { transform: scale(1.07); }
.master-orb__btn:active { transform: scale(0.9); }

/* While dragging: kill the hover/active scale + grabbing cursor, and don't
   animate the position so the orb tracks the finger 1:1. */
.master-orb.is-dragging { transition: none; }
.master-orb.is-dragging .master-orb__btn {
  cursor: grabbing;
  transform: none;
  transition: none;
}

.master-orb__label {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.master-orb__ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(110, 168, 255, 0.6);
  opacity: 0;
  pointer-events: none;
}

/* active-call states */
.master-orb.is-active .master-orb__btn {
  background: radial-gradient(circle at 30% 28%, #8ad0a0 0%, #34b46b 46%, #1f8f52 100%);
  box-shadow: 0 6px 22px rgba(31, 143, 82, 0.5), inset 0 1px 2px rgba(255, 255, 255, 0.35);
}
.master-orb.is-listening .master-orb__ring { animation: orb-pulse 1.8s ease-out infinite; opacity: 1; }
.master-orb.is-speaking .master-orb__ring { animation: orb-pulse 0.9s ease-out infinite; opacity: 1; border-color: rgba(138, 208, 160, 0.75); }
.master-orb.is-thinking .master-orb__btn { animation: orb-breathe 1.2s ease-in-out infinite; }
/* second ring, offset in time for a layered ripple */
.master-orb.is-listening .master-orb__ring--2 { animation: orb-pulse 1.8s ease-out 0.9s infinite; opacity: 1; }
.master-orb.is-speaking .master-orb__ring--2 { animation: orb-pulse 0.9s ease-out 0.45s infinite; opacity: 1; border-color: rgba(138, 208, 160, 0.55); }
/* mic actively open (push-to-talk listening): a red pulse ring on the orb so
   it's unmistakable that it's hearing her right now. */
.master-orb.is-miclive .master-orb__ring {
  animation: orb-pulse 1.2s ease-out infinite;
  opacity: 1;
  border-color: rgba(240, 90, 90, 0.85);
}

@keyframes orb-pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}
@keyframes orb-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* HUD panel */
.master-orb__hud {
  order: -1;              /* sits above the orb */
  width: 260px;
  max-width: 78vw;
  background: rgba(20, 24, 34, 0.92);
  color: #e8ecf4;
  border: 1px solid rgba(120, 150, 210, 0.28);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  font-size: 13px;
  line-height: 1.4;
  transform-origin: bottom right;
  /* Closed: collapsed + faded, non-interactive. Opening is driven by
     `.master-orb.is-active`, so the panel eases in instead of popping. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.94);
  pointer-events: none;
  transition: opacity 0.24s ease,
              transform 0.34s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0s linear 0.28s;
}
.master-orb.is-active .master-orb__hud {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  transition: opacity 0.22s ease,
              transform 0.42s cubic-bezier(0.34, 1.4, 0.5, 1),
              visibility 0s;
}
@media (prefers-reduced-motion: reduce) {
  .master-orb__hud,
  .master-orb.is-active .master-orb__hud { transform: none; transition: opacity 0.15s ease, visibility 0s; }
}
.master-orb__state { font-weight: 600; color: #9fc0ff; margin-bottom: 6px; }
.master-orb__transcript { color: #dfe6f2; min-height: 1.2em; word-break: break-word; }
.master-orb__say { color: #a9d6b8; margin-top: 6px; font-style: italic; word-break: break-word; }
/* Push-to-talk — the primary control. Big and prominent; turns red and pulses
   while the mic is open so "it's listening to me right now" is unmistakable. */
.master-orb__ptt {
  margin-top: 12px;
  width: 100%;
  padding: 14px 12px;
  border-radius: 12px;
  border: 1px solid rgba(120, 160, 240, 0.55);
  background: linear-gradient(180deg, rgba(92, 132, 224, 0.30), rgba(60, 100, 200, 0.24));
  color: #eaf1ff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.master-orb__ptt:hover { background: linear-gradient(180deg, rgba(92, 132, 224, 0.42), rgba(60, 100, 200, 0.34)); }
.master-orb__ptt:active { transform: scale(0.97); }
.master-orb__ptt-ic { font-size: 20px; line-height: 1; }
.master-orb__ptt.is-live {
  border-color: rgba(240, 96, 96, 0.75);
  background: linear-gradient(180deg, rgba(220, 64, 64, 0.34), rgba(180, 40, 40, 0.28));
  color: #ffe4e4;
  animation: ptt-live 1.3s ease-in-out infinite;
}
@keyframes ptt-live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 80, 80, 0.5); }
  50% { box-shadow: 0 0 0 9px rgba(240, 80, 80, 0); }
}
.master-orb__hang {
  margin-top: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(220, 120, 120, 0.4);
  background: rgba(180, 60, 60, 0.22);
  color: #ffd7d7;
  transition: background 0.15s ease, transform 0.1s ease;
}
.master-orb__hang:hover { background: rgba(180, 60, 60, 0.35); }
.master-orb__hang:active { transform: scale(0.97); }

/* light theme */
@media (prefers-color-scheme: light) {
  .master-orb__hud {
    background: rgba(250, 251, 254, 0.95);
    color: #1c2534;
    border-color: rgba(80, 120, 200, 0.25);
  }
  .master-orb__state { color: #2f5fd0; }
  .master-orb__transcript { color: #2a3446; }
  .master-orb__say { color: #1f8f52; }
}
:root[data-theme="light"] .master-orb__hud {
  background: rgba(250, 251, 254, 0.95);
  color: #1c2534;
  border-color: rgba(80, 120, 200, 0.25);
}
:root[data-theme="light"] .master-orb__state { color: #2f5fd0; }
:root[data-theme="dark"] .master-orb__hud {
  background: rgba(20, 24, 34, 0.92);
  color: #e8ecf4;
  border-color: rgba(120, 150, 210, 0.28);
}

@media (max-width: 560px) {
  .master-orb { right: 14px; bottom: 14px; }
  .master-orb__btn { width: 56px; height: 56px; }
}

/* Touch / phone: the orb defaults to bottom-right, where it collides with the
   fixed keybar. Lift the orb above the keybar (+ iOS safe area). */
body.is-touch .master-orb {
  bottom: calc(var(--mobile-keybar-h, 44px) + env(safe-area-inset-bottom, 0px) + 16px);
}

/* On a phone the call HUD anchored to the corner opens off-screen / clipped by
   the bottom browser chrome — the user sees "Bağlanıyor" nowhere. When a call
   is active, detach it from the orb and pin it as a fixed, centred card that
   can't be missed. Gated on width (not the is-touch JS class) so it applies
   even if that class never got set. */
@media (max-width: 760px) {
  /* On a phone, anchor the call card to screen-centre for BOTH states so it
     can't open off-screen behind the browser chrome — and so it can animate
     (a corner→fixed jump can't transition). The closed state is invisible. */
  .master-orb__hud {
    position: fixed;
    left: 50%;
    top: 50%;
    transform-origin: center;
    transform: translate(-50%, -46%) scale(0.94);
    width: min(92vw, 440px);
    max-width: none;
    font-size: 14px;
    z-index: 9600;
  }
  .master-orb.is-active .master-orb__hud {
    transform: translate(-50%, -50%) scale(1);
  }
}
