:root { --sky: #7cc4f4; --sun: #ffd166; --ink: #20334a; --tray-h: 150px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: "Chalkboard SE", "Comic Sans MS", "Marker Felt", ui-rounded, system-ui, sans-serif;
  background: var(--sky); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.on { display: block; }

.round {
  width: 64px; height: 64px; border-radius: 50%; font-size: 32px;
  background: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.18), 0 8px 18px rgba(0,0,0,.15);
  display: grid; place-items: center; transition: transform .12s;
}
.round:active { transform: translateY(3px) scale(.95); box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.round.muted { opacity: .55; filter: grayscale(1); }

/* ---------- HOME ---------- */
#home {
  background:
    radial-gradient(circle at 74% 14%, var(--sun) 0 56px, transparent 58px),
    linear-gradient(#8fd0f7, #bfe6fb 60%, #9ad77f 60.2%, #7cc464);
  display: none; flex-direction: column;
  padding: max(20px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 20px max(24px, env(safe-area-inset-left));
}
#home.on { display: flex; }
.home-head { display: flex; align-items: center; justify-content: space-between; }
.title {
  margin: 0; font-size: clamp(38px, 7vw, 76px); color: #fff; letter-spacing: 1px;
  text-shadow: 0 4px 0 #2a7fc0, 0 8px 18px rgba(0,0,0,.2);
  animation: bob 3s ease-in-out infinite;
}
.scene-list {
  flex: 1; display: flex; gap: 28px; align-items: center; justify-content: safe center; overflow-x: auto; overflow-y: hidden;
  padding: 20px 10px 30px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}
.scene-card {
  flex: 0 0 auto; width: min(40vw, 440px); scroll-snap-align: center;
  background: #fff; border-radius: 28px; padding: 12px 12px 8px;
  box-shadow: 0 8px 0 rgba(0,0,0,.15), 0 16px 30px rgba(0,0,0,.18);
  transform: rotate(var(--tilt, 0deg)); transition: transform .15s;
}
.scene-card:active { transform: scale(.96) rotate(var(--tilt, 0deg)); }
.scene-card .pic { aspect-ratio: 4 / 3; border-radius: 18px; background: #ddd center / cover no-repeat; }
.scene-card .name { font-size: 28px; padding: 8px 4px 2px; text-align: center; }
.nothing { font-size: 26px; text-align: center; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }

/* ---------- PLAY ---------- */
.backdrop { position: absolute; inset: -40px; background: #333 center / cover; filter: blur(24px) brightness(.8); transform: scale(1.1); }
.stage-wrap { position: absolute; inset: 0; bottom: var(--tray-space, var(--tray-h)); display: grid; place-items: center; transition: bottom .3s ease; }
.stage {
  position: relative; background: #eee center / 100% 100% no-repeat; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.35); border-radius: 6px; touch-action: none;
}

.item { position: absolute; transform: translate(-50%, -100%); touch-action: none; cursor: grab; }
.item .flip { height: 100%; transition: transform .2s; }
.item.flipped .flip { transform: scaleX(-1); }
.item img { height: 100%; width: auto; display: block; filter: drop-shadow(0 6px 4px rgba(0,0,0,.18)); transform-origin: 50% 100%; }
.item.dragging { cursor: grabbing; z-index: 9999 !important; }
.item.dragging img { transform: scale(1.08) translateY(-4%); filter: drop-shadow(0 18px 12px rgba(0,0,0,.25)); transition: transform .1s; }
.item.boing img { animation: boing .6s ease; }
.item.wiggle img { animation: wiggle .5s ease; }
.item.pop img { animation: pop .35s ease-out; }
.item.poof { transition: transform .25s, opacity .25s; opacity: 0; transform: translate(-50%, -100%) scale(.2); }

.bubble {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -6px) scale(0); transform-origin: 50% 100%;
  background: #fff; border-radius: 22px; padding: 8px 16px; font-size: clamp(16px, 2.2vw, 24px); white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); transition: transform .2s cubic-bezier(.3,1.6,.6,1); pointer-events: none; z-index: 2;
}
.bubble::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -10px; border: 10px solid transparent; border-top-color: #fff; }
.bubble.show { transform: translate(-50%, -6px) scale(1); }

.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); pointer-events: none; z-index: 20; }
.hud > *, .hud-right > * { pointer-events: auto; }
.hud-right { display: flex; gap: 12px; }

.trash {
  position: absolute; right: 24px; bottom: calc(var(--tray-space, var(--tray-h)) + 16px); z-index: 30;
  width: 96px; height: 96px; border-radius: 50%; background: rgba(255,255,255,.9); font-size: 50px;
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  transform: scale(0); transition: transform .2s cubic-bezier(.3,1.6,.6,1); pointer-events: none;
}
.trash.show { transform: scale(1); }
.trash.hot { transform: scale(1.25); background: #ffdfdf; }

.tray {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--tray-h); z-index: 25;
  background: rgba(255,255,255,.92); border-radius: 28px 28px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.2);
  padding: 0 max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
  transition: transform .3s ease; display: flex; align-items: stretch; gap: 10px;
}
.tray:not(.open) { transform: translateY(calc(100% - 22px)); }
.tray-toggle {
  position: absolute; left: 50%; top: -34px; transform: translateX(-50%); width: 90px; height: 36px;
  background: rgba(255,255,255,.92); border-radius: 18px 18px 0 0; font-size: 26px; line-height: 36px;
}
.tray:not(.open) .tray-toggle { transform: translateX(-50%) rotate(180deg); border-radius: 0 0 18px 18px; top: -14px; }
.tray-tabs { display: flex; flex-direction: column; justify-content: center; gap: 8px; padding: 10px 0; }
.tab { padding: 10px 14px; border-radius: 18px; font-size: 20px; background: #eef4fa; white-space: nowrap; }
.tab.on { background: var(--sun); box-shadow: 0 3px 0 #d9a93a; }
.tray-items {
  flex: 1; display: flex; align-items: center; gap: 14px; overflow-x: auto; overflow-y: hidden;
  padding: 10px 6px; touch-action: pan-x; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tray-items::-webkit-scrollbar { display: none; }
.thumb {
  flex: 0 0 auto; width: 118px; height: 118px; border-radius: 22px; background: #fff; padding: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,.08), inset 0 0 0 3px #e7eef6; touch-action: pan-x;
}
.thumb img { max-width: 100%; max-height: 86px; object-fit: contain; }
.thumb span { font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb.placed { opacity: .45; }
.thumb:active { transform: scale(.95); }

.confirm { position: absolute; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: grid; place-items: center; }
.confirm[hidden] { display: none; }
.confirm-box { background: #fff; border-radius: 32px; padding: 26px 36px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.3); animation: pop .3s ease-out; }
.confirm-q { font-size: 40px; margin-bottom: 18px; }
.confirm-btns { display: flex; gap: 26px; justify-content: center; }
.big { width: 100px; height: 100px; border-radius: 50%; font-size: 48px; color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.big.yes { background: #4cc26b; }
.big.no { background: #ef6b6b; }

@keyframes bob { 50% { transform: translateY(-6px) rotate(-1deg); } }
@keyframes boing {
  0% { transform: scale(1, 1); } 20% { transform: scale(1.12, .86); } 40% { transform: scale(.9, 1.14) translateY(-10%); }
  60% { transform: scale(1.05, .95); } 80% { transform: scale(.98, 1.02); } 100% { transform: scale(1, 1); }
}
@keyframes wiggle { 20% { transform: rotate(-9deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }

@media (max-height: 600px) {
  :root { --tray-h: 112px; }
  .thumb { width: 88px; height: 88px; } .thumb img { max-height: 60px; } .thumb span { display: none; }
  .round { width: 50px; height: 50px; font-size: 24px; }
  .tab { font-size: 16px; padding: 6px 10px; }
}
@media (orientation: portrait) {
  .stage-wrap::before {
    content: "↻ Turn me sideways!"; position: absolute; top: 90px; left: 0; right: 0; text-align: center;
    color: #fff; font-size: 26px; text-shadow: 0 2px 4px rgba(0,0,0,.5); z-index: 5;
  }
}
.title { display: flex; align-items: center; gap: 16px; }
.title img { width: clamp(64px, 10vw, 110px); height: auto; filter: drop-shadow(0 6px 8px rgba(0,0,0,.2)); }
