@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ink: #5a3a6e;
  --pink: #ff6fae;
  --purple: #a66cff;
  --soft: #f6ecff;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #ffe9f5;
  color: var(--ink);
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font-family: inherit; color: inherit; cursor: pointer; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Home ---------- */
#home {
  align-items: center;
  overflow-y: auto;
  background:
    radial-gradient(circle at 10% 15%, #fff 0 3px, transparent 4px) 0 0 / 120px 120px,
    radial-gradient(circle at 60% 70%, #fff8 0 2px, transparent 3px) 0 0 / 90px 90px,
    linear-gradient(160deg, #ffd6ec, #e7d4ff 60%, #d4e8ff);
}
#title {
  margin: 24px 16px 0;
  font-size: clamp(38px, 7vw, 76px);
  font-weight: 700;
  text-align: center;
  line-height: 1.05;
  letter-spacing: 1px;
}
#title span {
  display: inline-block;
  -webkit-text-stroke: 2px #fff;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #fff, 0 6px 10px #a66cff55;
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes wiggle { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
.sub { font-size: clamp(24px, 3.5vw, 36px); font-weight: 600; margin: 6px 0 14px; }
#rooms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  width: min(940px, 100% - 32px);
  padding-bottom: 32px;
}
.room-card {
  border: none;
  background: #fff;
  border-radius: 26px;
  padding: 10px 10px 4px;
  box-shadow: 0 6px 0 #e2c4f2, 0 10px 24px #a66cff33;
  transition: transform .15s;
}
.room-card:active { transform: scale(.96); }
.prev { position: relative; aspect-ratio: 16 / 10; border-radius: 18px; overflow: hidden; }
.label { font-size: clamp(22px, 3vw, 30px); font-weight: 600; padding: 6px 0; }

/* ---------- Scene (shared by stage and previews) ---------- */
.scene { position: absolute; left: 0; top: 0; width: 1000px; height: 625px; transform-origin: 0 0; overflow: hidden; }
.scene .bgfill, #bg { position: absolute; inset: 0; }
.scene .bgfill svg, #bg svg { display: block; }

.stk { position: absolute; pointer-events: none; }
.stk .in { width: 100%; height: 100%; transition: transform .15s; }
.stk svg { width: 100%; height: 100%; display: block; overflow: visible; pointer-events: none; }
#layer .stk svg g * { pointer-events: visiblePainted; }
.stk.lift .in { transform: scale(1.07); }
.stk.pop .in { animation: peel .5s cubic-bezier(.3, 1.6, .5, 1); }
.stk.bye .in { animation: bye .3s forwards; }
@keyframes peel { 0% { transform: scale(1.4) rotate(-12deg); opacity: 0 } 40% { opacity: 1 } 100% { transform: none } }
@keyframes bye { to { transform: scale(0) rotate(40deg); opacity: 0 } }

/* ---------- Play screen ---------- */
#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #ffffffb0;
}
#roomName { flex: 1; text-align: center; font-size: 26px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 22px;
  font-weight: 600;
  background: #fff;
  box-shadow: 0 4px 0 #e2c4f2;
  white-space: nowrap;
}
.pill:active { transform: translateY(3px); box-shadow: 0 1px 0 #e2c4f2; }
.pill.round { padding: 8px 12px; }
.pill.tada { background: #ffe066; box-shadow: 0 4px 0 #e9b500; }
.pill.pink { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #d94b8c; }
.pill.big { font-size: 32px; padding: 12px 38px; }

#wrap { flex: 1; position: relative; overflow: hidden; min-height: 0; }
#stage {
  position: absolute; left: 0; top: 0; width: 1000px; height: 625px;
  transform-origin: 0 0;
  touch-action: none;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 8px 30px #a66cff44;
}
#selbox {
  position: absolute;
  display: none;
  border: 4px dashed var(--purple);
  border-radius: 18px;
  pointer-events: none;
  --h: 56px;
}
.h {
  position: absolute;
  width: var(--h); height: var(--h);
  margin: calc(var(--h) / -2);
  border-radius: 50%;
  border: calc(var(--h) * .07) solid #fff;
  box-shadow: 0 3px 6px #0003;
  color: #fff;
  font-size: calc(var(--h) * .5);
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  pointer-events: auto;
}
.h-del { left: 0; top: 0; background: #ff5d8f; }
.h-flip { left: 100%; top: 0; background: #4dabf7; }
.h-rot { left: 100%; top: 100%; background: var(--purple); }

#fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.spark { position: absolute; font-size: 34px; animation: spark .7s ease-out forwards; }
@keyframes spark { from { transform: translate(-50%, -50%) scale(.4); opacity: 1 } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1) rotate(90deg); opacity: 0 } }
.confetti { position: absolute; top: -40px; font-size: 40px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(720px) rotate(var(--spin)); } }

#hint {
  position: absolute; bottom: 10px; left: 50%;
  background: #fff;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 28px; font-weight: 600;
  box-shadow: 0 4px 0 #e2c4f2;
  pointer-events: none;
  animation: bob 1.2s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translate(-50%, 0) } 50% { transform: translate(-50%, -8px) } }
#cheer {
  position: absolute; left: 50%; top: 40%;
  font-size: clamp(48px, 9vw, 96px); font-weight: 700;
  color: var(--pink);
  -webkit-text-stroke: 3px #fff; paint-order: stroke fill;
  text-shadow: 0 6px 0 #fff, 0 8px 20px #a66cff66;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
#cheer.show { animation: cheer 1.8s ease-out forwards; }
@keyframes cheer {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) }
  30% { transform: translate(-50%, -50%) scale(1) }
  80% { opacity: 1 }
  100% { opacity: 0; transform: translate(-50%, -60%) }
}

/* ---------- Sticker tray ---------- */
#tray {
  background: #fff;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -6px 20px #a66cff22;
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs, #sheet { display: flex; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar, #sheet::-webkit-scrollbar { display: none; }
#tabs { gap: 8px; padding: 10px 12px 0; }
.tab {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 4px 16px 4px 6px;
  font-size: 21px; font-weight: 600;
  background: var(--soft);
}
.tab svg { width: 38px; height: 38px; overflow: visible; }
.tab.on { background: var(--purple); color: #fff; }
#sheet { gap: 10px; padding: 10px 12px 14px; touch-action: pan-x; }
.item {
  flex: 0 0 auto;
  width: 100px; height: 100px;
  border-radius: 22px;
  background: #fff6fb;
  border: 3px solid #f3dcff;
  display: grid; place-items: center;
  transition: transform .1s;
}
.item svg { width: 80px; height: 80px; overflow: visible; pointer-events: none; }
.item.press { transform: scale(.92); background: #ffe3f3; }
.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; }
.ghost svg { width: 100%; height: 100%; overflow: visible; transform: rotate(-6deg) scale(1.08); }

/* ---------- Modal ---------- */
#modal { position: fixed; inset: 0; background: #5a3a6e66; display: grid; place-items: center; z-index: 60; }
#modal .box { background: #fff; border-radius: 30px; padding: 26px 36px; text-align: center; box-shadow: 0 10px 40px #0003; }
#modal p { font-size: 36px; font-weight: 600; margin: 0 0 22px; }
#modal .row { display: flex; gap: 20px; justify-content: center; }

/* Small screens (Fire 7, phones) */
@media (max-height: 640px) {
  #bar { padding: 5px 10px; gap: 8px; }
  .pill { font-size: 18px; padding: 6px 14px; }
  #roomName { font-size: 20px; }
  .tab { font-size: 17px; }
  .tab svg { width: 30px; height: 30px; }
  .item { width: 78px; height: 78px; border-radius: 18px; }
  .item svg { width: 62px; height: 62px; }
  #sheet { padding: 8px 10px 10px; }
  #hint { font-size: 22px; }
}
@media (max-width: 700px) {
  #roomName { display: none; }
}
