/* Voice mode for the avatar's surface: the head, the voice mode button, the stage and its settings sheet.
   Split from lani-assistant.css (the 600-line cap); it reads that sheet's --assistant-* tokens, which are
   declared on .lani-assistant. */

/* ── Voice mode (js/shell/assistant-voice-mode.js) ──
   In chat the avatar is its head, at the start of the side panel's header. Voice mode changes the surface in place
   into the persona's face: the conversation and the composer give way to the stage and come back with "Back to
   chat". */

/* The head: the persona's live medallion, and a way into voice mode. */
.lani-assistant__head {
    position: relative;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--persona-rig-disc);
    overflow: hidden;
    cursor: pointer;
}

.lani-assistant__head .persona-art,
.lani-assistant__voice-face .persona-art {
    display: block;
}

.lani-assistant__head:hover,
.lani-assistant__head:focus-visible,
.lani-assistant__voice-face:focus-visible {
    outline: 2px solid var(--assistant-blue);
    outline-offset: 2px;
}

/* The avatar's dialog and a message's reply box stand beside the orb, which is the head there; in voice mode the
   head has become the face. */
.lani-assistant--compact .lani-assistant__head,
.lani-assistant.is-voice .lani-assistant__head {
    display: none;
}

/* The voice mode button: the composer's fourth round button, after the dictation microphone. */
.lani-assistant__voice-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--assistant-muted);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.lani-assistant__voice-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--assistant-text);
}

/* A reply box is this same composer; voice mode is a conversation with the avatar, not a reply to somebody. */
.lani-assistant--compact .lani-assistant__voice-btn {
    display: none;
}

.lani-orb-popover .lani-assistant--compact .lani-assistant__voice-btn {
    display: flex;
}

.lani-assistant.is-voice .lani-assistant__thread-links,
.lani-assistant.is-voice .lani-assistant__widget {
    display: none;
}

/* The stage grows out of where the head stood. */
.lani-assistant__voice {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px 18px 16px;
    overflow-y: auto;
    text-align: center;
    transform-origin: 27px 0;
    animation: lani-assistant-voice-in 280ms ease-out;
}

.lani-assistant__voice[hidden] {
    display: none;
}

@keyframes lani-assistant-voice-in {
    from { opacity: 0; transform: scale(0.3); }
    to { opacity: 1; transform: none; }
}

.lani-assistant__voice-figure {
    position: relative;
    flex-shrink: 0;
    width: min(220px, 58%);
    aspect-ratio: 1;
}

.lani-assistant--compact .lani-assistant__voice-figure {
    width: min(168px, 50%);
}

.lani-assistant__voice-face {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    cursor: pointer;
}

/* A ring round the face says whose turn it is: the person's while it listens, the avatar's while it speaks. */
.lani-assistant__voice-figure::before {
    content: '';
    position: absolute;
    inset: -7px;
    border: 2px solid transparent;
    border-radius: 50%;
    pointer-events: none;
    transition: border-color 0.2s;
}

.lani-assistant__voice[data-state="listening"] .lani-assistant__voice-figure::before {
    border-color: rgba(69, 223, 149, 0.45);
    animation: lani-assistant-pulse 1.6s ease-in-out infinite;
}

.lani-assistant__voice[data-state="hearing"] .lani-assistant__voice-figure::before {
    border-color: var(--assistant-green);
}

.lani-assistant__voice[data-state="speaking"] .lani-assistant__voice-figure::before {
    border-color: var(--assistant-blue);
}

/* While the person's words are read and while the avatar thinks, a light travels round the ring in the
   persona's own colour (assistant-voice-mode.js sets it): the wait is the avatar's, and something is
   happening. The face's own lights circle at half this speed (tools/persona-rig, `stars.orbit`). */
.lani-assistant__voice-figure::after {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    background: conic-gradient(from 0deg, transparent 0 55%, var(--assistant-voice-ring, var(--assistant-blue)) 100%);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
    transition: opacity 0.25s;
}

.lani-assistant__voice[data-state="transcribing"] .lani-assistant__voice-figure::after,
.lani-assistant__voice[data-state="thinking"] .lani-assistant__voice-figure::after {
    opacity: 1;
    animation: lani-assistant-voice-turn 2.4s linear infinite;
}

@keyframes lani-assistant-voice-turn {
    to { transform: rotate(360deg); }
}

/* Mute sits on the face. */
.lani-assistant__voice-mute {
    position: absolute;
    right: 2%;
    bottom: 2%;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--assistant-border);
    border-radius: 50%;
    background: var(--assistant-card);
    color: var(--assistant-text);
    cursor: pointer;
}

.lani-assistant__voice-mute:hover {
    border-color: rgba(46, 200, 255, 0.55);
}

.lani-assistant__voice-mute[aria-pressed="true"] {
    border-color: rgba(255, 115, 115, 0.5);
    color: #ff7373;
}

.lani-assistant__voice-name {
    margin-top: 6px;
    font-size: var(--fs-title);
    font-weight: 600;
    line-height: var(--lh-tight);
}

.lani-assistant__voice-state {
    min-height: 1.35em;
    color: var(--assistant-muted);
    font-size: var(--fs-ui);
    line-height: var(--lh-snug);
}

.lani-assistant__voice[data-state="listening"] .lani-assistant__voice-state,
.lani-assistant__voice[data-state="hearing"] .lani-assistant__voice-state {
    color: var(--assistant-green);
}

.lani-assistant__voice[data-state="denied"] .lani-assistant__voice-state,
.lani-assistant__voice[data-state="failed"] .lani-assistant__voice-state {
    color: var(--assistant-amber);
}

/* Why the answers are shown and not said, when no voice says them. */
.lani-assistant__voice-note {
    max-width: 38ch;
    color: var(--assistant-amber);
    font-size: var(--fs-meta);
    line-height: var(--lh-snug);
}

/* What was heard, then what was said: the exchange in front; the whole of it is in the chat. */
.lani-assistant__voice-heard {
    max-width: 34ch;
    color: var(--assistant-muted);
    font-size: var(--fs-ui);
    line-height: var(--lh-snug);
}

.lani-assistant__voice-said {
    max-width: 38ch;
    max-height: 9em;
    overflow-y: auto;
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    scrollbar-width: thin;
}

.lani-assistant__voice-leave {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 6px 12px;
    border: 1px solid var(--assistant-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.035);
    color: var(--assistant-muted);
    font: inherit;
    font-size: var(--fs-ui);
    cursor: pointer;
}

.lani-assistant__voice-leave:hover {
    color: var(--assistant-text);
}

/* The last answer has a written part in the chat that was not said. */
.lani-assistant__voice-leave--more {
    border-color: var(--assistant-blue);
    color: var(--assistant-text);
}

/* The "…" on the face, opposite mute: voice settings. */
.lani-assistant__voice-more {
    position: absolute;
    left: 2%;
    bottom: 2%;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--assistant-border);
    border-radius: 50%;
    background: var(--assistant-card);
    color: var(--assistant-text);
    cursor: pointer;
}

.lani-assistant__voice-more:hover {
    border-color: rgba(46, 200, 255, 0.55);
}

/* ── Voice settings (js/shell/assistant-voice-settings.js): a sheet over the stage, in place ── */
.lani-assistant__voice {
    position: relative;
}

.lani-assistant__voice-settings {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px 16px 16px;
    overflow-y: auto;
    background: var(--assistant-bg);
    text-align: left;
    scrollbar-width: thin;
}

.lani-assistant__voice-settings[hidden] {
    display: none;
}

.lani-assistant__voice-settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.lani-assistant__voice-settings-head h3 {
    margin: 0;
    font-size: var(--fs-subtitle);
    font-weight: 600;
    line-height: var(--lh-tight);
}

.lani-assistant__voice-settings-close {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 1px solid var(--assistant-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.035);
    color: var(--assistant-muted);
    font: inherit;
    cursor: pointer;
}

.lani-assistant__voice-settings-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--assistant-border);
    border-radius: 10px;
    background: var(--assistant-panel);
}

.lani-assistant__voice-settings-group h4 {
    margin: 0;
    color: var(--assistant-muted);
    font-size: var(--fs-meta);
    font-weight: 600;
    letter-spacing: var(--ls-caps);
    text-transform: uppercase;
}

.lani-assistant__voice-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: var(--fs-ui);
    line-height: var(--lh-snug);
}

.lani-assistant__voice-settings-row select,
.lani-assistant__voice-settings-row input[type="range"] {
    flex: 0 1 58%;
    min-width: 0;
    accent-color: var(--assistant-blue);
}

.lani-assistant__voice-settings-row select {
    padding: 4px 6px;
    border: 1px solid var(--assistant-border);
    border-radius: 6px;
    background: var(--assistant-card);
    color: var(--assistant-text);
    font: inherit;
    font-size: var(--fs-ui);
}

/* What stands in while the persona's own voice cannot speak, and the step before leaving for Settings. */
.lani-assistant__voice-settings-standin,
.lani-assistant__voice-settings-leave {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lani-assistant__voice-settings-standin[hidden],
.lani-assistant__voice-settings-leave[hidden],
.lani-assistant__voice-settings-action[hidden] {
    display: none;
}

.lani-assistant__voice-settings-leave .lani-assistant__voice-settings-row {
    justify-content: flex-start;
}

.lani-assistant__voice-settings-action {
    flex-shrink: 0;
    padding: 5px 12px;
    border: 1px solid var(--assistant-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.035);
    color: var(--assistant-text);
    font: inherit;
    font-size: var(--fs-ui);
    cursor: pointer;
}

.lani-assistant__voice-settings-action:disabled {
    color: var(--assistant-muted);
    cursor: default;
}

.lani-assistant__voice-settings-note {
    color: var(--assistant-muted);
    font-size: var(--fs-meta);
    line-height: var(--lh-snug);
}

/* The level meter: how loud the microphone hears the room while it is tested. */
.lani-assistant__voice-settings-meter {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.lani-assistant__voice-settings-meter > span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--assistant-green);
}

@media (prefers-reduced-motion: reduce) {
    .lani-assistant__voice,
    .lani-assistant__voice[data-state="listening"] .lani-assistant__voice-figure::before {
        animation: none;
    }

    /* The thinking ring stands still and whole. */
    .lani-assistant__voice[data-state="transcribing"] .lani-assistant__voice-figure::after,
    .lani-assistant__voice[data-state="thinking"] .lani-assistant__voice-figure::after {
        animation: none;
        background: var(--assistant-voice-ring, var(--assistant-blue));
    }
}
