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

:root {
    --bg-primary: #313b5d;
    --bg-surface: #151929;
    --bg-elevated: #1c2137;
    --border: #2a2f45;
    --text-primary: #e8eaed;
    --text-secondary: #8b92a8;
    --text-muted: #5c637a;
    --accent: #6c8cff;
    --accent-glow: rgba(108, 140, 255, 0.35);
    --user-msg: #3a5bc7;
    --agent-msg: #1c2137;
    --error-bg: #3a1525;
    --error-text: #f5a0a0;
    --listening: #6c8cff;
    --thinking: #c78dff;
    --speaking: #5ce0b5;
    --connecting: #ffb347;
}

body {
    display: flex;
    justify-content: center;
    min-height: 100dvh;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */

#app {
    width: 100%;
    max-width: 600px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 2rem 1.25rem 1.5rem;
    gap: 1.25rem;
}

/* ---- Header ---- */

header {
    text-align: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ---- Onboarding ---- */

#onboarding {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    transition: opacity 0.4s ease, max-height 0.5s ease, padding 0.4s ease, margin 0.4s ease;
    overflow: hidden;
}

#onboarding.hidden {
    opacity: 0;
    max-height: 0;
    padding: 0 1.5rem;
    margin: 0;
    border: none;
    pointer-events: none;
}

.onboarding-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.capabilities {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.capability {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.cap-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-elevated);
    color: var(--accent);
    flex-shrink: 0;
}

/* ---- Transcript log ---- */

#transcript-log {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: 14px;
    border: 1px solid var(--border);
    scroll-behavior: smooth;
}

#transcript-log:empty {
    display: none;
}

#transcript-log::-webkit-scrollbar {
    width: 4px;
}

#transcript-log::-webkit-scrollbar-track {
    background: transparent;
}

#transcript-log::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.msg {
    padding: 0.65rem 1rem;
    border-radius: 12px;
    line-height: 1.55;
    max-width: 85%;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 0.9rem;
    animation: msg-in 0.25s ease-out;
}

@keyframes msg-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg.user {
    align-self: flex-end;
    background: var(--user-msg);
    color: #dbeafe;
    border-bottom-right-radius: 4px;
}

.msg.agent {
    align-self: flex-start;
    background: var(--agent-msg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.msg.error {
    align-self: flex-start;
    background: var(--error-bg);
    color: var(--error-text);
    font-size: 0.85rem;
}

.msg.streaming::after {
    content: "\2589";
    animation: blink 0.6s steps(2) infinite;
    color: var(--accent);
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
}

/* ---- Controls area ---- */

#controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.5rem;
    flex-shrink: 0;
}

/* ---- State orb ---- */

#state-orb {
    position: relative;
    width: 88px;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.orb-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: border-color 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
    opacity: 0;
}

/* ---- Voice button ---- */

#voice-btn {
    position: relative;
    z-index: 2;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#voice-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.05);
}

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

.hidden {
    display: none !important;
}

/* ---- Idle state ---- */

.state-idle .orb-ring { opacity: 0; }

/* ---- Connecting state ---- */

.state-connecting #voice-btn {
    border-color: var(--connecting);
    color: var(--connecting);
}

.state-connecting .orb-ring-1 {
    opacity: 0.4;
    border-color: var(--connecting);
    animation: spin-slow 3s linear infinite;
}

/* ---- Listening state ---- */

.state-listening #voice-btn {
    border-color: var(--listening);
    color: var(--listening);
    background: rgba(108, 140, 255, 0.1);
}

.state-listening .orb-ring-1 {
    opacity: 0.6;
    border-color: var(--listening);
    border-top-color: transparent;
    border-right-color: transparent;
    animation: spin-slow 4s linear infinite;
}

.state-listening .orb-ring-2 {
    opacity: 0.3;
    border-color: var(--listening);
    border-bottom-color: transparent;
    border-left-color: transparent;
    animation: spin-slow 6s linear infinite reverse;
    inset: -6px;
}

.state-listening .orb-ring-3 {
    opacity: 0;
}

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

/* ---- Thinking state ---- */

.state-thinking #voice-btn {
    border-color: var(--thinking);
    color: var(--thinking);
    background: rgba(199, 141, 255, 0.08);
}

.state-thinking .orb-ring-1 {
    opacity: 0.7;
    border-color: var(--thinking);
    border-top-color: transparent;
    animation: spin-slow 1.5s linear infinite;
}

.state-thinking .orb-ring-2 {
    opacity: 0.4;
    border-color: var(--thinking);
    border-bottom-color: transparent;
    border-right-color: transparent;
    animation: spin-slow 2.2s linear infinite reverse;
    inset: -7px;
}

.state-thinking .orb-ring-3 {
    opacity: 0.2;
    border-color: var(--thinking);
    border-left-color: transparent;
    border-top-color: transparent;
    animation: spin-slow 3s linear infinite;
    inset: -14px;
}

/* ---- Speaking state ---- */

.state-speaking #voice-btn {
    border-color: var(--speaking);
    color: var(--speaking);
    background: rgba(92, 224, 181, 0.08);
}

.state-speaking .orb-ring-1 {
    opacity: 0.6;
    border-color: var(--speaking);
    animation: pulse-ring-speak 1.8s ease-in-out infinite;
}

.state-speaking .orb-ring-2 {
    opacity: 0.35;
    border-color: var(--speaking);
    animation: pulse-ring-speak 1.8s ease-in-out 0.3s infinite;
    inset: -6px;
}

.state-speaking .orb-ring-3 {
    opacity: 0.15;
    border-color: var(--speaking);
    animation: pulse-ring-speak 1.8s ease-in-out 0.6s infinite;
    inset: -12px;
}

@keyframes pulse-ring-speak {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.12);
        opacity: 0.2;
    }
}

/* ---- Status text ---- */

#voice-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    min-height: 1.2em;
    transition: color 0.3s ease;
}

.state-listening #voice-status { color: var(--listening); }
.state-thinking #voice-status { color: var(--thinking); }
.state-speaking #voice-status { color: var(--speaking); }

.state-label {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    min-height: 1em;
    transition: color 0.3s ease;
}

.state-listening .state-label { color: var(--listening); }
.state-thinking .state-label { color: var(--thinking); }
.state-speaking .state-label { color: var(--speaking); }

/* ---- Responsive ---- */

@media (max-height: 700px) {
    #onboarding { padding: 1rem 1.25rem; }
    .capability { font-size: 0.85rem; }
}

@media (max-width: 400px) {
    #app { padding: 1.5rem 1rem 1rem; }
    h1 { font-size: 1.3rem; }
}
