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

:root {
    --bg-primary: #1a1625;
    --bg-secondary: #2d2640;
    --bg-tertiary: #231e30;
    --accent: #c9956b;
    --accent-hover: #dba87e;
    --text-primary: #e8e0d4;
    --text-secondary: #9a8f84;
    --text-muted: #6b6270;
    --user-msg-bg: #3d3555;
    --assistant-msg-bg: #2a3040;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 12px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
                 "Microsoft YaHei", "Segoe UI", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.demo-home-link {
    position: fixed;
    top: max(0.75rem, env(safe-area-inset-top));
    left: max(0.75rem, env(safe-area-inset-left));
    z-index: 130;
    color: rgba(232, 224, 212, 0.82);
    font-size: 0.82rem;
    text-decoration: none;
    padding: 0.35rem 0.55rem;
    border-radius: 8px;
    background: rgba(10, 8, 16, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
}

.demo-home-link:hover {
    color: var(--accent-hover);
    background: rgba(10, 8, 16, 0.62);
}

/* ─── 加载遮罩 ─── */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 1rem;
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ─── 注册弹窗 ─── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 8, 16, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 2.5rem 2rem;
    border-radius: 20px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--shadow);
}

.modal-photo {
    margin-bottom: 1rem;
}

.modal-photo img {
    width: 96px;
    aspect-ratio: 9 / 16;
    border-radius: 12px;
    object-fit: cover;
    border: 3px solid var(--accent);
    box-shadow: 0 0 20px rgba(201, 149, 107, 0.3);
}

.modal-logo {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.modal-content h2 {
    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    letter-spacing: 1px;
}

.modal-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.2rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    width: 100%;
    padding: 0.85rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 0.8rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    width: 100%;
    padding: 0.8rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 0.65rem;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.04);
}

.credits-modal-content {
    text-align: left;
}

.credits-modal-content h2,
.credits-modal-content .modal-subtitle {
    text-align: center;
}

.credits-note {
    margin: 1.25rem 0;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.7;
}

.credits-note p + p {
    margin-top: 0.45rem;
}

.modal-home-link {
    display: inline-block;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.86rem;
    text-decoration: none;
}

.modal-home-link:hover {
    color: var(--accent-hover);
}

/* ─── 聊天容器 ─── */
#chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* ─── 视频区域 ─── */
.video-area {
    position: relative;
    --avatar-height: clamp(320px, 52dvh, 620px);
    width: min(100%, calc(var(--avatar-height) * 9 / 16));
    height: var(--avatar-height);
    aspect-ratio: 9 / 16;
    margin: 0 auto;
    background: #000;
    overflow: hidden;
    flex-shrink: 0;
}

.video-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}

.person-name {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: 500;
}

/* ─── 消息区域 ─── */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 80%;
    padding: 0.65rem 1rem;
    margin-bottom: 0.75rem;
    border-radius: var(--radius);
    font-size: 0.93rem;
    line-height: 1.6;
    word-break: break-word;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    background: var(--user-msg-bg);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--assistant-msg-bg);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.message.system {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    background: none;
    max-width: 100%;
}

/* ─── 输入区域 ─── */
.input-area {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.text-input-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.text-input-row input {
    flex: 1;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.text-input-row input:focus {
    border-color: var(--accent);
}

.text-input-row input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    padding: 0 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--accent-hover);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-record {
    width: 100%;
    padding: 0.7rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: all 0.2s;
}

.btn-record:active,
.btn-record.recording {
    background: #8b2020;
    border-color: #c0392b;
    color: #fff;
}

.btn-record.recording span::after {
    content: "...";
    animation: dots 1s infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

/* ─── 桌面端适配 ─── */
@media (min-width: 768px) {
    #chat-container {
        max-width: 480px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }

    .video-area {
        --avatar-height: clamp(360px, 58vh, 680px);
    }

    .message {
        max-width: 70%;
    }
}

/* ─── 安全区域适配（刘海屏等） ─── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
}
