:root { --bg: #ffe9c7; --wall: #ffe9c7; --counter: #e0a86b; --counter-edge: #c98b4e; }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); }
img, svg { pointer-events: none; }

#app {
  position: fixed; inset: 0; display: grid;
  grid-template-rows: 34% 34% 32%; grid-template-areas: "stage" "kitchen" "tray";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: linear-gradient(var(--wall) 0 56%, var(--counter-edge) 56% 57.5%, var(--counter) 57.5% 100%);
  font-family: -apple-system, "Hiragino Sans", system-ui, sans-serif; overflow: hidden;
}
section { position: relative; min-height: 0; }

/* ---- 動物 ---- */
#stage { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
#character { height: 88%; max-width: 100%; aspect-ratio: 1; display: grid; place-items: center; }
#character svg { height: 100%; width: 100%; overflow: visible; }
#plate-slot { height: 12%; width: 60%; }
.bubble {
  position: absolute; top: 2%; right: 5%;
  font-size: clamp(34px, 9vmin, 64px); line-height: 1; padding: .18em .3em; background: #fff; border-radius: 1em; border-bottom-left-radius: .2em;
  box-shadow: 0 3px 0 rgba(0,0,0,.08); opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
}
.bubble.show { opacity: 1; }

.chara .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.2s infinite; }
.chara .mouth-open, .chara .mouth-chew { display: none; }
.chara[data-mouth="open"] .mouth-open { display: block; }
.chara[data-mouth="open"] .mouth-closed, .chara[data-mouth="chew"] .mouth-closed { display: none; }
.chara[data-mouth="chew"] .mouth-chew { display: block; transform-box: fill-box; transform-origin: center; animation: chew .22s infinite alternate; }
.chara .cheek { opacity: 0; transition: opacity .35s; }
#character.happy .cheek { opacity: .9; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }
@keyframes chew { from { transform: scaleY(.45); } to { transform: scaleY(1.35); } }

/* ---- コンロとお鍋 ---- */
#kitchen { display: grid; place-items: end center; }
#pot { position: relative; width: min(86%, 460px); }
.pot-svg { display: block; width: 100%; height: auto; }
.flame { opacity: 0; transition: opacity .4s; }
[data-phase="cook"] .flame, [data-phase="serve"] .flame { opacity: 1; animation: flicker .5s infinite alternate; }
@keyframes flicker { from { opacity: .55; } to { opacity: 1; } }

#pot-inner { position: absolute; left: 20%; width: 60%; top: 26%; height: 14%; }
#pieces { position: absolute; inset: 0; }
.pot-piece { position: absolute; font-size: clamp(22px, 7vmin, 40px); line-height: 1; transform: translate(-50%, -50%); animation: bob 1.4s ease-in-out infinite alternate; pointer-events: none; }
@keyframes bob { from { transform: translate(-50%, -50%) rotate(-8deg); } to { transform: translate(-50%, -62%) rotate(8deg); } }

#bubbles { position: absolute; inset: 0; display: none; }
[data-phase="cook"] #bubbles, [data-phase="serve"] #bubbles { display: block; }
#bubbles i { position: absolute; bottom: 20%; width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.85); animation: rise 1.3s ease-out infinite; }
#bubbles i:nth-child(1) { left: 14%; animation-delay: 0s; }
#bubbles i:nth-child(2) { left: 30%; animation-delay: .4s; width: 7px; height: 7px; }
#bubbles i:nth-child(3) { left: 46%; animation-delay: .9s; }
#bubbles i:nth-child(4) { left: 60%; animation-delay: .2s; width: 13px; height: 13px; }
#bubbles i:nth-child(5) { left: 74%; animation-delay: .7s; }
#bubbles i:nth-child(6) { left: 86%; animation-delay: 1.1s; width: 7px; height: 7px; }
@keyframes rise { 0% { transform: translateY(0) scale(.5); opacity: 0; } 25% { opacity: .95; } 100% { transform: translateY(-34px) scale(1.25); opacity: 0; } }

#spoon { position: absolute; left: 50%; top: 50%; font-size: clamp(44px, 13vmin, 80px); line-height: 1; transform: translate(-50%, -80%); transform-origin: 50% 85%; display: none; pointer-events: none; filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
[data-phase="cook"] #spoon { display: block; animation: spoon-idle 1.6s ease-in-out infinite alternate; }
@keyframes spoon-idle { from { transform: translate(-50%, -80%) rotate(-12deg); } to { transform: translate(-50%, -80%) rotate(12deg); } }
#spoon.stirring { animation: none; }

#steam { position: absolute; left: 50%; top: 2%; width: 40%; height: 40%; transform: translateX(-50%); display: none; pointer-events: none; }
[data-phase="serve"] #steam, [data-phase="eat"] #steam { display: block; }
#steam i { position: absolute; bottom: 0; width: 26px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.85); filter: blur(5px); animation: steam 1.8s ease-out infinite; }
#steam i:nth-child(1) { left: 20%; animation-delay: 0s; }
#steam i:nth-child(2) { left: 48%; animation-delay: .6s; }
#steam i:nth-child(3) { left: 72%; animation-delay: 1.2s; }
@keyframes steam { 0% { transform: translateY(0) scaleX(1); opacity: 0; } 30% { opacity: .9; } 100% { transform: translateY(-90px) scaleX(1.8); opacity: 0; } }

/* ---- トレイ ---- */
#tray { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 2%; padding: 3% 4% calc(3% + env(safe-area-inset-bottom)); }
.item { display: grid; place-items: center; border-radius: 22px; background: rgba(255,255,255,.55); box-shadow: inset 0 -4px 0 rgba(0,0,0,.06); font-size: clamp(48px, 16vmin, 96px); line-height: 1; min-height: 0; }
.item span { display: block; transform-origin: 50% 70%; pointer-events: none; }
.item.dragging { background: transparent; box-shadow: none; z-index: 5; position: relative; }
.item.gone { visibility: hidden; }

/* ---- お皿・飛ぶ物 ---- */
.plate { position: fixed; left: 0; top: 0; width: clamp(130px, 42vmin, 250px); height: clamp(50px, 15vmin, 90px); transform: translate(-50%, -50%); display: none; }
.plate::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.08), inset 0 0 0 6px #f1f1f1; }
.plate #dish { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -62%); font-size: clamp(64px, 22vmin, 130px); line-height: 1; transition: transform .25s; }
[data-phase="serve"] .plate, [data-phase="eat"] .plate, [data-phase="yum"] .plate { display: block; }
#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#fx span { position: absolute; line-height: 1; will-change: transform, opacity; }
.piece-fly { font-size: clamp(28px, 9vmin, 52px); }
.knife { font-size: clamp(36px, 11vmin, 64px); }
.heart { font-size: clamp(26px, 8vmin, 48px); }
.spark { font-size: clamp(30px, 9vmin, 56px); }
.splash { font-size: clamp(20px, 6vmin, 36px); }

/* ---- 横持ち（iPad など） ---- */
@media (min-aspect-ratio: 1/1) {
  #app { grid-template-rows: 1fr; grid-template-columns: 30% 40% 30%; grid-template-areas: "stage kitchen tray"; background: linear-gradient(var(--wall) 0 62%, var(--counter-edge) 62% 63.5%, var(--counter) 63.5% 100%); }
  #stage { grid-area: stage; } #kitchen { grid-area: kitchen; } #tray { grid-area: tray; }
  #character { height: auto; width: 84%; }
  #tray { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); padding: 4%; }
  #pot { width: min(84%, 520px); }
}
