html, body {
  margin: 0; width: 100%; height: 100dvh; overflow: hidden;
  background: #1a1420; color: #fff;
  font-family: 'VT323', monospace;
}
body { display: flex; align-items: center; justify-content: center; }
#wrap { position: relative; width: 100vw; height: 100dvh; --s: 3; }
#game { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }

#overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bubble, .prompt {
  position: absolute; transform: translate(-50%, -100%);
  color: #2b1d14; background: #fffaf0;
  border: 2px solid #2b1d14; border-radius: 6px;
  padding: 2px 7px;
  font-size: clamp(16px, calc(var(--s) * 5px), 24px); line-height: 1.05;
  width: max-content; max-width: min(70vw, 280px); text-align: center;
}
.bubble b { display: block; font-size: .82em; color: #b0562b; }
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid #2b1d14;
}
.prompt { background: #ffd84d; font-size: clamp(15px, calc(var(--s) * 4.5px), 22px); }

#hud {
  position: absolute;
  left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top));
  background: rgba(20, 14, 28, .78); border-radius: 8px;
  padding: 6px 10px;
  font-size: clamp(16px, calc(var(--s) * 5.2px), 24px); min-width: clamp(150px, 24vw, 210px);
}
#hud .row { display: flex; justify-content: space-between; gap: 12px; }
.bar { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.bar span { font-size: .85em; }
.track { flex: 1; height: clamp(8px, calc(var(--s) * 2.8px), 12px); background: #3a2d40; border-radius: 99px; overflow: hidden; }
.fill { height: 100%; width: 50%; transition: width .2s; }
.hunger { background: #f39c3d; } .energy { background: #4fc3f7; } .trust { background: #ff6f9c; }
.low { animation: blink .6s infinite; }
@keyframes blink { 50% { opacity: .3; } }
#item { margin-top: 4px; font-size: .9em; color: #ffd84d; }

#objective {
  position: absolute;
  right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top));
  max-width: min(44vw, 340px);
  background: rgba(20, 14, 28, .78); border-radius: 8px;
  padding: 6px 10px;
  font-size: clamp(15px, calc(var(--s) * 4.6px), 22px); line-height: 1.1;
}
#toast {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; transition: all .3s;
  background: rgba(20, 14, 28, .9); border: 2px solid #ffb347;
  border-radius: 8px; padding: 6px 14px;
  font-size: clamp(16px, calc(var(--s) * 4.8px), 23px); max-width: min(86vw, 520px); text-align: center; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 16px;
  background: rgba(20, 12, 30, .86); font-size: clamp(17px, calc(var(--s) * 5px), 24px);
}
.screen h1 { margin: 0; font-size: clamp(42px, 10vmin, 76px); color: #ffb347; text-shadow: 3px 3px 0 #8a3f12; line-height: 1; }
.screen h2 { margin: 0 0 8px; font-size: clamp(22px, 4.8vmin, 34px); color: #ffe0b0; font-weight: normal; }
.story { max-width: min(88vw, 540px); margin: 8px 0; color: #eadcf0; line-height: 1.2; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; margin: 8px 0 16px; text-align: left; }
kbd { background: #3a2d40; border: 1px solid #6b5a75; border-radius: 4px; padding: 0 5px; color: #ffd84d; }
button {
  font-family: inherit; font-size: clamp(20px, 5vmin, 30px); cursor: pointer;
  background: #ffb347; color: #2b1d14; border: none; border-radius: 8px;
  padding: 6px 20px; box-shadow: 0 3px 0 #8a3f12;
}
button:hover { background: #ffc66e; }
.small { font-size: .82em; color: #a799b3; margin: 6px 0; }
.btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.bar .nm { font-size: .78em; width: 52px; color: #ffb3c8; white-space: nowrap; }
#status { font-size: .85em; color: #9fd4ff; margin-top: 2px; }
#status:empty, #item:empty { display: none; }
#objective { white-space: pre-line; }

body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch #toast { bottom: auto; top: max(10px, env(safe-area-inset-top)); z-index: 12; }
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#stick {
  position: absolute;
  left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(96px, 24vmin, 136px); height: clamp(96px, 24vmin, 136px); border-radius: 50%;
  background: rgba(255, 255, 255, .12); border: 2px solid rgba(255, 255, 255, .3);
  pointer-events: auto; touch-action: none;
}
#knob {
  position: absolute; left: 50%; top: 50%;
  width: 44%; height: 44%; margin: -22%;
  border-radius: 50%; background: rgba(255, 179, 71, .75); pointer-events: none;
}
#tbtns {
  position: absolute;
  right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  pointer-events: auto;
  display: grid; grid-template-columns: auto auto; gap: 10px; align-items: end; justify-items: center;
}
#fsBtn { grid-column: 1 / -1; justify-self: end; }
.tb {
  width: clamp(42px, 11vmin, 56px); height: clamp(42px, 11vmin, 56px);
  border-radius: 50%; padding: 0; font-size: clamp(18px, 4.5vmin, 24px);
  touch-action: none; opacity: .72;
}
.tb.big {
  width: clamp(58px, 15vmin, 76px); height: clamp(58px, 15vmin, 76px);
  font-size: clamp(24px, 6vmin, 32px);
}
.tb.on { background: #fff0c8; transform: scale(.94); opacity: 1; }
