/* ===== リセット・ベース ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  /* dynamic viewport height: アドレスバーを除いた高さ */
  background-color: #f0fff0;
  color: #000000;
  font-family: "MS PGothic", Osaka, sans-serif;
  font-size: 16px;
  /* スマホで自動ズームを防ぐため 16px 以上に */
}

/* ===== リンク ===== */
a {
  color: #0000ee;
}

a:visited {
  color: #551a8b;
}

a:active {
  color: #ff0000;
}

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  flex-shrink: 0;
}

h1 {
  font-size: 1.4em;
  color: brown;
  font-weight: bold;
  margin: 0;
}

/* ===== インストールボタン ===== */
.install-btn {
  height: 36px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: bold;
  color: #000000;
  background-color: #ffe36e;
  border: 2px solid #000000;
  box-shadow: 2px 2px 0px #b88246;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.install-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px #b88246;
}

/* ===== 区切り線 ===== */
hr {
  margin: 0;
  border: none;
  border-top: 1px solid #ccc;
  flex-shrink: 0;
}

/* ===== メッセージエリア（スクロール可能） ===== */
#messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  /* iOS Safari のオーバースクロール慣性スクロール */
  -webkit-overflow-scrolling: touch;
}

/* メッセージ行 */
[data-message-row] {
  padding: 4px 0;
  line-height: 1.6;
  word-break: break-word;
}

/* 思考中トーン */
[data-message-tone="thinking"] {
  color: #888;
  font-style: italic;
}

/* エラートーン */
[data-message-tone="error"] {
  color: #c0392b;
}

/* ===== Markdownコンテンツ ===== */
#messages [data-message-body] table {
  border-collapse: collapse;
  margin: 0.5em 0;
  width: 100%;
  font-size: 0.9em;
}

#messages [data-message-body] th,
#messages [data-message-body] td {
  border: 1px solid currentColor;
  padding: 4px 8px;
}

#messages [data-message-body]>p:first-child {
  display: inline;
  margin: 0;
}

#messages [data-message-body]>p {
  margin: 0.5em 0 0 0;
}

/* ===== 入力フォーム（画面下部固定） ===== */
#chat-form-wrapper {
  flex-shrink: 0;
  border-top: 1px solid #ccc;
  background: #f0fff0;
  /* iOS でキーボードが出たとき一緒に上がるように */
  padding: env(safe-area-inset-bottom, 0) 0 0 0;
}

#chat-form {
  display: flex;
  gap: 6px;
  align-items: stretch;
  padding: 8px 10px;
}

#prompt {
  flex: 1 1 auto;
  min-width: 0;
  /* flexbox内で縮めるため */
  padding: 10px 12px;
  font-size: 16px;
  /* 16px 未満だとiOSで自動ズームが発生する */
  border: 1px solid #aaa;
  border-radius: 4px;
  background: #fff;
}

#prompt:disabled {
  background: #e8e8e8;
}

#send {
  flex-shrink: 0;
  padding: 0 18px;
  font-size: 16px;
  font-weight: bold;
  color: #000;
  border: 2px solid #000;
  cursor: pointer;
  border-radius: 4px;
  touch-action: manipulation;
}

#send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

#send:not(:disabled):active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px #b88246;
}

/* ===== デスクトップ向け補正 ===== */
@media (min-width: 600px) {
  h1 {
    font-size: 2em;
  }

  .app-header {
    padding: 0 16px;
    margin-top: 1rem;
  }

  #messages {
    padding: 16px;
  }

  #chat-form {
    padding: 10px 12px;
  }
}