* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1f2120;
  color: #fbf3e4;
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 64px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  font-size: clamp(13px, 1vmin + 9px, 18px);
  font-weight: 800;
}

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgb(42 44 42 / 0.86);
  border: 1px solid #46443e;
  white-space: nowrap;
  color: #d9cfbd;
}

.pill.strong {
  color: #fbf3e4;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
  .hud {
    gap: 4px;
    left: 6px;
    right: 58px;
  }
  .pill {
    padding: 5px 9px;
  }
}

/* ---------- Pause button ---------- */

.icon-btn {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  right: 8px;
  width: 46px;
  height: 46px;
  border: 1px solid #46443e;
  border-radius: 14px;
  background: rgb(42 44 42 / 0.86);
  color: #fbf3e4;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn:focus-visible,
.btn:focus-visible {
  outline: 3px solid #c6f432;
  outline-offset: 3px;
}

.pause-glyph {
  width: 14px;
  height: 16px;
  border-left: 5px solid currentColor;
  border-right: 5px solid currentColor;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: rgb(31 33 32 / 0.7);
  overflow-y: auto;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.8vmin, 12px);
  width: min(480px, 100%);
  margin: auto 0;
  padding: clamp(16px, 4vmin, 30px) clamp(16px, 4vmin, 28px);
  border-radius: 28px;
  background: rgb(42 44 42 / 0.95);
  border: 1px solid #46443e;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.45);
}

.badge {
  position: relative;
  width: clamp(72px, 16vmin, 96px);
  height: clamp(72px, 16vmin, 96px);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #e2ffa6, #b9f24a 55%, #7fb81f);
  box-shadow: 0 6px 0 #5e8a14;
}

.badge .bolt {
  position: absolute;
  left: 30%;
  top: 18%;
  width: 40%;
  height: 64%;
  background: #1f2120;
  clip-path: polygon(55% 0, 10% 58%, 45% 58%, 30% 100%, 90% 38%, 55% 38%, 75% 0);
}

.overlay h1,
.overlay h2 {
  margin: 0;
  font-size: clamp(30px, 8vmin, 52px);
  font-weight: 900;
  line-height: 1.05;
  color: #fbf3e4;
}

.overlay p {
  margin: 0;
  color: #d9cfbd;
  font-size: clamp(14px, 3.4vmin, 17px);
  line-height: 1.35;
}

.overlay .hint,
.overlay .note {
  font-size: clamp(13px, 3vmin, 15px);
}

.overlay .note {
  color: #b3a995;
}

.overlay .result {
  font-size: clamp(30px, 8vmin, 48px);
  color: #fbf3e4;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.near-miss {
  margin: 6px 0 8px;
  padding: 6px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffb86c;
  background: rgba(255, 184, 108, 0.12);
  border: 1px solid rgba(255, 184, 108, 0.35);
  border-radius: 999px;
  text-align: center;
  animation: pulse-near-miss 1.8s ease-in-out infinite;
}

@keyframes pulse-near-miss {
  0%, 100% {
    transform: scale(1);
    opacity: 0.95;
  }
  50% {
    transform: scale(1.02);
    opacity: 1;
  }
}

.overlay strong {
  color: #fbf3e4;
}

.overlay .best-line strong,
.overlay .stats strong {
  color: #27d6c1;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-top: 4px;
}

.mode-grid .btn {
  min-width: 0;
  font-size: 17px;
  padding: 10px 12px;
}

@media (max-width: 360px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  width: 100%;
}

.mode-buttons .btn {
  min-width: 0;
  flex: 1 1 180px;
  font-size: 18px;
}

.btn {
  min-width: 160px;
  min-height: 52px;
  padding: 12px 24px;
  border: 0;
  border-radius: 999px;
  background: #ee5e24;
  color: #15130f;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8400f;
  transition: transform 0.08s ease;
}

.btn:hover {
  background: #8552f7;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #b8400f;
}

.btn.btn-alt {
  background: #363836;
  box-shadow: 0 6px 0 #46443e;
  border: 1px solid #3a4250;
}

.btn.btn-alt:hover {
  background: #2a3140;
}

.btn.btn-alt:active {
  box-shadow: 0 3px 0 #46443e;
}

/* Last results as small bars (taller = slower). The numbers are in #history-line. */
.history {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 52px;
  padding: 6px 10px;
  border-radius: 14px;
  background: #1f2120;
  border: 1px solid #46443e;
}

.history i {
  display: block;
  width: 12px;
  border-radius: 4px 4px 2px 2px;
  background: #3a4250;
}

.history i.now {
  background: #27d6c1;
}

.history i.best {
  background: #b9f24a;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

@media (max-height: 460px) {
  .badge,
  .overlay .note {
    display: none;
  }
  .card {
    gap: 6px;
    padding: 12px 18px;
  }
  .btn {
    min-height: 46px;
    font-size: 17px;
  }
  .mode-grid .btn {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}
