:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #6ea8fe;
  --accent-strong: #4c8dfd;
  --notice-bg: #1a2230;
  --warn-bg: #2a2210;
  --warn-text: #f2c94c;
  --chip-bg: #202634;
  --bubble-user: #262b36;
  --max-width: 760px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ==== ヘッダー（常に画面上部に固定） ==== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 残りの質問回数：ピル型で目立たせる */
.remaining {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}

.remaining.remaining-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}

/* ==== 全体レイアウト ==== */
.app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: calc(var(--header-h, 48px) + 16px) 16px 140px;
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

/* ==== 初回画面（ChatGPT風の中央寄せ） ==== */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding-top: 8vh;
}

.welcome-title {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

/* ==== 利用条件への同意カード ==== */
.consent-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* フォームの最後（送信ボタンの直前）に置く同意欄 */
.consent-in-form {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.12));
}

.question-count-note {
  font-size: 0.78rem;
  color: var(--muted);
}

.consent-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.consent-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.consent-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--muted);
  cursor: pointer;
}

.consent-checkbox {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--accent-strong);
  cursor: pointer;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}

.intake-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

select, textarea, input:not([type="checkbox"]) {
  font-size: 16px; /* iOSでの自動ズームを防ぐ */
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
}

.required-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.badge-required {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: #0b1220;
  background: var(--accent-strong);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 4px;
  vertical-align: middle;
}

.field-error {
  font-size: 0.78rem;
  color: #ff8a8a;
  font-weight: 600;
}

select.field-invalid, textarea.field-invalid {
  border-color: #ff8a8a;
}

.consent-gate-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* 黒背景でも選択肢が読める配色にする */
select {
  color-scheme: dark;
  background-color: var(--surface-2);
  color: var(--text);
}

select option {
  background-color: #1e222b;
  color: #e8eaed;
}

textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.6;
}

.question-field {
  gap: 6px;
}

.question-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-examples-label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.question-example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.question-example-chip {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
}

.question-example-chip:hover {
  background: var(--chip-bg);
}

.char-count {
  align-self: flex-end;
  font-size: 0.78rem;
  color: var(--muted);
}

button[type="submit"], .send-button {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent-strong);
  color: #0b1220;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

button[type="submit"]:disabled, .send-button:disabled {
  background: #3a3f4b;
  color: var(--muted);
  cursor: not-allowed;
}

/* ==== 会話表示 ==== */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 0 24px;
}

.message {
  display: flex;
  gap: 10px;
  font-size: 0.95rem;
  line-height: 1.75;
}

.message-user {
  justify-content: flex-end;
}

.message-user .bubble {
  background: var(--bubble-user);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  max-width: 80%;
  white-space: pre-wrap;
}

.message-model {
  justify-content: flex-start;
  align-items: flex-start;
}

.message-model .avatar {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.message-model .content {
  max-width: 88%;
  white-space: pre-wrap;
}

.message-model .answer-text {
  color: var(--text);
}

.message-model .answer-text a {
  color: var(--accent);
  word-break: break-all;
  overflow-wrap: anywhere;
}

.message-model .answer-text strong {
  font-weight: 700;
  color: var(--text);
}

/* 「回答を考え中…」の点アニメーション */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: thinking-bounce 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* 出典チップ */
.sources {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-chip {
  display: inline-block;
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
}

/* 免責文（小さく・薄い色） */
.answer-disclaimer {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.6;
}

/* 👍👎 */
.feedback {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}

.feedback button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feedback button:hover {
  background: var(--surface-2);
}

.feedback-done {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ==== 上限バナー（帯。左ボーダーは使わない） ==== */
.limit-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--composer-h, 120px);
  z-index: 9;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 16px;
  text-align: center;
}

/* ==== 入力欄（画面下に固定） ==== */
.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: rgba(15, 17, 21, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}

.composer-form {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 8px 8px 16px;
}

.composer-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 0;
  resize: none;
  max-height: 120px;
  font-size: 16px;
  line-height: 1.5;
}

.composer-form textarea:focus {
  outline: none;
}

.composer-send {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent-strong);
  color: #0b1220;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.composer-send:disabled {
  background: #3a3f4b;
  color: var(--muted);
  cursor: not-allowed;
}

.composer-footer {
  max-width: var(--max-width);
  margin: 4px auto 0;
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
  padding-right: 8px;
}

/* hidden属性をdisplay指定より優先する（送信後にフォームが残る不具合の修正） */
[hidden]{display:none !important}

/* 同意欄はチェックボックスと文を横並びにする（汎用の label 指定より優先） */
label.consent-item{flex-direction:row;align-items:flex-start}

/* 同意：5項目は読むだけの箇条書き、チェックは1つ */
.consent-points{margin:0 0 10px;padding-left:1.2em;display:flex;flex-direction:column;gap:6px;font-size:0.85rem;line-height:1.6;color:var(--muted)}
.consent-terms-link{font-size:0.82rem;color:var(--muted);margin:0 0 12px}
.consent-terms-link a{color:var(--accent-strong)}
label.consent-single{background:var(--surface-2);border-radius:10px;padding:12px;color:var(--text,#e8eaed);font-weight:700}
/* 必須バッジはラベルの文字の横に小さく付ける */
.label-row{display:flex;align-items:center;gap:6px}
.label-row .badge-required{margin-left:0}

/* フォームの枠からはみ出さないようにする（長い学校名のプルダウンが列を押し広げていた） */
.form-grid{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
@media (max-width:560px){.form-grid{grid-template-columns:minmax(0,1fr)}}
.form-grid > label{min-width:0}
.form-grid select{width:100%;max-width:100%;min-width:0;text-overflow:ellipsis}
