* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0a0a12;
  color: #e8e3d6;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  overflow: hidden;
}

.wrap {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  gap: 8px;
}

.hud {
  width: min(480px, 100vw - 16px);
  display: flex;
  justify-content: space-between;
  background: #14141f;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  padding: 8px 12px;
  font-variant-numeric: tabular-nums;
  gap: 6px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
}

.hud .label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #7a7a8a;
}

.hud-item span:last-child {
  font-size: 17px;
  font-weight: 600;
  color: #e8e3d6;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  position: relative;
  aspect-ratio: 3 / 4;
  width: min(480px, 100vw - 16px, calc((100dvh - 110px) * 3 / 4));
  height: auto;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  overflow: hidden;
  background: #0d0d18;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #0d0d18;
  touch-action: none;
}

.pause-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(20, 20, 31, 0.7);
  color: #e8e3d6;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
  backdrop-filter: blur(4px);
  font-family: inherit;
  padding: 0;
}

.pause-btn.show { display: flex; }
.pause-btn:active { transform: scale(0.94); background: rgba(40, 40, 60, 0.85); }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 18, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  gap: 10px;
  backdrop-filter: blur(2px);
  overflow-y: auto;
  z-index: 10;
}

.overlay.hidden { display: none; }

.overlay h1 {
  font-size: clamp(24px, 6vw, 36px);
  margin: 0;
  letter-spacing: 2px;
  color: #ff6b3d;
}

.overlay h2 {
  font-size: clamp(20px, 5vw, 28px);
  margin: 0;
  letter-spacing: 1px;
  color: #ff6b3d;
}

.overlay p {
  margin: 0;
  font-size: 14px;
  color: #c8c3b6;
}

.overlay .hint {
  color: #7a7a8a;
  font-size: 12px;
}

.btn {
  margin-top: 4px;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  background: #ff6b3d;
  color: #0a0a12;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  font-family: inherit;
}

.btn:hover { background: #ff8559; }
.btn:active { transform: scale(0.97); }

.name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.name-row label {
  font-size: 13px;
  color: #7a7a8a;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#nameInput {
  background: #14141f;
  color: #e8e3d6;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 16px;
  width: min(220px, 60vw);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-user-select: text;
  user-select: text;
}

#nameInput:focus { border-color: #ff6b3d; }

.leaderboard {
  width: min(280px, calc(100% - 16px));
  background: #14141f;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 8px 12px;
}

.lb-title {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #7a7a8a;
  margin-bottom: 4px;
}

.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  max-height: 38vh;
  overflow-y: auto;
}

.lb-list li {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: #c8c3b6;
}

.lb-list li.me { color: #ffd24a; font-weight: 600; }

.lb-list li .lb-rank { color: #7a7a8a; width: 26px; text-align: left; }

.lb-list li .lb-name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 8px;
}

.lb-list li.lb-empty {
  color: #5a5a6a;
  justify-content: center;
}

.popups {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}

.popup {
  position: absolute;
  font-family: "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #ffd24a;
  font-size: clamp(20px, 5vw, 28px);
  text-shadow:
    0 0 8px #ffd24a,
    0 0 18px #ff8c1a,
    2px 2px 0 #0a0a12;
  animation: popupAnim 1.2s ease-out forwards;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

@keyframes popupAnim {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  60%  { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -110%) scale(0.95); }
}

.beast-banner {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  font-family: "Courier New", monospace;
  font-weight: 900;
  letter-spacing: 6px;
  font-size: clamp(28px, 8vw, 56px);
  color: #ff2d3b;
  text-shadow: 0 0 18px #ff2d3b, 0 0 40px #ff2d3b, 4px 4px 0 #000;
  opacity: 0;
}

.beast-banner.flash {
  animation: beastFlash 1.6s ease-out forwards;
}

@keyframes beastFlash {
  0%   { opacity: 0; transform: scale(0.4); }
  20%  { opacity: 1; transform: scale(1.2); }
  60%  { opacity: 1; transform: scale(1.0); }
  100% { opacity: 0; transform: scale(1.05); }
}

.touch-hint {
  display: none;
  font-size: 12px;
  color: #7a7a8a;
}

@media (hover: none) and (pointer: coarse) {
  .desktop-hint { display: none; }
  .touch-hint { display: block; }
}
