/* ══════════════════════════════════════════════════════════════════════════
   SONNY TALK — Standalone voice PWA
   v6.0 — emoji-free UI + wake lock always-on
   ══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg: #050810;
    --bg-card: #0d1220;
    --border: #1a2235;
    --text: #e2e8f0;
    --text-muted: #6b7a8d;
    --blue: #3b82f6;
    --blue-glow: rgba(59, 130, 246, 0.4);
    --green: #10b981;
    --green-glow: rgba(16, 185, 129, 0.4);
    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.3);
    --red: #ef4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────── */

.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 32px;
    width: 300px;
}

.login-icon {
    font-size: 48px;
    font-weight: 200;
    color: var(--blue);
    letter-spacing: 2px;
}
.login-box h2 {
    font-size: 20px;
    letter-spacing: 4px;
    color: var(--text-muted);
    font-weight: 300;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 16px;
    text-align: center;
    outline: none;
}
.login-box input:focus { border-color: var(--blue); }

.login-box button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--blue);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }


/* ── App layout ──────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
}


/* ── Waveform area ───────────────────────────────────────────── */

.face-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 20px 8px;
    position: relative;
    cursor: pointer;
    min-height: 200px;
    height: 38%;
}

.waveform-canvas {
    width: 260px;
    height: 260px;
    border-radius: 50%;
}

.face-status {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    z-index: 2;
    transition: color 0.3s;
    text-align: center;
}

/* State-based status colour */
.app[data-state="listening"] .face-status { color: var(--blue); }
.app[data-state="thinking"] .face-status { color: var(--amber); }
.app[data-state="speaking"] .face-status { color: var(--green); }


/* ── Transcript bar ──────────────────────────────────────────── */

.transcript-bar {
    flex-shrink: 0;
    padding: 8px 20px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.transcript-text {
    font-size: 15px;
    color: var(--text);
    text-align: center;
    max-width: 90%;
    line-height: 1.4;
    opacity: 0.9;
}

.transcript-text:empty { display: none; }

.transcript-text .interim {
    color: var(--text-muted);
    font-style: italic;
}


/* ── Conversation ────────────────────────────────────────────── */

.conversation {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

.conversation::-webkit-scrollbar { width: 4px; }
.conversation::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    animation: msgFade 0.3s ease;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

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

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

.msg-assistant {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg-error {
    align-self: center;
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
    font-size: 13px;
}

.msg-header {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.6;
    margin-bottom: 3px;
}

.msg-user .msg-header { text-align: right; }

/* Markdown basics inside messages */
.msg-assistant strong { font-weight: 700; }
.msg-assistant em { font-style: italic; }
.msg-assistant code {
    background: rgba(255,255,255,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}
.msg-assistant pre {
    background: rgba(0,0,0,0.3);
    padding: 8px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    margin: 6px 0;
}
.msg-assistant ul, .msg-assistant ol {
    margin: 4px 0;
    padding-left: 18px;
}
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3, .msg-assistant h4 {
    margin-top: 8px;
    margin-bottom: 4px;
}
.msg-assistant table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 6px 0;
}
.msg-assistant th, .msg-assistant td {
    padding: 4px 8px;
    border: 1px solid var(--border);
    text-align: left;
}
.msg-assistant th { background: rgba(255,255,255,0.05); }


/* ── Bottom controls ─────────────────────────────────────────── */

.controls {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 12px 16px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    background: var(--bg);
}

.mic-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 3px solid var(--blue);
    background: transparent;
    color: var(--blue);
    font-size: 26px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: all 0.3s;
}

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

.mic-btn.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.mic-ring {
    position: absolute;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 2px solid var(--blue);
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}

.mic-ring.active {
    animation: ringExpand 1.5s ease-out infinite;
}

@keyframes ringExpand {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.8); opacity: 0; }
}

.ctrl-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ctrl-btn:hover { border-color: var(--blue); color: var(--text); }

/* SVG icon sizing inside control buttons */
.ctrl-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.mic-btn svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}


/* ── Settings drawer ─────────────────────────────────────────── */

.settings-drawer {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.settings-content {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 480px;
    padding: 20px 24px 32px;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 600;
}

.settings-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
}

.setting-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
    cursor: pointer;
}

.setting-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 16px;
    margin-bottom: 8px;
}

.agent-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.agent-chip {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.agent-chip.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

.settings-footer {
    margin-top: 20px;
    text-align: center;
}

.settings-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}
.settings-link:hover { color: var(--text); }


/* ── Responsive ──────────────────────────────────────────────── */

@media (min-height: 700px) {
    .face-area { height: 40%; }
    .waveform-canvas { width: 280px; height: 280px; }
}

@media (min-height: 850px) {
    .face-area { height: 42%; padding-top: 32px; }
    .waveform-canvas { width: 300px; height: 300px; }
}

@media (max-height: 550px) {
    .face-area { height: 30%; min-height: 150px; padding: 8px 20px 4px; }
    .waveform-canvas { width: 180px; height: 180px; }
    .face-status { font-size: 12px; margin-top: 6px; }
    .mic-btn { width: 56px; height: 56px; font-size: 22px; }
    .mic-btn svg { width: 22px; height: 22px; }
    .mic-ring { width: 56px; height: 56px; }
}
