:root {
  --bg: #ffe9c7; --wall: #fff5e1; --floor: #eac898; --ink: #3a2a1a; --accent: #ff8a3d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c", "Rounded Mplus 1c", "Noto Sans JP", system-ui, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; width: 100%; height: 100%; }

#app {
  height: 100vh; height: 100dvh; max-width: 900px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

#top {
  display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 8px 14px;
}
#title { display: flex; flex-direction: column; font-weight: 800; font-size: 1.5rem; line-height: 1.2; min-width: 6em; }
#day { font-size: .95rem; opacity: .75; }
#stats { flex: 1; display: flex; gap: 6px 18px; flex-wrap: wrap; }
.stat { display: flex; align-items: center; gap: 6px; }
.sicon { width: 34px; height: 34px; }
.hearts { display: flex; gap: 3px; }
.hearts span { width: 28px; height: 28px; }
#soundBtn { margin-left: auto; width: 52px; height: 52px; padding: 7px; border: 3px solid var(--ink); border-radius: 14px; background: #fff7e8; }

#room {
  flex: 1; position: relative; overflow: hidden; min-height: 240px;
  border: 3px solid var(--ink); border-radius: 24px;
  background: linear-gradient(var(--wall) 0 66%, var(--floor) 66%);
}
#window {
  position: absolute; top: 7%; left: 7%; width: 20%; max-width: 150px; aspect-ratio: 1;
  border: 5px solid #b0794a; border-radius: 12px; overflow: hidden; background: #9fd8ff;
}
#petWrap {
  position: absolute; bottom: 5%; left: 50%; height: 60%; max-width: 70%; aspect-ratio: 1;
  transform: translateX(-50%); transition: left 2.4s ease-in-out; z-index: 2;
}
#pet { width: 100%; height: 100%; transition: transform .35s; }
#pet.flip { transform: scaleX(-1); }
#pet svg { transform-origin: 50% 95%; animation: bob 1.3s ease-in-out infinite; }
#room.egg #pet svg { animation: wobble 2.6s ease-in-out infinite; }
#room.sleeping #pet svg { animation: breathe 3.2s ease-in-out infinite; }
#room.sick #pet svg { animation: shiver .5s linear infinite; }
#petWrap.hop #pet svg { animation: hop .55s ease-out; }
#petWrap.no #pet svg { animation: no .6s ease-in-out; }
.chomp { transform-box: fill-box; transform-origin: center; animation: chomp .25s ease-in-out infinite alternate; }

@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-3%) } }
@keyframes breathe { 0%,100% { transform: scale(1, 1) } 50% { transform: scale(1.03, .97) } }
@keyframes wobble { 0%,70%,100% { transform: rotate(0) } 76% { transform: rotate(-8deg) } 84% { transform: rotate(8deg) } 92% { transform: rotate(-4deg) } }
@keyframes shiver { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-1%) } 75% { transform: translateX(1%) } }
@keyframes hop { 0% { transform: translateY(0) scale(1.08, .92) } 40% { transform: translateY(-22%) scale(.95, 1.05) } 100% { transform: translateY(0) } }
@keyframes no { 0%,100% { transform: rotate(0) } 25% { transform: rotate(-10deg) } 75% { transform: rotate(10deg) } }
@keyframes chomp { from { transform: scaleY(1) } to { transform: scaleY(.25) } }

#alert {
  position: absolute; top: 2%; right: 6%; width: 48px; height: 48px; border-radius: 50%;
  background: #ff4d4d; color: #fff; font-weight: 900; font-size: 32px; line-height: 1;
  display: grid; place-items: center; border: 3px solid var(--ink); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.15) } }

#poops { position: absolute; left: 0; right: 0; bottom: 4%; height: 15%; z-index: 1; }
.poop { position: absolute; bottom: 0; height: 100%; aspect-ratio: 1; transform: translateX(-50%); }
.poop.gone { animation: swoosh .5s ease-in forwards; }
@keyframes swoosh { to { transform: translateX(200%) scale(.3); opacity: 0 } }

#fx { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.float { position: absolute; width: 56px; height: 56px; animation: floatUp 1.2s ease-out forwards; }
@keyframes floatUp { from { transform: translate(-50%, 0) scale(.6); opacity: 1 } to { transform: translate(-50%, -140px) scale(1.1); opacity: 0 } }
.food { position: absolute; width: 70px; height: 70px; transform: translate(-50%, 0); animation: eaten 1.6s ease-in forwards; }
@keyframes eaten { 0% { transform: translate(-50%, -40px) scale(.4); opacity: 0 } 20% { transform: translate(-50%, 0) scale(1); opacity: 1 } 80% { transform: translate(-50%, 0) scale(.5); opacity: 1 } 100% { transform: translate(-50%, 0) scale(0); opacity: 0 } }
.broomFx { position: absolute; bottom: 4%; width: 90px; height: 90px; animation: sweep 1s ease-in-out forwards; }
@keyframes sweep { from { left: -10% } to { left: 105% } }

#night { position: absolute; inset: 0; background: rgba(20, 24, 70, .55); opacity: 0; pointer-events: none; transition: opacity 1.2s; z-index: 3; }
#room.sleeping #night { opacity: 1; }
#zzz { position: absolute; top: 18%; left: 58%; z-index: 4; color: #fff; font-weight: 900; font-size: 2.4rem; }
#zzz span { display: inline-block; animation: zz 2.4s ease-in-out infinite; }
#zzz span:nth-child(2) { font-size: .8em; animation-delay: .4s; }
#zzz span:nth-child(3) { font-size: .6em; animation-delay: .8s; }
@keyframes zz { 0%,100% { transform: translateY(0); opacity: .4 } 50% { transform: translateY(-14px); opacity: 1 } }

#bubble {
  position: absolute; top: 6%; left: 50%; transform: translateX(-50%); z-index: 6;
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 10px 20px;
  font-size: 1.55rem; font-weight: 800; max-width: 86%; text-align: center; line-height: 1.4;
  animation: popIn .2s ease-out;
}
@keyframes popIn { from { transform: translateX(-50%) scale(.7) } to { transform: translateX(-50%) scale(1) } }

#actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
#actions button {
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 8px 4px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-weight: 800; font-size: 1.2rem; box-shadow: 0 5px 0 var(--ink); min-height: 96px;
}
#actions button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#actions .icon { width: 54px; height: 54px; }
#actions button.glow { background: #fff2a8; animation: pulse 1.1s ease-in-out infinite; }
@media (max-width: 560px) {
  #actions { grid-template-columns: repeat(3, 1fr); }
  #actions button { min-height: 84px; font-size: 1.05rem; }
  #title { font-size: 1.25rem; }
  #stats { order: 3; flex-basis: 100%; justify-content: space-around; }
  .hearts span { width: 24px; height: 24px; }
}

#modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; }
.card {
  background: #fff; border: 4px solid var(--ink); border-radius: 28px; padding: 22px;
  width: min(540px, 100%); max-height: 94vh; overflow: auto; text-align: center;
  font-size: 1.45rem; font-weight: 800; line-height: 1.5; animation: cardIn .25s ease-out;
}
@keyframes cardIn { from { transform: scale(.8); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.card h2 { margin: 0 0 8px; font-size: 1.8rem; }
.card p { margin: 8px 0; }
.card .art { width: min(55vw, 230px); aspect-ratio: 1; margin: 0 auto; }
.card .art.glowArt { filter: drop-shadow(0 0 18px #ffd84d); animation: hop .8s ease-out 2; }
.choices { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.big {
  font-size: 1.45rem; font-weight: 800; padding: 12px 26px; border-radius: 20px;
  border: 3px solid var(--ink); background: var(--accent); color: #fff; box-shadow: 0 5px 0 var(--ink);
}
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.big.sub { background: #fff; color: var(--ink); }
.choice { background: #fff; color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 9em; }
.choice span:first-child { width: 80px; height: 80px; }
.card input {
  width: 100%; font: inherit; font-size: 1.7rem; text-align: center; padding: 10px;
  border: 3px solid var(--ink); border-radius: 16px; margin: 10px 0;
}
.statRow { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 6px 0; }
.statRow .sicon { width: 40px; height: 40px; }
.statRow .hearts span { width: 34px; height: 34px; }
.small { font-size: 1rem; opacity: .7; }

#game {
  position: fixed; inset: 0; z-index: 15; color: #fff; display: flex; flex-direction: column;
  background: linear-gradient(#1b2a6b, #5a3f9a);
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}
#gHead { display: flex; justify-content: space-between; font-size: 1.8rem; font-weight: 900; }
#gScore { background: #ffd84d; color: var(--ink); border-radius: 16px; padding: 0 18px; }
#gBar { height: 14px; background: rgba(255, 255, 255, .25); border-radius: 7px; margin: 8px 0; overflow: hidden; }
#gTime { height: 100%; width: 100%; background: #7cf0a0; transition: width 1s linear; }
#gField { position: relative; flex: 1; overflow: hidden; }
.star { position: absolute; top: -110px; width: min(19vw, 100px); aspect-ratio: 1; animation: fall linear forwards; touch-action: none; }
.star svg { pointer-events: none; }
.star.got { animation: starPop .35s ease-out forwards; }
@keyframes fall { from { top: -110px; transform: rotate(0) } to { top: 105%; transform: rotate(220deg) } }
@keyframes starPop { to { transform: scale(1.8); opacity: 0 } }
#gPet { height: 22%; aspect-ratio: 1; margin: 0 auto; }
#gPet svg { animation: bob .7s ease-in-out infinite; }

/* サーバーに保存できていないとき (保護者むけの小さな表示) */
#offline {
  position: absolute; right: 10px; bottom: 10px; z-index: 6; font-size: .9rem; font-weight: 700;
  background: rgba(255, 255, 255, .85); color: #a33; border: 2px solid #a33; border-radius: 12px; padding: 2px 10px;
}
