:root {
  --bg: #fff6ec;
  --bg-2: #ffeedd;
  --card: #ffffff;
  --text: #4a3a33;
  --muted: #9a857a;
  --red: #e5574f;
  --red-dark: #cf453e;
  --green: #3f8a63;
  --gold: #f2b93b;
  --bubble-bot: #ffffff;
  --bubble-me: #e5574f;
  --line: #f1dfd0;
  --shadow: 0 6px 24px rgba(166, 104, 72, 0.12);
  --radius: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ── 雪 ── */
.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.snow i {
  position: absolute; top: -12px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 4px rgba(229, 87, 79, 0.15);
  animation: fall linear infinite;
  opacity: 0.9;
}
@keyframes fall {
  to { transform: translate3d(var(--drift, 20px), 105vh, 0); }
}
@media (prefers-reduced-motion: reduce) { .snow { display: none; } }

/* ── ようこそ ── */
.welcome {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.welcome-card {
  width: 100%; max-width: 400px;
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 32px 24px 28px;
  text-align: center;
}
.welcome-art svg { display: block; margin: 0 auto 8px; }
.welcome h1 { font-size: 22px; margin: 8px 0 12px; }
.welcome p { line-height: 1.8; margin: 0 0 16px; font-size: 15px; }
.welcome-notes {
  list-style: none; padding: 12px 16px; margin: 0 0 24px;
  background: var(--bg); border-radius: 14px; font-size: 13px; color: var(--muted); text-align: left;
}
.welcome-notes li { padding: 2px 0 2px 20px; position: relative; }
.welcome-notes li::before { content: '❄'; position: absolute; left: 0; color: #9cc6d8; }

.primary-btn {
  width: 100%;
  font: inherit; font-weight: 700; font-size: 17px;
  color: #fff; background: var(--red);
  border: 0; border-radius: 999px; padding: 15px 20px;
  box-shadow: 0 6px 0 var(--red-dark);
  cursor: pointer; transition: transform 0.1s, box-shadow 0.1s;
}
.primary-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--red-dark); }
.primary-btn:disabled { opacity: 0.6; }

/* ── チャット ── */
.chat {
  position: relative; z-index: 1;
  height: 100dvh;
  max-width: 640px; margin: 0 auto;
  display: flex; flex-direction: column;
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(255, 246, 236, 0.88);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.avatar {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  font-size: 22px; border-radius: 50%;
  background: #ffe3d3;
}
.header-text { flex: 1; min-width: 0; }
.bot-name { font-weight: 700; font-size: 16px; }
.bot-status { font-size: 12px; color: var(--green); }
.bot-status::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; }
.progress { width: 72px; flex: none; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--green), var(--gold));
  border-radius: inherit; transition: width 0.6s ease;
}

.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
.row { display: flex; align-items: flex-end; gap: 8px; animation: pop 0.25s ease-out; }
.row.me { justify-content: flex-end; }
.row .mini-avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: #ffe3d3; display: grid; place-items: center; font-size: 16px;
}
.row.cont .mini-avatar { visibility: hidden; }
.bubble {
  max-width: min(78%, 460px);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word;
}
.row.bot .bubble { background: var(--bubble-bot); border-bottom-left-radius: 6px; box-shadow: 0 2px 8px rgba(166, 104, 72, 0.08); }
.row.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 6px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.typing .bubble { display: flex; gap: 5px; padding: 14px 16px; }
.typing .bubble span {
  width: 7px; height: 7px; border-radius: 50%; background: #d8c2b4;
  animation: blink 1.2s infinite ease-in-out;
}
.typing .bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing .bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.done-card {
  margin: 4px 16px 12px; padding: 20px; text-align: center;
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  line-height: 1.8; font-size: 14.5px;
}
.done-card p { margin: 0; }
.done-emoji { font-size: 36px; }
.done-title { font-weight: 700; font-size: 18px; color: var(--red); }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 246, 236, 0.92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none;
  font: inherit; font-size: 16px; /* iOSのズーム防止のため16px以上 */
  line-height: 1.5; color: var(--text);
  max-height: 132px; padding: 10px 16px;
  border: 1.5px solid var(--line); border-radius: 22px; background: #fff;
  outline: none; transition: border-color 0.15s;
}
.composer textarea:focus { border-color: #f0a99f; }
.composer textarea::placeholder { color: #c4b0a4; }
.send-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--red); color: #fff; cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.35; cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 10; max-width: calc(100% - 32px);
  background: rgba(74, 58, 51, 0.92); color: #fff;
  padding: 10px 16px; border-radius: 14px; font-size: 14px; text-align: center;
}
