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

:root {
    --bg: #09090b;
    --surface: #111113;
    --surface2: #1a1a1f;
    --surface3: #232329;
    --border: rgba(255,255,255,0.06);
    --text: #ececf1;
    --text-dim: #71717a;
    --text-muted: #52525b;
    --accent: #7CB342;
    --accent-dim: rgba(124,179,66,0.15);
    --accent-glow: rgba(124,179,66,0.3);
    --user-bubble: rgba(124,179,66,0.08);
    --user-border: rgba(124,179,66,0.15);
    --assistant-bubble: rgba(255,255,255,0.03);
    --assistant-border: rgba(255,255,255,0.06);
    --danger: #ef5350;
    --radius: 16px;
    --radius-sm: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

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

/* ── Header ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    flex-shrink: 0;
    z-index: 10;
    background: transparent;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { transform: scale(0.92); }

/* ── Settings Drawer ── */
.drawer {
    position: fixed;
    inset: 0;
    z-index: 100;
    transition: opacity 0.25s;
}

.drawer.hidden { display: none; }

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.drawer-content {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
}

.drawer-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    margin-top: 12px;
    font-weight: 500;
}

#model-select,
#stt-engine-select {
    width: 100%;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    transition: border-color 0.15s;
}

#model-select:focus,
#stt-engine-select:focus { border-color: var(--accent); }

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 28px;
    accent-color: var(--accent);
    cursor: pointer;
    touch-action: pan-x;
}

.slider-row span {
    min-width: 32px;
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ── Conversation ── */
main#conversation {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

main#conversation::-webkit-scrollbar { width: 3px; }
main#conversation::-webkit-scrollbar-track { background: transparent; }
main#conversation::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}

.welcome p { color: var(--text-muted); font-size: 0.85rem; }

.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    line-height: 1.55;
    font-size: 0.9rem;
    animation: msgIn 0.25s ease;
    white-space: pre-wrap;
    word-wrap: break-word;
}

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

.msg.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border: 1px solid var(--user-border);
    border-bottom-right-radius: 4px;
}

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

.msg .role-label {
    display: block;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-weight: 500;
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 0.7s step-end infinite;
    vertical-align: text-bottom;
}

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

/* ── Orb Area ── */
.orb-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px 4px;
    gap: 8px;
}

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

.orb-ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: all 0.4s ease;
    pointer-events: none;
}

.orb-btn {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

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

.orb-icon {
    width: 52px;
    height: 52px;
    opacity: 0.5;
    transition: opacity 0.3s;
    filter: grayscale(0.5);
}

/* Mic ON idle state */
.orb-btn.mic-on {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: 0 0 30px var(--accent-dim);
}

.orb-btn.mic-on .orb-icon {
    opacity: 0.8;
    filter: none;
}

.orb-btn.mic-on ~ .orb-ring {
    border: 0;
}

/* Listening (voice detected) */
.orb-btn.listening {
    border-color: var(--accent);
    background: rgba(124,179,66,0.2);
    box-shadow: 0 0 40px var(--accent-glow), 0 0 80px rgba(124,179,66,0.1);
}

.orb-btn.listening .orb-icon {
    opacity: 1;
    filter: none;
}

.orb-ring.active {
    border-color: var(--accent);
    animation: ringPulse 1.8s ease-in-out infinite;
}

@keyframes ringPulse {
    0%, 100% {
        inset: -6px;
        opacity: 0.5;
        border-color: var(--accent);
    }
    50% {
        inset: -14px;
        opacity: 0.15;
        border-color: var(--accent);
    }
}

/* Speaking (AI responding) */
.orb-btn.speaking {
    border-color: #60a5fa;
    background: rgba(96,165,250,0.12);
    box-shadow: 0 0 30px rgba(96,165,250,0.15);
}

.orb-btn.speaking .orb-icon {
    opacity: 0.9;
    filter: hue-rotate(80deg);
}

.orb-ring.speaking-ring {
    border-color: rgba(96,165,250,0.4);
    animation: speakPulse 1s ease-in-out infinite;
}

@keyframes speakPulse {
    0%, 100% { inset: -4px; opacity: 0.4; }
    50% { inset: -10px; opacity: 0.1; }
}

/* Processing */
.orb-btn.processing {
    border-color: #fbbf24;
    background: rgba(251,191,36,0.08);
}

.orb-btn.processing .orb-icon {
    opacity: 0.7;
    animation: processSpin 2s linear infinite;
}

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

.status-text {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    text-align: center;
    min-height: 1.2em;
    transition: color 0.2s;
}

.status-text.active { color: var(--accent); }

/* ── Footer / Input ── */
footer {
    flex-shrink: 0;
    padding: 4px 16px 12px;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: transparent;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-input {
    flex: 1;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 11px 18px;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

#chat-input::placeholder { color: var(--text-muted); }
#chat-input:focus { border-color: rgba(124,179,66,0.4); }

#btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #111;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

#btn-send:active { transform: scale(0.92); opacity: 0.85; }

/* ── Summary Bubble ── */
.summary-bubble {
    align-self: stretch;
    max-width: 100%;
    background: rgba(124,179,66,0.04);
    border: 1px dashed rgba(124,179,66,0.2);
    border-radius: var(--radius);
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--text-dim);
}

.summary-label {
    color: var(--accent) !important;
    font-size: 0.6rem !important;
    letter-spacing: 1.2px !important;
    display: flex !important;
    align-items: center;
    gap: 6px;
}

.summary-label::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.5;
}

.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 600px) {
    header { padding: 8px 12px; }
    main#conversation { padding: 6px 12px; gap: 6px; }
    .msg {
        max-width: 92%;
        padding: 9px 12px;
        font-size: 0.86rem;
    }
    .orb-area { padding: 8px 12px 2px; }
    #orb-container { width: 88px; height: 88px; }
    .orb-btn { width: 88px; height: 88px; }
    .orb-icon { width: 46px; height: 46px; }
    footer { padding: 4px 12px 10px; }
    #chat-input { font-size: 0.84rem; padding: 10px 14px; }
    #btn-send { width: 38px; height: 38px; }
}

@media (max-width: 380px) {
    #orb-container { width: 76px; height: 76px; }
    .orb-btn { width: 76px; height: 76px; }
    .orb-icon { width: 40px; height: 40px; }
}

@media (hover: hover) {
    .icon-btn:hover { background: var(--surface2); color: var(--text); }
    .orb-btn:hover { border-color: var(--accent); }
}

@media (display-mode: standalone) {
    header { padding-top: env(safe-area-inset-top, 12px); }
}
