/* まぜまぜ へんしん ラボ — 見た目。ライト=うすむらさき・ダーク=よるの ラボ。外部フォントは使わない */
:root {
  --bg: #f1ecff;
  --lab: #ffffff;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #cfc3ee;
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a2b;
    --lab: #3b3556;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --card: #2f2a45;
    --card-sh: #12101c;
    --focus: #ffc53d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 15vh calc(env(safe-area-inset-left) + 10px);
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; font-size: clamp(17px, 4.6vw, 24px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
@media (max-width: 440px) { .logo span { display: none; } }
.kids { display: flex; gap: 6px; }
.kid { width: 52px; height: 56px; padding: 2px 4px 6px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.kid[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.snd { flex-shrink: 0; width: 52px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg { width: 32px; height: 32px; }
.spk { fill: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }
.kid:active, .snd:active { transform: translateY(3px); }

/* みつけた すがた(シール)。あたらしい ものが ひだり。からの わくは みせない。おおいときは よこに すべらせる */
.wall { display: flex; gap: 6px; height: 52px; padding: 2px 2px 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; touch-action: pan-x; }
.wall::-webkit-scrollbar { display: none; }
.stk { flex: 0 0 auto; width: 44px; height: 44px; padding: 2px; border-radius: 12px; background: var(--card); box-shadow: 0 3px 0 var(--card-sh); }
.stk.new { animation: stk .6s ease-out; box-shadow: 0 3px 0 var(--card-sh), 0 0 0 3px var(--gold); }
@keyframes stk { 0% { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.3); } }

/* ---- ラボ ---- */
.stage {
  position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 24px; overflow: hidden;
  background: radial-gradient(circle at 50% 62%, rgba(255, 255, 255, .0) 0 30%, transparent 31%), var(--lab);
  display: grid; place-items: center;
}
.stage::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: 12%; height: 8%; border-radius: 50%; background: rgba(43, 36, 51, .12); }
.me { position: absolute; z-index: 2; top: 3%; left: 0; right: 0; margin: 0 auto; height: 83%; width: auto; max-width: 92%; aspect-ratio: 200 / 220; }
.mv { display: block; width: 100%; height: 100%; transform-origin: 50% 85%; }
.name { position: absolute; z-index: 3; left: 0; right: 0; bottom: 2%; margin: 0; text-align: center; font-size: clamp(18px, 5vw, 26px); font-weight: 900; }

.a-idle { animation: breathe 2.4s ease-in-out infinite; }
.a-bounce { animation: bounce .8s ease-in-out infinite; }
.a-float { animation: float 2.2s ease-in-out infinite; }
.a-shiver { animation: shiver .18s linear infinite; }
.a-wobble { animation: wobble 1.4s ease-in-out infinite; }
.a-dizzy { animation: dizzy 2s ease-in-out infinite; }
.a-skate { animation: skate 2.6s ease-in-out infinite; }
.a-robot { animation: robot 1.2s steps(2) infinite; }
@keyframes breathe { 50% { transform: scale(1.03, .97); } }
@keyframes bounce { 50% { transform: translateY(-8%) scale(.97, 1.04); } }
@keyframes float { 50% { transform: translateY(-7%); } }
@keyframes shiver { 25% { transform: translateX(-1.5%); } 75% { transform: translateX(1.5%); } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes dizzy { 25% { transform: rotate(-14deg) translateX(-4%); } 75% { transform: rotate(14deg) translateX(4%); } }
@keyframes skate { 25% { transform: translateX(-14%) rotate(-6deg); } 75% { transform: translateX(14%) rotate(6deg); } }
@keyframes robot { 50% { transform: translateY(-3%) rotate(3deg); } }
.orbit { transform-origin: 100px 128px; animation: spin 5s linear infinite; }
.orbit.r2 { animation-duration: 3.4s; animation-direction: reverse; }
.sparks { transform-origin: 100px 128px; animation: twinkle .7s ease-in-out infinite; }
.puff { animation: puff 1.6s ease-in-out infinite; }
.puff:nth-child(2) { animation-delay: -.5s; } .puff:nth-child(3) { animation-delay: -1s; }
.tent { animation: float 1s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes twinkle { 50% { transform: scale(1.08); opacity: .7; } }
@keyframes puff { 50% { transform: translateY(-6px); opacity: .6; } }

/* だいの えんしゅつ */
.glow { position: absolute; inset: 0; opacity: 0; transition: opacity .25s; }
.glow.g-fire { background: radial-gradient(circle at 50% 70%, #ffa94d, transparent 65%); opacity: .7; }
.glow.g-ice { background: radial-gradient(circle at 50% 50%, #a5d8ff, transparent 70%); opacity: .8; }
.glow.g-spin { background: radial-gradient(circle at 50% 50%, #b2f2bb, transparent 65%); opacity: .7; }
.glow.g-zap { background: #fff3bf; opacity: .9; animation: flash .12s steps(2) 4; }
.glow.g-bubble, .glow.g-bath { background: radial-gradient(circle at 50% 60%, #ffdeeb, transparent 70%); opacity: .7; }
.glow.g-bath { background: radial-gradient(circle at 50% 60%, #d0ebff, transparent 70%); }
@keyframes flash { 50% { opacity: .2; } }
.fx { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.fx i { position: absolute; left: var(--x); bottom: 8%; display: block; animation-delay: var(--d); animation-fill-mode: both; }
.f-fire i { width: 26px; height: 40px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: radial-gradient(circle at 50% 70%, #ffe066 0 30%, #ff922b 32%); border: 3px solid #2b2433; animation: rise .7s ease-out; }
.f-ice i { width: 14px; height: 14px; bottom: auto; top: -10%; border-radius: 3px; background: #fff; border: 2.5px solid #4dabf7; transform: rotate(45deg); animation: snow .7s ease-in; }
.f-bubble i, .f-bath i { width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, .5); border: 3px solid #f783ac; animation: rise .7s ease-out; }
.f-bath i { border-color: #4dabf7; }
.f-zap i { width: 30px; height: 60px; top: 10%; bottom: auto; background: #fab005; clip-path: polygon(60% 0, 10% 55%, 45% 55%, 30% 100%, 90% 40%, 55% 40%); animation: zap .6s steps(3); }
@keyframes rise { from { transform: translateY(40%) scale(.6); opacity: 1; } to { transform: translateY(-260%) scale(1.1); opacity: 0; } }
@keyframes snow { from { transform: translateY(0) rotate(45deg); } to { transform: translateY(420%) rotate(225deg); opacity: 0; } }
@keyframes zap { 0%, 100% { opacity: 0; } 30%, 70% { opacity: 1; } }

/* ---- だいの ボタン ---- */
.tray { display: flex; justify-content: center; }
.stations { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(100%, 560px); }
.stn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 78px; padding: 6px 4px; border-radius: 18px;
  background: var(--card); box-shadow: 0 5px 0 var(--card-sh);
}
.stn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--card-sh); }
.si { width: 48px; height: 48px; padding: 4px; border-radius: 12px; background: var(--c); border: 2.5px solid #2b2433; }
.sn { font-size: clamp(13px, 3.6vw, 17px); font-weight: 900; white-space: nowrap; }

/* スマホを横にしたとき: だいを みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(0, 1fr); column-gap: 12px; }
  .top { grid-column: 1 / -1; }
  .wall { grid-column: 1; }
  .stage { grid-column: 1; }
  .tray { grid-column: 2; grid-row: 2 / 4; align-items: center; }
  .stations { width: auto; grid-template-columns: repeat(2, 84px); gap: 8px; }
  .stn { min-height: 0; height: min(calc((100svh - 15vh - 90px) / 3), 84px); padding: 2px; }
  .si { width: 36px; height: 36px; }
  .sn { font-size: 13px; }
  .stk { width: 40px; height: 40px; }
  .kid, .snd { height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
