:root {
    --bg-0: #050818;
    --bg-1: #0a1128;
    --accent-1: #3b82f6;
    --accent-2: #8b5cf6;
    --accent-3: #06b6d4;
    --text: #e6edf7;
    --text-dim: #7b88a8;
    --panel: rgba(20, 30, 60, 0.4);
    --panel-border: rgba(139, 92, 246, 0.15);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    height: 100%; min-height: 100%;
    overflow: hidden;
    background: var(--bg-0);
}
body {
    background: radial-gradient(ellipse at top, var(--bg-1) 0%, var(--bg-0) 60%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top, 20px) 20px 0 20px;
    gap: 12px;
}

/* Browser (Safari mit URL-Leiste): mehr Platz unten */
#controls {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
    margin-bottom: -60px;   /* damit Chat-Row visuell im safe-area sitzt */
}

/* Standalone-PWA (Home-Screen-App): weniger padding, direkt an safe-area */
@media (display-mode: standalone) {
    #controls {
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
        margin-bottom: 0;
    }
}

/* ---- ORB ---- */
#orb-container {
    position: relative;
    width: min(280px, 65vw);
    aspect-ratio: 1;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#orb {
    width: 100%;
    height: 100%;
    display: block;
}
#orb-glow {
    position: absolute;
    inset: -20%;
    background: radial-gradient(circle at center,
        rgba(59, 130, 246, 0.35) 0%,
        rgba(139, 92, 246, 0.15) 40%,
        transparent 70%);
    pointer-events: none;
    z-index: -1;
    filter: blur(20px);
    transition: opacity 0.4s ease;
}
body[data-state="listening"] #orb-glow {
    background: radial-gradient(circle at center,
        rgba(6, 182, 212, 0.5) 0%,
        rgba(59, 130, 246, 0.2) 40%,
        transparent 70%);
    animation: pulseGlow 1.5s ease-in-out infinite;
}
body[data-state="thinking"] #orb-glow {
    background: radial-gradient(circle at center,
        rgba(139, 92, 246, 0.5) 0%,
        rgba(59, 130, 246, 0.2) 40%,
        transparent 70%);
    animation: pulseGlow 2s ease-in-out infinite;
}
body[data-state="speaking"] #orb-glow {
    background: radial-gradient(circle at center,
        rgba(6, 182, 212, 0.6) 0%,
        rgba(139, 92, 246, 0.3) 40%,
        transparent 70%);
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* ---- STATUS ---- */
#status {
    font-size: 14px;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    min-height: 20px;
    text-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

/* ---- MESSAGES ---- */
#messages {
    flex: 1;
    width: 100%;
    max-width: 640px;
    overflow-y: auto;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 2px; }

.msg {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 85%;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}
.msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    border-bottom-right-radius: 4px;
}
.msg.jarvis {
    align-self: flex-start;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(10px);
}
.msg-link {
    display: inline-block;
    color: var(--accent-3);
    background: rgba(6, 182, 212, 0.12);
    padding: 4px 10px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 500;
    margin: 4px 4px 4px 0;
    border: 1px solid rgba(6, 182, 212, 0.25);
    transition: all 0.15s ease;
}
.msg-link:active, .msg-link:hover {
    background: rgba(6, 182, 212, 0.2);
    transform: scale(0.98);
}
.msg.transcript {
    align-self: flex-end;
    background: transparent;
    color: var(--text-dim);
    font-style: italic;
    border: 1px dashed var(--panel-border);
    max-width: 85%;
}

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

/* ---- CONTROLS ---- */
#controls {
    width: 100%;
    max-width: 640px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}
#mic-btn {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--accent-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
#cam-btn {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--accent-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
    position: relative;
}
#cam-btn:active { transform: scale(0.95); }

#mic-btn:active, #mic-btn.recording {
    background: linear-gradient(135deg, var(--accent-3), var(--accent-1));
    color: white;
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(6, 182, 212, 0.5);
}
#mic-btn.recording {
    animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(6, 182, 212, 0.5); }
    50% { box-shadow: 0 0 40px rgba(6, 182, 212, 0.8); }
}

#chat-form {
    flex: 1;
    display: flex;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 26px;
    padding: 4px 6px 4px 16px;
    backdrop-filter: blur(10px);
}
#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    outline: none;
    min-width: 0;
}
#chat-input::placeholder { color: var(--text-dim); }
#chat-form button[type=submit] {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 3px;
}

/* ---- AUTH OVERLAY ---- */
#auth-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, var(--bg-1) 0%, var(--bg-0) 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
#auth-overlay[hidden] { display: none !important; }
#auth-form {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 32px 24px;
    max-width: 320px;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(20px);
    box-shadow: 0 0 60px rgba(6, 182, 212, 0.15);
}
#auth-form h2 {
    margin: 0 0 8px 0;
    color: var(--accent-3);
    font-size: 28px;
    letter-spacing: 0.05em;
    text-shadow: 0 0 20px rgba(6, 182, 212, 0.4);
}
#auth-form p {
    color: var(--text-dim);
    font-size: 14px;
    margin: 0 0 20px 0;
}
#auth-input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(5, 8, 24, 0.5);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    color: var(--text);
    font-size: 16px;
    outline: none;
    margin-bottom: 12px;
    box-sizing: border-box;
}
#auth-input:focus { border-color: var(--accent-3); }
#auth-form button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.03em;
}
#auth-error {
    color: #ff6b6b;
    font-size: 13px;
    margin-top: 10px;
}
