* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  background: #f2e3c6;
  color: #fff9ec;
  /* Stop the page panning/zooming under a thumb: every touch here is a hold. */
  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;
  gap: 10px;
  text-shadow: 0 2px 8px rgba(60, 36, 12, 0.45);
}

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

#stars,
#clock {
  font-size: clamp(1rem, 3.2vw, 1.5rem);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(74, 44, 16, 0.5);
  white-space: nowrap;
}

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

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

#stars.pop {
  animation: pop 380ms ease-out;
}

/* The jar fills up as the stars go in: the whole goal in one bar. */
#jar {
  flex: 1;
  min-width: 60px;
  height: 14px;
  border-radius: 999px;
  background: rgba(74, 44, 16, 0.5);
  box-shadow: inset 0 0 0 2px rgba(255, 236, 200, 0.4);
  overflow: hidden;
}

#jar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd23f, #ffa726);
  transition: width 200ms ease;
}

#message {
  margin-top: auto;
  align-self: center;
  max-width: 24ch;
  text-align: center;
  font-size: clamp(1.2rem, 4.4vw, 1.9rem);
  font-weight: 900;
  padding: 8px 22px;
  border-radius: 16px;
  background: rgba(74, 44, 16, 0.5);
  opacity: 0;
  transition: opacity 160ms ease;
}

#message.show {
  opacity: 1;
}

/* A standing reminder of the only control there is. */
#tip {
  align-self: center;
  margin-top: 10px;
  font-size: clamp(0.85rem, 2.6vw, 1.05rem);
  font-weight: 700;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(74, 44, 16, 0.38);
  opacity: 0.9;
  transition: opacity 200ms ease;
}

#tip.gone {
  opacity: 0;
}

@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; }
}

/* --- Start / finish screen --- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 32%, #6b4a86, #2b1b3d 74%);
  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 {
  margin: 6px auto;
  max-width: 52ch;
  font-size: clamp(0.85rem, 2.5vw, 1.02rem);
  line-height: 1.5;
  color: #e6dcf2;
}

.hint b {
  color: #fff9ec;
}

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

  #jar-fill,
  #tip {
    transition: none;
  }
}

/* --- The shop --- */
#shop {
  width: min(460px, 100%);
  margin: 0 auto 18px;
  /* The overlay can be taller than a phone once the shop is on it. */
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#purse {
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 800;
  color: #ffd166;
  margin-bottom: 10px;
}

#shop-list {
  display: grid;
  gap: 10px;
}

/* Whole rows, not little links: these are for small fingers. */
.buy {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 62px;
  padding: 12px 16px;
  border: 3px solid rgba(255, 209, 102, 0.5);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff9ec;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.buy:disabled {
  cursor: default;
  opacity: 0.55;
}

.buy.can-afford {
  border-color: #ffd166;
  background: rgba(255, 209, 102, 0.2);
}

.buy .label {
  flex: 1;
}

.buy .name {
  display: block;
  font-size: clamp(1rem, 3vw, 1.15rem);
  font-weight: 800;
}

.buy .what {
  display: block;
  font-size: clamp(0.75rem, 2.3vw, 0.9rem);
  font-weight: 600;
  opacity: 0.8;
  line-height: 1.35;
}

.buy .pips {
  letter-spacing: 2px;
  font-size: 0.9rem;
  color: #ffd166;
}

.buy .price {
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  font-weight: 900;
  white-space: nowrap;
}

#play {
  min-height: 64px;
  padding: 16px 46px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(140deg, #ffd23f, #ffa726);
  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, 167, 38, 0.35);
}
