* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  background: #9ed8f5;
  color: #fff8ec;
  /* Stop the page panning and zooming under a thumb: every touch here walks. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
}

.hidden {
  display: none !important;
}

/* --- HUD --- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) clamp(12px, 3vw, 28px) 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-shadow: 0 2px 8px rgba(38, 26, 12, 0.5);
}

#top {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 16px);
}

#keys,
#biscuits,
#clock {
  font-size: clamp(1rem, 3.2vw, 1.5rem);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(52, 38, 20, 0.55);
  white-space: nowrap;
}

#clock {
  font-variant-numeric: tabular-nums;
}

#clock.low {
  background: rgba(196, 60, 40, 0.7);
  animation: pulse 700ms ease-in-out infinite;
}

#keys.pop,
#biscuits.pop {
  animation: pop 380ms ease-out;
}

/* The one line that tells you where to go next. */
#hint {
  font-size: clamp(0.95rem, 3vw, 1.25rem);
  font-weight: 800;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(52, 38, 20, 0.42);
  color: #ffe08a;
}

#message {
  margin-top: auto;
  /* Sit above the Search button so the two never cover each other. */
  margin-bottom: clamp(96px, 20vw, 130px);
  max-width: 22ch;
  text-align: center;
  font-size: clamp(1.1rem, 4.2vw, 1.8rem);
  font-weight: 900;
  padding: 8px 22px;
  border-radius: 16px;
  background: rgba(52, 38, 20, 0.55);
  opacity: 0;
  transition: opacity 160ms ease;
}

#message.show {
  opacity: 1;
}

/* --- The Search button: one big target, always in the same place --- */
#search {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 5;
  min-width: min(320px, 76vw);
  min-height: 68px;
  padding: 14px 28px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(140deg, #ffd23f, #ff9f1c);
  color: #3a2408;
  font: inherit;
  font-size: clamp(1.05rem, 3.4vw, 1.4rem);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(58, 36, 8, 0.35);
}

#search:disabled {
  cursor: default;
  background: rgba(52, 38, 20, 0.4);
  color: rgba(255, 248, 236, 0.75);
  box-shadow: none;
}

#search:active:not(:disabled) {
  transform: translateX(-50%) translateY(2px);
}

/* --- The walking stick: it appears wherever a thumb lands --- */
#joystick {
  position: fixed;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  border-radius: 50%;
  background: rgba(255, 248, 236, 0.18);
  border: 3px solid rgba(255, 248, 236, 0.45);
  pointer-events: none;
  z-index: 4;
}

#joyknob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 248, 236, 0.8);
}

/* --- Start and finish screen --- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  overflow-y: auto;
  background: radial-gradient(circle at 50% 30%, #3f6ea8, #1a2c46 76%);
  cursor: pointer;
}

#overlay h1 {
  margin: 0 0 8px;
  font-size: clamp(1.9rem, 8vw, 4.2rem);
  line-height: 1.05;
}

#overlay h1 span {
  color: #ffd166;
}

#overlay-text {
  margin: 0 0 18px;
  font-size: clamp(1.15rem, 3.8vw, 1.6rem);
  font-weight: 800;
  color: #ffd166;
}

#overlay-score {
  margin: 0 auto 18px;
  padding: 14px 24px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.14);
  font-size: clamp(1.05rem, 3.2vw, 1.3rem);
  font-weight: 800;
  line-height: 1.7;
  max-width: 36ch;
}

.hint-line {
  margin: 6px auto;
  max-width: 52ch;
  font-size: clamp(0.85rem, 2.5vw, 1.02rem);
  line-height: 1.5;
  color: #dfe8f4;
}

.hint-line b {
  color: #fff8ec;
}

#play {
  min-height: 64px;
  padding: 16px 46px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(140deg, #ffd23f, #ff9f1c);
  color: #3a2408;
  font: inherit;
  font-size: clamp(1.15rem, 3.6vw, 1.5rem);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(255, 159, 28, 0.35);
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  #keys.pop,
  #biscuits.pop,
  #clock.low {
    animation: none;
  }
}
