:root {
  --merah: #d64545;
  --merah-deep: #b83a3a;
  --gold: #f2b545;
  --gold-deep: #d99a2f;
  --ink: #3a2a18;
  --cream: #fff7ea;
  --paper: #fbf4e6;
  --panel: rgba(255, 250, 240, 0.96);
  --shadow: 0 10px 30px rgba(90, 50, 20, 0.20);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  color: var(--ink);
  background: linear-gradient(180deg, #5f6bab 0%, #e98e6e 44%, #ffd6a6 100%);
  user-select: none; touch-action: none;
}
.hidden { display: none !important; }

/* top bar */
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, #d64545, #c23c3c);
  box-shadow: 0 3px 16px rgba(120, 30, 30, 0.32);
}
.brand { color: #fff; font-weight: 900; font-size: 18px; letter-spacing: 0.01em; text-shadow: 0 1px 0 rgba(0,0,0,0.18); }
.brand span { color: var(--gold); }
button { font-family: inherit; cursor: pointer; border: none; }
.primary { background: var(--gold); color: #5a3a0a; font-weight: 800; font-size: 14px; padding: 9px 16px; border-radius: 999px; box-shadow: 0 3px 0 #c98f1e; }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #c98f1e; }
.wa { background: #25d366; color: #04341a; box-shadow: 0 3px 0 #169a4a; }

/* stage */
#stage {
  position: fixed; top: calc(54px + env(safe-area-inset-top)); left: 0; right: 0;
  bottom: 100px; display: grid; place-items: center; overflow: hidden; padding: 6px;
}
#scene {
  position: relative; aspect-ratio: 464 / 832; height: min(82vh, 780px); width: auto; max-width: 96vw;
  border-radius: 22px; overflow: hidden; border: 5px solid #fbf4e6;
  box-shadow: 0 18px 44px rgba(60, 30, 12, 0.42), 0 2px 0 rgba(255,255,255,0.5) inset;
}
#backdrop { position: absolute; inset: 0; z-index: 0; }
.scene-img { width: 100%; height: 100%; object-fit: cover; display: block; }
#skyfx { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
#grid { position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: 0.14; transition: opacity 0.22s; }
#grid svg { width: 100%; height: 100%; display: block; }
#grid line { stroke: #fffaf0; stroke-width: 1.4; vector-effect: non-scaling-stroke; opacity: 0.6; }
#bloc-hot { fill: #f2b545; opacity: 0; transition: x 0.08s linear, y 0.08s linear; }
#scene.snapping #grid { opacity: 0.85; }
#scene.snapping #bloc-hot { opacity: 0.42; }
#items { position: absolute; inset: 0; z-index: 2; }
.deco { position: absolute; width: 104px; transform-origin: center; touch-action: none; }
.deco img { width: 100%; height: auto; display: block; pointer-events: none; filter: drop-shadow(0 5px 6px rgba(40,24,10,0.4)); }
.deco.sel { outline: 2.5px dashed var(--gold); outline-offset: 3px; border-radius: 10px; }
.deco.lift { z-index: 6; }
.deco.lift img { filter: drop-shadow(0 14px 14px rgba(40,24,10,0.5)) !important; }

/* ambient decoration motion (inner img — independent of the drag transform) */
.deco.sway img { transform-origin: 50% 100%; animation: sway 3.8s ease-in-out infinite; }
.deco.bob img  { animation: bob 2.8s ease-in-out infinite; }
.deco.spin img { animation: spin 5s linear infinite; }
.deco.glow img { animation: glow 2.4s ease-in-out infinite; }
.deco.flicker img { animation: flicker 1.5s ease-in-out infinite; }
@keyframes sway { 0%,100% { transform: rotate(-2.6deg); } 50% { transform: rotate(2.6deg); } }
@keyframes bob  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glow {
  0%,100% { filter: drop-shadow(0 5px 6px rgba(40,24,10,0.4)) drop-shadow(0 0 3px rgba(255,190,90,0.4)); }
  50%     { filter: drop-shadow(0 5px 6px rgba(40,24,10,0.4)) drop-shadow(0 0 13px rgba(255,205,110,0.95)); }
}
@keyframes flicker {
  0%,100% { filter: drop-shadow(0 5px 6px rgba(40,24,10,0.4)) drop-shadow(0 0 6px rgba(244,140,30,0.8)); }
  45%     { filter: drop-shadow(0 4px 5px rgba(40,24,10,0.4)) drop-shadow(0 0 16px rgba(255,170,60,1)); }
  60%     { filter: drop-shadow(0 5px 6px rgba(40,24,10,0.4)) drop-shadow(0 0 9px rgba(244,140,30,0.7)); }
}

/* fireflies */
.ff { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #ffe79a; box-shadow: 0 0 8px 2px rgba(255,225,150,0.85); opacity: 0; animation: fly 5s ease-in-out infinite; }
@keyframes fly { 0%,100% { opacity: 0; transform: translate(0,0); } 30% { opacity: 0.9; } 50% { opacity: 0.55; transform: translate(11px,-13px); } 72% { opacity: 0.85; transform: translate(-6px,-6px); } }

#hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(42,28,16,0.82); color: #fff; font-size: 12.5px; font-weight: 600;
  padding: 7px 15px; border-radius: 999px; white-space: nowrap; z-index: 4;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.72} 50%{opacity:1} }

/* item toolbar */
#item-tools { position: fixed; z-index: 20; display: flex; gap: 4px; padding: 5px; background: var(--panel); border-radius: 999px; box-shadow: var(--shadow); transform: translate(-50%, -50%); }
#item-tools button { background: #f1ece3; border-radius: 50%; width: 38px; height: 38px; font-size: 17px; }
#item-tools button:active { background: #e2d8c8; }

/* tray */
#tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(108px + env(safe-area-inset-bottom)); padding: 8px 8px env(safe-area-inset-bottom);
  display: flex; gap: 8px; overflow-x: auto; align-items: center;
  background: var(--panel); box-shadow: 0 -4px 20px rgba(90,50,20,0.16); scrollbar-width: none;
}
#tray::-webkit-scrollbar { display: none; }
.tray-item {
  flex: 0 0 auto; width: 84px; height: 90px; border-radius: 16px;
  background: linear-gradient(180deg, #fffaf0, #fdf2dd);
  box-shadow: 0 3px 9px rgba(90,50,20,0.14), 0 1px 0 #fff inset;
  display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 6px; border: 2px solid transparent;
}
.tray-item:active { transform: scale(0.95); border-color: var(--gold); }
.tray-item img { width: 100%; height: 48px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(40,24,10,0.25)); }
.tray-item span { font-size: 10.5px; font-weight: 800; color: #7a6447; margin-top: 2px; }

/* share sheet */
#sheet { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(50, 26, 12, 0.6); backdrop-filter: blur(3px); }
.sheet-card { width: 100%; max-width: 420px; background: #fff; border-radius: 22px; padding: 18px; box-shadow: 0 22px 64px rgba(60,20,20,0.45); text-align: center; max-height: 92vh; overflow-y: auto; }
.sheet-title { font-weight: 900; font-size: 19px; color: var(--merah-deep); margin-bottom: 12px; }
#name { width: 100%; border: 2px solid #eee; border-radius: 12px; padding: 11px 14px; font-size: 15px; outline: none; margin-bottom: 12px; }
#name:focus { border-color: var(--gold); }
#preview { width: 100%; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,0.18); display: block; min-height: 60px; background: #fbf4e6; }
.sheet-row { display: flex; gap: 10px; margin-top: 14px; }
.sheet-row .primary { flex: 1; padding: 13px; font-size: 15px; }
.ghost { background: none; color: #8a7a64; font-weight: 700; font-size: 14px; margin-top: 10px; padding: 8px; width: 100%; }

/* bar controls */
.bar-right { display: flex; gap: 8px; align-items: center; }
.round { background: rgba(255,255,255,0.22); color: #fff; width: 38px; height: 38px; border-radius: 50%; font-size: 17px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28); }
.round:active { transform: scale(0.92); }

/* place bounce */
.deco.pop { animation: pop 0.34s cubic-bezier(.34,1.56,.64,1); }
@keyframes pop { 0% { transform: translate(-50%,-50%) scale(0.2); } }

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -24px; width: 10px; height: 14px; border-radius: 2px; animation: drop 2.3s ease-in forwards; }
@keyframes drop { to { transform: translateY(114vh) rotate(560deg); opacity: 0.6; } }

/* shared-link view */
#view { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: radial-gradient(circle at 50% 0%, #ffe3a8, #ffcaa0 60%, #e98e6e 100%); }
.view-card { width: 100%; max-width: 420px; text-align: center; }
.view-title { font-weight: 900; font-size: 20px; color: var(--merah-deep); margin-bottom: 12px; }
#view-img { width: 100%; border-radius: 16px; box-shadow: 0 16px 48px rgba(120,40,20,0.4); display: block; }
.big { width: 100%; margin-top: 18px; padding: 16px; font-size: 17px; }
