* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0b0f1a;
    --bg-2: #11182a;
    --fg: #e8edf6;
    --fg-dim: #95a0b8;
    --accent: #7c5cff;
    --accent-2: #22d3ee;
    --ok: #22c55e;
    --warn: #eab308;
    --err: #ef4444;
    --ring: rgba(124, 92, 255, .45);
    --card: rgba(255, 255, 255, .04);
    --border: rgba(255, 255, 255, .08);
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 99px;
    color: var(--fg-dim);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    transition: background .2s ease, color .2s ease, transform .15s ease;
}

.back-btn:hover {
    background: rgba(255,255,255,.08);
    color: var(--fg);
    transform: translateX(-2px);
}

.stage {
    position: relative;
    height: 100dvh;
    width: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto;
    isolation: isolate;
}

.backdrop {
    position: absolute;
    inset: -20%;
    z-index: -1;
    background:
        radial-gradient(40% 40% at 20% 10%, rgba(124, 92, 255, .35), transparent 60%),
        radial-gradient(35% 35% at 85% 80%, rgba(34, 211, 238, .28), transparent 60%),
        radial-gradient(60% 60% at 50% 50%, rgba(20, 30, 60, .4), transparent 70%),
        var(--bg);
    filter: blur(40px) saturate(120%);
}

/* Topbar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.2px;
}

.logo-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 18px var(--ring);
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 13px;
    color: var(--fg-dim);
    backdrop-filter: blur(10px);
}

.status-pill .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--warn);
    box-shadow: 0 0 10px currentColor;
    transition: all .25s ease;
}

.status-pill[data-state="ok"] .dot { background: var(--ok); }
.status-pill[data-state="err"] .dot { background: var(--err); }
.status-pill[data-state="speaking"] .dot {
    background: var(--accent);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.6); opacity: .6; }
}

/* Main */
.main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 20px;
    min-height: 0;
}

.avatar-ring {
    position: relative;
    width: min(42vh, 340px);
    aspect-ratio: 1;
    border-radius: 50%;
    padding: 6px;
    box-shadow: 0 30px 80px -20px var(--ring);
    isolation: isolate;
}

/* Static colorful border */
.avatar-ring::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
    z-index: 0;
}

/* Glow halo behind everything */
.avatar-ring::after {
    content: "";
    position: absolute;
    inset: -14px;
    border-radius: 50%;
    background: radial-gradient(50% 50% at 50% 50%, var(--ring), transparent 70%);
    opacity: .5;
    filter: blur(14px);
    z-index: -1;
}

.stage[data-speaking="true"] .avatar-ring {
    box-shadow: 0 30px 100px -15px rgba(124, 92, 255, .8);
}
.stage[data-speaking="true"] .avatar-ring::after {
    opacity: 1;
    animation: glow 0.8s ease-in-out infinite alternate;
}

@keyframes glow { to { opacity: .3; } }

.avatar-wrap {
    position: relative;
    z-index: 1;
    width: 100%; height: 100%;
    border-radius: 50%;
    overflow: hidden;
    background: #000;
    isolation: isolate;
    contain: paint;
    transform: translateZ(0);
}

.avatar-wrap img,
.avatar-wrap video {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    max-width: 100%; max-height: 100%;
    object-fit: cover;
    transition: opacity .4s ease;
    border-radius: 50%;
    clip-path: circle(50% at 50% 50%);
}

.avatar-wrap video { opacity: 0; }
.avatar-wrap[data-live="true"] video { opacity: 1; }
.avatar-wrap[data-live="true"] img { opacity: 0; }

.avatar-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .55);
    color: var(--fg);
    font-size: 13px;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
}

.avatar-overlay[data-show="true"] { opacity: 1; }

.spinner {
    width: 32px; height: 32px;
    border: 3px solid rgba(255, 255, 255, .18);
    border-top-color: var(--accent-2);
    border-radius: 50%;
    animation: rot .8s linear infinite;
}

@keyframes rot { to { transform: rotate(360deg); } }

.meta {
    text-align: center;
}

.meta h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.meta p {
    font-size: 14px;
    color: var(--fg-dim);
    margin-top: 4px;
}

.speaking-hint {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 13px;
    color: var(--fg-dim);
    backdrop-filter: blur(10px);
    min-height: 40px;
}

.wave { display: inline-flex; gap: 3px; align-items: flex-end; height: 14px; }
.wave i {
    display: block;
    width: 3px;
    height: 4px;
    background: var(--fg-dim);
    border-radius: 2px;
    transition: background .2s ease;
}

.stage[data-user-speaking="true"] .wave i {
    background: var(--accent-2);
    animation: wave 0.9s ease-in-out infinite;
}

.wave i:nth-child(1) { animation-delay: 0s; }
.wave i:nth-child(2) { animation-delay: .1s; }
.wave i:nth-child(3) { animation-delay: .2s; }
.wave i:nth-child(4) { animation-delay: .3s; }
.wave i:nth-child(5) { animation-delay: .4s; }

@keyframes wave {
    0%, 100% { height: 4px; }
    50% { height: 14px; }
}

.transcript {
    width: min(640px, 90%);
    max-height: 80px;
    overflow: hidden;
    text-align: center;
    font-size: 15px;
    color: var(--fg-dim);
    transition: opacity .3s ease;
    line-height: 1.5;
}

.transcript .speaker {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--fg-dim);
    opacity: .6;
    margin-bottom: 4px;
    display: block;
}

.transcript .text {
    color: var(--fg);
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    border: 0;
    border-radius: 99px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .25s ease, background .2s ease;
    color: #fff;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 24px -6px var(--ring);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 32px -8px var(--ring); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
    background: rgba(239, 68, 68, .15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, .3);
}

.btn-ghost:hover { background: rgba(239, 68, 68, .25); }

.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

@media (max-width: 480px) {
    .topbar { padding: 14px 16px; }
    .avatar-ring { width: 68vw; }
    .meta h1 { font-size: 20px; }
    .btn { padding: 12px 22px; font-size: 14px; }
}
