:root {
  --bg: #1f2120;
  --violet: #7c47f5;
  --cyan: #27d6c1;
  --yellow: #facc15;
  --pink: #fb7185;
  --lime: #a3e635;
  --orange: #fb923c;
  --text: #fbf3e4;
  --muted: #b4bccb;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

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

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

.hud {
  position: fixed;
  z-index: 2;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  pointer-events: none;
  font-size: clamp(14px, 1.6vmin + 9px, 22px);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
  padding: 0.3em 0.75em;
  border-radius: 999px;
  background: rgb(31 33 32 / 0.72);
  border: 2px solid rgb(255 255 255 / 0.1);
  font-weight: 800;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.pill .label {
  font-size: 0.62em;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.pill-time.warn {
  border-color: var(--pink);
  background: rgb(190 18 60 / 0.55);
}

.pill-time.hit {
  animation: hit 0.5s ease;
}

@keyframes hit {
  0%,
  100% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.25);
    background: rgb(251 113 133 / 0.9);
  }
}

.pill-combo .mult {
  display: none;
  margin-left: 0.15em;
  padding: 0.05em 0.4em;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 900;
  color: #1a1300;
}

.pill-combo.x2 {
  border-color: var(--cyan);
}

.pill-combo.x2 .mult {
  display: inline;
  background: var(--cyan);
  color: #062a33;
}

.pill-combo.x3 {
  border-color: var(--yellow);
}

.pill-combo.x3 .mult {
  display: inline;
  background: var(--yellow);
}

.icon-btn {
  display: none;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 0.14);
  border-radius: 999px;
  background: rgb(31 33 32 / 0.72);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.is-playing .icon-btn {
  display: inline-flex;
}

.icon-btn .bar {
  width: 5px;
  height: 16px;
  border-radius: 3px;
  background: currentColor;
}

.icon-btn:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

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

.overlay {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 35%, rgb(124 58 237 / 0.3), transparent 65%), rgb(31 33 32 / 0.78);
  touch-action: manipulation;
}

.panel {
  margin: auto;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2.2vmin, 16px);
  text-align: center;
}

.overlay h1,
.overlay h2 {
  margin: 0;
  font-size: clamp(32px, 8vmin, 64px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.01em;
  color: var(--yellow);
  text-shadow: 0 4px 0 #7c47f5, 0 8px 24px rgb(124 58 237 / 0.5);
}

.overlay p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.goal {
  max-width: 30em;
  font-size: clamp(15px, 1.2vmin + 11px, 19px);
  color: var(--text) !important;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.07);
  font-size: 14px;
  color: var(--text);
}

.legend svg {
  width: 26px;
  height: 26px;
  flex: none;
}

.legend b {
  color: var(--yellow);
}

.legend li:last-child b {
  color: var(--pink);
}

.combo-note {
  font-size: 14px;
}

.combo-note b {
  color: var(--cyan);
}

.result {
  font-size: clamp(20px, 2vmin + 14px, 30px);
  color: var(--text) !important;
}

.result strong {
  color: var(--yellow);
  font-size: 1.3em;
}

.best strong {
  color: var(--text);
}

.stats {
  font-size: 15px;
}

.hidden {
  display: none !important;
}

.btn {
  min-width: 170px;
  min-height: 54px;
  padding: 12px 30px;
  border: 0;
  border-radius: 999px;
  background: #ee5e24;
  color: #15130f;
  font: inherit;
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8400f;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:hover {
  background: #d93d12;
}

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

.hint {
  font-size: 14px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: min(420px, 100%);
}

.btn-row .btn {
  flex: 1 1 160px;
  min-width: 0;
  padding-left: 18px;
  padding-right: 18px;
}

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

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

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

.mode-tag {
  padding: 2px 12px;
  border-radius: 999px;
  background: #27d6c1;
  color: #1f2120 !important;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.unlock {
  padding: 6px 14px;
  border-radius: 14px;
  background: #363836;
  border: 1px solid #3a4250;
  color: #fbf3e4 !important;
  font-weight: 800;
}

.near-miss {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: #ff6b4a;
  letter-spacing: 0.02em;
  animation: pulse-near 1.5s ease-in-out infinite;
}

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

.skins {
  display: flex;
  align-items: center;
  gap: 10px;
}

.skin-label {
  font-size: 13px;
  font-weight: 800;
  color: #d9cfbd;
}

.skin-row {
  display: flex;
  gap: 8px;
}

.skin {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #3a4250;
  border-radius: 14px;
  background: #363836;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.skin .bowl {
  width: 26px;
  height: 16px;
  border-radius: 3px 3px 12px 12px;
  background: linear-gradient(var(--top), var(--bottom));
  box-shadow: 0 -4px 0 var(--rim);
}

.skin[aria-pressed="true"] {
  border-color: #fbf3e4;
  background: #2a3140;
}

.skin:disabled {
  cursor: not-allowed;
}

.skin:disabled .bowl {
  opacity: 0.25;
}

.skin .lock {
  position: absolute;
  inset: auto 0 1px 0;
  font-size: 10px;
  font-weight: 900;
  color: #d9cfbd;
}

.skin:focus-visible {
  outline: 3px solid #c6f432;
  outline-offset: 3px;
}

@media (max-height: 600px) {
  .skins {
    display: none;
  }
}

@media (max-height: 430px) {
  .overlay h1,
  .overlay h2 {
    font-size: clamp(28px, 9vmin, 44px);
  }

  .panel {
    gap: 8px;
  }

  .goal {
    font-size: 15px;
  }

  .legend li {
    padding: 3px 10px 3px 4px;
  }

  .btn {
    min-height: 48px;
    font-size: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pill-time.hit {
    animation: none;
  }

  .btn {
    transition: none;
  }
}
