:root {
    /* Initial Theme - Deep Purple / M3 Default */
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;

    --md-sys-color-secondary: #625B71;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-on-secondary-container: #1D192B;

    --md-sys-color-surface: #FEF7FF;
    --md-sys-color-surface-container: #F3EDF7;
    --md-sys-color-on-surface: #1D1B20;

    --md-sys-color-outline: #79747E;

    --ease-elastic: cubic-bezier(0.68, -0.6, 0.32, 1.6);
    --ease-material: cubic-bezier(0.2, 0.0, 0, 1.0);
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Google Sans Text', sans-serif;
    background-color: var(--md-sys-color-surface);
    transition: background-color 1s ease;
}

.app-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    position: relative;
    /* Clean backdrop */
}

/* Ambient Background Blobs that shift colors */
.ambient-shape {
    position: absolute;
    border-radius: 50%;
    opacity: 0.15;
    filter: blur(80px);
    transition: background-color 1s ease;
    z-index: 0;
}

.shape-1 {
    top: -10%;
    left: -10%;
    width: 70vw;
    height: 70vw;
    background: var(--md-sys-color-primary-container);
    animation: float 20s infinite ease-in-out;
}

.shape-2 {
    bottom: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: var(--md-sys-color-secondary-container);
    animation: float 25s infinite ease-in-out reverse;
}

@keyframes float {
    0% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(20px, 20px);
    }

    100% {
        transform: translate(0, 0);
    }
}

/* Animation Stage */
.stage {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

/* 
 * COMPONENT: FAB (Initial State)
 */
.fab {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    z-index: 20;
    overflow: hidden;
    /* Transition properties */
    transition:
        width 0.6s var(--ease-material),
        height 0.6s var(--ease-material),
        border-radius 0.6s var(--ease-material),
        opacity 0.3s ease,
        transform 0.6s var(--ease-material);
}

.fab .icon {
    font-size: 24px;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    /* Hide text until font loads to prevent showing "chat_bubble" text */
    opacity: 0;
    visibility: hidden;
    color: transparent;
}

/* Show icon only when font is loaded */
.fonts-loaded .fab .icon {
    opacity: 1;
    visibility: visible;
    color: var(--md-sys-color-on-primary-container);
}

/* 
 * COMPONENT: Chat Window (Expanded State)
 */
.chat-window {
    width: 380px;
    height: 700px;
    max-height: 90vh;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 28px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    position: absolute;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    /* Hidden initially */
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;

    transition:
        opacity 0.4s ease,
        transform 0.6s var(--ease-material);
}

.chat-header {
    height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    z-index: 5;
}

.chat-header-text {
    margin-left: 16px;
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.chat-subtitle {
    font-size: 12px;
    color: var(--md-sys-color-outline);
}

.chat-body {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: hidden;
    /* Programmatic scroll mainly */
}

/* Messages */
.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 24px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    opacity: 0;
    transform: translateY(20px);
}

.message-animate-in {
    animation: messagePop 0.5s var(--ease-material) forwards;
}

@keyframes messagePop {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border-bottom-left-radius: 4px;
}

.message.ai strong {
    font-weight: 600;
    color: var(--md-sys-color-primary);
}

/* Input Area Simulation */
.input-area {
    padding: 20px;
    background: var(--md-sys-color-surface);
    margin: 10px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--md-sys-color-outline);
    border: 1px solid transparent;
    transition: all 0.3s ease;
}

.input-area.active {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
}

/* AI Thinking State */
.ai-thinking-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: auto;
    margin-bottom: auto;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.ai-thinking-container.visible {
    opacity: 1;
}

.thinking-text {
    margin-top: 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    letter-spacing: 0.5px;
}

.wave-loader {
    display: flex;
    gap: 6px;
}

.wave-bar {
    width: 4px;
    height: 15px;
    background: var(--md-sys-color-primary);
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}

.wave-bar:nth-child(2) {
    animation-delay: 0.1s;
}

.wave-bar:nth-child(3) {
    animation-delay: 0.2s;
}

.wave-bar:nth-child(4) {
    animation-delay: 0.3s;
}

.wave-bar:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes wave {

    0%,
    100% {
        height: 15px;
    }

    50% {
        height: 35px;
    }
}

/* STATE: EXPANDED */
/* When we switch to expanded, we hide FAB and show Window seamlessly 
   But to make it morph, we might manipulate the FAB to become the window. 
   Simplest "Seamles" approach: 
   1. FAB expands. 
   2. Window fades in over it or FAB morphs.
   
   Let's try a shared layout approach via JS class toggling
*/

body.expanded .fab {
    width: 380px;
    height: 700px;
    border-radius: 28px;
    opacity: 0;
    /* Fade out as real window takes over? Or keep it as background? */
    pointer-events: none;
}

body.expanded .chat-window {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

/* Responsive */
@media (max-width: 600px) {
    .chat-window {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    body.expanded .fab {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}