* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0a0a1a;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 10px 20px;
  background: #12101f;
  border-bottom: 1px solid #2a1a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header h1 {
  font-size: 1.1rem;
  background: linear-gradient(135deg, #b366ff, #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.hamburger-btn {
  background: none;
  border: none;
  color: #888;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s;
}
.hamburger-btn:hover { color: #ccc; }

/* 設定モーダル */
.settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: flex-start;
  justify-content: flex-end;
}
.settings-overlay.open { display: flex; }

.settings-modal {
  background: #1a1a2a;
  border-left: 1px solid #2a1a3a;
  width: min(360px, 90vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  animation: slide-in 0.2s ease;
}
@keyframes slide-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.settings-header {
  padding: 14px 20px;
  border-bottom: 1px solid #2a1a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  color: #aaa;
}
.settings-header button {
  background: none;
  border: none;
  color: #666;
  font-size: 1rem;
  cursor: pointer;
}
.settings-header button:hover { color: #ccc; }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 0.75rem;
  color: #6a5a8a;
  margin-top: 8px;
}

.api-key-row {
  display: flex;
  gap: 6px;
}
.api-key-row input { flex: 1; }

.settings-body input[type="password"],
.settings-body input[type="text"],
.settings-body input[type="url"],
.settings-body select,
.settings-body textarea {
  width: 100%;
  padding: 8px 10px;
  background: #12101f;
  border: 1px solid #3a2a5a;
  border-radius: 8px;
  color: #e0d0f0;
  font-size: 0.85rem;
  font-family: inherit;
}
.settings-body textarea { min-height: 120px; resize: vertical; }
.settings-body input:focus,
.settings-body select:focus,
.settings-body textarea:focus { outline: none; border-color: #b366ff; }

.api-key-row button {
  padding: 6px 10px;
  background: none;
  border: 1px solid #3a2a5a;
  border-radius: 8px;
  color: #888;
  cursor: pointer;
  font-size: 0.85rem;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 80px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: #4f46e5;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  align-self: flex-start;
}
.msg-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  object-fit: cover;
}
.msg.bot {
  align-self: flex-start;
  background: #1e1e3a;
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}

/* Mascot bust-up */
.mascot-bustup {
  position: fixed;
  bottom: calc(var(--input-area-h, 65px) + 8px);
  right: -60px;
  pointer-events: none;
  opacity: 0.6;
  z-index: 0;
  transition: opacity 0.3s;
}
.mascot-bustup:hover { opacity: 1; }
.mascot-bustup.hidden { display: none; }
@media (max-width: 600px) {
  .mascot-bustup {
    right: 0;
    bottom: calc(var(--input-area-h, 65px));
    opacity: 0.85;
    width: 30%;
  }
}

.msg.bot strong { color: #b366ff; }
.msg.bot a { color: #b366ff; }
.msg.bot code { background: #2a2a4a; padding: 2px 5px; border-radius: 3px; font-size: 0.85em; }
.msg.bot pre { background: #2a2a4a; padding: 8px 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; font-size: 0.8rem; }
.msg.bot ul, .msg.bot ol { padding-left: 1.2em; margin: 4px 0; }
.msg.bot blockquote { border-left: 3px solid #b366ff; padding-left: 10px; margin: 4px 0; opacity: 0.85; }
.msg.bot p { margin: 4px 0; }
.msg.bot p:first-child { margin-top: 0; }
.msg.bot p:last-child { margin-bottom: 0; }

.msg.system {
  align-self: center;
  background: none;
  color: #6a5a8a;
  font-size: 0.8rem;
  text-align: center;
}

.typing {
  align-self: flex-start;
  color: #6a5a8a;
  font-size: 0.85rem;
  padding: 8px 14px;
}

.typing::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* 音声テキストオーバーレイ */
.input-preview-overlay {
  position: fixed;
  bottom: 70px;
  left: 20px;
  right: 20px;
  z-index: 9;
  background: rgba(10, 10, 26, 0.5);
  border-radius: 12px;
  padding: 10px 40px 10px 14px;
  display: none;
}
.input-preview-overlay.visible { display: block; }

.input-preview {
  font-size: 0.95rem;
  color: #ddd;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.input-preview.interim { color: #888; font-style: italic; }

/* クリアボタン（右上赤丸） */
.clear-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50% !important;
  background: #952826 !important;
  border: none !important;
  color: #fff !important;
  font-size: 0.6rem !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
}

.input-area {
  background: #12101f;
  border-top: 1px solid #2a1a3a;
  display: flex;
  flex-direction: column;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ナビバー */
.input-bar {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

/* 送信ボタンをセンター */
.send-btn {
  position: absolute !important;
  left: 50%;
  transform: translateX(-50%);
}

/* マイクボタン */
.mic-btn {
  width: 48px;
  height: 48px;
  border-radius: 50% !important;
  padding: 0 !important;
  font-size: 1.2rem !important;
  flex-shrink: 0;
  background: #1a1a2a !important;
  border: 1px solid #3a2a5a !important;
  color: #aaa !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.mic-btn:hover { border-color: #b366ff !important; color: #b366ff !important; }
.mic-btn.listening {
  background: #3a0d0d !important;
  border-color: #e53935 !important;
  color: #e53935 !important;
  animation: mic-pulse 1s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,57,53,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(229,57,53,0); }
}

/* 送信ボタン */
.send-btn {
  width: 56px !important;
  height: 56px !important;
  border-radius: 50% !important;
  padding: 0 !important;
  font-size: 1.3rem !important;
  background: linear-gradient(135deg, #b366ff, #7c3aed) !important;
  border: none !important;
  color: #fff !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
}
.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn.is-loading { opacity: 0.7; cursor: pointer; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.7; } 50% { opacity: 1; } }

.input-area textarea,
.hidden { display: none !important; }

.input-area button {
  padding: 10px 20px;
  background: linear-gradient(135deg, #b366ff, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.input-area button:hover { opacity: 0.85; }
.input-area button:disabled { opacity: 0.4; cursor: not-allowed; }



/* マイクボタン */
.mic-btn {
  display: flex; /* PC でも表示 */
  width: 44px;
  height: 44px;
  border-radius: 50% !important;
  padding: 0 !important;
  font-size: 1.2rem !important;
  flex-shrink: 0;
  background: #1a1a2a !important;
  border: 1px solid #3a2a5a !important;
}
.mic-btn.listening {
  background: #3a0d0d !important;
  border-color: #e53935 !important;
  animation: mic-pulse 1s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,57,53,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(229,57,53,0); }
}

@media (max-width: 600px) {
  .mic-btn { align-items: center; justify-content: center; }
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #6a5a8a;
  text-align: center;
  padding: 40px;
}

.welcome h2 {
  font-size: 1.5rem;
  background: linear-gradient(135deg, #b366ff, #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome p { font-size: 0.9rem; max-width: 400px; line-height: 1.6; }

/* Config panel */
.config-toggle {
  background: none;
  border: none;
  padding: 0;
  color: #6a5a8a;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
  font-family: inherit;
}

.config-panel {
  display: none;
  width: 100%;
  padding: 10px 20px;
  background: #0f0f1f;
  border-bottom: 1px solid #2a1a3a;
}

.config-panel.active { display: block; }

.config-panel textarea {
  width: 100%;
  height: 120px;
  padding: 10px;
  background: #1a1a2a;
  border: 1px solid #3a2a5a;
  border-radius: 8px;
  color: #e0d0f0;
  font-size: 0.8rem;
  font-family: monospace;
  resize: vertical;
  line-height: 1.5;
}

.config-panel textarea:focus { outline: none; border-color: #b366ff; }

.config-panel label {
  display: block;
  font-size: 0.75rem;
  color: #8a7aaa;
  margin-bottom: 4px;
}

.config-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.config-row select, .config-row input {
  padding: 4px 8px;
  background: #1a1a2a;
  border: 1px solid #3a2a5a;
  border-radius: 6px;
  color: #e0d0f0;
  font-size: 0.8rem;
}

.config-row label {
  display: inline;
  font-size: 0.75rem;
  color: #8a7aaa;
  margin-bottom: 0;
}

.btn-danger, .btn-secondary {
  padding: 4px 10px;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
}
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }

/* Security modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: #1a1a2e;
  border: 1px solid #3a2a5a;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-box h3 {
  color: #ffd700;
  font-size: 1rem;
  margin-bottom: 12px;
}
.modal-box ul {
  list-style: none;
  padding: 0;
  margin: 0 0 16px 0;
}
.modal-box li {
  color: #ccc;
  font-size: 0.85rem;
  padding: 6px 0;
  border-bottom: 1px solid #2a1a3a;
}
.modal-box li::before {
  content: '⚠️ ';
}
.modal-box li:last-child { border-bottom: none; }
.modal-box li:last-child::before { content: '💡 '; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-actions button {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.modal-cancel {
  background: #333;
  color: #aaa;
}
.modal-cancel:hover { background: #444; }
.modal-confirm {
  background: linear-gradient(135deg, #b366ff, #8a2be2);
  color: #fff;
}
.modal-confirm:hover { opacity: 0.9; }

/* Utility classes for elements that had inline styles */
#botTitle { width: 150px; }
#memoryPreview { margin-top: 8px; font-size: 0.7rem; color: #6a5a8a; max-height: 60px; overflow-y: auto; }
#welcomeImg { width: 100%; max-width: 400px; border-radius: 12px; margin-bottom: 8px; opacity: 0.9; }
.welcome .hint { font-size: 0.75rem; }
.modal-box a { color: #b366ff; }

@media (max-width: 600px) {
  .header { gap: 8px; }
  .header .api-group { width: 100%; margin-left: 0; }
  .header input[type="password"], .header input[type="text"] { flex: 1; width: auto; }
  .msg { max-width: 90%; }
}

/* TTS Button */
.tts-btn {
  display: inline-block;
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 8px;
  margin-top: 6px;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s;
}
.tts-btn:hover { opacity: 1; background: rgba(255,255,255,0.08); }
.tts-btn.loading { opacity: 0.3; cursor: wait; }
.tts-btn.playing { opacity: 1; background: rgba(139,92,246,0.3); border-color: rgba(139,92,246,0.5); }
