/* Mobile-Specific Styles */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0;
    padding: 0;
    background: #000;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.mobile-container {
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Avatar Section (Upper portion) */
.avatar-section {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 55vh; /* Normal height */
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f1419 100%);
    z-index: 1;
    padding-top: 40px;
    transition: height 0.4s ease; /* Smooth height transition */
}

/* Add fade effect at bottom of avatar section */
.avatar-section::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(
        to bottom,
        rgba(15, 20, 25, 0) 0%,
        rgba(15, 20, 25, 0.3) 50%,
        rgba(15, 20, 25, 0.8) 100%
    );
    pointer-events: none;
    z-index: 2;
}

.loading-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.1em;
    animation: pulse 1.5s ease-in-out infinite;
    text-align: center;
}

.avatar-video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;  
    max-height: 120%;
    object-fit: contain;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 1;
    aspect-ratio: auto;
}

/* Disable video controls completely for mobile */
video {
    outline: none;
    -webkit-tap-highlight-color: transparent;
    pointer-events: none; /* Prevent any interactions on mobile */
}

video::-webkit-media-controls-panel {
    display: none !important;
}

video::-webkit-media-controls-play-button {
    display: none !important;
}

video::-webkit-media-controls-start-playback-button {
    display: none !important;
}

video::-webkit-media-controls-timeline {
    display: none !important;
}

video::-webkit-media-controls-current-time-display {
    display: none !important;
}

video::-webkit-media-controls-time-remaining-display {
    display: none !important;
}

video::-webkit-media-controls-mute-button {
    display: none !important;
}

video::-webkit-media-controls-volume-slider {
    display: none !important;
}

video::-webkit-media-controls-fullscreen-button {
    display: none !important;
}

video::-webkit-media-controls-toggle-closed-captions-button {
    display: none !important;
}

video::-webkit-media-controls {
    display: none !important;
}

/* Video Queue Indicator */
.video-queue-indicator {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 8px 12px;
    z-index: 10;
}

.queue-text {
    color: #ffffff;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: #ff6b6b;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

/* Desktop Link in Avatar Section */
.desktop-link-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 3;
}

.desktop-link {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 10px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.desktop-link:hover {
    color: #ffffff;
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Chat Section (Lower portion) */
.chat-overlay {
    position: absolute;
    top: 50vh; /* Start at 50% of screen height */
    left: 0;
    right: 0;
    bottom: 0; /* Extend to bottom of viewport */
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.2) 0%,
        rgba(0, 0, 0, 0.7) 30%,
        rgba(0, 0, 0, 0.9) 100%
    );
    backdrop-filter: blur(10px);
    border-radius: 25px 25px 0 0;
    z-index: 2;
    transition: all 0.3s ease;
    overflow: hidden;
    border-top: 2px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}

/* Chat Expanded Mode */
.chat-overlay.expanded {
    top: 15vh; /* Expand to cover more of the screen */
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.4) 0%,
        rgba(0, 0, 0, 0.8) 20%,
        rgba(0, 0, 0, 0.95) 100%
    );
}

/* Avatar Section - Compact when chat is expanded */
.avatar-section.compact {
    height: 20vh; /* Reduced height when chat is expanded */
}

/* Adjust avatar content when compact */
.avatar-section.compact .avatar-image,
.avatar-section.compact .avatar-video {
    max-height: 60%; /* Smaller avatar when compact */
}

.chat-header {
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 50px; /* Slightly increased for two lines of text */
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
}

.header-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-info-text {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1;
}

.status-text {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1;
    min-height: 12px;
}

/* Chat Controls */
.chat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-expand-btn,
.settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.settings-btn::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, transparent, rgba(120, 119, 255, 0.5), transparent);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chat-expand-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.settings-btn:hover::before {
    opacity: 1;
    animation: rotate 2s linear infinite;
}

/* Hamburger menu animation */
.settings-btn svg line {
    transition: all 0.3s ease;
    transform-origin: center;
}

.settings-btn:hover svg line:nth-child(1) {
    transform: translateY(-2px);
}

.settings-btn:hover svg line:nth-child(3) {
    transform: translateY(2px);
}

.settings-btn:active svg line:nth-child(1) {
    transform: translateY(-1px) rotate(3deg);
}

.settings-btn:active svg line:nth-child(2) {
    transform: scaleX(0.9);
}

.settings-btn:active svg line:nth-child(3) {
    transform: translateY(1px) rotate(-3deg);
}

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

.chat-expand-btn.active {
    background: rgba(72, 187, 120, 0.3);
    color: #51cf66;
}

.mode-controls {
    display: flex;
    gap: 6px;
}

.mode-toggle {
    position: relative;
}

.mode-toggle input[type="checkbox"] {
    display: none;
}

.mode-toggle label {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 3px 6px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 24px;
}

.mode-toggle input:checked + label {
    background: rgba(72, 187, 120, 0.3);
}

.toggle-on, .toggle-off {
    transition: opacity 0.3s ease;
}

.mode-toggle input:not(:checked) + label .toggle-on {
    opacity: 0.5;
}

.mode-toggle input:checked + label .toggle-off {
    opacity: 0.5;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 5px 20px 20px; /* Reduced top padding since header is now fixed */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-messages::-webkit-scrollbar {
    display: none;
}

.msg {
    padding: 12px 16px;
    border-radius: 18px;
    margin-bottom: 12px;
    max-width: 85%;
    word-wrap: break-word;
    animation: slideIn 0.3s ease-out;
    backdrop-filter: blur(10px);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-msg {
    margin-left: auto;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.bot-msg {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.system-msg .msg {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: 100%;
    font-size: 13px;
    margin: 0 auto 20px;
}

/* Input Section (Fixed at bottom) */
.input-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
    padding: 15px 15px 20px; /* Increased padding for more space */
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    padding: 6px;
    margin-bottom: 8px;
}

.voice-btn, .send-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

.voice-btn:hover, .send-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.voice-btn.recording {
    background: #ff6b6b;
    animation: pulse 1.5s infinite;
}

.voice-btn.preparing {
    background: #ffc107;
    animation: pulse 0.5s ease-in-out infinite;
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 16px;
    padding: 8px 12px;
    outline: none;
}

.message-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.send-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.send-btn:hover {
    background: linear-gradient(135deg, #5a6fd8, #6a4190);
}

/* Status */
/* Status section removed - now in header */

/* Avatar Controls (Collapsible) */
.avatar-controls {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
    z-index: 5; /* Ensure controls are clickable */
}

.controls-toggle {
    width: 100%;
    background: transparent;
    border: none;
    color: #ffffff;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    min-height: 44px; /* Ensure touch target is large enough */
    position: relative;
    z-index: 6;
}

.controls-toggle svg {
    transition: transform 0.3s ease;
}

.avatar-controls.expanded .controls-toggle svg {
    transform: rotate(180deg);
}

.controls-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    position: relative;
    z-index: 5;
}

.avatar-controls.expanded .controls-content {
    max-height: 250px; /* Reduced max height */
}

.control-group {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.control-label {
    display: block;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    margin-bottom: 8px;
}

.control-select {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: #ffffff;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 14px;
}

.control-select option {
    background: #2d3748;
    color: #ffffff;
}

.control-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #ffffff;
    padding: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px; /* Ensure touch target */
    position: relative;
    z-index: 6;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.control-btn.warning {
    background: rgba(255, 193, 7, 0.2);
    border-color: rgba(255, 193, 7, 0.4);
    color: #ffc107;
}

.control-btn.danger {
    background: rgba(220, 53, 69, 0.2);
    border-color: rgba(220, 53, 69, 0.4);
    color: #dc3545;
}

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

/* Scroll-based opacity adjustment */
.chat-overlay.scrolled {
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.4) 0%,
        rgba(0, 0, 0, 0.8) 30%,
        rgba(0, 0, 0, 0.95) 100%
    );
}

/* Improved readability when scrolled */
.chat-overlay.scrolled .chat-header {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(20px);
}

/* Animation for better UX */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-container {
    animation: fadeInUp 0.5s ease-out;
}

/* Modal Styles for Mobile */
.modal-dialog.modal-sm {
    max-width: 90%;
    margin: 1rem auto;
}

.modal-content {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    overflow: hidden;
}

.modal-header {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 20px;
    font-size: 14px;
}

.modal-footer {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
}

.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.85);
}

/* Safe area handling for iOS */
@supports (padding: max(0px)) {
    .input-section {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}
