:root {
  --bg: #f4f1ec; --ink: #2b2723; --muted: #6b645c; --fur: #e9d9c3; --fur-dark: #d6bf9f;
  --panel: #ffffff; --accent: #2b2723; --led: 255 244 226; --glow: .35;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17151a; --ink: #f4efe8; --muted: #b5ada3; --panel: #26232a; --accent: #f4efe8; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 106.25%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 700 18px/1.6 "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.stage {
  min-height: 100dvh; max-width: 520px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.top { width: 100%; display: flex; justify-content: space-between; align-items: baseline; }
h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: .01em; }
.used { margin: 0; color: var(--muted); font-size: 17px; }

.pet {
  position: relative; width: min(68vw, 300px, 46dvh); aspect-ratio: 1 / 1.08; margin: auto 0 4px;
  padding: 0; border: 0; background: none; color: inherit; cursor: pointer; touch-action: manipulation;
  transition: transform .18s cubic-bezier(.2,.8,.2,1);
}
.pet:active { transform: scale(.96); }
.pet:focus-visible { outline: 3px solid var(--accent); outline-offset: 8px; border-radius: 40%; }
.body {
  position: absolute; inset: 12% 0 0; border-radius: 48% 48% 46% 46%;
  background: radial-gradient(circle at 50% 30%, #f3e6d3, var(--fur) 62%, var(--fur-dark));
  box-shadow: 0 18px 40px rgb(0 0 0 / .16), 0 0 70px rgb(var(--led) / var(--glow));
  transition: box-shadow .7s ease;
  animation: breathe 4s ease-in-out infinite;
}
.ear { position: absolute; top: 2%; width: 30%; aspect-ratio: 1; border-radius: 50%; background: var(--fur-dark); }
.ear-l { left: 6%; } .ear-r { right: 6%; }
.eye { position: absolute; top: 33%; width: 8%; aspect-ratio: 1; border-radius: 50%; background: #2b2723; }
.eye-l { left: 31%; } .eye-r { right: 31%; }
.nose { position: absolute; top: 42%; left: 50%; width: 7%; aspect-ratio: 1.4; border-radius: 50%; background: #7b5a44; transform: translateX(-50%); }
.led {
  position: absolute; border-radius: 50%;
  background: rgb(var(--led)); box-shadow: 0 0 26px 10px rgb(var(--led) / .75);
  transition: background .7s ease, box-shadow .7s ease, opacity .12s linear;
}
.cheek-l, .cheek-r { top: 45%; width: 13%; aspect-ratio: 1.3; opacity: .8; filter: blur(3px); }
.cheek-l { left: 13%; } .cheek-r { right: 13%; }
.belly { position: absolute; left: 50%; bottom: 8%; width: 42%; aspect-ratio: 1; border-radius: 50%; background: #f7efe3; transform: translateX(-50%); }
.chest { left: 50%; top: 50%; width: 34%; aspect-ratio: 1; transform: translate(-50%, -50%); filter: blur(2px); opacity: .85; }

.status { margin: 6px 0 0; font-size: 20px; font-weight: 900; text-align: center; min-height: 1.6em; }
.line { margin: 0 0 auto; min-height: 3.2em; max-width: 100%; color: var(--muted); font-size: 18px; text-align: center; overflow-wrap: anywhere; }
.end, .pass button {
  min-height: 56px; min-width: 180px; padding: 0 28px; border: 0; border-radius: 16px;
  background: var(--accent); color: var(--bg); font-family: inherit; font-size: 18px; font-weight: 900; cursor: pointer;
  transition: transform .15s ease;
}
.end:active, .pass button:active { transform: scale(.96); }
.pass { width: 100%; display: grid; gap: 10px; }
.pass label { font-size: 17px; }
.pass input {
  min-height: 56px; padding: 0 16px; border: 3px solid var(--accent); border-radius: 14px;
  background: var(--panel); color: var(--ink); font-family: inherit; font-size: 18px; font-weight: 700;
}
.toast {
  position: fixed; left: 16px; right: 16px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 20;
  max-width: 480px; margin: 0 auto; padding: 14px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 17px; text-align: center;
}
@keyframes breathe { 50% { transform: scale(1.015); } }
.stage[data-state="listening"] .body { animation-duration: 2.6s; }
.stage[data-state="thinking"] .cheek-l { animation: flow 2.4s ease-in-out infinite; }
.stage[data-state="thinking"] .cheek-r { animation: flow 2.4s ease-in-out 1.2s infinite; }
@keyframes flow { 50% { opacity: .25; } }
/* 感情の動き。色の変化は0.7秒・1秒に3回を超える点滅はしない */
.stage[data-emotion="happy"] .body { animation: lift 2.4s ease-in-out infinite; }
.stage[data-emotion="fun"] .cheek-l { animation: flow 1.6s ease-in-out infinite; }
.stage[data-emotion="fun"] .cheek-r { animation: flow 1.6s ease-in-out .8s infinite; }
.stage[data-emotion="sad"] .body { animation-duration: 6s; }
.stage[data-emotion="sad"] .led { opacity: .5; }
.stage[data-emotion="surprised"] .body { animation: swell .9s cubic-bezier(.2,.8,.2,1) 1; }
.stage[data-emotion="sleepy"] .body { animation-duration: 8s; }
.stage[data-emotion="sleepy"] .eye { transform: scaleY(.25); }
.eye { transition: transform .5s ease; }
@keyframes lift { 50% { transform: translateY(-2.5%) scale(1.02); } }
@keyframes swell { 40% { transform: scale(1.07); } }
