:root {
  --bg: #f5f0e8;
  --surface: #ffffff;
  --text: #362f28;
  --text-soft: #8a8175;
  --border: #e6ddcf;
  --accent: #7f9573;
  --accent-text: #ffffff;
  --danger: #c65f4a;

  /* 猫の色。明るい体の色なので、ダークモードでもそのまま使える */
  --cat-body: #f2d7b0;
  --cat-line: #4b3f34;
  --cat-ear: #eda9a2;
  --cat-blush: #f3aa9f;
  --cat-accent: #e2857c;
  --cat-mug: #8fae82;
  --cat-anger: #d9534f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201d19;
    --surface: #2a2521;
    --text: #ece6db;
    --text-soft: #a89f90;
    --border: #3d372f;
    --accent: #8fae82;
    --accent-text: #17231a;
    --danger: #e08267;
  }
}

* { box-sizing: border-box; }

/* display:flex を指定した要素でも hidden 属性が確実に効くようにする */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  font-size: 15.5px;
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

textarea {
  font-family: inherit;
}

/* ---------- ヘッダー ---------- */
.app-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex: none;
}

.app-header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:hover {
  background: var(--surface);
}

.menu {
  position: absolute;
  top: 56px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 180px;
  z-index: 20;
}

.menu button {
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 12px 16px;
  font-size: 14.5px;
}

.menu button:hover {
  background: var(--bg);
}

.menu button.danger {
  color: var(--danger);
}

/* ---------- チャット本体 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.row {
  display: flex;
  max-width: 100%;
}

.row.ai { justify-content: flex-start; align-items: flex-end; gap: 8px; }
.row.me { justify-content: flex-end; }

/* 同じ返答の中の2個目以降の短い発言。詰めて表示して、一続きの発言に見せる。 */
.row.ai.grouped { margin-top: -4px; }

/* ---------- 猫のアイコン ---------- */
/* 2個目以降の発言では場所だけ空けて絵は出さない（一続きの発言に見せるため） */
.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  align-self: flex-end;
}

.avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- スタンプ ---------- */
/* 吹き出しに入れず、絵だけを置く（LINEのスタンプのような見せ方） */
.stamp {
  width: 118px;
  height: 118px;
  flex: none;
}

.stamp svg {
  width: 100%;
  height: 100%;
  display: block;
}

.row.stamp-row { margin-top: 0; }

@media (prefers-reduced-motion: no-preference) {
  .stamp { animation: stamp-pop 0.28s ease-out; }
}

@keyframes stamp-pop {
  from { transform: scale(0.72); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

.row.ai .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  color: var(--text);
}

.row.me .bubble {
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 6px;
}

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-soft);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .typing .dot { animation: none; opacity: 0.8; }
}

/* ---------- 話し方チップ ---------- */
.mood-bar {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  flex: none;
}

.mood-label {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-soft);
}

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

.mood-chips button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13.5px;
}

.mood-chips button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* ---------- 入力欄 ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#input {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 11px 16px;
  font-size: 15.5px;
  line-height: 1.5;
  background: var(--surface);
  color: var(--text);
}

#input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.privacy-note {
  flex: none;
  margin: 0;
  padding: 0 14px 8px;
  font-size: 11.5px;
  color: var(--text-soft);
  text-align: center;
  background: var(--bg);
}

/* ---------- シート（モーダル） ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sheet-panel {
  position: relative;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 18px; max-height: 70vh; }
}

.sheet-panel h2 {
  margin: 0 0 12px;
  font-size: 16.5px;
}

.sheet-panel p {
  line-height: 1.8;
  font-size: 14.5px;
}

.sheet-panel a {
  color: var(--accent);
}

.sheet-close {
  margin-top: 14px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 11px;
  font-size: 14.5px;
}

.sheet-close.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

/* ---------- デスクトップ幅で読みやすく中央寄せ ---------- */
@media (min-width: 640px) {
  body {
    max-width: 560px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
