* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  background: #7fc3f2;
  color: #fff9ec;
  /* Stop the page panning/zooming under a thumb: every tap here is a jump. */
  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) 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-shadow: 0 2px 8px rgba(20, 30, 60, 0.45);
}

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

#stars {
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(24, 40, 74, 0.42);
  white-space: nowrap;
}

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

/* The route is the thing a young player steers by: school at one end, home at
   the other, and a little runner showing how far along he is. */
#route {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(1.1rem, 3.2vw, 1.5rem);
  min-width: 90px;
}

#route-bar {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(24, 40, 74, 0.42);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
}

#route-boy {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: clamp(1rem, 3vw, 1.4rem);
  transition: left 120ms linear;
}

#togo {
  font-size: clamp(0.95rem, 2.8vw, 1.3rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(24, 40, 74, 0.42);
  white-space: nowrap;
}

/* How close Miss Chalk is. It fills up as she gains on you. */
#chase {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 14px;
  border-radius: 999px;
  background: rgba(24, 40, 74, 0.42);
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  font-weight: 800;
}

#chase-bar {
  width: clamp(90px, 26vw, 170px);
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

#chase-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: #7ddb8a;
  transition: width 140ms linear, background-color 240ms ease;
}

#chase.close #chase-fill {
  background: #ffb703;
}

#chase.very-close #chase-fill {
  background: #ff5a5a;
}

#chase.very-close {
  animation: pulse 700ms ease-in-out infinite;
}

#message {
  margin-top: auto;
  align-self: center;
  max-width: 26ch;
  text-align: center;
  font-size: clamp(1.1rem, 4vw, 1.7rem);
  font-weight: 900;
  padding: 8px 20px;
  border-radius: 16px;
  background: rgba(24, 40, 74, 0.42);
  opacity: 0;
  transition: opacity 160ms ease;
}

#message.show {
  opacity: 1;
}

@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 / caught / home 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%, #59a9e6, #17356b 74%);
  cursor: pointer;
}

#overlay h1 {
  margin: 0 0 8px;
  font-size: clamp(2.1rem, 9vw, 4.6rem);
  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: #d8e8f8;
}

.hint b {
  color: #fff9ec;
}

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

  #route-boy,
  #chase-fill {
    transition: none;
  }
}
