/* Lip-synced avatar. --mouth (0..1) is set on #avatar by audio.js while audio plays. */

.avatar-stage {
    flex-shrink: 0; display: flex; align-items: center; gap: 16px;
    padding: 10px 20px;
    background: linear-gradient(180deg, #f8fbff, #eef4ff);
    border-bottom: 1px solid var(--border);
}

.avatar {
    --mouth: 0;
    flex-shrink: 0; width: 92px; height: 92px; border-radius: 50%;
    box-shadow: 0 4px 14px rgba(37, 99, 235, .22);
    transition: box-shadow .3s ease;
}
.avatar.speaking { box-shadow: 0 0 0 4px rgba(59, 130, 246, .25), 0 4px 18px rgba(37, 99, 235, .35); }
.avatar-svg { width: 100%; height: 100%; display: block; }

/* mouth */
.avatar .smile { opacity: calc(1 - var(--mouth) * 4); }
.avatar .mouth-open {
    transform-box: fill-box; transform-origin: 50% 30%;
    transform: scaleY(calc(0.04 + var(--mouth) * 1.15));
    opacity: min(1, calc(var(--mouth) * 8));
}

/* head: idle blink, gentle sway while speaking, slight tilt while thinking */
.avatar .head { transform-origin: 100px 150px; transition: transform .35s ease; }
.avatar.thinking .head { transform: rotate(-3deg); }
.avatar.speaking .head { animation: av-sway 1.6s ease-in-out infinite; }
.avatar .eyes { transform-box: fill-box; transform-origin: center; animation: av-blink 5s infinite; }

@keyframes av-blink { 0%, 94%, 100% { transform: scaleY(1); } 96.5% { transform: scaleY(.08); } }
@keyframes av-sway { 0%, 100% { transform: rotate(-1.2deg); } 50% { transform: rotate(1.2deg); } }

/* caption */
.avatar-caption { min-width: 0; }
.avatar-name { font-weight: 600; font-size: 15px; }
.avatar-status { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.avatar-status .spinner { margin: 0; width: 14px; height: 14px; }

.wave { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.wave i { width: 3px; height: 100%; border-radius: 2px; background: var(--primary); animation: av-wave 0.9s ease-in-out infinite; transform-origin: bottom; }
.wave i:nth-child(2) { animation-delay: .15s; }
.wave i:nth-child(3) { animation-delay: .3s; }
@keyframes av-wave { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

@media (max-width: 640px) {
    .avatar-stage { padding: 8px 12px; gap: 12px; }
    .avatar { width: 68px; height: 68px; }
}

/* the mouth still follows the audio (it conveys speech); decorative motion is turned off */
@media (prefers-reduced-motion: reduce) {
    .avatar .head, .avatar .eyes, .wave i { animation: none; }
}
.avatar-shell {
    position: fixed;
    inset: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #101010;
}

.avatar-header {
    flex: none;
    padding-top: env(safe-area-inset-top);
    background: #fff;
}

    .avatar-header .brand-bar {
        min-height: 64px;
    }

.live-avatar-page {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    box-sizing: border-box;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow: hidden;
    background: #101010;
    color: white;
}

.live-avatar-page video {
    grid-area: 1 / 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.live-avatar-page audio {
    position: absolute;
}

.live-avatar-controls {
    grid-area: 1 / 1;
    z-index: 1;
    box-sizing: border-box;
    width: min(100%, 24rem);
    max-height: 100%;
    padding: clamp(1rem, 4vw, 1.5rem);
    overflow: auto;
    text-align: center;
}

.live-avatar-intake {
    display: grid;
    gap: .5rem;
    padding: clamp(1rem, 5vw, 1.5rem);
    border-radius: 1rem;
    background: #fff;
    color: #102942;
    text-align: left;
}

.live-avatar-intake h1 {
    margin: 0 0 .5rem;
    font-size: 1.35rem;
    line-height: 1.25;
}

.live-avatar-intake label {
    font-weight: 600;
}

.live-avatar-intake input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    box-sizing: border-box;
    margin-bottom: .4rem;
    padding: .5rem .75rem;
    border: 1px solid #8294a5;
    border-radius: .5rem;
    color: inherit;
    font: inherit;
    font-size: 1rem;
}

.live-avatar-controls .live-avatar-intake button {
    width: 100%;
    background: #174a82;
    color: white;
    font-weight: 600;
}

.live-avatar-intake button:disabled {
    opacity: .65;
}

.live-avatar-controls p {
    margin: .75rem 0 0;
}

.live-avatar-controls p:empty {
    display: none;
}

.live-avatar-controls button {
    min-height: 48px;
    max-width: 100%;
    padding: .75rem 1rem;
    border: 0;
    border-radius: .5rem;
    background: white;
    color: #101010;
    font: inherit;
}

@media (max-width: 600px) and (orientation: portrait) {
    .live-avatar-page video {
        position: absolute;
        inset: 0;
        object-fit: cover;
        object-position: center;
    }

    .live-avatar-controls button {
        width: 100%;
    }
}
/* Compact header on the avatar page */
.avatar-header .wordmark img {
    max-height: 40px;
}

/* Bottom stack: transcript panel above the action buttons */
.avatar-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    padding: 0 max(1rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    pointer-events: none;
}

    .avatar-bottom > *,
    .avatar-bar > *,
    .avatar-dock > * {
        pointer-events: auto;
    }

.avatar-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    pointer-events: none;
}

.avatar-dock {
    display: flex;
    align-items: center;
    gap: .6rem;
    pointer-events: none;
}

    .avatar-dock[hidden],
    .avatar-skip[hidden] {
        display: none;
    }

.avatar-action,
.avatar-skip,
.transcript-toggle {
    min-height: 48px;
    padding: .6rem 1.2rem;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

    .avatar-action:focus-visible,
    .avatar-skip:focus-visible,
    .transcript-toggle:focus-visible {
        outline: 2px solid #08786f;
        outline-offset: 3px;
    }

.avatar-action {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    background: #fff;
    color: #174a82;
}

    .avatar-action .icon {
        display: none;
        width: 1.35rem;
        height: 1.35rem;
        flex: none;
    }

        .avatar-action .icon:not(.icon-processing) {
            fill: currentColor;
        }

    .avatar-action[data-state="ready"] .icon-ready,
    .avatar-action[data-state="listening"] .icon-listening,
    .avatar-action[data-state="speaking"] .icon-speaking,
    .avatar-action[data-state="paused"] .icon-paused,
    .avatar-action[data-state="processing"] .icon-processing {
        display: block;
    }

    .avatar-action[data-state="listening"] {
        background: #b42318;
        color: #fff;
    }

    .avatar-action[data-state="processing"] .icon-processing {
        animation: avatar-spin 1s linear infinite;
    }

    .avatar-action:disabled {
        opacity: .8;
        cursor: default;
    }

@keyframes avatar-spin {
    to {
        transform: rotate(360deg);
    }
}

.avatar-skip {
    border: 1px solid rgba(255, 255, 255, .55);
    background: rgba(16, 16, 16, .6);
    color: #fff;
    box-shadow: none;
}

.transcript-toggle {
    background: #fff;
    color: #174a82;
}

    .transcript-toggle[aria-expanded="true"] {
        background: #174a82;
        color: #fff;
    }

/* Transcript panel */
.transcript-panel {
    align-self: flex-end;
    display: flex;
    flex-direction: column;
    width: min(24rem, 100%);
    height: min(24rem, 42dvh);
    overflow: hidden;
    border-radius: 1rem;
    background: rgba(255, 255, 255, .96);
    color: #102942;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}

    .transcript-panel.is-large {
        height: min(34rem, 68dvh);
    }

.transcript-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .5rem .75rem .5rem 1rem;
    border-bottom: 1px solid #dbe5ee;
    font-weight: 600;
}

.transcript-size {
    min-height: 32px;
    padding: .2rem .8rem;
    border: 1px solid #b4c3d1;
    border-radius: 999px;
    background: #fff;
    color: #174a82;
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
}

/* column-reverse keeps the newest words in view as the answer is revealed */
.transcript-scroll {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column-reverse;
    overflow-y: auto;
}

.transcript-lines {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
}

.transcript-empty {
    margin: 0;
    padding: 1rem;
    color: #5b7186;
    font-size: 14px;
    text-align: center;
}

.transcript-wait {
    color: #5b7186;
    letter-spacing: .15em;
}

/* Phones: a short sheet so the avatar's face stays visible */
@media (max-width: 600px) {
    .transcript-panel {
        align-self: stretch;
        width: auto;
        height: clamp(6.5rem, 22dvh, 12rem);
    }

        .transcript-panel.is-large {
            height: min(58dvh, 26rem);
        }

    .avatar-action,
    .avatar-skip,
    .transcript-toggle {
        padding: .5rem .9rem;
        font-size: .9rem;
    }
}

/* Phones in landscape: a narrow panel on the right */
@media (max-height: 500px) and (orientation: landscape) {
    .transcript-panel {
        width: min(22rem, 45%);
        height: min(11rem, 40dvh);
    }

        .transcript-panel.is-large {
            height: calc(100dvh - 11rem);
        }
}