/* ムーン｜mooncore 水彩トーン
   キャラ憲法 §4 ビジュアル憲法：深い紺ブルー基調 ＋ パステルピンク/ブルーのグラデーション雲
   ランタンの暖かい光を差し色に。 */

:root {
  --navy-0: #0a1028;
  --navy-1: #111a35;
  --navy-2: #1b2750;
  --ink: #eef1fb;
  --ink-dim: #a6b0d4;
  --lantern: #ffca7a;
  --lantern-soft: rgba(255, 202, 122, 0.16);
  --pink: #f3b8d0;
  --blue: #9fd0f0;
  --bubble-moon: rgba(255, 255, 255, 0.09);
  --bubble-user: rgba(159, 208, 240, 0.16);
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy-0);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.85;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 空（背景） ───────────────────────────── */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(120% 80% at 50% 105%, rgba(243, 184, 208, 0.30) 0%, rgba(159, 208, 240, 0.16) 38%, transparent 70%),
    linear-gradient(180deg, var(--navy-0) 0%, var(--navy-1) 45%, var(--navy-2) 100%);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, rgba(255,255,255,.85) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 78% 12%, rgba(255,255,255,.7) 50%, transparent 51%),
    radial-gradient(1.6px 1.6px at 33% 34%, rgba(255,255,255,.6) 50%, transparent 51%),
    radial-gradient(1.1px 1.1px at 61% 27%, rgba(255,255,255,.75) 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 88% 41%, rgba(255,255,255,.55) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 22% 52%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 50% 8%, rgba(255,255,255,.8) 50%, transparent 51%);
  animation: twinkle 7s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: .75; }
  50% { opacity: 1; }
}

.clouds {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: -6%;
  height: 46%;
  background:
    radial-gradient(60% 100% at 20% 100%, rgba(243, 184, 208, 0.34), transparent 70%),
    radial-gradient(55% 100% at 70% 100%, rgba(159, 208, 240, 0.30), transparent 70%),
    radial-gradient(45% 100% at 45% 100%, rgba(255, 255, 255, 0.10), transparent 70%);
  filter: blur(6px);
}

@media (prefers-reduced-motion: reduce) {
  .stars { animation: none; }
}

/* ── ヘッダー ─────────────────────────────── */
.head {
  flex: 0 0 auto;
  padding: max(env(safe-area-inset-top, 0px), 8px) 12px 8px;
  backdrop-filter: blur(8px);
  background: linear-gradient(180deg, rgba(10,16,40,.85), rgba(10,16,40,.35));
}

.head-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,.14), 0 0 18px var(--lantern-soft);
}

.head-text { flex: 1 1 auto; min-width: 0; }

.head h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .04em;
}

.sub {
  margin: 0;
  font-size: .72rem;
  color: var(--ink-dim);
  line-height: 1.4;
}

.mock-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid rgba(255, 202, 122, .45);
  border-radius: 999px;
  background: rgba(255, 202, 122, .12);
  color: var(--lantern);
  font-size: .62rem;
  letter-spacing: .02em;
  vertical-align: 1px;
}

.icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.07);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255,255,255,.13); }

/* ── ムーン（立ち絵） ─────────────────────── */
.stage {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: min(30vh, 210px);
  min-height: 110px;
  margin-top: 2px;
  pointer-events: none;
}

/* ランタンの灯りのような後光 */
.glow {
  position: absolute;
  bottom: -6%;
  width: min(58vw, 260px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--lantern-soft) 0%, rgba(255, 202, 122, 0.06) 45%, transparent 70%);
  animation: breathe 5.5s ease-in-out infinite;
}

.moon {
  position: relative;
  height: 100%;
  width: auto;
  max-width: 82vw;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 6px 22px rgba(0, 0, 0, 0.38));
  animation: float 5.5s ease-in-out infinite;
  transform-origin: 50% 100%;
  user-select: none;
  -webkit-user-drag: none;
}

/* ふわふわ浮いている（重力がゆるい世界観） */
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  35%      { transform: translateY(-6px) rotate(-0.8deg); }
  70%      { transform: translateY(-2px) rotate(0.6deg); }
}

@keyframes breathe {
  0%, 100% { opacity: .75; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.06); }
}

/* 話しているあいだは、すこし弾む */
.stage.talking .moon {
  animation: talk .46s ease-in-out infinite;
}

@keyframes talk {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50%      { transform: translateY(-3px) scale(1.012, 0.988); }
}

/* 考えているあいだは、ゆっくり首をかしげる */
.stage.thinking .moon {
  animation: ponder 2.6s ease-in-out infinite;
}

@keyframes ponder {
  0%, 100% { transform: rotate(-2.5deg) translateY(0); }
  50%      { transform: rotate(2.5deg) translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .moon, .glow,
  .stage.talking .moon,
  .stage.thinking .moon { animation: none; }
}

/* ── 会話ログ ─────────────────────────────── */
.log {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise .32s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}

.msg.moon {
  align-self: flex-start;
  background: var(--bubble-moon);
  border: 1px solid rgba(255,255,255,.10);
  border-bottom-left-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,.22), 0 0 30px var(--lantern-soft);
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border: 1px solid rgba(159, 208, 240, .22);
  border-bottom-right-radius: 6px;
}

.msg.error {
  align-self: center;
  max-width: 100%;
  background: rgba(255, 202, 122, .10);
  border: 1px solid rgba(255, 202, 122, .30);
  color: #ffe0b4;
  font-size: .86rem;
  text-align: center;
}

/* ── 考え中 ───────────────────────────────── */
.typing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 20px 6px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  color: var(--ink-dim);
  font-size: .78rem;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lantern);
  opacity: .5;
  animation: blink 1.3s infinite;
}

.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 100% { opacity: .28; }
  50% { opacity: 1; }
}

.typing-text { margin-left: 4px; }

/* ── 入力欄 ───────────────────────────────── */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 14px calc(6px + var(--safe-b));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 11px 15px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: var(--radius);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  font: inherit;
  line-height: 1.6;
}

.input::placeholder { color: rgba(166,176,212,.65); }

.input:focus {
  outline: none;
  border-color: rgba(255, 202, 122, .45);
  box-shadow: 0 0 0 3px rgba(255, 202, 122, .12);
}

.send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--lantern);
  color: #3a2a10;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}

.send:hover { transform: translateY(-1px); }
.send:disabled { opacity: .35; cursor: default; transform: none; }

/* ── フッター注記 ─────────────────────────── */
.foot {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 18px calc(10px + var(--safe-b));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  font-size: .66rem;
  line-height: 1.6;
  color: rgba(166,176,212,.72);
  text-align: center;
}

.foot a { color: rgba(196, 214, 245, .9); }

#quota { display: block; }

/* ── メニュー ─────────────────────────────── */
.menu {
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  background: var(--navy-1);
  color: var(--ink);
  padding: 18px;
  min-width: 260px;
  max-width: 90vw;
}

.menu::backdrop { background: rgba(5, 8, 20, .6); }

.menu h2 {
  margin: 0 0 12px;
  font-size: .95rem;
  font-weight: 600;
}

.menu-item {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 11px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.menu-item:hover { background: rgba(255,255,255,.10); }
.menu-item.danger { color: #ffc0c8; border-color: rgba(255,160,170,.28); }

.menu-note {
  margin: 14px 0 0;
  font-size: .72rem;
  line-height: 1.7;
  color: var(--ink-dim);
}

.menu-note a { color: rgba(196, 214, 245, .95); }
