/* ================================
   全体レイアウト共通
================================ */

/* 画面全体を使うための基本設定 */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* 全体レイアウト ------------------------ */
body {
    font-family:
        "Hiragino Sans",
        "Hiragino Kaku Gothic ProN",
        "Hiragino Kaku Gothic Pro",
        "Noto Sans JP",
        sans-serif;
    margin: 0;
    display: flex;
    height: 100dvh;
    background: #f3f4f6;
}

/* 左：チャットエリア / 右：ユーザー一覧 */
.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ddd;
    min-width: 0;
    min-height: 0;
}

.sidebar {
    width: 220px;
    padding: 8px;
    box-sizing: border-box;
    overflow-y: auto;
}

.sidebar h3 {
    margin-top: 0;
    font-size: 14px;
}

#userList {
    font-size: 13px;
    line-height: 1.6;
}

/* ヘッダー ------------------------------ */
header {
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

#roomTitle {
    font-weight: bold;
}

#statusText {
    font-size: 12px;
    color: #555;
}

/* 入室前のお知らせエリア */
#chatInfoBeforeJoin {
    padding: 8px 12px;
    font-size: 13px;
    color: #666;
    border-bottom: 1px solid #ddd;
}

/* ================================
   チャットログ
================================ */

#chatLog {
    flex: 1;                 /* ヘッダーとフッター以外を全部使う */
    padding: 8px 12px;
    overflow-y: auto;
    font-size: 14px;
    background: #fafafa;
    display: none;           /* 入室前は非表示 */
}

.system-message {
    color: #777;
    font-size: 12px;
    margin: 4px 0;
}

.message-row {
    display: flex;
    flex-direction: column;
}

.message-row.self {
    align-items: flex-end;
}

.message {
    margin: 4px 0;
    padding: 6px 8px;
    border-radius: 12px;
    display: inline-block;
    max-width: 80%;
    word-break: break-word;
    position: relative; /* しっぽの基準 */
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.message-meta {
    font-size: 11px;
    color: #666;
    margin-bottom: 2px;
}

.message-self {
    background: #e0f3ff;
    align-self: flex-end;
}

.message-other {
    background: #ffffff;
}

/* 吹き出しのしっぽ ---------------------- */
.message::after {
    content: "";
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--bubble-color, #ffffff);
    transform: rotate(45deg);
}

.message-row.other .message::after {
    bottom: -4px;
    left: 14px;
}

.message-row.self .message::after {
    bottom: -4px;
    right: 14px;
}


/* お題メッセージ ----------------------------------- */
.topic-message {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 10px;
    background: linear-gradient(135deg, #fef2f2, #fff7ed);
    border: 1px solid #fecaca;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

/* 上部のヘッダー行（ラベル＋メタ情報） */
.topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 11px;
}

/* 🎯 お題ラベル部分（ピル型） */
.topic-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(248, 113, 113, 0.18);  /* 薄い赤 */
    color: #b91c1c;
    font-weight: 600;
}

/* [時間] 誰が引いたか */
.topic-meta {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
}

/* お題本文 */
.topic-body {
    margin-top: 2px;
    font-size: 14px;
    font-weight: 600;
    color: #7f1d1d;
    line-height: 1.5;
}

/* ================================
   フッター（入力まわり）
================================ */

.footer {
    border-top: 1px solid #ddd;
    padding: 8px 12px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;      /* 高さは中身に合わせる */
}

/* 入室前：名前入力 */
.name-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

#nameInput {
    flex: 1;
}

/* メッセージ入力＆送信ボタン */
.input-row {
    display: none; /* 入室前は非表示（入室後に JS で flex に） */
    gap: 4px;
}

#msgInput {
    flex: 1;
}

input[type="text"] {
    padding: 4px 6px;
    font-size: 13px;
}

#sendBtn {
    background: #4b5563;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

#sendBtn:hover {
    background: #374151;
}

#sendBtn:disabled {
    background: #9ca3af;
    cursor: default;
}

#joinBtn,
#renameBtn {
    font-size: 13px;
    padding: 4px 8px;
    cursor: pointer;
}

/* 吹き出し色選択 ------------------------ */
.color-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 12px;
    color: #555;
}

.color-label {
    white-space: nowrap;
}

.color-row label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

/* ラジオボタン本体は隠す */
.color-row input[type="radio"] {
    display: none;
}

/* 色見本の丸いスウォッチ */
.color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid #d4d4d8;
    display: inline-block;
}

/* パレットの色（HTML の value と合わせるだけ） */
.color-pink   { background: #FFEBEE; }
.color-blue   { background: #E3F2FD; }
.color-green  { background: #E8F5E9; }
.color-orange { background: #FFF3E0; }

/* 選択中のものだけ縁取り */
.color-row input[type="radio"]:checked + .color-swatch {
    outline: 2px solid #4b5563;
    outline-offset: 1px;
}

/* 定型文ボタンの行 ---------------------- */
.template-row {
    display: none;          /* 入室前は非表示（入室後に JS で flex に） */
    gap: 8px;
    margin-top: 8px;
}

.template-btn {
    background: #6b7280;
    color: white;
    border: none;
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
}

.template-btn:hover {
    background: #4b5563;
}

.template-btn:disabled {
    background: #9ca3af;
    cursor: default;
}

/* ダイスボタン（定型文とほぼ同じ） */
.dice-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    background-color: #6b7280;
    color: #ffffff;
    cursor: pointer;
}

.dice-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #fff; 
}

/* 入室後だけ表示する小さなコントロール */
.after-join-controls {
    display: none;     /* 入室前は非表示 */
    gap: 6px;
    justify-content: space-between;
}

.after-join-controls button {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    white-space: nowrap;
    font-size: 14px;
    background: #e5e7eb;
    color: #444;
    border: 1px solid #ccc;
    border-radius: 6px;
    cursor: pointer;
}

.after-join-controls button:hover {
    background: #d4d4d4;
}

/* 色変更 UI（ラジオ + 決定/キャンセル） */
.color-change-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.color-change-row label {
    display: flex;
    align-items: center;
}

.color-change-btn {
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
}

/* 入室後はメッセージ入力欄を少し強調 */
body.joined #msgInput {
    border: 1px solid #2563eb;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}

#typingInfo {
    font-size: 11px;
    color: #888;
    min-height: 14px;
}

/* ================================
   スマホ用オンライン一覧モーダル
================================ */

/* ヘッダー右のボタン（PCでは非表示） */
.mobile-user-btn {
    display: none;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid #d4d4d4;
    background: #ffffff;
    color: #374151;
    cursor: pointer;
}

/* オンライン一覧モーダル（スマホ用） */
.mobile-user-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.mobile-user-panel {
    width: 90%;
    max-width: 340px;
    max-height: 70vh;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.mobile-user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
}

.mobile-user-close {
    border: none;
    background: transparent;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
}

.mobile-user-list {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.6;
    max-height: 56vh;
    overflow-y: auto;
}

/* ================================
   利用上の注意
================================ */

.chat-notice {
    background-color: #f7f7f7;
    border: 1px solid #dddddd;
    border-radius: 6px;
    padding: 8px 10px;
    margin: 8px 8px 4px;
    font-size: 12px;
    line-height: 1.4;
    color: #444;
}

.chat-notice-title {
    margin: 0 0 4px;
    font-weight: bold;
    font-size: 13px;
    color: #333;
}

.chat-notice-list {
    margin: 0;
    padding-left: 18px;
}

.chat-notice-list li {
    margin-bottom: 2px;
}

/* ================================
   ハンバーガーメニュー（スマホ）
================================ */

/* ボタン本体 */
.mobile-menu-btn {
    border: none;
    background: none;
    padding: 6px;
    display: none; /* PCでは非表示 */
    cursor: pointer;
}

.mobile-menu-btn span {
    display: block;
    width: 20px;
    height: 2px;
    margin: 3px 0;
    background-color: #000; /* ヘッダー背景が白前提で黒に */
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* メニュー本体（閉じているときは非表示） */
.mobile-menu {
    display: none;
    position: absolute;
    top: 56px; /* ヘッダーの高さに合わせて調整 */
    right: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.9);
    padding: 8px 0;
    z-index: 1000;
}

.mobile-menu-item {
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    border: none;
    background: transparent;
    color: #fff;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-menu-item:last-child {
    border-bottom: none;
}

.mobile-menu-leave {
    color: #ff7676;
}

/* メニューが開いているとき用のクラス */
.mobile-menu.open {
    display: block;
}

.mobile-menu-btn.open span:nth-child(1) {
    transform: translateY(5px) rotate(45deg);
}
.mobile-menu-btn.open span:nth-child(2) {
    opacity: 0;
}
.mobile-menu-btn.open span:nth-child(3) {
    transform: translateY(-5px) rotate(-45deg);
}

/* ================================
   スマホ向けレイアウト
================================ */

@media (max-width: 768px) {

    /* 縦並びレイアウトに変更（サイドバーを下ではなく消す） */
    body {
        flex-direction: column;
    }

    .chat-wrapper {
        border-right: none;
        border-bottom: 1px solid #ddd;
        width: 100%;
        min-height: 0;
    }

    /* サイドバーは非表示（オンラインはモーダルで見る） */
    .sidebar {
        display: none;
    }

    /* フッターをスリムに */
    .footer {
        padding: 6px 8px;
        gap: 4px;
    }

    /* 入力欄をコンパクトに */
    .input-row input#msgInput {
        font-size: 16px;
        padding: 4px 6px;
        height: 32px;
    }

    .input-row button#sendBtn {
        padding: 4px 8px;
        font-size: 13px;
        height: 32px;
    }

    /* 名前入力行も少し詰める */
    .name-row input#nameInput {
        font-size: 16px;
        padding: 4px 6px;
        height: 32px;
    }

    .name-row button#joinBtn {
        padding: 4px 8px;
        font-size: 13px;
        height: 32px;
    }

    /* 入力欄・送信・入室ボタンを統一した高さにする */
    .input-row input#msgInput,
    .input-row button#sendBtn,
    .name-row input#nameInput,
    .name-row button#joinBtn {
        box-sizing: border-box;
        height: 36px;            /* ← 好きな高さに（32〜40推奨） */
        font-size: 16px;
        padding: 6px 8px;        /* ← input と button を揃える */
    }

    /* 名前入力欄の全幅を維持 */
    #nameInput,
    #msgInput {
        width: 100%;
    }

    /* after-join-controls（名前変更／色変更／退室）は
       スマホでは非表示にしてヘッダーメニューへ集約 */
    .after-join-controls {
        display: none !important;
    }

    /* 高さは送信ボタンと揃える（36px） */
    .template-row .template-btn,
    .template-row .dice-btn {
        height: 36px;
        padding: 0 8px;
        font-size: 13px;
        border-radius: 6px;
        box-sizing: border-box;
    }

    /* ボタン間の余白はすべて均等に */
    .template-row {
        gap: 4px;
    }

    /* 吹き出し色行も少し詰める（入室前のみ表示想定） */
    .color-row {
        gap: 4px;
        font-size: 11px;
    }
    .color-label {
        font-size: 11px;
    }

    /* ハンバーガーメニューを表示 */
    .mobile-menu-btn {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    /* 旧モバイル用オンラインボタンは使わない */
    .mobile-user-btn {
        display: none;
    }

    /* スマホではチャットログの文字を少しだけ小さめに */
    #chatLog {
        padding: 6px 8px;
        font-size: 13px;
    }

    .message {
        max-width: 90%;
        font-size: 14px;
    }

    .message-meta {
        font-size: 11px;
    }

    .topic-message {
        padding: 6px 8px;
    }
    .topic-body {
        font-size: 13px;
    }

}
