@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #0d0f14;
    --bg-2: #111318;
    --surface: #16191f;
    --surface-2: #1c2028;
    --glass: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);

    --text: #f0f0f3;
    --text-secondary: #8b92a5;
    --muted: #555c6e;

    --accent: #5b7cf6;
    --accent-2: #7c5cfc;
    --accent-gradient: linear-gradient(135deg, #5b7cf6 0%, #7c5cfc 100%);

    --bubble-user-bg: linear-gradient(135deg, #4f6ef5 0%, #7655f8 100%);
    --bubble-user-text: #ffffff;
    --bubble-bot-bg: rgba(255, 255, 255, 0.05);
    --bubble-bot-border: rgba(255, 255, 255, 0.08);
    --bubble-bot-text: #e8eaf0;

    --border: rgba(255, 255, 255, 0.07);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.3);

    --status-online: #22c55e;
    --error-bg: rgba(239, 68, 68, 0.12);
    --error-border: rgba(239, 68, 68, 0.25);
    --error-text: #fca5a5;

    --radius-bubble: 18px;
    --radius-input: 28px;
    --composer-h: 72px;
    --topbar-h: 64px;
}

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

html,
body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    z-index: 10;
}

.topbar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(91, 124, 246, 0.4), transparent);
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(91, 124, 246, 0.3), var(--shadow-sm);
    letter-spacing: -0.3px;
    line-height: 1;
}

.meta {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.name {
    margin: 0;
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    letter-spacing: -0.2px;
    line-height: 1.2;
}

.status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.2;
}

.status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--status-online);
    box-shadow: 0 0 6px var(--status-online);
    animation: pulse-dot 2.5s ease-in-out infinite;
    flex-shrink: 0;
    display: inline-block;
}

.topbar-nav {
    margin-left: auto;
    display: flex;
    align-items: center;
}

.topbar-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    color: #a78bfa;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(124, 92, 252, 0.08);
    border: 1px solid rgba(124, 92, 252, 0.2);
    transition: all 0.2s ease;
    line-height: 1;
}

.topbar-link:hover {
    color: #c4b5fd;
    background: rgba(124, 92, 252, 0.16);
    border-color: rgba(124, 92, 252, 0.35);
    transform: translateY(-1px);
}

@keyframes pulse-dot {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.bubble {
    max-width: min(72%, 520px);
    padding: 12px 16px;
    border-radius: var(--radius-bubble);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14.5px;
    animation: bubble-in 0.22s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

@keyframes bubble-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.bubble.user {
    align-self: flex-end;
    background: var(--bubble-user-bg);
    color: var(--bubble-user-text);
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 20px rgba(91, 124, 246, 0.3);
}

.bubble.assistant {
    align-self: flex-start;
    background: var(--bubble-bot-bg);
    color: var(--bubble-bot-text);
    border: 1px solid var(--bubble-bot-border);
    border-bottom-left-radius: 5px;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-sm);
}

.bubble.error {
    align-self: center;
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-border);
    font-size: 13px;
    border-radius: 10px;
    padding: 8px 14px;
    max-width: min(90%, 400px);
    text-align: center;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: blink 1.3s infinite both;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.18s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes blink {
    0%,
    80%,
    100% {
        opacity: 0.2;
        transform: scale(0.85);
    }

    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.composer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
}

.composer::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(91, 124, 246, 0.3), transparent);
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.input {
    width: 100%;
    padding: 11px 18px;
    border-radius: var(--radius-input);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    caret-color: var(--accent);
}

.input::placeholder {
    color: var(--muted);
}

.input:focus {
    border-color: rgba(91, 124, 246, 0.6);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 0 3px rgba(91, 124, 246, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: #fff;
    cursor: pointer;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    box-shadow: 0 4px 14px rgba(91, 124, 246, 0.45);
}

.send svg {
    display: block;
    transform: translate(-1px, 1px);
}

.send:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 6px 20px rgba(91, 124, 246, 0.6);
}

.send:active:not(:disabled) {
    transform: scale(0.94);
}

.send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

#turnstile-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#turnstile-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

#turnstile-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.turnstile-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(91, 124, 246, 0.1);
    animation: card-in 0.3s cubic-bezier(0.34, 1.3, 0.64, 1) both;
    max-width: 320px;
    width: 90%;
}

@keyframes card-in {
    from {
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.turnstile-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

.turnstile-card-sub {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

@media (min-width: 640px) {
    body {
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #0a0c12 0%, #111520 100%);
    }

    body::before {
        content: '';
        position: fixed;
        inset: 0;
        background:
            radial-gradient(ellipse 60% 50% at 20% 30%, rgba(91, 124, 246, 0.08) 0%, transparent 70%),
            radial-gradient(ellipse 50% 40% at 80% 70%, rgba(124, 92, 252, 0.06) 0%, transparent 70%);
        pointer-events: none;
    }

    .chat-container {
        max-width: 680px;
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

@media (max-width: 639px) {
    .messages {
        padding: 16px 12px;
    }

    .bubble {
        max-width: 85%;
    }

    .composer {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .topbar {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--topbar-h) + env(safe-area-inset-top));
    }
}