/*
   JOHNNY: THE DARK LIQUID PIVOT
   Inky black sphere with vibrant neon morphing glows.
*/

:root {
    --sphere-size: clamp(260px, 65vmin, 480px);
    --inky-black: #000000;
    --accent-glow: rgba(0, 212, 255, 0.6);
    --bg-dark: #000000;

    /* Vibrant Palette for Morphing */
    --accent-blue: #00d4ff;
    --accent-purple: #bb2dff;
    --accent-gold: #ffc400;
    --accent-ruby: #ff004c;
}

#voice-widget-container {
    position: fixed;
    inset: 0;
    z-index: 2147483640;
    font-family: 'Inter', system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-dark);
    color: white;
    overflow: hidden;
    pointer-events: none;
}

/* The Inky Liquid Sphere */
.voice-widget-card {
    position: relative;
    pointer-events: auto;
    width: var(--sphere-size);
    height: var(--sphere-size);
    background: radial-gradient(circle at 30% 30%, #1a1a1a 0%, var(--inky-black) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 50%;
    margin-top: 8vh;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(var(--sphere-scale, 1));
    transition: all 0.8s cubic-bezier(0.19, 1, 0.22, 1);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 40px rgba(0, 212, 255, 0.2), inset 0 0 20px rgba(255, 255, 255, 0.05);
    animation: float 8s ease-in-out infinite, liquidPulse 4s ease-in-out infinite;
}

.glow-field {
    position: absolute;
    inset: -40px;
    background: conic-gradient(from 0deg, transparent, var(--accent-blue) 15%, var(--accent-purple) 35%, var(--accent-ruby) 55%, var(--accent-gold) 75%, var(--accent-blue) 90%, transparent);
    filter: blur(60px);
    opacity: 0.6;
    animation: rotateGlow 12s linear infinite, glowPulse 6s ease-in-out infinite alternate;
    z-index: -1;
    border-radius: 50%;
}

@keyframes glowPulse {
    from {
        transform: scale(0.9) rotate(0deg);
        opacity: 0.3;
    }

    to {
        transform: scale(1.1) rotate(10deg);
        opacity: 0.5;
    }
}

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

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

@keyframes liquidPulse {

    0%,
    100% {
        border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%;
    }

    50% {
        border-radius: 45% 55% 48% 52% / 55% 45% 52% 48%;
    }
}

.bottom-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin-top: 2rem;
    overflow: hidden;
    pointer-events: auto;
}

.chat-viewport {
    width: 100%;
    overflow-y: auto;
    padding: 1rem;
    flex-grow: 1;
    mask-image: linear-gradient(to bottom, transparent, black 5%, black 95%, transparent);
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 100px;
}

.input-area {
    width: 100%;
    padding: 10px 20px 20px;
    box-sizing: border-box;
}

#voice-text-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.upload-btn {
    position: absolute;
    left: 12px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 5;
}

.upload-btn:hover {
    color: #00d4ff;
    transform: scale(1.1);
}

.upload-btn svg {
    width: 20px;
    height: 20px;
}

#voice-text-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 18px 12px 48px;
    /* Extra left padding for the icon */
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

#voice-text-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.05);
}

/* Message Styles */
.message-bubble-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: bubbleAppear 0.4s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes bubbleAppear {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
    }

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

.message-bubble-wrapper.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-bubble-wrapper.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble-label {
    font-size: 0.55rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.25);
    margin-bottom: 0.3rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.message-content {
    padding: 0.9rem 1.3rem;
    border-radius: 20px;
    font-size: 1.05rem;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.9);
    white-space: pre-wrap;
    word-break: break-word;
}

.user .message-content {
    color: #00d4ff;
    background: rgba(0, 212, 255, 0.05);
    border-color: rgba(0, 212, 255, 0.15);
    border-bottom-right-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 212, 255, 0.05);
}

.assistant .message-content {
    border-bottom-left-radius: 4px;
}

.chat-viewport::-webkit-scrollbar {
    width: 4px;
}

.chat-viewport::-webkit-scrollbar-track {
    background: transparent;
}

.chat-viewport::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.status-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    z-index: 10;
}

.status-label {
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 2px;
    /* Slightly reduced to fit longer text */
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}

/* TOP CONTROLS - RELOCATED TO BOTTOM OF SPHERE */
.top-controls {
    position: absolute;
    top: 8vh;
    left: 50%;
    width: var(--sphere-size);
    height: var(--sphere-size);
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 2000;
}

.top-control {
    position: absolute;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    width: 100px;
    height: 100px;
}

.top-control:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Mic Button Bottom-Left, Closer to Sphere */
.top-control.bottom-left {
    bottom: 5%;
    left: -10px;
    /* Nearly touching the left curve */
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.4);
    border-color: rgba(34, 197, 94, 0.6);
    color: #4ade80;
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.3);
}

.top-control.bottom-left svg {
    width: 45px;
    height: 45px;
}

/* NEW Button Bottom-Right, Symmetrical to Mic */
.top-control.bottom-right {
    bottom: 5%;
    right: -10px;
    /* Nearly touching the right curve */
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: 2px;
}

/* Red Mute State */
.top-control[data-muted="true"] {
    background: rgba(239, 68, 68, 0.5) !important;
    border-color: rgba(239, 68, 68, 0.7) !important;
    color: #f87171 !important;
    box-shadow: 0 0 40px rgba(239, 68, 68, 0.4) !important;
}

/* Strikethrough effect */
.top-control[data-muted="true"]::after {
    content: "";
    position: absolute;
    width: 60%;
    height: 3px;
    background: #f87171;
    transform: rotate(-45deg);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
    pointer-events: none;
}

.mute-label {
    display: none;
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.55rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: #ef4444;
    text-transform: uppercase;
}

[data-muted="true"] .mute-label {
    display: block;
}

/* Mobile Overrides (Portrait) */
@media (max-width: 600px) {
    :root {
        --sphere-size: clamp(200px, 80vmin, 300px);
    }

    .top-control {
        width: 75px;
        height: 75px;
        border-width: 1.5px;
    }

    .top-control.bottom-left,
    .top-control.bottom-right {
        bottom: 0%;
    }

    .top-control.bottom-left {
        left: -5px;
    }

    .top-control.bottom-right {
        right: -5px;
        font-size: 0.9rem;
        border-radius: 12px;
    }

    .top-control.bottom-left svg {
        width: 35px;
        height: 35px;
    }
}

.audio-visualizer {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 15px;
    opacity: 0;
    transition: opacity 0.5s;
}

[data-state="listening"] .audio-visualizer,
[data-state="speaking"] .audio-visualizer {
    opacity: 1;
}

.v-bar {
    width: 3px;
    height: 4px;
    background: white;
    border-radius: 2px;
}

[data-state="listening"] .v-bar {
    background: #fbbf24;
    animation: wave 0.5s infinite alternate;
}

[data-state="speaking"] .v-bar {
    background: #00d4ff;
    animation: wave 0.3s infinite alternate;
}

@keyframes wave {
    from {
        height: 4px;
    }

    to {
        height: 20px;
    }
}

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

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

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

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

.voice-widget-card[data-state="connecting"] {
    --accent-glow: rgba(255, 255, 255, 0.5);
}

.voice-widget-card[data-state="listening"] {
    --accent-glow: rgba(251, 191, 36, 0.8);
}

.voice-widget-card[data-state="speaking"] {
    --accent-glow: rgba(0, 212, 255, 0.8);
}

.voice-widget-card:active {
    transform: scale(0.95);
}

.mic-button {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 100;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(var(--sphere-scale, 1));
    }

    50% {
        transform: translate(0, -15px) scale(var(--sphere-scale, 1));
    }
}

.face-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1s;
    filter: blur(10px);
}

.voice-widget-card[data-state="speaking"] .face-layer {
    opacity: 0.3;
}

.eye {
    position: absolute;
    width: 25px;
    height: 15px;
    background: white;
    border-radius: 50%;
    top: 40%;
}

.eye.left {
    left: 30%;
}

.eye.right {
    right: 30%;
}

.mouth {
    position: absolute;
    bottom: 30%;
    width: 50px;
    height: 5px;
    background: white;
    border-radius: 50%;
}