:root {
  --ink: #1d2333;
  --pink: #f37aa4;
  --pink-soft: #fde4ee;
  --lilac: #8f9cf5;
  --card: #fffafc;
  --gold: #f6b72d;
  --panel: #fff4f8;
  --bg: #f7d6e6;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; overscroll-behavior: none; }
body { font: 700 14px/1.1 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif; color: var(--ink); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
img { -webkit-user-drag: none; pointer-events: none; }

#app { display: flex; flex-direction: column; height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#stage { position: relative; flex: 1 1 55%; min-height: 0; overflow: hidden; }
#scene { display: block; width: 100%; height: 100%; }
#doll { cursor: pointer; }
#doll .fx, #doll .breathe { transform-box: fill-box; transform-origin: 50% 100%; }
#doll .breathe { animation: breathe 2.6s ease-in-out infinite; }
#doll .fx.hop { animation: hop .45s cubic-bezier(.3,1.6,.5,1); }
#doll .fx.twirl { animation: twirl .7s ease-in-out; transform-origin: 50% 50%; }
@keyframes breathe { 50% { transform: scale(1.012, .992) translateY(-1px); } }
@keyframes hop { 35% { transform: translateY(-9px); } }
@keyframes twirl { 0% { transform: scaleX(1); } 25% { transform: scaleX(.05); } 50% { transform: scaleX(-1); } 75% { transform: scaleX(.05); } 100% { transform: scaleX(1); } }

#ambient { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#ambient img { position: absolute; opacity: 0; }
#ambient .up { bottom: -40px; animation: floatUp linear forwards; }
#ambient .down { top: -40px; animation: fallDown linear forwards; }
#ambient .twinkle { filter: drop-shadow(0 0 6px #ffe9a8); }
@keyframes floatUp { 10% { opacity: .85; } 50% { transform: translate(var(--sx), -45vh) rotate(20deg); } 90% { opacity: .7; } 100% { transform: translate(0, -95vh) rotate(-10deg); opacity: 0; } }
@keyframes fallDown { 10% { opacity: .9; } 50% { transform: translate(var(--sx), 45vh) rotate(120deg); } 90% { opacity: .8; } 100% { transform: translate(0, 95vh) rotate(260deg); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #doll .breathe { animation: none; } }

#topbar { position: absolute; top: 10px; right: 10px; left: 10px; display: flex; gap: 10px; justify-content: flex-end; align-items: flex-start; pointer-events: none; }
.round { pointer-events: auto; width: 56px; height: 56px; border-radius: 50%; background: var(--card); border: 4px solid var(--ink); display: grid; place-items: center; box-shadow: 0 4px 0 rgba(29,35,51,.25); transition: transform .1s; }
.round img { width: 38px; height: 38px; }
.round.big { width: 76px; height: 76px; background: #fff3c4; }
.round.big img { width: 54px; height: 54px; }
.round:active { transform: scale(.9); }
.round.off img { opacity: .35; }
#btn-night.lit { background: #2a1f5c; }
.dot.rainbow { background: conic-gradient(#ff6b8a, #ffb84d, #ffe95c, #6be08f, #5cc8ff, #9d7bff, #ff6b8a) !important; }
#btn-sound { margin-right: auto; }

#sparkles { position: absolute; inset: 0; pointer-events: none; }
#sparkles img { position: absolute; width: 44px; height: 44px; animation: burst 1s ease-out forwards; opacity: 0; }
@keyframes burst { 0% { transform: translate(0,0) scale(.2) rotate(0); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(200deg); opacity: 0; } }

#panel { flex: 1 1 45%; min-height: 0; display: flex; flex-direction: column; background: var(--panel); border-top: 4px solid var(--ink); border-radius: 26px 26px 0 0; margin-top: -22px; position: relative; z-index: 1; }
#tabs { display: flex; gap: 6px; padding: 10px 10px 6px; overflow-x: auto; scrollbar-width: none; flex: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 64px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 5px; border-radius: 16px; border: 3px solid var(--ink); background: #fff; font-size: 12px; }
.tab img { width: 34px; height: 34px; }
.tab.on { background: var(--pink); color: #fff; }

#colours { display: flex; gap: 10px; padding: 4px 14px 6px; flex-wrap: wrap; align-items: center; min-height: 6px; flex: none; }
#colours:empty { padding: 0; }
.dot { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); }
.dot.on { box-shadow: 0 0 0 3px #fff, 0 0 0 7px var(--gold); }
.sep { width: 10px; }

#grid { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 12px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; align-content: start; }
.card { aspect-ratio: 1; border-radius: 50%; background: var(--card); border: 4px solid var(--ink); display: grid; place-items: center; overflow: hidden; transition: transform .1s; }
.card svg { width: 84%; height: 84%; pointer-events: none; }
.card.on { background: #fff6d6; box-shadow: 0 0 0 4px #fff, 0 0 0 8px var(--gold); }
.card:active { transform: scale(.92); }

#grid.rooms { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
#grid.rooms .card { aspect-ratio: 4/3; border-radius: 22px; }
.roomthumb { width: 100%; height: 100%; background-size: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.roomthumb img { height: 62%; }
.roomthumb b { background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 3px 8px; font-size: 13px; }

@media (max-width: 560px) and (orientation: portrait) {
  .tab { flex: 1 0 44px; padding: 6px 2px; }
  .tab span { display: none; }
}
/* landscape tablets / phones: wardrobe on the right */
@media (orientation: landscape) and (min-width: 700px), (orientation: landscape) and (max-height: 500px) {
  #app { flex-direction: row; }
  #stage { flex: 1 1 60%; }
  #panel { flex: 0 0 min(44%, 440px); border-top: 0; border-left: 4px solid var(--ink); border-radius: 26px 0 0 26px; margin: 0 0 0 -22px; }
  #tabs { flex-wrap: wrap; }
  .tab { flex: 1 0 22%; }
  #topbar { right: 32px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .tab span { display: none; }
  .tab img { width: 28px; height: 28px; }
  #grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}
