body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f7f6;
  color: #333;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background-color: #4caf50;
  color: white;
  padding: 15px 20px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
  margin: 0;
  font-size: 1.8em;
}

header p {
  margin: 5px 0 0;
  font-size: 0.9em;
}

header a {
  color: white;
  text-decoration: underline;
  font-size: 0.8em;
}

main {
  flex-grow: 1;
  padding: 20px;
  /* PCなど広い画面での最大幅を固定し、中央寄せにする */
  max-width: 600px; /* ここで最大横幅を設定 */
  margin: 20px auto;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

/* Chat Page Specific Styles */
#chat-box {
  border: 1px solid #ddd;
  border-radius: 5px;
  height: 400px; /* 固定の高さ */
  overflow-y: auto;
  padding: 15px;
  margin-bottom: 15px;
  background-color: #e9ecef;
  display: flex;
  flex-direction: column;
}

.message-row {
  display: flex;
  margin-bottom: 10px;
  align-items: flex-start; /* メッセージが複数行になっても上揃え */
}

.message-row .speaker {
  font-weight: bold;
  margin-right: 5px;
  min-width: 40px; /* スピーカー名の幅をある程度固定 */
}

.user-message {
  justify-content: flex-end; /* ユーザーメッセージを右寄せ */
  text-align: right;
}

.user-message .speaker {
  color: #007bff; /* 青色 */
}

.ai-message {
  justify-content: flex-start; /* AIメッセージを左寄せ */
  text-align: left;
}

.ai-message .speaker {
  color: #4caf50; /* 緑色 */
}

/* Loading message specific style */
.ai-message.loading {
  color: #6c757d; /* グレー */
  font-style: italic;
}

#message-form {
  display: flex;
  padding: 10px 20px;
  background-color: #f8f9fa;
  border-top: 1px solid #e2e6ea;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}

#message-input {
  flex-grow: 1;
  padding: 10px 15px;
  border: 1px solid #ccc;
  border-radius: 20px;
  font-size: 1em;
  margin-right: 10px;
  outline: none;
}

#message-form button {
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 1em;
  transition: background-color 0.3s ease;
}

#message-form button:hover {
  background-color: #0056b3;
}

/* Settings Page Specific Styles */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #555;
}

.form-group select,
.form-group input[type="text"] {
  width: calc(100% - 20px); /* Padding adjustment */
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 1em;
  box-sizing: border-box; /* Include padding in width */
}

.explanation-text {
  font-size: 0.9em;
  color: #666;
  margin-top: 5px;
  padding-left: 5px;
  border-left: 3px solid #eee;
}

#persona-form button[type="submit"] {
  display: block;
  width: 100%;
  padding: 12px;
  background-color: #28a745;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1.1em;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

#persona-form button[type="submit"]:hover {
  background-color: #218838;
}

/* Footer (optional, but good for structure) */
footer {
  text-align: center;
  padding: 15px;
  background-color: #333;
  color: white;
  font-size: 0.8em;
  margin-top: auto; /* Push footer to bottom */
}

/* ==================================================================== */
/* レスポンシブデザインのためのメディアクエリ */
/* 小さな画面（スマートフォン向け） */
@media (max-width: 768px) {
  header {
    padding: 10px 15px; /* 上下のパディングを少し減らす */
  }

  header h1 {
    font-size: 1.5em; /* フォントサイズを少し小さく */
  }

  header p {
    font-size: 0.8em;
  }

  main {
    margin: 10px; /* 左右の余白を減らす */
    padding: 15px; /* 内部パディングを減らす */
    width: auto; /* 最大幅を解除して画面幅いっぱいにする */
    max-width: 100%; /* スマートフォンでは親要素の100%を使用 */
    border-radius: 0; /* 角丸をなくして全幅表示に合わせる */
    box-shadow: none; /* ボックスシャドウをなくす */
  }

  #chat-box {
    height: calc(
      100vh - 200px
    ); /* 画面の高さいっぱいまで使うように調整 (ヘッダーとフォーム分を引く) */
    padding: 10px;
    border-radius: 0; /* 角丸をなくす */
    margin-bottom: 10px;
  }

  .message-row {
    margin-bottom: 8px; /* メッセージ間の余白を減らす */
    font-size: 0.95em; /* メッセージのフォントサイズを微調整 */
  }

  #message-form {
    padding: 8px 10px; /* パディングを減らす */
    position: sticky; /* スクロールしても追従 */
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #f8f9fa; /* 背景色 */
    border-top: 1px solid #e2e6ea; /* 上部に境界線 */
    z-index: 10; /* 他の要素より手前に表示 */
  }

  #message-input {
    padding: 8px 12px; /* 入力フィールドのパディングを減らす */
    font-size: 0.95em;
    margin-right: 8px;
  }

  #message-form button {
    padding: 8px 15px; /* ボタンのパディングを減らす */
    font-size: 0.95em;
  }

  /* 設定画面のフォームグループ */
  .form-group select,
  .form-group input[type="text"] {
    width: 100%; /* 全幅に広げる */
    padding: 8px;
    font-size: 0.95em;
  }

  .form-group label {
    font-size: 0.9em;
    margin-bottom: 5px;
  }

  #persona-form button[type="submit"] {
    padding: 10px;
    font-size: 1em;
  }
}

/* さらに小さな画面（特にiPhone SEなどの縦長デバイス向け） */
@media (max-width: 480px) {
  header h1 {
    font-size: 1.3em;
  }

  header p {
    font-size: 0.75em;
  }

  #chat-box {
    height: calc(100vh - 180px); /* さらに高さを調整 */
  }

  #message-input {
    font-size: 0.9em;
  }

  #message-form button {
    font-size: 0.9em;
    padding: 8px 12px;
  }

  .form-group select,
  .form-group input[type="text"] {
    font-size: 0.9em;
  }
}
