/* The voice island (voice.js) — Jarvis listening, hearing, thinking and speaking, above every
   screen; and the Voice section of the chat's Session panel.
   Tokens only (DESIGN.md §5.1). Motion: ease-out, under 300 ms for UI, none when reduced.
   --vlevel (0–1) is set on .vi by voice.js every frame: the mic while listening, Jarvis's voice
   while speaking. */

.vi {
  --vlevel: 0;
  position: fixed;
  top: 60px;                        /* just under the header bar — its search and buttons stay usable */
  left: 50%;
  z-index: 80;                      /* above the dock and nav (60), below overlays (90) */
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  max-width: min(640px, calc(100vw - 32px));
  padding: 8px 8px 8px 8px;
  border-radius: 28px;
  color: var(--text);
  font: 13px/1.38 var(--font);
  transform: translateX(-50%);
  transition: transform var(--dur-ui) var(--ease-out), opacity var(--dur-ui) var(--ease-out), border-radius var(--dur-ui) var(--ease-out);
}
.vi[hidden] { display: none; }
/* the Hub is a voice surface of its own (the core, the talk bar): the island steps aside there */
.vi.is-away { visibility: hidden; opacity: 0; pointer-events: none; }
.vi.is-entering { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.97); }
.vi.is-leaving { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.97); transition-duration: var(--dur-fast); }
.vi.has-text { align-items: flex-start; border-radius: 22px; }

/* ── the orb ── */
.vi-orb {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out);
}
.vi-core {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent-text), var(--accent) 55%, var(--accent-strong));
  box-shadow: 0 0 calc(6px + 22px * var(--vlevel)) color-mix(in srgb, var(--accent) 70%, transparent);
  transform: scale(calc(0.84 + 0.34 * var(--vlevel)));
  transition: transform 70ms linear, box-shadow 70ms linear, opacity var(--dur-ui) var(--ease-out);
}
.vi-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--accent-sep);
}
.vi[data-phase="idle"] .vi-core { opacity: 0.72; }
.vi[data-phase="listening"] .vi-ring { box-shadow: inset 0 0 0 2px var(--accent); animation: vi-breathe 1.6s var(--ease-in-out) infinite; }
.vi[data-phase="hearing"] .vi-ring,
.vi[data-phase="thinking"] .vi-ring {
  box-shadow: none;
  background: conic-gradient(from 0deg, transparent 0 55%, var(--accent) 88%, transparent);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), black calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), black calc(100% - 2px));
  animation: vi-spin 0.9s linear infinite;
}
.vi[data-phase="thinking"] .vi-ring { animation-duration: 1.6s; }
.vi[data-phase="speaking"] .vi-ring { box-shadow: inset 0 0 0 1.5px var(--accent-text); }

@keyframes vi-spin { to { transform: rotate(1turn); } }
@keyframes vi-breathe { 0%, 100% { transform: scale(1); opacity: 0.95; } 50% { transform: scale(1.07); opacity: 0.55; } }

/* ── the words ── */
.vi-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 1px 0; }
.vi.has-text .vi-text { padding-top: 2px; }
.vi-state {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.vi:not(.has-text) .vi-text { justify-content: center; min-height: 40px; }
.vi-dots { display: none; gap: 3px; }
.vi-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent-text); animation: vi-dot 1.2s var(--ease-in-out) infinite; }
.vi-dots i:nth-child(2) { animation-delay: 0.15s; }
.vi-dots i:nth-child(3) { animation-delay: 0.3s; }
.vi[data-phase="hearing"] .vi-dots,
.vi[data-phase="thinking"] .vi-dots { display: inline-flex; }
@keyframes vi-dot { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.vi-caption {
  font-size: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vi[data-phase="hearing"] .vi-caption,
.vi[data-phase="thinking"] .vi-caption { color: var(--text-2); }
.vi-caption:empty, .vi-note:empty { display: none; }
.vi-note { font-size: 12px; color: var(--text-2); }

/* a confirmation card waiting during a voice turn — yellow is "waiting for you" (DESIGN.md §2) */
.vi-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--yellow) 11%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--yellow) 32%, transparent);
}
.vi-card[hidden] { display: none; }
.vi-card-title { flex: 1 1 200px; font-size: 12.5px; }
.vi-card-actions { display: flex; gap: 6px; }
.vi-btn {
  padding: 5px 12px;
  border: 0;
  border-radius: var(--r-pill);
  font: 600 12px/1.2 var(--font);
  color: var(--text);
  background: var(--fill-2);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.vi-btn-go { background: var(--accent-strong); }

/* ── the tools ── */
.vi-tools { display: flex; flex: none; align-self: center; gap: 2px; }
.vi.has-text .vi-tools { align-self: flex-start; }
.vi-tool {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  font-size: 15px;
  color: var(--text-2);
  background: transparent;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.vi-tool[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-fill); }
@media (hover: hover) and (pointer: fine) {
  .vi-tool:hover { color: var(--text); background: var(--fill); }
  .vi-btn:hover { background: var(--fill-3); }
  .vi-btn-go:hover { background: var(--accent); }
}
.vi-orb:active, .vi-tool:active, .vi-btn:active { transform: scale(0.97); }
.vi-orb:focus-visible, .vi-tool:focus-visible, .vi-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 560px) {
  .vi { top: 56px; min-width: 0; width: calc(100vw - 16px); max-width: none; }
  .vi-caption { font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .vi, .vi * { animation: none !important; transition: none !important; }
  .vi-core { transform: none; }
}

/* ── the Voice section of the chat's Session panel ── */
.vset-input { font-size: 12.5px; }
.vset-row { display: flex; align-items: center; gap: 6px; }
.vset-row .vset-input { flex: 1; min-width: 0; }
.vset-btn { align-self: flex-start; font-size: 11.5px; }
.vset-hint { margin: 0; font-size: 11px; line-height: 1.45; color: var(--text-2); }
.vset-warn { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--orange); }
.vset-ok { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--text-2); }
.vset-range { width: 100%; accent-color: var(--accent); }
.vset-link { padding: 0; border: 0; font: inherit; color: var(--accent-text); text-decoration: underline; background: none; cursor: pointer; }

/* ── Fish voice search results (Session panel) ── */
.vset-found { display: grid; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.vset-found li { display: grid; gap: 1px; }

/* ── voice mode: the full-screen conversation (voice.js voiceModeOpen) ──────────────────────────
   One orb, captions, four controls. --vlevel (0–1) is set every frame: your voice while Jarvis
   listens, his while he speaks. The orb's colour clouds are three blurred blobs inside a clipped
   circle; they drift slowly, faster while he thinks. Tokens only. */

.vm-launch {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-2);
}
.vm-launch i { font-size: 18px; }
.vm-launch:hover { color: var(--accent-text); }

body.vm-open { overflow: hidden; }
body.vm-open #voice-island { display: none; }

.vm {
  --vlevel: 0;
  position: fixed;
  inset: 0;
  z-index: 95;                       /* above everything, including the overlays (90) */
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  color: var(--text);
  font: 15px/1.45 var(--font);
  background:
    radial-gradient(60vmax 60vmax at 50% 42%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  transition: opacity var(--dur-modal) var(--ease-out), transform var(--dur-modal) var(--ease-out);
}
.vm.is-entering { opacity: 0; transform: scale(1.02); }
.vm.is-leaving { opacity: 0; transform: scale(1.01); transition-duration: var(--dur-ui); pointer-events: none; }

.vm-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.vm-brand { display: inline-flex; align-items: center; gap: 8px; font: 600 13px/1 var(--font-display); letter-spacing: 0.18em; color: var(--text-2); }
.vm-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.vm-engine { font-size: 12px; color: var(--text-3); text-align: right; }

.vm-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 0;
  text-align: center;
}

/* the orb */
.vm-orb {
  position: relative;
  width: min(240px, 58vw);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transform: scale(calc(0.92 + 0.16 * var(--vlevel)));
  transition: transform 90ms linear;
  -webkit-tap-highlight-color: transparent;
}
.vm-orb:focus-visible { outline: 2px solid var(--accent-sep); outline-offset: 10px; }
.vm-orb-glow {
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 34%, transparent) 0%, transparent 62%);
  opacity: calc(0.45 + 0.55 * var(--vlevel));
  filter: blur(10px);
  transition: opacity 90ms linear;
}
.vm-orb-core {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--accent-text) 0%, var(--accent) 42%, var(--accent-strong) 78%, var(--indigo) 100%);
  box-shadow:
    inset 0 -18px 40px color-mix(in srgb, var(--indigo) 55%, transparent),
    inset 0 14px 30px color-mix(in srgb, var(--text) 22%, transparent),
    0 18px 60px color-mix(in srgb, var(--accent) 30%, transparent);
  isolation: isolate;
}
.vm-orb-core i {
  position: absolute;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  filter: blur(22px);
  mix-blend-mode: screen;
  opacity: 0.85;
  animation: vm-drift 14s linear infinite;
}
.vm-orb-core i:nth-child(1) { top: -10%; left: -6%; background: var(--teal); animation-duration: 13s; }
.vm-orb-core i:nth-child(2) { bottom: -14%; right: -10%; background: var(--purple); animation-duration: 17s; animation-direction: reverse; }
.vm-orb-core i:nth-child(3) { top: 30%; left: 30%; width: 50%; height: 50%; background: var(--accent-text); opacity: 0.6; animation-duration: 21s; }
@keyframes vm-drift {
  0%   { transform: rotate(0deg) translateX(14%) rotate(0deg); }
  100% { transform: rotate(360deg) translateX(14%) rotate(-360deg); }
}
@keyframes vm-breathe {
  0%, 100% { scale: 0.97; }
  50%      { scale: 1.03; }
}
@keyframes vm-think {
  0%, 100% { scale: 0.95; filter: saturate(1) brightness(1); }
  50%      { scale: 1.02; filter: saturate(1.25) brightness(1.12); }
}
.vm[data-phase="listening"] .vm-orb-core,
.vm[data-phase="idle"] .vm-orb-core { animation: vm-breathe 4.2s var(--ease-in-out) infinite; }
.vm[data-phase="hearing"] .vm-orb-core,
.vm[data-phase="thinking"] .vm-orb-core { animation: vm-think 1.4s var(--ease-in-out) infinite; }
.vm[data-phase="hearing"] .vm-orb-core i,
.vm[data-phase="thinking"] .vm-orb-core i { animation-duration: 3.5s; }
.vm[data-phase="speaking"] .vm-orb-core i { animation-duration: 7s; }
.vm[data-phase="muted"] .vm-orb-core { filter: grayscale(0.85) brightness(0.7); }
.vm[data-phase="muted"] .vm-orb { transform: scale(0.9); }

.vm-state { min-height: 22px; font: 500 15px/1.4 var(--font-display); color: var(--text-2); letter-spacing: 0.01em; }
.vm-captions { display: grid; gap: 8px; width: min(680px, 100%); min-height: 5.5em; }
.vm.no-captions .vm-captions { visibility: hidden; }
.vm-said { margin: 0; font-size: 14px; color: var(--text-3); }
.vm-said:not(:empty)::before { content: "You · "; color: var(--text-3); }
.vm-caption { margin: 0; font: 400 clamp(17px, 2.4vw, 22px)/1.45 var(--font-display); color: var(--text); text-wrap: pretty; }
.vm-note { min-height: 1.2em; margin: 0; font-size: 12.5px; color: var(--text-2); }

.vm-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: min(560px, 100%);
  padding: 10px 12px;
  border: 1px solid var(--accent-sep);
  border-radius: var(--r-lg);
  background: var(--accent-fill);
  font-size: 13px;
}
.vm-card[hidden] { display: none; }
.vm-card-actions { display: inline-flex; gap: 6px; }

.vm-controls { display: flex; align-items: flex-start; justify-content: center; gap: clamp(14px, 4vw, 28px); }
.vm-btn {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  font: 500 11.5px/1 var(--font);
  color: var(--text-2);
  background: none;
  cursor: pointer;
}
.vm-btn i {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 22px;
  color: var(--text);
  background: var(--fill-2);
  box-shadow: inset 0 0 0 1px var(--sep);
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.vm-btn:active i { transform: scale(0.94); }
.vm-btn:focus-visible { outline: none; }
.vm-btn:focus-visible i { box-shadow: inset 0 0 0 1px var(--sep), 0 0 0 2px var(--accent-sep); }
.vm-btn[aria-pressed="true"][data-vm-mute] i { color: var(--bg); background: var(--text); }
.vm-btn[aria-pressed="false"][data-vm-captions] i { color: var(--text-3); }
.vm-end i { color: var(--text); background: color-mix(in srgb, var(--red) 82%, transparent); box-shadow: none; }

@media (hover: hover) and (pointer: fine) {
  .vm-btn:hover i { background: var(--fill-3); }
  .vm-end:hover i { background: var(--red); }
}
@media (max-width: 560px) {
  .vm-btn span { display: none; }
  .vm-btn i { width: 52px; height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  .vm, .vm-orb, .vm-orb-glow { transition: none; }
  .vm-orb-core, .vm-orb-core i { animation: none !important; }
}
