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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: #f0f4f8;
}

#app {
  width: 100%;
  height: 100%; /* JS で visualViewport.height に上書きされる */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: #1a56db;
  color: #fff;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0));
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  flex-shrink: 0;
}
header .material-symbols-outlined { font-size: 1.8rem; }
header h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: .03em; }
header p { font-size: .72rem; opacity: .82; margin-top: 1px; }

.material-symbols-outlined { user-select: none; }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 520px);
}
.bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.bot  { align-self: flex-start; align-items: flex-start; }

.label {
  font-size: .68rem;
  color: #6b7280;
  margin-bottom: 3px;
  padding: 0 4px;
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .93rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  text-align: left;
}
.bubble-wrap.user .bubble {
  background: #1a56db;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-wrap.bot .bubble {
  background: #fff;
  color: #1f2937;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}

.spinner-wrap { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.spinner {
  width: 20px; height: 20px;
  border: 3px solid #d1d5db;
  border-top-color: #1a56db;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-wrap span { font-size: .83rem; color: #6b7280; }

#input-area {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
  background: #fff;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}
#question {
  flex: 1;
  resize: none;
  border: 1.5px solid #d1d5db;
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 16px; /* 16px未満だとiOSがタップ時に自動ズームするため */
  font-family: inherit;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color .2s;
}
#question:focus { border-color: #1a56db; }
#question::placeholder { color: #9ca3af; }

#send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: #1a56db;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .1s;
  align-self: flex-end;
}
#send-btn:hover { background: #1648c0; }
#send-btn:active { transform: scale(.93); }
#send-btn:disabled { background: #9ca3af; cursor: not-allowed; }
#send-btn .material-symbols-outlined { font-size: 1.2rem; }

.welcome {
  align-self: center;
  text-align: center;
  color: #6b7280;
  font-size: .88rem;
  margin-top: 24px;
  line-height: 1.7;
  background: #fff;
  border-radius: 14px;
  padding: 18px 22px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  max-width: 340px;
}
.welcome .material-symbols-outlined { font-size: 2.4rem; display: block; margin-bottom: 6px; color: #1a56db; }

@media (max-width: 480px) {
  header h1 { font-size: .97rem; }
  .bubble { font-size: .88rem; }
}
