/* ===== ベース ===== */
html, body {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', 'Meiryo', sans-serif;
    background: #f5f5f5;
    color: #333;
}

/* ===== 共通スタイル ===== */
#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== TOPページ ===== */
#top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #7c4dff;
}

#top-header h1 {
    font-size: 1.8em;
    color: #7c4dff;
    margin: 0;
}

#new-session-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #7c4dff;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: bold;
    transition: background 0.2s;
}

#new-session-btn:hover {
    background: #6200ea;
}

#session-list h2 {
    font-size: 1.3em;
    color: #555;
    margin-bottom: 20px;
}

#sessions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.session-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.session-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.session-card h3 {
    margin: 0 0 10px 0;
    color: #7c4dff;
    font-size: 1.1em;
}

.session-card .character-name {
    font-weight: bold;
    margin-bottom: 5px;
}

.session-card .session-title {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 10px;
}

.session-card .session-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: #999;
    margin-top: 10px;
}

.session-card .continue-btn {
    display: inline-block;
    margin-top: 15px;
    padding: 8px 16px;
    background: #7c4dff;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9em;
    transition: background 0.2s;
}

.session-card .continue-btn:hover {
    background: #6200ea;
}

.empty-message {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: 1.1em;
}

/* ===== 新規セッション作成ページ ===== */
#new-session-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #7c4dff;
}

#new-session-header h1 {
    font-size: 1.8em;
    color: #7c4dff;
    margin: 0;
    flex-grow: 1;
}

#back-btn {
    display: inline-block;
    padding: 8px 16px;
    background: #f0f0f0;
    color: #666;
    text-decoration: none;
    border-radius: 6px;
    font-weight: bold;
    transition: background 0.2s;
}

#back-btn:hover {
    background: #e0e0e0;
}

#character-grid h2 {
    font-size: 1.3em;
    color: #555;
    margin-bottom: 20px;
}

#characters-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.character-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.character-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.character-card .avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #f0e6ff;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.character-card .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-card .avatar-placeholder {
    font-size: 2em;
    color: #7c4dff;
}

.character-card .name {
    font-size: 1.2em;
    font-weight: bold;
    color: #7c4dff;
    text-align: center;
    margin-bottom: 10px;
}

.character-card .description {
    font-size: 0.9em;
    color: #666;
    line-height: 1.6;
    margin-bottom: 15px;
    max-height: 60px;
    overflow: hidden;
}

.character-card .start-btn {
    display: block;
    padding: 10px;
    background: #7c4dff;
    color: white;
    text-align: center;
    text-decoration: none;
    border-radius: 6px;
    font-weight: bold;
    transition: background 0.2s;
}

.character-card .start-btn:hover {
    background: #6200ea;
}

/* ===== チャットページ (既存スタイルを継承) ===== */
/* チャットコンテナ */
#chat-container {
    max-width: 700px;
    height: 100vh;
    margin: 0 auto;
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* チャットヘッダー */
#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 8px;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 8px;
}

#header-title {
    font-size: 1.05em;
    font-weight: bold;
    color: #5a3db0;
}

#panel-toggle {
    background: none;
    border: none;
    font-size: 1.4em;
    cursor: pointer;
    color: #7c4dff;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s;
}

#panel-toggle:hover {
    background: #ede7ff;
    transform: rotate(20deg);
}

/* メッセージエリア */
#messages {
    border: 1px solid #ccc;
    flex-grow: 1;
    overflow-y: scroll;
    margin-bottom: 10px;
    padding: 10px 10px 80vh 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fff;
    border-radius: 10px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.ai {
    align-self: flex-start;
    align-items: flex-start;
    max-width: 100%;
}

.bubble {
    padding: 10px 14px;
    border-radius: 15px;
    margin-top: 2px;
    white-space: pre-wrap;
    line-height: 1.6;
}

.user .bubble {
    background-color: #d4f5d4;
}

.ai .bubble {
    background-color: #f0e6ff;
}

/* AIメッセージ内の各エリア */
.ai .bubble.main-area {
    background-color: #fff8e8;
    color: #000;
    border-radius: 0px;
    border: 1px solid #e0e0e0;
    margin-top: 4px;
}

.ai .bubble.message-area {
    background-color: #f0e6ff;
    margin-top: 4px;
}

.ai .bubble.meta-area {
    background-color: #eee;
    color: #888;
    font-size: 0.7em;
    padding: 6px 10px;
    border-radius: 0px;
    margin-top: 4px;
    border: 1px solid #ddd;
}

.ai-name {
    font-weight: bold;
    color: #7c4dff;
}

/* メッセージヘッダーとアクションボタン */
.msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.user .msg-header {
    justify-content: flex-end;
}

.ai .msg-header {
    justify-content: flex-start;
}

.msg-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.msg-btn {
    background: transparent;
    border: none;
    padding: 0 3px;
    font-size: 0.9em;
    cursor: pointer;
    opacity: 0.35;
    transition: opacity 0.2s, transform 0.1s;
    line-height: 1;
    color: #555;
}

.msg-btn:hover {
    opacity: 0.95;
    transform: scale(1.15);
}


/* 思考エリア（ストリーミング中：垂れ流し表示） */
.thought {
    font-size: 0.82em;
    color: #666;
    background: linear-gradient(135deg, #f5f5f5, #ececec);
    border-left: 3px solid #aaa;
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    white-space: pre-wrap;
    font-style: italic;
    width: 100%;
    box-sizing: border-box;
}

.thought::before {
    content: "💭 思考中…";
    display: block;
    font-size: 0.85em;
    font-weight: bold;
    color: #888;
    margin-bottom: 4px;
    font-style: normal;
}

/* 思考アコーディオン（完了後） */
.thought-accordion {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 6px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #fafafa;
    overflow: hidden;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.thought-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-size: 0.82em;
    font-weight: bold;
    color: #777;
    cursor: pointer;
    user-select: none;
    list-style: none;
    background: linear-gradient(135deg, #efefef, #e6e6e6);
    border-radius: 8px;
    transition: background 0.2s;
}

.thought-summary::-webkit-details-marker {
    display: none;
}

.thought-summary::marker {
    display: none;
}

.thought-summary::after {
    content: '▶';
    margin-left: auto;
    font-size: 0.75em;
    transition: transform 0.25s ease;
    color: #aaa;
}

.thought-accordion[open] .thought-summary::after {
    transform: rotate(90deg);
}

.thought-summary:hover {
    background: linear-gradient(135deg, #e8e8e8, #ddd);
}

.thought-content {
    margin: 0;
    padding: 8px 12px;
    font-size: 0.80em;
    color: #666;
    white-space: pre-wrap;
    font-style: italic;
    font-family: inherit;
    line-height: 1.5;
    border-top: 1px solid #e0e0e0;
}

/* 入力エリア */
#input-area {
    display: flex;
    gap: 10px;
    padding: 10px 0;
}

#input {
    flex-grow: 1;
    padding: 10px;
    box-sizing: border-box;
    resize: vertical;
    min-height: 50px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1em;
}

#send {
    padding: 10px 20px;
    background: #7c4dff;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
}

#send:hover {
    background: #6200ea;
}

/* ===== サイドパネル オーバーレイ ===== */
#panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#panel-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== サイドパネル本体 ===== */
#side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 101;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#side-panel.open {
    transform: translateX(0);
}

/* パネルヘッダー */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #ede7ff;
    background: linear-gradient(135deg, #7c4dff, #6200ea);
}

.panel-title {
    font-size: 1.05em;
    font-weight: bold;
    color: #fff;
    letter-spacing: 0.03em;
}

#panel-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 1em;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#panel-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* パネルボディ */
.panel-body {
    flex-grow: 1;
    padding: 20px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* 設定グループ */
.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-label {
    font-size: 0.88em;
    font-weight: bold;
    color: #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-value {
    font-size: 0.95em;
    font-weight: bold;
    color: #7c4dff;
    background: #ede7ff;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 36px;
    text-align: center;
}

/* セレクトボックス */
.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '▾';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #7c4dff;
    pointer-events: none;
    font-size: 1em;
}

.select-wrapper select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background: #f7f4ff;
    border: 1.5px solid #c9b8ff;
    border-radius: 8px;
    padding: 8px 30px 8px 12px;
    font-size: 0.88em;
    color: #333;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.select-wrapper select:focus {
    border-color: #7c4dff;
}

/* レンジスライダー */
input[type="range"] {
    width: 100%;
    accent-color: #7c4dff;
    cursor: pointer;
    height: 5px;
}

.range-minmax {
    display: flex;
    justify-content: space-between;
    font-size: 0.75em;
    color: #999;
    margin-top: -4px;
}

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
    #app {
        padding: 10px;
    }

    #sessions-container,
    #characters-container {
        grid-template-columns: 1fr;
    }

    #top-header,
    #new-session-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    #new-session-btn {
        width: 100%;
        text-align: center;
    }
}

/* ===== キャラクター詳細オーバーレイ ===== */
.md-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.md-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.md-modal {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    transform: translateY(20px) scale(0.98);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.md-overlay.active .md-modal {
    transform: translateY(0) scale(1);
}

.md-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #ede7ff;
    background: linear-gradient(135deg, #7c4dff, #6200ea);
    border-radius: 12px 12px 0 0;
}

.md-header h2 {
    margin: 0;
    color: #fff;
    font-size: 1.2em;
    font-weight: bold;
}

.md-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1.4em;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s;
}

.md-close:hover {
    background: rgba(255,255,255,0.3);
}

.md-content {
    padding: 24px;
    overflow-y: auto;
    flex-grow: 1;
    font-family: 'Segoe UI','Meiryo',sans-serif;
    line-height: 1.8;
    color: #333;
    white-space: pre-wrap;
    word-break: break-word;
}

.md-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #ede7ff;
    background: #fafafa;
    border-radius: 0 0 12px 12px;
}

.md-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.md-btn:active {
    transform: scale(0.98);
}

.md-btn-primary {
    background: #7c4dff;
    color: white;
}

.md-btn-primary:hover {
    background: #6200ea;
}

.md-btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.md-btn-secondary:hover {
    background: #d0d0d0;
}

#edit-modal-textarea {
    width: 100%;
    min-height: 240px;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', 'Meiryo', monospace;
    font-size: 0.95em;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
}

#edit-modal-textarea:focus {
    outline: none;
    border-color: #7c4dff;
    box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.15);
}

.edit-modal-note {
    margin: 12px 0 0 0;
    font-size: 0.85em;
    color: #888;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .md-modal {
        width: 95%;
        max-height: 90vh;
    }
}

/* 閲覧専用モードでユーザープロンプトの «...» 部分を非表示 */
.hidden-prompt {
    display: none;
}

/* ===== 閲覧専用モード (mode=view) ===== */
body.view-mode #side-panel,
body.view-mode #panel-overlay,
body.view-mode #panel-toggle,
body.view-mode #input-area,
body.view-mode .msg-actions,
body.view-mode .edit-title-btn {
    display: none !important;
}

body.view-mode #chat-container {
    max-width: 900px;
    margin: 0 auto;
}

body.view-mode #messages {
    margin-bottom: 0;
    padding-bottom: 10px;
}
