/* がしゃがしゃ こうじょう — 見た目。ライト=だんボールいろ・ダーク=よるの こうじょう。外部フォントは使わない */
:root {
  --bg: #f3e6d3;
  --wall: #fbf3e6;
  --wall-2: #efe0c8;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #d9c3a3;
  --steel: #8d96a8;
  --belt: #3b3f4c;
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1d27;
    --wall: #2a2735;
    --wall-2: #24212e;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --card: #2f2b3e;
    --card-sh: #14121c;
    --steel: #6c7488;
    --belt: #11131a;
    --focus: #ffc53d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
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 minmax(0, 1fr) auto;
  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; font-size: clamp(18px, 5vw, 26px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; }
.snd { flex-shrink: 0; width: 56px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }
.snd svg { width: 34px; height: 34px; }
.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; }

/* ---- こうじょう ---- */
.scene { min-height: 0; display: flex; align-items: center; justify-content: center; }
.factory {
  position: relative; width: 100%; height: 100%; max-width: 900px; max-height: 520px;
  border: 3px solid var(--ink); border-radius: 22px; overflow: hidden;
  background: repeating-linear-gradient(90deg, var(--wall) 0 46px, var(--wall-2) 46px 48px);
}
.rail { position: absolute; left: 0; right: 0; top: 8%; height: 10px; background: var(--steel); border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }

.slots { position: absolute; inset: 0; pointer-events: none; }
.slot { position: absolute; top: calc(8% + 6px); height: calc(var(--beltY) - 8% - 6px); pointer-events: auto; border-radius: 14px; }
.mach { position: absolute; left: 0; right: 0; top: 0; display: flex; flex-direction: column; align-items: center; }
.mbody {
  width: 100%; aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--ink);
  padding: 12%; background: var(--card); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14);
}
.arm { width: 10px; height: 5%; min-height: 8px; background: var(--steel); border: 3px solid var(--ink); border-top: 0; border-bottom: 0; }
.head { width: 70%; height: 12px; border-radius: 4px; background: var(--steel); border: 3px solid var(--ink); }
.slot.empty .mbody { background: transparent; border-style: dashed; box-shadow: none; display: grid; place-items: center; }
.slot.empty .mbody::after { content: "+"; font-size: 30px; font-weight: 900; color: var(--sub); }
.slot.empty .arm, .slot.empty .head { visibility: hidden; }
/* えらんでいる ばしょ(つぎに きかいが はいる ところ) */
.slot.sel .mbody { box-shadow: 0 0 0 4px var(--gold), inset 0 -6px 0 rgba(0, 0, 0, .14); }
.slot.empty.sel .mbody { border-color: var(--gold); border-width: 4px; background: rgba(255, 197, 61, .16); }
.slot.empty.sel .mbody::after { color: #e8a200; animation: plus 1s ease-in-out infinite; }
@keyframes plus { 50% { transform: scale(1.25); } }
.xbtn { position: absolute; z-index: 3; width: 48px; height: 48px; padding: 8px; }
.xbtn:active { transform: scale(.9); }

.belt { position: absolute; left: -2%; width: calc(82% + var(--size) * .5 + 2%); top: var(--beltY); height: 20px; border: 3px solid var(--ink); border-left: 0; border-radius: 0 12px 12px 0; background: var(--belt); overflow: hidden; }
.belt-strip { position: absolute; top: 0; bottom: 0; left: 0; width: calc(100% + 80px); background: repeating-linear-gradient(90deg, transparent 0 28px, rgba(255, 255, 255, .28) 28px 40px); will-change: transform; }
.belt::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 3px 0 rgba(255, 255, 255, .18); }

.toys { position: absolute; inset: 0; pointer-events: none; }
.toy { position: absolute; left: 0; top: 0; width: var(--size); height: calc(var(--size) * 1.5); pointer-events: auto; will-change: transform; }
.toy .bob { display: block; width: 100%; height: 100%; transform-origin: 50% 100%; }

.truck { position: absolute; right: 1%; width: 19%; top: calc(var(--beltY) - 4px); aspect-ratio: 120 / 80; }
.truck .bed { position: absolute; left: 4%; width: 62%; bottom: 64%; display: flex; flex-wrap: wrap-reverse; justify-content: center; }
.truck .mini { width: 30%; aspect-ratio: 100 / 150; margin: 0 -4%; }

/* ---- きかいの ボタン ---- */
.tray { display: flex; justify-content: center; }
.machines { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(100%, 560px); }
.mbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 80px; padding: 6px 4px; border-radius: 18px;
  background: var(--card); box-shadow: 0 5px 0 var(--card-sh);
}
.mbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--card-sh); }
.mi { width: 50px; height: 50px; padding: 5px; border-radius: 12px; background: var(--c); border: 2.5px solid var(--ink); }
.mn { font-size: clamp(13px, 3.6vw, 17px); font-weight: 900; white-space: nowrap; }
.cbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 80px; padding: 6px 4px; border-radius: 18px; background: var(--card); box-shadow: 0 5px 0 var(--card-sh);
}
.cbtn[aria-pressed="true"] { box-shadow: 0 5px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.cbtn:active { transform: translateY(3px); }
.cs { width: 50px; height: 50px; border-radius: 50%; border: 3px solid var(--ink); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15); }
.colors .cbtn { animation: rise .22s ease-out both; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.hint .mbtn { animation: nudge 1.2s ease-in-out infinite; }
.hint .mbtn:nth-child(2) { animation-delay: .1s; } .hint .mbtn:nth-child(3) { animation-delay: .2s; }
.hint .mbtn:nth-child(4) { animation-delay: .3s; } .hint .mbtn:nth-child(5) { animation-delay: .4s; } .hint .mbtn:nth-child(6) { animation-delay: .5s; }
@keyframes nudge { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-6px); } }

/* スマホを横にしたとき: きかいの ボタンを みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); column-gap: 12px; }
  .top { grid-column: 1 / -1; }
  .logo img { width: 32px; height: 32px; }
  .snd { width: 48px; height: 48px; }
  .tray { grid-column: 2; grid-row: 2; align-items: center; }
  .machines { width: auto; grid-template-columns: repeat(2, 84px); gap: 8px; }
  .mbtn, .cbtn { min-height: 0; height: min(calc((100svh - 15vh - 90px) / 3), 86px); padding: 2px; }
  .cs { width: 38px; height: 38px; }
  .mi { width: 38px; height: 38px; }
  .mn { font-size: 13px; }
}

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