:root {
  --bg-color: #0a0712;
  --panel-bg: rgba(22, 18, 36, 0.75);
  --card-bg: rgba(32, 26, 53, 0.6);
  --accent-purple: #9d4edd;
  --accent-purple-glow: rgba(157, 78, 221, 0.4);
  --accent-gold: #ffb703;
  --accent-gold-glow: rgba(255, 183, 3, 0.35);
  --text-main: #f3f0f7;
  --text-muted: #9e9aa7;
  --border-color: rgba(90, 63, 156, 0.4);
  --danger-color: #e63946;
  --success-color: #2a9d8f;
  --taro-bubble: rgba(56, 36, 92, 0.85);
  --monet-bubble-bg: rgba(22, 18, 36, 0.82);
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; 
}

/* カスタムスクロールバー */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0a0712; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent-purple), #5a3f9c);
  border-radius: 4px;
  border: 1px solid rgba(255, 183, 3, 0.3);
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--accent-gold), var(--accent-purple));
}

body { 
  background-color: var(--bg-color); 
  color: var(--text-main); 
  height: 100vh; 
  height: 100dvh;
  display: flex; 
  flex-direction: column; 
  overflow: hidden; 
  position: relative;
}

/* スマホ・背面常駐用レイヤー */
#mobile-bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
  pointer-events: none;
}
#mobile-bg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 80% 80%, rgba(10, 7, 18, 0.35) 0%, rgba(10, 7, 18, 0.85) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 0;
  pointer-events: none;
}

/* --- ヘッダー開閉（トグル格納）機能 --- */
header {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-top 0.3s ease;
  will-change: transform;
  background: var(--panel-bg); 
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color); 
  padding: 10px 16px; 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  z-index: 10; 
  flex-wrap: wrap; 
  gap: 8px; 
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.header-collapsed header {
  transform: translateY(-100%);
  margin-bottom: 0;
  pointer-events: none;
}

#header-expand-btn {
  display: none;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  background: rgba(22, 18, 36, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 3px 14px;
  font-size: 0.7rem;
  color: var(--accent-gold);
  letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: all 0.2s ease;
}
#header-expand-btn:hover {
  background: rgba(45, 36, 75, 0.95);
  box-shadow: 0 0 10px var(--accent-gold-glow);
}
body.header-collapsed #header-expand-btn {
  display: block;
}

#header-collapse-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
#header-collapse-btn:hover {
  color: var(--accent-gold);
}

.logo-area { display: flex; align-items: center; gap: 8px; }
.logo-title { 
  font-size: 1.15rem; 
  font-weight: bold; 
  letter-spacing: 0.5px;
  background: linear-gradient(45deg, var(--accent-purple), var(--accent-gold)); 
  -webkit-background-clip: text; 
  -webkit-text-fill-color: transparent; 
  text-shadow: 0 0 12px var(--accent-purple-glow);
}
.header-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ボタン＆ネオンエフェクト */
button { 
  background: var(--card-bg); 
  color: var(--text-main); 
  border: 1px solid var(--border-color); 
  border-radius: 6px; 
  padding: 6px 12px; 
  font-size: 0.85rem; 
  cursor: pointer; 
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); 
  position: relative;
}
button:hover { 
  border-color: var(--accent-purple); 
  box-shadow: 0 0 10px var(--accent-purple-glow);
  transform: translateY(-1px);
}
button:active { transform: translateY(1px); }
button.primary { 
  background: linear-gradient(135deg, #7b2cbf, #9d4edd); 
  border: none; 
  font-weight: bold; 
  box-shadow: 0 0 8px var(--accent-purple-glow);
  color: #fff;
}
button.primary:hover { box-shadow: 0 0 15px rgba(157, 78, 221, 0.7); }
button.gold { 
  background: linear-gradient(135deg, #b58300, #ffb703); 
  color: #0b0911; 
  font-weight: bold; 
  border: none; 
  box-shadow: 0 0 8px var(--accent-gold-glow);
}
button.gold:hover { box-shadow: 0 0 15px rgba(255, 183, 3, 0.6); }
button.small { padding: 2px 6px; font-size: 0.75rem; border-radius: 4px; }

select, input[type="text"], input[type="password"] { 
  background-color: rgba(22, 18, 36, 0.9); 
  color: var(--text-main); 
  border: 1px solid var(--border-color); 
  border-radius: 6px; 
  padding: 6px 10px; 
  font-size: 0.85rem; 
  outline: none; 
  transition: border-color 0.2s, box-shadow 0.2s;
}
select:focus, input:focus { 
  border-color: var(--accent-gold); 
  box-shadow: 0 0 8px var(--accent-gold-glow);
}
/* Thinking非活性時のスタイル */
#thinking-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: rgba(15, 12, 24, 0.6);
  border-color: rgba(90, 63, 156, 0.2);
  color: var(--text-muted);
}

/* 3カラム Main Container */
main { 
  flex: 1; 
  display: flex; 
  overflow: hidden; 
  position: relative; 
  gap: 14px;
  padding: 12px 14px 0 14px;
  z-index: 1;
}

/* 1. 左カラム：キャラクターステージ */
#character-stage {
  flex: 0 0 28%;
  max-width: 380px;
  min-width: 200px;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.interaction-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: rgba(22, 18, 36, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(157, 78, 221, 0.25);
  border-radius: 12px;
  z-index: 5;
  align-self: flex-start;
  margin-bottom: auto;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.interaction-palette button {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 10px;
  background: rgba(32, 26, 53, 0.65);
  border: 1px solid rgba(157, 78, 221, 0.3);
  color: #e5def0;
  white-space: nowrap;
}
.interaction-palette button:hover {
  background: rgba(58, 36, 92, 0.85);
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
  color: #fff;
}

.character-view-container {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  pointer-events: none;
}
#character-view {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 0 20px rgba(157, 78, 221, 0.3));
  display: none;
}

/* 2. 中央カラム：Chat Area */
#chat-container { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  height: 100%; 
  min-width: 0;
}
#message-list { 
  flex: 1; 
  overflow-y: auto; 
  padding: 8px 8px 16px 8px; 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
}

.message { 
  display: flex; 
  flex-direction: column; 
  max-width: 88%; 
  line-height: 1.65; 
  word-break: break-word; 
  font-size: 0.95rem; 
  position: relative; 
}

.message.user { align-self: flex-end; }
.message.user .bubble { 
  background-color: var(--taro-bubble); 
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff; 
  border-radius: 16px 16px 2px 16px; 
  padding: 10px 16px; 
  border: 1px solid #5a3f9c; 
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.message.model { align-self: flex-start; }
.message.model .bubble { 
  background: var(--monet-bubble-bg); 
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-main); 
  border-radius: 16px 16px 16px 2px; 
  padding: 12px 18px; 
  border: 1px solid transparent; 
  background-image: linear-gradient(rgba(22, 18, 36, 0.92), rgba(22, 18, 36, 0.92)), 
                    linear-gradient(135deg, var(--accent-purple), var(--accent-gold));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 12px rgba(157, 78, 221, 0.25); 
}

.msg-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sender-name { font-size: 0.75rem; color: var(--accent-gold); font-weight: bold; letter-spacing: 0.5px; }
.message.user .sender-name { color: var(--accent-purple); }

.msg-actions { display: flex; gap: 4px; opacity: 0.6; transition: opacity 0.2s; }
.message:hover .msg-actions { opacity: 1; }

pre { 
  background-color: #0b0814; 
  border: 1px solid var(--border-color); 
  border-radius: 6px; 
  padding: 10px; 
  overflow-x: auto; 
  margin: 8px 0; 
  font-family: monospace; 
  font-size: 0.85rem; 
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}
code { font-family: monospace; color: var(--accent-gold); }

/* Input Area */
#input-area { 
  background: var(--panel-bg); 
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color); 
  padding: 12px 16px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.quick-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; align-items: center; }
.quick-bar button { 
  padding: 5px 12px; 
  font-size: 0.78rem; 
  white-space: nowrap; 
  border-radius: 14px; 
  background: rgba(32, 26, 53, 0.7);
  border: 1px solid rgba(157, 78, 221, 0.3);
}
.quick-bar button:hover {
  box-shadow: 0 0 12px var(--accent-purple-glow);
  border-color: var(--accent-purple);
  background: rgba(45, 36, 75, 0.9);
}

.input-row { display: flex; gap: 8px; align-items: center; }
#user-input { 
  flex: 1; 
  background-color: rgba(22, 18, 36, 0.8); 
  color: var(--text-main); 
  border: 1px solid var(--border-color); 
  border-radius: 8px; 
  padding: 10px 14px; 
  font-size: 0.95rem; 
  resize: none; 
  height: 52px; 
  outline: none; 
  transition: border-color 0.2s, box-shadow 0.2s;
}
#user-input:focus { 
  border-color: var(--accent-purple); 
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

/* =========================================================================
   マルチモーダル（添付機能・複数＆非画像対応）スタイル
   ========================================================================= */

/* 添付ボタン（📎） */
#attach-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  flex-shrink: 0;
}
#attach-btn:hover {
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
  transform: translateY(-1px);
}
#attach-btn:active {
  transform: translateY(1px);
}

/* 添付中ファイルプレビュー枠（複数横並び・スクロール） */
#attachment-preview-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(32, 26, 53, 0.7);
  border: 1px dashed var(--accent-purple);
  border-radius: 8px;
  max-width: 100%;
  overflow-x: auto;
}

.preview-item-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 11, 26, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.preview-thumb-box {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 6px;
  border: 1.5px solid var(--accent-purple);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-file-icon {
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  background: rgba(32, 26, 53, 0.6);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.preview-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 130px;
}
.preview-filename {
  font-size: 0.76rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-tag {
  font-size: 0.65rem;
  color: var(--accent-gold);
}

.preview-remove-btn {
  background: rgba(230, 57, 70, 0.2);
  border: 1px solid var(--danger-color);
  color: #ff8b94;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  min-width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  font-size: 0.75rem;
}
.preview-remove-btn:hover {
  background: var(--danger-color);
  color: #fff;
}

/* チャット吹き出し内の添付要素表示 */
.message-attachments-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.message-attached-image {
  max-width: 220px;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(157, 78, 221, 0.4);
  display: block;
  background: #000;
}
.message.user .message-attached-image {
  border-color: rgba(255, 183, 3, 0.4);
}

.message-attached-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 7, 18, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.8rem;
  color: var(--text-main);
}
.message-attached-file .file-icon {
  font-size: 1.1rem;
}
.message.user .message-attached-file {
  border-color: rgba(255, 183, 3, 0.4);
  color: var(--accent-gold);
}

/* 3. 右カラム：Forge画像生成＆情景スタジオ */
#forge-panel {
  flex: 0 0 380px;
  max-width: 400px;
  min-width: 340px;
  height: 100%;
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-color);
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
  z-index: 15;
  overflow-y: auto;
  transition: flex 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              padding 0.3s ease, 
              border-width 0.3s ease, 
              opacity 0.25s ease, 
              transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 1025px) {
  #forge-panel.collapsed {
    flex: 0 0 0px !important;
    max-width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
  }
}
.forge-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}
.forge-panel-title {
  font-size: 0.88rem;
  font-weight: bold;
  color: var(--accent-gold);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.5px;
}

/* 最新画像プレビュー枠 */
.forge-preview-box {
  width: 100%;
  height: 320px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: radial-gradient(circle, rgba(22, 18, 36, 0.9) 0%, rgba(10, 7, 18, 0.98) 100%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8), 0 0 10px rgba(157, 78, 221, 0.15);
}
.forge-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  transition: opacity 0.3s ease;
}
.forge-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 16px;
}

/* ローディングスピナー */
.forge-spinner-container {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 7, 18, 0.88);
  backdrop-filter: blur(4px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 5;
}
.forge-pulse-ring {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(157, 78, 221, 0.2);
  border-top-color: var(--accent-purple);
  border-right-color: var(--accent-gold);
  animation: forgeSpin 1.1s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
  box-shadow: 0 0 16px var(--accent-purple-glow);
}
@keyframes forgeSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.forge-spinner-text {
  font-size: 0.82rem;
  color: var(--accent-gold);
  text-shadow: 0 0 8px var(--accent-gold-glow);
  font-weight: 500;
  text-align: center;
  line-height: 1.4;
}

/* クイックアクションボタン群 */
.forge-quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.forge-quick-actions button {
  padding: 6px 4px;
  font-size: 0.76rem;
  border-radius: 6px;
  white-space: nowrap;
}
.forge-quick-actions button.pinned {
  background: linear-gradient(135deg, rgba(255, 183, 3, 0.25), rgba(157, 78, 221, 0.3));
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold-glow);
}

/* 表示切替タブ */
.forge-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  gap: 4px;
}
.forge-tab-btn {
  flex: 1;
  padding: 5px 8px;
  font-size: 0.78rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
}
.forge-tab-btn.active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
  font-weight: bold;
  background: rgba(157, 78, 221, 0.12);
}

.forge-tab-pane {
  display: none;
  flex-direction: column;
  gap: 4px;
}
.forge-tab-pane.active {
  display: flex;
}
.forge-textarea {
  width: 100%;
  height: 70px;
  background: rgba(11, 8, 20, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-main);
  padding: 6px 8px;
  font-size: 0.78rem;
  resize: vertical;
  font-family: inherit;
  outline: none;
}
.forge-textarea:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 6px var(--accent-gold-glow);
}

/* 生成ボタン */
.forge-generate-btn {
  width: 100%;
  padding: 8px 12px;
  font-weight: bold;
  font-size: 0.85rem;
}

/* FIFO履歴枠 */
.forge-history-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.forge-history-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.forge-history-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  min-height: 68px;
  align-items: center;
}
.forge-thumb-card {
  flex: 0 0 60px;
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: #000;
  transition: all 0.2s ease;
}
.forge-thumb-card:hover {
  border-color: var(--accent-gold);
  transform: scale(1.05);
  box-shadow: 0 0 8px var(--accent-gold-glow);
}
.forge-thumb-card.active {
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
}
.forge-thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.forge-thumb-pin {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.65rem;
  background: rgba(10, 7, 18, 0.75);
  border-radius: 4px;
  padding: 1px 2px;
  line-height: 1;
  display: none;
}
.forge-thumb-card.is-pinned .forge-thumb-pin {
  display: block;
}

/* アラートバナー */
.forge-alert-banner {
  display: none;
  background: rgba(230, 57, 70, 0.18);
  border: 1px solid var(--danger-color);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.76rem;
  color: #ff8b94;
  line-height: 1.4;
  margin-top: 4px;
}

#forge-drawer-close-btn { display: none; }
#forge-drawer-toggle-btn { display: none; }
#forge-desktop-toggle-btn { display: inline-flex; }
@media (max-width: 1024px) {
  #forge-desktop-toggle-btn { display: none !important; }
}

/* 鑑賞モード */
body.immersive-view header,
body.immersive-view #chat-container,
body.immersive-view #forge-panel {
  opacity: 0 !important;
  pointer-events: none !important;
}
body.immersive-view #character-stage {
  flex: 1 !important;
  max-width: 100% !important;
  z-index: 100;
}
body.immersive-view .interaction-palette {
  display: none !important;
}
#view-restore-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  background: rgba(22, 18, 36, 0.9);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 10px 18px;
  border-radius: 20px;
  box-shadow: 0 0 15px var(--accent-gold-glow);
  font-weight: bold;
  cursor: pointer;
}
body.immersive-view #view-restore-btn {
  display: block;
}

/* Modals */
#settings-modal, #memory-modal { 
  display: none; 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  background: rgba(5, 3, 10, 0.8); 
  backdrop-filter: blur(6px);
  z-index: 200; 
  justify-content: center; 
  align-items: center; 
}
.modal-content { 
  background: rgba(22, 18, 36, 0.95); 
  border: 1px solid var(--border-color); 
  border-radius: 12px; 
  width: 90%; 
  max-width: 650px; 
  max-height: 85vh; 
  display: flex; 
  flex-direction: column; 
  padding: 20px; 
  gap: 14px; 
  overflow-y: auto; 
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px var(--accent-purple-glow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; color: var(--accent-gold); font-weight: bold; }
textarea.full-text { width: 100%; height: 200px; background: rgba(11, 8, 20, 0.8); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 6px; padding: 8px; font-family: monospace; font-size: 0.8rem; resize: vertical; }

/* Cursor */
.typing-cursor::after { 
  content: '▋'; 
  display: inline-block; 
  color: var(--accent-gold); 
  text-shadow: 0 0 6px var(--accent-gold-glow);
  animation: blink 0.8s infinite; 
  margin-left: 2px; 
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* =========================================================================
   レスポンシブ・1カラム最適化（スマホ・タブレット・低身長ガード）
   ========================================================================= */
@media (max-width: 768px), 
       screen and (orientation: portrait) and (max-width: 1024px), 
       (max-height: 500px) {

  main { 
    padding: 4px 6px env(safe-area-inset-bottom, 0px) 6px; 
    gap: 0;
  }

  #character-stage { 
    display: none !important; 
  }
  #mobile-bg-layer, 
  #mobile-bg-overlay { 
    opacity: 1 !important; 
  }

  #chat-container {
    width: 100%;
    flex: 1 1 100%;
    min-width: 0;
  }
  #message-list {
    padding: 8px 6px 12px 6px;
    gap: 12px;
  }
  .message {
    max-width: 94%;
  }

  #input-area {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
    gap: 6px;
  }
  
  #user-input,
  .forge-textarea,
  select,
  input[type="text"],
  input[type="password"] {
    font-size: 16px !important;
  }

  #user-input {
    height: 48px;
    padding: 10px 12px;
  }

  #attach-btn {
    min-width: 44px;
    min-height: 48px;
    height: 48px;
  }

  #send-btn {
    min-width: 58px;
    min-height: 48px;
    font-size: 0.95rem;
  }
  #forge-drawer-toggle-btn { 
    display: inline-flex !important;
    min-height: 40px;
    align-items: center;
  }
  #forge-drawer-close-btn { 
    display: inline-block !important;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.1rem;
  }
  .quick-bar button {
    min-height: 38px;
    padding: 6px 14px;
  }

  #forge-desktop-toggle-btn { 
    display: none !important; 
  }
  #forge-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 88%;
    max-width: 380px;
    height: 100vh;
    height: 100dvh;
    border-radius: 16px 0 0 16px;
    transform: translateX(105%);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.8);
    z-index: 120;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #forge-panel.drawer-open { 
    transform: translateX(0); 
  }

  #forge-drawer-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 3, 10, 0.5);
    backdrop-filter: none;
    -webkit-backdrop-filter: blur(4px);
    z-index: 110;
  }
  #forge-drawer-backdrop.active { 
    display: block; 
  }
}

/* PWA 最適化 */
@media (display-mode: standalone), (display-mode: fullscreen) {
  main {
    padding-bottom: 0 !important;
  }
  #input-area {
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important;
  }
  #user-input {
    margin-bottom: 0;
  }
}
/* =========================================================================
   Google Search Grounding スタイル
   ========================================================================= */

/* 検索トグルボタン */
#search-toggle-btn {
  transition: all 0.25s ease;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  background: rgba(32, 26, 53, 0.7);
}

#search-toggle-btn.active {
  color: #0b0911;
  background: linear-gradient(135deg, #00f5d4, #ffb703);
  border-color: #00f5d4;
  box-shadow: 0 0 12px rgba(0, 245, 212, 0.6), 0 0 4px var(--accent-gold-glow);
  font-weight: bold;
}

/* 回答内のグラウンディング（検索参照ソース）表示 */
.grounding-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed rgba(157, 78, 221, 0.3);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.grounding-title {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  color: var(--accent-gold);
  font-weight: bold;
}

.grounding-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.grounding-item a {
  color: #70d6ff;
  text-decoration: none;
  background: rgba(11, 8, 20, 0.6);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(112, 214, 255, 0.3);
  display: inline-block;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  transition: all 0.2s ease;
}

.grounding-item a:hover {
  border-color: #70d6ff;
  box-shadow: 0 0 8px rgba(112, 214, 255, 0.5);
  color: #fff;
}
/* =========================================================================
   gpt-image-2 情緒スチル お知らせカード
   ========================================================================= */
.still-notify-card {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(42, 157, 143, 0.18);
  border: 1px solid rgba(72, 202, 228, 0.45);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: #e0fbfc;
  box-shadow: 0 0 12px rgba(72, 202, 228, 0.2);
}
.still-notify-card button {
  background: linear-gradient(135deg, #2a9d8f, #48cae4);
  color: #0b0911;
  font-weight: bold;
  border: none;
  padding: 5px 12px;
  font-size: 0.76rem;
  white-space: nowrap;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.still-notify-card button:hover {
  box-shadow: 0 0 10px rgba(72, 202, 228, 0.6);
  transform: translateY(-1px);
}
/* Google Drive 連携ボタン */
#google-drive-auth-btn {
  transition: all 0.25s ease;
  border-color: rgba(157, 78, 221, 0.4);
}
#google-drive-auth-btn:hover {
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
}
#google-drive-auth-btn.authenticated {
  background: linear-gradient(135deg, #2a9d8f, #52b788);
  border-color: #52b788;
  color: #0b0911;
  font-weight: bold;
  box-shadow: 0 0 10px rgba(82, 183, 136, 0.6);
}
}