:root {
    font-size: 1.125rem;
    --vh: 1vh;
    /* Fallback value for browsers that don't support custom properties */
    --bg0: #FFF;
    --bg1: rgba(206, 206, 206, .5);
    --fg0: #000;
    --fg1: rgba(0, 0, 0, .5);
    --a0: #0076FF;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg0: #000;
        --bg1: rgba(206, 206, 206, .125);
        --fg0: #FFF;
        --fg1: rgba(206, 206, 206, .5);
        --a0: #0076FF;
    }
}

@media (min-width: 600px) {
    :root {
        font-size: 1.5rem;
    }
}

@media (min-width: 900px) {
    :root {
        font-size: 1.75rem;
    }
}

@media (min-width: 1200px) {
    :root {
        font-size: 2rem;
    }
}

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

strong {
    background: linear-gradient(310deg, #0076FF 0%, #44cedb 90%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

html,
body {
    background: var(--bg0);
    color: var(--fg0);
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}

.chat-container {
    width: 100%;
}

.messages {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    overflow: auto;
    width: 100%;
    max-width: 600px;
    max-height: calc(var(--vh, 1vh) * 100);
    padding: 1rem .4rem 4rem;
    margin: 0 auto;
    transition: max-height 0.3s ease-in-out;
}

/* Fallback for browsers that don't support CSS custom properties */
@supports not (max-height: calc(var(--vh) * 100)) {
    .messages {
        max-height: 100vh;
    }
}

/* Custom scrollbar styling for webkit browsers */
.messages::-webkit-scrollbar {
    width: 2px;
}

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

.messages::-webkit-scrollbar-thumb {
    background: var(--fg1);
    border-radius: 1px;
    transition: background 0.2s ease;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--a0);
}

/* Firefox scrollbar styling */
.messages {
    scrollbar-width: thin;
    scrollbar-color: var(--fg1) transparent;
}

.message-group {
    display: flex;
    max-width: 80%;
    flex-direction: column;
    margin-bottom: .25rem;
    position: relative;
}

/* Message group alignment classes */
.message-group.right-group {
    align-self: flex-end;
}

.message-group.left-group {
    align-self: flex-start;
}

.bubble {
    overflow: hidden;
    display: inline-block;
    margin: 0 0 .1rem 0;
    padding: .5rem .85rem;
    line-height: 1.25rem;
    border-radius: 1.25rem;
    transform-origin: 0 100%;
    vertical-align: middle;
    transition: border-radius .15s ease-out 0.1s;
}

.bubble.left {
    background: var(--bg1);
    align-self: flex-start;
}

.bubble.right {
    background: var(--a0);
    align-self: flex-end;
}

/* Bubble corner styling for continuous message threads */
/* Left-aligned bubbles (bot messages) */
.bubble.left:only-child {
    border-radius: 1.25rem;
    /* Fully rounded for single messages */
}

.bubble.left:not(:first-child):not(:last-child) {
    border-top-left-radius: 0.25rem;
    /* Flatten top-left for middle messages in thread */
    border-bottom-left-radius: 0.25rem;
    /* Flatten bottom-left for middle messages in thread */
}

.bubble.left:first-child:not(:last-child) {
    border-bottom-left-radius: 0.25rem;
    /* Flatten bottom-left for first message in thread */
}

.bubble.left:last-child:not(:first-child) {
    border-top-left-radius: 0.25rem;
    /* Flatten top-left for last message in thread */
}

/* Right-aligned bubbles (user messages) */
.bubble.right:only-child {
    border-radius: 1.25rem;
    /* Fully rounded for single messages */
}

.bubble.right:not(:first-child):not(:last-child) {
    border-top-right-radius: 0.25rem;
    /* Flatten top-right for middle messages in thread */
    border-bottom-right-radius: 0.25rem;
    /* Flatten bottom-right for middle messages in thread */
}

.bubble.right:first-child:not(:last-child) {
    border-bottom-right-radius: 0.25rem;
    /* Flatten bottom-right for first message in thread */
}

.bubble.right:last-child:not(:first-child) {
    border-top-right-radius: 0.25rem;
    /* Flatten top-right for last message in thread */
}

.bubble span {
    display: inline;
}

.bubble span.message {
    opacity: 0;
}

.bubble a {
    color: var(--a0);
}

.bubble .loading {
    position: absolute;
    white-space: pre;
    font-size: 1.625rem;
    line-height: 0.9rem;
}

.bubble .loading b {
    display: inline-block;
    color: var(--fg1);
}

.chat-input-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    z-index: 1000;
    padding: 0 .4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: bottom 0.3s ease-in-out, transform 0.3s ease-in-out;
}

.chat-input {
    width: 100%;
    padding: .65rem .9rem;
    border: 1px solid var(--fg1);
    border-radius: 1.5rem;
    background: var(--bg0);
    color: var(--fg0);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--a0);
}

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

.button-container {
    position: relative;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
}

.send-button {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: 50%;
    background: var(--a0);
    color: var(--bg0);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    opacity: 1;
    contain: layout style paint;
    /* Performance optimization for animations */
}

.send-button:hover:not(:disabled) {
    background: var(--a0);
    opacity: 0.8;
    transform: scale(1.05);
}

.send-button:disabled {
    background: var(--fg1);
    cursor: not-allowed;
    opacity: 0.5;
}

.send-button img {
    width: 1.25rem;
    height: 1.25rem;
}

.loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fg1);
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    transition: opacity 0.2s ease-in-out;
    opacity: 0;
    contain: layout style paint;
    /* Performance optimization */
}

.loading-spinner img {
    width: 1.25rem;
    height: 1.25rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.wave {
    display: inline-block !important;
    transform-origin: center bottom !important;
    animation: wave 5s ease-in-out infinite !important;
}

@keyframes wave {
    0%, 20%, 100% {
        transform: rotate(0deg);
    }
    2.5%, 7.5%, 12.5%, 17.5% {
        transform: rotate(-8deg);
    }
    5%, 10%, 15% {
        transform: rotate(8deg);
    }
}