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

:root {
    --bg: #0a0a0f;
    --surface: #16161f;
    --text: #e8e8ed;
    --text-dim: #6b6b7b;
    --accent: #4a9eff;
    --accent-glow: rgba(74, 158, 255, 0.3);
    --user-bg: #1e3a5f;
    --assistant-bg: #1a1a2a;
    --danger: #ff4a6a;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
}

/* Status bar */
#status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    padding-top: max(12px, env(safe-area-inset-top));
    font-size: 13px;
    color: var(--text-dim);
}

#model-name {
    font-weight: 600;
    color: var(--accent);
}

#connection-status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 6px;
    vertical-align: middle;
}

/* Chat */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    -webkit-overflow-scrolling: touch;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 16px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

.message.user {
    align-self: flex-end;
    background: var(--user-bg);
    border-bottom-right-radius: 6px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bg);
    border-bottom-left-radius: 6px;
}

.message.error {
    background: rgba(255, 74, 106, 0.15);
    color: var(--danger);
    align-self: center;
    font-size: 13px;
}

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

/* Controls */
#controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    gap: 12px;
}

#state-label {
    font-size: 14px;
    color: var(--text-dim);
    min-height: 20px;
    transition: color 0.2s;
}

#mic-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#mic-btn svg {
    width: 36px;
    height: 36px;
}

#mic-btn:active {
    transform: scale(0.95);
}

#mic-btn.listening {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 0 8px var(--accent-glow);
    animation: pulse 1.5s ease-in-out infinite;
}

#mic-btn.processing {
    background: var(--surface);
    color: var(--text-dim);
    animation: spin 1s linear infinite;
}

#stop-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

#stop-btn svg {
    width: 32px;
    height: 32px;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 8px var(--accent-glow); }
    50% { box-shadow: 0 0 0 16px rgba(74, 158, 255, 0.1); }
}

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

#clear-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
}

#clear-btn:active {
    background: var(--surface);
}

/* Scrollbar */
#chat-container::-webkit-scrollbar {
    width: 4px;
}
#chat-container::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 2px;
}

/* Login */
#login {
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#login-box {
    text-align: center;
    padding: 40px 30px;
    max-width: 320px;
    width: 100%;
}

#login-box h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--accent);
}

#login-box p {
    color: var(--text-dim);
    margin-bottom: 24px;
    font-size: 14px;
}

#login-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--text-dim);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    text-align: center;
    margin-bottom: 16px;
    outline: none;
    -webkit-appearance: none;
}

#login-input:focus {
    border-color: var(--accent);
}

#login-btn, #faceid-btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    margin-bottom: 12px;
}

#login-btn:active, #faceid-btn:active {
    opacity: 0.8;
}

#faceid-btn {
    background: var(--surface);
    border: 1px solid var(--accent);
    color: var(--accent);
}

#login-error {
    color: var(--danger);
    font-size: 13px;
    min-height: 20px;
    margin-top: 8px;
}
