/* ============================================
   基本レイアウト
   ============================================ */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* 全体のスクロールを禁止 */
}

body { 
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
    background: #fff5e6; 
    display: flex; 
    flex-direction: column; 
    /* iOS/Androidのアドレスバーを考慮した動的な高さ設定 */
    height: 100dvh; 
    width: 100%;
    position: fixed; /* 画面全体のバウンス（揺れ）を防止 */
}

/* ============================================
   チャットエリア（ここだけをスクロールさせる）
   ============================================ */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch; /* iOSでスルスル動くように */
    background: #fff5e6;
}

#chat { 
    display: flex; 
    flex-direction: column; 
    width: 100%;
    box-sizing: border-box;
}

/* 吹き出し */
.bubble { 
    margin-bottom: 15px; 
    padding: 12px 18px; 
    border-radius: 18px; 
    max-width: 400px; /* PCでの最大幅 */
    line-height: 1.6; 
    font-size: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    display: block;
    width: fit-content;
    min-width: 0;
}

.ai { 
    background: #ffffff; 
    align-self: flex-start; 
    border: 1px solid #ffcc80; 
    color: #333;
}

.user { 
    background: #ffcc80; 
    align-self: flex-end; 
    color: #5d4037;
}

/* 吹き出し内の画像設定：物語の燃料を最大限活かす */
.bubble img { 
    width: 100%;
    max-width: 100%; 
    height: auto;
    border-radius: 12px; 
    margin-top: 10px; 
    display: block; 
    cursor: zoom-in;
    transition: transform 0.2s;
}

/* ============================================
   下部固定エリア（入力欄 ＋ 案内板）
   ============================================ */
footer-area {
    flex-shrink: 0;
    background: #fff;
}

/* 作品案内板：スマホで場所を取らないよう横スクロール化 */
#guide-board {
    display: flex;
    flex-wrap: nowrap; 
    overflow-x: auto;
    gap: 8px;
    padding: 10px 15px; 
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

#guide-board::-webkit-scrollbar {
    display: none; /* スクロールバー非表示 */
}

.guide-chip {
    flex: 0 0 auto;
    font-size: 11px;
    padding: 6px 14px;
    background: #fff;
    color: #8d6e63;
    border: 1px solid #ffcc80;
    border-radius: 20px;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

/* 入力エリア */
#input-area { 
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); 
    background: #fff; 
    display: flex; 
    gap: 8px; 
    border-top: 1px solid #ffcc80; 
    flex-shrink: 0;
    align-items: center;
}

#lang-toggle-btn {
    padding: 8px 10px;
    font-size: 12px;
    background: #fff;
    border: 1px solid #ffcc80;
    color: #8d6e63;
    min-width: 50px;
    border-radius: 8px;
    flex-shrink: 0;
}

#episode-list {
    padding: 8px 5px;
    border: 1px solid #ffcc80;
    border-radius: 8px;
    background: #fff;
    color: #5d4037;
    font-size: 13px;
    max-width: 100px;
    cursor: pointer;
    flex-shrink: 0;
}

input { 
    flex: 1; 
    min-width: 0;
    padding: 10px; 
    border: 1px solid #ddd; 
    border-radius: 8px; 
    outline: none; 
    font-size: 16px; /* iOSのズーム防止 */
}

#send-btn { 
    background: #ffcc80; 
    border: none; 
    padding: 10px 20px; 
    border-radius: 8px; 
    cursor: pointer; 
    font-weight: bold;
    color: #5d4037;
    flex-shrink: 0;
}

/* ============================================
   レスポンシブ・演出
   ============================================ */
@media screen and (max-width: 768px) {
    .bubble {
        max-width: 90%; 
    }
}

/* PC用：マウスホバー */
@media (hover: hover) {
    .bubble img:hover { transform: scale(1.02); }
    .guide-chip:hover {
        background: #ffcc80;
        color: #5d4037;
        transform: translateY(-1px);
    }
}

/* ライトボックス */
#lightbox {
    display: none;
    position: fixed;
    z-index: 2000;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    cursor: zoom-out;
    align-items: center;
    justify-content: center;
}

#lightbox img {
    max-width: 95%;
    max-height: 95%;
    border: 2px solid white;
    border-radius: 4px;
}

/* style.css: ポップアップの基本スタイル */
#expanded-input-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none; /* JSで制御 */
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 15px;
    box-sizing: border-box;
}

#expanded-input-card {
    background: #fff;
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
    color: #8d6e63;
}

#expanded-msg {
    width: 100%;
    height: 100px; /* 100文字程度に最適な高さ */
    border: 1px solid #ffcc80;
    border-radius: 10px;
    padding: 12px;
    box-sizing: border-box;
    font-size: 16px; /* iOSズーム防止 */
    resize: none;
    outline: none;
}

#expanded-send-btn {
    width: 100%;
    margin-top: 15px;
    padding: 12px;
    background: #ffcc80;
    border: none;
    border-radius: 10px;
    color: #5d4037;
    font-weight: bold;
}
/* デバッグログを最下部（入力欄の上）に配置 */
/* --- デバッグログの配置修正 --- */
#debug-log {
    /* position: fixed をやめて、通常の要素として最下部に配置 */
    position: relative; 
    background: #333; /* 背景を暗くしてデバッグ情報を際立たせる */
    color: #00ff00;   /* 緑文字 */
    font-family: monospace;
    font-size: 10px;
    padding: 10px;
    max-height: 80px; /* 高くなりすぎないよう制限 */
    overflow-y: auto;
    border-top: 1px solid #444;
    width: 100%;
    box-sizing: border-box;
    /* pointer-events: none; は外します。ログのコピーやスクロールができるようにするため */
}

/* クイックボタンのコンテナ：少しだけ高さを抑える */
#quick-btn-container {
    display: flex;
    justify-content: center;
    gap: 8px; /* 間隔を少し詰める */
    padding: 8px 10px; /* 上下パディングを小さく */
    background: #fff;
    border-top: 1px solid #ffcc80;
    flex-shrink: 0;
}

/* ボタン本体：一回り小さく、丸みを維持 */
.quick-chip {
    padding: 5px 12px; /* 小さく調整 */
    background: #fff;
    border: 1.5px solid #ffcc80; /* 線も少し細く */
    border-radius: 15px; /* サイズに合わせて丸みを調整 */
    color: #5d4037;
    font-size: 12px; /* 13pxから12pxへ */
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(255, 204, 128, 0.1);
    transition: all 0.2s;
    white-space: nowrap; /* 改行防止 */
}

/* PCホバー時の動きを控えめに */
@media (hover: hover) {
    .quick-chip:hover {
        background: #ffcc80;
        transform: translateY(-0.5px);
    }
}
