:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --primary-color: #38bdf8;
    --text-color: #f8fafc;
    --secondary-text: #94a3b8;
    --accent-glow: rgba(56, 189, 248, 0.5);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(to bottom, #0f172a, #1e293b);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1 {
    font-size: 2.0rem;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--primary-color);
}

.timestamp-text {
    font-size: 0.6em;
    color: rgba(255, 255, 255, 0.5);
    margin-right: 8px;
    font-weight: 300;
}

/* Video Background (Default Portrait) */
#video-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: transparent;
    /* Changed from #000 to transparent to show gradient */
}

video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Changed to cover to fill screen/container */
    /* Maintain aspect ratio, do not stretch or crop */
    object-position: center top;
    /* Align to top center */
    /* Align to bottom */
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

video.active {
    opacity: 1;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    transition: opacity 0.5s ease;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* UI Overlay */
#ui-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 2rem;
    pointer-events: none;
    /* Let clicks pass through to video if needed, but enable for children */
}

#ui-overlay>* {
    pointer-events: auto;
}

.container {
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4rem;
    /* Increased gap */
}

/* ... existing styles ... */

.avatar-container {
    /* Default Portrait: Match video-container behavior but keep content centered */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* Remove card-bg, let gradient show */
    z-index: -1;
    /* Behind UI */
    display: flex;
    justify-content: center;
    align-items: center;
    /* Push avatar up slightly to avoid being covered by UI */
    padding-bottom: 20vh;
}

/* Landscape Layout - Split Screen */
@media (min-width: 768px) and (orientation: landscape) {
    /* ... existing layout-wrapper ... */

    /* ... existing video-container ... */

    /* Ava1 on Left (40%) - Same as video-container */
    .avatar-container {
        position: relative;
        width: 40%;
        height: 100%;
        z-index: 1;
        order: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        /* Reset fixed positioning properties */
        top: auto;
        left: auto;
        transform: none;
        /* Reset padding from portrait mode */
        padding-bottom: 0;
    }

    /* Fix hover effect in landscape (remove translate) */
    .avatar-container:hover {
        transform: scale(1.02);
    }

    /* ... existing ui-overlay ... */
}

#ava2-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* ... existing styles ... */

/* Interaction Container */
.interaction-container {
    width: 90%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Conversation Log */
.conversation-log {
    width: 100%;
    height: 200px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.7);
    /* 70% opacity */
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Custom Scrollbar */
.conversation-log::-webkit-scrollbar {
    width: 8px;
}

.conversation-log::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.conversation-log::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.3);
    border-radius: 4px;
}

.conversation-log::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 189, 248, 0.5);
}

.log-entry {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 80%;
    font-size: 1.2rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

.log-entry.user {
    align-self: flex-end;
    background: rgba(56, 189, 248, 0.3);
    color: #e0f2fe;
    border-bottom-right-radius: 4px;
}

.log-entry.ava {
    align-self: flex-start;
    background: rgba(148, 163, 184, 0.3);
    color: #f1f5f9;
    border-bottom-left-radius: 4px;
}

.log-entry.warning {
    align-self: center;
    background: rgba(239, 68, 68, 0.2);
    color: #fecaca;
    font-size: 0.85rem;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 5px 0;
}

/* Log Wrapper for expand functionality */
.log-wrapper {
    position: relative;
    width: 100%;
}

.log-wrapper.log-expanded {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    background: var(--bg-color);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.log-wrapper.log-expanded .conversation-log {
    height: 100%;
    max-height: none;
    border-radius: 8px;
}

#expand-log-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

.log-wrapper.log-expanded #expand-log-btn {
    top: 1.5rem;
    right: 1.5rem;
}

.icon-btn-tiny {
    background: var(--primary-color);
    border: none;
    color: #000;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px;
}

.icon-btn-tiny:hover {
    background: var(--primary-color);
    color: var(--text-color);
}

/* Loading indicator in log */
.log-entry.loading {
    align-self: center;
    background: rgba(56, 189, 248, 0.15);
    color: var(--secondary-text);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Stop button style */
#speak-btn.stop-mode {
    background: rgba(239, 68, 68, 0.8);
}

#speak-btn.stop-mode:hover {
    background: #ef4444;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

.avatar-container:hover {
    transform: scale(1.02);
}

.avatar {
    width: 200px;
    height: 200px;
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    border-radius: 40% 40% 50% 50%;
    position: relative;
    box-shadow: inset -10px -10px 20px rgba(0, 0, 0, 0.1);
    animation: float 6s ease-in-out infinite;
    margin-bottom: 80px;
}

.avatar-face {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.eyes {
    display: flex;
    gap: 40px;
}

.eye {
    width: 20px;
    height: 20px;
    background: #1e293b;
    border-radius: 50%;
    animation: blink 4s infinite;
}

.mouth {
    width: 40px;
    height: 10px;
    background: #1e293b;
    border-radius: 20px;
    transition: height 0.1s ease;
}

/* Speaking Animation State */
.avatar.speaking .mouth {
    animation: talk 0.2s infinite alternate;
}

/* Controls */
.controls {
    width: 100%;
    margin-bottom: 1rem;
}

.input-group {
    display: flex;
    gap: 10px;
    background: rgba(15, 23, 42, 0.7);
    /* 70% opacity */
    backdrop-filter: blur(10px);
    padding: 10px;
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

input[type="text"] {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
}

input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

button {
    background: rgba(56, 189, 248, 0.8);
    border: none;
    color: var(--bg-color);
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

button:hover {
    background: #38bdf8;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

#avatar-btn {
    background: rgba(99, 102, 241, 0.8);
}

#avatar-btn:hover {
    background: #818cf8;
}

button.listening {
    background: rgba(239, 68, 68, 0.8);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Footer Styles (Global) */
footer {
    margin-top: 20px;
    align-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.footer-controls {
    display: flex;
    gap: 15px;
    flex-direction: row;
    flex-wrap: nowrap;
}

.icon-btn-small {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--secondary-text);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn-small:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-color);
    transform: translateY(-2px);
}

/* Landscape Layout - Split Screen */
@media (min-width: 768px) and (orientation: landscape) {
    .layout-wrapper {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100vh;
        padding: 0 5%;
        /* 5% on each side to make total gap/padding logic work */
        gap: 10%;
        /* Gap between video and UI */
    }

    /* Video on Left (40%) */
    #video-container {
        position: relative;
        /* Not fixed anymore */
        width: 40%;
        height: 100%;
        /* Fill full height */
        z-index: 1;
        background: transparent;
        order: 1;
        display: flex;
        align-items: center;
        /* Center vertically */
        /* Align video to bottom */
        justify-content: center;
    }

    video {
        position: absolute;
        /* Absolute to prevent shifting/stacking */
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        /* Ensure it covers the container */
        object-position: center top;
    }

    /* UI on Right (40%) */
    #ui-overlay {
        position: relative;
        /* Not fixed anymore */
        width: 40%;
        height: auto;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        /* Center items horizontally (including title) */
        padding: 0;
        order: 2;
        pointer-events: auto;
    }

    .interaction-container {
        width: 100%;
        max-width: none;
        align-items: stretch;
    }

    .conversation-log {
        height: 400px;
        /* Taller log */
    }


}

/* Animations */
@keyframes float {

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

    50% {
        transform: translateY(-10px);
    }
}

@keyframes blink {

    0%,
    96%,
    100% {
        transform: scaleY(1);
    }

    98% {
        transform: scaleY(0.1);
    }
}

@keyframes talk {
    0% {
        height: 10px;
        border-radius: 20px;
    }

    100% {
        height: 25px;
        border-radius: 50%;
    }
}

/* Avatar Selection Styles */
.avatar-select-btn {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px solid transparent;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--card-bg);
}

.avatar-select-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.avatar-select-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
    box-shadow: 0 0 20px var(--accent-glow);
}

.avatar-select-btn:hover img {
    transform: scale(1.1);
}

#stop-btn {
    background: rgba(239, 68, 68, 0.8);
}

#stop-btn:hover {
    background: #ef4444;
}

/* Language Selection Buttons */
.select-btn-lang {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px solid transparent;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--card-bg);
    color: #fff;
}

.select-btn-lang:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
    box-shadow: 0 0 20px var(--accent-glow);
}