/* ============================================
   基本レイアウト
   ============================================ */
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; /* 画面全体のバウンス（揺れ）を防止 */
}

/* ============================================
   ヘッダー（外部CSSがある想定ですが、高さを維持）
   ============================================ */
.nav {
    flex-shrink: 0; /* 潰れないように固定 */
}

/* ============================================
   チャットエリア（ここだけをスクロールさせる）
   ============================================ */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    -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: 80%; /* スマホで見やすい幅 */
    line-height: 1.6; 
    font-size: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    display: block;
    width: fit-content;
}

.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;
}

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

/* 作品案内板：スマホで場所を取らないよう横スクロール化 */
#guide-board {
    display: flex;
    flex-wrap: nowrap; 
    overflow-x: auto;
    gap: 8px;
    padding: 10px; 
    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 12px;
    background: #fff;
    color: #8d6e63;
    border: 1px solid #ffcc80;
    border-radius: 20px;
    text-decoration: none;
    white-space: nowrap;
}

/* 入力エリア */
#input-area { 
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); /* iPhoneのホームバー余白を確保 */
    background: #fff; 
    display: flex; 
    gap: 8px; 
    border-top: 1px solid #ffcc80; 
    flex-shrink: 0;
    align-items: center;
}

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

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

input { 
    flex: 1; 
    min-width: 0; /* flex内のinputがはみ出すのを防ぐ */
    padding: 10px; 
    border: 1px solid #ddd; 
    border-radius: 8px; 
    outline: none; 
    font-size: 16px; /* 16px以上にするとiOSの自動ズームを防げる */
}

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

/* ============================================
   その他演出
   ============================================ */
#lightbox {
    display: none;
    position: fixed;
    z-index: 2000;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    align-items: center;
    justify-content: center;
}

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

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