:root {
    --bg: #0e1420;
    --bg-panel: #141b2b;
    --bg-card: #1a2236;
    --border: #2a3550;
    --border-strong: #3a4870;
    --text-primary: #eef1f8;
    --text-secondary: #9aa7c7;
    --text-muted: #64709a;
    --accent: #5b8cff;
    --accent-strong: #7ea2ff;
    --danger: #ff6b6b;
    --success: #3ddc97;
    --radius-md: 12px;
    --radius-lg: 20px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
}

/* ============================================================
   MÀN HÌNH CHÀO
============================================================= */
.welcome-screen {
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    background: radial-gradient(
            circle at 20% 20%,
            rgba(91, 140, 255, 0.12),
            transparent 45%
        ),
        radial-gradient(
            circle at 80% 80%,
            rgba(61, 220, 151, 0.08),
            transparent 45%
        ),
        var(--bg);
}

.welcome-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    text-align: center;
}

.welcome-badge {
    display: inline-block;
    font-size: 12px;
    letter-spacing: 0.04em;
    color: var(--accent-strong);
    background: rgba(91, 140, 255, 0.12);
    border: 1px solid rgba(91, 140, 255, 0.3);
    border-radius: 999px;
    padding: 6px 14px;
    margin-bottom: 20px;
}

.welcome-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin: 0 0 12px;
    line-height: 1.35;
}

.welcome-card p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.6;
    margin: 0 0 28px;
}

.start-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 600;
    transition: background 0.15s ease, transform 0.1s ease;
}

.start-btn:hover {
    background: var(--accent-strong);
}
.start-btn:active {
    transform: scale(0.98);
}

.start-btn-icon {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffffff;
}

.permission-error {
    margin-top: 16px;
    color: var(--danger);
    font-size: 13px;
    line-height: 1.5;
}

.welcome-notes {
    text-align: left;
    margin: 28px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.welcome-notes li {
    font-size: 12.5px;
    color: var(--text-muted);
    padding-left: 18px;
    position: relative;
    line-height: 1.5;
}

.welcome-notes li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border-strong);
}

/* ============================================================
   ỨNG DỤNG CHÍNH
============================================================= */
.app-screen {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
    flex-wrap: wrap;
}

.topbar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.is-connecting {
    background: #f5b942;
    animation: pulse 1.2s infinite ease-in-out;
}
.status-dot.is-connected {
    background: var(--success);
}
.status-dot.is-error {
    background: var(--danger);
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ghost-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    font-size: 13px;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.ghost-btn:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.ghost-btn[aria-pressed="false"] {
    color: var(--danger);
    border-color: rgba(255, 107, 107, 0.4);
}

.end-btn {
    background: rgba(255, 107, 107, 0.12);
    color: var(--danger);
    border: 1px solid rgba(255, 107, 107, 0.35);
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
}

.end-btn:hover {
    background: rgba(255, 107, 107, 0.2);
}

/* ---- Khu vực sân khấu: nơi đổi giữa 2 trạng thái ---- */
.stage {
    flex: 1;
    min-height: 0;
    position: relative;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.avatar-frame {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.35s ease, height 0.35s ease, position 0.35s ease,
        top 0.35s ease, left 0.35s ease, border-radius 0.35s ease,
        box-shadow 0.35s ease;
}

.avatar-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.avatar-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.avatar-placeholder-ring {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

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

.speaking-indicator {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(61, 220, 151, 0.15);
    color: var(--success);
    border: 1px solid rgba(61, 220, 151, 0.4);
    border-radius: 999px;
    font-size: 12px;
    padding: 4px 12px;
}

/* Trạng thái 1 (mặc định): avatar chiếm trung tâm, kích thước lớn */
.stage--default .avatar-frame {
    width: min(400px, 90vw);
    /* height: min(560px, 70vh); */
}

/* Trạng thái 2 (FAQ): avatar thu nhỏ về góc trên trái */
.stage--faq {
    align-items: stretch;
    justify-content: flex-start;
}

.stage--faq .avatar-frame {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 200px;
    height: 200px;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 2;
}

@media (min-width: 720px) {
    .stage--faq .avatar-frame {
        width: 300px;
        height: 300px;
    }
}

.faq-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    padding-left: 240px;
}

@media (min-width: 720px) {
    .faq-panel {
        padding-left: 340px;
    }
}

.faq-panel-header h2 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 600;
}

.faq-panel-header p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13.5px;
}

.faq-gif-wrap {
    flex: 1;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
}

.faq-gif {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.transcript-bar {
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
    padding: 14px 20px;
    text-align: center;
}

.transcript-bar p {
    margin: 0;
    font-size: 13.5px;
    color: var(--text-secondary);
}

@media (max-width: 560px) {
    .welcome-card {
        padding: 32px 22px;
    }
    .topbar {
        padding: 12px 14px;
    }
    .stage {
        padding: 14px;
    }
    .faq-panel {
        padding: 16px;
        padding-left: 232px;
    }
}
