* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #0b1026;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* The game is portrait. On a phone the frame is the whole screen; on a wide
   screen it is a centred portrait column. */
#frame {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: min(100vw, calc(100dvh * 0.72));
  transform: translateX(-50%);
  overflow: hidden;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

#hud[hidden] { display: none; }
.label { display: block; font-size: 11px; letter-spacing: 0.12em; opacity: 0.9; }
#score { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1; }
#lead { flex: 1; }
#lead .track { height: 12px; margin-top: 4px; border-radius: 6px; background: rgba(11, 16, 38, 0.45); overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.8); }
#lead-fill { height: 100%; width: 80%; background: #5cf08a; transition: width 0.15s linear, background 0.3s; }
#lead.low #lead-fill { background: #ff4d4d; }
#lead.low .label { color: #ffd0d0; animation: blink 0.5s steps(2, start) infinite; }

#mute {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(11, 16, 38, 0.45);
  font-size: 18px;
}

#combo {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 34px;
  font-weight: 900;
  font-style: italic;
  color: #ffd23f;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
}

#combo.show { animation: pop 0.8s ease-out forwards; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(11, 16, 38, 0.62);
}

#overlay[hidden] { display: none; }

#title {
  margin: 0;
  font-size: clamp(34px, 11vw, 60px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  color: #ffd23f;
  text-shadow: 0 4px 0 #b8421f;
}

#sub { margin: 0; font-weight: 700; }
#how { margin: 0; padding: 0; list-style: none; line-height: 1.9; font-weight: 600; }
#how b { display: inline-block; min-width: 2.6em; padding: 0 0.4em; border-radius: 6px; background: rgba(255, 255, 255, 0.18); }
#result { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.5; }
#result[hidden], #how[hidden], #sub[hidden] { display: none; }
#go { margin: 6px 0 0; font-size: 20px; font-weight: 900; letter-spacing: 0.06em; animation: blink 1.1s steps(2, start) infinite; }

@keyframes blink { to { visibility: hidden; } }
@keyframes pop {
  0% { opacity: 0; transform: scale(1.6); }
  15% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}
