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

:root {
    --primary: #5b4dc7;
    --primary-light: #ede9ff;
    --bg: #f3f0ff;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #888;
    --radius: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    -webkit-text-size-adjust: 100%;
}

#app {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
}

/* ====== Header ====== */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-left, .header-right { width: 40px; }
.header-center {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 4px;
}
.header-icon { font-size: 14px; }
.header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.header-btn:active { background: rgba(0,0,0,0.05); }

/* ====== Welcome ====== */
.welcome-area {
    padding: 30px 24px 20px;
    text-align: center;
}

.welcome-avatar {
    margin-bottom: 16px;
}

.avatar-img {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 8px 24px rgba(91, 77, 199, 0.25);
    border: 3px solid white;
}

.welcome-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.sparkle { font-size: 24px; }

.welcome-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Quick questions */
.quick-questions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
    margin: 0 auto;
}

.quick-item {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    transition: transform 0.15s, box-shadow 0.15s;
}

.quick-item:active {
    transform: scale(0.98);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.quick-item span:nth-child(2) { flex: 1; text-align: left; }

.quick-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ====== Messages ====== */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}

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

.message.user { align-self: flex-end; }
.message.assistant {
    align-self: flex-start;
    flex-direction: row;
    gap: 8px;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}

.bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 15px;
    word-break: break-word;
}

.message.user .bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--card-bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.bubble.streaming::after {
    content: " ●";
    animation: blink 0.8s infinite;
    color: var(--primary);
    font-size: 12px;
}

@keyframes blink { 50% { opacity: 0.2; } }

/* ====== Status Bar ====== */
#status-bar {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.6);
}

/* ====== Input Area ====== */
#input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,0.05);
}

.input-wrapper {
    flex: 1;
    position: relative;
}

#text-input {
    width: 100%;
    background: #f0eef6;
    border: none;
    border-radius: 22px;
    padding: 11px 18px;
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: background 0.2s;
}

#text-input:focus {
    background: #e8e5f0;
}

#text-input::placeholder {
    color: #aaa;
}

#send-btn, #voice-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

#send-btn {
    background: var(--primary);
    color: white;
}
#send-btn:active { transform: scale(0.92); }

#voice-btn {
    background: #f0eef6;
    color: #666;
}
#voice-btn:active { transform: scale(0.92); }

#voice-btn.recording {
    background: #e53e3e;
    color: white;
    animation: pulse 1.5s infinite;
}

#voice-btn.connecting {
    background: #ecc94b;
    color: white;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.3); }
    50% { box-shadow: 0 0 0 10px rgba(229, 62, 62, 0); }
}

/* ====== Scrollbar ====== */
#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ====== Mobile ====== */
@media (max-width: 480px) {
    #app { max-width: 100%; }
    .message { max-width: 88%; }
    .welcome-title { font-size: 24px; }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #input-area {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}
