:root {
    --bg-color: #f0f4f8;
    --sidebar-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --accent-color: #4285f4;
    --accent-hover: #3367d6;
    --chat-bubble-user: #e3f2fd;
    --chat-bubble-ai: #f5f5f5;
    --border-color: #e0e0e0;
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.header {
    margin-bottom: 20px;
}

.back-link {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    margin-bottom: 5px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent-color);
}

/* Settings Box */
.settings-box {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.setting-group {
    margin-bottom: 12px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.secondary-btn {
    width: 100%;
    padding: 8px;
    background: #f0f0f0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: #e0e0e0;
}

.slider-group {
    margin-bottom: 8px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.slider-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.setting-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.setting-group select,
.setting-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
}

.setting-group.compact {
    display: flex;
    gap: 8px;
}

.setting-group.compact button {
    padding: 0 12px;
    background: var(--text-secondary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Chat Log */
.chat-log-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.placeholder {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #ccc;
    font-size: 0.9rem;
}

.message {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
}

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

.message.ai {
    align-self: flex-start;
    background-color: var(--chat-bubble-ai);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* Controls */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.primary-btn {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn:hover {
    background-color: var(--accent-hover);
}

.primary-btn:active {
    transform: scale(0.98);
}

.primary-btn.connected {
    background-color: #ea4335;
    /* Red for stop */
}

.sub-controls {
    display: flex;
    gap: 10px;
}

.icon-btn {
    flex: 1;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: #f5f5f5;
}

.icon-btn.active {
    background-color: #e3f2fd;
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Main Screen (Avatar Stage) */
.main-screen {
    flex: 1;
    position: relative;
    background: linear-gradient(135deg, #eef2f3, #dbe4ef);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

/* Vision Container */
.vision-container {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 240px;
    background: black;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transition: all 0.3s;
}

.vision-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-20px);
}

#cameraFeed,
#sharedImage {
    width: 100%;
    display: block;
}

#sharedImage {
    display: none;
    /* デフォルトはカメラ優先 */
}

.vision-controls {
    padding: 8px;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: space-between;
}

.vision-controls button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

/* Avatar Styles */
.avatar-stage {
    position: relative;
    width: 100%;
    height: 100%;
    /* フルスクリーン */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.avatar-container {
    position: relative;
    width: 60vh;
    /* 高さ基準でサイズ決定 */
    height: 60vh;
    /* max-width: 500px; */
    /* border: 1px solid red; debug */
}

.avatar-base {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Mouth Overlay - 簡易リップシンク */
.mouth-overlay {
    position: absolute;
    /* アバター画像の口の位置に合わせて調整が必要です。
       生成された画像によるので、仮の値を設定し、調整機能をJSにつけるか
       目視でCSSを修正します。 */
    top: 50%;
    left: 50%;
    transform: translateX(-50%);
    width: 8%;
    /* 口の幅 */
    height: 5%;
    /* 口の最大開き幅 */
    /* background: rgba(255, 0, 0, 0.3); Debug用 */
    display: flex;
    justify-content: center;
    align-items: center;
}

.mouth-shape {
    width: 100%;
    height: 100%;
    background-color: #d88e8e;
    /* 口の中の色 */
    border-radius: 50%;
    transform: scaleY(0.1);
    /* デフォルトは閉じている(0に近い値) */
    transform-origin: center;
    transition: transform 0.05s ease-out;
    /* 高速に反応させる */

    /* 簡易的な唇の表現 */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Status Indicator */
.status-indicator {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#statusText {
    font-size: 1.2rem;
    font-weight: 700;
    color: #555;
    background: rgba(255, 255, 255, 0.8);
    padding: 5px 15px;
    border-radius: 20px;
}

.visualizer-bars {
    display: flex;
    gap: 4px;
    height: 30px;
    align-items: flex-end;
}

.bar {
    width: 6px;
    background-color: var(--accent-color);
    border-radius: 3px;
    animation: bounce 0.5s infinite ease-in-out;
}

@keyframes bounce {

    0%,
    100% {
        height: 20%;
    }

    50% {
        height: 100%;
    }
}

/* Responsive */
@media (max-width: 768px) {

    html,
    body {
        overflow-y: auto !important;
        height: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .app-container {
        flex-direction: column;
        height: auto !important;
        min-height: 100vh;
        overflow: visible !important;
    }

    .sidebar {
        width: 100%;
        height: auto;
        /* Fit content */
        order: 2;
        border-right: none;
        border-top: 1px solid var(--border-color);
        overflow: visible;
        flex: none;
        /* Prevent flex shrinking */
    }

    .main-screen {
        height: 50vh;
        /* Fixed height for avatar area */
        min-height: 300px;
        order: 1;
    }

    .avatar-container {
        width: 40vh;
        height: 40vh;
    }

    .chat-log-container {
        height: 400px;
        /* Give it fixed height so it scrolls internally */
        flex: none;
    }
}