* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0e1116;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #fff;
  touch-action: none;        /* let the game own all gestures */
  overscroll-behavior: none;  /* no pull-to-refresh / rubber-banding on mobile */
  user-select: none;
  -webkit-user-select: none;
}

canvas { display: block; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 22px;
  pointer-events: none;
  z-index: 5;
}

.hud-box {
  background: rgba(10, 14, 22, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 8px 16px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 90px;
}

.hud-box .unit { font-size: 13px; opacity: 0.7; font-weight: 600; }
#best-box { justify-content: center; font-size: 16px; }
#speed-box { justify-content: flex-end; }

.coin-box { color: #ffd43b; }
.coin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe27a, #f5b301 60%, #b97e00);
  border: 2px solid #8a5a00;
  box-shadow: 0 0 10px rgba(255, 212, 59, 0.7);
  align-self: center;
}

#coin-box.pulse { animation: coin-pulse 0.35s ease-out; }

@keyframes coin-pulse {
  0%   { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.float-score {
  position: fixed;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 900;
  color: #ffd43b;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 7;
  animation: float-up 0.7s ease-out forwards;
}

@keyframes float-up {
  0%   { opacity: 1; margin-top: 0; }
  100% { opacity: 0; margin-top: -70px; }
}

/* ---------- countdown ---------- */
#count {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 160px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  z-index: 6;
}

#count.pop { animation: count-pop 0.9s ease-out; }

@keyframes count-pop {
  0%   { transform: scale(2.2); opacity: 0; }
  25%  { transform: scale(1);   opacity: 1; }
  80%  { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(0.9);  opacity: 0; }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.62);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.overlay.show { display: flex; }

.panel {
  background: linear-gradient(160deg, #1b2333 0%, #131a28 100%);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  padding: 44px 56px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  max-width: 520px;
  width: calc(100% - 48px);
}

.panel h1 {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, #ffd166, #ef476f, #8338ec);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 10px;
}

.panel .sub {
  color: rgba(255, 255, 255, 0.75);
  font-size: 16px;
  margin-bottom: 26px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 30px;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.85);
}

kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  margin: 0 2px;
}

button {
  font-family: inherit;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(90deg, #ef476f, #f78c2a);
  border: none;
  border-radius: 14px;
  padding: 14px 44px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(239, 71, 111, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

button:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(239, 71, 111, 0.55); }
button:active { transform: translateY(1px); }

.hint { margin-top: 14px; font-size: 13px; color: rgba(255, 255, 255, 0.45); }

.back-link {
  display: inline-block;
  margin-top: 18px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #8fa3bf;
  text-decoration: none;
  border-bottom: 2px solid rgba(255, 255, 255, 0.25);
  padding-bottom: 3px;
  transition: color 0.15s, border-color 0.15s;
}

.back-link:hover {
  color: #fff;
  border-color: #ef476f;
}

.final-score {
  font-size: 72px;
  font-weight: 900;
  margin: 8px 0 4px;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 10px;
}

.best-line { margin-top: 6px; font-size: 15px; color: rgba(255, 255, 255, 0.65); }
.best-line span { font-weight: 700; color: #ffd166; }

/* ---------- mobile ---------- */
/* phone = narrow, short, FHD-portrait, 21:9-landscape, or any touch device */
@media (max-width: 600px), (max-height: 500px), (orientation: portrait) and (max-width: 1080px), (orientation: landscape) and (max-height: 1080px) and (min-aspect-ratio: 2/1), (pointer: coarse) and (max-width: 2000px) {
  #hud { padding: 12px 12px; gap: 6px; }
  .hud-box {
    font-size: 15px;
    padding: 6px 10px;
    min-width: 56px;
    border-radius: 10px;
  }
  .hud-box .unit { font-size: 10px; }

  .panel {
    padding: 30px 22px;
    border-radius: 18px;
    max-width: 400px;
  }
  .panel h1 { font-size: 34px; letter-spacing: 2px; }
  .panel .sub { font-size: 14px; }
  .controls { gap: 8px; font-size: 13px; }
  kbd { font-size: 11px; padding: 2px 6px; }

  #start-btn, #restart-btn { font-size: 16px; padding: 14px 32px; }
  .final-score { font-size: 52px; }
  .hint { font-size: 12px; }
  .back-link { font-size: 13px; }

  #count { font-size: 100px; }
}
