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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
    'Noto Sans JP', sans-serif;
  background: #f7f4ef;
  color: #333;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 390px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---- Screens ---- */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
}

/* ---- Header ---- */
.header {
  background: #c8702a;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
}

.logo-sub {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.02em;
}

.back-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  line-height: 1;
}

/* ---- Consult screen ---- */
.consult-main {
  flex: 1;
  padding: 20px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* サンプルカードと入力欄を隙間なく並べるラッパー */
.consult-bottom {
  display: flex;
  flex-direction: column;
}

/* 相談画面の入力エリア（固定なし・通常フロー） */
.consult-input-area {
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#consult-input {
  height: 150px;
  min-height: 100px;
  max-height: 400px;
  resize: vertical;
}

/* ---- Bubbles ---- */
.bubble {
  border-radius: 18px;
  padding: 12px 16px;
  line-height: 1.6;
  font-size: 0.92rem;
  max-width: 85%;
  word-break: break-word;
}

.ai-bubble {
  background: #fff;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

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

.welcome-bubble {
  max-width: 100%;
}

/* ---- Sample cards ---- */
.sample-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sample-card {
  background: #fff;
  border: 1.5px solid #e8dfd5;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  font-size: 0.88rem;
  color: #555;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  line-height: 1.5;
}

.sample-card:active,
.sample-card:hover {
  border-color: #c8702a;
  background: #fdf6f0;
  color: #333;
}

/* ---- Input area（回答画面の下部固定入力欄） ---- */
.input-area {
  flex-shrink: 0;      /* flex 親から圧縮されないよう固定 */
  background: #f7f4ef;
  padding: 12px 16px 20px;
  border-top: 1px solid #e4ddd5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

textarea {
  width: 100%;
  border: 1.5px solid #ddd4c8;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  background: #fff;
  color: #333;
  line-height: 1.6;
  transition: border-color 0.18s;
  box-sizing: border-box;
}

textarea:focus {
  outline: none;
  border-color: #c8702a;
}

textarea::placeholder {
  color: #bbb;
}

.submit-btn {
  align-self: flex-end;
  background: #c8702a;
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 10px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, opacity 0.18s;
}

.submit-btn:hover {
  background: #b0601e;
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---- Answer screen ---- */

/* 画面全体を 100dvh に固定して内部だけスクロールさせる */
#screen-answer {
  height: 100dvh;
  overflow: hidden;
}

.answer-main {
  flex: 1;
  min-height: 0;       /* flex 子要素がコンテンツ高さ以下に縮めるよう必須 */
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- AI bubble markdown styles ---- */
.ai-bubble ol,
.ai-bubble ul {
  margin: 4px 0;
  padding-left: 20px;
}

.ai-bubble li {
  margin: 2px 0;
  line-height: 1.6;
}

/* ---- Loading dots ---- */
.loading {
  display: flex;
  gap: 6px;
  align-self: flex-start;
  padding: 14px 18px;
  background: #fff;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.loading.hidden {
  display: none;
}

.dot {
  width: 8px;
  height: 8px;
  background: #c8702a;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-6px); opacity: 1; }
}
