:root {
  --ink: #0d1530;
  --blue: #2f7df6;
  --blue-hi: #6fc2ff;
  --gold: #ffd23f;
  --red: #e8262c;
  --display: "Arial Black", "Segoe UI Black", "Helvetica Neue", Impact, system-ui, sans-serif;
  --text: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #1c2a5c 0%, #0a0f24 70%);
  color: #fff;
  font-family: var(--text);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#stage {
  position: relative;
  height: 100dvh;
  width: min(100vw, calc(100dvh * 0.6));
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
  background: #0a0f24;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
}

#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.hidden { display: none !important; }

/* ---------- world-anchored labels ---------- */
.wl { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; font-family: var(--display); }
.wl.num {
  font-size: 40px; line-height: 1; color: #fff;
  -webkit-text-stroke: 7px #17171f; paint-order: stroke fill;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}
.wl.count {
  font-size: 19px; line-height: 1; padding: 4px 13px 5px; border-radius: 999px;
  background: linear-gradient(#3b8cff, #1c53c9); border: 2px solid #dff1ff; color: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.wl.bossbar {
  width: 168px; height: 26px; border-radius: 7px; background: #3a0d10; border: 3px solid #15050a;
  overflow: hidden; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}
.wl.bossbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#ff6a55, #d6181f); transition: width 0.08s linear; }
.wl.bossbar b {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 19px; font-weight: 900;
  -webkit-text-stroke: 4px #15050a; paint-order: stroke fill;
}

.pop {
  position: absolute; font-family: var(--display); font-size: 22px; white-space: nowrap;
  -webkit-text-stroke: 5px #10131f; paint-order: stroke fill;
  animation: pop-up 0.85s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}
.pop.blue { color: #bfe9ff; }
.pop.gold { color: #ffe066; }
.pop.red { color: #ff6a5a; }
.pop.big { font-size: 32px; }
.pop.huge { font-size: 40px; animation-duration: 1.3s; }
@keyframes pop-up {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  18% { transform: translate(-50%, -90%) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -260%) scale(1); opacity: 0; }
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; padding: max(10px, env(safe-area-inset-top)) 10px 10px; }
.hud-top { display: flex; align-items: center; gap: 10px; }
.hud-mid { flex: 1; min-width: 0; text-align: center; }
#hud-level {
  font-family: var(--display); font-size: 13px; letter-spacing: 0.08em; margin-bottom: 5px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.progress {
  position: relative; height: 12px; border-radius: 999px; background: rgba(8, 12, 30, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.progress i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--blue-hi), var(--blue)); }
.progress .skull {
  position: absolute; right: -9px; top: 50%; width: 20px; height: 20px; margin-top: -10px; border-radius: 50%;
  background: var(--red); border: 2px solid #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.progress .skull::before, .progress .skull::after {
  content: ""; position: absolute; top: -6px; width: 0; height: 0; border: 4px solid transparent; border-bottom: 8px solid #f3e6c8;
}
.progress .skull::before { left: -3px; transform: rotate(-28deg); }
.progress .skull::after { right: -3px; transform: rotate(28deg); }

.icon-btn {
  pointer-events: auto; width: 42px; height: 42px; flex: none; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.85);
  background: rgba(8, 12, 30, 0.55); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.off #mute-wave { display: none; }
.icon-btn.off { opacity: 0.6; }
.icon-btn:active { transform: translateY(2px); }

.hud-loadout {
  margin: 8px auto 0; width: max-content; display: flex; align-items: center; gap: 8px; padding: 4px 12px;
  border-radius: 999px; background: rgba(8, 12, 30, 0.55); font-family: var(--display); font-size: 12px; letter-spacing: 0.06em;
}
.rank { display: inline-flex; gap: 3px; }
.rank i { width: 9px; height: 9px; transform: rotate(45deg); background: rgba(255, 255, 255, 0.25); }
.rank i.on { background: var(--gold); }

#toast {
  position: absolute; left: 0; right: 0; top: 24%; text-align: center; font-family: var(--display); font-size: 34px;
  color: #fff; -webkit-text-stroke: 7px #5a0d10; paint-order: stroke fill; opacity: 0; letter-spacing: 0.04em;
}
#toast.show { animation: toast 1.9s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: scale(1.6); }
  12% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.95); }
}
#hint {
  position: absolute; left: 0; right: 0; bottom: 7%; text-align: center; font-family: var(--display); font-size: 17px;
  letter-spacing: 0.1em; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6); animation: hint 1.1s ease-in-out infinite alternate;
  transition: opacity 0.4s;
}
#hint.gone { opacity: 0; }
@keyframes hint { from { transform: translateX(-14px); } to { transform: translateX(14px); } }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
  background: linear-gradient(rgba(8, 12, 32, 0.25), rgba(8, 12, 32, 0.78) 62%, rgba(8, 12, 32, 0.92));
}
#screen-loading { background: #0a0f24; }
#screen-title { justify-content: flex-end; padding-bottom: max(26px, env(safe-area-inset-bottom)); }
#screen-title .logo { margin-top: 9vh; margin-bottom: auto; }

.logo { font-family: var(--display); line-height: 0.86; transform: rotate(-4deg); filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.35)); }
.logo span { display: block; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; }
.logo span:first-child { font-size: clamp(54px, 19vw, 96px); color: var(--gold); letter-spacing: 0.02em; }
.logo span:last-child { font-size: clamp(34px, 11.6vw, 60px); color: #fff; letter-spacing: 0.03em; }
.logo.small { transform: rotate(-4deg) scale(0.7); }
.tagline { margin: 0; font-weight: 700; font-size: 16px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); }

.levels { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 330px; }
.levels button {
  width: 46px; height: 46px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.85); background: rgba(12, 20, 52, 0.75);
  color: #fff; font-family: var(--display); font-size: 17px; cursor: pointer;
}
.levels button.sel { background: linear-gradient(#59b0ff, #1f62dc); box-shadow: 0 4px 0 #0f2f7c; transform: translateY(-2px); }
.levels button:disabled { opacity: 0.35; cursor: default; border-style: dashed; }
#level-name { width: 100%; font-family: var(--display); font-size: 13px; letter-spacing: 0.08em; opacity: 0.9; }

.btn {
  pointer-events: auto; min-width: 210px; padding: 13px 26px 15px; border-radius: 16px; border: 3px solid #fff;
  background: linear-gradient(#34406e, #1b2347); color: #fff; font-family: var(--display); font-size: 19px; letter-spacing: 0.06em;
  cursor: pointer; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.45);
}
.btn.primary { background: linear-gradient(#ffe066, #ffab1f); color: #4a2500; font-size: 26px; min-width: 240px; box-shadow: 0 7px 0 #9a5a00; }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45); }

.howto { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 7px; font-size: 13.5px; font-weight: 600; text-align: left; }
.howto li { display: flex; align-items: center; gap: 9px; }
.chip {
  display: inline-grid; place-items: center; width: 38px; height: 24px; border-radius: 7px; font-family: var(--display); font-size: 13px;
  border: 2px solid #fff;
}
.chip.blue { background: var(--blue); }
.chip.gold { background: var(--gold); color: #4a2500; }
.chip.red { background: var(--red); }
#version { font-size: 11px; font-weight: 700; opacity: 0.55; letter-spacing: 0.06em; }

.screen h2 { font-family: var(--display); font-size: 44px; margin: 0 0 8px; -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill; }

.banner {
  width: 118%; padding: 16px 0 18px; transform: rotate(-4deg); font-family: var(--display); font-size: clamp(34px, 11vw, 54px);
  background: linear-gradient(#ffe066, #ffab1f); color: #4a2500; border-top: 5px solid #fff; border-bottom: 5px solid #fff;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.35); animation: banner-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.banner.fail { background: linear-gradient(#5b6078, #30344a); color: #fff; }
@keyframes banner-in { from { transform: rotate(-4deg) scale(0.2); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }
#result-sub { margin: 8px 0 0; font-weight: 700; font-size: 16px; }
.stats { display: flex; gap: 10px; margin: 4px 0 8px; }
.stats div { min-width: 92px; padding: 9px 8px; border-radius: 12px; background: rgba(12, 20, 52, 0.8); border: 2px solid rgba(255, 255, 255, 0.5); }
.stats b { display: block; font-family: var(--display); font-size: 24px; }
.stats span { font-size: 11.5px; font-weight: 700; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.05em; }

@media (prefers-reduced-motion: reduce) {
  #hint, .banner, #toast.show { animation-duration: 0.01s; }
}
