:root {
  --bg1: #2a2847;
  --bg2: #121120;
  --ink: #f4ecd8;
  --gold: #f1b94a;
  --hud-h: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* Stop iOS rubber-band scrolling and the long-press callout while rubbing. */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg2) url(img/deck.webp) center 70% / cover no-repeat;
  /* Every gesture belongs to the app; the browser gets none. */
  touch-action: none;
}

/* --- HUD --------------------------------------------------------------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(var(--hud-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
  pointer-events: none;
}
.hud h1 {
  margin: 0;
  font-size: clamp(20px, 4vw, 34px);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 2px 0 #000a;
}
.counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 110px;
  padding: 6px 14px;
  border-radius: 14px;
  background: #0007;
  border: 2px solid #f1b94a55;
}
.counter .label { font-size: 13px; opacity: 0.8; }
.counter .value { font-size: 28px; font-weight: bold; color: var(--gold); }
.counter.bump { animation: bump 0.45s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.3); border-color: var(--gold); }
  100% { transform: scale(1); }
}

/* --- Garland ------------------------------------------------------------ */
.scene {
  position: absolute;
  top: calc(var(--hud-h) + env(safe-area-inset-top));
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  /* Feet a little above the bottom edge so he stands on the deck planks. */
  padding-bottom: 2vh;
}
.stage {
  position: relative;
  /* Full height always; his width follows the picture's shape. */
  height: 100%;
  aspect-ratio: 751 / 1400;
  flex-shrink: 0; /* never squeezed narrower than the picture */
  transform-origin: 50% 100%;
}
/* Weight gain: app.js sets --girth from the turkey-leg count. Scaling from
   the feet keeps him standing on the same spot; the springy curve makes each
   gain a visible "poof" right after he swallows. */
.body {
  position: absolute;
  inset: 0;
  /* Wider only; his height never changes. */
  transform: scaleX(var(--girth, 1));
  transform-origin: 50% 100%;
  transition: transform 0.9s cubic-bezier(.3,1.7,.5,1);
}
.frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  visibility: hidden;
  pointer-events: none;
}
.frame.show { visibility: visible; }

/* Squash-and-stretch while giggling. Origin at the feet so he bounces. */
.stage.jiggle { animation: jiggle 0.5s ease-in-out infinite; }
@keyframes jiggle {
  0%, 100% { transform: scale(1, 1); }
  25% { transform: scale(1.025, 0.975); }
  50% { transform: scale(0.985, 1.015) rotate(-0.6deg); }
  75% { transform: scale(1.02, 0.98) rotate(0.6deg); }
}
.stage.nom { animation: nom 0.28s ease-in-out; }
@keyframes nom {
  50% { transform: scale(1.01, 0.99) translateY(0.5%); }
}

/* Captain lobster (sprites from build_assets.py). His box is 442,113 to
   735,372 in the 751 x 1400 picture. As Garland widens about his centre the
   lobster's box slides outward with the shoulder, unstretched:
   shift = (girth - 1) * (box centre 588.5/751 - 0.5) of the stage width,
   written here in units of the box's own width. */
.lobster {
  position: absolute;
  left: calc(442 / 751 * 100%);
  top: calc(113 / 1400 * 100%);
  width: calc(293 / 751 * 100%);
  height: calc(259 / 1400 * 100%);
  pointer-events: none;
  transform: translateX(calc((var(--girth, 1) - 1) * (588.5 / 751 - 0.5) / (293 / 751) * 100%));
  transition: transform 0.9s cubic-bezier(.3,1.7,.5,1);
}
.lobster img { position: absolute; inset: 0; width: 100%; height: 100%; }
/* The head turns about his neck (585,255 in the picture). */
.lobster-head { transform-origin: calc(143 / 293 * 100%) calc(142 / 259 * 100%); }
.lobster-head.no { animation: shakeNo 0.9s ease-in-out; }
@keyframes shakeNo {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-6deg); }
  35% { transform: rotate(6deg); }
  55% { transform: rotate(-5deg); }
  75% { transform: rotate(4deg); }
}

/* Speech bubble; app.js places its tail at the lobster's mouth. */
.bubble {
  position: absolute;
  z-index: 6;
  max-width: min(260px, 60vw);
  padding: 10px 14px;
  border-radius: 18px;
  background: #fffaf0;
  color: #2a1d10;
  font-size: clamp(15px, 2.4vw, 20px);
  font-weight: bold;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 4px 12px #0007;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%) scale(0.6);
  transform-origin: var(--tail, 50%) 100%;
  transition: opacity 0.2s, transform 0.25s cubic-bezier(.3,1.6,.5,1);
}
.bubble::after {
  content: "";
  position: absolute;
  left: var(--tail, 50%);
  bottom: -12px;
  margin-left: -10px;
  border: 10px solid transparent;
  border-top: 12px solid #fffaf0;
  border-bottom: 0;
}
.bubble.show { opacity: 1; transform: translate(-50%, -100%) scale(1); }

/* Visible only while debugging hitboxes (?debug in the URL). */
.belly-zone { position: absolute; border-radius: 50%; pointer-events: none; }
.debug .belly-zone { outline: 2px dashed #0f0; }
.debug .mouth-dot { position: absolute; width: 10px; height: 10px; margin: -5px; border-radius: 50%; background: #f0f; z-index: 9; pointer-events: none; }

/* --- Plate and turkey leg ---------------------------------------------- */
.table {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 10px 10px #0008);
}
.leg {
  position: absolute;
  left: 0; top: 0;
  width: var(--leg-w, 180px);
  z-index: 3;
  cursor: grab;
  /* The sprite's meat end points left; mirror it so it points at his mouth. */
  transform: translate(var(--x, 0px), var(--y, 0px)) scaleX(-1);
  filter: drop-shadow(0 6px 6px #0007);
  transition: clip-path 0.12s ease-out;
  touch-action: none;
}
.leg.dragging {
  cursor: grabbing;
  z-index: 6;
  filter: drop-shadow(0 14px 12px #0009);
}
.leg.fly { transition: transform 0.35s cubic-bezier(.3,1.4,.5,1), clip-path 0.12s ease-out; }
.leg.spawn { animation: spawn 0.4s cubic-bezier(.3,1.6,.5,1); }
@keyframes spawn {
  from { opacity: 0; scale: 0.3; }
  to { opacity: 1; scale: 1; }
}
.leg.gone { opacity: 0; transition: opacity 0.25s; pointer-events: none; }
.leg.eating { pointer-events: none; z-index: 4; }

/* --- Effects ------------------------------------------------------------ */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 7; overflow: hidden; }
.float-text {
  position: absolute;
  font-size: clamp(22px, 4vw, 36px);
  font-weight: bold;
  color: #ffe9a8;
  text-shadow: 0 2px 0 #7a3b00, 0 0 12px #000;
  white-space: nowrap;
  animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp {
  from { opacity: 0; transform: translate(-50%, 0) scale(0.6) rotate(var(--r, 0deg)); }
  15% { opacity: 1; transform: translate(-50%, -20px) scale(1.1) rotate(var(--r, 0deg)); }
  to { opacity: 0; transform: translate(-50%, -110px) scale(1) rotate(var(--r, 0deg)); }
}
.crumb {
  position: absolute;
  width: 8px; height: 8px;
  margin: -4px;
  border-radius: 40% 60% 50% 50%;
  background: #b5651d;
  animation: crumb 0.7s cubic-bezier(.2,.6,.6,1) forwards;
}
@keyframes crumb {
  to { transform: translate(var(--dx), var(--dy)) rotate(200deg); opacity: 0; }
}
.flyer {
  position: absolute;
  width: 56px;
  margin: -20px -28px;
  transform: scaleX(-1);
  transition: left 0.6s cubic-bezier(.5,-0.3,.6,1), top 0.6s cubic-bezier(.3,.2,.6,1), opacity 0.6s;
}

/* --- Footer bits -------------------------------------------------------- */
.hint {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: #0008;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s;
  z-index: 5;
}
.hint.hidden { opacity: 0; }
.reset {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 5;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #0006;
  border: 1px solid #fff3;
  border-radius: 999px;
  padding: 6px 12px;
  opacity: 0.6;
}
.reset.armed { opacity: 1; background: #a3332b; }

@media (max-width: 600px) {
  :root { --hud-h: 64px; }
  .counter { min-width: 86px; padding: 4px 8px; }
  .counter .value { font-size: 22px; }
  .hud h1 { display: none; }
  .hint { font-size: 12px; bottom: auto; top: calc(var(--hud-h) + env(safe-area-inset-top) + 4px); }
}
