:root {
  --bg: #1b1524;
  --panel: #2a2236;
  --text: #f4eef8;
  --accent: #ff7a59;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html, body {
  margin: 0;
  height: var(--tg-viewport-stable-height, 100dvh);
  min-height: 100%;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app {
  height: var(--tg-viewport-stable-height, 100dvh);
  display: flex;
  flex-direction: column;
}

.hud {
  display: flex;
  justify-content: space-around;
  padding: 10px 8px 6px;
  font-size: 13px;
  opacity: .9;
}
.hud span { font-weight: 800; }

.stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 180px;
  z-index: 1;
  overflow: hidden;
}

.room {
  position: absolute;
  inset: 0;
  background: #5a3f72 url("sprites/room.png?v=10") center / cover no-repeat;
  overflow: hidden;
}

.girl, .guy {
  position: absolute;
  bottom: 4%;
  height: 82%;
  overflow: visible;
}

.girl {
  left: 10%;
  width: 40%;
  z-index: 2;
}

.guy {
  left: 48%;
  width: 40%;
  z-index: 3;
}

.sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  display: block;
  pointer-events: none;
  transform-origin: 50% 80%;
}
.sprite { image-rendering: auto; }
.girl.idle .sprite, .guy.idle .sprite { animation: none; }
.girl.talk .sprite { animation: talk 0.35s ease-in-out infinite; }
.guy.win .sprite { animation: cheer 0.45s ease-in-out infinite; }
.girl.swing .sprite { animation: panhit 0.4s ease-in 1; }
.guy.hurt .sprite { animation: bonk 0.45s ease-in 2; }

.dog {
  position: absolute;
  left: 41%;
  bottom: 20%;
  width: 18%;
  height: 34%;
  z-index: 1;
  pointer-events: none;
}
.dog .sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
}
.dog.fly {
  z-index: 7;
  width: 46%;
  height: 22%;
  left: 28%;
  bottom: 38%;
  animation: dogFly 1.2s ease-in forwards;
}
@keyframes dogFly {
  0%   { transform: translate(0, 20%); opacity: 1; }
  28%  { transform: translate(0, -70%); }
  100% { transform: translate(-240%, -80%); opacity: 0; }
}

.table {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 0;
  width: 88%;
  height: 28%;
  object-fit: contain;
  object-position: bottom;
  image-rendering: auto;
  z-index: 5;
  pointer-events: none;
}

.bubble {
  position: absolute;
  left: 8%;
  top: 4%;
  max-width: 92%;
  background: #fff;
  color: #222;
  padding: 8px 10px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.25;
  z-index: 6;
  box-shadow: 0 5px 0 #00000033;
}
.bubble::after {
  content: "";
  position: absolute;
  left: 22px;
  bottom: -10px;
  border: 8px solid transparent;
  border-top-color: #fff;
}

.yell {
  position: absolute;
  left: 50%;
  top: 2%;
  transform: translateX(-50%);
  background: #7ad67a;
  color: #142014;
  font-weight: 900;
  font-size: 22px;
  padding: 6px 12px;
  border-radius: 14px;
  z-index: 7;
  animation: pop .35s ease-out;
}
.yell[hidden] { display: none !important; }

.panel {
  position: relative;
  z-index: 50;
  flex: 0 0 auto;
  padding: 10px 14px calc(16px + var(--tg-safe-area-inset-bottom, 0px) + env(safe-area-inset-bottom, 0px));
  background: var(--tg-theme-secondary-bg-color, var(--panel));
  pointer-events: auto;
}

.meters {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.meter {
  background: #00000022;
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
}
.meter span { display: block; font-size: 11px; opacity: .7; }
.meter strong { font-size: 22px; }

.tap {
  width: 100%;
  height: 72px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: #1a1010;
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
}
.tap:disabled { opacity: .45; }
.tap:active:not(:disabled) { transform: scale(.98); }

body.tg .start { display: none; }

.start {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: #222;
  font-weight: 700;
  position: relative;
  z-index: 51;
  pointer-events: auto;
}

.hint {
  margin: 0 0 8px;
  font-size: 13px;
  opacity: .8;
  text-align: center;
}

.win-glow .room { box-shadow: inset 0 0 80px #7ad67a44; }

@keyframes breathe {
  0%,100% { transform: translateY(0) scale(1,1); }
  50% { transform: translateY(-2%) scale(1.01,0.99); }
}
@keyframes talk {
  0%,100% { transform: translateY(-8%) rotate(0); }
  50% { transform: translateY(-12%) rotate(-2deg); }
}
@keyframes cheer {
  0%,100% { transform: translateY(-8%) rotate(-3deg); }
  50% { transform: translateY(-18%) rotate(4deg); }
}
@keyframes panhit {
  0% { transform: translateY(-8%) rotate(0); }
  40% { transform: translateY(-8%) rotate(-18deg) translateX(8%); }
  70% { transform: translateY(-6%) rotate(12deg) translateX(-4%); }
  100% { transform: translateY(-8%) rotate(0); }
}
@keyframes bonk {
  0% { transform: translateY(-8%) rotate(0); }
  30% { transform: translateY(-4%) rotate(14deg) translateX(10%); }
  100% { transform: translateY(-8%) rotate(-4deg); }
}
@keyframes pop {
  from { transform: translateX(-50%) scale(.6); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}
