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

:root {
    --bg:        #020408;
    --text:      #475569;
    --text-dim:  #1e293b;
    --idle:      #1e3a5f;
    --listen:    #4fc3f7;
    --speak:     #c084fc;
    --btn-size:  clamp(72px, 20vmin, 100px);
}

html, body {
    width: 100%; height: 100%;
    background: radial-gradient(ellipse at 50% 42%, #0b1624 0%, var(--bg) 68%);
    color: var(--text);
    font-family: ui-monospace, "SF Mono", "Fira Code", monospace;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Background grid ── */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(30,41,59,0.18) 1px, transparent 1px),
        linear-gradient(90deg, rgba(30,41,59,0.18) 1px, transparent 1px);
    background-size: 44px 44px;
    pointer-events: none;
    z-index: 0;
}

/* ── Layout ── */
main {
    position: relative;
    z-index: 1;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.6rem, 2vh, 1.4rem);
    padding: 1rem;
}

/* ── Header ── */
.app-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-icon {
    width: clamp(32px, 8vmin, 46px);
    height: clamp(32px, 8vmin, 46px);
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 12px rgba(79,195,247,0.15);
    flex-shrink: 0;
}

.header-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.header-name {
    font-size: clamp(1rem, 3.5vmin, 1.35rem);
    font-weight: 700;
    letter-spacing: 0.25em;
    color: #94a3b8;
    line-height: 1;
}

.header-sub {
    font-size: clamp(0.55rem, 1.6vmin, 0.65rem);
    letter-spacing: 0.18em;
    color: var(--text-dim);
    text-transform: uppercase;
    line-height: 1;
}

/* ── Visualizer ── */
.viz-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

canvas { display: block; }

/* ── Status ── */
#status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: clamp(0.62rem, 1.8vmin, 0.72rem);
    letter-spacing: 0.13em;
    text-transform: uppercase;
    color: var(--text);
    transition: color 0.4s;
    min-height: 1em;
}

.status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--idle);
    flex-shrink: 0;
    transition: background 0.4s, box-shadow 0.4s;
}

/* ── Button + rings ── */
.btn-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--btn-size) * 3);
    height: calc(var(--btn-size) * 3);
    flex-shrink: 0;
}

.ring {
    position: absolute;
    width: var(--btn-size);
    height: var(--btn-size);
    border-radius: 50%;
    border: 1.5px solid transparent;
    pointer-events: none;
    opacity: 0;
}

#btn {
    position: relative;
    z-index: 2;
    width: var(--btn-size);
    height: var(--btn-size);
    border-radius: 50%;
    border: 2px solid var(--idle);
    background: rgba(14, 30, 54, 0.6);
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.3s, color 0.3s, background 0.3s, box-shadow 0.3s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    backdrop-filter: blur(4px);
}

#btn svg {
    width: 38%;
    height: 38%;
    pointer-events: none;
    transition: transform 0.2s;
}

#btn:active svg { transform: scale(0.88); }

/* ── State: disconnected / connecting ── */
[data-state="connecting"] #status,
[data-state="connecting"] .header-name {
    animation: text-pulse 1.2s ease-in-out infinite;
}

/* ── State: recording ── */
[data-state="recording"] #btn {
    border-color: var(--listen);
    color: var(--listen);
    background: rgba(79,195,247,0.08);
    box-shadow: 0 0 28px rgba(79,195,247,0.2), inset 0 0 12px rgba(79,195,247,0.06);
}

[data-state="recording"] #status { color: var(--listen); }

[data-state="recording"] .status-dot {
    background: var(--listen);
    box-shadow: 0 0 8px var(--listen);
    animation: dot-pulse 1s ease-in-out infinite;
}

[data-state="recording"] .ring {
    border-color: var(--listen);
    animation: ring-expand 1.8s ease-out infinite;
    animation-delay: var(--delay);
    opacity: 1;
}

/* ── State: speaking / processing ── */
[data-state="speaking"] #btn,
[data-state="processing"] #btn {
    border-color: var(--speak);
    color: var(--speak);
    background: rgba(192,132,252,0.08);
    box-shadow: 0 0 28px rgba(192,132,252,0.2), inset 0 0 12px rgba(192,132,252,0.06);
}

[data-state="speaking"] #status,
[data-state="processing"] #status { color: var(--speak); }

[data-state="speaking"] .status-dot,
[data-state="processing"] .status-dot {
    background: var(--speak);
    box-shadow: 0 0 8px var(--speak);
}

[data-state="speaking"] .ring {
    border-color: var(--speak);
    animation: ring-expand 2.2s ease-out infinite;
    animation-delay: var(--delay);
    opacity: 1;
}

[data-state="processing"] #btn { opacity: 0.6; }

/* ── State: ready ── */
[data-state="ready"] #btn {
    border-color: var(--idle);
    color: #64748b;
}

[data-state="ready"] .header-icon {
    box-shadow: 0 0 16px rgba(79,195,247,0.2);
}

/* ── Animations ── */
@keyframes ring-expand {
    0%   { transform: scale(1);   opacity: 0.65; }
    100% { transform: scale(3);   opacity: 0; }
}

@keyframes text-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

@keyframes dot-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.5); }
}
