/* Agent Bridge live voice: an accessible, CSS-only fluid glow with no GPU canvas. */
#bridge-voice {
  --voice-level: 0;
  --voice-a: #49d8ff;
  --voice-b: #7c5cff;
  --voice-c: #ee7cff;
  --voice-ink: #eaf8ff;
  --voice-muted: #91a3b8;
  --voice-panel: rgba(8, 14, 27, 0.88);
  --voice-border: rgba(116, 208, 255, 0.2);
  position: relative;
  display: grid;
  grid-template-columns: minmax(190px, 0.72fr) minmax(250px, 1.28fr);
  grid-template-areas:
    "stage actions"
    "stage disclosure";
  align-items: center;
  gap: clamp(16px, 3vw, 34px);
  margin: 12px;
  padding: clamp(16px, 3vw, 28px);
  overflow: hidden;
  isolation: isolate;
  color: var(--voice-ink);
  border: 1px solid var(--voice-border);
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--voice-a) 13%, transparent), transparent 38%),
    radial-gradient(circle at 88% 78%, color-mix(in srgb, var(--voice-b) 12%, transparent), transparent 42%),
    linear-gradient(145deg, rgba(14, 22, 40, 0.96), var(--voice-panel));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.04), 0 18px 54px rgba(0, 0, 0, 0.28);
}

#bridge-voice::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: 62%;
  aspect-ratio: 1;
  left: -24%;
  bottom: -74%;
  border-radius: 46% 54% 61% 39% / 42% 39% 61% 58%;
  background: color-mix(in srgb, var(--voice-b) 18%, transparent);
  filter: blur(28px);
  transform: rotate(-12deg);
  animation: voice-panel-drift 12s ease-in-out infinite alternate;
  pointer-events: none;
}

/* Keep the resting palette explicit so every state has a named visual
   contract, instead of relying on the base rule as an implicit idle state. */
#bridge-voice[data-state="idle"] {
  --voice-a: #49d8ff;
  --voice-b: #7c5cff;
  --voice-c: #ee7cff;
  --voice-border: rgba(116, 208, 255, 0.2);
}

#bridge-voice[data-state="listening"] {
  --voice-a: #4fffc1;
  --voice-b: #27c7ff;
  --voice-c: #a5ff87;
  --voice-border: rgba(79, 255, 193, 0.34);
}

#bridge-voice[data-state="thinking"] {
  --voice-a: #9d7bff;
  --voice-b: #4e7cff;
  --voice-c: #e781ff;
  --voice-border: rgba(157, 123, 255, 0.34);
}

#bridge-voice[data-state="speaking"] {
  --voice-a: #ffcc66;
  --voice-b: #ff6ea8;
  --voice-c: #9d7bff;
  --voice-border: rgba(255, 180, 104, 0.38);
}

#bridge-voice[data-state="error"] {
  --voice-a: #ff6f91;
  --voice-b: #e63f64;
  --voice-c: #ffad7c;
  --voice-border: rgba(255, 97, 130, 0.5);
}

.voice-stage,
#bridge-voice .voice-stage {
  grid-area: stage;
  min-width: 0;
  display: grid;
  place-items: center;
  gap: 11px;
  text-align: center;
}

#voice-orb {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  filter: saturate(1.16);
}

#voice-orb::before,
#voice-orb::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
}

#voice-orb::before {
  inset: -8%;
  opacity: calc(0.35 + var(--voice-level) * 0.42);
  background:
    conic-gradient(from 20deg,
      transparent 0 8%,
      color-mix(in srgb, var(--voice-a) 72%, transparent) 18%,
      transparent 32% 48%,
      color-mix(in srgb, var(--voice-c) 66%, transparent) 63%,
      transparent 78% 88%,
      color-mix(in srgb, var(--voice-b) 72%, transparent));
  filter: blur(calc(12px + var(--voice-level) * 13px));
  transform: scale(calc(0.96 + var(--voice-level) * 0.13));
  animation: voice-halo-turn 8s linear infinite;
}

#voice-orb::after {
  inset: 7%;
  background:
    radial-gradient(circle at 32% 25%, rgba(255, 255, 255, 0.42), transparent 14%),
    radial-gradient(circle at 34% 34%, var(--voice-a), transparent 38%),
    radial-gradient(circle at 68% 62%, var(--voice-c), transparent 45%),
    radial-gradient(circle at 42% 78%, var(--voice-b), transparent 48%),
    #0c1023;
  box-shadow:
    inset 13px 12px 24px rgba(255, 255, 255, 0.11),
    inset -20px -18px 34px rgba(0, 0, 0, 0.34),
    0 0 calc(26px + var(--voice-level) * 34px) color-mix(in srgb, var(--voice-a) 48%, transparent),
    0 0 calc(54px + var(--voice-level) * 42px) color-mix(in srgb, var(--voice-b) 25%, transparent);
  transform: scale(calc(0.91 + var(--voice-level) * 0.1));
  animation: voice-fluid-breathe 5.8s ease-in-out infinite alternate;
}

#voice-orb-button {
  position: relative;
  z-index: 2;
  width: clamp(132px, 18vw, 196px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0 !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  border-radius: 50% !important;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.25), transparent 27%),
    linear-gradient(145deg,
      color-mix(in srgb, var(--voice-a) 42%, rgba(10, 17, 33, 0.82)),
      color-mix(in srgb, var(--voice-b) 46%, rgba(7, 12, 28, 0.92))) !important;
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.32),
    inset -9px -12px 22px rgba(0, 0, 0, 0.24),
    0 8px 24px rgba(0, 0, 0, 0.28);
  font: 700 clamp(12px, 1.6vw, 15px)/1.15 inherit;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 240ms ease;
}

.voice-orb-blob,
.voice-orb-core {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  mix-blend-mode: screen;
}

.voice-orb-blob {
  width: 58%;
  height: 58%;
  filter: blur(13px);
  opacity: calc(0.45 + var(--voice-level) * 0.36);
}

.voice-orb-blob-a {
  top: 10%;
  left: 8%;
  background: var(--voice-a);
  animation: voice-blob-a 4.8s ease-in-out infinite alternate;
}

.voice-orb-blob-b {
  right: 4%;
  bottom: 9%;
  background: var(--voice-b);
  animation: voice-blob-b 5.6s ease-in-out infinite alternate;
}

.voice-orb-blob-c {
  right: 12%;
  top: 18%;
  width: 44%;
  height: 44%;
  background: var(--voice-c);
  animation: voice-blob-c 4.1s ease-in-out infinite alternate;
}

.voice-orb-core {
  inset: 29%;
  background: rgba(255, 255, 255, 0.24);
  filter: blur(8px);
  box-shadow: 0 0 calc(13px + var(--voice-level) * 18px) rgba(255, 255, 255, 0.52);
}

#voice-orb-button::before,
#voice-orb-button::after {
  content: "";
  position: absolute;
  inset: -32%;
  z-index: 0;
  border-radius: 43% 57% 39% 61% / 48% 37% 63% 52%;
  background: conic-gradient(from 90deg,
    transparent,
    color-mix(in srgb, var(--voice-c) 56%, transparent),
    transparent 42%,
    color-mix(in srgb, var(--voice-a) 64%, transparent),
    transparent 78%);
  opacity: calc(0.38 + var(--voice-level) * 0.45);
  animation: voice-fluid-turn 6.4s linear infinite;
}

#voice-orb-button::after {
  inset: -46%;
  opacity: 0.34;
  animation-duration: 9.2s;
  animation-direction: reverse;
}

#voice-orb-button:hover {
  transform: scale(1.035);
  border-color: rgba(255, 255, 255, 0.56);
}

#voice-orb-button:active {
  transform: scale(0.98);
}

#voice-orb-button:focus-visible,
#bridge-voice button:focus-visible,
#bridge-voice select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--voice-a) 75%, white);
  outline-offset: 3px;
}

#bridge-voice[data-state="listening"] #voice-orb {
  animation: voice-listen-pulse 1.55s ease-in-out infinite;
}

#bridge-voice[data-state="thinking"] #voice-orb::before,
#bridge-voice[data-state="thinking"] #voice-orb-button::before {
  animation-duration: 2.4s;
}

#bridge-voice[data-state="thinking"] #voice-orb::after {
  animation: voice-thinking-fold 2.1s ease-in-out infinite alternate;
}

#bridge-voice[data-state="speaking"] #voice-orb::before {
  animation-duration: 2.2s;
}

#bridge-voice[data-state="speaking"] #voice-orb::after {
  animation: voice-speaking-wave 0.9s ease-in-out infinite alternate;
}

#bridge-voice[data-state="error"] #voice-orb {
  animation: voice-error-shiver 500ms ease-in-out 2;
}

.voice-copy,
#bridge-voice .voice-copy {
  min-width: 0;
  display: grid;
  gap: 12px;
}

#voice-state-label {
  margin: 0;
  color: var(--voice-ink);
  font-size: clamp(21px, 3vw, 31px);
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

#voice-state-label::before {
  content: "";
  display: inline-block;
  width: 0.48em;
  height: 0.48em;
  margin-right: 0.42em;
  vertical-align: 0.09em;
  border-radius: 50%;
  background: var(--voice-a);
  box-shadow: 0 0 14px var(--voice-a);
}

#voice-detail {
  min-height: 2.8em;
  margin: 0;
  color: var(--voice-muted);
  font-size: 13px;
  line-height: 1.45;
}

#voice-meter {
  position: relative;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: rgba(143, 166, 198, 0.14);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.32);
}

#voice-meter::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--voice-a), var(--voice-c));
  box-shadow: 0 0 13px var(--voice-a);
  transform: scaleX(var(--voice-level));
  transform-origin: left center;
  transition: transform 72ms linear;
}

#bridge-voice .voice-actions {
  grid-area: actions;
  align-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.voice-disclosure,
#bridge-voice .voice-disclosure {
  grid-area: disclosure;
  align-self: start;
  margin: 0;
  color: var(--voice-muted);
  font-size: 11px;
  line-height: 1.45;
}

#bridge-voice button:not(#voice-orb-button),
#bridge-voice select {
  min-height: 40px;
  padding: 8px 12px;
  color: var(--voice-ink);
  border: 1px solid rgba(149, 180, 218, 0.22);
  border-radius: 11px;
  background: rgba(18, 29, 49, 0.82);
  font: 650 12px/1.2 inherit;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

#bridge-voice button:not(#voice-orb-button):hover,
#bridge-voice select:hover {
  border-color: color-mix(in srgb, var(--voice-a) 56%, transparent);
  background: rgba(26, 40, 66, 0.92);
}

#bridge-voice button:not(#voice-orb-button):active {
  transform: translateY(1px);
}

#bridge-voice button[aria-pressed="true"] {
  color: #07141b !important;
  border-color: transparent !important;
  background: linear-gradient(120deg, var(--voice-a), var(--voice-c)) !important;
  box-shadow: 0 0 17px color-mix(in srgb, var(--voice-a) 30%, transparent);
}

#bridge-voice button:disabled,
#bridge-voice select:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

#voice-stop:not(:disabled) {
  color: #ffd9e1;
  border-color: rgba(255, 111, 145, 0.38);
}

#voice-select {
  flex: 1 1 155px;
  max-width: 260px;
}

.large-text #bridge-voice {
  grid-template-columns: minmax(180px, 0.6fr) minmax(280px, 1.4fr);
}

.large-text #voice-detail,
.large-text #bridge-voice button:not(#voice-orb-button),
.large-text #bridge-voice select {
  font-size: 0.92em;
}

.large-text #voice-orb-button {
  font-size: 0.74em;
}

@keyframes voice-halo-turn {
  to { transform: scale(calc(0.96 + var(--voice-level) * 0.13)) rotate(360deg); }
}

@keyframes voice-fluid-turn {
  0% { transform: rotate(0deg) scale(1); border-radius: 43% 57% 39% 61% / 48% 37% 63% 52%; }
  50% { transform: rotate(180deg) scale(1.07); border-radius: 62% 38% 53% 47% / 36% 61% 39% 64%; }
  100% { transform: rotate(360deg) scale(1); border-radius: 43% 57% 39% 61% / 48% 37% 63% 52%; }
}

@keyframes voice-fluid-breathe {
  0% { transform: scale(calc(0.9 + var(--voice-level) * 0.1)) rotate(-2deg); }
  100% { transform: scale(calc(0.94 + var(--voice-level) * 0.12)) rotate(4deg); }
}

@keyframes voice-listen-pulse {
  0%, 100% { transform: scale(0.985); }
  50% { transform: scale(calc(1 + var(--voice-level) * 0.045)); }
}

@keyframes voice-thinking-fold {
  0% { transform: scale(0.91) rotate(-5deg); filter: hue-rotate(0deg); }
  100% { transform: scale(0.97) rotate(7deg); filter: hue-rotate(24deg); }
}

@keyframes voice-speaking-wave {
  0% { transform: scale(calc(0.9 + var(--voice-level) * 0.08)); }
  100% { transform: scale(calc(0.96 + var(--voice-level) * 0.13)); }
}

@keyframes voice-error-shiver {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes voice-panel-drift {
  from { transform: translate3d(-3%, 1%, 0) rotate(-12deg); }
  to { transform: translate3d(18%, -12%, 0) rotate(14deg); }
}

@keyframes voice-blob-a {
  from { transform: translate3d(-7%, -4%, 0) scale(0.9); }
  to { transform: translate3d(28%, 24%, 0) scale(1.14); }
}

@keyframes voice-blob-b {
  from { transform: translate3d(8%, 5%, 0) scale(1.05); }
  to { transform: translate3d(-25%, -24%, 0) scale(0.88); }
}

@keyframes voice-blob-c {
  from { transform: translate3d(0, 20%, 0) scale(0.82); }
  to { transform: translate3d(-30%, -8%, 0) scale(1.18); }
}

@media (max-width: 700px) {
  /* The original chat keeps its conversation rail beside the composer on a
     phone.  A voice stage needs the full width, so stack the rail above the
     chat and let the page scroll while the message log keeps its own bounds. */
  #chat-panel .chat-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  #chat-panel .chat-sidebar {
    max-height: 150px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  #chat-panel .chat-main {
    overflow: visible;
  }

  #chat-panel #chat-messages {
    flex: 0 0 min(44vh, 360px);
    min-height: 220px;
    max-height: 360px;
  }

  #bridge-voice,
  .large-text #bridge-voice {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "actions"
      "disclosure";
    gap: 10px;
    margin: 8px;
    padding: 16px;
    text-align: center;
  }

  #voice-orb-button {
    width: min(46vw, 170px);
  }

  #voice-detail {
    min-height: 0;
  }

  #bridge-voice .voice-actions {
    justify-content: center;
  }

  #voice-select {
    flex-basis: 100%;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #bridge-voice,
  #bridge-voice::before,
  #voice-orb,
  #voice-orb::before,
  #voice-orb::after,
  #voice-orb-button::before,
  #voice-orb-button::after,
  .voice-orb-blob-a,
  .voice-orb-blob-b,
  .voice-orb-blob-c {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  #voice-meter::after {
    transition: none;
  }
}

@supports not (color: color-mix(in srgb, white, black)) {
  #bridge-voice {
    background: linear-gradient(145deg, #111b31, #080e1b);
  }

  #voice-orb::before {
    background: conic-gradient(transparent, var(--voice-a), transparent, var(--voice-c), transparent);
  }

  #voice-orb-button {
    background: linear-gradient(145deg, #245b74, #3d3479);
  }
}

/* Captions: what you said and what the Bridge answered (Jarvis lane and VS Code readouts). */
.voice-caption,
#bridge-voice .voice-caption {
  display: grid;
  gap: 6px;
  width: 100%;
  margin: 0;
  color: var(--voice-ink);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
}

.voice-caption[hidden] {
  display: none;
}

.voice-caption-you {
  color: var(--voice-muted);
}

.voice-caption-bridge {
  color: var(--voice-ink);
}

#voice-brain,
#voice-vscode-readout {
  flex: 1 1 150px;
  max-width: 240px;
}

/* Focus: the orb and captions fill the screen, Jarvis style. Escape or the button leaves. */
html.voice-focus {
  overflow: hidden;
}

html.voice-focus #bridge-voice {
  position: fixed;
  inset: 0;
  z-index: 60;
  margin: 0;
  border-radius: 0;
  grid-template-columns: 1fr;
  grid-template-areas:
    "stage"
    "actions"
    "disclosure";
  align-content: center;
  justify-items: center;
  padding: clamp(20px, 5vw, 56px);
  overflow: auto;
}

html.voice-focus #voice-orb-button {
  width: clamp(220px, 42vmin, 420px);
}

html.voice-focus #voice-state-label {
  font-size: clamp(28px, 5vw, 44px);
}

html.voice-focus #voice-detail {
  font-size: clamp(15px, 2vw, 19px);
}

html.voice-focus .voice-caption,
html.voice-focus #bridge-voice .voice-caption {
  max-width: 720px;
  font-size: clamp(16px, 2.2vw, 22px);
  text-align: center;
}

html.voice-focus #bridge-voice .voice-actions {
  justify-content: center;
}

html.voice-focus .voice-disclosure,
html.voice-focus #bridge-voice .voice-disclosure {
  max-width: 640px;
  text-align: center;
}

/* ---------------------------------------------------------------------------------------------------------
   Compact voice bar (the chat box copied from Server Farm Swarm, 2026-10-08): one row of pills docked above
   the composer: orb, state, level, Push to talk, Live voice, Stop, Voice, Answer with, VS Code replies, Focus.
   Focus (html.voice-focus) still fills the screen with the orb and captions, with the rules above.
   --------------------------------------------------------------------------------------------------------- */
html:not(.voice-focus) #bridge-voice {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 0; padding: 8px 10px; border-radius: 10px; box-shadow: none;
  background: color-mix(in srgb, var(--bridge-bg, #07111f) 60%, transparent);
  border-color: var(--bridge-border, rgba(116, 208, 255, 0.2));
}
html:not(.voice-focus) #bridge-voice::before { display: none; }
html:not(.voice-focus) #bridge-voice .voice-stage {
  display: flex; flex: 0 1 auto; align-items: center; gap: 8px; min-width: 0; text-align: left;
}
html:not(.voice-focus) #voice-orb-button { width: 40px; height: 40px; min-height: 0; flex: none; }
html:not(.voice-focus) #bridge-voice .voice-copy { display: flex; align-items: center; gap: 8px; }
html:not(.voice-focus) #voice-state-label {
  padding: 5px 10px; border: 1px solid rgba(149, 180, 218, 0.22); border-radius: 999px;
  font-size: 12px; font-weight: 650; letter-spacing: 0; white-space: nowrap;
}
html:not(.voice-focus) #voice-detail,
html:not(.voice-focus) #bridge-voice .voice-caption,
html:not(.voice-focus) #bridge-voice .voice-disclosure { display: none; }
html:not(.voice-focus) #voice-meter { width: 64px; height: 6px; flex: none; }
html:not(.voice-focus) #bridge-voice .voice-actions { display: contents; }
html:not(.voice-focus) #bridge-voice button:not(#voice-orb-button),
html:not(.voice-focus) #bridge-voice select {
  min-height: 32px; padding: 6px 10px; border-radius: 8px; font-size: 12px;
}
html:not(.voice-focus) #bridge-voice label { color: var(--voice-muted); font-size: 12px; white-space: nowrap; }
html:not(.voice-focus) #voice-select,
html:not(.voice-focus) #voice-brain,
html:not(.voice-focus) #voice-vscode-readout { flex: 0 1 auto; max-width: 190px; }
