:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --border: #e6e6e1;
    --text: #1a1a1a;
    --muted: #6b6b66;
    --accent: #1a73c4;
    --user: #2c5282;
    --jarvis: #1a4d3a;
    --recording: #d23838;
    --playing: #2e8c4a;
    --warn: #b87333;
    --error: #c0392b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    overscroll-behavior: contain;
}

body {
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.5px;
}

.user-info {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.875rem;
}

.health-banner,
.conn-banner {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.health-banner {
    background: rgba(184, 115, 51, 0.15);
    color: var(--warn);
    border: 1px solid rgba(184, 115, 51, 0.4);
}

.conn-banner {
    background: rgba(192, 57, 43, 0.15);
    color: var(--error);
    border: 1px solid rgba(192, 57, 43, 0.4);
}

.conversation {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.welcome {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem;
}

.welcome .hint {
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.bubble {
    max-width: min(80%, 36rem);
    padding: 0.625rem 0.875rem;
    border-radius: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--surface);
    border: 1px solid var(--border);
}

.bubble.user {
    align-self: flex-end;
    background: var(--user);
    color: white;
    border-color: transparent;
    border-bottom-right-radius: 4px;
}

.bubble.jarvis {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.bubble.error {
    align-self: stretch;
    background: rgba(192, 57, 43, 0.08);
    border-color: rgba(192, 57, 43, 0.3);
    color: var(--error);
    text-align: center;
}

.bubble.system {
    align-self: center;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.8rem;
    font-style: italic;
}

.footer {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.ptt {
    width: 100%;
    max-width: 24rem;
    padding: 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 999px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.ptt:active {
    transform: scale(0.98);
}

.ptt.state-recording {
    background: var(--recording);
    border-color: var(--recording);
    color: white;
    animation: pulse-recording 1.2s ease-in-out infinite;
}

.ptt.state-processing {
    background: var(--surface);
    color: var(--muted);
    border-color: var(--border);
    cursor: wait;
}

.ptt.state-processing .ptt-label::after {
    content: " ⏳";
}

.ptt.state-playing {
    background: var(--playing);
    border-color: var(--playing);
    color: white;
    animation: pulse-playing 1.6s ease-in-out infinite;
}

.ptt:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.stop {
    padding: 0.5rem 1.25rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--error);
    font-weight: 600;
    cursor: pointer;
}

@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(210, 56, 56, 0.6); }
    50%      { box-shadow: 0 0 0 16px rgba(210, 56, 56, 0); }
}

@keyframes pulse-playing {
    0%, 100% { box-shadow: 0 0 0 0 rgba(46, 140, 74, 0.5); }
    50%      { box-shadow: 0 0 0 12px rgba(46, 140, 74, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .ptt.state-recording,
    .ptt.state-playing {
        animation: none;
    }
}
