* {
  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;
}

.pill.round {
  color: #d9cfbd;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #1f2120;
}

.p1 .swatch {
  background: #27d6c1;
}

.p2 .swatch {
  background: #ff6b8e;
}

.pips {
  display: flex;
  gap: 4px;
}

.pips i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #b3a995;
}

.p1 .pips i.on {
  background: #27d6c1;
  border-color: #27d6c1;
}

.p2 .pips i.on {
  background: #ff6b8e;
  border-color: #ff6b8e;
}

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

/* ---------- 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.66);
  overflow-y: auto;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.8vmin, 12px);
  width: min(460px, 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(88px, 20vmin, 120px);
  height: clamp(48px, 11vmin, 66px);
  border-radius: 18px;
  background: repeating-linear-gradient(90deg, #3fae5a 0 14px, #379c50 14px 28px);
  box-shadow: 0 6px 0 #2a7a3e;
  overflow: hidden;
}

.badge span {
  position: absolute;
  bottom: 14%;
  width: 30%;
  height: 56%;
  border-radius: 50%;
}

.badge .b1 {
  left: 8%;
  background: #27d6c1;
}

.badge .b2 {
  right: 8%;
  background: #ff6b8e;
}

.badge .ball {
  left: 41%;
  top: 14%;
  bottom: auto;
  width: 18%;
  height: 33%;
  background: #fbf3e4;
}

.hud .clock {
  min-width: 64px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  color: #ffc857;
}

.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 {
  font-size: clamp(13px, 3vmin, 15px);
}

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

.overlay .near-miss {
  margin: 4px 0 2px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(251, 146, 60, 0.22);
  border: 1px solid rgba(251, 146, 60, 0.45);
  color: #fed7aa;
  font-size: clamp(13px, 3vmin, 15px);
  font-weight: 700;
  animation: popNearMiss 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popNearMiss {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.overlay strong {
  color: #fbf3e4;
}

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

.controls {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  color: #d9cfbd;
  font-size: clamp(13px, 3vmin, 15px);
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  margin-right: 4px;
  border-radius: 999px;
  color: #1f2120;
  font-weight: 800;
}

.tag.p1 {
  background: #27d6c1;
}

.tag.p2 {
  background: #ff6b8e;
}

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

.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,
  .controls {
    display: none;
  }
  .card {
    gap: 6px;
    padding: 14px 18px;
  }
  .btn {
    min-height: 46px;
    font-size: 17px;
  }
}

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