* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: #000;
    /* 黒背景 */
    min-height: 100vh;
    /* 最小高さ100vh */
    overflow-x: auto;
    /* 横スクロール許可 */
    overflow-y: auto;
    /* 縦スクロール許可 */
}

.container {
    max-width: 1670px;
    /* 最大幅1670px */
    width: 100%;
    /* 可変幅 */
    min-height: 100vh;
    /* 最小高さ100vh */
    display: flex;
    flex-direction: column;
    border: 3px solid #333;
    /* 濃いグレーのボーダー */
    background: #111;
    /* 濃い黒背景 */
    margin: 0 auto;
    /* 中央寄せ */
}

.header {
    background: #222;
    /* 濃いグレー */
    color: white;
    padding: 8px 15px;
    /* よりスリムに */
    border-bottom: 2px solid #333;
    /* ボーダーも細く */
    font-size: 16px;
    /* フォントサイズを小さく */
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-toggle-btn {
    background: transparent;
    /* 背景を透明に */
    border: none;
    /* ボーダーを削除 */
    color: #ffffff;
    /* 白文字 */
    padding: 4px 8px;
    /* よりコンパクトに */
    cursor: pointer;
    font-size: 14px;
    /* フォントサイズを小さく */
    font-weight: normal;
    /* 太字を解除 */
    transition: all 0.3s ease;
    min-width: auto;
    /* 最小幅を自動に */
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-toggle-btn:hover {
    color: #cccccc;
    /* ホバー時に少し暗く */
    transform: none;
    /* 拡大効果を削除 */
}

.chat-toggle-btn:active {
    transform: none;
    /* クリック時の縮小効果も削除 */
    color: #aaaaaa;
    /* クリック時により暗く */
}

.main-content {
    flex: 1;
    display: flex;
    min-height: 600px;
    /* 最小高さを指定 */
}

.stream-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 3px solid #333;
    min-width: 0;
    /* flexアイテムの最小幅を0に */
    overflow: hidden;
    /* はみ出しを防ぐ */
}

.stream-container {
    /* 16:9のアスペクト比を維持 */
    position: relative;
    width: 100%;
    height: 0;
    padding-top: 56.25%;
    /* 16:9 = 9/16 = 0.5625 = 56.25% */
    background: #000;
    /* 黒背景 */
    min-height: 0;
    overflow: hidden;
    /* スクロールを完全に無効化 */
}

.stream-container .stream-placeholder,
.stream-container .stream-frame,
.stream-container>div[id*="youtube-player"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.stream-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #888;
    /* グレーのテキスト */
    text-align: center;
}

.stream-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
    overflow: hidden;
    /* スクロールを無効化 */
}

.stream-frame.active {
    display: block;
}

.controls {
    padding: 15px;
    background: #222;
    /* 濃いグレー */
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;
    /* 折り返しを無効化 */
    justify-content: flex-start;
    /* 左寄せ */
    overflow-x: auto;
    /* 横スクロール有効 */
    overflow-y: hidden;
    white-space: nowrap;
    /* 横並び強制 */
}

/* スクロールバーのスタイリング（Webkit系ブラウザ） */
.controls::-webkit-scrollbar {
    height: 6px;
}

.controls::-webkit-scrollbar-track {
    background: #333;
    border-radius: 3px;
}

.controls::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 3px;
}

.controls::-webkit-scrollbar-thumb:hover {
    background: #888;
}

.stream-button {
    padding: 10px 20px;
    border: 2px solid #666;
    /* グレーのボーダー */
    background: #333;
    /* 濃いグレー背景 */
    color: #fff;
    /* 白文字 */
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    border-radius: 5px;
    transition: all 0.2s;
    white-space: nowrap;
    /* ボタン内テキストの改行を防ぐ */
    flex-shrink: 0;
    /* ボタンサイズを固定 */
    height: 50px;
}

.stream-button:hover {
    background: #444;
    /* ホバー時少し明るく */
    border-color: #888;
}

.stream-button.active {
    background: #666;
    /* アクティブ時はより明るいグレー */
    color: white;
    border-color: #999;
}

.image-area {
    padding: 15px;
    background: #222;
    /* 濃いグレー */
    display: flex;
    gap: 10px;
    justify-content: center;
    /* デフォルトは中央寄せ */
    align-items: center;
    overflow-x: auto;
    /* 横スクロール有効 */
    overflow-y: hidden;
    white-space: nowrap;
    /* 横並び強制 */
    flex-wrap: nowrap;
    /* 折り返し無効 */
}

/* 横スクロールが必要な場合は左寄せ */
.image-area.scrollable {
    justify-content: flex-start;
}

/* スクロールバーのスタイリング（Webkit系ブラウザ） */
.image-area::-webkit-scrollbar {
    height: 6px;
}

.image-area::-webkit-scrollbar-track {
    background: #333;
    /* 黒っぽい背景 */
    border-radius: 3px;
}

.image-area::-webkit-scrollbar-thumb {
    background: #666;
    /* グレーのスクロールバー */
    border-radius: 3px;
}

.image-area::-webkit-scrollbar-thumb:hover {
    background: #888;
    /* ホバー時少し明るく */
}

.stream-image {
    width: 111px;
    height: 80px;
    object-fit: cover;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
    /* 画像サイズを固定 */
}

.stream-image:hover {
    transform: scale(1.05);
}

.chat-area {
    width: 385px;
    background: #111;
    /* 濃い黒背景 */
    border-left: 3px solid #333;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    flex-shrink: 0;
    /* 幅を固定 */
}

.chat-area.hidden {
    width: 0;
    overflow: hidden;
    border-left: none;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    min-height: 200px;
    /* チャットの最小高さを確保 */
}

.chat-frame {
    width: 100%;
    height: 100%;
    border: 1px solid #333;
    /* グレーのボーダー */
    border-radius: 5px;
    display: none;
    overflow: hidden;
    /* チャットのスクロールバーを無効化 */
}

.chat-frame.active {
    display: block;
}

/* YouTube表示時は16:9を解除 */
.stream-container.youtube-mode {
    height: auto;
    padding-top: 0;
    min-height: 500px;
}

.stream-container.youtube-mode .stream-placeholder,
.stream-container.youtube-mode .stream-frame,
.stream-container.youtube-mode>div[id*="youtube-player"] {
    position: relative;
    height: 100%;
    min-height: 500px;
}

/* スマホ時のYouTubeモード */
@media (max-width: 768px) {
    .stream-container.youtube-mode {
        min-height: 400px;
    }

    .stream-container.youtube-mode .stream-placeholder,
    .stream-container.youtube-mode .stream-frame,
    .stream-container.youtube-mode>div[id*="youtube-player"] {
        min-height: 400px;
    }
}

/* 縦幅が小さい場合の調整 */
@media (max-height: 700px) {
    .main-content {
        min-height: 400px;
        /* より小さい最小高さ */
    }

    .stream-container {
        min-height: 300px;
        /* 配信エリアの最小高さ */
    }

    .chat-container {
        min-height: 150px;
        /* チャットエリアの最小高さ */
    }
}

@media (max-height: 500px) {
    .header {
        padding: 6px 12px;
        /* さらにスリムに */
        font-size: 14px;
        /* フォントサイズをより小さく */
    }

    .controls {
        padding: 8px;
        /* コントロールを小さく */
    }

    .image-area {
        padding: 8px;
        /* 画像エリアを小さく */
    }

    .main-content {
        min-height: 250px;
    }

    .stream-container {
        min-height: 200px;
    }

    .chat-container {
        min-height: 100px;
        padding: 10px;
    }
}

/* 画面幅1200px以下でのチャット幅調整 */
@media (max-width: 1200px) and (min-width: 769px) {
    .chat-area {
        width: 350px;
        /* より狭くする */
    }
}

/* タブレット用レスポンシブデザイン（768px〜1024px） */
@media (max-width: 1024px) and (min-width: 769px) {
    .controls {
        padding: 12px;
        gap: 8px;
        flex-wrap: nowrap;
        /* 折り返し無効 */
        overflow-x: auto;
        /* 横スクロール */
    }

    .stream-button {
        padding: 8px 16px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .chat-area {
        width: 350px;
        /* タブレットでのチャット最小幅を確保 */
    }

    .chat-container {
        height: 300px;
        /* タブレットでのチャット最小高さを確保 */
    }
}

/* スマートフォン用レスポンシブデザイン（768px以下） */
@media (max-width: 768px) {
    .container {
        width: 100%;
        max-width: 100%;
    }

    .main-content {
        flex-direction: column;
        min-height: auto;
        /* 自動高さに変更 */
    }

    .stream-area {
        border-right: none;
        border-bottom: 3px solid #333;
        flex: none;
        /* flexを無効化 */
        min-width: 0;
        /* 最小幅をリセット */
        overflow: hidden;
        /* はみ出しを防ぐ */
    }

    /* スマホでも16:9維持 */
    .stream-container {
        position: relative;
        width: 100%;
        height: 0;
        padding-top: 56.25%;
        min-height: 0;
        overflow: hidden;
    }

    .stream-container .stream-placeholder,
    .stream-container .stream-frame,
    .stream-container>div[id*="youtube-player"] {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    .chat-area {
        width: 100% !important;
        /* チャット幅を100%に */
        flex: 1 !important;
        /* 残りの高さを全て使用 */
        border-left: none;
        border-top: 3px solid #333;
        /* 重要：flexアイテムとしての制約を完全に解除 */
        max-width: none !important;
        flex-basis: 0 !important;
        min-height: 0 !important;
        /* flexで高さを決定 */
    }

    .chat-area.hidden {
        width: 100% !important;
        /* 隠れ状態でも幅は100% */
        height: 0 !important;
        min-height: 0 !important;
        flex: 0 0 0 !important;
        /* 高さを0に */
        overflow: hidden;
        border-top: none;
        /* 隠れ状態でも幅制約を解除 */
        max-width: none !important;
    }

    .chat-container {
        flex: 1 !important;
        /* チャットコンテナも残り高さを全て使用 */
        height: 100% !important;
        /* 親要素の高さを100%使用 */
        width: 100% !important;
        /* コンテナも100%幅 */
        min-height: 0 !important;
        /* flexで高さを決定 */
    }

    .chat-frame {
        height: 100% !important;
        /* フレームも100%の高さ */
        width: 100% !important;
        /* フレームも100%幅 */
        min-height: 0 !important;
        /* flexで高さを決定 */
    }

    .controls {
        padding: 10px;
        gap: 8px;
        flex-wrap: nowrap;
        /* 折り返し無効 */
        justify-content: flex-start;
        /* 左寄せに変更 */
        min-width: 0;
        overflow-x: auto;
        /* 横スクロール */
        overflow-y: hidden;
    }

    .stream-button {
        padding: 8px 12px;
        font-size: 12px;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .header {
        padding: 8px 12px;
        /* スリムに調整 */
        font-size: 14px;
        /* フォントサイズを小さく */
        min-width: 0;
    }

    .chat-toggle-btn {
        padding: 4px 6px;
        /* よりコンパクトに */
        font-size: 12px;
        /* フォントサイズを小さく */
        flex-shrink: 0;
    }

    .image-area {
        padding: 10px;
        gap: 8px;
        min-width: 0;
        overflow-x: auto;
    }

    .stream-image {
        flex-shrink: 0;
        width: 111px;
        height: 80px;
    }
}